From 5a38acf2a7a5f32eea23abd594a041e9c87d4d46 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sun, 25 Aug 2024 20:29:52 -0400 Subject: [PATCH] #540 display pocket connecting failure reasons --- graphics/elements/textbox.lua | 3 +++ pocket/iocontrol.lua | 6 ++++++ pocket/pocket.lua | 13 +++++++++++++ pocket/startup.lua | 2 +- pocket/ui/components/conn_waiting.lua | 12 +++++++++--- scada-common/util.lua | 9 +++++++++ 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/graphics/elements/textbox.lua b/graphics/elements/textbox.lua index 2a61860..a52d528 100644 --- a/graphics/elements/textbox.lua +++ b/graphics/elements/textbox.lua @@ -57,6 +57,9 @@ local function textbox(args) for i = 1, #lines do if i > e.frame.h then break end + -- trim leading/trailing whitespace + lines[i] = util.trim(lines[i]) + local len = string.len(lines[i]) -- use cursor position to align this line diff --git a/pocket/iocontrol.lua b/pocket/iocontrol.lua index aff9c17..d7964fb 100644 --- a/pocket/iocontrol.lua +++ b/pocket/iocontrol.lua @@ -376,6 +376,12 @@ function iocontrol.report_link_state(state, sv_addr, api_addr) end end +-- show the reason the supervisor connection isn't linking +function iocontrol.report_svr_link_error(msg) io.ps.publish("svr_link_msg", msg) end + +-- show the reason the coordinator api connection isn't linking +function iocontrol.report_crd_link_error(msg) io.ps.publish("api_link_msg", msg) end + -- determine supervisor connection quality (trip time) ---@param trip_time integer function iocontrol.report_svr_tt(trip_time) diff --git a/pocket/pocket.lua b/pocket/pocket.lua index dc9fa28..a8867fb 100644 --- a/pocket/pocket.lua +++ b/pocket/pocket.lua @@ -686,6 +686,8 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav) self.api.linked = true self.api.addr = src_addr + iocontrol.report_crd_link_error("") + if self.sv.linked then iocontrol.report_link_state(LINK_STATE.LINKED, nil, self.api.addr) else @@ -701,14 +703,19 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav) if self.api.last_est_ack ~= est_ack then if est_ack == ESTABLISH_ACK.DENY then log.info("coordinator connection denied") + iocontrol.report_crd_link_error("denied") elseif est_ack == ESTABLISH_ACK.COLLISION then log.info("coordinator connection denied due to collision") + iocontrol.report_crd_link_error("collision") elseif est_ack == ESTABLISH_ACK.BAD_VERSION then log.info("coordinator comms version mismatch") + iocontrol.report_crd_link_error("comms version mismatch") elseif est_ack == ESTABLISH_ACK.BAD_API_VERSION then log.info("coordinator api version mismatch") + iocontrol.report_crd_link_error("API version mismatch") else log.debug("coordinator SCADA_MGMT establish packet reply unsupported") + iocontrol.report_crd_link_error("unknown reply") end end @@ -826,6 +833,8 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav) self.sv.linked = true self.sv.addr = src_addr + iocontrol.report_svr_link_error("") + if self.api.linked then iocontrol.report_link_state(LINK_STATE.LINKED, self.sv.addr, nil) else @@ -835,12 +844,16 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav) if self.sv.last_est_ack ~= est_ack then if est_ack == ESTABLISH_ACK.DENY then log.info("supervisor connection denied") + iocontrol.report_svr_link_error("denied") elseif est_ack == ESTABLISH_ACK.COLLISION then log.info("supervisor connection denied due to collision") + iocontrol.report_svr_link_error("collision") elseif est_ack == ESTABLISH_ACK.BAD_VERSION then log.info("supervisor comms version mismatch") + iocontrol.report_svr_link_error("comms version mismatch") else log.debug("supervisor SCADA_MGMT establish packet reply unsupported") + iocontrol.report_svr_link_error("unknown reply") end end diff --git a/pocket/startup.lua b/pocket/startup.lua index d548b73..9bb49d7 100644 --- a/pocket/startup.lua +++ b/pocket/startup.lua @@ -20,7 +20,7 @@ local pocket = require("pocket.pocket") local renderer = require("pocket.renderer") local threads = require("pocket.threads") -local POCKET_VERSION = "v0.11.7-alpha" +local POCKET_VERSION = "v0.11.8-alpha" local println = util.println local println_ts = util.println_ts diff --git a/pocket/ui/components/conn_waiting.lua b/pocket/ui/components/conn_waiting.lua index 6b69650..b55f067 100644 --- a/pocket/ui/components/conn_waiting.lua +++ b/pocket/ui/components/conn_waiting.lua @@ -2,6 +2,8 @@ -- Connection Waiting Spinner -- +local iocontrol = require("pocket.iocontrol") + local style = require("pocket.ui.style") local core = require("graphics.core") @@ -23,16 +25,20 @@ local function init(parent, y, is_api) local root = Div{parent=parent,x=1,y=1} -- bounding box div - local box = Div{parent=root,x=1,y=y,height=6} + local box = Div{parent=root,x=1,y=y,height=12} local waiting_x = math.floor(parent.get_width() / 2) - 1 + local msg = TextBox{parent=box,x=3,y=11,width=box.get_width()-4,height=2,text="",alignment=ALIGN.CENTER,fg_bg=cpair(colors.red,style.root.bkg)} + if is_api then WaitingAnim{parent=box,x=waiting_x,y=1,fg_bg=cpair(colors.blue,style.root.bkg)} - TextBox{parent=box,text="Connecting to API",alignment=ALIGN.CENTER,y=5,fg_bg=cpair(colors.white,style.root.bkg)} + TextBox{parent=box,y=5,text="Connecting to API",alignment=ALIGN.CENTER,fg_bg=cpair(colors.white,style.root.bkg)} + msg.register(iocontrol.get_db().ps, "api_link_msg", msg.set_value) else WaitingAnim{parent=box,x=waiting_x,y=1,fg_bg=cpair(colors.green,style.root.bkg)} - TextBox{parent=box,text="Connecting to Supervisor",alignment=ALIGN.CENTER,y=5,fg_bg=cpair(colors.white,style.root.bkg)} + TextBox{parent=box,y=5,text="Connecting to Supervisor",alignment=ALIGN.CENTER,fg_bg=cpair(colors.white,style.root.bkg)} + msg.register(iocontrol.get_db().ps, "svr_link_msg", msg.set_value) end return root diff --git a/scada-common/util.lua b/scada-common/util.lua index b86f8bb..b4a5885 100644 --- a/scada-common/util.lua +++ b/scada-common/util.lua @@ -110,6 +110,15 @@ function util.pad(str, n) return t_concat{util.spaces(lpad), str, util.spaces(rpad)} end +-- trim leading and trailing whitespace +---@nodiscard +---@param s string text +---@return string +function util.trim(s) + local str = s:gsub("^%s*(.-)%s*$", "%1") + return str +end + -- wrap a string into a table of lines ---@nodiscard ---@param str string