test_zigbee.py
Go to the documentation of this file.
00001 """
00002 test_zigbee.py
00003 
00004 By Paul Malmsten, 2010
00005 pmalmsten@gmail.com
00006 
00007 Tests the XBee ZB (ZigBee) implementation class for API compliance
00008 """
00009 import unittest
00010 from xbee.zigbee import ZigBee
00011 
00012 class TestZigBee(unittest.TestCase):
00013     """
00014     Tests ZigBee-specific features
00015     """
00016 
00017     def setUp(self):
00018         self.zigbee = ZigBee(None)
00019 
00020     def test_null_terminated_field(self):
00021         """
00022         Packets with null-terminated fields
00023         should be properly parsed
00024         """
00025         expected_data = '\x01\x02\x03\x04'
00026         terminator = '\x00'
00027         node_identifier = '\x95' + '\x00' * 21 + expected_data + terminator + '\x00' * 8
00028 
00029         data = self.zigbee._split_response(node_identifier)
00030 
00031         self.assertEqual(data['node_id'], expected_data)
00032 
00033     def test_split_node_identification_identifier(self):
00034             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'
00035             info = self.zigbee._split_response(data)
00036             expected_info = {
00037                 'id': 'node_id_indicator',
00038                 'sender_addr_long': '\x00\x13\xa2\x00\x40\x52\x2b\xaa',
00039                 'sender_addr': '\x7d\x84',
00040                 'options': '\x02',
00041                 'source_addr': '\x7d\x84',
00042                 'source_addr_long': '\x00\x13\xa2\x00\x40\x52\x2b\xaa',
00043                 'node_id': ' ',
00044                 'parent_source_addr': '\xff\xfe',
00045                 'device_type': '\x01',
00046                 'source_event': '\x01',
00047                 'digi_profile_id': '\xc1\x05',
00048                 'manufacturer_id': '\x10\x1e',
00049             }
00050             
00051             self.assertEqual(info, expected_info)
00052             
00053     def test_split_node_identification_identifier2(self):
00054             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'
00055             info = self.zigbee._split_response(data)
00056             expected_info = {
00057                 'id': 'node_id_indicator',
00058                 'sender_addr_long': '\x00\x13\xa2\x00\x40\x52\x2b\xaa',
00059                 'sender_addr': '\x7d\x84',
00060                 'options': '\x02',
00061                 'source_addr': '\x7d\x84',
00062                 'source_addr_long': '\x00\x13\xa2\x00\x40\x52\x2b\xaa',
00063                 'node_id': 'Coordinator',
00064                 'parent_source_addr': '\xff\xfe',
00065                 'device_type': '\x01',
00066                 'source_event': '\x01',
00067                 'digi_profile_id': '\xc1\x05',
00068                 'manufacturer_id': '\x10\x1e',
00069             }
00070             
00071             self.assertEqual(info, expected_info)
00072 
00073 class TestParseZigBeeIOData(unittest.TestCase):
00074     """
00075     Test parsing ZigBee specific IO data
00076     """
00077 
00078     def setUp(self):
00079         self.zigbee = ZigBee(None)
00080 
00081     def test_parse_dio_adc(self):
00082             data = '\x01\x08\x00\x0e\x08\x00\x00\x00\x02P\x02\x06'
00083             expected_results = [{'dio-11': True,
00084                                  'adc-1': 0,
00085                                  'adc-2': 592,
00086                                  'adc-3': 518}]
00087             results = self.zigbee._parse_samples(data)
00088             self.assertEqual(results, expected_results)


rosserial_xbee
Author(s): Adam Stambler
autogenerated on Fri Aug 28 2015 12:44:47