From ecdaf78ed01aa385a8bd6f9dbac281dd4ea58560 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sun, 9 Feb 2025 13:48:20 -0500 Subject: [PATCH] #589 moved boot recovery to facility update file --- supervisor/facility.lua | 46 +++--------------------- supervisor/facility_update.lua | 66 ++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 49 deletions(-) diff --git a/supervisor/facility.lua b/supervisor/facility.lua index a4fb432..de13c9b 100644 --- a/supervisor/facility.lua +++ b/supervisor/facility.lua @@ -5,7 +5,6 @@ local util = require("scada-common.util") local unit = require("supervisor.unit") local fac_update = require("supervisor.facility_update") -local plc = require("supervisor.session.plc") local rsctl = require("supervisor.session.rsctl") local svsessions = require("supervisor.session.svsessions") @@ -53,7 +52,7 @@ function facility.new(config) ---@class _facility_self local self = { units = {}, ---@type reactor_unit[] - types = { AUTO_SCRAM = AUTO_SCRAM, START_STATUS = START_STATUS }, + types = { AUTO_SCRAM = AUTO_SCRAM, START_STATUS = START_STATUS, RCV_STATE = RCV_STATE }, status_text = { "START UP", "initializing..." }, all_sys_ok = false, allow_testing = false, @@ -177,6 +176,7 @@ function facility.new(config) -- PRIVATE FUNCTIONS -- + -- check an auto process control configuration and save it if its valid (does not start the process) ---@param auto_cfg start_auto_config configuration ---@return boolean ready, number[] unit_limits local function _auto_check_and_save(auto_cfg) @@ -319,46 +319,8 @@ function facility.new(config) -- update (iterate) the facility management function public.update() - -- attempt reboot recovery if in progress - if self.recovery == RCV_STATE.RUNNING then - -- try to start auto control - if self.recovery_boot_state.mode ~= nil and self.units_ready then - if self.recovery_boot_state.mode ~= PROCESS.INACTIVE and self.recovery_boot_state.mode ~= PROCESS.SYSTEM_ALARM_IDLE then - self.mode = self.mode_set - log.info("FAC: process startup resume initiated") - end - - self.recovery_boot_state.mode = nil - end - - local recovered = self.recovery_boot_state.mode == nil or self.recovery_boot_state.mode == PROCESS.INACTIVE - - -- restore manual control reactors - for i = 1, #self.units do - local u = self.units[i] - - if self.recovery_boot_state.unit_states[i] and self.group_map[i] == AUTO_GROUP.MANUAL then - recovered = false - - if u.get_control_inf().ready then - local plc_s = svsessions.get_reactor_session(i) - if plc_s ~= nil then - plc_s.in_queue.push_command(plc.PLC_S_CMDS.ENABLE) - log.info("FAC: startup resume enabling manually controlled reactor unit #" .. i) - - -- only execute once - self.recovery_boot_state.unit_states[i] = nil - end - end - end - end - - if recovered then - self.recovery = RCV_STATE.STOPPED - self.recovery_boot_state = nil - log.info("FAC: startup resume sequence completed") - end - end + -- run reboot recovery routine if needed + f_update.boot_recovery() -- run process control and evaluate automatic SCRAM f_update.pre_auto() diff --git a/supervisor/facility_update.lua b/supervisor/facility_update.lua index f951661..738662a 100644 --- a/supervisor/facility_update.lua +++ b/supervisor/facility_update.lua @@ -1,17 +1,21 @@ -local audio = require("scada-common.audio") -local const = require("scada-common.constants") -local log = require("scada-common.log") -local rsio = require("scada-common.rsio") -local types = require("scada-common.types") -local util = require("scada-common.util") +local audio = require("scada-common.audio") +local const = require("scada-common.constants") +local log = require("scada-common.log") +local rsio = require("scada-common.rsio") +local types = require("scada-common.types") +local util = require("scada-common.util") -local qtypes = require("supervisor.session.rtu.qtypes") +local plc = require("supervisor.session.plc") +local svsessions = require("supervisor.session.svsessions") + +local qtypes = require("supervisor.session.rtu.qtypes") local TONE = audio.TONE local ALARM = types.ALARM local PRIO = types.ALARM_PRIORITY local ALARM_STATE = types.ALARM_STATE +local AUTO_GROUP = types.AUTO_GROUP local CONTAINER_MODE = types.CONTAINER_MODE local PROCESS = types.PROCESS local PROCESS_NAMES = types.PROCESS_NAMES @@ -131,6 +135,54 @@ end --#region PUBLIC FUNCTIONS +-- run reboot recovery routine if needed +function update.boot_recovery() + local RCV_STATE = self.types.RCV_STATE + + -- attempt reboot recovery if in progress + if self.recovery == RCV_STATE.RUNNING then + local was_inactive = self.recovery_boot_state.mode == PROCESS.INACTIVE or self.recovery_boot_state.mode == PROCESS.SYSTEM_ALARM_IDLE + + -- try to start auto control + if self.recovery_boot_state.mode ~= nil and self.units_ready then + if was_inactive then + self.mode = self.mode_set + log.info("FAC: process startup resume initiated") + end + + self.recovery_boot_state.mode = nil + end + + local recovered = self.recovery_boot_state.mode == nil or was_inactive + + -- restore manual control reactors + for i = 1, #self.units do + local u = self.units[i] + + if self.recovery_boot_state.unit_states[i] and self.group_map[i] == AUTO_GROUP.MANUAL then + recovered = false + + if u.get_control_inf().ready then + local plc_s = svsessions.get_reactor_session(i) + if plc_s ~= nil then + plc_s.in_queue.push_command(plc.PLC_S_CMDS.ENABLE) + log.info("FAC: startup resume enabling manually controlled reactor unit #" .. i) + + -- only execute once + self.recovery_boot_state.unit_states[i] = nil + end + end + end + end + + if recovered then + self.recovery = RCV_STATE.STOPPED + self.recovery_boot_state = nil + log.info("FAC: startup resume sequence completed") + end + end +end + -- automatic control pre-update logic function update.pre_auto() -- unlink RTU sessions if they are closed