diff zbtest.py @ 11:75f785a09e2e

Add license. Split test stuff into a separate file. Fix some bugs.. - Default frame ID to 1 so we get status replies by default. - Correct address generation routine for TX packets. Add doc strings and epydoc variable comments.
author darius@Inchoate
date Tue, 13 Jan 2009 12:14:13 +1030
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zbtest.py	Tue Jan 13 12:14:13 2009 +1030
@@ -0,0 +1,86 @@
+#
+# Test code for ZigBee code
+#
+# Copyright (c) 2009
+#      Daniel O'Connor <darius@dons.net.au>.  All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+
+import zb, serial, time
+
+def polldev():
+    while (1):
+        foo = up.getdata()
+        for p in up.pktq:
+            print p
+
+        if (foo == 0):
+            time.sleep(0.1)
+
+#for c in dir():
+#    if (issubclass(c, PktBase)):
+#        print ..
+
+try:
+    s = serial.Serial(port='/dev/cuaU0', baudrate=38400, bytesize=8, parity='N', \
+                      stopbits=1, rtscts=0)
+    # Non-blocking
+    s.timeout = 0
+    #s.write('+++')
+    #s.readline(eol='\r')
+except serial.serialutil.SerialException, e:
+    print "Can't open serial port - " + str(e)
+    s = None
+    
+# 0x0001 (-36dBm) -> 1 samples, mask 0x000f, DIO - 0x00f
+goodtest = [126, 0, 10, 131, 0, 1, 36, 0, 1, 0, 15, 0, 15, 56]
+
+# Checksum error
+badtest = [126, 0, 10, 131, 0, 1, 36, 0, 1, 0, 15, 0, 14, 56]
+
+#0x0005 (-36dBm) -> 1 samples, mask 0x020e, DIO - 0x00e, ADC0 - 0x3ff
+adctest = [126, 0, 12, 131, 0, 5, 36, 0, 1, 2, 14, 0, 14, 3, 255, 50]
+
+# Exception
+badpkttypetest = [126, 0, 3, 10, 86, 76, 83]
+
+# Frame ID = 0, Cmd = 'VL', Status = OK, Value = 'VL Result'
+atreply = [126, 0, 14, 136, 0, 86, 76, 0, 86, 76, 32, 82, 101, 115, 117, 108, 116, 148]
+
+# Do some basic tests
+up = zb.Packets(s)
+up.process(goodtest)
+up.process(badtest)
+up.process(adctest)
+p = up.pktq.pop(0)
+assert(p.sender == 0x1 and p.rssi == -36 and p.nsamples == 1 and p.mask == 0xf)
+
+p = up.pktq.pop(0)
+assert(p.sender == 0x5 and p.rssi == -36 and p.nsamples == 1 and p.mask == 0x20e)
+
+assert len(up.pktq) == 0
+
+assert(up.rx_cnt == 2)
+assert(up.ck_err == 1)
+assert(up.fr_err == 0)
+