Add RS485 transport simulation layer
This commit is contained in:
@@ -97,11 +97,27 @@
|
||||
<div>Messages Sent <strong id="commsSent">--</strong></div>
|
||||
<div>Messages Received <strong id="commsReceived">--</strong></div>
|
||||
<div>Last Message <strong id="commsLast">--</strong></div>
|
||||
<div>Latency <strong id="commsLatency">--</strong></div>
|
||||
<div>Packet Loss <strong id="commsPacketLoss">--</strong></div>
|
||||
</div>
|
||||
|
||||
<button onclick="disconnectRs485()">Disconnect RS-485</button>
|
||||
<button onclick="restoreRs485()">Restore RS-485</button>
|
||||
|
||||
<div class="settings-list">
|
||||
<label>
|
||||
Simulated Latency ms
|
||||
<input id="latencyInput" type="number" value="0">
|
||||
</label>
|
||||
|
||||
<label>
|
||||
Packet Loss %
|
||||
<input id="packetLossInput" type="number" value="0">
|
||||
</label>
|
||||
|
||||
<button onclick="saveCommsSimulation()">Save Comms Simulation</button>
|
||||
</div>
|
||||
|
||||
<h2>Sensor Fault Simulation</h2>
|
||||
<div class="settings-list">
|
||||
<button onclick="toggleSensorFault('fridge_zone_1')">Toggle Fridge Zone 1 Fault</button>
|
||||
@@ -389,6 +405,14 @@ async function loadStatus() {
|
||||
document.getElementById('commsLast').textContent = data.network.last_message_time
|
||||
? new Date(data.network.last_message_time * 1000).toLocaleTimeString()
|
||||
: '--';
|
||||
document.getElementById('commsLatency').textContent =
|
||||
data.network.latency_ms !== null && data.network.latency_ms !== undefined
|
||||
? `${data.network.latency_ms} ms`
|
||||
: '--';
|
||||
document.getElementById('commsPacketLoss').textContent =
|
||||
data.network.packet_loss_percent !== undefined
|
||||
? `${data.network.packet_loss_percent}%`
|
||||
: '--';
|
||||
|
||||
updateSleepOverlay(data.vehicle?.ignition_on ?? true);
|
||||
|
||||
@@ -462,6 +486,25 @@ async function restoreRs485() {
|
||||
loadStatus();
|
||||
}
|
||||
|
||||
async function saveCommsSimulation() {
|
||||
const latency = Number(document.getElementById('latencyInput').value);
|
||||
const packetLoss = Number(document.getElementById('packetLossInput').value);
|
||||
|
||||
await fetch('/comms/latency', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({latency_ms: latency})
|
||||
});
|
||||
|
||||
await fetch('/comms/packet-loss', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({percent: packetLoss})
|
||||
});
|
||||
|
||||
loadStatus();
|
||||
}
|
||||
|
||||
async function toggleSensorFault(name) {
|
||||
await fetch(`/sensor/${name}/fault`, {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user