#48 only log every 20 PPM faults (per function)

This commit is contained in:
Mikayla Fischler 2022-05-19 10:35:56 -04:00
parent 6a168c884d
commit 44d30ae583
4 changed files with 19 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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