diff zb.py @ 24:c6ee9eae9e49

Add some tests to zb.py.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 16 Apr 2013 08:20:15 +0930
parents 729f2393f296
children
line wrap: on
line diff
--- a/zb.py	Tue Apr 16 08:15:09 2013 +0930
+++ b/zb.py	Tue Apr 16 08:20:15 2013 +0930
@@ -449,3 +449,36 @@
         
         return pktcount
 
+if __name__ == '__main__':
+    # 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 = Packets(None)
+    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)
+