#362 taking max of connected radiation monitors

This commit is contained in:
Mikayla Fischler
2023-11-12 11:54:47 -05:00
parent 1ba178eae8
commit f2f5c3201f
14 changed files with 116 additions and 68 deletions

View File

@@ -232,9 +232,7 @@ function facility.new(num_reactors, cooling_conf)
-- link a redstone RTU session
---@param rs_unit unit_session
function public.add_redstone(rs_unit)
table.insert(self.redstone, rs_unit)
end
function public.add_redstone(rs_unit) table.insert(self.redstone, rs_unit) end
-- link an induction matrix RTU session
---@param imatrix unit_session
@@ -258,23 +256,11 @@ function facility.new(num_reactors, cooling_conf)
-- link a dynamic tank RTU session
---@param dynamic_tank unit_session
---@return boolean linked dynamic tank accepted (max 1)
function public.add_tank(dynamic_tank)
if #self.tanks == 0 then
table.insert(self.tanks, dynamic_tank)
return true
else return false end
end
function public.add_tank(dynamic_tank) table.insert(self.tanks, dynamic_tank) end
-- link an environment detector RTU session
---@param envd unit_session
---@return boolean linked environment detector accepted (max 1)
function public.add_envd(envd)
if #self.envd == 0 then
table.insert(self.envd, envd)
return true
else return false end
end
function public.add_envd(envd) table.insert(self.envd, envd) end
-- purge devices associated with the given RTU session ID
---@param session integer RTU session ID
@@ -643,11 +629,16 @@ function facility.new(num_reactors, cooling_conf)
end
-- check for facility radiation
if self.envd[1] ~= nil then
local envd = self.envd[1] ---@type unit_session
local e_db = envd.get_db() ---@type envd_session_db
if #self.envd > 0 then
local max_rad = 0
astatus.radiation = e_db.radiation_raw > ALARM_LIMS.FAC_HIGH_RAD
for i = 1, #self.envd do
local envd = self.envd[i] ---@type unit_session
local e_db = envd.get_db() ---@type envd_session_db
if e_db.radiation_raw > max_rad then max_rad = e_db.radiation_raw end
end
astatus.radiation = max_rad > ALARM_LIMS.FAC_HIGH_RAD
else
-- don't clear, if it is true then we lost it with high radiation, so just keep alarming
-- operator can restart the system or hit the stop/reset button
@@ -1183,7 +1174,8 @@ function facility.new(num_reactors, cooling_conf)
status.rad_mon = {}
for i = 1, #self.envd do
local envd = self.envd[i] ---@type unit_session
status.rad_mon[i] = { envd.is_faulted(), envd.get_db().radiation }
local db = envd.get_db() ---@type envd_session_db
status.rad_mon[envd.get_device_idx()] = { envd.is_faulted(), db.radiation, db.radiation_raw }
end
return status

View File

