From 231ce4b2a22d2895ee0bf6db4536cc2a56dbbcbd Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 21 Apr 2018 16:22:12 +0200 Subject: Add python driver for new comms protocol --- firmware/olsndot.py | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 firmware/olsndot.py (limited to 'firmware') diff --git a/firmware/olsndot.py b/firmware/olsndot.py new file mode 100644 index 0000000..016ac3a --- /dev/null +++ b/firmware/olsndot.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + +import serial +import struct +from cobs import cobs +from collections import namedtuple +from enum import Enum +import time + +EOP = b'\0' + +#def cobs_encode(data): +# return b''.join(bytes([len(x)+1]) + x for x in data.split(EOP)) +# +#def cobs_decode(data): +# out = b'' +# while data: +# n, *rest = data +# out += b'\0' + bytes(rest[:n-1]) +# data = rest[n-1:] +# return out[1:] + +def address_pkt(addr): + return struct.pack(''.format( + self.addr, self.fw_ver, self.hw_ver, self.nchannels, self.channel_format, + st.uptime_s, st.vcc_mv/1000, st.temp_celsius) + + @property + def channel_format(self): + return '{}{}'.format(self.color_spec.name, self.nbits) + +if __name__ == '__main__': + d = Driver('/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50285BI-if00-port0') + for addr, tid, drv in d.probe_devices(): + print(addr, tid, drv) -- cgit