]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/MultihopOscilloscope/oscilloscope.py
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / apps / MultihopOscilloscope / oscilloscope.py
diff --git a/apps/MultihopOscilloscope/oscilloscope.py b/apps/MultihopOscilloscope/oscilloscope.py
new file mode 100644 (file)
index 0000000..de29c89
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+import sys
+import tos
+
+AM_OSCILLOSCOPE = 0x93
+
+class OscilloscopeMsg(tos.Packet):
+    def __init__(self, packet = None):
+        tos.Packet.__init__(self,
+                            [('version',  'int', 2),
+                             ('interval', 'int', 2),
+                             ('id',       'int', 2),
+                             ('count',    'int', 2),
+                             ('readings', 'blob', None)],
+                            packet)
+
+if '-h' in sys.argv:
+    print "Usage:", sys.argv[0], "serial@/dev/ttyUSB0:57600"
+    sys.exit()
+
+am = tos.AM()
+
+while True:
+    p = am.read()
+    if p and p.type == AM_OSCILLOSCOPE:
+        msg = OscilloscopeMsg(p.data)
+        print msg.id, msg.count, [i<<8 | j for (i,j) in zip(msg.readings[::2], msg.readings[1::2])]
+        #print msg
+