1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Package entry-point."""
10 from tornado
import ioloop
12 import composite_echo_gadget
14 import hid_echo_gadget
15 import keyboard_gadget
22 """Parse application arguments."""
23 parser
= argparse
.ArgumentParser(description
='USB gadget server.')
25 '-i', '--interface', default
='lo',
26 help='Listen for HTTP connections on this interface.')
28 '-p', '--port', default
=8080,
29 help='Listen for HTTP connections on this port.')
31 '--hardware', default
='beaglebone-black',
32 help='Hardware configuration.')
35 help='Start with the device claimed by this client.')
36 return parser
.parse_args()
42 server
.interface
= args
.interface
43 server
.port
= args
.port
44 server
.hardware
= args
.hardware
45 server
.claimed_by
= args
.start_claimed
47 addrs
= netifaces
.ifaddresses(server
.interface
)
48 ip_address
= addrs
[netifaces
.AF_INET
][0]['addr']
49 server
.address
= '{}:{}'.format(ip_address
, server
.port
)
51 server
.chip
= linux_gadgetfs
.LinuxGadgetfs(server
.hardware
)
52 server
.SwitchGadget(server
.default
)
54 composite_echo_gadget
.RegisterHandlers()
55 echo_gadget
.RegisterHandlers()
56 hid_echo_gadget
.RegisterHandlers()
57 keyboard_gadget
.RegisterHandlers()
58 mouse_gadget
.RegisterHandlers()
60 server
.http_server
.listen(server
.port
)
62 ioloop
.IOLoop
.instance().start()
66 if __name__
== '__main__':