Skip to content

Instantly share code, notes, and snippets.

@NickCrews
Last active May 31, 2019 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickCrews/52ab07c8519b56c0ec671d3338760516 to your computer and use it in GitHub Desktop.
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
#!/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