diff --git a/reactor-plc/plc.lua b/reactor-plc/plc.lua index b54354c..1123399 100644 --- a/reactor-plc/plc.lua +++ b/reactor-plc/plc.lua @@ -51,7 +51,9 @@ plc.rps_init = function (reactor) -- set reactor access fault flag local _set_fault = function () - self.state[state_keys.fault] = true + if self.reactor.__p_last_fault() ~= "Terminated" then + self.state[state_keys.fault] = true + end end -- clear reactor access fault flag diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index aad57f7..214b167 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -13,7 +13,7 @@ local config = require("reactor-plc.config") local plc = require("reactor-plc.plc") local threads = require("reactor-plc.threads") -local R_PLC_VERSION = "alpha-v0.6.6" +local R_PLC_VERSION = "alpha-v0.6.7" local print = util.print local println = util.println diff --git a/scada-common/ppm.lua b/scada-common/ppm.lua index c5026ea..6efa33c 100644 --- a/scada-common/ppm.lua +++ b/scada-common/ppm.lua @@ -19,6 +19,7 @@ local _ppm_sys = { mounts = {}, auto_cf = false, faulted = false, + last_fault = "", terminate = false, mute = false } @@ -32,6 +33,7 @@ local _ppm_sys = { local peri_init = function (iface) local self = { faulted = false, + last_fault = "", auto_cf = true, type = peripheral.getType(iface), device = peripheral.wrap(iface) @@ -51,7 +53,10 @@ local peri_init = function (iface) else -- function failed self.faulted = true + self.last_fault = result + _ppm_sys.faulted = true + _ppm_sys.last_fault = result if not _ppm_sys.mute then log.error("PPM: protected " .. key .. "() -> " .. result) @@ -69,6 +74,7 @@ local peri_init = function (iface) -- fault management functions local clear_fault = function () self.faulted = false end + local get_last_fault = function () return self.last_fault end local is_faulted = function () return self.faulted end local is_ok = function () return not self.faulted end @@ -78,6 +84,7 @@ local peri_init = function (iface) -- append to device functions self.device.__p_clear_fault = clear_fault + self.device.__p_last_fault = get_last_fault self.device.__p_is_faulted = is_faulted self.device.__p_is_ok = is_ok self.device.__p_enable_afc = enable_afc @@ -117,14 +124,19 @@ ppm.disable_afc = function () _ppm_sys.auto_cf = false end +-- clear fault flag +ppm.clear_fault = function () + _ppm_sys.faulted = false +end + -- check fault flag ppm.is_faulted = function () return _ppm_sys.faulted end --- clear fault flag -ppm.clear_fault = function () - _ppm_sys.faulted = false +-- get the last fault message +ppm.get_last_fault = function () + return _ppm_sys.last_fault end -- TERMINATION --