From d1e4ea586ea6d7477afc65ad7db400b8c4f62c9f Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Tue, 5 Mar 2024 21:47:14 -0500 Subject: [PATCH] supervisor comment cleanup --- supervisor/facility.lua | 48 +++++++++++++++++++++++++++++++--------- supervisor/startup.lua | 2 +- supervisor/unit.lua | 22 +++++++++--------- supervisor/unitlogic.lua | 30 ++++++++++++------------- 4 files changed, 63 insertions(+), 39 deletions(-) diff --git a/supervisor/facility.lua b/supervisor/facility.lua index 94f93b3..43c6cc4 100644 --- a/supervisor/facility.lua +++ b/supervisor/facility.lua @@ -152,6 +152,8 @@ function facility.new(num_reactors, cooling_conf) table.insert(self.test_tone_states, false) end + -- PRIVATE FUNCTIONS -- + -- check if all auto-controlled units completed ramping ---@nodiscard local function _all_units_ramped() @@ -228,7 +230,7 @@ function facility.new(num_reactors, cooling_conf) ---@class facility local public = {} - -- ADD/LINK DEVICES -- + --#region Add/Link Devices -- link a redstone RTU session ---@param rs_unit unit_session @@ -268,11 +270,9 @@ function facility.new(num_reactors, cooling_conf) for _, v in pairs(self.rtu_list) do util.filter_table(v, function (s) return s.get_session_id() ~= session end) end end - -- UPDATE -- + --#endregion - -- supervisor sessions reporting the list of active RTU sessions - ---@param rtu_sessions table session list of all connected RTUs - function public.report_rtus(rtu_sessions) self.rtu_conn_count = #rtu_sessions end + --#region Update -- update (iterate) the facility management function public.update() @@ -323,7 +323,7 @@ function facility.new(num_reactors, cooling_conf) -- Run Process Control -- ------------------------- - --#region Process Control + --#region local avg_charge = self.avg_charge.compute() local avg_inflow = self.avg_inflow.compute() @@ -597,7 +597,7 @@ function facility.new(num_reactors, cooling_conf) -- Evaluate Automatic SCRAM -- ------------------------------ - --#region Automatic SCRAM + --#region local astatus = self.ascram_status @@ -727,6 +727,8 @@ function facility.new(num_reactors, cooling_conf) -- Handle Redstone I/O -- ------------------------- + --#region + if #self.redstone > 0 then -- handle facility SCRAM if self.io_ctl.digital_read(IO.F_SCRAM) then @@ -756,10 +758,14 @@ function facility.new(num_reactors, cooling_conf) self.io_ctl.digital_write(IO.F_ALARM_ANY, has_any_alarm) end + --#endregion + ---------------- -- Unit Tasks -- ---------------- + --#region + local insufficent_po_rate = false local need_emcool = false @@ -798,10 +804,14 @@ function facility.new(num_reactors, cooling_conf) end end + --#endregion + ------------------------ -- Update Alarm Tones -- ------------------------ + --#region + local allow_test = self.allow_testing and self.test_tone_set local alarms = { false, false, false, false, false, false, false, false, false, false, false, false } @@ -888,6 +898,8 @@ function facility.new(num_reactors, cooling_conf) self.test_tone_set = false self.test_tone_reset = true end + + --#endregion end -- call the update function of all units in the facility
@@ -900,7 +912,9 @@ function facility.new(num_reactors, cooling_conf) end end - -- COMMANDS -- + --#endregion + + --#region Commands -- SCRAM all reactor units function public.scram_all() @@ -988,7 +1002,9 @@ function facility.new(num_reactors, cooling_conf) } end - -- SETTINGS -- + --#endregion + + --#region Settings -- set the automatic control group of a unit ---@param unit_id integer unit ID @@ -1029,7 +1045,9 @@ function facility.new(num_reactors, cooling_conf) return self.pu_fallback end - -- DIAGNOSTIC TESTING -- + --#endregion + + --#region Diagnostic Testing -- attempt to set a test tone state ---@param id TONE|0 tone ID or 0 to disable all @@ -1069,7 +1087,9 @@ function facility.new(num_reactors, cooling_conf) return self.allow_testing, self.test_alarm_states end - -- READ STATES/PROPERTIES -- + --#endregion + + --#region Read States/Properties -- get current alarm tone on/off states ---@nodiscard @@ -1183,6 +1203,12 @@ function facility.new(num_reactors, cooling_conf) return status end + --#endregion + + -- supervisor sessions reporting the list of active RTU sessions + ---@param rtu_sessions table session list of all connected RTUs + function public.report_rtus(rtu_sessions) self.rtu_conn_count = #rtu_sessions end + -- get the units in this facility ---@nodiscard function public.get_units() return self.units end diff --git a/supervisor/startup.lua b/supervisor/startup.lua index 7176c3e..72c0c97 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.2.10" +local SUPERVISOR_VERSION = "v1.2.11" local println = util.println local println_ts = util.println_ts diff --git a/supervisor/unit.lua b/supervisor/unit.lua index e5f29b2..afdf6f3 100644 --- a/supervisor/unit.lua +++ b/supervisor/unit.lua @@ -255,7 +255,7 @@ function unit.new(reactor_id, num_boilers, num_turbines) -- PRIVATE FUNCTIONS -- - --#region time derivative utility functions + --#region Time Derivative Utility Functions -- compute a change with respect to time of the given value ---@param key string value key @@ -330,7 +330,7 @@ function unit.new(reactor_id, num_boilers, num_turbines) --#endregion - --#region redstone I/O + --#region Redstone I/O -- create a generic valve interface ---@nodiscard @@ -397,8 +397,7 @@ function unit.new(reactor_id, num_boilers, num_turbines) ---@class reactor_unit local public = {} - -- ADD/LINK DEVICES -- - --#region + --#region Add/Link Devices -- link the PLC ---@param plc_session plc_session_struct @@ -488,7 +487,7 @@ function unit.new(reactor_id, num_boilers, num_turbines) --#endregion - -- UPDATE SESSION -- + --#region Update Session -- update (iterate) this unit function public.update() @@ -556,8 +555,9 @@ function unit.new(reactor_id, num_boilers, num_turbines) end end - -- AUTO CONTROL OPERATIONS -- - --#region + --#endregion + + --#region Auto Control Operations -- engage automatic control function public.auto_engage() @@ -644,8 +644,7 @@ function unit.new(reactor_id, num_boilers, num_turbines) --#endregion - -- OPERATIONS -- - --#region + --#region Operations -- queue a command to disable the reactor function public.disable() @@ -725,8 +724,7 @@ function unit.new(reactor_id, num_boilers, num_turbines) --#endregion - -- READ STATES/PROPERTIES -- - --#region + --#region Read States/Properties -- check if an alarm of at least a certain priority level is tripped ---@nodiscard @@ -877,7 +875,7 @@ function unit.new(reactor_id, num_boilers, num_turbines) return status end - -- get the current total [max] production rate is + -- get the current total max production rate ---@nodiscard ---@return number total_avail_rate function public.get_sna_rate() diff --git a/supervisor/unitlogic.lua b/supervisor/unitlogic.lua index e207c44..f43ff03 100644 --- a/supervisor/unitlogic.lua +++ b/supervisor/unitlogic.lua @@ -54,9 +54,7 @@ function logic.update_annunciator(self) -- variables for boiler, or reactor if no boilers used local total_boil_rate = 0.0 - ------------- - -- REACTOR -- - ------------- + --#region Reactor annunc.AutoControl = self.auto_engaged @@ -143,9 +141,9 @@ function logic.update_annunciator(self) self.plc_cache.ok = false end - --------------- - -- MISC RTUs -- - --------------- + --#endregion + + --#region Misc RTUs local max_rad, any_faulted = 0, false @@ -170,9 +168,9 @@ function logic.update_annunciator(self) end end - ------------- - -- BOILERS -- - ------------- + --#endregion + + --#region Boilers local boilers_ready = num_boilers == #self.boilers @@ -230,9 +228,9 @@ function logic.update_annunciator(self) boiler_water_dt_sum = _get_dt(DT_KEYS.ReactorCCool) end - --------------------------- - -- COOLANT FEED MISMATCH -- - --------------------------- + --#endregion + + --#region Coolant Feed Mismatch -- check coolant feed mismatch if using boilers, otherwise calculate with reactor local cfmismatch = false @@ -263,9 +261,9 @@ function logic.update_annunciator(self) annunc.CoolantFeedMismatch = cfmismatch - -------------- - -- TURBINES -- - -------------- + --#endregion + + --#region Turbines local turbines_ready = num_turbines == #self.turbines @@ -340,6 +338,8 @@ function logic.update_annunciator(self) annunc.TurbineTrip[idx] = has_steam and db.state.flow_rate == 0 end + --#endregion + -- update auto control ready state for this unit self.db.control.ready = plc_ready and boilers_ready and turbines_ready end