diff --git a/commander.html b/commander.html index ce92f74..6860812 100644 --- a/commander.html +++ b/commander.html @@ -26,9 +26,9 @@ height: 200px; } .btn { - padding: 10px 20px; - background-color: #808080; + padding: 5px 10px; cursor: pointer; + display: inline-block; } @@ -46,6 +46,7 @@ + @@ -56,6 +57,7 @@
bootjes
id naam
+ @@ -191,7 +193,7 @@ if (boatRow.dataset['state'] == "locked") { lockBtn.innerHTML = openIcon; - lockBtn.addEventListener('click', unlockBoat); + lockBtn.addEventListener('click', freeBoat); } else { @@ -224,36 +226,6 @@ } } - function getDataFomEl(el) - { - while (el.tagName != "BODY" && el.dataset['id'] == null) - { - el = el.parentElement; - } - return el.dataset; - } - - function kickClient(e) - { - let client = getDataFomEl(e.target); - console.log("kickClient", client); - conn.send(passEl.value + ";kick;" + client['id']); - } - - function unlockBoat(e) - { - let boat = getDataFomEl(e.target); - console.log("unlockBoat", boat); - conn.send(passEl.value + ";unlock;" + boat['id']); - } - - function lockBoat(e) - { - let boat = getDataFomEl(e.target); - console.log("lockBoat", boat); - conn.send(passEl.value + ";lock;" + boat['id']); - } - function addClient(client) { client = client.split(';') @@ -288,6 +260,36 @@ { console.warn("addClient(): incorect number of args (" + client.length.toString() + "; " + client.toString() + ")"); } + + function getDataFomEl(el) + { + while (el.tagName != "BODY" && el.dataset['id'] == null) + { + el = el.parentElement; + } + return el.dataset; + } + + function kickClient(e) + { + let client = getDataFomEl(e.target); + console.log("kickClient", client); + conn.send(passEl.value + ";kick;" + client['id']); + } + + function freeBoat(e) + { + let boat = getDataFomEl(e.target); + console.log("unlockBoat", boat); + conn.send(passEl.value + ";free;" + boat['id']); + } + + function lockBoat(e) + { + let boat = getDataFomEl(e.target); + console.log("lockBoat", boat); + conn.send(passEl.value + ";lock;" + boat['id']); + } } diff --git a/ground-station.py b/ground-station.py index 57c5b97..41b7a37 100644 --- a/ground-station.py +++ b/ground-station.py @@ -17,8 +17,8 @@ Boats = [] Clients = [] async def sendToBoat(boat, cmd): - client['boat']['log'].append({"t": datetime.timestamp(datetime.now()), "type": "tx", "msg": cmd}) - await client['boat']['ws'].send(cmd) + boat['log'].append({"t": datetime.timestamp(datetime.now()), "type": "tx", "msg": cmd}) + await boat['ws'].send(cmd) async def echo_boats(client): """echo list of all not locked boats to client""" @@ -46,7 +46,10 @@ async def echo_clients(client): if client['id'] == ADMIN_ID: data = "clients:" for clie in Clients: - data += str(clie['id']) + ";" + str(clie['boat']) + ";" + str(clie['state']) + ":" + if (clie['id'] == ADMIN_ID): + data += "admin;" + str(clie['boat']) + ";" + str(clie['state']) + ":" + else: + data += str(clie['id']) + ";" + str(clie['boat']) + ";" + str(clie['state']) + ":" await client['ws'].send(data + '\n') async def take_controll(client, boat): @@ -74,8 +77,7 @@ async def free_boat(boat): break for b in Boats: if b['id'] == boat and b['state'] != BOAT_STATE_TERMINATED: - if b['state'] == BOAT_STATE_INCTRL: - b["state"] = BOAT_STATE_AVAILABLE + b["state"] = BOAT_STATE_AVAILABLE break async def lock_boat(boat): @@ -142,6 +144,8 @@ async def on_message(message, client): await getlog(client, data) elif data[1] == "sendcmd" and client['id'] == ADMIN_ID: await sendcmd(data) + elif client['id'] == ADMIN_ID: + print("WARN: invalid command (admin): '" + data[1] + "'") else: print("WARN: invalid command (" + client['id'] + "): '" + data[1] + "'")
clients
id boat