#201 added pocket connecting screens

This commit is contained in:
Mikayla Fischler 2023-04-18 13:47:06 -04:00
parent 438ab55f4f
commit d295c2b3c3
6 changed files with 105 additions and 26 deletions

35
pocket/coreio.lua Normal file
View File

@ -0,0 +1,35 @@
--
-- Core I/O - Pocket Central I/O Management
--
local psil = require("scada-common.psil")
local coreio = {}
---@class pocket_core_io
local io = {
ps = psil.create()
}
---@enum POCKET_LINK_STATE
local LINK_STATE = {
UNLINKED = 0,
SV_LINK_ONLY = 1,
API_LINK_ONLY = 2,
LINKED = 3
}
coreio.LINK_STATE = LINK_STATE
-- get the core PSIL
function coreio.core_ps()
return io.ps
end
-- set network link state
---@param state POCKET_LINK_STATE
function coreio.report_link_state(state)
io.ps.publish("link_state", state)
end
return coreio

View File

@ -1,6 +1,8 @@
local comms = require("scada-common.comms") local comms = require("scada-common.comms")
local log = require("scada-common.log") local log = require("scada-common.log")
local util = require("scada-common.util") local util = require("scada-common.util")
local coreio = require("pocket.coreio")
local PROTOCOL = comms.PROTOCOL local PROTOCOL = comms.PROTOCOL
local DEVICE_TYPE = comms.DEVICE_TYPE local DEVICE_TYPE = comms.DEVICE_TYPE
@ -8,6 +10,8 @@ local ESTABLISH_ACK = comms.ESTABLISH_ACK
local SCADA_MGMT_TYPE = comms.SCADA_MGMT_TYPE local SCADA_MGMT_TYPE = comms.SCADA_MGMT_TYPE
local CAPI_TYPE = comms.CAPI_TYPE local CAPI_TYPE = comms.CAPI_TYPE
local LINK_STATE = coreio.LINK_STATE
local pocket = {} local pocket = {}
-- pocket coordinator + supervisor communications -- pocket coordinator + supervisor communications
@ -205,10 +209,13 @@ function pocket.comms(version, modem, local_port, sv_port, api_port, range, sv_w
---@param packet mgmt_frame|capi_frame|nil ---@param packet mgmt_frame|capi_frame|nil
function public.handle_packet(packet) function public.handle_packet(packet)
if packet ~= nil then if packet ~= nil then
local protocol = packet.scada_frame.protocol() local l_port = packet.scada_frame.local_port()
local r_port = packet.scada_frame.remote_port() local r_port = packet.scada_frame.remote_port()
local protocol = packet.scada_frame.protocol()
if r_port == api_port then if l_port ~= local_port then
log.debug("received packet on unconfigured channel " .. l_port, true)
elseif r_port == api_port then
-- check sequence number -- check sequence number
if self.api.r_seq_num == nil then if self.api.r_seq_num == nil then
self.api.r_seq_num = packet.scada_frame.seq_num() self.api.r_seq_num = packet.scada_frame.seq_num()
@ -235,6 +242,12 @@ function pocket.comms(version, modem, local_port, sv_port, api_port, range, sv_w
log.info("coordinator connection established") log.info("coordinator connection established")
self.establish_delay_counter = 0 self.establish_delay_counter = 0
self.api.linked = true self.api.linked = true
if self.sv.linked then
coreio.report_link_state(LINK_STATE.LINKED)
else
coreio.report_link_state(LINK_STATE.API_LINK_ONLY)
end
elseif est_ack == ESTABLISH_ACK.DENY then elseif est_ack == ESTABLISH_ACK.DENY then
if self.api.last_est_ack ~= est_ack then if self.api.last_est_ack ~= est_ack then
log.info("coordinator connection denied") log.info("coordinator connection denied")
@ -312,6 +325,12 @@ function pocket.comms(version, modem, local_port, sv_port, api_port, range, sv_w
log.info("supervisor connection established") log.info("supervisor connection established")
self.establish_delay_counter = 0 self.establish_delay_counter = 0
self.sv.linked = true self.sv.linked = true
if self.api.linked then
coreio.report_link_state(LINK_STATE.LINKED)
else
coreio.report_link_state(LINK_STATE.SV_LINK_ONLY)
end
elseif est_ack == ESTABLISH_ACK.DENY then elseif est_ack == ESTABLISH_ACK.DENY then
if self.sv.last_est_ack ~= est_ack then if self.sv.last_est_ack ~= est_ack then
log.info("supervisor connection denied") log.info("supervisor connection denied")

View File

@ -2,9 +2,6 @@
-- Graphics Rendering Control -- Graphics Rendering Control
-- --
local log = require("scada-common.log")
local util = require("scada-common.util")
local main_view = require("pocket.ui.main") local main_view = require("pocket.ui.main")
local style = require("pocket.ui.style") local style = require("pocket.ui.style")

View File

@ -13,6 +13,7 @@ local util = require("scada-common.util")
local core = require("graphics.core") local core = require("graphics.core")
local config = require("pocket.config") local config = require("pocket.config")
local coreio = require("pocket.coreio")
local pocket = require("pocket.pocket") local pocket = require("pocket.pocket")
local renderer = require("pocket.renderer") local renderer = require("pocket.renderer")
@ -63,9 +64,11 @@ local function main()
ppm.mount_all() ppm.mount_all()
---------------------------------------- ----------------------------------------
-- setup communications -- setup communications & clocks
---------------------------------------- ----------------------------------------
coreio.report_link_state(coreio.LINK_STATE.UNLINKED)
-- get the communications modem -- get the communications modem
local modem = ppm.get_wireless_modem() local modem = ppm.get_wireless_modem()
if modem == nil then if modem == nil then

View File

@ -25,11 +25,11 @@ local function init(parent, y, is_api)
local waiting_x = math.floor(parent.width() / 2) - 1 local waiting_x = math.floor(parent.width() / 2) - 1
if is_api then if is_api then
TextBox{parent=root,text="Connecting to API",alignment=TEXT_ALIGN.CENTER,y=1,height=1,fg_bg=cpair(colors.white,style.root.bkg)} WaitingAnim{parent=root,x=waiting_x,y=1,fg_bg=cpair(colors.blue,style.root.bkg)}
WaitingAnim{parent=root,x=waiting_x,y=3,fg_bg=cpair(colors.blue,style.root.bkg)} TextBox{parent=root,text="Connecting to API",alignment=TEXT_ALIGN.CENTER,y=5,height=1,fg_bg=cpair(colors.white,style.root.bkg)}
else else
TextBox{parent=root,text="Connecting to Supervisor",alignment=TEXT_ALIGN.CENTER,y=1,height=1,fg_bg=cpair(colors.white,style.root.bkg)} WaitingAnim{parent=root,x=waiting_x,y=1,fg_bg=cpair(colors.green,style.root.bkg)}
WaitingAnim{parent=root,x=waiting_x,y=3,fg_bg=cpair(colors.green,style.root.bkg)} TextBox{parent=root,text="Connecting to Supervisor",alignment=TEXT_ALIGN.CENTER,y=5,height=1,fg_bg=cpair(colors.white,style.root.bkg)}
end end
return root return root

View File

@ -4,6 +4,8 @@
local util = require("scada-common.util") local util = require("scada-common.util")
local coreio = require("pocket.coreio")
local style = require("pocket.ui.style") local style = require("pocket.ui.style")
local conn_waiting = require("pocket.ui.components.conn_waiting") local conn_waiting = require("pocket.ui.components.conn_waiting")
@ -38,10 +40,36 @@ local function init(monitor)
local main = DisplayBox{window=monitor,fg_bg=style.root} local main = DisplayBox{window=monitor,fg_bg=style.root}
-- window header message -- window header message
local header = TextBox{parent=main,y=1,text="",alignment=TEXT_ALIGN.LEFT,height=1,fg_bg=style.header} TextBox{parent=main,y=1,text="",alignment=TEXT_ALIGN.LEFT,height=1,fg_bg=style.header}
-- local api_wait = conn_waiting(main, 8, true) --
-- local sv_wait = conn_waiting(main, 8, false) -- root panel panes (connection screens + main screen)
--
local root_pane_div = Div{parent=main,x=1,y=2}
local conn_sv_wait = conn_waiting(root_pane_div, 6, false)
local conn_api_wait = conn_waiting(root_pane_div, 6, true)
local main_pane = Div{parent=main,x=1,y=2}
local root_panes = { conn_sv_wait, conn_api_wait, main_pane }
local root_pane = MultiPane{parent=root_pane_div,x=1,y=1,panes=root_panes}
coreio.core_ps().subscribe("link_state", function (state)
if state == coreio.LINK_STATE.UNLINKED or state == coreio.LINK_STATE.API_LINK_ONLY then
root_pane.set_value(1)
elseif state == coreio.LINK_STATE.SV_LINK_ONLY then
root_pane.set_value(2)
else
root_pane.set_value(3)
end
end)
--
-- main page panel panes & sidebar
--
local page_div = Div{parent=main_pane,x=4,y=2}
local sidebar_tabs = { local sidebar_tabs = {
{ {
@ -66,19 +94,16 @@ local function init(monitor)
} }
} }
local mp_div = Div{parent=main,x=4,y=2} local pane_1 = home_page(page_div)
local pane_2 = unit_page(page_div)
local pane_1 = home_page(mp_div) local pane_3 = reactor_page(page_div)
local pane_2 = unit_page(mp_div) local pane_4 = boiler_page(page_div)
local pane_3 = reactor_page(mp_div) local pane_5 = turbine_page(page_div)
local pane_4 = boiler_page(mp_div)
local pane_5 = turbine_page(mp_div)
local panes = { pane_1, pane_2, pane_3, pane_4, pane_5 } local panes = { pane_1, pane_2, pane_3, pane_4, pane_5 }
local multipane = MultiPane{parent=mp_div,x=1,y=1,panes=panes} local page_pane = MultiPane{parent=page_div,x=1,y=1,panes=panes}
local sidebar = Sidebar{parent=main,x=1,y=2,tabs=sidebar_tabs,fg_bg=cpair(colors.white,colors.gray),callback=multipane.set_value} Sidebar{parent=main_pane,x=1,y=2,tabs=sidebar_tabs,fg_bg=cpair(colors.white,colors.gray),callback=page_pane.set_value}
return main return main
end end