FreeDATA/modem/command_arq_raw.py

39 lines
1.2 KiB
Python
Raw Normal View History

2023-12-05 14:40:04 +00:00
import queue
from command import TxCommand
import api_validations
2023-12-05 14:40:04 +00:00
import base64
from queue import Queue
from arq_session_iss import ARQSessionISS
2024-01-30 08:30:13 +00:00
from arq_data_type_handler import ARQ_SESSION_TYPES
2023-12-21 14:05:22 +00:00
class ARQRawCommand(TxCommand):
def set_params_from_api(self, apiParams):
2023-12-15 15:22:38 +00:00
self.dxcall = apiParams['dxcall']
if not api_validations.validate_freedata_callsign(self.dxcall):
self.dxcall = f"{self.dxcall}-0"
try:
2024-01-30 08:30:13 +00:00
self.type = ARQ_SESSION_TYPES[apiParams['type']]
except KeyError:
2024-01-30 08:30:13 +00:00
self.type = ARQ_SESSION_TYPES.raw
2023-12-05 14:40:04 +00:00
self.data = base64.b64decode(apiParams['data'])
def run(self, event_queue: Queue, modem):
2024-02-21 16:05:28 +00:00
try:
self.emit_event(event_queue)
self.logger.info(self.log_message())
prepared_data, type_byte = self.arq_data_type_handler.prepare(self.data, self.type)
2024-02-21 16:05:28 +00:00
iss = ARQSessionISS(self.config, modem, self.dxcall, self.state_manager, prepared_data, type_byte)
if iss.id:
self.state_manager.register_arq_iss_session(iss)
iss.start()
return iss
except Exception as e:
self.log(f"Error starting ARQ session: {e}", isWarning=True)
2024-01-04 20:44:59 +00:00
return False