Files
panda-meb/tests/debug_console.py

39 lines
1.1 KiB
Python
Raw Normal View History

2017-04-06 18:11:36 -07:00
#!/usr/bin/env python
from __future__ import print_function
2017-04-06 18:11:36 -07:00
import os
import sys
import time
import select
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
from panda import Panda
2017-04-06 18:11:36 -07:00
setcolor = ["\033[1;32;40m", "\033[1;31;40m"]
unsetcolor = "\033[00m"
if __name__ == "__main__":
port_number = int(os.getenv("PORT", 0))
serials = Panda.list()
if os.getenv("SERIAL"):
serials = filter(lambda x: x==os.getenv("SERIAL"), serials)
2017-06-28 14:50:00 -07:00
pandas = list(map(lambda x: Panda(x, False), serials))
for i, p in enumerate(pandas):
print("%s Panda %s%s" % (setcolor[i], p._serial, unsetcolor))
while True:
2017-04-06 18:11:36 -07:00
for i, panda in enumerate(pandas):
while True:
2017-04-29 00:09:08 -07:00
ret = panda.serial_read(port_number)
if len(ret) > 0:
sys.stdout.write(setcolor[i] + ret.decode('utf8') + unsetcolor)
2017-04-29 00:09:08 -07:00
sys.stdout.flush()
else:
break
2017-06-28 14:50:00 -07:00
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
2017-04-06 18:11:36 -07:00
ln = sys.stdin.readline()
panda.serial_write(port_number, ln)
2017-04-29 00:09:08 -07:00
time.sleep(0.01)