#540 display pocket connecting failure reasons

This commit is contained in:
Mikayla Fischler 2024-08-25 20:29:52 -04:00
parent b3be2d4bfc
commit 5a38acf2a7
6 changed files with 41 additions and 4 deletions

View File

@ -57,6 +57,9 @@ local function textbox(args)
for i = 1, #lines do for i = 1, #lines do
if i > e.frame.h then break end if i > e.frame.h then break end
-- trim leading/trailing whitespace
lines[i] = util.trim(lines[i])
local len = string.len(lines[i]) local len = string.len(lines[i])
-- use cursor position to align this line -- use cursor position to align this line

View File

@ -376,6 +376,12 @@ function iocontrol.report_link_state(state, sv_addr, api_addr)
end end
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) -- determine supervisor connection quality (trip time)
---@param trip_time integer ---@param trip_time integer
function iocontrol.report_svr_tt(trip_time) function iocontrol.report_svr_tt(trip_time)

View File

@ -686,6 +686,8 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
self.api.linked = true self.api.linked = true
self.api.addr = src_addr self.api.addr = src_addr
iocontrol.report_crd_link_error("")
if self.sv.linked then if self.sv.linked then
iocontrol.report_link_state(LINK_STATE.LINKED, nil, self.api.addr) iocontrol.report_link_state(LINK_STATE.LINKED, nil, self.api.addr)
else 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 self.api.last_est_ack ~= est_ack then
if est_ack == ESTABLISH_ACK.DENY then if est_ack == ESTABLISH_ACK.DENY then
log.info("coordinator connection denied") log.info("coordinator connection denied")
iocontrol.report_crd_link_error("denied")
elseif est_ack == ESTABLISH_ACK.COLLISION then elseif est_ack == ESTABLISH_ACK.COLLISION then
log.info("coordinator connection denied due to collision") log.info("coordinator connection denied due to collision")
iocontrol.report_crd_link_error("collision")
elseif est_ack == ESTABLISH_ACK.BAD_VERSION then elseif est_ack == ESTABLISH_ACK.BAD_VERSION then
log.info("coordinator comms version mismatch") log.info("coordinator comms version mismatch")
iocontrol.report_crd_link_error("comms version mismatch")
elseif est_ack == ESTABLISH_ACK.BAD_API_VERSION then elseif est_ack == ESTABLISH_ACK.BAD_API_VERSION then
log.info("coordinator api version mismatch") log.info("coordinator api version mismatch")
iocontrol.report_crd_link_error("API version mismatch")
else else
log.debug("coordinator SCADA_MGMT establish packet reply unsupported") log.debug("coordinator SCADA_MGMT establish packet reply unsupported")
iocontrol.report_crd_link_error("unknown reply")
end end
end end
@ -826,6 +833,8 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
self.sv.linked = true self.sv.linked = true
self.sv.addr = src_addr self.sv.addr = src_addr
iocontrol.report_svr_link_error("")
if self.api.linked then if self.api.linked then
iocontrol.report_link_state(LINK_STATE.LINKED, self.sv.addr, nil) iocontrol.report_link_state(LINK_STATE.LINKED, self.sv.addr, nil)
else 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 self.sv.last_est_ack ~= est_ack then
if est_ack == ESTABLISH_ACK.DENY then if est_ack == ESTABLISH_ACK.DENY then
log.info("supervisor connection denied") log.info("supervisor connection denied")
iocontrol.report_svr_link_error("denied")
elseif est_ack == ESTABLISH_ACK.COLLISION then elseif est_ack == ESTABLISH_ACK.COLLISION then
log.info("supervisor connection denied due to collision") log.info("supervisor connection denied due to collision")
iocontrol.report_svr_link_error("collision")
elseif est_ack == ESTABLISH_ACK.BAD_VERSION then elseif est_ack == ESTABLISH_ACK.BAD_VERSION then
log.info("supervisor comms version mismatch") log.info("supervisor comms version mismatch")
iocontrol.report_svr_link_error("comms version mismatch")
else else
log.debug("supervisor SCADA_MGMT establish packet reply unsupported") log.debug("supervisor SCADA_MGMT establish packet reply unsupported")
iocontrol.report_svr_link_error("unknown reply")
end end
end end

View File

@ -20,7 +20,7 @@ local pocket = require("pocket.pocket")
local renderer = require("pocket.renderer") local renderer = require("pocket.renderer")
local threads = require("pocket.threads") 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 = util.println
local println_ts = util.println_ts local println_ts = util.println_ts

View File

@ -2,6 +2,8 @@
-- Connection Waiting Spinner -- Connection Waiting Spinner
-- --
local iocontrol = require("pocket.iocontrol")
local style = require("pocket.ui.style") local style = require("pocket.ui.style")
local core = require("graphics.core") 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} local root = Div{parent=parent,x=1,y=1}
-- bounding box div -- 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 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 if is_api then
WaitingAnim{parent=box,x=waiting_x,y=1,fg_bg=cpair(colors.blue,style.root.bkg)} 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 else
WaitingAnim{parent=box,x=waiting_x,y=1,fg_bg=cpair(colors.green,style.root.bkg)} 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 end
return root return root

View File

@ -110,6 +110,15 @@ function util.pad(str, n)
return t_concat{util.spaces(lpad), str, util.spaces(rpad)} return t_concat{util.spaces(lpad), str, util.spaces(rpad)}
end 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 -- wrap a string into a table of lines
---@nodiscard ---@nodiscard
---@param str string ---@param str string