Skip to content

Commit

Permalink
get dxcall by session id
Browse files Browse the repository at this point in the history
  • Loading branch information
DJ2LS committed Nov 9, 2024
1 parent ed6796f commit 08ea177
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions freedata_server/frame_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] != "------":
Expand Down Expand Up @@ -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'])
Expand Down
28 changes: 27 additions & 1 deletion freedata_server/state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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

0 comments on commit 08ea177

Please sign in to comment.