reorganized unit logic inclusion to work like facility update
This commit is contained in:
@@ -4,7 +4,7 @@ local types = require("scada-common.types")
|
|||||||
local util = require("scada-common.util")
|
local util = require("scada-common.util")
|
||||||
|
|
||||||
local alarm_ctl = require("supervisor.alarm_ctl")
|
local alarm_ctl = require("supervisor.alarm_ctl")
|
||||||
local logic = require("supervisor.unitlogic")
|
local unit_logic = require("supervisor.unit_logic")
|
||||||
|
|
||||||
local plc = require("supervisor.session.plc")
|
local plc = require("supervisor.session.plc")
|
||||||
local rsctl = require("supervisor.session.rsctl")
|
local rsctl = require("supervisor.session.rsctl")
|
||||||
@@ -240,6 +240,9 @@ 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 }
|
||||||
|
|
||||||
@@ -583,20 +586,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(self)
|
logic.update_annunciator()
|
||||||
|
|
||||||
-- update alarm status
|
-- update alarm status
|
||||||
logic.update_alarms(self)
|
logic.update_alarms()
|
||||||
|
|
||||||
-- if in auto mode, SCRAM on certain alarms
|
-- if in auto mode, SCRAM on certain alarms
|
||||||
logic.update_auto_safety(public, self)
|
logic.update_auto_safety(public)
|
||||||
|
|
||||||
-- update status text
|
-- update status text
|
||||||
logic.update_status_text(self)
|
logic.update_status_text()
|
||||||
|
|
||||||
-- handle redstone I/O
|
-- handle redstone I/O
|
||||||
if #self.redstone > 0 then
|
if #self.redstone > 0 then
|
||||||
logic.handle_redstone(self)
|
logic.handle_redstone()
|
||||||
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
|
||||||
|
|||||||
@@ -26,18 +26,18 @@ local IO = rsio.IO
|
|||||||
|
|
||||||
local PLC_S_CMDS = plc.PLC_S_CMDS
|
local PLC_S_CMDS = plc.PLC_S_CMDS
|
||||||
|
|
||||||
local FLOW_STABILITY_DELAY_MS = const.FLOW_STABILITY_DELAY_MS
|
|
||||||
|
|
||||||
local ANNUNC_LIMS = const.ANNUNCIATOR_LIMITS
|
local ANNUNC_LIMS = const.ANNUNCIATOR_LIMITS
|
||||||
local ALARM_LIMS = const.ALARM_LIMITS
|
local ALARM_LIMS = const.ALARM_LIMITS
|
||||||
|
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
|
||||||
---@param self _unit_self
|
function logic.update_annunciator()
|
||||||
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,23 +421,21 @@ function logic.update_annunciator(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- update an alarm state given conditions
|
-- update an alarm state given conditions
|
||||||
---@param self _unit_self unit instance
|
|
||||||
---@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(self, tripped, alarm)
|
local function _update_alarm_state(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
|
||||||
---@param self _unit_self unit instance
|
function logic.update_alarms()
|
||||||
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(self, (not plc_cache.ok) and (plc_cache.damage > 99), self.alarms.ContainmentBreach)
|
_update_alarm_state((not plc_cache.ok) and (plc_cache.damage > 99), self.alarms.ContainmentBreach)
|
||||||
|
|
||||||
-- Containment Radiation
|
-- Containment Radiation
|
||||||
local rad_alarm = false
|
local rad_alarm = false
|
||||||
@@ -446,38 +444,38 @@ function logic.update_alarms(self)
|
|||||||
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(self, rad_alarm, self.alarms.ContainmentRadiation)
|
_update_alarm_state(rad_alarm, self.alarms.ContainmentRadiation)
|
||||||
|
|
||||||
-- Reactor Lost
|
-- Reactor Lost
|
||||||
_update_alarm_state(self, self.had_reactor and self.plc_i == nil, self.alarms.ReactorLost)
|
_update_alarm_state(self.had_reactor and self.plc_i == nil, self.alarms.ReactorLost)
|
||||||
|
|
||||||
-- Critical Damage
|
-- Critical Damage
|
||||||
_update_alarm_state(self, plc_cache.damage >= 100, self.alarms.CriticalDamage)
|
_update_alarm_state(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(self, (plc_cache.damage > 0) or rps_dmg_90, self.alarms.ReactorDamage) then
|
if _update_alarm_state((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(self, (plc_cache.temp >= 1200) or rps_high_temp, self.alarms.ReactorOverTemp) then
|
if _update_alarm_state((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(self, plc_cache.temp >= high_temp, self.alarms.ReactorHighTemp)
|
_update_alarm_state(plc_cache.temp >= high_temp, self.alarms.ReactorHighTemp)
|
||||||
|
|
||||||
-- Waste Leak
|
-- Waste Leak
|
||||||
_update_alarm_state(self, plc_cache.waste >= 1.0, self.alarms.ReactorWasteLeak)
|
_update_alarm_state(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(self, (plc_cache.waste > ALARM_LIMS.HIGH_WASTE) or rps_high_waste, self.alarms.ReactorHighWaste) then
|
if _update_alarm_state((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
|
||||||
@@ -492,7 +490,7 @@ function logic.update_alarms(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
_update_alarm_state(self, rps_alarm, self.alarms.RPSTransient)
|
_update_alarm_state(rps_alarm, self.alarms.RPSTransient)
|
||||||
|
|
||||||
-- RCS Transient
|
-- RCS Transient
|
||||||
local any_low = annunc.CoolantLevelLow
|
local any_low = annunc.CoolantLevelLow
|
||||||
@@ -525,7 +523,7 @@ function logic.update_alarms(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if _update_alarm_state(self, rcs_trans, self.alarms.RCSTransient) then
|
if _update_alarm_state(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, "]"))
|
||||||
@@ -536,7 +534,7 @@ function logic.update_alarms(self)
|
|||||||
-- 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(self, any_trip, self.alarms.TurbineTrip)
|
_update_alarm_state(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
|
||||||
@@ -544,8 +542,7 @@ 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 public reactor_unit reactor unit public functions
|
---@param public reactor_unit reactor unit public functions
|
||||||
---@param self _unit_self unit instance
|
function logic.update_auto_safety(public)
|
||||||
function logic.update_auto_safety(public, self)
|
|
||||||
if self.auto_engaged then
|
if self.auto_engaged then
|
||||||
local alarmed = false
|
local alarmed = false
|
||||||
|
|
||||||
@@ -572,8 +569,7 @@ function logic.update_auto_safety(public, self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- update the two unit status text messages
|
-- update the two unit status text messages
|
||||||
---@param self _unit_self unit instance
|
function logic.update_status_text()
|
||||||
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)
|
||||||
@@ -735,8 +731,7 @@ function logic.update_status_text(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- handle unit redstone I/O
|
-- handle unit redstone I/O
|
||||||
---@param self _unit_self unit instance
|
function logic.handle_redstone()
|
||||||
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
|
||||||
@@ -893,4 +888,9 @@ function logic.handle_redstone(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return logic
|
-- link the self instance and return the logic interface
|
||||||
|
---@param unit_self _unit_self
|
||||||
|
return function (unit_self)
|
||||||
|
self = unit_self
|
||||||
|
return logic
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user