mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
Merge branch 'devel' into pocket-alpha-dev
This commit is contained in:
@ -24,6 +24,21 @@ function crash.set_env(application, version)
|
||||
ver = version
|
||||
end
|
||||
|
||||
-- log environment versions
|
||||
---@param log_msg function log function to use
|
||||
local function log_versions(log_msg)
|
||||
log_msg(util.c("RUNTIME: ", _HOST))
|
||||
log_msg(util.c("LUA VERSION: ", _VERSION))
|
||||
log_msg(util.c("APPLICATION: ", app))
|
||||
log_msg(util.c("FIRMWARE VERSION: ", ver))
|
||||
log_msg(util.c("COMMS VERSION: ", comms.version))
|
||||
if has_graphics then log_msg(util.c("GRAPHICS VERSION: ", core.version)) end
|
||||
if has_lockbox then log_msg(util.c("LOCKBOX VERSION: ", lockbox.version)) end
|
||||
end
|
||||
|
||||
-- when running with debug logs, log the useful information that the crash handler knows
|
||||
function crash.dbg_log_env() log_versions(log.debug) end
|
||||
|
||||
-- handle a crash error
|
||||
---@param error string error message
|
||||
function crash.handler(error)
|
||||
@ -31,13 +46,7 @@ function crash.handler(error)
|
||||
log.info("=====> FATAL SOFTWARE FAULT <=====")
|
||||
log.fatal(error)
|
||||
log.info("----------------------------------")
|
||||
log.info(util.c("RUNTIME: ", _HOST))
|
||||
log.info(util.c("LUA VERSION: ", _VERSION))
|
||||
log.info(util.c("APPLICATION: ", app))
|
||||
log.info(util.c("FIRMWARE VERSION: ", ver))
|
||||
log.info(util.c("COMMS VERSION: ", comms.version))
|
||||
if has_graphics then log.info(util.c("GRAPHICS VERSION: ", core.version)) end
|
||||
if has_lockbox then log.info(util.c("LOCKBOX VERSION: ", lockbox.version)) end
|
||||
log_versions(log.info)
|
||||
log.info("----------------------------------")
|
||||
log.info(debug.traceback("--- begin debug trace ---", 1))
|
||||
log.info("--- end debug trace ---")
|
||||
|
@ -51,11 +51,13 @@ local function peri_init(iface)
|
||||
self.device = peripheral.wrap(iface)
|
||||
end
|
||||
|
||||
-- initialization process (re-map)
|
||||
|
||||
for key, func in pairs(self.device) do
|
||||
self.fault_counts[key] = 0
|
||||
self.device[key] = function (...)
|
||||
-- create a protected version of a peripheral function call
|
||||
---@nodiscard
|
||||
---@param key string function name
|
||||
---@param func function function
|
||||
---@return function method protected version of the function
|
||||
local function protect_peri_function(key, func)
|
||||
return function (...)
|
||||
local return_table = table.pack(pcall(func, ...))
|
||||
|
||||
local status = return_table[1]
|
||||
@ -85,20 +87,24 @@ local function peri_init(iface)
|
||||
count_str = " [" .. self.fault_counts[key] .. " total faults]"
|
||||
end
|
||||
|
||||
log.error(util.c("PPM: protected ", key, "() -> ", result, count_str))
|
||||
log.error(util.c("PPM: [@", iface, "] protected ", key, "() -> ", result, count_str))
|
||||
end
|
||||
|
||||
self.fault_counts[key] = self.fault_counts[key] + 1
|
||||
|
||||
if result == "Terminated" then
|
||||
ppm_sys.terminate = true
|
||||
end
|
||||
if result == "Terminated" then ppm_sys.terminate = true end
|
||||
|
||||
return ACCESS_FAULT
|
||||
return ACCESS_FAULT, result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- initialization process (re-map)
|
||||
for key, func in pairs(self.device) do
|
||||
self.fault_counts[key] = 0
|
||||
self.device[key] = protect_peri_function(key, func)
|
||||
end
|
||||
|
||||
-- fault management & monitoring functions
|
||||
|
||||
local function clear_fault() self.faulted = false end
|
||||
@ -131,31 +137,42 @@ local function peri_init(iface)
|
||||
|
||||
local mt = {
|
||||
__index = function (_, key)
|
||||
-- this will continuously be counting calls here as faults
|
||||
-- unlike other functions, faults here can't be cleared as it is just not defined
|
||||
if self.fault_counts[key] == nil then
|
||||
self.fault_counts[key] = 0
|
||||
-- try to find the function in case it was added (multiblock formed)
|
||||
local funcs = peripheral.wrap(iface)
|
||||
if (type(funcs) == "table") and (type(funcs[key]) == "function") then
|
||||
-- add this function then return it
|
||||
self.device[key] = protect_peri_function(key, funcs[key])
|
||||
log.info(util.c("PPM: [@", iface, "] initialized previously undefined field ", key, "()"))
|
||||
|
||||
return self.device[key]
|
||||
end
|
||||
|
||||
-- function failed
|
||||
self.faulted = true
|
||||
self.last_fault = UNDEFINED_FIELD
|
||||
-- function still missing, return an undefined function handler
|
||||
-- note: code should avoid storing functions for multiblocks and instead try to index them again
|
||||
return (function ()
|
||||
-- this will continuously be counting calls here as faults
|
||||
if self.fault_counts[key] == nil then self.fault_counts[key] = 0 end
|
||||
|
||||
ppm_sys.faulted = true
|
||||
ppm_sys.last_fault = UNDEFINED_FIELD
|
||||
-- function failed
|
||||
self.faulted = true
|
||||
self.last_fault = UNDEFINED_FIELD
|
||||
|
||||
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 calls]"
|
||||
ppm_sys.faulted = true
|
||||
ppm_sys.last_fault = UNDEFINED_FIELD
|
||||
|
||||
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 calls]"
|
||||
end
|
||||
|
||||
log.error(util.c("PPM: [@", iface, "] caught undefined function ", key, "()", count_str))
|
||||
end
|
||||
|
||||
log.error(util.c("PPM: caught undefined function ", key, "()", count_str))
|
||||
end
|
||||
self.fault_counts[key] = self.fault_counts[key] + 1
|
||||
|
||||
self.fault_counts[key] = self.fault_counts[key] + 1
|
||||
|
||||
return (function () return UNDEFINED_FIELD end)
|
||||
return ACCESS_FAULT, UNDEFINED_FIELD
|
||||
end)
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ local t_pack = table.pack
|
||||
local util = {}
|
||||
|
||||
-- scada-common version
|
||||
util.version = "1.1.18"
|
||||
util.version = "1.2.0"
|
||||
|
||||
util.TICK_TIME_S = 0.05
|
||||
util.TICK_TIME_MS = 50
|
||||
|
Reference in New Issue
Block a user