#367 logic for missing device detection and user-friendly messages
This commit is contained in:
@@ -2,14 +2,12 @@
|
||||
-- RTU ID Check Failure Entry
|
||||
--
|
||||
|
||||
local databus = require("supervisor.databus")
|
||||
local style = require("supervisor.panel.style")
|
||||
|
||||
local style = require("supervisor.panel.style")
|
||||
local core = require("graphics.core")
|
||||
|
||||
local core = require("graphics.core")
|
||||
|
||||
local Div = require("graphics.elements.div")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
local Div = require("graphics.elements.div")
|
||||
local TextBox = require("graphics.elements.textbox")
|
||||
|
||||
local ALIGN = core.ALIGN
|
||||
|
||||
@@ -17,9 +15,9 @@ local cpair = core.cpair
|
||||
|
||||
-- create an ID check list entry
|
||||
---@param parent graphics_element parent
|
||||
---@param unit unit_session RTU session
|
||||
---@param msg string message
|
||||
---@param fail_code integer failure code
|
||||
local function init(parent, unit, fail_code, cmp_id)
|
||||
local function init(parent, msg, fail_code, cmp_id)
|
||||
local s_hi_box = style.theme.highlight_box
|
||||
|
||||
local label_fg = style.fp.label_fg
|
||||
@@ -42,17 +40,13 @@ local function init(parent, unit, fail_code, cmp_id)
|
||||
TextBox{parent=entry,text="",width=11,fg_bg=cpair(colors.black,colors.yellow)}
|
||||
end
|
||||
|
||||
if fail_code ~= 4 and cmp_id then
|
||||
local rtu_addr = TextBox{parent=entry,x=1,y=2,text="@ C ??",alignment=ALIGN.CENTER,width=8,fg_bg=s_hi_box,nav_active=cpair(colors.gray,colors.black)}
|
||||
if fail_code == 4 then
|
||||
TextBox{parent=entry,x=13,y=2,text=msg}
|
||||
else
|
||||
TextBox{parent=entry,x=13,y=2,text="@ C "..cmp_id,alignment=ALIGN.CENTER,width=8,fg_bg=s_hi_box,nav_active=cpair(colors.gray,colors.black)}
|
||||
TextBox{parent=entry,x=21,y=2,text=msg}
|
||||
end
|
||||
|
||||
if fail_code ~= 4 and cmp_id then
|
||||
local rtu_addr = TextBox{parent=entry,x=1,y=2,text="@ C ??",alignment=ALIGN.CENTER,width=8,fg_bg=s_hi_box,nav_active=cpair(colors.gray,colors.black)}
|
||||
end
|
||||
|
||||
TextBox{parent=entry,x=21,y=2,text="FW:",width=3}
|
||||
local rtu_fw_v = TextBox{parent=entry,x=25,y=2,text=" ------- ",width=9,fg_bg=label_fg}
|
||||
|
||||
return root
|
||||
end
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ local data = {
|
||||
pdg_entry = nil, ---@type function
|
||||
chk_entry = nil, ---@type function
|
||||
-- list entries
|
||||
entries = { rtu = {}, pdg = {}, chk = {} }
|
||||
entries = { rtu = {}, pdg = {}, chk = {}, missing = {} }
|
||||
}
|
||||
|
||||
-- link list boxes
|
||||
@@ -111,14 +111,15 @@ end
|
||||
-- add a device ID check failure entry to the CHK list
|
||||
---@param unit unit_session RTU session
|
||||
---@param fail_code integer failure code
|
||||
---@param cmp_id integer|nil computer ID if this isn't a 'missing' entry
|
||||
function pgi.create_chk_entry(unit, fail_code, cmp_id)
|
||||
---@param cmp_id integer computer ID
|
||||
---@param msg string description to show the user
|
||||
function pgi.create_chk_entry(unit, fail_code, cmp_id, msg)
|
||||
local gw_session = unit.get_session_id()
|
||||
|
||||
if data.chk_list ~= nil and data.chk_entry ~= nil then
|
||||
if not data.entries.chk[gw_session] then data.entries.chk[gw_session] = {} end
|
||||
|
||||
local success, result = pcall(data.chk_entry, data.chk_list, unit, fail_code, cmd_id)
|
||||
local success, result = pcall(data.chk_entry, data.chk_list, msg, fail_code, cmp_id)
|
||||
|
||||
if success then
|
||||
data.entries.chk[gw_session][unit.get_unit_id()] = result
|
||||
@@ -149,4 +150,36 @@ function pgi.delete_chk_entry(unit)
|
||||
end
|
||||
end
|
||||
|
||||
-- add a device ID missing entry to the CHK list
|
||||
---@param message string missing device message
|
||||
function pgi.create_missing_entry(message)
|
||||
if data.chk_list ~= nil and data.chk_entry ~= nil then
|
||||
local success, result = pcall(data.chk_entry, data.chk_list, message, 4, -1)
|
||||
|
||||
if success then
|
||||
data.entries.missing[message] = result
|
||||
log.debug(util.c("PGI: created missing CHK entry (", message, ")"))
|
||||
else
|
||||
log.error(util.c("PGI: failed to create missing CHK entry (", result, ")"), true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- delete a device ID missing entry from the CHK list
|
||||
---@param message string missing device message
|
||||
function pgi.delete_missing_entry(message)
|
||||
if data.entries.missing[message] ~= nil then
|
||||
local success, result = pcall(data.entries.missing[message].delete)
|
||||
data.entries.missing[message] = nil
|
||||
|
||||
if success then
|
||||
log.debug(util.c("PGI: deleted missing CHK entry \"", message, "\""))
|
||||
else
|
||||
log.error(util.c("PGI: failed to delete missing CHK entry (", result, ")"), true)
|
||||
end
|
||||
else
|
||||
log.warning(util.c("PGI: tried to delete unknown missing CHK entry \"", message, "\""))
|
||||
end
|
||||
end
|
||||
|
||||
return pgi
|
||||
|
||||
Reference in New Issue
Block a user