From 08ea177681fe65fe323f747acc65e0c81e96abbe Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:09:09 +0100 Subject: [PATCH] get dxcall by session id --- freedata_server/frame_handler.py | 6 ++++++ freedata_server/state_manager.py | 28 +++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/freedata_server/frame_handler.py b/freedata_server/frame_handler.py index 8d7960abd..c00bd46cb 100644 --- a/freedata_server/frame_handler.py +++ b/freedata_server/frame_handler.py @@ -168,6 +168,7 @@ def make_event(self): } if 'origin' in self.details['frame']: event['dxcallsign'] = self.details['frame']['origin'] + if 'gridsquare' in self.details['frame']: event['gridsquare'] = self.details['frame']['gridsquare'] if event['gridsquare'] != "------": @@ -212,6 +213,11 @@ def handle(self, frame, snr, frequency_offset, freedv_inst, bytes_per_frame): print(self.details) + if 'origin' not in frame and 'session_id' in frame: + dxcall = self.states.get_dxcall_by_session_id(frame['session_id']) + if dxcall: + self.details['origin'] = dxcall + # look in database for a full callsign if only crc is present if 'origin' not in frame and 'origin_crc' in frame: self.details['frame']['origin'] = DatabaseManager(self.event_manager).get_callsign_by_checksum(frame['origin_crc']) diff --git a/freedata_server/state_manager.py b/freedata_server/state_manager.py index a30285af3..5c05bfec6 100644 --- a/freedata_server/state_manager.py +++ b/freedata_server/state_manager.py @@ -259,4 +259,30 @@ def register_p2p_connection_session(self, session): def get_p2p_connection_session(self, id): if id not in self.p2p_connection_sessions: pass - return self.p2p_connection_sessions[id] \ No newline at end of file + return self.p2p_connection_sessions[id] + + def get_dxcall_by_session_id(self, session_id): + """ + Retrieves the dxcall associated with a given session ID by checking both ISS and IRS sessions. + + Args: + session_id (str): The ID of the session. + + Returns: + str: The dxcall associated with the session ID, or None if not found. + """ + try: + # Check ISS sessions + if session_id in self.arq_iss_sessions: + return self.arq_iss_sessions[session_id].dxcall + + # Check IRS sessions + if session_id in self.arq_irs_sessions: + return self.arq_irs_sessions[session_id].dxcall + + # If not found in either session dictionary + self.log(f"Session ID {session_id} not found in ISS or IRS sessions", isWarning=True) + return None + except KeyError: + self.log(f"Error retrieving session ID {session_id}", isError=True) + return None