#!/usr/bin/env python3 # Copyright 2019 Oticon A/S # Copyright 2023 Nordic Semiconductor ASA # SPDX-License-Identifier: Apache-2.0 import time import argparse import struct from csv_common import * # default max packet length (phdr + access address + pdu + crc) SNAPLEN = 512 def write(outfile, *inputs, snaplen = SNAPLEN, basetime=None): #For information on the pcap format see https://wiki.wireshark.org/Development/LibpcapFileFormat buf = bytearray(30) if basetime == None: basetime = int(time.time() * 1000000) # write pcap header struct.pack_into('= 1.0 and freq < 81.0: rf_channel = int((freq - 1.0) / 2) elif freq >= 2401.0 and freq < 2481.0: rf_channel = int((freq - 2401.0) / 2) else: raise ValueError try: pdu_crc = bytes.fromhex(row['packet']) except: #In case the packet is broken mid byte pdu_crc = bytes.fromhex("00") if len(pdu_crc) != orig_len: # Let's handle this somehow gracefully print("Truncated input file (partial packet), writing partial packet in output") orig_len = len(pdu_crc) orig_len += 5; # 4 bytes preamble + 1 bytes address/SFD incl_len = min(orig_len, snaplen) access_address = int(row['phy_address'], 16) ts = basetime + min_ts ts_sec = ts // 1000000 ts_usec = ts % 1000000 struct.pack_into('