2023-12-22 16:12:47 +00:00
|
|
|
--
|
|
|
|
-- Unit Overview Page
|
|
|
|
--
|
2023-04-16 19:05:28 +00:00
|
|
|
|
2024-05-10 03:05:55 +00:00
|
|
|
local util = require("scada-common.util")
|
2024-05-11 23:19:52 +00:00
|
|
|
local log = require("scada-common.log")
|
|
|
|
|
|
|
|
local iocontrol = require("pocket.iocontrol")
|
2023-04-16 19:05:28 +00:00
|
|
|
|
2023-12-22 16:12:47 +00:00
|
|
|
local core = require("graphics.core")
|
2023-04-16 19:05:28 +00:00
|
|
|
|
2023-12-22 16:12:47 +00:00
|
|
|
local Div = require("graphics.elements.div")
|
2024-05-11 23:19:52 +00:00
|
|
|
local MultiPane = require("graphics.elements.multipane")
|
2023-12-22 16:12:47 +00:00
|
|
|
local TextBox = require("graphics.elements.textbox")
|
2023-04-16 19:05:28 +00:00
|
|
|
|
2024-05-10 03:05:55 +00:00
|
|
|
local AlarmLight = require("graphics.elements.indicators.alight")
|
|
|
|
local CoreMap = require("graphics.elements.indicators.coremap")
|
|
|
|
local DataIndicator = require("graphics.elements.indicators.data")
|
|
|
|
local IconIndicator = require("graphics.elements.indicators.icon")
|
|
|
|
local IndicatorLight = require("graphics.elements.indicators.light")
|
|
|
|
local RadIndicator = require("graphics.elements.indicators.rad")
|
|
|
|
local TriIndicatorLight = require("graphics.elements.indicators.trilight")
|
|
|
|
local VerticalBar = require("graphics.elements.indicators.vbar")
|
|
|
|
|
|
|
|
local HazardButton = require("graphics.elements.controls.hazard_button")
|
|
|
|
local MultiButton = require("graphics.elements.controls.multi_button")
|
|
|
|
local PushButton = require("graphics.elements.controls.push_button")
|
|
|
|
local RadioButton = require("graphics.elements.controls.radio_button")
|
|
|
|
local SpinboxNumeric = require("graphics.elements.controls.spinbox_numeric")
|
|
|
|
|
2023-10-04 03:16:46 +00:00
|
|
|
local ALIGN = core.ALIGN
|
2024-05-10 03:05:55 +00:00
|
|
|
local cpair = core.cpair
|
2023-04-16 19:05:28 +00:00
|
|
|
|
2024-05-11 23:19:52 +00:00
|
|
|
local basic_states = {
|
|
|
|
{ color = cpair(colors.black, colors.lightGray), symbol = "\x07" },
|
|
|
|
{ color = cpair(colors.black, colors.red), symbol = "-" },
|
|
|
|
{ color = cpair(colors.black, colors.yellow), symbol = "\x1e" },
|
|
|
|
{ color = cpair(colors.black, colors.green), symbol = "+" }
|
|
|
|
}
|
|
|
|
|
|
|
|
local mode_states = {
|
|
|
|
{ color = cpair(colors.black, colors.lightGray), symbol = "\x07" },
|
|
|
|
{ color = cpair(colors.black, colors.red), symbol = "-" },
|
|
|
|
{ color = cpair(colors.black, colors.green), symbol = "+" },
|
|
|
|
{ color = cpair(colors.black, colors.purple), symbol = "A" }
|
|
|
|
}
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
local red_ind_s = {
|
|
|
|
{ color = cpair(colors.black, colors.lightGray), symbol = "+" },
|
|
|
|
{ color = cpair(colors.black, colors.red), symbol = "-" }
|
|
|
|
}
|
|
|
|
|
|
|
|
local yel_ind_s = {
|
|
|
|
{ color = cpair(colors.black, colors.lightGray), symbol = "+" },
|
|
|
|
{ color = cpair(colors.black, colors.yellow), symbol = "-" }
|
|
|
|
}
|
|
|
|
|
2023-04-16 19:05:28 +00:00
|
|
|
-- new unit page view
|
|
|
|
---@param root graphics_element parent
|
|
|
|
local function new_view(root)
|
2023-12-22 16:12:47 +00:00
|
|
|
local db = iocontrol.get_db()
|
|
|
|
|
2023-04-16 19:05:28 +00:00
|
|
|
local main = Div{parent=root,x=1,y=1}
|
|
|
|
|
2024-04-13 18:47:20 +00:00
|
|
|
local app = db.nav.register_app(iocontrol.APP_ID.UNITS, main)
|
|
|
|
|
2024-05-10 03:05:55 +00:00
|
|
|
TextBox{parent=main,y=2,text="Units App",height=1,alignment=ALIGN.CENTER}
|
|
|
|
|
|
|
|
TextBox{parent=main,y=4,text="Loading...",height=1,alignment=ALIGN.CENTER}
|
|
|
|
|
|
|
|
local btn_fg_bg = cpair(colors.yellow, colors.black)
|
|
|
|
local btn_active = cpair(colors.white, colors.black)
|
2024-05-12 17:28:34 +00:00
|
|
|
|
|
|
|
local nav_links = {}
|
2024-05-10 03:05:55 +00:00
|
|
|
|
2024-05-11 23:19:52 +00:00
|
|
|
local function set_sidebar(id)
|
2024-05-12 17:28:34 +00:00
|
|
|
-- local unit = db.units[id] ---@type pioctl_unit
|
2024-05-11 23:19:52 +00:00
|
|
|
|
|
|
|
local list = {
|
2024-05-10 03:05:55 +00:00
|
|
|
{ label = " # ", tall = true, color = core.cpair(colors.black, colors.green), callback = function () db.nav.open_app(iocontrol.APP_ID.ROOT) end },
|
2024-05-12 17:28:34 +00:00
|
|
|
{ label = "U-" .. id, color = core.cpair(colors.black, colors.yellow), callback = function () app.switcher(id) end },
|
2024-05-12 17:36:46 +00:00
|
|
|
{ label = " \x13 ", color = core.cpair(colors.black, colors.red), callback = nav_links[id].alarm },
|
2024-05-12 17:28:34 +00:00
|
|
|
{ label = "RPS", tall = true, color = core.cpair(colors.black, colors.cyan), callback = nav_links[id].rps },
|
|
|
|
-- { label = " R ", color = core.cpair(colors.black, colors.lightGray), callback = function () end },
|
2024-05-11 23:19:52 +00:00
|
|
|
{ label = "RCS", tall = true, color = core.cpair(colors.black, colors.blue), callback = function () end },
|
|
|
|
}
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
-- for i = 1, unit.num_boilers do
|
|
|
|
-- table.insert(list, { label = "B-" .. i, color = core.cpair(colors.black, colors.lightBlue), callback = function () end })
|
|
|
|
-- end
|
2024-05-11 23:19:52 +00:00
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
-- for i = 1, unit.num_turbines do
|
|
|
|
-- table.insert(list, { label = "T-" .. i, color = core.cpair(colors.black, colors.white), callback = function () end })
|
|
|
|
-- end
|
2024-05-11 23:19:52 +00:00
|
|
|
|
|
|
|
app.set_sidebar(list)
|
2024-05-10 03:05:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function load()
|
2024-05-11 23:19:52 +00:00
|
|
|
local page_div = Div{parent=main,x=2,y=2,width=main.get_width()-2}
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
local panes = {}
|
2024-05-10 03:05:55 +00:00
|
|
|
|
|
|
|
local active_unit = 1
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
-- create all page divs
|
2024-05-10 03:05:55 +00:00
|
|
|
for _ = 1, db.facility.num_units do
|
|
|
|
local div = Div{parent=page_div}
|
2024-05-12 17:28:34 +00:00
|
|
|
table.insert(panes, div)
|
|
|
|
table.insert(nav_links, {})
|
2024-05-10 03:05:55 +00:00
|
|
|
end
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
-- previous unit
|
2024-05-10 03:05:55 +00:00
|
|
|
local function prev(x)
|
|
|
|
active_unit = util.trinary(x == 1, db.facility.num_units, x - 1)
|
2024-05-11 23:19:52 +00:00
|
|
|
app.switcher(active_unit)
|
2024-05-10 03:05:55 +00:00
|
|
|
set_sidebar(active_unit)
|
|
|
|
end
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
-- next unit
|
2024-05-10 03:05:55 +00:00
|
|
|
local function next(x)
|
|
|
|
active_unit = util.trinary(x == db.facility.num_units, 1, x + 1)
|
2024-05-11 23:19:52 +00:00
|
|
|
app.switcher(active_unit)
|
2024-05-10 03:05:55 +00:00
|
|
|
set_sidebar(active_unit)
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, db.facility.num_units do
|
2024-05-12 17:28:34 +00:00
|
|
|
local u_div = panes[i] ---@type graphics_element
|
2024-05-10 03:05:55 +00:00
|
|
|
local unit = db.units[i] ---@type pioctl_unit
|
2024-05-12 17:28:34 +00:00
|
|
|
local u_ps = unit.unit_ps
|
2024-05-10 03:05:55 +00:00
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
-- refresh data callback, every 500ms it will re-send the query
|
2024-05-11 23:19:52 +00:00
|
|
|
local last_update = 0
|
|
|
|
local function update()
|
|
|
|
if util.time_ms() - last_update >= 500 then
|
|
|
|
db.api.get_unit(i)
|
|
|
|
last_update = util.time_ms()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
-- Main Unit Overview
|
|
|
|
|
|
|
|
local u_page = app.new_page(nil, i)
|
|
|
|
u_page.tasks = { update }
|
2024-05-11 23:19:52 +00:00
|
|
|
|
2024-05-10 03:05:55 +00:00
|
|
|
TextBox{parent=u_div,y=1,text="Reactor Unit #"..i,height=1,alignment=ALIGN.CENTER}
|
|
|
|
PushButton{parent=u_div,x=1,y=1,text="<",fg_bg=btn_fg_bg,active_fg_bg=btn_active,callback=function()prev(i)end}
|
|
|
|
PushButton{parent=u_div,x=21,y=1,text=">",fg_bg=btn_fg_bg,active_fg_bg=btn_active,callback=function()next(i)end}
|
|
|
|
|
|
|
|
local type = util.trinary(unit.num_boilers > 0, "Sodium Cooled Reactor", "Boiling Water Reactor")
|
|
|
|
TextBox{parent=u_div,y=3,text=type,height=1,alignment=ALIGN.CENTER,fg_bg=cpair(colors.gray,colors.black)}
|
|
|
|
|
|
|
|
local lu_col = cpair(colors.lightGray, colors.lightGray)
|
|
|
|
local text_fg = cpair(colors.white, colors._INHERIT)
|
|
|
|
|
|
|
|
local rate = DataIndicator{parent=u_div,y=5,lu_colors=lu_col,label="Rate",unit="mB/t",format="%10.2f",value=0,commas=true,width=26,fg_bg=text_fg}
|
|
|
|
local temp = DataIndicator{parent=u_div,lu_colors=lu_col,label="Temp",unit="K",format="%10.2f",value=0,commas=true,width=26,fg_bg=text_fg}
|
|
|
|
|
|
|
|
local ctrl = IconIndicator{parent=u_div,x=1,y=8,label="Control State",states=mode_states}
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
rate.register(u_ps, "act_burn_rate", rate.update)
|
|
|
|
temp.register(u_ps, "temp", temp.update)
|
|
|
|
ctrl.register(u_ps, "U_ControlStatus", ctrl.update)
|
2024-05-10 03:05:55 +00:00
|
|
|
|
|
|
|
u_div.line_break()
|
|
|
|
|
|
|
|
local rct = IconIndicator{parent=u_div,x=1,label="Fission Reactor",states=basic_states}
|
|
|
|
local rps = IconIndicator{parent=u_div,x=1,label="Protection System",states=basic_states}
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
rct.register(u_ps, "U_ReactorStatus", rct.update)
|
|
|
|
rps.register(u_ps, "U_RPS", rps.update)
|
2024-05-11 23:19:52 +00:00
|
|
|
|
2024-05-10 03:05:55 +00:00
|
|
|
u_div.line_break()
|
|
|
|
|
|
|
|
local rcs = IconIndicator{parent=u_div,x=1,label="Coolant System",states=basic_states}
|
|
|
|
|
|
|
|
for b = 1, unit.num_boilers do
|
|
|
|
local blr = IconIndicator{parent=u_div,x=1,label="Boiler "..b,states=basic_states}
|
2024-05-11 23:19:52 +00:00
|
|
|
blr.register(unit.boiler_ps_tbl[b], "BoilerStatus", blr.update)
|
2024-05-10 03:05:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
for t = 1, unit.num_turbines do
|
2024-05-11 23:19:52 +00:00
|
|
|
local tbn = IconIndicator{parent=u_div,x=1,label="Turbine "..t,states=basic_states}
|
|
|
|
tbn.register(unit.turbine_ps_tbl[t], "TurbineStatus", tbn.update)
|
2024-05-10 03:05:55 +00:00
|
|
|
end
|
2024-05-12 17:28:34 +00:00
|
|
|
|
2024-05-12 17:36:46 +00:00
|
|
|
-- Alarms Tab
|
|
|
|
|
|
|
|
local alm_div = Div{parent=page_div}
|
|
|
|
table.insert(panes, alm_div)
|
|
|
|
|
|
|
|
local alm_page = app.new_page(u_page, #panes)
|
|
|
|
alm_page.tasks = { update }
|
|
|
|
|
|
|
|
nav_links[i].alarm = alm_page.nav_to
|
|
|
|
|
|
|
|
TextBox{parent=alm_div,y=1,text="Unit Alarms",height=1,alignment=ALIGN.CENTER}
|
|
|
|
|
|
|
|
TextBox{parent=alm_div,y=3,text="work in progress",height=1,alignment=ALIGN.CENTER,fg_bg=cpair(colors.gray,colors.black)}
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
-- RPS Tab
|
|
|
|
|
|
|
|
local rps_div = Div{parent=page_div}
|
|
|
|
table.insert(panes, rps_div)
|
|
|
|
|
2024-05-12 17:36:46 +00:00
|
|
|
local rps_page = app.new_page(u_page, #panes)
|
|
|
|
rps_page.tasks = { update }
|
|
|
|
|
|
|
|
nav_links[i].rps = rps_page.nav_to
|
|
|
|
|
2024-05-12 17:28:34 +00:00
|
|
|
TextBox{parent=rps_div,y=1,text="Protection System",height=1,alignment=ALIGN.CENTER}
|
|
|
|
|
|
|
|
local r_trip = IconIndicator{parent=rps_div,x=1,y=3,label="RPS Trip",states=basic_states}
|
|
|
|
r_trip.register(u_ps, "U_RPS", r_trip.update)
|
|
|
|
|
|
|
|
local r_mscrm = IconIndicator{parent=rps_div,x=1,y=5,label="Manual SCRAM",states=red_ind_s}
|
|
|
|
local r_ascrm = IconIndicator{parent=rps_div,x=1,label="Automatic SCRAM",states=red_ind_s}
|
|
|
|
local rps_tmo = IconIndicator{parent=rps_div,x=1,label="Timeout",states=yel_ind_s}
|
2024-05-12 18:20:48 +00:00
|
|
|
local rps_flt = IconIndicator{parent=rps_div,x=1,label="PPM Fault",states=yel_ind_s}
|
|
|
|
local rps_sfl = IconIndicator{parent=rps_div,x=1,label="Not Formed",states=red_ind_s}
|
2024-05-12 17:28:34 +00:00
|
|
|
|
|
|
|
r_mscrm.register(u_ps, "manual", r_mscrm.update)
|
|
|
|
r_ascrm.register(u_ps, "automatic", r_ascrm.update)
|
|
|
|
rps_tmo.register(u_ps, "timeout", rps_tmo.update)
|
|
|
|
rps_flt.register(u_ps, "fault", rps_flt.update)
|
|
|
|
rps_sfl.register(u_ps, "sys_fail", rps_sfl.update)
|
|
|
|
|
|
|
|
rps_div.line_break()
|
2024-05-12 18:20:48 +00:00
|
|
|
local rps_dmg = IconIndicator{parent=rps_div,x=1,label="Reactor Damage Hi",states=red_ind_s}
|
|
|
|
local rps_tmp = IconIndicator{parent=rps_div,x=1,label="Temp. Critical",states=red_ind_s}
|
|
|
|
local rps_nof = IconIndicator{parent=rps_div,x=1,label="Fuel Level Lo",states=yel_ind_s}
|
|
|
|
local rps_exw = IconIndicator{parent=rps_div,x=1,label="Waste Level Hi",states=yel_ind_s}
|
|
|
|
local rps_loc = IconIndicator{parent=rps_div,x=1,label="Coolant Lo Lo",states=yel_ind_s}
|
|
|
|
local rps_exh = IconIndicator{parent=rps_div,x=1,label="Heated Coolant Hi",states=yel_ind_s}
|
2024-05-12 17:28:34 +00:00
|
|
|
|
|
|
|
rps_dmg.register(u_ps, "high_dmg", rps_dmg.update)
|
|
|
|
rps_tmp.register(u_ps, "high_temp", rps_tmp.update)
|
|
|
|
rps_nof.register(u_ps, "no_fuel", rps_nof.update)
|
|
|
|
rps_exw.register(u_ps, "ex_waste", rps_exw.update)
|
|
|
|
rps_loc.register(u_ps, "low_cool", rps_loc.update)
|
|
|
|
rps_exh.register(u_ps, "ex_hcool", rps_exh.update)
|
|
|
|
|
2024-05-12 17:36:46 +00:00
|
|
|
-- RCS Tab
|
|
|
|
|
|
|
|
local rcs_div = Div{parent=page_div}
|
|
|
|
table.insert(panes, rcs_div)
|
|
|
|
|
|
|
|
local rcs_page = app.new_page(u_page, #panes)
|
|
|
|
rcs_page.tasks = { update }
|
|
|
|
|
|
|
|
nav_links[i].rcs = rcs_page.nav_to
|
|
|
|
|
|
|
|
TextBox{parent=rcs_div,y=1,text="Coolant System",height=1,alignment=ALIGN.CENTER}
|
2024-05-12 17:28:34 +00:00
|
|
|
|
2024-05-10 03:05:55 +00:00
|
|
|
end
|
2024-05-12 17:28:34 +00:00
|
|
|
|
|
|
|
-- setup multipane
|
|
|
|
local u_pane = MultiPane{parent=page_div,x=1,y=1,panes=panes}
|
|
|
|
app.set_root_pane(u_pane)
|
|
|
|
|
|
|
|
set_sidebar(active_unit)
|
2024-05-10 03:05:55 +00:00
|
|
|
end
|
2024-04-14 19:28:38 +00:00
|
|
|
|
2024-05-10 03:05:55 +00:00
|
|
|
app.set_on_load(load)
|
2023-04-16 19:05:28 +00:00
|
|
|
|
|
|
|
return main
|
|
|
|
end
|
|
|
|
|
|
|
|
return new_view
|