def test_shorthand_disabled(self): """ When shorthand is disabled, any attempt at calling a non-existant attribute should raise AttributeError """ self.xbee = XBeePro900(self.ser, shorthand=False) try: self.xbee.at except AttributeError: pass else: self.fail("Specified shorthand command should not exist")
def test_read_at(self): """ read and parse a parameterless AT command """ device = FakeReadDevice('\x7E\x00\x05\x88DMY\x01\x8c') xbee = XBeePro900(device) info = xbee.wait_read_frame() expected_info = { 'id': 'at_response', 'frame_id': 'D', 'command': 'MY', 'status': '\x01' } self.assertEqual(info, expected_info)
def test_send_at_command_with_param(self): """ calling send should write a full API frame containing the API AT command packet to the serial device. """ serial_port = FakeDevice() xbee = XBeePro900(serial_port) # Send an AT command xbee.send('at', frame_id='A', command='MY', parameter='\x00\x00') # Expect a full packet to be written to the device expected_data = '\x7E\x00\x06\x08AMY\x00\x00\x10' self.assertEqual(serial_port.data, expected_data)
def test_read_90(self): """ Read and parse an RX packet from an XBee-Pro 900MHz module. """ data = '~\x00L\x90\x00}3\xa2\x00@x\xcd9\xff\xfe\x02\x00\x0f\x0e/AccelX\x00\x00\x00\x00\x00\x00\xc0L?AccelY\x00\x00\x00\x00\x00\x00\xc0L?AccelZ\x00\x00\x00\x00\x00\x00\xc0L?Yaw\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0L?\xc1' device = FakeReadDevice(data) xbee = XBeePro900(device, escaped=True) info = xbee.wait_read_frame() # import pprint # pprint.pprint(info) ## {'frame_id': '\x00', ## 'id': 'rx_pro', ## 'reserved': '\xfe\x02', ## 'rf_data': '\x0f\x0e/AccelX\x00\x00\x00\x00\x00\x00\xc0L?AccelY\x00\x00\x00\x00\x00\x00\xc0L?AccelZ\x00\x00\x00\x00\x00\x00\xc0L?Yaw\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0L?', ## 'rx_opt': '\x00', ## 'source_addr_long': '\x13\xa2\x00@x\xcd9\xff'} expected_info = { 'id': 'rx', 'frame_id': '\x00', 'source_addr': '\x13\xa2\x00\x40\x78\xcd\x39', 'reserved': '\xff\xfe', 'options': '\x02', 'rf_data': '\x00\x0f\x0e/AccelX\x00\x00\x00\x00\x00\x00\xc0L?AccelY\x00\x00\x00\x00\x00\x00\xc0L?AccelZ\x00\x00\x00\x00\x00\x00\xc0L?Yaw\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0L?' } self.maxDiff = None self.assertEqual(info, expected_info)
def setUp(self): """ Prepare a fake device to read from """ self.ser = FakeDevice() self.xbee = XBeePro900(self.ser)
def setUp(self): """ Initialize XBee object """ self.xbee = XBeePro900(None)