Last active
May 31, 2019 17:34
-
-
Save NickCrews/52ab07c8519b56c0ec671d3338760516 to your computer and use it in GitHub Desktop.
Test script to write a telemetry command and read a response from the Wilco EC
This file contains hidden or 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
#!/usr/bin/python | |
# https://gist.github.com/NickCrews/52ab07c8519b56c0ec671d3338760516 | |
import os, glob | |
def test(bytes): | |
fname = glob.glob("/dev/wilco_telem*")[0] | |
fd = None | |
try: | |
fd = os.open(fname, os.O_RDWR) | |
bytes = [chr(n) for n in bytes] | |
print "=" * 80 | |
print "writing to file: %s " % " ".join(n.encode("hex") for n in bytes) | |
ret = os.write(fd, ''.join(bytes)) | |
print "write() returned: %d " % ret | |
try: | |
bytes = os.read(fd, 32) | |
print "read from file: %s " % " ".join(n.encode("hex") for n in bytes) | |
except Exception as e: | |
print "failed reading: ", e | |
except Exception as e: | |
print "failed writing: ", e | |
finally: | |
if (fd): | |
os.close(fd) | |
test(range(32)) | |
test(range(100)) | |
test([]) | |
test([0]) | |
test([0x38, 0, 3]) | |
test([0x38, 0]) | |
test([0x38, 1, 3]) | |
test([0x38, 0, 2]) | |
test([0x39, 0, 3]) | |
test([0x38, 0, 3, 0]) | |
test([0x2C, 0, 0, 0]) | |
test([0x2C, 0, 0]) | |
test([0x2C, 0, 1]) | |
test([0x2C, 0, 2]) | |
test([0x2C, 0, 3]) | |
test([0x2C, 0, 4]) | |
test([0x8A, 0, 1]) | |
test([0x8A, 0, 4]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment