Normalize primary communication around UART
This commit is contained in:
+8
-8
@@ -96,16 +96,16 @@ def comms():
|
||||
return jsonify(pico.get_comms())
|
||||
|
||||
|
||||
@app.route("/comms/rs485/disconnect", methods=["POST"])
|
||||
def disconnect_rs485():
|
||||
pico.disconnect_rs485()
|
||||
return jsonify({"success": True, "rs485_connected": False})
|
||||
@app.route("/comms/uart/disconnect", methods=["POST"])
|
||||
def disconnect_uart():
|
||||
pico.disconnect_uart()
|
||||
return jsonify({"success": True, "uart_connected": False})
|
||||
|
||||
|
||||
@app.route("/comms/rs485/restore", methods=["POST"])
|
||||
def restore_rs485():
|
||||
pico.restore_rs485()
|
||||
return jsonify({"success": True, "rs485_connected": True})
|
||||
@app.route("/comms/uart/restore", methods=["POST"])
|
||||
def restore_uart():
|
||||
pico.restore_uart()
|
||||
return jsonify({"success": True, "uart_connected": True})
|
||||
|
||||
|
||||
@app.route("/comms/latency", methods=["POST"])
|
||||
|
||||
@@ -198,7 +198,7 @@ class ESP32Simulator:
|
||||
"network": {
|
||||
"wifi_enabled": starlink_on or wifi_override_active,
|
||||
"wifi_override_active": wifi_override_active,
|
||||
"rs485_connected": True,
|
||||
"uart_connected": True,
|
||||
"starlink_enabled": starlink_on
|
||||
},
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ from protocol import (
|
||||
toggle_ignition_request,
|
||||
toggle_sensor_fault_request,
|
||||
)
|
||||
from transport import RS485Transport
|
||||
from transport import UARTTransport
|
||||
|
||||
|
||||
class PicoSimulator:
|
||||
def __init__(self, controller):
|
||||
self.transport = RS485Transport(controller)
|
||||
self.transport = UARTTransport(controller)
|
||||
self.last_status = None
|
||||
self.primary_link = "rs485"
|
||||
self.primary_link = "uart"
|
||||
self.backup_link_available = True
|
||||
self.messages_sent = 0
|
||||
self.messages_received = 0
|
||||
@@ -40,7 +40,7 @@ class PicoSimulator:
|
||||
|
||||
if response.get("type") == "error":
|
||||
if self.last_status:
|
||||
self.last_status["network"]["rs485_connected"] = False
|
||||
self.last_status["network"]["uart_connected"] = False
|
||||
self.last_status["network"]["communication_lost"] = True
|
||||
self.add_comms_to_status(self.last_status)
|
||||
return self.last_status
|
||||
@@ -53,7 +53,7 @@ class PicoSimulator:
|
||||
"sensor_health": {},
|
||||
"relays": {},
|
||||
"network": {
|
||||
"rs485_connected": False,
|
||||
"uart_connected": False,
|
||||
"communication_lost": True,
|
||||
"wifi_enabled": False,
|
||||
"wifi_override_active": False,
|
||||
@@ -63,7 +63,7 @@ class PicoSimulator:
|
||||
}
|
||||
|
||||
self.last_status = response["data"]
|
||||
self.last_status["network"]["rs485_connected"] = self.transport.connected
|
||||
self.last_status["network"]["uart_connected"] = self.transport.connected
|
||||
self.last_status["network"]["communication_lost"] = False
|
||||
self.add_comms_to_status(self.last_status)
|
||||
return self.last_status
|
||||
@@ -87,10 +87,10 @@ class PicoSimulator:
|
||||
def toggle_sensor_fault(self, sensor):
|
||||
return self.send_message(toggle_sensor_fault_request(sensor))
|
||||
|
||||
def disconnect_rs485(self):
|
||||
def disconnect_uart(self):
|
||||
self.transport.disconnect()
|
||||
|
||||
def restore_rs485(self):
|
||||
def restore_uart(self):
|
||||
self.transport.restore()
|
||||
|
||||
def set_latency(self, latency_ms):
|
||||
@@ -103,7 +103,7 @@ class PicoSimulator:
|
||||
return {
|
||||
"primary": self.primary_link,
|
||||
"backup_available": self.backup_link_available,
|
||||
"rs485_connected": self.transport.connected,
|
||||
"uart_connected": self.transport.connected,
|
||||
"messages_sent": self.messages_sent,
|
||||
"messages_received": self.messages_received,
|
||||
"last_message_time": self.last_message_time,
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<main>
|
||||
<header>
|
||||
<h1>Xterra Dashboard</h1>
|
||||
<div id="statusLine">RS-485: -- | WiFi: --</div>
|
||||
<div id="statusLine">UART: -- | WiFi: --</div>
|
||||
</header>
|
||||
|
||||
<section id="dashboard" class="screen active">
|
||||
@@ -82,7 +82,7 @@
|
||||
<section id="system" class="screen">
|
||||
<h2>System</h2>
|
||||
<div class="detail-list">
|
||||
<div>RS-485 <strong id="sysRs485">--</strong></div>
|
||||
<div>UART <strong id="sysUart">--</strong></div>
|
||||
<div>WiFi <strong id="sysWifi">--</strong></div>
|
||||
<div>WiFi Override <strong id="sysWifiOverride">--</strong></div>
|
||||
<div>Ignition <strong id="sysIgnition">--</strong></div>
|
||||
@@ -101,8 +101,8 @@
|
||||
<div>Packet Loss <strong id="commsPacketLoss">--</strong></div>
|
||||
</div>
|
||||
|
||||
<button onclick="disconnectRs485()">Disconnect RS-485</button>
|
||||
<button onclick="restoreRs485()">Restore RS-485</button>
|
||||
<button onclick="disconnectUart()">Disconnect UART</button>
|
||||
<button onclick="restoreUart()">Restore UART</button>
|
||||
|
||||
<div class="settings-list">
|
||||
<label>
|
||||
@@ -235,7 +235,7 @@ function checkAlarms(data) {
|
||||
const warnings = [];
|
||||
|
||||
if (data.network.communication_lost) {
|
||||
warnings.push('Communication lost: RS-485 disconnected');
|
||||
warnings.push('Communication lost: UART disconnected');
|
||||
}
|
||||
|
||||
for (const [name, healthy] of Object.entries(data.sensor_health || {})) {
|
||||
@@ -347,7 +347,7 @@ async function loadStatus() {
|
||||
relayState = data.relays;
|
||||
|
||||
document.getElementById('statusLine').textContent =
|
||||
`RS-485: ${data.network.rs485_connected ? 'Connected' : 'Lost'} | WiFi: ${data.network.wifi_enabled ? 'Enabled' : 'Disabled'}`;
|
||||
`UART: ${data.network.uart_connected ? 'Connected' : 'Lost'} | WiFi: ${data.network.wifi_enabled ? 'Enabled' : 'Disabled'}`;
|
||||
|
||||
if (data.network.communication_lost) {
|
||||
document.body.classList.add('comms-lost');
|
||||
@@ -393,12 +393,12 @@ async function loadStatus() {
|
||||
document.getElementById('starlinkBtn').textContent = `Starlink: ${onOff(data.relays.starlink)}`;
|
||||
document.getElementById('fridgeBtn').textContent = `Fridge: ${onOff(data.relays.fridge)}`;
|
||||
|
||||
document.getElementById('sysRs485').textContent = data.network.rs485_connected ? 'Connected' : 'Disconnected';
|
||||
document.getElementById('sysUart').textContent = data.network.uart_connected ? 'Connected' : 'Disconnected';
|
||||
document.getElementById('sysWifi').textContent = data.network.wifi_enabled ? 'Enabled' : 'Disabled';
|
||||
document.getElementById('sysWifiOverride').textContent = data.network.wifi_override_active ? 'Active' : 'Inactive';
|
||||
document.getElementById('sysIgnition').textContent = data.vehicle?.ignition_on ? 'ON' : 'OFF';
|
||||
|
||||
document.getElementById('commsPrimary').textContent = data.network.rs485_connected ? 'RS-485' : 'RS-485 LOST';
|
||||
document.getElementById('commsPrimary').textContent = data.network.uart_connected ? 'UART' : 'UART LOST';
|
||||
document.getElementById('commsBackup').textContent = 'WiFi';
|
||||
document.getElementById('commsSent').textContent = data.network.messages_sent ?? '--';
|
||||
document.getElementById('commsReceived').textContent = data.network.messages_received ?? '--';
|
||||
@@ -466,8 +466,8 @@ async function toggleIgnition() {
|
||||
loadStatus();
|
||||
}
|
||||
|
||||
async function disconnectRs485() {
|
||||
await fetch('/comms/rs485/disconnect', {
|
||||
async function disconnectUart() {
|
||||
await fetch('/comms/uart/disconnect', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({})
|
||||
@@ -476,8 +476,8 @@ async function disconnectRs485() {
|
||||
loadStatus();
|
||||
}
|
||||
|
||||
async function restoreRs485() {
|
||||
await fetch('/comms/rs485/restore', {
|
||||
async function restoreUart() {
|
||||
await fetch('/comms/uart/restore', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({})
|
||||
|
||||
@@ -2,7 +2,7 @@ import random
|
||||
import time
|
||||
|
||||
|
||||
class RS485Transport:
|
||||
class UARTTransport:
|
||||
def __init__(self, controller):
|
||||
self.controller = controller
|
||||
self.connected = True
|
||||
@@ -14,7 +14,7 @@ class RS485Transport:
|
||||
return {
|
||||
"type": "error",
|
||||
"success": False,
|
||||
"error": "RS-485 disconnected"
|
||||
"error": "UART disconnected"
|
||||
}
|
||||
|
||||
if self.latency_ms > 0:
|
||||
@@ -25,7 +25,7 @@ class RS485Transport:
|
||||
return {
|
||||
"type": "error",
|
||||
"success": False,
|
||||
"error": "RS-485 packet lost"
|
||||
"error": "UART packet lost"
|
||||
}
|
||||
|
||||
return self.controller.handle_message(message)
|
||||
|
||||
Reference in New Issue
Block a user