From 0287dd2008bd9ba06c45d06a1c5fd7584202d22a Mon Sep 17 00:00:00 2001 From: Cyril Danilevski <cyril.danilevski@xfel.eu> Date: Thu, 13 Feb 2025 14:38:17 +0100 Subject: [PATCH] Add ramp status to panel and idn endpoints --- icbm.ino | 2 ++ mpod.cpp | 2 +- panel.hpp | 17 ++++++++++++++--- pins.hpp | 2 ++ powerproc.hpp | 2 ++ rest.cpp | 16 ++++++++++++++-- 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/icbm.ino b/icbm.ino index 4b1580e..c43b3cf 100644 --- a/icbm.ino +++ b/icbm.ino @@ -18,6 +18,8 @@ void setup() { start = millis(); poll_port_expander(); + PINS.stage = ""; + PINS.ramping = false; } enum { diff --git a/mpod.cpp b/mpod.cpp index ff68d80..04c602f 100644 --- a/mpod.cpp +++ b/mpod.cpp @@ -34,7 +34,7 @@ SNMP::Message *MPOD::read(uint16_t channel) { return message; } -// Create an SNMP SETREQUEST message to switch on or off the MPOD +// Create an SNMP SETREQUEST message to switch on or off the specified channel SNMP::Message *MPOD::output(const uint16_t channel, const bool on) { SNMP::Message *message = new SNMP::Message(SNMP::Version::V2C, "guru", SNMP::Type::SetRequest); // In SETREQUEST, use node type and set the value. diff --git a/panel.hpp b/panel.hpp index 1d62bda..884ba68 100644 --- a/panel.hpp +++ b/panel.hpp @@ -1,4 +1,4 @@ -String buildPanel(bool sib, bool plc, bool ups, unsigned long elapsed_secs) { +String buildPanel(const bool sib, const bool plc, const bool ups, const unsigned long elapsed_secs, const String& status, const bool ramping) { // Shows OK if not triggered (ie bool == false) String page = "<!DOCTYPE html><html lang=\"en\">\n"; page += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"; @@ -38,8 +38,19 @@ String buildPanel(bool sib, bool plc, bool ups, unsigned long elapsed_secs) { page += "<h3>Last Interrupt: "; page += elapsed_secs; - page += " secs. ago"; - page += "</h3></div></body></html>"; + page += " secs. ago<h3>"; + + page += "<h3>Status: "; + page += status; + page += "</h3>"; + + page += "<div class=\"status-item\">\n"; + page += "<span class=\"status-label\">Ramping:</span>\n"; + if (ramping) { page += "<span class=\"status-value status-error\">Powering Down</span>\n"; } + else { page += "<span class=\"status-value status-ok\">Idle</span>\n"; } + page += "</div>\n"; + + page += "</div></body></html>"; return page; } diff --git a/pins.hpp b/pins.hpp index e07afbf..0cd10be 100644 --- a/pins.hpp +++ b/pins.hpp @@ -21,6 +21,8 @@ struct pins { bool plc; bool ups; int last_triggered; + String stage; + bool ramping; }; extern struct pins PINS; diff --git a/powerproc.hpp b/powerproc.hpp index 859f00b..5f0236f 100644 --- a/powerproc.hpp +++ b/powerproc.hpp @@ -1,6 +1,8 @@ #pragma once #include <Arduino.h> +#include "pins.hpp" + #define STAGESCOUNT 4 class PowerProcedure { diff --git a/rest.cpp b/rest.cpp index 49cdf41..8a5a577 100644 --- a/rest.cpp +++ b/rest.cpp @@ -76,12 +76,20 @@ void identify() { unsigned long elapsed_seconds = (millis() - PINS.last_triggered) / 1000; message += "\"sec_since_interrupt\":"; message += elapsed_seconds; - message += "\n}"; + message += "\n},"; // TODO: Add here power sequence status // is_ramping_down // current step // percentage + message += "\"status\":{\n"; + message += "\"ramping\":"; + message += PINS.ramping; + message += ",\n"; + message += "\"stage\":"; + message += PINS.stage; + message += ",\n"; + message += "\n}"; message += "\n}"; @@ -90,7 +98,8 @@ void identify() { void panel() { unsigned long elapsed_seconds = (millis() - PINS.last_triggered) / 1000; - String content = buildPanel(PINS.sib, PINS.plc, PINS.ups, elapsed_seconds); + String content = + buildPanel(PINS.sib, PINS.plc, PINS.ups, elapsed_seconds, PINS.stage, PINS.ramping); restServer.send(200, "text/html", content); } @@ -231,15 +240,18 @@ void powerAllOff() { } if (success) { + PINS.ramping = true; for (uint8_t groupIdx = pproc.stagesCount - 1; groupIdx >= 0; groupIdx--) { group = pproc.stages[groupIdx].name; groups += group; groups += ","; + PINS.stage = group; success = pproc.powerOff(group); if (!success) { break; } } + PINS.ramping = false; } String http_msg = "{\n"; -- GitLab