fixed dataclass handling and process states

This commit is contained in:
DJ2LS 2023-10-17 14:30:34 +02:00
parent 7304246f69
commit 5f48dff549
16 changed files with 70 additions and 153 deletions

View file

@ -4,7 +4,7 @@ import helpers
import time
import modem
import base64
from static 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, TNC
import sock
import ujson as json

View file

@ -26,7 +26,7 @@ import crcengine
import log_handler
import serial.tools.list_ports
import sock
from static 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, TNC
import structlog
import ujson as json
@ -368,8 +368,13 @@ class DAEMON:
command += options
print(command)
proc = subprocess.Popen(command)
# append debugging paramter
options.append(("-vvv"))
self.log.info("[DMN] starting rigctld: ", param=command)
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
atexit.register(proc.kill)
Daemon.rigctldstarted = True
@ -378,7 +383,7 @@ class DAEMON:
except Exception as err:
self.log.info("[DMN] starting rigctld: ", e=err)
self.log.warning("[DMN] err starting rigctld: ", e=err)
@ -515,6 +520,7 @@ class DAEMON:
Daemon.tncstarted = False
if __name__ == "__main__":
mainlog = structlog.get_logger(__file__)
# we need to run this on Windows for multiprocessing support

View file

@ -24,7 +24,7 @@ import helpers
import modem
import numpy as np
import sock
from static 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, TNC
import structlog
import stats
import ujson as json

View file

@ -13,7 +13,7 @@ import time
import ujson as json
import structlog
import static
from static 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, TNC
log = structlog.get_logger("explorer")

19
tnc/global_instances.py Normal file
View file

@ -0,0 +1,19 @@
# global_instances.py
from static import Daemon, ARQ, AudioParam, Beacon, Channel, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC, MeshParam
# Initialize instances with appropriate default values
# Create single instances of each dataclass
Daemon = Daemon(tncprocess=None, rigctldprocess=None)
ARQ = ARQ()
AudioParam = AudioParam()
Beacon = Beacon()
Channel = Channel()
HamlibParam = HamlibParam()
ModemParam = ModemParam()
Station = Station()
Statistics = Statistics()
TCIParam = TCIParam()
TNC = TNC()
MeshParam = MeshParam()

View file

@ -8,7 +8,7 @@ import time
from datetime import datetime,timezone
import crcengine
import static
from static 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, TNC, MeshParam
import structlog
import numpy as np
import threading

View file

@ -29,7 +29,7 @@ import helpers
import log_handler
import modem
import static
from static 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, TNC, MeshParam
import structlog
import explorer
import json

View file

@ -36,7 +36,9 @@ SNR: negative --> * 2
# pylint: disable=invalid-name, line-too-long, c-extension-no-member
# pylint: disable=import-outside-toplevel, attribute-defined-outside-init
from static import TNC, MeshParam, FRAME_TYPE, Station, ModemParam, ARQ
from static import FRAME_TYPE
from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, Statistics, TCIParam, TNC
from codec2 import FREEDV_MODE
import numpy as np
import time

View file

@ -23,7 +23,7 @@ import numpy as np
import sock
import sounddevice as sd
import static
from static 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, TNC
from static import FRAME_TYPE
import structlog
import ujson as json

View file

@ -3,7 +3,7 @@ Hold queues used by more than one module to eliminate cyclic imports.
"""
import queue
import static
from static import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, TNC
from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, TNC
DATA_QUEUE_TRANSMIT = queue.Queue()
DATA_QUEUE_RECEIVED = queue.Queue()

View file

@ -10,7 +10,7 @@ import time
import structlog
import threading
import static
from static import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam
from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam
class radio:

View file

@ -7,7 +7,6 @@ simple TNC self tests
# pylint: disable=import-outside-toplevel, attribute-defined-outside-init
import sys
import structlog
from static import ARQ, Audio, Beacon, Channel, Daemon, Hamlib, Modem, Station, TCI, TNC
log = structlog.get_logger("selftest")

View file

@ -27,7 +27,7 @@ import time
import wave
import helpers
import static
from static 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, TNC, MeshParam
import structlog
from random import randrange
import ujson as json
@ -1248,6 +1248,32 @@ def send_daemon_state():
"""
log = structlog.get_logger("send_daemon_state")
# we need to do some process checking for providing the correct state
# at least we are checking the returncode of rigctld
# None state means, the process is still running
try:
retcode_rigctld = Daemon.rigctldprocess.poll()
if retcode_rigctld in [None, "None"]:
output, errs = Daemon.rigctldprocess.communicate()
print(f"rigctld out: {output}")
print(f"rigctld err: {errs}")
else:
# print(f"rigctld closed with code: {retcode_rigctld}")
Daemon.rigctldstarted = False
retcode_tnc = Daemon.tncprocess.poll()
if retcode_tnc in [None, "None"]:
output, errs = Daemon.tncprocess.communicate()
print(f"tnc out: {output}")
print(f"tnc err: {errs}")
else:
# print(f"tnc closed with code: {retcode_tnc}")
Daemon.tncstarted = False
except Exception:
pass
try:
python_version = f"{str(sys.version_info[0])}.{str(sys.version_info[1])}"

View file

