Add support for tacticals and cruddy filtering by those that have them
This commit is contained in:
parent
626cd02031
commit
70dcdf5d4f
79
client.js
79
client.js
@ -3,6 +3,30 @@ let stations = {};
|
|||||||
let messages = [];
|
let messages = [];
|
||||||
|
|
||||||
const timeoutLength = 20 * 60 * 1000; // 20 Minutes
|
const timeoutLength = 20 * 60 * 1000; // 20 Minutes
|
||||||
|
const trackedStations = {
|
||||||
|
// Digis/iGates
|
||||||
|
"W1FN-1": null,
|
||||||
|
"W1FN-3": null,
|
||||||
|
"W1FN-5": null,
|
||||||
|
"W1FN-6": null,
|
||||||
|
"W1FN-7": null,
|
||||||
|
"W1FN-8": null,
|
||||||
|
"W1FN-9": null,
|
||||||
|
"W1FN-10": null,
|
||||||
|
"N1GMC-1": null,
|
||||||
|
"N1GMC-2": null,
|
||||||
|
|
||||||
|
// Vehicles
|
||||||
|
"KC1GDW-6": "Rover 1",
|
||||||
|
"K1EHZ-9": "Rover 2",
|
||||||
|
"N0JSR-9": "Rover 3",
|
||||||
|
"W1KUA-9": "Manager",
|
||||||
|
"KC1GDW-13": "Coordinator",
|
||||||
|
"WB1BRE-12": "EMS",
|
||||||
|
"KC1GDW-11": "Bike Tech",
|
||||||
|
"KC1GDW-14": "Something (panel van thing)"
|
||||||
|
};
|
||||||
|
|
||||||
const lowVoltage = 11.9;
|
const lowVoltage = 11.9;
|
||||||
|
|
||||||
if (Notification.permission !== "granted") {
|
if (Notification.permission !== "granted") {
|
||||||
@ -13,6 +37,13 @@ if (Notification.permission !== "granted") {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTactical(callsign) {
|
||||||
|
if (trackedStations[callsign])
|
||||||
|
return `${trackedStations[callsign]} [${callsign}]`;
|
||||||
|
else
|
||||||
|
return callsign;
|
||||||
|
}
|
||||||
|
|
||||||
function prettyDuration(duration) {
|
function prettyDuration(duration) {
|
||||||
let date = new Date(timeoutLength);
|
let date = new Date(timeoutLength);
|
||||||
return date.getUTCHours() > 0 ? date.getUTCHours() + " Hours": "" +
|
return date.getUTCHours() > 0 ? date.getUTCHours() + " Hours": "" +
|
||||||
@ -41,7 +72,7 @@ function redrawTable() {
|
|||||||
tr.classList.add('lowVoltage');
|
tr.classList.add('lowVoltage');
|
||||||
}
|
}
|
||||||
tr.innerHTML =
|
tr.innerHTML =
|
||||||
`<td>${callsign}</td>` +
|
`<td>${getTactical(callsign)}</td>` +
|
||||||
`<td>${station.lastHeard.toLocaleTimeString('en-GB')}</td>` +
|
`<td>${station.lastHeard.toLocaleTimeString('en-GB')}</td>` +
|
||||||
`<td>${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})}</td>` +
|
`<td>${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})}</td>` +
|
||||||
`<td>${station.lastVoltage||''}</td>` +
|
`<td>${station.lastVoltage||''}</td>` +
|
||||||
@ -55,12 +86,12 @@ function notify(title, body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function alertNotHeard(callsign) {
|
function alertNotHeard(callsign) {
|
||||||
notify(`${callsign} has not been heard for ${prettyDuration(timeoutLength)}!`,
|
notify(`${getTactical(callsign)} has not been heard for ${prettyDuration(timeoutLength)}!`,
|
||||||
`Last Heard: ${stations[callsign].lastHeard.toLocaleTimeString('en-GB')}`);
|
`Last Heard: ${stations[callsign].lastHeard.toLocaleTimeString('en-GB')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function alertVoltage(callsign) {
|
function alertVoltage(callsign) {
|
||||||
notify(`${callsign}'s battery has dropepd below ${lowVoltage}V`,
|
notify(`${getTactical(callsign)}'s battery has dropepd below ${lowVoltage}V`,
|
||||||
`Voltage: ${stations[callsign].lastVoltage}`);
|
`Voltage: ${stations[callsign].lastVoltage}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,28 +104,32 @@ aprsStream.onmessage = function(event) {
|
|||||||
console.log(message);
|
console.log(message);
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
|
|
||||||
if (!(callsign in stations)) {
|
// TODO: hacky filter
|
||||||
stations[callsign] = {};
|
if (callsign in trackedStations) {
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
if (!(callsign in stations)) {
|
||||||
window.clearTimeout(stations[callsign].timeout);
|
stations[callsign] = {};
|
||||||
}
|
}
|
||||||
stations[callsign].lastHeard = date;
|
else {
|
||||||
stations[callsign].delta = date - stations[callsign].lastHeard;
|
window.clearTimeout(stations[callsign].timeout);
|
||||||
stations[callsign].timeout = window.setTimeout(
|
|
||||||
alertNotHeard, timeoutLength, callsign);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
redrawTable();
|
stations[callsign].lastHeard = date;
|
||||||
|
stations[callsign].delta = date - stations[callsign].lastHeard;
|
||||||
|
stations[callsign].timeout = window.setTimeout(
|
||||||
|
alertNotHeard, timeoutLength, callsign);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redrawTable();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("load", redrawTable);
|
window.addEventListener("load", redrawTable);
|
||||||
|
Loading…
Reference in New Issue
Block a user