@@ -37,9 +37,12 @@ local PERIODICS = {
---@param advert rtu_advertisement RTU advertisement table
---@param out_queue mqueue RTU unit message out queue
function boilerv.new(session_id, unit_id, advert, out_queue)
-- type check
-- checks
if advert.type ~= RTU_UNIT_TYPE.BOILER_VALVE then
log.error("attempt to instantiate boilerv RTU for type '" .. types.rtu_type_to_string(advert.type) .. "'. this is a bug.")
log.error("attempt to instantiate boilerv RTU for type " .. types.rtu_type_to_string(advert.type))
return nil
elseif not util.is_int(advert.index) then
log.error("attempt to instantiate boilerv RTU without index")
return nil
end

View File

@@ -49,9 +49,12 @@ local PERIODICS = {
---@param advert rtu_advertisement RTU advertisement table
---@param out_queue mqueue RTU unit message out queue
function dynamicv.new(session_id, unit_id, advert, out_queue)
-- type check
-- checks
if advert.type ~= RTU_UNIT_TYPE.DYNAMIC_VALVE then
log.error("attempt to instantiate dynamicv RTU for type '" .. types.rtu_type_to_string(advert.type) .. "'. this is a bug.")
log.error("attempt to instantiate dynamicv RTU for type " .. types.rtu_type_to_string(advert.type))
return nil
elseif not util.is_int(advert.index) then
log.error("attempt to instantiate dynamicv RTU without index")
return nil
end

View File

@@ -28,13 +28,16 @@ local PERIODICS = {
---@param advert rtu_advertisement
---@param out_queue mqueue
function envd.new(session_id, unit_id, advert, out_queue)
-- type check
-- checks
if advert.type ~= RTU_UNIT_TYPE.ENV_DETECTOR then
log.error("attempt to instantiate envd RTU for type '" .. types.rtu_type_to_string(advert.type) .. "'. this is a bug.")
log.error("attempt to instantiate envd RTU for type " .. types.rtu_type_to_string(advert.type))
return nil
elseif not util.is_int(advert.index) then
log.error("attempt to instantiate envd RTU without index")
return nil
end
local log_tag = util.c("session.rtu(", session_id, ").envd[@", unit_id, "]: ")
local log_tag = util.c("session.rtu(", session_id, ").envd(", advert.index, ")[@", unit_id, "]: ")
local self = {
session = unit_session.new(session_id, unit_id, advert, out_queue, log_tag, TXN_TAGS),

View File

@@ -37,9 +37,12 @@ local PERIODICS = {
---@param advert rtu_advertisement RTU advertisement table
---@param out_queue mqueue RTU unit message out queue
function imatrix.new(session_id, unit_id, advert, out_queue)
-- type check
-- checks
if advert.type ~= RTU_UNIT_TYPE.IMATRIX then
log.error("attempt to instantiate imatrix RTU for type '" .. types.rtu_type_to_string(advert.type) .. "'. this is a bug.")
log.error("attempt to instantiate imatrix RTU for type " .. types.rtu_type_to_string(advert.type))
return nil
elseif not util.is_int(advert.index) then
log.error("attempt to instantiate dynamicv RTU without index")
return nil
end

View File

@@ -52,7 +52,7 @@ local PERIODICS = {
function redstone.new(session_id, unit_id, advert, out_queue)
-- type check
if advert.type ~= RTU_UNIT_TYPE.REDSTONE then
log.error("attempt to instantiate redstone RTU for type '" .. types.rtu_type_to_string(advert.type) .. "'. this is a bug.")
log.error("attempt to instantiate redstone RTU for type " .. types.rtu_type_to_string(advert.type))
return nil
end

View File

@@ -36,7 +36,7 @@ local PERIODICS = {
function sna.new(session_id, unit_id, advert, out_queue)
-- type check
if advert.type ~= RTU_UNIT_TYPE.SNA then
log.error("attempt to instantiate sna RTU for type '" .. types.rtu_type_to_string(advert.type) .. "'. this is a bug.")
log.error("attempt to instantiate sna RTU for type " .. types.rtu_type_to_string(advert.type))
return nil
end

View File

@@ -39,7 +39,7 @@ local PERIODICS = {
function sps.new(session_id, unit_id, advert, out_queue)
-- type check
if advert.type ~= RTU_UNIT_TYPE.SPS then
log.error("attempt to instantiate sps RTU for type '" .. types.rtu_type_to_string(advert.type) .. "'. this is a bug.")
log.error("attempt to instantiate sps RTU for type " .. types.rtu_type_to_string(advert.type))
return nil
end

View File

@@ -49,9 +49,12 @@ local PERIODICS = {
---@param advert rtu_advertisement RTU advertisement table
---@param out_queue mqueue RTU unit message out queue
function turbinev.new(session_id, unit_id, advert, out_queue)
-- type check
-- checks
if advert.type ~= RTU_UNIT_TYPE.TURBINE_VALVE then
log.error("attempt to instantiate turbinev RTU for type '" .. types.rtu_type_to_string(advert.type) .. "'. this is a bug.")
log.error("attempt to instantiate turbinev RTU for type " .. types.rtu_type_to_string(advert.type))
return nil
elseif not util.is_int(advert.index) then
log.error("attempt to instantiate turbinev RTU without index")
return nil
end

View File

@@ -867,7 +867,8 @@ function unit.new(reactor_id, num_boilers, num_turbines)
status.rad_mon = {}
for i = 1, #self.envd do
local envd = self.envd[i] ---@type unit_session
status.rad_mon[i] = { envd.is_faulted(), envd.get_db().radiation }
local db = envd.get_db() ---@type envd_session_db
status.rad_mon[envd.get_device_idx()] = { envd.is_faulted(), db.radiation, db.radiation_raw }
end
return status