From 3abfe7976b80ed73ec14d3d249fb3ef3bac6fc68 Mon Sep 17 00:00:00 2001 From: Kirubakaran Date: Mon, 3 Nov 2025 05:18:55 +0530 Subject: [PATCH] feat: updated SDC decoding according to new proto --- backend/__pycache__/models.cpython-313.pyc | Bin 3832 -> 3839 bytes .../core/__pycache__/__init__.cpython-313.pyc | Bin 178 -> 185 bytes .../__pycache__/mqtt_client.cpython-313.pyc | Bin 6041 -> 6048 bytes .../protobuf_decoder.cpython-313.pyc | Bin 6595 -> 6602 bytes backend/main.py | 6 +- .../__pycache__/__init__.cpython-313.pyc | Bin 179 -> 186 bytes .../vec_payload_chgSt_pb2.cpython-313.pyc | Bin 6138 -> 6145 bytes frontend/dashboard.html | 27 +-- frontend/js/analytics.js | 4 +- frontend/js/auth.js | 2 +- frontend/js/common-header.js | 4 +- frontend/js/dashboard.js | 170 +++++++++++++++--- frontend/js/logs.js | 4 +- frontend/js/station_selection.js | 2 +- frontend/station_selection.html | 2 +- 15 files changed, 169 insertions(+), 52 deletions(-) diff --git a/backend/__pycache__/models.cpython-313.pyc b/backend/__pycache__/models.cpython-313.pyc index 4825daaf2ccab0d9c350f33d54958665d9aa7afa..38b37e55abc5e05990793a23a350c06f102ef07c 100644 GIT binary patch delta 46 zcmew%`(Kv(GcPX}0}#yCytI)!idi7g*(xTqIJKxa#yhj9G%0a%6|?N-ZsuHW09y(U A?*IS* delta 62 zcmew_`$LxdGcPX}0}#k;I=+!Ridn_W*(xTqIJKxa#yhj9G$}DVu_!Sw#wE2lyClCL QCM-2MH$Qpv1m=8h0FNXU(EtDd diff --git a/backend/core/__pycache__/__init__.cpython-313.pyc b/backend/core/__pycache__/__init__.cpython-313.pyc index 45a9ccac455279abe28182d91bc42420a8c9daf1..c037489994f8a7092cc445ab672be450d3a2f242 100644 GIT binary patch delta 66 zcmdnQxRa6lGcPX}0}wpdUNw>1SUbYmDkiizwWv78JF}=XDKW++wK%&ZzaSHX;R|kLRQ($O|0TV08l3m Af&c&j delta 51 zcmZ3WKU1IkGcPX}0}#YtKev%PkX1Cq*(xTqIJKxa#yhj9G$}DVu_!Tbat^EP=BcdQ FLI9v_5Ox3n diff --git a/backend/core/__pycache__/protobuf_decoder.cpython-313.pyc b/backend/core/__pycache__/protobuf_decoder.cpython-313.pyc index 1f52f62a83371a58259f6902999694e117d3ac6b..256f0bdcda0f1c398743761d0ca70e93e1fd6cbd 100644 GIT binary patch delta 46 zcmX?Xe9D;nGcPX}0}z}vT(yx~n?)eO*(xTqIJKxa#yhj9G%0biH;e4%7?yNV08CI0 ANB{r; delta 62 zcmX?QeAt-#GcPX}0}#k;I=+!xn?)tk*(xTqIJKxa#yhj9G$}DVu_!Sw#wE2lyClCL QCM-2MH$QoEB1@(y0D1KlN&o-= 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 2b269ac4005615fe422af8fb0a16f5a171c8e839..1d85a3af675dd9d044173f6fd73ba282d1fa074a 100644 GIT binary patch delta 66 zcmdnYxQmhdGcPX}0}wpdUNw>1SUb|$DkiizwWv78JF}=XDKW++wK%&ZzaS @@ -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 @@