From 5a910e0705feca6431fafde7e6d4e1124c8eebfc Mon Sep 17 00:00:00 2001 From: aniketSaha Date: Fri, 11 Jul 2025 12:48:07 +0200 Subject: [PATCH] Added changes related to Pre production mode and auto switch when ready for Production- need to be tested --- classCAN.py | 28 ++- main.py | 23 ++- templates/control.html | 418 ++++++++++++++++++++--------------------- 3 files changed, 249 insertions(+), 220 deletions(-) diff --git a/classCAN.py b/classCAN.py index 6720077..1fe3438 100644 --- a/classCAN.py +++ b/classCAN.py @@ -23,8 +23,8 @@ class CANBackend: # PU mapping: PU1->0x02, PU2->0x03, PU3->0x04 node_map = { 1: 0x02, - 2: 0x03, - 3: 0x04 + 2: 0x04, + 3: 0x127 } for pu_number, node_id in node_map.items(): @@ -61,11 +61,30 @@ class CANBackend: # Poll only PU1 (node ID 0x02) for live monitor values node = self.nodes.get(1) if node: + fm1 = node.sdo[0x2004][1].raw fm2 = node.sdo[0x2004][2].raw + fm3 = node.sdo[0x2004][3].raw + fm4 = node.sdo[0x2004][4].raw + ps1 = node.sdo[0x2005][1].raw + ps2 = node.sdo[0x2005][2].raw + ps3 = node.sdo[0x2005][3].raw + ps4 = node.sdo[0x2005][4].raw + + self.latest_data["FM1"] = fm1 / 100.0 self.latest_data["FM2"] = fm2 / 100.0 + self.latest_data["FM3"] = fm3 / 100.0 + self.latest_data["FM4"] = fm4 / 100.0 + self.latest_data["PS1"] = ps1 / 1000.0 - print(f"[SDO POLL] FM2: {fm2}, PS1: {ps1}") + self.latest_data["PS2"] = ps2 / 1000.0 + self.latest_data["PS3"] = ps3 / 1000.0 + self.latest_data["PS4"] = ps4 / 1000.0 + + print(f"[SDO POLL] FM1: {fm1}, PS1: {ps1}") + print(f"[SDO POLL] FM2: {fm2}, PS2: {ps2}") + print(f"[SDO POLL] FM3: {fm3}, PS3: {ps3}") + print(f"[SDO POLL] FM4: {fm4}, PS4: {ps4}") except Exception as e: print(f"[SDO POLL ERROR] {e}") time.sleep(1.0) @@ -112,7 +131,8 @@ class CANBackend: state_map = { "IDLE": 1, - "PRODUCTION": 2, + "PRE-PRODUCTION": 2, + "PRODUCTION" : 3, "MAINTENANCE": 8, "EMERGENCY_STOP": 9, "FIRST_START": 10 diff --git a/main.py b/main.py index d5641d1..4c67f79 100644 --- a/main.py +++ b/main.py @@ -108,11 +108,28 @@ def connect_toggle(): @app.post("/command/{state}/pu/{pu_number}") def send_command(state: str, pu_number: int, ploop_setpoint: float = Query(...)): - """Send a state command to a specific PU.""" + VALID_STATES = { + "IDLE", "PRE-PRODUCTION", "PRODUCTION", "FIRST_START", + "THERMALLOOPCLEANING", "DISINFECTION", "SLEEP" + } + + state = state.upper() + + if state not in VALID_STATES: + raise HTTPException(status_code=400, detail=f"Invalid state '{state}'") + logging.info(f"Sending state '{state}' to PU {pu_number}") + try: - can_backend.send_state_command(state.upper(), pu_number, ploop_setpoint) - return {"status": "success", "command": state.upper(), "pu": pu_number, "ploop_setpoint": ploop_setpoint} + can_backend.send_state_command(state, pu_number, ploop_setpoint) + current_state = can_backend.read_current_state(pu_number) + return { + "status": "success", + "command": state, + "pu": pu_number, + "ploop_setpoint": ploop_setpoint, + "current_state": current_state + } except Exception as e: raise HTTPException(status_code=500, detail=str(e)) diff --git a/templates/control.html b/templates/control.html index 030f608..5c65a96 100644 --- a/templates/control.html +++ b/templates/control.html @@ -10,12 +10,14 @@ font-family: Arial, sans-serif; margin: 0; padding: 0; - display: flex; - flex-direction: column; + overflow-x: hidden; /* ✅ prevent horizontal scroll */ height: 100vh; background-color: #121212; color: white; + display: flex; + flex-direction: column; } + .header { background-color: #1e1e1e; padding: 10px 20px; @@ -35,13 +37,15 @@ align-items: center; gap: 10px; } - .connected { - background-color: #00C851; - } + .connected { background-color: #00C851; } .container { display: flex; flex: 1; + max-width: 100vw; + overflow-x: hidden; + box-sizing: border-box; } + .left-panel, .right-panel { flex: 1; padding: 20px; @@ -61,10 +65,7 @@ flex-direction: column; gap: 10px; } - .pu-buttons { - display: flex; - gap: 10px; - } + .pu-buttons { display: flex; gap: 10px; } .mode-block button { background-color: #4285F4; color: white; @@ -76,15 +77,14 @@ transition: background-color 0.3s; flex: 1; } - .mode-block button:hover { - background-color: #3367d6; - } - .mode-block button.active { - background-color: #00C851; - } - .pu-status { - margin-top: 20px; + .mode-block button:hover { + background-color: #3367d6; } + .mode-block button.active { background-color: #00C851; } + .mode-block button.in-progress { background-color: #ffcc00; color: #000; } + .mode-block button.ready { background-color: #00C851; color: #fff; } + .mode-block button.disabled { background-color: #777; cursor: not-allowed; } + .pu-status { margin-top: 20px; } .pu-item { background-color: #333; padding: 10px; @@ -100,12 +100,6 @@ border-radius: 5px; margin-bottom: 15px; } - .monitor-block h2 { - margin-top: 0; - display: flex; - align-items: center; - gap: 10px; - } .monitor-values { display: grid; grid-template-columns: repeat(3, 1fr); @@ -118,6 +112,48 @@ text-align: center; border-radius: 5px; } + .slider-container { + background-color: #1e1e1e; + padding: 10px; + border-radius: 10px; + color: #fff; + width: 95%; + } + .slider-container label { + font-size: 1.2rem; + font-weight: bold; + margin-bottom: 10px; + display: block; + } + .slider-values { + display: flex; + justify-content: space-between; + font-size: 1rem; + margin-bottom: 8px; + width: 100%; + overflow: hidden; + } + + .slider-values span#currentValue { + font-weight: bold; + color: #00bfff; + } + .slider { + width: 100%; + height: 8px; + border-radius: 5px; + background: #444; + outline: none; + appearance: none; + cursor: pointer; + } + .slider::-webkit-slider-thumb, .slider::-moz-range-thumb { + height: 18px; + width: 18px; + background: #007bff; + border-radius: 50%; + cursor: pointer; + } .monitor-link { color: white; background-color: #007bff; @@ -125,216 +161,173 @@ border-radius: 5px; text-decoration: none; font-weight: bold; - transition: background-color 0.3s; - } - -.monitor-link:hover { - background-color: #0056b3; -} - - .slider-container { - margin-top: 10px; - } - .slider-container label { - display: block; - margin-bottom: 5px; - } - .slider-container input { - width: 100%; } + .monitor-link:hover { background-color: #0056b3; } -
-

