From 46a24c8a90d4e6e794a2c6ed79da94e02e2c7eab Mon Sep 17 00:00:00 2001
From: stuebinm
Date: Sun, 11 Sep 2022 13:07:02 +0200
Subject: on-board-unit: display estimated delay etc.

---
 site/obu.hamlet | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

(limited to 'site')

diff --git a/site/obu.hamlet b/site/obu.hamlet
index 9aec4c0..7068014 100644
--- a/site/obu.hamlet
+++ b/site/obu.hamlet
@@ -9,6 +9,11 @@
   <p><strong>Position: </strong><span id="lat"></span>, <span id="long"></span>
   <p><strong>Accuracy: </strong><span id="acc">
 
+<section>
+  <h2>_{MsgEstimated}
+  <p><strong>_{MsgDelay}</strong>: <span id="delay">
+  <p><strong>_{MsgSequence}</strong>: <span id="sequence">
+
 <section>
   <h2>Status
   <p id="status">_{MsgNone}
@@ -57,6 +62,14 @@
     setTimeout(openWebsocket, 1000);
   }
 
+  function wsMsg(msg) {
+    let json = JSON.parse(msg.data);
+    console.log(json);
+    document.getElementById("delay").innerText =
+      `${json.delay}s (${Math.floor(json.delay / 60)}min)`;
+    document.getElementById("sequence").innerText = json.sequence;
+  }
+
 
   function initGeopos() {
     document.getElementById("error").innerText = "";
@@ -72,7 +85,7 @@
     ws = new WebSocket((location.protocol == "http:" ? "ws" : "wss") + "://" + location.host + "/api/train/ping/ws");
     ws.onerror = wsError;
     ws.onclose = wsClose;
-    ws.onmessage = (msg) => console.log(msg.data); // TODO: display delays etc.
+    ws.onmessage = wsMsg
     ws.onopen = (event) => initGeopos();
   }
 
-- 
cgit v1.2.3