From 8b2412de961a11b9b2007772f6b08b7293dd3d83 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Sun, 4 Dec 2022 16:56:12 +0100 Subject: [PATCH] added respond to call --- tnc/data_handler.py | 33 +++++++++++++++++++++------------ tnc/sock.py | 12 ++++++++++++ tnc/static.py | 1 + 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/tnc/data_handler.py b/tnc/data_handler.py index 8a72cbfc..8a8df90e 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -1499,6 +1499,10 @@ class DATA: Args: data_in:bytes: """ + # if we don't want to respond to calls, return False + if not static.RESPOND_TO_CALL: + return False + self.IS_ARQ_SESSION_MASTER = False static.ARQ_SESSION_STATE = "connecting" @@ -1902,6 +1906,11 @@ class DATA: """ # We've arrived here from process_data which already checked that the frame # is intended for this station. + + # stop processing if we don't want to respond to a call when not in a arq session + if not static.RESPOND_TO_CALL and not static.ARQ_SESSION: + return False + self.arq_file_transfer = True self.is_IRS = True @@ -2208,18 +2217,18 @@ class DATA: dxcallsign = str(dxcallsign, "UTF-8"), snr=str(static.SNR), ) + if static.RESPOND_TO_CALL: + ping_frame = bytearray(self.length_sig0_frame) + ping_frame[:1] = bytes([FR_TYPE.PING_ACK.value]) + ping_frame[1:4] = static.DXCALLSIGN_CRC + ping_frame[4:7] = static.MYCALLSIGN_CRC + ping_frame[7:13] = static.MYGRID - ping_frame = bytearray(self.length_sig0_frame) - ping_frame[:1] = bytes([FR_TYPE.PING_ACK.value]) - ping_frame[1:4] = static.DXCALLSIGN_CRC - ping_frame[4:7] = static.MYCALLSIGN_CRC - ping_frame[7:13] = static.MYGRID - - self.log.info("[TNC] ENABLE FSK", state=static.ENABLE_FSK) - if static.ENABLE_FSK: - self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) - else: - self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.datac0.value) + self.log.info("[TNC] ENABLE FSK", state=static.ENABLE_FSK) + if static.ENABLE_FSK: + self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.fsk_ldpc_0.value) + else: + self.enqueue_frame_for_tx([ping_frame], c2_mode=FREEDV_MODE.datac0.value) def received_ping_ack(self, data_in: bytes) -> None: """ @@ -2476,7 +2485,7 @@ class DATA: static.HAMLIB_FREQUENCY, ) - if static.RESPOND_TO_CQ: + if static.RESPOND_TO_CQ and static.RESPOND_TO_CALL: self.transmit_qrv(dxcallsign) def transmit_qrv(self, dxcallsign: bytes) -> None: diff --git a/tnc/sock.py b/tnc/sock.py index ca842c11..03c2e4ae 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -226,6 +226,18 @@ def process_tnc_commands(data): "[SCK] CQ command execution error", e=err, command=received_json ) + # SET ENABLE/DISABLE RESPOND TO CALL ----------------------------------------------------- + if received_json["type"] == "set" and received_json["command"] == "respond_to_call": + try: + static.RESPOND_TO_CALL = received_json["state"] in ['true', 'True', True] + command_response("respond_to_call", True) + + except Exception as err: + command_response("respond_to_call", False) + log.warning( + "[SCK] CQ command execution error", e=err, command=received_json + ) + # SET ENABLE RESPOND TO CQ ----------------------------------------------------- if received_json["type"] == "set" and received_json["command"] == "respond_to_cq": try: diff --git a/tnc/static.py b/tnc/static.py index b824e2b6..3fd3ad81 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -73,6 +73,7 @@ SCATTER: list = [] ENABLE_SCATTER: bool = False ENABLE_FSK: bool = False RESPOND_TO_CQ: bool = False +RESPOND_TO_CALL: bool = True # respond to cq, ping, connection request, file request if not in session # --------------------------------- # Audio Defaults