From 9393b1830d05637e01f66c0fd7ed49bf5da62dfc Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Wed, 30 Apr 2025 10:17:09 -0400 Subject: [PATCH] restored use of self for unit logic function calls --- supervisor/unit.lua | 13 ++++------ supervisor/unit_logic.lua | 51 +++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/supervisor/unit.lua b/supervisor/unit.lua index 7f5e50b..6129d04 100644 --- a/supervisor/unit.lua +++ b/supervisor/unit.lua @@ -240,9 +240,6 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle, aux_coolant) } } - -- provide self to unit logic functions - local logic = unit_logic(self) - -- list for RTU session management self.rtu_list = { self.redstone, self.boilers, self.turbines, self.tanks, self.snas, self.envd } @@ -586,20 +583,20 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle, aux_coolant) _dt__compute_all() -- update annunciator logic - logic.update_annunciator() + unit_logic.update_annunciator(self) -- update alarm status - logic.update_alarms() + unit_logic.update_alarms(self) -- if in auto mode, SCRAM on certain alarms - logic.update_auto_safety(public) + unit_logic.update_auto_safety(self, public) -- update status text - logic.update_status_text() + unit_logic.update_status_text(self) -- handle redstone I/O if #self.redstone > 0 then - logic.handle_redstone() + unit_logic.handle_redstone(self) elseif not self.plc_cache.rps_trip then self.em_cool_opened = false end diff --git a/supervisor/unit_logic.lua b/supervisor/unit_logic.lua index fd6a67f..db8af3a 100644 --- a/supervisor/unit_logic.lua +++ b/supervisor/unit_logic.lua @@ -31,13 +31,12 @@ local ALARM_LIMS = const.ALARM_LIMITS local FLOW_STABILITY_DELAY_MS = const.FLOW_STABILITY_DELAY_MS local RS_THRESH = const.RS_THRESHOLDS -local self = nil ---@type _unit_self - ---@class unit_logic_extension local logic = {} -- update the annunciator -function logic.update_annunciator() +---@param self _unit_self +function logic.update_annunciator(self) local DT_KEYS = self.types.DT_KEYS local _get_dt = self._get_dt @@ -421,21 +420,23 @@ function logic.update_annunciator() end -- update an alarm state given conditions +---@param self _unit_self ---@param tripped boolean if the alarm condition is still active ---@param alarm alarm_def alarm table ---@return boolean new_trip if the alarm just changed to being tripped -local function _update_alarm_state(tripped, alarm) +local function _update_alarm_state(self, tripped, alarm) return alarm_ctl.update_alarm_state("UNIT " .. self.r_id, self.db.alarm_states, tripped, alarm) end -- evaluate alarm conditions -function logic.update_alarms() +---@param self _unit_self +function logic.update_alarms(self) local annunc = self.db.annunciator local plc_cache = self.plc_cache -- Containment Breach -- lost plc with critical damage (rip plc, you will be missed) - _update_alarm_state((not plc_cache.ok) and (plc_cache.damage > 99), self.alarms.ContainmentBreach) + _update_alarm_state(self, (not plc_cache.ok) and (plc_cache.damage > 99), self.alarms.ContainmentBreach) -- Containment Radiation local rad_alarm = false @@ -444,38 +445,38 @@ function logic.update_alarms() rad_alarm = self.last_radiation >= ALARM_LIMS.HIGH_RADIATION break end - _update_alarm_state(rad_alarm, self.alarms.ContainmentRadiation) + _update_alarm_state(self, rad_alarm, self.alarms.ContainmentRadiation) -- Reactor Lost - _update_alarm_state(self.had_reactor and self.plc_i == nil, self.alarms.ReactorLost) + _update_alarm_state(self, self.had_reactor and self.plc_i == nil, self.alarms.ReactorLost) -- Critical Damage - _update_alarm_state(plc_cache.damage >= 100, self.alarms.CriticalDamage) + _update_alarm_state(self, plc_cache.damage >= 100, self.alarms.CriticalDamage) -- Reactor Damage local rps_dmg_90 = plc_cache.rps_status.high_dmg and not self.last_rps_trips.high_dmg - if _update_alarm_state((plc_cache.damage > 0) or rps_dmg_90, self.alarms.ReactorDamage) then + if _update_alarm_state(self, (plc_cache.damage > 0) or rps_dmg_90, self.alarms.ReactorDamage) then log.debug(util.c(">> Trip Detail Report for ", types.ALARM_NAMES[self.alarms.ReactorDamage.id]," <<")) log.debug(util.c("| plc_cache.damage[", plc_cache.damage, "] rps_dmg_90[", rps_dmg_90, "]")) end -- Over-Temperature local rps_high_temp = plc_cache.rps_status.high_temp and not self.last_rps_trips.high_temp - if _update_alarm_state((plc_cache.temp >= 1200) or rps_high_temp, self.alarms.ReactorOverTemp) then + if _update_alarm_state(self, (plc_cache.temp >= 1200) or rps_high_temp, self.alarms.ReactorOverTemp) then log.debug(util.c(">> Trip Detail Report for ", types.ALARM_NAMES[self.alarms.ReactorOverTemp.id]," <<")) log.debug(util.c("| plc_cache.temp[", plc_cache.temp, "] rps_high_temp[", rps_high_temp, "]")) end -- High Temperature local high_temp = math.min(math.max(self.plc_cache.high_temp_lim, 1100), 1199.995) - _update_alarm_state(plc_cache.temp >= high_temp, self.alarms.ReactorHighTemp) + _update_alarm_state(self, plc_cache.temp >= high_temp, self.alarms.ReactorHighTemp) -- Waste Leak - _update_alarm_state(plc_cache.waste >= 1.0, self.alarms.ReactorWasteLeak) + _update_alarm_state(self, plc_cache.waste >= 1.0, self.alarms.ReactorWasteLeak) -- High Waste local rps_high_waste = plc_cache.rps_status.ex_waste and not self.last_rps_trips.ex_waste - if _update_alarm_state((plc_cache.waste > ALARM_LIMS.HIGH_WASTE) or rps_high_waste, self.alarms.ReactorHighWaste) then + if _update_alarm_state(self, (plc_cache.waste > ALARM_LIMS.HIGH_WASTE) or rps_high_waste, self.alarms.ReactorHighWaste) then log.debug(util.c(">> Trip Detail Report for ", types.ALARM_NAMES[self.alarms.ReactorHighWaste.id]," <<")) log.debug(util.c("| plc_cache.waste[", plc_cache.waste, "] rps_high_waste[", rps_high_waste, "]")) end @@ -490,7 +491,7 @@ function logic.update_alarms() end end - _update_alarm_state(rps_alarm, self.alarms.RPSTransient) + _update_alarm_state(self, rps_alarm, self.alarms.RPSTransient) -- RCS Transient local any_low = annunc.CoolantLevelLow @@ -523,7 +524,7 @@ function logic.update_alarms() end end - if _update_alarm_state(rcs_trans, self.alarms.RCSTransient) then + if _update_alarm_state(self, rcs_trans, self.alarms.RCSTransient) then log.debug(util.c(">> Trip Detail Report for ", types.ALARM_NAMES[self.alarms.RCSTransient.id]," <<")) log.debug(util.c("| any_low[", any_low, "] any_over[", any_over, "] gen_trip[", gen_trip, "]")) log.debug(util.c("| RCPTrip[", annunc.RCPTrip, "] MaxWaterReturnFeed[", annunc.MaxWaterReturnFeed, "]")) @@ -534,15 +535,16 @@ function logic.update_alarms() -- Turbine Trip local any_trip = false for i = 1, #annunc.TurbineTrip do any_trip = any_trip or annunc.TurbineTrip[i] end - _update_alarm_state(any_trip, self.alarms.TurbineTrip) + _update_alarm_state(self, any_trip, self.alarms.TurbineTrip) -- update last trips table for key, val in pairs(plc_cache.rps_status) do self.last_rps_trips[key] = val end end -- update the internal automatic safety control performed while in auto control mode +---@param self _unit_self ---@param public reactor_unit reactor unit public functions -function logic.update_auto_safety(public) +function logic.update_auto_safety(self, public) if self.auto_engaged then local alarmed = false @@ -569,7 +571,8 @@ function logic.update_auto_safety(public) end -- update the two unit status text messages -function logic.update_status_text() +---@param self _unit_self +function logic.update_status_text(self) local annunc = self.db.annunciator -- check if an alarm is active (tripped or ack'd) @@ -731,7 +734,8 @@ function logic.update_status_text() end -- handle unit redstone I/O -function logic.handle_redstone() +---@param self _unit_self +function logic.handle_redstone(self) local annunc = self.db.annunciator local cache = self.plc_cache local rps = cache.rps_status @@ -888,9 +892,4 @@ function logic.handle_redstone() end end --- link the self instance and return the logic interface ----@param unit_self _unit_self -return function (unit_self) - self = unit_self - return logic -end +return logic