Skip to content

Commit

Permalink
fix more encoding and some bytes cleanup (commaai#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini authored Oct 15, 2019
1 parent 162f485 commit 6b1f28f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def get_checksum(dat):
ts = x[i:i+0xf]
if DEBUG:
print("kline send: " + binascii.hexlify(ts))
self._handle.bulkWrite(2, chr(bus).encode()+ts)
self._handle.bulkWrite(2, bytes([bus]) + ts)
echo = self.kline_ll_recv(len(ts), bus=bus)
if echo != ts:
print("**** ECHO ERROR %d ****" % i)
Expand Down
6 changes: 3 additions & 3 deletions python/isotp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ def isotp_send(panda, x, addr, bus=0, recvaddr=None, subaddr=None):
panda.can_send(addr, bytes([subaddr]) + msg(x)[0:7], bus)
else:
if subaddr:
ss = bytes([subaddr]) + bytes([0x10 + (len(x) >> 8)]) + bytes([len(x) & 0xFF]) + x[0:5]
ss = bytes([subaddr, 0x10 + (len(x) >> 8), len(x) & 0xFF]) + x[0:5]
x = x[5:]
else:
ss = bytes([0x10 + (len(x) >> 8)]) + bytes([len(x) & 0xFF]) + x[0:6]
ss = bytes([0x10 + (len(x) >> 8), len(x) & 0xFF]) + x[0:6]
x = x[6:]
idx = 1
sends = []
while len(x) > 0:
if subaddr:
sends.append(((bytes([subaddr]) + bytes([0x20 + (idx & 0xF)]) + x[0:6]).ljust(8, b"\x00")))
sends.append(((bytes([subaddr, 0x20 + (idx & 0xF)]) + x[0:6]).ljust(8, b"\x00")))
x = x[6:]
else:
sends.append(((bytes([0x20 + (idx & 0xF)]) + x[0:7]).ljust(8, b"\x00")))
Expand Down
5 changes: 1 addition & 4 deletions python/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ def read(self, l=1):
def write(self, dat):
#print "W: ", dat.encode("hex")
#print ' pigeon_send("' + ''.join(map(lambda x: "\\x%02X" % ord(x), dat)) + '");'
if(isinstance(dat, bytes)):
return self.panda.serial_write(self.port, dat)
else:
return self.panda.serial_write(self.port, str.encode(dat))
return self.panda.serial_write(self.port, dat)

def close(self):
pass
Expand Down
2 changes: 1 addition & 1 deletion tests/elm_wifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def timed_recv_check(p, bus, goodmsg):

def kline_send(p, x, bus=2):
p.kline_drain(bus=bus)
p._handle.bulkWrite(2, chr(bus).encode()+x)
p._handle.bulkWrite(2, bytes([bus]) + x)
return timed_recv_check(p, bus, x)

def did_send(priority, toaddr, fromaddr, dat, bus=2, checkbyte=None):
Expand Down
42 changes: 19 additions & 23 deletions tests/gps_stability_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def add_nmea_checksum(msg):

# Upping baud rate
print("Upping GPS baud rate")
msg = add_nmea_checksum("$PUBX,41,1,0007,0003,%d,0" % GPS_BAUD)+"\r\n"
msg = str.encode(add_nmea_checksum("$PUBX,41,1,0007,0003,%d,0" % GPS_BAUD)+"\r\n")
ser.write(msg)
time.sleep(1) # needs a wait for it to actually send

Expand All @@ -86,24 +86,24 @@ def add_nmea_checksum(msg):

# Sending all config messages boardd sends
print("Sending config")
ser.write("\xB5\x62\x06\x00\x14\x00\x03\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x00\x00\x00\x1E\x7F")
ser.write("\xB5\x62\x06\x3E\x00\x00\x44\xD2")
ser.write("\xB5\x62\x06\x00\x14\x00\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x35")
ser.write("\xB5\x62\x06\x00\x14\x00\x01\x00\x00\x00\xC0\x08\x00\x00\x00\x08\x07\x00\x01\x00\x01\x00\x00\x00\x00\x00\xF4\x80")
ser.write("\xB5\x62\x06\x00\x14\x00\x04\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1D\x85")
ser.write("\xB5\x62\x06\x00\x00\x00\x06\x18")
ser.write("\xB5\x62\x06\x00\x01\x00\x01\x08\x22")
ser.write("\xB5\x62\x06\x00\x01\x00\x02\x09\x23")
ser.write("\xB5\x62\x06\x00\x01\x00\x03\x0A\x24")
ser.write("\xB5\x62\x06\x08\x06\x00\x64\x00\x01\x00\x00\x00\x79\x10")
ser.write("\xB5\x62\x06\x24\x24\x00\x05\x00\x04\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5A\x63")
ser.write("\xB5\x62\x06\x1E\x14\x00\x00\x00\x00\x00\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3C\x37")
ser.write("\xB5\x62\x06\x24\x00\x00\x2A\x84")
ser.write("\xB5\x62\x06\x23\x00\x00\x29\x81")
ser.write("\xB5\x62\x06\x1E\x00\x00\x24\x72")
ser.write("\xB5\x62\x06\x01\x03\x00\x01\x07\x01\x13\x51")
ser.write("\xB5\x62\x06\x01\x03\x00\x02\x15\x01\x22\x70")
ser.write("\xB5\x62\x06\x01\x03\x00\x02\x13\x01\x20\x6C")
ser.write(b"\xB5\x62\x06\x00\x14\x00\x03\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x00\x00\x00\x1E\x7F")
ser.write(b"\xB5\x62\x06\x3E\x00\x00\x44\xD2")
ser.write(b"\xB5\x62\x06\x00\x14\x00\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x35")
ser.write(b"\xB5\x62\x06\x00\x14\x00\x01\x00\x00\x00\xC0\x08\x00\x00\x00\x08\x07\x00\x01\x00\x01\x00\x00\x00\x00\x00\xF4\x80")
ser.write(b"\xB5\x62\x06\x00\x14\x00\x04\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1D\x85")
ser.write(b"\xB5\x62\x06\x00\x00\x00\x06\x18")
ser.write(b"\xB5\x62\x06\x00\x01\x00\x01\x08\x22")
ser.write(b"\xB5\x62\x06\x00\x01\x00\x02\x09\x23")
ser.write(b"\xB5\x62\x06\x00\x01\x00\x03\x0A\x24")
ser.write(b"\xB5\x62\x06\x08\x06\x00\x64\x00\x01\x00\x00\x00\x79\x10")
ser.write(b"\xB5\x62\x06\x24\x24\x00\x05\x00\x04\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x5A\x63")
ser.write(b"\xB5\x62\x06\x1E\x14\x00\x00\x00\x00\x00\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x3C\x37")
ser.write(b"\xB5\x62\x06\x24\x00\x00\x2A\x84")
ser.write(b"\xB5\x62\x06\x23\x00\x00\x29\x81")
ser.write(b"\xB5\x62\x06\x1E\x00\x00\x24\x72")
ser.write(b"\xB5\x62\x06\x01\x03\x00\x01\x07\x01\x13\x51")
ser.write(b"\xB5\x62\x06\x01\x03\x00\x02\x15\x01\x22\x70")
ser.write(b"\xB5\x62\x06\x01\x03\x00\x02\x13\x01\x20\x6C")

print("Initialized GPS")

Expand Down Expand Up @@ -163,7 +163,3 @@ def gps_read_thread(panda):
print("Total max failures: ", max_failures)
received_messages = 0
received_bytes = 0




2 changes: 1 addition & 1 deletion tests/location_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def add_nmea_checksum(msg):
baudrate = 460800

print("upping baud rate")
msg = add_nmea_checksum("$PUBX,41,1,0007,0003,%d,0" % baudrate)+"\r\n"
msg = str.encode(add_nmea_checksum("$PUBX,41,1,0007,0003,%d,0" % baudrate)+"\r\n")
print(msg)
ser.write(msg)
time.sleep(0.1) # needs a wait for it to actually send
Expand Down
2 changes: 1 addition & 1 deletion tests/loopback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_test_w_pandas(pandas, sleep_duration):

# send the characters
st = get_test_string()
st = b"\xaa"+chr(len(st)+3).encode()+st
st = bytes([0xaa, len(st) + 3]) + st
h[ho[0]].kline_send(st, bus=bus, checksum=False)

# check for receive
Expand Down
2 changes: 1 addition & 1 deletion tests/tucan_loopback.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_test_w_pandas(pandas, sleep_duration):

# send the characters
st = get_test_string()
st = b"\xaa"+chr(len(st)+3).encode()+st
st = bytes([0xaa, len(st) + 3]) + st
h[ho[0]].kline_send(st, bus=bus, checksum=False)

# check for receive
Expand Down

0 comments on commit 6b1f28f

Please sign in to comment.