diff --git a/pocket/iocontrol.lua b/pocket/iocontrol.lua index 83b807c..c3ecc35 100644 --- a/pocket/iocontrol.lua +++ b/pocket/iocontrol.lua @@ -783,18 +783,32 @@ function iocontrol.record_unit_data(data) local ps = unit.turbine_ps_tbl[id] ---@type psil local turbine_status = 1 + local computed_status = 1 if unit.rtu_hw.turbines[id].connected then if unit.rtu_hw.turbines[id].faulted then turbine_status = 3 + computed_status = 3 elseif turbine.formed then turbine_status = 4 + + if turbine.tanks.energy_fill >= 0.99 then + computed_status = 6 + elseif turbine.state.flow_rate < 100 then + computed_status = 4 + else + computed_status = 5 + end else turbine_status = 2 + computed_status = 2 end + + _record_multiblock_status(unit.rtu_hw.turbines[id].faulted, turbine, ps) end ps.publish("TurbineStatus", turbine_status) + ps.publish("TurbineStateStatus", computed_status) end unit.tank_data_tbl = data[9] diff --git a/pocket/ui/apps/unit.lua b/pocket/ui/apps/unit.lua index 51c27b8..a6f28b3 100644 --- a/pocket/ui/apps/unit.lua +++ b/pocket/ui/apps/unit.lua @@ -11,6 +11,7 @@ local style = require("pocket.ui.style") local boiler = require("pocket.ui.pages.unit_boiler") local reactor = require("pocket.ui.pages.unit_reactor") +local turbine = require("pocket.ui.pages.unit_turbine") local core = require("graphics.core") @@ -74,11 +75,11 @@ local function new_view(root) } for i = 1, unit.num_boilers do - table.insert(list, { label = "B-" .. i, color = core.cpair(colors.black, colors.lightBlue), callback = nav_links[id].boiler[i] }) + table.insert(list, { label = "B-" .. i, color = core.cpair(colors.black, colors.lightGray), callback = nav_links[id].boiler[i] }) end for i = 1, unit.num_turbines do - table.insert(list, { label = "T-" .. i, color = core.cpair(colors.black, colors.white), callback = function () end }) + table.insert(list, { label = "T-" .. i, color = core.cpair(colors.black, colors.lightGray), callback = nav_links[id].turbine[i] }) end app.set_sidebar(list) @@ -336,6 +337,18 @@ local function new_view(root) end --#endregion + + --#region Turbine Tabs + + local tbn_pane = Div{parent=page_div} + nav_links[i].turbine = {} + + for t_id = 1, unit.num_turbines do + local ps = unit.turbine_ps_tbl[t_id] + nav_links[i].turbine[t_id] = turbine(app, u_page, panes, tbn_pane, i, t_id, ps, update) + end + + --#endregion end -- setup multipane diff --git a/pocket/ui/pages/unit_boiler.lua b/pocket/ui/pages/unit_boiler.lua index c161248..e15ae40 100644 --- a/pocket/ui/pages/unit_boiler.lua +++ b/pocket/ui/pages/unit_boiler.lua @@ -20,11 +20,11 @@ local PushButton = require("graphics.elements.controls.push_button") 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 -local red_ind_s = style.icon_states.red_ind_s -local yel_ind_s = style.icon_states.yel_ind_s +local label = style.label +local lu_col = style.label_unit_pair +local text_fg = style.text_fg +local red_ind_s = style.icon_states.red_ind_s +local yel_ind_s = style.icon_states.yel_ind_s -- create a boiler view in the unit app ---@param app pocket_app @@ -43,7 +43,7 @@ return function (app, u_page, panes, blr_pane, b_id, ps, update) local blr_page = app.new_page(u_page, #panes) blr_page.tasks = { update } - TextBox{parent=blr_div,y=1,text="Boiler "..b_id,width=8,height=1} + TextBox{parent=blr_div,y=1,text="BLR #"..b_id,width=8,height=1} local status = StateIndicator{parent=blr_div,x=10,y=1,states=style.boiler.states,value=1,min_width=12} status.register(ps, "BoilerStateStatus", status.update) diff --git a/pocket/ui/pages/unit_turbine.lua b/pocket/ui/pages/unit_turbine.lua new file mode 100644 index 0000000..b4d9a2e --- /dev/null +++ b/pocket/ui/pages/unit_turbine.lua @@ -0,0 +1,117 @@ +local util = require("scada-common.util") + +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 DataIndicator = require("graphics.elements.indicators.data") +local IconIndicator = require("graphics.elements.indicators.icon") +local PowerIndicator = require("graphics.elements.indicators.power") +local StateIndicator = require("graphics.elements.indicators.state") +local VerticalBar = require("graphics.elements.indicators.vbar") + +local PushButton = require("graphics.elements.controls.push_button") + +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 +local tri_ind_s = style.icon_states.tri_ind_s +local red_ind_s = style.icon_states.red_ind_s +local yel_ind_s = style.icon_states.yel_ind_s + +-- create a turbine view in the unit app +---@param app pocket_app +---@param u_page nav_tree_page +---@param panes table +---@param tbn_pane graphics_element +---@param u_id integer unit ID +---@param t_id integer turbine ID +---@param ps psil +---@param update function +return function (app, u_page, panes, tbn_pane, u_id, t_id, ps, update) + local db = iocontrol.get_db() + + local tbn_div = Div{parent=tbn_pane,x=2,width=tbn_pane.get_width()-2} + table.insert(panes, tbn_div) + + local tbn_page = app.new_page(u_page, #panes) + tbn_page.tasks = { update } + + TextBox{parent=tbn_div,y=1,text="TRBN #"..t_id,width=8,height=1} + local status = StateIndicator{parent=tbn_div,x=10,y=1,states=style.turbine.states,value=1,min_width=12} + status.register(ps, "TurbineStateStatus", status.update) + + local steam = VerticalBar{parent=tbn_div,x=1,y=4,fg_bg=cpair(colors.white,colors.gray),height=5,width=1} + local ccool = VerticalBar{parent=tbn_div,x=21,y=4,fg_bg=cpair(colors.green,colors.gray),height=5,width=1} + + TextBox{parent=tbn_div,text="S",x=1,y=3,width=1,height=1,fg_bg=label} + TextBox{parent=tbn_div,text="E",x=21,y=3,width=1,height=1,fg_bg=label} + + steam.register(ps, "steam_fill", steam.update) + ccool.register(ps, "energy_fill", ccool.update) + + TextBox{parent=tbn_div,text="Production",x=3,y=3,width=17,height=1,fg_bg=label} + local prod_rate = PowerIndicator{parent=tbn_div,x=3,y=4,lu_colors=lu_col,label="",format="%11.2f",value=0,rate=true,width=17,fg_bg=text_fg} + TextBox{parent=tbn_div,text="Flow Rate",x=3,y=5,width=17,height=1,fg_bg=label} + local flow_rate = DataIndicator{parent=tbn_div,x=3,y=6,lu_colors=lu_col,label="",unit="mB/t",format="%11.0f",value=0,commas=true,width=17,fg_bg=text_fg} + TextBox{parent=tbn_div,text="Steam Input Rate",x=3,y=7,width=17,height=1,fg_bg=label} + local input_rate = DataIndicator{parent=tbn_div,x=3,y=8,lu_colors=lu_col,label="",unit="mB/t",format="%11.0f",value=0,commas=true,width=17,fg_bg=text_fg} + + prod_rate.register(ps, "prod_rate", function (val) prod_rate.update(util.joules_to_fe(val)) end) + flow_rate.register(ps, "flow_rate", flow_rate.update) + input_rate.register(ps, "steam_input_rate", input_rate.update) + + local t_sdo = IconIndicator{parent=tbn_div,y=10,label="Steam Dumping",states=tri_ind_s} + local t_tos = IconIndicator{parent=tbn_div,label="Over Speed",states=red_ind_s} + local t_gtrp = IconIndicator{parent=tbn_div,label="Generator Trip",states=yel_ind_s} + local t_trp = IconIndicator{parent=tbn_div,label="Turbine Trip",states=red_ind_s} + + t_sdo.register(ps, "SteamDumpOpen", t_sdo.update) + t_tos.register(ps, "TurbineOverSpeed", t_tos.update) + t_gtrp.register(ps, "GeneratorTrip", t_gtrp.update) + t_trp.register(ps, "TurbineTrip", t_trp.update) + + + local tbn_ext_div = Div{parent=tbn_pane,x=2,width=tbn_pane.get_width()-2} + table.insert(panes, tbn_ext_div) + + local tbn_ext_page = app.new_page(tbn_page, #panes) + tbn_ext_page.tasks = { update } + + PushButton{parent=tbn_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=tbn_ext_page.nav_to} + PushButton{parent=tbn_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=tbn_page.nav_to} + + TextBox{parent=tbn_ext_div,y=1,text="More Turbine Info",height=1,alignment=ALIGN.CENTER} + + TextBox{parent=tbn_ext_div,text="Steam Tank",x=1,y=3,width=10,height=1,fg_bg=label} + local steam_p = DataIndicator{parent=tbn_ext_div,x=14,y=3,lu_colors=lu_col,label="",unit="%",format="%6.2f",value=0,width=8,fg_bg=text_fg} + local steam_amnt = DataIndicator{parent=tbn_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} + + steam_p.register(ps, "steam_fill", function (x) steam_p.update(x * 100) end) + steam_amnt.register(ps, "steam", function (x) steam_amnt.update(x.amount) end) + + TextBox{parent=tbn_ext_div,text="Energy Fill",x=1,y=6,width=12,height=1,fg_bg=label} + local charge_p = DataIndicator{parent=tbn_ext_div,x=14,y=6,lu_colors=lu_col,label="",unit="%",format="%6.2f",value=0,width=8,fg_bg=text_fg} + local charge_amnt = PowerIndicator{parent=tbn_ext_div,x=1,y=7,lu_colors=lu_col,label="",format="%17.4f",value=0,width=21,fg_bg=text_fg} + + charge_p.register(ps, "energy_fill", function (x) charge_p.update(x * 100) end) + charge_amnt.register(ps, "energy", charge_amnt.update) + + TextBox{parent=tbn_ext_div,text="Rotation Rate",x=1,y=9,width=13,height=1,fg_bg=label} + local rotation = DataIndicator{parent=tbn_ext_div,x=1,y=10,lu_colors=lu_col,label="",unit="",format="%21.12f",value=0,width=21,fg_bg=text_fg} + + rotation.register(ps, "steam", function () + local status, result = pcall(function () return util.turbine_rotation(db.units[u_id].turbine_data_tbl[t_id]) end) + if status then rotation.update(result) end + end) + + return tbn_page.nav_to +end diff --git a/pocket/ui/style.lua b/pocket/ui/style.lua index f91d7b8..ad4a231 100644 --- a/pocket/ui/style.lua +++ b/pocket/ui/style.lua @@ -57,6 +57,12 @@ states.emc_ind_s = { { color = cpair(colors.black, colors.green), symbol = "+" } } +states.tri_ind_s = { + { color = cpair(colors.black, colors.lightGray), symbol = "+" }, + { color = cpair(colors.black, colors.yellow), symbol = "\x1e" }, + { color = cpair(colors.black, colors.red), symbol = "-" } +} + states.red_ind_s = { { color = cpair(colors.black, colors.lightGray), symbol = "+" }, { color = cpair(colors.black, colors.red), symbol = "-" } diff --git a/scada-common/util.lua b/scada-common/util.lua index d29a85e..344ffd8 100644 --- a/scada-common/util.lua +++ b/scada-common/util.lua @@ -4,6 +4,8 @@ local cc_strings = require("cc.strings") +local const = require("scada-common.constants") + local math = math local string = string local table = table @@ -368,7 +370,7 @@ end --#endregion ---#region MEKANISM POWER +--#region MEKANISM MATH -- convert Joules to FE ---@nodiscard @@ -434,6 +436,22 @@ function util.power_format(fe, combine_label, format) end end +-- compute Mekanism's rotation rate for a turbine +---@nodiscard +---@param turbine turbinev_session_db turbine data +function util.turbine_rotation(turbine) + local build = turbine.build + + local inner_vol = build.steam_cap / const.mek.TURBINE_GAS_PER_TANK + local disp_rate = (build.dispersers * const.mek.TURBINE_DISPERSER_FLOW) * inner_vol + local vent_rate = build.vents * const.mek.TURBINE_VENT_FLOW + + local max_rate = math.min(disp_rate, vent_rate) + local flow = math.min(max_rate, turbine.tanks.steam.amount) + + return (flow * (turbine.tanks.steam.amount / build.steam_cap)) / max_rate +end + --#endregion --#region UTILITY CLASSES diff --git a/supervisor/startup.lua b/supervisor/startup.lua index f83e973..89c38d8 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -21,7 +21,7 @@ local supervisor = require("supervisor.supervisor") local svsessions = require("supervisor.session.svsessions") -local SUPERVISOR_VERSION = "v1.3.11" +local SUPERVISOR_VERSION = "v1.3.12" local println = util.println local println_ts = util.println_ts diff --git a/supervisor/unitlogic.lua b/supervisor/unitlogic.lua index 3fe2ebc..20b00ff 100644 --- a/supervisor/unitlogic.lua +++ b/supervisor/unitlogic.lua @@ -39,21 +39,6 @@ local ALARM_LIMS = const.ALARM_LIMITS ---@class unit_logic_extension local logic = {} --- compute Mekanism's rotation rate for a turbine ----@param turbine turbinev_session_db -local function turbine_rotation(turbine) - local build = turbine.build - - local inner_vol = build.steam_cap / const.mek.TURBINE_GAS_PER_TANK - local disp_rate = (build.dispersers * const.mek.TURBINE_DISPERSER_FLOW) * inner_vol - local vent_rate = build.vents * const.mek.TURBINE_VENT_FLOW - - local max_rate = math.min(disp_rate, vent_rate) - local flow = math.min(max_rate, turbine.tanks.steam.amount) - - return (flow * (turbine.tanks.steam.amount / build.steam_cap)) / max_rate -end - -- update the annunciator ---@param self _unit_self function logic.update_annunciator(self) @@ -333,7 +318,7 @@ function logic.update_annunciator(self) local last = self.turbine_stability_data[i] if (not self.turbine_flow_stable) and (turbine.state.steam_input_rate > 0) then - local rotation = turbine_rotation(turbine) + local rotation = util.turbine_rotation(turbine) local rotation_stable = false -- see if data updated, and if so, check rotation speed change