Merge branch 'devel' into 479-sodium-emergency-coolant
This commit is contained in:
commit
909bd78912
@ -31,7 +31,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
|
|||||||
local sps_rtu = require("rtu.dev.sps_rtu")
|
local sps_rtu = require("rtu.dev.sps_rtu")
|
||||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||||
|
|
||||||
local RTU_VERSION = "v1.10.19"
|
local RTU_VERSION = "v1.10.20"
|
||||||
|
|
||||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
||||||
local RTU_HW_STATE = databus.RTU_HW_STATE
|
local RTU_HW_STATE = databus.RTU_HW_STATE
|
||||||
@ -428,7 +428,7 @@ local function main()
|
|||||||
if not formed then
|
if not formed then
|
||||||
if formed == false then
|
if formed == false then
|
||||||
log.info(util.c("sys_config> device '", name, "' is not formed"))
|
log.info(util.c("sys_config> device '", name, "' is not formed"))
|
||||||
end
|
else formed = false end
|
||||||
elseif faulted then
|
elseif faulted then
|
||||||
-- sometimes there is a race condition on server boot where it reports formed, but
|
-- sometimes there is a race condition on server boot where it reports formed, but
|
||||||
-- the other functions are not yet defined (that's the theory at least). mark as unformed to attempt connection later
|
-- the other functions are not yet defined (that's the theory at least). mark as unformed to attempt connection later
|
||||||
@ -458,7 +458,7 @@ local function main()
|
|||||||
|
|
||||||
table.insert(units, rtu_unit)
|
table.insert(units, rtu_unit)
|
||||||
|
|
||||||
local for_message = "facility"
|
local for_message = "the facility"
|
||||||
if for_reactor > 0 then
|
if for_reactor > 0 then
|
||||||
for_message = util.c("reactor ", for_reactor)
|
for_message = util.c("reactor ", for_reactor)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -486,7 +486,9 @@ function threads.thread__unit_comms(smem, unit)
|
|||||||
|
|
||||||
local last_f_check = 0
|
local last_f_check = 0
|
||||||
|
|
||||||
local detail_name = util.c(types.rtu_type_to_string(unit.type), " (", unit.name, ") [", unit.index, "] for reactor ", unit.reactor)
|
local detail_name = util.c(types.rtu_type_to_string(unit.type), " (", unit.name, ") ",
|
||||||
|
util.trinary(unit.index == false, "", util.c("[", unit.index, "] ")), "for ",
|
||||||
|
util.trinary(unit.reactor == 0, "the facility", util.c("reactor ", unit.reactor)))
|
||||||
local short_name = util.c(types.rtu_type_to_string(unit.type), " (", unit.name, ")")
|
local short_name = util.c(types.rtu_type_to_string(unit.type), " (", unit.name, ")")
|
||||||
|
|
||||||
if packet_queue == nil then
|
if packet_queue == nil then
|
||||||
|
|||||||
@ -8,6 +8,10 @@ local util = require("scada-common.util")
|
|||||||
local DBG_TAG, INF_TAG, WRN_TAG, ERR_TAG, FTL_TAG = "[DBG] ", "[INF] ", "[WRN] ", "[ERR] ", "[FTL] "
|
local DBG_TAG, INF_TAG, WRN_TAG, ERR_TAG, FTL_TAG = "[DBG] ", "[INF] ", "[WRN] ", "[ERR] ", "[FTL] "
|
||||||
local COLON, FUNC, ARROW = ":", "():", " > "
|
local COLON, FUNC, ARROW = ":", "():", " > "
|
||||||
|
|
||||||
|
local MIN_SPACE = 512
|
||||||
|
local OUT_OF_SPACE = "Out of space"
|
||||||
|
local TIME_FMT = "%F %T "
|
||||||
|
|
||||||
---@class logger
|
---@class logger
|
||||||
local log = {}
|
local log = {}
|
||||||
|
|
||||||
@ -34,13 +38,19 @@ local free_space = fs.getFreeSpace
|
|||||||
-- PRIVATE FUNCTIONS --
|
-- PRIVATE FUNCTIONS --
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
-- check if the provided error indicates out of space or if insufficient space available
|
||||||
|
---@param err_msg string|nil error message
|
||||||
|
---@return boolean out_of_space
|
||||||
|
local function check_out_of_space(err_msg)
|
||||||
|
return (free_space(logger.path) < MIN_SPACE) or ((err_msg ~= nil) and (string.find(err_msg, OUT_OF_SPACE) ~= nil))
|
||||||
|
end
|
||||||
|
|
||||||
-- private log write function
|
-- private log write function
|
||||||
---@param msg_bits any[]
|
---@param msg_bits any[]
|
||||||
local function _log(msg_bits)
|
local function _log(msg_bits)
|
||||||
if logger.not_ready then return end
|
if logger.not_ready then return end
|
||||||
|
|
||||||
local out_of_space = false
|
local time_stamp = os.date(TIME_FMT)
|
||||||
local time_stamp = os.date("[%c] ")
|
|
||||||
local stamped = util.c(time_stamp, table.unpack(msg_bits))
|
local stamped = util.c(time_stamp, table.unpack(msg_bits))
|
||||||
|
|
||||||
-- attempt to write log
|
-- attempt to write log
|
||||||
@ -50,18 +60,7 @@ local function _log(msg_bits)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- if we don't have space, we need to create a new log file
|
-- if we don't have space, we need to create a new log file
|
||||||
|
if check_out_of_space() then
|
||||||
if (not status) and (result ~= nil) then
|
|
||||||
out_of_space = string.find(result, "Out of space") ~= nil
|
|
||||||
|
|
||||||
if out_of_space then
|
|
||||||
-- will delete log file
|
|
||||||
else
|
|
||||||
util.println("unknown error writing to logfile: " .. result)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if out_of_space or (free_space(logger.path) < 512) then
|
|
||||||
-- delete the old log file before opening a new one
|
-- delete the old log file before opening a new one
|
||||||
logger.file.close()
|
logger.file.close()
|
||||||
fs.delete(logger.path)
|
fs.delete(logger.path)
|
||||||
@ -69,10 +68,12 @@ local function _log(msg_bits)
|
|||||||
-- re-init logger and pass dmesg_out so that it doesn't change
|
-- re-init logger and pass dmesg_out so that it doesn't change
|
||||||
log.init(logger.path, logger.mode, logger.debug, logger.dmesg_out)
|
log.init(logger.path, logger.mode, logger.debug, logger.dmesg_out)
|
||||||
|
|
||||||
-- leave a message
|
-- log the message and recycle warning
|
||||||
logger.file.writeLine(time_stamp .. "recycled log file")
|
logger.file.writeLine(time_stamp .. WRN_TAG .. "recycled log file")
|
||||||
logger.file.writeLine(stamped)
|
logger.file.writeLine(stamped)
|
||||||
logger.file.flush()
|
logger.file.flush()
|
||||||
|
elseif (not status) and (result ~= nil) then
|
||||||
|
util.println("unexpected error writing to the log file: " .. result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -86,15 +87,12 @@ end
|
|||||||
---@param include_debug boolean whether or not to include debug logs
|
---@param include_debug boolean whether or not to include debug logs
|
||||||
---@param dmesg_redirect? Redirect terminal/window to direct dmesg to
|
---@param dmesg_redirect? Redirect terminal/window to direct dmesg to
|
||||||
function log.init(path, write_mode, include_debug, dmesg_redirect)
|
function log.init(path, write_mode, include_debug, dmesg_redirect)
|
||||||
|
local err_msg
|
||||||
|
|
||||||
logger.path = path
|
logger.path = path
|
||||||
logger.mode = write_mode
|
logger.mode = write_mode
|
||||||
logger.debug = include_debug
|
logger.debug = include_debug
|
||||||
|
logger.file, err_msg = fs.open(path, util.trinary(logger.mode == MODE.APPEND, "a", "w"))
|
||||||
if logger.mode == MODE.APPEND then
|
|
||||||
logger.file = fs.open(path, "a")
|
|
||||||
else
|
|
||||||
logger.file = fs.open(path, "w")
|
|
||||||
end
|
|
||||||
|
|
||||||
if dmesg_redirect then
|
if dmesg_redirect then
|
||||||
logger.dmesg_out = dmesg_redirect
|
logger.dmesg_out = dmesg_redirect
|
||||||
@ -102,6 +100,25 @@ function log.init(path, write_mode, include_debug, dmesg_redirect)
|
|||||||
logger.dmesg_out = term.current()
|
logger.dmesg_out = term.current()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- check for space issues
|
||||||
|
local out_of_space = check_out_of_space(err_msg)
|
||||||
|
|
||||||
|
-- try to handle problems
|
||||||
|
if logger.file == nil or out_of_space then
|
||||||
|
if out_of_space then
|
||||||
|
if fs.exists(logger.path) then
|
||||||
|
fs.delete(logger.path)
|
||||||
|
|
||||||
|
logger.file, err_msg = fs.open(path, util.trinary(logger.mode == MODE.APPEND, "a", "w"))
|
||||||
|
|
||||||
|
if logger.file then
|
||||||
|
logger.file.writeLine(os.date(TIME_FMT) .. WRN_TAG .. "init recycled log file")
|
||||||
|
logger.file.flush()
|
||||||
|
else error("failed to setup the log file: " .. err_msg) end
|
||||||
|
else error("failed to make space for the log file, please delete unused files") end
|
||||||
|
else error("unexpected error setting up the log file: " .. err_msg) end
|
||||||
|
end
|
||||||
|
|
||||||
logger.not_ready = false
|
logger.not_ready = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ local t_pack = table.pack
|
|||||||
local util = {}
|
local util = {}
|
||||||
|
|
||||||
-- scada-common version
|
-- scada-common version
|
||||||
util.version = "1.4.8"
|
util.version = "1.4.10"
|
||||||
|
|
||||||
util.TICK_TIME_S = 0.05
|
util.TICK_TIME_S = 0.05
|
||||||
util.TICK_TIME_MS = 50
|
util.TICK_TIME_MS = 50
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user