Sat, 21 Dec 2013 16:51:38 +0100
fixed unlimited fuel set bug
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
1 | #!/usr/bin/env python |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
2 | """ |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
3 | Freeslot project |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
4 | Command line interface |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
5 | """ |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
6 | |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
7 | from freeslot import Blackbox, LOGLEVEL |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
8 | from optparse import OptionParser |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
9 | from operator import itemgetter |
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
10 | from subprocess import Popen, PIPE |
137
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
11 | from logger import eventLogger |
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
12 | import sys, os |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
13 | from copy import copy |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
14 | import curses |
137
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
15 | from time import sleep, time |
115 | 16 | import ConfigParser |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
17 | |
110
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
18 | import SimpleXMLRPCServer |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
19 | import xmlrpclib |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
20 | import threading |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
21 | |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
22 | |
139
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
23 | VERSION = "1.8.2" |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
24 | MAXSLOTS = 6 |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
25 | TERM = { |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
26 | "caption": "\033[1;37m\033[1;44m", |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
27 | "text": "\033[1;30m", |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
28 | } |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
29 | |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
30 | # disable debug log output |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
31 | LOGLEVEL = 10 |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
32 | |
81 | 33 | SOUNDPREFIX = "quake-" |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
34 | EVENTPREFIX = "event/" |
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
35 | SOUNDS = { |
81 | 36 | "countdown_start": os.path.abspath(SOUNDPREFIX + "sound/countdown.mp3"), |
37 | "race_start": os.path.abspath(SOUNDPREFIX + "sound/racestart.mp3"), | |
96
bcba10c35f09
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
95
diff
changeset
|
38 | "race_prepare": os.path.abspath(SOUNDPREFIX + "sound/prepare.mp3"), |
81 | 39 | "lap_record": os.path.abspath(SOUNDPREFIX + "sound/laprecord.mp3"), |
117
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
40 | # "first_position": os.path.abspath(SOUNDPREFIX + "sound/laprecord.mp3"), |
81 | 41 | "fuel_warning1": os.path.abspath(SOUNDPREFIX + "sound/fuel1.mp3"), |
42 | "fuel_warning2": os.path.abspath(SOUNDPREFIX + "sound/fuel2.mp3"), | |
43 | "fuel_full": os.path.abspath(SOUNDPREFIX + "sound/fuel_full.mp3"), | |
44 | "pitlane_enter": os.path.abspath(SOUNDPREFIX + "sound/pitlane_enter.mp3"), | |
45 | "pitlane_exit": os.path.abspath(SOUNDPREFIX + "sound/pitlane_exit.mp3"), | |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
46 | "data_error": os.path.abspath(SOUNDPREFIX + "sound/data_error.mp3"), |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
47 | "panic": os.path.abspath(SOUNDPREFIX + "sound/panic.mp3"), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
48 | "panic_shortcut": os.path.abspath(SOUNDPREFIX + "sound/panic_shortcut.mp3"), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
49 | "resume": os.path.abspath(SOUNDPREFIX + "sound/resume.mp3"), |
95 | 50 | "win": os.path.abspath(SOUNDPREFIX + "sound/win.mp3"), |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
51 | |
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
52 | } |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
53 | |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
54 | def trigger_sound(what): |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
55 | if what in SOUNDS: |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
56 | Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]]) |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
57 | #os.spawnlp(os.P_NOWAIT, "/usr/bin/mpg123", "mpg123", SOUNDS[what]) |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
58 | #Popen(["/usr/bin/mpg123", SOUNDS[what]]).pid |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
59 | |
112
fee43a74bed6
added controller number to event scripts parameter 1
Malte Bayer <mbayer@neo-soft.org>
parents:
111
diff
changeset
|
60 | def trigger_event(what, slot = 0): |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
61 | trigger_sound(what) |
112
fee43a74bed6
added controller number to event scripts parameter 1
Malte Bayer <mbayer@neo-soft.org>
parents:
111
diff
changeset
|
62 | Popen(["/bin/sh", os.path.abspath(EVENTPREFIX + what), str(slot)]) |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
63 | |
110
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
64 | class SlotServer(threading.Thread): |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
65 | def __init__(self, blackbox): |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
66 | threading.Thread.__init__(self) |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
67 | self.server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000)) |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
68 | self.server.register_instance(blackbox) |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
69 | #self.server.register_function(lambda astr: '_' + astr, '_string') |
111 | 70 | self.daemon = True |
110
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
71 | |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
72 | def run(self): |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
73 | self.server.serve_forever() |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
74 | |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
75 | class SlotClient(): |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
76 | def __init__(self, url): |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
77 | self.box = xmlrpclib.Server(url) |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
78 | |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
79 | class SlotCli(): |
106 | 80 | def __init__(self, test = None, dev=""): |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
81 | self.box = Blackbox() |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
82 | self.nofuel = False |
124
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
83 | self.pitfinish = False |
110
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
84 | if (not test): |
106 | 85 | self.box.connect(dev) |
110
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
86 | self.rpcserver = SlotServer(self.box) |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
87 | self.rpcserver.start() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
88 | self.slot_dummy = { |
115 | 89 | "name": "uninitialized", |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
90 | "laps": 0, |
95 | 91 | "laps_last": 0, |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
92 | "last": 0.00, |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
93 | "best": 0.00, |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
94 | "fuel": 0, |
81 | 95 | "fuel_last": 0, |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
96 | "position": 0, |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
97 | "drive": 0, |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
98 | "status": "Idle", |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
99 | "clk": 0, |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
100 | "car": 0, |
95 | 101 | "limit": 15, |
115 | 102 | "profilename": "default", |
103 | "profile": ConfigParser.RawConfigParser(), | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
104 | } |
115 | 105 | self.slot_dummy["profile"].read("profiles/" + self.slot_dummy["profilename"]) |
106 | self.slot_dummy["name"] = self.slot_dummy["profile"].get("Settings", "Name") | |
107 | self.slot_dummy["limit"] = self.slot_dummy["profile"].getint("Settings", "Limit") | |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
108 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
109 | self.slot = [ |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
110 | copy(self.slot_dummy), copy(self.slot_dummy), |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
111 | copy(self.slot_dummy), copy(self.slot_dummy), |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
112 | copy(self.slot_dummy), copy(self.slot_dummy), |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
113 | ] |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
114 | self.reset_slots() |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
115 | self.sysclk = 0.00 |
96
bcba10c35f09
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
95
diff
changeset
|
116 | self.sysclk_last = 0.00 |
117
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
117 | self.bestlap = 9999999.00 # best lap time |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
118 | self.test = test |
117
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
119 | self.laplimit = 999 # race laplimit |
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
120 | self.timelimit = 0 # race timelimit |
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
121 | self.firstpos = -1 # first position slot |
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
122 | self.freerun = True # freerun mode = sort order by best lap |
137
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
123 | self.raceName = "Freestyle" |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
124 | self.log = eventLogger("events.log") |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
125 | |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
126 | def reset_slots(self): |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
127 | idx = 0 |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
128 | for slt in self.slot: |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
129 | slt["laps"] = 0 |
95 | 130 | slt["laps_last"] = 0 |
122 | 131 | slt["last"] = 999.00 |
121 | 132 | slt["best"] = 999.00 |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
133 | slt["fuel"] = 100 |
81 | 134 | slt["fuel_last"] = 0 |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
135 | slt["position"] = idx |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
136 | slt["car"] = idx # used for sort order calculation |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
137 | slt["status"] = self.slot_dummy["status"] |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
138 | slt["clk"] = 0 |
115 | 139 | slt["limit"] = slt["profile"].getint("Settings", "Limit") |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
140 | idx += 1 |
82 | 141 | self.bestlap = 99999.00 |
97 | 142 | self.raceactive = False |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
143 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
144 | def update_positions(self): |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
145 | order1 = sorted(self.slot, key=itemgetter( |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
146 | "clk")) |
117
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
147 | if self.freerun: |
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
148 | order2 = sorted(self.slot, key=itemgetter( |
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
149 | "best")) |
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
150 | else: |
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
151 | order2 = sorted(self.slot, key=itemgetter( |
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
152 | "laps"), reverse=True) |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
153 | idx = 1 |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
154 | for tst in order2: |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
155 | self.slot[tst["car"]]["position"] = idx |
117
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
156 | # check if first position changed |
120 | 157 | if (self.firstpos != tst["car"]) and (idx == 1): |
117
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
158 | self.firstpos = tst["car"] |
534e5c4b82c3
added trigger for new first position
Malte Bayer <mbayer@neo-soft.org>
parents:
116
diff
changeset
|
159 | trigger_event("first_position", tst["car"] + 1) |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
160 | idx += 1 |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
161 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
162 | def render_slots(self): |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
163 | self.update_positions() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
164 | self.scr.addstr(3,0, |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
165 | #"Pos | #/Name | Laps | Best | Last | Fuel | Status ", |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
166 | "Pos | #/Name ", |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
167 | curses.color_pair(2)) |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
168 | self.scr.addstr(4,4, |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
169 | " Laps | Best | Last | Fuel | Status ", |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
170 | curses.color_pair(2)) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
171 | for idx in range(MAXSLOTS): |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
172 | """ |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
173 | self.scr.addstr((3 + (self.slot[idx]["position"] * 2)), 0, |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
174 | "%3i | %i %15s | %4i | %7.2fs | %7.2fs | %3i%% | %10s" % ( |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
175 | self.slot[idx]["position"], |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
176 | self.slot[idx]["car"] + 1, self.slot[idx]["name"], |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
177 | self.slot[idx]["laps"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
178 | self.slot[idx]["best"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
179 | self.slot[idx]["last"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
180 | self.slot[idx]["fuel"], |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
181 | self.slot[idx]["status"], |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
182 | ), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
183 | curses.color_pair(11 + idx) ) |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
184 | """ |
102
72f5eb420096
added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents:
101
diff
changeset
|
185 | if idx > 3: |
72f5eb420096
added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents:
101
diff
changeset
|
186 | namesuffix = " (%i)" % self.slot[idx]["drive"] |
72f5eb420096
added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents:
101
diff
changeset
|
187 | else: |
72f5eb420096
added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents:
101
diff
changeset
|
188 | namesuffix = "" |
72f5eb420096
added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents:
101
diff
changeset
|
189 | |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
190 | self.scr.addstr((3 + (self.slot[idx]["position"] * 2)), 0, |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
191 | "%3i | %i %15s %48s" % ( |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
192 | self.slot[idx]["position"], |
102
72f5eb420096
added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents:
101
diff
changeset
|
193 | self.slot[idx]["car"] + 1, (self.slot[idx]["name"] + namesuffix), |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
194 | "", |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
195 | ), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
196 | curses.color_pair(11 + idx) ) |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
197 | self.scr.addstr((4 + (self.slot[idx]["position"] * 2)), 4, |
95 | 198 | " %4i | %7.2fs | %7.2fs | %3i%% | %10s | %2i% 15s" % ( |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
199 | self.slot[idx]["laps"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
200 | self.slot[idx]["best"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
201 | self.slot[idx]["last"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
202 | self.slot[idx]["fuel"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
203 | self.slot[idx]["status"], |
95 | 204 | self.slot[idx]["limit"], |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
205 | "" |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
206 | ), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
207 | curses.color_pair(11 + idx) ) |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
208 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
209 | def cleartop(self): |
95 | 210 | self.scr.addstr(0,0, "%60s" % "Race Limits: %i Laps / %i Minutes" % (self.laplimit, self.timelimit)) |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
211 | self.scr.addstr(1,0, "%80s" % " ") |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
212 | |
115 | 213 | def flash_car_settings(self, slot): |
214 | # write current settings to car firmware | |
215 | self.box.setmode(0) | |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
216 | self.scr.addstr(1,0, "%70s" % "Writing settings for %s to car %i, PLEASE WAIT... " % ( |
115 | 217 | self.slot[slot]["name"], |
218 | slot + 1), | |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
219 | curses.color_pair(9)) |
115 | 220 | self.scr.refresh() |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
221 | if not self.nofuel: |
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
222 | self.box.progcar(slot, "fuel", 0) |
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
223 | sleep(0.5) |
115 | 224 | self.box.progcar(slot, "accel", self.slot[slot]["profile"].getint("Settings", "Accel")) |
225 | sleep(0.5) | |
226 | self.box.progcar(slot, "brake", self.slot[slot]["profile"].getint("Settings", "Brake")) | |
227 | sleep(0.5) | |
228 | self.box.speedlimit(slot, self.slot[slot]["limit"]) | |
229 | sleep(0.5) | |
146
a1eb2dc83819
fixed unlimited fuel set bug
Malte Bayer <mbayer@neo-soft.org>
parents:
143
diff
changeset
|
230 | if self.slot[slot]["profile"].getint("Settings", "Fuel") == 0: |
a1eb2dc83819
fixed unlimited fuel set bug
Malte Bayer <mbayer@neo-soft.org>
parents:
143
diff
changeset
|
231 | self.box.unlimitedfuel(slot, True) |
a1eb2dc83819
fixed unlimited fuel set bug
Malte Bayer <mbayer@neo-soft.org>
parents:
143
diff
changeset
|
232 | else: |
a1eb2dc83819
fixed unlimited fuel set bug
Malte Bayer <mbayer@neo-soft.org>
parents:
143
diff
changeset
|
233 | self.box.unlimitedfuel(slot, False) |
143
cb514887cf17
added unlimited fuel for profile (set fuel=0 to enable)
Malte Bayer <mbayer@neo-soft.org>
parents:
139
diff
changeset
|
234 | sleep(0.5) |
115 | 235 | self.cleartop() |
236 | self.box.setmode(1) | |
237 | ||
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
238 | def readName(self, slot): |
56
a20f59a3016c
ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents:
55
diff
changeset
|
239 | self.scr.nodelay(0) # enable delay on readkey |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
240 | curses.echo() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
241 | self.scr.addstr(0,0, "Enter Name for Controller %i [%s]:" % ( |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
242 | slot + 1, |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
243 | self.slot[slot]["name"]), |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
244 | curses.color_pair(1)) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
245 | self.scr.refresh() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
246 | name = self.scr.getstr(1,0, 15) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
247 | if name != "": |
115 | 248 | # look if profile with that name found |
249 | try: | |
250 | with open("profiles/" + name) as f: pass | |
251 | self.slot[slot]["profilename"] = name | |
252 | self.slot[slot]["profile"].read("profiles/" + name) | |
253 | self.slot[slot]["name"] = self.slot[slot]["profile"].get("Settings", "Name") | |
254 | self.slot[slot]["limit"] = self.slot[slot]["profile"].getint("Settings", "Limit") | |
255 | self.flash_car_settings(slot) | |
256 | except IOError, err: | |
143
cb514887cf17
added unlimited fuel for profile (set fuel=0 to enable)
Malte Bayer <mbayer@neo-soft.org>
parents:
139
diff
changeset
|
257 | # load default profile |
115 | 258 | self.slot[slot]["profilename"] = "default" |
259 | self.slot[slot]["profile"].read("profiles/default") | |
260 | self.slot[slot]["limit"] = self.slot[slot]["profile"].getint("Settings", "Limit") | |
261 | self.slot[slot]["name"] = name | |
262 | self.flash_car_settings(slot) | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
263 | self.cleartop() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
264 | self.scr.refresh() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
265 | curses.noecho() |
56
a20f59a3016c
ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents:
55
diff
changeset
|
266 | self.scr.nodelay(1) # disable delay on readkey |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
267 | |
137
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
268 | def readRaceName(self): |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
269 | self.scr.nodelay(0) # enable delay on readkey |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
270 | curses.echo() |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
271 | self.scr.addstr(0,0, "Enter Race Name [%s]:" % ( |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
272 | self.raceName), |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
273 | curses.color_pair(1)) |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
274 | self.scr.refresh() |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
275 | name = self.scr.getstr(1,0, 15) |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
276 | if name != "": |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
277 | self.raceName = name |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
278 | self.cleartop() |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
279 | self.scr.refresh() |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
280 | curses.noecho() |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
281 | self.scr.nodelay(1) # disable delay on readkey |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
282 | |
95 | 283 | def readLimit(self, slot): |
284 | limit = self.readInt("SPEEDLIMIT for %s (%i)" % ( | |
285 | self.slot[slot]["name"], | |
286 | slot + 1), | |
287 | self.slot[slot]["limit"], 15) | |
288 | if limit: | |
289 | self.slot[slot]["limit"] = limit | |
290 | self.cleartop() | |
291 | self.box.speedlimit(slot, limit) | |
292 | ||
293 | ||
294 | def readInt(self, msg, default, maximum = 999999): | |
94
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
295 | self.scr.nodelay(0) # enable delay on readkey |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
296 | curses.echo() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
297 | self.scr.addstr(0,0, "%s [%i]:" % ( |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
298 | msg, |
95 | 299 | default), |
94
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
300 | curses.color_pair(1)) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
301 | self.scr.refresh() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
302 | inp = self.scr.getstr(1,0, 4) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
303 | if inp != "": |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
304 | try: |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
305 | inp = int(inp) |
95 | 306 | if inp > maximum: inp = maximum |
94
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
307 | except Exception: |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
308 | inp = None |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
309 | else: |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
310 | inp = None |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
311 | self.cleartop() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
312 | self.scr.refresh() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
313 | curses.noecho() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
314 | self.scr.nodelay(1) # disable delay on readkey |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
315 | return inp |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
316 | |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
317 | |
103
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
318 | def monitor_init(self, live = 1): |
74
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
319 | """ |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
320 | Send initializing commands for live monitoring |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
321 | """ |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
322 | if self.nofuel: |
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
323 | #print cli.box.fueldivisor(0) |
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
324 | self.box.query("F0\n") # set fuel logic disabled |
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
325 | else: |
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
326 | #print cli.box.fueldivisor(25) |
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
327 | self.box.query("F1\n") # set fuel logic enabled |
124
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
328 | |
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
329 | if self.pitfinish: |
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
330 | self.box.query("X1\n") # set pitlane finish function |
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
331 | else: |
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
332 | #print cli.box.fueldivisor(25) |
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
333 | self.box.query("X0\n") |
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
334 | |
103
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
335 | self.box.query("*%i\n" % live) # set live fuel info |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
336 | |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
337 | def monitor_learn(self, slot): |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
338 | # clear garbage in UART rx buffer |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
339 | self.box.query("*0\n") # set live fuel info |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
340 | self.box.query("*0\n") # set live fuel info |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
341 | while self.box.readline() != "": pass |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
342 | |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
343 | trk = False |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
344 | spd = 0 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
345 | trk_old = False |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
346 | spd_old = 0 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
347 | clock = -1 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
348 | |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
349 | self.monitor_init(slot + 2) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
350 | while 1: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
351 | #key = self.scr.getch() |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
352 | #if key == ord('c'): break |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
353 | |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
354 | # is there something in the rx buffer? |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
355 | rx = self.box.readline() |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
356 | if (rx != ""): |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
357 | try: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
358 | data = rx.split(":") |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
359 | if rx[:3] == "LN:": |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
360 | if clock >= 0: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
361 | clock += 1 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
362 | spd = int(data[1], 16) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
363 | trk = (data[2] != 'X') |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
364 | if (spd != spd_old) or (trk != trk_old): |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
365 | if clock < 0: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
366 | clock = 0 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
367 | print "%i,%i,%s" % (clock, spd, trk) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
368 | trk_old = trk |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
369 | spd_old = spd * 1 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
370 | if rx[:2] == "L:": |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
371 | # update lap time info |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
372 | l = int(data[2], 16) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
373 | s = int(data[3]) - 1 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
374 | t = int(data[4], 16) / 2000.00 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
375 | if (slot == s): |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
376 | print "# lap %i complete: %3.2f seconds" % (l, t) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
377 | clock = 0 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
378 | print "%i,%i,%s" % (clock, spd, trk) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
379 | except: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
380 | print "RX ERROR: " % rx |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
381 | |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
382 | def monitor_playback(self, slot, filename): |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
383 | # clear garbage in UART rx buffer |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
384 | self.box.query("*0\n") # set live fuel info |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
385 | self.box.query("*0\n") # set live fuel info |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
386 | sleep(1) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
387 | cli.box.speedminimum(slot, 0 ) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
388 | while self.box.readline() != "": pass |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
389 | |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
390 | clock = -5 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
391 | trkfile = open(filename, "r").readlines() |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
392 | print "Loading %s..." % filename |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
393 | |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
394 | while 1: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
395 | try: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
396 | for l in trkfile: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
397 | l = l.strip() |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
398 | if (l != "") and (l[:1] != "#"): |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
399 | print "Line: %s" % repr(l) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
400 | data = l.split(",") |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
401 | speed = int(data[1]) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
402 | while (clock < int(data[0]) and (int(data[0]) > 0)): |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
403 | clock += 1 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
404 | sleep(0.07) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
405 | print "CLK %i/%i -> set: %i" % (clock, int(data[0]), speed) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
406 | cli.box.speedminimum(slot, speed ) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
407 | # now wait for lap sync :) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
408 | while self.box.readline() != "": pass |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
409 | rx = "" |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
410 | while rx[:2] != "L:": |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
411 | rx = self.box.readline() |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
412 | data = rx.split(":") |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
413 | l = int(data[2], 16) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
414 | s = int(data[3]) - 1 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
415 | t = int(data[4], 16) / 2000.00 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
416 | print "# lap %i complete: %3.2f seconds" % (l, t) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
417 | clock = -3 |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
418 | except Exception, e: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
419 | print repr(e) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
420 | sys.exit(1) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
421 | except KeyboardInterrupt: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
422 | print "resetting" |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
423 | cli.box.speedminimum(slot, 0 ) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
424 | cli.box.speedminimum(slot, 0 ) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
425 | sys.exit(0) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
426 | |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
427 | |
74
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
428 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
429 | def monitor(self): |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
430 | """ |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
431 | Live Monitor on the console |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
432 | Keyboard loop to control it??? |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
433 | """ |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
434 | # clear garbage in UART rx buffer |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
435 | while self.box.readline() != "": pass |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
436 | |
74
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
437 | self.monitor_init() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
438 | self.scr = curses.initscr() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
439 | curses.start_color() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
440 | curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK) # standard text |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
441 | curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE) # label |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
442 | curses.init_pair(9, curses.COLOR_WHITE, curses.COLOR_RED) # ATTENTION |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
443 | curses.init_pair(11, curses.COLOR_BLACK, curses.COLOR_YELLOW) # player 1 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
444 | curses.init_pair(12, curses.COLOR_BLACK, curses.COLOR_GREEN) # player 2 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
445 | curses.init_pair(13, curses.COLOR_BLACK, curses.COLOR_RED) # player 3 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
446 | curses.init_pair(14, curses.COLOR_BLACK, curses.COLOR_MAGENTA) # player 4 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
447 | curses.init_pair(15, curses.COLOR_WHITE, curses.COLOR_BLACK) # player 5 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
448 | curses.init_pair(16, curses.COLOR_WHITE, curses.COLOR_BLACK) # player 6 slot |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
449 | curses.noecho() # disable key echo |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
450 | curses.cbreak() # do not buffer keypresses |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
451 | self.scr.keypad(1) # enable special keys |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
452 | self.scr.nodelay(1) # disable delay on readkey |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
453 | |
59
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
454 | self.cleartop() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
455 | self.render_slots() |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
456 | self.scr.refresh() |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
457 | |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
458 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
459 | while 1: |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
460 | key = self.scr.getch() |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
461 | if key == ord('q'): break |
89
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
462 | elif key == ord(' '): self.box.query("+") # panic / resume |
118
9d5456cf6dad
new hotkey 'f' to toggle freerun mode
Malte Bayer <mbayer@neo-soft.org>
parents:
117
diff
changeset
|
463 | elif key == 10: |
9d5456cf6dad
new hotkey 'f' to toggle freerun mode
Malte Bayer <mbayer@neo-soft.org>
parents:
117
diff
changeset
|
464 | self.freerun = False |
9d5456cf6dad
new hotkey 'f' to toggle freerun mode
Malte Bayer <mbayer@neo-soft.org>
parents:
117
diff
changeset
|
465 | self.box.query("#") # remote start button press |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
466 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
467 | elif key == ord('1'): self.readName(0) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
468 | elif key == ord('2'): self.readName(1) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
469 | elif key == ord('3'): self.readName(2) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
470 | elif key == ord('4'): self.readName(3) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
471 | elif key == ord('5'): self.readName(4) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
472 | elif key == ord('6'): self.readName(5) |
115 | 473 | #elif key == ord('q'): self.readLimit(0) |
474 | #elif key == ord('w'): self.readLimit(1) | |
475 | #elif key == ord('e'): self.readLimit(2) | |
476 | #elif key == ord('r'): self.readLimit(3) | |
477 | #elif key == ord('t'): self.readLimit(4) | |
478 | #elif key == ord('z'): self.readLimit(5) | |
137
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
479 | elif key == ord('n'): self.readRaceName() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
480 | elif key == ord('a'): |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
481 | if self.slot[4]["drive"] > 0: self.slot[4]["drive"] -= 1 |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
482 | cli.box.speedminimum(4, self.slot[4]["drive"]) |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
483 | elif key == ord('s'): |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
484 | if self.slot[4]["drive"] < 16: self.slot[4]["drive"] += 1 |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
485 | cli.box.speedminimum(4, self.slot[4]["drive"]) |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
486 | elif key == ord('y'): |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
487 | if self.slot[5]["drive"] > 0: self.slot[5]["drive"] -= 1 |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
488 | cli.box.speedminimum(5, self.slot[5]["drive"]) |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
489 | elif key == ord('x'): |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
490 | if self.slot[5]["drive"] < 16: self.slot[5]["drive"] += 1 |
113 | 491 | cli.box.speedminimum(5, self.slot[5]["drive"]) |
94
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
492 | elif key == ord('t'): |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
493 | tmp = self.readInt("Set new Race TIME limit", self.timelimit) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
494 | if tmp: self.timelimit = tmp |
115 | 495 | self.cleartop() |
94
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
496 | elif key == ord('l'): |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
497 | tmp = self.readInt("Set new Race LAP limit", self.laplimit) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
498 | if tmp: self.laplimit = tmp |
115 | 499 | self.cleartop() |
500 | elif key == ord('/'): | |
501 | for slot in range(5): | |
502 | self.flash_car_settings(slot) | |
118
9d5456cf6dad
new hotkey 'f' to toggle freerun mode
Malte Bayer <mbayer@neo-soft.org>
parents:
117
diff
changeset
|
503 | elif key == ord('f'): |
9d5456cf6dad
new hotkey 'f' to toggle freerun mode
Malte Bayer <mbayer@neo-soft.org>
parents:
117
diff
changeset
|
504 | # set freerun mode manually (abort race) |
9d5456cf6dad
new hotkey 'f' to toggle freerun mode
Malte Bayer <mbayer@neo-soft.org>
parents:
117
diff
changeset
|
505 | self.freerun = not self.freerun |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
506 | |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
507 | |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
508 | # is there something in the rx buffer? |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
509 | rx = self.box.readline() |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
510 | if (rx != "") or self.test: |
123
ec623e5fcbca
firmware fix: only fuel to 100% once in pitlane
Malte Bayer <mbayer@neo-soft.org>
parents:
122
diff
changeset
|
511 | self.scr.addstr(17,3, |
ec623e5fcbca
firmware fix: only fuel to 100% once in pitlane
Malte Bayer <mbayer@neo-soft.org>
parents:
122
diff
changeset
|
512 | "RX: %19s" % rx, curses.color_pair(2)) |
99 | 513 | self.scr.redrawwin() |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
514 | self.scr.refresh() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
515 | # we have received something |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
516 | try: |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
517 | data = rx.split(":") |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
518 | if rx[:2] == "L:": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
519 | # update lap time info |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
520 | l = int(data[2], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
521 | slot = int(data[3]) - 1 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
522 | t = int(data[4], 16) / 2000.00 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
523 | self.sysclk = int(data[5], 16) / 2000.00 |
95 | 524 | self.slot[slot]["laps_last"] = self.slot[slot]["laps"] |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
525 | self.slot[slot]["laps"] = l |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
526 | self.slot[slot]["last"] = t |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
527 | self.slot[slot]["clk"] = self.sysclk |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
528 | if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
529 | self.slot[slot]["best"] = t |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
530 | if self.bestlap > t: |
120 | 531 | if self.freerun: |
532 | trigger_event("lap_record", slot + 1) | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
533 | self.bestlap = t |
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
534 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
535 | self.slot[slot]["status"] = "IN-RACE" |
95 | 536 | if (self.slot[slot]["laps_last"] != l) and (l == self.laplimit): |
537 | # we have lap limit reached! | |
112
fee43a74bed6
added controller number to event scripts parameter 1
Malte Bayer <mbayer@neo-soft.org>
parents:
111
diff
changeset
|
538 | trigger_event("win", slot + 1) |
97 | 539 | self.raceactive = False |
95 | 540 | self.slot[slot]["status"] = "WINNER!" |
541 | self.box.query("+") # stop race | |
542 | ||
137
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
543 | tmpname = "n/a" |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
544 | if not self.freerun: |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
545 | tmpname = self.raceName |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
546 | self.log.push([ |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
547 | time(), |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
548 | self.sysclk, |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
549 | tmpname, |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
550 | slot, |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
551 | self.slot[slot]["name"], |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
552 | l, |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
553 | t, |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
554 | self.slot[slot]["best"], |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
555 | self.laplimit, |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
556 | self.timelimit |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
557 | ]) |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
558 | |
94d71156517b
added textfile event logger
Malte Bayer <mbayer@neo-soft.org>
parents:
124
diff
changeset
|
559 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
560 | self.render_slots() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
561 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
562 | if rx[:2] == "F:": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
563 | # update fuel level |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
564 | slot = int(data[1]) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
565 | f = int(data[2], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
566 | f = f / 100 # fuel in percent |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
567 | self.sysclk = int(data[3], 16) / 2000.00 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
568 | self.slot[slot]["fuel_last"] = self.slot[slot]["fuel"] |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
569 | self.slot[slot]["fuel"] = f |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
570 | if self.slot[slot]["fuel_last"] != f: |
97 | 571 | if (self.slot[slot]["fuel_last"] == 16) and (f == 15): |
572 | # 15 percent fuel, set speed limit for car to 8 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
573 | # warning sound |
112
fee43a74bed6
added controller number to event scripts parameter 1
Malte Bayer <mbayer@neo-soft.org>
parents:
111
diff
changeset
|
574 | trigger_event("fuel_warning1", slot + 1) |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
575 | cli.box.speedlimit(slot, 8) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
576 | if (self.slot[slot]["fuel_last"] == 6) and (f == 5): |
97 | 577 | # 5 percent, set speed limit for car to 6 |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
578 | # warning sound |
112
fee43a74bed6
added controller number to event scripts parameter 1
Malte Bayer <mbayer@neo-soft.org>
parents:
111
diff
changeset
|
579 | trigger_event("fuel_warning2", slot + 1) |
97 | 580 | cli.box.speedlimit(slot, 6) |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
581 | if (self.slot[slot]["fuel_last"] == 1) and (f == 0): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
582 | # fuel empty |
97 | 583 | # set speedlimit to 4 |
584 | cli.box.speedlimit(slot, 4) | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
585 | if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
586 | cli.box.speedlimit(slot, 15) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
587 | if (self.slot[slot]["fuel_last"] < f) and (f == 100): |
112
fee43a74bed6
added controller number to event scripts parameter 1
Malte Bayer <mbayer@neo-soft.org>
parents:
111
diff
changeset
|
588 | trigger_event("fuel_full", slot + 1) |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
589 | self.render_slots() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
590 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
591 | if rx[:1] == "~": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
592 | # jumpstart occured |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
593 | slot = int(rx[1:2]) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
594 | t = int(data[1], 16) / 2000.00 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
595 | self.slot[slot]["jumpstart"] = t |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
596 | self.slot[slot]["status"] = "Jumpstart!" |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
597 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
598 | if rx[:3] == "RW:": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
599 | # ResponseWire packet, do nothing at the moment, just decode |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
600 | slot = int(data[1]) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
601 | devtype = int(data[2]) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
602 | sender = int(data[3], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
603 | status = int(data[4], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
604 | self.sysclk = int(data[5], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
605 | if (devtype == 4): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
606 | # pitlane sent something |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
607 | if (status == 5): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
608 | self.slot[slot]["status"] = "PITLANE" |
112
fee43a74bed6
added controller number to event scripts parameter 1
Malte Bayer <mbayer@neo-soft.org>
parents:
111
diff
changeset
|
609 | trigger_event("pitlane_enter", slot + 1) |
104
95b2c23cb973
pitlane checkout bug resolved, prepare for customized pitlane speedlimit
Malte Bayer <mbayer@neo-soft.org>
parents:
103
diff
changeset
|
610 | if (status == 7): |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
611 | self.slot[slot]["status"] = "IN-RACE" |
112
fee43a74bed6
added controller number to event scripts parameter 1
Malte Bayer <mbayer@neo-soft.org>
parents:
111
diff
changeset
|
612 | trigger_event("pitlane_exit", slot + 1) |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
613 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
614 | self.render_slots() |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
615 | |
139
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
616 | if rx == "!PRE": |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
617 | # reset current race status |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
618 | # and display PREPARE PHASE |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
619 | self.reset_slots() |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
620 | for slot in range(MAXSLOTS): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
621 | self.slot[slot]["status"] = "Prepare" |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
622 | trigger_event("race_prepare") |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
623 | |
139
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
624 | if rx == "!GO": |
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
625 | # race start! |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
626 | for slot in range(MAXSLOTS): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
627 | if self.slot[slot]["status"] == "~~~~~~~~~~": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
628 | self.slot[slot]["status"] = "Idle" |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
629 | trigger_event("race_start") |
97 | 630 | self.raceactive = True |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
631 | |
139
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
632 | if rx == "!SET": |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
633 | # countdown initiated |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
634 | for slot in range(MAXSLOTS): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
635 | self.slot[slot]["status"] = "~~~~~~~~~~" |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
636 | trigger_event("countdown_start") |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
637 | |
139
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
638 | if rx == "!STOP": |
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
639 | # panic mode, race stopped |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
640 | trigger_event("panic") |
89
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
641 | |
139
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
642 | if rx == "!OC": |
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
643 | # panic mode, overcurrent |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
644 | trigger_event("panic_shortcut") |
89
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
645 | |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
646 | if rx == "!RESUME": |
139
7127e7082ee0
switched firmware to binary protocol, TODO: client implementation
Malte Bayer <mbayer@neo-soft.org>
parents:
137
diff
changeset
|
647 | # panic mode reset - race goes on normally |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
648 | trigger_event("resume") |
89
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
649 | |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
650 | |
97 | 651 | if ((self.timelimit > 0) and (self.raceactive) and |
652 | (self.sysclk_last != self.sysclk) and | |
653 | ((self.sysclk / 60) >= self.timelimit)): | |
96
bcba10c35f09
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
95
diff
changeset
|
654 | self.sysclk_last = self.sysclk |
97 | 655 | self.raceactive = False |
96
bcba10c35f09
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
95
diff
changeset
|
656 | # we have time limit reached! |
97 | 657 | self.box.query("+") # stop race |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
658 | trigger_event("win") |
96
bcba10c35f09
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
95
diff
changeset
|
659 | # get the one with position 1 |
bcba10c35f09
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
95
diff
changeset
|
660 | for slot in self.slots: |
bcba10c35f09
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
95
diff
changeset
|
661 | if slot["position"] == 1: |
bcba10c35f09
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
95
diff
changeset
|
662 | slot["status"] = "WINNER!" |
120 | 663 | self.render_slots() |
96
bcba10c35f09
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
95
diff
changeset
|
664 | self.sysclk_last = self.sysclk |
120 | 665 | |
95 | 666 | |
89
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
667 | |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
668 | self.scr.addstr(17,31, |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
669 | "Race Timer: %7.3f min" % (self.sysclk / 60), |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
670 | curses.color_pair(2)) |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
671 | |
120 | 672 | tmpmode = "RACE MODE (LAPS)" |
673 | if self.freerun: | |
674 | tmpmode = "FREERUN (BEST)" | |
675 | self.scr.addstr(18,31, | |
676 | "%19s" % tmpmode, curses.color_pair(2)) | |
677 | ||
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
678 | self.scr.refresh() |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
679 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
680 | except Exception: |
107
efdf471642f5
added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents:
106
diff
changeset
|
681 | trigger_event("data_error") |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
682 | pass |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
683 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
684 | # terminate |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
685 | curses.nocbreak() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
686 | self.scr.keypad(0) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
687 | curses.echo() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
688 | curses.endwin() |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
689 | return None |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
690 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
691 | def cyclemode(self): |
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
692 | pass |
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
693 | |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
694 | if __name__ == "__main__": |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
695 | parser = OptionParser(version="%prog " + VERSION) |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
696 | parser.add_option("--live", dest="live", action="store_true", default=False, |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
697 | help="Run Live monitor on console", metavar="[0-5]") |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
698 | parser.add_option("--nofuel", dest="nofuel", action="store_true", default=False, |
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
699 | help="Disable Freeslot fuel management", metavar="[0-5]") |
124
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
700 | parser.add_option("--pit", dest="pitfinish", action="store_true", default=False, |
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
701 | help="Pitlane entry acts as finish line too", metavar="[0-5]") |
103
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
702 | parser.add_option("--learn", dest="learn", action="store_true", default=False, |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
703 | help="Run Learning mode for [slot]", metavar="[0-5]") |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
704 | parser.add_option("--teach", dest="playback", |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
705 | help="Playback teach file", metavar="[filename]") |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
706 | |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
707 | parser.add_option("--slot", dest="carid", |
101
92d204c738e1
changed --slot parameter to 1..6 instead of 0..5
Malte Bayer <mbayer@neo-soft.org>
parents:
100
diff
changeset
|
708 | help="Required for programming a car directly", metavar="[1-6]") |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
709 | parser.add_option("--fuel", dest="fuel", |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
710 | help="Set maximum CAR fuel level", metavar="[0-15]") |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
711 | parser.add_option("--brake", dest="brake", |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
712 | help="Set CAR brake strength", metavar="[0-15]") |
100
039ab094f79b
renamed --speed to --accel and added minimum value 6
Malte Bayer <mbayer@neo-soft.org>
parents:
99
diff
changeset
|
713 | parser.add_option("--accel", dest="accel", |
039ab094f79b
renamed --speed to --accel and added minimum value 6
Malte Bayer <mbayer@neo-soft.org>
parents:
99
diff
changeset
|
714 | help="Set CAR acceleration ", metavar="[6-15]") |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
715 | parser.add_option("--blink", dest="blink", |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
716 | help="Set car lights blinking state", metavar="[on|off]") |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
717 | parser.add_option("--limit", dest="limit", |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
718 | help="Controlled SPEED LIMIT (15 = no limit)", metavar="[0-15]") |
50
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
719 | parser.add_option("--drive", dest="drive", |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
720 | help="Controlled SPEED MINIMUM (0 = disabled)", metavar="[0-15]") |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
721 | parser.add_option("--test", dest="test", action="store_true", default=False, |
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
722 | help="", metavar="") |
106 | 723 | parser.add_option("--dev", dest="dev", default="/dev/ttyUSB0", |
724 | help="Communication port", metavar="[/dev/ttyUSB0]") | |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
725 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
726 | (options, args) = parser.parse_args() |
106 | 727 | #if not options.dev: |
728 | # options.dev = "/dev/ttyUSB0" | |
110
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
729 | |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
730 | if options.live or options.learn or options.playback: |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
731 | cli = SlotCli(options.test, options.dev) |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
732 | else: |
b0e4f4249351
added xmlrpc server to live viewer, cli functions communicate with server
Malte Bayer <mbayer@neo-soft.org>
parents:
109
diff
changeset
|
733 | cli = SlotClient('http://localhost:8000') |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
734 | # should a CLI function be started? |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
735 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
736 | if options.live: |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
737 | # start the live monitor |
116
c2fc650cc48f
added option to disable freeslot fuel logic
Malte Bayer <mbayer@neo-soft.org>
parents:
115
diff
changeset
|
738 | cli.nofuel = options.nofuel |
124
0b12a8bf23b2
new option to set pitlane entry as finish line too to increase laps
Malte Bayer <mbayer@neo-soft.org>
parents:
123
diff
changeset
|
739 | cli.pitfinish = options.pitfinish |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
740 | cli.monitor() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
741 | sys.exit(0) |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
742 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
743 | # check commandline if we have to program something |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
744 | if not options.carid: |
101
92d204c738e1
changed --slot parameter to 1..6 instead of 0..5
Malte Bayer <mbayer@neo-soft.org>
parents:
100
diff
changeset
|
745 | print "Option --slot is required for all car programming commands!\nUse --help to get a list of available commands" |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
746 | sys.exit(1) |
101
92d204c738e1
changed --slot parameter to 1..6 instead of 0..5
Malte Bayer <mbayer@neo-soft.org>
parents:
100
diff
changeset
|
747 | else: |
92d204c738e1
changed --slot parameter to 1..6 instead of 0..5
Malte Bayer <mbayer@neo-soft.org>
parents:
100
diff
changeset
|
748 | options.carid = int(options.carid) - 1 |
92d204c738e1
changed --slot parameter to 1..6 instead of 0..5
Malte Bayer <mbayer@neo-soft.org>
parents:
100
diff
changeset
|
749 | if (options.carid < 0) or (options.carid > 6): |
92d204c738e1
changed --slot parameter to 1..6 instead of 0..5
Malte Bayer <mbayer@neo-soft.org>
parents:
100
diff
changeset
|
750 | print "Error: Invalid slot selected" |
92d204c738e1
changed --slot parameter to 1..6 instead of 0..5
Malte Bayer <mbayer@neo-soft.org>
parents:
100
diff
changeset
|
751 | sys.exit(1) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
752 | |
103
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
753 | if options.learn: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
754 | # start the learn monitor |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
755 | cli.monitor_learn(options.carid) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
756 | sys.exit(0) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
757 | |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
758 | if options.playback: |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
759 | # start the playback monitor |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
760 | cli.monitor_playback(options.carid, options.playback) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
761 | sys.exit(0) |
52fd4283cd2c
added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents:
102
diff
changeset
|
762 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
763 | if options.fuel: |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
764 | print "setFuel: " + cli.box.progcar(int(options.carid), "fuel", int(options.fuel)) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
765 | |
100
039ab094f79b
renamed --speed to --accel and added minimum value 6
Malte Bayer <mbayer@neo-soft.org>
parents:
99
diff
changeset
|
766 | if options.accel: |
039ab094f79b
renamed --speed to --accel and added minimum value 6
Malte Bayer <mbayer@neo-soft.org>
parents:
99
diff
changeset
|
767 | print "setAccel: " + cli.box.progcar(int(options.carid), "accel", int(options.accel)) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
768 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
769 | if options.brake: |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
770 | print "setBrake: " + cli.box.progcar(int(options.carid), "brake", int(options.brake)) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
771 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
772 | if options.blink: |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
773 | state = False |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
774 | if options.blink == "on": |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
775 | state = True |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
776 | print "setBlink: " + cli.box.blinkcar(int(options.carid), state) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
777 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
778 | if options.limit: |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
779 | print "Change Speed Limit: " + cli.box.speedlimit(int(options.carid), int(options.limit)) |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
780 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
781 | if options.drive: |
50
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
782 | print "Change minimum Speed drive: " + cli.box.speedminimum(int(options.carid), int(options.drive)) |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
783 |