test_zigbee.py
Go to the documentation of this file.
1 """
2 test_zigbee.py
3 
4 By Paul Malmsten, 2010
5 pmalmsten@gmail.com
6 
7 Tests the XBee ZB (ZigBee) implementation class for API compliance
8 """
9 import unittest
10 from xbee.zigbee import ZigBee
11 
12 class TestZigBee(unittest.TestCase):
13  """
14  Tests ZigBee-specific features
15  """
16 
17  def setUp(self):
18  self.zigbee = ZigBee(None)
19 
21  """
22  Packets with null-terminated fields
23  should be properly parsed
24  """
25  expected_data = '\x01\x02\x03\x04'
26  terminator = '\x00'
27  node_identifier = '\x95' + '\x00' * 21 + expected_data + terminator + '\x00' * 8
28 
29  data = self.zigbee._split_response(node_identifier)
30 
31  self.assertEqual(data['node_id'], expected_data)
32 
34  data = '\x95\x00\x13\xa2\x00\x40\x52\x2b\xaa\x7d\x84\x02\x7d\x84\x00\x13\xa2\x00\x40\x52\x2b\xaa\x20\x00\xff\xfe\x01\x01\xc1\x05\x10\x1e'
35  info = self.zigbee._split_response(data)
36  expected_info = {
37  'id': 'node_id_indicator',
38  'sender_addr_long': '\x00\x13\xa2\x00\x40\x52\x2b\xaa',
39  'sender_addr': '\x7d\x84',
40  'options': '\x02',
41  'source_addr': '\x7d\x84',
42  'source_addr_long': '\x00\x13\xa2\x00\x40\x52\x2b\xaa',
43  'node_id': ' ',
44  'parent_source_addr': '\xff\xfe',
45  'device_type': '\x01',
46  'source_event': '\x01',
47  'digi_profile_id': '\xc1\x05',
48  'manufacturer_id': '\x10\x1e',
49  }
50 
51  self.assertEqual(info, expected_info)
52 
54  data = '\x95\x00\x13\xa2\x00\x40\x52\x2b\xaa\x7d\x84\x02\x7d\x84\x00\x13\xa2\x00\x40\x52\x2b\xaaCoordinator\x00\xff\xfe\x01\x01\xc1\x05\x10\x1e'
55  info = self.zigbee._split_response(data)
56  expected_info = {
57  'id': 'node_id_indicator',
58  'sender_addr_long': '\x00\x13\xa2\x00\x40\x52\x2b\xaa',
59  'sender_addr': '\x7d\x84',
60  'options': '\x02',
61  'source_addr': '\x7d\x84',
62  'source_addr_long': '\x00\x13\xa2\x00\x40\x52\x2b\xaa',
63  'node_id': 'Coordinator',
64  'parent_source_addr': '\xff\xfe',
65  'device_type': '\x01',
66  'source_event': '\x01',
67  'digi_profile_id': '\xc1\x05',
68  'manufacturer_id': '\x10\x1e',
69  }
70 
71  self.assertEqual(info, expected_info)
72 
73 class TestParseZigBeeIOData(unittest.TestCase):
74  """
75  Test parsing ZigBee specific IO data
76  """
77 
78  def setUp(self):
79  self.zigbee = ZigBee(None)
80 
81  def test_parse_dio_adc(self):
82  data = '\x01\x08\x00\x0e\x08\x00\x00\x00\x02P\x02\x06'
83  expected_results = [{'dio-11': True,
84  'adc-1': 0,
85  'adc-2': 592,
86  'adc-3': 518}]
87  results = self.zigbee._parse_samples(data)
88  self.assertEqual(results, expected_results)
def test_split_node_identification_identifier(self)
Definition: test_zigbee.py:33
def test_split_node_identification_identifier2(self)
Definition: test_zigbee.py:53


rosserial_xbee
Author(s): Adam Stambler
autogenerated on Mon Jun 10 2019 14:53:52