#290 pocket page management and alarm test tool, supervisor pocket diagnostics system
This commit is contained in:
@@ -9,16 +9,16 @@ local unit = require("supervisor.unit")
|
||||
|
||||
local rsctl = require("supervisor.session.rsctl")
|
||||
|
||||
local TONES = audio.TONES
|
||||
local TONES = audio.TONES
|
||||
|
||||
local ALARM = types.ALARM
|
||||
local PRIO = types.ALARM_PRIORITY
|
||||
local ALARM_STATE = types.ALARM_STATE
|
||||
local PROCESS = types.PROCESS
|
||||
local PROCESS_NAMES = types.PROCESS_NAMES
|
||||
local PRIO = types.ALARM_PRIORITY
|
||||
local ALARM = types.ALARM
|
||||
local ALARM_STATE = types.ALARM_STATE
|
||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
||||
local WASTE = types.WASTE_PRODUCT
|
||||
local WASTE_MODE = types.WASTE_MODE
|
||||
local WASTE = types.WASTE_PRODUCT
|
||||
|
||||
local IO = rsio.IO
|
||||
|
||||
@@ -65,6 +65,7 @@ function facility.new(num_reactors, cooling_conf)
|
||||
units = {},
|
||||
status_text = { "START UP", "initializing..." },
|
||||
all_sys_ok = false,
|
||||
allow_testing = false,
|
||||
-- rtus
|
||||
rtu_conn_count = 0,
|
||||
rtu_list = {},
|
||||
@@ -115,7 +116,11 @@ function facility.new(num_reactors, cooling_conf)
|
||||
current_waste_product = WASTE.PLUTONIUM,
|
||||
pu_fallback = false,
|
||||
-- alarm tones
|
||||
tone_states = { false, false, false, false, false, false, false, false },
|
||||
tone_states = {},
|
||||
test_tone_set = false,
|
||||
test_tone_reset = false,
|
||||
test_tone_states = {},
|
||||
test_alarm_states = {},
|
||||
-- statistics
|
||||
im_stat_init = false,
|
||||
avg_charge = util.mov_avg(3, 0.0),
|
||||
@@ -135,6 +140,13 @@ function facility.new(num_reactors, cooling_conf)
|
||||
-- init redstone RTU I/O controller
|
||||
self.io_ctl = rsctl.new(self.redstone)
|
||||
|
||||
-- fill blank alarm/tone states
|
||||
for _ = 1, 12 do table.insert(self.test_alarm_states, false) end
|
||||
for _ = 1, 8 do
|
||||
table.insert(self.tone_states, false)
|
||||
table.insert(self.test_tone_states, false)
|
||||
end
|
||||
|
||||
-- check if all auto-controlled units completed ramping
|
||||
---@nodiscard
|
||||
local function _all_units_ramped()
|
||||
@@ -269,15 +281,20 @@ function facility.new(num_reactors, cooling_conf)
|
||||
|
||||
-- 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
|
||||
function public.report_rtus(rtu_sessions) self.rtu_conn_count = #rtu_sessions end
|
||||
|
||||
-- update (iterate) the facility management
|
||||
function public.update()
|
||||
-- unlink RTU unit sessions if they are closed
|
||||
for _, v in pairs(self.rtu_list) do util.filter_table(v, function (u) return u.is_connected() end) end
|
||||
|
||||
-- check if test routines are allowed right now
|
||||
self.allow_testing = true
|
||||
for i = 1, #self.units do
|
||||
local u = self.units[i] ---@type reactor_unit
|
||||
self.allow_testing = self.allow_testing and u.is_safe_idle()
|
||||
end
|
||||
|
||||
-- current state for process control
|
||||
local charge_update = 0
|
||||
local rate_update = 0
|
||||
@@ -762,17 +779,43 @@ function facility.new(num_reactors, cooling_conf)
|
||||
-- Update Alarm Tones --
|
||||
------------------------
|
||||
|
||||
local alarms = { false, false, false, false, false, false, false, false, false, false, false, false }
|
||||
self.tone_states = { false, false, false, false, false, false, false, false}
|
||||
local allow_test = self.allow_testing and self.test_tone_set
|
||||
|
||||
-- check all alarms for all units
|
||||
for i = 1, #self.units do
|
||||
local u = self.units[i] ---@type reactor_unit
|
||||
for id, alarm in pairs(u.get_alarms()) do
|
||||
alarms[id] = alarms[id] or (alarm == ALARM_STATE.TRIPPED)
|
||||
end
|
||||
local alarms = { false, false, false, false, false, false, false, false, false, false, false, false }
|
||||
|
||||
for i = 1, #self.tone_states do
|
||||
-- reset tone states before re-evaluting
|
||||
self.tone_states[i] = false
|
||||
|
||||
-- clear testing tones if we aren't using them
|
||||
if (not allow_test) and (not self.test_tone_reset) then self.test_tone_states[i] = false end
|
||||
end
|
||||
|
||||
if allow_test then
|
||||
alarms = self.test_alarm_states
|
||||
else
|
||||
-- check all alarms for all units
|
||||
for i = 1, #self.units do
|
||||
local u = self.units[i] ---@type reactor_unit
|
||||
for id, alarm in pairs(u.get_alarms()) do
|
||||
alarms[id] = alarms[id] or (alarm == ALARM_STATE.TRIPPED)
|
||||
|
||||
-- clear testing alarms if we aren't using them
|
||||
if not self.test_tone_reset then self.test_alarm_states[id] = false end
|
||||
end
|
||||
end
|
||||
|
||||
self.test_tone_reset = true
|
||||
end
|
||||
|
||||
-- flag that tones were reset to notify diagnostic accessor
|
||||
if not allow_test then
|
||||
self.test_tone_set = false
|
||||
self.test_tone_reset = true
|
||||
end
|
||||
|
||||
-- Evaluate Alarms --
|
||||
|
||||
-- containment breach is worst case CRITICAL alarm, this takes priority
|
||||
if alarms[ALARM.ContainmentBreach] then
|
||||
self.tone_states[TONES.T_1800Hz_Int_4Hz] = true
|
||||
@@ -815,6 +858,13 @@ function facility.new(num_reactors, cooling_conf)
|
||||
self.tone_states[TONES.T_800Hz_Int] = false
|
||||
self.tone_states[TONES.T_1000Hz_Int] = false
|
||||
end
|
||||
|
||||
-- add to tone states if testing is active
|
||||
if allow_test then
|
||||
for i = 1, #self.tone_states do
|
||||
self.tone_states[i] = self.tone_states[i] or self.test_tone_states[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- call the update function of all units in the facility<br>
|
||||
@@ -956,6 +1006,46 @@ function facility.new(num_reactors, cooling_conf)
|
||||
return self.pu_fallback
|
||||
end
|
||||
|
||||
-- DIAGNOSTIC TESTING --
|
||||
|
||||
-- attempt to set a test tone state
|
||||
---@param id tone_id|0 tone ID or 0 to disable all
|
||||
---@param state boolean state
|
||||
---@return boolean allow_testing, table test_tone_states
|
||||
function public.diag_set_test_tone(id, state)
|
||||
if self.allow_testing then
|
||||
self.test_tone_set = true
|
||||
self.test_tone_reset = false
|
||||
|
||||
if id == 0 then
|
||||
for i = 1, #self.test_tone_states do self.test_tone_states[i] = false end
|
||||
else
|
||||
self.test_tone_states[id] = state
|
||||
end
|
||||
end
|
||||
|
||||
return self.allow_testing, self.test_tone_states
|
||||
end
|
||||
|
||||
-- attempt to set a test alarm state
|
||||
---@param id ALARM|0 alarm ID or 0 to disable all
|
||||
---@param state boolean state
|
||||
---@return boolean allow_testing, table test_alarm_states
|
||||
function public.diag_set_test_alarm(id, state)
|
||||
if self.allow_testing then
|
||||
self.test_tone_set = true
|
||||
self.test_tone_reset = false
|
||||
|
||||
if id == 0 then
|
||||
for i = 1, #self.test_alarm_states do self.test_alarm_states[i] = false end
|
||||
else
|
||||
self.test_alarm_states[id] = state
|
||||
end
|
||||
end
|
||||
|
||||
return self.allow_testing, self.test_alarm_states
|
||||
end
|
||||
|
||||
-- READ STATES/PROPERTIES --
|
||||
|
||||
-- get current alarm tone on/off states
|
||||
|
||||
Reference in New Issue
Block a user