2024-03-16 10:14:48 +00:00
|
|
|
from command_p2p_connection import P2PConnectionCommand
|
|
|
|
|
|
|
|
class SocketCommandHandler:
|
|
|
|
|
2024-03-16 14:52:14 +00:00
|
|
|
def __init__(self, cmd_request, modem, config_manager, state_manager, event_manager):
|
|
|
|
self.cmd_request = cmd_request
|
2024-03-16 12:44:58 +00:00
|
|
|
self.modem = modem
|
|
|
|
self.config_manager = config_manager
|
2024-03-16 10:14:48 +00:00
|
|
|
self.state_manager = state_manager
|
2024-03-16 12:44:58 +00:00
|
|
|
self.event_manager = event_manager
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def send_response(self, message):
|
2024-03-16 14:52:14 +00:00
|
|
|
full_message = f"{message}\r\n"
|
|
|
|
self.cmd_request.sendall(full_message.encode())
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def handle_connect(self, data):
|
|
|
|
# Your existing connect logic
|
2024-03-16 14:52:14 +00:00
|
|
|
self.send_response("OK")
|
2024-03-16 12:44:58 +00:00
|
|
|
|
2024-03-16 10:14:48 +00:00
|
|
|
params = {
|
2024-03-16 14:52:14 +00:00
|
|
|
'origin': data[0],
|
|
|
|
'destination': data[1],
|
2024-03-16 10:14:48 +00:00
|
|
|
}
|
2024-03-16 14:52:14 +00:00
|
|
|
cmd = P2PConnectionCommand(self.config_manager.read(), self.state_manager, self.event_manager, params, self)
|
2024-03-16 12:44:58 +00:00
|
|
|
session = cmd.run(self.event_manager.queues, self.modem)
|
2024-03-16 10:14:48 +00:00
|
|
|
if session.session_id:
|
2024-03-16 12:44:58 +00:00
|
|
|
self.state_manager.register_p2p_connection_session(session)
|
2024-03-16 10:14:48 +00:00
|
|
|
session.connect()
|
|
|
|
|
|
|
|
def handle_disconnect(self, data):
|
2024-03-16 14:52:14 +00:00
|
|
|
# Your existing connect logic
|
|
|
|
self.send_response("OK")
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def handle_mycall(self, data):
|
|
|
|
# Logic for handling MYCALL command
|
2024-03-16 14:52:14 +00:00
|
|
|
self.send_response("OK")
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def handle_bw(self, data):
|
|
|
|
# Logic for handling BW command
|
2024-03-16 14:52:14 +00:00
|
|
|
self.send_response("OK")
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def handle_abort(self, data):
|
|
|
|
# Logic for handling ABORT command
|
2024-03-16 14:52:14 +00:00
|
|
|
self.send_response("OK")
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def handle_public(self, data):
|
|
|
|
# Logic for handling PUBLIC command
|
2024-03-16 14:52:14 +00:00
|
|
|
self.send_response("OK")
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def handle_cwid(self, data):
|
|
|
|
# Logic for handling CWID command
|
2024-03-16 14:52:14 +00:00
|
|
|
self.send_response("OK")
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def handle_listen(self, data):
|
|
|
|
# Logic for handling LISTEN command
|
2024-03-16 14:52:14 +00:00
|
|
|
self.send_response("OK")
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def handle_compression(self, data):
|
|
|
|
# Logic for handling COMPRESSION command
|
2024-03-16 14:52:14 +00:00
|
|
|
self.send_response("OK")
|
2024-03-16 10:14:48 +00:00
|
|
|
|
|
|
|
def handle_winlink_session(self, data):
|
|
|
|
# Logic for handling WINLINK SESSION command
|
2024-03-16 14:52:14 +00:00
|
|
|
self.send_response("OK")
|
|
|
|
|
|
|
|
def socket_respond_disconnected(self):
|
|
|
|
self.send_response("DISCONNECTED")
|
|
|
|
|
2024-03-16 15:11:38 +00:00
|
|
|
def socket_respond_connected(self, mycall, dxcall, bandwidth):
|
|
|
|
message = f"CONNECTED {mycall} {dxcall} {bandwidth}"
|
|
|
|
self.send_response(message)
|