From 72b08b631d94f54eb92e1192d92b6e8158060747 Mon Sep 17 00:00:00 2001 From: FReenen Date: Mon, 12 Aug 2024 19:31:04 +0200 Subject: [PATCH] commander update --- commander.html | 18 ++++++++++++++++++ ground-station.py | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/commander.html b/commander.html index b18623c..36e0eee 100644 --- a/commander.html +++ b/commander.html @@ -38,6 +38,12 @@
+
+ + + + +
@@ -76,6 +82,7 @@ var boatsLocked = []; loginEl.addEventListener('click', login); + document.getElementById('refresh').addEventListener('click', refreshAll); function login(e) { @@ -88,7 +95,13 @@ function onOpen(e) { conn.send(passEl.value + ";4675;" + Math.floor(new Date().getTime()/1000.0)); + refreshAll() + } + + function refreshAll() + { reqBoats(); + reqLockedBoats(); reqClients(); } @@ -128,6 +141,11 @@ conn.send(passEl.value + ";boats"); } + function reqLockedBoats() + { + conn.send(passEl.value + ";locked"); + } + function reqClients() { conn.send(passEl.value + ";clients"); diff --git a/ground-station.py b/ground-station.py index fd26b85..c071517 100644 --- a/ground-station.py +++ b/ground-station.py @@ -69,7 +69,7 @@ async def take_controll(client, boat): async def free_boat(boat): """make boat available for next client""" for client in Clients: - if client["boat"]['id'] == boat: + if client["boat"] is not None and client["boat"]['id'] == boat: client["boat"] = None break for b in Boats: @@ -81,7 +81,7 @@ async def free_boat(boat): async def lock_boat(boat): """lock a boat so client can't take controll over it""" for client in Clients: - if client["boat"]['id'] == boat: + if client["boat"] is not None and client["boat"]['id'] == boat: client["boat"] = None break for b in Boats: @@ -136,7 +136,7 @@ async def on_message(message, client): print("WARN: controll cmd (" + client['id'] + ") to None: " + data[2]) elif client['boat']['lastMsg'] + BOAT_DATA_INTERVAL_MAX < datetime.timestamp(datetime.now()): # print("INFO: controll cmd (" + client['id'] + ") to " + client['boat']['name'] + ": " + data[2]) - sendToBoat(client['boat'], "d:" + data[2] + "\n") + await sendToBoat(client['boat'], "d:" + data[2] + "\n") client['boat']['lastMsg'] = datetime.timestamp(datetime.now()) elif data[1] == "getlog" and client['id'] == ADMIN_ID: await getlog(client, data)