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 end
-- environment detector status -- environment detector status
if type(rtu_statuses.rad_mon) == "table" then if type(rtu_statuses.envds) == "table" then
if #rtu_statuses.rad_mon > 0 then local max_rad, max_reading, any_conn, any_faulted = 0, types.new_zero_radiation_reading(), false, false
local max_rad, max_reading, any_faulted = 0, types.new_zero_radiation_reading(), false
for i = 1, #rtu_statuses.rad_mon do for _, envd in pairs(rtu_statuses.envds) do
local rad_mon = rtu_statuses.rad_mon[i] local rtu_faulted = envd[1] ---@type boolean
local rtu_faulted = rad_mon[1] ---@type boolean local radiation = envd[2] ---@type radiation_reading
local radiation = rad_mon[2] ---@type radiation_reading local rad_raw = envd[3] ---@type number
local rad_raw = rad_mon[3] ---@type number
any_conn = true
any_faulted = any_faulted or rtu_faulted any_faulted = any_faulted or rtu_faulted
if rad_raw > max_rad then if rad_raw > max_rad then
max_rad = rad_raw max_rad = rad_raw
max_reading = radiation max_reading = radiation
end end
end end
if any_conn then
fac.radiation = max_reading fac.radiation = max_reading
fac.ps.publish("rad_computed_status", util.trinary(any_faulted, 2, 3)) fac.ps.publish("rad_computed_status", util.trinary(any_faulted, 2, 3))
else else
@ -786,7 +787,7 @@ function iocontrol.update_facility_status(status)
fac.ps.publish("radiation", fac.radiation) fac.ps.publish("radiation", fac.radiation)
else else
log.debug(log_header .. "radiation monitor list not a table") log.debug(log_header .. "environment detector list not a table")
valid = false valid = false
end end
else else
@ -1061,15 +1062,14 @@ function iocontrol.update_unit_statuses(statuses)
end end
-- environment detector status -- environment detector status
if type(rtu_statuses.rad_mon) == "table" then if type(rtu_statuses.envds) == "table" then
local max_rad, max_reading = 0, types.new_zero_radiation_reading() 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 any_conn = true
local rad_mon = rtu_statuses.rad_mon[id]
local radiation = rad_mon[2] ---@type radiation_reading
local rad_raw = rad_mon[3] ---@type number
if rad_raw > max_rad then if rad_raw > max_rad then
max_rad = rad_raw max_rad = rad_raw
@ -1077,6 +1077,7 @@ function iocontrol.update_unit_statuses(statuses)
end end
end end
if any_conn then
unit.radiation = max_reading unit.radiation = max_reading
else else
unit.radiation = types.new_zero_radiation_reading() 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.") 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 elseif type == "dynamicValve" then
tool_ctl.p_prompt.set_value("This is the # dynamic tank for...") 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.show()
tool_ctl.p_idx.redraw() tool_ctl.p_idx.redraw()
tool_ctl.p_idx.set_max(4) tool_ctl.p_idx.set_max(4)
@ -724,23 +728,19 @@ local function config_view(display)
tool_ctl.p_unit.enable() tool_ctl.p_unit.enable()
end 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.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.") 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 elseif type == "environmentDetector" then
tool_ctl.p_prompt.set_value("This is the # environment detector for...") 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.show()
tool_ctl.p_idx.redraw() tool_ctl.p_idx.redraw()
tool_ctl.p_idx.set_max(99) tool_ctl.p_idx.set_max(99)
tool_ctl.p_unit.reposition(18, 6) 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 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.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.") 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 elseif type == "inductionPort" or type == "spsPort" then
@ -882,6 +882,8 @@ local function config_view(display)
tool_ctl.p_err.show() tool_ctl.p_err.show()
return return
else index = idx end else index = idx end
elseif peri_type == "dynamicValve" then
index = 1
elseif peri_type == "environmentDetector" then elseif peri_type == "environmentDetector" then
if not (util.is_int(idx) and idx > 0) then if not (util.is_int(idx) and idx > 0) then
tool_ctl.p_err.set_value("Index must be greater than 0.") 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 ---@cast for_reactor integer
assignment = "reactor unit " .. entry.unit assignment = "reactor unit " .. entry.unit
if rs_rtus[for_reactor] == nil then 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 = {} } rs_rtus[for_reactor] = { rtu = redstone_rtu.new(), capabilities = {} }
end end
elseif entry.unit == nil then elseif entry.unit == nil then
assignment = "facility" assignment = "facility"
for_reactor = 0 for_reactor = 0
if rs_rtus[for_reactor] == nil then 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 = {} } rs_rtus[for_reactor] = { rtu = redstone_rtu.new(), capabilities = {} }
end end
else 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) println(message)
log.fatal(message) log.fatal(message)
return false return false
@ -184,7 +184,7 @@ local function main()
local capabilities = rs_rtus[for_reactor].capabilities local capabilities = rs_rtus[for_reactor].capabilities
if not valid then 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) println(message)
log.fatal(message) log.fatal(message)
return false return false
@ -194,7 +194,7 @@ local function main()
if mode == rsio.IO_MODE.DIGITAL_IN then if mode == rsio.IO_MODE.DIGITAL_IN then
-- can't have duplicate inputs -- can't have duplicate inputs
if util.table_contains(capabilities, entry.port) then 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) println(message)
log.warning(message) log.warning(message)
else else
@ -205,7 +205,7 @@ local function main()
elseif mode == rsio.IO_MODE.ANALOG_IN then elseif mode == rsio.IO_MODE.ANALOG_IN then
-- can't have duplicate inputs -- can't have duplicate inputs
if util.table_contains(capabilities, entry.port) then 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) println(message)
log.warning(message) log.warning(message)
else else
@ -215,14 +215,14 @@ local function main()
rs_rtu.link_ao(entry.side) rs_rtu.link_ao(entry.side)
else else
-- should be unreachable code, we already validated ports -- 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) log.error("sys_config> fell through if chain attempting to identify IO mode at block index #" .. entry_idx, true)
println("configure> encountered a software error, check logs") println("sys_config> encountered a software error, check logs")
return false return false
end end
table.insert(capabilities, entry.port) 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
end end
@ -252,7 +252,7 @@ local function main()
for_message = util.c("reactor unit ", for_reactor) for_message = util.c("reactor unit ", for_reactor)
end 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 unit.uid = #units
@ -268,7 +268,7 @@ local function main()
-- CHECK: name is a string -- CHECK: name is a string
if type(name) ~= "string" then 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) println(message)
log.fatal(message) log.fatal(message)
return false return false
@ -276,7 +276,7 @@ local function main()
-- CHECK: index type -- CHECK: index type
if (index ~= nil) and (not util.is_int(index)) then 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) println(message)
log.fatal(message) log.fatal(message)
return false return false
@ -284,8 +284,9 @@ local function main()
-- CHECK: index range -- CHECK: index range
local function validate_index(min, max) local function validate_index(min, max)
if (util.is_int(index) and index < min) and (max ~= nil and index > max) then if (not util.is_int(index)) or ((index < min) and (max ~= nil and index > max)) then
local message = util.c("configure> device entry #", i, ": index ", index, " isn't >= ", min, " and <= ", max) 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) println(message)
log.fatal(message) log.fatal(message)
return false return false
@ -295,12 +296,12 @@ local function main()
-- CHECK: reactor is an integer >= 0 -- CHECK: reactor is an integer >= 0
local function validate_assign(for_facility) local function validate_assign(for_facility)
if for_facility and for_reactor ~= 0 then 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) println(message)
log.fatal(message) log.fatal(message)
return false return false
elseif (not for_facility) and ((not util.is_int(for_reactor)) or (for_reactor < 1) or (for_reactor > 4)) then 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) println(message)
log.fatal(message) log.fatal(message)
return false return false
@ -317,7 +318,7 @@ local function main()
local faulted = nil ---@type boolean|nil local faulted = nil ---@type boolean|nil
if device == nil then 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) println(message)
log.warning(message) log.warning(message)
@ -338,8 +339,8 @@ local function main()
formed = device.isFormed() formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed")) println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed boiler multiblock")) log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed boiler multiblock"))
return false return false
end end
elseif type == "turbineValve" then elseif type == "turbineValve" then
@ -353,8 +354,8 @@ local function main()
formed = device.isFormed() formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed")) println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed turbine multiblock")) log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed turbine multiblock"))
return false return false
end end
elseif type == "dynamicValve" then elseif type == "dynamicValve" then
@ -373,8 +374,8 @@ local function main()
formed = device.isFormed() formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed")) println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed dynamic tank multiblock")) log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed dynamic tank multiblock"))
return false return false
end end
elseif type == "inductionPort" then elseif type == "inductionPort" then
@ -387,8 +388,8 @@ local function main()
formed = device.isFormed() formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed")) println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed induction matrix multiblock")) log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed induction matrix multiblock"))
return false return false
end end
elseif type == "spsPort" then elseif type == "spsPort" then
@ -401,8 +402,8 @@ local function main()
formed = device.isFormed() formed = device.isFormed()
if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then if formed == ppm.UNDEFINED_FIELD or formed == ppm.ACCESS_FAULT then
println_ts(util.c("configure> failed to check if '", name, "' is formed")) println_ts(util.c("sys_config> failed to check if '", name, "' is formed"))
log.fatal(util.c("configure> failed to check if '", name, "' is a formed SPS multiblock")) log.fatal(util.c("sys_config> failed to check if '", name, "' is a formed SPS multiblock"))
return false return false
end end
elseif type == "solarNeutronActivator" then elseif type == "solarNeutronActivator" then
@ -423,7 +424,7 @@ local function main()
rtu_type = RTU_UNIT_TYPE.VIRTUAL rtu_type = RTU_UNIT_TYPE.VIRTUAL
rtu_iface = rtu.init_unit().interface() rtu_iface = rtu.init_unit().interface()
else 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) println_ts(message)
log.fatal(message) log.fatal(message)
return false return false
@ -431,12 +432,12 @@ local function main()
if is_multiblock then if is_multiblock then
if not formed 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 elseif faulted then
-- sometimes there is a race condition on server boot where it reports formed, but -- 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 -- the other functions are not yet defined (that's the theory at least). mark as unformed to attempt connection later
formed = false 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
end end
@ -466,7 +467,7 @@ local function main()
for_message = util.c("reactor ", for_reactor) for_message = util.c("reactor ", for_reactor)
end 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 rtu_unit.uid = #units

View File

@ -1171,11 +1171,11 @@ function facility.new(num_reactors, cooling_conf)
end end
-- radiation monitors (environment detectors) -- radiation monitors (environment detectors)
status.rad_mon = {} status.envds = {}
for i = 1, #self.envd do for i = 1, #self.envd do
local envd = self.envd[i] ---@type unit_session local envd = self.envd[i] ---@type unit_session
local db = envd.get_db() ---@type envd_session_db 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 end
return status 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 } status.sna = { #self.snas, public.get_sna_rate(), total_peak }
-- radiation monitors (environment detectors) -- radiation monitors (environment detectors)
status.rad_mon = {} status.envds = {}
for i = 1, #self.envd do for i = 1, #self.envd do
local envd = self.envd[i] ---@type unit_session local envd = self.envd[i] ---@type unit_session
local db = envd.get_db() ---@type envd_session_db 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 end
return status return status