#181 independent emergency coolant valve control
This commit is contained in:
@@ -2,6 +2,7 @@ local comms = require("scada-common.comms")
|
||||
local const = require("scada-common.constants")
|
||||
local log = require("scada-common.log")
|
||||
local ppm = require("scada-common.ppm")
|
||||
local rsio = require("scada-common.rsio")
|
||||
local types = require("scada-common.types")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
@@ -34,7 +35,8 @@ local PCALL_START_MSG = "pcall: Reactor is already active."
|
||||
---@nodiscard
|
||||
---@param reactor table
|
||||
---@param is_formed boolean
|
||||
function plc.rps_init(reactor, is_formed)
|
||||
---@param emer_cool nil|table emergency coolant configuration
|
||||
function plc.rps_init(reactor, is_formed, emer_cool)
|
||||
local state_keys = {
|
||||
high_dmg = 1,
|
||||
high_temp = 2,
|
||||
@@ -54,6 +56,7 @@ function plc.rps_init(reactor, is_formed)
|
||||
state = { false, false, false, false, false, false, false, false, false, false, false, false },
|
||||
reactor_enabled = false,
|
||||
enabled_at = 0,
|
||||
emer_cool_active = nil, ---@type boolean
|
||||
formed = is_formed,
|
||||
force_disabled = false,
|
||||
tripped = false,
|
||||
@@ -74,6 +77,41 @@ function plc.rps_init(reactor, is_formed)
|
||||
self.state[state_keys.fault] = false
|
||||
end
|
||||
|
||||
-- set emergency coolant control (if configured)
|
||||
---@param state boolean true to enable emergency coolant, false to disable
|
||||
local function _set_emer_cool(state)
|
||||
-- check if this was configured: if it's a table, fields have already been validated.
|
||||
if type(emer_cool) == "table" then
|
||||
local level = rsio.digital_write_active(rsio.IO.U_EMER_COOL, state)
|
||||
|
||||
if level ~= false then
|
||||
if rsio.is_color(emer_cool.color) then
|
||||
local output = rs.getBundledOutput(emer_cool.side)
|
||||
|
||||
if rsio.digital_write(level) then
|
||||
output = colors.combine(output, emer_cool.color)
|
||||
else
|
||||
output = colors.subtract(output, emer_cool.color)
|
||||
end
|
||||
|
||||
rs.setBundledOutput(emer_cool.side, output)
|
||||
else
|
||||
rs.setOutput(emer_cool.side, rsio.digital_write(level))
|
||||
end
|
||||
|
||||
if state ~= self.emer_cool_active then
|
||||
if state then
|
||||
log.info("RPS: emergency coolant valve OPENED")
|
||||
else
|
||||
log.info("RPS: emergency coolant valve CLOSED")
|
||||
end
|
||||
|
||||
self.emer_cool_active = state
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- check if the reactor is formed
|
||||
local function _is_formed()
|
||||
local formed = reactor.isFormed()
|
||||
@@ -348,6 +386,9 @@ function plc.rps_init(reactor, is_formed)
|
||||
end
|
||||
end
|
||||
|
||||
-- update emergency coolant control if configured
|
||||
_set_emer_cool(self.state[state_keys.low_coolant])
|
||||
|
||||
return self.tripped, status, first_trip
|
||||
end
|
||||
|
||||
@@ -358,6 +399,8 @@ function plc.rps_init(reactor, is_formed)
|
||||
function public.is_tripped() return self.tripped end
|
||||
---@nodiscard
|
||||
function public.get_trip_cause() return self.trip_cause end
|
||||
---@nodiscard
|
||||
function public.is_low_coolant() return self.states[state_keys.low_coolant] end
|
||||
|
||||
---@nodiscard
|
||||
function public.is_active() return self.reactor_enabled end
|
||||
|
||||
Reference in New Issue
Block a user