2024-09-12 01:02:57 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>succd</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
2024-09-27 00:10:39 +00:00
|
|
|
<link rel="shortcut icon" type="image/png" href="/favicon.png">
|
2024-09-12 01:02:57 +00:00
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
font-size: 14px;
|
2024-09-27 00:31:38 +00:00
|
|
|
padding: 2em;
|
2024-09-12 01:02:57 +00:00
|
|
|
}
|
|
|
|
table {
|
2024-09-27 00:31:38 +00:00
|
|
|
font-size: 40px;
|
2024-09-12 01:02:57 +00:00
|
|
|
}
|
|
|
|
th, td {
|
2024-09-27 00:31:38 +00:00
|
|
|
background-color: #e8e8e8;
|
|
|
|
padding: 0.4em;
|
2024-09-12 01:02:57 +00:00
|
|
|
}
|
|
|
|
th {
|
2024-09-27 00:31:38 +00:00
|
|
|
font-weight: 100;
|
|
|
|
text-align: right;
|
|
|
|
font-size: 30px;
|
2024-09-12 01:02:57 +00:00
|
|
|
}
|
|
|
|
td {
|
2024-09-27 00:31:38 +00:00
|
|
|
text-align: left;
|
2024-09-12 01:02:57 +00:00
|
|
|
}
|
|
|
|
td {
|
2024-09-27 00:31:38 +00:00
|
|
|
font-weight: 800;
|
2024-09-12 01:02:57 +00:00
|
|
|
}
|
|
|
|
h2 {
|
2024-09-27 00:31:38 +00:00
|
|
|
font-style: italic;
|
|
|
|
font-weight: 100;
|
2024-09-12 01:02:57 +00:00
|
|
|
}
|
2024-09-25 21:28:57 +00:00
|
|
|
button {
|
|
|
|
height: 4.5em;
|
|
|
|
padding-left: 1.5em;
|
|
|
|
padding-right: 1.5em;
|
|
|
|
}
|
2024-09-27 00:10:39 +00:00
|
|
|
|
2024-09-27 00:11:04 +00:00
|
|
|
td > span {
|
|
|
|
padding: 0.2em;
|
|
|
|
}
|
|
|
|
|
2024-09-27 00:10:39 +00:00
|
|
|
.logo {
|
|
|
|
float: left;
|
|
|
|
margin-right: 2em;
|
|
|
|
}
|
|
|
|
|
|
|
|
.logo > img {
|
|
|
|
height: 10em;
|
|
|
|
}
|
2024-09-12 01:02:57 +00:00
|
|
|
</style>
|
|
|
|
|
2024-09-27 00:10:39 +00:00
|
|
|
<div class="logo"><img src="/favicon.png" /></div>
|
|
|
|
|
2024-09-12 01:02:57 +00:00
|
|
|
<h1>succd</h1>
|
|
|
|
<h2>nothing more permanent than a temporary solution</h2>
|
|
|
|
|
2024-09-27 00:10:39 +00:00
|
|
|
<p style="margin-top: 2em; clear: both;">
|
2024-09-27 00:31:38 +00:00
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Voltage</th>
|
|
|
|
<td id="volts" colspan="4">{{.volts}}</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>Pressure</th>
|
|
|
|
<td id="mbar" colspan="4">{{.mbar}}</td>
|
|
|
|
</tr>
|
2024-09-27 00:11:04 +00:00
|
|
|
<tr>
|
|
|
|
<th>Thresholds</th>
|
|
|
|
<td>Rough:</td>
|
|
|
|
<td id="trough">...</td>
|
|
|
|
<td>High:</td>
|
|
|
|
<td id="thigh">...</td>
|
|
|
|
</tr>
|
2024-09-27 00:31:38 +00:00
|
|
|
<tr>
|
|
|
|
<th>Pumps</th>
|
2024-09-27 00:11:04 +00:00
|
|
|
<td>RP:</td>
|
|
|
|
<td id="rp">{{ if .rp }}ON{{ else }}OFF{{ end }}</td>
|
|
|
|
<td>DP:</td>
|
|
|
|
<td id="dp">{{ if .dp }}ON{{ else }}OFF{{ end }}</td>
|
2024-09-27 00:31:38 +00:00
|
|
|
</tr>
|
2024-09-25 21:28:57 +00:00
|
|
|
<tr>
|
|
|
|
<th>Evac Control</th>
|
2024-09-27 00:11:04 +00:00
|
|
|
<td colspan="4">
|
2024-09-25 21:28:57 +00:00
|
|
|
<button id="pd">Pump Down</button>
|
|
|
|
<button id="vent">Vent</button>
|
|
|
|
<button id="rpon">RP On</button>
|
|
|
|
<button id="rpoff">RP Off</button>
|
|
|
|
<button id="dpon">DP On</button>
|
|
|
|
<button id="dpoff">DP Off</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2024-09-27 00:31:38 +00:00
|
|
|
<tr>
|
|
|
|
<th>Status</th>
|
|
|
|
<td id="status" colspan="4">OK</td>
|
|
|
|
</tr>
|
2024-09-27 21:49:24 +00:00
|
|
|
<tr>
|
|
|
|
<th>Failsafe</th>
|
|
|
|
<td id="failsafe" colspan="4">OK</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>Diffusion Pump Lockout</th>
|
|
|
|
<td id="highpressure" colspan="4">OK</td>
|
|
|
|
</tr>
|
2024-09-27 00:31:38 +00:00
|
|
|
</table>
|
2024-09-12 01:02:57 +00:00
|
|
|
</p>
|
|
|
|
<p style="margin-top: 2em;">
|
2024-09-12 01:22:02 +00:00
|
|
|
<canvas id="graph" width="1024" height="512" style="max-width: 100%;"></canvas>
|
2024-09-12 01:02:57 +00:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<p style="font-style: italic; font-size: 12px; margin-top: 5em;">
|
2024-09-27 00:31:38 +00:00
|
|
|
{{.hostname}} | load: {{.load}} | <a href="/debug/pprof">pprof</a> | <a href="/metrics">metrics</a> | ws ping: <span id="ping">…</span>
|
2024-09-12 01:02:57 +00:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
let historical = [];
|
|
|
|
let canvas = null;
|
|
|
|
|
|
|
|
// Push a datapoint (in mbar) to the historical buffer, maintaining enough data
|
|
|
|
// for ~10 minutes.
|
|
|
|
let historicalPush = (v) => {
|
|
|
|
historical.push({v: v, time: Date.now() / 1000});
|
|
|
|
let len = historical.length;
|
|
|
|
// TODO(q3k): trim based on recorded timestamp, not constant buffer size.
|
|
|
|
let trim = len - 8192;
|
|
|
|
if (trim > 0) {
|
|
|
|
historical = historical.slice(trim);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Draw the historical graph and schedule next draw in 100msec.
|
|
|
|
let historicalDraw = (w, h) => {
|
|
|
|
const now = Date.now() / 1000;
|
|
|
|
|
|
|
|
// TODO(q3k): better use canvas API to not have so much silly math around
|
|
|
|
// coordinate calculation.
|
|
|
|
|
|
|
|
canvas.clearRect(0, 0, w, h);
|
|
|
|
canvas.fillStyle = "#f0f0f0";
|
|
|
|
canvas.fillRect(0, 0, w, h);
|
|
|
|
|
|
|
|
// Margins of the main graph window.
|
|
|
|
const marginLeft = 64;
|
|
|
|
const marginRight = 32;
|
|
|
|
const marginTop = 32;
|
|
|
|
const marginBottom = 32;
|
|
|
|
|
|
|
|
// Draw main graph window.
|
|
|
|
canvas.fillStyle = "#f8f8f8";
|
|
|
|
canvas.strokeStyle = "#444";
|
|
|
|
canvas.lineWidth = 1;
|
|
|
|
canvas.fillRect(marginLeft, marginTop, w-(marginLeft+marginRight), h-(marginTop+marginBottom));
|
|
|
|
canvas.strokeRect(marginLeft, marginTop, w-(marginLeft+marginRight), h-(marginTop+marginBottom));
|
|
|
|
|
|
|
|
// Range of decades for Y value.
|
|
|
|
const ymin = -4;
|
|
|
|
const ymax = 4;
|
|
|
|
// Pixels per decade.
|
|
|
|
const yscale = (h - (marginTop+marginBottom)) / (ymax - ymin);
|
|
|
|
|
|
|
|
// For every decade...
|
|
|
|
for (let i = ymin; i < ymax; i++) {
|
|
|
|
const yoff = (i - ymin) * yscale + yscale / 2;
|
|
|
|
const y = Math.floor(h - marginBottom - yoff) + 0.5;
|
|
|
|
// Draw Y scale ticks.
|
|
|
|
canvas.beginPath();
|
|
|
|
canvas.moveTo(marginLeft-5, y);
|
|
|
|
canvas.lineTo(marginLeft, y);
|
|
|
|
canvas.strokeStyle = "#000";
|
|
|
|
canvas.stroke();
|
|
|
|
|
|
|
|
// Draw Y grid.
|
|
|
|
canvas.beginPath();
|
|
|
|
canvas.moveTo(marginLeft, y);
|
|
|
|
canvas.lineTo(w-marginRight-1, y);
|
|
|
|
canvas.strokeStyle = "#ccc";
|
|
|
|
canvas.stroke();
|
|
|
|
|
|
|
|
// Draw Y fine grid.
|
|
|
|
if (i > ymin) {
|
|
|
|
for (let j = 2; j < 10; j++) {
|
|
|
|
let yy = y - Math.log10(j/10) * yscale;
|
|
|
|
canvas.beginPath();
|
|
|
|
canvas.moveTo(marginLeft, yy);
|
|
|
|
canvas.lineTo(w-marginRight-1, yy);
|
|
|
|
canvas.strokeStyle = "#eee";
|
|
|
|
canvas.stroke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw Y labels.
|
|
|
|
canvas.font = "10px sans-serif";
|
|
|
|
canvas.fillStyle = "#000";
|
|
|
|
canvas.textAlign = "right";
|
|
|
|
const text = `10^${i}`;
|
|
|
|
canvas.fillText(text, marginLeft-10, y+5);
|
|
|
|
}
|
|
|
|
|
|
|
|
// How much space to leave in front of the graph.
|
|
|
|
const xhead = 10;
|
|
|
|
|
|
|
|
// Draw X labels..
|
|
|
|
canvas.textAlign = "center";
|
|
|
|
canvas.fillText("Now", w - marginRight - xhead, h - marginBottom + 15)
|
|
|
|
canvas.fillText("-10min", marginLeft, h - marginBottom + 15)
|
|
|
|
|
|
|
|
const xmax = 60 * 10;
|
|
|
|
const xscale = (w - (marginLeft+marginRight+xhead)) / (xmax);
|
|
|
|
|
|
|
|
// Clip to main window.
|
|
|
|
canvas.save();
|
|
|
|
canvas.beginPath();
|
|
|
|
canvas.rect(marginLeft, marginTop, w-(marginLeft+marginRight), h-(marginTop+marginBottom+1));
|
|
|
|
canvas.clip();
|
|
|
|
|
|
|
|
// Draw actual data line.
|
|
|
|
let first = true;
|
|
|
|
canvas.beginPath();
|
|
|
|
historical.forEach((v) => {
|
|
|
|
const time = v.time;
|
|
|
|
const mbar = v.v;
|
|
|
|
const elapsed = now-time;
|
|
|
|
if (elapsed > xmax) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const x = (w - marginRight - xhead) - (elapsed * xscale);
|
|
|
|
const yoff = (Math.log10(mbar) - ymin) * yscale + yscale / 2;
|
|
|
|
const y = h - marginBottom - yoff;
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
canvas.moveTo(x, y);
|
|
|
|
} else {
|
|
|
|
canvas.lineTo(x, y);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
canvas.strokeStyle = "#de1010";
|
|
|
|
canvas.lineWidth = 1;
|
|
|
|
canvas.stroke();
|
|
|
|
canvas.restore();
|
|
|
|
|
|
|
|
setTimeout(() => { historicalDraw(w, h); }, 100);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener("load", (_) => {
|
2024-09-27 00:31:38 +00:00
|
|
|
console.log("s u c c");
|
2024-09-12 01:02:57 +00:00
|
|
|
|
2024-09-27 00:31:38 +00:00
|
|
|
let status = document.querySelector("#status");
|
2024-09-27 21:49:24 +00:00
|
|
|
let failsafe = document.querySelector("#failsafe");
|
|
|
|
let highpressure = document.querySelector("#highpressure");
|
2024-09-27 00:31:38 +00:00
|
|
|
let volts = document.querySelector("#volts");
|
|
|
|
let mbar = document.querySelector("#mbar");
|
|
|
|
let ping = document.querySelector("#ping");
|
2024-09-27 00:11:04 +00:00
|
|
|
let trough = document.querySelector("#trough");
|
|
|
|
let thigh = document.querySelector("#thigh");
|
2024-09-25 21:28:57 +00:00
|
|
|
|
|
|
|
// Buttons
|
2024-09-27 00:31:38 +00:00
|
|
|
let pd = document.querySelector("#pd");
|
|
|
|
let vent = document.querySelector("#vent");
|
|
|
|
let rpon = document.querySelector("#rpon");
|
|
|
|
let rpoff = document.querySelector("#rpoff");
|
2024-09-12 01:02:57 +00:00
|
|
|
canvas = document.querySelector("#graph").getContext("2d");
|
|
|
|
|
2024-09-12 01:22:02 +00:00
|
|
|
// TODO(q3k): unhardcode this.
|
2024-09-12 01:02:57 +00:00
|
|
|
historicalDraw(1024, 512);
|
|
|
|
|
|
|
|
// Basic retry loop for connecting to WS.
|
2024-09-27 00:31:38 +00:00
|
|
|
let loc = window.location;
|
|
|
|
let wsloc = "";
|
|
|
|
if (loc.protocol == "https:") {
|
|
|
|
wsloc = "wss:";
|
|
|
|
} else {
|
|
|
|
wsloc = "ws:";
|
|
|
|
}
|
|
|
|
wsloc += "//" + loc.host + "/stream";
|
|
|
|
console.log("Connecting to " + wsloc + "...");
|
|
|
|
|
|
|
|
let connected = false;
|
|
|
|
let connect = () => {
|
|
|
|
const socket = new WebSocket(wsloc);
|
|
|
|
socket.addEventListener("open", (event) => {
|
|
|
|
connected = true;
|
|
|
|
console.log("Socket connected!");
|
|
|
|
status.innerHTML = "Online";
|
|
|
|
status.style = "background-color: #60f060;";
|
|
|
|
});
|
|
|
|
socket.addEventListener("message", (event) => {
|
|
|
|
const data = JSON.parse(event.data);
|
|
|
|
volts.innerHTML = data.Volts;
|
|
|
|
mbar.innerHTML = data.Mbar;
|
2024-09-27 21:49:24 +00:00
|
|
|
failsafe.innerHTML = data.failsafe ? "ON" : "OFF";
|
|
|
|
if data.failsafe {
|
|
|
|
failsafe.innerHTML = "ON"";
|
|
|
|
failsafe.style = "background-color: #f06060";
|
|
|
|
} else {
|
|
|
|
failsafe.innerHTML = "OFF";
|
|
|
|
failsafe.style = "background-color: #60f060";
|
|
|
|
}
|
|
|
|
if data.highpressure {
|
|
|
|
highpressure.innerHTML = "ON";
|
|
|
|
highpressure.style = "background-color: #f06060";
|
|
|
|
} else {
|
|
|
|
highpressure.innerHTML = "OFF";
|
|
|
|
highpressure.style = "background-color: #60f060";
|
|
|
|
}
|
2024-09-25 21:28:57 +00:00
|
|
|
rp.innerHTML = data.RPOn ? "ON" : "OFF";
|
|
|
|
if (data.RPOn) {
|
|
|
|
rp.style = "background-color: #60f060";
|
|
|
|
} else {
|
|
|
|
rp.style = "background-color: #f06060";
|
|
|
|
}
|
|
|
|
dp.innerHTML = data.DPOn ? "ON" : "OFF";
|
|
|
|
if (data.DPOn) {
|
|
|
|
dp.style = "background-color: #60f060";
|
|
|
|
} else {
|
|
|
|
dp.style = "background-color: #f06060";
|
|
|
|
}
|
2024-09-27 00:11:04 +00:00
|
|
|
|
|
|
|
let t = [];
|
|
|
|
if (data.RoughReached) {
|
|
|
|
trough.innerHTML = "OK";
|
|
|
|
trough.style = "background-color: #60f060";
|
|
|
|
} else {
|
|
|
|
trough.innerHTML = "NOK";
|
|
|
|
trough.style = "background-color: #f06060";
|
|
|
|
}
|
|
|
|
if (data.HighReached) {
|
|
|
|
thigh.innerHTML = "OK";
|
|
|
|
thigh.style = "background-color: #60f060";
|
|
|
|
} else {
|
|
|
|
thigh.innerHTML = "NOK";
|
|
|
|
thigh.style = "background-color: #f06060";
|
|
|
|
}
|
2024-09-12 01:02:57 +00:00
|
|
|
historicalPush(data.MbarFloat);
|
2024-09-27 00:31:38 +00:00
|
|
|
ping.innerHTML = Date.now();
|
|
|
|
});
|
|
|
|
socket.addEventListener("close", (event) => {
|
|
|
|
status.innerHTML = "Offline";
|
|
|
|
status.style = "background-color: #f06060;";
|
|
|
|
if (connected) {
|
|
|
|
console.log("Socket dead, reconnecting...");
|
|
|
|
}
|
|
|
|
connected = false;
|
|
|
|
setTimeout(connect, 1000);
|
|
|
|
});
|
|
|
|
socket.addEventListener("error", (event) => {
|
|
|
|
socket.close();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
connect();
|
2024-09-25 21:28:57 +00:00
|
|
|
|
|
|
|
pd.addEventListener("click", async (event) => {
|
|
|
|
await fetch("/button/pumpdown");
|
|
|
|
});
|
|
|
|
vent.addEventListener("click", async (event) => {
|
|
|
|
await fetch("/button/vent");
|
|
|
|
});
|
|
|
|
rpon.addEventListener("click", async (event) => {
|
|
|
|
await fetch("/rp/on");
|
|
|
|
});
|
|
|
|
rpoff.addEventListener("click", async (event) => {
|
|
|
|
await fetch("/rp/off");
|
|
|
|
});
|
|
|
|
dpon.addEventListener("click", async (event) => {
|
|
|
|
await fetch("/dp/on");
|
|
|
|
});
|
|
|
|
dpoff.addEventListener("click", async (event) => {
|
|
|
|
await fetch("/dp/off");
|
|
|
|
});
|
2024-09-12 01:02:57 +00:00
|
|
|
});
|
2024-09-27 00:31:38 +00:00
|
|
|
</script>
|