From 402d8607b6262ab2dbafa3c99b0dc80e3271de8d Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sun, 8 Sep 2024 13:26:43 -0400 Subject: [PATCH] added AUTO_GROUP enum --- coordinator/iocontrol.lua | 5 ++--- coordinator/ui/components/unit_detail.lua | 12 ++++++------ pocket/iocontrol.lua | 15 ++++++--------- pocket/ui/apps/control.lua | 9 ++++++--- scada-common/types.lua | 17 +++++++++++++++++ supervisor/facility.lua | 13 +++++++------ 6 files changed, 44 insertions(+), 27 deletions(-) diff --git a/coordinator/iocontrol.lua b/coordinator/iocontrol.lua index 956cf41..37230b3 100644 --- a/coordinator/iocontrol.lua +++ b/coordinator/iocontrol.lua @@ -182,7 +182,7 @@ function iocontrol.init(conf, comms, temp_scale, energy_scale) turbine_flow_stable = false, -- auto control group - a_group = 0, + a_group = types.AUTO_GROUP.MANUAL, start = function () io.process.start(i) end, scram = function () io.process.scram(i) end, @@ -569,11 +569,10 @@ function iocontrol.update_facility_status(status) local group_map = ctl_status[14] if (type(group_map) == "table") and (#group_map == fac.num_units) then - local names = { "Manual", "Primary", "Secondary", "Tertiary", "Backup" } for i = 1, #group_map do io.units[i].a_group = group_map[i] io.units[i].unit_ps.publish("auto_group_id", group_map[i]) - io.units[i].unit_ps.publish("auto_group", names[group_map[i] + 1]) + io.units[i].unit_ps.publish("auto_group", types.AUTO_GROUP_NAMES[group_map[i] + 1]) end end diff --git a/coordinator/ui/components/unit_detail.lua b/coordinator/ui/components/unit_detail.lua index d898d34..fcfd062 100644 --- a/coordinator/ui/components/unit_detail.lua +++ b/coordinator/ui/components/unit_detail.lua @@ -29,6 +29,8 @@ local PushButton = require("graphics.elements.controls.push_button") local RadioButton = require("graphics.elements.controls.radio_button") local SpinboxNumeric = require("graphics.elements.controls.spinbox_numeric") +local AUTO_GROUP = types.AUTO_GROUP + local ALIGN = core.ALIGN local cpair = core.cpair @@ -382,7 +384,7 @@ local function init(parent, id) if (unit.reactor_data ~= nil) and (unit.reactor_data.mek_status ~= nil) then local can_start = (not unit.reactor_data.mek_status.status) and (not unit.reactor_data.rps_tripped) and - (unit.a_group == 0) + (unit.a_group == AUTO_GROUP.MANUAL) if can_start then start.enable() else start.disable() end end end @@ -486,9 +488,7 @@ local function init(parent, id) local auto_ctl = Rectangle{parent=main,border=border(1,colors.purple,true),thin=true,width=13,height=15,x=32,y=37} local auto_div = Div{parent=auto_ctl,width=13,height=15,x=1,y=1} - local ctl_opts = { "Manual", "Primary", "Secondary", "Tertiary", "Backup" } - - local group = RadioButton{parent=auto_div,options=ctl_opts,callback=function()end,radio_colors=cpair(style.theme.accent_dark,style.theme.accent_light),select_color=colors.purple} + local group = RadioButton{parent=auto_div,options=types.AUTO_GROUP_NAMES,callback=function()end,radio_colors=cpair(style.theme.accent_dark,style.theme.accent_light),select_color=colors.purple} group.register(u_ps, "auto_group_id", function (gid) group.set_value(gid + 1) end) @@ -523,10 +523,10 @@ local function init(parent, id) -- enable/disable controls based on group assignment (start button is separate) burn_rate.register(u_ps, "auto_group_id", function (gid) - if gid == 0 then burn_rate.enable() else burn_rate.disable() end + if gid == AUTO_GROUP.MANUAL then burn_rate.enable() else burn_rate.disable() end end) set_burn_btn.register(u_ps, "auto_group_id", function (gid) - if gid == 0 then set_burn_btn.enable() else set_burn_btn.disable() end + if gid == AUTO_GROUP.MANUAL then set_burn_btn.enable() else set_burn_btn.disable() end end) -- can't change group if auto is engaged regardless of if this unit is part of auto control diff --git a/pocket/iocontrol.lua b/pocket/iocontrol.lua index 61f761d..d71911f 100644 --- a/pocket/iocontrol.lua +++ b/pocket/iocontrol.lua @@ -2,11 +2,10 @@ -- I/O Control for Pocket Integration with Supervisor & Coordinator -- -local const = require("scada-common.constants") --- local log = require("scada-common.log") -local psil = require("scada-common.psil") -local types = require("scada-common.types") -local util = require("scada-common.util") +local const = require("scada-common.constants") +local psil = require("scada-common.psil") +local types = require("scada-common.types") +local util = require("scada-common.util") local process = require("pocket.process") @@ -22,8 +21,6 @@ local TEMP_UNITS = types.TEMP_SCALE_UNITS local WARN_TT = 40 local HIGH_TT = 80 -local GROUP_NAMES = { "Manual", "Primary", "Secondary", "Tertiary", "Backup" } - local iocontrol = {} ---@enum POCKET_LINK_STATE @@ -318,7 +315,7 @@ function iocontrol.init_fac(conf) turbine_flow_stable = false, -- auto control group - a_group = 0, + a_group = types.AUTO_GROUP.MANUAL, start = function () process.start(i) end, scram = function () process.scram(i) end, @@ -499,7 +496,7 @@ function iocontrol.record_unit_data(data) unit.alarms = data[5] unit.unit_ps.publish("auto_group_id", unit.a_group) - unit.unit_ps.publish("auto_group", GROUP_NAMES[unit.a_group + 1]) + unit.unit_ps.publish("auto_group", types.AUTO_GROUP_NAMES[unit.a_group + 1]) --#region Annunciator diff --git a/pocket/ui/apps/control.lua b/pocket/ui/apps/control.lua index 99d363a..6cd1a76 100644 --- a/pocket/ui/apps/control.lua +++ b/pocket/ui/apps/control.lua @@ -2,6 +2,7 @@ -- Unit Control Page -- +local types = require("scada-common.types") local util = require("scada-common.util") local iocontrol = require("pocket.iocontrol") @@ -26,6 +27,8 @@ local NumberField = require("graphics.elements.form.number_field") local DataIndicator = require("graphics.elements.indicators.data") local IconIndicator = require("graphics.elements.indicators.icon") +local AUTO_GROUP = types.AUTO_GROUP + local ALIGN = core.ALIGN local cpair = core.cpair @@ -146,10 +149,10 @@ local function new_view(root) -- enable/disable controls based on group assignment (start button is separate) burn_cmd.register(u_ps, "auto_group_id", function (gid) - if gid == 0 then burn_cmd.enable() else burn_cmd.disable() end + if gid == AUTO_GROUP.MANUAL then burn_cmd.enable() else burn_cmd.disable() end end) set_burn_btn.register(u_ps, "auto_group_id", function (gid) - if gid == 0 then set_burn_btn.enable() else set_burn_btn.disable() end + if gid == AUTO_GROUP.MANUAL then set_burn_btn.enable() else set_burn_btn.disable() end end) burn_cmd.register(u_ps, "burn_rate", burn_cmd.set_value) @@ -169,7 +172,7 @@ local function new_view(root) if (unit.reactor_data ~= nil) and (unit.reactor_data.mek_status ~= nil) then local can_start = (not unit.reactor_data.mek_status.status) and (not unit.reactor_data.rps_tripped) and - (unit.a_group == 0) + (unit.a_group == AUTO_GROUP.MANUAL) if can_start then start.enable() else start.disable() end end end diff --git a/scada-common/types.lua b/scada-common/types.lua index c27d2d7..2bf6ae1 100644 --- a/scada-common/types.lua +++ b/scada-common/types.lua @@ -209,6 +209,23 @@ types.PROCESS_NAMES = { "GEN_RATE_FAULT_IDLE" } +---@enum AUTO_GROUP +types.AUTO_GROUP = { + MANUAL = 0, + PRIMARY = 1, + SECONDARY = 2, + TERTIARY = 3, + BACKUP = 4 +} + +types.AUTO_GROUP_NAMES = { + "Manual", + "Primary", + "Secondary", + "Tertiary", + "Backup" +} + ---@enum WASTE_MODE types.WASTE_MODE = { AUTO = 1, diff --git a/supervisor/facility.lua b/supervisor/facility.lua index 9948023..7b786a2 100644 --- a/supervisor/facility.lua +++ b/supervisor/facility.lua @@ -8,6 +8,7 @@ local fac_update = require("supervisor.facility_update") local rsctl = require("supervisor.session.rsctl") local svsessions = require("supervisor.session.svsessions") +local AUTO_GROUP = types.AUTO_GROUP local PROCESS = types.PROCESS local RTU_ID_FAIL = types.RTU_ID_FAIL local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE @@ -73,7 +74,7 @@ function facility.new(config) burn_target = 0.1, -- burn rate target for aggregate burn mode charge_setpoint = 0, -- FE charge target setpoint gen_rate_setpoint = 0, -- FE/t charge rate target setpoint - group_map = {}, ---@type integer[] units -> group IDs + group_map = {}, ---@type AUTO_GROUP[] units -> group IDs prio_defs = { {}, {}, {}, {} }, ---@type reactor_unit[][] priority definitions (each level is a table of units) at_max_burn = false, ascram = false, @@ -130,7 +131,7 @@ function facility.new(config) for i = 1, config.UnitCount do table.insert(self.units, unit.new(i, self.cooling_conf.r_cool[i].BoilerCount, self.cooling_conf.r_cool[i].TurbineCount, config.ExtChargeIdling)) - table.insert(self.group_map, 0) + table.insert(self.group_map, AUTO_GROUP.MANUAL) end -- list for RTU session management @@ -454,19 +455,19 @@ function facility.new(config) -- set the automatic control group of a unit ---@param unit_id integer unit ID - ---@param group integer group ID or 0 for independent + ---@param group AUTO_GROUP group ID or 0 for independent function public.set_group(unit_id, group) - if (group >= 0 and group <= 4) and (unit_id > 0 and unit_id <= config.UnitCount) and self.mode == PROCESS.INACTIVE then + if (group >= AUTO_GROUP.MANUAL and group <= AUTO_GROUP.BACKUP) and (unit_id > 0 and unit_id <= config.UnitCount) and self.mode == PROCESS.INACTIVE then -- remove from old group if previously assigned local old_group = self.group_map[unit_id] - if old_group ~= 0 then + if old_group ~= AUTO_GROUP.MANUAL then util.filter_table(self.prio_defs[old_group], function (u) return u.get_id() ~= unit_id end) end self.group_map[unit_id] = group -- add to group if not independent - if group > 0 then + if group > AUTO_GROUP.MANUAL then table.insert(self.prio_defs[group], self.units[unit_id]) end end