catch terminations that are caught by PPM

This commit is contained in:
Mikayla Fischler 2022-04-18 10:31:24 -04:00
parent 91079eeb78
commit 6a5e0243be
3 changed files with 32 additions and 8 deletions

View File

@ -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")

View File

@ -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

View File

@ -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)