restored use of self for unit logic function calls
This commit is contained in:
parent
0df1e48780
commit
9393b1830d
@ -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
|
-- list for RTU session management
|
||||||
self.rtu_list = { self.redstone, self.boilers, self.turbines, self.tanks, self.snas, self.envd }
|
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()
|
_dt__compute_all()
|
||||||
|
|
||||||
-- update annunciator logic
|
-- update annunciator logic
|
||||||
logic.update_annunciator()
|
unit_logic.update_annunciator(self)
|
||||||
|
|
||||||
-- update alarm status
|
-- update alarm status
|
||||||
logic.update_alarms()
|
unit_logic.update_alarms(self)
|
||||||
|
|
||||||
-- if in auto mode, SCRAM on certain alarms
|
-- if in auto mode, SCRAM on certain alarms
|
||||||
logic.update_auto_safety(public)
|
unit_logic.update_auto_safety(self, public)
|
||||||
|
|
||||||
-- update status text
|
-- update status text
|
||||||
logic.update_status_text()
|
unit_logic.update_status_text(self)
|
||||||
|
|
||||||
-- handle redstone I/O
|
-- handle redstone I/O
|
||||||
if #self.redstone > 0 then
|
if #self.redstone > 0 then
|
||||||
logic.handle_redstone()
|
unit_logic.handle_redstone(self)
|
||||||
elseif not self.plc_cache.rps_trip then
|
elseif not self.plc_cache.rps_trip then
|
||||||
self.em_cool_opened = false
|
self.em_cool_opened = false
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,13 +31,12 @@ local ALARM_LIMS = const.ALARM_LIMITS
|
|||||||
local FLOW_STABILITY_DELAY_MS = const.FLOW_STABILITY_DELAY_MS
|
local FLOW_STABILITY_DELAY_MS = const.FLOW_STABILITY_DELAY_MS
|
||||||
local RS_THRESH = const.RS_THRESHOLDS
|
local RS_THRESH = const.RS_THRESHOLDS
|
||||||
|
|
||||||
local self = nil ---@type _unit_self
|
|
||||||
|
|
||||||
---@class unit_logic_extension
|
---@class unit_logic_extension
|
||||||
local logic = {}
|
local logic = {}
|
||||||
|
|
||||||
-- update the annunciator
|
-- update the annunciator
|
||||||
function logic.update_annunciator()
|
---@param self _unit_self
|
||||||
|
function logic.update_annunciator(self)
|
||||||
local DT_KEYS = self.types.DT_KEYS
|
local DT_KEYS = self.types.DT_KEYS
|
||||||
local _get_dt = self._get_dt
|
local _get_dt = self._get_dt
|
||||||
|
|
||||||
@ -421,21 +420,23 @@ function logic.update_annunciator()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- update an alarm state given conditions
|
-- update an alarm state given conditions
|
||||||
|
---@param self _unit_self
|
||||||
---@param tripped boolean if the alarm condition is still active
|
---@param tripped boolean if the alarm condition is still active
|
||||||
---@param alarm alarm_def alarm table
|
---@param alarm alarm_def alarm table
|
||||||
---@return boolean new_trip if the alarm just changed to being tripped
|
---@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)
|
return alarm_ctl.update_alarm_state("UNIT " .. self.r_id, self.db.alarm_states, tripped, alarm)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- evaluate alarm conditions
|
-- evaluate alarm conditions
|
||||||
function logic.update_alarms()
|
---@param self _unit_self
|
||||||
|
function logic.update_alarms(self)
|
||||||
local annunc = self.db.annunciator
|
local annunc = self.db.annunciator
|
||||||
local plc_cache = self.plc_cache
|
local plc_cache = self.plc_cache
|
||||||
|
|
||||||
-- Containment Breach
|
-- Containment Breach
|
||||||
-- lost plc with critical damage (rip plc, you will be missed)
|
-- 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
|
-- Containment Radiation
|
||||||
local rad_alarm = false
|
local rad_alarm = false
|
||||||
@ -444,38 +445,38 @@ function logic.update_alarms()
|
|||||||
rad_alarm = self.last_radiation >= ALARM_LIMS.HIGH_RADIATION
|
rad_alarm = self.last_radiation >= ALARM_LIMS.HIGH_RADIATION
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
_update_alarm_state(rad_alarm, self.alarms.ContainmentRadiation)
|
_update_alarm_state(self, rad_alarm, self.alarms.ContainmentRadiation)
|
||||||
|
|
||||||
-- Reactor Lost
|
-- 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
|
-- 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
|
-- Reactor Damage
|
||||||
local rps_dmg_90 = plc_cache.rps_status.high_dmg and not self.last_rps_trips.high_dmg
|
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(">> 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, "]"))
|
log.debug(util.c("| plc_cache.damage[", plc_cache.damage, "] rps_dmg_90[", rps_dmg_90, "]"))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Over-Temperature
|
-- Over-Temperature
|
||||||
local rps_high_temp = plc_cache.rps_status.high_temp and not self.last_rps_trips.high_temp
|
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(">> 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, "]"))
|
log.debug(util.c("| plc_cache.temp[", plc_cache.temp, "] rps_high_temp[", rps_high_temp, "]"))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- High Temperature
|
-- High Temperature
|
||||||
local high_temp = math.min(math.max(self.plc_cache.high_temp_lim, 1100), 1199.995)
|
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
|
-- 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
|
-- High Waste
|
||||||
local rps_high_waste = plc_cache.rps_status.ex_waste and not self.last_rps_trips.ex_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(">> 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, "]"))
|
log.debug(util.c("| plc_cache.waste[", plc_cache.waste, "] rps_high_waste[", rps_high_waste, "]"))
|
||||||
end
|
end
|
||||||
@ -490,7 +491,7 @@ function logic.update_alarms()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
_update_alarm_state(rps_alarm, self.alarms.RPSTransient)
|
_update_alarm_state(self, rps_alarm, self.alarms.RPSTransient)
|
||||||
|
|
||||||
-- RCS Transient
|
-- RCS Transient
|
||||||
local any_low = annunc.CoolantLevelLow
|
local any_low = annunc.CoolantLevelLow
|
||||||
@ -523,7 +524,7 @@ function logic.update_alarms()
|
|||||||
end
|
end
|
||||||
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(">> 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("| any_low[", any_low, "] any_over[", any_over, "] gen_trip[", gen_trip, "]"))
|
||||||
log.debug(util.c("| RCPTrip[", annunc.RCPTrip, "] MaxWaterReturnFeed[", annunc.MaxWaterReturnFeed, "]"))
|
log.debug(util.c("| RCPTrip[", annunc.RCPTrip, "] MaxWaterReturnFeed[", annunc.MaxWaterReturnFeed, "]"))
|
||||||
@ -534,15 +535,16 @@ function logic.update_alarms()
|
|||||||
-- Turbine Trip
|
-- Turbine Trip
|
||||||
local any_trip = false
|
local any_trip = false
|
||||||
for i = 1, #annunc.TurbineTrip do any_trip = any_trip or annunc.TurbineTrip[i] end
|
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
|
-- update last trips table
|
||||||
for key, val in pairs(plc_cache.rps_status) do self.last_rps_trips[key] = val end
|
for key, val in pairs(plc_cache.rps_status) do self.last_rps_trips[key] = val end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update the internal automatic safety control performed while in auto control mode
|
-- update the internal automatic safety control performed while in auto control mode
|
||||||
|
---@param self _unit_self
|
||||||
---@param public reactor_unit reactor unit public functions
|
---@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
|
if self.auto_engaged then
|
||||||
local alarmed = false
|
local alarmed = false
|
||||||
|
|
||||||
@ -569,7 +571,8 @@ function logic.update_auto_safety(public)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- update the two unit status text messages
|
-- 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
|
local annunc = self.db.annunciator
|
||||||
|
|
||||||
-- check if an alarm is active (tripped or ack'd)
|
-- check if an alarm is active (tripped or ack'd)
|
||||||
@ -731,7 +734,8 @@ function logic.update_status_text()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- handle unit redstone I/O
|
-- handle unit redstone I/O
|
||||||
function logic.handle_redstone()
|
---@param self _unit_self
|
||||||
|
function logic.handle_redstone(self)
|
||||||
local annunc = self.db.annunciator
|
local annunc = self.db.annunciator
|
||||||
local cache = self.plc_cache
|
local cache = self.plc_cache
|
||||||
local rps = cache.rps_status
|
local rps = cache.rps_status
|
||||||
@ -888,9 +892,4 @@ function logic.handle_redstone()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- link the self instance and return the logic interface
|
return logic
|
||||||
---@param unit_self _unit_self
|
|
||||||
return function (unit_self)
|
|
||||||
self = unit_self
|
|
||||||
return logic
|
|
||||||
end
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user