Пример #1
0
    def extract_payload_data(packet_info: cp.processing):
        # print(packet_info.reduced_bytes)

        if not packet_info.reduced_bytes.__len__() < 2:
            # Extract client id
            packet_info.client_identifier = cp.extract_string(packet_info)

        if (not packet_info.reduced_bytes.__len__() < 2
            ) and packet_info.connect_flags.will_flag:
            # Extract will topic
            packet_info.will_topic = cp.extract_string(packet_info)

        if (not packet_info.reduced_bytes.__len__() < 2
            ) and packet_info.connect_flags.will_flag:
            # Extract will message
            packet_info.will_message = cp.extract_string(packet_info)

        if (not packet_info.reduced_bytes.__len__() < 2
            ) and packet_info.connect_flags.user_name:
            # Extract user name
            packet_info.user_name = cp.extract_string(packet_info)

        if (not packet_info.reduced_bytes.__len__() < 2
            ) and packet_info.connect_flags.password:
            # Extract password
            packet_info.password = cp.extract_string(packet_info)
Пример #2
0
    def extract_variable_header(packet_info: cp.processing):
        if packet_info.reduced_bytes.__len__() < 2:
            raise Exception("Topic name not found")

        packet_info.published_topic = cp.extract_string(packet_info)
        if (packet_info.qosLevel == 1) or (packet_info.qosLevel == 2):
            packet_info.packet_identifier_msb = packet_info.pop_a_msb()
            packet_info.packet_identifier_lsb = packet_info.pop_a_msb()
Пример #3
0
def extract_string(packet_info: cp.processing):
    msb = packet_info.pop_a_msb()
    lsb = packet_info.pop_a_msb()
    string_length = (msb << 1) | lsb
    ascii_list = []
    for c in range(0, string_length):
        ascii_list.append(packet_info.pop_a_msb())

    return "".join(chr(i) for i in ascii_list)
Пример #4
0
    def extract_payload_data(packet_info: cp.processing):
        # print(packet_info.reduced_bytes)

        len = packet_info.reduced_bytes.__len__()

        while len != 0:
            len -= 1
            packet_info.published_message.append(packet_info.pop_a_msb())
Пример #5
0
 def extract_payload_data(packet_info: cp.processing):
     # print(packet_info.reduced_bytes)
     while True:
         topic_qos_pair = []
         if packet_info.reduced_bytes.__len__() < 2:
             return
         topic_qos_pair.append(cp.extract_string(packet_info))
         topic_qos_pair.append(packet_info.pop_a_msb())
         packet_info.subscribed_topics.append(topic_qos_pair)
Пример #6
0
    def extract_variable_header(packet_info: cp.processing):

        iterations = 2
        for index in range(0, iterations):

            if packet_info.reduced_bytes.__len__() < iterations:
                raise Exception(
                    "Error in packet size, can not get variable packet header "
                )

            byte = packet_info.reduced_bytes[0]
            packet_info.pop_a_msb()

            # print("byte:", byte)

            if index == 0:
                if byte != 0:
                    raise Exception("Invalid packet identifier 1")
                packet_info.packet_identifier = ((byte & 255) << 8)
                packet_info.packet_identifier_msb = byte

            # FIXME : Paho request of subscribe doesnt' match documentation of MQTTv311 section 3.8.2.1, figure 3.21
            # Documentation says the packet identifier lsb should be 10
            # But the paho is sending the packet identifier lsb equal to 1

            elif index == 1:
                # if byte != 10:
                #     print(byte)
                #     raise Exception("Invalid packet identifier 2")
                packet_info.packet_identifier = packet_info.packet_identifier | (
                    byte & 255)
                # packet_info.packet_identifier_lsb = 10
                packet_info.packet_identifier_lsb = byte
Пример #7
0
    def extract_variable_header(packet_info: cp.processing):

        iterations = 10
        for index in range(0, iterations):

            if packet_info.reduced_bytes.__len__() < iterations:
                raise Exception(
                    "Error in packet size, can not get variable packet header "
                )

            byte = packet_info.reduced_bytes[0]
            packet_info.pop_a_msb()

            # print("byte:", byte)

            if index == 0:
                if byte != 0:
                    raise Exception("Invalid Protocol (a)")

            elif index == 1:
                if byte != 4:
                    raise Exception("Invalid Protocol2 (b)")

            elif index == 2:
                if byte != 77:
                    raise Exception("Invalid Protocol (c)")

            elif index == 3:
                if byte != 81:
                    raise Exception("Invalid Protocol (d)")

            elif index == 4:
                if byte != 84:
                    raise Exception("Invalid Protocol (e)")

            elif index == 5:
                if byte != 84:
                    raise Exception("Invalid Protocol (f)")

            elif index == 6:
                packet_info.protocol_level = byte

            elif index == 7:
                packet_info.connect_flags = cp.connect_flags(byte)

            elif index == 8:
                packet_info.keep_alive = (byte & 255) << 8

            elif index == 9:
                packet_info.keep_alive = packet_info.keep_alive | (byte & 255)
Пример #8
0
    def extract_variable_header(packet_info: cp.processing):

        iterations = 2
        for index in range(0, iterations):

            if packet_info.reduced_bytes.__len__() < iterations:
                raise Exception(
                    "Error in packet size, can not get variable packet header "
                )

            byte = packet_info.reduced_bytes[0]
            packet_info.pop_a_msb()

            if index == 0:
                if byte != 0:
                    raise Exception("Invalid packet identifier 1")
                packet_info.packet_identifier = ((byte & 255) << 8)
                packet_info.packet_identifier_msb = byte

            elif index == 1:
                packet_info.packet_identifier = packet_info.packet_identifier | (
                    byte & 255)
                packet_info.packet_identifier_lsb = byte