diff --git a/onbeat_rx_wrapper.py b/onbeat_rx_wrapper.py new file mode 100644 index 0000000..bcd0273 --- /dev/null +++ b/onbeat_rx_wrapper.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import asyncio +import framing +from header import Onbeat_Header +import json + +PACKET_LEN=255*4 + 32 +DATA_LEN=223*4 +HEADER_LEN=32 + + +async def tcp_client(): + port = 50002 + reader, _ = await asyncio.open_connection( + '127.0.0.1', port) + output: list[tuple[Onbeat_Header, list[int]]] = [] + packet_loss = 0 + while message := await reader.read(PACKET_LEN): + try: + received = framing.decode_packet([i for i in message]) + output.append(received) + if received[0].pkt_len == 0: + break + except KeyboardInterrupt: + break + except Exception as e: + packet_loss += 1 + print(e) + + return output + + +rs_coding = False +filename = "loremipsum" +received = asyncio.run(tcp_client()) + + + +with open("rx_packets.json") as packetfile: + json.dump(received, packetfile) diff --git a/onbeat_tx_wrapper.py b/onbeat_tx_wrapper.py new file mode 100644 index 0000000..a0fc753 --- /dev/null +++ b/onbeat_tx_wrapper.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import asyncio +from time import sleep +import framing +# from header import Onbeat_Header +import json + +PACKET_LEN=255*4 + 32 +DATA_LEN=223*4 +HEADER_LEN=32 + + +async def tcp_client(file_2_send: str, callsign: str, rs_coding: bool = True): + port = 50001 + _, writer = await asyncio.open_connection( + '127.0.0.1', port) + with open(file_2_send, "rb") as file_to_send: + seq = 0 + sent: list[list[int]] = [] + try: + while message := file_to_send.read(DATA_LEN if rs_coding == True else (PACKET_LEN - HEADER_LEN)): + sent.append([i for i in message]) + frame = bytes(framing.encode_packet([i for i in message], callsign, seq, rs_coding)) + writer.write(frame) + seq += 1 + sleep(0.1) + else: + frame = bytes(framing.encode_packet([], callsign, seq, rs_coding)) + for _ in range(0,16): + writer.write(frame) + sleep(0.1) + sent.append([]) + except KeyboardInterrupt: + return sent + + +rs_coding = False +filename = "loremipsum" +sent = asyncio.run(tcp_client(filename, "HA5PLS", rs_coding)) + + + +with open("packets.json") as packetfile: + json.dump(sent, packetfile)