From 68ae061ed31135947ca0282dfbd16172d3226d2e Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sat, 15 Nov 2025 23:06:04 -0500 Subject: [PATCH] #647 rtu gateway status light functionality --- rtu/databus.lua | 32 +++++++++++++++++++++++++++++++- rtu/panel/front_panel.lua | 4 ++-- rtu/startup.lua | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/rtu/databus.lua b/rtu/databus.lua index ae11487..296e6d6 100644 --- a/rtu/databus.lua +++ b/rtu/databus.lua @@ -7,6 +7,25 @@ local util = require("scada-common.util") local databus = {} +local _dbus = { + wd_modem = true, + wl_modem = true, + coroutines = {} +} + +-- evaluate and publish system health status +local function eval_status() + local ok = _dbus.wd_modem and _dbus.wl_modem + + if ok then + for _, v in pairs(_dbus.coroutines) do + ok = ok and v + end + end + + databus.ps.publish("status", ok) +end + -- databus PSIL databus.ps = psil.create() @@ -35,12 +54,18 @@ end ---@param has_modem boolean function databus.tx_hw_wd_modem(has_modem) databus.ps.publish("has_wd_modem", has_modem) + + _dbus.wd_modem = has_modem + eval_status() end -- transmit hardware status for the wireless comms modem ---@param has_modem boolean function databus.tx_hw_wl_modem(has_modem) databus.ps.publish("has_wl_modem", has_modem) + + _dbus.wl_modem = has_modem + eval_status() end -- transmit the number of speakers connected @@ -67,7 +92,12 @@ end ---@param thread string thread name ---@param ok boolean thread state function databus.tx_rt_status(thread, ok) - databus.ps.publish(util.c("routine__", thread), ok) + local name = util.c("routine__", thread) + + databus.ps.publish(name, ok) + + _dbus.coroutines[name] = ok + eval_status() end -- transmit supervisor link state diff --git a/rtu/panel/front_panel.lua b/rtu/panel/front_panel.lua index 48401f3..177d6aa 100644 --- a/rtu/panel/front_panel.lua +++ b/rtu/panel/front_panel.lua @@ -51,11 +51,11 @@ local function init(panel, config, units) local system = Div{parent=panel,width=14,height=term_h-5,x=2,y=3} - local on = LED{parent=system,label="STATUS",colors=cpair(colors.green,colors.red)} + local status = LED{parent=system,label="STATUS",colors=cpair(colors.green,colors.red)} local heartbeat = LED{parent=system,label="HEARTBEAT",colors=ind_grn} - on.update(true) system.line_break() + status.register(databus.ps, "status", status.update) heartbeat.register(databus.ps, "heartbeat", heartbeat.update) if config.WirelessModem and config.WiredModem then diff --git a/rtu/startup.lua b/rtu/startup.lua index 322a9ae..b2726f3 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -21,7 +21,7 @@ local rtu = require("rtu.rtu") local threads = require("rtu.threads") local uinit = require("rtu.uinit") -local RTU_VERSION = "v1.13.0" +local RTU_VERSION = "v1.13.1" local println = util.println local println_ts = util.println_ts