cleaner session stopping

pull/918/head
DJ2LS 2025-03-18 09:14:43 +01:00
parent 2c061939f5
commit 93eb1d64ca
4 changed files with 48 additions and 30 deletions

View File

@ -785,18 +785,10 @@ async def post_modem_stop_transmission(request:Request):
Raises:
HTTPException: If the modem is not running or an error occurs.
"""
if not request.app.state_manager.is_modem_running:
api_abort("Modem not running", 503)
if request.app.state_manager.getARQ():
try:
for session in request.app.state_manager.arq_irs_sessions.values():
# session.abort_transmission()
session.transmission_aborted()
for session in request.app.state_manager.arq_iss_sessions.values():
session.abort_transmission(send_stop=False)
session.transmission_aborted()
except Exception as e:
print(f"Error during transmission stopping: {e}")
try:
request.app.state_manager.stop_transmission()
except Exception as e:
print(f"Error during transmission stopping: {e}")
return api_ok()

View File

@ -486,15 +486,16 @@ class ARQSessionIRS(arq_session.ARQSession):
Returns:
Tuple[None, None]: Returns None for both data and type_byte.
"""
self.log("session aborted")
self.session_ended = time.time()
self.set_state(IRS_State.ABORTED)
# break actual retries
self.event_frame_received.set()
if self.state not in [IRS_State.ABORTED, IRS_State.ENDED]:
self.log("session aborted")
self.session_ended = time.time()
self.set_state(IRS_State.ABORTED)
# break actual retries
self.event_frame_received.set()
#self.modem.demodulator.set_decode_mode()
self.event_manager.send_arq_session_finished(
True, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics(self.received_bytes, self.total_length))
self.states.setARQ(False)
#self.modem.demodulator.set_decode_mode()
self.event_manager.send_arq_session_finished(
True, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics(self.received_bytes, self.total_length))
self.states.setARQ(False)
return None, None

View File

@ -464,14 +464,17 @@ class ARQSessionISS(arq_session.ARQSession):
Returns:
Tuple[None, None]: Returns None for both data and type_byte.
"""
self.log("session aborted")
self.session_ended = time.time()
self.set_state(ISS_State.ABORTED)
# break actual retries
self.event_frame_received.set()
self.event_manager.send_arq_session_finished(
True, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics(self.confirmed_bytes, self.total_length))
#self.state_manager.remove_arq_iss_session(self.id)
self.states.setARQ(False)
# Only run this part, if we are not already aborted or ended the session.
if self.state not in [ISS_State.ABORTED, ISS_State.ENDED]:
self.log("session aborted")
self.session_ended = time.time()
self.set_state(ISS_State.ABORTED)
# break actual retries
self.event_frame_received.set()
self.event_manager.send_arq_session_finished(
True, self.id, self.dxcall, False, self.state.name, statistics=self.calculate_session_statistics(self.confirmed_bytes, self.total_length))
#self.state_manager.remove_arq_iss_session(self.id)
self.states.setARQ(False)
return None, None

View File

@ -412,6 +412,28 @@ class StateManager:
if id in self.arq_irs_sessions:
del self.arq_irs_sessions[id]
def stop_transmission(self):
"""Stops any ongoing ARQ transmissions.
This method iterates through all active ARQ Information Sending Station (ISS)
and Information Receiving Station (IRS) sessions and aborts their transmissions.
ISS sessions are removed after being stopped, while IRS sessions are retained
to allow for potential resumption.
"""
# Stop and remove IRS sessions
for session_id in list(self.arq_irs_sessions.keys()):
session = self.arq_irs_sessions[session_id]
session.transmission_aborted()
# For now, we don't remove IRS session because of resuming transmissions.
#self.remove_arq_irs_session(session_id)
# Stop and remove ISS sessions
for session_id in list(self.arq_iss_sessions.keys()):
session = self.arq_iss_sessions[session_id]
session.abort_transmission(send_stop=False)
session.transmission_aborted()
self.remove_arq_iss_session(session_id)
def add_activity(self, activity_data):
"""Adds a new activity to the activities list.