diff --git a/reactor-plc/panel/front_panel.lua b/reactor-plc/panel/front_panel.lua index fa05f3c..dfd9d19 100644 --- a/reactor-plc/panel/front_panel.lua +++ b/reactor-plc/panel/front_panel.lua @@ -51,7 +51,7 @@ local function init(panel) local system = Div{parent=panel,width=14,height=18,x=2,y=3} - local degraded = LED{parent=system,label="STATUS",colors=cpair(colors.green,colors.red)} + local degraded = LED{parent=system,label="STATUS",colors=cpair(colors.red,colors.green)} local heartbeat = LED{parent=system,label="HEARTBEAT",colors=ind_grn} system.line_break() diff --git a/reactor-plc/plc.lua b/reactor-plc/plc.lua index 7da563f..208197e 100644 --- a/reactor-plc/plc.lua +++ b/reactor-plc/plc.lua @@ -118,7 +118,7 @@ function plc.rps_init(reactor, is_formed) reactor_enabled = false, enabled_at = 0, emer_cool_active = nil, ---@type boolean - formed = is_formed, + formed = is_formed, ---@type boolean|nil force_disabled = false, tripped = false, trip_cause = "ok" ---@type rps_trip_cause @@ -364,29 +364,35 @@ function plc.rps_init(reactor, is_formed) return public.activate() end - -- check all safety conditions + -- check all safety conditions if we have a formed reactor, otherwise handle a subset of conditions ---@nodiscard + ---@param has_reactor boolean if the PLC state indicates we have a reactor ---@return boolean tripped, rps_trip_cause trip_status, boolean first_trip - function public.check() + function public.check(has_reactor) local status = RPS_TRIP_CAUSE.OK local was_tripped = self.tripped local first_trip = false - if self.formed then - -- update state - parallel.waitForAll( - _is_formed, - _is_force_disabled, - _high_damage, - _high_temp, - _low_coolant, - _excess_waste, - _excess_heated_coolant, - _insufficient_fuel - ) + if has_reactor then + if self.formed then + -- update state + parallel.waitForAll( + _is_formed, + _is_force_disabled, + _high_damage, + _high_temp, + _low_coolant, + _excess_waste, + _excess_heated_coolant, + _insufficient_fuel + ) + else + -- check to see if its now formed + _is_formed() + end else - -- check to see if its now formed - _is_formed() + self.formed = nil + self.state[CHK.SYS_FAIL] = true end -- check system states in order of severity @@ -474,6 +480,7 @@ function plc.rps_init(reactor, is_formed) ---@nodiscard function public.is_active() return self.reactor_enabled end ---@nodiscard + ---@return boolean|nil formed true if formed, false if not, nil if unknown function public.is_formed() return self.formed end ---@nodiscard function public.is_force_disabled() return self.force_disabled end @@ -495,14 +502,14 @@ function plc.rps_init(reactor, is_formed) end -- partial RPS reset that only clears fault and sys_fail - function public.reset_formed() + function public.reset_reattach() self.tripped = false self.trip_cause = RPS_TRIP_CAUSE.OK self.state[CHK.FAULT] = false self.state[CHK.SYS_FAIL] = false - log.info("RPS: partial reset on formed") + log.info("RPS: partial reset on connected or formed") end -- reset the automatic and timeout trip flags, then clear trip if that was the trip cause @@ -584,11 +591,7 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog) -- dynamic reactor status information, excluding heating rate ---@return table data_table, boolean faulted local function _get_reactor_status() - local fuel = nil - local waste = nil - local coolant = nil - local hcoolant = nil - + local fuel, waste, coolant, hcoolant = nil, nil, nil, nil local data_table = {} reactor.__p_disable_afc() diff --git a/reactor-plc/threads.lua b/reactor-plc/threads.lua index 5703dc7..c38a5a3 100644 --- a/reactor-plc/threads.lua +++ b/reactor-plc/threads.lua @@ -94,12 +94,9 @@ function threads.thread__main(smem) -- reactor now formed plc_state.reactor_formed = true - println_ts("reactor is now formed.") + println_ts("reactor is now formed") log.info("reactor is now formed") - -- SCRAM newly formed reactor - smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM) - -- determine if we are still in a degraded state if (not networked) or nic.is_connected() then plc_state.degraded = false @@ -107,10 +104,10 @@ function threads.thread__main(smem) -- partial reset of RPS, specific to becoming formed -- without this, auto control can't resume on chunk load - rps.reset_formed() - elseif plc_state.reactor_formed and not rps.is_formed() then + rps.reset_reattach() + elseif plc_state.reactor_formed and (rps.is_formed() == false) then -- reactor no longer formed - println_ts("reactor is no longer formed.") + println_ts("reactor is no longer formed") log.info("reactor is no longer formed") plc_state.reactor_formed = false @@ -182,7 +179,7 @@ function threads.thread__main(smem) plc_dev.reactor = device plc_state.no_reactor = false - println_ts("reactor reconnected.") + println_ts("reactor reconnected") log.info("reactor reconnected") -- we need to assume formed here as we cannot check in this main loop @@ -203,7 +200,7 @@ function threads.thread__main(smem) -- partial reset of RPS, specific to becoming formed/reconnected -- without this, auto control can't resume on chunk load - rps.reset_formed() + rps.reset_reattach() elseif networked and type == "modem" then ---@cast device Modem -- note, check init_ok first since nic will be nil if it is false @@ -218,7 +215,7 @@ function threads.thread__main(smem) log.info("comms modem reconnected") -- determine if we are still in a degraded state - if not plc_state.no_reactor then + if plc_state.reactor_formed and not plc_state.no_reactor then plc_state.degraded = false end elseif device.isWireless() then @@ -327,15 +324,10 @@ function threads.thread__rps(smem) if not (networked or smem.plc_state.fp_ok) then rps.reset(true) end -- check safety (SCRAM occurs if tripped) - if not plc_state.no_reactor then - local rps_tripped, rps_status_string, rps_first = rps.check() - - if rps_tripped and rps_first then - println_ts("[RPS] SCRAM! safety trip: " .. rps_status_string) - if networked and not plc_state.no_modem then - plc_comms.send_rps_alarm(rps_status_string) - end - end + local rps_tripped, rps_status_string, rps_first = rps.check(not plc_state.no_reactor) + if rps_tripped and rps_first then + println_ts("[RPS] SCRAM! safety trip: " .. rps_status_string) + if networked then plc_comms.send_rps_alarm(rps_status_string) end end -- check for messages in the message queue