slotUI/SlotCli.py

changeset 110
b0e4f4249351
parent 109
bb00e6994e5e
child 111
7e9a451870ed
equal deleted inserted replaced
109:bb00e6994e5e 110:b0e4f4249351
10 from subprocess import Popen, PIPE 10 from subprocess import Popen, PIPE
11 import sys, os 11 import sys, os
12 from copy import copy 12 from copy import copy
13 import curses 13 import curses
14 from time import sleep 14 from time import sleep
15
16 import SimpleXMLRPCServer
17 import xmlrpclib
18 import threading
19
15 20
16 VERSION = "1.7" 21 VERSION = "1.7"
17 MAXSLOTS = 6 22 MAXSLOTS = 6
18 TERM = { 23 TERM = {
19 "caption": "\033[1;37m\033[1;44m", 24 "caption": "\033[1;37m\033[1;44m",
51 56
52 def trigger_event(what): 57 def trigger_event(what):
53 trigger_sound(what) 58 trigger_sound(what)
54 Popen(["/bin/sh", os.path.abspath(EVENTPREFIX + what)]) 59 Popen(["/bin/sh", os.path.abspath(EVENTPREFIX + what)])
55 60
61 class SlotServer(threading.Thread):
62 def __init__(self, blackbox):
63 threading.Thread.__init__(self)
64 self.server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000))
65 self.server.register_instance(blackbox)
66 #self.server.register_function(lambda astr: '_' + astr, '_string')
67
68 def run(self):
69 self.server.serve_forever()
70
71 class SlotClient():
72 def __init__(self, url):
73 self.box = xmlrpclib.Server(url)
74
56 class SlotCli(): 75 class SlotCli():
57 def __init__(self, test = None, dev=""): 76 def __init__(self, test = None, dev=""):
58 self.box = Blackbox() 77 self.box = Blackbox()
59 if not test: 78 if (not test):
60 self.box.connect(dev) 79 self.box.connect(dev)
80 self.rpcserver = SlotServer(self.box)
81 self.rpcserver.start()
61 self.slot_dummy = { 82 self.slot_dummy = {
62 "name": "Unnamed", 83 "name": "Unnamed",
63 "laps": 0, 84 "laps": 0,
64 "laps_last": 0, 85 "laps_last": 0,
65 "last": 0.00, 86 "last": 0.00,
572 help="Communication port", metavar="[/dev/ttyUSB0]") 593 help="Communication port", metavar="[/dev/ttyUSB0]")
573 594
574 (options, args) = parser.parse_args() 595 (options, args) = parser.parse_args()
575 #if not options.dev: 596 #if not options.dev:
576 # options.dev = "/dev/ttyUSB0" 597 # options.dev = "/dev/ttyUSB0"
577 cli = SlotCli(options.test, options.dev) 598
599 if options.live or options.learn or options.playback:
600 cli = SlotCli(options.test, options.dev)
601 else:
602 cli = SlotClient('http://localhost:8000')
578 # should a CLI function be started? 603 # should a CLI function be started?
579 604
580 if options.live: 605 if options.live:
581 # start the live monitor 606 # start the live monitor
582 cli.monitor() 607 cli.monitor()

mercurial