pocket signal bars

This commit is contained in:
Mikayla Fischler
2024-01-14 14:20:59 -05:00
parent 03de90c3d8
commit d5d818e625
7 changed files with 136 additions and 12 deletions

View File

@@ -8,13 +8,11 @@ local types = require("scada-common.types")
local ALARM = types.ALARM
local iocontrol = {}
---@todo nominal trip time is ping (0ms to 10ms usually)
local WARN_TT = 40
local HIGH_TT = 80
---@class pocket_ioctl
local io = {
nav_root = nil, ---@type nav_tree_node
ps = psil.create()
}
local iocontrol = {}
---@enum POCKET_LINK_STATE
local LINK_STATE = {
@@ -26,6 +24,12 @@ local LINK_STATE = {
iocontrol.LINK_STATE = LINK_STATE
---@class pocket_ioctl
local io = {
nav_root = nil, ---@type nav_tree_node
ps = psil.create()
}
---@class nav_tree_node
---@field _p nav_tree_node|nil page's parent
---@field _c table page's children
@@ -161,7 +165,43 @@ function iocontrol.init_fac() end
-- set network link state
---@param state POCKET_LINK_STATE
function iocontrol.report_link_state(state) io.ps.publish("link_state", state) end
function iocontrol.report_link_state(state)
io.ps.publish("link_state", state)
if state == LINK_STATE.API_LINK_ONLY or state == LINK_STATE.UNLINKED then
io.ps.publish("svr_conn_quality", 0)
end
if state == LINK_STATE.SV_LINK_ONLY or state == LINK_STATE.UNLINKED then
io.ps.publish("crd_conn_quality", 0)
end
end
-- determine supervisor connection quality (trip time)
---@param trip_time integer
function iocontrol.report_svr_tt(trip_time)
local state = 3
if trip_time > HIGH_TT then
state = 1
elseif trip_time > WARN_TT then
state = 2
end
io.ps.publish("svr_conn_quality", state)
end
-- determine coordinator connection quality (trip time)
---@param trip_time integer
function iocontrol.report_crd_tt(trip_time)
local state = 3
if trip_time > HIGH_TT then
state = 1
elseif trip_time > WARN_TT then
state = 2
end
io.ps.publish("crd_conn_quality", state)
end
-- get the IO controller database
function iocontrol.get_db() return io end

View File

@@ -250,9 +250,11 @@ function pocket.comms(version, nic, pkt_channel, svr_channel, crd_channel, range
log.warning("pocket coordinator KEEP_ALIVE trip time > 750ms (" .. trip_time .. "ms)")
end
-- log.debug("pocket coordinator RTT = " .. trip_time .. "ms")
log.debug("pocket coordinator TT = " .. trip_time .. "ms")
_send_api_keep_alive_ack(timestamp)
iocontrol.report_crd_tt(trip_time)
else
log.debug("coordinator SCADA keep alive packet length mismatch")
end
@@ -340,9 +342,11 @@ function pocket.comms(version, nic, pkt_channel, svr_channel, crd_channel, range
log.warning("pocket supervisor KEEP_ALIVE trip time > 750ms (" .. trip_time .. "ms)")
end
-- log.debug("pocket supervisor RTT = " .. trip_time .. "ms")
log.debug("pocket supervisor TT = " .. trip_time .. "ms")
_send_sv_keep_alive_ack(timestamp)
iocontrol.report_svr_tt(trip_time)
else
log.debug("supervisor SCADA keep alive packet length mismatch")
end

View File

@@ -24,6 +24,8 @@ local TextBox = require("graphics.elements.textbox")
local PushButton = require("graphics.elements.controls.push_button")
local Sidebar = require("graphics.elements.controls.sidebar")
local SignalBar = require("graphics.elements.indicators.signal")
local LINK_STATE = iocontrol.LINK_STATE
local ALIGN = core.ALIGN
@@ -36,7 +38,12 @@ local function init(main)
local db = iocontrol.get_db()
-- window header message
TextBox{parent=main,y=1,text="ALPHA APP - INCOMPLETE",alignment=ALIGN.CENTER,height=1,fg_bg=style.header}
TextBox{parent=main,y=1,text="DEV ALPHA APP S C ",alignment=ALIGN.LEFT,height=1,fg_bg=style.header}
local svr_conn = SignalBar{parent=main,y=1,x=20,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.white,colors.gray)}
local crd_conn = SignalBar{parent=main,y=1,x=24,colors_low_med=cpair(colors.red,colors.yellow),disconnect_color=colors.lightGray,fg_bg=cpair(colors.white,colors.gray)}
db.ps.subscribe("svr_conn_quality", svr_conn.set_value)
db.ps.subscribe("crd_conn_quality", crd_conn.set_value)
--#region root panel panes (connection screens + main screen)