Skip to content

Commit

Permalink
add PandaSerial and location panda (aka pigeon) test
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Jan 7, 2018
1 parent c371fe6 commit 65997ff
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .python import Panda, PandaWifiStreaming, PandaDFU, ESPROM, CesantaFlasher, flash_release, BASEDIR, ensure_st_up_to_date, build_st
from .python import Panda, PandaWifiStreaming, PandaDFU, ESPROM, CesantaFlasher, flash_release, BASEDIR, ensure_st_up_to_date, build_st, PandaSerial
1 change: 1 addition & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from esptool import ESPROM, CesantaFlasher
from flash_release import flash_release
from update import ensure_st_up_to_date
from serial import PandaSerial

__version__ = '0.0.6'

Expand Down
26 changes: 26 additions & 0 deletions python/serial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# mimic a python serial port
class PandaSerial(object):
def __init__(self, panda, port, baud):
self.panda = panda
self.port = port
self.panda.set_uart_parity(self.port, 0)
self.panda.set_uart_baud(self.port, baud)
self.buf = ""

def read(self, l=1):
tt = self.panda.serial_read(self.port)
if len(tt) > 0:
#print "R: ", tt.encode("hex")
self.buf += tt
ret = self.buf[0:l]
self.buf = self.buf[l:]
return ret

def write(self, dat):
#print "W: ", dat.encode("hex")
return self.panda.serial_write(self.port, dat)

def close(self):
pass


44 changes: 44 additions & 0 deletions tests/location_listener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python
import os
import time
import sys

sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
from panda import Panda, PandaSerial

def add_nmea_checksum(msg):
d = msg[1:]
cs = 0
for i in d:
cs ^= ord(i)
return msg + "*%02X" % cs

if __name__ == "__main__":
panda = Panda()
ser = PandaSerial(panda, 1, 9600)

# power cycle by toggling reset
print "resetting"
panda.set_esp_power(0)
time.sleep(0.1)
panda.set_esp_power(1)
time.sleep(0.5)
print "done"
print ser.read(1024)

# upping baud rate
print "upping baud rate (broken)"
msg = add_nmea_checksum("$PUBX,41,1,0007,0003,9600,0")+"\r\n"
print msg
ser.write(msg)

# new panda serial
ser = PandaSerial(panda, 1, 9600)

while True:
ret = ser.read(1024)
if len(ret) > 0:
sys.stdout.write(ret)
sys.stdout.flush()
#print str(ret).encode("hex")

0 comments on commit 65997ff

Please sign in to comment.