Files
panda-meb/tests/debug_console.py

42 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))
2017-07-29 18:16:08 -07:00
claim = os.getenv("CLAIM") is not None
2017-04-06 18:11:36 -07:00
serials = Panda.list()
if os.getenv("SERIAL"):
serials = filter(lambda x: x==os.getenv("SERIAL"), serials)
2017-07-29 18:16:08 -07:00
pandas = list(map(lambda x: Panda(x, claim=claim), serials))
2017-10-15 18:13:52 -07:00
if os.getenv("BAUD") is not None:
for panda in pandas:
panda.set_uart_baud(port_number, int(os.getenv("BAUD")))
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:
2017-07-20 15:34:45 -07:00
sys.stdout.write(setcolor[i] + str(ret) + 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()
2017-07-29 18:16:08 -07:00
if claim:
panda.serial_write(port_number, ln)
2017-04-29 00:09:08 -07:00
time.sleep(0.01)