diff --git a/.github/workflows/build_multiplatform.yml b/.github/workflows/build_multiplatform.yml index 6128bca9..3c9d7140 100644 --- a/.github/workflows/build_multiplatform.yml +++ b/.github/workflows/build_multiplatform.yml @@ -200,21 +200,21 @@ jobs: zip_name: ubuntu_tnc generator: Unix Makefiles daemon_binary_name: freedata-daemon - tnc_binary_name: freedata-tnc + tnc_binary_name: freedata-modem electron_parameters: "-p always" - os: macos-11 zip_name: macos_tnc generator: Unix Makefiles daemon_binary_name: freedata-daemon - tnc_binary_name: freedata-tnc + tnc_binary_name: freedata-modem electron_parameters: "-p always" - os: windows-latest zip_name: windows_tnc generator: Visual Studio 16 2019 daemon_binary_name: freedata-daemon.exe - tnc_binary_name: freedata-tnc.exe + tnc_binary_name: freedata-modem.exe electron_parameters: "-p always --x64 --ia32" steps: - name: Checkout code for ${{ matrix.platform.name }} @@ -232,30 +232,30 @@ jobs: with: node-version: 18.17 - - name: Create tnc/dist - working-directory: tnc + - name: Create modem/dist + working-directory: modem run: | mkdir -p dist - - name: Create tnc/dist/tnc - working-directory: tnc + - name: Create modem/dist/modem + working-directory: modem run: | mkdir -p dist/tnc ##- name: Download libcodec2 artifact TNC DIST ## uses: actions/download-artifact@v3 ## with: - ## path: tnc/dist/codec2 + ## path: modem/dist/codec2 - - name: create tnc/lib/codec2 - working-directory: tnc/lib/ + - name: create modem/lib/codec2 + working-directory: modem/lib/ run: | mkdir codec2 - name: Download libcodec2 artifact TNC LIB uses: actions/download-artifact@v3 with: - path: tnc/lib/codec2 + path: modem/lib/codec2 - name: Install Linux dependencies @@ -285,7 +285,7 @@ jobs: - name: Build binaries macOS if: ${{startsWith(matrix.os, 'macos')}} - working-directory: tnc + working-directory: modem run: | # now build tnc binaries pyinstaller -y freedata.spec @@ -295,7 +295,7 @@ jobs: - name: Build binaries Linux and Windows if: ${{!startsWith(matrix.os, 'macos')}} - working-directory: tnc + working-directory: modem run: | # pyinstaller freedata.spec # python3 -m nuitka --enable-plugin=numpy --assume-yes-for-downloads --onefile daemon.py -o ${{ matrix.daemon_binary_name }} @@ -305,30 +305,30 @@ jobs: - name: Copy binaries - Linux if: ${{startsWith(matrix.os, 'ubuntu')}} - working-directory: tnc + working-directory: modem run: | cp -r -f daemon.dist/* dist/tnc cp -r -f main.dist/* dist/tnc - name: Copy binaries - Windows if: ${{startsWith(matrix.os, 'windows')}} - working-directory: tnc + working-directory: modem # These are powershell aliases, not UNIX commands. run: | cp -r -Force daemon.dist/* dist/tnc cp -r -Force main.dist/* dist/tnc - - name: Rename tnc binaries + - name: Rename modem binaries # we don't need renaming for pyinstaller builds as output name is defined if: ${{!startsWith(matrix.os, 'macos')}} - working-directory: tnc + working-directory: modem run: | mv dist/tnc/daemon* dist/tnc/${{ matrix.daemon_binary_name }} mv dist/tnc/main* dist/tnc/${{ matrix.tnc_binary_name }} - uses: actions/download-artifact@v3 with: - path: tnc/dist/tnc + path: modem/dist/modem - name: LIST ALL FILES @@ -336,7 +336,7 @@ jobs: - name: Download Portaudio binaries Linux macOS if: ${{!startsWith(matrix.os, 'windows')}} - working-directory: tnc + working-directory: modem run: | if ! test -d "dist/tnc/_sounddevice_data"; then git clone https://github.com/spatialaudio/portaudio-binaries dist/tnc/_sounddevice_data/portaudio-binaries @@ -344,7 +344,7 @@ jobs: - name: Download Portaudio binaries Windows if: ${{startsWith(matrix.os, 'windows')}} - working-directory: tnc + working-directory: modem run: | if(Test-Path -Path "dist/tnc/_sounddevice_data"){ echo "sounddevice folder already exists" @@ -382,8 +382,8 @@ jobs: with: type: 'zip' filename: '${{ matrix.zip_name }}.zip' - # directory: ./tnc/dist/tnc - directory: ./tnc/dist/tnc + # directory: ./modem/dist/modem + directory: ./modem/dist/modem path: . # exclusions: '*.git* /*node_modules/* .editorconfig' @@ -391,8 +391,8 @@ jobs: uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/v') with: - files: ./tnc/dist/tnc/${{ matrix.zip_name }}.zip - #files: ./tnc/dist/${{ matrix.zip_name }}.zip + files: ./modem/dist/modem/${{ matrix.zip_name }}.zip + #files: ./modem/dist/${{ matrix.zip_name }}.zip - name: LIST ALL FILES run: ls -R @@ -402,13 +402,13 @@ jobs: # if: ${{!startsWith(github.ref, 'refs/tags/v')}} # with: # name: ${{ matrix.zip_name }}.zip - # # path: ./tnc/dist/tnc/${{ matrix.zip_name }}.zip - # path: ./tnc/dist/tnc/${{ matrix.zip_name }}.zip# + # # path: ./modem/dist/modem/${{ matrix.zip_name }}.zip + # path: ./modem/dist/modem/${{ matrix.zip_name }}.zip# #- name: Upload App bundle artifacts # uses: actions/upload-artifact@v3 # if: ${{!startsWith(github.ref, 'refs/tags/v')}} # with: # name: app_bundle_${{ matrix.os }}.zip - # # path: ./tnc/dist/tnc/${{ matrix.zip_name }}.zip + # # path: ./modem/dist/modem/${{ matrix.zip_name }}.zip # path: ./gui/dist/* diff --git a/.gitignore b/.gitignore index 1a809e3a..ea41981c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -# possible installation of codec2 within tnc -tnc/codec2 +# possible installation of codec2 within modem +modem/codec2 # temporary test artifacts **/build diff --git a/tnc/.gitignore b/modem/.gitignore similarity index 100% rename from tnc/.gitignore rename to modem/.gitignore diff --git a/tnc/audio.py b/modem/audio.py similarity index 100% rename from tnc/audio.py rename to modem/audio.py diff --git a/tnc/broadcast.py b/modem/broadcast.py similarity index 88% rename from tnc/broadcast.py rename to modem/broadcast.py index e6cda727..8c51c475 100644 --- a/tnc/broadcast.py +++ b/modem/broadcast.py @@ -4,7 +4,7 @@ import helpers import time import modem import base64 -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem import sock import ujson as json @@ -34,7 +34,7 @@ class broadcastHandler: modem.RECEIVE_DATAC4 = True self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", fec="wakeup", mode=self.wakeup_mode, bursts=bursts, @@ -42,7 +42,7 @@ class broadcastHandler: ) self.log.info( - "[TNC] FRAME WAKEUP RCVD [" + "[Modem] FRAME WAKEUP RCVD [" + str(self.fec_wakeup_callsign, "UTF-8") + "] ", mode=self.wakeup_mode, bursts=bursts, ) @@ -51,13 +51,13 @@ class broadcastHandler: print(self.fec_wakeup_callsign) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", fec="broadcast", dxcallsign=str(self.fec_wakeup_callsign, "UTF-8"), data=base64.b64encode(data_in[1:]).decode("UTF-8") ) - self.log.info("[TNC] FEC DATA RCVD") + self.log.info("[Modem] FEC DATA RCVD") def send_data_to_socket_queue(self, **jsondata): """ @@ -67,7 +67,7 @@ class broadcastHandler: Dictionary containing the data to be sent, in the format: key=value, for each item. E.g.: self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="received", status="success", uuid=self.transmission_uuid, @@ -87,12 +87,12 @@ class broadcastHandler: if "dxcallsign" not in jsondata: jsondata["dxcallsign"] = str(Station.dxcallsign, "UTF-8") except Exception as e: - self.log.debug("[TNC] error adding callsigns to network message", e=e) + self.log.debug("[Modem] error adding callsigns to network message", e=e) # run json dumps json_data_out = json.dumps(jsondata) - self.log.debug("[TNC] send_data_to_socket_queue:", jsondata=json_data_out) + self.log.debug("[Modem] send_data_to_socket_queue:", jsondata=json_data_out) # finally push data to our network queue sock.SOCKET_QUEUE.put(json_data_out) @@ -106,7 +106,7 @@ class broadcastHandler: self.broadcast_timeout_reached = True self.log.info( - "[TNC] closing broadcast slot [" + "[Modem] closing broadcast slot [" + str(self.fec_wakeup_callsign, "UTF-8") + "] ", mode=self.wakeup_mode, bursts=self.broadcast_payload_bursts, ) diff --git a/modem/callsign_reverse_db.txt b/modem/callsign_reverse_db.txt new file mode 100644 index 00000000..d3e169f7 --- /dev/null +++ b/modem/callsign_reverse_db.txt @@ -0,0 +1 @@ +{"DJ2LS-0": "22864b", "IW2DHW-0": "fcef94", "BEACON": "5492c7", "EI7IG-0": "0975c8", "G0HWW-0": "2cb363", "LA3QMA-0": "2b9fac", "EA7KOH-0": "9e1c3e", "OK6MS-0": "5f75ed", "N1QM-0": "e045a0"} \ No newline at end of file diff --git a/tnc/codec2.py b/modem/codec2.py similarity index 100% rename from tnc/codec2.py rename to modem/codec2.py diff --git a/tnc/config.py b/modem/config.py similarity index 97% rename from tnc/config.py rename to modem/config.py index 98a93fc1..032e7283 100644 --- a/tnc/config.py +++ b/modem/config.py @@ -45,7 +45,7 @@ class CONFIG: write entire config """ self.config['NETWORK'] = {'#Network settings': None, - 'TNCPORT': data[50] + 'ModemPORT': data[50] } self.config['STATION'] = {'#Station settings': None, @@ -66,7 +66,7 @@ class CONFIG: 'rigctld_ip': data[6], 'rigctld_port': data[7] } - self.config['TNC'] = {'#TNC settings': None, + self.config['Modem'] = {'#Modem settings': None, 'scatter': data[8], 'fft': data[9], 'narrowband': data[10], diff --git a/modem/cw.py b/modem/cw.py new file mode 100644 index 00000000..6a678050 --- /dev/null +++ b/modem/cw.py @@ -0,0 +1,70 @@ +import numpy as np + +""" + morse code generator + MorseCodePlayer().text_to_signal("DJ2LS-1") + + + """ +class MorseCodePlayer: + def __init__(self, wpm=150, f=1500, fs=48000): + self.wpm = wpm + self.f0 = f + self.fs = fs + self.dot_duration = 1.2/(self.wpm) + self.dash_duration = 3*self.dot_duration + self.pause_duration = self.dot_duration + self.word_pause_duration = 7*self.dot_duration + self.morse_alphabet = { + 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', + 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', + 'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', + 'Y': '-.--', 'Z': '--..', '0': '-----', '1': '.----', '2': '..---', '3': '...--', '4': '....-', + '5': '.....', '6': '-....', '7': '--...', '8': '---..', '9': '----.', '.': '.-.-.-', ',': '--..--', + '?': '..--..', "'": '.----.', '!': '-.-.--', '/': '-..-.', '(': '-.--.', ')': '-.--.-', '&': '.-...', + ':': '---...', ';': '-.-.-.', '=': '-...-', '+': '.-.-.', '-': '-....-', '_': '..--.-', '"': '.-..-.', + '$': '...-..-', '@': '.--.-.' + } + + def text_to_morse(self, text): + morse = '' + for char in text: + if char.upper() in self.morse_alphabet: + morse += self.morse_alphabet[char.upper()] + ' ' + elif char == ' ': + morse += ' ' + return morse + + def morse_to_signal(self, morse): + signal = np.array([], dtype=np.int16) + for char in morse: + if char == '.': + duration = int(self.dot_duration * self.fs) + s = np.sin(2 * np.pi * self.f0 * np.arange(duration) / self.fs) + signal = np.concatenate((signal, s * 32767)) + pause_duration = int(self.pause_duration * self.fs) + signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16))) + elif char == '-': + duration = int(self.dash_duration * self.fs) + s = np.sin(2 * np.pi * self.f0 * np.arange(duration) / self.fs) + signal = np.concatenate((signal, s * 32767)) + pause_duration = int(self.pause_duration * self.fs) + signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16))) + elif char == ' ': + pause_duration = int(self.word_pause_duration * self.fs) + signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16))) + pause_duration = int(self.pause_duration * self.fs) + signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16))) + + pause_duration = int(self.word_pause_duration * self.fs) + #signal = np.concatenate((signal, np.zeros(pause_duration, dtype=np.int16))) + + # Convert the signal to mono (single-channel) + #signal = signal.reshape(-1, 1) + + return signal + + def text_to_signal(self, text): + morse = self.text_to_morse(text) + return self.morse_to_signal(morse) + diff --git a/tnc/daemon.py b/modem/daemon.py similarity index 93% rename from tnc/daemon.py rename to modem/daemon.py index 925ca0e3..429d8ab9 100755 --- a/tnc/daemon.py +++ b/modem/daemon.py @@ -5,7 +5,7 @@ daemon.py Author: DJ2LS, January 2022 -daemon for providing basic information for the tnc like audio or serial devices +daemon for providing basic information for the modem like audio or serial devices """ # pylint: disable=invalid-name, line-too-long, c-extension-no-member @@ -26,7 +26,7 @@ import crcengine import log_handler import serial.tools.list_ports import sock -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem import structlog import ujson as json @@ -83,7 +83,7 @@ class DAEMON: """ while True: try: - if not Daemon.tncstarted: + if not Daemon.modemstarted: ( AudioParam.audio_input_devices, AudioParam.audio_output_devices, @@ -153,8 +153,8 @@ class DAEMON: # data[20] stats # data[21] tx_delay - if data[0] == "STARTTNC": - self.start_tnc(data) + if data[0] == "STARTModem": + self.start_modem(data) if data[0] == "TEST_HAMLIB": # data[9] radiocontrol @@ -387,8 +387,8 @@ class DAEMON: - def start_tnc(self, data): - self.log.warning("[DMN] Starting TNC", rig=data[5], port=data[6]) + def start_modem(self, data): + self.log.warning("[DMN] Starting Modem", rig=data[5], port=data[6]) # list of parameters, necessary for running subprocess command as a list options = ["--port", str(DAEMON.port - 1)] @@ -467,8 +467,8 @@ class DAEMON: # safe data to config file config.write_entire_config(data) - # Try running tnc from binary, else run from source - # This helps running the tnc in a developer environment + # Try running modem from binary, else run from source + # This helps running the modem in a developer environment try: command = [] @@ -477,12 +477,12 @@ class DAEMON: # extends the sys module by a flag frozen=True and sets the app # path into variable _MEIPASS'. application_path = sys._MEIPASS - command.append(f'{application_path}/freedata-tnc') + command.append(f'{application_path}/freedata-modem') elif sys.platform in ["linux", "darwin"]: - command.append("./freedata-tnc") + command.append("./freedata-modem") elif sys.platform in ["win32", "win64"]: - command.append("freedata-tnc.exe") + command.append("freedata-modem.exe") command += options @@ -490,11 +490,11 @@ class DAEMON: atexit.register(proc.kill) - Daemon.tncprocess = proc - Daemon.tncstarted = True + Daemon.modemprocess = proc + Daemon.modemstarted = True - self.log.info("[DMN] TNC started", path="binary") + self.log.info("[DMN] Modem started", path="binary") except FileNotFoundError as err1: try: @@ -511,13 +511,13 @@ class DAEMON: proc = subprocess.Popen(command) atexit.register(proc.kill) - self.log.info("[DMN] TNC started", path="source") + self.log.info("[DMN] Modem started", path="source") - Daemon.tncprocess = proc - Daemon.tncstarted = True + Daemon.modemprocess = proc + Daemon.modemstarted = True except Exception as e: - self.log.error("[DMN] TNC not started", error=e) - Daemon.tncstarted = False + self.log.error("[DMN] Modem not started", error=e) + Daemon.modemstarted = False @@ -569,7 +569,7 @@ if __name__ == "__main__": # https://stackoverflow.com/a/16641793 socketserver.TCPServer.allow_reuse_address = True cmdserver = sock.ThreadedTCPServer( - (TNC.host, DAEMON.port), sock.ThreadedTCPRequestHandler + (Modem.host, DAEMON.port), sock.ThreadedTCPRequestHandler ) server_thread = threading.Thread(target=cmdserver.serve_forever) server_thread.daemon = True @@ -586,7 +586,7 @@ if __name__ == "__main__": "[DMN] Starting FreeDATA Daemon", author="DJ2LS", year="2023", - version=TNC.version, + version=Modem.version, ) while True: threading.Event().wait(1) diff --git a/tnc/data_handler.py b/modem/data_handler.py similarity index 90% rename from tnc/data_handler.py rename to modem/data_handler.py index 3ff9ab84..a7a66055 100644 --- a/tnc/data_handler.py +++ b/modem/data_handler.py @@ -24,7 +24,7 @@ import helpers import modem import numpy as np import sock -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem import structlog import stats import ujson as json @@ -145,7 +145,7 @@ class DATA: # Mode list for selecting between low bandwidth ( 500Hz ) and modes with higher bandwidth # but ability to fall back to low bandwidth modes if needed. - if TNC.low_bandwidth_mode: + if Modem.low_bandwidth_mode: # List of codec2 modes to use in "low bandwidth" mode. self.mode_list = self.mode_list_low_bw # list of times to wait for corresponding mode in seconds @@ -280,12 +280,12 @@ class DATA: # send transmission queued information once if ARQ.arq_state or ModemParam.is_codec2_traffic: self.log.debug( - "[TNC] TX DISPATCHER - waiting with processing command ", + "[Modem] TX DISPATCHER - waiting with processing command ", arq_state=ARQ.arq_state, ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", command=data[0], status="queued", ) @@ -299,7 +299,7 @@ class DATA: # 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]}...") + self.log.debug(f"[Modem] TX {self.command_dispatcher[data[0]][1]}...") self.command_dispatcher[data[0]][0]() # Dispatch commands that need more arguments. @@ -346,7 +346,7 @@ class DATA: self.send_fec(data[1], data[2], data[3], data[4]) else: self.log.error( - "[TNC] worker_transmit: received invalid command:", data=data + "[Modem] worker_transmit: received invalid command:", data=data ) def worker_receive(self) -> None: @@ -373,7 +373,7 @@ class DATA: """ self.log.debug( - "[TNC] process_data:", n_retries_per_burst=self.n_retries_per_burst + "[Modem] process_data:", n_retries_per_burst=self.n_retries_per_burst ) # Process data only if broadcast or we are the receiver @@ -415,7 +415,7 @@ class DATA: # Dispatch activity based on received frametype if frametype in self.rx_dispatcher: # Process frames "known" by rx_dispatcher - # self.log.debug(f"[TNC] {self.rx_dispatcher[frametype][1]} RECEIVED....") + # self.log.debug(f"[Modem] {self.rx_dispatcher[frametype][1]} RECEIVED....") self.rx_dispatcher[frametype][0](bytes_out[:-2]) # Process frametypes requiring a different set of arguments. @@ -424,7 +424,7 @@ class DATA: # FIXME: find a fix for this - after moving to classes, this no longer works # snr = self.calculate_snr(freedv) snr = ModemParam.snr - self.log.debug("[TNC] RX SNR", snr=snr) + self.log.debug("[Modem] RX SNR", snr=snr) # send payload data to arq checker without CRC16 self.arq_data_received( bytes(bytes_out[:-2]), bytes_per_frame, snr, freedv @@ -432,23 +432,23 @@ class DATA: # if we received the last frame of a burst or the last remaining rpt frame, do a modem unsync # if ARQ.rx_burst_buffer.count(None) <= 1 or (frame+1) == n_frames_per_burst: - # self.log.debug(f"[TNC] LAST FRAME OF BURST --> UNSYNC {frame+1}/{n_frames_per_burst}") + # self.log.debug(f"[Modem] LAST FRAME OF BURST --> UNSYNC {frame+1}/{n_frames_per_burst}") # self.c_lib.freedv_set_sync(freedv, 0) # TESTFRAMES elif frametype == FR_TYPE.TEST_FRAME.value: - self.log.debug("[TNC] TESTFRAME RECEIVED", frame=bytes_out[:]) + self.log.debug("[Modem] TESTFRAME RECEIVED", frame=bytes_out[:]) # Unknown frame type else: self.log.warning( - "[TNC] ARQ - other frame type", frametype=FR_TYPE(frametype).name + "[Modem] ARQ - other frame type", frametype=FR_TYPE(frametype).name ) else: # for debugging purposes to receive all data self.log.debug( - "[TNC] Foreign frame received", + "[Modem] Foreign frame received", frame=bytes_out[:-2].hex(), frame_type=FR_TYPE(int.from_bytes(bytes_out[:1], byteorder="big")).name, ) @@ -461,7 +461,7 @@ class DATA: repeat_delay=0, ) -> None: """ - Send (transmit) supplied frame to TNC + Send (transmit) supplied frame to Modem :param frame_to_tx: Frame data to send :type frame_to_tx: list of bytearrays @@ -475,16 +475,16 @@ class DATA: #print(frame_to_tx[0]) #print(frame_to_tx) frame_type = FR_TYPE(int.from_bytes(frame_to_tx[0][:1], byteorder="big")).name - self.log.debug("[TNC] enqueue_frame_for_tx", c2_mode=FREEDV_MODE(c2_mode).name, data=frame_to_tx, + self.log.debug("[Modem] enqueue_frame_for_tx", c2_mode=FREEDV_MODE(c2_mode).name, data=frame_to_tx, type=frame_type) # Set the TRANSMITTING flag before adding an object to the transmit queue # TODO: This is not that nice, we could improve this somehow - TNC.transmitting = True + Modem.transmitting = True modem.MODEM_TRANSMIT_QUEUE.put([c2_mode, copies, repeat_delay, frame_to_tx]) # Wait while transmitting - while TNC.transmitting: + while Modem.transmitting: threading.Event().wait(0.01) def send_data_to_socket_queue(self, **jsondata): @@ -495,7 +495,7 @@ class DATA: Dictionary containing the data to be sent, in the format: key=value, for each item. E.g.: self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="received", status="success", uuid=self.transmission_uuid, @@ -515,12 +515,12 @@ class DATA: if "dxcallsign" not in jsondata: jsondata["dxcallsign"] = str(Station.dxcallsign, "UTF-8") except Exception as e: - self.log.debug("[TNC] error adding callsigns to network message", e=e) + self.log.debug("[Modem] error adding callsigns to network message", e=e) # run json dumps json_data_out = json.dumps(jsondata) - self.log.debug("[TNC] send_data_to_socket_queue:", jsondata=json_data_out) + self.log.debug("[Modem] send_data_to_socket_queue:", jsondata=json_data_out) # finally push data to our network queue sock.SOCKET_QUEUE.put(json_data_out) @@ -589,7 +589,7 @@ class DATA: rpt_frame[1:2] = self.session_id rpt_frame[2:2 + len(missing_frames)] = missing_frames - self.log.info("[TNC] ARQ | RX | Requesting", frames=missing_frames) + self.log.info("[Modem] ARQ | RX | Requesting", frames=missing_frames) # Transmit frame self.enqueue_frame_for_tx([rpt_frame], c2_mode=FREEDV_MODE.sig1.value, copies=1, repeat_delay=0) @@ -627,7 +627,7 @@ class DATA: ARQ.rx_burst_buffer = [] # Create and send ACK frame - self.log.info("[TNC] ARQ | RX | SENDING NACK") + self.log.info("[Modem] ARQ | RX | SENDING NACK") nack_frame = bytearray(self.length_sig1_frame) nack_frame[:1] = bytes([FR_TYPE.BURST_NACK.value]) nack_frame[1:2] = self.session_id @@ -684,14 +684,14 @@ class DATA: data_in = bytes(data_in) # only process data if we are in ARQ and BUSY state else return to quit - if not ARQ.arq_state and TNC.tnc_state not in ["BUSY"]: - self.log.warning("[TNC] wrong tnc state - dropping data", arq_state=ARQ.arq_state, - tnc_state=TNC.tnc_state) + if not ARQ.arq_state and Modem.modem_state not in ["BUSY"]: + self.log.warning("[Modem] wrong modem state - dropping data", arq_state=ARQ.arq_state, + modem_state=Modem.modem_state) return self.arq_file_transfer = True - TNC.tnc_state = "BUSY" + Modem.modem_state = "BUSY" ARQ.arq_state = True # Update data_channel timestamp @@ -740,30 +740,30 @@ class DATA: # catch possible modem error which leads into false byteorder # modem possibly decodes too late - data then is pushed to buffer # which leads into wrong byteorder - # Lets put this in try/except so we are not crashing tnc as its highly experimental + # Lets put this in try/except so we are not crashing modem as its highly experimental # This might only work for datac1 and datac3 try: # area_of_interest = (modem.get_bytes_per_frame(self.mode_list[speed_level] - 1) -3) * 2 if ARQ.rx_frame_buffer.endswith(temp_burst_buffer[:246]) and len(temp_burst_buffer) >= 246: self.log.warning( - "[TNC] ARQ | RX | wrong byteorder received - dropping data" + "[Modem] ARQ | RX | wrong byteorder received - dropping data" ) # we need to run a return here, so we are not sending an ACK # return except Exception as e: self.log.warning( - "[TNC] ARQ | RX | wrong byteorder check failed", e=e + "[Modem] ARQ | RX | wrong byteorder check failed", e=e ) - self.log.debug("[TNC] temp_burst_buffer", buffer=temp_burst_buffer) - self.log.debug("[TNC] ARQ.rx_frame_buffer", buffer=ARQ.rx_frame_buffer) + self.log.debug("[Modem] temp_burst_buffer", buffer=temp_burst_buffer) + self.log.debug("[Modem] ARQ.rx_frame_buffer", buffer=ARQ.rx_frame_buffer) # if frame buffer ends not with the current frame, we are going to append new data # if data already exists, we received the frame correctly, # but the ACK frame didn't receive its destination (ISS) if ARQ.rx_frame_buffer.endswith(temp_burst_buffer): self.log.info( - "[TNC] ARQ | RX | Frame already received - sending ACK again" + "[Modem] ARQ | RX | Frame already received - sending ACK again" ) else: @@ -795,12 +795,12 @@ class DATA: : search_position + get_position ] self.log.warning( - "[TNC] ARQ | RX | replacing existing buffer data", + "[Modem] ARQ | RX | replacing existing buffer data", area=search_area, pos=get_position, ) else: - self.log.debug("[TNC] ARQ | RX | appending data to buffer") + self.log.debug("[Modem] ARQ | RX | appending data to buffer") ARQ.rx_frame_buffer += temp_burst_buffer @@ -818,7 +818,7 @@ class DATA: self.data_channel_last_received = int(time.time()) + 6 + 6 self.burst_last_received = int(time.time()) + 6 + 6 # Create and send ACK frame - self.log.info("[TNC] ARQ | RX | SENDING ACK", finished=ARQ.arq_seconds_until_finish, + self.log.info("[Modem] ARQ | RX | SENDING ACK", finished=ARQ.arq_seconds_until_finish, bytesperminute=ARQ.bytes_per_minute) self.send_burst_ack_frame(snr) @@ -833,7 +833,7 @@ class DATA: # send a network message with information self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="receiving", uuid=self.transmission_uuid, @@ -853,7 +853,7 @@ class DATA: # # frame of a burst otherwise the entire burst is lost # # TODO: See if a timeout on the send side with re-transmit last burst would help. # self.log.debug( - # "[TNC] last frames of burst received:", + # "[Modem] last frames of burst received:", # frame=self.rx_n_frame_of_burst, # frames=self.rx_n_frames_per_burst, # @@ -864,20 +864,20 @@ class DATA: # elif self.rx_n_frame_of_burst not in [self.rx_n_frames_per_burst - 1]: # self.log.info( - # "[TNC] data_handler: received burst", + # "[Modem] data_handler: received burst", # frame=self.rx_n_frame_of_burst + 1, # frames=self.rx_n_frames_per_burst, # ) # else: # self.log.error( - # "[TNC] data_handler: Should not reach this point...", + # "[Modem] data_handler: Should not reach this point...", # frame=self.rx_n_frame_of_burst + 1, # frames=self.rx_n_frames_per_burst, # ) else: self.log.warning( - "[TNC] data_handler: missing data in burst buffer...", + "[Modem] data_handler: missing data in burst buffer...", frame=self.rx_n_frame_of_burst + 1, frames=self.rx_n_frames_per_burst ) @@ -898,7 +898,7 @@ class DATA: and None not in ARQ.rx_burst_buffer ): self.log.debug( - "[TNC] arq_data_received:", + "[Modem] arq_data_received:", bof_position=bof_position, eof_position=eof_position, ) @@ -920,9 +920,9 @@ class DATA: data_frame_crc_received = helpers.get_crc_32(data_frame) # check if hmac signing enabled - if TNC.enable_hmac: + if Modem.enable_hmac: self.log.info( - "[TNC] [HMAC] Enabled", + "[Modem] [HMAC] Enabled", ) # now check if we have valid hmac signature - returns salt or bool salt_found = helpers.search_hmac_salt(self.dxcallsign, self.mycallsign, data_frame_crc, data_frame, token_iters=100) @@ -937,12 +937,12 @@ class DATA: self.arq_process_received_data_frame(data_frame, snr, signed=False) elif data_frame_crc == data_frame_crc_received: self.log.warning( - "[TNC] [HMAC] Disabled, using CRC", + "[Modem] [HMAC] Disabled, using CRC", ) self.arq_process_received_data_frame(data_frame, snr, signed=False) else: self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="failed", uuid=self.transmission_uuid, @@ -953,7 +953,7 @@ class DATA: duration = time.time() - self.rx_start_of_transmission self.log.warning( - "[TNC] ARQ | RX | DATA FRAME NOT SUCCESSFULLY RECEIVED!", + "[Modem] ARQ | RX | DATA FRAME NOT SUCCESSFULLY RECEIVED!", e="wrong crc", expected=data_frame_crc.hex(), received=data_frame_crc_received.hex(), @@ -965,10 +965,10 @@ class DATA: data=data_frame, ) - if TNC.enable_stats: + if Modem.enable_stats: self.stats.push(frame_nack_counter=self.frame_nack_counter, status="wrong_crc", duration=duration) - self.log.info("[TNC] ARQ | RX | Sending NACK", finished=ARQ.arq_seconds_until_finish, + self.log.info("[Modem] ARQ | RX | Sending NACK", finished=ARQ.arq_seconds_until_finish, bytesperminute=ARQ.bytes_per_minute) self.send_burst_nack_frame(snr) @@ -1003,7 +1003,7 @@ class DATA: mode_slots = FREEDV_MODE_USED_SLOTS[mode_name].value if mode_slots in [ModemParam.channel_busy_slot]: self.log.warning( - "[TNC] busy slot detection", + "[Modem] busy slot detection", slots=ModemParam.channel_busy_slot, mode_slots=mode_slots, ) @@ -1027,7 +1027,7 @@ class DATA: else: - self.log.info("[TNC] ARQ | increasing speed level not possible because of SNR limit", + self.log.info("[Modem] ARQ | increasing speed level not possible because of SNR limit", given_snr=ModemParam.snr, needed_snr=self.snr_list[new_speed_level] ) @@ -1054,7 +1054,7 @@ class DATA: self.calculate_transfer_rate_rx( self.rx_start_of_transmission, len(ARQ.rx_frame_buffer) ) - self.log.info("[TNC] ARQ | RX | DATA FRAME SUCCESSFULLY RECEIVED", nacks=self.frame_nack_counter, + self.log.info("[Modem] ARQ | RX | DATA FRAME SUCCESSFULLY RECEIVED", nacks=self.frame_nack_counter, bytesperminute=ARQ.bytes_per_minute, total_bytes=ARQ.total_bytes, duration=duration, hmac_signed=signed) # Decompress the data frame @@ -1077,7 +1077,7 @@ class DATA: else: # if full, free space by getting an item self.log.info( - "[TNC] ARQ | RX | RX_BUFFER FULL - dropping old data", + "[Modem] ARQ | RX | RX_BUFFER FULL - dropping old data", buffer_size=RX_BUFFER.qsize(), maxsize=int(ARQ.rx_buffer_size) ) @@ -1085,7 +1085,7 @@ class DATA: # add item to RX_BUFFER self.log.info( - "[TNC] ARQ | RX | saving data to rx buffer", + "[Modem] ARQ | RX | saving data to rx buffer", buffer_size=RX_BUFFER.qsize() + 1, maxsize=RX_BUFFER.maxsize ) @@ -1125,7 +1125,7 @@ class DATA: # # Occurs on Raspberry Pi and Python 3.7 self.log.error( - "[TNC] ARQ | RX | error occurred when saving data!", + "[Modem] ARQ | RX | error occurred when saving data!", e=e, uuid=self.transmission_uuid, timestamp=timestamp, @@ -1146,7 +1146,7 @@ class DATA: ) except Exception as e: self.log.error( - "[TNC] ARQ | RX | can't save file to folder", + "[Modem] ARQ | RX | can't save file to folder", e=e, uuid=self.transmission_uuid, timestamp=timestamp, @@ -1156,7 +1156,7 @@ class DATA: ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="received", uuid=self.transmission_uuid, @@ -1176,12 +1176,12 @@ class DATA: speed_list=ARQ.speed_list ) - if TNC.enable_stats: + if Modem.enable_stats: duration = time.time() - self.rx_start_of_transmission self.stats.push(frame_nack_counter=self.frame_nack_counter, status="received", duration=duration) self.log.info( - "[TNC] ARQ | RX | SENDING DATA FRAME ACK") + "[Modem] ARQ | RX | SENDING DATA FRAME ACK") self.send_data_ack_frame(snr) # Update statistics AFTER the frame ACK is sent @@ -1190,7 +1190,7 @@ class DATA: ) self.log.info( - "[TNC] | RX | DATACHANNEL [" + "[Modem] | RX | DATACHANNEL [" + str(self.mycallsign, "UTF-8") + "]<< >>[" + str(Station.dxcallsign, "UTF-8") @@ -1228,7 +1228,7 @@ class DATA: compression_factor = bytes([int(ARQ.arq_compression_factor * 10)]) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="transmitting", uuid=self.transmission_uuid, @@ -1242,7 +1242,7 @@ class DATA: ) self.log.info( - "[TNC] | TX | DATACHANNEL", + "[Modem] | TX | DATACHANNEL", Bytes=ARQ.total_bytes, ) @@ -1259,12 +1259,12 @@ class DATA: hmac_digest = hmac.new(hmac_salt, data_out, hashlib.sha256).digest() # truncate to 32bit frame_payload_crc = hmac_digest[:4] - self.log.debug("[TNC] frame payload HMAC:", crc=frame_payload_crc.hex()) + self.log.debug("[Modem] frame payload HMAC:", crc=frame_payload_crc.hex()) else: # Append a crc at the beginning and end of file indicators frame_payload_crc = helpers.get_crc_32(data_out) - self.log.debug("[TNC] frame payload CRC:", crc=frame_payload_crc.hex()) + self.log.debug("[Modem] frame payload CRC:", crc=frame_payload_crc.hex()) # Assemble the data frame data_out = ( @@ -1275,7 +1275,7 @@ class DATA: + data_out + self.data_frame_eof ) - self.log.debug("[TNC] frame raw data:", data=data_out) + self.log.debug("[Modem] frame raw data:", data=data_out) # Initial bufferposition is 0 bufferposition = 0 bufferposition_end = 0 @@ -1295,7 +1295,7 @@ class DATA: data_mode = self.mode_list[self.speed_level] self.log.debug( - "[TNC] Speed-level:", + "[Modem] Speed-level:", level=self.speed_level, retry=self.tx_n_retry_of_burst, mode=FREEDV_MODE(data_mode).name, @@ -1304,7 +1304,7 @@ class DATA: # Payload information payload_per_frame = modem.get_bytes_per_frame(data_mode) - 2 - self.log.info("[TNC] early buffer info", + self.log.info("[Modem] early buffer info", bufferposition=bufferposition, bufferposition_end=bufferposition_end, bufferposition_burst_start=bufferposition_burst_start @@ -1322,7 +1322,7 @@ class DATA: break else: n_frames_per_burst = 1 - self.log.info("[TNC] calculated frames_per_burst:", n=n_frames_per_burst) + self.log.info("[Modem] calculated frames_per_burst:", n=n_frames_per_burst) tempbuffer = [] self.rpt_request_buffer = [] @@ -1335,14 +1335,14 @@ class DATA: arqheader[2:3] = self.session_id # only check for buffer position if at least one NACK received - self.log.info("[TNC] ----- data buffer position:", iss_buffer_pos=bufferposition, + self.log.info("[Modem] ----- data buffer position:", iss_buffer_pos=bufferposition, irs_bufferposition=self.irs_buffer_position) if self.frame_nack_counter > 0 and self.irs_buffer_position != bufferposition: - self.log.error("[TNC] ----- data buffer offset:", iss_buffer_pos=bufferposition, + self.log.error("[Modem] ----- data buffer offset:", iss_buffer_pos=bufferposition, irs_bufferposition=self.irs_buffer_position) # only adjust buffer position for experimental versions - if 'exp' in TNC.version: - self.log.warning("[TNC] ----- data adjustment disabled!") + if 'exp' in Modem.version: + self.log.warning("[Modem] ----- data adjustment disabled!") # bufferposition = self.irs_buffer_position bufferposition_end = bufferposition + payload_per_frame - len(arqheader) @@ -1367,9 +1367,9 @@ class DATA: # set new buffer position bufferposition = bufferposition_end - self.log.debug("[TNC] tempbuffer:", tempbuffer=tempbuffer) + self.log.debug("[Modem] tempbuffer:", tempbuffer=tempbuffer) self.log.info( - "[TNC] ARQ | TX | FRAMES", + "[Modem] ARQ | TX | FRAMES", mode=FREEDV_MODE(data_mode).name, fpb=n_frames_per_burst, retry=self.tx_n_retry_of_burst, @@ -1392,7 +1392,7 @@ class DATA: self.burst_ack = False # reset ack state self.tx_n_retry_of_burst = 0 # reset retries self.log.debug( - "[TNC] arq_transmit: Received BURST ACK. Sending next chunk." + "[Modem] arq_transmit: Received BURST ACK. Sending next chunk." , irs_snr=self.burst_ack_snr) # update temp bufferposition for n frames per burst early calculation bufferposition_burst_start = bufferposition_end @@ -1400,7 +1400,7 @@ class DATA: if self.data_frame_ack_received: self.log.debug( - "[TNC] arq_transmit: Received FRAME ACK. Braking retry loop." + "[Modem] arq_transmit: Received FRAME ACK. Braking retry loop." ) break # break retry loop @@ -1408,7 +1408,7 @@ class DATA: self.tx_n_retry_of_burst += 1 self.log.warning( - "[TNC] arq_transmit: Received BURST NACK. Resending data", + "[Modem] arq_transmit: Received BURST NACK. Resending data", bufferposition_burst_start=bufferposition_burst_start, bufferposition=bufferposition ) @@ -1422,7 +1422,7 @@ class DATA: # ARQ.arq_state == "DATA" --> when stopping transmission manually if not ARQ.arq_state: self.log.debug( - "[TNC] arq_transmit: ARQ State changed to FALSE. Breaking retry loop." + "[Modem] arq_transmit: ARQ State changed to FALSE. Breaking retry loop." ) break @@ -1431,7 +1431,7 @@ class DATA: ) # NEXT ATTEMPT self.log.debug( - "[TNC] ATTEMPT:", + "[Modem] ATTEMPT:", retry=self.tx_n_retry_of_burst, maxretries=self.tx_n_max_retries_per_burst, overflows=AudioParam.buffer_overflow_counter, @@ -1446,7 +1446,7 @@ class DATA: ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="transmitting", uuid=self.transmission_uuid, @@ -1464,7 +1464,7 @@ class DATA: # the loop exits after sending the last frame only once and doesn't # wait for an acknowledgement. if self.data_frame_ack_received and bufferposition > len(data_out): - self.log.debug("[TNC] arq_tx: Last fragment sent and acknowledged.") + self.log.debug("[Modem] arq_tx: Last fragment sent and acknowledged.") break # GOING TO NEXT ITERATION @@ -1475,7 +1475,7 @@ class DATA: if TESTMODE: # Quit after transmission - self.log.debug("[TNC] TESTMODE: arq_transmit exiting.") + self.log.debug("[Modem] TESTMODE: arq_transmit exiting.") sys.exit(0) def arq_transmit_success(self): @@ -1488,7 +1488,7 @@ class DATA: # so let's sleep a little threading.Event().wait(0.2) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="transmitted", uuid=self.transmission_uuid, @@ -1504,7 +1504,7 @@ class DATA: ) self.log.info( - "[TNC] ARQ | TX | DATA TRANSMITTED!", + "[Modem] ARQ | TX | DATA TRANSMITTED!", BytesPerMinute=ARQ.bytes_per_minute, total_bytes=ARQ.total_bytes, BitsPerSecond=ARQ.arq_bits_per_second, @@ -1520,7 +1520,7 @@ class DATA: will be called if we not successfully transmitted all of queued data """ self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="failed", uuid=self.transmission_uuid, @@ -1535,7 +1535,7 @@ class DATA: ) self.log.info( - "[TNC] ARQ | TX | TRANSMISSION FAILED OR TIME OUT!", + "[Modem] ARQ | TX | TRANSMISSION FAILED OR TIME OUT!", overflows=AudioParam.buffer_overflow_counter, ) @@ -1568,7 +1568,7 @@ class DATA: if frametype == FR_TYPE.BURST_ACK.value: # Increase speed level if we received a burst ack # self.speed_level = min(self.speed_level + 1, len(self.mode_list) - 1) - # Force data retry loops of TX TNC to stop and continue with next frame + # Force data retry loops of TX Modem to stop and continue with next frame self.burst_ack = True # Reset burst nack counter self.burst_nack_counter = 0 @@ -1589,7 +1589,7 @@ class DATA: self.irs_buffer_position = int.from_bytes(data_in[5:9], "big") self.log.warning( - "[TNC] ARQ | TX | Burst NACK received", + "[Modem] ARQ | TX | Burst NACK received", burst_nack_counter=self.burst_nack_counter, irs_buffer_position=self.irs_buffer_position, ) @@ -1618,7 +1618,7 @@ class DATA: ModemParam.frequency_offset, HamlibParam.hamlib_frequency, ) - # Force data loops of TNC to stop and continue with next frame + # Force data loops of Modem to stop and continue with next frame self.data_frame_ack_received = True # Update arq_session and data_channel timestamp self.data_channel_last_received = int(time.time()) @@ -1634,7 +1634,7 @@ class DATA: data_in:bytes: """ - self.log.warning("[TNC] ARQ FRAME NACK RECEIVED - cleanup!", + self.log.warning("[Modem] ARQ FRAME NACK RECEIVED - cleanup!", arq="transmission", status="failed", uuid=self.transmission_uuid, @@ -1657,7 +1657,7 @@ class DATA: HamlibParam.hamlib_frequency, ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="failed", uuid=self.transmission_uuid, @@ -1684,7 +1684,7 @@ class DATA: """ # Only process data if we are in ARQ and BUSY state - if not ARQ.arq_state or TNC.tnc_state != "BUSY": + if not ARQ.arq_state or Modem.modem_state != "BUSY": return Station.dxgrid = b'------' helpers.add_to_heard_stations( @@ -1696,7 +1696,7 @@ class DATA: HamlibParam.hamlib_frequency, ) - self.log.info("[TNC] ARQ REPEAT RECEIVED") + self.log.info("[Modem] ARQ REPEAT RECEIVED") # self.rpt_request_received = True # Update data_channel timestamp @@ -1714,7 +1714,7 @@ class DATA: missing_frames_buffer_position = missing_area[i] - 1 tempbuffer_rptframes.append(self.rpt_request_buffer[missing_frames_buffer_position]) - self.log.info("[TNC] SENDING REPEAT....") + self.log.info("[Modem] SENDING REPEAT....") data_mode = self.mode_list[self.speed_level] self.enqueue_frame_for_tx(tempbuffer_rptframes, c2_mode=data_mode) @@ -1745,7 +1745,7 @@ class DATA: # TODO: we need to check this, maybe placing it to class init self.datachannel_timeout = False self.log.info( - "[TNC] SESSION [" + "[Modem] SESSION [" + str(self.mycallsign, "UTF-8") + "]>> <<[" + str(self.dxcallsign, "UTF-8") @@ -1755,9 +1755,9 @@ class DATA: # Let's check if we have a busy channel if ModemParam.channel_busy: - self.log.warning("[TNC] Channel busy, waiting until free...") + self.log.warning("[Modem] Channel busy, waiting until free...") self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="waiting", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -1771,10 +1771,10 @@ class DATA: # if channel busy timeout reached stop connecting if time.time() > channel_busy_timeout: - self.log.warning("[TNC] Channel busy, try again later...") + self.log.warning("[Modem] Channel busy, try again later...") ARQ.arq_session_state = "failed" self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="failed", reason="busy", @@ -1790,7 +1790,7 @@ class DATA: threading.Event().wait(0.01) ARQ.arq_session_state = "connecting" self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="connecting", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -1799,7 +1799,7 @@ class DATA: if ARQ.arq_session and ARQ.arq_session_state == "connected": # ARQ.arq_session_state = "connected" self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="connected", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -1808,7 +1808,7 @@ class DATA: return True self.log.warning( - "[TNC] SESSION FAILED [" + "[Modem] SESSION FAILED [" + str(self.mycallsign, "UTF-8") + "]>>X<<[" + str(self.dxcallsign, "UTF-8") @@ -1819,7 +1819,7 @@ class DATA: ) ARQ.arq_session_state = "failed" self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="failed", reason="timeout", @@ -1853,7 +1853,7 @@ class DATA: threading.Event().wait(0.01) for attempt in range(self.session_connect_max_retries): self.log.info( - "[TNC] SESSION [" + "[Modem] SESSION [" + str(self.mycallsign, "UTF-8") + "]>>?<<[" + str(self.dxcallsign, "UTF-8") @@ -1863,7 +1863,7 @@ class DATA: ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="connecting", attempt=attempt + 1, @@ -1898,7 +1898,7 @@ class DATA: # Given the while condition, it will only exit when `ARQ.arq_session` is True self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="connected", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -1914,7 +1914,7 @@ class DATA: data_in:bytes: """ # if we don't want to respond to calls, return False - if not TNC.respond_to_call: + if not Modem.respond_to_call: return False # ignore channel opener if already in ARQ STATE @@ -1949,7 +1949,7 @@ class DATA: HamlibParam.hamlib_frequency, ) self.log.info( - "[TNC] SESSION [" + "[Modem] SESSION [" + str(self.mycallsign, "UTF-8") + "]>>|<<[" + str(self.dxcallsign, "UTF-8") @@ -1957,10 +1957,10 @@ class DATA: state=ARQ.arq_session_state, ) ARQ.arq_session = True - TNC.tnc_state = "BUSY" + Modem.modem_state = "BUSY" self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="connected", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -1973,7 +1973,7 @@ class DATA: ARQ.arq_session_state = "disconnecting" self.log.info( - "[TNC] SESSION [" + "[Modem] SESSION [" + str(self.mycallsign, "UTF-8") + "]<>[" + str(self.dxcallsign, "UTF-8") @@ -1982,7 +1982,7 @@ class DATA: ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="close", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -2023,7 +2023,7 @@ class DATA: HamlibParam.hamlib_frequency, ) self.log.info( - "[TNC] SESSION [" + "[Modem] SESSION [" + str(mycallsign, "UTF-8") + "]<>[" + str(self.dxcallsign, "UTF-8") @@ -2032,7 +2032,7 @@ class DATA: ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="close", mycallsign=str(mycallsign, 'UTF-8'), @@ -2046,7 +2046,7 @@ class DATA: def transmit_session_heartbeat(self) -> None: """Send ARQ sesion heartbeat while connected""" # ARQ.arq_session = True - # TNC.tnc_state = "BUSY" + # Modem.modem_state = "BUSY" # ARQ.arq_session_state = "connected" connection_frame = bytearray(self.length_sig0_frame) @@ -2054,7 +2054,7 @@ class DATA: connection_frame[1:2] = self.session_id self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="connected", heartbeat="transmitting", @@ -2075,7 +2075,7 @@ class DATA: _valid_crc, _ = helpers.check_callsign(self.dxcallsign, bytes(data_in[4:7])) _valid_session = helpers.check_session_id(self.session_id, bytes(data_in[1:2])) if _valid_crc or _valid_session and ARQ.arq_session_state in ["connected", "connecting"]: - self.log.debug("[TNC] Received session heartbeat") + self.log.debug("[Modem] Received session heartbeat") Station.dxgrid = b'------' helpers.add_to_heard_stations( self.dxcallsign, @@ -2087,7 +2087,7 @@ class DATA: ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="connected", heartbeat="received", @@ -2097,7 +2097,7 @@ class DATA: ARQ.arq_session = True ARQ.arq_session_state = "connected" - TNC.tnc_state = "BUSY" + Modem.modem_state = "BUSY" # Update the timeout timestamps self.arq_session_last_received = int(time.time()) @@ -2152,7 +2152,7 @@ class DATA: # override session connection attempts self.data_channel_max_retries = attempts - TNC.tnc_state = "BUSY" + Modem.modem_state = "BUSY" self.arq_file_transfer = True self.transmission_uuid = transmission_uuid @@ -2172,7 +2172,7 @@ class DATA: self.arq_open_data_channel(mycallsign) # wait until data channel is open - while not ARQ.arq_state and not self.datachannel_timeout and TNC.tnc_state in ["BUSY"]: + while not ARQ.arq_state and not self.datachannel_timeout and Modem.modem_state in ["BUSY"]: threading.Event().wait(0.01) if ARQ.arq_state: @@ -2203,13 +2203,13 @@ class DATA: # Update data_channel timestamp self.data_channel_last_received = int(time.time()) - if TNC.low_bandwidth_mode: + if Modem.low_bandwidth_mode: frametype = bytes([FR_TYPE.ARQ_DC_OPEN_N.value]) - self.log.debug("[TNC] Requesting low bandwidth mode") + self.log.debug("[Modem] Requesting low bandwidth mode") else: frametype = bytes([FR_TYPE.ARQ_DC_OPEN_W.value]) - self.log.debug("[TNC] Requesting high bandwidth mode") + self.log.debug("[Modem] Requesting high bandwidth mode") connection_frame = bytearray(self.length_sig0_frame) connection_frame[:1] = frametype @@ -2223,7 +2223,7 @@ class DATA: for attempt in range(self.data_channel_max_retries): self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="opening", mycallsign=str(mycallsign, 'UTF-8'), @@ -2232,7 +2232,7 @@ class DATA: ) self.log.info( - "[TNC] ARQ | DATA | TX | [" + "[Modem] ARQ | DATA | TX | [" + str(mycallsign, "UTF-8") + "]>> <<[" + str(self.dxcallsign, "UTF-8") @@ -2242,9 +2242,9 @@ class DATA: # Let's check if we have a busy channel and if we are not in a running arq session. if ModemParam.channel_busy and not ARQ.arq_state: - self.log.warning("[TNC] Channel busy, waiting until free...") + self.log.warning("[Modem] Channel busy, waiting until free...") self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="waiting", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -2265,17 +2265,17 @@ class DATA: # Stop waiting if data channel is opened if ARQ.arq_state: return True - if TNC.tnc_state in ["IDLE"]: + if Modem.modem_state in ["IDLE"]: return False # `data_channel_max_retries` attempts have been sent. Aborting attempt & cleaning up self.log.debug( - "[TNC] arq_open_data_channel:", transmission_uuid=self.transmission_uuid + "[Modem] arq_open_data_channel:", transmission_uuid=self.transmission_uuid ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="failed", reason="unknown", @@ -2291,7 +2291,7 @@ class DATA: ) self.log.warning( - "[TNC] ARQ | TX | DATA [" + "[Modem] ARQ | TX | DATA [" + str(mycallsign, "UTF-8") + "]>>X<<[" + str(self.dxcallsign, "UTF-8") @@ -2320,12 +2320,12 @@ class DATA: # is intended for this station. # stop processing if we don't want to respond to a call when not in a arq session - if not TNC.respond_to_call and not ARQ.arq_session: + if not Modem.respond_to_call and not ARQ.arq_session: return False - # stop processing if not in arq session, but tnc state is busy and we have a different session id + # stop processing if not in arq session, but modem state is busy and we have a different session id # use-case we get a connection request while connecting to another station - if not ARQ.arq_session and TNC.tnc_state in ["BUSY"] and data_in[13:14] != self.session_id: + if not ARQ.arq_session and Modem.modem_state in ["BUSY"] and data_in[13:14] != self.session_id: return False self.arq_file_transfer = True @@ -2348,7 +2348,7 @@ class DATA: Station.dxcallsign = self.dxcallsign self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="opening", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -2367,7 +2367,7 @@ class DATA: # ISS(n) <-> IRS(w) # ISS(n) <-> IRS(n) - if frametype == FR_TYPE.ARQ_DC_OPEN_W.value and not TNC.low_bandwidth_mode: + if frametype == FR_TYPE.ARQ_DC_OPEN_W.value and not Modem.low_bandwidth_mode: # ISS(w) <-> IRS(w) constellation = "ISS(w) <-> IRS(w)" self.received_LOW_BANDWIDTH_MODE = False @@ -2381,7 +2381,7 @@ class DATA: self.mode_list = self.mode_list_low_bw self.time_list = self.time_list_low_bw self.snr_list = self.snr_list_low_bw - elif frametype == FR_TYPE.ARQ_DC_OPEN_N.value and not TNC.low_bandwidth_mode: + elif frametype == FR_TYPE.ARQ_DC_OPEN_N.value and not Modem.low_bandwidth_mode: # ISS(n) <-> IRS(w) constellation = "ISS(n) <-> IRS(w)" self.received_LOW_BANDWIDTH_MODE = True @@ -2418,13 +2418,13 @@ class DATA: if mode_slots in [ModemParam.channel_busy_slot]: self.speed_level = 0 self.log.warning( - "[TNC] busy slot detection", + "[Modem] busy slot detection", slots=ModemParam.channel_busy_slot, mode_slots=mode_slots, ) self.log.debug( - "[TNC] calculated speed level", + "[Modem] calculated speed level", speed_level=self.speed_level, given_snr=ModemParam.snr, min_snr=self.snr_list[self.speed_level], @@ -2448,7 +2448,7 @@ class DATA: _, self.mycallsign = helpers.check_callsign(self.mycallsign, data_in[1:4]) self.log.info( - "[TNC] ARQ | DATA | RX | [" + "[Modem] ARQ | DATA | RX | [" + str(self.mycallsign, "UTF-8") + "]>> <<[" + str(self.dxcallsign, "UTF-8") @@ -2463,17 +2463,17 @@ class DATA: # Set ARQ State AFTER resetting timeouts # this avoids timeouts starting too early ARQ.arq_state = True - TNC.tnc_state = "BUSY" + Modem.modem_state = "BUSY" self.reset_statistics() - # Select the frame type based on the current TNC mode - if TNC.low_bandwidth_mode or self.received_LOW_BANDWIDTH_MODE: + # Select the frame type based on the current Modem mode + if Modem.low_bandwidth_mode or self.received_LOW_BANDWIDTH_MODE: frametype = bytes([FR_TYPE.ARQ_DC_OPEN_ACK_N.value]) - self.log.debug("[TNC] Responding with low bandwidth mode") + self.log.debug("[Modem] Responding with low bandwidth mode") else: frametype = bytes([FR_TYPE.ARQ_DC_OPEN_ACK_W.value]) - self.log.debug("[TNC] Responding with high bandwidth mode") + self.log.debug("[Modem] Responding with high bandwidth mode") connection_frame = bytearray(self.length_sig0_frame) connection_frame[:1] = frametype @@ -2484,7 +2484,7 @@ class DATA: self.enqueue_frame_for_tx([connection_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="opened", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -2493,7 +2493,7 @@ class DATA: ) self.log.info( - "[TNC] ARQ | DATA | RX | [" + "[Modem] ARQ | DATA | RX | [" + str(self.mycallsign, "UTF-8") + "]>>|<<[" + str(self.dxcallsign, "UTF-8") @@ -2519,7 +2519,7 @@ class DATA: protocol_version = int.from_bytes(bytes(data_in[13:14]), "big") if protocol_version == ARQ.arq_protocol_version: self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="opened", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -2532,16 +2532,16 @@ class DATA: self.received_LOW_BANDWIDTH_MODE = True self.mode_list = self.mode_list_low_bw self.time_list = self.time_list_low_bw - self.log.debug("[TNC] low bandwidth mode", modes=self.mode_list) + self.log.debug("[Modem] low bandwidth mode", modes=self.mode_list) else: self.received_LOW_BANDWIDTH_MODE = False self.mode_list = self.mode_list_high_bw self.time_list = self.time_list_high_bw - self.log.debug("[TNC] high bandwidth mode", modes=self.mode_list) + self.log.debug("[Modem] high bandwidth mode", modes=self.mode_list) # set speed level from session opener frame which is selected by SNR measurement 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.log.debug("[Modem] speed level selected for given SNR", speed_level=self.speed_level) # self.speed_level = len(self.mode_list) - 1 Station.dxgrid = b'------' helpers.add_to_heard_stations( @@ -2554,7 +2554,7 @@ class DATA: ) self.log.info( - "[TNC] ARQ | DATA | TX | [" + "[Modem] ARQ | DATA | TX | [" + str(self.mycallsign, "UTF-8") + "]>>|<<[" + str(self.dxcallsign, "UTF-8") @@ -2567,10 +2567,10 @@ class DATA: # Update data_channel timestamp self.data_channel_last_received = int(time.time()) else: - TNC.tnc_state = "IDLE" + Modem.modem_state = "IDLE" ARQ.arq_state = False self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="failed", reason="protocol version missmatch", @@ -2580,7 +2580,7 @@ class DATA: ) # TODO: We should display a message to this effect on the UI. self.log.warning( - "[TNC] protocol version mismatch:", + "[Modem] protocol version mismatch:", received=protocol_version, own=ARQ.arq_protocol_version, ) @@ -2597,19 +2597,19 @@ class DATA: """ if not str(dxcallsign).strip(): # TODO: We should display a message to this effect on the UI. - self.log.warning("[TNC] Missing required callsign", dxcallsign=dxcallsign) + self.log.warning("[Modem] Missing required callsign", dxcallsign=dxcallsign) return Station.dxcallsign = dxcallsign Station.dxcallsign_crc = helpers.get_crc_24(Station.dxcallsign) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", ping="transmitting", dxcallsign=str(dxcallsign, "UTF-8"), mycallsign=str(mycallsign, "UTF-8"), snr=str(ModemParam.snr), ) self.log.info( - "[TNC] PING REQ [" + "[Modem] PING REQ [" + str(mycallsign, "UTF-8") + "] >>> [" + str(dxcallsign, "UTF-8") @@ -2622,8 +2622,8 @@ class DATA: ping_frame[4:7] = helpers.get_crc_24(mycallsign) ping_frame[7:13] = helpers.callsign_to_bytes(mycallsign) - if TNC.enable_fsk: - self.log.info("[TNC] ENABLE FSK", state=TNC.enable_fsk) + if Modem.enable_fsk: + self.log.info("[Modem] ENABLE FSK", state=Modem.enable_fsk) self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) else: self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.sig0.value) @@ -2643,13 +2643,13 @@ class DATA: valid, mycallsign = helpers.check_callsign(self.mycallsign, data_in[1:4]) if not valid: # PING packet not for me. - self.log.debug("[TNC] received_ping: ping not for this station.") + self.log.debug("[Modem] received_ping: ping not for this station.") return Station.dxcallsign_crc = dxcallsign_crc Station.dxcallsign = dxcallsign self.log.info( - "[TNC] PING REQ [" + "[Modem] PING REQ [" + str(mycallsign, "UTF-8") + "] <<< [" + str(dxcallsign, "UTF-8") @@ -2668,7 +2668,7 @@ class DATA: ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", ping="received", uuid=str(uuid.uuid4()), timestamp=int(time.time()), @@ -2677,7 +2677,7 @@ class DATA: mycallsign=str(mycallsign, "UTF-8"), snr=str(ModemParam.snr), ) - if TNC.respond_to_call: + if Modem.respond_to_call: self.transmit_ping_ack() def transmit_ping_ack(self): @@ -2693,7 +2693,7 @@ class DATA: ping_frame[7:11] = helpers.encode_grid(Station.mygrid.decode("UTF-8")) ping_frame[13:14] = helpers.snr_to_bytes(ModemParam.snr) - if TNC.enable_fsk: + if Modem.enable_fsk: self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) else: self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.sig0.value) @@ -2714,7 +2714,7 @@ class DATA: Station.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", + freedata="modem-message", ping="acknowledge", uuid=str(uuid.uuid4()), timestamp=int(time.time()), @@ -2736,7 +2736,7 @@ class DATA: ) self.log.info( - "[TNC] PING ACK [" + "[Modem] PING ACK [" + str(mycallsign, "UTF-8") + "] >|< [" + str(Station.dxcallsign, "UTF-8") @@ -2744,10 +2744,10 @@ class DATA: snr=ModemParam.snr, dxsnr=dxsnr, ) - TNC.tnc_state = "IDLE" + Modem.modem_state = "IDLE" else: self.log.info( - "[TNC] FOREIGN PING ACK [" + "[Modem] FOREIGN PING ACK [" + str(self.mycallsign, "UTF-8") + "] ??? [" + str(bytes(data_in[4:7]), "UTF-8") @@ -2759,12 +2759,12 @@ class DATA: """ Force a stop of the running transmission """ - self.log.warning("[TNC] Stopping transmission!") + self.log.warning("[Modem] Stopping transmission!") - TNC.tnc_state = "IDLE" + Modem.modem_state = "IDLE" ARQ.arq_state = False self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="stopped", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -2789,11 +2789,11 @@ class DATA: """ Received a transmission stop """ - self.log.warning("[TNC] Stopping transmission!") - TNC.tnc_state = "IDLE" + self.log.warning("[Modem] Stopping transmission!") + Modem.modem_state = "IDLE" ARQ.arq_state = False self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="stopped", mycallsign=str(self.mycallsign, 'UTF-8'), @@ -2822,17 +2822,17 @@ class DATA: and not self.arq_file_transfer and not Beacon.beacon_pause #and not ModemParam.channel_busy - and TNC.tnc_state not in ["BUSY"] + and Modem.modem_state not in ["BUSY"] and not ARQ.arq_state ): self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", beacon="transmitting", dxcallsign="None", interval=self.beacon_interval, ) self.log.info( - "[TNC] Sending beacon!", interval=self.beacon_interval + "[Modem] Sending beacon!", interval=self.beacon_interval ) beacon_frame = bytearray(self.length_sig0_frame) @@ -2840,8 +2840,8 @@ class DATA: beacon_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign) beacon_frame[7:11] = helpers.encode_grid(Station.mygrid.decode("UTF-8")) - if TNC.enable_fsk: - self.log.info("[TNC] ENABLE FSK", state=TNC.enable_fsk) + if Modem.enable_fsk: + self.log.info("[Modem] ENABLE FSK", state=Modem.enable_fsk) self.enqueue_frame_for_tx( [beacon_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value, @@ -2859,7 +2859,7 @@ class DATA: threading.Event().wait(0.01) except Exception as err: - self.log.debug("[TNC] run_beacon: ", exception=err) + self.log.debug("[Modem] run_beacon: ", exception=err) def received_beacon(self, data_in: bytes) -> None: """ @@ -2872,7 +2872,7 @@ class DATA: beacon_callsign = helpers.bytes_to_callsign(bytes(data_in[1:7])) Station.dxgrid = bytes(helpers.decode_grid(data_in[7:11]), "UTF-8") self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", beacon="received", uuid=str(uuid.uuid4()), timestamp=int(time.time()), @@ -2882,7 +2882,7 @@ class DATA: ) self.log.info( - "[TNC] BEACON RCVD [" + "[Modem] BEACON RCVD [" + str(beacon_callsign, "UTF-8") + "][" + str(Station.dxgrid, "UTF-8") @@ -2907,9 +2907,9 @@ class DATA: Returns: Nothing """ - self.log.info("[TNC] CQ CQ CQ") + self.log.info("[Modem] CQ CQ CQ") self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", cq="transmitting", mycallsign=str(self.mycallsign, "UTF-8"), dxcallsign="None", @@ -2919,15 +2919,15 @@ class DATA: cq_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign) cq_frame[7:11] = helpers.encode_grid(Station.mygrid.decode("UTF-8")) - self.log.debug("[TNC] CQ Frame:", data=[cq_frame]) + self.log.debug("[Modem] CQ Frame:", data=[cq_frame]) - if TNC.enable_fsk: - self.log.info("[TNC] ENABLE FSK", state=TNC.enable_fsk) + if Modem.enable_fsk: + self.log.info("[Modem] ENABLE FSK", state=Modem.enable_fsk) self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) else: self.enqueue_frame_for_tx([cq_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0) # FIXME: Remove or change this in later versions for full CW support - # TNC.transmitting = True + # Modem.transmitting = True # modem.MODEM_TRANSMIT_QUEUE.put(["morse", 1, 0, "123"]) def received_cq(self, data_in: bytes) -> None: @@ -2941,18 +2941,18 @@ 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) + self.log.debug("[Modem] received_cq:", dxcallsign=dxcallsign) Station.dxgrid = bytes(helpers.decode_grid(data_in[7:11]), "UTF-8") self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", cq="received", mycallsign=str(self.mycallsign, "UTF-8"), dxcallsign=str(dxcallsign, "UTF-8"), dxgrid=str(Station.dxgrid, "UTF-8"), ) self.log.info( - "[TNC] CQ RCVD [" + "[Modem] CQ RCVD [" + str(dxcallsign, "UTF-8") + "][" + str(Station.dxgrid, "UTF-8") @@ -2968,7 +2968,7 @@ class DATA: HamlibParam.hamlib_frequency, ) - if TNC.respond_to_cq and TNC.respond_to_call: + if Modem.respond_to_cq and Modem.respond_to_call: self.transmit_qrv(dxcallsign) def transmit_qrv(self, dxcallsign: bytes) -> None: @@ -2986,15 +2986,15 @@ class DATA: # in self.duration_sig1_frame increments. # FIXME: This causes problems when running ctests - we need to figure out why if not TESTMODE: - self.log.info("[TNC] Waiting for QRV slot...") + self.log.info("[Modem] Waiting for QRV slot...") helpers.wait(randrange(0, int(self.duration_sig1_frame * 4), self.duration_sig1_frame * 10 // 10.0)) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", qrv="transmitting", dxcallsign=str(dxcallsign, "UTF-8"), ) - self.log.info("[TNC] Sending QRV!") + self.log.info("[Modem] Sending QRV!") qrv_frame = bytearray(self.length_sig0_frame) qrv_frame[:1] = bytes([FR_TYPE.QRV.value]) @@ -3002,8 +3002,8 @@ class DATA: qrv_frame[7:11] = helpers.encode_grid(Station.mygrid.decode("UTF-8")) qrv_frame[11:12] = helpers.snr_to_bytes(ModemParam.snr) - if TNC.enable_fsk: - self.log.info("[TNC] ENABLE FSK", state=TNC.enable_fsk) + if Modem.enable_fsk: + self.log.info("[Modem] ENABLE FSK", state=Modem.enable_fsk) self.enqueue_frame_for_tx([qrv_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) else: self.enqueue_frame_for_tx([qrv_frame], c2_mode=FREEDV_MODE.sig0.value, copies=1, repeat_delay=0) @@ -3023,7 +3023,7 @@ class DATA: combined_snr = f"{ModemParam.snr}/{dxsnr}" self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", qrv="received", dxcallsign=str(dxcallsign, "UTF-8"), dxgrid=str(Station.dxgrid, "UTF-8"), @@ -3032,7 +3032,7 @@ class DATA: ) self.log.info( - "[TNC] QRV RCVD [" + "[Modem] QRV RCVD [" + str(dxcallsign, "UTF-8") + "][" + str(Station.dxgrid, "UTF-8") @@ -3062,13 +3062,13 @@ class DATA: dxcallsign = helpers.bytes_to_callsign(bytes(data_in[1:7])) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", fec="is_writing", dxcallsign=str(dxcallsign, "UTF-8") ) self.log.info( - "[TNC] IS_WRITING RCVD [" + "[Modem] IS_WRITING RCVD [" + str(dxcallsign, "UTF-8") + "] ", ) @@ -3122,7 +3122,7 @@ class DATA: ARQ.bytes_per_minute = 0 ARQ.arq_seconds_until_finish = 0 except Exception as err: - self.log.error(f"[TNC] calculate_transfer_rate_rx: Exception: {err}") + self.log.error(f"[Modem] calculate_transfer_rate_rx: Exception: {err}") ARQ.arq_transmission_percent = 0.0 ARQ.arq_bits_per_second = 0 ARQ.bytes_per_minute = 0 @@ -3186,7 +3186,7 @@ class DATA: ARQ.arq_seconds_until_finish = 0 except Exception as err: - self.log.error(f"[TNC] calculate_transfer_rate_tx: Exception: {err}") + self.log.error(f"[Modem] calculate_transfer_rate_tx: Exception: {err}") ARQ.arq_transmission_percent = 0.0 ARQ.arq_bits_per_second = 0 ARQ.bytes_per_minute = 0 @@ -3203,10 +3203,10 @@ class DATA: Cleanup function which clears all ARQ states """ if TESTMODE: - self.log.debug("[TNC] TESTMODE: arq_cleanup: Not performing cleanup.") + self.log.debug("[Modem] TESTMODE: arq_cleanup: Not performing cleanup.") return - self.log.debug("[TNC] arq_cleanup") + self.log.debug("[Modem] arq_cleanup") # wait a second for smoother arq behaviour helpers.wait(1.0) @@ -3255,7 +3255,7 @@ class DATA: # we need to keep these values if in ARQ_SESSION if not ARQ.arq_session: - TNC.tnc_state = "IDLE" + Modem.modem_state = "IDLE" self.dxcallsign = b"AA0AA-0" self.mycallsign = Station.mycallsign self.session_id = bytes(1) @@ -3300,32 +3300,32 @@ class DATA: modem.RECEIVE_DATAC3 = False modem.RECEIVE_DATAC4 = False modem.RECEIVE_FSK_LDPC_1 = False - self.log.debug("[TNC] Changing listening data mode", mode="datac1") + self.log.debug("[Modem] Changing listening data mode", mode="datac1") elif mode == codec2.FREEDV_MODE.datac3.value: modem.RECEIVE_DATAC1 = False modem.RECEIVE_DATAC3 = True modem.RECEIVE_DATAC4 = False modem.RECEIVE_FSK_LDPC_1 = False - self.log.debug("[TNC] Changing listening data mode", mode="datac3") + self.log.debug("[Modem] Changing listening data mode", mode="datac3") elif mode == codec2.FREEDV_MODE.datac4.value: modem.RECEIVE_DATAC1 = False modem.RECEIVE_DATAC3 = False modem.RECEIVE_DATAC4 = True modem.RECEIVE_FSK_LDPC_1 = False - self.log.debug("[TNC] Changing listening data mode", mode="datac4") + self.log.debug("[Modem] Changing listening data mode", mode="datac4") elif mode == codec2.FREEDV_MODE.fsk_ldpc_1.value: modem.RECEIVE_DATAC1 = False modem.RECEIVE_DATAC3 = False modem.RECEIVE_DATAC4 = False modem.RECEIVE_FSK_LDPC_1 = True - self.log.debug("[TNC] Changing listening data mode", mode="fsk_ldpc_1") + self.log.debug("[Modem] Changing listening data mode", mode="fsk_ldpc_1") else: modem.RECEIVE_DATAC1 = True modem.RECEIVE_DATAC3 = True modem.RECEIVE_DATAC4 = True modem.RECEIVE_FSK_LDPC_1 = True self.log.debug( - "[TNC] Changing listening data mode", mode="datac1/datac3/fsk_ldpc" + "[Modem] Changing listening data mode", mode="datac1/datac3/fsk_ldpc" ) # ------------------------- WATCHDOG FUNCTIONS FOR TIMER @@ -3380,7 +3380,7 @@ class DATA: # print(f"timeout expected in:{round(timeout - time.time())} | frames left: {frames_left} of {self.rx_n_frames_per_burst} | speed level: {self.speed_level}") if timeout <= time.time() or modem_error_state: self.log.warning( - "[TNC] Burst decoding error or timeout", + "[Modem] Burst decoding error or timeout", attempt=self.n_retries_per_burst, max_attempts=self.rx_n_max_retries_per_burst, speed_level=self.speed_level, @@ -3439,7 +3439,7 @@ class DATA: DATA CHANNEL """ # and not static.ARQ_SEND_KEEP_ALIVE: - if ARQ.arq_state and TNC.tnc_state == "BUSY": + if ARQ.arq_state and Modem.modem_state == "BUSY": threading.Event().wait(0.01) if ( self.data_channel_last_received + self.transmission_timeout @@ -3458,14 +3458,14 @@ class DATA: # Clear the timeout timestamp self.data_channel_last_received = 0 self.log.info( - "[TNC] DATA [" + "[Modem] DATA [" + str(self.mycallsign, "UTF-8") + "]<>[" + str(Station.dxcallsign, "UTF-8") + "]" ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="transmission", status="failed", uuid=self.transmission_uuid, @@ -3482,21 +3482,21 @@ class DATA: """ if ( ARQ.arq_session - and TNC.tnc_state == "BUSY" + and Modem.modem_state == "BUSY" and not self.arq_file_transfer ): if self.arq_session_last_received + self.arq_session_timeout > time.time(): threading.Event().wait(0.01) else: self.log.info( - "[TNC] SESSION [" + "[Modem] SESSION [" + str(self.mycallsign, "UTF-8") + "]<>[" + str(self.dxcallsign, "UTF-8") + "]" ) self.send_data_to_socket_queue( - freedata="tnc-message", + freedata="modem-message", arq="session", status="failed", reason="timeout", @@ -3572,7 +3572,7 @@ class DATA: # send burst only if channel not busy - but without waiting # otherwise burst will be dropped - if not ModemParam.channel_busy and not TNC.transmitting: + if not ModemParam.channel_busy and not Modem.transmitting: self.enqueue_frame_for_tx( frame_to_tx=[fec_frame], c2_mode=codec2.FREEDV_MODE["sig0"].value ) @@ -3596,7 +3596,7 @@ class DATA: try: - self.log.info("[TNC] ARQ | RX | saving data to folder") + self.log.info("[Modem] ARQ | RX | saving data to folder") mycallsign = str(mycallsign, "UTF-8") dxcallsign = str(dxcallsign, "UTF-8") @@ -3639,7 +3639,7 @@ class DATA: crc = helpers.get_crc_32(data).hex().lower() validity = checksum_delivered == crc self.log.info( - "[TNC] ARQ | RX | checking data crc", + "[Modem] ARQ | RX | checking data crc", crc_delivered=checksum_delivered, crc_calculated=crc, valid=validity, @@ -3656,4 +3656,4 @@ class DATA: file.write(message) except Exception as e: - self.log.error("[TNC] error saving data to folder", e=e) \ No newline at end of file + self.log.error("[Modem] error saving data to folder", e=e) \ No newline at end of file diff --git a/tnc/exceptions.py b/modem/exceptions.py similarity index 100% rename from tnc/exceptions.py rename to modem/exceptions.py diff --git a/tnc/explorer.py b/modem/explorer.py similarity index 92% rename from tnc/explorer.py rename to modem/explorer.py index 439683ba..e6a65bcc 100644 --- a/tnc/explorer.py +++ b/modem/explorer.py @@ -13,7 +13,7 @@ import time import ujson as json import structlog import static -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem log = structlog.get_logger("explorer") @@ -38,8 +38,8 @@ class explorer(): band = "USB" callsign = str(Station.mycallsign, "utf-8") gridsquare = str(Station.mygrid, "utf-8") - version = str(TNC.version) - bandwidth = str(TNC.low_bandwidth_mode) + version = str(Modem.version) + bandwidth = str(Modem.low_bandwidth_mode) beacon = str(Beacon.beacon_state) strength = str(HamlibParam.hamlib_strength) @@ -48,7 +48,7 @@ class explorer(): headers = {"Content-Type": "application/json"} station_data = {'callsign': callsign, 'gridsquare': gridsquare, 'frequency': frequency, 'strength': strength, 'band': band, 'version': version, 'bandwidth': bandwidth, 'beacon': beacon, "lastheard": []} - for i in TNC.heard_stations: + for i in Modem.heard_stations: try: callsign = str(i[0], "UTF-8") grid = str(i[1], "UTF-8") diff --git a/tnc/freedata.spec b/modem/freedata.spec similarity index 83% rename from tnc/freedata.spec rename to modem/freedata.spec index feb115de..6ae5fdc1 100644 --- a/tnc/freedata.spec +++ b/modem/freedata.spec @@ -41,8 +41,8 @@ daemon_a.datas += Tree('lib', prefix='lib') # daemon_a.datas += Tree('./codec2', prefix='codec2') -# TNC -------------------------------------------------- -tnc_a = Analysis(['main.py'], +# Modem -------------------------------------------------- +modem_a = Analysis(['main.py'], pathex=[], binaries=[], datas=[], @@ -55,15 +55,15 @@ tnc_a = Analysis(['main.py'], win_private_assemblies=False, cipher=block_cipher, noarchive=False) -tnc_pyz = PYZ(tnc_a.pure, tnc_a.zipped_data, +modem_pyz = PYZ(modem_a.pure, modem_a.zipped_data, cipher=block_cipher) -tnc_exe = EXE(tnc_pyz, - tnc_a.scripts, +modem_exe = EXE(modem_pyz, + modem_a.scripts, [], exclude_binaries=True, - name='freedata-tnc', - bundle_identifier='com.dj2ls.freedata-tnc', + name='freedata-modem', + bundle_identifier='com.dj2ls.freedata-modem', debug=False, bootloader_ignore_signals=False, strip=False, @@ -79,11 +79,11 @@ coll = COLLECT(daemon_exe, daemon_a.binaries, daemon_a.zipfiles, daemon_a.datas, - tnc_exe, - tnc_a.binaries, - tnc_a.zipfiles, - tnc_a.datas, + modem_exe, + modem_a.binaries, + modem_a.zipfiles, + modem_a.datas, strip=False, upx=True, upx_exclude=[], - name='tnc') + name='modem') diff --git a/tnc/global_instances.py b/modem/global_instances.py similarity index 84% rename from tnc/global_instances.py rename to modem/global_instances.py index d5c5b1a2..0be48ab5 100644 --- a/tnc/global_instances.py +++ b/modem/global_instances.py @@ -1,6 +1,6 @@ # global_instances.py -from static import Daemon, ARQ, AudioParam, Beacon, Channel, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC, MeshParam +from static import Daemon, ARQ, AudioParam, Beacon, Channel, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem, MeshParam # Initialize instances with appropriate default values @@ -15,5 +15,5 @@ ModemParam = ModemParam() Station = Station() Statistics = Statistics() TCIParam = TCIParam() -TNC = TNC() +Modem = Modem() MeshParam = MeshParam() diff --git a/tnc/helpers.py b/modem/helpers.py similarity index 94% rename from tnc/helpers.py rename to modem/helpers.py index ef13cfab..59f69860 100644 --- a/tnc/helpers.py +++ b/modem/helpers.py @@ -8,7 +8,7 @@ import time from datetime import datetime,timezone import crcengine import static -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC, MeshParam +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem, MeshParam import structlog import numpy as np import threading @@ -139,16 +139,16 @@ def add_to_heard_stations(dxcallsign, dxgrid, datatype, snr, offset, frequency): Nothing """ # check if buffer empty - if len(TNC.heard_stations) == 0: - TNC.heard_stations.append( + if len(Modem.heard_stations) == 0: + Modem.heard_stations.append( [dxcallsign, dxgrid, int(datetime.now(timezone.utc).timestamp()), datatype, snr, offset, frequency] ) # if not, we search and update else: - for i in range(len(TNC.heard_stations)): + for i in range(len(Modem.heard_stations)): # Update callsign with new timestamp - if TNC.heard_stations[i].count(dxcallsign) > 0: - TNC.heard_stations[i] = [ + if Modem.heard_stations[i].count(dxcallsign) > 0: + Modem.heard_stations[i] = [ dxcallsign, dxgrid, int(time.time()), @@ -159,8 +159,8 @@ def add_to_heard_stations(dxcallsign, dxgrid, datatype, snr, offset, frequency): ] break # Insert if nothing found - if i == len(TNC.heard_stations) - 1: - TNC.heard_stations.append( + if i == len(Modem.heard_stations) - 1: + Modem.heard_stations.append( [ dxcallsign, dxgrid, @@ -174,10 +174,10 @@ def add_to_heard_stations(dxcallsign, dxgrid, datatype, snr, offset, frequency): break -# for idx, item in enumerate(TNC.heard_stations): +# for idx, item in enumerate(Modem.heard_stations): # if dxcallsign in item: # item = [dxcallsign, int(time.time())] -# TNC.heard_stations[idx] = item +# Modem.heard_stations[idx] = item def callsign_to_bytes(callsign) -> bytes: @@ -530,7 +530,7 @@ def get_hmac_salt(dxcallsign: bytes, mycallsign: bytes): filepath = subfolder / filename except Exception as e: log.error( - "[TNC] [HMAC] File lookup error", file=filepath, + "[Modem] [HMAC] File lookup error", file=filepath, ) # check if file exists else return false @@ -580,13 +580,13 @@ def search_hmac_salt(dxcallsign: bytes, mycallsign: bytes, search_token, data_fr filepath = subfolder / filename except Exception as e: log.error( - "[TNC] [HMAC] File lookup error", file=filepath, + "[Modem] [HMAC] File lookup error", file=filepath, ) # check if file exists else return false if not check_if_file_exists(filepath): log.warning( - "[TNC] [HMAC] Token file not found", file=filepath, + "[Modem] [HMAC] Token file not found", file=filepath, ) return False @@ -611,19 +611,19 @@ def search_hmac_salt(dxcallsign: bytes, mycallsign: bytes, search_token, data_fr token_position = len(token_list) - _ delete_last_line_from_hmac_list(filepath, token_position) log.info( - "[TNC] [HMAC] Signature found", expected=search_token.hex(), + "[Modem] [HMAC] Signature found", expected=search_token.hex(), ) return True log.warning( - "[TNC] [HMAC] Signature not found", expected=search_token.hex(), filepath=filepath, + "[Modem] [HMAC] Signature not found", expected=search_token.hex(), filepath=filepath, ) return False except Exception as e: log.warning( - "[TNC] [HMAC] Lookup failed", e=e, expected=search_token, + "[Modem] [HMAC] Lookup failed", e=e, expected=search_token, ) return False @@ -662,6 +662,6 @@ def check_if_file_exists(path): return False except Exception as e: log.warning( - "[TNC] [FILE] Lookup failed", e=e, path=path, + "[Modem] [FILE] Lookup failed", e=e, path=path, ) return False \ No newline at end of file diff --git a/tnc/log_handler.py b/modem/log_handler.py similarity index 100% rename from tnc/log_handler.py rename to modem/log_handler.py diff --git a/tnc/main.py b/modem/main.py similarity index 85% rename from tnc/main.py rename to modem/main.py index a2044253..b96be8e1 100755 --- a/tnc/main.py +++ b/modem/main.py @@ -5,11 +5,11 @@ Created on Tue Dec 22 16:58:45 2020 @author: DJ2LS -main module for running the tnc +main module for running the modem """ -# run tnc self test on startup before we are doing other things +# run modem self test on startup before we are doing other things # import selftest # selftest.TEST() @@ -29,7 +29,7 @@ import helpers import log_handler import modem import static -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC, MeshParam +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem, MeshParam import structlog import explorer import json @@ -46,7 +46,7 @@ def signal_handler(sig, frame): Returns: system exit """ - print("Closing TNC...") + print("Closing Modem...") sock.CLOSE_SIGNAL = True sys.exit(0) @@ -57,7 +57,7 @@ if __name__ == "__main__": # This is for Windows multiprocessing support multiprocessing.freeze_support() # --------------------------------------------GET PARAMETER INPUTS - PARSER = argparse.ArgumentParser(description="FreeDATA TNC") + PARSER = argparse.ArgumentParser(description="FreeDATA Modem") #PARSER.add_argument( # "--use-config", @@ -205,7 +205,7 @@ if __name__ == "__main__": "--explorer", dest="enable_explorer", action="store_true", - help="Enable sending tnc data to https://explorer.freedata.app", + help="Enable sending modem data to https://explorer.freedata.app", ) PARSER.add_argument( @@ -295,27 +295,27 @@ if __name__ == "__main__": except ValueError: AudioParam.audio_output_device = ARGS.audio_output_device - TNC.port = ARGS.socket_port + Modem.port = ARGS.socket_port HamlibParam.hamlib_radiocontrol = ARGS.hamlib_radiocontrol HamlibParam.hamlib_rigctld_ip = ARGS.rigctld_ip HamlibParam.hamlib_rigctld_port = str(ARGS.rigctld_port) ModemParam.enable_scatter = ARGS.send_scatter AudioParam.enable_fft = ARGS.send_fft - TNC.enable_fsk = ARGS.enable_fsk - TNC.low_bandwidth_mode = ARGS.low_bandwidth_mode + Modem.enable_fsk = ARGS.enable_fsk + Modem.low_bandwidth_mode = ARGS.low_bandwidth_mode ModemParam.tuning_range_fmin = ARGS.tuning_range_fmin ModemParam.tuning_range_fmax = ARGS.tuning_range_fmax AudioParam.tx_audio_level = ARGS.tx_audio_level - TNC.respond_to_cq = ARGS.enable_respond_to_cq + Modem.respond_to_cq = ARGS.enable_respond_to_cq ARQ.rx_buffer_size = ARGS.rx_buffer_size - TNC.enable_explorer = ARGS.enable_explorer + Modem.enable_explorer = ARGS.enable_explorer AudioParam.audio_auto_tune = ARGS.enable_audio_auto_tune - TNC.enable_stats = ARGS.enable_stats + Modem.enable_stats = ARGS.enable_stats TCIParam.ip = ARGS.tci_ip TCIParam.port = ARGS.tci_port ModemParam.tx_delay = ARGS.tx_delay MeshParam.enable_protocol = ARGS.enable_mesh - TNC.enable_hmac = ARGS.enable_hmac + Modem.enable_hmac = ARGS.enable_hmac except Exception as e: @@ -348,25 +348,25 @@ if __name__ == "__main__": except ValueError: AudioParam.audio_output_device = conf.get('AUDIO', 'tx', '0') - TNC.port = int(conf.get('NETWORK', 'tncport', '3000')) + Modem.port = int(conf.get('NETWORK', 'modemport', '3000')) HamlibParam.hamlib_radiocontrol = conf.get('RADIO', 'radiocontrol', 'disabled') HamlibParam.hamlib_rigctld_ip = conf.get('RADIO', 'rigctld_ip', '127.0.0.1') HamlibParam.hamlib_rigctld_port = str(conf.get('RADIO', 'rigctld_port', '4532')) - ModemParam.enable_scatter = conf.get('TNC', 'scatter', 'True') - AudioParam.enable_fft = conf.get('TNC', 'fft', 'True') - TNC.enable_fsk = conf.get('TNC', 'fsk', 'False') - TNC.low_bandwidth_mode = conf.get('TNC', 'narrowband', 'False') - ModemParam.tuning_range_fmin = float(conf.get('TNC', 'fmin', '-50.0')) - ModemParam.tuning_range_fmax = float(conf.get('TNC', 'fmax', '50.0')) + ModemParam.enable_scatter = conf.get('Modem', 'scatter', 'True') + AudioParam.enable_fft = conf.get('Modem', 'fft', 'True') + Modem.enable_fsk = conf.get('Modem', 'fsk', 'False') + Modem.low_bandwidth_mode = conf.get('Modem', 'narrowband', 'False') + ModemParam.tuning_range_fmin = float(conf.get('Modem', 'fmin', '-50.0')) + ModemParam.tuning_range_fmax = float(conf.get('Modem', 'fmax', '50.0')) AudioParam.tx_audio_level = int(conf.get('AUDIO', 'txaudiolevel', '100')) - TNC.respond_to_cq = conf.get('TNC', 'qrv', 'True') - ARQ.rx_buffer_size = int(conf.get('TNC', 'rx_buffer_size', '16')) - TNC.enable_explorer = conf.get('TNC', 'explorer', 'False') + Modem.respond_to_cq = conf.get('Modem', 'qrv', 'True') + ARQ.rx_buffer_size = int(conf.get('Modem', 'rx_buffer_size', '16')) + Modem.enable_explorer = conf.get('Modem', 'explorer', 'False') AudioParam.audio_auto_tune = conf.get('AUDIO', 'auto_tune', 'False') - TNC.enable_stats = conf.get('TNC', 'stats', 'False') + Modem.enable_stats = conf.get('Modem', 'stats', 'False') TCIParam.ip = str(conf.get('TCI', 'tci_ip', 'localhost')) TCIParam.port = int(conf.get('TCI', 'tci_port', '50001')) - ModemParam.tx_delay = int(conf.get('TNC', 'tx_delay', '0')) + ModemParam.tx_delay = int(conf.get('Modem', 'tx_delay', '0')) MeshParam.enable_protocol = conf.get('MESH','mesh_enable','False') except KeyError as e: log.warning("[CFG] Error reading config file near", key=str(e)) @@ -384,7 +384,7 @@ if __name__ == "__main__": # config logging try: if sys.platform == "linux": - logging_path = os.getenv("HOME") + "/.config/" + "FreeDATA/" + "tnc" + logging_path = os.getenv("HOME") + "/.config/" + "FreeDATA/" + "modem" if sys.platform == "darwin": logging_path = ( @@ -392,11 +392,11 @@ if __name__ == "__main__": + "/Library/" + "Application Support/" + "FreeDATA/" - + "tnc" + + "modem" ) if sys.platform in ["win32", "win64"]: - logging_path = os.getenv("APPDATA") + "/" + "FreeDATA/" + "tnc" + logging_path = os.getenv("APPDATA") + "/" + "FreeDATA/" + "modem" if not os.path.exists(logging_path): os.makedirs(logging_path) @@ -405,7 +405,7 @@ if __name__ == "__main__": log.error("[DMN] logger init error", exception=err) log.info( - "[TNC] Starting FreeDATA", author="DJ2LS", version=TNC.version + "[Modem] Starting FreeDATA", author="DJ2LS", version=Modem.version ) # start data handler @@ -421,17 +421,17 @@ if __name__ == "__main__": mesh = mesh.MeshRouter() # optionally start explorer module - if TNC.enable_explorer: - log.info("[EXPLORER] Publishing to https://explorer.freedata.app", state=TNC.enable_explorer) + if Modem.enable_explorer: + log.info("[EXPLORER] Publishing to https://explorer.freedata.app", state=Modem.enable_explorer) explorer = explorer.explorer() # --------------------------------------------START CMD SERVER try: - log.info("[TNC] Starting TCP/IP socket", port=TNC.port) + log.info("[Modem] Starting TCP/IP socket", port=Modem.port) # https://stackoverflow.com/a/16641793 socketserver.TCPServer.allow_reuse_address = True cmdserver = sock.ThreadedTCPServer( - (TNC.host, TNC.port), sock.ThreadedTCPRequestHandler + (Modem.host, Modem.port), sock.ThreadedTCPRequestHandler ) server_thread = threading.Thread(target=cmdserver.serve_forever) @@ -439,7 +439,7 @@ if __name__ == "__main__": server_thread.start() except Exception as err: - log.error("[TNC] Starting TCP/IP socket failed", port=TNC.port, e=err) + log.error("[Modem] Starting TCP/IP socket failed", port=Modem.port, e=err) sys.exit(1) while True: threading.Event().wait(1) \ No newline at end of file diff --git a/tnc/mesh.py b/modem/mesh.py similarity index 98% rename from tnc/mesh.py rename to modem/mesh.py index 1d517df4..fc4f0f2b 100644 --- a/tnc/mesh.py +++ b/modem/mesh.py @@ -37,7 +37,7 @@ SNR: negative --> * 2 # pylint: disable=import-outside-toplevel, attribute-defined-outside-init from static import FRAME_TYPE -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem from codec2 import FREEDV_MODE import numpy as np @@ -113,7 +113,7 @@ class MeshRouter(): heard stations format: [dxcallsign,dxgrid,int(time.time()),datatype,snr,offset,frequency] - TNC.heard_stations.append( + Modem.heard_stations.append( [ dxcallsign, dxgrid, @@ -134,7 +134,7 @@ class MeshRouter(): frequency_position = 6 try: - for item in TNC.heard_stations: + for item in Modem.heard_stations: #print("-----------") #print(item) #print(item[snr_position]) @@ -222,13 +222,13 @@ class MeshRouter(): #print(len(_)) frame_list.append(mesh_broadcast_frame_header + _) - TNC.transmitting = True + Modem.transmitting = True c2_mode = FREEDV_MODE.datac4.value self.log.info("[MESH] broadcasting routing table", frame_list=frame_list, frames=len(split_result)) modem.MODEM_TRANSMIT_QUEUE.put([c2_mode, 1, 0, frame_list]) # Wait while transmitting - while TNC.transmitting: + while Modem.transmitting: threading.Event().wait(0.01) except Exception as e: self.log.warning("[MESH] broadcasting routing table", e=e) @@ -522,7 +522,7 @@ class MeshRouter(): repeat_delay=0, ) -> None: """ - Send (transmit) supplied frame to TNC + Send (transmit) supplied frame to Modem :param frame_to_tx: Frame data to send :type frame_to_tx: list of bytearrays @@ -536,16 +536,16 @@ class MeshRouter(): #print(frame_to_tx[0]) #print(frame_to_tx) frame_type = FRAME_TYPE(int.from_bytes(frame_to_tx[0][:1], byteorder="big")).name - self.log.debug("[TNC] enqueue_frame_for_tx", c2_mode=FREEDV_MODE(c2_mode).name, data=frame_to_tx, + self.log.debug("[Modem] enqueue_frame_for_tx", c2_mode=FREEDV_MODE(c2_mode).name, data=frame_to_tx, type=frame_type) # Set the TRANSMITTING flag before adding an object to the transmit queue # TODO: This is not that nice, we could improve this somehow - TNC.transmitting = True + Modem.transmitting = True modem.MODEM_TRANSMIT_QUEUE.put([c2_mode, copies, repeat_delay, frame_to_tx]) # Wait while transmitting - while TNC.transmitting: + while Modem.transmitting: threading.Event().wait(0.01) diff --git a/tnc/modem.py b/modem/modem.py similarity index 98% rename from tnc/modem.py rename to modem/modem.py index 20d22f87..823a6eff 100644 --- a/tnc/modem.py +++ b/modem/modem.py @@ -23,7 +23,7 @@ import numpy as np import sock import sounddevice as sd import static -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem from static import FRAME_TYPE import structlog import ujson as json @@ -37,7 +37,7 @@ TESTMODE = False RXCHANNEL = "" TXCHANNEL = "" -TNC.transmitting = False +Modem.transmitting = False # Receive only specific modes to reduce CPU load RECEIVE_SIG0 = True @@ -287,7 +287,7 @@ class RF: ) fft_thread.start() - if TNC.enable_fsk: + if Modem.enable_fsk: audio_thread_fsk_ldpc0 = threading.Thread( target=self.audio_fsk_ldpc_0, name="AUDIO_THREAD FSK LDPC0", daemon=True ) @@ -386,8 +386,8 @@ class RF: (self.dat0_datac1_buffer, RECEIVE_DATAC1), (self.dat0_datac3_buffer, RECEIVE_DATAC3), (self.dat0_datac4_buffer, RECEIVE_DATAC4), - (self.fsk_ldpc_buffer_0, TNC.enable_fsk), - (self.fsk_ldpc_buffer_1, TNC.enable_fsk), + (self.fsk_ldpc_buffer_0, Modem.enable_fsk), + (self.fsk_ldpc_buffer_1, Modem.enable_fsk), ]: if ( not (data_buffer.nbuffer + length_x) > data_buffer.size @@ -420,8 +420,8 @@ class RF: (self.dat0_datac1_buffer, RECEIVE_DATAC1), (self.dat0_datac3_buffer, RECEIVE_DATAC3), (self.dat0_datac4_buffer, RECEIVE_DATAC4), - (self.fsk_ldpc_buffer_0, TNC.enable_fsk), - (self.fsk_ldpc_buffer_1, TNC.enable_fsk), + (self.fsk_ldpc_buffer_0, Modem.enable_fsk), + (self.fsk_ldpc_buffer_1, Modem.enable_fsk), ]: if ( not (data_buffer.nbuffer + length_x) > data_buffer.size @@ -468,7 +468,7 @@ class RF: # Avoid decoding when transmitting to reduce CPU # TODO: Overriding this for testing purposes - # if not TNC.transmitting: + # if not Modem.transmitting: length_x = len(x) # Avoid buffer overflow by filling only if buffer for # selected datachannel mode is not full @@ -478,14 +478,14 @@ class RF: (self.dat0_datac1_buffer, RECEIVE_DATAC1, 2), (self.dat0_datac3_buffer, RECEIVE_DATAC3, 3), (self.dat0_datac4_buffer, RECEIVE_DATAC4, 4), - (self.fsk_ldpc_buffer_0, TNC.enable_fsk, 5), - (self.fsk_ldpc_buffer_1, TNC.enable_fsk, 6), + (self.fsk_ldpc_buffer_0, Modem.enable_fsk, 5), + (self.fsk_ldpc_buffer_1, Modem.enable_fsk, 6), ]: if (audiobuffer.nbuffer + length_x) > audiobuffer.size: AudioParam.buffer_overflow_counter[index] += 1 elif receive: audiobuffer.push(x) - # end of "not TNC.transmitting" if block + # end of "not Modem.transmitting" if block if not self.modoutqueue or self.mod_out_locked: data_out48k = np.zeros(frames, dtype=np.int16) @@ -541,7 +541,7 @@ class RF: else: return False - TNC.transmitting = True + Modem.transmitting = True # if we're transmitting FreeDATA signals, reset channel busy state ModemParam.channel_busy = False @@ -729,7 +729,7 @@ class RF: self.mod_out_locked = True self.modem_transmit_queue.task_done() - TNC.transmitting = False + Modem.transmitting = False threading.Event().set() end_of_transmission = time.time() @@ -737,7 +737,7 @@ class RF: self.log.debug("[MDM] ON AIR TIME", time=transmission_time) def transmit_morse(self, repeats, repeat_delay, frames): - TNC.transmitting = True + Modem.transmitting = True # if we're transmitting FreeDATA signals, reset channel busy state ModemParam.channel_busy = False self.log.debug( @@ -800,7 +800,7 @@ class RF: self.mod_out_locked = True self.modem_transmit_queue.task_done() - TNC.transmitting = False + Modem.transmitting = False threading.Event().set() end_of_transmission = time.time() @@ -894,8 +894,8 @@ class RF: if nbytes == bytes_per_frame: print(bytes(bytes_out)) - # process commands only if TNC.listen = True - if TNC.listen: + # process commands only if Modem.listen = True + if Modem.listen: # ignore data channel opener frames for avoiding toggle states @@ -931,7 +931,7 @@ class RF: else: self.log.warning( "[MDM] [demod_audio] received frame but ignored processing", - listen=TNC.listen + listen=Modem.listen ) except Exception as e: self.log.warning("[MDM] [demod_audio] Stream not active anymore", e=e) @@ -1244,7 +1244,7 @@ class RF: threading.Event().wait(0.1) HamlibParam.hamlib_status = self.radio.get_status() threading.Event().wait(0.1) - if TNC.transmitting: + if Modem.transmitting: HamlibParam.alc = self.radio.get_alc() threading.Event().wait(0.1) # HamlibParam.hamlib_rf = self.radio.get_level() @@ -1295,7 +1295,7 @@ class RF: # Therefore we are setting it to 100 so it will be highlighted # Have to do this when we are not transmitting so our # own sending data will not affect this too much - if not TNC.transmitting: + if not Modem.transmitting: dfft[dfft > avg + 15] = 100 # Calculate audio dbfs @@ -1354,12 +1354,12 @@ class RF: range_start = range[0] range_end = range[1] # define the area, we are detecting busy state - #dfft = dfft[120:176] if TNC.low_bandwidth_mode else dfft[65:231] + #dfft = dfft[120:176] if Modem.low_bandwidth_mode else dfft[65:231] slotdfft = dfft[range_start:range_end] # Check for signals higher than average by checking for "100" # If we have a signal, increment our channel_busy delay counter # so we have a smoother state toggle - if np.sum(slotdfft[slotdfft > avg + 15]) >= 200 and not TNC.transmitting: + if np.sum(slotdfft[slotdfft > avg + 15]) >= 200 and not Modem.transmitting: addDelay=True ModemParam.channel_busy_slot[slot] = True else: diff --git a/tnc/queues.py b/modem/queues.py similarity index 89% rename from tnc/queues.py rename to modem/queues.py index defe9b2c..befba860 100644 --- a/tnc/queues.py +++ b/modem/queues.py @@ -3,7 +3,7 @@ Hold queues used by more than one module to eliminate cyclic imports. """ import queue import static -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, TNC +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, Modem DATA_QUEUE_TRANSMIT = queue.Queue() DATA_QUEUE_RECEIVED = queue.Queue() diff --git a/tnc/rigctld.py b/modem/rigctld.py similarity index 100% rename from tnc/rigctld.py rename to modem/rigctld.py diff --git a/tnc/rigdummy.py b/modem/rigdummy.py similarity index 100% rename from tnc/rigdummy.py rename to modem/rigdummy.py diff --git a/tnc/selftest.py b/modem/selftest.py similarity index 91% rename from tnc/selftest.py rename to modem/selftest.py index 577e8d81..d3f4b1e9 100644 --- a/tnc/selftest.py +++ b/modem/selftest.py @@ -1,5 +1,5 @@ """ -simple TNC self tests +simple Modem self tests """ # -*- coding: utf-8 -*- @@ -15,9 +15,9 @@ class TEST(): def __init__(self): log.info("[selftest] running self tests...") if self.run_tests(): - log.info("[selftest] passed -> starting TNC") + log.info("[selftest] passed -> starting Modem") else: - log.error("[selftest] failed -> closing TNC") + log.error("[selftest] failed -> closing Modem") sys.exit(0) def run_tests(self): diff --git a/tnc/sock.py b/modem/sock.py similarity index 86% rename from tnc/sock.py rename to modem/sock.py index 8e40c1bd..783efaac 100644 --- a/tnc/sock.py +++ b/modem/sock.py @@ -27,7 +27,7 @@ import time import wave import helpers import static -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC, MeshParam +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, Modem, MeshParam import structlog from random import randrange import ujson as json @@ -66,10 +66,10 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): """ tempdata = b"" while self.connection_alive and not CLOSE_SIGNAL: - # send tnc state as network stream + # send modem state as network stream # check server port against daemon port and send corresponding data - if self.server.server_address[1] == TNC.port and not Daemon.tncstarted: - data = send_tnc_state() + if self.server.server_address[1] == Modem.port and not Daemon.modemstarted: + data = send_modem_state() if data != tempdata: tempdata = data SOCKET_QUEUE.put(data) @@ -126,8 +126,8 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): # iterate thorugh data list for commands in data: - if self.server.server_address[1] == TNC.port: - self.process_tnc_commands(commands) + if self.server.server_address[1] == Modem.port: + self.process_modem_commands(commands) else: self.process_daemon_commands(commands) @@ -191,10 +191,10 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): e=e, ) - # ------------------------ TNC COMMANDS - def process_tnc_commands(self, data): + # ------------------------ Modem COMMANDS + def process_modem_commands(self, data): """ - process tnc commands + process modem commands Args: data: @@ -202,7 +202,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): Returns: """ - log = structlog.get_logger("process_tnc_commands") + log = structlog.get_logger("process_modem_commands") # we need to do some error handling in case of socket timeout or decoding issue try: @@ -210,207 +210,207 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): received_json = json.loads(data) log.debug("[SCK] CMD", command=received_json) - # ENABLE TNC LISTENING STATE + # ENABLE Modem LISTENING STATE if received_json["type"] == "set" and received_json["command"] == "listen": if TESTMODE: - ThreadedTCPRequestHandler.tnc_set_listen(None, received_json) + ThreadedTCPRequestHandler.modem_set_listen(None, received_json) else: - self.tnc_set_listen(received_json) + self.modem_set_listen(received_json) # START STOP AUDIO RECORDING if received_json["type"] == "set" and received_json["command"] == "record_audio": if TESTMODE: - ThreadedTCPRequestHandler.tnc_set_record_audio(None, received_json) + ThreadedTCPRequestHandler.modem_set_record_audio(None, received_json) else: - self.tnc_set_record_audio(received_json) + self.modem_set_record_audio(received_json) # SET ENABLE/DISABLE RESPOND TO CALL if received_json["type"] == "set" and received_json["command"] == "respond_to_call": if TESTMODE: - ThreadedTCPRequestHandler.tnc_set_respond_to_call(None, received_json) + ThreadedTCPRequestHandler.modem_set_respond_to_call(None, received_json) else: - self.tnc_set_respond_to_call(received_json) + self.modem_set_respond_to_call(received_json) # SET ENABLE RESPOND TO CQ if received_json["type"] == "set" and received_json["command"] == "respond_to_cq": if TESTMODE: - ThreadedTCPRequestHandler.tnc_set_record_audio(None, received_json) + ThreadedTCPRequestHandler.modem_set_record_audio(None, received_json) else: - self.tnc_set_record_audio(received_json) + self.modem_set_record_audio(received_json) # SET TX AUDIO LEVEL if received_json["type"] == "set" and received_json["command"] == "tx_audio_level": if TESTMODE: - ThreadedTCPRequestHandler.tnc_set_tx_audio_level(None, received_json) + ThreadedTCPRequestHandler.modem_set_tx_audio_level(None, received_json) else: - self.tnc_set_tx_audio_level(received_json) + self.modem_set_tx_audio_level(received_json) # TRANSMIT TEST FRAME if received_json["type"] == "set" and received_json["command"] == "send_test_frame": if TESTMODE: - ThreadedTCPRequestHandler.tnc_set_send_test_frame(None, received_json) - elif TNC.tnc_state in ['busy']: + ThreadedTCPRequestHandler.modem_set_send_test_frame(None, received_json) + elif Modem.modem_state in ['busy']: log.warning( "[SCK] Dropping command", - e="tnc state", - state=TNC.tnc_state, + e="modem state", + state=Modem.modem_state, command=received_json, ) else: - self.tnc_set_send_test_frame(received_json) + self.modem_set_send_test_frame(received_json) # TRANSMIT FEC FRAME if received_json["type"] == "fec" and received_json["command"] == "transmit": if TESTMODE: - ThreadedTCPRequestHandler.tnc_fec_transmit(None, received_json) + ThreadedTCPRequestHandler.modem_fec_transmit(None, received_json) else: - self.tnc_fec_transmit(received_json) + self.modem_fec_transmit(received_json) # TRANSMIT IS WRITING FRAME if received_json["type"] == "fec" and received_json["command"] == "transmit_is_writing": if TESTMODE: - ThreadedTCPRequestHandler.tnc_fec_is_writing(None, received_json) - elif TNC.tnc_state in ['busy']: + ThreadedTCPRequestHandler.modem_fec_is_writing(None, received_json) + elif Modem.modem_state in ['busy']: log.warning( "[SCK] Dropping command", - e="tnc state", - state=TNC.tnc_state, + e="modem state", + state=Modem.modem_state, command=received_json, ) else: - self.tnc_fec_is_writing(received_json) + self.modem_fec_is_writing(received_json) # CQ CQ CQ if received_json["command"] == "cqcqcq": if TESTMODE: - ThreadedTCPRequestHandler.tnc_cqcqcq(None, received_json) - elif TNC.tnc_state in ['BUSY']: + ThreadedTCPRequestHandler.modem_cqcqcq(None, received_json) + elif Modem.modem_state in ['BUSY']: log.warning( "[SCK] Dropping command", - e="tnc state", - state=TNC.tnc_state, + e="modem state", + state=Modem.modem_state, command=received_json, ) else: - self.tnc_cqcqcq(received_json) + self.modem_cqcqcq(received_json) # START_BEACON if received_json["command"] == "start_beacon": if TESTMODE: - ThreadedTCPRequestHandler.tnc_start_beacon(None, received_json) + ThreadedTCPRequestHandler.modem_start_beacon(None, received_json) else: - self.tnc_start_beacon(received_json) + self.modem_start_beacon(received_json) # STOP_BEACON if received_json["command"] == "stop_beacon": if TESTMODE: - ThreadedTCPRequestHandler.tnc_stop_beacon(None, received_json) + ThreadedTCPRequestHandler.modem_stop_beacon(None, received_json) else: - self.tnc_stop_beacon(received_json) + self.modem_stop_beacon(received_json) # PING if received_json["type"] == "ping" and received_json["command"] == "ping": if TESTMODE: - ThreadedTCPRequestHandler.tnc_ping_ping(None, received_json) - elif TNC.tnc_state in ['BUSY']: + ThreadedTCPRequestHandler.modem_ping_ping(None, received_json) + elif Modem.modem_state in ['BUSY']: log.warning( "[SCK] Dropping command", - e="tnc state", - state=TNC.tnc_state, + e="modem state", + state=Modem.modem_state, command=received_json, ) else: - self.tnc_ping_ping(received_json) + self.modem_ping_ping(received_json) # CONNECT if received_json["type"] == "arq" and received_json["command"] == "connect": if TESTMODE: - ThreadedTCPRequestHandler.tnc_arq_connect(None, received_json) - elif TNC.tnc_state in ['BUSY']: + ThreadedTCPRequestHandler.modem_arq_connect(None, received_json) + elif Modem.modem_state in ['BUSY']: log.warning( "[SCK] Dropping command", - e="tnc state", - state=TNC.tnc_state, + e="modem state", + state=Modem.modem_state, command=received_json, ) else: - self.tnc_arq_connect(received_json) + self.modem_arq_connect(received_json) # DISCONNECT if received_json["type"] == "arq" and received_json["command"] == "disconnect": if TESTMODE: - ThreadedTCPRequestHandler.tnc_arq_disconnect(None, received_json) + ThreadedTCPRequestHandler.modem_arq_disconnect(None, received_json) else: - self.tnc_arq_disconnect(received_json) + self.modem_arq_disconnect(received_json) # TRANSMIT RAW DATA if received_json["type"] == "arq" and received_json["command"] == "send_raw": if TESTMODE: - ThreadedTCPRequestHandler.tnc_arq_send_raw(None, received_json) - elif TNC.tnc_state in ['busy']: + ThreadedTCPRequestHandler.modem_arq_send_raw(None, received_json) + elif Modem.modem_state in ['busy']: log.warning( "[SCK] Dropping command", - e="tnc state", - state=TNC.tnc_state, + e="modem state", + state=Modem.modem_state, command=received_json, ) else: - self.tnc_arq_send_raw(received_json) + self.modem_arq_send_raw(received_json) # STOP TRANSMISSION if received_json["type"] == "arq" and received_json["command"] == "stop_transmission": if TESTMODE: - ThreadedTCPRequestHandler.tnc_arq_stop_transmission(None, received_json) + ThreadedTCPRequestHandler.modem_arq_stop_transmission(None, received_json) else: - self.tnc_arq_stop_transmission(received_json) + self.modem_arq_stop_transmission(received_json) # GET RX BUFFER if received_json["type"] == "get" and received_json["command"] == "rx_buffer": if TESTMODE: - ThreadedTCPRequestHandler.tnc_get_rx_buffer(None, received_json) + ThreadedTCPRequestHandler.modem_get_rx_buffer(None, received_json) else: - self.tnc_get_rx_buffer(received_json) + self.modem_get_rx_buffer(received_json) # DELETE RX BUFFER if received_json["type"] == "set" and received_json["command"] == "del_rx_buffer": if TESTMODE: - ThreadedTCPRequestHandler.tnc_set_del_rx_buffer(None, received_json) + ThreadedTCPRequestHandler.modem_set_del_rx_buffer(None, received_json) else: - self.tnc_set_del_rx_buffer(received_json) + self.modem_set_del_rx_buffer(received_json) # SET FREQUENCY if received_json["type"] == "set" and received_json["command"] == "frequency": if TESTMODE: - ThreadedTCPRequestHandler.tnc_set_frequency(None, received_json) + ThreadedTCPRequestHandler.modem_set_frequency(None, received_json) else: - self.tnc_set_frequency(received_json) + self.modem_set_frequency(received_json) # SET MODE if received_json["type"] == "set" and received_json["command"] == "mode": if TESTMODE: - ThreadedTCPRequestHandler.tnc_set_mode(None, received_json) + ThreadedTCPRequestHandler.modem_set_mode(None, received_json) else: - self.tnc_set_mode(received_json) + self.modem_set_mode(received_json) # GET ROUTING TABLE if received_json["type"] == "get" and received_json["command"] == "routing_table": - self.tnc_get_mesh_routing_table(received_json) + self.modem_get_mesh_routing_table(received_json) # -------------- MESH ---------------- # # MESH PING if received_json["type"] == "mesh" and received_json["command"] == "ping": - self.tnc_mesh_ping(received_json) + self.modem_mesh_ping(received_json) except Exception as err: log.error("[SCK] JSON decoding error", e=err) - def tnc_set_listen(self, received_json): + def modem_set_listen(self, received_json): try: - TNC.listen = received_json["state"] in ['true', 'True', True, "ON", "on"] + Modem.listen = received_json["state"] in ['true', 'True', True, "ON", "on"] command_response("listen", True) - # if tnc is connected, force disconnect when TNC.listen == False - if not TNC.listen and ARQ.arq_session_state not in ["disconnecting", "disconnected", "failed"]: + # if modem is connected, force disconnect when Modem.listen == False + if not Modem.listen and ARQ.arq_session_state not in ["disconnecting", "disconnected", "failed"]: DATA_QUEUE_TRANSMIT.put(["DISCONNECT"]) # set early disconnecting state so we can interrupt connection attempts ARQ.arq_session_state = "disconnecting" @@ -424,11 +424,11 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): "[SCK] CQ command execution error", e=err, command=received_json ) - def tnc_set_record_audio(self, received_json): + def modem_set_record_audio(self, received_json): try: if not AudioParam.audio_record: AudioParam.audio_record_file = wave.open(f"{int(time.time())}_audio_recording.wav", 'w') - AudioParam.audio_record_file.setnchannels(1) + AudioParam.audio_record_file.semodemhannels(1) AudioParam.audio_record_file.setsampwidth(2) AudioParam.audio_record_file.setframerate(8000) AudioParam.audio_record = True @@ -444,9 +444,9 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): "[SCK] CQ command execution error", e=err, command=received_json ) - def tnc_set_respond_to_call(self, received_json): + def modem_set_respond_to_call(self, received_json): try: - TNC.respond_to_call = received_json["state"] in ['true', 'True', True] + Modem.respond_to_call = received_json["state"] in ['true', 'True', True] command_response("respond_to_call", True) except Exception as err: @@ -455,9 +455,9 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): "[SCK] CQ command execution error", e=err, command=received_json ) - def tnc_set_respond_to_cq(self, received_json): + def modem_set_respond_to_cq(self, received_json): try: - TNC.respond_to_cq = received_json["state"] in ['true', 'True', True] + Modem.respond_to_cq = received_json["state"] in ['true', 'True', True] command_response("respond_to_cq", True) except Exception as err: @@ -466,7 +466,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): "[SCK] CQ command execution error", e=err, command=received_json ) - def tnc_set_tx_audio_level(self, received_json): + def modem_set_tx_audio_level(self, received_json): try: AudioParam.tx_audio_level = int(received_json["value"]) command_response("tx_audio_level", True) @@ -479,7 +479,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_set_send_test_frame(self, received_json): + def modem_set_send_test_frame(self, received_json): try: DATA_QUEUE_TRANSMIT.put(["SEND_TEST_FRAME"]) command_response("send_test_frame", True) @@ -491,7 +491,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_fec_transmit(self, received_json): + def modem_fec_transmit(self, received_json): try: mode = received_json["mode"] wakeup = received_json["wakeup"] @@ -519,7 +519,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_fec_is_writing(self, received_json): + def modem_fec_is_writing(self, received_json): try: mycallsign = received_json["mycallsign"] DATA_QUEUE_TRANSMIT.put(["FEC_IS_WRITING", mycallsign]) @@ -532,7 +532,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_cqcqcq(self, received_json): + def modem_cqcqcq(self, received_json): try: DATA_QUEUE_TRANSMIT.put(["CQ"]) command_response("cqcqcq", True) @@ -543,7 +543,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): "[SCK] CQ command execution error", e=err, command=received_json ) - def tnc_start_beacon(self, received_json): + def modem_start_beacon(self, received_json): try: Beacon.beacon_state = True interval = int(received_json["parameter"]) @@ -557,7 +557,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_stop_beacon(self, received_json): + def modem_stop_beacon(self, received_json): try: log.warning("[SCK] Stopping beacon!") Beacon.beacon_state = False @@ -572,7 +572,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): ) - def tnc_mesh_ping(self, received_json): + def modem_mesh_ping(self, received_json): # send ping frame and wait for ACK try: dxcallsign = received_json["dxcallsign"] @@ -585,7 +585,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): dxcallsign = helpers.callsign_to_bytes(dxcallsign) dxcallsign = helpers.bytes_to_callsign(dxcallsign) - # check if specific callsign is set with different SSID than the TNC is initialized + # check if specific callsign is set with different SSID than the Modem is initialized try: mycallsign = received_json["mycallsign"] mycallsign = helpers.callsign_to_bytes(mycallsign) @@ -605,7 +605,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): "[SCK] PING command execution error", e=err, command=received_json ) - def tnc_ping_ping(self, received_json): + def modem_ping_ping(self, received_json): # send ping frame and wait for ACK try: @@ -619,7 +619,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): dxcallsign = helpers.callsign_to_bytes(dxcallsign) dxcallsign = helpers.bytes_to_callsign(dxcallsign) - # check if specific callsign is set with different SSID than the TNC is initialized + # check if specific callsign is set with different SSID than the Modem is initialized try: mycallsign = received_json["mycallsign"] mycallsign = helpers.callsign_to_bytes(mycallsign) @@ -639,7 +639,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): "[SCK] PING command execution error", e=err, command=received_json ) - def tnc_arq_connect(self, received_json): + def modem_arq_connect(self, received_json): # pause our beacon first Beacon.beacon_pause = True @@ -653,7 +653,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): dxcallsign = received_json["dxcallsign"] - # check if specific callsign is set with different SSID than the TNC is initialized + # check if specific callsign is set with different SSID than the Modem is initialized try: mycallsign = received_json["mycallsign"] mycallsign = helpers.callsign_to_bytes(mycallsign) @@ -697,7 +697,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): # allow beacon transmission again Beacon.beacon_pause = False - def tnc_arq_disconnect(self, received_json): + def modem_arq_disconnect(self, received_json): try: if ARQ.arq_session_state not in ["disconnecting", "disconnected", "failed"]: DATA_QUEUE_TRANSMIT.put(["DISCONNECT"]) @@ -716,7 +716,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_arq_send_raw(self, received_json): + def modem_arq_send_raw(self, received_json): Beacon.beacon_pause = True # wait some random time @@ -754,7 +754,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): base64data = received_json["parameter"][0]["data"] - # check if specific callsign is set with different SSID than the TNC is initialized + # check if specific callsign is set with different SSID than the Modem is initialized try: mycallsign = received_json["parameter"][0]["mycallsign"] mycallsign = helpers.callsign_to_bytes(mycallsign) @@ -800,12 +800,12 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_arq_stop_transmission(self, received_json): + def modem_arq_stop_transmission(self, received_json): try: - if TNC.tnc_state == "BUSY" or ARQ.arq_state: + if Modem.modem_state == "BUSY" or ARQ.arq_state: DATA_QUEUE_TRANSMIT.put(["STOP"]) log.warning("[SCK] Stopping transmission!") - TNC.tnc_state = "IDLE" + Modem.modem_state = "IDLE" ARQ.arq_state = False command_response("stop_transmission", True) except Exception as err: @@ -814,7 +814,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): "[SCK] STOP command execution error", e=err, command=received_json ) - def tnc_get_mesh_routing_table(self, received_json): + def modem_get_mesh_routing_table(self, received_json): try: output = { "command": "routing_table", @@ -851,7 +851,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_get_rx_buffer(self, received_json): + def modem_get_rx_buffer(self, received_json): try: if not RX_BUFFER.empty(): # TODO: REMOVE DEPRECATED MESSAGES @@ -892,7 +892,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): # RX_BUFFER[10] = speed list stats for _buffer_length in range(RX_BUFFER.qsize()): output = { - "freedata" : "tnc-message", + "freedata" : "modem-message", "arq" : "transmission", "status" : "received", "uuid" : RX_BUFFER.queue[_buffer_length][0], @@ -929,7 +929,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_set_del_rx_buffer(self, received_json): + def modem_set_del_rx_buffer(self, received_json): try: RX_BUFFER.queue.clear() command_response("del_rx_buffer", True) @@ -941,7 +941,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_set_mode(self, received_json): + def modem_set_mode(self, received_json): try: RIGCTLD_COMMAND_QUEUE.put(["set_mode", received_json["mode"]]) command_response("set_mode", True) @@ -953,7 +953,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command=received_json, ) - def tnc_set_frequency(self, received_json): + def modem_set_frequency(self, received_json): try: RIGCTLD_COMMAND_QUEUE.put(["set_frequency", received_json["frequency"]]) command_response("set_frequency", True) @@ -990,16 +990,16 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): if ( received_json["type"] == "set" - and received_json["command"] == "start_tnc" - and not Daemon.tncstarted + and received_json["command"] == "start_modem" + and not Daemon.modemstarted ): - self.daemon_start_tnc(received_json) + self.daemon_start_modem(received_json) if received_json["type"] == "get" and received_json["command"] == "test_hamlib": self.daemon_test_hamlib(received_json) - if received_json["type"] == "set" and received_json["command"] == "stop_tnc": - self.daemon_stop_tnc(received_json) + if received_json["type"] == "set" and received_json["command"] == "stop_modem": + self.daemon_stop_modem(received_json) if received_json["type"] == "set" and received_json["command"] == "start_rigctld" and not Daemon.rigctldstarted: self.daemon_start_rigctld(received_json) @@ -1047,7 +1047,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): command_response("mygrid", False) log.warning("[SCK] command execution error", e=err, command=received_json) - def daemon_start_tnc(self, received_json): + def daemon_start_modem(self, received_json): try: startparam = received_json["parameter"][0] @@ -1087,13 +1087,13 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): # print some debugging parameters for item in startparam: log.debug( - f"[SCK] TNC Startup Config : {item}", + f"[SCK] Modem Startup Config : {item}", value=startparam[item], ) DAEMON_QUEUE.put( [ - "STARTTNC", + "STARTModem", mycall, mygrid, rx_audio, @@ -1120,23 +1120,23 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): enable_mesh ] ) - command_response("start_tnc", True) + command_response("start_modem", True) except Exception as err: - command_response("start_tnc", False) + command_response("start_modem", False) log.warning("[SCK] command execution error", e=err, command=received_json) - def daemon_stop_tnc(self, received_json): + def daemon_stop_modem(self, received_json): try: - Daemon.tncprocess.kill() + Daemon.modemprocess.kill() # unregister process from atexit to avoid process zombies - atexit.unregister(Daemon.tncprocess.kill) + atexit.unregister(Daemon.modemprocess.kill) - log.warning("[SCK] Stopping TNC") - Daemon.tncstarted = False - command_response("stop_tnc", True) + log.warning("[SCK] Stopping Modem") + Daemon.modemstarted = False + command_response("stop_modem", True) except Exception as err: - command_response("stop_tnc", False) + command_response("stop_modem", False) log.warning("[SCK] command execution error", e=err, command=received_json) def daemon_test_hamlib(self, received_json): @@ -1236,7 +1236,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): Daemon.rigctldstarted = False command_response("stop_rigctld", True) except Exception as err: - command_response("stop_tnc", False) + command_response("stop_modem", False) log.warning("[SCK] command execution error", e=err, command=received_json) @@ -1264,16 +1264,16 @@ def send_daemon_state(): Daemon.rigctldstarted = False - retcode_tnc = Daemon.tncprocess.poll() - if retcode_tnc in [None, "None"]: - Daemon.tncstarted = True + retcode_modem = Daemon.modemprocess.poll() + if retcode_modem in [None, "None"]: + Daemon.modemstarted = True # This is a blocking code .... - # output, errs = Daemon.tncprocess.communicate() - # print(f"tnc out: {output}") - # print(f"tnc err: {errs}") + # output, errs = Daemon.modemprocess.communicate() + # print(f"modem out: {output}") + # print(f"modem err: {errs}") else: - # print(f"tnc closed with code: {retcode_tnc}") - Daemon.tncstarted = False + # print(f"modem closed with code: {retcode_modem}") + Daemon.modemstarted = False except Exception: pass @@ -1291,10 +1291,10 @@ def send_daemon_state(): "serial_devices": Daemon.serial_devices, # 'cpu': str(psutil.cpu_percent()), # 'ram': str(psutil.virtual_memory().percent), - "version": TNC.version, + "version": Modem.version, } - if Daemon.tncstarted: + if Daemon.modemstarted: output["daemon_state"].append({"status": "running"}) else: output["daemon_state"].append({"status": "stopped"}) @@ -1310,15 +1310,15 @@ def send_daemon_state(): return None -def send_tnc_state(): +def send_modem_state(): """ - send the tnc state to network + send the modem state to network """ encoding = "utf-8" output = { - "command": "tnc_state", + "command": "modem_state", "ptt_state": str(HamlibParam.ptt_state), - "tnc_state": str(TNC.tnc_state), + "modem_state": str(Modem.modem_state), "arq_state": str(ARQ.arq_state), "arq_session": str(ARQ.arq_session), "arq_session_state": str(ARQ.arq_session_state), @@ -1357,13 +1357,13 @@ def send_tnc_state(): "dxcallsign": str(Station.dxcallsign, encoding), "dxgrid": str(Station.dxgrid, encoding), "hamlib_status": HamlibParam.hamlib_status, - "listen": str(TNC.listen), + "listen": str(Modem.listen), "audio_recording": str(AudioParam.audio_record), } # add heard stations to heard stations object - for heard in TNC.heard_stations: + for heard in Modem.heard_stations: output["stations"].append( { "dxcallsign": str(heard[0], encoding), diff --git a/tnc/static.py b/modem/static.py similarity index 97% rename from tnc/static.py rename to modem/static.py index a18f0861..13ca89cb 100644 --- a/tnc/static.py +++ b/modem/static.py @@ -73,9 +73,9 @@ class Channel: @dataclass class Daemon: - tncprocess: subprocess.Popen + modemprocess: subprocess.Popen rigctldprocess: subprocess.Popen - tncstarted: bool = False + modemstarted: bool = False rigctldstarted: bool = False port: int = 3001 serial_devices = [] @@ -133,12 +133,12 @@ class TCIParam: port: int = '9000' @dataclass -class TNC: +class Modem: version = "0.11.0-alpha.1-vuejs" host: str = "0.0.0.0" port: int = 3000 SOCKET_TIMEOUT: int = 1 # seconds - tnc_state: str = "IDLE" + modem_state: str = "IDLE" enable_explorer = False enable_stats = False transmitting: bool = False diff --git a/tnc/stats.py b/modem/stats.py similarity index 95% rename from tnc/stats.py rename to modem/stats.py index 5c1876a4..d295b9fa 100644 --- a/tnc/stats.py +++ b/modem/stats.py @@ -12,7 +12,7 @@ import threading import time import ujson as json import structlog -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, TNC +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, Modem log = structlog.get_logger("stats") @@ -47,7 +47,7 @@ class stats(): 'duration': duration, 'percentage': ARQ.arq_transmission_percent, 'status': status, - 'version': TNC.version + 'version': Modem.version } station_data = json.dumps(station_data) diff --git a/tnc/tci.py b/modem/tci.py similarity index 99% rename from tnc/tci.py rename to modem/tci.py index 30796f52..3d353f52 100644 --- a/tnc/tci.py +++ b/modem/tci.py @@ -7,7 +7,7 @@ import websocket import numpy as np import time from queues import AUDIO_TRANSMIT_QUEUE, AUDIO_RECEIVED_QUEUE -from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, TNC +from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, Modem class TCICtrl: def __init__(self, hostname='127.0.0.1', port=50001): diff --git a/test/hamlib-test.py b/test/hamlib-test.py index 87ddb6b7..ad68f7d5 100644 --- a/test/hamlib-test.py +++ b/test/hamlib-test.py @@ -39,7 +39,7 @@ class RETCODE(Enum): RIG_EVFO = 16 RIG_EDOM = 17 -libname = pathlib.Path("../tnc/lib/hamlib/linux/libhamlib.so") +libname = pathlib.Path("../modem/lib/hamlib/linux/libhamlib.so") hamlib = ctypes.CDLL(libname) class SERIAL(ctypes.Structure): diff --git a/test/test_highsnr_stdio_C_P_datacx.py b/test/test_highsnr_stdio_C_P_datacx.py index aa095cd6..231ff380 100644 --- a/test/test_highsnr_stdio_C_P_datacx.py +++ b/test/test_highsnr_stdio_C_P_datacx.py @@ -66,9 +66,9 @@ def t_HighSNR_C_P_DATACx( tx_side = "freedv_data_raw_tx" _txpaths = ( - os.path.join("..", "tnc") - if os.path.exists(os.path.join("..", "tnc")) - else "tnc" + os.path.join("..", "modem") + if os.path.exists(os.path.join("..", "modem")) + else "modem" ) _txpaths = glob.glob(rf"{_txpaths}/**/{tx_side}", recursive=True) for path in _txpaths: diff --git a/test/test_highsnr_stdio_P_C_datacx.py b/test/test_highsnr_stdio_P_C_datacx.py index 5574636d..81cde7a5 100644 --- a/test/test_highsnr_stdio_P_C_datacx.py +++ b/test/test_highsnr_stdio_P_C_datacx.py @@ -59,9 +59,9 @@ def t_HighSNR_P_C_DATACx(bursts: int, frames_per_burst: int, mode: str): # Facilitate running from main directory as well as inside test/ rx_side = "freedv_data_raw_rx" _rxpath = ( - os.path.join("..", "tnc") - if os.path.exists(os.path.join("..", "tnc")) - else "tnc" + os.path.join("..", "modem") + if os.path.exists(os.path.join("..", "modem")) + else "modem" ) _rxpaths = glob.glob(rf"{_rxpath}/**/{rx_side}", recursive=True) for path in _rxpaths: diff --git a/test/test_tnc_states.py b/test/test_tnc_states.py index d4aab6dc..6a46319e 100644 --- a/test/test_tnc_states.py +++ b/test/test_tnc_states.py @@ -23,7 +23,7 @@ import pytest # pylint: disable=wrong-import-position sys.path.insert(0, "..") -sys.path.insert(0, "../tnc") +sys.path.insert(0, "../modem") import data_handler import helpers from static import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC diff --git a/test/util_callback_multimode_rx.py b/test/util_callback_multimode_rx.py index 3ef2d35c..94eda986 100644 --- a/test/util_callback_multimode_rx.py +++ b/test/util_callback_multimode_rx.py @@ -16,7 +16,7 @@ import numpy as np import pyaudio sys.path.insert(0, "..") -from tnc import codec2 +from modem import codec2 # --------------------------------------------GET PARAMETER INPUTS parser = argparse.ArgumentParser(description="FreeDATA audio test") diff --git a/test/util_callback_multimode_rx_outside.py b/test/util_callback_multimode_rx_outside.py index eb4d8952..1bef5a51 100644 --- a/test/util_callback_multimode_rx_outside.py +++ b/test/util_callback_multimode_rx_outside.py @@ -15,7 +15,7 @@ import numpy as np import pyaudio sys.path.insert(0, "..") -from tnc import codec2 +from modem import codec2 # --------------------------------------------GET PARAMETER INPUTS parser = argparse.ArgumentParser(description="FreeDATA audio test") diff --git a/test/util_callback_multimode_tx.py b/test/util_callback_multimode_tx.py index 79e30284..c155c366 100644 --- a/test/util_callback_multimode_tx.py +++ b/test/util_callback_multimode_tx.py @@ -16,7 +16,7 @@ import numpy as np import pyaudio sys.path.insert(0, "..") -from tnc import codec2 +from modem import codec2 # --------------------------------------------GET PARAMETER INPUTS parser = argparse.ArgumentParser(description="FreeDATA audio test") diff --git a/test/util_callback_rx.py b/test/util_callback_rx.py index 0a7237b1..3c17860e 100644 --- a/test/util_callback_rx.py +++ b/test/util_callback_rx.py @@ -15,7 +15,7 @@ import numpy as np import pyaudio sys.path.insert(0, "..") -from tnc import codec2 +from modem import codec2 # --------------------------------------------GET PARAMETER INPUTS parser = argparse.ArgumentParser(description="FreeDATA audio test") diff --git a/test/util_callback_rx_outside.py b/test/util_callback_rx_outside.py index dc1fc3ce..c038c547 100644 --- a/test/util_callback_rx_outside.py +++ b/test/util_callback_rx_outside.py @@ -15,7 +15,7 @@ import numpy as np import pyaudio sys.path.insert(0, "..") -from tnc import codec2 +from modem import codec2 # --------------------------------------------GET PARAMETER INPUTS parser = argparse.ArgumentParser(description="FreeDATA audio test") diff --git a/test/util_callback_tx.py b/test/util_callback_tx.py index 3991a71f..ba3ace1d 100644 --- a/test/util_callback_tx.py +++ b/test/util_callback_tx.py @@ -17,7 +17,7 @@ import numpy as np import pyaudio sys.path.insert(0, "..") -from tnc import codec2 +from modem import codec2 # --------------------------------------------GET PARAMETER INPUTS parser = argparse.ArgumentParser(description="FreeDATA audio test") diff --git a/test/util_chat_text_1.py b/test/util_chat_text_1.py index 444f5460..b21699a6 100644 --- a/test/util_chat_text_1.py +++ b/test/util_chat_text_1.py @@ -202,8 +202,8 @@ def t_highsnr_arq_short_station1( time.sleep(0.5) log.info("station1", arq_state=pformat(ARQ.arq_state)) - # log.info("S1 DQT: ", DQ_Tx=pformat(tnc.data_queue_transmit.queue)) - # log.info("S1 DQR: ", DQ_Rx=pformat(tnc.data_queue_received.queue)) + # log.info("S1 DQT: ", DQ_Tx=pformat(modem.data_queue_transmit.queue)) + # log.info("S1 DQR: ", DQ_Rx=pformat(modem.data_queue_received.queue)) log.info("S1 Socket: ", socket_queue=pformat(sock.SOCKET_QUEUE.queue)) assert '"arq":"transmission","status":"transmitting"' in str( diff --git a/test/util_chat_text_2.py b/test/util_chat_text_2.py index 77f2523b..55cad060 100644 --- a/test/util_chat_text_2.py +++ b/test/util_chat_text_2.py @@ -153,8 +153,8 @@ def t_highsnr_arq_short_station2( time.sleep(0.5) log.info("station2", arq_state=pformat(ARQ.arq_state)) - # log.info("S2 DQT: ", DQ_Tx=pformat(tnc.data_queue_transmit.queue)) - # log.info("S2 DQR: ", DQ_Rx=pformat(tnc.data_queue_received.queue)) + # log.info("S2 DQT: ", DQ_Tx=pformat(modem.data_queue_transmit.queue)) + # log.info("S2 DQR: ", DQ_Rx=pformat(modem.data_queue_received.queue)) log.info("S2 Socket: ", socket_queue=pformat(sock.SOCKET_QUEUE.queue)) assert '"arq":"transmission","status":"received"' in str(sock.SOCKET_QUEUE.queue) diff --git a/test/util_datac13_negative.py b/test/util_datac13_negative.py index 882acc98..9105905c 100644 --- a/test/util_datac13_negative.py +++ b/test/util_datac13_negative.py @@ -189,8 +189,8 @@ def t_datac13_1( time.sleep(0.5) log.info("station1, final") - # log.info("S1 DQT: ", DQ_Tx=pformat(tnc.data_queue_transmit.queue)) - # log.info("S1 DQR: ", DQ_Rx=pformat(tnc.data_queue_received.queue)) + # log.info("S1 DQT: ", DQ_Tx=pformat(modem.data_queue_transmit.queue)) + # log.info("S1 DQR: ", DQ_Rx=pformat(modem.data_queue_received.queue)) log.debug("S1 Socket: ", socket_queue=pformat(sock.SOCKET_QUEUE.queue)) for item in final_tx_check: @@ -298,8 +298,8 @@ def t_datac13_2( time.sleep(0.5) log.info("station2, final") - # log.info("S2 DQT: ", DQ_Tx=pformat(tnc.data_queue_transmit.queue)) - # log.info("S2 DQR: ", DQ_Rx=pformat(tnc.data_queue_received.queue)) + # log.info("S2 DQT: ", DQ_Tx=pformat(modem.data_queue_transmit.queue)) + # log.info("S2 DQR: ", DQ_Rx=pformat(modem.data_queue_received.queue)) log.debug("S2 Socket: ", socket_queue=pformat(sock.SOCKET_QUEUE.queue)) for item in final_rx_check: diff --git a/test/util_multimode_rx.py b/test/util_multimode_rx.py index 5e59431f..aef517fc 100755 --- a/test/util_multimode_rx.py +++ b/test/util_multimode_rx.py @@ -23,7 +23,7 @@ import numpy as np import pyaudio sys.path.insert(0, "..") -from tnc import codec2 +from modem import codec2 def test_mm_rx(): diff --git a/test/util_multimode_tx.py b/test/util_multimode_tx.py index 00d99b66..f9f5338b 100644 --- a/test/util_multimode_tx.py +++ b/test/util_multimode_tx.py @@ -22,7 +22,7 @@ import numpy as np import pyaudio sys.path.insert(0, "..") -from tnc import codec2 +from modem import codec2 def test_mm_tx(): diff --git a/test/util_rx.py b/test/util_rx.py index 620c256a..127ef4bf 100644 --- a/test/util_rx.py +++ b/test/util_rx.py @@ -23,8 +23,8 @@ import sounddevice as sd # pylint: disable=wrong-import-position sys.path.insert(0, "..") -sys.path.insert(0, "../tnc") -from tnc import codec2 +sys.path.insert(0, "../modem") +from modem import codec2 def util_rx(): diff --git a/test/util_tnc_IRS.py b/test/util_tnc_IRS.py index 99507cd3..637ada88 100644 --- a/test/util_tnc_IRS.py +++ b/test/util_tnc_IRS.py @@ -18,7 +18,7 @@ from typing import Callable import structlog -sys.path.insert(0, "../tnc") +sys.path.insert(0, "../modem") import data_handler import helpers import modem diff --git a/test/util_tnc_ISS.py b/test/util_tnc_ISS.py index f1a69f19..076769e9 100644 --- a/test/util_tnc_ISS.py +++ b/test/util_tnc_ISS.py @@ -19,7 +19,7 @@ from typing import Callable import structlog -sys.path.insert(0, "../tnc") +sys.path.insert(0, "../modem") import data_handler import helpers import modem diff --git a/test/util_tx.py b/test/util_tx.py index c4cc6ec1..3c0e6d40 100644 --- a/test/util_tx.py +++ b/test/util_tx.py @@ -21,7 +21,7 @@ import numpy as np import sounddevice as sd sys.path.insert(0, "..") -from tnc import codec2 +from modem import codec2 def util_tx(): diff --git a/tnc/config.ini b/tnc/config.ini deleted file mode 100644 index eedcc637..00000000 --- a/tnc/config.ini +++ /dev/null @@ -1,46 +0,0 @@ -[NETWORK] -#network settings -tncport = 3000 - -[STATION] -#station settings -mycall = DJ2LS -mygrid = JN48cs -ssid_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - -[AUDIO] -#audio settings -rx = 4 -tx = 4 -txaudiolevel = 100 -auto_tune = False - -[RADIO] -#radio settings -radiocontrol = disabled -rigctld_ip = 127.0.0.1 -rigctld_port = 4532 - -[TNC] -#tnc settings -scatter = True -fft = True -narrowband = False -fmin = -50.0 -fmax = 50.0 -qrv = True -rx_buffer_size = 16 -explorer = True -stats = False -fsk = False -tx_delay = 0 - -[TCI] -#tci settings -ip = undefined -port = undefined - -[MESH] -#tci settings -enable_protocol = False - diff --git a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp310-cp310-win32.whl b/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp310-cp310-win32.whl deleted file mode 100644 index 714d844b..00000000 Binary files a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp310-cp310-win32.whl and /dev/null differ diff --git a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp310-cp310-win_amd64.whl b/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp310-cp310-win_amd64.whl deleted file mode 100644 index 782de1b3..00000000 Binary files a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp310-cp310-win_amd64.whl and /dev/null differ diff --git a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp311-cp311-win32.whl b/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp311-cp311-win32.whl deleted file mode 100644 index 245f9222..00000000 Binary files a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp311-cp311-win32.whl and /dev/null differ diff --git a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp311-cp311-win_amd64.whl b/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp311-cp311-win_amd64.whl deleted file mode 100644 index 50209e44..00000000 Binary files a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp311-cp311-win_amd64.whl and /dev/null differ diff --git a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp39-cp39-win32.whl b/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp39-cp39-win32.whl deleted file mode 100644 index bda06fd9..00000000 Binary files a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp39-cp39-win32.whl and /dev/null differ diff --git a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp39-cp39-win_amd64.whl b/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp39-cp39-win_amd64.whl deleted file mode 100644 index 09114331..00000000 Binary files a/tnc/lib/pyaudio/windows/PyAudio-0.2.11-cp39-cp39-win_amd64.whl and /dev/null differ diff --git a/tnc/lib/pyaudio/windows/README.md b/tnc/lib/pyaudio/windows/README.md deleted file mode 100644 index 7beb7c48..00000000 --- a/tnc/lib/pyaudio/windows/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# PyAudio - -## downloaded from - -https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio diff --git a/tools/create_hmac_tokes.py b/tools/create_hmac_tokes.py index f7c6bc71..b66e5149 100755 --- a/tools/create_hmac_tokes.py +++ b/tools/create_hmac_tokes.py @@ -39,7 +39,7 @@ def create_hmac_salts(dxcallsign: str, mycallsign: str, num_tokens: int): for _ in range(len(token_array)): file.write(token_array[_] + '\n') - print("files created - place them in tnc/hmac folder and share the file with the remote station") + print("files created - place them in modem/hmac folder and share the file with the remote station") except Exception: print("error creating hmac file") diff --git a/tools/freedata_network_listener.py b/tools/freedata_network_listener.py index 651ccfeb..6a813038 100755 --- a/tools/freedata_network_listener.py +++ b/tools/freedata_network_listener.py @@ -5,7 +5,7 @@ daemon.py Author: DJ2LS, January 2022 -daemon for providing basic information for the tnc like audio or serial devices +daemon for providing basic information for the modem like audio or serial devices """ # pylint: disable=invalid-name, line-too-long, c-extension-no-member @@ -92,7 +92,7 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: #pass print(jsondata.get("routing_table")) - if jsondata.get('freedata') == "tnc-message": + if jsondata.get('freedata') == "modem-message": log.info(jsondata) if jsondata.get('ping') == "acknowledge":