From 44d30ae5839738f1ef181ad44f9672a371d20800 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Thu, 19 May 2022 10:35:56 -0400 Subject: [PATCH] #48 only log every 20 PPM faults (per function) --- reactor-plc/startup.lua | 2 +- rtu/startup.lua | 2 +- scada-common/ppm.lua | 18 ++++++++++++++++-- supervisor/startup.lua | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index c1fb666..86e7722 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.8" +local R_PLC_VERSION = "alpha-v0.6.9" local print = util.print local println = util.println diff --git a/rtu/startup.lua b/rtu/startup.lua index 26abaf9..90578ce 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -24,7 +24,7 @@ local imatrix_rtu = require("rtu.dev.imatrix_rtu") local turbine_rtu = require("rtu.dev.turbine_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu") -local RTU_VERSION = "alpha-v0.6.7" +local RTU_VERSION = "alpha-v0.6.8" local rtu_t = types.rtu_t diff --git a/scada-common/ppm.lua b/scada-common/ppm.lua index 6efa33c..fd84503 100644 --- a/scada-common/ppm.lua +++ b/scada-common/ppm.lua @@ -15,6 +15,8 @@ ppm.ACCESS_FAULT = ACCESS_FAULT -- PRIVATE DATA/FUNCTIONS -- ---------------------------- +local REPORT_FREQUENCY = 20 -- log every 20 faults per function + local _ppm_sys = { mounts = {}, auto_cf = false, @@ -34,6 +36,7 @@ local peri_init = function (iface) local self = { faulted = false, last_fault = "", + fault_counts = {}, auto_cf = true, type = peripheral.getType(iface), device = peripheral.wrap(iface) @@ -42,6 +45,7 @@ local peri_init = function (iface) -- initialization process (re-map) for key, func in pairs(self.device) do + self.fault_counts[key] = 0 self.device[key] = function (...) local status, result = pcall(func, ...) @@ -49,6 +53,9 @@ local peri_init = function (iface) -- auto fault clear if self.auto_cf then self.faulted = false end if _ppm_sys.auto_cf then _ppm_sys.faulted = false end + + self.fault_counts[key] = 0 + return result else -- function failed @@ -58,10 +65,17 @@ local peri_init = function (iface) _ppm_sys.faulted = true _ppm_sys.last_fault = result - if not _ppm_sys.mute then - log.error("PPM: protected " .. key .. "() -> " .. result) + if not _ppm_sys.mute and (self.fault_counts[key] % REPORT_FREQUENCY == 0) then + local count_str = "" + if self.fault_counts[key] > 0 then + count_str = " [" .. self.fault_counts[key] .. " total faults]" + end + + log.error("PPM: protected " .. key .. "() -> " .. result .. count_str) end + self.fault_counts[key] = self.fault_counts[key] + 1 + if result == "Terminated" then _ppm_sys.terminate = true end diff --git a/supervisor/startup.lua b/supervisor/startup.lua index e175f3a..d23436d 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -13,7 +13,7 @@ local svsessions = require("supervisor.session.svsessions") local config = require("supervisor.config") local supervisor = require("supervisor.supervisor") -local SUPERVISOR_VERSION = "alpha-v0.3.9" +local SUPERVISOR_VERSION = "alpha-v0.3.10" local print = util.print local println = util.println