#123 RTU startup without devices, fixed repeat RTU advert handling, added PPM virtual devices, fixed log out of space detection, updated RTU type conversion functions in comms
This commit is contained in:
@@ -642,6 +642,12 @@ function comms.rtu_t_to_unit_type(type)
|
||||
return RTU_UNIT_TYPES.TURBINE_VALVE
|
||||
elseif type == rtu_t.induction_matrix then
|
||||
return RTU_UNIT_TYPES.IMATRIX
|
||||
elseif type == rtu_t.sps then
|
||||
return RTU_UNIT_TYPES.SPS
|
||||
elseif type == rtu_t.sna then
|
||||
return RTU_UNIT_TYPES.SNA
|
||||
elseif type == rtu_t.env_detector then
|
||||
return RTU_UNIT_TYPES.ENV_DETECTOR
|
||||
end
|
||||
|
||||
return nil
|
||||
@@ -659,6 +665,12 @@ function comms.advert_type_to_rtu_t(utype)
|
||||
return rtu_t.turbine_valve
|
||||
elseif utype == RTU_UNIT_TYPES.IMATRIX then
|
||||
return rtu_t.induction_matrix
|
||||
elseif utype == RTU_UNIT_TYPES.SPS then
|
||||
return rtu_t.sps
|
||||
elseif utype == RTU_UNIT_TYPES.SNA then
|
||||
return rtu_t.sna
|
||||
elseif utype == RTU_UNIT_TYPES.ENV_DETECTOR then
|
||||
return rtu_t.env_detector
|
||||
end
|
||||
|
||||
return nil
|
||||
|
||||
@@ -58,6 +58,7 @@ end
|
||||
-- private log write function
|
||||
---@param msg string
|
||||
local function _log(msg)
|
||||
local out_of_space = false
|
||||
local time_stamp = os.date("[%c] ")
|
||||
local stamped = time_stamp .. util.strval(msg)
|
||||
|
||||
@@ -69,15 +70,17 @@ local function _log(msg)
|
||||
|
||||
-- if we don't have space, we need to create a new log file
|
||||
|
||||
if not status then
|
||||
if result == "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
|
||||
elseif result ~= nil then
|
||||
else
|
||||
util.println("unknown error writing to logfile: " .. result)
|
||||
end
|
||||
end
|
||||
|
||||
if (result == "Out of space") or (free_space(_log_sys.path) < 100) then
|
||||
if out_of_space or (free_space(_log_sys.path) < 100) then
|
||||
-- delete the old log file and open a new one
|
||||
_log_sys.file.close()
|
||||
fs.delete(_log_sys.path)
|
||||
|
||||
@@ -12,8 +12,11 @@ local ACCESS_FAULT = nil ---@type nil
|
||||
|
||||
local UNDEFINED_FIELD = "undefined field"
|
||||
|
||||
local VIRTUAL_DEVICE_TYPE = "ppm_vdev"
|
||||
|
||||
ppm.ACCESS_FAULT = ACCESS_FAULT
|
||||
ppm.UNDEFINED_FIELD = UNDEFINED_FIELD
|
||||
ppm.VIRTUAL_DEVICE_TYPE = VIRTUAL_DEVICE_TYPE
|
||||
|
||||
----------------------------
|
||||
-- PRIVATE DATA/FUNCTIONS --
|
||||
@@ -23,6 +26,7 @@ local REPORT_FREQUENCY = 20 -- log every 20 faults per function
|
||||
|
||||
local _ppm_sys = {
|
||||
mounts = {},
|
||||
next_vid = 0,
|
||||
auto_cf = false,
|
||||
faulted = false,
|
||||
last_fault = "",
|
||||
@@ -42,10 +46,15 @@ local function peri_init(iface)
|
||||
last_fault = "",
|
||||
fault_counts = {},
|
||||
auto_cf = true,
|
||||
type = peripheral.getType(iface),
|
||||
device = peripheral.wrap(iface)
|
||||
type = VIRTUAL_DEVICE_TYPE,
|
||||
device = {}
|
||||
}
|
||||
|
||||
if iface ~= "__virtual__" then
|
||||
self.type = peripheral.getType(iface)
|
||||
self.device = peripheral.wrap(iface)
|
||||
end
|
||||
|
||||
-- initialization process (re-map)
|
||||
|
||||
for key, func in pairs(self.device) do
|
||||
@@ -245,6 +254,19 @@ function ppm.mount(iface)
|
||||
return pm_type, pm_dev
|
||||
end
|
||||
|
||||
-- mount a virtual, placeholder device (specifically designed for RTU startup with missing devices)
|
||||
---@return string type, table device
|
||||
function ppm.mount_virtual()
|
||||
local iface = "ppm_vdev_" .. _ppm_sys.next_vid
|
||||
|
||||
_ppm_sys.mounts[iface] = peri_init("__virtual__")
|
||||
_ppm_sys.next_vid = _ppm_sys.next_vid + 1
|
||||
|
||||
log.info(util.c("PPM: mount_virtual() -> allocated new virtual device ", iface))
|
||||
|
||||
return _ppm_sys.mounts[iface].type, _ppm_sys.mounts[iface].dev
|
||||
end
|
||||
|
||||
-- manually unmount a peripheral from the PPM
|
||||
---@param device table device table
|
||||
function ppm.unmount(device)
|
||||
|
||||
Reference in New Issue
Block a user