commander update

This commit is contained in:
Laila van Reenen 2024-08-12 19:31:04 +02:00
parent ac6d94d4a3
commit 72b08b631d
Signed by: LailaTheElf
GPG Key ID: 1F4E6EE3E6DDF769
2 changed files with 21 additions and 3 deletions

View File

@ -38,6 +38,12 @@
<button id="login">login</button> <button id="login">login</button>
</div> </div>
<main> <main>
<div id="refresh" class="btn">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2z"/>
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466"/>
</svg>
</div>
<table> <table>
<thead> <thead>
<tr> <tr>
@ -76,6 +82,7 @@
var boatsLocked = []; var boatsLocked = [];
loginEl.addEventListener('click', login); loginEl.addEventListener('click', login);
document.getElementById('refresh').addEventListener('click', refreshAll);
function login(e) function login(e)
{ {
@ -88,7 +95,13 @@
function onOpen(e) function onOpen(e)
{ {
conn.send(passEl.value + ";4675;" + Math.floor(new Date().getTime()/1000.0)); conn.send(passEl.value + ";4675;" + Math.floor(new Date().getTime()/1000.0));
refreshAll()
}
function refreshAll()
{
reqBoats(); reqBoats();
reqLockedBoats();
reqClients(); reqClients();
} }
@ -128,6 +141,11 @@
conn.send(passEl.value + ";boats"); conn.send(passEl.value + ";boats");
} }
function reqLockedBoats()
{
conn.send(passEl.value + ";locked");
}
function reqClients() function reqClients()
{ {
conn.send(passEl.value + ";clients"); conn.send(passEl.value + ";clients");

View File

@ -69,7 +69,7 @@ async def take_controll(client, boat):
async def free_boat(boat): async def free_boat(boat):
"""make boat available for next client""" """make boat available for next client"""
for client in Clients: for client in Clients:
if client["boat"]['id'] == boat: if client["boat"] is not None and client["boat"]['id'] == boat:
client["boat"] = None client["boat"] = None
break break
for b in Boats: for b in Boats:
@ -81,7 +81,7 @@ async def free_boat(boat):
async def lock_boat(boat): async def lock_boat(boat):
"""lock a boat so client can't take controll over it""" """lock a boat so client can't take controll over it"""
for client in Clients: for client in Clients:
if client["boat"]['id'] == boat: if client["boat"] is not None and client["boat"]['id'] == boat:
client["boat"] = None client["boat"] = None
break break
for b in Boats: for b in Boats:
@ -136,7 +136,7 @@ async def on_message(message, client):
print("WARN: controll cmd (" + client['id'] + ") to None: " + data[2]) print("WARN: controll cmd (" + client['id'] + ") to None: " + data[2])
elif client['boat']['lastMsg'] + BOAT_DATA_INTERVAL_MAX < datetime.timestamp(datetime.now()): elif client['boat']['lastMsg'] + BOAT_DATA_INTERVAL_MAX < datetime.timestamp(datetime.now()):
# print("INFO: controll cmd (" + client['id'] + ") to " + client['boat']['name'] + ": " + data[2]) # 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()) client['boat']['lastMsg'] = datetime.timestamp(datetime.now())
elif data[1] == "getlog" and client['id'] == ADMIN_ID: elif data[1] == "getlog" and client['id'] == ADMIN_ID:
await getlog(client, data) await getlog(client, data)