diff --git a/backend/__pycache__/models.cpython-313.pyc b/backend/__pycache__/models.cpython-313.pyc index 4825daa..38b37e5 100644 Binary files a/backend/__pycache__/models.cpython-313.pyc and b/backend/__pycache__/models.cpython-313.pyc differ diff --git a/backend/core/__pycache__/__init__.cpython-313.pyc b/backend/core/__pycache__/__init__.cpython-313.pyc index 45a9cca..c037489 100644 Binary files a/backend/core/__pycache__/__init__.cpython-313.pyc and b/backend/core/__pycache__/__init__.cpython-313.pyc differ diff --git a/backend/core/__pycache__/mqtt_client.cpython-313.pyc b/backend/core/__pycache__/mqtt_client.cpython-313.pyc index abf65da..92291de 100644 Binary files a/backend/core/__pycache__/mqtt_client.cpython-313.pyc and b/backend/core/__pycache__/mqtt_client.cpython-313.pyc differ diff --git a/backend/core/__pycache__/protobuf_decoder.cpython-313.pyc b/backend/core/__pycache__/protobuf_decoder.cpython-313.pyc index 1f52f62..256f0bd 100644 Binary files a/backend/core/__pycache__/protobuf_decoder.cpython-313.pyc and b/backend/core/__pycache__/protobuf_decoder.cpython-313.pyc differ diff --git a/backend/main.py b/backend/main.py index 3fac265..825d480 100644 --- a/backend/main.py +++ b/backend/main.py @@ -39,7 +39,7 @@ app = Flask(__name__) # CORS(app, resources={r"/api/*": {"origins": "http://127.0.0.1:5500"}}, supports_credentials=True, expose_headers='Content-Disposition') -CORS(app, resources={r"/api/*": {"origins": ["http://10.10.2.47:5501","http://127.0.0.1:5501"]}}, supports_credentials=True, expose_headers='Content-Disposition') +CORS(app, resources={r"/api/*": {"origins": ["http://172.20.10.4:5500","http://127.0.0.1:5500"]}}, supports_credentials=True, expose_headers='Content-Disposition') # CORS(app, resources={r"/api/*": {"origins": "http://localhost:5173"}}) , "http://127.0.0.1:5500" # This tells Flask: "For any route starting with /api/, allow requests @@ -953,5 +953,5 @@ if __name__ == '__main__': mqtt_thread = threading.Thread(target=start_mqtt_clients, daemon=True) mqtt_thread.start() - print(f"Starting Flask-SocketIO server on http://10.10.2.47:5000") - socketio.run(app, host='10.10.2.47', port=5000) + print(f"Starting Flask-SocketIO server on http://172.20.10.4:5000") + socketio.run(app, host='172.20.10.4', port=5000) diff --git a/backend/proto/__pycache__/__init__.cpython-313.pyc b/backend/proto/__pycache__/__init__.cpython-313.pyc index 2b269ac..1d85a3a 100644 Binary files a/backend/proto/__pycache__/__init__.cpython-313.pyc and b/backend/proto/__pycache__/__init__.cpython-313.pyc differ diff --git a/backend/proto/__pycache__/vec_payload_chgSt_pb2.cpython-313.pyc b/backend/proto/__pycache__/vec_payload_chgSt_pb2.cpython-313.pyc index ccff2e0..d80a5a2 100644 Binary files a/backend/proto/__pycache__/vec_payload_chgSt_pb2.cpython-313.pyc and b/backend/proto/__pycache__/vec_payload_chgSt_pb2.cpython-313.pyc differ diff --git a/frontend/dashboard.html b/frontend/dashboard.html index 10877e1..f639d81 100644 --- a/frontend/dashboard.html +++ b/frontend/dashboard.html @@ -150,6 +150,13 @@ .bat-id-big{font-size:14px;font-weight:800;border-radius:.5rem;padding:.2rem .4rem; background:rgba(0,0,0,.25);border:1px solid rgba(255,255,255,.10)} + + #diag-flags-grid{ + display:grid; + grid-template-columns: 80px 1fr; /* label col = 88px; adjust to taste */ + column-gap: 0.5rem; /* ~8px gap between columns */ + row-gap: 0.1; /* vertical spacing */ + } @@ -161,7 +168,7 @@
-
+
-
- System Diagnostics Code - + STATION DIAGNOSTIC CODE (SDC) +
+ +
-
-
Lock Power Cut
Main Power Cut
-
Relayboard CAN
DB CAN Recv
-
MB Can Recv
Smoke Alarm
-
Water Alarm
Phase Failure
-
Earth Leakage
+ +
- +
diff --git a/frontend/js/analytics.js b/frontend/js/analytics.js index 94f8267..c23dc05 100644 --- a/frontend/js/analytics.js +++ b/frontend/js/analytics.js @@ -1,7 +1,7 @@ document.addEventListener('DOMContentLoaded', () => { // --- CONFIGURATION --- - const SOCKET_URL = "http://10.10.2.47:5000"; - const API_BASE = "http://10.10.2.47:5000/api"; + const SOCKET_URL = "http://172.20.10.4:5000"; + const API_BASE = "http://172.20.10.4:5000/api"; // --- DOM ELEMENT REFERENCES --- const stationNameEl = document.getElementById('station-name'); diff --git a/frontend/js/auth.js b/frontend/js/auth.js index aab6210..e2fb22a 100644 --- a/frontend/js/auth.js +++ b/frontend/js/auth.js @@ -11,7 +11,7 @@ document.addEventListener('DOMContentLoaded', () => { const password = document.getElementById('password').value; try { - const response = await fetch('http://10.10.2.47:5000/api/login', { + const response = await fetch('http://172.20.10.4:5000/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }), diff --git a/frontend/js/common-header.js b/frontend/js/common-header.js index 4a1cc5b..a160167 100644 --- a/frontend/js/common-header.js +++ b/frontend/js/common-header.js @@ -1,8 +1,8 @@ // frontend/js/common-header.js document.addEventListener('DOMContentLoaded', () => { // --- CONFIGURATION --- - const SOCKET_URL = "http://10.10.2.47:5000"; - const API_BASE = "http://10.10.2.47:5000/api"; + const SOCKET_URL = "http://172.20.10.4:5000"; + const API_BASE = "http://172.20.10.4:5000/api"; // --- STATE & SELECTED STATION --- let selectedStation = null; diff --git a/frontend/js/dashboard.js b/frontend/js/dashboard.js index a99bc05..238bc2b 100644 --- a/frontend/js/dashboard.js +++ b/frontend/js/dashboard.js @@ -1,7 +1,7 @@ document.addEventListener('DOMContentLoaded', () => { // --- CONFIGURATION --- - const SOCKET_URL = "http://10.10.2.47:5000"; - const API_BASE = "http://10.10.2.47:5000/api"; // Added for API calls + const SOCKET_URL = "http://172.20.10.4:5000"; + const API_BASE = "http://172.20.10.4:5000/api"; // Added for API calls // --- DOM ELEMENT REFERENCES --- const grid = document.getElementById('chambersGrid'); @@ -13,7 +13,10 @@ document.addEventListener('DOMContentLoaded', () => { const deviceIdEl = document.getElementById('device-id'); const productIdEl = document.getElementById('product-id'); const lastUpdateEl = document.getElementById('last-update-status'); - const stationDiagCodeEl = document.getElementById('station-diag-code'); + + const stationDiagCodeEl = document.getElementById('station-diag-code-raw'); // CHANGED ID: Use new raw code display ID + const sdcVisualFlagsEl = document.getElementById('sdc-visual-flags'); + const backupPowerChip = document.getElementById('backup-power-chip'); const diagFlagsGrid = document.getElementById('diag-flags-grid'); const audioSelect = document.getElementById('audio-command-select'); @@ -30,12 +33,23 @@ document.addEventListener('DOMContentLoaded', () => { let chamberData = Array(9).fill({ batteryPresent: false }); // The list of errors from your Python code - const DIAGNOSTIC_ERRORS = [ - "Lock Power Cut", "Main Power Cut", - "Relayboard CAN", "DB CAN Recv", - "MB Can Recv", "Smoke Alarm", - "Water Alarm", "Phase Failure", - "Earth Leakage" + // const DIAGNOSTIC_ERRORS = [ + // "Lock Power Cut", "Main Power Cut", + // "Relayboard CAN", "DB CAN Recv", + // "MB Can Recv", "Smoke Alarm", + // "Water Alarm", "Phase Failure", + // "Earth Leakage" + // ]; + + const ALARM_GROUPS = [ + { name: "EarthLk", start_bit: 20, count: 11 }, + { name: "DBCF", start_bit: 5, count: 9 }, + { name: "RBCF", start_bit: 14, count: 3 }, + { name: "PF", start_bit: 17, count: 3 }, + { name: "SMPS", start_bit: 0, count: 2 }, + { name: "MBCF", start_bit: 4, count: 1 }, + { name: "Smoke Alarm", start_bit: 2, count: 1 }, + { name: "Water Level", start_bit: 3, count: 1 }, ]; const BATTERY_FAULT_MAP = { @@ -129,6 +143,58 @@ document.addEventListener('DOMContentLoaded', () => { updateSwapUI(); } +// asdfghjkjhgfdsdfghjkjhgfdfghghjkjhgfdsdfghjkjhgfdsdfghjkjhgfdsdfghjkjhgfdsdfghjkjhgfdsdfghjkjhgfdsdfghjkjhgf + function toHex8(n){ return "0x" + (Number(n>>>0).toString(16).toUpperCase().padStart(8,"0")); } + function sliceGroupBits(sdc, start, count){ return (sdc >>> start) & ((1<> bitToCheck) & 1) === 1; + } + + /* Renders quick chips row: PF/DBCF/etc lit if any bit in that group is 1 */ + function renderSdcChips(container, sdc){ + if(!container) return; + container.innerHTML = ""; + ALARM_GROUPS.forEach(g=>{ + const anyOn = sliceGroupBits(sdc, g.start_bit, g.count) !== 0; + const el = document.createElement("span"); + el.className = "chip " + (anyOn ? "chip-emerald" : "chip-slate"); + el.textContent = g.name; + el.title = anyOn ? "Some bits set" : "All clear"; + container.appendChild(el); + }); + } + + /* Renders the detailed dots grid; leftmost dot = highest bit */ + function renderSdcGrid(container, sdc){ + if(!container) return; + container.innerHTML = ""; + ALARM_GROUPS.forEach(g=>{ + const label = document.createElement("div"); + label.className = "text-xs text-slate-300 font-medium py-1"; + label.textContent = g.name; + container.appendChild(label); + + const row = document.createElement("div"); + row.className = "flex flex-wrap gap-1 py-1"; + const mask = sliceGroupBits(sdc, g.start_bit, g.count); + + for(let i=0;i { }; + // --- NEW: Function to decode the SDC and create visual pill elements --- + /** + * Decodes the SDC and creates visual pill elements for active faults. + * @param {number} sdcCode The station diagnostic code as an integer. + */ + // const updateSdcVisuals = (sdcCode) => { + // if (!sdcVisualFlagsEl) return; + // sdcVisualFlagsEl.innerHTML = ''; // Clear previous flags + + // let hasActiveFault = false; + + // for (const bitIndex in SDC_FLAGS) { + // const bit = parseInt(bitIndex, 10); + // if ((sdcCode & (1 << bit)) !== 0) { + // hasActiveFault = true; + // const flag = SDC_FLAGS[bitIndex]; + // const pill = document.createElement('div'); + // // Tailwind class for the pill look (using your defined style) + // pill.className = `flex items-center gap-1.5 text-xs font-medium rounded-full px-3 py-1 ${flag.style}`; + // // Use Lucide icon from the map + // pill.innerHTML = ` ${flag.name}`; + // sdcVisualFlagsEl.appendChild(pill); + // } + // } + + // // If no active faults, display a healthy message + // if (!hasActiveFault) { + // sdcVisualFlagsEl.innerHTML = ' System OK'; + // } + // // Re-run Lucide to render the newly added icons (like check-circle) + // lucide.createIcons(); + // }; + + const updateChamberUI = (card, slot) => { if (!card || !slot) return; @@ -264,26 +364,37 @@ document.addEventListener('DOMContentLoaded', () => { }; // --- NEW: Function to decode the SDC and update the UI --- - const updateDiagnosticsUI = (sdcCode) => { - if (!diagFlagsGrid) return; - diagFlagsGrid.innerHTML = ''; // Clear previous statuses + // const updateDiagnosticsUI = (sdcCode) => { + // if (!diagFlagsGrid) return; + // diagFlagsGrid.innerHTML = ''; // Clear previous statuses - DIAGNOSTIC_ERRORS.forEach((errorText, index) => { - // Use bitwise AND to check if the bit at this index is set - const isActive = (sdcCode & (1 << index)) !== 0; + // DIAGNOSTIC_ERRORS.forEach((errorText, index) => { + // // Use bitwise AND to check if the bit at this index is set + // const isActive = (sdcCode & (1 << index)) !== 0; - const div = document.createElement('div'); - div.textContent = errorText; + // const div = document.createElement('div'); + // div.textContent = errorText; - // Apply different styles based on whether the alarm is active - if (isActive) { - div.className = 'text-rose-300 text-center font-semibold'; - } else { - div.className = 'text-slate-500 text-center'; - } - diagFlagsGrid.appendChild(div); - }); - }; + // // Apply different styles based on whether the alarm is active + // if (isActive) { + // div.className = 'text-rose-300 text-center font-semibold'; + // } else { + // div.className = 'text-slate-500 text-center'; + // } + // diagFlagsGrid.appendChild(div); + // }); + // }; + function updateDiagnosticAlarms(sdcValue){ + const sdc = Number(sdcValue); + const hexEl = document.getElementById("station-diag-code-raw"); // hex display + const chipsEl = document.getElementById("sdc-visual-flags"); // quick flags row + const gridEl = document.getElementById("diag-flags-grid"); // dots grid + + if (hexEl) hexEl.textContent = toHex8(sdc); + renderSdcChips(chipsEl, sdc); + renderSdcGrid(gridEl, sdc); + } + const checkStationStatus = async () => { @@ -326,6 +437,7 @@ document.addEventListener('DOMContentLoaded', () => { card.querySelector('.filled-state').style.display = 'none'; card.querySelector('.empty-state').style.display = 'flex'; }); + updateDiagnosticAlarms(0); logToInstance("Station is offline. Clearing stale data.", "error"); }; @@ -500,9 +612,9 @@ document.addEventListener('DOMContentLoaded', () => { // 1. Check if the 'stationDiagnosticCode' key exists in the data. if (data.hasOwnProperty('stationDiagnosticCode')) { - const sdc = data.stationDiagnosticCode; - stationDiagCodeEl.textContent = sdc; - updateDiagnosticsUI(sdc); + const sdcRaw = data.stationDiagnosticCode; + const sdc = Number.isFinite(sdcRaw) ? Number(sdcRaw) : 0; + updateDiagnosticAlarms(sdc); } // 2. Check if the 'backupSupplyStatus' key exists. diff --git a/frontend/js/logs.js b/frontend/js/logs.js index 98b4319..84f4b2c 100644 --- a/frontend/js/logs.js +++ b/frontend/js/logs.js @@ -1,7 +1,7 @@ document.addEventListener('DOMContentLoaded', () => { // --- CONFIGURATION --- - const SOCKET_URL = "http://10.10.2.47:5000"; - const API_BASE = "http://10.10.2.47:5000/api"; + const SOCKET_URL = "http://172.20.10.4:5000"; + const API_BASE = "http://172.20.10.4:5000/api"; // --- DOM ELEMENT REFERENCES --- const stationNameEl = document.getElementById('station-name'); diff --git a/frontend/js/station_selection.js b/frontend/js/station_selection.js index 9433cd7..731f034 100644 --- a/frontend/js/station_selection.js +++ b/frontend/js/station_selection.js @@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', () => { const stationCountEl = document.getElementById('station-count'); // Make sure you have an element with this ID in your HTML // --- CONFIG & STATE --- - const API_BASE = 'http://10.10.2.47:5000/api'; + const API_BASE = 'http://172.20.10.4:5000/api'; let allStations = []; // Master list of stations from the API let pollingInterval = null; diff --git a/frontend/station_selection.html b/frontend/station_selection.html index 685c493..00e7b82 100644 --- a/frontend/station_selection.html +++ b/frontend/station_selection.html @@ -225,7 +225,7 @@