Exemplo n.º 1
0
 def test_num_data(self):
     ch = commandhandler.CommandHandler(None, True)
     ch.register_command(0x00, lambda t, d: self.cmd_callback(0x00, t, d),
                         0)
     ch.register_command(0x01, lambda t, d: self.cmd_callback(0x01, t, d),
                         1)
     ch.register_command(0x02, lambda t, d: self.cmd_callback(0x02, t, d),
                         2)
     ch.register_command(0x03, lambda t, d: self.cmd_callback(0x03, t, d),
                         3)
     ch.register_command(0x04, lambda t, d: self.cmd_callback(0x04, t, d),
                         (0, 1, 2, 3))
     ch.put(commandhandler.B42Frame(1, 0x00, None))
     self.assertEqual((1, 0x00, None), self._dispatched_commands[0])
     ch.put(commandhandler.B42Frame(2, 0x01, (1, )))
     self.assertEqual((2, 0x01, (1, )), self._dispatched_commands[1])
     ch.put(commandhandler.B42Frame(3, 0x02, (1, 2)))
     self.assertEqual((3, 0x02, (1, 2)), self._dispatched_commands[2])
     ch.put(commandhandler.B42Frame(4, 0x03, (1, 2, 3)))
     self.assertEqual((4, 0x03, (1, 2, 3)), self._dispatched_commands[3])
     ch.put(commandhandler.B42Frame(5, 0x04, None))
     self.assertEqual((5, 0x04, None), self._dispatched_commands[4])
     ch.put(commandhandler.B42Frame(6, 0x04, (1, )))
     self.assertEqual((6, 0x04, (1, )), self._dispatched_commands[5])
     ch.put(commandhandler.B42Frame(7, 0x04, (1, 2)))
     self.assertEqual((7, 0x04, (1, 2)), self._dispatched_commands[6])
     ch.put(commandhandler.B42Frame(8, 0x04, (1, 2, 3)))
     self.assertEqual((8, 0x04, (1, 2, 3)), self._dispatched_commands[7])
Exemplo n.º 2
0
 def test_commands_async(self):
     ch = commandhandler.CommandHandler(None, True)
     ch.register_command(0x01, self.cmd_callback1)
     ch.register_command(0x02, self.cmd_callback2)
     self.assertEqual(len(self._dispatched_commands), 0)
     ch.put(commandhandler.B42Frame(1, 0x01, None))
     self.assertEqual(len(self._dispatched_commands), 1)
     self.assertEqual((1, 0x01, None), self._dispatched_commands[0])
     ch.put(commandhandler.B42Frame(2, 0x01, (1, 2, 3)))
     self.assertEqual(len(self._dispatched_commands), 2)
     self.assertEqual((2, 0x01, (1, 2, 3)), self._dispatched_commands[1])
     ch.put(commandhandler.B42Frame(3, 0x02, (0, )))
     self.assertEqual(len(self._dispatched_commands), 3)
     self.assertEqual((3, 0x02, (0, )), self._dispatched_commands[2])
Exemplo n.º 3
0
 def test_num_data(self):
     ch = commandhandler.CommandHandler(self._error_q, True)
     ch.register_command(0x00, lambda t, d: self.cmd_callback(0x00, t, d),
                         0)
     ch.register_command(0x01, lambda t, d: self.cmd_callback(0x01, t, d),
                         1)
     ch.register_command(0x02, lambda t, d: self.cmd_callback(0x02, t, d),
                         2)
     ch.register_command(0x03, lambda t, d: self.cmd_callback(0x03, t, d),
                         3)
     ch.register_command(0x10, lambda t, d: self.cmd_callback(0x03, t, d),
                         (0, 2))
     self.assertTrue(self._error_q.empty())
     # no data bytes accepted
     ch.put(commandhandler.B42Frame(1, 0x00, (1, )))
     self.check_error(1, commandhandler.CMD_ERROR_NUM_DATA)
     # 1 data byte accepted
     ch.put(commandhandler.B42Frame(10, 0x01, None))
     self.check_error(10, commandhandler.CMD_ERROR_NUM_DATA)
     ch.put(commandhandler.B42Frame(12, 0x01, (1, 2)))
     self.check_error(12, commandhandler.CMD_ERROR_NUM_DATA)
     # 2 data bytes accepted
     ch.put(commandhandler.B42Frame(20, 0x02, None))
     self.check_error(20, commandhandler.CMD_ERROR_NUM_DATA)
     ch.put(commandhandler.B42Frame(21, 0x02, (1, )))
     self.check_error(21, commandhandler.CMD_ERROR_NUM_DATA)
     ch.put(commandhandler.B42Frame(23, 0x02, (1, 2, 3)))
     self.check_error(23, commandhandler.CMD_ERROR_NUM_DATA)
     # 3 data bytes accepted
     ch.put(commandhandler.B42Frame(30, 0x03, None))
     self.check_error(30, commandhandler.CMD_ERROR_NUM_DATA)
     ch.put(commandhandler.B42Frame(32, 0x03, (1, 2)))
     self.check_error(32, commandhandler.CMD_ERROR_NUM_DATA)
     ch.put(commandhandler.B42Frame(34, 0x03, (1, 2, 3, 4)))
     self.check_error(34, commandhandler.CMD_ERROR_NUM_DATA)
     # 0 or 2 data bytes accepted
     ch.put(commandhandler.B42Frame(41, 0x00, (1, )))
     self.check_error(41, commandhandler.CMD_ERROR_NUM_DATA)
     ch.put(commandhandler.B42Frame(43, 0x02, (1, 2, 3)))
     self.check_error(43, commandhandler.CMD_ERROR_NUM_DATA)
Exemplo n.º 4
0
 def test_unregistered(self):
     ch = commandhandler.CommandHandler(self._error_q, True)
     self.assertTrue(self._error_q.empty())
     # unregistered command
     ch.put(commandhandler.B42Frame(1, 0x01, None))
     self.check_error(1, commandhandler.CMD_ERROR_UNREGISTERED)