FreeDATA/modem/frame_handler_arq_session.py

59 lines
2.1 KiB
Python
Raw Normal View History

2023-12-05 14:40:04 +00:00
from queue import Queue
import frame_handler
2023-12-05 17:50:39 +00:00
from event_manager import EventManager
from state_manager import StateManager
2023-12-05 14:40:04 +00:00
from modem_frametypes import FRAME_TYPE as FR
from arq_session_irs import ARQSessionIRS
2023-12-05 18:12:21 +00:00
from arq_session_iss import ARQSessionISS
2023-12-05 14:40:04 +00:00
class ARQFrameHandler(frame_handler.FrameHandler):
def follow_protocol(self):
2024-01-14 22:33:06 +00:00
if not self.should_respond():
return
2023-12-05 14:40:04 +00:00
frame = self.details['frame']
2023-12-14 16:29:04 +00:00
session_id = frame['session_id']
2023-12-12 08:46:22 +00:00
snr = self.details["snr"]
frequency_offset = self.details["frequency_offset"]
2023-12-05 14:40:04 +00:00
2023-12-12 19:46:22 +00:00
if frame['frame_type_int'] == FR.ARQ_SESSION_OPEN.value:
2023-12-14 16:29:04 +00:00
2023-12-13 17:27:55 +00:00
# Lost OPEN_ACK case .. ISS will retry opening a session
2023-12-14 16:29:04 +00:00
if session_id in self.states.arq_irs_sessions:
session = self.states.arq_irs_sessions[session_id]
2023-12-13 17:27:55 +00:00
# Normal case when receiving a SESSION_OPEN for the first time
else:
if self.states.check_if_running_arq_session():
self.logger.warning("DISCARDING SESSION OPEN because of ongoing ARQ session ", frame=frame)
return
session = ARQSessionIRS(self.config,
self.modem,
2023-12-13 17:27:55 +00:00
frame['origin'],
2023-12-14 16:29:04 +00:00
session_id)
2023-12-13 17:27:55 +00:00
self.states.register_arq_irs_session(session)
2023-12-12 21:05:32 +00:00
2023-12-14 16:29:04 +00:00
elif frame['frame_type_int'] in [
FR.ARQ_SESSION_INFO.value,
FR.ARQ_BURST_FRAME.value,
2023-12-24 12:20:51 +00:00
FR.ARQ_STOP.value,
]:
2023-12-14 16:29:04 +00:00
session = self.states.get_arq_irs_session(session_id)
2023-12-12 21:33:17 +00:00
2023-12-14 16:29:04 +00:00
elif frame['frame_type_int'] in [
FR.ARQ_SESSION_OPEN_ACK.value,
FR.ARQ_SESSION_INFO_ACK.value,
FR.ARQ_BURST_ACK.value,
2023-12-21 14:05:22 +00:00
FR.ARQ_STOP_ACK.value
]:
2023-12-14 16:29:04 +00:00
session = self.states.get_arq_iss_session(session_id)
2023-12-09 12:28:32 +00:00
2023-12-12 21:33:17 +00:00
else:
self.logger.warning("DISCARDING FRAME", frame=frame)
2023-12-14 16:29:04 +00:00
return
session.set_details(snr, frequency_offset)
session.on_frame_received(frame)