2018-07-10 20:43:06 -04:00
|
|
|
let stations = {};
|
2018-07-10 01:15:26 -04:00
|
|
|
|
|
|
|
let messages = [];
|
|
|
|
|
2018-07-10 18:47:01 -04:00
|
|
|
const timeoutLength = 20 * 60 * 1000; // 20 Minutes
|
2018-07-11 21:17:57 -04:00
|
|
|
const lowVoltage = 11.9;
|
2018-07-10 01:15:26 -04:00
|
|
|
|
|
|
|
Notification.requestPermission(permission => {
|
|
|
|
if (permission === "granted") {
|
|
|
|
new Notification("Test notification", {body: "whatever"});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-10 19:03:21 -04:00
|
|
|
function redrawTable() {
|
2018-07-10 20:43:06 -04:00
|
|
|
let table = document.querySelector('table.stations');
|
2018-07-10 19:03:21 -04:00
|
|
|
table.innerHTML =
|
|
|
|
`<tr><th>Callsign</th>` +
|
|
|
|
`<th>Last Heard</th>` +
|
2018-07-11 21:17:57 -04:00
|
|
|
`<th>Time since Last Heard</th>` +
|
|
|
|
`<th>Last Voltage</th>` +
|
|
|
|
`<th>Last Temperature</th>`;
|
2018-07-10 20:43:06 -04:00
|
|
|
for (let callsign in stations) {
|
|
|
|
let station = stations[callsign];
|
|
|
|
let nowDelta = new Date(new Date() - station.lastHeard);
|
2018-07-10 19:03:21 -04:00
|
|
|
|
|
|
|
let tr = table.appendChild(document.createElement('tr'));
|
|
|
|
if (nowDelta.getTime() > timeoutLength) {
|
|
|
|
tr.classList.add('timedOut');
|
|
|
|
}
|
2018-07-11 21:17:57 -04:00
|
|
|
if (station.lastVoltage < lowVoltage) {
|
|
|
|
tr.classList.add('lowVoltage');
|
|
|
|
}
|
2018-07-10 19:03:21 -04:00
|
|
|
tr.innerHTML =
|
|
|
|
`<td>${callsign}</td>` +
|
2018-07-10 20:43:06 -04:00
|
|
|
`<td>${station.lastHeard.toLocaleTimeString('en-GB')}</td>` +
|
2018-07-11 21:17:57 -04:00
|
|
|
`<td>${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})}</td>` +
|
|
|
|
`<td>${station.lastVoltage||''}</td>` +
|
|
|
|
`<td>${station.lastTemperature||''}</td>`;
|
|
|
|
|
2018-07-10 19:03:21 -04:00
|
|
|
}
|
|
|
|
}
|
2018-07-10 18:47:01 -04:00
|
|
|
|
|
|
|
function alertNotHeard(callsign) {
|
|
|
|
new Notification(`${callsign} has not been heard for 20 Minutes!`,
|
2018-07-10 20:43:06 -04:00
|
|
|
{body: `Last Heard: ${stations[callsign].lastHeard.toLocaleTimeString('en-GB')}`});
|
2018-07-10 01:15:26 -04:00
|
|
|
}
|
|
|
|
|
2018-07-11 21:17:57 -04:00
|
|
|
function alertVoltage(callsign) {
|
|
|
|
new Notification(`${callsign}'s battery has dropepd below ${lowVoltage}V`,
|
|
|
|
{body: `Voltage: ${stations[callsign].lastVoltage}`});
|
|
|
|
}
|
|
|
|
|
2018-07-10 01:15:26 -04:00
|
|
|
let aprsStream = new WebSocket("ws://localhost:1234");
|
|
|
|
aprsStream.onmessage = function(event) {
|
|
|
|
let message = JSON.parse(event.data);
|
2018-07-10 18:47:01 -04:00
|
|
|
let callsign = `${message.from.call}-${message.from.ssid || 0}`;
|
|
|
|
let date = new Date(message.recieved);
|
2018-07-10 01:15:26 -04:00
|
|
|
|
|
|
|
console.log(message);
|
2018-07-10 18:47:01 -04:00
|
|
|
messages.push(message);
|
2018-07-10 01:15:26 -04:00
|
|
|
|
2018-07-10 20:43:06 -04:00
|
|
|
if (!(callsign in stations)) {
|
|
|
|
stations[callsign] = {
|
2018-07-10 18:47:01 -04:00
|
|
|
lastHeard: date,
|
|
|
|
};
|
2018-07-10 01:15:26 -04:00
|
|
|
}
|
2018-07-10 18:47:01 -04:00
|
|
|
|
|
|
|
else {
|
2018-07-10 20:43:06 -04:00
|
|
|
window.clearTimeout(stations[callsign].timeout);
|
2018-07-10 18:47:01 -04:00
|
|
|
}
|
|
|
|
|
2018-07-10 20:43:06 -04:00
|
|
|
stations[callsign].delta = date - stations[callsign].lastHeard;
|
|
|
|
stations[callsign].timeout = window.setTimeout(
|
2018-07-10 18:47:01 -04:00
|
|
|
alertNotHeard, timeoutLength, callsign);
|
2018-07-10 19:03:21 -04:00
|
|
|
|
2018-07-11 21:17:57 -04:00
|
|
|
if ('data' in message && 'analog' in message.data) {
|
|
|
|
stations[callsign].lastVoltage = message.data.analog[0] / 10;
|
|
|
|
stations[callsign].lastTemperature = message.data.analog[1];
|
|
|
|
|
|
|
|
if (stations[callsign].lastVoltage <= lowVoltage) {
|
|
|
|
alertVoltage(callsign);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-10 19:03:21 -04:00
|
|
|
redrawTable();
|
2018-07-10 01:15:26 -04:00
|
|
|
};
|
|
|
|
|
2018-07-10 19:03:21 -04:00
|
|
|
window.addEventListener("load", redrawTable);
|
|
|
|
window.setInterval(redrawTable, 1000);
|