diff --git a/coordinator/database.lua b/coordinator/database.lua index b15bf05..3cee4ac 100644 --- a/coordinator/database.lua +++ b/coordinator/database.lua @@ -51,4 +51,7 @@ function database.init(conf) end end +-- get the database +function database.get() return db end + return database diff --git a/coordinator/ui/components/boiler.lua b/coordinator/ui/components/boiler.lua index 204c317..f45585b 100644 --- a/coordinator/ui/components/boiler.lua +++ b/coordinator/ui/components/boiler.lua @@ -14,7 +14,12 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN local cpair = core.graphics.cpair local border = core.graphics.border -local function new_view(root, x, y) +-- new boiler view +---@param root graphics_element +---@param x integer +---@param y integer +---@param ps psil +local function new_view(root, x, y, ps) local boiler = Rectangle{parent=root,border=border(1, colors.gray, true),width=31,height=7,x=x,y=y} local text_fg_bg = cpair(colors.black, colors.lightGray) @@ -24,6 +29,10 @@ local function new_view(root, x, y) local temp = DataIndicator{parent=boiler,x=5,y=3,lu_colors=lu_col,label="Temp:",unit="K",format="%10.2f",value=1900,width=22,fg_bg=text_fg_bg} local boil_r = DataIndicator{parent=boiler,x=5,y=4,lu_colors=lu_col,label="Boil:",unit="mB/t",format="%10.0f",value=801523,commas=true,width=22,fg_bg=text_fg_bg} + ps.subscribe("status", status.update) + ps.subscribe("temp", temp.update) + ps.subscribe("boil_rate", boil_r.update) + TextBox{parent=boiler,text="H",x=2,y=5,height=1,width=1,fg_bg=text_fg_bg} TextBox{parent=boiler,text="W",x=3,y=5,height=1,width=1,fg_bg=text_fg_bg} TextBox{parent=boiler,text="S",x=27,y=5,height=1,width=1,fg_bg=text_fg_bg} @@ -32,12 +41,17 @@ local function new_view(root, x, y) local hcool = VerticalBar{parent=boiler,x=2,y=1,fg_bg=cpair(colors.orange,colors.gray),height=4,width=1} local water = VerticalBar{parent=boiler,x=3,y=1,fg_bg=cpair(colors.blue,colors.gray),height=4,width=1} local steam = VerticalBar{parent=boiler,x=27,y=1,fg_bg=cpair(colors.white,colors.gray),height=4,width=1} - local cool = VerticalBar{parent=boiler,x=28,y=1,fg_bg=cpair(colors.lightBlue,colors.gray),height=4,width=1} + local ccool = VerticalBar{parent=boiler,x=28,y=1,fg_bg=cpair(colors.lightBlue,colors.gray),height=4,width=1} + + ps.subscribe("hcool", hcool.update) + ps.subscribe("water", water.update) + ps.subscribe("steam", steam.update) + ps.subscribe("ccool", ccool.update) hcool.update(0.22) water.update(1) steam.update(0.05) - cool.update(0.13) + ccool.update(0.13) end return new_view diff --git a/coordinator/ui/components/reactor.lua b/coordinator/ui/components/reactor.lua index acd1ba7..05d27dd 100644 --- a/coordinator/ui/components/reactor.lua +++ b/coordinator/ui/components/reactor.lua @@ -14,7 +14,11 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN local cpair = core.graphics.cpair local border = core.graphics.border -local function new_view(root, x, y) +---@param root graphics_element +---@param x integer +---@param y integer +---@param ps psil +local function new_view(root, x, y, ps) local reactor = Rectangle{parent=root,border=border(1, colors.gray, true),width=30,height=7,x=x,y=y} local text_fg_bg = cpair(colors.black, colors.lightGray) @@ -25,6 +29,11 @@ local function new_view(root, x, y) local burn_r = DataIndicator{parent=reactor,x=2,y=4,lu_colors=lu_col,label="Burn Rate:",unit="mB/t",format="%10.1f",value=40.1,width=26,fg_bg=text_fg_bg} local heating_r = DataIndicator{parent=reactor,x=2,y=5,lu_colors=lu_col,label="Heating:",unit="mB/t",format="%12.0f",value=8015342,commas=true,width=26,fg_bg=text_fg_bg} + ps.subscribe("status", status.update) + ps.subscribe("temp", core_temp.update) + ps.subscribe("burn_rate", burn_r.update) + ps.subscribe("heating_rate", heating_r.update) + local reactor_fills = Rectangle{parent=root,border=border(1, colors.gray, true),width=24,height=7,x=(x + 29),y=y} TextBox{parent=reactor_fills,text="FUEL",x=2,y=1,height=1,fg_bg=text_fg_bg} @@ -33,12 +42,17 @@ local function new_view(root, x, y) TextBox{parent=reactor_fills,text="WASTE",x=2,y=5,height=1,fg_bg=text_fg_bg} local fuel = HorizontalBar{parent=reactor_fills,x=8,y=1,show_percent=true,bar_fg_bg=cpair(colors.black,colors.gray),height=1,width=14} - local cool = HorizontalBar{parent=reactor_fills,x=8,y=2,show_percent=true,bar_fg_bg=cpair(colors.lightBlue,colors.gray),height=1,width=14} + local ccool = HorizontalBar{parent=reactor_fills,x=8,y=2,show_percent=true,bar_fg_bg=cpair(colors.lightBlue,colors.gray),height=1,width=14} local hcool = HorizontalBar{parent=reactor_fills,x=8,y=4,show_percent=true,bar_fg_bg=cpair(colors.orange,colors.gray),height=1,width=14} local waste = HorizontalBar{parent=reactor_fills,x=8,y=5,show_percent=true,bar_fg_bg=cpair(colors.brown,colors.gray),height=1,width=14} + ps.subscribe("fuel", fuel.update) + ps.subscribe("ccool", ccool.update) + ps.subscribe("hcool", hcool.update) + ps.subscribe("waste", waste.update) + fuel.update(1) - cool.update(0.85) + ccool.update(0.85) hcool.update(0.08) waste.update(0.32) end diff --git a/coordinator/ui/components/turbine.lua b/coordinator/ui/components/turbine.lua index b4ad063..9498524 100644 --- a/coordinator/ui/components/turbine.lua +++ b/coordinator/ui/components/turbine.lua @@ -14,18 +14,29 @@ local TEXT_ALIGN = core.graphics.TEXT_ALIGN local cpair = core.graphics.cpair local border = core.graphics.border -local function new_view(root, x, y) +-- new turbine view +---@param root graphics_element +---@param x integer +---@param y integer +---@param ps psil +local function new_view(root, x, y, ps) local turbine = Rectangle{parent=root,border=border(1, colors.gray, true),width=23,height=7,x=x,y=y} local text_fg_bg = cpair(colors.black, colors.lightGray) local lu_col = cpair(colors.gray, colors.gray) local status = StateIndicator{parent=turbine,x=8,y=1,states=style.turbine.states,value=3,min_width=10} - local production = DataIndicator{parent=turbine,x=5,y=3,lu_colors=lu_col,label="",unit="MFE",format="%10.2f",value=3.2,width=16,fg_bg=text_fg_bg} + local prod_rate = DataIndicator{parent=turbine,x=5,y=3,lu_colors=lu_col,label="",unit="MFE",format="%10.2f",value=3.2,width=16,fg_bg=text_fg_bg} local flow_rate = DataIndicator{parent=turbine,x=5,y=4,lu_colors=lu_col,label="",unit="mB/t",format="%10.0f",value=801523,commas=true,width=16,fg_bg=text_fg_bg} + ps.subscribe("status", status.update) + ps.subscribe("prod_rate", prod_rate.update) + ps.subscribe("flow_rate", flow_rate.update) + local steam = VerticalBar{parent=turbine,x=2,y=1,fg_bg=cpair(colors.white,colors.gray),height=5,width=2} + ps.subscribe("steam", steam.update) + steam.update(0.12) end diff --git a/coordinator/ui/components/unit_overview.lua b/coordinator/ui/components/unit_overview.lua index e4c6b3a..6819930 100644 --- a/coordinator/ui/components/unit_overview.lua +++ b/coordinator/ui/components/unit_overview.lua @@ -17,25 +17,37 @@ local border = core.graphics.border local pipe = core.graphics.pipe ---@param parent graphics_element -local function make(parent, x, y, unit_id) +---@param x integer +---@param y integer +---@param unit coord_db_entry +local function make(parent, x, y, unit) -- bounding box div local root = Div{parent=parent,x=x,y=y,width=80,height=25} -- unit header message - TextBox{parent=root,text="Unit #" .. unit_id,alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} + TextBox{parent=root,text="Unit #" .. unit.unit_id,alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} + + local num_boilers = #unit.boiler_data_tbl + local num_turbines = #unit.turbine_data_tbl ------------- -- REACTOR -- ------------- - reactor_view(root, 1, 3) + reactor_view(root, 1, 3, unit.reactor_ps) - local coolant_pipes = { - pipe(0, 0, 11, 12, colors.lightBlue), - pipe(0, 0, 11, 3, colors.lightBlue), - pipe(2, 0, 11, 2, colors.orange), - pipe(2, 0, 11, 11, colors.orange) - } + local coolant_pipes = {} + + if num_boilers == 2 then + table.insert(coolant_pipes, pipe(0, 0, 11, 12, colors.lightBlue)) + end + + table.insert(coolant_pipes, pipe(0, 0, 11, 3, colors.lightBlue)) + table.insert(coolant_pipes, pipe(2, 0, 11, 2, colors.orange)) + + if num_boilers == 2 then + table.insert(coolant_pipes, pipe(2, 0, 11, 11, colors.orange)) + end PipeNetwork{parent=root,x=4,y=10,pipes=coolant_pipes,bg=colors.lightGray} @@ -43,41 +55,78 @@ local function make(parent, x, y, unit_id) -- BOILERS -- ------------- - boiler_view(root, 16, 11) - boiler_view(root, 16, 19) + boiler_view(root, 16, 11, unit.boiler_ps_tbl[1]) + if num_boilers == 2 then boiler_view(root, 16, 19, unit.boiler_ps_tbl[2]) end -------------- -- TURBINES -- -------------- - turbine_view(root, 58, 3) - turbine_view(root, 58, 11) - turbine_view(root, 58, 19) + local t_idx = 1 + + if num_turbines == 3 then + turbine_view(root, 58, 3, unit.turbine_ps_tbl[t_idx]) + t_idx = t_idx + 1 + end + + if num_turbines >= 1 then + turbine_view(root, 58, 11, unit.turbine_ps_tbl[t_idx]) + t_idx = t_idx + 1 + end + + if num_turbines >= 2 then turbine_view(root, 58, 19, unit.turbine_ps_tbl[t_idx]) end local steam_pipes_a = { - -- boiler 1 - pipe(0, 1, 6, 1, colors.white, false, true), - pipe(0, 2, 6, 2, colors.blue, false, true), - -- boiler 2 - pipe(0, 9, 6, 9, colors.white, false, true), - pipe(0, 10, 6, 10, colors.blue, false, true) + -- boiler 1 steam/water pipes + pipe(0, 1, 6, 1, colors.white, false, true), -- steam boiler 1 to turbine junction + pipe(0, 2, 6, 2, colors.blue, false, true) -- water boiler 1 to turbine junction } - local steam_pipes_b = { - -- turbines 1 & 2, pipes from boiler 1 - pipe(0, 9, 1, 2, colors.white, false, true), - pipe(1, 1, 3, 1, colors.white, false, false), - pipe(0, 9, 3, 9, colors.white, false, true), - pipe(0, 10, 2, 3, colors.blue, false, true), - pipe(2, 2, 3, 2, colors.blue, false, false), - pipe(0, 10, 3, 10, colors.blue, false, true), - -- turbine 3, pipes from boiler 2 - pipe(0, 18, 1, 9, colors.white, false, true), - pipe(1, 1, 3, 1, colors.white, false, false), - pipe(0, 17, 3, 17, colors.white, false, true), - pipe(0, 18, 2, 10, colors.blue, false, true), - pipe(0, 18, 3, 18, colors.blue, false, true), - } + if num_boilers == 2 then + -- boiler 2 steam/water pipes + table.insert(steam_pipes_a, pipe(0, 9, 6, 9, colors.white, false, true)) -- steam boiler 2 to turbine junction + table.insert(steam_pipes_a, pipe(0, 10, 6, 10, colors.blue, false, true)) -- water boiler 2 to turbine junction + end + + local steam_pipes_b = {} + + if num_turbines == 3 then + table.insert(steam_pipes_b, pipe(0, 9, 1, 2, colors.white, false, true)) -- steam boiler 1 to turbine 1 junction start + table.insert(steam_pipes_b, pipe(1, 1, 3, 1, colors.white, false, false)) -- steam boiler 1 to turbine 1 junction end + end + + table.insert(steam_pipes_b, pipe(0, 9, 3, 9, colors.white, false, true)) -- steam boiler 1 to turbine 2 + + if num_turbines == 3 then + table.insert(steam_pipes_b, pipe(0, 10, 2, 3, colors.blue, false, true)) -- water boiler 1 to turbine 1 junction start + table.insert(steam_pipes_b, pipe(2, 2, 3, 2, colors.blue, false, false)) -- water boiler 1 to turbine 1 junction end + end + + table.insert(steam_pipes_b, pipe(0, 10, 3, 10, colors.blue, false, true)) -- water boiler 1 to turbine 2 + + if num_turbines >= 2 then + if num_boilers == 2 then + table.insert(steam_pipes_b, pipe(0, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction + table.insert(steam_pipes_b, pipe(0, 17, 3, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3 + else + table.insert(steam_pipes_b, pipe(1, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction + table.insert(steam_pipes_b, pipe(1, 17, 3, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3 + end + + if num_boilers == 2 then + table.insert(steam_pipes_b, pipe(0, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3 + table.insert(steam_pipes_b, pipe(0, 18, 3, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction + else + table.insert(steam_pipes_b, pipe(2, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3 + table.insert(steam_pipes_b, pipe(2, 18, 3, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction + end + elseif num_turbines == 1 and num_boilers == 2 then + table.insert(steam_pipes_b, pipe(0, 17, 1, 9, colors.white, false, true)) -- steam boiler 2 to turbine 2 junction + table.insert(steam_pipes_b, pipe(0, 17, 1, 17, colors.white, false, true)) -- steam boiler 2 to turbine 3 + + table.insert(steam_pipes_b, pipe(0, 18, 2, 10, colors.blue, false, true)) -- water boiler 2 to turbine 3 + table.insert(steam_pipes_b, pipe(0, 18, 2, 18, colors.blue, false, true)) -- water boiler 2 to turbine 2 junction + end PipeNetwork{parent=root,x=47,y=11,pipes=steam_pipes_a,bg=colors.lightGray} PipeNetwork{parent=root,x=54,y=3,pipes=steam_pipes_b,bg=colors.lightGray} diff --git a/coordinator/ui/layout/main_view.lua b/coordinator/ui/layout/main_view.lua index da51586..f45413c 100644 --- a/coordinator/ui/layout/main_view.lua +++ b/coordinator/ui/layout/main_view.lua @@ -2,10 +2,12 @@ -- Main SCADA Coordinator GUI -- -local core = require("graphics.core") -local log = require("scada-common.log") +local log = require("scada-common.log") -local style = require("coordinator.ui.style") +local database = require("coordinator.database") +local style = require("coordinator.ui.style") + +local core = require("graphics.core") local DisplayBox = require("graphics.elements.displaybox") local TextBox = require("graphics.elements.textbox") @@ -20,11 +22,13 @@ local function init(monitor) -- window header message TextBox{parent=main,text="Nuclear Generation Facility SCADA Coordinator",alignment=TEXT_ALIGN.CENTER,height=1,fg_bg=style.header} + local db = database.get() + -- unit overviews - unit_overview(main, 2, 3, 1) - unit_overview(main, 84, 3, 2) - unit_overview(main, 2, 29, 3) - unit_overview(main, 84, 29, 4) + if db.facility.num_units >= 1 then unit_overview(main, 2, 3, db.units[1]) end + if db.facility.num_units >= 2 then unit_overview(main, 84, 3, db.units[2]) end + if db.facility.num_units >= 3 then unit_overview(main, 2, 29, db.units[3]) end + if db.facility.num_units == 4 then unit_overview(main, 84, 29, db.units[4]) end return main end