Sat, 10 Dec 2011 16:29:31 +0100
bugfix: responsewire bitmap, todo: trackswitch response
23 | 1 | """ |
2 | FreeSlot project | |
3 | Blackbox communication library | |
4 | """ | |
5 | ||
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
6 | import serial, sys, string, time |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
7 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
8 | # how often should a command retried when busy? |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
9 | RETRIES = 10 |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
10 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
11 | # define loglevels |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
12 | DEBUG = 20 |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
13 | def log(level, msg): |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
14 | """ |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
15 | Logging output function |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
16 | """ |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
17 | print msg |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
18 | |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
19 | class SerialCommunicator(): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
20 | def __init__(self, device, speed): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
21 | self.device = device |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
22 | self.speed = speed |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
23 | self.com = None |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
24 | self.connected = False |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
25 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
26 | def connect(self): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
27 | if self.connected: |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
28 | return True |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
26
diff
changeset
|
29 | try: |
57
c2e2695c92fe
decreased blocking time for serial rx
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
30 | self.com = serial.Serial(self.device, baudrate=self.speed, |
c2e2695c92fe
decreased blocking time for serial rx
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
31 | xonxoff=0, timeout=0.1) |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
26
diff
changeset
|
32 | except serial.SerialException, err: |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
26
diff
changeset
|
33 | print err |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
26
diff
changeset
|
34 | sys.exit(1) |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
35 | self.connected = True |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
36 | return True |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
37 | |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
38 | def disconnect(self): |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
39 | self.com = None |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
40 | return True |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
41 | |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
42 | def write(self, msg, getanswer=False): |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
43 | self.com.write(msg + "\n") |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
44 | if getanswer: |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
45 | return self.readline() |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
46 | return None |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
47 | |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
48 | def readline(self): |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
49 | answer = self.com.readline() |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
50 | return string.strip(answer, "\n") |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
51 | |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
52 | def query(self, msg): |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
53 | retry = 0 |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
54 | response = self.write(msg, True) |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
55 | while (retry < RETRIES) and (response == "BUSY"): |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
56 | time.sleep(0.1) |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
57 | response = self.write(msg, True) |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
58 | retry += 1 |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
59 | log( DEBUG, "%i> %s\n< %s" % (retry, msg, response) ) |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
60 | return response |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
61 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
62 | |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
63 | class Blackbox(): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
64 | def __init__(self): |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
65 | self.com = None |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
66 | self.info = None |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
67 | |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
68 | def connect(self, device="/dev/ttyUSB0", speed=57600): |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
69 | if self.com == None: |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
70 | self.com = SerialCommunicator(device, speed) |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
71 | if self.com.connected: |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
72 | self.com.disconnect() |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
73 | self.com.connect() |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
74 | self.info = self.readinfo() |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
75 | |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
76 | def disconnect(self): |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
77 | self.com.disconnect() |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
78 | |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
79 | def readinfo(self): |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
80 | """ |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
81 | Read complete Information from connected box |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
82 | This does not include race+car status! |
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
23
diff
changeset
|
83 | """ |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
84 | return None |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
85 | |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
86 | def progcar(self, carid, command, value): |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
87 | """ |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
88 | Send program packets to specified car id |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
89 | valid command: speed, brake, fuel |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
90 | valid value: 4 bit integer (0..15) |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
91 | valid carid: 0..5 |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
92 | """ |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
93 | if (carid < 0) or (carid > 5): |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
94 | return "ERR - invalid carid" |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
95 | cmd = -1 |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
96 | if command == "speed": |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
97 | cmd = 0 |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
98 | if command == "brake": |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
99 | cmd = 1 |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
100 | if command == "fuel": |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
101 | cmd = 2 |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
102 | if (cmd == -1): |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
103 | return "ERR - invalid command" |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
104 | if (value<0) or (value>15): |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
105 | return "ERR - invalid value" |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
106 | # transform value 10..15 to A..F |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
107 | if (value>9): |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
108 | value = chr(ord("A") + (value-10)) |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
109 | command = "P%i%s%i" % (cmd, value, carid) |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
110 | response = self.com.query( command ) |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
111 | return response |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
112 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
113 | def blinkcar(self, carid, blink): |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
114 | """ |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
115 | Set car blinking state |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
116 | """ |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
117 | if (carid < 0) or (carid > 5): |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
118 | return "ERR - invalid carid" |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
119 | if blink: |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
120 | return self.com.query( "P48%i" % carid ) |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
121 | else: |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
122 | return self.com.query( "P40%i" % carid ) |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
123 | |
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
|
124 | def speedlimit(self, carid, value): |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
125 | """ |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
126 | Set the maximum controller speed for a car |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
127 | Attention: this is software limited, this does not affect car acceleration! |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
128 | """ |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
129 | if (carid < 0) or (carid > 5): |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
130 | return "ERR - invalid carid" |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
131 | if (value<0) or (value>15): |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
132 | return "ERR - invalid value" |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
133 | # transform value 10..15 to A..F |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
134 | if (value>9): |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
135 | value = chr(ord("A") + (value-10)) |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
136 | return self.com.query( "L%i%s" % (carid, value) ) |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
137 | |
50
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
138 | def speedminimum(self, carid, value): |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
139 | """ |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
140 | Set the minimzm controller speed for a car |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
141 | """ |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
142 | if (carid < 0) or (carid > 5): |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
143 | return "ERR - invalid carid" |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
144 | if (value<0) or (value>15): |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
145 | return "ERR - invalid value" |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
146 | # transform value 10..15 to A..F |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
147 | if (value>9): |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
148 | value = chr(ord("A") + (value-10)) |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
149 | return self.com.query( "S%i%s" % (carid, value) ) |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
150 | |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
151 | |
26
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
152 | def setmode(self, mode): |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
153 | """ |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
154 | Switch the Blackbox mode |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
155 | Valid modes are: idle, prepare, race |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
156 | note: box will permanently send status info in race mode, so no |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
157 | polling is required |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
158 | """ |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
159 | return True |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
160 | |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
161 | def getmode(self): |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
162 | self.readinfo() |
4af697fa5ea9
added some communication definitions
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
163 | return self.info["mode"] |