From cbdbd30c3951f6b98701a299af1ca98407c6d033 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Tue, 9 Mar 2021 11:05:59 +0100 Subject: [PATCH] selective repeating first try --- data_handler.py | 6 ++++-- modem.py | 13 +++++++++---- sock.py | 16 ++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/data_handler.py b/data_handler.py index 8196571c..20e61133 100644 --- a/data_handler.py +++ b/data_handler.py @@ -643,6 +643,7 @@ def arq_disconnect_received(data_in): def transmit_ping(callsign): static.DXCALLSIGN = bytes(callsign, 'utf-8') + static.DXCALLSIGN_CRC8 = helpers.get_crc_8(static.DXCALLSIGN) logging.info("PING ["+ str(static.MYCALLSIGN, 'utf-8') + "] >>> [" + str(static.DXCALLSIGN, 'utf-8') + "] [BER."+str(static.BER)+"]") ping_frame = bytearray(14) @@ -692,7 +693,7 @@ async def transmit_cq(): cq_frame = bytearray(14) cq_frame[:1] = bytes([200]) - cq_frame[1:2] = bytes(1) #b'\x00' + cq_frame[1:2] = b'\x01' #b'\x00' cq_frame[2:3] = static.MYCALLSIGN_CRC8 cq_frame[3:9] = static.MYCALLSIGN @@ -704,7 +705,8 @@ async def transmit_cq(): time.sleep(0.1) def received_cq(data_in): - + static.DXCALLSIGN = b'' + static.DXCALLSIGN_CRC8 = b'' logging.info("CQ [" + str(bytes(data_in[3:9]), 'utf-8') + "] [BER."+str(static.BER)+"]") async def transmit_beacon(): diff --git a/modem.py b/modem.py index 2bc2aa39..2af02f55 100644 --- a/modem.py +++ b/modem.py @@ -337,8 +337,8 @@ class RF(): stuck_in_sync_10_counter = 0 #----------------------------------- - - if nbytes == bytes_per_frame:##########################################################FREEDV_DATA_BYTES_PER_FRAME + # forward data only if broadcast or we are the receiver + if nbytes == bytes_per_frame and bytes(bytes_out[1:2]) == static.MYCALLSIGN_CRC8 or bytes(bytes_out[1:2]) == b'\x01': self.calculate_ber(freedv) # counter reset for stuck in sync counter @@ -425,7 +425,7 @@ class RF(): # ARQ CONNECT ACK / KEEP ALIVE elif frametype == 230: logging.debug("BEACON RECEIVED") - + else: logging.info("OTHER FRAME: " + str(bytes_out[:-2])) print(frametype) @@ -435,7 +435,12 @@ class RF(): logging.debug("LAST FRAME ---> UNSYNC") self.c_lib.freedv_set_sync(freedv, 0) #FORCE UNSYNC - + + # clear bytes_out buffer to be ready for next frames after successfull decoding + + bytes_out = (ctypes.c_ubyte * bytes_per_frame) + bytes_out = bytes_out() #get pointer to bytes_out + def calculate_ber(self,freedv): Tbits = self.c_lib.freedv_get_total_bits(freedv) Terrs = self.c_lib.freedv_get_total_bit_errors(freedv) diff --git a/sock.py b/sock.py index d1f21603..425dfd64 100644 --- a/sock.py +++ b/sock.py @@ -37,18 +37,14 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler): # SOCKETTEST --------------------------------------------------- if data == 'SOCKETTEST': - cur_thread = threading.current_thread() + #cur_thread = threading.current_thread() response = bytes("WELL DONE! YOU ARE ABLE TO COMMUNICATE WITH THE TNC", encoding) self.request.sendall(response) # CQ CQ CQ ----------------------------------------------------- if data == 'CQCQCQ': - for i in range(0,3): - asyncio.run(data_handler.transmit_cq()) - #self.request.sendall(bytes("CALLING CQ")) - while static.ARQ_STATE == 'SENDING_SIGNALLING': - time.sleep(0.1) - pass + asyncio.run(data_handler.transmit_cq()) + self.request.sendall(b'CALLING CQ') # PING ---------------------------------------------------------- @@ -141,9 +137,9 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler): if data == 'GET:TNC_STATE': output = { "PTT_STATE": str(static.PTT_STATE), - "CHANNEL_STATE": static.CHANNEL_STATE, - "TNC_STATE": static.TNC_STATE, - "ARQ_STATE": static.ARQ_STATE + "CHANNEL_STATE": str(static.CHANNEL_STATE), + "TNC_STATE": str(static.TNC_STATE), + "ARQ_STATE": str(static.ARQ_STATE) } jsondata = json.dumps(output) self.request.sendall(bytes(jsondata, encoding))