slotUI/SlotCli.py

Sun, 28 Oct 2012 18:46:03 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Sun, 28 Oct 2012 18:46:03 +0100
changeset 108
350d7b571ad9
parent 107
efdf471642f5
child 109
bb00e6994e5e
permissions
-rwxr-xr-x

typo

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
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
11 import sys, os
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
12 from copy import copy
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
13 import curses
103
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
14 from time import sleep
35
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
15
103
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
16 VERSION = "1.7"
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
17 MAXSLOTS = 6
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
18 TERM = {
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
19 "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
20 "text": "\033[1;30m",
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
21 }
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
22
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
23 # disable debug log output
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
24 LOGLEVEL = 10
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
25
81
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
26 SOUNDPREFIX = "quake-"
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
27 EVENTPREFIX = "event/"
78
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
28 SOUNDS = {
81
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
29 "countdown_start": os.path.abspath(SOUNDPREFIX + "sound/countdown.mp3"),
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
30 "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
31 "race_prepare": os.path.abspath(SOUNDPREFIX + "sound/prepare.mp3"),
81
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
32 "lap_record": os.path.abspath(SOUNDPREFIX + "sound/laprecord.mp3"),
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
33 "fuel_warning1": os.path.abspath(SOUNDPREFIX + "sound/fuel1.mp3"),
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
34 "fuel_warning2": os.path.abspath(SOUNDPREFIX + "sound/fuel2.mp3"),
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
35 "fuel_full": os.path.abspath(SOUNDPREFIX + "sound/fuel_full.mp3"),
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
36 "pitlane_enter": os.path.abspath(SOUNDPREFIX + "sound/pitlane_enter.mp3"),
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
37 "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
38 "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
39 "panic": os.path.abspath(SOUNDPREFIX + "sound/panic.mp3"),
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
40 "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
41 "resume": os.path.abspath(SOUNDPREFIX + "sound/resume.mp3"),
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
42 "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
43
78
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
44 }
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
45
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
46 def trigger_sound(what):
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
47 if what in SOUNDS:
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
48 Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]])
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
49 #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
50 #Popen(["/usr/bin/mpg123", SOUNDS[what]]).pid
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
51
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
52 def trigger_event(what):
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
53 trigger_sound(what)
108
Malte Bayer <mbayer@neo-soft.org>
parents: 107
diff changeset
54 Popen([os.path.abspath(EVENTPREFIX + what)])
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
55
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
56 class SlotCli():
106
11fabe1f7c40 added dev parameter
Malte Bayer <mbayer@neo-soft.org>
parents: 104
diff changeset
57 def __init__(self, test = None, dev=""):
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
58 self.box = Blackbox()
86
79fb119cf3c3 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 85
diff changeset
59 if not test:
106
11fabe1f7c40 added dev parameter
Malte Bayer <mbayer@neo-soft.org>
parents: 104
diff changeset
60 self.box.connect(dev)
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
61 self.slot_dummy = {
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
62 "name": "Unnamed",
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
63 "laps": 0,
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
64 "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
65 "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
66 "best": 0.00,
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
67 "fuel": 0,
81
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
68 "fuel_last": 0,
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
69 "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
70 "drive": 0,
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
71 "status": "Idle",
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
72 "clk": 0,
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
73 "car": 0,
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
74 "limit": 15,
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
75 }
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
76
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
77 self.slot = [
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
78 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
79 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
80 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
81 ]
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
82 self.reset_slots()
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
83 self.sysclk = 0.00
96
bcba10c35f09 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 95
diff changeset
84 self.sysclk_last = 0.00
78
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
85 self.bestlap = 9999999.00
87
761863c71884 added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents: 86
diff changeset
86 self.test = test
94
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
87 self.laplimit = 999;
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
88 self.timelimit = 0;
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
89
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
90 def reset_slots(self):
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
91 idx = 0
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
92 for slt in self.slot:
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
93 slt["laps"] = 0
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
94 slt["laps_last"] = 0
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
95 slt["last"] = 0.00
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
96 slt["best"] = 0.00
93
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
97 slt["fuel"] = 100
81
4f2f94a043fd betatest corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 78
diff changeset
98 slt["fuel_last"] = 0
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
99 slt["position"] = idx
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
100 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
101 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
102 slt["clk"] = 0
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
103 slt["limit"] = 15
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
104 idx += 1
82
c89221096db7 bugfixes
Malte Bayer <mbayer@neo-soft.org>
parents: 81
diff changeset
105 self.bestlap = 99999.00
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
106 self.raceactive = False
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
107
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
108 def update_positions(self):
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
109 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
110 "clk"))
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
111 order2 = sorted(self.slot, key=itemgetter(
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
112 "laps"), reverse=True)
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
113 idx = 1
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
114 for tst in order2:
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
115 self.slot[tst["car"]]["position"] = idx
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
116 idx += 1
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
117
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
118 def render_slots(self):
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
119 self.update_positions()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
120 self.scr.addstr(3,0,
93
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
121 #"Pos | #/Name | Laps | Best | Last | Fuel | Status ",
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
122 "Pos | #/Name ",
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
123 curses.color_pair(2))
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
124 self.scr.addstr(4,4,
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
125 " 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
126 curses.color_pair(2))
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
127 for idx in range(MAXSLOTS):
93
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
128 """
87
761863c71884 added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents: 86
diff changeset
129 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
130 "%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
131 self.slot[idx]["position"],
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
132 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
133 self.slot[idx]["laps"],
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
134 self.slot[idx]["best"],
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
135 self.slot[idx]["last"],
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
136 self.slot[idx]["fuel"],
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
137 self.slot[idx]["status"],
93
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
138 ),
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
139 curses.color_pair(11 + idx) )
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
140 """
102
72f5eb420096 added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents: 101
diff changeset
141 if idx > 3:
72f5eb420096 added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents: 101
diff changeset
142 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
143 else:
72f5eb420096 added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents: 101
diff changeset
144 namesuffix = ""
72f5eb420096 added drive speed display for virtual slots to live screen
Malte Bayer <mbayer@neo-soft.org>
parents: 101
diff changeset
145
93
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
146 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
147 "%3i | %i %15s %48s" % (
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
148 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
149 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
150 "",
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
151 ),
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
152 curses.color_pair(11 + idx) )
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
153 self.scr.addstr((4 + (self.slot[idx]["position"] * 2)), 4,
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
154 " %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
155 self.slot[idx]["laps"],
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
156 self.slot[idx]["best"],
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
157 self.slot[idx]["last"],
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
158 self.slot[idx]["fuel"],
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
159 self.slot[idx]["status"],
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
160 self.slot[idx]["limit"],
93
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
161 ""
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
162 ),
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
163 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
164
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
165 def cleartop(self):
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
166 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
167 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
168
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
169 def readName(self, slot):
56
a20f59a3016c ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents: 55
diff changeset
170 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
171 curses.echo()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
172 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
173 slot + 1,
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
174 self.slot[slot]["name"]),
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
175 curses.color_pair(1))
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
176 self.scr.refresh()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
177 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
178 if name != "":
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
179 self.slot[slot]["name"] = name
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
180 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
181 self.scr.refresh()
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
182 curses.noecho()
56
a20f59a3016c ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents: 55
diff changeset
183 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
184
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
185 def readLimit(self, slot):
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
186 limit = self.readInt("SPEEDLIMIT for %s (%i)" % (
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
187 self.slot[slot]["name"],
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
188 slot + 1),
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
189 self.slot[slot]["limit"], 15)
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
190 if limit:
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
191 self.slot[slot]["limit"] = limit
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
192 self.cleartop()
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
193 self.box.speedlimit(slot, limit)
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
194
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
195
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
196 def readInt(self, msg, default, maximum = 999999):
94
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
197 self.scr.nodelay(0) # enable delay on readkey
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
198 curses.echo()
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
199 self.scr.addstr(0,0, "%s [%i]:" % (
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
200 msg,
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
201 default),
94
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
202 curses.color_pair(1))
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
203 self.scr.refresh()
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
204 inp = self.scr.getstr(1,0, 4)
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
205 if inp != "":
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
206 try:
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
207 inp = int(inp)
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
208 if inp > maximum: inp = maximum
94
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
209 except Exception:
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
210 inp = None
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
211 else:
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
212 inp = None
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
213 self.cleartop()
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
214 self.scr.refresh()
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
215 curses.noecho()
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
216 self.scr.nodelay(1) # disable delay on readkey
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
217 return inp
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
218
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
219
103
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
220 def monitor_init(self, live = 1):
74
173d0863a804 added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents: 61
diff changeset
221 """
173d0863a804 added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents: 61
diff changeset
222 Send initializing commands for live monitoring
173d0863a804 added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents: 61
diff changeset
223 """
86
79fb119cf3c3 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 85
diff changeset
224 self.box.query("F1\n") # set fuel logic enabled
103
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
225 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
226
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
227 def monitor_learn(self, slot):
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
228 # 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
229 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
230 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
231 while self.box.readline() != "": pass
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
232
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
233 trk = False
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
234 spd = 0
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
235 trk_old = False
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
236 spd_old = 0
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
237 clock = -1
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
238
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
239 self.monitor_init(slot + 2)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
240 while 1:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
241 #key = self.scr.getch()
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
242 #if key == ord('c'): break
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
243
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
244 # 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
245 rx = self.box.readline()
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
246 if (rx != ""):
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
247 try:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
248 data = rx.split(":")
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
249 if rx[:3] == "LN:":
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
250 if clock >= 0:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
251 clock += 1
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
252 spd = int(data[1], 16)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
253 trk = (data[2] != 'X')
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
254 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
255 if clock < 0:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
256 clock = 0
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
257 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
258 trk_old = trk
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
259 spd_old = spd * 1
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
260 if rx[:2] == "L:":
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
261 # update lap time info
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
262 l = int(data[2], 16)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
263 s = int(data[3]) - 1
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
264 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
265 if (slot == s):
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
266 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
267 clock = 0
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
268 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
269 except:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
270 print "RX ERROR: " % rx
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
271
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
272 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
273 # 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
274 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
275 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
276 sleep(1)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
277 cli.box.speedminimum(slot, 0 )
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
278 while self.box.readline() != "": pass
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
279
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
280 clock = -5
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
281 trkfile = open(filename, "r").readlines()
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
282 print "Loading %s..." % filename
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
283
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
284 while 1:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
285 try:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
286 for l in trkfile:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
287 l = l.strip()
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
288 if (l != "") and (l[:1] != "#"):
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
289 print "Line: %s" % repr(l)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
290 data = l.split(",")
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
291 speed = int(data[1])
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
292 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
293 clock += 1
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
294 sleep(0.07)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
295 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
296 cli.box.speedminimum(slot, speed )
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
297 # now wait for lap sync :)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
298 while self.box.readline() != "": pass
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
299 rx = ""
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
300 while rx[:2] != "L:":
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
301 rx = self.box.readline()
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
302 data = rx.split(":")
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
303 l = int(data[2], 16)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
304 s = int(data[3]) - 1
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
305 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
306 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
307 clock = -3
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
308 except Exception, e:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
309 print repr(e)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
310 sys.exit(1)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
311 except KeyboardInterrupt:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
312 print "resetting"
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
313 cli.box.speedminimum(slot, 0 )
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
314 cli.box.speedminimum(slot, 0 )
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
315 sys.exit(0)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
316
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
317
74
173d0863a804 added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents: 61
diff changeset
318
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
319 def monitor(self):
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
320 """
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
321 Live Monitor on the console
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
322 Keyboard loop to control it???
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
323 """
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
324 # clear garbage in UART rx buffer
86
79fb119cf3c3 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 85
diff changeset
325 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
326
74
173d0863a804 added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents: 61
diff changeset
327 self.monitor_init()
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
328 self.scr = curses.initscr()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
329 curses.start_color()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
330 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
331 curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE) # label
93
ee4f9b8a36e9 improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 90
diff changeset
332 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
333 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
334 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
335 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
336 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
337 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
338 curses.noecho() # disable key echo
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
339 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
340 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
341 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
342
59
361bc4602cf7 added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
343 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
344 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
345 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
346
9293f3efcc06 added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents: 54
diff changeset
347
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
348 while 1:
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
349 key = self.scr.getch()
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
350 if key == ord('c'): break
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
351 elif key == ord(' '): self.box.query("+") # panic / resume
90
7ed95dbadf1f added remote start button press
Malte Bayer <mbayer@neo-soft.org>
parents: 89
diff changeset
352 elif key == 10: self.box.query("#") # remote start button press
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
353 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
354 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
355 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
356 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
357 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
358 elif key == ord('6'): self.readName(5)
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
359 elif key == ord('q'): self.readLimit(0)
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
360 elif key == ord('w'): self.readLimit(1)
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
361 elif key == ord('e'): self.readLimit(2)
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
362 elif key == ord('r'): self.readLimit(3)
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
363 elif key == ord('t'): self.readLimit(4)
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
364 elif key == ord('z'): self.readLimit(5)
55
9293f3efcc06 added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents: 54
diff changeset
365 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
366 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
367 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
368 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
369 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
370 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
371 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
372 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
373 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
374 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
375 if self.slot[5]["drive"] < 16: 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
376 cli.box.speedminimum(5, self.slot[4]["drive"])
94
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
377 elif key == ord('t'):
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
378 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
379 if tmp: self.timelimit = tmp
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
380 elif key == ord('l'):
c7ff8cde6b1e improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents: 93
diff changeset
381 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
382 if tmp: self.laplimit = tmp
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
383
55
9293f3efcc06 added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents: 54
diff changeset
384
9293f3efcc06 added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents: 54
diff changeset
385 # is there something in the rx buffer?
86
79fb119cf3c3 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 85
diff changeset
386 rx = self.box.readline()
87
761863c71884 added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents: 86
diff changeset
387 if (rx != "") or self.test:
761863c71884 added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents: 86
diff changeset
388 self.scr.addstr(17,0,
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
389 "Last RX: %19s" % rx, curses.color_pair(2))
99
434d60dc9b12 fix winning position display
paepke
parents: 97
diff changeset
390 self.scr.redrawwin()
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
391 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
392 # we have received something
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
393 try:
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
394 data = rx.split(":")
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
395 if rx[:2] == "L:":
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
396 # update lap time info
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
397 l = int(data[2], 16)
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
398 slot = int(data[3]) - 1
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
399 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
400 self.sysclk = int(data[5], 16) / 2000.00
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
401 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
402 self.slot[slot]["laps"] = l
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
403 self.slot[slot]["last"] = t
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
404 self.slot[slot]["clk"] = self.sysclk
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
405 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
406 self.slot[slot]["best"] = t
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
407 if self.bestlap > t:
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
408 trigger_event("lap_record")
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
409 self.bestlap = t
78
d9126a55295c added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents: 77
diff changeset
410
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
411 self.slot[slot]["status"] = "IN-RACE"
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
412 if (self.slot[slot]["laps_last"] != l) and (l == self.laplimit):
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
413 # we have lap limit reached!
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
414 trigger_event("win")
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
415 self.raceactive = False
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
416 self.slot[slot]["status"] = "WINNER!"
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
417 self.box.query("+") # stop race
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
418
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
419 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
420
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
421 if rx[:2] == "F:":
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
422 # update fuel level
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
423 slot = int(data[1])
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
424 f = int(data[2], 16)
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
425 f = f / 100 # fuel in percent
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
426 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
427 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
428 self.slot[slot]["fuel"] = f
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
429 if self.slot[slot]["fuel_last"] != f:
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
430 if (self.slot[slot]["fuel_last"] == 16) and (f == 15):
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
431 # 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
432 # warning sound
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
433 trigger_event("fuel_warning1")
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
434 cli.box.speedlimit(slot, 8)
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
435 if (self.slot[slot]["fuel_last"] == 6) and (f == 5):
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
436 # 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
437 # warning sound
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
438 trigger_event("fuel_warning2")
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
439 cli.box.speedlimit(slot, 6)
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
440 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
441 # fuel empty
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
442 # set speedlimit to 4
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
443 cli.box.speedlimit(slot, 4)
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
444 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
445 cli.box.speedlimit(slot, 15)
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
446 if (self.slot[slot]["fuel_last"] < f) and (f == 100):
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
447 trigger_event("fuel_full")
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
448 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
449
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
450 if rx[:1] == "~":
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
451 # jumpstart occured
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
452 slot = int(rx[1:2])
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
453 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
454 self.slot[slot]["jumpstart"] = t
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
455 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
456
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
457 if rx[:3] == "RW:":
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
458 # 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
459 slot = int(data[1])
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
460 devtype = int(data[2])
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
461 sender = int(data[3], 16)
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
462 status = int(data[4], 16)
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
463 self.sysclk = int(data[5], 16)
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
464 if (devtype == 4):
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
465 # pitlane sent something
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
466 if (status == 5):
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
467 self.slot[slot]["status"] = "PITLANE"
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
468 trigger_event("pitlane_enter")
104
95b2c23cb973 pitlane checkout bug resolved, prepare for customized pitlane speedlimit
Malte Bayer <mbayer@neo-soft.org>
parents: 103
diff changeset
469 if (status == 7):
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
470 self.slot[slot]["status"] = "IN-RACE"
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
471 trigger_event("pitlane_exit")
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
472
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
473 self.render_slots()
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
474
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
475 if rx == "!RACE PREPARE":
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
476 # reset current race status
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
477 # and display PREPARE PHASE
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
478 self.reset_slots()
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
479 for slot in range(MAXSLOTS):
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
480 self.slot[slot]["status"] = "Prepare"
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
481 trigger_event("race_prepare")
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
482
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
483 if rx == "!RACE START":
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
484 for slot in range(MAXSLOTS):
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
485 if self.slot[slot]["status"] == "~~~~~~~~~~":
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
486 self.slot[slot]["status"] = "Idle"
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
487 trigger_event("race_start")
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
488 self.raceactive = True
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
489
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
490 if rx == "!COUNTDOWN":
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
491 # countdown initiated
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
492 for slot in range(MAXSLOTS):
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
493 self.slot[slot]["status"] = "~~~~~~~~~~"
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
494 trigger_event("countdown_start")
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
495
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
496 if rx == "!PANIC":
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
497 # panic mode
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
498 trigger_event("panic")
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
499
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
500 if rx == "!SHORTCUT":
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
501 # panic mode
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
502 trigger_event("panic_shortcut")
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
503
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
504 if rx == "!RESUME":
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
505 # panic mode
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
506 trigger_event("resume")
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
507
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
508
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
509 if ((self.timelimit > 0) and (self.raceactive) and
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
510 (self.sysclk_last != self.sysclk) and
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
511 ((self.sysclk / 60) >= self.timelimit)):
96
bcba10c35f09 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 95
diff changeset
512 self.sysclk_last = self.sysclk
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
513 self.raceactive = False
96
bcba10c35f09 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 95
diff changeset
514 # we have time limit reached!
97
9a01c57147db final corrections
Malte Bayer <mbayer@neo-soft.org>
parents: 96
diff changeset
515 self.box.query("+") # stop race
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
516 trigger_event("win")
96
bcba10c35f09 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 95
diff changeset
517 # get the one with position 1
bcba10c35f09 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 95
diff changeset
518 for slot in self.slots:
bcba10c35f09 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 95
diff changeset
519 if slot["position"] == 1:
bcba10c35f09 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 95
diff changeset
520 slot["status"] = "WINNER!"
99
434d60dc9b12 fix winning position display
paepke
parents: 97
diff changeset
521 self.render_slots()
96
bcba10c35f09 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 95
diff changeset
522 self.sysclk_last = self.sysclk
bcba10c35f09 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 95
diff changeset
523
95
85c4a4da2ffd added winning ability ;)
Malte Bayer <mbayer@neo-soft.org>
parents: 94
diff changeset
524
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 87
diff changeset
525
87
761863c71884 added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents: 86
diff changeset
526 self.scr.addstr(17,31,
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
527 "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
528 curses.color_pair(2))
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
529
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
530 self.scr.refresh()
77
cede78304992 finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents: 74
diff changeset
531
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
532 except Exception:
107
efdf471642f5 added custom event scripts
Malte Bayer <mbayer@neo-soft.org>
parents: 106
diff changeset
533 trigger_event("data_error")
85
a637228562a7 added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents: 82
diff changeset
534 pass
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
535
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
536 # terminate
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
537 curses.nocbreak()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
538 self.scr.keypad(0)
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
539 curses.echo()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
540 curses.endwin()
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
541 return None
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
542
58
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
543 def cyclemode(self):
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
544 pass
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
545
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
546 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
547 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
548 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
549 help="Run Live monitor on console", metavar="[0-5]")
103
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
550 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
551 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
552 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
553 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
554
86
79fb119cf3c3 added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents: 85
diff changeset
555 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
556 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
557 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
558 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
559 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
560 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
561 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
562 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
563 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
564 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
565 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
566 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
567 parser.add_option("--drive", dest="drive",
84b8ab4cd79e implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
568 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
569 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
570 help="", metavar="")
106
11fabe1f7c40 added dev parameter
Malte Bayer <mbayer@neo-soft.org>
parents: 104
diff changeset
571 parser.add_option("--dev", dest="dev", default="/dev/ttyUSB0",
11fabe1f7c40 added dev parameter
Malte Bayer <mbayer@neo-soft.org>
parents: 104
diff changeset
572 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
573
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
574 (options, args) = parser.parse_args()
106
11fabe1f7c40 added dev parameter
Malte Bayer <mbayer@neo-soft.org>
parents: 104
diff changeset
575 #if not options.dev:
11fabe1f7c40 added dev parameter
Malte Bayer <mbayer@neo-soft.org>
parents: 104
diff changeset
576 # options.dev = "/dev/ttyUSB0"
11fabe1f7c40 added dev parameter
Malte Bayer <mbayer@neo-soft.org>
parents: 104
diff changeset
577 cli = SlotCli(options.test, options.dev)
35
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
578 # 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
579
58
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
580 if options.live:
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
581 # start the live monitor
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
582 cli.monitor()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
583 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
584
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
585 # check commandline if we have to program something
58
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
586 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
587 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
588 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
589 else:
92d204c738e1 changed --slot parameter to 1..6 instead of 0..5
Malte Bayer <mbayer@neo-soft.org>
parents: 100
diff changeset
590 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
591 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
592 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
593 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
594
103
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
595 if options.learn:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
596 # start the learn monitor
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
597 cli.monitor_learn(options.carid)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
598 sys.exit(0)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
599
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
600 if options.playback:
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
601 # start the playback monitor
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
602 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
603 sys.exit(0)
52fd4283cd2c added learn and teach modes for intelligent ghostcars
Malte Bayer <mbayer@neo-soft.org>
parents: 102
diff changeset
604
58
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
605 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
606 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
607
100
039ab094f79b renamed --speed to --accel and added minimum value 6
Malte Bayer <mbayer@neo-soft.org>
parents: 99
diff changeset
608 if options.accel:
039ab094f79b renamed --speed to --accel and added minimum value 6
Malte Bayer <mbayer@neo-soft.org>
parents: 99
diff changeset
609 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
610
58
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
611 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
612 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
613
58
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
614 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
615 state = False
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
616 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
617 state = True
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
618 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
619
58
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
620 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
621 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
622
58
042c490fdfaa better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents: 56
diff changeset
623 if options.drive:
50
84b8ab4cd79e implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
624 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
625

mercurial