#367 WIP listing ID check failures and missing devices

This commit is contained in:
Mikayla Fischler 2024-08-18 23:04:44 -04:00
parent 072613959c
commit 4775639245
4 changed files with 66 additions and 9 deletions

View File

@ -19,7 +19,7 @@ local cpair = core.cpair
---@param parent graphics_element parent
---@param unit unit_session RTU session
---@param fail_code integer failure code
local function init(parent, unit, fail_code)
local function init(parent, unit, fail_code, cmp_id)
local s_hi_box = style.theme.highlight_box
local label_fg = style.fp.label_fg
@ -28,9 +28,27 @@ local function init(parent, unit, fail_code)
local root = Div{parent=parent,x=2,y=2,height=4,width=parent.get_width()-2,hidden=true}
local entry = Div{parent=root,x=2,y=1,height=3,fg_bg=style.theme.highlight_box_bright}
TextBox{parent=entry,x=1,y=1,text="",width=8,fg_bg=s_hi_box}
if fail_code == 1 then
TextBox{parent=entry,y=1,text="",width=11,fg_bg=cpair(colors.black,colors.orange)}
TextBox{parent=entry,text="BAD INDEX",alignment=ALIGN.CENTER,width=11,nav_active=cpair(colors.black,colors.orange)}
TextBox{parent=entry,text="",width=11,fg_bg=cpair(colors.black,colors.orange)}
elseif fail_code == 2 then
TextBox{parent=entry,y=1,text="",width=11,fg_bg=cpair(colors.black,colors.red)}
TextBox{parent=entry,text="DUPLICATE",alignment=ALIGN.CENTER,width=11,nav_active=cpair(colors.black,colors.red)}
TextBox{parent=entry,text="",width=11,fg_bg=cpair(colors.black,colors.red)}
elseif fail_code == 4 then
TextBox{parent=entry,y=1,text="",width=11,fg_bg=cpair(colors.black,colors.yellow)}
TextBox{parent=entry,text="MISSING",alignment=ALIGN.CENTER,width=11,nav_active=cpair(colors.black,colors.yellow)}
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)}
TextBox{parent=entry,x=1,y=3,text="",width=8,fg_bg=s_hi_box}
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}

View File

@ -111,13 +111,14 @@ end
-- add a device ID check failure entry to the CHK list
---@param unit unit_session RTU session
---@param fail_code integer failure code
function pgi.create_chk_entry(unit, fail_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)
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)
local success, result = pcall(data.chk_entry, data.chk_list, unit, fail_code, cmd_id)
if success then
data.entries.chk[gw_session][unit.get_unit_id()] = result

View File

@ -4,7 +4,8 @@ local util = require("scada-common.util")
local databus = require("supervisor.databus")
local facility = require("supervisor.facility")
local pgi = require("supervisor.pgi")
local pgi = require("supervisor.panel.pgi")
local coordinator = require("supervisor.session.coordinator")
local plc = require("supervisor.session.plc")
@ -39,7 +40,7 @@ local self = {
facility = nil, ---@type facility|nil
sessions = { rtu = {}, plc = {}, crd = {}, pdg = {} },
next_ids = { rtu = 0, plc = 0, crd = 0, pdg = 0 },
dev_dbg = { duplicate = {}, out_of_range = {} }
dev_dbg = { duplicate = {}, out_of_range = {}, connected = {} }
}
---@alias sv_session_structs plc_session_struct|rtu_session_struct|crd_session_struct|pdg_session_struct
@ -197,6 +198,14 @@ local function _update_dev_dbg()
util.filter_table(self.dev_dbg.duplicate, f, pgi.delete_chk_entry)
util.filter_table(self.dev_dbg.out_of_range, f, pgi.delete_chk_entry)
local conns = self.dev_dbg.connected
local units = self.facility.get_units()
for i = 1, #units do
local unit = units[i] ---@type reactor_unit
local rtus = unit.check_rtu_conns()
end
end
-- SHARED FUNCTIONS --
@ -229,7 +238,7 @@ local function check_rtu_id(unit, list, max)
end
-- add to the list for the user
if fail_code > 0 then
if fail_code > 0 and fail_code ~= 3 then
local cmp_id
for i = 1, #self.sessions.rtu do
@ -257,6 +266,12 @@ function svsessions.init(nic, fp_ok, config, cooling_conf)
self.fp_ok = fp_ok
self.config = config
self.facility = facility.new(config, cooling_conf, check_rtu_id)
-- initialize connection tracking table
self.dev_dbg.connected = { imatrix = nil, sps = nil, tanks = {}, units = {} }
for i = 1, config.UnitCount do
self.dev_dbg.connected.units[i] = { boilers = {}, turbines = {}, tanks = {} }
end
end
-- find an RTU session by the computer ID

View File

@ -912,6 +912,29 @@ function unit.new(reactor_id, num_boilers, num_turbines, check_rtu_id, ext_idle)
return rate or 0
end
-- check which RTUs are connected
---@nodiscard
function public.check_rtu_conns()
local conns = {}
conns.boilers = {}
for i = 1, #self.boilers do
conns.boilers[self.boilers[i].get_device_idx()] = true
end
conns.turbines = {}
for i = 1, #self.turbines do
conns.turbines[self.turbines[i].get_device_idx()] = true
end
conns.tanks = {}
for i = 1, #self.tanks do
conns.tanks[self.tanks[i].get_device_idx()] = true
end
return conns
end
-- get RTU statuses
---@nodiscard
function public.get_rtu_statuses()