From 8b136d78a8d95221d2fb86866cf26f2a66432464 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Tue, 11 Jul 2023 18:22:09 -0400 Subject: [PATCH] #268 better handling of wireless modem peripherals --- coordinator/startup.lua | 22 ++++++++++++++-------- reactor-plc/startup.lua | 2 +- reactor-plc/threads.lua | 27 ++++++++++++++++----------- rtu/startup.lua | 2 +- rtu/threads.lua | 12 +++++++++--- scada-common/network.lua | 2 +- supervisor/startup.lua | 12 +++++++++--- 7 files changed, 51 insertions(+), 28 deletions(-) diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 8b7e3e8..0f1d30a 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -22,7 +22,7 @@ local sounder = require("coordinator.sounder") local apisessions = require("coordinator.session.apisessions") -local COORDINATOR_VERSION = "v0.19.1" +local COORDINATOR_VERSION = "v0.19.2" local println = util.println local println_ts = util.println_ts @@ -234,13 +234,19 @@ local function main() nic.disconnect() log_sys("comms modem disconnected") - -- close out main UI - renderer.close_ui() + local other_modem = ppm.get_wireless_modem() + if other_modem then + log_sys("found another wireless modem, using it for comms") + nic.connect(other_modem) + else + -- close out main UI + renderer.close_ui() - -- alert user to status - log_sys("awaiting comms modem reconnect...") + -- alert user to status + log_sys("awaiting comms modem reconnect...") - iocontrol.fp_has_modem(false) + iocontrol.fp_has_modem(false) + end else log_sys("non-comms modem disconnected") end @@ -263,7 +269,7 @@ local function main() if type ~= nil and device ~= nil then if type == "modem" then - if device.isWireless() then + if device.isWireless() and not nic.is_connected() then -- reconnected modem log_sys("comms modem reconnected") nic.connect(device) @@ -288,7 +294,7 @@ local function main() iocontrol.heartbeat() -- maintain connection - if nic.connected() then + if nic.is_connected() then local ok, start_ui = coord_comms.try_connect() if not ok then link_failed = true diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index f4ac2fe..1f1cdf1 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -19,7 +19,7 @@ local plc = require("reactor-plc.plc") local renderer = require("reactor-plc.renderer") local threads = require("reactor-plc.threads") -local R_PLC_VERSION = "v1.5.2" +local R_PLC_VERSION = "v1.5.3" local println = util.println local println_ts = util.println_ts diff --git a/reactor-plc/threads.lua b/reactor-plc/threads.lua index cf18963..e3cd9a1 100644 --- a/reactor-plc/threads.lua +++ b/reactor-plc/threads.lua @@ -77,7 +77,7 @@ function threads.thread__main(smem, init) loop_clock.start() -- send updated data - if nic.connected() then + if nic.is_connected() then if plc_comms.is_linked() then smem.q.mq_comms_tx.push_command(MQ__COMM_CMD.SEND_STATUS) else @@ -116,7 +116,7 @@ function threads.thread__main(smem, init) smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM) -- determine if we are still in a degraded state - if (not networked) or nic.connected() then + if (not networked) or nic.is_connected() then plc_state.degraded = false end @@ -146,7 +146,7 @@ function threads.thread__main(smem, init) -- update indicators databus.tx_hw_status(plc_state) - elseif event == "modem_message" and networked and plc_state.init_ok and nic.connected() then + elseif event == "modem_message" and networked and plc_state.init_ok and nic.is_connected() then -- got a packet local packet = plc_comms.parse_packet(param1, param2, param3, param4, param5) if packet ~= nil then @@ -177,16 +177,21 @@ function threads.thread__main(smem, init) nic.disconnect() println_ts("comms modem disconnected!") - log.error("comms modem disconnected") + log.warning("comms modem disconnected") - plc_state.no_modem = true + local other_modem = ppm.get_wireless_modem() + if other_modem then + log.info("found another wireless modem, using it for comms") + nic.connect(other_modem) + else + plc_state.no_modem = true + plc_state.degraded = true - if plc_state.init_ok then - -- try to scram reactor if it is still connected - smem.q.mq_rps.push_command(MQ__RPS_CMD.DEGRADED_SCRAM) + if plc_state.init_ok then + -- try to scram reactor if it is still connected + smem.q.mq_rps.push_command(MQ__RPS_CMD.DEGRADED_SCRAM) + end end - - plc_state.degraded = true else log.warning("non-comms modem disconnected") end @@ -230,7 +235,7 @@ function threads.thread__main(smem, init) rps.reset() end elseif networked and type == "modem" then - if device.isWireless() then + if device.isWireless() and not nic.is_connected() then -- reconnected modem plc_dev.modem = device plc_state.no_modem = false diff --git a/rtu/startup.lua b/rtu/startup.lua index aa182d9..d91075e 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -30,7 +30,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.5.0" +local RTU_VERSION = "v1.5.1" local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE diff --git a/rtu/threads.lua b/rtu/threads.lua index 55a4b7a..32cda4f 100644 --- a/rtu/threads.lua +++ b/rtu/threads.lua @@ -98,9 +98,15 @@ function threads.thread__main(smem) nic.disconnect() println_ts("wireless modem disconnected!") - log.warning("comms modem disconnected!") + log.warning("comms modem disconnected") - databus.tx_hw_modem(false) + local other_modem = ppm.get_wireless_modem() + if other_modem then + log.info("found another wireless modem, using it for comms") + nic.connect(other_modem) + else + databus.tx_hw_modem(false) + end else log.warning("non-comms modem disconnected") end @@ -128,7 +134,7 @@ function threads.thread__main(smem) if type ~= nil and device ~= nil then if type == "modem" then - if device.isWireless() then + if device.isWireless() and not nic.is_connected() then -- reconnected modem nic.connect(device) diff --git a/scada-common/network.lua b/scada-common/network.lua index dbb3e75..491faef 100644 --- a/scada-common/network.lua +++ b/scada-common/network.lua @@ -94,7 +94,7 @@ function network.nic(modem) -- check if this NIC has a connected modem ---@nodiscard - function public.connected() return self.connected end + function public.is_connected() return self.connected end -- connect to a modem peripheral ---@param reconnected_modem table diff --git a/supervisor/startup.lua b/supervisor/startup.lua index 35b3366..fe6c84a 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -21,7 +21,7 @@ local supervisor = require("supervisor.supervisor") local svsessions = require("supervisor.session.svsessions") -local SUPERVISOR_VERSION = "v0.19.2" +local SUPERVISOR_VERSION = "v0.19.3" local println = util.println local println_ts = util.println_ts @@ -153,7 +153,13 @@ local function main() println_ts("wireless modem disconnected!") log.warning("comms modem disconnected") - databus.tx_hw_modem(false) + local other_modem = ppm.get_wireless_modem() + if other_modem then + log.info("found another wireless modem, using it for comms") + nic.connect(other_modem) + else + databus.tx_hw_modem(false) + end else log.warning("non-comms modem disconnected") end @@ -164,7 +170,7 @@ local function main() if type ~= nil and device ~= nil then if type == "modem" then - if device.isWireless() and not nic.connected() then + if device.isWireless() and not nic.is_connected() then -- reconnected modem nic.connect(device)