From 68754977b0ce99aa33dd53d5e0f41c50ac4a99f0 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sun, 12 Nov 2023 14:21:48 -0500 Subject: [PATCH] cleanup and fixes --- coordinator/iocontrol.lua | 8 ++-- coordinator/startup.lua | 2 +- rtu/threads.lua | 66 ++++++++---------------------- supervisor/facility.lua | 2 +- supervisor/session/rtu/imatrix.lua | 3 -- 5 files changed, 23 insertions(+), 58 deletions(-) diff --git a/coordinator/iocontrol.lua b/coordinator/iocontrol.lua index 96911e7..91ecc4d 100644 --- a/coordinator/iocontrol.lua +++ b/coordinator/iocontrol.lua @@ -783,12 +783,12 @@ function iocontrol.update_facility_status(status) fac.radiation = types.new_zero_radiation_reading() fac.ps.publish("rad_computed_status", 1) end + + fac.ps.publish("radiation", fac.radiation) else log.debug(log_header .. "radiation monitor list not a table") valid = false end - - fac.ps.publish("radiation", fac.radiation) else log.debug(log_header .. "rtu statuses not a table") valid = false @@ -1081,12 +1081,12 @@ function iocontrol.update_unit_statuses(statuses) else unit.radiation = types.new_zero_radiation_reading() end + + unit.unit_ps.publish("radiation", unit.radiation) else log.debug(log_header .. "radiation monitor list not a table") valid = false end - - unit.unit_ps.publish("radiation", unit.radiation) else log.debug(log_header .. "rtu list not a table") valid = false diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 0ce23ba..7811904 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 = "v1.0.16" +local COORDINATOR_VERSION = "v1.0.17" local println = util.println local println_ts = util.println_ts diff --git a/rtu/threads.lua b/rtu/threads.lua index 2a93638..f3147e7 100644 --- a/rtu/threads.lua +++ b/rtu/threads.lua @@ -40,10 +40,12 @@ local function handle_unit_mount(smem, println_ts, iface, type, device, unit) -- find disconnected device to reconnect -- note: cannot check isFormed as that would yield this coroutine and consume events if unit.name == iface then - local resend_advert = false - local faulted = false - local unknown = false - local invalid = false + local resend_advert, faulted, unknown, invalid = false, false, false, false + + local function fail(msg) + invalid = true + log.error(msg .. " in config") + end -- found, re-link unit.device = device @@ -52,79 +54,45 @@ local function handle_unit_mount(smem, println_ts, iface, type, device, unit) resend_advert = true if type == "boilerValve" then -- boiler multiblock - if unit.reactor < 1 or unit.reactor > 4 then - invalid = true - log.error(util.c("boiler '", unit.name, "' cannot init, not assigned to a valid unit in config")) - end - - if (unit.index == false) or unit.index < 1 or unit.index > 2 then - invalid = true - log.error(util.c("boiler '", unit.name, "' cannot init, invalid index provided in config")) - end + if unit.reactor < 1 or unit.reactor > 4 then fail(util.c("boiler '", unit.name, "' cannot init, not assigned to a valid unit")) end + if (unit.index == false) or unit.index < 1 or unit.index > 2 then fail(util.c("boiler '", unit.name, "' cannot init, invalid index provided")) end unit.type = RTU_UNIT_TYPE.BOILER_VALVE elseif type == "turbineValve" then -- turbine multiblock - if unit.reactor < 1 or unit.reactor > 4 then - invalid = true - log.error(util.c("turbine '", unit.name, "' cannot init, not assigned to a valid unit in config")) - end - - if (unit.index == false) or unit.index < 1 or unit.index > 3 then - invalid = true - log.error(util.c("turbine '", unit.name, "' cannot init, invalid index provided in config")) - end + if unit.reactor < 1 or unit.reactor > 4 then fail(util.c("turbine '", unit.name, "' cannot init, not assigned to a valid unit")) end + if (unit.index == false) or unit.index < 1 or unit.index > 3 then fail(util.c("turbine '", unit.name, "' cannot init, invalid index provided")) end unit.type = RTU_UNIT_TYPE.TURBINE_VALVE elseif type == "dynamicValve" then -- dynamic tank multiblock - if unit.reactor < 0 or unit.reactor > 4 then - invalid = true - log.error(util.c("dynamic tank '", unit.name, "' cannot init, no valid assignment provided in config")) - end + if unit.reactor < 0 or unit.reactor > 4 then fail(util.c("dynamic tank '", unit.name, "' cannot init, no valid assignment provided")) end if (unit.reactor == 0 and ((unit.index == false) or unit.index < 1 or unit.index > 4)) or (unit.reactor > 0 and unit.index ~= 1) then - invalid = true - log.error(util.c("dynamic tank '", unit.name, "' cannot init, invalid index provided in config")) + fail(util.c("dynamic tank '", unit.name, "' cannot init, invalid index provided")) end unit.type = RTU_UNIT_TYPE.DYNAMIC_VALVE elseif type == "inductionPort" then -- induction matrix multiblock - if unit.reactor ~= 0 then - invalid = true - log.error(util.c("induction matrix '", unit.name, "' cannot init, not assigned to facility in config")) - end + if unit.reactor ~= 0 then fail(util.c("induction matrix '", unit.name, "' cannot init, not assigned to facility")) end unit.type = RTU_UNIT_TYPE.IMATRIX elseif type == "spsPort" then -- SPS multiblock - if unit.reactor ~= 0 then - invalid = true - log.error(util.c("SPS '", unit.name, "' cannot init, not assigned to facility in config")) - end + if unit.reactor ~= 0 then fail(util.c("SPS '", unit.name, "' cannot init, not assigned to facility")) end unit.type = RTU_UNIT_TYPE.SPS elseif type == "solarNeutronActivator" then -- SNA - if unit.reactor < 1 or unit.reactor > 4 then - invalid = true - log.error(util.c("SNA '", unit.name, "' cannot init, not assigned to a valid unit in config")) - end + if unit.reactor < 1 or unit.reactor > 4 then fail(util.c("SNA '", unit.name, "' cannot init, not assigned to a valid unit")) end unit.type = RTU_UNIT_TYPE.SNA elseif type == "environmentDetector" then -- advanced peripherals environment detector - if unit.reactor < 0 or unit.reactor > 4 then - invalid = true - log.error(util.c("environment detector '", unit.name, "' cannot init, no valid assignment provided in config")) - end - - if (unit.index == false) or unit.index < 1 then - invalid = true - log.error(util.c("environment detector '", unit.name, "' cannot init, invalid index provided in config")) - end + if unit.reactor < 0 or unit.reactor > 4 then fail(util.c("environment detector '", unit.name, "' cannot init, no valid assignment provided")) end + if (unit.index == false) or unit.index < 1 then fail(util.c("environment detector '", unit.name, "' cannot init, invalid index provided")) end unit.type = RTU_UNIT_TYPE.ENV_DETECTOR else diff --git a/supervisor/facility.lua b/supervisor/facility.lua index 791aabd..7578cbd 100644 --- a/supervisor/facility.lua +++ b/supervisor/facility.lua @@ -638,7 +638,7 @@ function facility.new(num_reactors, cooling_conf) if e_db.radiation_raw > max_rad then max_rad = e_db.radiation_raw end end - astatus.radiation = max_rad > ALARM_LIMS.FAC_HIGH_RAD + astatus.radiation = max_rad >= ALARM_LIMS.FAC_HIGH_RAD else -- don't clear, if it is true then we lost it with high radiation, so just keep alarming -- operator can restart the system or hit the stop/reset button diff --git a/supervisor/session/rtu/imatrix.lua b/supervisor/session/rtu/imatrix.lua index 1bcf286..5a6880e 100644 --- a/supervisor/session/rtu/imatrix.lua +++ b/supervisor/session/rtu/imatrix.lua @@ -41,9 +41,6 @@ function imatrix.new(session_id, unit_id, advert, out_queue) if advert.type ~= RTU_UNIT_TYPE.IMATRIX then log.error("attempt to instantiate imatrix RTU for type " .. types.rtu_type_to_string(advert.type)) return nil - elseif not util.is_int(advert.index) then - log.error("attempt to instantiate dynamicv RTU without index") - return nil end local log_tag = util.c("session.rtu(", session_id, ").imatrix[@", unit_id, "]: ")