Skip to content

Commit

Permalink
still display supervisor/coordinator address info if not linked to both
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaylaFischler committed Jul 27, 2024
1 parent d58a6a3 commit f00751e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
31 changes: 22 additions & 9 deletions pocket/iocontrol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ local io = {
ps = psil.create()
}

local config = nil ---@type pkt_config

-- initialize facility-independent components of pocket iocontrol
---@param comms pocket_comms
---@param nav pocket_nav
function iocontrol.init_core(comms, nav)
---@param cfg pkt_config
function iocontrol.init_core(comms, nav, cfg)
config = cfg

io.nav = nav

---@class pocket_ioctl_diag
Expand Down Expand Up @@ -89,10 +94,9 @@ function iocontrol.init_core(comms, nav)
end

-- initialize facility-dependent components of pocket iocontrol
---@param conf facility_conf configuration
---@param temp_scale TEMP_SCALE temperature unit
---@param energy_scale ENERGY_SCALE energy unit
function iocontrol.init_fac(conf, temp_scale, energy_scale)
---@param conf facility_conf facility configuration
function iocontrol.init_fac(conf)
local temp_scale, energy_scale = config.TempScale, config.EnergyScale
io.temp_label = TEMP_UNITS[temp_scale]
io.energy_label = ENERGY_UNITS[energy_scale]

Expand Down Expand Up @@ -346,8 +350,8 @@ end

-- set network link state
---@param state POCKET_LINK_STATE
---@param sv_addr integer? supervisor address if linked
---@param api_addr integer? coordinator address if linked
---@param sv_addr integer|false|nil supervisor address if linked, nil if unchanged, false if unlinked
---@param api_addr integer|false|nil coordinator address if linked, nil if unchanged, false if unlinked
function iocontrol.report_link_state(state, sv_addr, api_addr)
io.ps.publish("link_state", state)

Expand All @@ -359,8 +363,17 @@ function iocontrol.report_link_state(state, sv_addr, api_addr)
io.ps.publish("crd_conn_quality", 0)
end

if sv_addr then io.ps.publish("sv_addr", sv_addr) end
if api_addr then io.ps.publish("api_addr", api_addr) end
if sv_addr then
io.ps.publish("sv_addr", util.c(sv_addr, ":", config.SVR_Channel))
elseif sv_addr == false then
io.ps.publish("sv_addr", "unknown (not linked)")
end

if api_addr then
io.ps.publish("api_addr", util.c(api_addr, ":", config.CRD_Channel))
elseif api_addr == false then
io.ps.publish("api_addr", "unknown (not linked)")
end
end

-- determine supervisor connection quality (trip time)
Expand Down
20 changes: 12 additions & 8 deletions pocket/pocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,11 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
-- attempt to re-link if any of the dependent links aren't active
function public.link_update()
if not self.sv.linked then
iocontrol.report_link_state(util.trinary(self.api.linked, LINK_STATE.API_LINK_ONLY, LINK_STATE.UNLINKED))
if self.api.linked then
iocontrol.report_link_state(LINK_STATE.API_LINK_ONLY, false, nil)
else
iocontrol.report_link_state(LINK_STATE.UNLINKED, false, false)
end

if self.establish_delay_counter <= 0 then
_send_sv_establish()
Expand All @@ -502,7 +506,7 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
self.establish_delay_counter = self.establish_delay_counter - 1
end
elseif not self.api.linked then
iocontrol.report_link_state(LINK_STATE.SV_LINK_ONLY)
iocontrol.report_link_state(LINK_STATE.SV_LINK_ONLY, nil, false)

if self.establish_delay_counter <= 0 then
_send_api_establish()
Expand All @@ -512,7 +516,7 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
end
else
-- linked, all good!
iocontrol.report_link_state(LINK_STATE.LINKED, self.sv.addr, self.api.addr)
iocontrol.report_link_state(LINK_STATE.LINKED)
end
end

Expand Down Expand Up @@ -678,17 +682,17 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
-- get configuration
local conf = { num_units = fac_config[1], cooling = fac_config[2] }

iocontrol.init_fac(conf, config.TempScale, config.EnergyScale)
iocontrol.init_fac(conf)

log.info("coordinator connection established")
self.establish_delay_counter = 0
self.api.linked = true
self.api.addr = src_addr

if self.sv.linked then
iocontrol.report_link_state(LINK_STATE.LINKED, self.sv.addr, self.api.addr)
iocontrol.report_link_state(LINK_STATE.LINKED, nil, self.api.addr)
else
iocontrol.report_link_state(LINK_STATE.API_LINK_ONLY)
iocontrol.report_link_state(LINK_STATE.API_LINK_ONLY, nil, self.api.addr)
end
else
log.debug("invalid facility configuration table received from coordinator, establish failed")
Expand Down Expand Up @@ -826,9 +830,9 @@ function pocket.comms(version, nic, sv_watchdog, api_watchdog, nav)
self.sv.addr = src_addr

if self.api.linked then
iocontrol.report_link_state(LINK_STATE.LINKED, self.sv.addr, self.api.addr)
iocontrol.report_link_state(LINK_STATE.LINKED, self.sv.addr, nil)
else
iocontrol.report_link_state(LINK_STATE.SV_LINK_ONLY)
iocontrol.report_link_state(LINK_STATE.SV_LINK_ONLY, self.sv.addr, nil)
end
elseif est_ack == ESTABLISH_ACK.DENY then
if self.sv.last_est_ack ~= est_ack then
Expand Down
4 changes: 2 additions & 2 deletions 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.3-alpha"
local POCKET_VERSION = "v0.11.4-alpha"

local println = util.println
local println_ts = util.println_ts
Expand Down Expand Up @@ -152,7 +152,7 @@ local function main()
log.debug("startup> comms init")

-- init I/O control
iocontrol.init_core(smem_sys.pocket_comms, smem_sys.nav)
iocontrol.init_core(smem_sys.pocket_comms, smem_sys.nav, config)

----------------------------------------
-- start the UI
Expand Down
4 changes: 2 additions & 2 deletions pocket/ui/apps/sys_apps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ local function create_pages(root)
TextBox{parent=nt_div,x=2,text="Coordinator Address",alignment=ALIGN.LEFT,fg_bg=label}
local coord = TextBox{parent=nt_div,x=2,text="",alignment=ALIGN.LEFT}

sv.register(db.ps, "sv_addr", function (addr) sv.set_value(util.c(addr, ":", config.SVR_Channel)) end)
coord.register(db.ps, "api_addr", function (addr) coord.set_value(util.c(addr, ":", config.CRD_Channel)) end)
sv.register(db.ps, "sv_addr", sv.set_value)
coord.register(db.ps, "api_addr", coord.set_value)

nt_div.line_break()
TextBox{parent=nt_div,x=2,text="Message Authentication",alignment=ALIGN.LEFT,fg_bg=label}
Expand Down

0 comments on commit f00751e

Please sign in to comment.