forked from commaai/panda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add PandaSerial and location panda (aka pigeon) test
- Loading branch information
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|