diff --git a/coordinator/config.lua b/coordinator/config.lua index 8e12c53..3196e80 100644 --- a/coordinator/config.lua +++ b/coordinator/config.lua @@ -28,5 +28,7 @@ config.LOG_PATH = "/log.txt" -- 0 = APPEND (adds to existing file on start) -- 1 = NEW (replaces existing file on start) config.LOG_MODE = 0 +-- true to log verbose debug messages +config.LOG_DEBUG = false return config diff --git a/coordinator/startup.lua b/coordinator/startup.lua index d9d5160..2944c14 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -50,6 +50,7 @@ cfv.assert_type_num(config.SOUNDER_VOLUME) cfv.assert_type_bool(config.TIME_24_HOUR) cfv.assert_type_str(config.LOG_PATH) cfv.assert_type_int(config.LOG_MODE) +cfv.assert_type_bool(config.LOG_DEBUG) assert(cfv.valid(), "bad config file: missing/invalid fields") @@ -57,7 +58,7 @@ assert(cfv.valid(), "bad config file: missing/invalid fields") -- log init ---------------------------------------- -log.init(config.LOG_PATH, config.LOG_MODE) +log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG) log.info("========================================") log.info("BOOTING coordinator.startup " .. COORDINATOR_VERSION) diff --git a/pocket/config.lua b/pocket/config.lua index cacd9f1..27e1489 100644 --- a/pocket/config.lua +++ b/pocket/config.lua @@ -17,5 +17,7 @@ config.LOG_PATH = "/log.txt" -- 0 = APPEND (adds to existing file on start) -- 1 = NEW (replaces existing file on start) config.LOG_MODE = 0 +-- true to log verbose debug messages +config.LOG_DEBUG = false return config diff --git a/pocket/startup.lua b/pocket/startup.lua index 42752a8..9ed088c 100644 --- a/pocket/startup.lua +++ b/pocket/startup.lua @@ -36,6 +36,7 @@ cfv.assert_type_num(config.COMMS_TIMEOUT) cfv.assert_min(config.COMMS_TIMEOUT, 2) cfv.assert_type_str(config.LOG_PATH) cfv.assert_type_int(config.LOG_MODE) +cfv.assert_type_bool(config.LOG_DEBUG) assert(cfv.valid(), "bad config file: missing/invalid fields") @@ -43,7 +44,7 @@ assert(cfv.valid(), "bad config file: missing/invalid fields") -- log init ---------------------------------------- -log.init(config.LOG_PATH, config.LOG_MODE) +log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG) log.info("========================================") log.info("BOOTING pocket.startup " .. POCKET_VERSION) diff --git a/reactor-plc/config.lua b/reactor-plc/config.lua index e479ede..e402bbb 100644 --- a/reactor-plc/config.lua +++ b/reactor-plc/config.lua @@ -24,5 +24,7 @@ config.LOG_PATH = "/log.txt" -- 0 = APPEND (adds to existing file on start) -- 1 = NEW (replaces existing file on start) config.LOG_MODE = 0 +-- true to log verbose debug messages +config.LOG_DEBUG = false return config diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index afe733f..183fbf3 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -38,6 +38,7 @@ cfv.assert_type_num(config.COMMS_TIMEOUT) cfv.assert_min(config.COMMS_TIMEOUT, 2) cfv.assert_type_str(config.LOG_PATH) cfv.assert_type_int(config.LOG_MODE) +cfv.assert_type_bool(config.LOG_DEBUG) assert(cfv.valid(), "bad config file: missing/invalid fields") @@ -54,7 +55,7 @@ end -- log init ---------------------------------------- -log.init(config.LOG_PATH, config.LOG_MODE) +log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG) log.info("========================================") log.info("BOOTING reactor-plc.startup " .. R_PLC_VERSION) diff --git a/rtu/config.lua b/rtu/config.lua index 96b26ee..1b96bec 100644 --- a/rtu/config.lua +++ b/rtu/config.lua @@ -17,6 +17,8 @@ config.LOG_PATH = "/log.txt" -- 0 = APPEND (adds to existing file on start) -- 1 = NEW (replaces existing file on start) config.LOG_MODE = 0 +-- true to log verbose debug messages +config.LOG_DEBUG = false -- RTU peripheral devices (named: side/network device name) config.RTU_DEVICES = { diff --git a/rtu/startup.lua b/rtu/startup.lua index 8612d72..0693f9f 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -49,6 +49,7 @@ cfv.assert_type_num(config.COMMS_TIMEOUT) cfv.assert_min(config.COMMS_TIMEOUT, 2) cfv.assert_type_str(config.LOG_PATH) cfv.assert_type_int(config.LOG_MODE) +cfv.assert_type_bool(config.LOG_DEBUG) cfv.assert_type_table(config.RTU_DEVICES) cfv.assert_type_table(config.RTU_REDSTONE) assert(cfv.valid(), "bad config file: missing/invalid fields") @@ -57,7 +58,7 @@ assert(cfv.valid(), "bad config file: missing/invalid fields") -- log init ---------------------------------------- -log.init(config.LOG_PATH, config.LOG_MODE) +log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG) log.info("========================================") log.info("BOOTING rtu.startup " .. RTU_VERSION) diff --git a/scada-common/log.lua b/scada-common/log.lua index 40baef2..7e2d3fd 100644 --- a/scada-common/log.lua +++ b/scada-common/log.lua @@ -15,12 +15,10 @@ local MODE = { log.MODE = MODE --- whether to log debug messages or not -local LOG_DEBUG = true - -local log_sys = { +local logger = { path = "/log.txt", mode = MODE.APPEND, + debug = false, file = nil, dmesg_out = nil } @@ -41,8 +39,8 @@ local function _log(msg) -- attempt to write log local status, result = pcall(function () - log_sys.file.writeLine(stamped) - log_sys.file.flush() + logger.file.writeLine(stamped) + logger.file.flush() end) -- if we don't have space, we need to create a new log file @@ -57,18 +55,18 @@ local function _log(msg) end end - if out_of_space or (free_space(log_sys.path) < 100) then + if out_of_space or (free_space(logger.path) < 100) then -- delete the old log file before opening a new one - log_sys.file.close() - fs.delete(log_sys.path) + logger.file.close() + fs.delete(logger.path) -- re-init logger and pass dmesg_out so that it doesn't change - log.init(log_sys.path, log_sys.mode, log_sys.dmesg_out) + log.init(logger.path, logger.mode, logger.debug, logger.dmesg_out) -- leave a message - log_sys.file.writeLine(time_stamp .. "recycled log file") - log_sys.file.writeLine(stamped) - log_sys.file.flush() + logger.file.writeLine(time_stamp .. "recycled log file") + logger.file.writeLine(stamped) + logger.file.flush() end end @@ -78,33 +76,35 @@ end -- initialize logger ---@param path string file path ----@param write_mode MODE +---@param write_mode MODE file write mode +---@param include_debug boolean whether or not to include debug logs ---@param dmesg_redirect? table terminal/window to direct dmesg to -function log.init(path, write_mode, dmesg_redirect) - log_sys.path = path - log_sys.mode = write_mode +function log.init(path, write_mode, include_debug, dmesg_redirect) + logger.path = path + logger.mode = write_mode + logger.debug = include_debug - if log_sys.mode == MODE.APPEND then - log_sys.file = fs.open(path, "a") + if logger.mode == MODE.APPEND then + logger.file = fs.open(path, "a") else - log_sys.file = fs.open(path, "w") + logger.file = fs.open(path, "w") end if dmesg_redirect then - log_sys.dmesg_out = dmesg_redirect + logger.dmesg_out = dmesg_redirect else - log_sys.dmesg_out = term.current() + logger.dmesg_out = term.current() end end -- close the log file handle function log.close() - log_sys.file.close() + logger.file.close() end -- direct dmesg output to a monitor/window ---@param window table window or terminal reference -function log.direct_dmesg(window) log_sys.dmesg_out = window end +function log.direct_dmesg(window) logger.dmesg_out = window end -- dmesg style logging for boot because I like linux-y things ---@param msg string message @@ -120,7 +120,7 @@ function log.dmesg(msg, tag, tag_color) tag = util.strval(tag) local t_stamp = string.format("%12.2f", os.clock()) - local out = log_sys.dmesg_out + local out = logger.dmesg_out if out ~= nil then local out_w, out_h = out.getSize() @@ -216,7 +216,7 @@ end function log.dmesg_working(msg, tag, tag_color) local ts_coord = log.dmesg(msg, tag, tag_color) - local out = log_sys.dmesg_out + local out = logger.dmesg_out local width = (ts_coord.x2 - ts_coord.x1) + 1 if out ~= nil then @@ -275,7 +275,7 @@ end ---@param msg string message ---@param trace? boolean include file trace function log.debug(msg, trace) - if LOG_DEBUG then + if logger.debug then local dbg_info = "" if trace then diff --git a/supervisor/config.lua b/supervisor/config.lua index 0aa26d8..b716d38 100644 --- a/supervisor/config.lua +++ b/supervisor/config.lua @@ -28,5 +28,7 @@ config.LOG_PATH = "/log.txt" -- 0 = APPEND (adds to existing file on start) -- 1 = NEW (replaces existing file on start) config.LOG_MODE = 0 +-- true to log verbose debug messages +config.LOG_DEBUG = false return config diff --git a/supervisor/session/rtu.lua b/supervisor/session/rtu.lua index 96309a0..13460f6 100644 --- a/supervisor/session/rtu.lua +++ b/supervisor/session/rtu.lua @@ -118,26 +118,31 @@ function rtu.new_session(id, in_queue, out_queue, timeout, advertisement, facili if unit_advert.reactor > 0 then local target_unit = self.fac_units[unit_advert.reactor] ---@type reactor_unit + -- unit RTUs if u_type == RTU_UNIT_TYPE.REDSTONE then -- redstone unit = svrs_redstone.new(id, i, unit_advert, self.modbus_q) if type(unit) ~= "nil" then target_unit.add_redstone(unit) end elseif u_type == RTU_UNIT_TYPE.BOILER_VALVE then - -- boiler (Mekanism 10.1+) + -- boiler unit = svrs_boilerv.new(id, i, unit_advert, self.modbus_q) if type(unit) ~= "nil" then target_unit.add_boiler(unit) end elseif u_type == RTU_UNIT_TYPE.TURBINE_VALVE then - -- turbine (Mekanism 10.1+) + -- turbine unit = svrs_turbinev.new(id, i, unit_advert, self.modbus_q) if type(unit) ~= "nil" then target_unit.add_turbine(unit) end elseif u_type == RTU_UNIT_TYPE.ENV_DETECTOR then -- environment detector unit = svrs_envd.new(id, i, unit_advert, self.modbus_q) if type(unit) ~= "nil" then target_unit.add_envd(unit) end + elseif u_type == RTU_UNIT_TYPE.VIRTUAL then + -- skip virtual units + log.debug(util.c(log_header, "skipping virtual RTU unit #", i)) else log.error(util.c(log_header, "bad advertisement: encountered unsupported reactor-specific RTU type ", type_string)) end else + -- facility RTUs if u_type == RTU_UNIT_TYPE.REDSTONE then -- redstone unit = svrs_redstone.new(id, i, unit_advert, self.modbus_q) @@ -156,6 +161,9 @@ function rtu.new_session(id, in_queue, out_queue, timeout, advertisement, facili -- environment detector unit = svrs_envd.new(id, i, unit_advert, self.modbus_q) if type(unit) ~= "nil" then facility.add_envd(unit) end + elseif u_type == RTU_UNIT_TYPE.VIRTUAL then + -- skip virtual units + log.debug(util.c(log_header, "skipping virtual RTU unit #", i)) else log.error(util.c(log_header, "bad advertisement: encountered unsupported reactor-independent RTU type ", type_string)) end @@ -164,7 +172,7 @@ function rtu.new_session(id, in_queue, out_queue, timeout, advertisement, facili if unit ~= nil then table.insert(self.units, unit) - else + elseif u_type ~= RTU_UNIT_TYPE.VIRTUAL then _reset_config() log.error(util.c(log_header, "bad advertisement: error occured while creating a unit (type is ", type_string, ")")) break diff --git a/supervisor/startup.lua b/supervisor/startup.lua index f14236e..2e16777 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -14,7 +14,7 @@ local supervisor = require("supervisor.supervisor") local svsessions = require("supervisor.session.svsessions") -local SUPERVISOR_VERSION = "v0.15.6" +local SUPERVISOR_VERSION = "v0.15.7" local println = util.println local println_ts = util.println_ts @@ -40,6 +40,7 @@ cfv.assert_type_int(config.NUM_REACTORS) cfv.assert_type_table(config.REACTOR_COOLING) cfv.assert_type_str(config.LOG_PATH) cfv.assert_type_int(config.LOG_MODE) +cfv.assert_type_bool(config.LOG_DEBUG) assert(cfv.valid(), "bad config file: missing/invalid fields") @@ -61,7 +62,7 @@ end -- log init ---------------------------------------- -log.init(config.LOG_PATH, config.LOG_MODE) +log.init(config.LOG_PATH, config.LOG_MODE, config.LOG_DEBUG) log.info("========================================") log.info("BOOTING supervisor.startup " .. SUPERVISOR_VERSION)