This commit is contained in:
Mikayla Fischler 2023-11-12 16:55:24 -05:00
parent 6e92097544
commit d7b1f9cc7e
5 changed files with 72 additions and 68 deletions

View File

@ -760,23 +760,24 @@ function iocontrol.update_facility_status(status)
end
-- environment detector status
if type(rtu_statuses.rad_mon) == "table" then
if #rtu_statuses.rad_mon > 0 then
local max_rad, max_reading, any_faulted = 0, types.new_zero_radiation_reading(), false
if type(rtu_statuses.envds) == "table" then
local max_rad, max_reading, any_conn, any_faulted = 0, types.new_zero_radiation_reading(), false, false
for i = 1, #rtu_statuses.rad_mon do
local rad_mon = rtu_statuses.rad_mon[i]
local rtu_faulted = rad_mon[1] ---@type boolean
local radiation = rad_mon[2] ---@type radiation_reading
local rad_raw = rad_mon[3] ---@type number
for _, envd in pairs(rtu_statuses.envds) do
local rtu_faulted = envd[1] ---@type boolean
local radiation = envd[2] ---@type radiation_reading
local rad_raw = envd[3] ---@type number
any_faulted = any_faulted or rtu_faulted
if rad_raw > max_rad then
max_rad = rad_raw
max_reading = radiation
end
any_conn = true
any_faulted = any_faulted or rtu_faulted
if rad_raw > max_rad then
max_rad = rad_raw
max_reading = radiation
end
end
if any_conn then
fac.radiation = max_reading
fac.ps.publish("rad_computed_status", util.trinary(any_faulted, 2, 3))
else
@ -786,7 +787,7 @@ function iocontrol.update_facility_status(status)
fac.ps.publish("radiation", fac.radiation)
else
log.debug(log_header .. "radiation monitor list not a table")
log.debug(log_header .. "environment detector list not a table")
valid = false
end
else
@ -1061,22 +1062,22 @@ function iocontrol.update_unit_statuses(statuses)
end
-- environment detector status
if type(rtu_statuses.rad_mon) == "table" then
local max_rad, max_reading = 0, types.new_zero_radiation_reading()
if type(rtu_statuses.envds) == "table" then
local max_rad, max_reading, any_conn = 0, types.new_zero_radiation_reading(), false
if #rtu_statuses.rad_mon > 0 then
for _, envd in pairs(rtu_statuses.envds) do
local radiation = envd[2] ---@type radiation_reading
local rad_raw = envd[3] ---@type number
for id = 1, #rtu_statuses.rad_mon do
local rad_mon = rtu_statuses.rad_mon[id]
local radiation = rad_mon[2] ---@type radiation_reading
local rad_raw = rad_mon[3] ---@type number
any_conn = true
if rad_raw > max_rad then
max_rad = rad_raw
max_reading = radiation
end
if rad_raw > max_rad then
max_rad = rad_raw
max_reading = radiation
end
end
if any_conn then
unit.radiation = max_reading
else
unit.radiation = types.new_zero_radiation_reading()

View File

@ -710,6 +710,10 @@ local function config_view(display)
tool_ctl.p_desc_ext.set_value("Before adding lots of SNAs: multiply the \"PEAK\" rate on the flow monitor (after connecting at least 1 SNA) by 10 to get the mB/t of waste that they can process. Enough SNAs to provide 2x to 3x of your max burn rate should be a good margin to catch up after night or cloudy weather. Too many devices (such as SNAs) on one RTU can cause lag.")
elseif type == "dynamicValve" then
tool_ctl.p_prompt.set_value("This is the # dynamic tank for...")
tool_ctl.p_assign_btn.show()
tool_ctl.p_assign_btn.redraw()
tool_ctl.p_assign_end.show()
tool_ctl.p_assign_end.redraw()
tool_ctl.p_idx.show()
tool_ctl.p_idx.redraw()
tool_ctl.p_idx.set_max(4)
@ -724,23 +728,19 @@ local function config_view(display)
tool_ctl.p_unit.enable()
end
tool_ctl.p_assign_btn.show()
tool_ctl.p_assign_btn.redraw()
tool_ctl.p_assign_end.show()
tool_ctl.p_assign_end.redraw()
tool_ctl.p_desc.reposition(1, 8)
tool_ctl.p_desc.set_value("Each reactor unit can have at most 1 tank and the facility can have at most 4. Each facility tank must have a unique # 1 through 4, regardless of where it is connected. Only a total of 4 tanks can be displayed on the flow monitor.")
elseif type == "environmentDetector" then
tool_ctl.p_prompt.set_value("This is the # environment detector for...")
tool_ctl.p_assign_btn.show()
tool_ctl.p_assign_btn.redraw()
tool_ctl.p_assign_end.show()
tool_ctl.p_assign_end.redraw()
tool_ctl.p_idx.show()
tool_ctl.p_idx.redraw()
tool_ctl.p_idx.set_max(99)
tool_ctl.p_unit.reposition(18, 6)
if tool_ctl.p_assign_btn.get_value() == 1 then tool_ctl.p_unit.disable() else tool_ctl.p_unit.enable() end
tool_ctl.p_assign_btn.show()
tool_ctl.p_assign_btn.redraw()
tool_ctl.p_assign_end.show()
tool_ctl.p_assign_end.redraw()
tool_ctl.p_desc.reposition(1, 8)
tool_ctl.p_desc.set_value("You can connect more than one environment detector for a particular unit or the facility. In that case, the maximum radiation reading from those assigned to that particular unit or the facility will be used for alarms and display.")
elseif type == "inductionPort" or type == "spsPort" then
@ -882,6 +882,8 @@ local function config_view(display)
tool_ctl.p_err.show()
return
else index = idx end
elseif peri_type == "dynamicValve" then
index = 1
elseif peri_type == "environmentDetector" then
if not (util.is_int(idx) and idx > 0) then
tool_ctl.p_err.set_value("Index must be greater than 0.")

