From fbfc036f9f749bdbe740e40ec737e99c995e3975 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Sun, 23 Apr 2023 14:58:03 +0200 Subject: [PATCH] implemented slot based busy state for performance testing --- gui/sock.js | 1 + tnc/modem.py | 51 +++++++++++++++++++++++++++++++++++---------------- tnc/sock.py | 2 +- tnc/static.py | 1 + 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/gui/sock.js b/gui/sock.js index 11ff5ead..9a938f81 100644 --- a/gui/sock.js +++ b/gui/sock.js @@ -198,6 +198,7 @@ client.on("data", function (socketdata) { dbfs_level: data["audio_dbfs"], fft: data["fft"], channel_busy: data["channel_busy"], + channel_busy_slot: data["channel_busy_slot"], scatter: data["scatter"], info: data["info"], rx_buffer_length: data["rx_buffer_length"], diff --git a/tnc/modem.py b/tnc/modem.py index e6b00791..fe09b685 100644 --- a/tnc/modem.py +++ b/tnc/modem.py @@ -1219,23 +1219,42 @@ class RF: # 2700Hz = 266 # 3200Hz = 315 - # define the area, we are detecting busy state - dfft = dfft[120:176] if static.LOW_BANDWIDTH_MODE else dfft[65:231] + # slot + slot = 0 + slot1 = [0, 65] + slot2 = [65,120] + slot3 = [120, 176] + slot4 = [176, 231] + slot5 = [231, len(dfftlist)] + for range in [slot1, slot2, slot3, slot4, slot5]: + + range_start = range[0] + range_end = range[1] + # define the area, we are detecting busy state + #dfft = dfft[120:176] if static.LOW_BANDWIDTH_MODE else dfft[65:231] + dfft = dfft[range_start:range_end] + # Check for signals higher than average by checking for "100" + # If we have a signal, increment our channel_busy delay counter + # so we have a smoother state toggle + if np.sum(dfft[dfft > avg + 15]) >= 400 and not static.TRANSMITTING: + static.CHANNEL_BUSY = True + static.CHANNEL_BUSY_SLOT[slot] = True + # Limit delay counter to a maximum of 200. The higher this value, + # the longer we will wait until releasing state + channel_busy_delay = min(channel_busy_delay + 10, 200) + else: + # Decrement channel busy counter if no signal has been detected. + channel_busy_delay = max(channel_busy_delay - 1, 0) + # When our channel busy counter reaches 0, toggle state to False + if channel_busy_delay == 0: + static.CHANNEL_BUSY = False + static.CHANNEL_BUSY_SLOT[slot] = False + + # increment slot + slot += 1 + + print(static.CHANNEL_BUSY_SLOT) - # 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 + 15]) >= 400 and not static.TRANSMITTING: - static.CHANNEL_BUSY = True - # Limit delay counter to a maximum of 200. The higher this value, - # the longer we will wait until releasing state - channel_busy_delay = min(channel_busy_delay + 10, 200) - else: - # Decrement channel busy counter if no signal has been detected. - channel_busy_delay = max(channel_busy_delay - 1, 0) - # When our channel busy counter reaches 0, toggle state to False - if channel_busy_delay == 0: - static.CHANNEL_BUSY = False static.FFT = dfftlist[:315] # 315 --> bandwidth 3200 except Exception as err: diff --git a/tnc/sock.py b/tnc/sock.py index ab93cb3e..f7b90d54 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -996,7 +996,6 @@ def send_tnc_state(): send the tnc state to network """ encoding = "utf-8" - output = { "command": "tnc_state", "ptt_state": str(static.PTT_STATE), @@ -1017,6 +1016,7 @@ def send_tnc_state(): "bandwidth": str(static.HAMLIB_BANDWIDTH), "fft": str(static.FFT), "channel_busy": str(static.CHANNEL_BUSY), + "channel_busy_slot": str(static.CHANNEL_BUSY_SLOT), "is_codec2_traffic": str(static.IS_CODEC2_TRAFFIC), "scatter": static.SCATTER, "rx_buffer_length": str(RX_BUFFER.qsize()), diff --git a/tnc/static.py b/tnc/static.py index 4cfaf548..01433dc6 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -10,6 +10,7 @@ Not nice, suggestions are appreciated :-) import subprocess from enum import Enum +CHANNEL_BUSY_SLOT = [False] * 5 VERSION = "0.9.0-alpha-exp.1"