diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index 869be2f..5692899 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -10,7 +10,7 @@ os.loadAPI("scada-common/comms.lua") os.loadAPI("config.lua") os.loadAPI("plc.lua") -local R_PLC_VERSION = "alpha-v0.1.5" +local R_PLC_VERSION = "alpha-v0.1.6" local print = util.print local println = util.println @@ -271,7 +271,12 @@ while true do iss.trip_timeout() println_ts("server timeout, reactor disabled") log._warning("server timeout, reactor disabled") - elseif event == "terminate" then + end + + -- check for termination request + if event == "terminate" or ppm.should_terminate() then + log._warning("terminate requested, exiting...") + -- safe exit if plc_state.init_ok then plc_state.scram = true @@ -282,9 +287,11 @@ while true do println_ts("exiting, reactor failed to disable") end end - -- send an alarm: plc_comms.send_alarm(ALARMS.PLC_SHUTDOWN) ? - println_ts("exited") - log._info("terminate requested, exiting") - return + + break end end + +-- send an alarm: plc_comms.send_alarm(ALARMS.PLC_SHUTDOWN) ? +println_ts("exited") +log._info("exited") diff --git a/rtu/startup.lua b/rtu/startup.lua index 8f03a35..0e2bfaa 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -17,7 +17,7 @@ os.loadAPI("dev/boiler_rtu.lua") os.loadAPI("dev/imatrix_rtu.lua") os.loadAPI("dev/turbine_rtu.lua") -local RTU_VERSION = "alpha-v0.1.4" +local RTU_VERSION = "alpha-v0.1.5" local print = util.print local println = util.println @@ -237,7 +237,10 @@ while true do -- if linked, stop sending advertisements linked = link_ref.linked - elseif event == "terminate" then + end + + -- check for termination request + if event == "terminate" or ppm.should_terminate() then log._warning("terminate requested, exiting...") break end diff --git a/scada-common/ppm.lua b/scada-common/ppm.lua index f11f0e2..fd92b23 100644 --- a/scada-common/ppm.lua +++ b/scada-common/ppm.lua @@ -15,6 +15,7 @@ local self = { mounts = {}, auto_cf = false, faulted = false, + terminate = false, mute = false } @@ -38,9 +39,15 @@ local peri_init = function (device) else -- function failed self.faulted = true + if not mute then log._error("PPM: protected " .. key .. "() -> " .. result) end + + if result == "Terminated" then + self.terminate = true + end + return ACCESS_FAULT end end @@ -85,6 +92,13 @@ function clear_fault() self.faulted = false end +-- TERMINATION -- + +-- if a caught error was a termination request +function should_terminate() + return self.terminate +end + -- MOUNTING -- -- mount all available peripherals (clears mounts first)