View File

@ -157,18 +157,18 @@ local function main()
---@cast for_reactor integer
assignment = "reactor unit " .. entry.unit
if rs_rtus[for_reactor] == nil then
log.debug(util.c("configure> allocated redstone RTU for reactor unit ", entry.unit))
log.debug(util.c("sys_config> allocated redstone RTU for reactor unit ", entry.unit))
rs_rtus[for_reactor] = { rtu = redstone_rtu.new(), capabilities = {} }
end
elseif entry.unit == nil then
assignment = "facility"
for_reactor = 0
if rs_rtus[for_reactor] == nil then
log.debug(util.c("configure> allocated redstone RTU for the facility"))
log.debug(util.c("sys_config> allocated redstone RTU for the facility"))
rs_rtus[for_reactor] = { rtu = redstone_rtu.new(), capabilities = {} }
end
else
local message = util.c("configure> invalid unit assignment at block index #", entry_idx)
local message = util.c("sys_config> invalid unit assignment at block index #", entry_idx)
println(message)
log.fatal(message)
return false
@ -184,7 +184,7 @@ local function main()
local capabilities = rs_rtus[for_reactor].capabilities
if not valid then
local message = util.c("configure> invalid redstone definition at block index #", entry_idx)
local message = util.c("sys_config> invalid redstone definition at block index #", entry_idx)
println(message)
log.fatal(message)
return false
@ -194,7 +194,7 @@ local function main()
if mode == rsio.IO_MODE.DIGITAL_IN then
-- can't have duplicate inputs
if util.table_contains(capabilities, entry.port) then
local message = util.c("configure> skipping duplicate input for port ", rsio.to_string(entry.port), " on side ", iface_name)
local message = util.c("sys_config> skipping duplicate input for port ", rsio.to_string(entry.port), " on side ", iface_name)
println(message)
log.warning(message)
else
@ -205,7 +205,7 @@ local function main()
elseif mode == rsio.IO_MODE.ANALOG_IN then
-- can't have duplicate inputs
if util.table_contains(capabilities, entry.port) then
local message = util.c("configure> skipping duplicate input for port ", rsio.to_string(entry.port), " on side ", iface_name)
local message = util.c("sys_config> skipping duplicate input for port ", rsio.to_string(entry.port), " on side ", iface_name)
println(message)
log.warning(message)
else
@ -215,14 +215,14 @@ local function main()
rs_rtu.link_ao(entry.side)
else
-- should be unreachable code, we already validated ports
log.error("configure> fell through if chain attempting to identify IO mode at block index #" .. entry_idx, true)
println("configure> encountered a software error, check logs")
log.error("sys_config> fell through if chain attempting to identify IO mode at block index #" .. entry_idx, true)
println("sys_config> encountered a software error, check logs")
return false
end
table.insert(capabilities, entry.port)
log.debug(util.c("configure> linked redstone ", #capabilities, ": ", rsio.to_string(entry.port), " (", iface_name, ") for ", assignment))
log.debug(util.c("sys_config> linked redstone ", #capabilities, ": ", rsio.to_string(entry.port), " (", iface_name, ") for ", assignment))
end
end
@ -252,7 +252,7 @@ local function main()
for_message = util.c("reactor unit ", for_reactor)
end
log.info(util.c("configure> initialized RTU unit #", #units, ": redstone_io (redstone) [1] for ", for_message))
log.info(util.c("sys_config> initialized RTU unit #", #units, ": redstone_io (redstone) [1] for ", for_message))
unit.uid = #units
@ -268,7 +268,7 @@ local function main()
-- CHECK: name is a string
if type(name) ~= "string" then
local message = util.c("configure> device entry #", i, ": device ", name, " isn't a string")
local message = util.c("sys_config> device entry #", i, ": device ", name, " isn't a string")
println(message)
log.fatal(message)
return false
@ -276,7 +276,7 @@ local function main()
-- CHECK: index type
if (index ~= nil) and (not util.is_int(index)) then
local message = util.c("configure> device entry #", i, ": index ", index, " isn't valid")
local message = util.c("sys_config> device entry #", i, ": index ", index, " isn't valid")
println(message)
log.fatal(message)
return false
@ -284,8 +284,9 @@ local function main()
-- CHECK: index range
local function validate_index(min, max)
if (util.is_int(index) and index < min) and (max ~= nil and index > max) then
local message = util.c("configure> device entry #", i, ": index ", index, " isn't >= ", min, " and <= ", max)
if (not util.is_int(index)) or ((index < min) and (max ~= nil and index > max)) then
local message = util.c("sys_config> device entry #", i, ": index ", index, " isn't >= ", min)
if max ~= nil then message = util.c(message, " and <= ", max) end
println(message)
log.fatal(message)
return false
@ -295,12 +296,12 @@ local function main()
-- CHECK: reactor is an integer >= 0
local function validate_assign(for_facility)
if for_facility and for_reactor ~= 0 then
local message = util.c("configure> device entry #", i, ": must only be for the facility")
local message = util.c("sys_config> device entry #", i, ": must only be for the facility")
println(message)
log.fatal(message)
return false
elseif (not for_facility) and ((not util.is_int(for_reactor)) or (for_reactor < 1) or (for_reactor > 4)) then
local message = util.c("configure> device entry #", i, ": unit assignment ", for_reactor, " isn't vaild")
local message = util.c("sys_config> device entry #", i, ": unit assignment ", for_reactor, " isn't vaild")
println(message)
log.fatal(message)
return false
@ -317,7 +318,7 @@ local function main()
local faulted = nil ---@type boolean|nil
if device == nil then
local message = util.c("configure> '", name, "' not found, using placeholder")
local message = util.c("sys_config> '", name, "' not found, using placeholder")
println(message)
log.warning(message)
@ -338,8 +339,8 @@ local function main()
formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed boiler multiblock"))
println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed boiler multiblock"))
return false
end
elseif type == "turbineValve" then
@ -353,8 +354,8 @@ local function main()
formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed turbine multiblock"))
println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed turbine multiblock"))
return false
end
elseif type == "dynamicValve" then
@ -373,8 +374,8 @@ local function main()
formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed dynamic tank multiblock"))
println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed dynamic tank multiblock"))
return false
end
elseif type == "inductionPort" then
@ -387,8 +388,8 @@ local function main()
formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed induction matrix multiblock"))
println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed induction matrix multiblock"))
return false
end
elseif type == "spsPort" then
@ -401,8 +402,8 @@ local function main()
formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed SPS multiblock"))
println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed SPS multiblock"))
return false
end
elseif type == "solarNeutronActivator" then
@ -423,7 +424,7 @@ local function main()
rtu_type = RTU_UNIT_TYPE.VIRTUAL
rtu_iface = rtu.init_unit().interface()
else
local message = util.c("configure> device '", name, "' is not a known type (", type, ")")
local message = util.c("sys_config> device '", name, "' is not a known type (", type, ")")
println_ts(message)
log.fatal(message)
return false
@ -431,12 +432,12 @@ local function main()
if is_multiblock then
if not formed then
log.info(util.c("configure> device '", name, "' is not formed"))
log.info(util.c("sys_config> device '", name, "' is not formed"))
elseif faulted then
-- sometimes there is a race condition on server boot where it reports formed, but
-- the other functions are not yet defined (that's the theory at least). mark as unformed to attempt connection later
formed = false
log.warning(util.c("configure> device '", name, "' is formed, but initialization had one or more faults: marked as unformed"))
log.warning(util.c("sys_config> device '", name, "' is formed, but initialization had one or more faults: marked as unformed"))
end
end
@ -466,7 +467,7 @@ local function main()
for_message = util.c("reactor ", for_reactor)
end
log.info(util.c("configure> initialized RTU unit #", #units, ": ", name, " (", types.rtu_type_to_string(rtu_type), ") [", index, "] for ", for_message))
log.info(util.c("sys_config> initialized RTU unit #", #units, ": ", name, " (", types.rtu_type_to_string(rtu_type), ") [", index, "] for ", for_message))
rtu_unit.uid = #units

View File

@ -1171,11 +1171,11 @@ function facility.new(num_reactors, cooling_conf)
end
-- radiation monitors (environment detectors)
status.rad_mon = {}
status.envds = {}
for i = 1, #self.envd do
local envd = self.envd[i] ---@type unit_session
local db = envd.get_db() ---@type envd_session_db
status.rad_mon[envd.get_device_idx()] = { envd.is_faulted(), db.radiation, db.radiation_raw }
status.envds[envd.get_device_idx()] = { envd.is_faulted(), db.radiation, db.radiation_raw }
end
return status

View File

@ -864,11 +864,11 @@ function unit.new(reactor_id, num_boilers, num_turbines)
status.sna = { #self.snas, public.get_sna_rate(), total_peak }
-- radiation monitors (environment detectors)
status.rad_mon = {}
status.envds = {}
for i = 1, #self.envd do
local envd = self.envd[i] ---@type unit_session
local db = envd.get_db() ---@type envd_session_db
status.rad_mon[envd.get_device_idx()] = { envd.is_faulted(), db.radiation, db.radiation_raw }
status.envds[envd.get_device_idx()] = { envd.is_faulted(), db.radiation, db.radiation_raw }
end
return status