From a094027a108926a00b89c94f95678c3784857770 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 25 May 2025 22:58:38 -0400 Subject: [PATCH] Implement OP25 commands --- app/internal/types.py | 3 ++ app/routers/nodes.py | 78 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/app/internal/types.py b/app/internal/types.py index b523eca..c1a3faa 100644 --- a/app/internal/types.py +++ b/app/internal/types.py @@ -12,6 +12,9 @@ class NodeCommands(str, Enum): JOIN = "join_server" LEAVE = "leave_server" STATUS = "get_status" + OP25_START = "op25_start" + OP25_STOP = "op25_stop" + OP25_SET = "op25_set" class TalkgroupTag: diff --git a/app/routers/nodes.py b/app/routers/nodes.py index 9134bc8..1eb5aa4 100644 --- a/app/routers/nodes.py +++ b/app/routers/nodes.py @@ -204,7 +204,7 @@ async def join(client_id): @nodes_bp.route("//leave", methods=['POST']) async def leave(client_id): """ - Send a leave command to the specific system specified + Send a leave command to the specific node """ data = await request.get_json() @@ -225,5 +225,81 @@ async def leave(client_id): return jsonify({"status": "command sent", "client_id": client_id, "command": NodeCommands.LEAVE}), 200 + except Exception as e: + return jsonify({"error": f"Failed to send command: {e}"}), 500 + + +@nodes_bp.route("//op25_start", methods=['POST']) +async def op25_start(client_id): + """ + Send an OP25 start command to the specific node + """ + data = await request.get_json() + + system_id = data.get("system_id") + + # Check to make sure the client is online + if client_id not in current_app.active_clients: + return jsonify({"error": f"Client {client_id} not found, it might be offline"}), 404 + + if not system_id: + return jsonify({"error":"No System ID supplied"}), 400 + + try: + # Send the command asynchronously + await send_command_to_client(client_id, NodeCommands.OP25_START) + + return jsonify({"status": "command sent", "client_id": client_id, "command": NodeCommands.OP25_START}), 200 + + except Exception as e: + return jsonify({"error": f"Failed to send command: {e}"}), 500 + + +@nodes_bp.route("//op25_stop", methods=['POST']) +async def op25_stop(client_id): + """ + Send an OP25 stop command to the specific node + """ + # Check to make sure the client is online + if client_id not in current_app.active_clients: + return jsonify({"error": f"Client {client_id} not found, it might be offline"}), 404 + + try: + # Send the command asynchronously + await send_command_to_client(client_id, NodeCommands.OP25_START) + + return jsonify({"status": "command sent", "client_id": client_id, "command": NodeCommands.OP25_STOP}), 200 + + except Exception as e: + return jsonify({"error": f"Failed to send command: {e}"}), 500 + + +@nodes_bp.route("//op25_set", methods=['POST']) +async def op25_set(client_id): + """ + Send an OP25 set config command to the specific node + """ + data = await request.get_json() + + system_id = data.get("system_id") + + # Check to make sure the client is online + if client_id not in current_app.active_clients: + return jsonify({"error": f"Client {client_id} not found, it might be offline"}), 404 + + if not system_id: + return jsonify({"error":"No System ID supplied"}), 400 + + try: + args = [system_id] + + if not isinstance(args, list): + return jsonify({"error": "'args' must be a list"}), 400 + + # Send the command asynchronously + await send_command_to_client(client_id, NodeCommands.OP25_START, *args) + + return jsonify({"status": "command sent", "client_id": client_id, "command": NodeCommands.OP25_SET}), 200 + except Exception as e: return jsonify({"error": f"Failed to send command: {e}"}), 500 \ No newline at end of file