From 5588df2ded9ce11dcca00b38b530d6db0f824e01 Mon Sep 17 00:00:00 2001 From: dj2ls Date: Sun, 22 Jan 2023 15:19:42 +0100 Subject: [PATCH 01/19] reject command if already in ARQ STATE --- tnc/sock.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tnc/sock.py b/tnc/sock.py index ac14c592..817d1ef8 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -470,10 +470,20 @@ def process_tnc_commands(data): if received_json["type"] == "arq" and received_json["command"] == "send_raw": static.BEACON_PAUSE = True + # we need to reject a command processing if already in arq state + if static.ARQ_STATE: + command_response("send_raw", False) + log.warning( + "[SCK] Send raw command execution error", + e="already in arq state", + command=received_json, + ) + return False + try: if not static.ARQ_SESSION: dxcallsign = received_json["parameter"][0]["dxcallsign"] - # additional step for beeing sure our callsign is correctly + # additional step for being sure our callsign is correctly # in case we are not getting a station ssid # then we are forcing a station ssid = 0 dxcallsign = helpers.callsign_to_bytes(dxcallsign) @@ -504,7 +514,7 @@ def process_tnc_commands(data): except Exception: # 15 == self.session_connect_max_retries - attempts = 15 + attempts = 10 # check if transmission uuid provided else set no-uuid try: @@ -517,6 +527,9 @@ def process_tnc_commands(data): binarydata = base64.b64decode(base64data) + # wait some random time which acts as collision detection + helpers.wait(randrange(0, 20, 5) / 10.0) + DATA_QUEUE_TRANSMIT.put( ["ARQ_RAW", binarydata, mode, n_frames, arq_uuid, mycallsign, dxcallsign, attempts] ) From 1d053e57dcc88a587cbcba3b9c6964bd9cad4691 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:28:34 +0100 Subject: [PATCH 02/19] fixed macOS build folder path --- .github/workflows/build_multiplatform.yml | 24 ++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_multiplatform.yml b/.github/workflows/build_multiplatform.yml index ff00e89a..75bd8387 100644 --- a/.github/workflows/build_multiplatform.yml +++ b/.github/workflows/build_multiplatform.yml @@ -294,8 +294,8 @@ jobs: # now build tnc binaries pyinstaller -y freedata.spec # and to some final cleanup - cp -r -f dist/tnc/* dist/ - rm -r dist/tnc + # cp -r -f dist/tnc/* dist/ + # rm -r dist/tnc - name: Build binaries Linux and Windows if: ${{!startsWith(matrix.os, 'macos')}} @@ -338,10 +338,23 @@ jobs: - name: LIST ALL FILES run: ls -R - - name: Download Portaudio binaries + - name: Download Portaudio binaries Linux macOS + if: ${{!startsWith(matrix.os, 'windows')}} working-directory: tnc run: | - git clone https://github.com/spatialaudio/portaudio-binaries dist/tnc/_sounddevice_data/portaudio-binaries + if ! test -d "dist/_sounddevice_data"; then + git clone https://github.com/spatialaudio/portaudio-binaries dist/_sounddevice_data/portaudio-binaries + fi + + - name: Download Portaudio binaries Windows + if: ${{startsWith(matrix.os, 'windows')}} + working-directory: tnc + run: | + if(Test-Path -Path "dist/_sounddevice_data"){ + echo "sounddevice folder already exists" + } else { + git clone https://github.com/spatialaudio/portaudio-binaries dist/_sounddevice_data/portaudio-binaries + } - name: LIST ALL FILES run: ls -R @@ -355,9 +368,6 @@ jobs: - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 - env: - APPLE_ID: ${{ secrets.APPLE_ID }} - APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }} with: package_root: "./gui/" github_token: ${{ secrets.github_token }} From 911d44fec73d0f804fb9a2bb07c067b181028952 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Sun, 22 Jan 2023 19:58:07 +0100 Subject: [PATCH 03/19] version update --- gui/package.json | 2 +- tnc/static.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/package.json b/gui/package.json index 5733e0a8..23d48169 100644 --- a/gui/package.json +++ b/gui/package.json @@ -1,6 +1,6 @@ { "name": "FreeDATA", - "version": "0.6.12-alpha.1", + "version": "0.6.12-alpha.2", "description": "FreeDATA ", "main": "main.js", "scripts": { diff --git a/tnc/static.py b/tnc/static.py index 78174ffd..45d4e166 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -11,7 +11,7 @@ Not nice, suggestions are appreciated :-) import subprocess from enum import Enum -VERSION = "0.6.12-alpha.1" +VERSION = "0.6.12-alpha.2" ENABLE_EXPLORER = False From ccf76f67806faa43d677662382171047013be196 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Sun, 22 Jan 2023 21:47:14 +0100 Subject: [PATCH 04/19] possible hotfix for missing portaudio --- .github/workflows/build_multiplatform.yml | 6 +++--- gui/package.json | 2 +- tnc/daemon.py | 25 +++++++++++++++++++---- tnc/static.py | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build_multiplatform.yml b/.github/workflows/build_multiplatform.yml index 75bd8387..1a418526 100644 --- a/.github/workflows/build_multiplatform.yml +++ b/.github/workflows/build_multiplatform.yml @@ -342,8 +342,8 @@ jobs: if: ${{!startsWith(matrix.os, 'windows')}} working-directory: tnc run: | - if ! test -d "dist/_sounddevice_data"; then - git clone https://github.com/spatialaudio/portaudio-binaries dist/_sounddevice_data/portaudio-binaries + if ! test -d "dist/tnc/_sounddevice_data"; then + git clone https://github.com/spatialaudio/portaudio-binaries dist/tnc/_sounddevice_data/portaudio-binaries fi - name: Download Portaudio binaries Windows @@ -353,7 +353,7 @@ jobs: if(Test-Path -Path "dist/_sounddevice_data"){ echo "sounddevice folder already exists" } else { - git clone https://github.com/spatialaudio/portaudio-binaries dist/_sounddevice_data/portaudio-binaries + git clone https://github.com/spatialaudio/portaudio-binaries dist/tnc/_sounddevice_data/portaudio-binaries } - name: LIST ALL FILES diff --git a/gui/package.json b/gui/package.json index 23d48169..6c489339 100644 --- a/gui/package.json +++ b/gui/package.json @@ -1,6 +1,6 @@ { "name": "FreeDATA", - "version": "0.6.12-alpha.2", + "version": "0.6.12-alpha.3", "description": "FreeDATA ", "main": "main.js", "scripts": { diff --git a/tnc/daemon.py b/tnc/daemon.py index 7a013b4f..0b9ced02 100755 --- a/tnc/daemon.py +++ b/tnc/daemon.py @@ -262,15 +262,30 @@ class DAEMON: # safe data to config file config.write_entire_config(data) + import os, sys + import sys + + + # Try running tnc from binary, else run from source # This helps running the tnc in a developer environment try: command = [] - if sys.platform in ["linux", "darwin"]: - command.append("./freedata-tnc") - elif sys.platform in ["win32", "win64"]: - command.append("freedata-tnc.exe") + + if getattr(sys, 'frozen', False): + # If the application is run as a bundle, the PyInstaller bootloader + # extends the sys module by a flag frozen=True and sets the app + # path into variable _MEIPASS'. + application_path = sys._MEIPASS + command.append(application_path + '/freedata-tnc') + + else: + + if sys.platform in ["linux", "darwin"]: + command.append("./freedata-tnc") + elif sys.platform in ["win32", "win64"]: + command.append("freedata-tnc.exe") command += options proc = subprocess.Popen(command) @@ -281,6 +296,7 @@ class DAEMON: except FileNotFoundError as err1: self.log.info("[DMN] worker: ", e=err1) command = [] + if sys.platform in ["linux", "darwin"]: command.append("python3") elif sys.platform in ["win32", "win64"]: @@ -288,6 +304,7 @@ class DAEMON: command.append("main.py") command += options + print(command) proc = subprocess.Popen(command) atexit.register(proc.kill) diff --git a/tnc/static.py b/tnc/static.py index 45d4e166..6cc7b20e 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -11,7 +11,7 @@ Not nice, suggestions are appreciated :-) import subprocess from enum import Enum -VERSION = "0.6.12-alpha.2" +VERSION = "0.6.12-alpha.3" ENABLE_EXPLORER = False From 408761f1c9f382060cb16e5bf4a3e13011bfa6ba Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Sun, 22 Jan 2023 22:05:07 +0100 Subject: [PATCH 05/19] fixed path env --- .github/workflows/build_multiplatform.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build_multiplatform.yml b/.github/workflows/build_multiplatform.yml index 1a418526..a289da6c 100644 --- a/.github/workflows/build_multiplatform.yml +++ b/.github/workflows/build_multiplatform.yml @@ -368,6 +368,9 @@ jobs: - name: Build/release Electron app uses: samuelmeuli/action-electron-builder@v1 + env: + APPLE_ID: ${{ secrets.APPLE_ID }} + APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }} with: package_root: "./gui/" github_token: ${{ secrets.github_token }} From e74a524f7c41f8692a147fe328716aaa214d820d Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Sun, 22 Jan 2023 22:05:29 +0100 Subject: [PATCH 06/19] version update --- gui/package.json | 2 +- tnc/static.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/package.json b/gui/package.json index 6c489339..91e6bf00 100644 --- a/gui/package.json +++ b/gui/package.json @@ -1,6 +1,6 @@ { "name": "FreeDATA", - "version": "0.6.12-alpha.3", + "version": "0.6.12-alpha.4", "description": "FreeDATA ", "main": "main.js", "scripts": { diff --git a/tnc/static.py b/tnc/static.py index 6cc7b20e..f46f5959 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -11,7 +11,7 @@ Not nice, suggestions are appreciated :-) import subprocess from enum import Enum -VERSION = "0.6.12-alpha.3" +VERSION = "0.6.12-alpha.4" ENABLE_EXPLORER = False From ce776fb1006f9f130e5ec9cf46b800609b6da3dd Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Sun, 22 Jan 2023 22:39:23 +0100 Subject: [PATCH 07/19] fixed wrong pyinstaller env detection for windows --- gui/package.json | 2 +- tnc/daemon.py | 2 +- tnc/static.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/package.json b/gui/package.json index 91e6bf00..b82ff9f9 100644 --- a/gui/package.json +++ b/gui/package.json @@ -1,6 +1,6 @@ { "name": "FreeDATA", - "version": "0.6.12-alpha.4", + "version": "0.6.12-alpha.5", "description": "FreeDATA ", "main": "main.js", "scripts": { diff --git a/tnc/daemon.py b/tnc/daemon.py index 0b9ced02..c7b5b5bc 100755 --- a/tnc/daemon.py +++ b/tnc/daemon.py @@ -273,7 +273,7 @@ class DAEMON: try: command = [] - if getattr(sys, 'frozen', False): + if (getattr(sys, 'frozen', False) or hasattr(sys, "_MEIPASS")) and sys.platform in ["darwin"]: # If the application is run as a bundle, the PyInstaller bootloader # extends the sys module by a flag frozen=True and sets the app # path into variable _MEIPASS'. diff --git a/tnc/static.py b/tnc/static.py index f46f5959..2b3e7f25 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -11,7 +11,7 @@ Not nice, suggestions are appreciated :-) import subprocess from enum import Enum -VERSION = "0.6.12-alpha.4" +VERSION = "0.6.12-alpha.5" ENABLE_EXPLORER = False From 5221a0bd718f471755989688e8f7d72cf1733517 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Sun, 22 Jan 2023 23:35:52 +0100 Subject: [PATCH 08/19] finally working macOS build --- gui/package.json | 2 +- tnc/codec2.py | 13 ++++++++----- tnc/static.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gui/package.json b/gui/package.json index b82ff9f9..d7a80412 100644 --- a/gui/package.json +++ b/gui/package.json @@ -1,6 +1,6 @@ { "name": "FreeDATA", - "version": "0.6.12-alpha.5", + "version": "0.6.12-alpha.6", "description": "FreeDATA ", "main": "main.js", "scripts": { diff --git a/tnc/codec2.py b/tnc/codec2.py index f9219c2f..903dd04a 100644 --- a/tnc/codec2.py +++ b/tnc/codec2.py @@ -60,17 +60,20 @@ def freedv_get_mode_name_by_value(mode: int) -> str: # Check if we are running in a pyinstaller environment -if hasattr(sys, "_MEIPASS"): - sys.path.append(getattr(sys, "_MEIPASS")) -else: - sys.path.append(os.path.abspath(".")) +#if hasattr(sys, "_MEIPASS"): +# sys.path.append(getattr(sys, "_MEIPASS")) +#else: +sys.path.append(os.path.abspath(".")) log.info("[C2 ] Searching for libcodec2...") if sys.platform == "linux": files = glob.glob(r"**/*libcodec2*", recursive=True) files.append("libcodec2.so") elif sys.platform == "darwin": - files = glob.glob(r"**/*libcodec2*.dylib", recursive=True) + if hasattr(sys, "_MEIPASS"): + files = glob.glob(getattr(sys, "_MEIPASS") + '/**/*libcodec2*', recursive=True) + else: + files = glob.glob(r"**/*libcodec2*.dylib", recursive=True) elif sys.platform in ["win32", "win64"]: files = glob.glob(r"**\*libcodec2*.dll", recursive=True) else: diff --git a/tnc/static.py b/tnc/static.py index 2b3e7f25..af52a46b 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -11,7 +11,7 @@ Not nice, suggestions are appreciated :-) import subprocess from enum import Enum -VERSION = "0.6.12-alpha.5" +VERSION = "0.6.12-alpha.6" ENABLE_EXPLORER = False From 2e78c851e485008c315c40cea86117faf6da2d6e Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 12:30:07 +0100 Subject: [PATCH 09/19] replacing dxgrid with spaces where no valid data available #340 --- tnc/data_handler.py | 47 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 4284a19f..ea3ce40a 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -662,6 +662,7 @@ class DATA: self.log.debug("[TNC] static.RX_BURST_BUFFER", buffer=static.RX_BURST_BUFFER) + static.DXGRID = b'------' helpers.add_to_heard_stations( static.DXCALLSIGN, static.DXGRID, @@ -1332,8 +1333,9 @@ class DATA: """ # Process data only if we are in ARQ and BUSY state if static.ARQ_STATE: + static.DXGRID = b'------' helpers.add_to_heard_stations( - static.DXCALLSIGN, + self.dxcallsign, static.DXGRID, "DATA-CHANNEL", static.SNR, @@ -1382,6 +1384,7 @@ class DATA: """Received an ACK for a transmitted frame""" # Process data only if we are in ARQ and BUSY state if static.ARQ_STATE: + static.DXGRID = b'------' helpers.add_to_heard_stations( static.DXCALLSIGN, static.DXGRID, @@ -1416,6 +1419,7 @@ class DATA: dxcallsign=str(self.dxcallsign, 'UTF-8'), ) + static.DXGRID = b'------' helpers.add_to_heard_stations( static.DXCALLSIGN, static.DXGRID, @@ -1449,6 +1453,7 @@ class DATA: """ # Only process data if we are in ARQ and BUSY state if static.ARQ_STATE and static.TNC_STATE == "BUSY": + static.DXGRID = b'------' helpers.add_to_heard_stations( static.DXCALLSIGN, static.DXGRID, @@ -1688,7 +1693,7 @@ class DATA: # check if callsign ssid override valid, mycallsign = helpers.check_callsign(self.mycallsign, data_in[2:5]) self.mycallsign = mycallsign - + static.DXGRID = b'------' helpers.add_to_heard_stations( static.DXCALLSIGN, static.DXGRID, @@ -1765,6 +1770,7 @@ class DATA: _valid_session = helpers.check_session_id(self.session_id, bytes(data_in[1:2])) if (_valid_crc or _valid_session) and static.ARQ_SESSION_STATE not in ["disconnected"]: static.ARQ_SESSION_STATE = "disconnected" + static.DXGRID = b'------' helpers.add_to_heard_stations( static.DXCALLSIGN, static.DXGRID, @@ -1829,6 +1835,7 @@ class DATA: _valid_session = helpers.check_session_id(self.session_id, bytes(data_in[1:2])) if _valid_crc or _valid_session and static.ARQ_SESSION_STATE in ["connected", "connecting"]: self.log.debug("[TNC] Received session heartbeat") + static.DXGRID = b'------' helpers.add_to_heard_stations( self.dxcallsign, static.DXGRID, @@ -2162,7 +2169,7 @@ class DATA: # Update modes we are listening to self.set_listening_modes(True, True, self.mode_list[self.speed_level]) - + static.DXGRID = b'------' helpers.add_to_heard_stations( static.DXCALLSIGN, static.DXGRID, @@ -2275,7 +2282,7 @@ class DATA: self.speed_level = int.from_bytes(bytes(data_in[8:9]), "big") self.log.debug("[TNC] speed level selected for given SNR", speed_level=self.speed_level) # self.speed_level = len(self.mode_list) - 1 - + static.DXGRID = b'------' helpers.add_to_heard_stations( static.DXCALLSIGN, static.DXGRID, @@ -2389,7 +2396,6 @@ class DATA: ) static.DXGRID = b'------' - helpers.add_to_heard_stations( dxcallsign, static.DXGRID, @@ -2414,7 +2420,7 @@ class DATA: ping_frame[:1] = bytes([FR_TYPE.PING_ACK.value]) ping_frame[1:4] = static.DXCALLSIGN_CRC ping_frame[4:7] = static.MYCALLSIGN_CRC - ping_frame[7:13] = static.MYGRID + ping_frame[7:11] = helpers.encode_grid(static.MYGRID.decode("UTF-8")) ping_frame[13:14] = helpers.snr_to_bytes(static.SNR) if static.ENABLE_FSK: @@ -2435,8 +2441,7 @@ class DATA: _valid, mycallsign = helpers.check_callsign(self.mycallsign, data_in[1:4]) if _valid: - # static.DXCALLSIGN_CRC = bytes(data_in[4:7]) - static.DXGRID = bytes(data_in[7:13]).rstrip(b"\x00") + static.DXGRID = bytes(helpers.decode_grid(data_in[7:11]), "UTF-8") dxsnr = helpers.snr_from_bytes(data_in[13:14]) self.send_data_to_socket_queue( freedata="tnc-message", @@ -2563,7 +2568,7 @@ class DATA: beacon_frame = bytearray(self.length_sig0_frame) beacon_frame[:1] = bytes([FR_TYPE.BEACON.value]) beacon_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign) - beacon_frame[7:13] = static.MYGRID + beacon_frame[7:11] = helpers.encode_grid(static.MYGRID.decode("UTF-8")) self.log.info("[TNC] ENABLE FSK", state=static.ENABLE_FSK) if static.ENABLE_FSK: @@ -2595,15 +2600,14 @@ class DATA: """ # here we add the received station to the heard stations buffer beacon_callsign = helpers.bytes_to_callsign(bytes(data_in[1:7])) - dxgrid = bytes(data_in[7:13]).rstrip(b"\x00") - + static.DXGRID = bytes(helpers.decode_grid(data_in[7:11]), "UTF-8") self.send_data_to_socket_queue( freedata="tnc-message", beacon="received", uuid=str(uuid.uuid4()), timestamp=int(time.time()), dxcallsign=str(beacon_callsign, "UTF-8"), - dxgrid=str(dxgrid, "UTF-8"), + dxgrid=str(static.DXGRID, "UTF-8"), snr=str(static.SNR), ) @@ -2611,13 +2615,13 @@ class DATA: "[TNC] BEACON RCVD [" + str(beacon_callsign, "UTF-8") + "][" - + str(dxgrid, "UTF-8") + + str(static.DXGRID, "UTF-8") + "] ", snr=static.SNR, ) helpers.add_to_heard_stations( beacon_callsign, - dxgrid, + static.DXGRID, "BEACON", static.SNR, static.FREQ_OFFSET, @@ -2665,7 +2669,8 @@ class DATA: # here we add the received station to the heard stations buffer dxcallsign = helpers.bytes_to_callsign(bytes(data_in[1:7])) self.log.debug("[TNC] received_cq:", dxcallsign=dxcallsign) - dxgrid = bytes(helpers.decode_grid(data_in[7:11]), "UTF-8") + static.DXGRID = bytes(helpers.decode_grid(data_in[7:11]), "UTF-8") + self.send_data_to_socket_queue( freedata="tnc-message", cq="received", @@ -2677,13 +2682,13 @@ class DATA: "[TNC] CQ RCVD [" + str(dxcallsign, "UTF-8") + "][" - + str(dxgrid, "UTF-8") + + str(static.DXGRID, "UTF-8") + "] ", snr=static.SNR, ) helpers.add_to_heard_stations( dxcallsign, - dxgrid, + static.DXGRID, "CQ CQ CQ", static.SNR, static.FREQ_OFFSET, @@ -2735,7 +2740,7 @@ class DATA: """ # here we add the received station to the heard stations buffer dxcallsign = helpers.bytes_to_callsign(bytes(data_in[1:7])) - dxgrid = bytes(helpers.decode_grid(data_in[7:11]), "UTF-8") + static.DXGRID = bytes(helpers.decode_grid(data_in[7:11]), "UTF-8") dxsnr = helpers.snr_from_bytes(data_in[11:12]) combined_snr = f"{static.SNR}/{dxsnr}" @@ -2744,7 +2749,7 @@ class DATA: freedata="tnc-message", qrv="received", dxcallsign=str(dxcallsign, "UTF-8"), - dxgrid=str(dxgrid, "UTF-8"), + dxgrid=str(static.DXGRID, "UTF-8"), snr=str(static.SNR), dxsnr=str(dxsnr) ) @@ -2753,14 +2758,14 @@ class DATA: "[TNC] QRV RCVD [" + str(dxcallsign, "UTF-8") + "][" - + str(dxgrid, "UTF-8") + + str(static.DXGRID, "UTF-8") + "] ", snr=static.SNR, dxsnr=dxsnr ) helpers.add_to_heard_stations( dxcallsign, - dxgrid, + static.DXGRID, "QRV", combined_snr, static.FREQ_OFFSET, From 73fdabcbfc2447e9ecfc5260bf8f82a6556e03c9 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 12:33:35 +0100 Subject: [PATCH 10/19] small code cleanup --- tnc/data_handler.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index ea3ce40a..8e81df39 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -466,8 +466,6 @@ class DATA: ack_frame = bytearray(self.length_sig1_frame) ack_frame[:1] = bytes([FR_TYPE.BURST_ACK.value]) - # ack_frame[1:4] = static.DXCALLSIGN_CRC - # ack_frame[4:7] = static.MYCALLSIGN_CRC ack_frame[1:2] = self.session_id ack_frame[2:3] = helpers.snr_to_bytes(snr) ack_frame[3:4] = bytes([int(self.speed_level)]) @@ -490,10 +488,6 @@ class DATA: ack_frame[:1] = bytes([FR_TYPE.FR_ACK.value]) ack_frame[1:2] = self.session_id ack_frame[2:3] = helpers.snr_to_bytes(snr) - # ack_frame[1:4] = static.DXCALLSIGN_CRC - # ack_frame[4:7] = static.MYCALLSIGN_CRC - # ack_frame[7:8] = bytes([int(snr)]) - # ack_frame[8:9] = bytes([int(self.speed_level)]) # wait while timeout not reached and our busy state is busy channel_busy_timeout = time.time() + 5 @@ -528,9 +522,6 @@ class DATA: rpt_frame = bytearray(self.length_sig1_frame) rpt_frame[:1] = bytes([FR_TYPE.FR_REPEAT.value]) rpt_frame[1:2] = self.session_id - # rpt_frame[1:4] = static.DXCALLSIGN_CRC - # rpt_frame[4:7] = static.MYCALLSIGN_CRC - # rpt_frame[7:13] = missing_frames self.log.info("[TNC] ARQ | RX | Requesting", frames=missing_frames) # Transmit frame @@ -542,8 +533,6 @@ class DATA: nack_frame = bytearray(self.length_sig1_frame) nack_frame[:1] = bytes([FR_TYPE.FR_NACK.value]) nack_frame[1:2] = self.session_id - # nack_frame[1:4] = static.DXCALLSIGN_CRC - # nack_frame[4:7] = static.MYCALLSIGN_CRC nack_frame[2:3] = helpers.snr_to_bytes(snr) nack_frame[3:4] = bytes([int(self.speed_level)]) @@ -570,8 +559,6 @@ class DATA: nack_frame = bytearray(self.length_sig1_frame) nack_frame[:1] = bytes([FR_TYPE.BURST_NACK.value]) nack_frame[1:2] = self.session_id - # nack_frame[1:4] = static.DXCALLSIGN_CRC - # nack_frame[4:7] = static.MYCALLSIGN_CRC nack_frame[2:3] = helpers.snr_to_bytes(snr) nack_frame[3:4] = bytes([int(self.speed_level)]) @@ -1149,8 +1136,6 @@ class DATA: arqheader[:1] = bytes([FR_TYPE.BURST_01.value]) arqheader[1:2] = bytes([n_frames_per_burst]) arqheader[2:3] = self.session_id - # arqheader[2:5] = static.DXCALLSIGN_CRC - # arqheader[5:8] = static.MYCALLSIGN_CRC bufferposition_end = bufferposition + payload_per_frame - len(arqheader) @@ -1593,7 +1578,6 @@ class DATA: static.ARQ_SESSION_STATE = "connecting" # create a random session id - # self.session_id = randbytes(1) self.session_id = np.random.bytes(1) connection_frame = bytearray(self.length_sig0_frame) @@ -1809,8 +1793,6 @@ class DATA: connection_frame = bytearray(self.length_sig0_frame) connection_frame[:1] = bytes([FR_TYPE.ARQ_SESSION_HB.value]) connection_frame[1:2] = self.session_id - # connection_frame[1:4] = static.DXCALLSIGN_CRC - # connection_frame[4:7] = static.MYCALLSIGN_CRC self.send_data_to_socket_queue( freedata="tnc-message", @@ -2215,8 +2197,6 @@ class DATA: connection_frame = bytearray(self.length_sig0_frame) connection_frame[:1] = frametype connection_frame[1:2] = self.session_id - # connection_frame[1:4] = static.DXCALLSIGN_CRC - # connection_frame[4:7] = static.MYCALLSIGN_CRC connection_frame[8:9] = bytes([self.speed_level]) # For checking protocol version on the receiving side From d40a018da30ae30994f3252a96b2d611bb3ff30c Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 12:35:29 +0100 Subject: [PATCH 11/19] added compression factor to tnc-message --- tnc/data_handler.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 8e81df39..7bda4a59 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -783,6 +783,7 @@ class DATA: uuid=self.transmission_uuid, percent=static.ARQ_TRANSMISSION_PERCENT, bytesperminute=static.ARQ_BYTES_PER_MINUTE, + compression=static.ARQ_COMPRESSION_FACTOR, mycallsign=str(self.mycallsign, 'UTF-8'), dxcallsign=str(self.dxcallsign, 'UTF-8'), finished=static.ARQ_SECONDS_UNTIL_FINISH, @@ -1002,6 +1003,7 @@ class DATA: nacks=self.frame_nack_counter, duration=duration, bytesperminute=static.ARQ_BYTES_PER_MINUTE, + compression=static.ARQ_COMPRESSION_FACTOR, data=data_frame, ) @@ -1047,6 +1049,7 @@ class DATA: uuid=self.transmission_uuid, percent=static.ARQ_TRANSMISSION_PERCENT, bytesperminute=static.ARQ_BYTES_PER_MINUTE, + compression=static.ARQ_COMPRESSION_FACTOR, finished=static.ARQ_SECONDS_UNTIL_FINISH, mycallsign=str(self.mycallsign, 'UTF-8'), dxcallsign=str(self.dxcallsign, 'UTF-8'), @@ -1240,6 +1243,7 @@ class DATA: uuid=self.transmission_uuid, percent=static.ARQ_TRANSMISSION_PERCENT, bytesperminute=static.ARQ_BYTES_PER_MINUTE, + compression=static.ARQ_COMPRESSION_FACTOR, finished=static.ARQ_SECONDS_UNTIL_FINISH, irs_snr=self.burst_ack_snr, mycallsign=str(self.mycallsign, 'UTF-8'), @@ -1266,6 +1270,7 @@ class DATA: uuid=self.transmission_uuid, percent=static.ARQ_TRANSMISSION_PERCENT, bytesperminute=static.ARQ_BYTES_PER_MINUTE, + compression=static.ARQ_COMPRESSION_FACTOR, finished=static.ARQ_SECONDS_UNTIL_FINISH, mycallsign=str(self.mycallsign, 'UTF-8'), dxcallsign=str(self.dxcallsign, 'UTF-8'), @@ -1288,6 +1293,7 @@ class DATA: uuid=self.transmission_uuid, percent=static.ARQ_TRANSMISSION_PERCENT, bytesperminute=static.ARQ_BYTES_PER_MINUTE, + compression=static.ARQ_COMPRESSION_FACTOR, mycallsign=str(self.mycallsign, 'UTF-8'), dxcallsign=str(self.dxcallsign, 'UTF-8'), ) @@ -1420,6 +1426,7 @@ class DATA: uuid=self.transmission_uuid, percent=static.ARQ_TRANSMISSION_PERCENT, bytesperminute=static.ARQ_BYTES_PER_MINUTE, + compression=static.ARQ_COMPRESSION_FACTOR, mycallsign=str(self.mycallsign, 'UTF-8'), dxcallsign=str(self.dxcallsign, 'UTF-8'), ) @@ -2025,6 +2032,7 @@ class DATA: uuid=self.transmission_uuid, percent=static.ARQ_TRANSMISSION_PERCENT, bytesperminute=static.ARQ_BYTES_PER_MINUTE, + compression=static.ARQ_COMPRESSION_FACTOR, mycallsign=str(self.mycallsign, 'UTF-8'), dxcallsign=str(self.dxcallsign, 'UTF-8'), ) From 41d785f2368b6feda21b530145e872421c7e643d Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 12:47:18 +0100 Subject: [PATCH 12/19] from random import randrange --- tnc/data_handler.py | 2 +- tnc/sock.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 7bda4a59..938a91e0 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -14,7 +14,7 @@ import threading import time import uuid import lzma -from random import randrange# , randbytes +from random import randrange import codec2 import helpers diff --git a/tnc/sock.py b/tnc/sock.py index 817d1ef8..c02d0629 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -25,7 +25,7 @@ import sys import threading import time import wave - +from random import randrange import helpers import static import structlog @@ -527,7 +527,7 @@ def process_tnc_commands(data): binarydata = base64.b64decode(base64data) - # wait some random time which acts as collision detection + # wait some random time which acts as slightly as collision detection helpers.wait(randrange(0, 20, 5) / 10.0) DATA_QUEUE_TRANSMIT.put( From c0c68fce4236fca1e0a2781a0e078b9afd145f23 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 13:20:57 +0100 Subject: [PATCH 13/19] wait with command processing if already in arq state --- tnc/data_handler.py | 22 +++++++++++++++++++++- tnc/sock.py | 10 +++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 938a91e0..cb379504 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -237,6 +237,25 @@ class DATA: while True: data = self.data_queue_transmit.get() + # if we are already in ARQ_STATE lets wait with processing data + # this should avoid weird toggle states where both stations + # stuck in IRS + # + # send transmission queued information once + if static.ARQ_STATE: + self.send_data_to_socket_queue( + freedata="tnc-message", + arq="transmission", + status="queued", + uuid=str(data[4], 'UTF-8'), + mycallsign=str(data[5], 'UTF-8'), + dxcallsign=str(data[6], 'UTF-8'), + ) + # now stay in while loop until state released + while static.ARQ_STATE: + threading.Event().wait(0.01) + self.log.debug(f"[TNC] TX DISPATCHER - waiting with processing command ", arq_state=static.ARQ_STATE) + # Dispatch commands known to command_dispatcher if data[0] in self.command_dispatcher: self.log.debug(f"[TNC] TX {self.command_dispatcher[data[0]][1]}...") @@ -475,12 +494,12 @@ class DATA: while static.CHANNEL_BUSY and time.time() < channel_busy_timeout: threading.Event().wait(0.01) - # Transmit frame self.enqueue_frame_for_tx([ack_frame], c2_mode=FREEDV_MODE.sig1.value) # reset burst timeout in case we had to wait too long self.burst_last_received = time.time() + def send_data_ack_frame(self, snr) -> None: """Build and send ACK frame for received DATA frame""" @@ -548,6 +567,7 @@ class DATA: self.enqueue_frame_for_tx([nack_frame], c2_mode=FREEDV_MODE.sig1.value, copies=6, repeat_delay=0) # reset burst timeout in case we had to wait too long self.burst_last_received = time.time() + def send_burst_nack_frame_watchdog(self, snr: bytes) -> None: """Build and send NACK frame for watchdog timeout""" diff --git a/tnc/sock.py b/tnc/sock.py index c02d0629..12f57049 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -25,7 +25,6 @@ import sys import threading import time import wave -from random import randrange import helpers import static import structlog @@ -470,15 +469,15 @@ def process_tnc_commands(data): if received_json["type"] == "arq" and received_json["command"] == "send_raw": static.BEACON_PAUSE = True - # we need to reject a command processing if already in arq state + # we need to warn if already in arq state if static.ARQ_STATE: command_response("send_raw", False) log.warning( - "[SCK] Send raw command execution error", + "[SCK] Send raw command execution warning", e="already in arq state", + i="command queued", command=received_json, ) - return False try: if not static.ARQ_SESSION: @@ -527,9 +526,6 @@ def process_tnc_commands(data): binarydata = base64.b64decode(base64data) - # wait some random time which acts as slightly as collision detection - helpers.wait(randrange(0, 20, 5) / 10.0) - DATA_QUEUE_TRANSMIT.put( ["ARQ_RAW", binarydata, mode, n_frames, arq_uuid, mycallsign, dxcallsign, attempts] ) From 0aff7dad2d0177800d387465cf0f515186866104 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 13:22:02 +0100 Subject: [PATCH 14/19] wait with command processing if already in arq state --- tnc/data_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index cb379504..a932b088 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -247,7 +247,7 @@ class DATA: freedata="tnc-message", arq="transmission", status="queued", - uuid=str(data[4], 'UTF-8'), + uuid=data[4], mycallsign=str(data[5], 'UTF-8'), dxcallsign=str(data[6], 'UTF-8'), ) From cd4a6b586fd32e18b0031027654675f7279b00cf Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 13:23:09 +0100 Subject: [PATCH 15/19] improved logging --- tnc/data_handler.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index a932b088..a873436d 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -243,6 +243,8 @@ class DATA: # # send transmission queued information once if static.ARQ_STATE: + self.log.debug(f"[TNC] TX DISPATCHER - waiting with processing command ", arq_state=static.ARQ_STATE) + self.send_data_to_socket_queue( freedata="tnc-message", arq="transmission", @@ -254,7 +256,6 @@ class DATA: # now stay in while loop until state released while static.ARQ_STATE: threading.Event().wait(0.01) - self.log.debug(f"[TNC] TX DISPATCHER - waiting with processing command ", arq_state=static.ARQ_STATE) # Dispatch commands known to command_dispatcher if data[0] in self.command_dispatcher: From 88993a41af6ad662e31fdb55621399dec944d7ea Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 14:17:09 +0100 Subject: [PATCH 16/19] fixed list index error --- tnc/data_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index a873436d..6154f298 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -247,9 +247,9 @@ class DATA: self.send_data_to_socket_queue( freedata="tnc-message", - arq="transmission", + arq="command", status="queued", - uuid=data[4], + command=data[0], mycallsign=str(data[5], 'UTF-8'), dxcallsign=str(data[6], 'UTF-8'), ) From a03db31c6183f38b0e6f423720f57fef1f660bdb Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 14:17:41 +0100 Subject: [PATCH 17/19] fixed list index error --- tnc/data_handler.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 6154f298..b4e1c1d1 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -247,9 +247,8 @@ class DATA: self.send_data_to_socket_queue( freedata="tnc-message", - arq="command", - status="queued", command=data[0], + status="queued", mycallsign=str(data[5], 'UTF-8'), dxcallsign=str(data[6], 'UTF-8'), ) From fd49dfd629320b3593d3af4ba2a3ba3c1924c626 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:35:49 +0100 Subject: [PATCH 18/19] keep tnc-message simple for transmit worker --- tnc/data_handler.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index b4e1c1d1..c0360b4a 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -249,8 +249,6 @@ class DATA: freedata="tnc-message", command=data[0], status="queued", - mycallsign=str(data[5], 'UTF-8'), - dxcallsign=str(data[6], 'UTF-8'), ) # now stay in while loop until state released while static.ARQ_STATE: From eb92db174d812202971b5a77b8530237d67c13e5 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:43:00 +0100 Subject: [PATCH 19/19] fixed ping dxcallsign --- tnc/data_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index c0360b4a..1b3f4fbd 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -2455,7 +2455,7 @@ class DATA: uuid=str(uuid.uuid4()), timestamp=int(time.time()), dxgrid=str(static.DXGRID, "UTF-8"), - dxcallsign = str(self.dxcallsign, "UTF-8"), + dxcallsign = str(static.DXCALLSIGN, "UTF-8"), mycallsign=str(mycallsign, "UTF-8"), snr=str(static.SNR), dxsnr=str(dxsnr)