@ -188,137 +188,3 @@ class FRAME_TYPE(Enum):
FEC_WAKEUP = 252
IDENT = 254
TEST_FRAME = 255
# ---------------------------------------------------------------
# DON'T USE THESE SETTINGS ANYMORE
# ---------------------------------------------------------------
# Fixme: REMOVE THESE OLD SETTINGS!
# REASON: For some reason ctests are failing when using dataclasses.
# We need to figure out whats happening and why the tests are failing.
CHANNEL_BUSY_SLOT = [False] * 5
ENABLE_EXPLORER = False
ENABLE_STATS = False
# DAEMON
DAEMONPORT: int = 3001
TNCSTARTED: bool = False
TNCPROCESS: subprocess.Popen
# Operator Defaults
MYCALLSIGN: bytes = b"AA0AA"
MYCALLSIGN_CRC: bytes = b"A"
DXCALLSIGN: bytes = b"ZZ9YY"
DXCALLSIGN_CRC: bytes = b"A"
MYGRID: bytes = b""
DXGRID: bytes = b""
SSID_LIST: list = [] # ssid list we are responding to
LOW_BANDWIDTH_MODE: bool = False
# ---------------------------------
# Server Defaults
HOST: str = "0.0.0.0"
PORT: int = 3000
SOCKET_TIMEOUT: int = 1 # seconds
# ---------------------------------
SERIAL_DEVICES: list = []
# ---------------------------------
LISTEN: bool = True
PTT_STATE: bool = False
TRANSMITTING: bool = False
HAMLIB_RADIOCONTROL: str = "disabled"
HAMLIB_RIGCTLD_IP: str = "127.0.0.1"
HAMLIB_RIGCTLD_PORT: str = "4532"
HAMLIB_STATUS: str = "unknown/disconnected"
HAMLIB_FREQUENCY: int = 0
HAMLIB_MODE: str = ""
HAMLIB_BANDWIDTH: int = 0
HAMLIB_RF: int = 0
HAMLIB_ALC: int = 0
HAMLIB_STRENGTH: int = 0
# -------------------------
# FreeDV Defaults
SNR: float = 0
FREQ_OFFSET: float = 0
SCATTER: list = []
ENABLE_SCATTER: bool = False
ENABLE_FSK: bool = False
RESPOND_TO_CQ: bool = False
RESPOND_TO_CALL: bool = True # respond to cq, ping, connection request, file request if not in session
TX_DELAY: int = 0 # delay in ms before sending modulation for triggering VOX for example or slow PTT radios
# ---------------------------------
# Audio Defaults
TX_AUDIO_LEVEL: int = 50
AUDIO_INPUT_DEVICES: list = []
AUDIO_OUTPUT_DEVICES: list = []
AUDIO_INPUT_DEVICE: int = -2
AUDIO_OUTPUT_DEVICE: int = -2
AUDIO_RECORD: bool = False
AUDIO_RECORD_FILE = ''
BUFFER_OVERFLOW_COUNTER: list = [0, 0, 0, 0, 0]
AUDIO_AUTO_TUNE: bool = False
# Audio TCI Support
AUDIO_ENABLE_TCI: bool = False
TCI_IP: str = '127.0.0.1'
TCI_PORT: int = '9000'
AUDIO_DBFS: int = 0
FFT: list = [0]
ENABLE_FFT: bool = True
CHANNEL_BUSY: bool = False
# ARQ PROTOCOL VERSION
# v.5 - signalling frame uses datac0
# v.6 - signalling frame uses datac13
# CHECKED # ARQ_PROTOCOL_VERSION: int = 6
# ARQ statistics
# CHECKED # SPEED_LIST: list = []
# CHECKED # ARQ_BYTES_PER_MINUTE_BURST: int = 0
# CHECKED # ARQ_BYTES_PER_MINUTE: int = 0
# CHECKED # ARQ_BITS_PER_SECOND_BURST: int = 0
# CHECKED # ARQ_BITS_PER_SECOND: int = 0
# CHECKED # ARQ_COMPRESSION_FACTOR: int = 0
# CHECKED # ARQ_TRANSMISSION_PERCENT: int = 0
# CHECKED # ARQ_SECONDS_UNTIL_FINISH: int = 0
# CHECKED # ARQ_SPEED_LEVEL: int = 0
# CHECKED # TOTAL_BYTES: int = 0
# set save to folder state for allowing downloading files to local file system
# CHECKED # ARQ_SAVE_TO_FOLDER: bool = False
# CHANNEL_STATE = 'RECEIVING_SIGNALLING'
TNC_STATE: str = "IDLE"
# CHECKED # ARQ_STATE: bool = False
# CHECKED # ARQ_SESSION: bool = False
# disconnected, connecting, connected, disconnecting, failed
# CHECKED # ARQ_SESSION_STATE: str = "disconnected"
# BEACON STATE
BEACON_STATE: bool = False
BEACON_PAUSE: bool = False
# ------- RX BUFFER
# CHECKED # RX_MSG_BUFFER: list = []
# CHECKED # RX_BURST_BUFFER: list = []
# CHECKED # RX_FRAME_BUFFER: bytes = b""
# CHECKED # RX_BUFFER_SIZE: int = 16
# ------- HEARD STATIONS BUFFER
HEARD_STATIONS: list = []
# ------- CODEC2 SETTINGS
TUNING_RANGE_FMIN: float = -50.0
TUNING_RANGE_FMAX: float = 50.0
IS_CODEC2_TRAFFIC: bool = False # true if we have codec2 signalling mode traffic on channel

View file

@ -12,8 +12,7 @@ import threading
import time
import ujson as json
import structlog
import static
from static import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, TNC
from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, TNC
log = structlog.get_logger("stats")

View file

@ -7,7 +7,7 @@ import websocket
import numpy as np
import time
from queues import AUDIO_TRANSMIT_QUEUE, AUDIO_RECEIVED_QUEUE
from static import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, TNC
from global_instances import ARQ, AudioParam, Beacon, Channel, Daemon, HamlibParam, ModemParam, Station, TCIParam, TNC
class TCICtrl:
def __init__(self, hostname='127.0.0.1', port=50001):