Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRIVERS: add interactive console to test siren over serial #423

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions utils/navigator_tools/scripts/siren_interactive
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python
from mil_tools import SimulatedSerial
import serial


class SimulatedSirenBoard(SimulatedSerial):
'''
Simulates the serial communication of the siren board
'''
def write(self, data):
for byte in data:
if byte == 'A':
print 'On'
else:
print 'Off'


class SirenBoard(object):
'''
Wrapper for siren board
'''
def __init__(self, port, baudrate, sim=False):
if sim:
self.ser = SimulatedSirenBoard()
else:
self.ser = serial.Serial(port=port, baudrate=baudrate)

def on(self):
self.ser.write('A')

def off(self):
self.ser.write('B')

if __name__ == '__main__':
print 'Siren board interactive Console'
board = SirenBoard('/dev/serial/by-id/usb-FTDI_FT230X_Basic_UART_DN05A8R2-if00-port0', 115200, sim=False)
while True:
try:
c = raw_input('1 for on, 2 for off: ')
if c == '1':
board.on()
elif c == '2':
board.off()
else:
print 'Unrecognized command'
except KeyboardInterrupt:
break