diff --git a/pocket/ui/apps/facility.lua b/pocket/ui/apps/facility.lua index 6abd78b..baf948d 100644 --- a/pocket/ui/apps/facility.lua +++ b/pocket/ui/apps/facility.lua @@ -10,6 +10,7 @@ local pocket = require("pocket.pocket") local style = require("pocket.ui.style") local dyn_tank = require("pocket.ui.pages.dynamic_tank") +local facility_sps = require("pocket.ui.pages.facility_sps") local induction_mtx = require("pocket.ui.pages.facility_matrix") local core = require("graphics.core") @@ -95,34 +96,22 @@ local function new_view(root) TextBox{parent=a_div,y=1,text="Annunciator",alignment=ALIGN.CENTER} - local all_ok = IconIndicator{parent=a_div,y=3,label="Unit Systems Online",states=grn_ind_s} + local all_ok = IconIndicator{parent=a_div,y=3,label="Units Online",states=grn_ind_s} local ind_mat = IconIndicator{parent=a_div,label="Induction Matrix",states=grn_ind_s} local sps = IconIndicator{parent=a_div,label="SPS Connected",states=grn_ind_s} all_ok.register(f_ps, "all_sys_ok", all_ok.update) - ind_mat.register(fac.induction_ps_tbl[1], "computed_status", function (status) ind_mat.update(status > 1) end) - sps.register(fac.sps_ps_tbl[1], "computed_status", function (status) sps.update(status > 1) end) - - a_div.line_break() - - local auto_ready = IconIndicator{parent=a_div,label="Configured Units Ready",states=grn_ind_s} - local auto_act = IconIndicator{parent=a_div,label="Process Active",states=grn_ind_s} - local auto_ramp = IconIndicator{parent=a_div,label="Process Ramping",states=wht_ind_s} - local auto_sat = IconIndicator{parent=a_div,label="Min/Max Burn Rate",states=yel_ind_s} - - auto_ready.register(f_ps, "auto_ready", auto_ready.update) - auto_act.register(f_ps, "auto_active", auto_act.update) - auto_ramp.register(f_ps, "auto_ramping", auto_ramp.update) - auto_sat.register(f_ps, "auto_saturated", auto_sat.update) + -- ind_mat.register(fac.induction_ps_tbl[1], "computed_status", function (status) ind_mat.update(status > 1) end) + -- sps.register(fac.sps_ps_tbl[1], "computed_status", function (status) sps.update(status > 1) end) a_div.line_break() local auto_scram = IconIndicator{parent=a_div,label="Automatic SCRAM",states=red_ind_s} - local matrix_flt = IconIndicator{parent=a_div,label="Induction Matrix Fault",states=yel_ind_s} - local matrix_fill = IconIndicator{parent=a_div,label="Matrix Charge High",states=red_ind_s} - local unit_crit = IconIndicator{parent=a_div,label="Unit Critical Alarm",states=red_ind_s} - local fac_rad_h = IconIndicator{parent=a_div,label="Facility Radiation High",states=red_ind_s} - local gen_fault = IconIndicator{parent=a_div,label="Gen. Control Fault",states=yel_ind_s} + local matrix_flt = IconIndicator{parent=a_div,label="Ind. Matrix Fault",states=yel_ind_s} + local matrix_fill = IconIndicator{parent=a_div,label="Matrix Charge Hi",states=red_ind_s} + local unit_crit = IconIndicator{parent=a_div,label="Unit Crit. Alarm",states=red_ind_s} + local fac_rad_h = IconIndicator{parent=a_div,label="FAC Radiation Hi",states=red_ind_s} + local gen_fault = IconIndicator{parent=a_div,label="Gen Control Fault",states=yel_ind_s} auto_scram.register(f_ps, "auto_scram", auto_scram.update) matrix_flt.register(f_ps, "as_matrix_fault", matrix_flt.update) @@ -139,30 +128,9 @@ local function new_view(root) --#endregion - --#region SPS page + --#region SPS - local s_pane = Div{parent=page_div} - local s_div = Div{parent=s_pane,x=2,width=main.get_width()-2} - table.insert(panes, s_pane) - - local sps_page = app.new_page(nil, #panes) - sps_page.tasks = { update } - - TextBox{parent=s_div,y=1,text="Facility SPS",alignment=ALIGN.CENTER} - - local sps_status = StateIndicator{parent=s_div,x=5,y=3,states=style.sps.states,value=1,min_width=12} - - sps_status.register(f_ps, "sps_computed_status", sps_status.update) - - TextBox{parent=s_div,y=5,text="Input Rate",width=10,fg_bg=label_fg_bg} - local sps_in = DataIndicator{parent=s_div,label="",format="%16.2f",value=0,unit="mB/t",lu_colors=lu_col,width=21,fg_bg=text_fg} - - sps_in.register(f_ps, "po_am_rate", sps_in.update) - - TextBox{parent=s_div,y=8,text="Production Rate",width=15,fg_bg=label_fg_bg} - local sps_rate = DataIndicator{parent=s_div,label="",format="%16d",value=0,unit="\xb5B/t",lu_colors=lu_col,width=21,fg_bg=text_fg} - - sps_rate.register(f_ps, "sps_process_rate", function (r) sps_rate.update(r * 1000) end) + local sps_page_nav = facility_sps(app, panes, Div{parent=page_div}, fac.sps_ps_tbl[1], update) --#endregion @@ -193,7 +161,7 @@ local function new_view(root) { label = " # ", tall = true, color = core.cpair(colors.black, colors.green), callback = db.nav.go_home }, { label = "FAC", color = core.cpair(colors.black, colors.orange), callback = f_annunc.nav_to }, { label = "MTX", color = core.cpair(colors.black, colors.white), callback = mtx_page_nav }, - { label = "SPS", color = core.cpair(colors.black, colors.purple), callback = sps_page.nav_to }, + { label = "SPS", color = core.cpair(colors.black, colors.purple), callback = sps_page_nav }, { label = "TNK", tall = true, color = core.cpair(colors.white, colors.gray), callback = tank_page.nav_to } } diff --git a/pocket/ui/pages/facility_sps.lua b/pocket/ui/pages/facility_sps.lua index e69de29..456adc1 100644 --- a/pocket/ui/pages/facility_sps.lua +++ b/pocket/ui/pages/facility_sps.lua @@ -0,0 +1,95 @@ +local iocontrol = require("pocket.iocontrol") + +local style = require("pocket.ui.style") + +local core = require("graphics.core") + +local Div = require("graphics.elements.Div") +local TextBox = require("graphics.elements.TextBox") + +local PushButton = require("graphics.elements.controls.PushButton") + +local DataIndicator = require("graphics.elements.indicators.DataIndicator") +local HorizontalBar = require("graphics.elements.indicators.HorizontalBar") +local PowerIndicator = require("graphics.elements.indicators.PowerIndicator") +local StateIndicator = require("graphics.elements.indicators.StateIndicator") + +local ALIGN = core.ALIGN +local cpair = core.cpair + +local label = style.label +local lu_col = style.label_unit_pair +local text_fg = style.text_fg + +-- create an SPS view in the facility app +---@param app pocket_app +---@param panes Div[] +---@param sps_pane Div +---@param ps psil +---@param update function +return function (app, panes, sps_pane, ps, update) + local db = iocontrol.get_db() + + local sps_div = Div{parent=sps_pane,x=2,width=sps_pane.get_width()-2} + table.insert(panes, sps_div) + + local sps_page = app.new_page(nil, #panes) + sps_page.tasks = { update } + + TextBox{parent=sps_div,y=1,text="Facility SPS",alignment=ALIGN.CENTER} + local status = StateIndicator{parent=sps_div,x=5,y=3,states=style.sps.states,value=1,min_width=12} + status.register(ps, "sps_computed_status", status.update) + + TextBox{parent=sps_div,text="Polonium",x=1,y=5,fg_bg=label} + local po_bar = HorizontalBar{parent=sps_div,x=1,y=6,fg_bg=cpair(colors.cyan,colors.gray)} + TextBox{parent=sps_div,text="Antimatter",x=1,y=5,fg_bg=label} + local am_bar = HorizontalBar{parent=sps_div,x=1,y=6,fg_bg=cpair(colors.purple,colors.gray)} + TextBox{parent=sps_div,text="Energy Storage",x=21,y=8,fg_bg=label} + local energy_bar = HorizontalBar{parent=sps_div,x=1,y=9,fg_bg=cpair(colors.green,colors.gray)} + + po_bar.register(ps, "input_fill", po_bar.update) + am_bar.register(ps, "output_fill", am_bar.update) + energy_bar.register(ps, "energy_fill", energy_bar.update) + + TextBox{parent=sps_div,text="Input Rate",x=3,y=11,width=17,fg_bg=label} + local input_rate = DataIndicator{parent=sps_div,x=3,y=12,lu_colors=lu_col,label="",unit="mB/t",format="%11.0f",value=0,commas=true,width=17,fg_bg=text_fg} + TextBox{parent=sps_div,text="Production",x=3,y=14,width=17,fg_bg=label} + local proc_rate = DataIndicator{parent=sps_div,x=3,y=15,lu_colors=lu_col,label="",unit="\xb5B/t",format="%11d",value=0,width=17,fg_bg=text_fg} + + proc_rate.register(ps, "process_rate", function (r) proc_rate.update(r * 1000) end) + input_rate.register(db.facility.ps, "po_am_rate", input_rate.update) + + local sps_ext_div = Div{parent=sps_pane,x=2,width=sps_pane.get_width()-2} + table.insert(panes, sps_ext_div) + + local sps_ext_page = app.new_page(sps_page, #panes) + sps_ext_page.tasks = { update } + + PushButton{parent=sps_div,x=9,y=18,text="MORE",min_width=6,fg_bg=cpair(colors.lightGray,colors.gray),active_fg_bg=cpair(colors.gray,colors.lightGray),callback=sps_ext_page.nav_to} + PushButton{parent=sps_ext_div,x=9,y=18,text="BACK",min_width=6,fg_bg=cpair(colors.lightGray,colors.gray),active_fg_bg=cpair(colors.gray,colors.lightGray),callback=sps_page.nav_to} + + TextBox{parent=sps_ext_div,y=1,text="More SPS Info",alignment=ALIGN.CENTER} + + TextBox{parent=sps_ext_div,text="Polonium Tank",x=1,y=3,width=10,fg_bg=label} + local input_p = DataIndicator{parent=sps_ext_div,x=14,y=3,lu_colors=lu_col,label="",unit="%",format="%6.2f",value=0,width=8,fg_bg=text_fg} + local input_amnt = DataIndicator{parent=sps_ext_div,x=1,y=4,lu_colors=lu_col,label="",unit="mB",format="%18.0f",value=0,commas=true,width=21,fg_bg=text_fg} + + input_p.register(ps, "input_fill", function (x) input_p.update(x * 100) end) + input_amnt.register(ps, "input", function (x) input_amnt.update(x.amount) end) + + TextBox{parent=sps_ext_div,text="Antimatter Tank",x=1,y=6,width=10,fg_bg=label} + local output_p = DataIndicator{parent=sps_ext_div,x=14,y=6,lu_colors=lu_col,label="",unit="%",format="%6.2f",value=0,width=8,fg_bg=text_fg} + local output_amnt = DataIndicator{parent=sps_ext_div,x=1,y=7,lu_colors=lu_col,label="",unit="mB",format="%18.3f",value=0,commas=true,width=21,fg_bg=text_fg} + + output_p.register(ps, "output_fill", function (x) output_p.update(x * 100) end) + output_amnt.register(ps, "output", function (x) output_amnt.update(x.amount) end) + + TextBox{parent=sps_ext_div,text="Energy Fill",x=1,y=8,width=12,fg_bg=label} + local energy_p = DataIndicator{parent=sps_ext_div,x=14,y=8,lu_colors=lu_col,label="",unit="%",format="%6.2f",value=0,width=8,fg_bg=text_fg} + local energy_amnt = PowerIndicator{parent=sps_ext_div,x=1,y=9,lu_colors=lu_col,label="",unit=db.energy_label,format="%17.4f",value=0,width=21,fg_bg=text_fg} + + energy_p.register(ps, "energy_fill", function (x) energy_p.update(x * 100) end) + energy_amnt.register(ps, "energy", function (val) energy_amnt.update(db.energy_convert(val)) end) + + return sps_page.nav_to +end diff --git a/scada-common/comms.lua b/scada-common/comms.lua index a3e40a8..a8d0014 100644 --- a/scada-common/comms.lua +++ b/scada-common/comms.lua @@ -17,8 +17,8 @@ local max_distance = nil local comms = {} -- protocol/data versions (protocol/data independent changes tracked by util.lua version) -comms.version = "3.0.3" -comms.api_version = "0.0.8" +comms.version = "3.0.4" +comms.api_version = "0.0.9" ---@enum PROTOCOL local PROTOCOL = { @@ -66,11 +66,12 @@ local CRDN_TYPE = { UNIT_BUILDS = 4, -- build of each reactor unit (reactor + RTUs) UNIT_STATUSES = 5, -- state of each of the reactor units UNIT_CMD = 6, -- command a reactor unit - API_GET_FAC = 7, -- API: get all the facility data - API_GET_UNIT = 8, -- API: get reactor unit data - API_GET_CTRL = 9, -- API: get data for the control app - API_GET_PROC = 10, -- API: get data for the process app - API_GET_WASTE = 11 -- API: get data for the waste app + API_GET_FAC = 7, -- API: get the facility general data + API_GET_FAC_DTL = 8, -- API: get (detailed) data for the facility app + API_GET_UNIT = 9, -- API: get reactor unit data + API_GET_CTRL = 10, -- API: get data for the control app + API_GET_PROC = 11, -- API: get data for the process app + API_GET_WASTE = 12 -- API: get data for the waste app } ---@enum ESTABLISH_ACK