mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
first test run with overriding connection attempts #288
This commit is contained in:
parent
03987de194
commit
38281ec06c
|
@ -525,7 +525,7 @@ exports.sendMessage = function(dxcallsign, mode, frames, data, checksum, uuid, c
|
|||
data = btoa(data)
|
||||
|
||||
//command = '{"type" : "arq", "command" : "send_message", "parameter" : [{ "dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '" , "checksum" : "' + checksum + '"}]}'
|
||||
command = '{"type" : "arq", "command" : "send_raw", "uuid" : "'+ uuid +'", "parameter" : [{"dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '"}]}'
|
||||
command = '{"type" : "arq", "command" : "send_raw", "uuid" : "'+ uuid +'", "parameter" : [{"dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '", attempts: "15"}]}'
|
||||
socketLog.info(command)
|
||||
socketLog.info("-------------------------------------")
|
||||
writeTncCommand(command)
|
||||
|
@ -563,7 +563,7 @@ exports.stopBeacon = function() {
|
|||
|
||||
// OPEN ARQ SESSION
|
||||
exports.connectARQ = function(dxcallsign) {
|
||||
command = '{"type" : "arq", "command" : "connect", "dxcallsign": "'+ dxcallsign + '"}'
|
||||
command = '{"type" : "arq", "command" : "connect", "dxcallsign": "'+ dxcallsign + '", attempts: "15"}'
|
||||
writeTncCommand(command)
|
||||
}
|
||||
|
||||
|
@ -573,7 +573,7 @@ exports.disconnectARQ = function() {
|
|||
writeTncCommand(command)
|
||||
}
|
||||
|
||||
// SEND SINE
|
||||
// SEND TEST FRAME
|
||||
exports.sendTestFrame = function() {
|
||||
command = '{"type" : "set", "command" : "send_test_frame"}'
|
||||
writeTncCommand(command)
|
||||
|
|
|
@ -186,7 +186,7 @@ class DATA:
|
|||
FR_TYPE.QRV.value: (self.received_qrv, "QRV"),
|
||||
}
|
||||
self.command_dispatcher = {
|
||||
"CONNECT": (self.arq_session_handler, "CONNECT"),
|
||||
#"CONNECT": (self.arq_session_handler, "CONNECT"),
|
||||
"CQ": (self.transmit_cq, "CQ"),
|
||||
"DISCONNECT": (self.close_session, "DISCONNECT"),
|
||||
"SEND_TEST_FRAME": (self.send_test_frame, "TEST"),
|
||||
|
@ -232,6 +232,11 @@ class DATA:
|
|||
self.command_dispatcher[data[0]][0]()
|
||||
|
||||
# Dispatch commands that need more arguments.
|
||||
elif data[0] == "CONNECT":
|
||||
# [1] dxcallsign
|
||||
# [2] attempts
|
||||
self.arq_session_handler(data[1], data[2])
|
||||
|
||||
elif data[0] == "PING":
|
||||
# [1] dxcallsign
|
||||
self.transmit_ping(data[1])
|
||||
|
@ -1274,7 +1279,7 @@ class DATA:
|
|||
############################################################################################################
|
||||
# ARQ SESSION HANDLER
|
||||
############################################################################################################
|
||||
def arq_session_handler(self) -> bool:
|
||||
def arq_session_handler(self, dxcallsign, attempts) -> bool:
|
||||
"""
|
||||
Create a session with `static.DXCALLSIGN` and wait until the session is open.
|
||||
|
||||
|
@ -1282,6 +1287,9 @@ class DATA:
|
|||
True if the session was opened successfully
|
||||
False if the session open request failed
|
||||
"""
|
||||
# override connection attempts
|
||||
self.session_connect_max_retries = attempts
|
||||
|
||||
# TODO: we need to check this, maybe placing it to class init
|
||||
self.datachannel_timeout = False
|
||||
self.log.info(
|
||||
|
@ -1362,7 +1370,6 @@ class DATA:
|
|||
# create a random session id
|
||||
# self.session_id = randbytes(1)
|
||||
self.session_id = np.random.bytes(1)
|
||||
print(self.session_id)
|
||||
|
||||
connection_frame = bytearray(self.length_sig0_frame)
|
||||
connection_frame[:1] = bytes([FR_TYPE.ARQ_SESSION_OPEN.value])
|
||||
|
@ -1587,6 +1594,7 @@ class DATA:
|
|||
n_frames_per_burst: int,
|
||||
transmission_uuid: str,
|
||||
mycallsign,
|
||||
attempts,
|
||||
) -> bool:
|
||||
"""
|
||||
Open data channel and transmit data
|
||||
|
@ -1648,7 +1656,7 @@ class DATA:
|
|||
)
|
||||
return False
|
||||
|
||||
self.arq_open_data_channel(mode, n_frames_per_burst, mycallsign)
|
||||
self.arq_open_data_channel(mode, n_frames_per_burst, mycallsign, attempts)
|
||||
|
||||
# wait until data channel is open
|
||||
while not static.ARQ_STATE and not self.datachannel_timeout:
|
||||
|
@ -1661,7 +1669,7 @@ class DATA:
|
|||
return False
|
||||
|
||||
def arq_open_data_channel(
|
||||
self, mode: int, n_frames_per_burst: int, mycallsign
|
||||
self, mode: int, n_frames_per_burst: int, mycallsign, attempts: int
|
||||
) -> bool:
|
||||
"""
|
||||
Open an ARQ data channel.
|
||||
|
@ -1670,6 +1678,7 @@ class DATA:
|
|||
mode:int:
|
||||
n_frames_per_burst:int:
|
||||
mycallsign:bytes:
|
||||
attempts:int: Number of attempts initiating a connection
|
||||
|
||||
Returns:
|
||||
True if the data channel was opened successfully
|
||||
|
@ -1677,6 +1686,9 @@ class DATA:
|
|||
"""
|
||||
self.is_IRS = False
|
||||
|
||||
# override connection attempts
|
||||
self.data_channel_max_retries = attempts
|
||||
|
||||
# init a new random session id if we are not in an arq session
|
||||
if not static.ARQ_SESSION:
|
||||
# self.session_id = randbytes(1)
|
||||
|
@ -2541,6 +2553,10 @@ class DATA:
|
|||
# reset retry counter for rx channel / burst
|
||||
self.n_retries_per_burst = 0
|
||||
|
||||
# reset max retries possibly overriden by api
|
||||
self.session_connect_max_retries = 15
|
||||
self.data_channel_max_retries = 15
|
||||
|
||||
if not static.ARQ_SESSION:
|
||||
static.TNC_STATE = "IDLE"
|
||||
|
||||
|
|
45
tnc/sock.py
45
tnc/sock.py
|
@ -310,6 +310,13 @@ def process_tnc_commands(data):
|
|||
# pause our beacon first
|
||||
static.BEACON_PAUSE = True
|
||||
|
||||
# check for connection attempts key
|
||||
try:
|
||||
attempts = int(received_json["attempts"])
|
||||
except Exception:
|
||||
# 15 == self.session_connect_max_retries
|
||||
attempts = 15
|
||||
|
||||
dxcallsign = received_json["dxcallsign"]
|
||||
|
||||
# additional step for being sure our callsign is correctly
|
||||
|
@ -326,32 +333,6 @@ def process_tnc_commands(data):
|
|||
command=received_json,
|
||||
)
|
||||
else:
|
||||
"""
|
||||
# check if we are going to connect to a different callsign
|
||||
# if so, then disconnect first
|
||||
if dxcallsign != static.DXCALLSIGN and static.ARQ_SESSION_STATE != "disconnected":
|
||||
command_response("connect", True)
|
||||
|
||||
# lets disconnect
|
||||
DATA_QUEUE_TRANSMIT.put(["DISCONNECT"])
|
||||
# set early disconnecting state so we can interrupt connection attempts
|
||||
static.ARQ_SESSION_STATE = "disconnecting"
|
||||
|
||||
# wait for disconnecting
|
||||
log.info(
|
||||
"[SCK] Waiting for disconnecting",
|
||||
callsign=static.DXCALLSIGN,
|
||||
command=received_json,
|
||||
)
|
||||
|
||||
|
||||
|
||||
# set disconnect timeout to 15 seconds to avoid being stuck here if disconnect fails
|
||||
disconnect_timeout = time.time() + 15
|
||||
# wait until disconnected or timeout reached
|
||||
while static.ARQ_SESSION_STATE != 'disconnected' and time.time() < disconnect_timeout:
|
||||
time.sleep(0.01)
|
||||
"""
|
||||
|
||||
# finally check again if we are disconnected or failed
|
||||
if static.ARQ_SESSION_STATE == 'disconnected' or static.ARQ_SESSION_STATE == 'failed':
|
||||
|
@ -361,7 +342,7 @@ def process_tnc_commands(data):
|
|||
static.DXCALLSIGN = dxcallsign
|
||||
static.DXCALLSIGN_CRC = helpers.get_crc_24(static.DXCALLSIGN)
|
||||
|
||||
DATA_QUEUE_TRANSMIT.put(["CONNECT", dxcallsign])
|
||||
DATA_QUEUE_TRANSMIT.put(["CONNECT", dxcallsign, attempts])
|
||||
command_response("connect", True)
|
||||
except Exception as err:
|
||||
command_response("connect", False)
|
||||
|
@ -402,6 +383,7 @@ def process_tnc_commands(data):
|
|||
# TRANSMIT RAW DATA -------------------------------------------
|
||||
if received_json["type"] == "arq" and received_json["command"] == "send_raw":
|
||||
static.BEACON_PAUSE = True
|
||||
|
||||
try:
|
||||
if not static.ARQ_SESSION:
|
||||
dxcallsign = received_json["parameter"][0]["dxcallsign"]
|
||||
|
@ -427,6 +409,13 @@ def process_tnc_commands(data):
|
|||
except Exception:
|
||||
mycallsign = static.MYCALLSIGN
|
||||
|
||||
# check for connection attempts key
|
||||
try:
|
||||
attempts = int(received_json["attempts"])
|
||||
except Exception:
|
||||
# 15 == self.session_connect_max_retries
|
||||
attempts = 15
|
||||
|
||||
# check if transmission uuid provided else set no-uuid
|
||||
try:
|
||||
arq_uuid = received_json["uuid"]
|
||||
|
@ -439,7 +428,7 @@ def process_tnc_commands(data):
|
|||
binarydata = base64.b64decode(base64data)
|
||||
|
||||
DATA_QUEUE_TRANSMIT.put(
|
||||
["ARQ_RAW", binarydata, mode, n_frames, arq_uuid, mycallsign]
|
||||
["ARQ_RAW", binarydata, mode, n_frames, arq_uuid, mycallsign, attempts]
|
||||
)
|
||||
|
||||
except Exception as err:
|
||||
|
|
Loading…
Reference in a new issue