adjusted response part for commands

This commit is contained in:
DJ2LS 2024-03-16 15:52:14 +01:00
parent 0f3611fb15
commit d2b3f3a36e
6 changed files with 32 additions and 42 deletions

View file

@ -8,7 +8,7 @@ from arq_data_type_handler import ARQDataTypeHandler
class TxCommand():
def __init__(self, config: dict, state_manager: StateManager, event_manager, apiParams:dict = {}, request=None):
def __init__(self, config: dict, state_manager: StateManager, event_manager, apiParams:dict = {}, socket_command_handler=None):
self.config = config
self.logger = structlog.get_logger(type(self).__name__)
self.state_manager = state_manager
@ -16,7 +16,7 @@ class TxCommand():
self.set_params_from_api(apiParams)
self.frame_factory = DataFrameFactory(config)
self.arq_data_type_handler = ARQDataTypeHandler(event_manager, state_manager)
self.request = request
self.socket_command_handler = socket_command_handler
def log(self, message, isWarning = False):
msg = f"[{type(self).__name__}]: {message}"

View file

@ -24,7 +24,7 @@ class P2PConnectionCommand(TxCommand):
try:
self.emit_event(event_queue)
self.logger.info(self.log_message())
session = P2PConnection(self.config, modem, self.origin, self.destination, self.state_manager, self.request)
session = P2PConnection(self.config, modem, self.origin, self.destination, self.state_manager, self.socket_command_handler)
if session.session_id:
self.state_manager.register_p2p_connection_session(session)
session.connect()

View file

@ -49,12 +49,12 @@ class P2PConnection:
},
}
def __init__(self, config: dict, modem, origin: str, destination: str, state_manager, request=None):
def __init__(self, config: dict, modem, origin: str, destination: str, state_manager, socket_command_handler=None):
self.logger = structlog.get_logger(type(self).__name__)
self.config = config
self.frame_factory = data_frame_factory.DataFrameFactory(self.config)
self.request = request
self.socket_command_handler = socket_command_handler
self.destination = destination
self.origin = origin
@ -193,8 +193,7 @@ class P2PConnection:
def session_failed(self):
self.log("FAILED...........................")
self.set_state(States.FAILED)
message = "DISCONNECTED\r\n"
self.request.sendall(message.encode())
self.socket_command_handler.socket_respond_disconnected()
def process_data_queue(self, frame=None):
if not self.p2p_tx_queue.empty():
@ -235,6 +234,7 @@ class P2PConnection:
def received_disconnect(self, frame):
self.log("DISCONNECTED...............")
self.set_state(States.DISCONNECTED)
self.socket_command_handler.socket_respond_disconnected()
self.is_ISS = False
disconnect_ack_frame = self.frame_factory.build_p2p_connection_disconnect_ack(self.session_id)
self.launch_twr_irs(disconnect_ack_frame, self.ENTIRE_CONNECTION_TIMEOUT, mode=FREEDV_MODE.signalling)
@ -242,6 +242,7 @@ class P2PConnection:
def received_disconnect_ack(self, frame):
self.log("DISCONNECTED...............")
self.set_state(States.DISCONNECTED)
self.socket_command_handler.socket_respond_disconnected()
def transmit_arq(self):

View file

@ -23,7 +23,6 @@ import command_arq_raw
import command_message_send
import event_manager
import atexit
from socket_interface import SocketInterfaceHandler
from message_system_db_manager import DatabaseManager
from message_system_db_messages import DatabaseManagerMessages
@ -362,10 +361,6 @@ if __name__ == "__main__":
# start service manager
app.service_manager = service_manager.SM(app)
#app.socket_interface_manager = SocketInterfaceHandler(app.service_manager.modem, app.config_manager, app.state_manager, app.event_manager)
# start modem service
app.modem_service.put("start")
# initialize database default values
@ -381,7 +376,5 @@ if __name__ == "__main__":
if not modemport:
modemport = 5000
#app.socket_interface_manager.start_servers()
app.run(modemaddress, modemport)

View file

@ -38,7 +38,6 @@ class SM:
elif cmd in ['stop'] and self.modem:
self.stop_modem()
self.stop_radio_manager()
self.socket_interface_manager.stop_servers()
# we need to wait a bit for avoiding a portaudio crash
threading.Event().wait(0.5)
@ -46,6 +45,8 @@ class SM:
elif cmd in ['restart']:
self.stop_modem()
self.stop_radio_manager()
self.socket_interface_manager.stop_servers()
# we need to wait a bit for avoiding a portaudio crash
threading.Event().wait(0.5)

View file

@ -2,72 +2,67 @@ from command_p2p_connection import P2PConnectionCommand
class SocketCommandHandler:
def __init__(self, request, modem, config_manager, state_manager, event_manager):
self.request = request
def __init__(self, cmd_request, modem, config_manager, state_manager, event_manager):
self.cmd_request = cmd_request
self.modem = modem
self.config_manager = config_manager
self.state_manager = state_manager
self.event_manager = event_manager
def send_response(self, message):
self.request.sendall(message.encode())
full_message = f"{message}\r\n"
self.cmd_request.sendall(full_message.encode())
def handle_connect(self, data):
# Your existing connect logic
self.send_response("OK\r\n")
print(self.modem)
print(self.config_manager)
print(self.state_manager)
print(self.event_manager)
self.send_response("OK")
params = {
'destination': "BB2BBB-2",
'origin': "AA1AAA-1",
'origin': data[0],
'destination': data[1],
}
cmd = P2PConnectionCommand(self.config_manager.read(), self.state_manager, self.event_manager, params, self.request)
cmd = P2PConnectionCommand(self.config_manager.read(), self.state_manager, self.event_manager, params, self)
session = cmd.run(self.event_manager.queues, self.modem)
if session.session_id:
self.state_manager.register_p2p_connection_session(session)
session.connect()
def handle_disconnect(self, data):
# Your existing disconnect logic
self.send_response("OK\r\n")
# Your existing connect logic
self.send_response("OK")
def handle_mycall(self, data):
# Logic for handling MYCALL command
self.send_response("OK\r\n")
self.send_response("OK")
def handle_bw(self, data):
# Logic for handling BW command
self.send_response("OK\r\n")
self.send_response("OK")
def handle_abort(self, data):
# Logic for handling ABORT command
self.send_response("OK\r\n")
self.send_response("OK")
def handle_public(self, data):
# Logic for handling PUBLIC command
self.send_response("OK\r\n")
self.send_response("OK")
def handle_cwid(self, data):
# Logic for handling CWID command
self.send_response("OK\r\n")
self.send_response("OK")
def handle_listen(self, data):
# Logic for handling LISTEN command
self.send_response("OK\r\n")
self.send_response("OK")
def handle_compression(self, data):
# Logic for handling COMPRESSION command
self.send_response("OK\r\n")
self.send_response("OK")
def handle_winlink_session(self, data):
# Logic for handling WINLINK SESSION command
self.send_response("OK\r\n")
self.send_response("OK")
def socket_respond_disconnected(self):
self.send_response("DISCONNECTED")