Add support for tacticals and cruddy filtering by those that have them

This commit is contained in:
Adam Goldsmith 2018-07-12 21:00:19 -04:00
parent 626cd02031
commit 70dcdf5d4f

View File

@ -3,6 +3,30 @@ let stations = {};
let messages = [];
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;
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) {
let date = new Date(timeoutLength);
return date.getUTCHours() > 0 ? date.getUTCHours() + " Hours": "" +
@ -41,7 +72,7 @@ function redrawTable() {
tr.classList.add('lowVoltage');
}
tr.innerHTML =
`<td>${callsign}</td>` +
`<td>${getTactical(callsign)}</td>` +
`<td>${station.lastHeard.toLocaleTimeString('en-GB')}</td>` +
`<td>${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})}</td>` +
`<td>${station.lastVoltage||''}</td>` +
@ -55,12 +86,12 @@ function notify(title, body) {
}
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')}`);
}
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}`);
}
@ -73,13 +104,16 @@ aprsStream.onmessage = function(event) {
console.log(message);
messages.push(message);
// TODO: hacky filter
if (callsign in trackedStations) {
if (!(callsign in stations)) {
stations[callsign] = {};
}
else {
window.clearTimeout(stations[callsign].timeout);
}
stations[callsign].lastHeard = date;
stations[callsign].delta = date - stations[callsign].lastHeard;
stations[callsign].timeout = window.setTimeout(
@ -95,6 +129,7 @@ aprsStream.onmessage = function(event) {
}
redrawTable();
}
};
window.addEventListener("load", redrawTable);