comparison 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
comparison
equal deleted inserted replaced
10:4c91fdfc862e 11:75f785a09e2e
1 #
2 # Test code for ZigBee code
3 #
4 # Copyright (c) 2009
5 # Daniel O'Connor <darius@dons.net.au>. All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # SUCH DAMAGE.
27 #
28
29 import zb, serial, time
30
31 def polldev():
32 while (1):
33 foo = up.getdata()
34 for p in up.pktq:
35 print p
36
37 if (foo == 0):
38 time.sleep(0.1)
39
40 #for c in dir():
41 # if (issubclass(c, PktBase)):
42 # print ..
43
44 try:
45 s = serial.Serial(port='/dev/cuaU0', baudrate=38400, bytesize=8, parity='N', \
46 stopbits=1, rtscts=0)
47 # Non-blocking
48 s.timeout = 0
49 #s.write('+++')
50 #s.readline(eol='\r')
51 except serial.serialutil.SerialException, e:
52 print "Can't open serial port - " + str(e)
53 s = None
54
55 # 0x0001 (-36dBm) -> 1 samples, mask 0x000f, DIO - 0x00f
56 goodtest = [126, 0, 10, 131, 0, 1, 36, 0, 1, 0, 15, 0, 15, 56]
57
58 # Checksum error
59 badtest = [126, 0, 10, 131, 0, 1, 36, 0, 1, 0, 15, 0, 14, 56]
60
61 #0x0005 (-36dBm) -> 1 samples, mask 0x020e, DIO - 0x00e, ADC0 - 0x3ff
62 adctest = [126, 0, 12, 131, 0, 5, 36, 0, 1, 2, 14, 0, 14, 3, 255, 50]
63
64 # Exception
65 badpkttypetest = [126, 0, 3, 10, 86, 76, 83]
66
67 # Frame ID = 0, Cmd = 'VL', Status = OK, Value = 'VL Result'
68 atreply = [126, 0, 14, 136, 0, 86, 76, 0, 86, 76, 32, 82, 101, 115, 117, 108, 116, 148]
69
70 # Do some basic tests
71 up = zb.Packets(s)
72 up.process(goodtest)
73 up.process(badtest)
74 up.process(adctest)
75 p = up.pktq.pop(0)
76 assert(p.sender == 0x1 and p.rssi == -36 and p.nsamples == 1 and p.mask == 0xf)
77
78 p = up.pktq.pop(0)
79 assert(p.sender == 0x5 and p.rssi == -36 and p.nsamples == 1 and p.mask == 0x20e)
80
81 assert len(up.pktq) == 0
82
83 assert(up.rx_cnt == 2)
84 assert(up.ck_err == 1)
85 assert(up.fr_err == 0)
86