# HG changeset patch # User Daniel O'Connor # Date 1366066215 -34200 # Node ID c6ee9eae9e49f4bbbcc03a1a61f12438600803d2 # Parent 08535b12504fc1d1c3d2dc0ff3d9b2217ab03c0e Add some tests to zb.py. diff -r 08535b12504f -r c6ee9eae9e49 zb.py --- 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) +