Example #1
0
    def test_023_test_serialize_deserialize(self):
        """ Test serializing and deserializing a DeviceBusPacket
        """
        dbp = DeviceBusPacket(sequence=0x00,
                              device_type=0x00,
                              board_id=0x00000000,
                              device_id=0x0000,
                              data=[0x0, 0x0, 0x0])

        packet = dbp.serialize()

        # F everything out so we know deserialization actually did something
        dbp.sequence = 0xFF
        dbp.device_type = 0xFF
        dbp.board_id = 0xFFFFFFFF
        dbp.device_id = 0xFFFF
        dbp.data = [0xFF, 0xFF]

        dbp.deserialize(packet)

        self.assertEqual(dbp.sequence, 0x00)
        self.assertEqual(dbp.device_type, 0x00)
        self.assertEqual(dbp.board_id, 0x00000000)
        self.assertEqual(dbp.device_id, 0x0000)
        self.assertEqual(dbp.data, [0x0, 0x0, 0x0])
Example #2
0
    def test_024_test_serialize_deserialize(self):
        """ Test serializing and deserializing a DeviceBusPacket
        """
        dbp = DeviceBusPacket(sequence=0xA0,
                              device_type=0xB3,
                              board_id=0xFA00B3E9,
                              device_id=0xF011,
                              data=[0x1B, 0xAA, 0xF0])

        packet = dbp.serialize()

        # 0 everything out so we know deserialization actually did something
        dbp.sequence = 0
        dbp.device_type = 0
        dbp.board_id = 0
        dbp.device_id = 0
        dbp.data = [0]

        dbp.deserialize(packet)

        self.assertEqual(dbp.sequence, 0xA0)
        self.assertEqual(dbp.device_type, 0xB3)
        self.assertEqual(dbp.board_id, 0xFA00B3E9)
        self.assertEqual(dbp.device_id, 0xF011)
        self.assertEqual(dbp.data, [0x1B, 0xAA, 0xF0])
Example #3
0
    def test_021_test_serialize_deserialize(self):
        """ Test serializing and deserializing a DeviceBusPacket
        """
        dbp = DeviceBusPacket(sequence=0x03,
                              device_type=0x40,
                              board_id=0x12345678,
                              device_id=0xAA05,
                              data=[0x1, 0x2, 0x3])

        packet = dbp.serialize()

        # 0 everything out so we know deserialization actually did something
        dbp.sequence = 0
        dbp.device_type = 0
        dbp.board_id = 0
        dbp.device_id = 0
        dbp.data = [0]

        dbp.deserialize(packet)

        self.assertEqual(dbp.sequence, 0x03)
        self.assertEqual(dbp.device_type, 0x40)
        self.assertEqual(dbp.board_id, 0x12345678)
        self.assertEqual(dbp.device_id, 0xAA05)
        self.assertEqual(dbp.data, [0x1, 0x2, 0x3])
Example #4
0
    def test_009_invalid_devicebus_packet_deserialize(self):
        """ Test deserializing a packet when the length of the packet is less than
        the minimum packet length
        """
        dbp = DeviceBusPacket()

        # invalid packet
        packet = [1, 12, 3, 64, 18, 52, 86, 120, 170, 244, 4]
        with self.assertRaises(BusDataException):
            dbp.deserialize(packet)
Example #5
0
    def test_013_invalid_devicebus_packet_deserialize(self):
        """ Test deserializing a packet where the trailer byte is invalid
        """
        dbp = DeviceBusPacket()

        # invalid packet
        packet = [
            0x00, 0x0B, 0x03, 0x40, 0x12, 0x34, 0x56, 0x78, 0xAA, 0x05, 0x1,
            0x2, 0x3, 0xf4, 0x03
        ]
        with self.assertRaises(BusDataException):
            dbp.deserialize(packet)
Example #6
0
    def test_010_invalid_devicesbus_packet_deserialize(self):
        """ Test deserializing a packet with an invalid header byte
        """
        dbp = DeviceBusPacket()

        # invalid packet
        packet = [
            0x00, 0x0C, 0x03, 0x40, 0x12, 0x34, 0x56, 0x78, 0xAA, 0x05, 0x1,
            0x2, 0x3, 0xf4, 0x04
        ]
        with self.assertRaises(BusDataException):
            dbp.deserialize(packet)
Example #7
0
    def test_012_invalid_devicebus_packet_deserialize(self):
        """ Test deserializing a packet when the packet checksum doesnt match the
        generated checksum
        """
        dbp = DeviceBusPacket()

        # invalid packet
        packet = [
            0x00, 0x0B, 0x03, 0x40, 0x12, 0x34, 0x56, 0x78, 0xAA, 0x05, 0x1,
            0x2, 0x3, 0xf0, 0x04
        ]
        with self.assertRaises(BusDataException):
            dbp.deserialize(packet)
Example #8
0
    def test_011_invalid_devicebus_packet_deserialize(self):
        """ Test deserializing a packet whose length byte doesnt match the length of
        the packet
        """
        dbp = DeviceBusPacket()

        # invalid packet
        packet = [
            0x00, 0x0B, 0x03, 0x40, 0x12, 0x34, 0x56, 0x78, 0xAA, 0x05, 0x1,
            0x2, 0x3, 0xf4, 0x04
        ]
        with self.assertRaises(BusDataException):
            dbp.deserialize(packet)
Example #9
0
    def test_008_valid_devicebus_packet_deserialize(self):
        """ Test deserializing a packet
        """
        dbp = DeviceBusPacket()

        # use a known packet
        packet = [1, 12, 3, 64, 18, 52, 86, 120, 170, 5, 1, 2, 3, 244, 4]
        dbp.deserialize(packet)

        self.assertEqual(dbp.sequence, 0x03)
        self.assertEqual(dbp.device_type, 0x40)
        self.assertEqual(dbp.board_id, 0x12345678)
        self.assertEqual(dbp.device_id, 0xAA05)
        self.assertEqual(dbp.data, [0x1, 0x2, 0x3])