comparison 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
comparison
equal deleted inserted replaced
23:08535b12504f 24:c6ee9eae9e49
447 print "Invalid state %s! Resetting" % (self.state) 447 print "Invalid state %s! Resetting" % (self.state)
448 self.state = 'init' 448 self.state = 'init'
449 449
450 return pktcount 450 return pktcount
451 451
452 if __name__ == '__main__':
453 # 0x0001 (-36dBm) -> 1 samples, mask 0x000f, DIO - 0x00f
454 goodtest = [126, 0, 10, 131, 0, 1, 36, 0, 1, 0, 15, 0, 15, 56]
455
456 # Checksum error
457 badtest = [126, 0, 10, 131, 0, 1, 36, 0, 1, 0, 15, 0, 14, 56]
458
459 #0x0005 (-36dBm) -> 1 samples, mask 0x020e, DIO - 0x00e, ADC0 - 0x3ff
460 adctest = [126, 0, 12, 131, 0, 5, 36, 0, 1, 2, 14, 0, 14, 3, 255, 50]
461
462 # Exception
463 badpkttypetest = [126, 0, 3, 10, 86, 76, 83]
464
465 # Frame ID = 0, Cmd = 'VL', Status = OK, Value = 'VL Result'
466 atreply = [126, 0, 14, 136, 0, 86, 76, 0, 86, 76, 32, 82, 101, 115, 117, 108, 116, 148]
467
468 # Do some basic tests
469 up = Packets(None)
470 up.process(goodtest)
471 up.process(badtest)
472 up.process(adctest)
473 p = up.pktq.pop(0)
474 assert(p.sender == 0x1 and p.rssi == -36 and p.nsamples == 1 and p.mask == 0xf)
475
476 p = up.pktq.pop(0)
477 assert(p.sender == 0x5 and p.rssi == -36 and p.nsamples == 1 and p.mask == 0x20e)
478
479 assert len(up.pktq) == 0
480
481 assert(up.rx_cnt == 2)
482 assert(up.ck_err == 1)
483 assert(up.fr_err == 0)
484