Example #1
0
 def pack(self):
     self.checksum = 0
     packet = bitstruct.pack_dict(IP_HEADER_STRUCT, IP_HEADER_NAMES,
                                  self.__dict__)
     self.checksum = ip_checksum(packet)
     return bitstruct.pack_dict(IP_HEADER_STRUCT, IP_HEADER_NAMES,
                                self.__dict__) + self.data
Example #2
0
def pack_operation_mode_bytes(operation_mode_data):
    operation_mode_bytes = bitstruct.pack_dict('u1u2u1b1b1b1b1b1b1b1u4', [
        'device_type', 'uwb_mode', 'fw_version', 'accelerometer_enable',
        'led_enable', 'fw_update_enable', 'reserved_01', 'initiator',
        'low_power_mode', 'location_engine', 'reserved_02'
    ], operation_mode_data)
    return operation_mode_bytes
Example #3
0
    def pack(self):
        self.checksum = 0
        options = 4 * b"\x00"  # not including this makes Wireshark suspicious

        # construct fake packet for checksum calculation
        tcp_packet = bitstruct.pack_dict(TCP_HEADER_STRUCT, TCP_HEADER_NAMES,
                                         self.__dict__) + options
        ip_header = bitstruct.pack_dict(
            PSEUDO_IP_HEADER_STRUCT, PSEUDO_IP_HEADER_NAMES, {
                "src_addr": self.src_addr,
                "dst_addr": self.dst_addr,
                "protocol": PROTOCOL_TCP,
                "tcp_len": len(tcp_packet)
            })

        # construct real packet
        self.checksum = ip_checksum(ip_header + tcp_packet + self.data)
        return bitstruct.pack_dict(TCP_HEADER_STRUCT, TCP_HEADER_NAMES,
                                   self.__dict__) + options + self.data
Example #4
0
def CmdToHex(cmd, addr, value):
    """convert the physical meaning to raw tlf35584 command to be send to TLF35584 ."""
    parity = 1 if (
        (bin(cmd).count("1") + bin(addr).count("1") + bin(value).count("1")) %
        2) == 1 else 0
    packed = bitstruct.pack_dict('u1u6u8u1', ['RW', 'Addr', 'Value', 'P'], {
        'RW': cmd,
        'Addr': addr,
        'Value': value,
        'P': parity
    })
    print("0X{}".format(packed.hex()))
    return packed.hex()
Example #5
0
def pack_persisted_position_bytes(persisted_position_data):
    persisted_position_bytes = bitstruct.pack_dict(
        's32s32s32u8<', ['x_position', 'y_position', 'z_position', 'quality'],
        persisted_position_data)
    return persisted_position_bytes
Example #6
0
def pack_update_rate_bytes(update_rate_data):
    update_rate_bytes = bitstruct.pack_dict(
        'u32u32<', ['moving_update_rate', 'stationary_update_rate'],
        update_rate_data)
    return update_rate_bytes
Example #7
0
 def pack(self):
     return bitstruct.pack_dict(ARP_STRUCT, ARP_NAMES, self.__dict__)
Example #8
0
 def pack(self):
     return bitstruct.pack_dict(ETHERNET_HEADER_STRUCT,
                                ETHERNET_HEADER_NAMES,
                                self.__dict__) + self.data