From 028a161af0d7506317b2315d230d8c6aee3c1000 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Mon, 5 May 2025 17:57:54 +0000 Subject: [PATCH] #580 RTU gateway changes for wired comms modems --- reactor-plc/threads.lua | 2 +- rtu/configure.lua | 4 +++- rtu/databus.lua | 2 +- rtu/rtu.lua | 6 +++++- rtu/startup.lua | 19 +++++++++++++------ rtu/threads.lua | 15 +++++++++------ 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/reactor-plc/threads.lua b/reactor-plc/threads.lua index dadb80d..0de3b7e 100644 --- a/reactor-plc/threads.lua +++ b/reactor-plc/threads.lua @@ -167,7 +167,7 @@ function threads.thread__main(smem, init) end end else - log.warning("a non-comms modem was disconnected") + log.warning("non-comms modem disconnected") end end end diff --git a/rtu/configure.lua b/rtu/configure.lua index 03fb1b9..fe06fea 100644 --- a/rtu/configure.lua +++ b/rtu/configure.lua @@ -88,8 +88,9 @@ local tmp_cfg = { SVR_Channel = nil, ---@type integer RTU_Channel = nil, ---@type integer ConnTimeout = nil, ---@type number + WiredModem = false, ---@type string|false TrustedRange = nil, ---@type number - AuthKey = nil, ---@type string|nil + AuthKey = nil, ---@type string LogMode = 0, ---@type LOG_MODE LogPath = "", LogDebug = false, @@ -107,6 +108,7 @@ local fields = { { "SVR_Channel", "SVR Channel", 16240 }, { "RTU_Channel", "RTU Channel", 16242 }, { "ConnTimeout", "Connection Timeout", 5 }, + { "WiredModem", "Wired Modem", false }, { "TrustedRange", "Trusted Range", 0 }, { "AuthKey", "Facility Auth Key", "" }, { "LogMode", "Log Mode", log.MODE.APPEND }, diff --git a/rtu/databus.lua b/rtu/databus.lua index 0d086f4..c4eb0ed 100644 --- a/rtu/databus.lua +++ b/rtu/databus.lua @@ -31,7 +31,7 @@ function databus.tx_versions(rtu_v, comms_v) databus.ps.publish("comms_version", comms_v) end --- transmit hardware status for modem connection state +-- transmit hardware status for comms modem connection state ---@param has_modem boolean function databus.tx_hw_modem(has_modem) databus.ps.publish("has_modem", has_modem) diff --git a/rtu/rtu.lua b/rtu/rtu.lua index d7a576e..ac1c2f7 100644 --- a/rtu/rtu.lua +++ b/rtu/rtu.lua @@ -36,6 +36,7 @@ function rtu.load_config() config.SVR_Channel = settings.get("SVR_Channel") config.RTU_Channel = settings.get("RTU_Channel") config.ConnTimeout = settings.get("ConnTimeout") + config.WiredModem = settings.get("WiredModem") config.TrustedRange = settings.get("TrustedRange") config.AuthKey = settings.get("AuthKey") @@ -61,6 +62,7 @@ function rtu.validate_config(cfg) cfv.assert_channel(cfg.RTU_Channel) cfv.assert_type_num(cfg.ConnTimeout) cfv.assert_min(cfg.ConnTimeout, 2) + cfv.assert((cfg.WiredModem == false) or (type(cfg.WiredModem) == "string")) cfv.assert_type_num(cfg.TrustedRange) cfv.assert_min(cfg.TrustedRange, 0) cfv.assert_type_str(cfg.AuthKey) @@ -299,7 +301,9 @@ function rtu.comms(version, nic, conn_watchdog) local insert = table.insert - comms.set_trusted_range(config.TrustedRange) + if nic.isWireless() then + comms.set_trusted_range(config.TrustedRange) + end -- PRIVATE FUNCTIONS -- diff --git a/rtu/startup.lua b/rtu/startup.lua index c1413a6..1385fae 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -31,7 +31,7 @@ local sna_rtu = require("rtu.dev.sna_rtu") local sps_rtu = require("rtu.dev.sps_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu") -local RTU_VERSION = "v1.11.8" +local RTU_VERSION = "v1.12.0" local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE local RTU_HW_STATE = databus.RTU_HW_STATE @@ -108,7 +108,9 @@ local function main() -- RTU gateway devices (not RTU units) rtu_dev = { - modem = ppm.get_wireless_modem(), + modem_wired = type(config.WiredModem) == "string", + modem_iface = config.WiredModem, + modem = nil, sounders = {} ---@type rtu_speaker_sounder[] }, @@ -131,8 +133,13 @@ local function main() local rtu_state = __shared_memory.rtu_state + -- get the configured modem + if smem_dev.modem_wired then + smem_dev.modem = ppm.get_wired_modem(smem_dev.modem_iface) + else smem_dev.modem = ppm.get_wireless_modem() end + ---------------------------------------- - -- interpret config and init units + -- interpret RTU configs and init units ---------------------------------------- local units = __shared_memory.rtu_sys.units @@ -506,10 +513,10 @@ local function main() log.info("startup> running in headless mode without front panel") end - -- check modem + -- check comms modem if smem_dev.modem == nil then - println("startup> wireless modem not found") - log.fatal("no wireless modem on startup") + println("startup> comms modem not found") + log.fatal("no comms modem on startup") return end diff --git a/rtu/threads.lua b/rtu/threads.lua index e1d8c6c..99ae9f8 100644 --- a/rtu/threads.lua +++ b/rtu/threads.lua @@ -189,6 +189,7 @@ function threads.thread__main(smem) -- load in from shared memory local rtu_state = smem.rtu_state + local rtu_dev = smem.rtu_dev local sounders = smem.rtu_dev.sounders local nic = smem.rtu_sys.nic local rtu_comms = smem.rtu_sys.rtu_comms @@ -246,11 +247,11 @@ function threads.thread__main(smem) if type ~= nil and device ~= nil then if type == "modem" then ---@cast device Modem - -- we only care if this is our wireless modem + -- we only care if this is our comms modem if nic.is_modem(device) then nic.disconnect() - println_ts("wireless modem disconnected!") + println_ts("comms modem disconnected!") log.warning("comms modem disconnected") local other_modem = ppm.get_wireless_modem() @@ -301,18 +302,20 @@ function threads.thread__main(smem) if type ~= nil and device ~= nil then if type == "modem" then ---@cast device Modem - if device.isWireless() and not nic.is_connected() then + local is_comms_modem = util.trinary(rtu_dev.modem_wired, rtu_dev.modem_iface == param1, device.isWireless()) + + if is_comms_modem and not nic.is_connected() then -- reconnected modem nic.connect(device) - println_ts("wireless modem reconnected.") + println_ts("comms modem reconnected.") log.info("comms modem reconnected") databus.tx_hw_modem(true) elseif device.isWireless() then - log.info("unused wireless modem reconnected") + log.info("unused wireless modem connected") else - log.info("wired modem reconnected") + log.info("non-comms wired modem connected") end elseif type == "speaker" then ---@cast device Speaker