From 92cfa367f371b0507b3ca172c9e50baca172c85c Mon Sep 17 00:00:00 2001 From: dj2ls Date: Mon, 11 Apr 2022 11:03:54 +0200 Subject: [PATCH] black code formatting --- tnc/audio.py | 34 +- tnc/codec2.py | 199 +- tnc/daemon.py | 337 +-- tnc/data_handler.py | 1982 +++++++++++------ tnc/helpers.py | 211 +- .../linux/python3.8/site-packages/Hamlib.py | 1706 +++++++++++--- tnc/log_handler.py | 12 +- tnc/main.py | 301 ++- tnc/modem.py | 720 +++--- tnc/rig.py | 230 +- tnc/rigctl.py | 164 +- tnc/rigctld.py | 112 +- tnc/rigdummy.py | 28 +- tnc/sock.py | 543 +++-- tnc/static.py | 62 +- 15 files changed, 4393 insertions(+), 2248 deletions(-) diff --git a/tnc/audio.py b/tnc/audio.py index 380f3c81..07ebe0db 100644 --- a/tnc/audio.py +++ b/tnc/audio.py @@ -1,4 +1,3 @@ - import json import sys import multiprocessing @@ -7,39 +6,41 @@ import atexit atexit.register(sd._terminate) -def get_audio_devices(): - +def get_audio_devices(): """ return list of input and output audio devices in own process to avoid crashes of portaudio on raspberry pi - + also uses a process data manager """ # we need to run this on windows for multiprocessing support # multiprocessing.freeze_support() - #multiprocessing.get_context('spawn') + # multiprocessing.get_context('spawn') # we need to reset and initialize sounddevice before running the multiprocessing part. # If we are not doing this at this early point, not all devices will be displayed sd._terminate() sd._initialize() - + with multiprocessing.Manager() as manager: - + proxy_input_devices = manager.list() proxy_output_devices = manager.list() - #print(multiprocessing.get_start_method()) - p = multiprocessing.Process(target=fetch_audio_devices, args=(proxy_input_devices, proxy_output_devices)) + # print(multiprocessing.get_start_method()) + p = multiprocessing.Process( + target=fetch_audio_devices, args=(proxy_input_devices, proxy_output_devices) + ) p.start() p.join() - - return list(proxy_input_devices), list(proxy_output_devices) + + return list(proxy_input_devices), list(proxy_output_devices) + def fetch_audio_devices(input_devices, output_devices): """ get audio devices from portaudio - + Args: input_devices: proxy variable for input devices output_devices: proxy variable for outout devices @@ -47,15 +48,15 @@ def fetch_audio_devices(input_devices, output_devices): Returns: """ - + devices = sd.query_devices(device=None, kind=None) index = 0 for device in devices: - #for i in range(0, p.get_device_count()): + # for i in range(0, p.get_device_count()): # we need to do a try exception, beacuse for windows theres no audio device range try: name = device["name"] - + maxOutputChannels = device["max_output_channels"] maxInputChannels = device["max_input_channels"] @@ -63,11 +64,10 @@ def fetch_audio_devices(input_devices, output_devices): print(e) maxInputChannels = 0 maxOutputChannels = 0 - name = '' + name = "" if maxInputChannels > 0: input_devices.append({"id": index, "name": str(name)}) if maxOutputChannels > 0: output_devices.append({"id": index, "name": str(name)}) index += 1 - diff --git a/tnc/codec2.py b/tnc/codec2.py index c1e84c15..dcc71545 100644 --- a/tnc/codec2.py +++ b/tnc/codec2.py @@ -17,6 +17,7 @@ class FREEDV_MODE(Enum): """ enum for codec2 modes and names """ + fsk_ldpc_0 = 200 fsk_ldpc_1 = 201 fsk_ldpc = 9 @@ -25,31 +26,33 @@ class FREEDV_MODE(Enum): datac3 = 12 allmodes = 255 + # function for returning the mode value def freedv_get_mode_value_by_name(mode): """ get the codec2 mode by entering its string Args: - mode: + mode: Returns: int """ return FREEDV_MODE[mode].value + # function for returning the mode name def freedv_get_mode_name_by_value(mode): """ get the codec2 mode name as string Args: - mode: + mode: Returns: string """ return FREEDV_MODE(mode).name - - + + # check if we are running in a pyinstaller environment try: app_path = sys._MEIPASS @@ -58,17 +61,17 @@ except: sys.path.append(app_path) structlog.get_logger("structlog").info("[C2 ] Searching for libcodec2...") -if sys.platform == 'linux': - files = glob.glob('**/*libcodec2*',recursive=True) - files.append('libcodec2.so') -elif sys.platform == 'darwin': - files = glob.glob('**/*libcodec2*.dylib',recursive=True) - -elif sys.platform == 'win32' or sys.platform == 'win64': - files = glob.glob('**\*libcodec2*.dll',recursive=True) +if sys.platform == "linux": + files = glob.glob("**/*libcodec2*", recursive=True) + files.append("libcodec2.so") +elif sys.platform == "darwin": + files = glob.glob("**/*libcodec2*.dylib", recursive=True) + +elif sys.platform == "win32" or sys.platform == "win64": + files = glob.glob("**\*libcodec2*.dll", recursive=True) else: files = [] - + for file in files: try: @@ -76,21 +79,21 @@ for file in files: structlog.get_logger("structlog").info("[C2 ] Libcodec2 loaded", path=file) break except Exception as e: - structlog.get_logger("structlog").warning("[C2 ] Libcodec2 found but not loaded", path=file, e=e) + structlog.get_logger("structlog").warning( + "[C2 ] Libcodec2 found but not loaded", path=file, e=e + ) -# quit module if codec2 cant be loaded -if not 'api' in locals(): +# quit module if codec2 cant be loaded +if not "api" in locals(): structlog.get_logger("structlog").critical("[C2 ] Libcodec2 not loaded", path=file) os._exit(1) +# ctypes function init - -# ctypes function init - -#api.freedv_set_tuning_range.restype = c_int -#api.freedv_set_tuning_range.argype = [c_void_p, c_float, c_float] +# api.freedv_set_tuning_range.restype = c_int +# api.freedv_set_tuning_range.argype = [c_void_p, c_float, c_float] api.freedv_open.argype = [c_int] api.freedv_open.restype = c_void_p @@ -121,24 +124,24 @@ api.freedv_get_n_max_modem_samples.restype = c_int api.freedv_set_frames_per_burst.argtype = [c_void_p, c_int] api.freedv_set_frames_per_burst.restype = c_void_p - + api.freedv_get_rx_status.argtype = [c_void_p] -api.freedv_get_rx_status.restype = c_int +api.freedv_get_rx_status.restype = c_int api.freedv_get_modem_stats.argtype = [c_void_p, c_void_p, c_void_p] api.freedv_get_modem_stats.restype = c_int api.freedv_get_n_tx_postamble_modem_samples.argtype = [c_void_p] -api.freedv_get_n_tx_postamble_modem_samples.restype = c_int +api.freedv_get_n_tx_postamble_modem_samples.restype = c_int api.freedv_get_n_tx_preamble_modem_samples.argtype = [c_void_p] -api.freedv_get_n_tx_preamble_modem_samples.restype = c_int +api.freedv_get_n_tx_preamble_modem_samples.restype = c_int api.freedv_get_n_tx_modem_samples.argtype = [c_void_p] -api.freedv_get_n_tx_modem_samples.restype = c_int +api.freedv_get_n_tx_modem_samples.restype = c_int api.freedv_get_n_max_modem_samples.argtype = [c_void_p] -api.freedv_get_n_max_modem_samples.restype = c_int +api.freedv_get_n_max_modem_samples.restype = c_int api.FREEDV_FS_8000 = 8000 api.FREEDV_MODE_DATAC1 = 10 @@ -151,17 +154,19 @@ api.FREEDV_MODE_FSK_LDPC = 9 # advanced structure for fsk modes class ADVANCED(ctypes.Structure): """ """ + _fields_ = [ - ("interleave_frames", ctypes.c_int), + ("interleave_frames", ctypes.c_int), ("M", ctypes.c_int), ("Rs", ctypes.c_int), ("Fs", ctypes.c_int), - ("first_tone", ctypes.c_int), - ("tone_spacing", ctypes.c_int), - ("codename", ctypes.c_char_p), + ("first_tone", ctypes.c_int), + ("tone_spacing", ctypes.c_int), + ("codename", ctypes.c_char_p), ] -''' + +""" adv.interleave_frames = 0 # max amplitude adv.M = 2 # number of fsk tones 2/4 adv.Rs = 100 # symbol rate @@ -181,16 +186,16 @@ H_128_256_5 rate 0.50 (256,128) BPF: 16 working H_4096_8192_3d rate 0.50 (8192,4096) BPF: 512 not working H_16200_9720 rate 0.60 (16200,9720) BPF: 1215 not working H_1024_2048_4f rate 0.50 (2048,1024) BPF: 128 working -''' +""" # --------------- 2 FSK H_128_256_5, 16 bytes api.FREEDV_MODE_FSK_LDPC_0_ADV = ADVANCED() api.FREEDV_MODE_FSK_LDPC_0_ADV.interleave_frames = 0 api.FREEDV_MODE_FSK_LDPC_0_ADV.M = 4 api.FREEDV_MODE_FSK_LDPC_0_ADV.Rs = 100 api.FREEDV_MODE_FSK_LDPC_0_ADV.Fs = 8000 -api.FREEDV_MODE_FSK_LDPC_0_ADV.first_tone = 1400 # 1150 4fsk, 1500 2fsk -api.FREEDV_MODE_FSK_LDPC_0_ADV.tone_spacing = 120 #200 -api.FREEDV_MODE_FSK_LDPC_0_ADV.codename = 'H_128_256_5'.encode('utf-8') # code word +api.FREEDV_MODE_FSK_LDPC_0_ADV.first_tone = 1400 # 1150 4fsk, 1500 2fsk +api.FREEDV_MODE_FSK_LDPC_0_ADV.tone_spacing = 120 # 200 +api.FREEDV_MODE_FSK_LDPC_0_ADV.codename = "H_128_256_5".encode("utf-8") # code word # --------------- 4 H_256_512_4, 7 bytes api.FREEDV_MODE_FSK_LDPC_1_ADV = ADVANCED() @@ -198,26 +203,27 @@ api.FREEDV_MODE_FSK_LDPC_1_ADV.interleave_frames = 0 api.FREEDV_MODE_FSK_LDPC_1_ADV.M = 4 api.FREEDV_MODE_FSK_LDPC_1_ADV.Rs = 100 api.FREEDV_MODE_FSK_LDPC_1_ADV.Fs = 8000 -api.FREEDV_MODE_FSK_LDPC_1_ADV.first_tone = 1250 # 1250 4fsk, 1500 2fsk +api.FREEDV_MODE_FSK_LDPC_1_ADV.first_tone = 1250 # 1250 4fsk, 1500 2fsk api.FREEDV_MODE_FSK_LDPC_1_ADV.tone_spacing = 200 -api.FREEDV_MODE_FSK_LDPC_1_ADV.codename = 'H_256_512_4'.encode('utf-8') # code word +api.FREEDV_MODE_FSK_LDPC_1_ADV.codename = "H_256_512_4".encode("utf-8") # code word # ------- MODEM STATS STRUCTURES -MODEM_STATS_NC_MAX = 50+1 -MODEM_STATS_NR_MAX = 160 -MODEM_STATS_ET_MAX = 8 -MODEM_STATS_EYE_IND_MAX = 160 -MODEM_STATS_NSPEC = 512 -MODEM_STATS_MAX_F_HZ = 4000 -MODEM_STATS_MAX_F_EST = 4 +MODEM_STATS_NC_MAX = 50 + 1 +MODEM_STATS_NR_MAX = 160 +MODEM_STATS_ET_MAX = 8 +MODEM_STATS_EYE_IND_MAX = 160 +MODEM_STATS_NSPEC = 512 +MODEM_STATS_MAX_F_HZ = 4000 +MODEM_STATS_MAX_F_EST = 4 # modem stats structure class MODEMSTATS(ctypes.Structure): """ """ + _fields_ = [ ("Nc", ctypes.c_int), ("snr_est", ctypes.c_float), - ("rx_symbols", (ctypes.c_float * MODEM_STATS_NR_MAX)*MODEM_STATS_NC_MAX), + ("rx_symbols", (ctypes.c_float * MODEM_STATS_NR_MAX) * MODEM_STATS_NC_MAX), ("nr", ctypes.c_int), ("sync", ctypes.c_int), ("foff", ctypes.c_float), @@ -227,19 +233,23 @@ class MODEMSTATS(ctypes.Structure): ("pre", ctypes.c_int), ("post", ctypes.c_int), ("uw_fails", ctypes.c_int), - ("neyetr", ctypes.c_int), # How many eye traces are plotted - ("neyesamp", ctypes.c_int), # How many samples in the eye diagram - ("f_est", (ctypes.c_float * MODEM_STATS_MAX_F_EST)), # How many samples in the eye diagram + ("neyetr", ctypes.c_int), # How many eye traces are plotted + ("neyesamp", ctypes.c_int), # How many samples in the eye diagram + ( + "f_est", + (ctypes.c_float * MODEM_STATS_MAX_F_EST), + ), # How many samples in the eye diagram ("fft_buf", (ctypes.c_float * MODEM_STATS_NSPEC * 2)), ] - - - + + # Return code flags for freedv_get_rx_status() function -api.FREEDV_RX_TRIAL_SYNC = 0x1 # demodulator has trial sync -api.FREEDV_RX_SYNC = 0x2 # demodulator has sync -api.FREEDV_RX_BITS = 0x4 # data bits have been returned -api.FREEDV_RX_BIT_ERRORS = 0x8 # FEC may not have corrected all bit errors (not all parity checks OK) +api.FREEDV_RX_TRIAL_SYNC = 0x1 # demodulator has trial sync +api.FREEDV_RX_SYNC = 0x2 # demodulator has sync +api.FREEDV_RX_BITS = 0x4 # data bits have been returned +api.FREEDV_RX_BIT_ERRORS = ( + 0x8 # FEC may not have corrected all bit errors (not all parity checks OK) +) api.rx_sync_flags_to_text = [ "----", @@ -257,68 +267,80 @@ api.rx_sync_flags_to_text = [ "EB--", "EB-T", "EBS-", - "EBST"] + "EBST", +] # audio buffer --------------------------------------------------------- + class audio_buffer: """ thread safe audio buffer, which fits to needs of codec2 - + made by David Rowe, VK5DGR """ + # a buffer of int16 samples, using a fixed length numpy array self.buffer for storage # self.nbuffer is the current number of samples in the buffer def __init__(self, size): - structlog.get_logger("structlog").debug("[C2 ] creating audio buffer", size=size) + structlog.get_logger("structlog").debug( + "[C2 ] creating audio buffer", size=size + ) self.size = size self.buffer = np.zeros(size, dtype=np.int16) self.nbuffer = 0 self.mutex = Lock() - def push(self,samples): + + def push(self, samples): """ Push new data to buffer Args: - samples: + samples: Returns: """ self.mutex.acquire() # add samples at the end of the buffer - assert self.nbuffer+len(samples) <= self.size - self.buffer[self.nbuffer:self.nbuffer+len(samples)] = samples + assert self.nbuffer + len(samples) <= self.size + self.buffer[self.nbuffer : self.nbuffer + len(samples)] = samples self.nbuffer += len(samples) self.mutex.release() - def pop(self,size): + + def pop(self, size): """ get data from buffer in size of NIN Args: - size: + size: Returns: """ self.mutex.acquire() # remove samples from the start of the buffer - self.nbuffer -= size; - self.buffer[:self.nbuffer] = self.buffer[size:size+self.nbuffer] + self.nbuffer -= size + self.buffer[: self.nbuffer] = self.buffer[size : size + self.nbuffer] assert self.nbuffer >= 0 self.mutex.release() - + + # resampler --------------------------------------------------------- -api.FDMDV_OS_48 = int(6) # oversampling rate -api.FDMDV_OS_TAPS_48K = int(48) # number of OS filter taps at 48kHz -api.FDMDV_OS_TAPS_48_8K = int(api.FDMDV_OS_TAPS_48K/api.FDMDV_OS_48) # number of OS filter taps at 8kHz +api.FDMDV_OS_48 = int(6) # oversampling rate +api.FDMDV_OS_TAPS_48K = int(48) # number of OS filter taps at 48kHz +api.FDMDV_OS_TAPS_48_8K = int( + api.FDMDV_OS_TAPS_48K / api.FDMDV_OS_48 +) # number of OS filter taps at 8kHz api.fdmdv_8_to_48_short.argtype = [c_void_p, c_void_p, c_int] api.fdmdv_48_to_8_short.argtype = [c_void_p, c_void_p, c_int] + class resampler: """ resampler class """ + # resample an array of variable length, we just store the filter memories here MEM8 = api.FDMDV_OS_TAPS_48_8K MEM48 = api.FDMDV_OS_TAPS_48K @@ -327,9 +349,8 @@ class resampler: structlog.get_logger("structlog").debug("[C2 ] create 48<->8 kHz resampler") self.filter_mem8 = np.zeros(self.MEM8, dtype=np.int16) self.filter_mem48 = np.zeros(self.MEM48) - - - def resample48_to_8(self,in48): + + def resample48_to_8(self, in48): """ audio resampler integration from codec2 downsample audio from 48000Hz to 8000Hz @@ -341,25 +362,25 @@ class resampler: """ assert in48.dtype == np.int16 # length of input vector must be an integer multiple of api.FDMDV_OS_48 - assert(len(in48) % api.FDMDV_OS_48 == 0) + assert len(in48) % api.FDMDV_OS_48 == 0 # concat filter memory and input samples - in48_mem = np.zeros(self.MEM48+len(in48), dtype=np.int16) - in48_mem[:self.MEM48] = self.filter_mem48 - in48_mem[self.MEM48:] = in48 + in48_mem = np.zeros(self.MEM48 + len(in48), dtype=np.int16) + in48_mem[: self.MEM48] = self.filter_mem48 + in48_mem[self.MEM48 :] = in48 # In C: pin48=&in48_mem[MEM48] - pin48 = byref(np.ctypeslib.as_ctypes(in48_mem), 2*self.MEM48) + pin48 = byref(np.ctypeslib.as_ctypes(in48_mem), 2 * self.MEM48) n8 = int(len(in48) / api.FDMDV_OS_48) out8 = np.zeros(n8, dtype=np.int16) - api.fdmdv_48_to_8_short(out8.ctypes, pin48, n8); + api.fdmdv_48_to_8_short(out8.ctypes, pin48, n8) # store memory for next time - self.filter_mem48 = in48_mem[:self.MEM48] + self.filter_mem48 = in48_mem[: self.MEM48] return out8 - def resample8_to_48(self,in8): + def resample8_to_48(self, in8): """ audio resampler integration from codec2 resample audio from 8000Hz to 48000Hz @@ -372,16 +393,16 @@ class resampler: assert in8.dtype == np.int16 # concat filter memory and input samples - in8_mem = np.zeros(self.MEM8+len(in8), dtype=np.int16) - in8_mem[:self.MEM8] = self.filter_mem8 - in8_mem[self.MEM8:] = in8 + in8_mem = np.zeros(self.MEM8 + len(in8), dtype=np.int16) + in8_mem[: self.MEM8] = self.filter_mem8 + in8_mem[self.MEM8 :] = in8 # In C: pin8=&in8_mem[MEM8] - pin8 = byref(np.ctypeslib.as_ctypes(in8_mem), 2*self.MEM8) - out48 = np.zeros(api.FDMDV_OS_48*len(in8), dtype=np.int16) - api.fdmdv_8_to_48_short(out48.ctypes, pin8, len(in8)); + pin8 = byref(np.ctypeslib.as_ctypes(in8_mem), 2 * self.MEM8) + out48 = np.zeros(api.FDMDV_OS_48 * len(in8), dtype=np.int16) + api.fdmdv_8_to_48_short(out48.ctypes, pin8, len(in8)) # store memory for next time - self.filter_mem8 = in8_mem[:self.MEM8] + self.filter_mem8 = in8_mem[: self.MEM8] return out48 diff --git a/tnc/daemon.py b/tnc/daemon.py index f51a22d3..38ea57a0 100755 --- a/tnc/daemon.py +++ b/tnc/daemon.py @@ -37,85 +37,93 @@ def signal_handler(sig, frame): """ signal handler for closing the network socket on app exit Args: - sig: - frame: + sig: + frame: Returns: system exit """ - print('Closing daemon...') + print("Closing daemon...") sock.CLOSE_SIGNAL = True sys.exit(0) + + signal.signal(signal.SIGINT, signal_handler) - -class DAEMON(): - """ - daemon class - +class DAEMON: """ + daemon class + + """ + def __init__(self): - - # load crc engine - self.crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc8 library - + + # load crc engine + self.crc_algorithm = crcengine.new("crc16-ccitt-false") # load crc8 library + self.daemon_queue = sock.DAEMON_QUEUE - update_audio_devices = threading.Thread(target=self.update_audio_devices, name="UPDATE_AUDIO_DEVICES", daemon=True) + update_audio_devices = threading.Thread( + target=self.update_audio_devices, name="UPDATE_AUDIO_DEVICES", daemon=True + ) update_audio_devices.start() - update_serial_devices = threading.Thread(target=self.update_serial_devices, name="UPDATE_SERIAL_DEVICES", daemon=True) + update_serial_devices = threading.Thread( + target=self.update_serial_devices, name="UPDATE_SERIAL_DEVICES", daemon=True + ) update_serial_devices.start() worker = threading.Thread(target=self.worker, name="WORKER", daemon=True) worker.start() - - - + def update_audio_devices(self): - """ + """ update audio devices and set to static """ while 1: try: if not static.TNCSTARTED: - - static.AUDIO_INPUT_DEVICES, static.AUDIO_OUTPUT_DEVICES = audio.get_audio_devices() + + ( + static.AUDIO_INPUT_DEVICES, + static.AUDIO_OUTPUT_DEVICES, + ) = audio.get_audio_devices() except Exception as e: print(e) time.sleep(1) - - + def update_serial_devices(self): """ update serial devices and set to static """ while 1: try: - #print("update serial") + # print("update serial") serial_devices = [] ports = serial.tools.list_ports.comports() for port, desc, hwid in ports: - + # calculate hex of hwid if we have unique names - crc_hwid = self.crc_algorithm(bytes(hwid, encoding='utf-8')) - crc_hwid = crc_hwid.to_bytes(2, byteorder='big') + crc_hwid = self.crc_algorithm(bytes(hwid, encoding="utf-8")) + crc_hwid = crc_hwid.to_bytes(2, byteorder="big") crc_hwid = crc_hwid.hex() - description = desc + ' [' + crc_hwid + ']' - serial_devices.append({"port": str(port), "description": str(description) }) - + description = desc + " [" + crc_hwid + "]" + serial_devices.append( + {"port": str(port), "description": str(description)} + ) + static.SERIAL_DEVICES = serial_devices time.sleep(1) except Exception as e: print(e) - + def worker(self): """ a worker for the received commands """ while 1: try: - + data = self.daemon_queue.get() # data[1] mycall @@ -138,132 +146,135 @@ class DAEMON(): # data[18] low_bandwith_mode # data[19] tuning_range_fmin # data[20] tuning_range_fmax - - if data[0] == 'STARTTNC': - structlog.get_logger("structlog").warning("[DMN] Starting TNC", rig=data[5], port=data[6]) + + if data[0] == "STARTTNC": + structlog.get_logger("structlog").warning( + "[DMN] Starting TNC", rig=data[5], port=data[6] + ) # list of parameters, necessary for running subprocess command as a list options = [] - - options.append('--port') + + options.append("--port") options.append(str(static.DAEMONPORT - 1)) - - options.append('--mycall') + + options.append("--mycall") options.append(data[1]) - - options.append('--mygrid') + + options.append("--mygrid") options.append(data[2]) - - options.append('--rx') + + options.append("--rx") options.append(data[3]) - - options.append('--tx') + + options.append("--tx") options.append(data[4]) - + # if radiocontrol != disabled - # this should hopefully avoid a ton of problems if we are just running in + # this should hopefully avoid a ton of problems if we are just running in # disabled mode - if data[13] != 'disabled': - - options.append('--devicename') + if data[13] != "disabled": + + options.append("--devicename") options.append(data[5]) - - options.append('--deviceport') + + options.append("--deviceport") options.append(data[6]) - - options.append('--serialspeed') + + options.append("--serialspeed") options.append(data[7]) - - options.append('--pttprotocol') + + options.append("--pttprotocol") options.append(data[8]) - - options.append('--pttport') + + options.append("--pttport") options.append(data[9]) - - options.append('--data_bits') + + options.append("--data_bits") options.append(data[10]) - - options.append('--stop_bits') + + options.append("--stop_bits") options.append(data[11]) - - options.append('--handshake') + + options.append("--handshake") options.append(data[12]) - - options.append('--radiocontrol') + + options.append("--radiocontrol") options.append(data[13]) - - if data[13] != 'rigctld': - options.append('--rigctld_ip') + + if data[13] != "rigctld": + options.append("--rigctld_ip") options.append(data[14]) - - options.append('--rigctld_port') + + options.append("--rigctld_port") options.append(data[15]) - - if data[16] == 'True': - options.append('--scatter') - - if data[17] == 'True': - options.append('--fft') - if data[18] == 'True': - options.append('--500hz') + if data[16] == "True": + options.append("--scatter") - - options.append('--tuning_range_fmin') + if data[17] == "True": + options.append("--fft") + + if data[18] == "True": + options.append("--500hz") + + options.append("--tuning_range_fmin") options.append(data[19]) - - options.append('--tuning_range_fmax') + + options.append("--tuning_range_fmax") options.append(data[20]) # overriding FSK mode - #if data[21] == 'True': + # if data[21] == 'True': # options.append('--fsk') - options.append('--tx-audio-level') - options.append(data[22]) - - - + options.append("--tx-audio-level") + options.append(data[22]) + # try running tnc from binary, else run from source # this helps running the tnc in a developer environment try: command = [] - if sys.platform == 'linux' or sys.platform == 'darwin': - command.append('./freedata-tnc') - elif sys.platform == 'win32' or sys.platform == 'win64': - command.append('freedata-tnc.exe') - + if sys.platform == "linux" or sys.platform == "darwin": + command.append("./freedata-tnc") + elif sys.platform == "win32" or sys.platform == "win64": + command.append("freedata-tnc.exe") + command += options p = subprocess.Popen(command) - + atexit.register(p.kill) - structlog.get_logger("structlog").info("[DMN] TNC started", path="binary") + structlog.get_logger("structlog").info( + "[DMN] TNC started", path="binary" + ) except: command = [] - if sys.platform == 'linux' or sys.platform == 'darwin': - command.append('python3') - elif sys.platform == 'win32' or sys.platform == 'win64': - command.append('python') - - command.append('main.py') + if sys.platform == "linux" or sys.platform == "darwin": + command.append("python3") + elif sys.platform == "win32" or sys.platform == "win64": + command.append("python") + + command.append("main.py") command += options p = subprocess.Popen(command) atexit.register(p.kill) - structlog.get_logger("structlog").info("[DMN] TNC started", path="source") + structlog.get_logger("structlog").info( + "[DMN] TNC started", path="source" + ) static.TNCPROCESS = p # .pid static.TNCSTARTED = True - ''' + """ # WE HAVE THIS PART in SOCKET if data[0] == 'STOPTNC': static.TNCPROCESS.kill() structlog.get_logger("structlog").warning("[DMN] Stopping TNC") #os.kill(static.TNCPROCESS, signal.SIGKILL) static.TNCSTARTED = False - ''' + """ # data[1] devicename # data[2] deviceport # data[3] serialspeed @@ -275,7 +286,7 @@ class DAEMON(): # data[9] radiocontrol # data[10] rigctld_ip # data[11] rigctld_port - if data[0] == 'TEST_HAMLIB': + if data[0] == "TEST_HAMLIB": devicename = data[1] deviceport = data[2] @@ -289,91 +300,125 @@ class DAEMON(): rigctld_ip = data[10] rigctld_port = data[11] - - # check how we want to control the radio - if radiocontrol == 'direct': + if radiocontrol == "direct": import rig - elif radiocontrol == 'rigctl': + elif radiocontrol == "rigctl": import rigctl as rig - elif radiocontrol == 'rigctld': + elif radiocontrol == "rigctld": import rigctld as rig else: import rigdummy as rig - + hamlib = rig.radio() - hamlib.open_rig(devicename=devicename, deviceport=deviceport, hamlib_ptt_type=pttprotocol, serialspeed=serialspeed, pttport=pttport, data_bits=data_bits, stop_bits=stop_bits, handshake=handshake, rigctld_ip=rigctld_ip, rigctld_port = rigctld_port) + hamlib.open_rig( + devicename=devicename, + deviceport=deviceport, + hamlib_ptt_type=pttprotocol, + serialspeed=serialspeed, + pttport=pttport, + data_bits=data_bits, + stop_bits=stop_bits, + handshake=handshake, + rigctld_ip=rigctld_ip, + rigctld_port=rigctld_port, + ) hamlib_version = rig.hamlib_version - hamlib.set_ptt(True) + hamlib.set_ptt(True) pttstate = hamlib.get_ptt() - + if pttstate: - structlog.get_logger("structlog").info("[DMN] Hamlib PTT", status = 'SUCCESS') - response = {'command': 'test_hamlib', 'result': 'SUCCESS'} + structlog.get_logger("structlog").info( + "[DMN] Hamlib PTT", status="SUCCESS" + ) + response = {"command": "test_hamlib", "result": "SUCCESS"} elif not pttstate: - structlog.get_logger("structlog").warning("[DMN] Hamlib PTT", status = 'NO SUCCESS') - response = {'command': 'test_hamlib', 'result': 'NOSUCCESS'} + structlog.get_logger("structlog").warning( + "[DMN] Hamlib PTT", status="NO SUCCESS" + ) + response = {"command": "test_hamlib", "result": "NOSUCCESS"} else: - structlog.get_logger("structlog").error("[DMN] Hamlib PTT", status = 'FAILED') - response = {'command': 'test_hamlib', 'result': 'FAILED'} - - hamlib.set_ptt(False) + structlog.get_logger("structlog").error( + "[DMN] Hamlib PTT", status="FAILED" + ) + response = {"command": "test_hamlib", "result": "FAILED"} + + hamlib.set_ptt(False) hamlib.close_rig() - + jsondata = json.dumps(response) sock.SOCKET_QUEUE.put(jsondata) - + except Exception as e: print(e) - -if __name__ == '__main__': +if __name__ == "__main__": # we need to run this on windows for multiprocessing support multiprocessing.freeze_support() - # --------------------------------------------GET PARAMETER INPUTS - PARSER = argparse.ArgumentParser(description='FreeDATA Daemon') - PARSER.add_argument('--port', dest="socket_port",default=3001, help="Socket port in the range of 1024-65536", type=int) + PARSER = argparse.ArgumentParser(description="FreeDATA Daemon") + PARSER.add_argument( + "--port", + dest="socket_port", + default=3001, + help="Socket port in the range of 1024-65536", + type=int, + ) ARGS = PARSER.parse_args() - + static.DAEMONPORT = ARGS.socket_port - try: - if sys.platform == 'linux': - logging_path = os.getenv("HOME") + '/.config/' + 'FreeDATA/' + 'daemon' - - if sys.platform == 'darwin': - logging_path = os.getenv("HOME") + '/Library/' + 'Application Support/' + 'FreeDATA/' + 'daemon' - - if sys.platform == 'win32' or sys.platform == 'win64': - logging_path = os.getenv('APPDATA') + '/' + 'FreeDATA/' + 'daemon' - + if sys.platform == "linux": + logging_path = os.getenv("HOME") + "/.config/" + "FreeDATA/" + "daemon" + + if sys.platform == "darwin": + logging_path = ( + os.getenv("HOME") + + "/Library/" + + "Application Support/" + + "FreeDATA/" + + "daemon" + ) + + if sys.platform == "win32" or sys.platform == "win64": + logging_path = os.getenv("APPDATA") + "/" + "FreeDATA/" + "daemon" + if not os.path.exists(logging_path): os.makedirs(logging_path) log_handler.setup_logging(logging_path) except: - structlog.get_logger("structlog").error("[DMN] logger init error") + structlog.get_logger("structlog").error("[DMN] logger init error") try: - structlog.get_logger("structlog").info("[DMN] Starting TCP/IP socket", port=static.DAEMONPORT) + structlog.get_logger("structlog").info( + "[DMN] Starting TCP/IP socket", port=static.DAEMONPORT + ) # https://stackoverflow.com/a/16641793 socketserver.TCPServer.allow_reuse_address = True - cmdserver = sock.ThreadedTCPServer((static.HOST, static.DAEMONPORT), sock.ThreadedTCPRequestHandler) + cmdserver = sock.ThreadedTCPServer( + (static.HOST, static.DAEMONPORT), sock.ThreadedTCPRequestHandler + ) server_thread = threading.Thread(target=cmdserver.serve_forever) server_thread.daemon = True server_thread.start() except Exception as e: - structlog.get_logger("structlog").error("[DMN] Starting TCP/IP socket failed", port=static.DAEMONPORT, e=e) + structlog.get_logger("structlog").error( + "[DMN] Starting TCP/IP socket failed", port=static.DAEMONPORT, e=e + ) os._exit(1) daemon = DAEMON() - - structlog.get_logger("structlog").info("[DMN] Starting FreeDATA Daemon", author="DJ2LS", year="2022", version=static.VERSION) + structlog.get_logger("structlog").info( + "[DMN] Starting FreeDATA Daemon", + author="DJ2LS", + year="2022", + version=static.VERSION, + ) while True: time.sleep(1) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 010446de..262d4950 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -24,16 +24,19 @@ import base64 import numpy as np TESTMODE = False - + DATA_QUEUE_TRANSMIT = queue.Queue() DATA_QUEUE_RECEIVED = queue.Queue() -class DATA(): + +class DATA: """ """ def __init__(self): - - self.mycallsign = static.MYCALLSIGN # initial callsign. Will be overwritten later + + self.mycallsign = ( + static.MYCALLSIGN + ) # initial callsign. Will be overwritten later self.data_queue_transmit = DATA_QUEUE_TRANSMIT self.data_queue_received = DATA_QUEUE_RECEIVED @@ -45,75 +48,111 @@ class DATA(): self.arq_session_timeout = 30 self.session_connect_max_retries = 3 - self.transmission_uuid = '' - - self.received_mycall_crc = b'' # received my callsign crc if we received a crc for another ssid + self.transmission_uuid = "" + self.received_mycall_crc = ( + b"" # received my callsign crc if we received a crc for another ssid + ) - - self.data_channel_last_received = 0.0 # time of last "live sign" of a frame - self.burst_ack_snr = 0 # SNR from received ack frames - self.burst_ack = False # if we received an acknowledge frame for a burst - self.data_frame_ack_received = False # if we received an acknowledge frame for a data frame - self.rpt_request_received = False # if we received an request for repeater frames - self.rpt_request_buffer = [] # requested frames, saved in a list - self.rx_start_of_transmission = 0 # time of transmission start - self.data_frame_bof = b'BOF' # 2 bytes for the BOF End of File indicator in a data frame - self.data_frame_eof = b'EOF' # 2 bytes for the EOF End of File indicator in a data frame + self.data_channel_last_received = 0.0 # time of last "live sign" of a frame + self.burst_ack_snr = 0 # SNR from received ack frames + self.burst_ack = False # if we received an acknowledge frame for a burst + self.data_frame_ack_received = ( + False # if we received an acknowledge frame for a data frame + ) + self.rpt_request_received = ( + False # if we received an request for repeater frames + ) + self.rpt_request_buffer = [] # requested frames, saved in a list + self.rx_start_of_transmission = 0 # time of transmission start + self.data_frame_bof = ( + b"BOF" # 2 bytes for the BOF End of File indicator in a data frame + ) + self.data_frame_eof = ( + b"EOF" # 2 bytes for the EOF End of File indicator in a data frame + ) self.rx_n_max_retries_per_burst = 50 self.n_retries_per_burst = 0 - - self.received_low_bandwith_mode = False # indicator if we recevied a low bandwith mode channel ope ner + + self.received_low_bandwith_mode = ( + False # indicator if we recevied a low bandwith mode channel ope ner + ) self.data_channel_max_retries = 5 - - self.mode_list_low_bw = [14,12] - self.time_list_low_bw = [3,7] - self.mode_list_high_bw = [14,12,10] #201 = FSK mode list of available modes, each mode will be used 2times per speed level - self.time_list_high_bw = [3, 7, 8, 30] # list for time to wait for correspinding mode in seconds + self.mode_list_low_bw = [14, 12] + self.time_list_low_bw = [3, 7] + + self.mode_list_high_bw = [ + 14, + 12, + 10, + ] # 201 = FSK mode list of available modes, each mode will be used 2times per speed level + self.time_list_high_bw = [ + 3, + 7, + 8, + 30, + ] # list for time to wait for correspinding mode in seconds # mode list for selecting between low bandwith ( 500Hz ) and normal modes with higher bandwith if static.LOW_BANDWITH_MODE: - self.mode_list = self.mode_list_low_bw # mode list of available modes, each mode will be used 2times per speed level - self.time_list = self.time_list_low_bw # list for time to wait for correspinding mode in seconds + self.mode_list = ( + self.mode_list_low_bw + ) # mode list of available modes, each mode will be used 2times per speed level + self.time_list = ( + self.time_list_low_bw + ) # list for time to wait for correspinding mode in seconds else: - self.mode_list = self.mode_list_high_bw # mode list of available modes, each mode will be used 2times per speed level - self.time_list = self.time_list_high_bw # list for time to wait for correspinding mode in seconds - - self.speed_level = len(self.mode_list) - 1 # speed level for selecting mode + self.mode_list = ( + self.mode_list_high_bw + ) # mode list of available modes, each mode will be used 2times per speed level + self.time_list = ( + self.time_list_high_bw + ) # list for time to wait for correspinding mode in seconds + + self.speed_level = len(self.mode_list) - 1 # speed level for selecting mode static.ARQ_SPEED_LEVEL = self.speed_level - + self.is_IRS = False self.burst_nack = False self.burst_nack_counter = 0 self.frame_received_counter = 0 - + self.rx_frame_bof_received = False self.rx_frame_eof_received = False - self.transmission_timeout = 360 # transmission timeout in seconds + self.transmission_timeout = 360 # transmission timeout in seconds - worker_thread_transmit = threading.Thread(target=self.worker_transmit, name="worker thread transmit",daemon=True) + worker_thread_transmit = threading.Thread( + target=self.worker_transmit, name="worker thread transmit", daemon=True + ) worker_thread_transmit.start() - - worker_thread_receive = threading.Thread(target=self.worker_receive, name="worker thread receive",daemon=True) + + worker_thread_receive = threading.Thread( + target=self.worker_receive, name="worker thread receive", daemon=True + ) worker_thread_receive.start() - + # START THE THREAD FOR THE TIMEOUT WATCHDOG - watchdog_thread = threading.Thread(target=self.watchdog, name="watchdog",daemon=True) + watchdog_thread = threading.Thread( + target=self.watchdog, name="watchdog", daemon=True + ) watchdog_thread.start() - - arq_session_thread = threading.Thread(target=self.heartbeat, name="watchdog",daemon=True) - arq_session_thread.start() - + + arq_session_thread = threading.Thread( + target=self.heartbeat, name="watchdog", daemon=True + ) + arq_session_thread.start() + self.beacon_interval = 0 - self.beacon_thread = threading.Thread(target=self.run_beacon, name="watchdog",daemon=True) + self.beacon_thread = threading.Thread( + target=self.run_beacon, name="watchdog", daemon=True + ) self.beacon_thread.start() - - + def worker_transmit(self): """ """ while True: @@ -121,31 +160,31 @@ class DATA(): data = self.data_queue_transmit.get() # [0] Command - if data[0] == 'CQ': + if data[0] == "CQ": # [0] CQ self.transmit_cq() - - elif data[0] == 'STOP': + + elif data[0] == "STOP": # [0] STOP self.stop_transmission() - elif data[0] == 'PING': + elif data[0] == "PING": # [0] PING # [1] dxcallsign self.transmit_ping(data[1]) - - elif data[0] == 'BEACON': + + elif data[0] == "BEACON": # [0] BEACON # [1] INTERVAL int # [2] STATE bool - #self.run_beacon(data[1]) + # self.run_beacon(data[1]) if data[2]: self.beacon_interval = data[1] static.BEACON_STATE = True else: static.BEACON_STATE = False - - elif data[0] == 'ARQ_RAW': + + elif data[0] == "ARQ_RAW": # [0] ARQ_RAW # [1] DATA_OUT bytes # [2] MODE int @@ -154,16 +193,15 @@ class DATA(): # [5] mycallsign with ssid self.open_dc_and_transmit(data[1], data[2], data[3], data[4], data[5]) - - elif data[0] == 'CONNECT': + elif data[0] == "CONNECT": # [0] DX CALLSIGN - self.arq_session_handler(data[1]) + self.arq_session_handler(data[1]) - elif data[0] == 'DISCONNECT': + elif data[0] == "DISCONNECT": # [0] DX CALLSIGN self.close_session() - elif data[0] == 'SEND_TEST_FRAME': + elif data[0] == "SEND_TEST_FRAME": # [0] DX CALLSIGN self.send_test_frame() else: @@ -171,7 +209,6 @@ class DATA(): print(f"wrong command {data}") pass - def worker_receive(self): """ """ while True: @@ -179,55 +216,55 @@ class DATA(): # [0] bytes # [1] freedv instance # [2] bytes_per_frame - self.process_data(bytes_out=data[0],freedv=data[1],bytes_per_frame=data[2]) + self.process_data( + bytes_out=data[0], freedv=data[1], bytes_per_frame=data[2] + ) - - def process_data(self, bytes_out, freedv, bytes_per_frame): + def process_data(self, bytes_out, freedv, bytes_per_frame): """ Args: - bytes_out: - freedv: - bytes_per_frame: + bytes_out: + freedv: + bytes_per_frame: Returns: """ # forward data only if broadcast or we are the receiver - # bytes_out[1:3] == callsign check for signalling frames, + # bytes_out[1:3] == callsign check for signalling frames, # bytes_out[2:4] == transmission # we could also create an own function, which returns True. - + frametype = int.from_bytes(bytes(bytes_out[:1]), "big") - - print(f"self.n_retries_per_burst = {self.n_retries_per_burst}") - - #if bytes(bytes_out[1:3]) == self.mycallsign_CRC or bytes(bytes_out[2:4]) == self.mycallsign_CRC or frametype == 200 or frametype == 250: + # if bytes(bytes_out[1:3]) == self.mycallsign_CRC or bytes(bytes_out[2:4]) == self.mycallsign_CRC or frametype == 200 or frametype == 250: _valid1, _ = helpers.check_callsign(self.mycallsign, bytes(bytes_out[1:3])) _valid2, _ = helpers.check_callsign(self.mycallsign, bytes(bytes_out[2:4])) if _valid1 or _valid2 or frametype in [200, 210, 250]: - + # CHECK IF FRAMETYPE IS BETWEEN 10 and 50 ------------------------ frame = frametype - 10 n_frames_per_burst = int.from_bytes(bytes(bytes_out[1:2]), "big") - #frequency_offset = self.get_frequency_offset(freedv) - #print("Freq-Offset: " + str(frequency_offset)) - + # frequency_offset = self.get_frequency_offset(freedv) + # print("Freq-Offset: " + str(frequency_offset)) + if 50 >= frametype >= 10: # get snr of received data - #snr = self.calculate_snr(freedv) + # snr = self.calculate_snr(freedv) # we need to find a wy fixing this because of mooving to class system this isn't working anymore snr = static.SNR structlog.get_logger("structlog").debug("[TNC] 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) + self.arq_data_received( + bytes(bytes_out[:-2]), bytes_per_frame, snr, freedv + ) # if we received the last frame of a burst or the last remaining rpt frame, do a modem unsync - #if static.RX_BURST_BUFFER.count(None) <= 1 or (frame+1) == n_frames_per_burst: + # if static.RX_BURST_BUFFER.count(None) <= 1 or (frame+1) == n_frames_per_burst: # structlog.get_logger("structlog").debug(f"LAST FRAME OF BURST --> UNSYNC {frame+1}/{n_frames_per_burst}") # self.c_lib.freedv_set_sync(freedv, 0) @@ -255,8 +292,7 @@ class DATA(): elif frametype == 64: structlog.get_logger("structlog").debug("BURST NACK RECEIVED....") self.burst_nack_received(bytes_out[:-2]) - - + # CQ FRAME elif frametype == 200: structlog.get_logger("structlog").debug("CQ RECEIVED....") @@ -268,27 +304,24 @@ class DATA(): # = self.get_frequency_offset(freedv) # we need to fix this later frequency_offset = "0" - #print("Freq-Offset: " + str(frequency_offset)) + # print("Freq-Offset: " + str(frequency_offset)) self.received_ping(bytes_out[:-2], frequency_offset) - # PING ACK elif frametype == 211: structlog.get_logger("structlog").debug("PING ACK RECEIVED....") # early detection of frequency offset - #frequency_offset = int.from_bytes(bytes(bytes_out[9:11]), "big", signed=True) - #print("Freq-Offset: " + str(frequency_offset)) - #current_frequency = self.my_rig.get_freq() - #corrected_frequency = current_frequency + frequency_offset + # frequency_offset = int.from_bytes(bytes(bytes_out[9:11]), "big", signed=True) + # print("Freq-Offset: " + str(frequency_offset)) + # current_frequency = self.my_rig.get_freq() + # corrected_frequency = current_frequency + frequency_offset # temporarely disabled this feature, beacuse it may cause some confusion. # we also have problems if we are operating at band bordes like 7.000Mhz # If we get a corrected frequency less 7.000 Mhz, Ham Radio devices will not transmit... - #self.my_rig.set_vfo(Hamlib.RIG_VFO_A) - #self.my_rig.set_freq(Hamlib.RIG_VFO_A, corrected_frequency) + # self.my_rig.set_vfo(Hamlib.RIG_VFO_A) + # self.my_rig.set_freq(Hamlib.RIG_VFO_A, corrected_frequency) self.received_ping_ack(bytes_out[:-2]) - - # SESSION OPENER elif frametype == 221: structlog.get_logger("structlog").debug("OPEN SESSION RECEIVED....") @@ -296,35 +329,42 @@ class DATA(): # SESSION HEARTBEAT elif frametype == 222: - structlog.get_logger("structlog").debug("SESSION HEARTBEAT RECEIVED....") + structlog.get_logger("structlog").debug( + "SESSION HEARTBEAT RECEIVED...." + ) self.received_session_heartbeat(bytes_out[:-2]) # SESSION CLOSE elif frametype == 223: - structlog.get_logger("structlog").debug("CLOSE ARQ SESSION RECEIVED....") + structlog.get_logger("structlog").debug( + "CLOSE ARQ SESSION RECEIVED...." + ) self.received_session_close() # ARQ FILE TRANSFER RECEIVED! elif frametype == 225 or frametype == 227: - structlog.get_logger("structlog").debug("ARQ arq_received_data_channel_opener") + structlog.get_logger("structlog").debug( + "ARQ arq_received_data_channel_opener" + ) self.arq_received_data_channel_opener(bytes_out[:-2]) - + # ARQ CHANNEL IS OPENED elif frametype == 226 or frametype == 228: - structlog.get_logger("structlog").debug("ARQ arq_received_channel_is_open") + structlog.get_logger("structlog").debug( + "ARQ arq_received_channel_is_open" + ) self.arq_received_channel_is_open(bytes_out[:-2]) - - # ARQ MANUAL MODE TRANSMISSION - elif 230 <= frametype <= 240 : + elif 230 <= frametype <= 240: structlog.get_logger("structlog").debug("ARQ manual mode ") self.arq_received_data_channel_opener(bytes_out[:-2]) - # ARQ STOP TRANSMISSION elif frametype == 249: - structlog.get_logger("structlog").debug("ARQ received stop transmission") + structlog.get_logger("structlog").debug( + "ARQ received stop transmission" + ) self.received_stop_transmission() # this is outdated and we may remove it @@ -334,133 +374,164 @@ class DATA(): # TESTFRAMES elif frametype == 255: - structlog.get_logger("structlog").debug("TESTFRAME RECEIVED", frame=bytes_out[:]) - + structlog.get_logger("structlog").debug( + "TESTFRAME RECEIVED", frame=bytes_out[:] + ) + else: - structlog.get_logger("structlog").warning("[TNC] ARQ - other frame type", frametype=frametype) + structlog.get_logger("structlog").warning( + "[TNC] ARQ - other frame type", frametype=frametype + ) else: # for debugging purposes to receive all data - structlog.get_logger("structlog").debug("[TNC] Unknown frame received", frame=bytes_out[:-2]) + structlog.get_logger("structlog").debug( + "[TNC] Unknown frame received", frame=bytes_out[:-2] + ) - - - def arq_data_received(self, data_in:bytes, bytes_per_frame:int, snr:int, freedv): + def arq_data_received(self, data_in: bytes, bytes_per_frame: int, snr: int, freedv): """ Args: - data_in:bytes: - bytes_per_frame:int: - snr:int: - freedv: + data_in:bytes: + bytes_per_frame:int: + snr:int: + freedv: Returns: """ - data_in = bytes(data_in) - + data_in = bytes(data_in) + # get received crc for different mycall ssids - self.received_mycall_crc = data_in[2:4] - + self.received_mycall_crc = data_in[2:4] + global TESTMODE - + # check if callsign ssid override - valid, mycallsign = helpers.check_callsign(self.mycallsign, self.received_mycall_crc) + valid, mycallsign = helpers.check_callsign( + self.mycallsign, self.received_mycall_crc + ) print(mycallsign) if not valid: # ARQ data packet not for me. if not TESTMODE: - self.arq_cleanup() + self.arq_cleanup() return - + # only process data if we are in ARQ and BUSY state else return to quit - if not static.ARQ_STATE and static.TNC_STATE != 'BUSY': + if not static.ARQ_STATE and static.TNC_STATE != "BUSY": return self.arq_file_transfer = True - RX_PAYLOAD_PER_MODEM_FRAME = bytes_per_frame - 2 # payload per moden frame + RX_PAYLOAD_PER_MODEM_FRAME = bytes_per_frame - 2 # payload per moden frame - static.TNC_STATE = 'BUSY' + static.TNC_STATE = "BUSY" static.ARQ_STATE = True static.INFO.append("ARQ;RECEIVING") self.data_channel_last_received = int(time.time()) - + # get some important data from the frame - RX_N_FRAME_OF_BURST = int.from_bytes(bytes(data_in[:1]), "big") - 10 # get number of burst frame - RX_N_FRAMES_PER_BURST = int.from_bytes(bytes(data_in[1:2]), "big") # get number of bursts from received frame + RX_N_FRAME_OF_BURST = ( + int.from_bytes(bytes(data_in[:1]), "big") - 10 + ) # get number of burst frame + RX_N_FRAMES_PER_BURST = int.from_bytes( + bytes(data_in[1:2]), "big" + ) # get number of bursts from received frame - - ''' + """ The RX burst buffer needs to have a fixed length filled with "None". We need this later for counting the "Nones" check if burst buffer has expected length else create it - ''' + """ if len(static.RX_BURST_BUFFER) != RX_N_FRAMES_PER_BURST: - static.RX_BURST_BUFFER = [None] * RX_N_FRAMES_PER_BURST + static.RX_BURST_BUFFER = [None] * RX_N_FRAMES_PER_BURST # append data to rx burst buffer - static.RX_BURST_BUFFER[RX_N_FRAME_OF_BURST] = data_in[6:] # [frame_type][n_frames_per_burst][CRC16][CRC16] - - structlog.get_logger("structlog").debug("[TNC] static.RX_BURST_BUFFER", buffer=static.RX_BURST_BUFFER) - - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - - ''' + static.RX_BURST_BUFFER[RX_N_FRAME_OF_BURST] = data_in[ + 6: + ] # [frame_type][n_frames_per_burst][CRC16][CRC16] + + structlog.get_logger("structlog").debug( + "[TNC] static.RX_BURST_BUFFER", buffer=static.RX_BURST_BUFFER + ) + + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + + """ check if we received all frames per burst by checking if burst buffer has no more "Nones" this is the ideal case because we received all data - ''' + """ if not None in static.RX_BURST_BUFFER: # then iterate through burst buffer and stick the burst together # the temp burst buffer is needed for checking, if we already recevied data - temp_burst_buffer = b'' - for i in range(0,len(static.RX_BURST_BUFFER)): - #static.RX_FRAME_BUFFER += static.RX_BURST_BUFFER[i] + temp_burst_buffer = b"" + for i in range(0, len(static.RX_BURST_BUFFER)): + # static.RX_FRAME_BUFFER += static.RX_BURST_BUFFER[i] temp_burst_buffer += static.RX_BURST_BUFFER[i] # 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 didnt receive its destination (ISS) if static.RX_FRAME_BUFFER.endswith(temp_burst_buffer): - structlog.get_logger("structlog").info("[TNC] ARQ | RX | Frame already received - sending ACK again") + structlog.get_logger("structlog").info( + "[TNC] ARQ | RX | Frame already received - sending ACK again" + ) static.RX_BURST_BUFFER = [] - + # here we are going to search for our data in the last received bytes # this increases chance we are not loosing the entire frame in case of signalling frame loss else: - # static.RX_FRAME_BUFFER --> exisitng data # temp_burst_buffer --> new data # search_area --> area where we want to search search_area = 510 - - search_position = len(static.RX_FRAME_BUFFER)-search_area + search_position = len(static.RX_FRAME_BUFFER) - search_area # find position of data. returns -1 if nothing found in area else >= 0 # we are beginning from the end, so if data exists twice or more, only the last one should be replaced - get_position = static.RX_FRAME_BUFFER[search_position:].rfind(temp_burst_buffer) + get_position = static.RX_FRAME_BUFFER[search_position:].rfind( + temp_burst_buffer + ) # if we find data, replace it at this position with the new data and strip it if get_position >= 0: - static.RX_FRAME_BUFFER = static.RX_FRAME_BUFFER[:search_position + get_position] + static.RX_FRAME_BUFFER = static.RX_FRAME_BUFFER[ + : search_position + get_position + ] static.RX_FRAME_BUFFER += temp_burst_buffer - structlog.get_logger("structlog").warning("[TNC] ARQ | RX | replacing existing buffer data", area=search_area, pos=get_position) + structlog.get_logger("structlog").warning( + "[TNC] ARQ | RX | replacing existing buffer data", + area=search_area, + pos=get_position, + ) # if we dont find data n this range, we really have new data and going to replace it else: static.RX_FRAME_BUFFER += temp_burst_buffer - structlog.get_logger("structlog").debug("[TNC] ARQ | RX | appending data to buffer") - - - + structlog.get_logger("structlog").debug( + "[TNC] ARQ | RX | appending data to buffer" + ) # lets check if we didnt receive a BOF and EOF yet to avoid sending ack frames if we already received all data - if not self.rx_frame_bof_received and not self.rx_frame_eof_received and data_in.find(self.data_frame_eof) < 0: - - self.frame_received_counter += 1 + if ( + not self.rx_frame_bof_received + and not self.rx_frame_eof_received + and data_in.find(self.data_frame_eof) < 0 + ): + + self.frame_received_counter += 1 if self.frame_received_counter >= 2: self.frame_received_counter = 0 self.speed_level += 1 if self.speed_level >= len(self.mode_list): self.speed_level = len(self.mode_list) - 1 - static.ARQ_SPEED_LEVEL = self.speed_level + static.ARQ_SPEED_LEVEL = self.speed_level # updated modes we are listening to self.set_listening_modes(self.mode_list[self.speed_level]) @@ -476,84 +547,109 @@ class DATA(): txbuffer = [ack_frame] structlog.get_logger("structlog").info("[TNC] ARQ | RX | SENDING ACK") static.TRANSMITTING = True - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) # reset n retries per burst counter self.n_retries_per_burst = 0 - - # calculate statistics - self.calculate_transfer_rate_rx(self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)) - + # calculate statistics + self.calculate_transfer_rate_rx( + self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER) + ) + # check if we received last frame of burst and we have "Nones" in our rx buffer # this is an indicator for missed frames. - # with this way of doing this, we always MUST receive the last frame of a burst otherwise the entire + # with this way of doing this, we always MUST receive the last frame of a burst otherwise the entire # burst is lost - elif RX_N_FRAME_OF_BURST == RX_N_FRAMES_PER_BURST -1: + elif RX_N_FRAME_OF_BURST == RX_N_FRAMES_PER_BURST - 1: # check where a None is in our burst buffer and do frame+1, beacuse lists start at 0 - missing_frames = [(frame+1) for frame, element in enumerate(static.RX_BURST_BUFFER) if element == None] - - structlog.get_logger("structlog").debug("all frames per burst received", frame=RX_N_FRAME_OF_BURST, frames=RX_N_FRAMES_PER_BURST) - + missing_frames = [ + (frame + 1) + for frame, element in enumerate(static.RX_BURST_BUFFER) + if element == None + ] + + structlog.get_logger("structlog").debug( + "all frames per burst received", + frame=RX_N_FRAME_OF_BURST, + frames=RX_N_FRAMES_PER_BURST, + ) + # set n frames per burst to modem # this is an idea so its not getting lost.... - # we need to work on this - codec2.api.freedv_set_frames_per_burst(freedv,len(missing_frames)) - - - # then create a repeat frame - rpt_frame = bytearray(14) - rpt_frame[:1] = bytes([62]) + # we need to work on this + codec2.api.freedv_set_frames_per_burst(freedv, len(missing_frames)) + + # then create a repeat frame + rpt_frame = bytearray(14) + rpt_frame[:1] = bytes([62]) rpt_frame[1:3] = static.DXCALLSIGN_CRC rpt_frame[3:5] = static.MYCALLSIGN_CRC - rpt_frame[5:11] = missing_frames + rpt_frame[5:11] = missing_frames # and transmit it txbuffer = [rpt_frame] - structlog.get_logger("structlog").info("[TNC] ARQ | RX | Requesting", frames=missing_frames) + structlog.get_logger("structlog").info( + "[TNC] ARQ | RX | Requesting", frames=missing_frames + ) static.TRANSMITTING = True - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) - self.calculate_transfer_rate_rx(self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)) - - + self.calculate_transfer_rate_rx( + self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER) + ) + # we should never reach this point else: - structlog.get_logger("structlog").error("we shouldnt reach this point...", frame=RX_N_FRAME_OF_BURST, frames=RX_N_FRAMES_PER_BURST) + structlog.get_logger("structlog").error( + "we shouldnt reach this point...", + frame=RX_N_FRAME_OF_BURST, + frames=RX_N_FRAMES_PER_BURST, + ) - # We have a BOF and EOF flag in our data. If we received both we received our frame. - # In case of loosing data but we received already a BOF and EOF we need to make sure, we - # received the complete last burst by checking it for Nones + # In case of loosing data but we received already a BOF and EOF we need to make sure, we + # received the complete last burst by checking it for Nones bof_position = static.RX_FRAME_BUFFER.find(self.data_frame_bof) eof_position = static.RX_FRAME_BUFFER.find(self.data_frame_eof) # get total bytes per transmission information as soon we recevied a frame with a BOF - if bof_position >=0: - - payload = static.RX_FRAME_BUFFER[bof_position+len(self.data_frame_bof):eof_position] - frame_length = int.from_bytes(payload[4:8], "big") #4:8 4bytes - static.TOTAL_BYTES = frame_length - compression_factor = int.from_bytes(payload[8:9], "big") #4:8 4bytes - compression_factor = np.clip(compression_factor, 0, 255) #limit to max value of 255 - static.ARQ_COMPRESSION_FACTOR = compression_factor / 10 - self.calculate_transfer_rate_rx(self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)) - + if bof_position >= 0: - if bof_position >= 0 and eof_position > 0 and not None in static.RX_BURST_BUFFER: + payload = static.RX_FRAME_BUFFER[ + bof_position + len(self.data_frame_bof) : eof_position + ] + frame_length = int.from_bytes(payload[4:8], "big") # 4:8 4bytes + static.TOTAL_BYTES = frame_length + compression_factor = int.from_bytes(payload[8:9], "big") # 4:8 4bytes + compression_factor = np.clip( + compression_factor, 0, 255 + ) # limit to max value of 255 + static.ARQ_COMPRESSION_FACTOR = compression_factor / 10 + self.calculate_transfer_rate_rx( + self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER) + ) + + if ( + bof_position >= 0 + and eof_position > 0 + and not None in static.RX_BURST_BUFFER + ): print(f"bof_position {bof_position} / eof_position {eof_position}") self.rx_frame_bof_received = True self.rx_frame_eof_received = True - - #now extract raw data from buffer - payload = static.RX_FRAME_BUFFER[bof_position+len(self.data_frame_bof):eof_position] + + # now extract raw data from buffer + payload = static.RX_FRAME_BUFFER[ + bof_position + len(self.data_frame_bof) : eof_position + ] # get the data frame crc - data_frame_crc = payload[:4] #0:4 4bytes - frame_length = int.from_bytes(payload[4:8], "big") #4:8 4bytes + data_frame_crc = payload[:4] # 0:4 4bytes + frame_length = int.from_bytes(payload[4:8], "big") # 4:8 4bytes static.TOTAL_BYTES = frame_length # 8:9 = compression factor @@ -562,139 +658,177 @@ class DATA(): data_frame_crc_received = helpers.get_crc_32(data_frame) # check if data_frame_crc is equal with received crc if data_frame_crc == data_frame_crc_received: - structlog.get_logger("structlog").info("[TNC] ARQ | RX | DATA FRAME SUCESSFULLY RECEIVED") - - + structlog.get_logger("structlog").info( + "[TNC] ARQ | RX | DATA FRAME SUCESSFULLY RECEIVED" + ) + # decompression data_frame_decompressed = zlib.decompress(data_frame) - static.ARQ_COMPRESSION_FACTOR = len(data_frame_decompressed) / len(data_frame) + static.ARQ_COMPRESSION_FACTOR = len(data_frame_decompressed) / len( + data_frame + ) data_frame = data_frame_decompressed - - + uniqueid = str(uuid.uuid4()) timestamp = int(time.time()) - - + # check if callsign ssid override - valid, mycallsign = helpers.check_callsign(self.mycallsign, self.received_mycall_crc) + valid, mycallsign = helpers.check_callsign( + self.mycallsign, self.received_mycall_crc + ) if not valid: # ARQ data packet not for me. if not TESTMODE: - self.arq_cleanup() + self.arq_cleanup() return - + base64_data = base64.b64encode(data_frame) base64_data = base64_data.decode("utf-8") - static.RX_BUFFER.append([uniqueid, timestamp, static.DXCALLSIGN, static.DXGRID, base64_data]) - jsondata = {"arq":"received", "uuid" : uniqueid, "timestamp": timestamp, "mycallsign" : str(mycallsign, 'utf-8'), "dxcallsign": str(static.DXCALLSIGN, 'utf-8'), "dxgrid": str(static.DXGRID, 'utf-8'), "data": base64_data} + static.RX_BUFFER.append( + [uniqueid, timestamp, static.DXCALLSIGN, static.DXGRID, base64_data] + ) + jsondata = { + "arq": "received", + "uuid": uniqueid, + "timestamp": timestamp, + "mycallsign": str(mycallsign, "utf-8"), + "dxcallsign": str(static.DXCALLSIGN, "utf-8"), + "dxgrid": str(static.DXGRID, "utf-8"), + "data": base64_data, + } json_data_out = json.dumps(jsondata) print(jsondata) sock.SOCKET_QUEUE.put(json_data_out) static.INFO.append("ARQ;RECEIVING;SUCCESS") - + # BUILDING ACK FRAME FOR DATA FRAME - ack_frame = bytearray(14) - ack_frame[:1] = bytes([61]) + ack_frame = bytearray(14) + ack_frame[:1] = bytes([61]) ack_frame[1:3] = static.DXCALLSIGN_CRC ack_frame[3:5] = static.MYCALLSIGN_CRC ack_frame[5:6] = bytes([int(snr)]) ack_frame[6:7] = bytes([int(self.speed_level)]) # TRANSMIT ACK FRAME FOR BURST - structlog.get_logger("structlog").info("[TNC] ARQ | RX | SENDING DATA FRAME ACK", snr=static.SNR, crc=data_frame_crc.hex()) + structlog.get_logger("structlog").info( + "[TNC] ARQ | RX | SENDING DATA FRAME ACK", + snr=static.SNR, + crc=data_frame_crc.hex(), + ) txbuffer = [ack_frame] static.TRANSMITTING = True - modem.MODEM_TRANSMIT_QUEUE.put([14,3,100,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 3, 100, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) # update our statistics AFTER the frame ACK - self.calculate_transfer_rate_rx(self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER)) - - structlog.get_logger("structlog").info("[TNC] | RX | DATACHANNEL [" + str(self.mycallsign, 'utf-8') + "]<< >>[" + str(static.DXCALLSIGN, 'utf-8') + "]", snr=static.SNR) + self.calculate_transfer_rate_rx( + self.rx_start_of_transmission, len(static.RX_FRAME_BUFFER) + ) + + structlog.get_logger("structlog").info( + "[TNC] | RX | DATACHANNEL [" + + str(self.mycallsign, "utf-8") + + "]<< >>[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + snr=static.SNR, + ) else: static.INFO.append("ARQ;RECEIVING;FAILED") - structlog.get_logger("structlog").warning("[TNC] ARQ | RX | DATA FRAME NOT SUCESSFULLY RECEIVED!", e="wrong crc", expected=data_frame_crc, received=data_frame_crc_received, overflows=static.BUFFER_OVERFLOW_COUNTER) + structlog.get_logger("structlog").warning( + "[TNC] ARQ | RX | DATA FRAME NOT SUCESSFULLY RECEIVED!", + e="wrong crc", + expected=data_frame_crc, + received=data_frame_crc_received, + overflows=static.BUFFER_OVERFLOW_COUNTER, + ) # BUILDING NACK FRAME FOR DATA FRAME - nack_frame = bytearray(14) - nack_frame[:1] = bytes([63]) + nack_frame = bytearray(14) + nack_frame[:1] = bytes([63]) nack_frame[1:3] = static.DXCALLSIGN_CRC - nack_frame[3:5] = static.MYCALLSIGN_CRC + nack_frame[3:5] = static.MYCALLSIGN_CRC nack_frame[5:6] = bytes([int(snr)]) nack_frame[6:7] = bytes([int(self.speed_level)]) - + # TRANSMIT NACK FRAME FOR BURST txbuffer = [nack_frame] static.TRANSMITTING = True - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) - # update session timeout - self.arq_session_last_received = int(time.time()) # we need to update our timeout timestamp - + self.arq_session_last_received = int( + time.time() + ) # we need to update our timeout timestamp + # And finally we do a cleanup of our buffers and states # do cleanup only when not in testmode if not TESTMODE: - self.arq_cleanup() - + self.arq_cleanup() - - def arq_transmit(self, data_out:bytes, mode:int, n_frames_per_burst:int): + def arq_transmit(self, data_out: bytes, mode: int, n_frames_per_burst: int): """ Args: - data_out:bytes: - mode:int: - n_frames_per_burst:int: + data_out:bytes: + mode:int: + n_frames_per_burst:int: Returns: """ global TESTMODE - + self.arq_file_transfer = True - - self.speed_level = len(self.mode_list) - 1 # speed level for selecting mode + + self.speed_level = len(self.mode_list) - 1 # speed level for selecting mode static.ARQ_SPEED_LEVEL = self.speed_level - TX_N_SENT_BYTES = 0 # already sent bytes per data frame - self.tx_n_retry_of_burst = 0 # retries we already sent data - TX_N_MAX_RETRIES_PER_BURST = 50 # max amount of retries we sent before frame is lost - TX_N_FRAMES_PER_BURST = n_frames_per_burst # amount of n frames per burst + TX_N_SENT_BYTES = 0 # already sent bytes per data frame + self.tx_n_retry_of_burst = 0 # retries we already sent data + TX_N_MAX_RETRIES_PER_BURST = ( + 50 # max amount of retries we sent before frame is lost + ) + TX_N_FRAMES_PER_BURST = n_frames_per_burst # amount of n frames per burst TX_BUFFER = [] # our buffer for appending new data - - # TIMEOUTS - BURST_ACK_TIMEOUT_SECONDS = 3.0 # timeout for burst acknowledges - DATA_FRAME_ACK_TIMEOUT_SECONDS = 3.0 # timeout for data frame acknowledges - RPT_ACK_TIMEOUT_SECONDS = 3.0 # timeout for rpt frame acknowledges + # TIMEOUTS + BURST_ACK_TIMEOUT_SECONDS = 3.0 # timeout for burst acknowledges + DATA_FRAME_ACK_TIMEOUT_SECONDS = 3.0 # timeout for data frame acknowledges + RPT_ACK_TIMEOUT_SECONDS = 3.0 # timeout for rpt frame acknowledges # save len of data_out to TOTAL_BYTES for our statistics --> kBytes - #static.TOTAL_BYTES = round(len(data_out) / 1024, 2) + # static.TOTAL_BYTES = round(len(data_out) / 1024, 2) static.TOTAL_BYTES = len(data_out) - frame_total_size = len(data_out).to_bytes(4, byteorder='big') + frame_total_size = len(data_out).to_bytes(4, byteorder="big") static.INFO.append("ARQ;TRANSMITTING") - - jsondata = {"arq":"transmission", "status" :"transmitting", "uuid" : self.transmission_uuid, "percent" : static.ARQ_TRANSMISSION_PERCENT, "bytesperminute" : static.ARQ_BYTES_PER_MINUTE} + + jsondata = { + "arq": "transmission", + "status": "transmitting", + "uuid": self.transmission_uuid, + "percent": static.ARQ_TRANSMISSION_PERCENT, + "bytesperminute": static.ARQ_BYTES_PER_MINUTE, + } json_data_out = json.dumps(jsondata) sock.SOCKET_QUEUE.put(json_data_out) - - - structlog.get_logger("structlog").info("[TNC] | TX | DATACHANNEL", mode=mode, Bytes=static.TOTAL_BYTES) - + structlog.get_logger("structlog").info( + "[TNC] | TX | DATACHANNEL", mode=mode, Bytes=static.TOTAL_BYTES + ) + # compression data_frame_compressed = zlib.compress(data_out) compression_factor = len(data_out) / len(data_frame_compressed) static.ARQ_COMPRESSION_FACTOR = np.clip(compression_factor, 0, 255) compression_factor = bytes([int(static.ARQ_COMPRESSION_FACTOR * 10)]) - - data_out = data_frame_compressed + + data_out = data_frame_compressed # reset statistics tx_start_of_transmission = time.time() @@ -703,25 +837,37 @@ class DATA(): # append a crc and beginn and end of file indicators frame_payload_crc = helpers.get_crc_32(data_out) # data_out = self.data_frame_bof + frame_payload_crc + data_out + self.data_frame_eof - data_out = self.data_frame_bof + frame_payload_crc + frame_total_size + compression_factor + data_out + self.data_frame_eof - - #initial bufferposition is 0 + data_out = ( + self.data_frame_bof + + frame_payload_crc + + frame_total_size + + compression_factor + + data_out + + self.data_frame_eof + ) + + # initial bufferposition is 0 bufferposition = 0 # iterate through data out buffer - while bufferposition < len(data_out) and not self.data_frame_ack_received and static.ARQ_STATE: + while ( + bufferposition < len(data_out) + and not self.data_frame_ack_received + and static.ARQ_STATE + ): - # we have TX_N_MAX_RETRIES_PER_BURST attempts for sending a burst - for self.tx_n_retry_of_burst in range(0,TX_N_MAX_RETRIES_PER_BURST): + for self.tx_n_retry_of_burst in range(0, TX_N_MAX_RETRIES_PER_BURST): # AUTO MODE SELECTION # mode 255 == AUTO MODE # force usage of selected mode if mode != 255: data_mode = mode - - structlog.get_logger("structlog").debug("FIXED MODE", mode=data_mode) + + structlog.get_logger("structlog").debug( + "FIXED MODE", mode=data_mode + ) else: # we are doing a modulo check of transmission retries of the actual burst @@ -729,151 +875,198 @@ class DATA(): # as soon as we received an ACK for the current burst, speed_level will increase # by 1. # the can be optimised by checking the optimal speed level for the current conditions - ''' + """ if not self.tx_n_retry_of_burst % 2 and self.tx_n_retry_of_burst > 0: self.speed_level -= 1 if self.speed_level < 0: self.speed_level = 0 - ''' - - #if self.tx_n_retry_of_burst <= 1: + """ + + # if self.tx_n_retry_of_burst <= 1: # self.speed_level += 1 # if self.speed_level >= len(self.mode_list)-1: # self.speed_level = len(self.mode_list)-1 - + # if speed level is greater than our available modes, set speed level to maximum = lenght of mode list -1 - if self.speed_level >= len(self.mode_list): self.speed_level = len(self.mode_list) - 1 static.ARQ_SPEED_LEVEL = self.speed_level data_mode = self.mode_list[self.speed_level] - - structlog.get_logger("structlog").debug("Speed-level:", level=self.speed_level, retry=self.tx_n_retry_of_burst, mode=data_mode) - - + + structlog.get_logger("structlog").debug( + "Speed-level:", + level=self.speed_level, + retry=self.tx_n_retry_of_burst, + mode=data_mode, + ) # payload information - payload_per_frame = modem.get_bytes_per_frame(data_mode) -2 + payload_per_frame = modem.get_bytes_per_frame(data_mode) - 2 # tempbuffer list for storing our data frames tempbuffer = [] - + # append data frames with TX_N_FRAMES_PER_BURST to tempbuffer # this part ineeds to a completly rewrite! # TX_NF_RAMES_PER_BURST = 1 is working arqheader = bytearray() - arqheader[:1] = bytes([10]) #bytes([10 + i]) - arqheader[1:2] = bytes([TX_N_FRAMES_PER_BURST]) + arqheader[:1] = bytes([10]) # bytes([10 + i]) + arqheader[1:2] = bytes([TX_N_FRAMES_PER_BURST]) arqheader[2:4] = static.DXCALLSIGN_CRC arqheader[4:6] = static.MYCALLSIGN_CRC - - bufferposition_end = (bufferposition + payload_per_frame - len(arqheader)) + + bufferposition_end = bufferposition + payload_per_frame - len(arqheader) # normal behavior if bufferposition_end <= len(data_out): - - frame = data_out[bufferposition:bufferposition_end] - frame = arqheader + frame - - # this point shouldnt reached that often + + frame = data_out[bufferposition:bufferposition_end] + frame = arqheader + frame + + # this point shouldnt reached that often elif bufferposition > len(data_out): break - - # the last bytes of a frame + + # the last bytes of a frame else: extended_data_out = data_out[bufferposition:] - extended_data_out += bytes([0]) * (payload_per_frame-len(extended_data_out)-len(arqheader)) + extended_data_out += bytes([0]) * ( + payload_per_frame - len(extended_data_out) - len(arqheader) + ) frame = arqheader + extended_data_out - - + # append frame to tempbuffer for transmission tempbuffer.append(frame) - - structlog.get_logger("structlog").debug("[TNC] tempbuffer", tempbuffer=tempbuffer) - structlog.get_logger("structlog").info("[TNC] ARQ | TX | FRAMES", mode=data_mode, fpb=TX_N_FRAMES_PER_BURST, retry=self.tx_n_retry_of_burst) - + + structlog.get_logger("structlog").debug( + "[TNC] tempbuffer", tempbuffer=tempbuffer + ) + structlog.get_logger("structlog").info( + "[TNC] ARQ | TX | FRAMES", + mode=data_mode, + fpb=TX_N_FRAMES_PER_BURST, + retry=self.tx_n_retry_of_burst, + ) + # we need to set our TRANSMITTING flag before we are adding an object the transmit queue # this is not that nice, we could improve this somehow static.TRANSMITTING = True - modem.MODEM_TRANSMIT_QUEUE.put([data_mode,1,0,tempbuffer]) - + modem.MODEM_TRANSMIT_QUEUE.put([data_mode, 1, 0, tempbuffer]) + # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) - + # after transmission finished wait for an ACK or RPT frame - ''' + """ burstacktimeout = time.time() + BURST_ACK_TIMEOUT_SECONDS + 100 while not self.burst_ack and not self.burst_nack and not self.rpt_request_received and not self.data_frame_ack_received and time.time() < burstacktimeout and static.ARQ_STATE: time.sleep(0.01) - ''' - #burstacktimeout = time.time() + BURST_ACK_TIMEOUT_SECONDS + 100 - while not self.burst_ack and not self.burst_nack and not self.rpt_request_received and not self.data_frame_ack_received and static.ARQ_STATE: + """ + # burstacktimeout = time.time() + BURST_ACK_TIMEOUT_SECONDS + 100 + while ( + not self.burst_ack + and not self.burst_nack + and not self.rpt_request_received + and not self.data_frame_ack_received + and static.ARQ_STATE + ): time.sleep(0.01) - + # once we received a burst ack, reset its state and break the RETRIES loop if self.burst_ack: - self.burst_ack = False # reset ack state - self.tx_n_retry_of_burst = 0 # reset retries - break #break retry loop + self.burst_ack = False # reset ack state + self.tx_n_retry_of_burst = 0 # reset retries + break # break retry loop if self.burst_nack: - self.burst_nack = False #reset nack state + self.burst_nack = False # reset nack state # not yet implemented if self.rpt_request_received: pass if self.data_frame_ack_received: - break #break retry loop - - + break # break retry loop + # we need this part for leaving the repeat loop # static.ARQ_STATE == 'DATA' --> when stopping transmission manually if not static.ARQ_STATE: - #print("not ready for data...leaving loop....") + # print("not ready for data...leaving loop....") break - - self.calculate_transfer_rate_tx(tx_start_of_transmission, bufferposition_end, len(data_out)) + + self.calculate_transfer_rate_tx( + tx_start_of_transmission, bufferposition_end, len(data_out) + ) # NEXT ATTEMPT - structlog.get_logger("structlog").debug("ATTEMPT", retry=self.tx_n_retry_of_burst, maxretries=TX_N_MAX_RETRIES_PER_BURST,overflows=static.BUFFER_OVERFLOW_COUNTER) - + structlog.get_logger("structlog").debug( + "ATTEMPT", + retry=self.tx_n_retry_of_burst, + maxretries=TX_N_MAX_RETRIES_PER_BURST, + overflows=static.BUFFER_OVERFLOW_COUNTER, + ) + # update buffer position bufferposition = bufferposition_end # update stats - self.calculate_transfer_rate_tx(tx_start_of_transmission, bufferposition_end, len(data_out)) - - jsondata = {"arq":"transmission", "status" :"transmitting", "uuid" : self.transmission_uuid, "percent" : static.ARQ_TRANSMISSION_PERCENT, "bytesperminute" : static.ARQ_BYTES_PER_MINUTE} + self.calculate_transfer_rate_tx( + tx_start_of_transmission, bufferposition_end, len(data_out) + ) + + jsondata = { + "arq": "transmission", + "status": "transmitting", + "uuid": self.transmission_uuid, + "percent": static.ARQ_TRANSMISSION_PERCENT, + "bytesperminute": static.ARQ_BYTES_PER_MINUTE, + } json_data_out = json.dumps(jsondata) sock.SOCKET_QUEUE.put(json_data_out) - - #GOING TO NEXT ITERATION - + + # GOING TO NEXT ITERATION if self.data_frame_ack_received: - + static.INFO.append("ARQ;TRANSMITTING;SUCCESS") - jsondata = {"arq":"transmission", "status" :"success", "uuid" : self.transmission_uuid, "percent" : static.ARQ_TRANSMISSION_PERCENT, "bytesperminute" : static.ARQ_BYTES_PER_MINUTE} + jsondata = { + "arq": "transmission", + "status": "success", + "uuid": self.transmission_uuid, + "percent": static.ARQ_TRANSMISSION_PERCENT, + "bytesperminute": static.ARQ_BYTES_PER_MINUTE, + } json_data_out = json.dumps(jsondata) sock.SOCKET_QUEUE.put(json_data_out) - - structlog.get_logger("structlog").info("ARQ | TX | DATA TRANSMITTED!", BytesPerMinute=static.ARQ_BYTES_PER_MINUTE, BitsPerSecond=static.ARQ_BITS_PER_SECOND, overflows=static.BUFFER_OVERFLOW_COUNTER) + structlog.get_logger("structlog").info( + "ARQ | TX | DATA TRANSMITTED!", + BytesPerMinute=static.ARQ_BYTES_PER_MINUTE, + BitsPerSecond=static.ARQ_BITS_PER_SECOND, + overflows=static.BUFFER_OVERFLOW_COUNTER, + ) - else: static.INFO.append("ARQ;TRANSMITTING;FAILED") - jsondata = {"arq":"transmission", "status" :"failed", "uuid" : self.transmission_uuid, "percent" : static.ARQ_TRANSMISSION_PERCENT, "bytesperminute" : static.ARQ_BYTES_PER_MINUTE} + jsondata = { + "arq": "transmission", + "status": "failed", + "uuid": self.transmission_uuid, + "percent": static.ARQ_TRANSMISSION_PERCENT, + "bytesperminute": static.ARQ_BYTES_PER_MINUTE, + } json_data_out = json.dumps(jsondata) sock.SOCKET_QUEUE.put(json_data_out) - - structlog.get_logger("structlog").info("ARQ | TX | TRANSMISSION FAILED OR TIME OUT!", overflows=static.BUFFER_OVERFLOW_COUNTER) + + structlog.get_logger("structlog").info( + "ARQ | TX | TRANSMISSION FAILED OR TIME OUT!", + overflows=static.BUFFER_OVERFLOW_COUNTER, + ) self.stop_transmission() - # and last but not least doing a state cleanup + # and last but not least doing a state cleanup # do cleanup only when not in testmode if not TESTMODE: self.arq_cleanup() @@ -881,124 +1074,178 @@ class DATA(): # quit after transmission if TESTMODE: import os + os._exit(0) - - # signalling frames received - def burst_ack_received(self, data_in:bytes): + def burst_ack_received(self, data_in: bytes): """ Args: - data_in:bytes: + data_in:bytes: Returns: """ - + # increase speed level if we received a burst ack - #self.speed_level += 1 - #if self.speed_level >= len(self.mode_list)-1: + # self.speed_level += 1 + # if self.speed_level >= len(self.mode_list)-1: # self.speed_level = len(self.mode_list)-1 - + # only process data if we are in ARQ and BUSY state if static.ARQ_STATE: - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - self.burst_ack = True # Force data loops of TNC to stop and continue with next frame - self.data_channel_last_received = int(time.time()) # we need to update our timeout timestamp - self.burst_ack_snr= int.from_bytes(bytes(data_in[5:6]), "big") - self.speed_level= int.from_bytes(bytes(data_in[6:7]), "big") + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + self.burst_ack = ( + True # Force data loops of TNC to stop and continue with next frame + ) + self.data_channel_last_received = int( + time.time() + ) # we need to update our timeout timestamp + self.burst_ack_snr = int.from_bytes(bytes(data_in[5:6]), "big") + self.speed_level = int.from_bytes(bytes(data_in[6:7]), "big") static.ARQ_SPEED_LEVEL = self.speed_level print(self.speed_level) - # reset burst nack counter + # reset burst nack counter self.burst_nack_counter = 0 # reset n retries per burst counter self.n_retries_per_burst = 0 + # signalling frames received - def burst_nack_received(self, data_in:bytes): + def burst_nack_received(self, data_in: bytes): """ Args: - data_in:bytes: + data_in:bytes: Returns: """ - + # increase speed level if we received a burst ack - #self.speed_level += 1 - #if self.speed_level >= len(self.mode_list)-1: + # self.speed_level += 1 + # if self.speed_level >= len(self.mode_list)-1: # self.speed_level = len(self.mode_list)-1 - + # only process data if we are in ARQ and BUSY state if static.ARQ_STATE: - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - self.burst_nack = True # Force data loops of TNC to stop and continue with next frame - self.data_channel_last_received = int(time.time()) # we need to update our timeout timestamp - self.burst_ack_snr= int.from_bytes(bytes(data_in[5:6]), "big") - self.speed_level= int.from_bytes(bytes(data_in[6:7]), "big") + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + self.burst_nack = ( + True # Force data loops of TNC to stop and continue with next frame + ) + self.data_channel_last_received = int( + time.time() + ) # we need to update our timeout timestamp + self.burst_ack_snr = int.from_bytes(bytes(data_in[5:6]), "big") + self.speed_level = int.from_bytes(bytes(data_in[6:7]), "big") static.ARQ_SPEED_LEVEL = self.speed_level self.burst_nack_counter += 1 print(self.speed_level) - def frame_ack_received(self): """ """ # only process data if we are in ARQ and BUSY state - if static.ARQ_STATE: - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - self.data_frame_ack_received = True # Force data loops of TNC to stop and continue with next frame - self.data_channel_last_received = int(time.time()) # we need to update our timeout timestamp - self.arq_session_last_received = int(time.time()) # we need to update our timeout timestamp + if static.ARQ_STATE: + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + self.data_frame_ack_received = ( + True # Force data loops of TNC to stop and continue with next frame + ) + self.data_channel_last_received = int( + time.time() + ) # we need to update our timeout timestamp + self.arq_session_last_received = int( + time.time() + ) # we need to update our timeout timestamp - def frame_nack_received(self, data_in:bytes): + def frame_nack_received(self, data_in: bytes): """ Args: - data_in:bytes: + data_in:bytes: Returns: """ - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) static.INFO.append("ARQ;TRANSMITTING;FAILED") - jsondata = {"arq":"transmission", "status" : "failed", "uuid" : self.transmission_uuid, "percent" : static.ARQ_TRANSMISSION_PERCENT, "bytesperminute" : static.ARQ_BYTES_PER_MINUTE} + jsondata = { + "arq": "transmission", + "status": "failed", + "uuid": self.transmission_uuid, + "percent": static.ARQ_TRANSMISSION_PERCENT, + "bytesperminute": static.ARQ_BYTES_PER_MINUTE, + } json_data_out = json.dumps(jsondata) - sock.SOCKET_QUEUE.put(json_data_out) - self.arq_session_last_received = int(time.time()) # we need to update our timeout timestamp - + sock.SOCKET_QUEUE.put(json_data_out) + self.arq_session_last_received = int( + time.time() + ) # we need to update our timeout timestamp + if not TESTMODE: self.arq_cleanup() - - - def burst_rpt_received(self, data_in:bytes): + def burst_rpt_received(self, data_in: bytes): """ Args: - data_in:bytes: + data_in:bytes: Returns: """ # only process data if we are in ARQ and BUSY state - if static.ARQ_STATE and static.TNC_STATE == 'BUSY': - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - + if static.ARQ_STATE and static.TNC_STATE == "BUSY": + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + self.rpt_request_received = True - self.data_channel_last_received = int(time.time()) # we need to update our timeout timestamp + self.data_channel_last_received = int( + time.time() + ) # we need to update our timeout timestamp self.rpt_request_buffer = [] missing_area = bytes(data_in[3:12]) # 1:9 for i in range(0, 6, 2): - if not missing_area[i:i + 2].endswith(b'\x00\x00'): - missing = missing_area[i:i + 2] + if not missing_area[i : i + 2].endswith(b"\x00\x00"): + missing = missing_area[i : i + 2] self.rpt_request_buffer.insert(0, missing) - - # ############################################################################################################ # ARQ SESSION HANDLER # ############################################################################################################ @@ -1007,251 +1254,317 @@ class DATA(): """ Args: - callsign: + callsign: Returns: """ # das hier müssen wir checken. Sollte vielleicht in INIT!!! self.datachannel_timeout = False - structlog.get_logger("structlog").info("SESSION [" + str(self.mycallsign, 'utf-8') + "]>> <<[" + str(static.DXCALLSIGN, 'utf-8') + "]", state=static.ARQ_SESSION_STATE) - + structlog.get_logger("structlog").info( + "SESSION [" + + str(self.mycallsign, "utf-8") + + "]>> <<[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + state=static.ARQ_SESSION_STATE, + ) + self.open_session(callsign) # wait until data channel is open while not static.ARQ_SESSION and not self.arq_session_timeout: time.sleep(0.01) - static.ARQ_SESSION_STATE = 'connecting' + static.ARQ_SESSION_STATE = "connecting" if static.ARQ_SESSION: - static.ARQ_SESSION_STATE = 'connected' + static.ARQ_SESSION_STATE = "connected" return True else: - static.ARQ_SESSION_STATE = 'failed' + static.ARQ_SESSION_STATE = "failed" return False - def open_session(self, callsign): """ Args: - callsign: + callsign: Returns: """ self.IS_ARQ_SESSION_MASTER = True - static.ARQ_SESSION_STATE = 'connecting' + static.ARQ_SESSION_STATE = "connecting" frametype = bytes([221]) - - connection_frame = bytearray(14) - connection_frame[:1] = frametype + + connection_frame = bytearray(14) + connection_frame[:1] = frametype connection_frame[1:3] = static.DXCALLSIGN_CRC connection_frame[3:5] = static.MYCALLSIGN_CRC - connection_frame[5:13] = helpers.callsign_to_bytes(self.mycallsign) - - + connection_frame[5:13] = helpers.callsign_to_bytes(self.mycallsign) + while not static.ARQ_SESSION: time.sleep(0.01) - for attempt in range(1,self.session_connect_max_retries+1): - txbuffer = [connection_frame] + for attempt in range(1, self.session_connect_max_retries + 1): + txbuffer = [connection_frame] static.TRANSMITTING = True - - structlog.get_logger("structlog").info("SESSION [" + str(self.mycallsign, 'utf-8') + "]>>?<<[" + str(static.DXCALLSIGN, 'utf-8') + "]", a=attempt, state=static.ARQ_SESSION_STATE) - - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + + structlog.get_logger("structlog").info( + "SESSION [" + + str(self.mycallsign, "utf-8") + + "]>>?<<[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + a=attempt, + state=static.ARQ_SESSION_STATE, + ) + + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) - - timeout = time.time() + 3 - while time.time() < timeout: + + timeout = time.time() + 3 + while time.time() < timeout: time.sleep(0.01) - # break if data channel is opened + # break if data channel is opened if static.ARQ_SESSION: # eventuell einfach nur return true um die nächste break ebene zu vermeiden? break if static.ARQ_SESSION: break - - - if not static.ARQ_SESSION and attempt == self.session_connect_max_retries: + + if ( + not static.ARQ_SESSION + and attempt == self.session_connect_max_retries + ): if not TESTMODE: self.arq_cleanup() return False - - - def received_session_opener(self, data_in:bytes): + + def received_session_opener(self, data_in: bytes): """ Args: - data_in:bytes: + data_in:bytes: Returns: """ self.IS_ARQ_SESSION_MASTER = False - static.ARQ_SESSION_STATE = 'connecting' + static.ARQ_SESSION_STATE = "connecting" self.arq_session_last_received = int(time.time()) static.DXCALLSIGN_CRC = bytes(data_in[3:5]) static.DXCALLSIGN = helpers.bytes_to_callsign(bytes(data_in[5:13])) - - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - structlog.get_logger("structlog").info("SESSION [" + str(self.mycallsign, 'utf-8') + "]>>|<<[" + str(static.DXCALLSIGN, 'utf-8') + "]", state=static.ARQ_SESSION_STATE) + + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + structlog.get_logger("structlog").info( + "SESSION [" + + str(self.mycallsign, "utf-8") + + "]>>|<<[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + state=static.ARQ_SESSION_STATE, + ) static.ARQ_SESSION = True - static.TNC_STATE = 'BUSY' + static.TNC_STATE = "BUSY" self.transmit_session_heartbeat() - def close_session(self): """ """ - static.ARQ_SESSION_STATE = 'disconnecting' - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - structlog.get_logger("structlog").info("SESSION [" + str(self.mycallsign, 'utf-8') + "]<>[" + str(static.DXCALLSIGN, 'utf-8') + "]", state=static.ARQ_SESSION_STATE) + static.ARQ_SESSION_STATE = "disconnecting" + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + structlog.get_logger("structlog").info( + "SESSION [" + + str(self.mycallsign, "utf-8") + + "]<>[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + state=static.ARQ_SESSION_STATE, + ) static.INFO.append("ARQ;SESSION;CLOSE") self.IS_ARQ_SESSION_MASTER = False static.ARQ_SESSION = False self.arq_cleanup() frametype = bytes([223]) - - disconnection_frame = bytearray(14) - disconnection_frame[:1] = frametype + + disconnection_frame = bytearray(14) + disconnection_frame[:1] = frametype disconnection_frame[1:3] = static.DXCALLSIGN_CRC disconnection_frame[3:5] = static.MYCALLSIGN_CRC - disconnection_frame[5:13] = helpers.callsign_to_bytes(self.mycallsign) - - txbuffer = [disconnection_frame] + disconnection_frame[5:13] = helpers.callsign_to_bytes(self.mycallsign) + + txbuffer = [disconnection_frame] static.TRANSMITTING = True - - modem.MODEM_TRANSMIT_QUEUE.put([14,2,250,txbuffer]) + + modem.MODEM_TRANSMIT_QUEUE.put([14, 2, 250, txbuffer]) # wait while transmitting while static.TRANSMITTING: - time.sleep(0.01) - - + time.sleep(0.01) - def received_session_close(self): """ """ - static.ARQ_SESSION_STATE = 'disconnected' - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - structlog.get_logger("structlog").info("SESSION [" + str(self.mycallsign, 'utf-8') + "]<>[" + str(static.DXCALLSIGN, 'utf-8') + "]", state=static.ARQ_SESSION_STATE) + static.ARQ_SESSION_STATE = "disconnected" + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + structlog.get_logger("structlog").info( + "SESSION [" + + str(self.mycallsign, "utf-8") + + "]<>[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + state=static.ARQ_SESSION_STATE, + ) static.INFO.append("ARQ;SESSION;CLOSE") self.IS_ARQ_SESSION_MASTER = False static.ARQ_SESSION = False self.arq_cleanup() - def transmit_session_heartbeat(self): """ """ static.ARQ_SESSION = True - static.TNC_STATE = 'BUSY' - static.ARQ_SESSION_STATE = 'connected' + static.TNC_STATE = "BUSY" + static.ARQ_SESSION_STATE = "connected" frametype = bytes([222]) - - connection_frame = bytearray(14) - connection_frame[:1] = frametype + + connection_frame = bytearray(14) + connection_frame[:1] = frametype connection_frame[1:3] = static.DXCALLSIGN_CRC connection_frame[3:5] = static.MYCALLSIGN_CRC - - txbuffer = [connection_frame] + txbuffer = [connection_frame] static.TRANSMITTING = True - - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting while static.TRANSMITTING: - time.sleep(0.01) + time.sleep(0.01) - - - - def received_session_heartbeat(self, data_in:bytes): + def received_session_heartbeat(self, data_in: bytes): """ Args: - data_in:bytes: + data_in:bytes: Returns: """ structlog.get_logger("structlog").debug("received session heartbeat") - helpers.add_to_heard_stations(static.DXCALLSIGN, static.DXGRID, 'SESSION-HB', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "SESSION-HB", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + + self.arq_session_last_received = int( + time.time() + ) # we need to update our timeout timestamp - self.arq_session_last_received = int(time.time()) # we need to update our timeout timestamp - static.ARQ_SESSION = True - static.ARQ_SESSION_STATE = 'connected' - static.TNC_STATE = 'BUSY' + static.ARQ_SESSION_STATE = "connected" + static.TNC_STATE = "BUSY" self.data_channel_last_received = int(time.time()) - if static.ARQ_SESSION and not self.IS_ARQ_SESSION_MASTER and not self.arq_file_transfer: + if ( + static.ARQ_SESSION + and not self.IS_ARQ_SESSION_MASTER + and not self.arq_file_transfer + ): self.transmit_session_heartbeat() # ############################################################################################################ # ARQ DATA CHANNEL HANDLER # ############################################################################################################ - def open_dc_and_transmit(self, data_out:bytes, mode:int, n_frames_per_burst:int, transmission_uuid:str, mycallsign): + def open_dc_and_transmit( + self, + data_out: bytes, + mode: int, + n_frames_per_burst: int, + transmission_uuid: str, + mycallsign, + ): """ Args: - data_out:bytes: - mode:int: - n_frames_per_burst:int: + data_out:bytes: + mode:int: + n_frames_per_burst:int: Returns: """ # overwrite mycallsign in case of different SSID self.mycallsign = mycallsign - - static.TNC_STATE = 'BUSY' + + static.TNC_STATE = "BUSY" self.arq_file_transfer = True - + self.transmission_uuid = transmission_uuid - + # wait a moment for the case, an heartbeat is already on the way back to us if static.ARQ_SESSION: time.sleep(0.5) - - + self.datachannel_timeout = False - + # we need to compress data for gettin a compression factor. # so we are compressing twice. This is not that nice and maybe theres another way # for calculating transmission statistics static.ARQ_COMPRESSION_FACTOR = len(data_out) / len(zlib.compress(data_out)) - + self.arq_open_data_channel(mode, n_frames_per_burst, mycallsign) - + # wait until data channel is open while not static.ARQ_STATE and not self.datachannel_timeout: time.sleep(0.01) - + if static.ARQ_STATE: self.arq_transmit(data_out, mode, n_frames_per_burst) else: - return False - - def arq_open_data_channel(self, mode:int, n_frames_per_burst:int, mycallsign): + return False + + def arq_open_data_channel(self, mode: int, n_frames_per_burst: int, mycallsign): """ Args: - mode:int: - n_frames_per_burst:int: + mode:int: + n_frames_per_burst:int: Returns: """ - self.is_IRS = False + self.is_IRS = False self.data_channel_last_received = int(time.time()) if static.LOW_BANDWITH_MODE and mode == 255: @@ -1262,34 +1575,42 @@ class DATA(): frametype = bytes([225]) structlog.get_logger("structlog").debug("requesting high bandwith mode") - if 230 <= mode <= 240: - structlog.get_logger("structlog").debug("requesting manual mode --> not yet implemented ") + structlog.get_logger("structlog").debug( + "requesting manual mode --> not yet implemented " + ) frametype = bytes([mode]) - - connection_frame = bytearray(14) - connection_frame[:1] = frametype + + connection_frame = bytearray(14) + connection_frame[:1] = frametype connection_frame[1:3] = static.DXCALLSIGN_CRC connection_frame[3:5] = static.MYCALLSIGN_CRC - connection_frame[5:13] = helpers.callsign_to_bytes(mycallsign) - connection_frame[13:14] = bytes([n_frames_per_burst]) - + connection_frame[5:13] = helpers.callsign_to_bytes(mycallsign) + connection_frame[13:14] = bytes([n_frames_per_burst]) + while not static.ARQ_STATE: time.sleep(0.01) - for attempt in range(1,self.data_channel_max_retries+1): + for attempt in range(1, self.data_channel_max_retries + 1): static.INFO.append("DATACHANNEL;OPENING") - structlog.get_logger("structlog").info("[TNC] ARQ | DATA | TX | [" + str(helpers.callsign_to_bytes(mycallsign), 'utf-8') + "]>> <<[" + str(static.DXCALLSIGN, 'utf-8') + "]", attempt=str(attempt) + "/" + str(self.data_channel_max_retries)) - txbuffer = [connection_frame] + structlog.get_logger("structlog").info( + "[TNC] ARQ | DATA | TX | [" + + str(helpers.callsign_to_bytes(mycallsign), "utf-8") + + "]>> <<[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + attempt=str(attempt) + "/" + str(self.data_channel_max_retries), + ) + txbuffer = [connection_frame] static.TRANSMITTING = True - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) - - timeout = time.time() + 3 - while time.time() < timeout: + + timeout = time.time() + 3 + while time.time() < timeout: time.sleep(0.01) - # break if data channel is opened + # break if data channel is opened if static.ARQ_STATE: break if static.ARQ_STATE: @@ -1298,73 +1619,93 @@ class DATA(): if not static.ARQ_STATE and attempt == self.data_channel_max_retries: static.INFO.append("DATACHANNEL;FAILED") print(self.transmission_uuid) - jsondata = {"arq":"transmission", "status" :"failed", "uuid" : self.transmission_uuid, "percent" : static.ARQ_TRANSMISSION_PERCENT, "bytesperminute" : static.ARQ_BYTES_PER_MINUTE} + jsondata = { + "arq": "transmission", + "status": "failed", + "uuid": self.transmission_uuid, + "percent": static.ARQ_TRANSMISSION_PERCENT, + "bytesperminute": static.ARQ_BYTES_PER_MINUTE, + } json_data_out = json.dumps(jsondata) sock.SOCKET_QUEUE.put(json_data_out) - - structlog.get_logger("structlog").warning("[TNC] ARQ | TX | DATA [" + str(mycallsign, 'utf-8') + "]>>X<<[" + str(static.DXCALLSIGN, 'utf-8') + "]") + + structlog.get_logger("structlog").warning( + "[TNC] ARQ | TX | DATA [" + + str(mycallsign, "utf-8") + + "]>>X<<[" + + str(static.DXCALLSIGN, "utf-8") + + "]" + ) self.datachannel_timeout = True if not TESTMODE: self.arq_cleanup() - + return False - #sys.exit() # close thread and so connection attempts + # sys.exit() # close thread and so connection attempts - - - - - def arq_received_data_channel_opener(self, data_in:bytes): + def arq_received_data_channel_opener(self, data_in: bytes): """ Args: - data_in:bytes: + data_in:bytes: Returns: """ self.arq_file_transfer = True - self.is_IRS = True + self.is_IRS = True static.INFO.append("DATACHANNEL;RECEIVEDOPENER") static.DXCALLSIGN_CRC = bytes(data_in[3:5]) static.DXCALLSIGN = helpers.bytes_to_callsign(bytes(data_in[5:13])) - n_frames_per_burst = int.from_bytes(bytes(data_in[13:14]), "big") + n_frames_per_burst = int.from_bytes(bytes(data_in[13:14]), "big") frametype = int.from_bytes(bytes(data_in[:1]), "big") - #check if we received low bandwith mode + # check if we received low bandwith mode if frametype == 225: self.received_low_bandwith_mode = False - self.mode_list = self.mode_list_high_bw + self.mode_list = self.mode_list_high_bw self.time_list = self.time_list_high_bw - self.speed_level = len(self.mode_list) - 1 + self.speed_level = len(self.mode_list) - 1 else: self.received_low_bandwith_mode = True - self.mode_list = self.mode_list_low_bw + self.mode_list = self.mode_list_low_bw self.time_list = self.time_list_low_bw - self.speed_level = len(self.mode_list) - 1 - - + self.speed_level = len(self.mode_list) - 1 + if 230 <= frametype <= 240: print("manual mode request") - + # updated modes we are listening to self.set_listening_modes(self.mode_list[self.speed_level]) - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + # check if callsign ssid override valid, mycallsign = helpers.check_callsign(self.mycallsign, data_in[1:3]) if not valid: # ARQ connect packet not for me. if not TESTMODE: - self.arq_cleanup() + self.arq_cleanup() return - - structlog.get_logger("structlog").info("[TNC] ARQ | DATA | RX | [" + str(mycallsign, 'utf-8') + "]>> <<[" + str(static.DXCALLSIGN, 'utf-8') + "]", bandwith="wide") - - static.ARQ_STATE = True - static.TNC_STATE = 'BUSY' + structlog.get_logger("structlog").info( + "[TNC] ARQ | DATA | RX | [" + + str(mycallsign, "utf-8") + + "]>> <<[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + bandwith="wide", + ) + + static.ARQ_STATE = True + static.TNC_STATE = "BUSY" self.reset_statistics() @@ -1375,33 +1716,43 @@ class DATA(): structlog.get_logger("structlog").debug("responding with low bandwith mode") else: frametype = bytes([226]) - structlog.get_logger("structlog").debug("responding with high bandwith mode") - + structlog.get_logger("structlog").debug( + "responding with high bandwith mode" + ) + connection_frame = bytearray(14) connection_frame[:1] = frametype connection_frame[1:3] = static.DXCALLSIGN_CRC connection_frame[3:5] = static.MYCALLSIGN_CRC - connection_frame[13:14] = bytes([static.ARQ_PROTOCOL_VERSION]) #crc8 of version for checking protocol version + connection_frame[13:14] = bytes( + [static.ARQ_PROTOCOL_VERSION] + ) # crc8 of version for checking protocol version txbuffer = [connection_frame] - + static.TRANSMITTING = True - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) - structlog.get_logger("structlog").info("[TNC] ARQ | DATA | RX | [" + str(mycallsign, 'utf-8') + "]>>|<<[" + str(static.DXCALLSIGN, 'utf-8') + "]", bandwith="wide", snr=static.SNR) - + structlog.get_logger("structlog").info( + "[TNC] ARQ | DATA | RX | [" + + str(mycallsign, "utf-8") + + "]>>|<<[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + bandwith="wide", + snr=static.SNR, + ) + # set start of transmission for our statistics self.rx_start_of_transmission = time.time() - - - def arq_received_channel_is_open(self, data_in:bytes): + def arq_received_channel_is_open(self, data_in: bytes): """ Called if we received a data channel opener Args: - data_in:bytes: + data_in:bytes: Returns: @@ -1409,55 +1760,82 @@ class DATA(): protocol_version = int.from_bytes(bytes(data_in[13:14]), "big") if protocol_version == static.ARQ_PROTOCOL_VERSION: static.INFO.append("DATACHANNEL;OPEN") - #static.DXCALLSIGN_CRC = bytes(data_in[3:5]) - frametype = int.from_bytes(bytes(data_in[:1]), "big") - + # static.DXCALLSIGN_CRC = bytes(data_in[3:5]) + frametype = int.from_bytes(bytes(data_in[:1]), "big") + if frametype == 228: self.received_low_bandwith_mode = True - self.mode_list = self.mode_list_low_bw + self.mode_list = self.mode_list_low_bw self.time_list = self.time_list_low_bw - self.speed_level = len(self.mode_list) - 1 - structlog.get_logger("structlog").debug("low bandwith mode", modes=self.mode_list) + self.speed_level = len(self.mode_list) - 1 + structlog.get_logger("structlog").debug( + "low bandwith mode", modes=self.mode_list + ) else: self.received_low_bandwith_mode = False - self.mode_list = self.mode_list_high_bw + self.mode_list = self.mode_list_high_bw self.time_list = self.time_list_high_bw - self.speed_level = len(self.mode_list) - 1 - structlog.get_logger("structlog").debug("high bandwith mode", modes=self.mode_list) - - helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - - structlog.get_logger("structlog").info("[TNC] ARQ | DATA | TX | [" + str(self.mycallsign, 'utf-8') + "]>>|<<[" + str(static.DXCALLSIGN, 'utf-8') + "]", snr=static.SNR) + self.speed_level = len(self.mode_list) - 1 + structlog.get_logger("structlog").debug( + "high bandwith mode", modes=self.mode_list + ) - # as soon as we set ARQ_STATE to DATA, transmission starts + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "DATA-CHANNEL", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + + structlog.get_logger("structlog").info( + "[TNC] ARQ | DATA | TX | [" + + str(self.mycallsign, "utf-8") + + "]>>|<<[" + + str(static.DXCALLSIGN, "utf-8") + + "]", + snr=static.SNR, + ) + + # as soon as we set ARQ_STATE to DATA, transmission starts static.ARQ_STATE = True self.data_channel_last_received = int(time.time()) else: - static.TNC_STATE = 'IDLE' + static.TNC_STATE = "IDLE" static.ARQ_STATE = False static.INFO.append("PROTOCOL;VERSION_MISSMATCH") - structlog.get_logger("structlog").warning("protocol version missmatch", received=protocol_version, own=static.ARQ_PROTOCOL_VERSION) + structlog.get_logger("structlog").warning( + "protocol version missmatch", + received=protocol_version, + own=static.ARQ_PROTOCOL_VERSION, + ) self.arq_cleanup() - # ---------- PING - def transmit_ping(self, dxcallsign:bytes): + def transmit_ping(self, dxcallsign: bytes): """ Funktion for controlling pings Args: - dxcallsign:bytes: + dxcallsign:bytes: Returns: """ static.DXCALLSIGN = dxcallsign static.DXCALLSIGN_CRC = helpers.get_crc_16(static.DXCALLSIGN) - - static.INFO.append("PING;SENDING") - structlog.get_logger("structlog").info("[TNC] PING REQ [" + str(self.mycallsign, 'utf-8') + "] >>> [" + str(static.DXCALLSIGN, 'utf-8') + "]" ) - ping_frame = bytearray(14) - ping_frame[:1] = bytes([210]) + static.INFO.append("PING;SENDING") + structlog.get_logger("structlog").info( + "[TNC] PING REQ [" + + str(self.mycallsign, "utf-8") + + "] >>> [" + + str(static.DXCALLSIGN, "utf-8") + + "]" + ) + + ping_frame = bytearray(14) + ping_frame[:1] = bytes([210]) ping_frame[1:3] = static.DXCALLSIGN_CRC ping_frame[3:5] = static.MYCALLSIGN_CRC ping_frame[5:13] = helpers.callsign_to_bytes(self.mycallsign) @@ -1466,20 +1844,20 @@ class DATA(): static.TRANSMITTING = True structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK) if static.ENABLE_FSK: - modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put(["FSK_LDPC_0", 1, 0, txbuffer]) else: - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) - - def received_ping(self, data_in:bytes, frequency_offset:str): + + def received_ping(self, data_in: bytes, frequency_offset: str): """ Called if we received a ping Args: - data_in:bytes: - frequency_offset:str: + data_in:bytes: + frequency_offset:str: Returns: @@ -1487,8 +1865,15 @@ class DATA(): static.DXCALLSIGN_CRC = bytes(data_in[3:5]) static.DXCALLSIGN = helpers.bytes_to_callsign(bytes(data_in[5:13])) - helpers.add_to_heard_stations(static.DXCALLSIGN, static.DXGRID, 'PING', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "PING", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + static.INFO.append("PING;RECEIVING") # check if callsign ssid override @@ -1496,69 +1881,98 @@ class DATA(): if not valid: # PING packet not for me. return - - structlog.get_logger("structlog").info("[TNC] PING REQ [" + str(mycallsign, 'utf-8') + "] <<< [" + str(static.DXCALLSIGN, 'utf-8') + "]", snr=static.SNR ) - ping_frame = bytearray(14) - ping_frame[:1] = bytes([211]) + structlog.get_logger("structlog").info( + "[TNC] PING REQ [" + + str(mycallsign, "utf-8") + + "] <<< [" + + str(static.DXCALLSIGN, "utf-8") + + "]", + snr=static.SNR, + ) + + ping_frame = bytearray(14) + ping_frame[:1] = bytes([211]) ping_frame[1:3] = static.DXCALLSIGN_CRC ping_frame[3:5] = static.MYCALLSIGN_CRC ping_frame[5:11] = static.MYGRID - ping_frame[11:13] = frequency_offset.to_bytes(2, byteorder='big', signed=True) + ping_frame[11:13] = frequency_offset.to_bytes(2, byteorder="big", signed=True) txbuffer = [ping_frame] static.TRANSMITTING = True structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK) if static.ENABLE_FSK: - modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put(["FSK_LDPC_0", 1, 0, txbuffer]) else: - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) - - def received_ping_ack(self, data_in:bytes): + + def received_ping_ack(self, data_in: bytes): """ Called if a PING ack has been received Args: - data_in:bytes: + data_in:bytes: Returns: """ static.DXCALLSIGN_CRC = bytes(data_in[3:5]) - static.DXGRID = bytes(data_in[5:11]).rstrip(b'\x00') - - jsondata = {"type" : "ping", "status" : "ack", "uuid" : str(uuid.uuid4()), "timestamp": int(time.time()), "mycallsign" : str(self.mycallsign, 'utf-8'), "dxcallsign": str(static.DXCALLSIGN, 'utf-8'), "dxgrid": str(static.DXGRID, 'utf-8'), "snr": str(static.SNR)} + static.DXGRID = bytes(data_in[5:11]).rstrip(b"\x00") + + jsondata = { + "type": "ping", + "status": "ack", + "uuid": str(uuid.uuid4()), + "timestamp": int(time.time()), + "mycallsign": str(self.mycallsign, "utf-8"), + "dxcallsign": str(static.DXCALLSIGN, "utf-8"), + "dxgrid": str(static.DXGRID, "utf-8"), + "snr": str(static.SNR), + } json_data_out = json.dumps(jsondata) - sock.SOCKET_QUEUE.put(json_data_out) - - helpers.add_to_heard_stations(static.DXCALLSIGN, static.DXGRID, 'PING-ACK', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - + sock.SOCKET_QUEUE.put(json_data_out) + + helpers.add_to_heard_stations( + static.DXCALLSIGN, + static.DXGRID, + "PING-ACK", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) + static.INFO.append("PING;RECEIVEDACK") - structlog.get_logger("structlog").info("[TNC] PING ACK [" + str(self.mycallsign, 'utf-8') + "] >|< [" + str(static.DXCALLSIGN, 'utf-8') + "]", snr=static.SNR ) - static.TNC_STATE = 'IDLE' - + structlog.get_logger("structlog").info( + "[TNC] PING ACK [" + + str(self.mycallsign, "utf-8") + + "] >|< [" + + str(static.DXCALLSIGN, "utf-8") + + "]", + snr=static.SNR, + ) + static.TNC_STATE = "IDLE" def stop_transmission(self): """ Force a stop of the running transmission """ structlog.get_logger("structlog").warning("[TNC] Stopping transmission!") - stop_frame = bytearray(14) - stop_frame[:1] = bytes([249]) + stop_frame = bytearray(14) + stop_frame[:1] = bytes([249]) stop_frame[1:3] = static.DXCALLSIGN_CRC stop_frame[3:5] = static.MYCALLSIGN_CRC txbuffer = [stop_frame] static.TRANSMITTING = True - modem.MODEM_TRANSMIT_QUEUE.put([14,2,250,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 2, 250, txbuffer]) while static.TRANSMITTING: time.sleep(0.01) - - static.TNC_STATE = 'IDLE' + + static.TNC_STATE = "IDLE" static.ARQ_STATE = False static.INFO.append("TRANSMISSION;STOPPED") self.arq_cleanup() @@ -1568,79 +1982,114 @@ class DATA(): Received a transmission stop """ structlog.get_logger("structlog").warning("[TNC] Stopping transmission!") - static.TNC_STATE = 'IDLE' + static.TNC_STATE = "IDLE" static.ARQ_STATE = False static.INFO.append("TRANSMISSION;STOPPED") self.arq_cleanup() - + # ----------- BROADCASTS - + def run_beacon(self): """ Controlling funktion for running a beacon Args: - interval:int: + interval:int: Returns: """ try: - + while 1: time.sleep(0.5) while static.BEACON_STATE: - if static.BEACON_STATE and not static.ARQ_SESSION and not self.arq_file_transfer and not static.BEACON_PAUSE: + if ( + static.BEACON_STATE + and not static.ARQ_SESSION + and not self.arq_file_transfer + and not static.BEACON_PAUSE + ): static.INFO.append("BEACON;SENDING") - structlog.get_logger("structlog").info("[TNC] Sending beacon!", interval=self.beacon_interval) - + structlog.get_logger("structlog").info( + "[TNC] Sending beacon!", interval=self.beacon_interval + ) + beacon_frame = bytearray(14) - beacon_frame[:1] = bytes([250]) - beacon_frame[1:9] = helpers.callsign_to_bytes(self.mycallsign) + beacon_frame[:1] = bytes([250]) + beacon_frame[1:9] = helpers.callsign_to_bytes(self.mycallsign) beacon_frame[9:13] = static.MYGRID[:4] txbuffer = [beacon_frame] static.TRANSMITTING = True - structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK) + structlog.get_logger("structlog").info( + "ENABLE FSK", state=static.ENABLE_FSK + ) if static.ENABLE_FSK: - modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put( + ["FSK_LDPC_0", 1, 0, txbuffer] + ) else: - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) - - + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) + # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) - + interval_timer = time.time() + self.beacon_interval - while time.time() < interval_timer and static.BEACON_STATE and not static.BEACON_PAUSE: + while ( + time.time() < interval_timer + and static.BEACON_STATE + and not static.BEACON_PAUSE + ): time.sleep(0.01) except Exception as e: print(e) - def received_beacon(self, data_in:bytes): + def received_beacon(self, data_in: bytes): """ Called if we received a beacon Args: - data_in:bytes: + data_in:bytes: Returns: """ - # here we add the received station to the heard stations buffer + # here we add the received station to the heard stations buffer dxcallsign = helpers.bytes_to_callsign(bytes(data_in[1:9])) - dxgrid = bytes(data_in[9:13]).rstrip(b'\x00') + dxgrid = bytes(data_in[9:13]).rstrip(b"\x00") - jsondata = {"type" : "beacon", "status" : "received", "uuid" : str(uuid.uuid4()), "timestamp": int(time.time()), "mycallsign" : str(self.mycallsign, 'utf-8'), "dxcallsign": str(dxcallsign, 'utf-8'), "dxgrid": str(dxgrid, 'utf-8'), "snr": str(static.SNR)} + jsondata = { + "type": "beacon", + "status": "received", + "uuid": str(uuid.uuid4()), + "timestamp": int(time.time()), + "mycallsign": str(self.mycallsign, "utf-8"), + "dxcallsign": str(dxcallsign, "utf-8"), + "dxgrid": str(dxgrid, "utf-8"), + "snr": str(static.SNR), + } json_data_out = json.dumps(jsondata) - sock.SOCKET_QUEUE.put(json_data_out) + sock.SOCKET_QUEUE.put(json_data_out) static.INFO.append("BEACON;RECEIVING") - structlog.get_logger("structlog").info("[TNC] BEACON RCVD [" + str(dxcallsign, 'utf-8') + "]["+ str(dxgrid, 'utf-8') +"] ", snr=static.SNR) - helpers.add_to_heard_stations(dxcallsign,dxgrid, 'BEACON', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) - - + structlog.get_logger("structlog").info( + "[TNC] BEACON RCVD [" + + str(dxcallsign, "utf-8") + + "][" + + str(dxgrid, "utf-8") + + "] ", + snr=static.SNR, + ) + helpers.add_to_heard_stations( + dxcallsign, + dxgrid, + "BEACON", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) def transmit_cq(self): """ @@ -1648,80 +2097,100 @@ class DATA(): """ structlog.get_logger("structlog").info("CQ CQ CQ") static.INFO.append("CQ;SENDING") - - cq_frame = bytearray(14) - cq_frame[:1] = bytes([200]) - cq_frame[1:9] = helpers.callsign_to_bytes(self.mycallsign) + + cq_frame = bytearray(14) + cq_frame[:1] = bytes([200]) + cq_frame[1:9] = helpers.callsign_to_bytes(self.mycallsign) cq_frame[9:13] = static.MYGRID[:4] - + txbuffer = [cq_frame] print(txbuffer) static.TRANSMITTING = True structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK) if static.ENABLE_FSK: - modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',3,500,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put(["FSK_LDPC_0", 3, 500, txbuffer]) else: - modem.MODEM_TRANSMIT_QUEUE.put([14,3,500,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 3, 500, txbuffer]) # wait while transmitting while static.TRANSMITTING: time.sleep(0.01) return - - def received_cq(self, data_in:bytes): + def received_cq(self, data_in: bytes): """ Called if we received a CQ Args: - data_in:bytes: + data_in:bytes: Returns: """ # here we add the received station to the heard stations buffer dxcallsign = helpers.bytes_to_callsign(bytes(data_in[1:9])) - dxgrid = bytes(data_in[9:13]).rstrip(b'\x00') + dxgrid = bytes(data_in[9:13]).rstrip(b"\x00") static.INFO.append("CQ;RECEIVING") - structlog.get_logger("structlog").info("[TNC] CQ RCVD [" + str(dxcallsign, 'utf-8') + "]["+ str(dxgrid, 'utf-8') +"] ", snr=static.SNR) - helpers.add_to_heard_stations(dxcallsign, dxgrid, 'CQ CQ CQ', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) + structlog.get_logger("structlog").info( + "[TNC] CQ RCVD [" + + str(dxcallsign, "utf-8") + + "][" + + str(dxgrid, "utf-8") + + "] ", + snr=static.SNR, + ) + helpers.add_to_heard_stations( + dxcallsign, + dxgrid, + "CQ CQ CQ", + static.SNR, + static.FREQ_OFFSET, + static.HAMLIB_FREQUENCY, + ) # ------------ CALUCLATE TRANSFER RATES - def calculate_transfer_rate_rx(self, rx_start_of_transmission:float, receivedbytes:int) -> list: + def calculate_transfer_rate_rx( + self, rx_start_of_transmission: float, receivedbytes: int + ) -> list: """ Calculate Transferrate for receiving data Args: - rx_start_of_transmission:float: - receivedbytes:int: + rx_start_of_transmission:float: + receivedbytes:int: Returns: """ - - try: + + try: if static.TOTAL_BYTES == 0: static.TOTAL_BYTES = 1 - static.ARQ_TRANSMISSION_PERCENT = int((receivedbytes*static.ARQ_COMPRESSION_FACTOR / (static.TOTAL_BYTES)) * 100) + static.ARQ_TRANSMISSION_PERCENT = int( + (receivedbytes * static.ARQ_COMPRESSION_FACTOR / (static.TOTAL_BYTES)) + * 100 + ) if static.ARQ_TRANSMISSION_PERCENT > 100: static.ARQ_TRANSMISSION_PERCENT = 100 - + transmissiontime = time.time() - self.rx_start_of_transmission - + if receivedbytes > 0: - static.ARQ_BITS_PER_SECOND = int((receivedbytes*8) / transmissiontime) - static.ARQ_BYTES_PER_MINUTE = int((receivedbytes) / (transmissiontime/60)) - + static.ARQ_BITS_PER_SECOND = int((receivedbytes * 8) / transmissiontime) + static.ARQ_BYTES_PER_MINUTE = int( + (receivedbytes) / (transmissiontime / 60) + ) + else: static.ARQ_BITS_PER_SECOND = 0 - static.ARQ_BYTES_PER_MINUTE = 0 + static.ARQ_BYTES_PER_MINUTE = 0 except: static.ARQ_TRANSMISSION_PERCENT = 0.0 static.ARQ_BITS_PER_SECOND = 0 static.ARQ_BYTES_PER_MINUTE = 0 - return [static.ARQ_BITS_PER_SECOND, \ - static.ARQ_BYTES_PER_MINUTE, \ - static.ARQ_TRANSMISSION_PERCENT] - - + return [ + static.ARQ_BITS_PER_SECOND, + static.ARQ_BYTES_PER_MINUTE, + static.ARQ_TRANSMISSION_PERCENT, + ] def reset_statistics(self): """ @@ -1734,45 +2203,52 @@ class DATA(): static.ARQ_BITS_PER_SECOND = 0 static.ARQ_TRANSMISSION_PERCENT = 0 static.TOTAL_BYTES = 0 - - def calculate_transfer_rate_tx(self, tx_start_of_transmission:float, sentbytes:int, tx_buffer_length:int) -> list: + + def calculate_transfer_rate_tx( + self, tx_start_of_transmission: float, sentbytes: int, tx_buffer_length: int + ) -> list: """ Calcualte Transferrate for transmission Args: - tx_start_of_transmission:float: - sentbytes:int: - tx_buffer_length:int: + tx_start_of_transmission:float: + sentbytes:int: + tx_buffer_length:int: Returns: """ - + try: static.ARQ_TRANSMISSION_PERCENT = int((sentbytes / tx_buffer_length) * 100) - + if static.ARQ_TRANSMISSION_PERCENT > 100: static.ARQ_TRANSMISSION_PERCENT = 100 - + transmissiontime = time.time() - tx_start_of_transmission if sentbytes > 0: - - static.ARQ_BITS_PER_SECOND = int((sentbytes*8) / transmissiontime) # Bits per Second - static.ARQ_BYTES_PER_MINUTE = int((sentbytes) / (transmissiontime/60)) #Bytes per Minute + + static.ARQ_BITS_PER_SECOND = int( + (sentbytes * 8) / transmissiontime + ) # Bits per Second + static.ARQ_BYTES_PER_MINUTE = int( + (sentbytes) / (transmissiontime / 60) + ) # Bytes per Minute else: static.ARQ_BITS_PER_SECOND = 0 - static.ARQ_BYTES_PER_MINUTE = 0 - + static.ARQ_BYTES_PER_MINUTE = 0 + except: static.ARQ_TRANSMISSION_PERCENT = 0.0 static.ARQ_BITS_PER_SECOND = 0 static.ARQ_BYTES_PER_MINUTE = 0 - return [static.ARQ_BITS_PER_SECOND, \ - static.ARQ_BYTES_PER_MINUTE, \ - static.ARQ_TRANSMISSION_PERCENT] - + return [ + static.ARQ_BITS_PER_SECOND, + static.ARQ_BYTES_PER_MINUTE, + static.ARQ_TRANSMISSION_PERCENT, + ] # ----------------------CLEANUP AND RESET FUNCTIONS def arq_cleanup(self): @@ -1780,28 +2256,27 @@ class DATA(): Cleanup funktion which clears all ARQ states """ - structlog.get_logger("structlog").debug("cleanup") - - self.received_mycall_crc = b'' - + + self.received_mycall_crc = b"" + self.rx_frame_bof_received = False self.rx_frame_eof_received = False self.burst_ack = False self.rpt_request_received = False self.data_frame_ack_received = False static.RX_BURST_BUFFER = [] - static.RX_FRAME_BUFFER = b'' - self.burst_ack_snr= 255 + static.RX_FRAME_BUFFER = b"" + self.burst_ack_snr = 255 # reset modem receiving state to reduce cpu load modem.RECEIVE_DATAC1 = False modem.RECEIVE_DATAC3 = False - #modem.RECEIVE_FSK_LDPC_0 = False + # modem.RECEIVE_FSK_LDPC_0 = False modem.RECEIVE_FSK_LDPC_1 = False - + # reset buffer overflow counter - static.BUFFER_OVERFLOW_COUNTER = [0,0,0,0,0] + static.BUFFER_OVERFLOW_COUNTER = [0, 0, 0, 0, 0] self.is_IRS = False self.burst_nack = False @@ -1809,30 +2284,26 @@ class DATA(): self.frame_received_counter = 0 self.speed_level = len(self.mode_list) - 1 static.ARQ_SPEED_LEVEL = self.speed_level - + # low bandwith mode indicator self.received_low_bandwith_mode = False - + # reset retry counter for rx channel / burst self.n_retries_per_burst = 0 - + if not static.ARQ_SESSION: - static.TNC_STATE = 'IDLE' - + static.TNC_STATE = "IDLE" + static.ARQ_STATE = False self.arq_file_transfer = False - + static.BEACON_PAUSE = False - - - - - - def arq_reset_ack(self,state:bool): + + def arq_reset_ack(self, state: bool): """ Funktion for resetting acknowledge states Args: - state:bool: + state:bool: Returns: @@ -1842,40 +2313,46 @@ class DATA(): self.rpt_request_received = state self.data_frame_ack_received = state - def set_listening_modes(self, mode): """ Function for setting the data modes we are listening to for saving cpu power Args: - mode: + mode: Returns: """ # set modes we want listening to - + mode_name = codec2.freedv_get_mode_name_by_value(mode) - if mode_name == 'datac1': + if mode_name == "datac1": modem.RECEIVE_DATAC1 = True - structlog.get_logger("structlog").debug("changing listening data mode", mode="datac1") - elif mode_name == 'datac3': + structlog.get_logger("structlog").debug( + "changing listening data mode", mode="datac1" + ) + elif mode_name == "datac3": modem.RECEIVE_DATAC3 = True - structlog.get_logger("structlog").debug("changing listening data mode", mode="datac3") - elif mode_name == 'fsk_ldpc_1': + structlog.get_logger("structlog").debug( + "changing listening data mode", mode="datac3" + ) + elif mode_name == "fsk_ldpc_1": modem.RECEIVE_FSK_LDPC_1 = True - structlog.get_logger("structlog").debug("changing listening data mode", mode="fsk_ldpc_1") - elif mode_name == 'allmodes': + structlog.get_logger("structlog").debug( + "changing listening data mode", mode="fsk_ldpc_1" + ) + elif mode_name == "allmodes": modem.RECEIVE_DATAC1 = True modem.RECEIVE_DATAC3 = True modem.RECEIVE_FSK_LDPC_1 = True - structlog.get_logger("structlog").debug("changing listening data mode", mode="datac1/datac3/fsk_ldpc") - + structlog.get_logger("structlog").debug( + "changing listening data mode", mode="datac1/datac3/fsk_ldpc" + ) # ------------------------- WATCHDOG FUNCTIONS FOR TIMER def watchdog(self): """Author: DJ2LS - + watchdog master function. Frome here we call the watchdogs Args: @@ -1889,106 +2366,131 @@ class DATA(): self.burst_watchdog() self.arq_session_keep_alive_watchdog() - def burst_watchdog(self): """ watchdog which checks if we are running into a connection timeout DATA BURST """ - - # IRS SIDE - if static.ARQ_STATE and static.TNC_STATE == 'BUSY' and self.is_IRS: - if self.data_channel_last_received + self.time_list[self.speed_level] > time.time(): - #print((self.data_channel_last_received + self.time_list[self.speed_level])-time.time()) + + # IRS SIDE + if static.ARQ_STATE and static.TNC_STATE == "BUSY" and self.is_IRS: + if ( + self.data_channel_last_received + self.time_list[self.speed_level] + > time.time() + ): + # print((self.data_channel_last_received + self.time_list[self.speed_level])-time.time()) pass else: - structlog.get_logger("structlog").warning("packet timeout", attempt=self.n_retries_per_burst, max_attempts=self.rx_n_max_retries_per_burst, speed_level=self.speed_level) + structlog.get_logger("structlog").warning( + "packet timeout", + attempt=self.n_retries_per_burst, + max_attempts=self.rx_n_max_retries_per_burst, + speed_level=self.speed_level, + ) self.frame_received_counter = 0 self.burst_nack_counter += 1 if self.burst_nack_counter >= 2: self.speed_level -= 1 - #print(self.burst_nack_counter) - #print(self.speed_level) + # print(self.burst_nack_counter) + # print(self.speed_level) static.ARQ_SPEED_LEVEL = self.speed_level self.burst_nack_counter = 0 if self.speed_level <= 0: self.speed_level = 0 static.ARQ_SPEED_LEVEL = self.speed_level - + # updated modes we are listening to self.set_listening_modes(self.mode_list[self.speed_level]) - + # BUILDING NACK FRAME FOR DATA FRAME - burst_nack_frame = bytearray(14) - burst_nack_frame[:1] = bytes([64]) + burst_nack_frame = bytearray(14) + burst_nack_frame[:1] = bytes([64]) burst_nack_frame[1:3] = static.DXCALLSIGN_CRC - burst_nack_frame[3:5] = static.MYCALLSIGN_CRC + burst_nack_frame[3:5] = static.MYCALLSIGN_CRC burst_nack_frame[5:6] = bytes([0]) burst_nack_frame[6:7] = bytes([int(self.speed_level)]) - + # TRANSMIT NACK FRAME FOR BURST txbuffer = [burst_nack_frame] static.TRANSMITTING = True - modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) + modem.MODEM_TRANSMIT_QUEUE.put([14, 1, 0, txbuffer]) # wait while transmitting - #while static.TRANSMITTING: + # while static.TRANSMITTING: # #time.sleep(0.01) # self.data_channel_last_received = time.time() self.data_channel_last_received = time.time() self.n_retries_per_burst += 1 - + if self.n_retries_per_burst >= self.rx_n_max_retries_per_burst: self.stop_transmission() self.arq_cleanup() - def data_channel_keep_alive_watchdog(self): """ watchdog which checks if we are running into a connection timeout - DATA CHANNEL + DATA CHANNEL """ - + # and not static.ARQ_SEND_KEEP_ALIVE: - if static.ARQ_STATE and static.TNC_STATE == 'BUSY': + if static.ARQ_STATE and static.TNC_STATE == "BUSY": time.sleep(0.01) - if self.data_channel_last_received + self.transmission_timeout > time.time(): + if ( + self.data_channel_last_received + self.transmission_timeout + > time.time() + ): time.sleep(0.01) - #print(self.data_channel_last_received + self.transmission_timeout - time.time()) - #pass + # print(self.data_channel_last_received + self.transmission_timeout - time.time()) + # pass else: self.data_channel_last_received = 0 - structlog.get_logger("structlog").info("DATA [" + str(self.mycallsign, 'utf-8') + "]<>[" + str(static.DXCALLSIGN, 'utf-8') + "]") + structlog.get_logger("structlog").info( + "DATA [" + + str(self.mycallsign, "utf-8") + + "]<>[" + + str(static.DXCALLSIGN, "utf-8") + + "]" + ) static.INFO.append("ARQ;RECEIVING;FAILED") if not TESTMODE: self.arq_cleanup() - + def arq_session_keep_alive_watchdog(self): """ watchdog which checks if we are running into a connection timeout ARQ SESSION """ - if static.ARQ_SESSION and static.TNC_STATE == 'BUSY' and not self.arq_file_transfer: + if ( + static.ARQ_SESSION + and static.TNC_STATE == "BUSY" + and not self.arq_file_transfer + ): if self.arq_session_last_received + self.arq_session_timeout > time.time(): time.sleep(0.01) else: - structlog.get_logger("structlog").info("SESSION [" + str(self.mycallsign, 'utf-8') + "]<>[" + str(static.DXCALLSIGN, 'utf-8') + "]") + structlog.get_logger("structlog").info( + "SESSION [" + + str(self.mycallsign, "utf-8") + + "]<>[" + + str(static.DXCALLSIGN, "utf-8") + + "]" + ) static.INFO.append("ARQ;SESSION;TIMEOUT") self.close_session() - - - + def heartbeat(self): """ heartbeat thread which auto resumes the heartbeat signal within a arq session """ while 1: time.sleep(0.01) - if static.ARQ_SESSION and self.IS_ARQ_SESSION_MASTER and not self.arq_file_transfer: + if ( + static.ARQ_SESSION + and self.IS_ARQ_SESSION_MASTER + and not self.arq_file_transfer + ): time.sleep(1) self.transmit_session_heartbeat() time.sleep(2) - - - + def send_test_frame(self): - modem.MODEM_TRANSMIT_QUEUE.put([12,1,0,[bytearray(126)]]) + modem.MODEM_TRANSMIT_QUEUE.put([12, 1, 0, [bytearray(126)]]) diff --git a/tnc/helpers.py b/tnc/helpers.py index 2d59f272..e628b01a 100644 --- a/tnc/helpers.py +++ b/tnc/helpers.py @@ -11,12 +11,11 @@ import crcengine import static - def wait(seconds): """ Args: - seconds: + seconds: Returns: @@ -26,62 +25,62 @@ def wait(seconds): while time.time() < timeout: time.sleep(0.01) return True - - + def get_crc_8(data): """Author: DJ2LS - + Get the CRC8 of a byte string - + param: data = bytes() Args: - data: + data: Returns: """ - crc_algorithm = crcengine.new('crc8-ccitt') # load crc8 library + crc_algorithm = crcengine.new("crc8-ccitt") # load crc8 library crc_data = crc_algorithm(data) - crc_data = crc_data.to_bytes(1, byteorder='big') + crc_data = crc_data.to_bytes(1, byteorder="big") return crc_data def get_crc_16(data): """Author: DJ2LS - + Get the CRC16 of a byte string - + param: data = bytes() Args: - data: + data: Returns: """ - crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc16 library + crc_algorithm = crcengine.new("crc16-ccitt-false") # load crc16 library crc_data = crc_algorithm(data) - crc_data = crc_data.to_bytes(2, byteorder='big') + crc_data = crc_data.to_bytes(2, byteorder="big") return crc_data + def get_crc_32(data): """Author: DJ2LS - + Get the CRC32 of a byte string - + param: data = bytes() Args: - data: + data: Returns: """ - crc_algorithm = crcengine.new('crc32') # load crc16 library + crc_algorithm = crcengine.new("crc32") # load crc16 library crc_data = crc_algorithm(data) - crc_data = crc_data.to_bytes(4, byteorder='big') + crc_data = crc_data.to_bytes(4, byteorder="big") return crc_data @@ -89,12 +88,12 @@ def add_to_heard_stations(dxcallsign, dxgrid, datatype, snr, offset, frequency): """ Args: - dxcallsign: - dxgrid: - datatype: - snr: - offset: - frequency: + dxcallsign: + dxgrid: + datatype: + snr: + offset: + frequency: Returns: @@ -102,17 +101,37 @@ def add_to_heard_stations(dxcallsign, dxgrid, datatype, snr, offset, frequency): # check if buffer empty if len(static.HEARD_STATIONS) == 0: - static.HEARD_STATIONS.append([dxcallsign, dxgrid, int(time.time()), datatype, snr, offset, frequency]) + static.HEARD_STATIONS.append( + [dxcallsign, dxgrid, int(time.time()), datatype, snr, offset, frequency] + ) # if not, we search and update else: for i in range(0, len(static.HEARD_STATIONS)): # update callsign with new timestamp if static.HEARD_STATIONS[i].count(dxcallsign) > 0: - static.HEARD_STATIONS[i] = [dxcallsign, dxgrid, int(time.time()), datatype, snr, offset, frequency] + static.HEARD_STATIONS[i] = [ + dxcallsign, + dxgrid, + int(time.time()), + datatype, + snr, + offset, + frequency, + ] break # insert if nothing found if i == len(static.HEARD_STATIONS) - 1: - static.HEARD_STATIONS.append([dxcallsign, dxgrid, int(time.time()), datatype, snr, offset, frequency]) + static.HEARD_STATIONS.append( + [ + dxcallsign, + dxgrid, + int(time.time()), + datatype, + snr, + offset, + frequency, + ] + ) break @@ -122,134 +141,132 @@ def add_to_heard_stations(dxcallsign, dxgrid, datatype, snr, offset, frequency): # static.HEARD_STATIONS[idx] = item - def callsign_to_bytes(callsign): """ Args: - callsign: + callsign: Returns: """ # http://www.aprs.org/aprs11/SSIDs.txt - #-0 Your primary station usually fixed and message capable - #-1 generic additional station, digi, mobile, wx, etc - #-2 generic additional station, digi, mobile, wx, etc - #-3 generic additional station, digi, mobile, wx, etc - #-4 generic additional station, digi, mobile, wx, etc - #-5 Other networks (Dstar, Iphones, Androids, Blackberry's etc) - #-6 Special activity, Satellite ops, camping or 6 meters, etc - #-7 walkie talkies, HT's or other human portable - #-8 boats, sailboats, RV's or second main mobile - #-9 Primary Mobile (usually message capable) - #-10 internet, Igates, echolink, winlink, AVRS, APRN, etc - #-11 balloons, aircraft, spacecraft, etc - #-12 APRStt, DTMF, RFID, devices, one-way trackers*, etc - #-13 Weather stations - #-14 Truckers or generally full time drivers - #-15 generic additional station, digi, mobile, wx, etc - + # -0 Your primary station usually fixed and message capable + # -1 generic additional station, digi, mobile, wx, etc + # -2 generic additional station, digi, mobile, wx, etc + # -3 generic additional station, digi, mobile, wx, etc + # -4 generic additional station, digi, mobile, wx, etc + # -5 Other networks (Dstar, Iphones, Androids, Blackberry's etc) + # -6 Special activity, Satellite ops, camping or 6 meters, etc + # -7 walkie talkies, HT's or other human portable + # -8 boats, sailboats, RV's or second main mobile + # -9 Primary Mobile (usually message capable) + # -10 internet, Igates, echolink, winlink, AVRS, APRN, etc + # -11 balloons, aircraft, spacecraft, etc + # -12 APRStt, DTMF, RFID, devices, one-way trackers*, etc + # -13 Weather stations + # -14 Truckers or generally full time drivers + # -15 generic additional station, digi, mobile, wx, etc + # try converting to bytestring if possible type string - try: - callsign = bytes(callsign, 'utf-8') + try: + callsign = bytes(callsign, "utf-8") except: pass - # we need to do this step to reduce the needed paypload by the callsign ( stripping "-" out of the callsign ) - callsign = callsign.split(b'-') + # we need to do this step to reduce the needed paypload by the callsign ( stripping "-" out of the callsign ) + callsign = callsign.split(b"-") try: ssid = int(callsign[1]) except: ssid = 0 - + callsign = callsign[0] - + bytestring = bytearray(8) - bytestring[:len(callsign)] = callsign + bytestring[: len(callsign)] = callsign bytestring[7:8] = bytes([ssid]) - return bytes(bytestring) - + return bytes(bytestring) + + def bytes_to_callsign(bytestring): """ Args: - bytestring: + bytestring: Returns: """ # http://www.aprs.org/aprs11/SSIDs.txt - #-0 Your primary station usually fixed and message capable - #-1 generic additional station, digi, mobile, wx, etc - #-2 generic additional station, digi, mobile, wx, etc - #-3 generic additional station, digi, mobile, wx, etc - #-4 generic additional station, digi, mobile, wx, etc - #-5 Other networks (Dstar, Iphones, Androids, Blackberry's etc) - #-6 Special activity, Satellite ops, camping or 6 meters, etc - #-7 walkie talkies, HT's or other human portable - #-8 boats, sailboats, RV's or second main mobile - #-9 Primary Mobile (usually message capable) - #-10 internet, Igates, echolink, winlink, AVRS, APRN, etc - #-11 balloons, aircraft, spacecraft, etc - #-12 APRStt, DTMF, RFID, devices, one-way trackers*, etc - #-13 Weather stations - #-14 Truckers or generally full time drivers - #-15 generic additional station, digi, mobile, wx, etc - - # we need to do this step to reduce the needed paypload by the callsign ( stripping "-" out of the callsign ) + # -0 Your primary station usually fixed and message capable + # -1 generic additional station, digi, mobile, wx, etc + # -2 generic additional station, digi, mobile, wx, etc + # -3 generic additional station, digi, mobile, wx, etc + # -4 generic additional station, digi, mobile, wx, etc + # -5 Other networks (Dstar, Iphones, Androids, Blackberry's etc) + # -6 Special activity, Satellite ops, camping or 6 meters, etc + # -7 walkie talkies, HT's or other human portable + # -8 boats, sailboats, RV's or second main mobile + # -9 Primary Mobile (usually message capable) + # -10 internet, Igates, echolink, winlink, AVRS, APRN, etc + # -11 balloons, aircraft, spacecraft, etc + # -12 APRStt, DTMF, RFID, devices, one-way trackers*, etc + # -13 Weather stations + # -14 Truckers or generally full time drivers + # -15 generic additional station, digi, mobile, wx, etc + + # we need to do this step to reduce the needed paypload by the callsign ( stripping "-" out of the callsign ) callsign = bytes(bytestring[:7]) - callsign = callsign.rstrip(b'\x00') + callsign = callsign.rstrip(b"\x00") ssid = int.from_bytes(bytes(bytestring[7:8]), "big") - callsign = callsign + b'-' - callsign = callsign.decode('utf-8') + callsign = callsign + b"-" + callsign = callsign.decode("utf-8") callsign = callsign + str(ssid) - callsign = callsign.encode('utf-8') - - return bytes(callsign) + callsign = callsign.encode("utf-8") + + return bytes(callsign) - - -def check_callsign(callsign:bytes, crc_to_check:bytes): +def check_callsign(callsign: bytes, crc_to_check: bytes): """ Funktion to check a crc against a callsign to calculate the ssid by generating crc until we got it Args: callsign: Callsign which we want to check - crc_to_check: The CRC which we want the callsign to check against + crc_to_check: The CRC which we want the callsign to check against Returns: [True, Callsign + SSID] False """ - crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc16 library - + crc_algorithm = crcengine.new("crc16-ccitt-false") # load crc16 library + try: - callsign = callsign.split(b'-') - callsign = callsign[0] # we want the callsign without SSID - + callsign = callsign.split(b"-") + callsign = callsign[0] # we want the callsign without SSID + except: callsign = callsign - + print(static.SSID_LIST) for ssid in static.SSID_LIST: - print(ssid) + print(ssid) for ssid in static.SSID_LIST: - #for ssid in range(0,254): - call_with_ssid = bytearray(callsign) - call_with_ssid.extend('-'.encode('utf-8')) - call_with_ssid.extend(str(ssid).encode('utf-8')) + # for ssid in range(0,254): + call_with_ssid = bytearray(callsign) + call_with_ssid.extend("-".encode("utf-8")) + call_with_ssid.extend(str(ssid).encode("utf-8")) callsign_crc = get_crc_16(call_with_ssid) if callsign_crc == crc_to_check: print(call_with_ssid) return [True, bytes(call_with_ssid)] - + return [False, ""] diff --git a/tnc/lib/hamlib/linux/python3.8/site-packages/Hamlib.py b/tnc/lib/hamlib/linux/python3.8/site-packages/Hamlib.py index b82b545c..bcdaa9e4 100644 --- a/tnc/lib/hamlib/linux/python3.8/site-packages/Hamlib.py +++ b/tnc/lib/hamlib/linux/python3.8/site-packages/Hamlib.py @@ -5,6 +5,7 @@ # the SWIG interface file instead. from sys import version_info as _swig_python_version_info + if _swig_python_version_info < (2, 7, 0): raise RuntimeError("Python 2.7 or later required") @@ -19,12 +20,17 @@ try: except ImportError: import __builtin__ + def _swig_repr(self): try: strthis = "proxy of " + self.this.__repr__() except __builtin__.Exception: strthis = "" - return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + return "<%s.%s; %s >" % ( + self.__class__.__module__, + self.__class__.__name__, + strthis, + ) def _swig_setattr_nondynamic_instance_variable(set): @@ -37,6 +43,7 @@ def _swig_setattr_nondynamic_instance_variable(set): set(self, name, value) else: raise AttributeError("You cannot add instance attributes to %s" % self) + return set_instance_attr @@ -46,18 +53,22 @@ def _swig_setattr_nondynamic_class_variable(set): set(cls, name, value) else: raise AttributeError("You cannot add class attributes to %s" % cls) + return set_class_attr def _swig_add_metaclass(metaclass): """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass""" + def wrapper(cls): return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy()) + return wrapper class _SwigNonDynamicMeta(type): """Meta class to enforce nondynamic attributes (no new attributes) for a class""" + __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__) @@ -599,8 +610,12 @@ RIG_CONF_BUTTON = _Hamlib.RIG_CONF_BUTTON RIG_CONF_BINARY = _Hamlib.RIG_CONF_BINARY RIG_COMBO_MAX = _Hamlib.RIG_COMBO_MAX RIG_BIN_MAX = _Hamlib.RIG_BIN_MAX + + class confparams(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr token = property(_Hamlib.confparams_token_get, _Hamlib.confparams_token_set) name = property(_Hamlib.confparams_name_get) @@ -612,41 +627,58 @@ class confparams(object): def __init__(self): _Hamlib.confparams_swiginit(self, _Hamlib.new_confparams()) + __swig_destroy__ = _Hamlib.delete_confparams + # Register confparams in _Hamlib: _Hamlib.confparams_swigregister(confparams) cvar = _Hamlib.cvar hamlib_version = cvar.hamlib_version hamlib_copyright = cvar.hamlib_copyright + class confparams_u(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr n = property(_Hamlib.confparams_u_n_get) c = property(_Hamlib.confparams_u_c_get) def __init__(self): _Hamlib.confparams_u_swiginit(self, _Hamlib.new_confparams_u()) + __swig_destroy__ = _Hamlib.delete_confparams_u + # Register confparams_u in _Hamlib: _Hamlib.confparams_u_swigregister(confparams_u) + class confparams_u_c(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - combostr = property(_Hamlib.confparams_u_c_combostr_get, _Hamlib.confparams_u_c_combostr_set) + combostr = property( + _Hamlib.confparams_u_c_combostr_get, _Hamlib.confparams_u_c_combostr_set + ) def __init__(self): _Hamlib.confparams_u_c_swiginit(self, _Hamlib.new_confparams_u_c()) + __swig_destroy__ = _Hamlib.delete_confparams_u_c + # Register confparams_u_c in _Hamlib: _Hamlib.confparams_u_c_swigregister(confparams_u_c) + class confparams_u_n(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr min = property(_Hamlib.confparams_u_n_min_get, _Hamlib.confparams_u_n_min_set) max = property(_Hamlib.confparams_u_n_max_get, _Hamlib.confparams_u_n_max_set) @@ -654,8 +686,10 @@ class confparams_u_n(object): def __init__(self): _Hamlib.confparams_u_n_swiginit(self, _Hamlib.new_confparams_u_n()) + __swig_destroy__ = _Hamlib.delete_confparams_u_n + # Register confparams_u_n in _Hamlib: _Hamlib.confparams_u_n_swigregister(confparams_u_n) @@ -684,8 +718,12 @@ RIG_METER_DB = _Hamlib.RIG_METER_DB RIG_METER_PO = _Hamlib.RIG_METER_PO RIG_METER_VDD = _Hamlib.RIG_METER_VDD RIG_METER_TEMP = _Hamlib.RIG_METER_TEMP + + class value_t(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr i = property(_Hamlib.value_t_i_get, _Hamlib.value_t_i_set) f = property(_Hamlib.value_t_f_get, _Hamlib.value_t_f_set) @@ -695,21 +733,28 @@ class value_t(object): def __init__(self): _Hamlib.value_t_swiginit(self, _Hamlib.new_value_t()) + __swig_destroy__ = _Hamlib.delete_value_t + # Register value_t in _Hamlib: _Hamlib.value_t_swigregister(value_t) + class value_t_b(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr l = property(_Hamlib.value_t_b_l_get, _Hamlib.value_t_b_l_set) d = property(_Hamlib.value_t_b_d_get, _Hamlib.value_t_b_d_set) def __init__(self): _Hamlib.value_t_b_swiginit(self, _Hamlib.new_value_t_b()) + __swig_destroy__ = _Hamlib.delete_value_t_b + # Register value_t_b in _Hamlib: _Hamlib.value_t_b_swigregister(value_t_b) @@ -930,49 +975,72 @@ RIG_MODE_TESTS_MAX = _Hamlib.RIG_MODE_TESTS_MAX RIG_MODE_SSB = _Hamlib.RIG_MODE_SSB RIG_MODE_ECSS = _Hamlib.RIG_MODE_ECSS RIG_DBLST_END = _Hamlib.RIG_DBLST_END + + class freq_range_t(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr startf = property(_Hamlib.freq_range_t_startf_get, _Hamlib.freq_range_t_startf_set) endf = property(_Hamlib.freq_range_t_endf_get, _Hamlib.freq_range_t_endf_set) modes = property(_Hamlib.freq_range_t_modes_get, _Hamlib.freq_range_t_modes_set) - low_power = property(_Hamlib.freq_range_t_low_power_get, _Hamlib.freq_range_t_low_power_set) - high_power = property(_Hamlib.freq_range_t_high_power_get, _Hamlib.freq_range_t_high_power_set) + low_power = property( + _Hamlib.freq_range_t_low_power_get, _Hamlib.freq_range_t_low_power_set + ) + high_power = property( + _Hamlib.freq_range_t_high_power_get, _Hamlib.freq_range_t_high_power_set + ) vfo = property(_Hamlib.freq_range_t_vfo_get, _Hamlib.freq_range_t_vfo_set) ant = property(_Hamlib.freq_range_t_ant_get, _Hamlib.freq_range_t_ant_set) label = property(_Hamlib.freq_range_t_label_get, _Hamlib.freq_range_t_label_set) def __init__(self): _Hamlib.freq_range_t_swiginit(self, _Hamlib.new_freq_range_t()) + __swig_destroy__ = _Hamlib.delete_freq_range_t + # Register freq_range_t in _Hamlib: _Hamlib.freq_range_t_swigregister(freq_range_t) + class tuning_step_list(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - modes = property(_Hamlib.tuning_step_list_modes_get, _Hamlib.tuning_step_list_modes_set) + modes = property( + _Hamlib.tuning_step_list_modes_get, _Hamlib.tuning_step_list_modes_set + ) ts = property(_Hamlib.tuning_step_list_ts_get, _Hamlib.tuning_step_list_ts_set) def __init__(self): _Hamlib.tuning_step_list_swiginit(self, _Hamlib.new_tuning_step_list()) + __swig_destroy__ = _Hamlib.delete_tuning_step_list + # Register tuning_step_list in _Hamlib: _Hamlib.tuning_step_list_swigregister(tuning_step_list) RIG_TS_ANY = _Hamlib.RIG_TS_ANY + + class filter_list(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr modes = property(_Hamlib.filter_list_modes_get, _Hamlib.filter_list_modes_set) width = property(_Hamlib.filter_list_width_get, _Hamlib.filter_list_width_set) def __init__(self): _Hamlib.filter_list_swiginit(self, _Hamlib.new_filter_list()) + __swig_destroy__ = _Hamlib.delete_filter_list + # Register filter_list in _Hamlib: _Hamlib.filter_list_swigregister(filter_list) @@ -981,23 +1049,34 @@ RIG_CHFLAG_NONE = _Hamlib.RIG_CHFLAG_NONE RIG_CHFLAG_SKIP = _Hamlib.RIG_CHFLAG_SKIP RIG_CHFLAG_DATA = _Hamlib.RIG_CHFLAG_DATA RIG_CHFLAG_PSKIP = _Hamlib.RIG_CHFLAG_PSKIP + + class ext_list(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr token = property(_Hamlib.ext_list_token_get, _Hamlib.ext_list_token_set) val = property(_Hamlib.ext_list_val_get, _Hamlib.ext_list_val_set) def __init__(self): _Hamlib.ext_list_swiginit(self, _Hamlib.new_ext_list()) + __swig_destroy__ = _Hamlib.delete_ext_list + # Register ext_list in _Hamlib: _Hamlib.ext_list_swigregister(ext_list) + class channel(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - channel_num = property(_Hamlib.channel_channel_num_get, _Hamlib.channel_channel_num_set) + channel_num = property( + _Hamlib.channel_channel_num_get, _Hamlib.channel_channel_num_set + ) bank_num = property(_Hamlib.channel_bank_num_get, _Hamlib.channel_bank_num_set) vfo = property(_Hamlib.channel_vfo_get, _Hamlib.channel_vfo_set) ant = property(_Hamlib.channel_ant_get, _Hamlib.channel_ant_set) @@ -1009,33 +1088,52 @@ class channel(object): tx_width = property(_Hamlib.channel_tx_width_get, _Hamlib.channel_tx_width_set) split = property(_Hamlib.channel_split_get, _Hamlib.channel_split_set) tx_vfo = property(_Hamlib.channel_tx_vfo_get, _Hamlib.channel_tx_vfo_set) - rptr_shift = property(_Hamlib.channel_rptr_shift_get, _Hamlib.channel_rptr_shift_set) + rptr_shift = property( + _Hamlib.channel_rptr_shift_get, _Hamlib.channel_rptr_shift_set + ) rptr_offs = property(_Hamlib.channel_rptr_offs_get, _Hamlib.channel_rptr_offs_set) - tuning_step = property(_Hamlib.channel_tuning_step_get, _Hamlib.channel_tuning_step_set) + tuning_step = property( + _Hamlib.channel_tuning_step_get, _Hamlib.channel_tuning_step_set + ) rit = property(_Hamlib.channel_rit_get, _Hamlib.channel_rit_set) xit = property(_Hamlib.channel_xit_get, _Hamlib.channel_xit_set) funcs = property(_Hamlib.channel_funcs_get, _Hamlib.channel_funcs_set) levels = property(_Hamlib.channel_levels_get, _Hamlib.channel_levels_set) - ctcss_tone = property(_Hamlib.channel_ctcss_tone_get, _Hamlib.channel_ctcss_tone_set) + ctcss_tone = property( + _Hamlib.channel_ctcss_tone_get, _Hamlib.channel_ctcss_tone_set + ) ctcss_sql = property(_Hamlib.channel_ctcss_sql_get, _Hamlib.channel_ctcss_sql_set) dcs_code = property(_Hamlib.channel_dcs_code_get, _Hamlib.channel_dcs_code_set) dcs_sql = property(_Hamlib.channel_dcs_sql_get, _Hamlib.channel_dcs_sql_set) - scan_group = property(_Hamlib.channel_scan_group_get, _Hamlib.channel_scan_group_set) + scan_group = property( + _Hamlib.channel_scan_group_get, _Hamlib.channel_scan_group_set + ) flags = property(_Hamlib.channel_flags_get, _Hamlib.channel_flags_set) - channel_desc = property(_Hamlib.channel_channel_desc_get, _Hamlib.channel_channel_desc_set) - ext_levels = property(_Hamlib.channel_ext_levels_get, _Hamlib.channel_ext_levels_set) + channel_desc = property( + _Hamlib.channel_channel_desc_get, _Hamlib.channel_channel_desc_set + ) + ext_levels = property( + _Hamlib.channel_ext_levels_get, _Hamlib.channel_ext_levels_set + ) def __init__(self, *args): _Hamlib.channel_swiginit(self, _Hamlib.new_channel(*args)) + __swig_destroy__ = _Hamlib.delete_channel + # Register channel in _Hamlib: _Hamlib.channel_swigregister(channel) + class channel_cap(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - bank_num = property(_Hamlib.channel_cap_bank_num_get, _Hamlib.channel_cap_bank_num_set) + bank_num = property( + _Hamlib.channel_cap_bank_num_get, _Hamlib.channel_cap_bank_num_set + ) vfo = property(_Hamlib.channel_cap_vfo_get, _Hamlib.channel_cap_vfo_set) ant = property(_Hamlib.channel_cap_ant_get, _Hamlib.channel_cap_ant_set) freq = property(_Hamlib.channel_cap_freq_get, _Hamlib.channel_cap_freq_set) @@ -1043,29 +1141,51 @@ class channel_cap(object): width = property(_Hamlib.channel_cap_width_get, _Hamlib.channel_cap_width_set) tx_freq = property(_Hamlib.channel_cap_tx_freq_get, _Hamlib.channel_cap_tx_freq_set) tx_mode = property(_Hamlib.channel_cap_tx_mode_get, _Hamlib.channel_cap_tx_mode_set) - tx_width = property(_Hamlib.channel_cap_tx_width_get, _Hamlib.channel_cap_tx_width_set) + tx_width = property( + _Hamlib.channel_cap_tx_width_get, _Hamlib.channel_cap_tx_width_set + ) split = property(_Hamlib.channel_cap_split_get, _Hamlib.channel_cap_split_set) tx_vfo = property(_Hamlib.channel_cap_tx_vfo_get, _Hamlib.channel_cap_tx_vfo_set) - rptr_shift = property(_Hamlib.channel_cap_rptr_shift_get, _Hamlib.channel_cap_rptr_shift_set) - rptr_offs = property(_Hamlib.channel_cap_rptr_offs_get, _Hamlib.channel_cap_rptr_offs_set) - tuning_step = property(_Hamlib.channel_cap_tuning_step_get, _Hamlib.channel_cap_tuning_step_set) + rptr_shift = property( + _Hamlib.channel_cap_rptr_shift_get, _Hamlib.channel_cap_rptr_shift_set + ) + rptr_offs = property( + _Hamlib.channel_cap_rptr_offs_get, _Hamlib.channel_cap_rptr_offs_set + ) + tuning_step = property( + _Hamlib.channel_cap_tuning_step_get, _Hamlib.channel_cap_tuning_step_set + ) rit = property(_Hamlib.channel_cap_rit_get, _Hamlib.channel_cap_rit_set) xit = property(_Hamlib.channel_cap_xit_get, _Hamlib.channel_cap_xit_set) funcs = property(_Hamlib.channel_cap_funcs_get, _Hamlib.channel_cap_funcs_set) levels = property(_Hamlib.channel_cap_levels_get, _Hamlib.channel_cap_levels_set) - ctcss_tone = property(_Hamlib.channel_cap_ctcss_tone_get, _Hamlib.channel_cap_ctcss_tone_set) - ctcss_sql = property(_Hamlib.channel_cap_ctcss_sql_get, _Hamlib.channel_cap_ctcss_sql_set) - dcs_code = property(_Hamlib.channel_cap_dcs_code_get, _Hamlib.channel_cap_dcs_code_set) + ctcss_tone = property( + _Hamlib.channel_cap_ctcss_tone_get, _Hamlib.channel_cap_ctcss_tone_set + ) + ctcss_sql = property( + _Hamlib.channel_cap_ctcss_sql_get, _Hamlib.channel_cap_ctcss_sql_set + ) + dcs_code = property( + _Hamlib.channel_cap_dcs_code_get, _Hamlib.channel_cap_dcs_code_set + ) dcs_sql = property(_Hamlib.channel_cap_dcs_sql_get, _Hamlib.channel_cap_dcs_sql_set) - scan_group = property(_Hamlib.channel_cap_scan_group_get, _Hamlib.channel_cap_scan_group_set) + scan_group = property( + _Hamlib.channel_cap_scan_group_get, _Hamlib.channel_cap_scan_group_set + ) flags = property(_Hamlib.channel_cap_flags_get, _Hamlib.channel_cap_flags_set) - channel_desc = property(_Hamlib.channel_cap_channel_desc_get, _Hamlib.channel_cap_channel_desc_set) - ext_levels = property(_Hamlib.channel_cap_ext_levels_get, _Hamlib.channel_cap_ext_levels_set) + channel_desc = property( + _Hamlib.channel_cap_channel_desc_get, _Hamlib.channel_cap_channel_desc_set + ) + ext_levels = property( + _Hamlib.channel_cap_ext_levels_get, _Hamlib.channel_cap_ext_levels_set + ) def __init__(self): _Hamlib.channel_cap_swiginit(self, _Hamlib.new_channel_cap()) + __swig_destroy__ = _Hamlib.delete_channel_cap + # Register channel_cap in _Hamlib: _Hamlib.channel_cap_swigregister(channel_cap) @@ -1077,8 +1197,12 @@ RIG_MTYPE_MEMOPAD = _Hamlib.RIG_MTYPE_MEMOPAD RIG_MTYPE_SAT = _Hamlib.RIG_MTYPE_SAT RIG_MTYPE_BAND = _Hamlib.RIG_MTYPE_BAND RIG_MTYPE_PRIO = _Hamlib.RIG_MTYPE_PRIO + + class chan_list(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr startc = property(_Hamlib.chan_list_startc_get, _Hamlib.chan_list_startc_set) endc = property(_Hamlib.chan_list_endc_get, _Hamlib.chan_list_endc_set) @@ -1087,14 +1211,20 @@ class chan_list(object): def __init__(self): _Hamlib.chan_list_swiginit(self, _Hamlib.new_chan_list()) + __swig_destroy__ = _Hamlib.delete_chan_list + # Register chan_list in _Hamlib: _Hamlib.chan_list_swigregister(chan_list) RIG_MEM_CAPS_ALL = _Hamlib.RIG_MEM_CAPS_ALL + + class gran(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr min = property(_Hamlib.gran_min_get, _Hamlib.gran_min_set) max = property(_Hamlib.gran_max_get, _Hamlib.gran_max_set) @@ -1102,73 +1232,108 @@ class gran(object): def __init__(self): _Hamlib.gran_swiginit(self, _Hamlib.new_gran()) + __swig_destroy__ = _Hamlib.delete_gran + # Register gran in _Hamlib: _Hamlib.gran_swigregister(gran) + class cal_table(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr size = property(_Hamlib.cal_table_size_get, _Hamlib.cal_table_size_set) table = property(_Hamlib.cal_table_table_get) def __init__(self): _Hamlib.cal_table_swiginit(self, _Hamlib.new_cal_table()) + __swig_destroy__ = _Hamlib.delete_cal_table + # Register cal_table in _Hamlib: _Hamlib.cal_table_swigregister(cal_table) + class cal_table_table(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr raw = property(_Hamlib.cal_table_table_raw_get, _Hamlib.cal_table_table_raw_set) val = property(_Hamlib.cal_table_table_val_get, _Hamlib.cal_table_table_val_set) def __init__(self): _Hamlib.cal_table_table_swiginit(self, _Hamlib.new_cal_table_table()) + __swig_destroy__ = _Hamlib.delete_cal_table_table + # Register cal_table_table in _Hamlib: _Hamlib.cal_table_table_swigregister(cal_table_table) + class cal_table_float(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr size = property(_Hamlib.cal_table_float_size_get, _Hamlib.cal_table_float_size_set) table = property(_Hamlib.cal_table_float_table_get) def __init__(self): _Hamlib.cal_table_float_swiginit(self, _Hamlib.new_cal_table_float()) + __swig_destroy__ = _Hamlib.delete_cal_table_float + # Register cal_table_float in _Hamlib: _Hamlib.cal_table_float_swigregister(cal_table_float) + class cal_table_float_table(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - raw = property(_Hamlib.cal_table_float_table_raw_get, _Hamlib.cal_table_float_table_raw_set) - val = property(_Hamlib.cal_table_float_table_val_get, _Hamlib.cal_table_float_table_val_set) + raw = property( + _Hamlib.cal_table_float_table_raw_get, _Hamlib.cal_table_float_table_raw_set + ) + val = property( + _Hamlib.cal_table_float_table_val_get, _Hamlib.cal_table_float_table_val_set + ) def __init__(self): - _Hamlib.cal_table_float_table_swiginit(self, _Hamlib.new_cal_table_float_table()) + _Hamlib.cal_table_float_table_swiginit( + self, _Hamlib.new_cal_table_float_table() + ) + __swig_destroy__ = _Hamlib.delete_cal_table_float_table + # Register cal_table_float_table in _Hamlib: _Hamlib.cal_table_float_table_swigregister(cal_table_float_table) + class rig_spectrum_scope(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr id = property(_Hamlib.rig_spectrum_scope_id_get, _Hamlib.rig_spectrum_scope_id_set) - name = property(_Hamlib.rig_spectrum_scope_name_get, _Hamlib.rig_spectrum_scope_name_set) + name = property( + _Hamlib.rig_spectrum_scope_name_get, _Hamlib.rig_spectrum_scope_name_set + ) def __init__(self): _Hamlib.rig_spectrum_scope_swiginit(self, _Hamlib.new_rig_spectrum_scope()) + __swig_destroy__ = _Hamlib.delete_rig_spectrum_scope + # Register rig_spectrum_scope in _Hamlib: _Hamlib.rig_spectrum_scope_swigregister(rig_spectrum_scope) @@ -1177,44 +1342,96 @@ RIG_SPECTRUM_MODE_CENTER = _Hamlib.RIG_SPECTRUM_MODE_CENTER RIG_SPECTRUM_MODE_FIXED = _Hamlib.RIG_SPECTRUM_MODE_FIXED RIG_SPECTRUM_MODE_CENTER_SCROLL = _Hamlib.RIG_SPECTRUM_MODE_CENTER_SCROLL RIG_SPECTRUM_MODE_FIXED_SCROLL = _Hamlib.RIG_SPECTRUM_MODE_FIXED_SCROLL + + class rig_spectrum_avg_mode(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - id = property(_Hamlib.rig_spectrum_avg_mode_id_get, _Hamlib.rig_spectrum_avg_mode_id_set) - name = property(_Hamlib.rig_spectrum_avg_mode_name_get, _Hamlib.rig_spectrum_avg_mode_name_set) + id = property( + _Hamlib.rig_spectrum_avg_mode_id_get, _Hamlib.rig_spectrum_avg_mode_id_set + ) + name = property( + _Hamlib.rig_spectrum_avg_mode_name_get, _Hamlib.rig_spectrum_avg_mode_name_set + ) def __init__(self): - _Hamlib.rig_spectrum_avg_mode_swiginit(self, _Hamlib.new_rig_spectrum_avg_mode()) + _Hamlib.rig_spectrum_avg_mode_swiginit( + self, _Hamlib.new_rig_spectrum_avg_mode() + ) + __swig_destroy__ = _Hamlib.delete_rig_spectrum_avg_mode + # Register rig_spectrum_avg_mode in _Hamlib: _Hamlib.rig_spectrum_avg_mode_swigregister(rig_spectrum_avg_mode) + class rig_spectrum_line(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr id = property(_Hamlib.rig_spectrum_line_id_get, _Hamlib.rig_spectrum_line_id_set) - data_level_min = property(_Hamlib.rig_spectrum_line_data_level_min_get, _Hamlib.rig_spectrum_line_data_level_min_set) - data_level_max = property(_Hamlib.rig_spectrum_line_data_level_max_get, _Hamlib.rig_spectrum_line_data_level_max_set) - signal_strength_min = property(_Hamlib.rig_spectrum_line_signal_strength_min_get, _Hamlib.rig_spectrum_line_signal_strength_min_set) - signal_strength_max = property(_Hamlib.rig_spectrum_line_signal_strength_max_get, _Hamlib.rig_spectrum_line_signal_strength_max_set) - spectrum_mode = property(_Hamlib.rig_spectrum_line_spectrum_mode_get, _Hamlib.rig_spectrum_line_spectrum_mode_set) - center_freq = property(_Hamlib.rig_spectrum_line_center_freq_get, _Hamlib.rig_spectrum_line_center_freq_set) - span_freq = property(_Hamlib.rig_spectrum_line_span_freq_get, _Hamlib.rig_spectrum_line_span_freq_set) - low_edge_freq = property(_Hamlib.rig_spectrum_line_low_edge_freq_get, _Hamlib.rig_spectrum_line_low_edge_freq_set) - high_edge_freq = property(_Hamlib.rig_spectrum_line_high_edge_freq_get, _Hamlib.rig_spectrum_line_high_edge_freq_set) - spectrum_data_length = property(_Hamlib.rig_spectrum_line_spectrum_data_length_get, _Hamlib.rig_spectrum_line_spectrum_data_length_set) - spectrum_data = property(_Hamlib.rig_spectrum_line_spectrum_data_get, _Hamlib.rig_spectrum_line_spectrum_data_set) + data_level_min = property( + _Hamlib.rig_spectrum_line_data_level_min_get, + _Hamlib.rig_spectrum_line_data_level_min_set, + ) + data_level_max = property( + _Hamlib.rig_spectrum_line_data_level_max_get, + _Hamlib.rig_spectrum_line_data_level_max_set, + ) + signal_strength_min = property( + _Hamlib.rig_spectrum_line_signal_strength_min_get, + _Hamlib.rig_spectrum_line_signal_strength_min_set, + ) + signal_strength_max = property( + _Hamlib.rig_spectrum_line_signal_strength_max_get, + _Hamlib.rig_spectrum_line_signal_strength_max_set, + ) + spectrum_mode = property( + _Hamlib.rig_spectrum_line_spectrum_mode_get, + _Hamlib.rig_spectrum_line_spectrum_mode_set, + ) + center_freq = property( + _Hamlib.rig_spectrum_line_center_freq_get, + _Hamlib.rig_spectrum_line_center_freq_set, + ) + span_freq = property( + _Hamlib.rig_spectrum_line_span_freq_get, _Hamlib.rig_spectrum_line_span_freq_set + ) + low_edge_freq = property( + _Hamlib.rig_spectrum_line_low_edge_freq_get, + _Hamlib.rig_spectrum_line_low_edge_freq_set, + ) + high_edge_freq = property( + _Hamlib.rig_spectrum_line_high_edge_freq_get, + _Hamlib.rig_spectrum_line_high_edge_freq_set, + ) + spectrum_data_length = property( + _Hamlib.rig_spectrum_line_spectrum_data_length_get, + _Hamlib.rig_spectrum_line_spectrum_data_length_set, + ) + spectrum_data = property( + _Hamlib.rig_spectrum_line_spectrum_data_get, + _Hamlib.rig_spectrum_line_spectrum_data_set, + ) def __init__(self): _Hamlib.rig_spectrum_line_swiginit(self, _Hamlib.new_rig_spectrum_line()) + __swig_destroy__ = _Hamlib.delete_rig_spectrum_line + # Register rig_spectrum_line in _Hamlib: _Hamlib.rig_spectrum_line_swigregister(rig_spectrum_line) + class rig_caps(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr rig_model = property(_Hamlib.rig_caps_rig_model_get, _Hamlib.rig_caps_rig_model_set) model_name = property(_Hamlib.rig_caps_model_name_get) @@ -1226,69 +1443,158 @@ class rig_caps(object): ptt_type = property(_Hamlib.rig_caps_ptt_type_get, _Hamlib.rig_caps_ptt_type_set) dcd_type = property(_Hamlib.rig_caps_dcd_type_get, _Hamlib.rig_caps_dcd_type_set) port_type = property(_Hamlib.rig_caps_port_type_get, _Hamlib.rig_caps_port_type_set) - serial_rate_min = property(_Hamlib.rig_caps_serial_rate_min_get, _Hamlib.rig_caps_serial_rate_min_set) - serial_rate_max = property(_Hamlib.rig_caps_serial_rate_max_get, _Hamlib.rig_caps_serial_rate_max_set) - serial_data_bits = property(_Hamlib.rig_caps_serial_data_bits_get, _Hamlib.rig_caps_serial_data_bits_set) - serial_stop_bits = property(_Hamlib.rig_caps_serial_stop_bits_get, _Hamlib.rig_caps_serial_stop_bits_set) - serial_parity = property(_Hamlib.rig_caps_serial_parity_get, _Hamlib.rig_caps_serial_parity_set) - serial_handshake = property(_Hamlib.rig_caps_serial_handshake_get, _Hamlib.rig_caps_serial_handshake_set) - write_delay = property(_Hamlib.rig_caps_write_delay_get, _Hamlib.rig_caps_write_delay_set) - post_write_delay = property(_Hamlib.rig_caps_post_write_delay_get, _Hamlib.rig_caps_post_write_delay_set) + serial_rate_min = property( + _Hamlib.rig_caps_serial_rate_min_get, _Hamlib.rig_caps_serial_rate_min_set + ) + serial_rate_max = property( + _Hamlib.rig_caps_serial_rate_max_get, _Hamlib.rig_caps_serial_rate_max_set + ) + serial_data_bits = property( + _Hamlib.rig_caps_serial_data_bits_get, _Hamlib.rig_caps_serial_data_bits_set + ) + serial_stop_bits = property( + _Hamlib.rig_caps_serial_stop_bits_get, _Hamlib.rig_caps_serial_stop_bits_set + ) + serial_parity = property( + _Hamlib.rig_caps_serial_parity_get, _Hamlib.rig_caps_serial_parity_set + ) + serial_handshake = property( + _Hamlib.rig_caps_serial_handshake_get, _Hamlib.rig_caps_serial_handshake_set + ) + write_delay = property( + _Hamlib.rig_caps_write_delay_get, _Hamlib.rig_caps_write_delay_set + ) + post_write_delay = property( + _Hamlib.rig_caps_post_write_delay_get, _Hamlib.rig_caps_post_write_delay_set + ) timeout = property(_Hamlib.rig_caps_timeout_get, _Hamlib.rig_caps_timeout_set) retry = property(_Hamlib.rig_caps_retry_get, _Hamlib.rig_caps_retry_set) - has_get_func = property(_Hamlib.rig_caps_has_get_func_get, _Hamlib.rig_caps_has_get_func_set) - has_set_func = property(_Hamlib.rig_caps_has_set_func_get, _Hamlib.rig_caps_has_set_func_set) - has_get_level = property(_Hamlib.rig_caps_has_get_level_get, _Hamlib.rig_caps_has_get_level_set) - has_set_level = property(_Hamlib.rig_caps_has_set_level_get, _Hamlib.rig_caps_has_set_level_set) - has_get_parm = property(_Hamlib.rig_caps_has_get_parm_get, _Hamlib.rig_caps_has_get_parm_set) - has_set_parm = property(_Hamlib.rig_caps_has_set_parm_get, _Hamlib.rig_caps_has_set_parm_set) - level_gran = property(_Hamlib.rig_caps_level_gran_get, _Hamlib.rig_caps_level_gran_set) + has_get_func = property( + _Hamlib.rig_caps_has_get_func_get, _Hamlib.rig_caps_has_get_func_set + ) + has_set_func = property( + _Hamlib.rig_caps_has_set_func_get, _Hamlib.rig_caps_has_set_func_set + ) + has_get_level = property( + _Hamlib.rig_caps_has_get_level_get, _Hamlib.rig_caps_has_get_level_set + ) + has_set_level = property( + _Hamlib.rig_caps_has_set_level_get, _Hamlib.rig_caps_has_set_level_set + ) + has_get_parm = property( + _Hamlib.rig_caps_has_get_parm_get, _Hamlib.rig_caps_has_get_parm_set + ) + has_set_parm = property( + _Hamlib.rig_caps_has_set_parm_get, _Hamlib.rig_caps_has_set_parm_set + ) + level_gran = property( + _Hamlib.rig_caps_level_gran_get, _Hamlib.rig_caps_level_gran_set + ) parm_gran = property(_Hamlib.rig_caps_parm_gran_get, _Hamlib.rig_caps_parm_gran_set) extparms = property(_Hamlib.rig_caps_extparms_get, _Hamlib.rig_caps_extparms_set) extlevels = property(_Hamlib.rig_caps_extlevels_get, _Hamlib.rig_caps_extlevels_set) extfuncs = property(_Hamlib.rig_caps_extfuncs_get, _Hamlib.rig_caps_extfuncs_set) - ext_tokens = property(_Hamlib.rig_caps_ext_tokens_get, _Hamlib.rig_caps_ext_tokens_set) - ctcss_list = property(_Hamlib.rig_caps_ctcss_list_get, _Hamlib.rig_caps_ctcss_list_set) + ext_tokens = property( + _Hamlib.rig_caps_ext_tokens_get, _Hamlib.rig_caps_ext_tokens_set + ) + ctcss_list = property( + _Hamlib.rig_caps_ctcss_list_get, _Hamlib.rig_caps_ctcss_list_set + ) dcs_list = property(_Hamlib.rig_caps_dcs_list_get, _Hamlib.rig_caps_dcs_list_set) preamp = property(_Hamlib.rig_caps_preamp_get, _Hamlib.rig_caps_preamp_set) - attenuator = property(_Hamlib.rig_caps_attenuator_get, _Hamlib.rig_caps_attenuator_set) + attenuator = property( + _Hamlib.rig_caps_attenuator_get, _Hamlib.rig_caps_attenuator_set + ) max_rit = property(_Hamlib.rig_caps_max_rit_get, _Hamlib.rig_caps_max_rit_set) max_xit = property(_Hamlib.rig_caps_max_xit_get, _Hamlib.rig_caps_max_xit_set) - max_ifshift = property(_Hamlib.rig_caps_max_ifshift_get, _Hamlib.rig_caps_max_ifshift_set) - agc_level_count = property(_Hamlib.rig_caps_agc_level_count_get, _Hamlib.rig_caps_agc_level_count_set) - agc_levels = property(_Hamlib.rig_caps_agc_levels_get, _Hamlib.rig_caps_agc_levels_set) + max_ifshift = property( + _Hamlib.rig_caps_max_ifshift_get, _Hamlib.rig_caps_max_ifshift_set + ) + agc_level_count = property( + _Hamlib.rig_caps_agc_level_count_get, _Hamlib.rig_caps_agc_level_count_set + ) + agc_levels = property( + _Hamlib.rig_caps_agc_levels_get, _Hamlib.rig_caps_agc_levels_set + ) announces = property(_Hamlib.rig_caps_announces_get, _Hamlib.rig_caps_announces_set) vfo_ops = property(_Hamlib.rig_caps_vfo_ops_get, _Hamlib.rig_caps_vfo_ops_set) scan_ops = property(_Hamlib.rig_caps_scan_ops_get, _Hamlib.rig_caps_scan_ops_set) - targetable_vfo = property(_Hamlib.rig_caps_targetable_vfo_get, _Hamlib.rig_caps_targetable_vfo_set) - transceive = property(_Hamlib.rig_caps_transceive_get, _Hamlib.rig_caps_transceive_set) + targetable_vfo = property( + _Hamlib.rig_caps_targetable_vfo_get, _Hamlib.rig_caps_targetable_vfo_set + ) + transceive = property( + _Hamlib.rig_caps_transceive_get, _Hamlib.rig_caps_transceive_set + ) bank_qty = property(_Hamlib.rig_caps_bank_qty_get, _Hamlib.rig_caps_bank_qty_set) - chan_desc_sz = property(_Hamlib.rig_caps_chan_desc_sz_get, _Hamlib.rig_caps_chan_desc_sz_set) + chan_desc_sz = property( + _Hamlib.rig_caps_chan_desc_sz_get, _Hamlib.rig_caps_chan_desc_sz_set + ) chan_list = property(_Hamlib.rig_caps_chan_list_get, _Hamlib.rig_caps_chan_list_set) - rx_range_list1 = property(_Hamlib.rig_caps_rx_range_list1_get, _Hamlib.rig_caps_rx_range_list1_set) - tx_range_list1 = property(_Hamlib.rig_caps_tx_range_list1_get, _Hamlib.rig_caps_tx_range_list1_set) - rx_range_list2 = property(_Hamlib.rig_caps_rx_range_list2_get, _Hamlib.rig_caps_rx_range_list2_set) - tx_range_list2 = property(_Hamlib.rig_caps_tx_range_list2_get, _Hamlib.rig_caps_tx_range_list2_set) - rx_range_list3 = property(_Hamlib.rig_caps_rx_range_list3_get, _Hamlib.rig_caps_rx_range_list3_set) - tx_range_list3 = property(_Hamlib.rig_caps_tx_range_list3_get, _Hamlib.rig_caps_tx_range_list3_set) - rx_range_list4 = property(_Hamlib.rig_caps_rx_range_list4_get, _Hamlib.rig_caps_rx_range_list4_set) - tx_range_list4 = property(_Hamlib.rig_caps_tx_range_list4_get, _Hamlib.rig_caps_tx_range_list4_set) - rx_range_list5 = property(_Hamlib.rig_caps_rx_range_list5_get, _Hamlib.rig_caps_rx_range_list5_set) - tx_range_list5 = property(_Hamlib.rig_caps_tx_range_list5_get, _Hamlib.rig_caps_tx_range_list5_set) - tuning_steps = property(_Hamlib.rig_caps_tuning_steps_get, _Hamlib.rig_caps_tuning_steps_set) + rx_range_list1 = property( + _Hamlib.rig_caps_rx_range_list1_get, _Hamlib.rig_caps_rx_range_list1_set + ) + tx_range_list1 = property( + _Hamlib.rig_caps_tx_range_list1_get, _Hamlib.rig_caps_tx_range_list1_set + ) + rx_range_list2 = property( + _Hamlib.rig_caps_rx_range_list2_get, _Hamlib.rig_caps_rx_range_list2_set + ) + tx_range_list2 = property( + _Hamlib.rig_caps_tx_range_list2_get, _Hamlib.rig_caps_tx_range_list2_set + ) + rx_range_list3 = property( + _Hamlib.rig_caps_rx_range_list3_get, _Hamlib.rig_caps_rx_range_list3_set + ) + tx_range_list3 = property( + _Hamlib.rig_caps_tx_range_list3_get, _Hamlib.rig_caps_tx_range_list3_set + ) + rx_range_list4 = property( + _Hamlib.rig_caps_rx_range_list4_get, _Hamlib.rig_caps_rx_range_list4_set + ) + tx_range_list4 = property( + _Hamlib.rig_caps_tx_range_list4_get, _Hamlib.rig_caps_tx_range_list4_set + ) + rx_range_list5 = property( + _Hamlib.rig_caps_rx_range_list5_get, _Hamlib.rig_caps_rx_range_list5_set + ) + tx_range_list5 = property( + _Hamlib.rig_caps_tx_range_list5_get, _Hamlib.rig_caps_tx_range_list5_set + ) + tuning_steps = property( + _Hamlib.rig_caps_tuning_steps_get, _Hamlib.rig_caps_tuning_steps_set + ) filters = property(_Hamlib.rig_caps_filters_get, _Hamlib.rig_caps_filters_set) str_cal = property(_Hamlib.rig_caps_str_cal_get, _Hamlib.rig_caps_str_cal_set) swr_cal = property(_Hamlib.rig_caps_swr_cal_get, _Hamlib.rig_caps_swr_cal_set) alc_cal = property(_Hamlib.rig_caps_alc_cal_get, _Hamlib.rig_caps_alc_cal_set) - rfpower_meter_cal = property(_Hamlib.rig_caps_rfpower_meter_cal_get, _Hamlib.rig_caps_rfpower_meter_cal_set) - comp_meter_cal = property(_Hamlib.rig_caps_comp_meter_cal_get, _Hamlib.rig_caps_comp_meter_cal_set) - vd_meter_cal = property(_Hamlib.rig_caps_vd_meter_cal_get, _Hamlib.rig_caps_vd_meter_cal_set) - id_meter_cal = property(_Hamlib.rig_caps_id_meter_cal_get, _Hamlib.rig_caps_id_meter_cal_set) - spectrum_scopes = property(_Hamlib.rig_caps_spectrum_scopes_get, _Hamlib.rig_caps_spectrum_scopes_set) - spectrum_modes = property(_Hamlib.rig_caps_spectrum_modes_get, _Hamlib.rig_caps_spectrum_modes_set) - spectrum_spans = property(_Hamlib.rig_caps_spectrum_spans_get, _Hamlib.rig_caps_spectrum_spans_set) - spectrum_avg_modes = property(_Hamlib.rig_caps_spectrum_avg_modes_get, _Hamlib.rig_caps_spectrum_avg_modes_set) - spectrum_attenuator = property(_Hamlib.rig_caps_spectrum_attenuator_get, _Hamlib.rig_caps_spectrum_attenuator_set) + rfpower_meter_cal = property( + _Hamlib.rig_caps_rfpower_meter_cal_get, _Hamlib.rig_caps_rfpower_meter_cal_set + ) + comp_meter_cal = property( + _Hamlib.rig_caps_comp_meter_cal_get, _Hamlib.rig_caps_comp_meter_cal_set + ) + vd_meter_cal = property( + _Hamlib.rig_caps_vd_meter_cal_get, _Hamlib.rig_caps_vd_meter_cal_set + ) + id_meter_cal = property( + _Hamlib.rig_caps_id_meter_cal_get, _Hamlib.rig_caps_id_meter_cal_set + ) + spectrum_scopes = property( + _Hamlib.rig_caps_spectrum_scopes_get, _Hamlib.rig_caps_spectrum_scopes_set + ) + spectrum_modes = property( + _Hamlib.rig_caps_spectrum_modes_get, _Hamlib.rig_caps_spectrum_modes_set + ) + spectrum_spans = property( + _Hamlib.rig_caps_spectrum_spans_get, _Hamlib.rig_caps_spectrum_spans_set + ) + spectrum_avg_modes = property( + _Hamlib.rig_caps_spectrum_avg_modes_get, _Hamlib.rig_caps_spectrum_avg_modes_set + ) + spectrum_attenuator = property( + _Hamlib.rig_caps_spectrum_attenuator_get, + _Hamlib.rig_caps_spectrum_attenuator_set, + ) cfgparams = property(_Hamlib.rig_caps_cfgparams_get, _Hamlib.rig_caps_cfgparams_set) priv = property(_Hamlib.rig_caps_priv_get, _Hamlib.rig_caps_priv_set) rig_init = property(_Hamlib.rig_caps_rig_init_get, _Hamlib.rig_caps_rig_init_set) @@ -1301,40 +1607,90 @@ class rig_caps(object): set_ptt = property(_Hamlib.rig_caps_set_ptt_get, _Hamlib.rig_caps_set_ptt_set) get_ptt = property(_Hamlib.rig_caps_get_ptt_get, _Hamlib.rig_caps_get_ptt_set) get_dcd = property(_Hamlib.rig_caps_get_dcd_get, _Hamlib.rig_caps_get_dcd_set) - set_rptr_shift = property(_Hamlib.rig_caps_set_rptr_shift_get, _Hamlib.rig_caps_set_rptr_shift_set) - get_rptr_shift = property(_Hamlib.rig_caps_get_rptr_shift_get, _Hamlib.rig_caps_get_rptr_shift_set) - set_rptr_offs = property(_Hamlib.rig_caps_set_rptr_offs_get, _Hamlib.rig_caps_set_rptr_offs_set) - get_rptr_offs = property(_Hamlib.rig_caps_get_rptr_offs_get, _Hamlib.rig_caps_get_rptr_offs_set) - set_split_freq = property(_Hamlib.rig_caps_set_split_freq_get, _Hamlib.rig_caps_set_split_freq_set) - get_split_freq = property(_Hamlib.rig_caps_get_split_freq_get, _Hamlib.rig_caps_get_split_freq_set) - set_split_mode = property(_Hamlib.rig_caps_set_split_mode_get, _Hamlib.rig_caps_set_split_mode_set) - get_split_mode = property(_Hamlib.rig_caps_get_split_mode_get, _Hamlib.rig_caps_get_split_mode_set) - set_split_freq_mode = property(_Hamlib.rig_caps_set_split_freq_mode_get, _Hamlib.rig_caps_set_split_freq_mode_set) - get_split_freq_mode = property(_Hamlib.rig_caps_get_split_freq_mode_get, _Hamlib.rig_caps_get_split_freq_mode_set) - set_split_vfo = property(_Hamlib.rig_caps_set_split_vfo_get, _Hamlib.rig_caps_set_split_vfo_set) - get_split_vfo = property(_Hamlib.rig_caps_get_split_vfo_get, _Hamlib.rig_caps_get_split_vfo_set) + set_rptr_shift = property( + _Hamlib.rig_caps_set_rptr_shift_get, _Hamlib.rig_caps_set_rptr_shift_set + ) + get_rptr_shift = property( + _Hamlib.rig_caps_get_rptr_shift_get, _Hamlib.rig_caps_get_rptr_shift_set + ) + set_rptr_offs = property( + _Hamlib.rig_caps_set_rptr_offs_get, _Hamlib.rig_caps_set_rptr_offs_set + ) + get_rptr_offs = property( + _Hamlib.rig_caps_get_rptr_offs_get, _Hamlib.rig_caps_get_rptr_offs_set + ) + set_split_freq = property( + _Hamlib.rig_caps_set_split_freq_get, _Hamlib.rig_caps_set_split_freq_set + ) + get_split_freq = property( + _Hamlib.rig_caps_get_split_freq_get, _Hamlib.rig_caps_get_split_freq_set + ) + set_split_mode = property( + _Hamlib.rig_caps_set_split_mode_get, _Hamlib.rig_caps_set_split_mode_set + ) + get_split_mode = property( + _Hamlib.rig_caps_get_split_mode_get, _Hamlib.rig_caps_get_split_mode_set + ) + set_split_freq_mode = property( + _Hamlib.rig_caps_set_split_freq_mode_get, + _Hamlib.rig_caps_set_split_freq_mode_set, + ) + get_split_freq_mode = property( + _Hamlib.rig_caps_get_split_freq_mode_get, + _Hamlib.rig_caps_get_split_freq_mode_set, + ) + set_split_vfo = property( + _Hamlib.rig_caps_set_split_vfo_get, _Hamlib.rig_caps_set_split_vfo_set + ) + get_split_vfo = property( + _Hamlib.rig_caps_get_split_vfo_get, _Hamlib.rig_caps_get_split_vfo_set + ) set_rit = property(_Hamlib.rig_caps_set_rit_get, _Hamlib.rig_caps_set_rit_set) get_rit = property(_Hamlib.rig_caps_get_rit_get, _Hamlib.rig_caps_get_rit_set) set_xit = property(_Hamlib.rig_caps_set_xit_get, _Hamlib.rig_caps_set_xit_set) get_xit = property(_Hamlib.rig_caps_get_xit_get, _Hamlib.rig_caps_get_xit_set) set_ts = property(_Hamlib.rig_caps_set_ts_get, _Hamlib.rig_caps_set_ts_set) get_ts = property(_Hamlib.rig_caps_get_ts_get, _Hamlib.rig_caps_get_ts_set) - set_dcs_code = property(_Hamlib.rig_caps_set_dcs_code_get, _Hamlib.rig_caps_set_dcs_code_set) - get_dcs_code = property(_Hamlib.rig_caps_get_dcs_code_get, _Hamlib.rig_caps_get_dcs_code_set) + set_dcs_code = property( + _Hamlib.rig_caps_set_dcs_code_get, _Hamlib.rig_caps_set_dcs_code_set + ) + get_dcs_code = property( + _Hamlib.rig_caps_get_dcs_code_get, _Hamlib.rig_caps_get_dcs_code_set + ) set_tone = property(_Hamlib.rig_caps_set_tone_get, _Hamlib.rig_caps_set_tone_set) get_tone = property(_Hamlib.rig_caps_get_tone_get, _Hamlib.rig_caps_get_tone_set) - set_ctcss_tone = property(_Hamlib.rig_caps_set_ctcss_tone_get, _Hamlib.rig_caps_set_ctcss_tone_set) - get_ctcss_tone = property(_Hamlib.rig_caps_get_ctcss_tone_get, _Hamlib.rig_caps_get_ctcss_tone_set) - set_dcs_sql = property(_Hamlib.rig_caps_set_dcs_sql_get, _Hamlib.rig_caps_set_dcs_sql_set) - get_dcs_sql = property(_Hamlib.rig_caps_get_dcs_sql_get, _Hamlib.rig_caps_get_dcs_sql_set) - set_tone_sql = property(_Hamlib.rig_caps_set_tone_sql_get, _Hamlib.rig_caps_set_tone_sql_set) - get_tone_sql = property(_Hamlib.rig_caps_get_tone_sql_get, _Hamlib.rig_caps_get_tone_sql_set) - set_ctcss_sql = property(_Hamlib.rig_caps_set_ctcss_sql_get, _Hamlib.rig_caps_set_ctcss_sql_set) - get_ctcss_sql = property(_Hamlib.rig_caps_get_ctcss_sql_get, _Hamlib.rig_caps_get_ctcss_sql_set) + set_ctcss_tone = property( + _Hamlib.rig_caps_set_ctcss_tone_get, _Hamlib.rig_caps_set_ctcss_tone_set + ) + get_ctcss_tone = property( + _Hamlib.rig_caps_get_ctcss_tone_get, _Hamlib.rig_caps_get_ctcss_tone_set + ) + set_dcs_sql = property( + _Hamlib.rig_caps_set_dcs_sql_get, _Hamlib.rig_caps_set_dcs_sql_set + ) + get_dcs_sql = property( + _Hamlib.rig_caps_get_dcs_sql_get, _Hamlib.rig_caps_get_dcs_sql_set + ) + set_tone_sql = property( + _Hamlib.rig_caps_set_tone_sql_get, _Hamlib.rig_caps_set_tone_sql_set + ) + get_tone_sql = property( + _Hamlib.rig_caps_get_tone_sql_get, _Hamlib.rig_caps_get_tone_sql_set + ) + set_ctcss_sql = property( + _Hamlib.rig_caps_set_ctcss_sql_get, _Hamlib.rig_caps_set_ctcss_sql_set + ) + get_ctcss_sql = property( + _Hamlib.rig_caps_get_ctcss_sql_get, _Hamlib.rig_caps_get_ctcss_sql_set + ) power2mW = property(_Hamlib.rig_caps_power2mW_get, _Hamlib.rig_caps_power2mW_set) mW2power = property(_Hamlib.rig_caps_mW2power_get, _Hamlib.rig_caps_mW2power_set) - set_powerstat = property(_Hamlib.rig_caps_set_powerstat_get, _Hamlib.rig_caps_set_powerstat_set) - get_powerstat = property(_Hamlib.rig_caps_get_powerstat_get, _Hamlib.rig_caps_get_powerstat_set) + set_powerstat = property( + _Hamlib.rig_caps_set_powerstat_get, _Hamlib.rig_caps_set_powerstat_set + ) + get_powerstat = property( + _Hamlib.rig_caps_get_powerstat_get, _Hamlib.rig_caps_get_powerstat_set + ) reset = property(_Hamlib.rig_caps_reset_get, _Hamlib.rig_caps_reset_set) set_ant = property(_Hamlib.rig_caps_set_ant_get, _Hamlib.rig_caps_set_ant_set) get_ant = property(_Hamlib.rig_caps_get_ant_get, _Hamlib.rig_caps_get_ant_set) @@ -1344,20 +1700,40 @@ class rig_caps(object): get_func = property(_Hamlib.rig_caps_get_func_get, _Hamlib.rig_caps_get_func_set) set_parm = property(_Hamlib.rig_caps_set_parm_get, _Hamlib.rig_caps_set_parm_set) get_parm = property(_Hamlib.rig_caps_get_parm_get, _Hamlib.rig_caps_get_parm_set) - set_ext_level = property(_Hamlib.rig_caps_set_ext_level_get, _Hamlib.rig_caps_set_ext_level_set) - get_ext_level = property(_Hamlib.rig_caps_get_ext_level_get, _Hamlib.rig_caps_get_ext_level_set) - set_ext_func = property(_Hamlib.rig_caps_set_ext_func_get, _Hamlib.rig_caps_set_ext_func_set) - get_ext_func = property(_Hamlib.rig_caps_get_ext_func_get, _Hamlib.rig_caps_get_ext_func_set) - set_ext_parm = property(_Hamlib.rig_caps_set_ext_parm_get, _Hamlib.rig_caps_set_ext_parm_set) - get_ext_parm = property(_Hamlib.rig_caps_get_ext_parm_get, _Hamlib.rig_caps_get_ext_parm_set) + set_ext_level = property( + _Hamlib.rig_caps_set_ext_level_get, _Hamlib.rig_caps_set_ext_level_set + ) + get_ext_level = property( + _Hamlib.rig_caps_get_ext_level_get, _Hamlib.rig_caps_get_ext_level_set + ) + set_ext_func = property( + _Hamlib.rig_caps_set_ext_func_get, _Hamlib.rig_caps_set_ext_func_set + ) + get_ext_func = property( + _Hamlib.rig_caps_get_ext_func_get, _Hamlib.rig_caps_get_ext_func_set + ) + set_ext_parm = property( + _Hamlib.rig_caps_set_ext_parm_get, _Hamlib.rig_caps_set_ext_parm_set + ) + get_ext_parm = property( + _Hamlib.rig_caps_get_ext_parm_get, _Hamlib.rig_caps_get_ext_parm_set + ) set_conf = property(_Hamlib.rig_caps_set_conf_get, _Hamlib.rig_caps_set_conf_set) get_conf = property(_Hamlib.rig_caps_get_conf_get, _Hamlib.rig_caps_get_conf_set) send_dtmf = property(_Hamlib.rig_caps_send_dtmf_get, _Hamlib.rig_caps_send_dtmf_set) recv_dtmf = property(_Hamlib.rig_caps_recv_dtmf_get, _Hamlib.rig_caps_recv_dtmf_set) - send_morse = property(_Hamlib.rig_caps_send_morse_get, _Hamlib.rig_caps_send_morse_set) - stop_morse = property(_Hamlib.rig_caps_stop_morse_get, _Hamlib.rig_caps_stop_morse_set) - wait_morse = property(_Hamlib.rig_caps_wait_morse_get, _Hamlib.rig_caps_wait_morse_set) - send_voice_mem = property(_Hamlib.rig_caps_send_voice_mem_get, _Hamlib.rig_caps_send_voice_mem_set) + send_morse = property( + _Hamlib.rig_caps_send_morse_get, _Hamlib.rig_caps_send_morse_set + ) + stop_morse = property( + _Hamlib.rig_caps_stop_morse_get, _Hamlib.rig_caps_stop_morse_set + ) + wait_morse = property( + _Hamlib.rig_caps_wait_morse_get, _Hamlib.rig_caps_wait_morse_set + ) + send_voice_mem = property( + _Hamlib.rig_caps_send_voice_mem_get, _Hamlib.rig_caps_send_voice_mem_set + ) set_bank = property(_Hamlib.rig_caps_set_bank_get, _Hamlib.rig_caps_set_bank_set) set_mem = property(_Hamlib.rig_caps_set_mem_get, _Hamlib.rig_caps_set_mem_set) get_mem = property(_Hamlib.rig_caps_get_mem_get, _Hamlib.rig_caps_get_mem_set) @@ -1365,15 +1741,31 @@ class rig_caps(object): scan = property(_Hamlib.rig_caps_scan_get, _Hamlib.rig_caps_scan_set) set_trn = property(_Hamlib.rig_caps_set_trn_get, _Hamlib.rig_caps_set_trn_set) get_trn = property(_Hamlib.rig_caps_get_trn_get, _Hamlib.rig_caps_get_trn_set) - decode_event = property(_Hamlib.rig_caps_decode_event_get, _Hamlib.rig_caps_decode_event_set) - set_channel = property(_Hamlib.rig_caps_set_channel_get, _Hamlib.rig_caps_set_channel_set) - get_channel = property(_Hamlib.rig_caps_get_channel_get, _Hamlib.rig_caps_get_channel_set) + decode_event = property( + _Hamlib.rig_caps_decode_event_get, _Hamlib.rig_caps_decode_event_set + ) + set_channel = property( + _Hamlib.rig_caps_set_channel_get, _Hamlib.rig_caps_set_channel_set + ) + get_channel = property( + _Hamlib.rig_caps_get_channel_get, _Hamlib.rig_caps_get_channel_set + ) get_info = property(_Hamlib.rig_caps_get_info_get, _Hamlib.rig_caps_get_info_set) - set_chan_all_cb = property(_Hamlib.rig_caps_set_chan_all_cb_get, _Hamlib.rig_caps_set_chan_all_cb_set) - get_chan_all_cb = property(_Hamlib.rig_caps_get_chan_all_cb_get, _Hamlib.rig_caps_get_chan_all_cb_set) - set_mem_all_cb = property(_Hamlib.rig_caps_set_mem_all_cb_get, _Hamlib.rig_caps_set_mem_all_cb_set) - get_mem_all_cb = property(_Hamlib.rig_caps_get_mem_all_cb_get, _Hamlib.rig_caps_get_mem_all_cb_set) - set_vfo_opt = property(_Hamlib.rig_caps_set_vfo_opt_get, _Hamlib.rig_caps_set_vfo_opt_set) + set_chan_all_cb = property( + _Hamlib.rig_caps_set_chan_all_cb_get, _Hamlib.rig_caps_set_chan_all_cb_set + ) + get_chan_all_cb = property( + _Hamlib.rig_caps_get_chan_all_cb_get, _Hamlib.rig_caps_get_chan_all_cb_set + ) + set_mem_all_cb = property( + _Hamlib.rig_caps_set_mem_all_cb_get, _Hamlib.rig_caps_set_mem_all_cb_set + ) + get_mem_all_cb = property( + _Hamlib.rig_caps_get_mem_all_cb_get, _Hamlib.rig_caps_get_mem_all_cb_set + ) + set_vfo_opt = property( + _Hamlib.rig_caps_set_vfo_opt_get, _Hamlib.rig_caps_set_vfo_opt_set + ) set_clock = property(_Hamlib.rig_caps_set_clock_get, _Hamlib.rig_caps_set_clock_set) get_clock = property(_Hamlib.rig_caps_get_clock_get, _Hamlib.rig_caps_get_clock_set) clone_combo_set = property(_Hamlib.rig_caps_clone_combo_set_get) @@ -1381,8 +1773,10 @@ class rig_caps(object): def __init__(self): _Hamlib.rig_caps_swiginit(self, _Hamlib.new_rig_caps()) + __swig_destroy__ = _Hamlib.delete_rig_caps + # Register rig_caps in _Hamlib: _Hamlib.rig_caps_swigregister(rig_caps) @@ -1470,8 +1864,11 @@ RIG_FUNCTION_SET_MEM_ALL_CB = _Hamlib.RIG_FUNCTION_SET_MEM_ALL_CB RIG_FUNCTION_GET_MEM_ALL_CB = _Hamlib.RIG_FUNCTION_GET_MEM_ALL_CB RIG_FUNCTION_SET_VFO_OPT = _Hamlib.RIG_FUNCTION_SET_VFO_OPT + def rig_get_function_ptr(rig_model, rig_function): return _Hamlib.rig_get_function_ptr(rig_model, rig_function) + + RIG_CAPS_TARGETABLE_VFO = _Hamlib.RIG_CAPS_TARGETABLE_VFO RIG_CAPS_RIG_MODEL = _Hamlib.RIG_CAPS_RIG_MODEL RIG_CAPS_PORT_TYPE = _Hamlib.RIG_CAPS_PORT_TYPE @@ -1482,37 +1879,63 @@ RIG_CAPS_MFG_NAME_CPTR = _Hamlib.RIG_CAPS_MFG_NAME_CPTR RIG_CAPS_MODEL_NAME_CPTR = _Hamlib.RIG_CAPS_MODEL_NAME_CPTR RIG_CAPS_STATUS_CPTR = _Hamlib.RIG_CAPS_STATUS_CPTR + def rig_get_caps_int(rig_model, rig_caps): return _Hamlib.rig_get_caps_int(rig_model, rig_caps) + def rig_get_caps_cptr(rig_model, rig_caps): return _Hamlib.rig_get_caps_cptr(rig_model, rig_caps) + + class hamlib_port_t(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr type = property(_Hamlib.hamlib_port_t_type_get) fd = property(_Hamlib.hamlib_port_t_fd_get, _Hamlib.hamlib_port_t_fd_set) - handle = property(_Hamlib.hamlib_port_t_handle_get, _Hamlib.hamlib_port_t_handle_set) - write_delay = property(_Hamlib.hamlib_port_t_write_delay_get, _Hamlib.hamlib_port_t_write_delay_set) - post_write_delay = property(_Hamlib.hamlib_port_t_post_write_delay_get, _Hamlib.hamlib_port_t_post_write_delay_set) + handle = property( + _Hamlib.hamlib_port_t_handle_get, _Hamlib.hamlib_port_t_handle_set + ) + write_delay = property( + _Hamlib.hamlib_port_t_write_delay_get, _Hamlib.hamlib_port_t_write_delay_set + ) + post_write_delay = property( + _Hamlib.hamlib_port_t_post_write_delay_get, + _Hamlib.hamlib_port_t_post_write_delay_set, + ) post_write_date = property(_Hamlib.hamlib_port_t_post_write_date_get) - timeout = property(_Hamlib.hamlib_port_t_timeout_get, _Hamlib.hamlib_port_t_timeout_set) + timeout = property( + _Hamlib.hamlib_port_t_timeout_get, _Hamlib.hamlib_port_t_timeout_set + ) retry = property(_Hamlib.hamlib_port_t_retry_get, _Hamlib.hamlib_port_t_retry_set) - flushx = property(_Hamlib.hamlib_port_t_flushx_get, _Hamlib.hamlib_port_t_flushx_set) - pathname = property(_Hamlib.hamlib_port_t_pathname_get, _Hamlib.hamlib_port_t_pathname_set) + flushx = property( + _Hamlib.hamlib_port_t_flushx_get, _Hamlib.hamlib_port_t_flushx_set + ) + pathname = property( + _Hamlib.hamlib_port_t_pathname_get, _Hamlib.hamlib_port_t_pathname_set + ) parm = property(_Hamlib.hamlib_port_t_parm_get) - client_port = property(_Hamlib.hamlib_port_t_client_port_get, _Hamlib.hamlib_port_t_client_port_set) + client_port = property( + _Hamlib.hamlib_port_t_client_port_get, _Hamlib.hamlib_port_t_client_port_set + ) rig = property(_Hamlib.hamlib_port_t_rig_get, _Hamlib.hamlib_port_t_rig_set) def __init__(self): _Hamlib.hamlib_port_t_swiginit(self, _Hamlib.new_hamlib_port_t()) + __swig_destroy__ = _Hamlib.delete_hamlib_port_t + # Register hamlib_port_t in _Hamlib: _Hamlib.hamlib_port_t_swigregister(hamlib_port_t) + class hamlib_port_parm(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr serial = property(_Hamlib.hamlib_port_parm_serial_get) parallel = property(_Hamlib.hamlib_port_parm_parallel_get) @@ -1522,99 +1945,198 @@ class hamlib_port_parm(object): def __init__(self): _Hamlib.hamlib_port_parm_swiginit(self, _Hamlib.new_hamlib_port_parm()) + __swig_destroy__ = _Hamlib.delete_hamlib_port_parm + # Register hamlib_port_parm in _Hamlib: _Hamlib.hamlib_port_parm_swigregister(hamlib_port_parm) + class hamlib_port_parm_gpio(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - on_value = property(_Hamlib.hamlib_port_parm_gpio_on_value_get, _Hamlib.hamlib_port_parm_gpio_on_value_set) - value = property(_Hamlib.hamlib_port_parm_gpio_value_get, _Hamlib.hamlib_port_parm_gpio_value_set) + on_value = property( + _Hamlib.hamlib_port_parm_gpio_on_value_get, + _Hamlib.hamlib_port_parm_gpio_on_value_set, + ) + value = property( + _Hamlib.hamlib_port_parm_gpio_value_get, _Hamlib.hamlib_port_parm_gpio_value_set + ) def __init__(self): - _Hamlib.hamlib_port_parm_gpio_swiginit(self, _Hamlib.new_hamlib_port_parm_gpio()) + _Hamlib.hamlib_port_parm_gpio_swiginit( + self, _Hamlib.new_hamlib_port_parm_gpio() + ) + __swig_destroy__ = _Hamlib.delete_hamlib_port_parm_gpio + # Register hamlib_port_parm_gpio in _Hamlib: _Hamlib.hamlib_port_parm_gpio_swigregister(hamlib_port_parm_gpio) + class hamlib_port_parm_usb(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - vid = property(_Hamlib.hamlib_port_parm_usb_vid_get, _Hamlib.hamlib_port_parm_usb_vid_set) - pid = property(_Hamlib.hamlib_port_parm_usb_pid_get, _Hamlib.hamlib_port_parm_usb_pid_set) - conf = property(_Hamlib.hamlib_port_parm_usb_conf_get, _Hamlib.hamlib_port_parm_usb_conf_set) - iface = property(_Hamlib.hamlib_port_parm_usb_iface_get, _Hamlib.hamlib_port_parm_usb_iface_set) - alt = property(_Hamlib.hamlib_port_parm_usb_alt_get, _Hamlib.hamlib_port_parm_usb_alt_set) - vendor_name = property(_Hamlib.hamlib_port_parm_usb_vendor_name_get, _Hamlib.hamlib_port_parm_usb_vendor_name_set) - product = property(_Hamlib.hamlib_port_parm_usb_product_get, _Hamlib.hamlib_port_parm_usb_product_set) + vid = property( + _Hamlib.hamlib_port_parm_usb_vid_get, _Hamlib.hamlib_port_parm_usb_vid_set + ) + pid = property( + _Hamlib.hamlib_port_parm_usb_pid_get, _Hamlib.hamlib_port_parm_usb_pid_set + ) + conf = property( + _Hamlib.hamlib_port_parm_usb_conf_get, _Hamlib.hamlib_port_parm_usb_conf_set + ) + iface = property( + _Hamlib.hamlib_port_parm_usb_iface_get, _Hamlib.hamlib_port_parm_usb_iface_set + ) + alt = property( + _Hamlib.hamlib_port_parm_usb_alt_get, _Hamlib.hamlib_port_parm_usb_alt_set + ) + vendor_name = property( + _Hamlib.hamlib_port_parm_usb_vendor_name_get, + _Hamlib.hamlib_port_parm_usb_vendor_name_set, + ) + product = property( + _Hamlib.hamlib_port_parm_usb_product_get, + _Hamlib.hamlib_port_parm_usb_product_set, + ) def __init__(self): _Hamlib.hamlib_port_parm_usb_swiginit(self, _Hamlib.new_hamlib_port_parm_usb()) + __swig_destroy__ = _Hamlib.delete_hamlib_port_parm_usb + # Register hamlib_port_parm_usb in _Hamlib: _Hamlib.hamlib_port_parm_usb_swigregister(hamlib_port_parm_usb) + class hamlib_port_parm_cm108(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - ptt_bitnum = property(_Hamlib.hamlib_port_parm_cm108_ptt_bitnum_get, _Hamlib.hamlib_port_parm_cm108_ptt_bitnum_set) + ptt_bitnum = property( + _Hamlib.hamlib_port_parm_cm108_ptt_bitnum_get, + _Hamlib.hamlib_port_parm_cm108_ptt_bitnum_set, + ) def __init__(self): - _Hamlib.hamlib_port_parm_cm108_swiginit(self, _Hamlib.new_hamlib_port_parm_cm108()) + _Hamlib.hamlib_port_parm_cm108_swiginit( + self, _Hamlib.new_hamlib_port_parm_cm108() + ) + __swig_destroy__ = _Hamlib.delete_hamlib_port_parm_cm108 + # Register hamlib_port_parm_cm108 in _Hamlib: _Hamlib.hamlib_port_parm_cm108_swigregister(hamlib_port_parm_cm108) + class hamlib_port_parm_parallel(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - pin = property(_Hamlib.hamlib_port_parm_parallel_pin_get, _Hamlib.hamlib_port_parm_parallel_pin_set) + pin = property( + _Hamlib.hamlib_port_parm_parallel_pin_get, + _Hamlib.hamlib_port_parm_parallel_pin_set, + ) def __init__(self): - _Hamlib.hamlib_port_parm_parallel_swiginit(self, _Hamlib.new_hamlib_port_parm_parallel()) + _Hamlib.hamlib_port_parm_parallel_swiginit( + self, _Hamlib.new_hamlib_port_parm_parallel() + ) + __swig_destroy__ = _Hamlib.delete_hamlib_port_parm_parallel + # Register hamlib_port_parm_parallel in _Hamlib: _Hamlib.hamlib_port_parm_parallel_swigregister(hamlib_port_parm_parallel) + class hamlib_port_parm_serial(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - rate = property(_Hamlib.hamlib_port_parm_serial_rate_get, _Hamlib.hamlib_port_parm_serial_rate_set) - data_bits = property(_Hamlib.hamlib_port_parm_serial_data_bits_get, _Hamlib.hamlib_port_parm_serial_data_bits_set) - stop_bits = property(_Hamlib.hamlib_port_parm_serial_stop_bits_get, _Hamlib.hamlib_port_parm_serial_stop_bits_set) - parity = property(_Hamlib.hamlib_port_parm_serial_parity_get, _Hamlib.hamlib_port_parm_serial_parity_set) - handshake = property(_Hamlib.hamlib_port_parm_serial_handshake_get, _Hamlib.hamlib_port_parm_serial_handshake_set) - rts_state = property(_Hamlib.hamlib_port_parm_serial_rts_state_get, _Hamlib.hamlib_port_parm_serial_rts_state_set) - dtr_state = property(_Hamlib.hamlib_port_parm_serial_dtr_state_get, _Hamlib.hamlib_port_parm_serial_dtr_state_set) + rate = property( + _Hamlib.hamlib_port_parm_serial_rate_get, + _Hamlib.hamlib_port_parm_serial_rate_set, + ) + data_bits = property( + _Hamlib.hamlib_port_parm_serial_data_bits_get, + _Hamlib.hamlib_port_parm_serial_data_bits_set, + ) + stop_bits = property( + _Hamlib.hamlib_port_parm_serial_stop_bits_get, + _Hamlib.hamlib_port_parm_serial_stop_bits_set, + ) + parity = property( + _Hamlib.hamlib_port_parm_serial_parity_get, + _Hamlib.hamlib_port_parm_serial_parity_set, + ) + handshake = property( + _Hamlib.hamlib_port_parm_serial_handshake_get, + _Hamlib.hamlib_port_parm_serial_handshake_set, + ) + rts_state = property( + _Hamlib.hamlib_port_parm_serial_rts_state_get, + _Hamlib.hamlib_port_parm_serial_rts_state_set, + ) + dtr_state = property( + _Hamlib.hamlib_port_parm_serial_dtr_state_get, + _Hamlib.hamlib_port_parm_serial_dtr_state_set, + ) def __init__(self): - _Hamlib.hamlib_port_parm_serial_swiginit(self, _Hamlib.new_hamlib_port_parm_serial()) + _Hamlib.hamlib_port_parm_serial_swiginit( + self, _Hamlib.new_hamlib_port_parm_serial() + ) + __swig_destroy__ = _Hamlib.delete_hamlib_port_parm_serial + # Register hamlib_port_parm_serial in _Hamlib: _Hamlib.hamlib_port_parm_serial_swigregister(hamlib_port_parm_serial) + class hamlib_port_post_write_date(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - tv_sec = property(_Hamlib.hamlib_port_post_write_date_tv_sec_get, _Hamlib.hamlib_port_post_write_date_tv_sec_set) - tv_usec = property(_Hamlib.hamlib_port_post_write_date_tv_usec_get, _Hamlib.hamlib_port_post_write_date_tv_usec_set) + tv_sec = property( + _Hamlib.hamlib_port_post_write_date_tv_sec_get, + _Hamlib.hamlib_port_post_write_date_tv_sec_set, + ) + tv_usec = property( + _Hamlib.hamlib_port_post_write_date_tv_usec_get, + _Hamlib.hamlib_port_post_write_date_tv_usec_set, + ) def __init__(self): - _Hamlib.hamlib_port_post_write_date_swiginit(self, _Hamlib.new_hamlib_port_post_write_date()) + _Hamlib.hamlib_port_post_write_date_swiginit( + self, _Hamlib.new_hamlib_port_post_write_date() + ) + __swig_destroy__ = _Hamlib.delete_hamlib_port_post_write_date + # Register hamlib_port_post_write_date in _Hamlib: _Hamlib.hamlib_port_post_write_date_swigregister(hamlib_port_post_write_date) + class hamlib_port_type(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr rig = property(_Hamlib.hamlib_port_type_rig_get, _Hamlib.hamlib_port_type_rig_set) ptt = property(_Hamlib.hamlib_port_type_ptt_get, _Hamlib.hamlib_port_type_ptt_set) @@ -1622,8 +2144,10 @@ class hamlib_port_type(object): def __init__(self): _Hamlib.hamlib_port_type_swiginit(self, _Hamlib.new_hamlib_port_type()) + __swig_destroy__ = _Hamlib.delete_hamlib_port_type + # Register hamlib_port_type in _Hamlib: _Hamlib.hamlib_port_type_swigregister(hamlib_port_type) @@ -1640,174 +2164,391 @@ HAMLIB_CACHE_SPLIT = _Hamlib.HAMLIB_CACHE_SPLIT HAMLIB_CACHE_WIDTH = _Hamlib.HAMLIB_CACHE_WIDTH TWIDDLE_OFF = _Hamlib.TWIDDLE_OFF TWIDDLE_ON = _Hamlib.TWIDDLE_ON + + class rig_cache(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - timeout_ms = property(_Hamlib.rig_cache_timeout_ms_get, _Hamlib.rig_cache_timeout_ms_set) + timeout_ms = property( + _Hamlib.rig_cache_timeout_ms_get, _Hamlib.rig_cache_timeout_ms_set + ) vfo = property(_Hamlib.rig_cache_vfo_get, _Hamlib.rig_cache_vfo_set) freqCurr = property(_Hamlib.rig_cache_freqCurr_get, _Hamlib.rig_cache_freqCurr_set) - freqOther = property(_Hamlib.rig_cache_freqOther_get, _Hamlib.rig_cache_freqOther_set) - freqMainA = property(_Hamlib.rig_cache_freqMainA_get, _Hamlib.rig_cache_freqMainA_set) - freqMainB = property(_Hamlib.rig_cache_freqMainB_get, _Hamlib.rig_cache_freqMainB_set) - freqMainC = property(_Hamlib.rig_cache_freqMainC_get, _Hamlib.rig_cache_freqMainC_set) + freqOther = property( + _Hamlib.rig_cache_freqOther_get, _Hamlib.rig_cache_freqOther_set + ) + freqMainA = property( + _Hamlib.rig_cache_freqMainA_get, _Hamlib.rig_cache_freqMainA_set + ) + freqMainB = property( + _Hamlib.rig_cache_freqMainB_get, _Hamlib.rig_cache_freqMainB_set + ) + freqMainC = property( + _Hamlib.rig_cache_freqMainC_get, _Hamlib.rig_cache_freqMainC_set + ) freqSubA = property(_Hamlib.rig_cache_freqSubA_get, _Hamlib.rig_cache_freqSubA_set) freqSubB = property(_Hamlib.rig_cache_freqSubB_get, _Hamlib.rig_cache_freqSubB_set) freqSubC = property(_Hamlib.rig_cache_freqSubC_get, _Hamlib.rig_cache_freqSubC_set) freqMem = property(_Hamlib.rig_cache_freqMem_get, _Hamlib.rig_cache_freqMem_set) modeCurr = property(_Hamlib.rig_cache_modeCurr_get, _Hamlib.rig_cache_modeCurr_set) - modeOther = property(_Hamlib.rig_cache_modeOther_get, _Hamlib.rig_cache_modeOther_set) - modeMainA = property(_Hamlib.rig_cache_modeMainA_get, _Hamlib.rig_cache_modeMainA_set) - modeMainB = property(_Hamlib.rig_cache_modeMainB_get, _Hamlib.rig_cache_modeMainB_set) - modeMainC = property(_Hamlib.rig_cache_modeMainC_get, _Hamlib.rig_cache_modeMainC_set) + modeOther = property( + _Hamlib.rig_cache_modeOther_get, _Hamlib.rig_cache_modeOther_set + ) + modeMainA = property( + _Hamlib.rig_cache_modeMainA_get, _Hamlib.rig_cache_modeMainA_set + ) + modeMainB = property( + _Hamlib.rig_cache_modeMainB_get, _Hamlib.rig_cache_modeMainB_set + ) + modeMainC = property( + _Hamlib.rig_cache_modeMainC_get, _Hamlib.rig_cache_modeMainC_set + ) modeSubA = property(_Hamlib.rig_cache_modeSubA_get, _Hamlib.rig_cache_modeSubA_set) modeSubB = property(_Hamlib.rig_cache_modeSubB_get, _Hamlib.rig_cache_modeSubB_set) modeSubC = property(_Hamlib.rig_cache_modeSubC_get, _Hamlib.rig_cache_modeSubC_set) modeMem = property(_Hamlib.rig_cache_modeMem_get, _Hamlib.rig_cache_modeMem_set) - widthCurr = property(_Hamlib.rig_cache_widthCurr_get, _Hamlib.rig_cache_widthCurr_set) - widthOther = property(_Hamlib.rig_cache_widthOther_get, _Hamlib.rig_cache_widthOther_set) - widthMainA = property(_Hamlib.rig_cache_widthMainA_get, _Hamlib.rig_cache_widthMainA_set) - widthMainB = property(_Hamlib.rig_cache_widthMainB_get, _Hamlib.rig_cache_widthMainB_set) - widthMainC = property(_Hamlib.rig_cache_widthMainC_get, _Hamlib.rig_cache_widthMainC_set) - widthSubA = property(_Hamlib.rig_cache_widthSubA_get, _Hamlib.rig_cache_widthSubA_set) - widthSubB = property(_Hamlib.rig_cache_widthSubB_get, _Hamlib.rig_cache_widthSubB_set) - widthSubC = property(_Hamlib.rig_cache_widthSubC_get, _Hamlib.rig_cache_widthSubC_set) + widthCurr = property( + _Hamlib.rig_cache_widthCurr_get, _Hamlib.rig_cache_widthCurr_set + ) + widthOther = property( + _Hamlib.rig_cache_widthOther_get, _Hamlib.rig_cache_widthOther_set + ) + widthMainA = property( + _Hamlib.rig_cache_widthMainA_get, _Hamlib.rig_cache_widthMainA_set + ) + widthMainB = property( + _Hamlib.rig_cache_widthMainB_get, _Hamlib.rig_cache_widthMainB_set + ) + widthMainC = property( + _Hamlib.rig_cache_widthMainC_get, _Hamlib.rig_cache_widthMainC_set + ) + widthSubA = property( + _Hamlib.rig_cache_widthSubA_get, _Hamlib.rig_cache_widthSubA_set + ) + widthSubB = property( + _Hamlib.rig_cache_widthSubB_get, _Hamlib.rig_cache_widthSubB_set + ) + widthSubC = property( + _Hamlib.rig_cache_widthSubC_get, _Hamlib.rig_cache_widthSubC_set + ) widthMem = property(_Hamlib.rig_cache_widthMem_get, _Hamlib.rig_cache_widthMem_set) ptt = property(_Hamlib.rig_cache_ptt_get, _Hamlib.rig_cache_ptt_set) split = property(_Hamlib.rig_cache_split_get, _Hamlib.rig_cache_split_set) - split_vfo = property(_Hamlib.rig_cache_split_vfo_get, _Hamlib.rig_cache_split_vfo_set) - time_freqCurr = property(_Hamlib.rig_cache_time_freqCurr_get, _Hamlib.rig_cache_time_freqCurr_set) - time_freqOther = property(_Hamlib.rig_cache_time_freqOther_get, _Hamlib.rig_cache_time_freqOther_set) - time_freqMainA = property(_Hamlib.rig_cache_time_freqMainA_get, _Hamlib.rig_cache_time_freqMainA_set) - time_freqMainB = property(_Hamlib.rig_cache_time_freqMainB_get, _Hamlib.rig_cache_time_freqMainB_set) - time_freqMainC = property(_Hamlib.rig_cache_time_freqMainC_get, _Hamlib.rig_cache_time_freqMainC_set) - time_freqSubA = property(_Hamlib.rig_cache_time_freqSubA_get, _Hamlib.rig_cache_time_freqSubA_set) - time_freqSubB = property(_Hamlib.rig_cache_time_freqSubB_get, _Hamlib.rig_cache_time_freqSubB_set) - time_freqSubC = property(_Hamlib.rig_cache_time_freqSubC_get, _Hamlib.rig_cache_time_freqSubC_set) - time_freqMem = property(_Hamlib.rig_cache_time_freqMem_get, _Hamlib.rig_cache_time_freqMem_set) + split_vfo = property( + _Hamlib.rig_cache_split_vfo_get, _Hamlib.rig_cache_split_vfo_set + ) + time_freqCurr = property( + _Hamlib.rig_cache_time_freqCurr_get, _Hamlib.rig_cache_time_freqCurr_set + ) + time_freqOther = property( + _Hamlib.rig_cache_time_freqOther_get, _Hamlib.rig_cache_time_freqOther_set + ) + time_freqMainA = property( + _Hamlib.rig_cache_time_freqMainA_get, _Hamlib.rig_cache_time_freqMainA_set + ) + time_freqMainB = property( + _Hamlib.rig_cache_time_freqMainB_get, _Hamlib.rig_cache_time_freqMainB_set + ) + time_freqMainC = property( + _Hamlib.rig_cache_time_freqMainC_get, _Hamlib.rig_cache_time_freqMainC_set + ) + time_freqSubA = property( + _Hamlib.rig_cache_time_freqSubA_get, _Hamlib.rig_cache_time_freqSubA_set + ) + time_freqSubB = property( + _Hamlib.rig_cache_time_freqSubB_get, _Hamlib.rig_cache_time_freqSubB_set + ) + time_freqSubC = property( + _Hamlib.rig_cache_time_freqSubC_get, _Hamlib.rig_cache_time_freqSubC_set + ) + time_freqMem = property( + _Hamlib.rig_cache_time_freqMem_get, _Hamlib.rig_cache_time_freqMem_set + ) time_vfo = property(_Hamlib.rig_cache_time_vfo_get, _Hamlib.rig_cache_time_vfo_set) - time_modeCurr = property(_Hamlib.rig_cache_time_modeCurr_get, _Hamlib.rig_cache_time_modeCurr_set) - time_modeOther = property(_Hamlib.rig_cache_time_modeOther_get, _Hamlib.rig_cache_time_modeOther_set) - time_modeMainA = property(_Hamlib.rig_cache_time_modeMainA_get, _Hamlib.rig_cache_time_modeMainA_set) - time_modeMainB = property(_Hamlib.rig_cache_time_modeMainB_get, _Hamlib.rig_cache_time_modeMainB_set) - time_modeMainC = property(_Hamlib.rig_cache_time_modeMainC_get, _Hamlib.rig_cache_time_modeMainC_set) - time_modeSubA = property(_Hamlib.rig_cache_time_modeSubA_get, _Hamlib.rig_cache_time_modeSubA_set) - time_modeSubB = property(_Hamlib.rig_cache_time_modeSubB_get, _Hamlib.rig_cache_time_modeSubB_set) - time_modeSubC = property(_Hamlib.rig_cache_time_modeSubC_get, _Hamlib.rig_cache_time_modeSubC_set) - time_modeMem = property(_Hamlib.rig_cache_time_modeMem_get, _Hamlib.rig_cache_time_modeMem_set) - time_widthCurr = property(_Hamlib.rig_cache_time_widthCurr_get, _Hamlib.rig_cache_time_widthCurr_set) - time_widthOther = property(_Hamlib.rig_cache_time_widthOther_get, _Hamlib.rig_cache_time_widthOther_set) - time_widthMainA = property(_Hamlib.rig_cache_time_widthMainA_get, _Hamlib.rig_cache_time_widthMainA_set) - time_widthMainB = property(_Hamlib.rig_cache_time_widthMainB_get, _Hamlib.rig_cache_time_widthMainB_set) - time_widthMainC = property(_Hamlib.rig_cache_time_widthMainC_get, _Hamlib.rig_cache_time_widthMainC_set) - time_widthSubA = property(_Hamlib.rig_cache_time_widthSubA_get, _Hamlib.rig_cache_time_widthSubA_set) - time_widthSubB = property(_Hamlib.rig_cache_time_widthSubB_get, _Hamlib.rig_cache_time_widthSubB_set) - time_widthSubC = property(_Hamlib.rig_cache_time_widthSubC_get, _Hamlib.rig_cache_time_widthSubC_set) - time_widthMem = property(_Hamlib.rig_cache_time_widthMem_get, _Hamlib.rig_cache_time_widthMem_set) + time_modeCurr = property( + _Hamlib.rig_cache_time_modeCurr_get, _Hamlib.rig_cache_time_modeCurr_set + ) + time_modeOther = property( + _Hamlib.rig_cache_time_modeOther_get, _Hamlib.rig_cache_time_modeOther_set + ) + time_modeMainA = property( + _Hamlib.rig_cache_time_modeMainA_get, _Hamlib.rig_cache_time_modeMainA_set + ) + time_modeMainB = property( + _Hamlib.rig_cache_time_modeMainB_get, _Hamlib.rig_cache_time_modeMainB_set + ) + time_modeMainC = property( + _Hamlib.rig_cache_time_modeMainC_get, _Hamlib.rig_cache_time_modeMainC_set + ) + time_modeSubA = property( + _Hamlib.rig_cache_time_modeSubA_get, _Hamlib.rig_cache_time_modeSubA_set + ) + time_modeSubB = property( + _Hamlib.rig_cache_time_modeSubB_get, _Hamlib.rig_cache_time_modeSubB_set + ) + time_modeSubC = property( + _Hamlib.rig_cache_time_modeSubC_get, _Hamlib.rig_cache_time_modeSubC_set + ) + time_modeMem = property( + _Hamlib.rig_cache_time_modeMem_get, _Hamlib.rig_cache_time_modeMem_set + ) + time_widthCurr = property( + _Hamlib.rig_cache_time_widthCurr_get, _Hamlib.rig_cache_time_widthCurr_set + ) + time_widthOther = property( + _Hamlib.rig_cache_time_widthOther_get, _Hamlib.rig_cache_time_widthOther_set + ) + time_widthMainA = property( + _Hamlib.rig_cache_time_widthMainA_get, _Hamlib.rig_cache_time_widthMainA_set + ) + time_widthMainB = property( + _Hamlib.rig_cache_time_widthMainB_get, _Hamlib.rig_cache_time_widthMainB_set + ) + time_widthMainC = property( + _Hamlib.rig_cache_time_widthMainC_get, _Hamlib.rig_cache_time_widthMainC_set + ) + time_widthSubA = property( + _Hamlib.rig_cache_time_widthSubA_get, _Hamlib.rig_cache_time_widthSubA_set + ) + time_widthSubB = property( + _Hamlib.rig_cache_time_widthSubB_get, _Hamlib.rig_cache_time_widthSubB_set + ) + time_widthSubC = property( + _Hamlib.rig_cache_time_widthSubC_get, _Hamlib.rig_cache_time_widthSubC_set + ) + time_widthMem = property( + _Hamlib.rig_cache_time_widthMem_get, _Hamlib.rig_cache_time_widthMem_set + ) time_ptt = property(_Hamlib.rig_cache_time_ptt_get, _Hamlib.rig_cache_time_ptt_set) - time_split = property(_Hamlib.rig_cache_time_split_get, _Hamlib.rig_cache_time_split_set) + time_split = property( + _Hamlib.rig_cache_time_split_get, _Hamlib.rig_cache_time_split_set + ) satmode = property(_Hamlib.rig_cache_satmode_get, _Hamlib.rig_cache_satmode_set) def __init__(self): _Hamlib.rig_cache_swiginit(self, _Hamlib.new_rig_cache()) + __swig_destroy__ = _Hamlib.delete_rig_cache + # Register rig_cache in _Hamlib: _Hamlib.rig_cache_swigregister(rig_cache) + class rig_state(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr rigport = property(_Hamlib.rig_state_rigport_get, _Hamlib.rig_state_rigport_set) pttport = property(_Hamlib.rig_state_pttport_get, _Hamlib.rig_state_pttport_set) dcdport = property(_Hamlib.rig_state_dcdport_get, _Hamlib.rig_state_dcdport_set) vfo_comp = property(_Hamlib.rig_state_vfo_comp_get, _Hamlib.rig_state_vfo_comp_set) - deprecated_itu_region = property(_Hamlib.rig_state_deprecated_itu_region_get, _Hamlib.rig_state_deprecated_itu_region_set) - rx_range_list = property(_Hamlib.rig_state_rx_range_list_get, _Hamlib.rig_state_rx_range_list_set) - tx_range_list = property(_Hamlib.rig_state_tx_range_list_get, _Hamlib.rig_state_tx_range_list_set) - tuning_steps = property(_Hamlib.rig_state_tuning_steps_get, _Hamlib.rig_state_tuning_steps_set) + deprecated_itu_region = property( + _Hamlib.rig_state_deprecated_itu_region_get, + _Hamlib.rig_state_deprecated_itu_region_set, + ) + rx_range_list = property( + _Hamlib.rig_state_rx_range_list_get, _Hamlib.rig_state_rx_range_list_set + ) + tx_range_list = property( + _Hamlib.rig_state_tx_range_list_get, _Hamlib.rig_state_tx_range_list_set + ) + tuning_steps = property( + _Hamlib.rig_state_tuning_steps_get, _Hamlib.rig_state_tuning_steps_set + ) filters = property(_Hamlib.rig_state_filters_get, _Hamlib.rig_state_filters_set) str_cal = property(_Hamlib.rig_state_str_cal_get, _Hamlib.rig_state_str_cal_set) - chan_list = property(_Hamlib.rig_state_chan_list_get, _Hamlib.rig_state_chan_list_set) + chan_list = property( + _Hamlib.rig_state_chan_list_get, _Hamlib.rig_state_chan_list_set + ) max_rit = property(_Hamlib.rig_state_max_rit_get, _Hamlib.rig_state_max_rit_set) max_xit = property(_Hamlib.rig_state_max_xit_get, _Hamlib.rig_state_max_xit_set) - max_ifshift = property(_Hamlib.rig_state_max_ifshift_get, _Hamlib.rig_state_max_ifshift_set) - announces = property(_Hamlib.rig_state_announces_get, _Hamlib.rig_state_announces_set) + max_ifshift = property( + _Hamlib.rig_state_max_ifshift_get, _Hamlib.rig_state_max_ifshift_set + ) + announces = property( + _Hamlib.rig_state_announces_get, _Hamlib.rig_state_announces_set + ) preamp = property(_Hamlib.rig_state_preamp_get, _Hamlib.rig_state_preamp_set) - attenuator = property(_Hamlib.rig_state_attenuator_get, _Hamlib.rig_state_attenuator_set) - has_get_func = property(_Hamlib.rig_state_has_get_func_get, _Hamlib.rig_state_has_get_func_set) - has_set_func = property(_Hamlib.rig_state_has_set_func_get, _Hamlib.rig_state_has_set_func_set) - has_get_level = property(_Hamlib.rig_state_has_get_level_get, _Hamlib.rig_state_has_get_level_set) - has_set_level = property(_Hamlib.rig_state_has_set_level_get, _Hamlib.rig_state_has_set_level_set) - has_get_parm = property(_Hamlib.rig_state_has_get_parm_get, _Hamlib.rig_state_has_get_parm_set) - has_set_parm = property(_Hamlib.rig_state_has_set_parm_get, _Hamlib.rig_state_has_set_parm_set) - level_gran = property(_Hamlib.rig_state_level_gran_get, _Hamlib.rig_state_level_gran_set) - parm_gran = property(_Hamlib.rig_state_parm_gran_get, _Hamlib.rig_state_parm_gran_set) - hold_decode = property(_Hamlib.rig_state_hold_decode_get, _Hamlib.rig_state_hold_decode_set) - current_vfo = property(_Hamlib.rig_state_current_vfo_get, _Hamlib.rig_state_current_vfo_set) + attenuator = property( + _Hamlib.rig_state_attenuator_get, _Hamlib.rig_state_attenuator_set + ) + has_get_func = property( + _Hamlib.rig_state_has_get_func_get, _Hamlib.rig_state_has_get_func_set + ) + has_set_func = property( + _Hamlib.rig_state_has_set_func_get, _Hamlib.rig_state_has_set_func_set + ) + has_get_level = property( + _Hamlib.rig_state_has_get_level_get, _Hamlib.rig_state_has_get_level_set + ) + has_set_level = property( + _Hamlib.rig_state_has_set_level_get, _Hamlib.rig_state_has_set_level_set + ) + has_get_parm = property( + _Hamlib.rig_state_has_get_parm_get, _Hamlib.rig_state_has_get_parm_set + ) + has_set_parm = property( + _Hamlib.rig_state_has_set_parm_get, _Hamlib.rig_state_has_set_parm_set + ) + level_gran = property( + _Hamlib.rig_state_level_gran_get, _Hamlib.rig_state_level_gran_set + ) + parm_gran = property( + _Hamlib.rig_state_parm_gran_get, _Hamlib.rig_state_parm_gran_set + ) + hold_decode = property( + _Hamlib.rig_state_hold_decode_get, _Hamlib.rig_state_hold_decode_set + ) + current_vfo = property( + _Hamlib.rig_state_current_vfo_get, _Hamlib.rig_state_current_vfo_set + ) vfo_list = property(_Hamlib.rig_state_vfo_list_get, _Hamlib.rig_state_vfo_list_set) - comm_state = property(_Hamlib.rig_state_comm_state_get, _Hamlib.rig_state_comm_state_set) + comm_state = property( + _Hamlib.rig_state_comm_state_get, _Hamlib.rig_state_comm_state_set + ) priv = property(_Hamlib.rig_state_priv_get, _Hamlib.rig_state_priv_set) obj = property(_Hamlib.rig_state_obj_get, _Hamlib.rig_state_obj_set) - transceive = property(_Hamlib.rig_state_transceive_get, _Hamlib.rig_state_transceive_set) - poll_interval = property(_Hamlib.rig_state_poll_interval_get, _Hamlib.rig_state_poll_interval_set) - current_freq = property(_Hamlib.rig_state_current_freq_get, _Hamlib.rig_state_current_freq_set) - current_mode = property(_Hamlib.rig_state_current_mode_get, _Hamlib.rig_state_current_mode_set) - current_width = property(_Hamlib.rig_state_current_width_get, _Hamlib.rig_state_current_width_set) + transceive = property( + _Hamlib.rig_state_transceive_get, _Hamlib.rig_state_transceive_set + ) + poll_interval = property( + _Hamlib.rig_state_poll_interval_get, _Hamlib.rig_state_poll_interval_set + ) + current_freq = property( + _Hamlib.rig_state_current_freq_get, _Hamlib.rig_state_current_freq_set + ) + current_mode = property( + _Hamlib.rig_state_current_mode_get, _Hamlib.rig_state_current_mode_set + ) + current_width = property( + _Hamlib.rig_state_current_width_get, _Hamlib.rig_state_current_width_set + ) tx_vfo = property(_Hamlib.rig_state_tx_vfo_get, _Hamlib.rig_state_tx_vfo_set) - mode_list = property(_Hamlib.rig_state_mode_list_get, _Hamlib.rig_state_mode_list_set) + mode_list = property( + _Hamlib.rig_state_mode_list_get, _Hamlib.rig_state_mode_list_set + ) transmit = property(_Hamlib.rig_state_transmit_get, _Hamlib.rig_state_transmit_set) lo_freq = property(_Hamlib.rig_state_lo_freq_get, _Hamlib.rig_state_lo_freq_set) - twiddle_time = property(_Hamlib.rig_state_twiddle_time_get, _Hamlib.rig_state_twiddle_time_set) - twiddle_timeout = property(_Hamlib.rig_state_twiddle_timeout_get, _Hamlib.rig_state_twiddle_timeout_set) + twiddle_time = property( + _Hamlib.rig_state_twiddle_time_get, _Hamlib.rig_state_twiddle_time_set + ) + twiddle_timeout = property( + _Hamlib.rig_state_twiddle_timeout_get, _Hamlib.rig_state_twiddle_timeout_set + ) uplink = property(_Hamlib.rig_state_uplink_get, _Hamlib.rig_state_uplink_set) cache = property(_Hamlib.rig_state_cache_get, _Hamlib.rig_state_cache_set) vfo_opt = property(_Hamlib.rig_state_vfo_opt_get, _Hamlib.rig_state_vfo_opt_set) - auto_power_on = property(_Hamlib.rig_state_auto_power_on_get, _Hamlib.rig_state_auto_power_on_set) - auto_power_off = property(_Hamlib.rig_state_auto_power_off_get, _Hamlib.rig_state_auto_power_off_set) - auto_disable_screensaver = property(_Hamlib.rig_state_auto_disable_screensaver_get, _Hamlib.rig_state_auto_disable_screensaver_set) - ptt_share = property(_Hamlib.rig_state_ptt_share_get, _Hamlib.rig_state_ptt_share_set) - power_now = property(_Hamlib.rig_state_power_now_get, _Hamlib.rig_state_power_now_set) - power_min = property(_Hamlib.rig_state_power_min_get, _Hamlib.rig_state_power_min_set) - power_max = property(_Hamlib.rig_state_power_max_get, _Hamlib.rig_state_power_max_set) - disable_yaesu_bandselect = property(_Hamlib.rig_state_disable_yaesu_bandselect_get, _Hamlib.rig_state_disable_yaesu_bandselect_set) - twiddle_rit = property(_Hamlib.rig_state_twiddle_rit_get, _Hamlib.rig_state_twiddle_rit_set) - twiddle_state = property(_Hamlib.rig_state_twiddle_state_get, _Hamlib.rig_state_twiddle_state_set) + auto_power_on = property( + _Hamlib.rig_state_auto_power_on_get, _Hamlib.rig_state_auto_power_on_set + ) + auto_power_off = property( + _Hamlib.rig_state_auto_power_off_get, _Hamlib.rig_state_auto_power_off_set + ) + auto_disable_screensaver = property( + _Hamlib.rig_state_auto_disable_screensaver_get, + _Hamlib.rig_state_auto_disable_screensaver_set, + ) + ptt_share = property( + _Hamlib.rig_state_ptt_share_get, _Hamlib.rig_state_ptt_share_set + ) + power_now = property( + _Hamlib.rig_state_power_now_get, _Hamlib.rig_state_power_now_set + ) + power_min = property( + _Hamlib.rig_state_power_min_get, _Hamlib.rig_state_power_min_set + ) + power_max = property( + _Hamlib.rig_state_power_max_get, _Hamlib.rig_state_power_max_set + ) + disable_yaesu_bandselect = property( + _Hamlib.rig_state_disable_yaesu_bandselect_get, + _Hamlib.rig_state_disable_yaesu_bandselect_set, + ) + twiddle_rit = property( + _Hamlib.rig_state_twiddle_rit_get, _Hamlib.rig_state_twiddle_rit_set + ) + twiddle_state = property( + _Hamlib.rig_state_twiddle_state_get, _Hamlib.rig_state_twiddle_state_set + ) rx_vfo = property(_Hamlib.rig_state_rx_vfo_get, _Hamlib.rig_state_rx_vfo_set) def __init__(self): _Hamlib.rig_state_swiginit(self, _Hamlib.new_rig_state()) + __swig_destroy__ = _Hamlib.delete_rig_state + # Register rig_state in _Hamlib: _Hamlib.rig_state_swigregister(rig_state) + class rig_callbacks(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr - freq_event = property(_Hamlib.rig_callbacks_freq_event_get, _Hamlib.rig_callbacks_freq_event_set) - freq_arg = property(_Hamlib.rig_callbacks_freq_arg_get, _Hamlib.rig_callbacks_freq_arg_set) - mode_event = property(_Hamlib.rig_callbacks_mode_event_get, _Hamlib.rig_callbacks_mode_event_set) - mode_arg = property(_Hamlib.rig_callbacks_mode_arg_get, _Hamlib.rig_callbacks_mode_arg_set) - vfo_event = property(_Hamlib.rig_callbacks_vfo_event_get, _Hamlib.rig_callbacks_vfo_event_set) - vfo_arg = property(_Hamlib.rig_callbacks_vfo_arg_get, _Hamlib.rig_callbacks_vfo_arg_set) - ptt_event = property(_Hamlib.rig_callbacks_ptt_event_get, _Hamlib.rig_callbacks_ptt_event_set) - ptt_arg = property(_Hamlib.rig_callbacks_ptt_arg_get, _Hamlib.rig_callbacks_ptt_arg_set) - dcd_event = property(_Hamlib.rig_callbacks_dcd_event_get, _Hamlib.rig_callbacks_dcd_event_set) - dcd_arg = property(_Hamlib.rig_callbacks_dcd_arg_get, _Hamlib.rig_callbacks_dcd_arg_set) - pltune = property(_Hamlib.rig_callbacks_pltune_get, _Hamlib.rig_callbacks_pltune_set) - pltune_arg = property(_Hamlib.rig_callbacks_pltune_arg_get, _Hamlib.rig_callbacks_pltune_arg_set) - spectrum_event = property(_Hamlib.rig_callbacks_spectrum_event_get, _Hamlib.rig_callbacks_spectrum_event_set) - spectrum_arg = property(_Hamlib.rig_callbacks_spectrum_arg_get, _Hamlib.rig_callbacks_spectrum_arg_set) + freq_event = property( + _Hamlib.rig_callbacks_freq_event_get, _Hamlib.rig_callbacks_freq_event_set + ) + freq_arg = property( + _Hamlib.rig_callbacks_freq_arg_get, _Hamlib.rig_callbacks_freq_arg_set + ) + mode_event = property( + _Hamlib.rig_callbacks_mode_event_get, _Hamlib.rig_callbacks_mode_event_set + ) + mode_arg = property( + _Hamlib.rig_callbacks_mode_arg_get, _Hamlib.rig_callbacks_mode_arg_set + ) + vfo_event = property( + _Hamlib.rig_callbacks_vfo_event_get, _Hamlib.rig_callbacks_vfo_event_set + ) + vfo_arg = property( + _Hamlib.rig_callbacks_vfo_arg_get, _Hamlib.rig_callbacks_vfo_arg_set + ) + ptt_event = property( + _Hamlib.rig_callbacks_ptt_event_get, _Hamlib.rig_callbacks_ptt_event_set + ) + ptt_arg = property( + _Hamlib.rig_callbacks_ptt_arg_get, _Hamlib.rig_callbacks_ptt_arg_set + ) + dcd_event = property( + _Hamlib.rig_callbacks_dcd_event_get, _Hamlib.rig_callbacks_dcd_event_set + ) + dcd_arg = property( + _Hamlib.rig_callbacks_dcd_arg_get, _Hamlib.rig_callbacks_dcd_arg_set + ) + pltune = property( + _Hamlib.rig_callbacks_pltune_get, _Hamlib.rig_callbacks_pltune_set + ) + pltune_arg = property( + _Hamlib.rig_callbacks_pltune_arg_get, _Hamlib.rig_callbacks_pltune_arg_set + ) + spectrum_event = property( + _Hamlib.rig_callbacks_spectrum_event_get, + _Hamlib.rig_callbacks_spectrum_event_set, + ) + spectrum_arg = property( + _Hamlib.rig_callbacks_spectrum_arg_get, _Hamlib.rig_callbacks_spectrum_arg_set + ) def __init__(self): _Hamlib.rig_callbacks_swiginit(self, _Hamlib.new_rig_callbacks()) + __swig_destroy__ = _Hamlib.delete_rig_callbacks + # Register rig_callbacks in _Hamlib: _Hamlib.rig_callbacks_swigregister(rig_callbacks) + class s_rig(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr caps = property(_Hamlib.s_rig_caps_get, _Hamlib.s_rig_caps_set) state = property(_Hamlib.s_rig_state_get, _Hamlib.s_rig_state_set) @@ -1815,8 +2556,10 @@ class s_rig(object): def __init__(self): _Hamlib.s_rig_swiginit(self, _Hamlib.new_s_rig()) + __swig_destroy__ = _Hamlib.delete_s_rig + # Register s_rig in _Hamlib: _Hamlib.s_rig_swigregister(s_rig) @@ -1824,264 +2567,362 @@ _Hamlib.s_rig_swigregister(s_rig) def rig_init(rig_model): return _Hamlib.rig_init(rig_model) + def rig_flush(port): return _Hamlib.rig_flush(port) + def rig_get_vfo_list(rig, buf, buflen): return _Hamlib.rig_get_vfo_list(rig, buf, buflen) + def netrigctl_get_vfo_mode(rig): return _Hamlib.netrigctl_get_vfo_mode(rig) + def rig_set_split_freq_mode(rig, vfo, tx_freq, tx_mode, tx_width): return _Hamlib.rig_set_split_freq_mode(rig, vfo, tx_freq, tx_mode, tx_width) + def rig_get_split_freq_mode(rig, vfo, tx_freq, tx_mode, tx_width): return _Hamlib.rig_get_split_freq_mode(rig, vfo, tx_freq, tx_mode, tx_width) + def rig_set_split_vfo(arg1, rx_vfo, split, tx_vfo): return _Hamlib.rig_set_split_vfo(arg1, rx_vfo, split, tx_vfo) + def rig_get_split_vfo(arg1, rx_vfo, split, tx_vfo): return _Hamlib.rig_get_split_vfo(arg1, rx_vfo, split, tx_vfo) + def rig_set_ext_func(rig, vfo, token, status): return _Hamlib.rig_set_ext_func(rig, vfo, token, status) + def rig_get_ext_func(rig, vfo, token, status): return _Hamlib.rig_get_ext_func(rig, vfo, token, status) + def rig_ext_func_foreach(rig, cfunc, data): return _Hamlib.rig_ext_func_foreach(rig, cfunc, data) + def rig_ext_lookup(rig, name): return _Hamlib.rig_ext_lookup(rig, name) + def rig_ext_lookup_tok(rig, token): return _Hamlib.rig_ext_lookup_tok(rig, token) + def rig_ext_token_lookup(rig, name): return _Hamlib.rig_ext_token_lookup(rig, name) + def rig_token_foreach(rig, cfunc, data): return _Hamlib.rig_token_foreach(rig, cfunc, data) + def rig_confparam_lookup(rig, name): return _Hamlib.rig_confparam_lookup(rig, name) + def rig_stop_morse(rig, vfo): return _Hamlib.rig_stop_morse(rig, vfo) + def rig_wait_morse(rig, vfo): return _Hamlib.rig_wait_morse(rig, vfo) + def rig_send_voice_mem(rig, vfo, ch): return _Hamlib.rig_send_voice_mem(rig, vfo, ch) + def rig_set_chan_all(rig, vfo, chans): return _Hamlib.rig_set_chan_all(rig, vfo, chans) + def rig_get_chan_all(rig, vfo, chans): return _Hamlib.rig_get_chan_all(rig, vfo, chans) + def rig_set_chan_all_cb(rig, vfo, chan_cb, arg4): return _Hamlib.rig_set_chan_all_cb(rig, vfo, chan_cb, arg4) + def rig_get_chan_all_cb(rig, vfo, chan_cb, arg4): return _Hamlib.rig_get_chan_all_cb(rig, vfo, chan_cb, arg4) + def rig_set_mem_all_cb(rig, vfo, chan_cb, parm_cb, arg5): return _Hamlib.rig_set_mem_all_cb(rig, vfo, chan_cb, parm_cb, arg5) + def rig_get_mem_all_cb(rig, vfo, chan_cb, parm_cb, arg5): return _Hamlib.rig_get_mem_all_cb(rig, vfo, chan_cb, parm_cb, arg5) + def rig_set_mem_all(rig, vfo, chan, arg4, arg5): return _Hamlib.rig_set_mem_all(rig, vfo, chan, arg4, arg5) + def rig_get_mem_all(rig, vfo, chan, arg4, arg5): return _Hamlib.rig_get_mem_all(rig, vfo, chan, arg4, arg5) + def rig_lookup_mem_caps(rig, ch): return _Hamlib.rig_lookup_mem_caps(rig, ch) + def rig_mem_count(rig): return _Hamlib.rig_mem_count(rig) + def rig_set_spectrum_callback(arg1, arg2, arg3): return _Hamlib.rig_set_spectrum_callback(arg1, arg2, arg3) + def rig_set_twiddle(rig, seconds): return _Hamlib.rig_set_twiddle(rig, seconds) + def rig_get_twiddle(rig, seconds): return _Hamlib.rig_get_twiddle(rig, seconds) + def rig_set_uplink(rig, val): return _Hamlib.rig_set_uplink(rig, val) + def rig_get_caps(rig_model): return _Hamlib.rig_get_caps(rig_model) + def rig_get_range(range_list, freq, mode): return _Hamlib.rig_get_range(range_list, freq, mode) + def rigerror(errnum): return _Hamlib.rigerror(errnum) + def rig_setting2idx(s): return _Hamlib.rig_setting2idx(s) + def rig_idx2setting(i): return _Hamlib.rig_idx2setting(i) + def rig_set_debug(debug_level): return _Hamlib.rig_set_debug(debug_level) + def rig_set_debug_time_stamp(flag): return _Hamlib.rig_set_debug_time_stamp(flag) + def rig_need_debug(debug_level): return _Hamlib.rig_need_debug(debug_level) + + DEBUGMSGSAVE_SIZE = _Hamlib.DEBUGMSGSAVE_SIZE + def rig_debug(*args): return _Hamlib.rig_debug(*args) + def rig_set_debug_callback(cb, arg): return _Hamlib.rig_set_debug_callback(cb, arg) + def rig_set_debug_file(stream): return _Hamlib.rig_set_debug_file(stream) + def rig_register(caps): return _Hamlib.rig_register(caps) + def rig_unregister(rig_model): return _Hamlib.rig_unregister(rig_model) + def rig_list_foreach(cfunc, data): return _Hamlib.rig_list_foreach(cfunc, data) + def rig_list_foreach_model(cfunc, data): return _Hamlib.rig_list_foreach_model(cfunc, data) + def rig_load_backend(be_name): return _Hamlib.rig_load_backend(be_name) + def rig_check_backend(rig_model): return _Hamlib.rig_check_backend(rig_model) + def rig_load_all_backends(): return _Hamlib.rig_load_all_backends() + def rig_probe_all(p, arg2, arg3): return _Hamlib.rig_probe_all(p, arg2, arg3) + def rig_strrmode(mode): return _Hamlib.rig_strrmode(mode) + def rig_strrmodes(modes, buf, buflen): return _Hamlib.rig_strrmodes(modes, buf, buflen) + def rig_strvfo(vfo): return _Hamlib.rig_strvfo(vfo) + def rig_strfunc(arg1): return _Hamlib.rig_strfunc(arg1) + def rig_strlevel(arg1): return _Hamlib.rig_strlevel(arg1) + def rig_strparm(arg1): return _Hamlib.rig_strparm(arg1) + def rig_stragclevel(level): return _Hamlib.rig_stragclevel(level) + def rig_strptrshift(arg1): return _Hamlib.rig_strptrshift(arg1) + def rig_strvfop(op): return _Hamlib.rig_strvfop(op) + def rig_strscan(scan): return _Hamlib.rig_strscan(scan) + def rig_strstatus(status): return _Hamlib.rig_strstatus(status) + def rig_strmtype(mtype): return _Hamlib.rig_strmtype(mtype) + def rig_strspectrummode(mode): return _Hamlib.rig_strspectrummode(mode) + def rig_parse_mode(s): return _Hamlib.rig_parse_mode(s) + def rig_parse_vfo(s): return _Hamlib.rig_parse_vfo(s) + def rig_parse_func(s): return _Hamlib.rig_parse_func(s) + def rig_parse_level(s): return _Hamlib.rig_parse_level(s) + def rig_parse_parm(s): return _Hamlib.rig_parse_parm(s) + def rig_parse_vfo_op(s): return _Hamlib.rig_parse_vfo_op(s) + def rig_parse_scan(s): return _Hamlib.rig_parse_scan(s) + def rig_parse_rptr_shift(s): return _Hamlib.rig_parse_rptr_shift(s) + def rig_parse_mtype(s): return _Hamlib.rig_parse_mtype(s) + def rig_license(): return _Hamlib.rig_license() + def rig_version(): return _Hamlib.rig_version() + def rig_copyright(): return _Hamlib.rig_copyright() + def rig_no_restore_ai(): return _Hamlib.rig_no_restore_ai() + def rig_get_cache_timeout_ms(rig, selection): return _Hamlib.rig_get_cache_timeout_ms(rig, selection) + def rig_set_cache_timeout_ms(rig, selection, ms): return _Hamlib.rig_set_cache_timeout_ms(rig, selection, ms) + def rig_set_vfo_opt(rig, status): return _Hamlib.rig_set_vfo_opt(rig, status) + def rig_get_rig_info(rig, response, max_response_len): return _Hamlib.rig_get_rig_info(rig, response, max_response_len) -def rig_get_cache(rig, vfo, freq, cache_ms_freq, mode, cache_ms_mode, width, cache_ms_width): - return _Hamlib.rig_get_cache(rig, vfo, freq, cache_ms_freq, mode, cache_ms_mode, width, cache_ms_width) + +def rig_get_cache( + rig, vfo, freq, cache_ms_freq, mode, cache_ms_mode, width, cache_ms_width +): + return _Hamlib.rig_get_cache( + rig, vfo, freq, cache_ms_freq, mode, cache_ms_mode, width, cache_ms_width + ) + def rig_set_clock(rig, year, month, day, hour, min, sec, msec, utc_offset): - return _Hamlib.rig_set_clock(rig, year, month, day, hour, min, sec, msec, utc_offset) + return _Hamlib.rig_set_clock( + rig, year, month, day, hour, min, sec, msec, utc_offset + ) + def rig_get_clock(rig, year, month, day, hour, min, sec, msec, utc_offset): - return _Hamlib.rig_get_clock(rig, year, month, day, hour, min, sec, msec, utc_offset) + return _Hamlib.rig_get_clock( + rig, year, month, day, hour, min, sec, msec, utc_offset + ) + def hl_usleep(msec): return _Hamlib.hl_usleep(msec) + def rig_cookie(rig, cookie_cmd, cookie, cookie_len): return _Hamlib.rig_cookie(rig, cookie_cmd, cookie, cookie_len) + + ROT_MODEL_NONE = _Hamlib.ROT_MODEL_NONE ROT_MODEL_DUMMY = _Hamlib.ROT_MODEL_DUMMY ROT_MODEL_NETROTCTL = _Hamlib.ROT_MODEL_NETROTCTL @@ -2188,8 +3029,12 @@ ROT_PARM_FLOAT_LIST = _Hamlib.ROT_PARM_FLOAT_LIST ROT_PARM_READONLY_LIST = _Hamlib.ROT_PARM_READONLY_LIST ROT_FUNC_NONE = _Hamlib.ROT_FUNC_NONE ROT_FUNC_BIT63 = _Hamlib.ROT_FUNC_BIT63 + + class rot_caps(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr rot_model = property(_Hamlib.rot_caps_rot_model_get, _Hamlib.rot_caps_rot_model_set) model_name = property(_Hamlib.rot_caps_model_name_get) @@ -2199,29 +3044,63 @@ class rot_caps(object): status = property(_Hamlib.rot_caps_status_get, _Hamlib.rot_caps_status_set) rot_type = property(_Hamlib.rot_caps_rot_type_get, _Hamlib.rot_caps_rot_type_set) port_type = property(_Hamlib.rot_caps_port_type_get, _Hamlib.rot_caps_port_type_set) - serial_rate_min = property(_Hamlib.rot_caps_serial_rate_min_get, _Hamlib.rot_caps_serial_rate_min_set) - serial_rate_max = property(_Hamlib.rot_caps_serial_rate_max_get, _Hamlib.rot_caps_serial_rate_max_set) - serial_data_bits = property(_Hamlib.rot_caps_serial_data_bits_get, _Hamlib.rot_caps_serial_data_bits_set) - serial_stop_bits = property(_Hamlib.rot_caps_serial_stop_bits_get, _Hamlib.rot_caps_serial_stop_bits_set) - serial_parity = property(_Hamlib.rot_caps_serial_parity_get, _Hamlib.rot_caps_serial_parity_set) - serial_handshake = property(_Hamlib.rot_caps_serial_handshake_get, _Hamlib.rot_caps_serial_handshake_set) - write_delay = property(_Hamlib.rot_caps_write_delay_get, _Hamlib.rot_caps_write_delay_set) - post_write_delay = property(_Hamlib.rot_caps_post_write_delay_get, _Hamlib.rot_caps_post_write_delay_set) + serial_rate_min = property( + _Hamlib.rot_caps_serial_rate_min_get, _Hamlib.rot_caps_serial_rate_min_set + ) + serial_rate_max = property( + _Hamlib.rot_caps_serial_rate_max_get, _Hamlib.rot_caps_serial_rate_max_set + ) + serial_data_bits = property( + _Hamlib.rot_caps_serial_data_bits_get, _Hamlib.rot_caps_serial_data_bits_set + ) + serial_stop_bits = property( + _Hamlib.rot_caps_serial_stop_bits_get, _Hamlib.rot_caps_serial_stop_bits_set + ) + serial_parity = property( + _Hamlib.rot_caps_serial_parity_get, _Hamlib.rot_caps_serial_parity_set + ) + serial_handshake = property( + _Hamlib.rot_caps_serial_handshake_get, _Hamlib.rot_caps_serial_handshake_set + ) + write_delay = property( + _Hamlib.rot_caps_write_delay_get, _Hamlib.rot_caps_write_delay_set + ) + post_write_delay = property( + _Hamlib.rot_caps_post_write_delay_get, _Hamlib.rot_caps_post_write_delay_set + ) timeout = property(_Hamlib.rot_caps_timeout_get, _Hamlib.rot_caps_timeout_set) retry = property(_Hamlib.rot_caps_retry_get, _Hamlib.rot_caps_retry_set) - has_get_func = property(_Hamlib.rot_caps_has_get_func_get, _Hamlib.rot_caps_has_get_func_set) - has_set_func = property(_Hamlib.rot_caps_has_set_func_get, _Hamlib.rot_caps_has_set_func_set) - has_get_level = property(_Hamlib.rot_caps_has_get_level_get, _Hamlib.rot_caps_has_get_level_set) - has_set_level = property(_Hamlib.rot_caps_has_set_level_get, _Hamlib.rot_caps_has_set_level_set) - has_get_parm = property(_Hamlib.rot_caps_has_get_parm_get, _Hamlib.rot_caps_has_get_parm_set) - has_set_parm = property(_Hamlib.rot_caps_has_set_parm_get, _Hamlib.rot_caps_has_set_parm_set) - has_status = property(_Hamlib.rot_caps_has_status_get, _Hamlib.rot_caps_has_status_set) - level_gran = property(_Hamlib.rot_caps_level_gran_get, _Hamlib.rot_caps_level_gran_set) + has_get_func = property( + _Hamlib.rot_caps_has_get_func_get, _Hamlib.rot_caps_has_get_func_set + ) + has_set_func = property( + _Hamlib.rot_caps_has_set_func_get, _Hamlib.rot_caps_has_set_func_set + ) + has_get_level = property( + _Hamlib.rot_caps_has_get_level_get, _Hamlib.rot_caps_has_get_level_set + ) + has_set_level = property( + _Hamlib.rot_caps_has_set_level_get, _Hamlib.rot_caps_has_set_level_set + ) + has_get_parm = property( + _Hamlib.rot_caps_has_get_parm_get, _Hamlib.rot_caps_has_get_parm_set + ) + has_set_parm = property( + _Hamlib.rot_caps_has_set_parm_get, _Hamlib.rot_caps_has_set_parm_set + ) + has_status = property( + _Hamlib.rot_caps_has_status_get, _Hamlib.rot_caps_has_status_set + ) + level_gran = property( + _Hamlib.rot_caps_level_gran_get, _Hamlib.rot_caps_level_gran_set + ) parm_gran = property(_Hamlib.rot_caps_parm_gran_get, _Hamlib.rot_caps_parm_gran_set) extparms = property(_Hamlib.rot_caps_extparms_get, _Hamlib.rot_caps_extparms_set) extlevels = property(_Hamlib.rot_caps_extlevels_get, _Hamlib.rot_caps_extlevels_set) extfuncs = property(_Hamlib.rot_caps_extfuncs_get, _Hamlib.rot_caps_extfuncs_set) - ext_tokens = property(_Hamlib.rot_caps_ext_tokens_get, _Hamlib.rot_caps_ext_tokens_set) + ext_tokens = property( + _Hamlib.rot_caps_ext_tokens_get, _Hamlib.rot_caps_ext_tokens_set + ) min_az = property(_Hamlib.rot_caps_min_az_get, _Hamlib.rot_caps_min_az_set) max_az = property(_Hamlib.rot_caps_max_az_get, _Hamlib.rot_caps_max_az_set) min_el = property(_Hamlib.rot_caps_min_el_get, _Hamlib.rot_caps_min_el_set) @@ -2231,8 +3110,12 @@ class rot_caps(object): rot_init = property(_Hamlib.rot_caps_rot_init_get, _Hamlib.rot_caps_rot_init_set) set_conf = property(_Hamlib.rot_caps_set_conf_get, _Hamlib.rot_caps_set_conf_set) get_conf = property(_Hamlib.rot_caps_get_conf_get, _Hamlib.rot_caps_get_conf_set) - set_position = property(_Hamlib.rot_caps_set_position_get, _Hamlib.rot_caps_set_position_set) - get_position = property(_Hamlib.rot_caps_get_position_get, _Hamlib.rot_caps_get_position_set) + set_position = property( + _Hamlib.rot_caps_set_position_get, _Hamlib.rot_caps_set_position_set + ) + get_position = property( + _Hamlib.rot_caps_get_position_get, _Hamlib.rot_caps_get_position_set + ) stop = property(_Hamlib.rot_caps_stop_get, _Hamlib.rot_caps_stop_set) park = property(_Hamlib.rot_caps_park_get, _Hamlib.rot_caps_park_set) reset = property(_Hamlib.rot_caps_reset_get, _Hamlib.rot_caps_reset_set) @@ -2244,64 +3127,118 @@ class rot_caps(object): get_func = property(_Hamlib.rot_caps_get_func_get, _Hamlib.rot_caps_get_func_set) set_parm = property(_Hamlib.rot_caps_set_parm_get, _Hamlib.rot_caps_set_parm_set) get_parm = property(_Hamlib.rot_caps_get_parm_get, _Hamlib.rot_caps_get_parm_set) - set_ext_level = property(_Hamlib.rot_caps_set_ext_level_get, _Hamlib.rot_caps_set_ext_level_set) - get_ext_level = property(_Hamlib.rot_caps_get_ext_level_get, _Hamlib.rot_caps_get_ext_level_set) - set_ext_func = property(_Hamlib.rot_caps_set_ext_func_get, _Hamlib.rot_caps_set_ext_func_set) - get_ext_func = property(_Hamlib.rot_caps_get_ext_func_get, _Hamlib.rot_caps_get_ext_func_set) - set_ext_parm = property(_Hamlib.rot_caps_set_ext_parm_get, _Hamlib.rot_caps_set_ext_parm_set) - get_ext_parm = property(_Hamlib.rot_caps_get_ext_parm_get, _Hamlib.rot_caps_get_ext_parm_set) - get_status = property(_Hamlib.rot_caps_get_status_get, _Hamlib.rot_caps_get_status_set) + set_ext_level = property( + _Hamlib.rot_caps_set_ext_level_get, _Hamlib.rot_caps_set_ext_level_set + ) + get_ext_level = property( + _Hamlib.rot_caps_get_ext_level_get, _Hamlib.rot_caps_get_ext_level_set + ) + set_ext_func = property( + _Hamlib.rot_caps_set_ext_func_get, _Hamlib.rot_caps_set_ext_func_set + ) + get_ext_func = property( + _Hamlib.rot_caps_get_ext_func_get, _Hamlib.rot_caps_get_ext_func_set + ) + set_ext_parm = property( + _Hamlib.rot_caps_set_ext_parm_get, _Hamlib.rot_caps_set_ext_parm_set + ) + get_ext_parm = property( + _Hamlib.rot_caps_get_ext_parm_get, _Hamlib.rot_caps_get_ext_parm_set + ) + get_status = property( + _Hamlib.rot_caps_get_status_get, _Hamlib.rot_caps_get_status_set + ) def __init__(self): _Hamlib.rot_caps_swiginit(self, _Hamlib.new_rot_caps()) + __swig_destroy__ = _Hamlib.delete_rot_caps + # Register rot_caps in _Hamlib: _Hamlib.rot_caps_swigregister(rot_caps) + class rot_state(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr min_az = property(_Hamlib.rot_state_min_az_get, _Hamlib.rot_state_min_az_set) max_az = property(_Hamlib.rot_state_max_az_get, _Hamlib.rot_state_max_az_set) min_el = property(_Hamlib.rot_state_min_el_get, _Hamlib.rot_state_min_el_set) max_el = property(_Hamlib.rot_state_max_el_get, _Hamlib.rot_state_max_el_set) - south_zero = property(_Hamlib.rot_state_south_zero_get, _Hamlib.rot_state_south_zero_set) - az_offset = property(_Hamlib.rot_state_az_offset_get, _Hamlib.rot_state_az_offset_set) - el_offset = property(_Hamlib.rot_state_el_offset_get, _Hamlib.rot_state_el_offset_set) - has_get_func = property(_Hamlib.rot_state_has_get_func_get, _Hamlib.rot_state_has_get_func_set) - has_set_func = property(_Hamlib.rot_state_has_set_func_get, _Hamlib.rot_state_has_set_func_set) - has_get_level = property(_Hamlib.rot_state_has_get_level_get, _Hamlib.rot_state_has_get_level_set) - has_set_level = property(_Hamlib.rot_state_has_set_level_get, _Hamlib.rot_state_has_set_level_set) - has_get_parm = property(_Hamlib.rot_state_has_get_parm_get, _Hamlib.rot_state_has_get_parm_set) - has_set_parm = property(_Hamlib.rot_state_has_set_parm_get, _Hamlib.rot_state_has_set_parm_set) - has_status = property(_Hamlib.rot_state_has_status_get, _Hamlib.rot_state_has_status_set) - level_gran = property(_Hamlib.rot_state_level_gran_get, _Hamlib.rot_state_level_gran_set) - parm_gran = property(_Hamlib.rot_state_parm_gran_get, _Hamlib.rot_state_parm_gran_set) + south_zero = property( + _Hamlib.rot_state_south_zero_get, _Hamlib.rot_state_south_zero_set + ) + az_offset = property( + _Hamlib.rot_state_az_offset_get, _Hamlib.rot_state_az_offset_set + ) + el_offset = property( + _Hamlib.rot_state_el_offset_get, _Hamlib.rot_state_el_offset_set + ) + has_get_func = property( + _Hamlib.rot_state_has_get_func_get, _Hamlib.rot_state_has_get_func_set + ) + has_set_func = property( + _Hamlib.rot_state_has_set_func_get, _Hamlib.rot_state_has_set_func_set + ) + has_get_level = property( + _Hamlib.rot_state_has_get_level_get, _Hamlib.rot_state_has_get_level_set + ) + has_set_level = property( + _Hamlib.rot_state_has_set_level_get, _Hamlib.rot_state_has_set_level_set + ) + has_get_parm = property( + _Hamlib.rot_state_has_get_parm_get, _Hamlib.rot_state_has_get_parm_set + ) + has_set_parm = property( + _Hamlib.rot_state_has_set_parm_get, _Hamlib.rot_state_has_set_parm_set + ) + has_status = property( + _Hamlib.rot_state_has_status_get, _Hamlib.rot_state_has_status_set + ) + level_gran = property( + _Hamlib.rot_state_level_gran_get, _Hamlib.rot_state_level_gran_set + ) + parm_gran = property( + _Hamlib.rot_state_parm_gran_get, _Hamlib.rot_state_parm_gran_set + ) rotport = property(_Hamlib.rot_state_rotport_get, _Hamlib.rot_state_rotport_set) rotport2 = property(_Hamlib.rot_state_rotport2_get, _Hamlib.rot_state_rotport2_set) - comm_state = property(_Hamlib.rot_state_comm_state_get, _Hamlib.rot_state_comm_state_set) + comm_state = property( + _Hamlib.rot_state_comm_state_get, _Hamlib.rot_state_comm_state_set + ) priv = property(_Hamlib.rot_state_priv_get, _Hamlib.rot_state_priv_set) obj = property(_Hamlib.rot_state_obj_get, _Hamlib.rot_state_obj_set) - current_speed = property(_Hamlib.rot_state_current_speed_get, _Hamlib.rot_state_current_speed_set) + current_speed = property( + _Hamlib.rot_state_current_speed_get, _Hamlib.rot_state_current_speed_set + ) def __init__(self): _Hamlib.rot_state_swiginit(self, _Hamlib.new_rot_state()) + __swig_destroy__ = _Hamlib.delete_rot_state + # Register rot_state in _Hamlib: _Hamlib.rot_state_swigregister(rot_state) + class s_rot(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr caps = property(_Hamlib.s_rot_caps_get, _Hamlib.s_rot_caps_set) state = property(_Hamlib.s_rot_state_get, _Hamlib.s_rot_state_set) def __init__(self): _Hamlib.s_rot_swiginit(self, _Hamlib.new_s_rot()) + __swig_destroy__ = _Hamlib.delete_s_rot + # Register s_rot in _Hamlib: _Hamlib.s_rot_swigregister(s_rot) @@ -2309,163 +3246,219 @@ _Hamlib.s_rot_swigregister(s_rot) def rot_init(rot_model): return _Hamlib.rot_init(rot_model) + def rot_has_get_level(rot, level): return _Hamlib.rot_has_get_level(rot, level) + def rot_has_set_level(rot, level): return _Hamlib.rot_has_set_level(rot, level) + def rot_has_get_parm(rot, parm): return _Hamlib.rot_has_get_parm(rot, parm) + def rot_has_set_parm(rot, parm): return _Hamlib.rot_has_set_parm(rot, parm) + def rot_has_get_func(rot, func): return _Hamlib.rot_has_get_func(rot, func) + def rot_has_set_func(rot, func): return _Hamlib.rot_has_set_func(rot, func) + def rot_set_func(rot, func, status): return _Hamlib.rot_set_func(rot, func, status) + def rot_get_func(rot, func, status): return _Hamlib.rot_get_func(rot, func, status) + def rot_set_level(rig, level, val): return _Hamlib.rot_set_level(rig, level, val) + def rot_get_level(rig, level, val): return _Hamlib.rot_get_level(rig, level, val) + def rot_set_parm(rig, parm, val): return _Hamlib.rot_set_parm(rig, parm, val) + def rot_get_parm(rig, parm, val): return _Hamlib.rot_get_parm(rig, parm, val) + def rot_set_ext_level(rig, token, val): return _Hamlib.rot_set_ext_level(rig, token, val) + def rot_get_ext_level(rig, token, val): return _Hamlib.rot_get_ext_level(rig, token, val) + def rot_set_ext_func(rig, token, status): return _Hamlib.rot_set_ext_func(rig, token, status) + def rot_get_ext_func(rig, token, status): return _Hamlib.rot_get_ext_func(rig, token, status) + def rot_set_ext_parm(rig, token, val): return _Hamlib.rot_set_ext_parm(rig, token, val) + def rot_get_ext_parm(rig, token, val): return _Hamlib.rot_get_ext_parm(rig, token, val) + def rot_get_status(rot, status): return _Hamlib.rot_get_status(rot, status) + def rot_register(caps): return _Hamlib.rot_register(caps) + def rot_unregister(rot_model): return _Hamlib.rot_unregister(rot_model) + def rot_list_foreach(cfunc, data): return _Hamlib.rot_list_foreach(cfunc, data) + def rot_load_backend(be_name): return _Hamlib.rot_load_backend(be_name) + def rot_check_backend(rot_model): return _Hamlib.rot_check_backend(rot_model) + def rot_load_all_backends(): return _Hamlib.rot_load_all_backends() + def rot_probe_all(p): return _Hamlib.rot_probe_all(p) + def rot_token_foreach(rot, cfunc, data): return _Hamlib.rot_token_foreach(rot, cfunc, data) + def rot_confparam_lookup(rot, name): return _Hamlib.rot_confparam_lookup(rot, name) + def rot_token_lookup(rot, name): return _Hamlib.rot_token_lookup(rot, name) + def rot_ext_func_foreach(rot, cfunc, data): return _Hamlib.rot_ext_func_foreach(rot, cfunc, data) + def rot_ext_level_foreach(rot, cfunc, data): return _Hamlib.rot_ext_level_foreach(rot, cfunc, data) + def rot_ext_parm_foreach(rot, cfunc, data): return _Hamlib.rot_ext_parm_foreach(rot, cfunc, data) + def rot_ext_lookup(rot, name): return _Hamlib.rot_ext_lookup(rot, name) + def rot_ext_lookup_tok(rot, token): return _Hamlib.rot_ext_lookup_tok(rot, token) + def rot_ext_token_lookup(rot, name): return _Hamlib.rot_ext_token_lookup(rot, name) + def rot_get_caps(rot_model): return _Hamlib.rot_get_caps(rot_model) + def qrb(lon1, lat1, lon2, lat2): return _Hamlib.qrb(lon1, lat1, lon2, lat2) + def distance_long_path(distance): return _Hamlib.distance_long_path(distance) + def azimuth_long_path(azimuth): return _Hamlib.azimuth_long_path(azimuth) + def longlat2locator(longitude, latitude, pair_count): return _Hamlib.longlat2locator(longitude, latitude, pair_count) + def locator2longlat(locator): return _Hamlib.locator2longlat(locator) + def dms2dec(degrees, minutes, seconds, sw): return _Hamlib.dms2dec(degrees, minutes, seconds, sw) + def dec2dms(dec): return _Hamlib.dec2dms(dec) + def dec2dmmm(dec): return _Hamlib.dec2dmmm(dec) + def dmmm2dec(degrees, minutes, seconds, sw): return _Hamlib.dmmm2dec(degrees, minutes, seconds, sw) + def rot_parse_func(s): return _Hamlib.rot_parse_func(s) + def rot_parse_level(s): return _Hamlib.rot_parse_level(s) + def rot_parse_parm(s): return _Hamlib.rot_parse_parm(s) + def rot_strfunc(arg1): return _Hamlib.rot_strfunc(arg1) + def rot_strlevel(arg1): return _Hamlib.rot_strlevel(arg1) + def rot_strparm(arg1): return _Hamlib.rot_strparm(arg1) + def rot_strstatus(arg1): return _Hamlib.rot_strstatus(arg1) + + class Rig(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr rig = property(_Hamlib.Rig_rig_get, _Hamlib.Rig_rig_set) caps = property(_Hamlib.Rig_caps_get, _Hamlib.Rig_caps_set) @@ -2475,6 +3468,7 @@ class Rig(object): def __init__(self, rig_model): _Hamlib.Rig_swiginit(self, _Hamlib.new_Rig(rig_model)) + __swig_destroy__ = _Hamlib.delete_Rig def open(self): @@ -2738,15 +3732,20 @@ class Rig(object): def get_ext_parm(self, parm): return _Hamlib.Rig_get_ext_parm(self, parm) + # Register Rig in _Hamlib: _Hamlib.Rig_swigregister(Rig) + class channelArray(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr def __init__(self, nelements): _Hamlib.channelArray_swiginit(self, _Hamlib.new_channelArray(nelements)) + __swig_destroy__ = _Hamlib.delete_channelArray def __getitem__(self, index): @@ -2762,18 +3761,24 @@ class channelArray(object): def frompointer(t): return _Hamlib.channelArray_frompointer(t) + # Register channelArray in _Hamlib: _Hamlib.channelArray_swigregister(channelArray) + def channelArray_frompointer(t): return _Hamlib.channelArray_frompointer(t) + class toneArray(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr def __init__(self, nelements): _Hamlib.toneArray_swiginit(self, _Hamlib.new_toneArray(nelements)) + __swig_destroy__ = _Hamlib.delete_toneArray def __getitem__(self, index): @@ -2789,14 +3794,19 @@ class toneArray(object): def frompointer(t): return _Hamlib.toneArray_frompointer(t) + # Register toneArray in _Hamlib: _Hamlib.toneArray_swigregister(toneArray) + def toneArray_frompointer(t): return _Hamlib.toneArray_frompointer(t) + class Rot(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr rot = property(_Hamlib.Rot_rot_get, _Hamlib.Rot_rot_set) caps = property(_Hamlib.Rot_caps_get, _Hamlib.Rot_caps_set) @@ -2806,6 +3816,7 @@ class Rot(object): def __init__(self, rot_model): _Hamlib.Rot_swiginit(self, _Hamlib.new_Rot(rot_model)) + __swig_destroy__ = _Hamlib.delete_Rot def open(self): @@ -2844,11 +3855,15 @@ class Rot(object): def get_info(self): return _Hamlib.Rot_get_info(self) + # Register Rot in _Hamlib: _Hamlib.Rot_swigregister(Rot) + class Amp(object): - thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") + thisown = property( + lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag" + ) __repr__ = _swig_repr amp = property(_Hamlib.Amp_amp_get, _Hamlib.Amp_amp_set) caps = property(_Hamlib.Amp_caps_get, _Hamlib.Amp_caps_set) @@ -2858,6 +3873,7 @@ class Amp(object): def __init__(self, amp_model): _Hamlib.Amp_swiginit(self, _Hamlib.new_Amp(amp_model)) + __swig_destroy__ = _Hamlib.delete_Amp def open(self): @@ -2887,8 +3903,6 @@ class Amp(object): def get_info(self): return _Hamlib.Amp_get_info(self) + # Register Amp in _Hamlib: _Hamlib.Amp_swigregister(Amp) - - - diff --git a/tnc/log_handler.py b/tnc/log_handler.py index dfe22d85..629fcfa8 100644 --- a/tnc/log_handler.py +++ b/tnc/log_handler.py @@ -3,7 +3,7 @@ def setup_logging(filename): """ Args: - filename: + filename: Returns: @@ -20,7 +20,8 @@ def setup_logging(filename): timestamper, ] - logging.config.dictConfig({ + logging.config.dictConfig( + { "version": 1, "disable_existing_loggers": False, "formatters": { @@ -44,7 +45,7 @@ def setup_logging(filename): "file": { "level": "DEBUG", "class": "logging.handlers.WatchedFileHandler", - "filename": filename + '.log', + "filename": filename + ".log", "formatter": "plain", }, }, @@ -54,8 +55,9 @@ def setup_logging(filename): "level": "DEBUG", "propagate": True, }, - } - }) + }, + } + ) structlog.configure( processors=[ structlog.stdlib.add_log_level, diff --git a/tnc/main.py b/tnc/main.py index 7a3dc619..79365b49 100755 --- a/tnc/main.py +++ b/tnc/main.py @@ -13,18 +13,19 @@ main module for running the tnc import argparse import threading -import static import socketserver -import helpers -import data_handler -import structlog -import log_handler -import modem import sys import os import signal import time import multiprocessing +import structlog + +import modem +import static +import log_handler +import helpers +import data_handler # signal handler for closing aplication @@ -33,61 +34,207 @@ def signal_handler(sig, frame): a signal handler, which closes the network/socket when closing the application Args: sig: signal - frame: + frame: Returns: system exit """ - print('Closing TNC...') + print("Closing TNC...") sock.CLOSE_SIGNAL = True sys.exit(0) - + + signal.signal(signal.SIGINT, signal_handler) -if __name__ == '__main__': +if __name__ == "__main__": # we need to run this on windows for multiprocessing support multiprocessing.freeze_support() # --------------------------------------------GET PARAMETER INPUTS - PARSER = argparse.ArgumentParser(description='FreeDATA TNC') - PARSER.add_argument('--mycall', dest="mycall", default="AA0AA", help="My callsign", type=str) - PARSER.add_argument('--ssid', dest="ssid_list", nargs='*', default=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], help="SSID list we are responding to", type=str) - PARSER.add_argument('--mygrid', dest="mygrid", default="JN12AA", help="My gridsquare", type=str) - PARSER.add_argument('--rx', dest="audio_input_device", default=0, help="listening sound card", type=int) - PARSER.add_argument('--tx', dest="audio_output_device", default=0, help="transmitting sound card", type=int) - PARSER.add_argument('--port', dest="socket_port", default=3000, help="Socket port in the range of 1024-65536", type=int) - PARSER.add_argument('--deviceport', dest="hamlib_device_port", default="/dev/ttyUSB0", help="Hamlib device port", type=str) - PARSER.add_argument('--devicename', dest="hamlib_device_name", default="2028", help="Hamlib device name", type=str) - PARSER.add_argument('--serialspeed', dest="hamlib_serialspeed", choices=[1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200], default=9600, help="Serialspeed", type=int) - PARSER.add_argument('--pttprotocol', dest="hamlib_ptt_type", choices=['USB', 'RIG', 'RTS', 'DTR', 'CM108', 'MICDATA', 'PARALLEL', 'DTR-H', 'DTR-L', 'NONE'], default='USB', help="PTT Type", type=str) - PARSER.add_argument('--pttport', dest="hamlib_ptt_port", default="/dev/ttyUSB0", help="PTT Port", type=str) - PARSER.add_argument('--data_bits', dest="hamlib_data_bits", choices=[7, 8], default=8, help="Hamlib data bits", type=int) - PARSER.add_argument('--stop_bits', dest="hamlib_stop_bits", choices=[1, 2], default=1, help="Hamlib stop bits", type=int) - PARSER.add_argument('--handshake', dest="hamlib_handshake", default="None", help="Hamlib handshake", type=str) - PARSER.add_argument('--radiocontrol', dest="hamlib_radiocontrol", choices=['disabled', 'direct', 'rigctl', 'rigctld'], default="disabled", help="Set how you want to control your radio") - PARSER.add_argument('--rigctld_port', dest="rigctld_port", default=4532, type=int, help="Set rigctld port") - PARSER.add_argument('--rigctld_ip', dest="rigctld_ip", default="localhost", help="Set rigctld ip") - PARSER.add_argument('--scatter', dest="send_scatter", action="store_true", help="Send scatter information via network") - PARSER.add_argument('--fft', dest="send_fft", action="store_true", help="Send fft information via network") - PARSER.add_argument('--500hz', dest="low_bandwith_mode", action="store_true", help="Enable low bandwith mode ( 500 Hz only )") - PARSER.add_argument('--fsk', dest="enable_fsk", action="store_true", help="Enable FSK mode for ping, beacon and CQ") - PARSER.add_argument('--tuning_range_fmin', dest="tuning_range_fmin", choices=[-50.0, -100.0, -150.0, -200.0, -250.0], default=-50.0, help="Tuning range fmin", type=float) - PARSER.add_argument('--tuning_range_fmax', dest="tuning_range_fmax", choices=[50.0, 100.0, 150.0, 200.0, 250.0], default=50.0, help="Tuning range fmax", type=float) - PARSER.add_argument('--tx-audio-level', dest="tx_audio_level", default=50, help="Set the tx audio level at an early stage", type=int) - - + PARSER = argparse.ArgumentParser(description="FreeDATA TNC") + PARSER.add_argument( + "--mycall", dest="mycall", default="AA0AA", help="My callsign", type=str + ) + PARSER.add_argument( + "--ssid", + dest="ssid_list", + nargs="*", + default=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + help="SSID list we are responding to", + type=str, + ) + PARSER.add_argument( + "--mygrid", dest="mygrid", default="JN12AA", help="My gridsquare", type=str + ) + PARSER.add_argument( + "--rx", + dest="audio_input_device", + default=0, + help="listening sound card", + type=int, + ) + PARSER.add_argument( + "--tx", + dest="audio_output_device", + default=0, + help="transmitting sound card", + type=int, + ) + PARSER.add_argument( + "--port", + dest="socket_port", + default=3000, + help="Socket port in the range of 1024-65536", + type=int, + ) + PARSER.add_argument( + "--deviceport", + dest="hamlib_device_port", + default="/dev/ttyUSB0", + help="Hamlib device port", + type=str, + ) + PARSER.add_argument( + "--devicename", + dest="hamlib_device_name", + default="2028", + help="Hamlib device name", + type=str, + ) + PARSER.add_argument( + "--serialspeed", + dest="hamlib_serialspeed", + choices=[1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200], + default=9600, + help="Serialspeed", + type=int, + ) + PARSER.add_argument( + "--pttprotocol", + dest="hamlib_ptt_type", + choices=[ + "USB", + "RIG", + "RTS", + "DTR", + "CM108", + "MICDATA", + "PARALLEL", + "DTR-H", + "DTR-L", + "NONE", + ], + default="USB", + help="PTT Type", + type=str, + ) + PARSER.add_argument( + "--pttport", + dest="hamlib_ptt_port", + default="/dev/ttyUSB0", + help="PTT Port", + type=str, + ) + PARSER.add_argument( + "--data_bits", + dest="hamlib_data_bits", + choices=[7, 8], + default=8, + help="Hamlib data bits", + type=int, + ) + PARSER.add_argument( + "--stop_bits", + dest="hamlib_stop_bits", + choices=[1, 2], + default=1, + help="Hamlib stop bits", + type=int, + ) + PARSER.add_argument( + "--handshake", + dest="hamlib_handshake", + default="None", + help="Hamlib handshake", + type=str, + ) + PARSER.add_argument( + "--radiocontrol", + dest="hamlib_radiocontrol", + choices=["disabled", "direct", "rigctl", "rigctld"], + default="disabled", + help="Set how you want to control your radio", + ) + PARSER.add_argument( + "--rigctld_port", + dest="rigctld_port", + default=4532, + type=int, + help="Set rigctld port", + ) + PARSER.add_argument( + "--rigctld_ip", dest="rigctld_ip", default="localhost", help="Set rigctld ip" + ) + PARSER.add_argument( + "--scatter", + dest="send_scatter", + action="store_true", + help="Send scatter information via network", + ) + PARSER.add_argument( + "--fft", + dest="send_fft", + action="store_true", + help="Send fft information via network", + ) + PARSER.add_argument( + "--500hz", + dest="low_bandwith_mode", + action="store_true", + help="Enable low bandwith mode ( 500 Hz only )", + ) + PARSER.add_argument( + "--fsk", + dest="enable_fsk", + action="store_true", + help="Enable FSK mode for ping, beacon and CQ", + ) + PARSER.add_argument( + "--tuning_range_fmin", + dest="tuning_range_fmin", + choices=[-50.0, -100.0, -150.0, -200.0, -250.0], + default=-50.0, + help="Tuning range fmin", + type=float, + ) + PARSER.add_argument( + "--tuning_range_fmax", + dest="tuning_range_fmax", + choices=[50.0, 100.0, 150.0, 200.0, 250.0], + default=50.0, + help="Tuning range fmax", + type=float, + ) + PARSER.add_argument( + "--tx-audio-level", + dest="tx_audio_level", + default=50, + help="Set the tx audio level at an early stage", + type=int, + ) + ARGS = PARSER.parse_args() # additional step for beeing sure our callsign is correctly # in case we are not getting a station ssid # then we are forcing a station ssid = 0 - mycallsign = bytes(ARGS.mycall.upper(), 'utf-8') + mycallsign = bytes(ARGS.mycall.upper(), "utf-8") mycallsign = helpers.callsign_to_bytes(mycallsign) static.MYCALLSIGN = helpers.bytes_to_callsign(mycallsign) - static.MYCALLSIGN_CRC = helpers.get_crc_16(static.MYCALLSIGN) - + static.MYCALLSIGN_CRC = helpers.get_crc_16(static.MYCALLSIGN) + static.SSID_LIST = ARGS.ssid_list - - static.MYGRID = bytes(ARGS.mygrid, 'utf-8') + + static.MYGRID = bytes(ARGS.mygrid, "utf-8") static.AUDIO_INPUT_DEVICE = ARGS.audio_input_device static.AUDIO_OUTPUT_DEVICE = ARGS.audio_output_device static.PORT = ARGS.socket_port @@ -104,58 +251,68 @@ if __name__ == '__main__': static.HAMLIB_RGICTLD_PORT = str(ARGS.rigctld_port) static.ENABLE_SCATTER = ARGS.send_scatter static.ENABLE_FFT = ARGS.send_fft - static.ENABLE_FSK = ARGS.enable_fsk - static.LOW_BANDWITH_MODE = ARGS.low_bandwith_mode - static.TUNING_RANGE_FMIN = ARGS.tuning_range_fmin - static.TUNING_RANGE_FMAX = ARGS.tuning_range_fmax - static.TX_AUDIO_LEVEL = ARGS.tx_audio_level - - + static.ENABLE_FSK = ARGS.enable_fsk + static.LOW_BANDWITH_MODE = ARGS.low_bandwith_mode + static.TUNING_RANGE_FMIN = ARGS.tuning_range_fmin + static.TUNING_RANGE_FMAX = ARGS.tuning_range_fmax + static.TX_AUDIO_LEVEL = ARGS.tx_audio_level + # we need to wait until we got all parameters from argparse first before we can load the other modules - import sock - - # config logging - try: - if sys.platform == 'linux': - logging_path = os.getenv("HOME") + '/.config/' + 'FreeDATA/' + 'tnc' - - if sys.platform == 'darwin': - logging_path = os.getenv("HOME") + '/Library/' + 'Application Support/' + 'FreeDATA/' + 'tnc' - - if sys.platform == 'win32' or sys.platform == 'win64': - logging_path = os.getenv('APPDATA') + '/' + 'FreeDATA/' + 'tnc' - + import sock + + # config logging + try: + if sys.platform == "linux": + logging_path = os.getenv("HOME") + "/.config/" + "FreeDATA/" + "tnc" + + if sys.platform == "darwin": + logging_path = ( + os.getenv("HOME") + + "/Library/" + + "Application Support/" + + "FreeDATA/" + + "tnc" + ) + + if sys.platform in ["win32", "win64"]: + logging_path = os.getenv("APPDATA") + "/" + "FreeDATA/" + "tnc" + if not os.path.exists(logging_path): os.makedirs(logging_path) log_handler.setup_logging(logging_path) except: - structlog.get_logger("structlog").error("[DMN] logger init error") + structlog.get_logger("structlog").error("[DMN] logger init error") + + structlog.get_logger("structlog").info( + "[TNC] Starting FreeDATA", author="DJ2LS", year="2022", version=static.VERSION + ) - - - structlog.get_logger("structlog").info("[TNC] Starting FreeDATA", author="DJ2LS", year="2022", version=static.VERSION) - # start data handler data_handler.DATA() - + # start modem modem = modem.RF() - # --------------------------------------------START CMD SERVER try: - structlog.get_logger("structlog").info("[TNC] Starting TCP/IP socket", port=static.PORT) + structlog.get_logger("structlog").info( + "[TNC] Starting TCP/IP socket", port=static.PORT + ) # https://stackoverflow.com/a/16641793 socketserver.TCPServer.allow_reuse_address = True - cmdserver = sock.ThreadedTCPServer((static.HOST, static.PORT), sock.ThreadedTCPRequestHandler) + cmdserver = sock.ThreadedTCPServer( + (static.HOST, static.PORT), sock.ThreadedTCPRequestHandler + ) server_thread = threading.Thread(target=cmdserver.serve_forever) server_thread.daemon = True server_thread.start() except Exception as e: - structlog.get_logger("structlog").error("[TNC] Starting TCP/IP socket failed", port=static.PORT, e=e) + structlog.get_logger("structlog").error( + "[TNC] Starting TCP/IP socket failed", port=static.PORT, e=e + ) os._exit(1) while 1: time.sleep(1) diff --git a/tnc/modem.py b/tnc/modem.py index b4f9f926..03016499 100644 --- a/tnc/modem.py +++ b/tnc/modem.py @@ -41,31 +41,36 @@ RECEIVE_DATAC3 = False RECEIVE_FSK_LDPC_1 = False -class RF(): +class RF: """ """ def __init__(self): - + self.sampler_avg = 0 self.buffer_avg = 0 - self.AUDIO_SAMPLE_RATE_RX = 48000 self.AUDIO_SAMPLE_RATE_TX = 48000 self.MODEM_SAMPLE_RATE = codec2.api.FREEDV_FS_8000 - self.AUDIO_FRAMES_PER_BUFFER_RX = 2400*2 #8192 - self.AUDIO_FRAMES_PER_BUFFER_TX = 2400*2 #8192 Lets to some tests with very small chunks for TX - self.AUDIO_CHUNKS = 48 #8 * (self.AUDIO_SAMPLE_RATE_RX/self.MODEM_SAMPLE_RATE) #48 + self.AUDIO_FRAMES_PER_BUFFER_RX = 2400 * 2 # 8192 + self.AUDIO_FRAMES_PER_BUFFER_TX = ( + 2400 * 2 + ) # 8192 Lets to some tests with very small chunks for TX + self.AUDIO_CHUNKS = ( + 48 # 8 * (self.AUDIO_SAMPLE_RATE_RX/self.MODEM_SAMPLE_RATE) #48 + ) self.AUDIO_CHANNELS = 1 - + # locking state for mod out so buffer will be filled before we can use it # https://github.com/DJ2LS/FreeDATA/issues/127 # https://github.com/DJ2LS/FreeDATA/issues/99 self.mod_out_locked = True - + # make sure our resampler will work - assert (self.AUDIO_SAMPLE_RATE_RX / self.MODEM_SAMPLE_RATE) == codec2.api.FDMDV_OS_48 - + assert ( + self.AUDIO_SAMPLE_RATE_RX / self.MODEM_SAMPLE_RATE + ) == codec2.api.FDMDV_OS_48 + # small hack for initializing codec2 via codec2.py module # TODO: we need to change the entire modem module to integrate codec2 module self.c_lib = codec2.api @@ -76,59 +81,110 @@ class RF(): # init FIFO queue to store modulation out in self.modoutqueue = deque() - + # define fft_data buffer self.fft_data = bytes() - - # open codec2 instance - self.datac0_freedv = cast(codec2.api.freedv_open(codec2.api.FREEDV_MODE_DATAC0), c_void_p) - self.c_lib.freedv_set_tuning_range(self.datac0_freedv, c_float(static.TUNING_RANGE_FMIN), c_float(static.TUNING_RANGE_FMAX)) - self.datac0_bytes_per_frame = int(codec2.api.freedv_get_bits_per_modem_frame(self.datac0_freedv)/8) - self.datac0_payload_per_frame = self.datac0_bytes_per_frame -2 - self.datac0_n_nom_modem_samples = self.c_lib.freedv_get_n_nom_modem_samples(self.datac0_freedv) - self.datac0_n_tx_modem_samples = self.c_lib.freedv_get_n_tx_modem_samples(self.datac0_freedv) - self.datac0_n_tx_preamble_modem_samples = self.c_lib.freedv_get_n_tx_preamble_modem_samples(self.datac0_freedv) - self.datac0_n_tx_postamble_modem_samples = self.c_lib.freedv_get_n_tx_postamble_modem_samples(self.datac0_freedv) + + # open codec2 instance + self.datac0_freedv = cast( + codec2.api.freedv_open(codec2.api.FREEDV_MODE_DATAC0), c_void_p + ) + self.c_lib.freedv_set_tuning_range( + self.datac0_freedv, + c_float(static.TUNING_RANGE_FMIN), + c_float(static.TUNING_RANGE_FMAX), + ) + self.datac0_bytes_per_frame = int( + codec2.api.freedv_get_bits_per_modem_frame(self.datac0_freedv) / 8 + ) + self.datac0_payload_per_frame = self.datac0_bytes_per_frame - 2 + self.datac0_n_nom_modem_samples = self.c_lib.freedv_get_n_nom_modem_samples( + self.datac0_freedv + ) + self.datac0_n_tx_modem_samples = self.c_lib.freedv_get_n_tx_modem_samples( + self.datac0_freedv + ) + self.datac0_n_tx_preamble_modem_samples = ( + self.c_lib.freedv_get_n_tx_preamble_modem_samples(self.datac0_freedv) + ) + self.datac0_n_tx_postamble_modem_samples = ( + self.c_lib.freedv_get_n_tx_postamble_modem_samples(self.datac0_freedv) + ) self.datac0_bytes_out = create_string_buffer(self.datac0_bytes_per_frame) - codec2.api.freedv_set_frames_per_burst(self.datac0_freedv,1) - self.datac0_buffer = codec2.audio_buffer(2*self.AUDIO_FRAMES_PER_BUFFER_RX) + codec2.api.freedv_set_frames_per_burst(self.datac0_freedv, 1) + self.datac0_buffer = codec2.audio_buffer(2 * self.AUDIO_FRAMES_PER_BUFFER_RX) - self.datac1_freedv = cast(codec2.api.freedv_open(codec2.api.FREEDV_MODE_DATAC1), c_void_p) - self.c_lib.freedv_set_tuning_range(self.datac1_freedv, c_float(static.TUNING_RANGE_FMIN), c_float(static.TUNING_RANGE_FMAX)) - self.datac1_bytes_per_frame = int(codec2.api.freedv_get_bits_per_modem_frame(self.datac1_freedv)/8) + self.datac1_freedv = cast( + codec2.api.freedv_open(codec2.api.FREEDV_MODE_DATAC1), c_void_p + ) + self.c_lib.freedv_set_tuning_range( + self.datac1_freedv, + c_float(static.TUNING_RANGE_FMIN), + c_float(static.TUNING_RANGE_FMAX), + ) + self.datac1_bytes_per_frame = int( + codec2.api.freedv_get_bits_per_modem_frame(self.datac1_freedv) / 8 + ) self.datac1_bytes_out = create_string_buffer(self.datac1_bytes_per_frame) - codec2.api.freedv_set_frames_per_burst(self.datac1_freedv,1) - self.datac1_buffer = codec2.audio_buffer(2*self.AUDIO_FRAMES_PER_BUFFER_RX) + codec2.api.freedv_set_frames_per_burst(self.datac1_freedv, 1) + self.datac1_buffer = codec2.audio_buffer(2 * self.AUDIO_FRAMES_PER_BUFFER_RX) - self.datac3_freedv = cast(codec2.api.freedv_open(codec2.api.FREEDV_MODE_DATAC3), c_void_p) - self.c_lib.freedv_set_tuning_range(self.datac3_freedv, c_float(static.TUNING_RANGE_FMIN), c_float(static.TUNING_RANGE_FMAX)) - self.datac3_bytes_per_frame = int(codec2.api.freedv_get_bits_per_modem_frame(self.datac3_freedv)/8) + self.datac3_freedv = cast( + codec2.api.freedv_open(codec2.api.FREEDV_MODE_DATAC3), c_void_p + ) + self.c_lib.freedv_set_tuning_range( + self.datac3_freedv, + c_float(static.TUNING_RANGE_FMIN), + c_float(static.TUNING_RANGE_FMAX), + ) + self.datac3_bytes_per_frame = int( + codec2.api.freedv_get_bits_per_modem_frame(self.datac3_freedv) / 8 + ) self.datac3_bytes_out = create_string_buffer(self.datac3_bytes_per_frame) - codec2.api.freedv_set_frames_per_burst(self.datac3_freedv,1) - self.datac3_buffer = codec2.audio_buffer(2*self.AUDIO_FRAMES_PER_BUFFER_RX) + codec2.api.freedv_set_frames_per_burst(self.datac3_freedv, 1) + self.datac3_buffer = codec2.audio_buffer(2 * self.AUDIO_FRAMES_PER_BUFFER_RX) - - self.fsk_ldpc_freedv_0 = cast(codec2.api.freedv_open_advanced(codec2.api.FREEDV_MODE_FSK_LDPC, ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_0_ADV)), c_void_p) - self.fsk_ldpc_bytes_per_frame_0 = int(codec2.api.freedv_get_bits_per_modem_frame(self.fsk_ldpc_freedv_0)/8) - self.fsk_ldpc_bytes_out_0 = create_string_buffer(self.fsk_ldpc_bytes_per_frame_0) - #codec2.api.freedv_set_frames_per_burst(self.fsk_ldpc_freedv_0,1) + self.fsk_ldpc_freedv_0 = cast( + codec2.api.freedv_open_advanced( + codec2.api.FREEDV_MODE_FSK_LDPC, + ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_0_ADV), + ), + c_void_p, + ) + self.fsk_ldpc_bytes_per_frame_0 = int( + codec2.api.freedv_get_bits_per_modem_frame(self.fsk_ldpc_freedv_0) / 8 + ) + self.fsk_ldpc_bytes_out_0 = create_string_buffer( + self.fsk_ldpc_bytes_per_frame_0 + ) + # codec2.api.freedv_set_frames_per_burst(self.fsk_ldpc_freedv_0,1) self.fsk_ldpc_buffer_0 = codec2.audio_buffer(self.AUDIO_FRAMES_PER_BUFFER_RX) - self.fsk_ldpc_freedv_1 = cast(codec2.api.freedv_open_advanced(codec2.api.FREEDV_MODE_FSK_LDPC, ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_1_ADV)), c_void_p) - self.fsk_ldpc_bytes_per_frame_1 = int(codec2.api.freedv_get_bits_per_modem_frame(self.fsk_ldpc_freedv_1)/8) - self.fsk_ldpc_bytes_out_1 = create_string_buffer(self.fsk_ldpc_bytes_per_frame_1) - #codec2.api.freedv_set_frames_per_burst(self.fsk_ldpc_freedv_0,1) + self.fsk_ldpc_freedv_1 = cast( + codec2.api.freedv_open_advanced( + codec2.api.FREEDV_MODE_FSK_LDPC, + ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_1_ADV), + ), + c_void_p, + ) + self.fsk_ldpc_bytes_per_frame_1 = int( + codec2.api.freedv_get_bits_per_modem_frame(self.fsk_ldpc_freedv_1) / 8 + ) + self.fsk_ldpc_bytes_out_1 = create_string_buffer( + self.fsk_ldpc_bytes_per_frame_1 + ) + # codec2.api.freedv_set_frames_per_burst(self.fsk_ldpc_freedv_0,1) self.fsk_ldpc_buffer_1 = codec2.audio_buffer(self.AUDIO_FRAMES_PER_BUFFER_RX) - # initial nin values - self.datac0_nin = codec2.api.freedv_nin(self.datac0_freedv) - self.datac1_nin = codec2.api.freedv_nin(self.datac1_freedv) + # initial nin values + self.datac0_nin = codec2.api.freedv_nin(self.datac0_freedv) + self.datac1_nin = codec2.api.freedv_nin(self.datac1_freedv) self.datac3_nin = codec2.api.freedv_nin(self.datac3_freedv) - self.fsk_ldpc_nin_0 = codec2.api.freedv_nin(self.fsk_ldpc_freedv_0) - self.fsk_ldpc_nin_1 = codec2.api.freedv_nin(self.fsk_ldpc_freedv_1) + self.fsk_ldpc_nin_0 = codec2.api.freedv_nin(self.fsk_ldpc_freedv_0) + self.fsk_ldpc_nin_1 = codec2.api.freedv_nin(self.fsk_ldpc_freedv_1) # --------------------------------------------CREATE PYAUDIO INSTANCE - - ''' + + """ try: # we need to "try" this, because sometimes libasound.so isn't in the default place # try to supress error messages @@ -151,9 +207,9 @@ class RF(): static.AUDIO_OUTPUT_DEVICE = loopback_list[1] #1 = TX print(f"loopback_list rx: {loopback_list}", file=sys.stderr) - ''' + """ try: - ''' + """ self.audio_stream = self.p.open(format=audio.pyaudio.paInt16, channels=self.AUDIO_CHANNELS, rate=self.AUDIO_SAMPLE_RATE_RX, @@ -164,156 +220,200 @@ class RF(): output_device_index=static.AUDIO_OUTPUT_DEVICE, stream_callback=self.audio_callback ) - ''' - - self.stream = sd.RawStream(channels=1, dtype='int16', callback=self.callback, device=(static.AUDIO_INPUT_DEVICE, static.AUDIO_OUTPUT_DEVICE), samplerate = self.AUDIO_SAMPLE_RATE_RX, blocksize=4800) - - - atexit.register(self.stream.stop) - + """ + + self.stream = sd.RawStream( + channels=1, + dtype="int16", + callback=self.callback, + device=(static.AUDIO_INPUT_DEVICE, static.AUDIO_OUTPUT_DEVICE), + samplerate=self.AUDIO_SAMPLE_RATE_RX, + blocksize=4800, + ) + + atexit.register(self.stream.stop) + structlog.get_logger("structlog").info("opened audio devices") - - except Exception as e: - structlog.get_logger("structlog").error("can't open audio device. Exit", e=e) - os._exit(1) - - try: - structlog.get_logger("structlog").debug("[TNC] starting pyaudio callback") - #self.audio_stream.start_stream() - self.stream.start() except Exception as e: - structlog.get_logger("structlog").error("[TNC] starting pyaudio callback failed", e=e) + structlog.get_logger("structlog").error( + "can't open audio device. Exit", e=e + ) + os._exit(1) + + try: + structlog.get_logger("structlog").debug("[TNC] starting pyaudio callback") + # self.audio_stream.start_stream() + self.stream.start() + + except Exception as e: + structlog.get_logger("structlog").error( + "[TNC] starting pyaudio callback failed", e=e + ) # --------------------------------------------INIT AND OPEN HAMLIB # check how we want to control the radio - if static.HAMLIB_RADIOCONTROL == 'direct': + if static.HAMLIB_RADIOCONTROL == "direct": import rig - elif static.HAMLIB_RADIOCONTROL == 'rigctl': + elif static.HAMLIB_RADIOCONTROL == "rigctl": import rigctl as rig - elif static.HAMLIB_RADIOCONTROL == 'rigctld': + elif static.HAMLIB_RADIOCONTROL == "rigctld": import rigctld as rig - elif static.HAMLIB_RADIOCONTROL == 'disabled': + elif static.HAMLIB_RADIOCONTROL == "disabled": import rigdummy as rig else: - import rigdummy as rig + import rigdummy as rig - self.hamlib = rig.radio() - self.hamlib.open_rig(devicename=static.HAMLIB_DEVICE_NAME, deviceport=static.HAMLIB_DEVICE_PORT, hamlib_ptt_type=static.HAMLIB_PTT_TYPE, serialspeed=static.HAMLIB_SERIAL_SPEED, pttport=static.HAMLIB_PTT_PORT, data_bits=static.HAMLIB_DATA_BITS, stop_bits=static.HAMLIB_STOP_BITS, handshake=static.HAMLIB_HANDSHAKE, rigctld_ip = static.HAMLIB_RGICTLD_IP, rigctld_port = static.HAMLIB_RGICTLD_PORT) + self.hamlib.open_rig( + devicename=static.HAMLIB_DEVICE_NAME, + deviceport=static.HAMLIB_DEVICE_PORT, + hamlib_ptt_type=static.HAMLIB_PTT_TYPE, + serialspeed=static.HAMLIB_SERIAL_SPEED, + pttport=static.HAMLIB_PTT_PORT, + data_bits=static.HAMLIB_DATA_BITS, + stop_bits=static.HAMLIB_STOP_BITS, + handshake=static.HAMLIB_HANDSHAKE, + rigctld_ip=static.HAMLIB_RGICTLD_IP, + rigctld_port=static.HAMLIB_RGICTLD_PORT, + ) # --------------------------------------------START DECODER THREAD if static.ENABLE_FFT: - fft_thread = threading.Thread(target=self.calculate_fft, name="FFT_THREAD" ,daemon=True) + fft_thread = threading.Thread( + target=self.calculate_fft, name="FFT_THREAD", daemon=True + ) fft_thread.start() - - audio_thread_datac0 = threading.Thread(target=self.audio_datac0, name="AUDIO_THREAD DATAC0",daemon=True) + + audio_thread_datac0 = threading.Thread( + target=self.audio_datac0, name="AUDIO_THREAD DATAC0", daemon=True + ) audio_thread_datac0.start() - audio_thread_datac1 = threading.Thread(target=self.audio_datac1, name="AUDIO_THREAD DATAC1",daemon=True) + audio_thread_datac1 = threading.Thread( + target=self.audio_datac1, name="AUDIO_THREAD DATAC1", daemon=True + ) audio_thread_datac1.start() - - audio_thread_datac3 = threading.Thread(target=self.audio_datac3, name="AUDIO_THREAD DATAC3",daemon=True) + + audio_thread_datac3 = threading.Thread( + target=self.audio_datac3, name="AUDIO_THREAD DATAC3", daemon=True + ) audio_thread_datac3.start() - + if static.ENABLE_FSK: - audio_thread_fsk_ldpc0 = threading.Thread(target=self.audio_fsk_ldpc_0, name="AUDIO_THREAD FSK LDPC0",daemon=True) + audio_thread_fsk_ldpc0 = threading.Thread( + target=self.audio_fsk_ldpc_0, name="AUDIO_THREAD FSK LDPC0", daemon=True + ) audio_thread_fsk_ldpc0.start() - audio_thread_fsk_ldpc1 = threading.Thread(target=self.audio_fsk_ldpc_1, name="AUDIO_THREAD FSK LDPC1",daemon=True) + audio_thread_fsk_ldpc1 = threading.Thread( + target=self.audio_fsk_ldpc_1, name="AUDIO_THREAD FSK LDPC1", daemon=True + ) audio_thread_fsk_ldpc1.start() - - hamlib_thread = threading.Thread(target=self.update_rig_data, name="HAMLIB_THREAD",daemon=True) + + hamlib_thread = threading.Thread( + target=self.update_rig_data, name="HAMLIB_THREAD", daemon=True + ) hamlib_thread.start() - - worker_received = threading.Thread(target=self.worker_received, name="WORKER_THREAD",daemon=True) + + worker_received = threading.Thread( + target=self.worker_received, name="WORKER_THREAD", daemon=True + ) worker_received.start() - - worker_transmit = threading.Thread(target=self.worker_transmit, name="WORKER_THREAD",daemon=True) + + worker_transmit = threading.Thread( + target=self.worker_transmit, name="WORKER_THREAD", daemon=True + ) worker_transmit.start() - + # -------------------------------------------------------------------------------------------------------- - #def audio_callback(self, data_in48k, frame_count, time_info, status): + # def audio_callback(self, data_in48k, frame_count, time_info, status): def callback(self, data_in48k, outdata, frames, time, status): """ Args: - data_in48k: - frame_count: - time_info: - status: + data_in48k: + frame_count: + time_info: + status: Returns: - """ - + """ + x = np.frombuffer(data_in48k, dtype=np.int16) - x = self.resampler.resample48_to_8(x) + x = self.resampler.resample48_to_8(x) length_x = len(x) - + # avoid decoding when transmitting to reduce CPU if not static.TRANSMITTING: # avoid buffer overflow by filling only if buffer not full - if not self.datac0_buffer.nbuffer+length_x > self.datac0_buffer.size: + if not self.datac0_buffer.nbuffer + length_x > self.datac0_buffer.size: self.datac0_buffer.push(x) else: static.BUFFER_OVERFLOW_COUNTER[0] += 1 - + # avoid buffer overflow by filling only if buffer not full and selected datachannel mode - if not self.datac1_buffer.nbuffer+length_x > self.datac1_buffer.size: + if not self.datac1_buffer.nbuffer + length_x > self.datac1_buffer.size: if RECEIVE_DATAC1: self.datac1_buffer.push(x) else: static.BUFFER_OVERFLOW_COUNTER[1] += 1 - + # avoid buffer overflow by filling only if buffer not full and selected datachannel mode - if not self.datac3_buffer.nbuffer+length_x > self.datac3_buffer.size: + if not self.datac3_buffer.nbuffer + length_x > self.datac3_buffer.size: if RECEIVE_DATAC3: self.datac3_buffer.push(x) else: static.BUFFER_OVERFLOW_COUNTER[2] += 1 # avoid buffer overflow by filling only if buffer not full and selected datachannel mode - if not self.fsk_ldpc_buffer_0.nbuffer+length_x > self.fsk_ldpc_buffer_0.size: - if static.ENABLE_FSK: + if ( + not self.fsk_ldpc_buffer_0.nbuffer + length_x + > self.fsk_ldpc_buffer_0.size + ): + if static.ENABLE_FSK: self.fsk_ldpc_buffer_0.push(x) else: static.BUFFER_OVERFLOW_COUNTER[3] += 1 # avoid buffer overflow by filling only if buffer not full and selected datachannel mode - if not self.fsk_ldpc_buffer_1.nbuffer+length_x > self.fsk_ldpc_buffer_1.size: - if RECEIVE_FSK_LDPC_1 and static.ENABLE_FSK: + if ( + not self.fsk_ldpc_buffer_1.nbuffer + length_x + > self.fsk_ldpc_buffer_1.size + ): + if RECEIVE_FSK_LDPC_1 and static.ENABLE_FSK: self.fsk_ldpc_buffer_1.push(x) else: static.BUFFER_OVERFLOW_COUNTER[4] += 1 - - if len(self.modoutqueue) <= 0 or self.mod_out_locked: - #if not self.modoutqueue or self.mod_out_locked: + + if len(self.modoutqueue) <= 0 or self.mod_out_locked: + # if not self.modoutqueue or self.mod_out_locked: data_out48k = np.zeros(frames, dtype=np.int16) self.fft_data = x - + else: data_out48k = self.modoutqueue.popleft() self.fft_data = data_out48k - + try: - outdata[:] = data_out48k[:frames] + outdata[:] = data_out48k[:frames] except Exception as e: print(e) - #return (data_out48k, audio.pyaudio.paContinue) + # return (data_out48k, audio.pyaudio.paContinue) # -------------------------------------------------------------------------------------------------------- - def transmit(self, mode, repeats, repeat_delay, frames): + def transmit(self, mode, repeats, repeat_delay, frames): """ Args: - mode: - repeats: - repeat_delay: - frames: + mode: + repeats: + repeat_delay: + frames: Returns: @@ -321,79 +421,114 @@ class RF(): static.TRANSMITTING = True # toggle ptt early to save some time and send ptt state via socket static.PTT_STATE = self.hamlib.set_ptt(True) - jsondata = {"ptt":"True"} + jsondata = {"ptt": "True"} data_out = json.dumps(jsondata) sock.SOCKET_QUEUE.put(data_out) - - - # open codec2 instance + + # open codec2 instance self.MODE = mode - if self.MODE == 'FSK_LDPC_0' or self.MODE == 200: - freedv = cast(codec2.api.freedv_open_advanced(codec2.api.FREEDV_MODE_FSK_LDPC, ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_0_ADV)), c_void_p) - elif self.MODE == 'FSK_LDPC_1' or self.MODE == 201: - freedv = cast(codec2.api.freedv_open_advanced(codec2.api.FREEDV_MODE_FSK_LDPC, ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_1_ADV)), c_void_p) - + if self.MODE == "FSK_LDPC_0" or self.MODE == 200: + freedv = cast( + codec2.api.freedv_open_advanced( + codec2.api.FREEDV_MODE_FSK_LDPC, + ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_0_ADV), + ), + c_void_p, + ) + elif self.MODE == "FSK_LDPC_1" or self.MODE == 201: + freedv = cast( + codec2.api.freedv_open_advanced( + codec2.api.FREEDV_MODE_FSK_LDPC, + ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_1_ADV), + ), + c_void_p, + ) + else: freedv = cast(codec2.api.freedv_open(self.MODE), c_void_p) - # get number of bytes per frame for mode - bytes_per_frame = int(codec2.api.freedv_get_bits_per_modem_frame(freedv)/8) - payload_bytes_per_frame = bytes_per_frame -2 + bytes_per_frame = int(codec2.api.freedv_get_bits_per_modem_frame(freedv) / 8) + payload_bytes_per_frame = bytes_per_frame - 2 # init buffer for data n_tx_modem_samples = codec2.api.freedv_get_n_tx_modem_samples(freedv) mod_out = create_string_buffer(n_tx_modem_samples * 2) # init buffer for preample - n_tx_preamble_modem_samples = codec2.api.freedv_get_n_tx_preamble_modem_samples(freedv) + n_tx_preamble_modem_samples = codec2.api.freedv_get_n_tx_preamble_modem_samples( + freedv + ) mod_out_preamble = create_string_buffer(n_tx_preamble_modem_samples * 2) # init buffer for postamble - n_tx_postamble_modem_samples = codec2.api.freedv_get_n_tx_postamble_modem_samples(freedv) + n_tx_postamble_modem_samples = ( + codec2.api.freedv_get_n_tx_postamble_modem_samples(freedv) + ) mod_out_postamble = create_string_buffer(n_tx_postamble_modem_samples * 2) # add empty data to handle ptt toggle time - data_delay_mseconds = 0 #miliseconds - data_delay = int(self.MODEM_SAMPLE_RATE*(data_delay_mseconds/1000)) - mod_out_silence = create_string_buffer(data_delay*2) - txbuffer = bytes(mod_out_silence) - - structlog.get_logger("structlog").debug("TRANSMIT", mode=self.MODE, payload=payload_bytes_per_frame) - - for i in range(0,repeats): - # codec2 fsk preamble may be broken - at least it sounds like that so we are disabling it for testing - if not self.MODE == 'FSK_LDPC_0' or self.MODE == 200 or self.MODE == 'FSK_LDPC_1' or self.MODE == 201: + data_delay_mseconds = 0 # miliseconds + data_delay = int(self.MODEM_SAMPLE_RATE * (data_delay_mseconds / 1000)) + mod_out_silence = create_string_buffer(data_delay * 2) + txbuffer = bytes(mod_out_silence) + + structlog.get_logger("structlog").debug( + "TRANSMIT", mode=self.MODE, payload=payload_bytes_per_frame + ) + + for i in range(0, repeats): + # codec2 fsk preamble may be broken - at least it sounds like that so we are disabling it for testing + if ( + not self.MODE == "FSK_LDPC_0" + or self.MODE == 200 + or self.MODE == "FSK_LDPC_1" + or self.MODE == 201 + ): # write preamble to txbuffer codec2.api.freedv_rawdatapreambletx(freedv, mod_out_preamble) txbuffer += bytes(mod_out_preamble) # create modulaton for n frames in list - for n in range(0,len(frames)): + for n in range(0, len(frames)): # create buffer for data - buffer = bytearray(payload_bytes_per_frame) # use this if CRC16 checksum is required ( DATA1-3) - buffer[:len(frames[n])] = frames[n] # set buffersize to length of data which will be send + buffer = bytearray( + payload_bytes_per_frame + ) # use this if CRC16 checksum is required ( DATA1-3) + buffer[: len(frames[n])] = frames[ + n + ] # set buffersize to length of data which will be send - # create crc for data frame - we are using the crc function shipped with codec2 to avoid + # create crc for data frame - we are using the crc function shipped with codec2 to avoid # crc algorithm incompatibilities - crc = ctypes.c_ushort(codec2.api.freedv_gen_crc16(bytes(buffer), payload_bytes_per_frame)) # generate CRC16 - crc = crc.value.to_bytes(2, byteorder='big') # convert crc to 2 byte hex string - buffer += crc # append crc16 to buffer - + crc = ctypes.c_ushort( + codec2.api.freedv_gen_crc16(bytes(buffer), payload_bytes_per_frame) + ) # generate CRC16 + crc = crc.value.to_bytes( + 2, byteorder="big" + ) # convert crc to 2 byte hex string + buffer += crc # append crc16 to buffer + data = (ctypes.c_ubyte * bytes_per_frame).from_buffer_copy(buffer) - codec2.api.freedv_rawdatatx(freedv,mod_out,data) # modulate DATA and save it into mod_out pointer + codec2.api.freedv_rawdatatx( + freedv, mod_out, data + ) # modulate DATA and save it into mod_out pointer txbuffer += bytes(mod_out) - - - # codec2 fsk preamble may be broken - at least it sounds like that so we are disabling it for testing - if not self.MODE == 'FSK_LDPC_0' or self.MODE == 200 or self.MODE == 'FSK_LDPC_1' or self.MODE == 201: + + # codec2 fsk preamble may be broken - at least it sounds like that so we are disabling it for testing + if ( + not self.MODE == "FSK_LDPC_0" + or self.MODE == 200 + or self.MODE == "FSK_LDPC_1" + or self.MODE == 201 + ): # write preamble to txbuffer codec2.api.freedv_rawdatapostambletx(freedv, mod_out_postamble) txbuffer += bytes(mod_out_postamble) - # append postamble to txbuffer + # append postamble to txbuffer # add delay to end of frames - samples_delay = int(self.MODEM_SAMPLE_RATE*(repeat_delay/1000)) - mod_out_silence = create_string_buffer(samples_delay*2) + samples_delay = int(self.MODEM_SAMPLE_RATE * (repeat_delay / 1000)) + mod_out_silence = create_string_buffer(samples_delay * 2) txbuffer += bytes(mod_out_silence) - + # resample up to 48k (resampler works on np.int16) x = np.frombuffer(txbuffer, dtype=np.int16) x = set_audio_volume(x, static.TX_AUDIO_LEVEL) @@ -404,9 +539,11 @@ class RF(): # deaktivated for testing purposes self.mod_out_locked = False - - chunk_length = self.AUDIO_FRAMES_PER_BUFFER_TX #4800 - chunk = [txbuffer_48k[i:i+chunk_length] for i in range(0, len(txbuffer_48k), chunk_length)] + chunk_length = self.AUDIO_FRAMES_PER_BUFFER_TX # 4800 + chunk = [ + txbuffer_48k[i : i + chunk_length] + for i in range(0, len(txbuffer_48k), chunk_length) + ] for c in chunk: if len(c) < chunk_length: @@ -414,45 +551,53 @@ class RF(): delta_zeros = np.zeros(delta, dtype=np.int16) c = np.append(c, delta_zeros) - #structlog.get_logger("structlog").debug("[TNC] mod out shorter than audio buffer", delta=delta) + # structlog.get_logger("structlog").debug("[TNC] mod out shorter than audio buffer", delta=delta) self.modoutqueue.append(c) - - - # Release our mod_out_lock so we can use the queue + # Release our mod_out_lock so we can use the queue self.mod_out_locked = False while self.modoutqueue: time.sleep(0.01) - + static.PTT_STATE = self.hamlib.set_ptt(False) - + # push ptt state to socket stream - jsondata = {"ptt":"False"} + jsondata = {"ptt": "False"} data_out = json.dumps(jsondata) sock.SOCKET_QUEUE.put(data_out) - + # after processing we want to set the locking state back to true to be prepared for next transmission self.mod_out_locked = True - + self.c_lib.freedv_close(freedv) self.modem_transmit_queue.task_done() static.TRANSMITTING = False threading.Event().set() - def audio_datac0(self): + def audio_datac0(self): """ """ - nbytes_datac0 = 0 + nbytes_datac0 = 0 while self.stream.active: threading.Event().wait(0.01) - while self.datac0_buffer.nbuffer >= self.datac0_nin: + while self.datac0_buffer.nbuffer >= self.datac0_nin: # demodulate audio - nbytes_datac0 = codec2.api.freedv_rawdatarx(self.datac0_freedv, self.datac0_bytes_out, self.datac0_buffer.buffer.ctypes) + nbytes_datac0 = codec2.api.freedv_rawdatarx( + self.datac0_freedv, + self.datac0_bytes_out, + self.datac0_buffer.buffer.ctypes, + ) self.datac0_buffer.pop(self.datac0_nin) self.datac0_nin = codec2.api.freedv_nin(self.datac0_freedv) if nbytes_datac0 == self.datac0_bytes_per_frame: - self.modem_received_queue.put([self.datac0_bytes_out, self.datac0_freedv ,self.datac0_bytes_per_frame]) - #self.get_scatter(self.datac0_freedv) + self.modem_received_queue.put( + [ + self.datac0_bytes_out, + self.datac0_freedv, + self.datac0_bytes_per_frame, + ] + ) + # self.get_scatter(self.datac0_freedv) self.calculate_snr(self.datac0_freedv) def audio_datac1(self): @@ -462,73 +607,111 @@ class RF(): threading.Event().wait(0.01) while self.datac1_buffer.nbuffer >= self.datac1_nin: # demodulate audio - nbytes_datac1 = codec2.api.freedv_rawdatarx(self.datac1_freedv, self.datac1_bytes_out, self.datac1_buffer.buffer.ctypes) + nbytes_datac1 = codec2.api.freedv_rawdatarx( + self.datac1_freedv, + self.datac1_bytes_out, + self.datac1_buffer.buffer.ctypes, + ) self.datac1_buffer.pop(self.datac1_nin) self.datac1_nin = codec2.api.freedv_nin(self.datac1_freedv) if nbytes_datac1 == self.datac1_bytes_per_frame: - self.modem_received_queue.put([self.datac1_bytes_out, self.datac1_freedv ,self.datac1_bytes_per_frame]) - #self.get_scatter(self.datac1_freedv) + self.modem_received_queue.put( + [ + self.datac1_bytes_out, + self.datac1_freedv, + self.datac1_bytes_per_frame, + ] + ) + # self.get_scatter(self.datac1_freedv) self.calculate_snr(self.datac1_freedv) - - def audio_datac3(self): + + def audio_datac3(self): """ """ nbytes_datac3 = 0 while self.stream.active: threading.Event().wait(0.01) while self.datac3_buffer.nbuffer >= self.datac3_nin: - # demodulate audio - nbytes_datac3 = codec2.api.freedv_rawdatarx(self.datac3_freedv, self.datac3_bytes_out, self.datac3_buffer.buffer.ctypes) + # demodulate audio + nbytes_datac3 = codec2.api.freedv_rawdatarx( + self.datac3_freedv, + self.datac3_bytes_out, + self.datac3_buffer.buffer.ctypes, + ) self.datac3_buffer.pop(self.datac3_nin) self.datac3_nin = codec2.api.freedv_nin(self.datac3_freedv) if nbytes_datac3 == self.datac3_bytes_per_frame: - self.modem_received_queue.put([self.datac3_bytes_out, self.datac3_freedv ,self.datac3_bytes_per_frame]) - #self.get_scatter(self.datac3_freedv) - self.calculate_snr(self.datac3_freedv) - - def audio_fsk_ldpc_0(self): + self.modem_received_queue.put( + [ + self.datac3_bytes_out, + self.datac3_freedv, + self.datac3_bytes_per_frame, + ] + ) + # self.get_scatter(self.datac3_freedv) + self.calculate_snr(self.datac3_freedv) + + def audio_fsk_ldpc_0(self): """ """ nbytes_fsk_ldpc_0 = 0 while self.stream.active and static.ENABLE_FSK: threading.Event().wait(0.01) while self.fsk_ldpc_buffer_0.nbuffer >= self.fsk_ldpc_nin_0: - # demodulate audio - nbytes_fsk_ldpc_0 = codec2.api.freedv_rawdatarx(self.fsk_ldpc_freedv_0, self.fsk_ldpc_bytes_out_0, self.fsk_ldpc_buffer_0.buffer.ctypes) + # demodulate audio + nbytes_fsk_ldpc_0 = codec2.api.freedv_rawdatarx( + self.fsk_ldpc_freedv_0, + self.fsk_ldpc_bytes_out_0, + self.fsk_ldpc_buffer_0.buffer.ctypes, + ) self.fsk_ldpc_buffer_0.pop(self.fsk_ldpc_nin_0) self.fsk_ldpc_nin_0 = codec2.api.freedv_nin(self.fsk_ldpc_freedv_0) if nbytes_fsk_ldpc_0 == self.fsk_ldpc_bytes_per_frame_0: - self.modem_received_queue.put([self.fsk_ldpc_bytes_out_0, self.fsk_ldpc_freedv_0 ,self.fsk_ldpc_bytes_per_frame_0]) - #self.get_scatter(self.fsk_ldpc_freedv_0) - self.calculate_snr(self.fsk_ldpc_freedv_0) + self.modem_received_queue.put( + [ + self.fsk_ldpc_bytes_out_0, + self.fsk_ldpc_freedv_0, + self.fsk_ldpc_bytes_per_frame_0, + ] + ) + # self.get_scatter(self.fsk_ldpc_freedv_0) + self.calculate_snr(self.fsk_ldpc_freedv_0) - def audio_fsk_ldpc_1(self): + def audio_fsk_ldpc_1(self): """ """ nbytes_fsk_ldpc_1 = 0 while self.stream.active and static.ENABLE_FSK: threading.Event().wait(0.01) while self.fsk_ldpc_buffer_1.nbuffer >= self.fsk_ldpc_nin_1: - # demodulate audio - nbytes_fsk_ldpc_1 = codec2.api.freedv_rawdatarx(self.fsk_ldpc_freedv_1, self.fsk_ldpc_bytes_out_1, self.fsk_ldpc_buffer_1.buffer.ctypes) + # demodulate audio + nbytes_fsk_ldpc_1 = codec2.api.freedv_rawdatarx( + self.fsk_ldpc_freedv_1, + self.fsk_ldpc_bytes_out_1, + self.fsk_ldpc_buffer_1.buffer.ctypes, + ) self.fsk_ldpc_buffer_1.pop(self.fsk_ldpc_nin_1) self.fsk_ldpc_nin_1 = codec2.api.freedv_nin(self.fsk_ldpc_freedv_1) if nbytes_fsk_ldpc_1 == self.fsk_ldpc_bytes_per_frame_1: - self.modem_received_queue.put([self.fsk_ldpc_bytes_out_1, self.fsk_ldpc_freedv_1 ,self.fsk_ldpc_bytes_per_frame_1]) - #self.get_scatter(self.fsk_ldpc_freedv_1) - self.calculate_snr(self.fsk_ldpc_freedv_1) - - - - # worker for FIFO queue for processing received frames + self.modem_received_queue.put( + [ + self.fsk_ldpc_bytes_out_1, + self.fsk_ldpc_freedv_1, + self.fsk_ldpc_bytes_per_frame_1, + ] + ) + # self.get_scatter(self.fsk_ldpc_freedv_1) + self.calculate_snr(self.fsk_ldpc_freedv_1) + + # worker for FIFO queue for processing received frames def worker_transmit(self): """ """ while True: data = self.modem_transmit_queue.get() - - self.transmit(mode=data[0], repeats=data[1], repeat_delay=data[2], frames=data[3]) - #self.modem_transmit_queue.task_done() - - - # worker for FIFO queue for processing received frames + self.transmit( + mode=data[0], repeats=data[1], repeat_delay=data[2], frames=data[3] + ) + # self.modem_transmit_queue.task_done() + + # worker for FIFO queue for processing received frames def worker_received(self): """ """ while True: @@ -538,13 +721,12 @@ class RF(): # data[2] = bytes_per_frame data_handler.DATA_QUEUE_RECEIVED.put([data[0], data[1], data[2]]) self.modem_received_queue.task_done() - def get_frequency_offset(self, freedv): """ Args: - freedv: + freedv: Returns: @@ -555,13 +737,12 @@ class RF(): offset = round(modemStats.foff) * (-1) static.FREQ_OFFSET = offset return offset - - + def get_scatter(self, freedv): """ Args: - freedv: + freedv: Returns: @@ -577,8 +758,8 @@ class RF(): for j in range(codec2.MODEM_STATS_NR_MAX): # check if odd or not to get every 2nd item for x if (j % 2) == 0: - xsymbols = round(modemStats.rx_symbols[i][j]/1000) - ysymbols = round(modemStats.rx_symbols[i][j+1]/1000) + xsymbols = round(modemStats.rx_symbols[i][j] / 1000) + ysymbols = round(modemStats.rx_symbols[i][j + 1] / 1000) # check if value 0.0 or has real data if xsymbols != 0.0 and ysymbols != 0.0: scatterdata.append({"x": xsymbols, "y": ysymbols}) @@ -591,12 +772,11 @@ class RF(): scatterdata_small = scatterdata[::10] static.SCATTER = scatterdata_small - def calculate_snr(self, freedv): """ Args: - freedv: + freedv: Returns: @@ -606,13 +786,15 @@ class RF(): modem_stats_snr = c_float() modem_stats_sync = c_int() - self.c_lib.freedv_get_modem_stats(freedv, byref(modem_stats_sync), byref(modem_stats_snr)) + self.c_lib.freedv_get_modem_stats( + freedv, byref(modem_stats_sync), byref(modem_stats_snr) + ) modem_stats_snr = modem_stats_snr.value modem_stats_sync = modem_stats_sync.value snr = round(modem_stats_snr, 1) print(snr) - static.SNR = np.clip(snr, 0, 255) #limit to max value of 255 + static.SNR = np.clip(snr, 0, 255) # limit to max value of 255 return static.SNR except: static.SNR = 0 @@ -621,26 +803,25 @@ class RF(): def update_rig_data(self): """ """ while True: - #time.sleep(1.5) + # time.sleep(1.5) threading.Event().wait(0.5) - #(static.HAMLIB_FREQUENCY, static.HAMLIB_MODE, static.HAMLIB_BANDWITH, static.PTT_STATE) = self.hamlib.get_rig_data() + # (static.HAMLIB_FREQUENCY, static.HAMLIB_MODE, static.HAMLIB_BANDWITH, static.PTT_STATE) = self.hamlib.get_rig_data() static.HAMLIB_FREQUENCY = self.hamlib.get_frequency() static.HAMLIB_MODE = self.hamlib.get_mode() static.HAMLIB_BANDWITH = self.hamlib.get_bandwith() - def calculate_fft(self): """ """ # channel_busy_delay counter channel_busy_delay = 0 - + while True: - #time.sleep(0.01) + # time.sleep(0.01) threading.Event().wait(0.01) - # WE NEED TO OPTIMIZE THIS! - + # WE NEED TO OPTIMIZE THIS! + if len(self.fft_data) >= 128: - + # https://gist.github.com/ZWMiller/53232427efc5088007cab6feee7c6e4c # Fast Fourier Transform, 10*log10(abs) is to scale it to dB # and make sure it's not imaginary @@ -650,92 +831,101 @@ class RF(): # set value 0 to 1 to avoid division by zero fftarray[fftarray == 0] = 1 - dfft = 10.*np.log10(abs(fftarray)) - + dfft = 10.0 * np.log10(abs(fftarray)) + # get average of dfft avg = np.mean(dfft) - # detect signals which are higher than the average + 10 ( +10 smoothes the output ) # data higher than the average must be a signal. Therefore we are setting it to 100 so it will be highlighted # have to do this when we are not transmittig so our own sending data will not affect this too much if not static.TRANSMITTING: - dfft[dfft>avg+10] = 100 - + dfft[dfft > avg + 10] = 100 + # calculate audio max value - #static.AUDIO_RMS = np.amax(self.fft_data) - - + # static.AUDIO_RMS = np.amax(self.fft_data) + # 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(dfft[dfft>avg+10]) >= 300 and not static.TRANSMITTING: + + if np.sum(dfft[dfft > avg + 10]) >= 300 and not static.TRANSMITTING: static.CHANNEL_BUSY = True channel_busy_delay += 5 # limit delay counter to a maximun of 30. The higher this value, the linger we will wait until releasing state if channel_busy_delay > 50: channel_busy_delay = 50 else: - # decrement channel busy counter if no signal has been detected. + # decrement channel busy counter if no signal has been detected. channel_busy_delay -= 1 if channel_busy_delay < 0: channel_busy_delay = 0 # if our channel busy counter reached 0, we toggle state to False if channel_busy_delay == 0: static.CHANNEL_BUSY = False - + # round data to decrease size dfft = np.around(dfft, 0) dfftlist = dfft.tolist() - - static.FFT = dfftlist[0:320] #200 --> bandwith 3000 + + static.FFT = dfftlist[0:320] # 200 --> bandwith 3000 except: - + structlog.get_logger("structlog").debug("[TNC] Setting fft=0") # else 0 static.FFT = [0] else: pass - + def set_frames_per_burst(self, n_frames_per_burst): """ Args: - n_frames_per_burst: + n_frames_per_burst: Returns: """ - codec2.api.freedv_set_frames_per_burst(self.datac1_freedv,n_frames_per_burst) - codec2.api.freedv_set_frames_per_burst(self.datac3_freedv,n_frames_per_burst) - codec2.api.freedv_set_frames_per_burst(self.fsk_ldpc_freedv_0,n_frames_per_burst) - - - + codec2.api.freedv_set_frames_per_burst(self.datac1_freedv, n_frames_per_burst) + codec2.api.freedv_set_frames_per_burst(self.datac3_freedv, n_frames_per_burst) + codec2.api.freedv_set_frames_per_burst( + self.fsk_ldpc_freedv_0, n_frames_per_burst + ) + + def get_bytes_per_frame(mode): """ provide bytes per frame information for accessing from data handler - + Args: - mode: + mode: Returns: """ if mode == 200: - freedv = cast(codec2.api.freedv_open_advanced(codec2.api.FREEDV_MODE_FSK_LDPC, ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_0_ADV)), c_void_p) + freedv = cast( + codec2.api.freedv_open_advanced( + codec2.api.FREEDV_MODE_FSK_LDPC, + ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_0_ADV), + ), + c_void_p, + ) elif mode == 201: - freedv = cast(codec2.api.freedv_open_advanced(codec2.api.FREEDV_MODE_FSK_LDPC, ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_1_ADV)), c_void_p) + freedv = cast( + codec2.api.freedv_open_advanced( + codec2.api.FREEDV_MODE_FSK_LDPC, + ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_1_ADV), + ), + c_void_p, + ) else: freedv = cast(codec2.api.freedv_open(mode), c_void_p) # get number of bytes per frame for mode - return int(codec2.api.freedv_get_bits_per_modem_frame(freedv)/8) - - + return int(codec2.api.freedv_get_bits_per_modem_frame(freedv) / 8) + + def set_audio_volume(datalist, volume): - data = np.fromstring(datalist, np.int16) * (volume / 100.) + data = np.fromstring(datalist, np.int16) * (volume / 100.0) return data.astype(np.int16) - - diff --git a/tnc/rig.py b/tnc/rig.py index 05e62548..3c4dd1be 100644 --- a/tnc/rig.py +++ b/tnc/rig.py @@ -20,103 +20,133 @@ except: sys.path.append(app_path) -# try importing hamlib +# try importing hamlib try: # get python version python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1]) # installation path for Ubuntu 20.04 LTS python modules - #sys.path.append('/usr/local/lib/python'+ python_version +'/site-packages') - + # sys.path.append('/usr/local/lib/python'+ python_version +'/site-packages') + # installation path for Ubuntu 20.10 + - sys.path.append('/usr/local/lib/') - + sys.path.append("/usr/local/lib/") + # installation path for Suse - sys.path.append('/usr/local/lib64/python'+ python_version +'/site-packages') + sys.path.append("/usr/local/lib64/python" + python_version + "/site-packages") # everything else... not nice, but an attempt to see how its running within app bundle # this is not needed as python will be shipped with app bundle - sys.path.append('/usr/local/lib/python3.6/site-packages') - sys.path.append('/usr/local/lib/python3.7/site-packages') - sys.path.append('/usr/local/lib/python3.8/site-packages') - sys.path.append('/usr/local/lib/python3.9/site-packages') - sys.path.append('/usr/local/lib/python3.10/site-packages') - - sys.path.append('lib/hamlib/linux/python3.8/site-packages') + sys.path.append("/usr/local/lib/python3.6/site-packages") + sys.path.append("/usr/local/lib/python3.7/site-packages") + sys.path.append("/usr/local/lib/python3.8/site-packages") + sys.path.append("/usr/local/lib/python3.9/site-packages") + sys.path.append("/usr/local/lib/python3.10/site-packages") + + sys.path.append("lib/hamlib/linux/python3.8/site-packages") import Hamlib - + # https://stackoverflow.com/a/4703409 - hamlib_version = re.findall(r"[-+]?\d*\.?\d+|\d+", Hamlib.cvar.hamlib_version) + hamlib_version = re.findall(r"[-+]?\d*\.?\d+|\d+", Hamlib.cvar.hamlib_version) hamlib_version = float(hamlib_version[0]) - + min_hamlib_version = 4.1 if hamlib_version > min_hamlib_version: - structlog.get_logger("structlog").info("[RIG] Hamlib found", version=hamlib_version) + structlog.get_logger("structlog").info( + "[RIG] Hamlib found", version=hamlib_version + ) else: - structlog.get_logger("structlog").warning("[RIG] Hamlib outdated", found=hamlib_version, recommend=min_hamlib_version) + structlog.get_logger("structlog").warning( + "[RIG] Hamlib outdated", found=hamlib_version, recommend=min_hamlib_version + ) except Exception as e: - structlog.get_logger("structlog").warning("[RIG] Python Hamlib binding not found", error=e) + structlog.get_logger("structlog").warning( + "[RIG] Python Hamlib binding not found", error=e + ) try: structlog.get_logger("structlog").warning("[RIG] Trying to open rigctl") - rigctl = subprocess.Popen("rigctl -V",shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + rigctl = subprocess.Popen( + "rigctl -V", + shell=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + text=True, + ) hamlib_version = rigctl.stdout.readline() - hamlib_version = hamlib_version.split(' ') + hamlib_version = hamlib_version.split(" ") - if hamlib_version[1] == 'Hamlib': - structlog.get_logger("structlog").warning("[RIG] Rigctl found! Please try using this", version=hamlib_version[2]) + if hamlib_version[1] == "Hamlib": + structlog.get_logger("structlog").warning( + "[RIG] Rigctl found! Please try using this", version=hamlib_version[2] + ) sys.exit() else: raise Exception except Exception as e: - structlog.get_logger("structlog").critical("[RIG] HAMLIB NOT INSTALLED", error=e) + structlog.get_logger("structlog").critical( + "[RIG] HAMLIB NOT INSTALLED", error=e + ) hamlib_version = 0 sys.exit() - - + + class radio: """ """ + def __init__(self): - - self.devicename = '' - self.devicenumber = '' - self.deviceport = '' - self.serialspeed = '' - self.hamlib_ptt_type = '' - self.my_rig = '' - self.pttport = '' - self.data_bits = '' - self.stop_bits = '' - self.handshake = '' - - def open_rig(self, devicename, deviceport, hamlib_ptt_type, serialspeed, pttport, data_bits, stop_bits, handshake, rigctld_port, rigctld_ip): + + self.devicename = "" + self.devicenumber = "" + self.deviceport = "" + self.serialspeed = "" + self.hamlib_ptt_type = "" + self.my_rig = "" + self.pttport = "" + self.data_bits = "" + self.stop_bits = "" + self.handshake = "" + + def open_rig( + self, + devicename, + deviceport, + hamlib_ptt_type, + serialspeed, + pttport, + data_bits, + stop_bits, + handshake, + rigctld_port, + rigctld_ip, + ): """ Args: - devicename: - deviceport: - hamlib_ptt_type: - serialspeed: - pttport: - data_bits: - stop_bits: - handshake: - rigctld_port: - rigctld_ip: + devicename: + deviceport: + hamlib_ptt_type: + serialspeed: + pttport: + data_bits: + stop_bits: + handshake: + rigctld_port: + rigctld_ip: Returns: """ - + self.devicename = devicename self.deviceport = str(deviceport) - self.serialspeed = str(serialspeed) # we need to ensure this is a str, otherwise set_conf functions are crashing + self.serialspeed = str( + serialspeed + ) # we need to ensure this is a str, otherwise set_conf functions are crashing self.hamlib_ptt_type = str(hamlib_ptt_type) self.pttport = str(pttport) self.data_bits = str(data_bits) self.stop_bits = str(stop_bits) self.handshake = str(handshake) - - + # try to init hamlib try: Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE) @@ -125,10 +155,11 @@ class radio: try: self.devicenumber = int(getattr(Hamlib, self.devicename)) except: - structlog.get_logger("structlog").error("[RIG] Hamlib: rig not supported...") + structlog.get_logger("structlog").error( + "[RIG] Hamlib: rig not supported..." + ) self.devicenumber = 0 - - + self.my_rig = Hamlib.Rig(self.devicenumber) self.my_rig.set_conf("rig_pathname", self.deviceport) self.my_rig.set_conf("retry", "5") @@ -137,109 +168,120 @@ class radio: self.my_rig.set_conf("stop_bits", self.stop_bits) self.my_rig.set_conf("data_bits", self.data_bits) self.my_rig.set_conf("ptt_pathname", self.pttport) - - - - if self.hamlib_ptt_type == 'RIG': + if self.hamlib_ptt_type == "RIG": self.hamlib_ptt_type = Hamlib.RIG_PTT_RIG - self.my_rig.set_conf("ptt_type", 'RIG') + self.my_rig.set_conf("ptt_type", "RIG") - elif self.hamlib_ptt_type == 'USB': + elif self.hamlib_ptt_type == "USB": self.hamlib_ptt_type = Hamlib.RIG_PORT_USB - self.my_rig.set_conf("ptt_type", 'USB') + self.my_rig.set_conf("ptt_type", "USB") - - elif self.hamlib_ptt_type == 'DTR-H': + elif self.hamlib_ptt_type == "DTR-H": self.hamlib_ptt_type = Hamlib.RIG_PTT_SERIAL_DTR self.my_rig.set_conf("dtr_state", "HIGH") self.my_rig.set_conf("ptt_type", "DTR") - elif self.hamlib_ptt_type == 'DTR-L': + elif self.hamlib_ptt_type == "DTR-L": self.hamlib_ptt_type = Hamlib.RIG_PTT_SERIAL_DTR self.my_rig.set_conf("dtr_state", "LOW") self.my_rig.set_conf("ptt_type", "DTR") - elif self.hamlib_ptt_type == 'RTS': + elif self.hamlib_ptt_type == "RTS": self.hamlib_ptt_type = Hamlib.RIG_PTT_SERIAL_RTS self.my_rig.set_conf("dtr_state", "OFF") self.my_rig.set_conf("ptt_type", "RTS") - elif self.hamlib_ptt_type == 'PARALLEL': + elif self.hamlib_ptt_type == "PARALLEL": self.hamlib_ptt_type = Hamlib.RIG_PTT_PARALLEL - elif self.hamlib_ptt_type == 'MICDATA': + elif self.hamlib_ptt_type == "MICDATA": self.hamlib_ptt_type = Hamlib.RIG_PTT_RIG_MICDATA - elif self.hamlib_ptt_type == 'CM108': + elif self.hamlib_ptt_type == "CM108": self.hamlib_ptt_type = Hamlib.RIG_PTT_CM108 - elif self.hamlib_ptt_type == 'RIG_PTT_NONE': - self.hamlib_ptt_type = Hamlib.RIG_PTT_NONE - - else: #self.hamlib_ptt_type == 'RIG_PTT_NONE': + elif self.hamlib_ptt_type == "RIG_PTT_NONE": self.hamlib_ptt_type = Hamlib.RIG_PTT_NONE - structlog.get_logger("structlog").info("[RIG] Opening...", device=self.devicenumber, path=self.my_rig.get_conf("rig_pathname"), serial_speed=self.my_rig.get_conf("serial_speed"), serial_handshake=self.my_rig.get_conf("serial_handshake"), stop_bits=self.my_rig.get_conf("stop_bits"), data_bits=self.my_rig.get_conf("data_bits"), ptt_pathname=self.my_rig.get_conf("ptt_pathname")) + else: # self.hamlib_ptt_type == 'RIG_PTT_NONE': + self.hamlib_ptt_type = Hamlib.RIG_PTT_NONE + structlog.get_logger("structlog").info( + "[RIG] Opening...", + device=self.devicenumber, + path=self.my_rig.get_conf("rig_pathname"), + serial_speed=self.my_rig.get_conf("serial_speed"), + serial_handshake=self.my_rig.get_conf("serial_handshake"), + stop_bits=self.my_rig.get_conf("stop_bits"), + data_bits=self.my_rig.get_conf("data_bits"), + ptt_pathname=self.my_rig.get_conf("ptt_pathname"), + ) self.my_rig.open() atexit.register(self.my_rig.close) - + try: # lets determine the error message when opening rig error = str(Hamlib.rigerror(my_rig.error_status)).splitlines() - error = error[1].split('err=') + error = error[1].split("err=") error = error[1] - - if error == 'Permission denied': - structlog.get_logger("structlog").error("[RIG] Hamlib has no permissions", e = error) - help_url = 'https://github.com/DJ2LS/FreeDATA/wiki/UBUNTU-Manual-installation#1-permissions' - structlog.get_logger("structlog").error("[RIG] HELP:", check = help_url) - except: - structlog.get_logger("structlog").info("[RIG] Hamlib device opened", status='SUCCESS') + if error == "Permission denied": + structlog.get_logger("structlog").error( + "[RIG] Hamlib has no permissions", e=error + ) + help_url = "https://github.com/DJ2LS/FreeDATA/wiki/UBUNTU-Manual-installation#1-permissions" + structlog.get_logger("structlog").error( + "[RIG] HELP:", check=help_url + ) + except: + structlog.get_logger("structlog").info( + "[RIG] Hamlib device opened", status="SUCCESS" + ) # set ptt to false if ptt is stuck for some reason self.set_ptt(False) # set rig mode to USB # temporarly outcommented because of possible problems. - #self.my_rig.set_mode(Hamlib.RIG_MODE_USB) + # self.my_rig.set_mode(Hamlib.RIG_MODE_USB) # self.my_rig.set_mode(Hamlib.RIG_MODE_PKTUSB) return True except Exception as e: - structlog.get_logger("structlog").error("[RIG] Hamlib - can't open rig", error=e, e=sys.exc_info()[0]) + structlog.get_logger("structlog").error( + "[RIG] Hamlib - can't open rig", error=e, e=sys.exc_info()[0] + ) return False - + def get_frequency(self): """ """ return int(self.my_rig.get_freq()) - + def get_mode(self): """ """ (hamlib_mode, bandwith) = self.my_rig.get_mode() return Hamlib.rig_strrmode(hamlib_mode) - + def get_bandwith(self): """ """ (hamlib_mode, bandwith) = self.my_rig.get_mode() return bandwith # not needed yet beacuse of some possible problems - #def set_mode(self, mode): + # def set_mode(self, mode): # return 0 - + def get_ptt(self): """ """ return self.my_rig.get_ptt() - + def set_ptt(self, state): """ Args: - state: + state: Returns: @@ -249,7 +291,7 @@ class radio: else: self.my_rig.set_ptt(Hamlib.RIG_VFO_CURR, 0) return state - + def close_rig(self): """ """ self.my_rig.close() diff --git a/tnc/rigctl.py b/tnc/rigctl.py index 8a9c1f65..ad7f7c24 100644 --- a/tnc/rigctl.py +++ b/tnc/rigctl.py @@ -13,123 +13,149 @@ import structlog import time import sys import os + # for rig_model -> rig_number only # set global hamlib version hamlib_version = 0 - + + class radio: """ """ + def __init__(self): - - self.devicename = '' - self.devicenumber = '' - self.deviceport = '' - self.serialspeed = '' - self.hamlib_ptt_type = '' - self.my_rig = '' - self.pttport = '' - self.data_bits = '' - self.stop_bits = '' - self.handshake = '' - - def open_rig(self, devicename, deviceport, hamlib_ptt_type, serialspeed, pttport, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port): + + self.devicename = "" + self.devicenumber = "" + self.deviceport = "" + self.serialspeed = "" + self.hamlib_ptt_type = "" + self.my_rig = "" + self.pttport = "" + self.data_bits = "" + self.stop_bits = "" + self.handshake = "" + + def open_rig( + self, + devicename, + deviceport, + hamlib_ptt_type, + serialspeed, + pttport, + data_bits, + stop_bits, + handshake, + rigctld_ip, + rigctld_port, + ): """ Args: - devicename: - deviceport: - hamlib_ptt_type: - serialspeed: - pttport: - data_bits: - stop_bits: - handshake: - rigctld_ip: - rigctld_port: + devicename: + deviceport: + hamlib_ptt_type: + serialspeed: + pttport: + data_bits: + stop_bits: + handshake: + rigctld_ip: + rigctld_port: Returns: """ - + self.devicename = devicename self.deviceport = deviceport - self.serialspeed = str(serialspeed) # we need to ensure this is a str, otherwise set_conf functions are crashing + self.serialspeed = str( + serialspeed + ) # we need to ensure this is a str, otherwise set_conf functions are crashing self.hamlib_ptt_type = hamlib_ptt_type self.pttport = pttport self.data_bits = data_bits self.stop_bits = stop_bits self.handshake = handshake - - - # check if we are running in a pyinstaller environment + + # check if we are running in a pyinstaller environment try: app_path = sys._MEIPASS except: app_path = os.path.abspath(".") - sys.path.append(app_path) - + sys.path.append(app_path) + # get devicenumber by looking for deviceobject in Hamlib module try: import Hamlib + self.devicenumber = int(getattr(Hamlib, self.devicename)) except: if int(self.devicename): self.devicenumber = int(self.devicename) else: - self.devicenumber = 6 #dummy - structlog.get_logger("structlog").warning("[RIGCTL] RADIO NOT FOUND USING DUMMY!", error=e) - + self.devicenumber = 6 # dummy + structlog.get_logger("structlog").warning( + "[RIGCTL] RADIO NOT FOUND USING DUMMY!", error=e + ) + # set deviceport to dummy port, if we selected dummy model if self.devicenumber == 1 or self.devicenumber == 6: - self.deviceport = '/dev/ttyUSB0' - + self.deviceport = "/dev/ttyUSB0" + print(self.devicenumber, self.deviceport, self.serialspeed) - - - # select precompiled executable for win32/win64 rigctl # this is really a hack...somewhen we need a native hamlib integration for windows - if sys.platform == 'win32' or sys.platform == 'win64': - self.cmd = app_path + 'lib\\hamlib\\'+sys.platform+'\\rigctl -m %d -r %s -s %d ' % (int(self.devicenumber), self.deviceport, int(self.serialspeed)) - + if sys.platform == "win32" or sys.platform == "win64": + self.cmd = ( + app_path + + "lib\\hamlib\\" + + sys.platform + + "\\rigctl -m %d -r %s -s %d " + % (int(self.devicenumber), self.deviceport, int(self.serialspeed)) + ) + else: - self.cmd = 'rigctl -m %d -r %s -s %d ' % (int(self.devicenumber), self.deviceport, int(self.serialspeed)) + self.cmd = "rigctl -m %d -r %s -s %d " % ( + int(self.devicenumber), + self.deviceport, + int(self.serialspeed), + ) # eseguo semplicemente rigctl con il solo comando T 1 o T 0 per - # il set e t per il get + # il set e t per il get # set ptt to false if ptt is stuck for some reason self.set_ptt(False) return True - + def get_frequency(self): """ """ - cmd = self.cmd + ' f' - sw_proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + cmd = self.cmd + " f" + sw_proc = subprocess.Popen( + cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True + ) time.sleep(0.5) freq = sw_proc.communicate()[0] - #print('get_frequency', freq, sw_proc.communicate()) + # print('get_frequency', freq, sw_proc.communicate()) try: return int(freq) except: return False - def get_mode(self): """ """ - #(hamlib_mode, bandwith) = self.my_rig.get_mode() - #return Hamlib.rig_strrmode(hamlib_mode) + # (hamlib_mode, bandwith) = self.my_rig.get_mode() + # return Hamlib.rig_strrmode(hamlib_mode) try: - return 'PKTUSB' + return "PKTUSB" except: return False - def get_bandwith(self): """ """ - #(hamlib_mode, bandwith) = self.my_rig.get_mode() + # (hamlib_mode, bandwith) = self.my_rig.get_mode() bandwith = 2700 try: @@ -141,18 +167,20 @@ class radio: """ Args: - mode: + mode: Returns: """ # non usata return 0 - + def get_ptt(self): """ """ - cmd = self.cmd + ' t' - sw_proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + cmd = self.cmd + " t" + sw_proc = subprocess.Popen( + cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True + ) time.sleep(0.5) status = sw_proc.communicate()[0] @@ -160,31 +188,31 @@ class radio: return status except: return False - + def set_ptt(self, state): """ Args: - state: + state: Returns: """ - cmd = self.cmd + ' T ' - print('set_ptt', state) + cmd = self.cmd + " T " + print("set_ptt", state) if state: - cmd = cmd + '1' + cmd = cmd + "1" else: - cmd = cmd + '0' - print('set_ptt', cmd) + cmd = cmd + "0" + print("set_ptt", cmd) - sw_proc = subprocess.Popen(cmd, shell=True, text=True) + sw_proc = subprocess.Popen(cmd, shell=True, text=True) try: return state except: return False - + def close_rig(self): """ """ - #self.my_rig.close() + # self.my_rig.close() return diff --git a/tnc/rigctld.py b/tnc/rigctld.py index 6d3f5660..2250f1a9 100644 --- a/tnc/rigctld.py +++ b/tnc/rigctld.py @@ -5,6 +5,7 @@ import log_handler import logging import time import static + # class taken from darsidelemm # rigctl - https://github.com/darksidelemm/rotctld-web-gui/blob/master/rotatorgui.py#L35 # @@ -13,117 +14,148 @@ import static # set global hamlib version hamlib_version = 0 -class radio(): + +class radio: """rotctld (hamlib) communication class""" - # Note: This is a massive hack. + + # Note: This is a massive hack. def __init__(self, hostname="localhost", port=4532, poll_rate=5, timeout=5): - """ Open a connection to rotctld, and test it for validity """ + """Open a connection to rotctld, and test it for validity""" self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - #self.sock.settimeout(timeout) + # self.sock.settimeout(timeout) self.connected = False self.hostname = hostname self.port = port self.connection_attempts = 5 - def open_rig(self, devicename, deviceport, hamlib_ptt_type, serialspeed, pttport, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port): + def open_rig( + self, + devicename, + deviceport, + hamlib_ptt_type, + serialspeed, + pttport, + data_bits, + stop_bits, + handshake, + rigctld_ip, + rigctld_port, + ): """ Args: - devicename: - deviceport: - hamlib_ptt_type: - serialspeed: - pttport: - data_bits: - stop_bits: - handshake: - rigctld_ip: - rigctld_port: + devicename: + deviceport: + hamlib_ptt_type: + serialspeed: + pttport: + data_bits: + stop_bits: + handshake: + rigctld_ip: + rigctld_port: Returns: """ self.hostname = rigctld_ip self.port = int(rigctld_port) - - + if self.connect(): logging.debug(f"Rigctl intialized") return True else: - structlog.get_logger("structlog").error("[RIGCTLD] Can't connect to rigctld!", ip=self.hostname, port=self.port) + structlog.get_logger("structlog").error( + "[RIGCTLD] Can't connect to rigctld!", ip=self.hostname, port=self.port + ) return False - + def connect(self): """Connect to rigctld instance""" if not self.connected: try: - self.connection = socket.create_connection((self.hostname,self.port)) + self.connection = socket.create_connection((self.hostname, self.port)) self.connected = True - structlog.get_logger("structlog").info("[RIGCTLD] Connected to rigctld!", ip=self.hostname, port=self.port) + structlog.get_logger("structlog").info( + "[RIGCTLD] Connected to rigctld!", ip=self.hostname, port=self.port + ) return True except Exception as e: # ConnectionRefusedError: [Errno 111] Connection refused self.close_rig() - structlog.get_logger("structlog").warning("[RIGCTLD] Connection to rigctld refused! Reconnect...", ip=self.hostname, port=self.port, e=e) + structlog.get_logger("structlog").warning( + "[RIGCTLD] Connection to rigctld refused! Reconnect...", + ip=self.hostname, + port=self.port, + e=e, + ) return False - + def close_rig(self): """ """ self.sock.close() self.connected = False - def send_command(self, command): """Send a command to the connected rotctld instance, and return the return value. Args: - command: + command: Returns: """ if self.connected: try: - self.connection.sendall(command+b'\n') + self.connection.sendall(command + b"\n") except: - structlog.get_logger("structlog").warning("[RIGCTLD] Command not executed!", command=command, ip=self.hostname, port=self.port) + structlog.get_logger("structlog").warning( + "[RIGCTLD] Command not executed!", + command=command, + ip=self.hostname, + port=self.port, + ) self.connected = False try: return self.connection.recv(1024) except: - structlog.get_logger("structlog").warning("[RIGCTLD] No command response!", command=command, ip=self.hostname, port=self.port) + structlog.get_logger("structlog").warning( + "[RIGCTLD] No command response!", + command=command, + ip=self.hostname, + port=self.port, + ) self.connected = False else: - + # reconnecting.... time.sleep(0.5) self.connect() - def get_mode(self): """ """ try: data = self.send_command(b"m") - data = data.split(b'\n') + data = data.split(b"\n") mode = data[0] - return mode.decode("utf-8") + return mode.decode("utf-8") except: 0 + def get_bandwith(self): """ """ try: data = self.send_command(b"m") - data = data.split(b'\n') + data = data.split(b"\n") bandwith = data[1] return bandwith.decode("utf-8") except: return 0 - + def get_frequency(self): """ """ try: @@ -131,28 +163,28 @@ class radio(): return frequency.decode("utf-8") except: return 0 - + def get_ptt(self): """ """ try: return self.send_command(b"t") except: return False - + def set_ptt(self, state): """ Args: - state: + state: Returns: """ try: if state: - self.send_command(b"T 1") + self.send_command(b"T 1") else: - self.send_command(b"T 0") - return state + self.send_command(b"T 0") + return state except: return False diff --git a/tnc/rigdummy.py b/tnc/rigdummy.py index cff2ce47..ccd3012f 100644 --- a/tnc/rigdummy.py +++ b/tnc/rigdummy.py @@ -3,32 +3,33 @@ import structlog hamlib_version = 0 - + + class radio: """ """ + def __init__(self): pass - - def open_rig(self, **kwargs): + def open_rig(self, **kwargs): """ Args: - **kwargs: + **kwargs: Returns: """ return True - + def get_frequency(self): """ """ return None - + def get_mode(self): """ """ return None - + def get_bandwith(self): """ """ return None @@ -37,29 +38,28 @@ class radio: """ Args: - mode: + mode: Returns: """ return None - + def get_ptt(self): """ """ return None - - def set_ptt(self, state): + + def set_ptt(self, state): """ Args: - state: + state: Returns: """ return state - + def close_rig(self): """ """ return - diff --git a/tnc/sock.py b/tnc/sock.py index bcaa323f..4f9d2533 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -42,34 +42,29 @@ CONNECTED_CLIENTS = set() CLOSE_SIGNAL = False - - - - class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): """ the socket handler base class """ + pass - - - + + class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): """ """ - def send_to_client(self): """ function called by socket handler send data to a network client if available - + """ - tempdata = b'' + tempdata = b"" while self.connection_alive and not CLOSE_SIGNAL: # send tnc state as network stream # check server port against daemon port and send corresponding data - + if self.server.server_address[1] == static.PORT and not static.TNCSTARTED: data = send_tnc_state() if data != tempdata: @@ -81,15 +76,14 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): tempdata = data SOCKET_QUEUE.put(data) time.sleep(0.5) - while not SOCKET_QUEUE.empty(): data = SOCKET_QUEUE.get() - sock_data = bytes(data, 'utf-8') - sock_data += b'\n' # append line limiter - + sock_data = bytes(data, "utf-8") + sock_data += b"\n" # append line limiter + # send data to all clients - #try: + # try: for client in CONNECTED_CLIENTS: try: client.send(sock_data) @@ -101,8 +95,8 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): # we want to transmit scatter data only once to reduce network traffic static.SCATTER = [] # we want to display INFO messages only once - static.INFO = [] - #self.request.sendall(sock_data) + static.INFO = [] + # self.request.sendall(sock_data) time.sleep(0.15) def receive_from_client(self): @@ -115,18 +109,17 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): try: chunk = self.request.recv(1024) data += chunk - - if chunk == b'': - #print("connection broken. Closing...") - self.connection_alive = False - - if data.startswith(b'{') and data.endswith(b'}\n'): + if chunk == b"": + # print("connection broken. Closing...") + self.connection_alive = False + + if data.startswith(b"{") and data.endswith(b"}\n"): # split data by \n if we have multiple commands in socket buffer - data = data.split(b'\n') + data = data.split(b"\n") # remove empty data - data.remove(b'') - + data.remove(b"") + # iterate thorugh data list for commands in data: if self.server.server_address[1] == static.PORT: @@ -136,19 +129,22 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): # wait some time between processing multiple commands # this is only a first test to avoid doubled transmission - # we might improve this by only processing one command or + # we might improve this by only processing one command or # doing some kind of selection to determin which commands need to be dropped # and which one can be processed during a running transmission time.sleep(3) - - + # finally delete our rx buffer to be ready for new commands data = bytes() except Exception as e: - structlog.get_logger("structlog").info("[SCK] Connection closed", ip=self.client_address[0], port=self.client_address[1], e=e) + structlog.get_logger("structlog").info( + "[SCK] Connection closed", + ip=self.client_address[0], + port=self.client_address[1], + e=e, + ) self.connection_alive = False - - + def handle(self): """ socket handler @@ -156,25 +152,38 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): CONNECTED_CLIENTS.add(self.request) - structlog.get_logger("structlog").debug("[SCK] Client connected", ip=self.client_address[0], port=self.client_address[1]) + structlog.get_logger("structlog").debug( + "[SCK] Client connected", + ip=self.client_address[0], + port=self.client_address[1], + ) self.connection_alive = True - - self.sendThread = threading.Thread(target=self.send_to_client, args=[],daemon=True).start() - self.receiveThread = threading.Thread(target=self.receive_from_client, args=[],daemon=True).start() - + + self.sendThread = threading.Thread( + target=self.send_to_client, args=[], daemon=True + ).start() + self.receiveThread = threading.Thread( + target=self.receive_from_client, args=[], daemon=True + ).start() + # keep connection alive until we close it while self.connection_alive and not CLOSE_SIGNAL: time.sleep(1) - - def finish(self): """ """ - structlog.get_logger("structlog").warning("[SCK] Closing client socket", ip=self.client_address[0], port=self.client_address[1]) + structlog.get_logger("structlog").warning( + "[SCK] Closing client socket", + ip=self.client_address[0], + port=self.client_address[1], + ) try: CONNECTED_CLIENTS.remove(self.request) except: - structlog.get_logger("structlog").warning("[SCK] client connection already removed from client list", client=self.request) + structlog.get_logger("structlog").warning( + "[SCK] client connection already removed from client list", + client=self.request, + ) def process_tnc_commands(data): @@ -182,7 +191,7 @@ def process_tnc_commands(data): process tnc commands Args: - data: + data: Returns: @@ -194,58 +203,73 @@ def process_tnc_commands(data): received_json = json.loads(data) structlog.get_logger("structlog").debug("[SCK] CMD", command=received_json) # SET TX AUDIO LEVEL ----------------------------------------------------- - if received_json["type"] == "set" and received_json["command"] == "tx_audio_level": + if ( + received_json["type"] == "set" + and received_json["command"] == "tx_audio_level" + ): try: static.TX_AUDIO_LEVEL = int(received_json["value"]) command_response("tx_audio_level", True) - - except Exception as e: - command_response("tx_audio_level", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) + except Exception as e: + command_response("tx_audio_level", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) # TRANSMIT SINE WAVE ----------------------------------------------------- - if received_json["type"] == "set" and received_json["command"] == "send_test_frame": + if ( + received_json["type"] == "set" + and received_json["command"] == "send_test_frame" + ): try: - data_handler.DATA_QUEUE_TRANSMIT.put(['SEND_TEST_FRAME']) + data_handler.DATA_QUEUE_TRANSMIT.put(["SEND_TEST_FRAME"]) command_response("send_test_frame", True) - except Exception as e: - command_response("send_test_frame", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) + except Exception as e: + command_response("send_test_frame", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) # CQ CQ CQ ----------------------------------------------------- if received_json["command"] == "cqcqcq": try: - data_handler.DATA_QUEUE_TRANSMIT.put(['CQ']) + data_handler.DATA_QUEUE_TRANSMIT.put(["CQ"]) command_response("cqcqcq", True) - - except Exception as e: - command_response("cqcqcq", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) + + except Exception as e: + command_response("cqcqcq", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) # START_BEACON ----------------------------------------------------- if received_json["command"] == "start_beacon": try: static.BEACON_STATE = True interval = int(received_json["parameter"]) - data_handler.DATA_QUEUE_TRANSMIT.put(['BEACON', interval, True]) + data_handler.DATA_QUEUE_TRANSMIT.put(["BEACON", interval, True]) command_response("start_beacon", True) - except Exception as e: - command_response("start_beacon", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - + except Exception as e: + command_response("start_beacon", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + # STOP_BEACON ----------------------------------------------------- if received_json["command"] == "stop_beacon": - try: + try: structlog.get_logger("structlog").warning("[TNC] Stopping beacon!") static.BEACON_STATE = False - data_handler.DATA_QUEUE_TRANSMIT.put(['BEACON', None, False]) + data_handler.DATA_QUEUE_TRANSMIT.put(["BEACON", None, False]) command_response("stop_beacon", True) - except Exception as e: - command_response("stop_beacon", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - + except Exception as e: + command_response("stop_beacon", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + # PING ---------------------------------------------------------- - if received_json["type"] == 'ping' and received_json["command"] == "ping": + if received_json["type"] == "ping" and received_json["command"] == "ping": # send ping frame and wait for ACK try: dxcallsign = received_json["dxcallsign"] @@ -255,16 +279,17 @@ def process_tnc_commands(data): # then we are forcing a station ssid = 0 dxcallsign = helpers.callsign_to_bytes(dxcallsign) dxcallsign = helpers.bytes_to_callsign(dxcallsign) - - data_handler.DATA_QUEUE_TRANSMIT.put(['PING', dxcallsign]) + + data_handler.DATA_QUEUE_TRANSMIT.put(["PING", dxcallsign]) command_response("ping", True) - except Exception as e: + except Exception as e: command_response("ping", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - - + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + # CONNECT ---------------------------------------------------------- - if received_json["type"] == 'arq' and received_json["command"] == "connect": + if received_json["type"] == "arq" and received_json["command"] == "connect": static.BEACON_PAUSE = True # send ping frame and wait for ACK try: @@ -275,31 +300,35 @@ def process_tnc_commands(data): # then we are forcing a station ssid = 0 dxcallsign = helpers.callsign_to_bytes(dxcallsign) dxcallsign = helpers.bytes_to_callsign(dxcallsign) - + static.DXCALLSIGN = dxcallsign static.DXCALLSIGN_CRC = helpers.get_crc_16(static.DXCALLSIGN) - - data_handler.DATA_QUEUE_TRANSMIT.put(['CONNECT', dxcallsign]) + + data_handler.DATA_QUEUE_TRANSMIT.put(["CONNECT", dxcallsign]) command_response("connect", True) - except Exception as e: - command_response("connect", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) + except Exception as e: + command_response("connect", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) # DISCONNECT ---------------------------------------------------------- - if received_json["type"] == 'arq' and received_json["command"] == "disconnect": + if received_json["type"] == "arq" and received_json["command"] == "disconnect": # send ping frame and wait for ACK try: - data_handler.DATA_QUEUE_TRANSMIT.put(['DISCONNECT']) + data_handler.DATA_QUEUE_TRANSMIT.put(["DISCONNECT"]) command_response("disconnect", True) - except Exception as e: + except Exception as e: command_response("disconnect", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + # TRANSMIT RAW DATA ------------------------------------------- - if received_json["type"] == 'arq' and received_json["command"] == "send_raw": + if received_json["type"] == "arq" and received_json["command"] == "send_raw": static.BEACON_PAUSE = True - try: + try: if not static.ARQ_SESSION: dxcallsign = received_json["parameter"][0]["dxcallsign"] # additional step for beeing sure our callsign is correctly @@ -314,91 +343,113 @@ def process_tnc_commands(data): dxcallsign = static.DXCALLSIGN static.DXCALLSIGN_CRC = helpers.get_crc_16(static.DXCALLSIGN) - mode = int(received_json["parameter"][0]["mode"]) n_frames = int(received_json["parameter"][0]["n_frames"]) base64data = received_json["parameter"][0]["data"] - + # check if specific callsign is set with different SSID than the TNC is initialized try: mycallsign = received_json["parameter"][0]["mycallsign"] except: mycallsign = static.MYCALLSIGN - + # check if transmission uuid provided else set no-uuid try: arq_uuid = received_json["uuid"] except: - arq_uuid = 'no-uuid' - - if not len(base64data) % 4: + arq_uuid = "no-uuid" + + if not len(base64data) % 4: binarydata = base64.b64decode(base64data) - data_handler.DATA_QUEUE_TRANSMIT.put(['ARQ_RAW', binarydata, mode, n_frames, arq_uuid, mycallsign]) + data_handler.DATA_QUEUE_TRANSMIT.put( + ["ARQ_RAW", binarydata, mode, n_frames, arq_uuid, mycallsign] + ) else: raise TypeError - except Exception as e: - command_response("send_raw", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - + except Exception as e: + command_response("send_raw", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) - - # STOP TRANSMISSION ---------------------------------------------------------- - if received_json["type"] == 'arq' and received_json["command"] == "stop_transmission": + # STOP TRANSMISSION ---------------------------------------------------------- + if ( + received_json["type"] == "arq" + and received_json["command"] == "stop_transmission" + ): try: - if static.TNC_STATE == 'BUSY' or static.ARQ_STATE: - data_handler.DATA_QUEUE_TRANSMIT.put(['STOP']) - structlog.get_logger("structlog").warning("[TNC] Stopping transmission!") - static.TNC_STATE = 'IDLE' + if static.TNC_STATE == "BUSY" or static.ARQ_STATE: + data_handler.DATA_QUEUE_TRANSMIT.put(["STOP"]) + structlog.get_logger("structlog").warning( + "[TNC] Stopping transmission!" + ) + static.TNC_STATE = "IDLE" static.ARQ_STATE = False command_response("stop_transmission", True) - except Exception as e: - command_response("stop_transmission", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - + except Exception as e: + command_response("stop_transmission", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) - if received_json["type"] == 'get' and received_json["command"] == 'rx_buffer': + if received_json["type"] == "get" and received_json["command"] == "rx_buffer": try: output = { "command": "rx_buffer", "data-array": [], } - + for i in range(0, len(static.RX_BUFFER)): - #print(static.RX_BUFFER[i][4]) - #rawdata = json.loads(static.RX_BUFFER[i][4]) + # print(static.RX_BUFFER[i][4]) + # rawdata = json.loads(static.RX_BUFFER[i][4]) base64_data = static.RX_BUFFER[i][4] - output["data-array"].append({"uuid": static.RX_BUFFER[i][0],"timestamp": static.RX_BUFFER[i][1], "dxcallsign": str(static.RX_BUFFER[i][2], 'utf-8'), "dxgrid": str(static.RX_BUFFER[i][3], 'utf-8'), "data": base64_data}) + output["data-array"].append( + { + "uuid": static.RX_BUFFER[i][0], + "timestamp": static.RX_BUFFER[i][1], + "dxcallsign": str(static.RX_BUFFER[i][2], "utf-8"), + "dxgrid": str(static.RX_BUFFER[i][3], "utf-8"), + "data": base64_data, + } + ) jsondata = json.dumps(output) - #self.request.sendall(bytes(jsondata, encoding)) + # self.request.sendall(bytes(jsondata, encoding)) SOCKET_QUEUE.put(jsondata) command_response("rx_buffer", True) - - except Exception as e: - command_response("rx_buffer", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - - - if received_json["type"] == 'set' and received_json["command"] == 'del_rx_buffer': + + except Exception as e: + command_response("rx_buffer", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + + if ( + received_json["type"] == "set" + and received_json["command"] == "del_rx_buffer" + ): try: static.RX_BUFFER = [] command_response("del_rx_buffer", True) - except Exception as e: - command_response("del_rx_buffer", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) + except Exception as e: + command_response("del_rx_buffer", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) # exception, if JSON cant be decoded except Exception as e: structlog.get_logger("structlog").error("[TNC] JSON decoding error", e=e) + def send_tnc_state(): """ send the tnc state to network """ - - encoding = 'utf-8' + + encoding = "utf-8" output = { "command": "tnc_state", @@ -410,7 +461,7 @@ def send_tnc_state(): "audio_rms": str(static.AUDIO_RMS), "snr": str(static.SNR), "frequency": str(static.HAMLIB_FREQUENCY), - "speed_level": str(static.ARQ_SPEED_LEVEL), + "speed_level": str(static.ARQ_SPEED_LEVEL), "mode": str(static.HAMLIB_MODE), "bandwith": str(static.HAMLIB_BANDWITH), "fft": str(static.FFT), @@ -423,8 +474,8 @@ def send_tnc_state(): "arq_compression_factor": str(static.ARQ_COMPRESSION_FACTOR), "arq_transmission_percent": str(static.ARQ_TRANSMISSION_PERCENT), "total_bytes": str(static.TOTAL_BYTES), - "info" : static.INFO, - "beacon_state" : str(static.BEACON_STATE), + "info": static.INFO, + "beacon_state": str(static.BEACON_STATE), "stations": [], "mycallsign": str(static.MYCALLSIGN, encoding), "dxcallsign": str(static.DXCALLSIGN, encoding), @@ -433,8 +484,18 @@ def send_tnc_state(): # add heard stations to heard stations object for i in range(0, len(static.HEARD_STATIONS)): - output["stations"].append({"dxcallsign": str(static.HEARD_STATIONS[i][0], 'utf-8'), "dxgrid": str(static.HEARD_STATIONS[i][1], 'utf-8'),"timestamp": static.HEARD_STATIONS[i][2], "datatype": static.HEARD_STATIONS[i][3], "snr": static.HEARD_STATIONS[i][4], "offset": static.HEARD_STATIONS[i][5], "frequency": static.HEARD_STATIONS[i][6]}) - + output["stations"].append( + { + "dxcallsign": str(static.HEARD_STATIONS[i][0], "utf-8"), + "dxgrid": str(static.HEARD_STATIONS[i][1], "utf-8"), + "timestamp": static.HEARD_STATIONS[i][2], + "datatype": static.HEARD_STATIONS[i][3], + "snr": static.HEARD_STATIONS[i][4], + "offset": static.HEARD_STATIONS[i][5], + "frequency": static.HEARD_STATIONS[i][6], + } + ) + jsondata = json.dumps(output) return jsondata @@ -444,7 +505,7 @@ def process_daemon_commands(data): process daemon commands Args: - data: + data: Returns: @@ -452,41 +513,57 @@ def process_daemon_commands(data): # convert data to json object received_json = json.loads(data) structlog.get_logger("structlog").debug("[SCK] CMD", command=received_json) - if received_json["type"] == 'set' and received_json["command"] == 'mycallsign': + if received_json["type"] == "set" and received_json["command"] == "mycallsign": try: callsign = received_json["parameter"] - if bytes(callsign, 'utf-8') == b'': - self.request.sendall(b'INVALID CALLSIGN') - structlog.get_logger("structlog").warning("[DMN] SET MYCALL FAILED", call=static.MYCALLSIGN, crc=static.MYCALLSIGN_CRC) + if bytes(callsign, "utf-8") == b"": + self.request.sendall(b"INVALID CALLSIGN") + structlog.get_logger("structlog").warning( + "[DMN] SET MYCALL FAILED", + call=static.MYCALLSIGN, + crc=static.MYCALLSIGN_CRC, + ) else: - static.MYCALLSIGN = bytes(callsign, 'utf-8') + static.MYCALLSIGN = bytes(callsign, "utf-8") static.MYCALLSIGN_CRC = helpers.get_crc_16(static.MYCALLSIGN) command_response("mycallsign", True) - structlog.get_logger("structlog").info("[DMN] SET MYCALL", call=static.MYCALLSIGN, crc=static.MYCALLSIGN_CRC) - except Exception as e: + structlog.get_logger("structlog").info( + "[DMN] SET MYCALL", + call=static.MYCALLSIGN, + crc=static.MYCALLSIGN_CRC, + ) + except Exception as e: command_response("mycallsign", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - - - if received_json["type"] == 'set' and received_json["command"] == 'mygrid': + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + + if received_json["type"] == "set" and received_json["command"] == "mygrid": try: mygrid = received_json["parameter"] - if bytes(mygrid, 'utf-8') == b'': - self.request.sendall(b'INVALID GRID') + if bytes(mygrid, "utf-8") == b"": + self.request.sendall(b"INVALID GRID") else: - static.MYGRID = bytes(mygrid, 'utf-8') - structlog.get_logger("structlog").info("[SCK] SET MYGRID", grid=static.MYGRID) + static.MYGRID = bytes(mygrid, "utf-8") + structlog.get_logger("structlog").info( + "[SCK] SET MYGRID", grid=static.MYGRID + ) command_response("mygrid", True) - except Exception as e: + except Exception as e: command_response("mygrid", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - - - if received_json["type"] == 'set' and received_json["command"] == 'start_tnc' and not static.TNCSTARTED: - + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + + if ( + received_json["type"] == "set" + and received_json["command"] == "start_tnc" + and not static.TNCSTARTED + ): + try: mycall = str(received_json["parameter"][0]["mycall"]) mygrid = str(received_json["parameter"][0]["mygrid"]) @@ -513,39 +590,47 @@ def process_daemon_commands(data): # print some debugging parameters for item in received_json["parameter"][0]: - structlog.get_logger("structlog").debug("[DMN] TNC Startup Config : " + item, value=received_json["parameter"][0][item]) + structlog.get_logger("structlog").debug( + "[DMN] TNC Startup Config : " + item, + value=received_json["parameter"][0][item], + ) - DAEMON_QUEUE.put(['STARTTNC', \ - mycall, \ - mygrid, \ - rx_audio, \ - tx_audio, \ - devicename, \ - deviceport, \ - serialspeed, \ - pttprotocol, \ - pttport, \ - data_bits, \ - stop_bits, \ - handshake, \ - radiocontrol, \ - rigctld_ip, \ - rigctld_port, \ - enable_scatter, \ - enable_fft, \ - low_bandwith_mode, \ - tuning_range_fmin, \ - tuning_range_fmax, \ - enable_fsk, \ - tx_audio_level \ - ]) + DAEMON_QUEUE.put( + [ + "STARTTNC", + mycall, + mygrid, + rx_audio, + tx_audio, + devicename, + deviceport, + serialspeed, + pttprotocol, + pttport, + data_bits, + stop_bits, + handshake, + radiocontrol, + rigctld_ip, + rigctld_port, + enable_scatter, + enable_fft, + low_bandwith_mode, + tuning_range_fmin, + tuning_range_fmax, + enable_fsk, + tx_audio_level, + ] + ) command_response("start_tnc", True) - - except Exception as e: - command_response("start_tnc", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - if received_json["type"] == 'get' and received_json["command"] == 'test_hamlib': + except Exception as e: + command_response("start_tnc", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + + if received_json["type"] == "get" and received_json["command"] == "test_hamlib": try: devicename = str(received_json["parameter"][0]["devicename"]) @@ -560,37 +645,45 @@ def process_daemon_commands(data): rigctld_ip = str(received_json["parameter"][0]["rigctld_ip"]) rigctld_port = str(received_json["parameter"][0]["rigctld_port"]) - DAEMON_QUEUE.put(['TEST_HAMLIB', \ - devicename, \ - deviceport, \ - serialspeed, \ - pttprotocol, \ - pttport, \ - data_bits, \ - stop_bits, \ - handshake, \ - radiocontrol, \ - rigctld_ip, \ - rigctld_port \ - ]) + DAEMON_QUEUE.put( + [ + "TEST_HAMLIB", + devicename, + deviceport, + serialspeed, + pttprotocol, + pttport, + data_bits, + stop_bits, + handshake, + radiocontrol, + rigctld_ip, + rigctld_port, + ] + ) command_response("test_hamlib", True) - except Exception as e: - command_response("test_hamlib", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - - if received_json["type"] == 'set' and received_json["command"] == 'stop_tnc': + except Exception as e: + command_response("test_hamlib", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + + if received_json["type"] == "set" and received_json["command"] == "stop_tnc": try: static.TNCPROCESS.kill() # unregister process from atexit to avoid process zombies atexit.unregister(static.TNCPROCESS.kill) - + structlog.get_logger("structlog").warning("[DMN] Stopping TNC") static.TNCSTARTED = False command_response("stop_tnc", True) - except Exception as e: - command_response("stop_tnc", False) - structlog.get_logger("structlog").warning("[SCK] command execution error", e=e, command=received_json) - + except Exception as e: + command_response("stop_tnc", False) + structlog.get_logger("structlog").warning( + "[SCK] command execution error", e=e, command=received_json + ) + + def send_daemon_state(): """ send the daemon state to network @@ -599,37 +692,37 @@ def send_daemon_state(): python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1]) output = { - 'command': 'daemon_state', - 'daemon_state': [], - 'python_version': str(python_version), - 'hamlib_version': static.HAMLIB_VERSION, - 'input_devices': static.AUDIO_INPUT_DEVICES, - 'output_devices': static.AUDIO_OUTPUT_DEVICES, - 'serial_devices': static.SERIAL_DEVICES, + "command": "daemon_state", + "daemon_state": [], + "python_version": str(python_version), + "hamlib_version": static.HAMLIB_VERSION, + "input_devices": static.AUDIO_INPUT_DEVICES, + "output_devices": static.AUDIO_OUTPUT_DEVICES, + "serial_devices": static.SERIAL_DEVICES, #'cpu': str(psutil.cpu_percent()), #'ram': str(psutil.virtual_memory().percent), - 'version': '0.1' - } - + "version": "0.1", + } + if static.TNCSTARTED: output["daemon_state"].append({"status": "running"}) else: output["daemon_state"].append({"status": "stopped"}) - - + jsondata = json.dumps(output) return jsondata except Exception as e: structlog.get_logger("structlog").warning("[SCK] error", e=e) return None - + + def command_response(command, status): if status: status = "OK" else: status = "Failed" - - jsondata = {"command_response": command, "status" : status} + + jsondata = {"command_response": command, "status": status} data_out = json.dumps(jsondata) SOCKET_QUEUE.put(data_out) diff --git a/tnc/static.py b/tnc/static.py index dfef3bff..89380257 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -8,7 +8,7 @@ Here we are saving application wide variables and stats, which have to be access Not nice, suggestions are appreciated :-) """ -VERSION = '0.3.3-alpha' +VERSION = "0.3.3-alpha" # DAEMON DAEMONPORT = 3001 @@ -17,16 +17,16 @@ TNCPROCESS = 0 # Operator Defaults -MYCALLSIGN = b'AA0AA' -MYCALLSIGN_CRC = b'A' +MYCALLSIGN = b"AA0AA" +MYCALLSIGN_CRC = b"A" -DXCALLSIGN = b'AA0AA' -DXCALLSIGN_CRC = b'A' +DXCALLSIGN = b"AA0AA" +DXCALLSIGN_CRC = b"A" -MYGRID = b'' -DXGRID = b'' +MYGRID = b"" +DXGRID = b"" -SSID_LIST = [] # ssid list we are responding to +SSID_LIST = [] # ssid list we are responding to LOW_BANDWITH_MODE = False # --------------------------------- @@ -34,7 +34,7 @@ LOW_BANDWITH_MODE = False # Server Defaults HOST = "0.0.0.0" PORT = 3000 -SOCKET_TIMEOUT = 1 # seconds +SOCKET_TIMEOUT = 1 # seconds # --------------------------------- SERIAL_DEVICES = [] # --------------------------------- @@ -43,21 +43,21 @@ SERIAL_DEVICES = [] PTT_STATE = False TRANSMITTING = False -HAMLIB_VERSION = '0' -HAMLIB_PTT_TYPE = 'RTS' -HAMLIB_DEVICE_NAME = 'RIG_MODEL_DUMMY_NOVFO' -HAMLIB_DEVICE_PORT = '/dev/ttyUSB0' -HAMLIB_SERIAL_SPEED = '9600' -HAMLIB_PTT_PORT = '/dev/ttyUSB0' -HAMLIB_STOP_BITS = '1' -HAMLIB_DATA_BITS = '8' -HAMLIB_HANDSHAKE = 'None' -HAMLIB_RADIOCONTROL = 'direct' -HAMLIB_RIGCTLD_IP = '127.0.0.1' -HAMLIB_RIGCTLD_PORT = '4532' - +HAMLIB_VERSION = "0" +HAMLIB_PTT_TYPE = "RTS" +HAMLIB_DEVICE_NAME = "RIG_MODEL_DUMMY_NOVFO" +HAMLIB_DEVICE_PORT = "/dev/ttyUSB0" +HAMLIB_SERIAL_SPEED = "9600" +HAMLIB_PTT_PORT = "/dev/ttyUSB0" +HAMLIB_STOP_BITS = "1" +HAMLIB_DATA_BITS = "8" +HAMLIB_HANDSHAKE = "None" +HAMLIB_RADIOCONTROL = "direct" +HAMLIB_RIGCTLD_IP = "127.0.0.1" +HAMLIB_RIGCTLD_PORT = "4532" + HAMLIB_FREQUENCY = 0 -HAMLIB_MODE = '' +HAMLIB_MODE = "" HAMLIB_BANDWITH = 0 # ------------------------- # FreeDV Defaults @@ -75,7 +75,7 @@ AUDIO_INPUT_DEVICES = [] AUDIO_OUTPUT_DEVICES = [] AUDIO_INPUT_DEVICE = -2 AUDIO_OUTPUT_DEVICE = -2 -BUFFER_OVERFLOW_COUNTER = [0,0,0,0,0] +BUFFER_OVERFLOW_COUNTER = [0, 0, 0, 0, 0] AUDIO_RMS = 0 FFT = [0] @@ -96,11 +96,13 @@ ARQ_SPEED_LEVEL = 0 TOTAL_BYTES = 0 -#CHANNEL_STATE = 'RECEIVING_SIGNALLING' -TNC_STATE = 'IDLE' +# CHANNEL_STATE = 'RECEIVING_SIGNALLING' +TNC_STATE = "IDLE" ARQ_STATE = False ARQ_SESSION = False -ARQ_SESSION_STATE = 'disconnected' # disconnected, connecting, connected, disconnecting, failed +ARQ_SESSION_STATE = ( + "disconnected" # disconnected, connecting, connected, disconnecting, failed +) # BEACON STATE BEACON_STATE = False @@ -110,8 +112,8 @@ BEACON_PAUSE = False RX_BUFFER = [] RX_MSG_BUFFER = [] RX_BURST_BUFFER = [] -RX_FRAME_BUFFER = b'' -#RX_BUFFER_SIZE = 0 +RX_FRAME_BUFFER = b"" +# RX_BUFFER_SIZE = 0 # ------- HEARD STATIOS BUFFER HEARD_STATIONS = [] @@ -121,4 +123,4 @@ INFO = [] # ------- CODEC2 SETTINGS TUNING_RANGE_FMIN = -50.0 -TUNING_RANGE_FMAX = 50.0 +TUNING_RANGE_FMAX = 50.0