Hydraulic Machine Control

- - Monitor - - -
-
-
-
-
- - - -
-
-
-
- - - -
-
-
-
- - - -
-
-
- -
- 0.5 - 1.0 - 3.5 -
- -
- - -
- -
-
-
- PU 1: Offline -
-
- PU 2: Offline -
-
- PU 3: Offline -
+
+

Hydraulic Machine Control

+ + Monitor + + +
+
+
+
+
+ + +
-
-
-

Q Perm

-
-
#1
0.0 L/h
-
#2
0.0 L/h
-
#3
0.0 L/h
-
+
+
+ + +
-
-

P Dilute

-
-
#1
0.0 bar
-
#2
0.0 bar
-
#3
0.0 bar
-
+
+
+
+ + +
-
-

Conductivity

-
-
#1
0.0 µS/cm
-
#2
0.0 µS/cm
-
#3
0.0 µS/cm
-
+
+
+ +
+ 0.5 + 1.0 + 3.5
-
-

Pro

-
-
#1
0.0 units
-
#2
0.0 units
-
#3
0.0 units
-
+ +
+
+ +
+
+
PU 1: Offline
+
PU 2: Offline
+
PU 3: Offline
+
+
+
+
+

Q Perm

+
+
#1
0.0 L/h
+
#2
0.0 L/h
+
#3
0.0 L/h
+
+
+
+

P Dilute

+
+
#1
0.0 bar
+
#2
0.0 bar
+
#3
0.0 bar
+
+
+
+

Conductivity

+
+
#1
0.0 µS/cm
+
#2
0.0 µS/cm
+
#3
0.0 µS/cm
+
+
+
+

Pro

+
+
#1
0.0 units
+
#2
0.0 units
+
#3
0.0 units
+
- - - +