コード例 #1
0
    def test_protocol_with_acks_and_checksum(self):
        proto_file = get_path_for_data_file("ack_frames_with_crc.proto.xml")
        protocol = ProtocolAnalyzer(signal=None, filename=proto_file)
        protocol.from_xml_file(filename=proto_file, read_bits=True)

        self.clear_message_types(protocol.messages)

        ff = FormatFinder(protocol.messages)
        ff.known_participant_addresses.clear()

        ff.run()
        self.assertEqual(
            util.convert_numbers_to_hex_string(
                ff.known_participant_addresses[0]), "1337")
        self.assertEqual(
            util.convert_numbers_to_hex_string(
                ff.known_participant_addresses[1]), "4711")

        for mt in ff.message_types:
            preamble = mt.get_first_label_with_type(
                FieldType.Function.PREAMBLE)
            self.assertEqual(preamble.start, 0)
            self.assertEqual(preamble.length, 16)
            sync = mt.get_first_label_with_type(FieldType.Function.SYNC)
            self.assertEqual(sync.start, 16)
            self.assertEqual(sync.length, 16)
            length = mt.get_first_label_with_type(FieldType.Function.LENGTH)
            self.assertEqual(length.start, 32)
            self.assertEqual(length.length, 8)
コード例 #2
0
    def test_homematic(self):
        proto_file = get_path_for_data_file("homematic.proto.xml")
        protocol = ProtocolAnalyzer(signal=None, filename=proto_file)
        protocol.message_types = []
        protocol.from_xml_file(filename=proto_file, read_bits=True)
        # prevent interfering with preassinged labels
        protocol.message_types = [MessageType("Default")]

        participants = sorted({msg.participant for msg in protocol.messages})

        self.clear_message_types(protocol.messages)
        ff = FormatFinder(protocol.messages, participants=participants)
        ff.known_participant_addresses.clear()
        ff.perform_iteration()

        self.assertGreater(len(ff.message_types), 0)

        for i, message_type in enumerate(ff.message_types):
            preamble = message_type.get_first_label_with_type(FieldType.Function.PREAMBLE)
            self.assertEqual(preamble.start, 0)
            self.assertEqual(preamble.length, 32)

            sync = message_type.get_first_label_with_type(FieldType.Function.SYNC)
            self.assertEqual(sync.start, 32)
            self.assertEqual(sync.length, 32)

            length = message_type.get_first_label_with_type(FieldType.Function.LENGTH)
            self.assertEqual(length.start, 64)
            self.assertEqual(length.length, 8)

            seq = message_type.get_first_label_with_type(FieldType.Function.SEQUENCE_NUMBER)
            self.assertEqual(seq.start, 72)
            self.assertEqual(seq.length, 8)

            src = message_type.get_first_label_with_type(FieldType.Function.SRC_ADDRESS)
            self.assertEqual(src.start, 96)
            self.assertEqual(src.length, 24)

            dst = message_type.get_first_label_with_type(FieldType.Function.DST_ADDRESS)
            self.assertEqual(dst.start, 120)
            self.assertEqual(dst.length, 24)

            checksum = message_type.get_first_label_with_type(FieldType.Function.CHECKSUM)
            self.assertEqual(checksum.length, 16)
            self.assertIn("CC1101", checksum.checksum.caption)

            for msg_index in ff.existing_message_types[message_type]:
                msg_len = len(protocol.messages[msg_index])
                self.assertEqual(checksum.start, msg_len-16)
                self.assertEqual(checksum.end, msg_len)
コード例 #3
0
    def generate_rwe(cls, num_messages: int, save_protocol=True):
        proto_file = get_path_for_data_file("rwe.proto.xml")
        protocol = ProtocolAnalyzer(signal=None, filename=proto_file)
        protocol.from_xml_file(filename=proto_file, read_bits=True)
        messages = protocol.messages

        result = ProtocolAnalyzer(None)
        message_type = MessageType("empty")
        for i in range(num_messages):
            msg = messages[i % len(messages)]  # type: Message
            msg.message_type = message_type
            result.messages.append(msg)

        if save_protocol:
            cls.save_protocol("rwe", result)

        return result
コード例 #4
0
ファイル: AWRETestCase.py プロジェクト: starling021/uh
    def get_format_finder_from_protocol_file(self,
                                             filename: str,
                                             clear_participant_addresses=True,
                                             return_messages=False):
        proto_file = get_path_for_data_file(filename)
        protocol = ProtocolAnalyzer(signal=None, filename=proto_file)
        protocol.from_xml_file(filename=proto_file, read_bits=True)

        self.clear_message_types(protocol.messages)

        ff = FormatFinder(protocol.messages)
        if clear_participant_addresses:
            ff.known_participant_addresses.clear()

        if return_messages:
            return ff, protocol.messages
        else:
            return ff