def METHOD_NAME(port, out):
    # count incoming packets
    count = 0
    # output overall PCAP header
    out.write(pack("<LHHLLLL", MAGIC, MAJOR, MINOR, ZONE, SIG, SNAPLEN, NETWORK))
    sys.stderr.write("RX: %i\r" % count)
    while True:
        line = port.readline().rstrip()
        pkt_header = re.match(
            r">? *rftest-rx --- len (\w+).*", line.decode(errors="ignore")
        )
        if pkt_header:
            now = time()
            sec = int(now)
            usec = int((now - sec) * 1000000)
            length = int(pkt_header.group(1), 16)
            out.write(pack("<LLLL", sec, usec, length, length))
            out.flush()
            count += 1
            sys.stderr.write("RX: %i\r" % count)
            continue
        pkt_data = re.match(r"(\w\w )+", line.decode(errors="ignore"))
        if pkt_data:
            for part in line.decode(errors="ignore").split(" "):
                byte = re.match(r"(\w\w)", part)
                if byte:
                    out.write(pack("<B", int(byte.group(1), 16)))
            out.flush()