Skip to content

Commit

Permalink
Merge pull request #541 from MikaylaFischler/pocket-alpha-dev
Browse files Browse the repository at this point in the history
display pocket connecting failure reasons
  • Loading branch information
MikaylaFischler authored Aug 26, 2024
2 parents b3be2d4 + ebeeecc commit fe1b916
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion graphics/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")

local core = {}

core.version = "2.3.2"
core.version = "2.3.3"

core.flasher = flasher
core.events = events
Expand Down
6 changes: 3 additions & 3 deletions graphics/element.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- Generic Graphics Element
--

local log = require("scada-common.log")
-- local log = require("scada-common.log")
local util = require("scada-common.util")

local core = require("graphics.core")
Expand Down Expand Up @@ -504,10 +504,10 @@ function element.new(args, constraint, child_offset_x, child_offset_y)

if args.parent ~= nil then
-- remove self from parent
log.debug("removing " .. self.id .. " from parent")
-- log.debug("removing " .. self.id .. " from parent")
args.parent.__remove_child(self.id)
else
log.debug("no parent for " .. self.id .. " on delete attempt")
-- log.debug("no parent for " .. self.id .. " on delete attempt")
end
end

Expand Down
10 changes: 5 additions & 5 deletions graphics/elements/listbox.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Scroll-able List Box Display Graphics Element

local log = require("scada-common.log")
-- local log = require("scada-common.log")
local tcd = require("scada-common.tcd")

local core = require("graphics.core")
Expand Down Expand Up @@ -153,7 +153,7 @@ local function listbox(args)
next_y = next_y + item.h + item_pad
item.e.reposition(1, item.y)
item.e.show()
log.debug("iterated " .. item.e.get_id())
-- log.debug("iterated " .. item.e.get_id())
end

content_height = next_y
Expand Down Expand Up @@ -212,7 +212,7 @@ local function listbox(args)
---@param child graphics_element child element
function e.on_added(id, child)
table.insert(list, { id = id, e = child, y = 0, h = child.get_height() })
log.debug("added child " .. id .. " into slot " .. #list)
-- log.debug("added child " .. id .. " into slot " .. #list)
update_positions()
end

Expand All @@ -222,12 +222,12 @@ local function listbox(args)
for idx, elem in ipairs(list) do
if elem.id == id then
table.remove(list, idx)
log.debug("removed child " .. id .. " from slot " .. idx)
-- log.debug("removed child " .. id .. " from slot " .. idx)
update_positions()
return
end
end
log.debug("failed to remove child " .. id)
-- log.debug("failed to remove child " .. id)
end

-- handle focus
Expand Down
3 changes: 3 additions & 0 deletions graphics/elements/textbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pocket/iocontrol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions pocket/pocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pocket/startup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions pocket/ui/components/conn_waiting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
-- Connection Waiting Spinner
--

local iocontrol = require("pocket.iocontrol")

local style = require("pocket.ui.style")

local core = require("graphics.core")
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions scada-common/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe1b916

Please sign in to comment.