Пример #1
0
 def test_send_at_command(self):
     """
     calling send should write a full API frame containing the
     API AT command packet to the serial device.
     """
     
     serial_port = FakeDevice()
     xbee = XBee(serial_port)
     
     # Send an AT command
     xbee.send('at', frame_id=stringToBytes('A'), command=stringToBytes('MY'))
     
     # Expect a full packet to be written to the device
     expected_data = b'\x7E\x00\x04\x08AMY\x10'
     self.assertEqual(serial_port.data, expected_data)
Пример #2
0
 def test_send_at_command(self):
     """
     calling send should write a full API frame containing the
     API AT command packet to the serial device.
     """
     
     serial_port = FakeDevice()
     xbee = XBee(serial_port)
     
     # Send an AT command
     xbee.send('at', frame_id=stringToBytes('A'), command=stringToBytes('MY'))
     
     # Expect a full packet to be written to the device
     expected_data = b'\x7E\x00\x04\x08AMY\x10'
     self.assertEqual(serial_port.data, expected_data)
Пример #3
0
    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 = XBee(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)
Пример #4
0
    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 = Serial()
        xbee = XBee(serial_port)

        # Send an AT command
        xbee.send('at',
                  frame_id=stringToBytes('A'),
                  command=stringToBytes('MY'),
                  parameter=b'\x00\x00')

        # Expect a full packet to be written to the device
        result_data = serial_port.get_data_written()
        expected_data = b'\x7E\x00\x06\x08AMY\x00\x00\x10'
        self.assertEqual(result_data, expected_data)
Пример #5
0
 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 = XBee(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)
 if xbee_relay_IF.connected():
     msgs = xbee_relay_IF.tick()
     for typ,msg,client in msgs:
         if typ == 'xbee_relay_cmd_pb2':
             cmd_msg = xbee_relay_cmd_pb2.XBee_Relay_Cmd()
             cmd_msg.ParseFromString(msg);
             if ( cmd_msg.command == xbee_relay_cmd_pb2.XBee_Relay_Cmd.FORWARD_TO_XBEE ):
                 if send_to_xbee(cmd_msg.to.upper(), cmd_msg.data):
                     pass
                 else:
                     resp = xbee_relay_resp_pb2.XBee_Relay_Resp()
                     resp.seq_no = cmd_msg.seq_no
                     resp.cod = xbee_relay_resp_pb2.XBee_Relay_Resp.ADDRESS_NOT_FOUND
             elif ( cmd_msg.command == xbee_relay_cmd_pb2.XBee_Relay_Cmd.BROADCAST_TO_XBEE ):
                 if IEEE_BROADCAST:
                     xbee.send('tx_long_addr',dest_addr='\x00\x00\x00\x00\x00\x00\xFF\xFF',data=cmd_msg.data)
                 else:
                     for d in children_cache:
                         send_to_xbee(d,cmd_msg.data)
             else:
                 print "Unknown command code"
         elif typ == 'xbee_relay_resp_pb2':
             resp_msg = xbee_relay_resp_pb2.XBee_Relay_Resp()
             resp_msg.ParseFromString(msg);
         else:
             pass
 else:
     xbee_relay_IF.reconnect();
     if xbee_relay_IF.connected():
         xbee_relay_IF.register_as_relay();