cleanup and fixes

This commit is contained in:
Mikayla Fischler
2023-11-12 14:21:48 -05:00
parent 78ad6d5457
commit 68754977b0
5 changed files with 23 additions and 58 deletions

View File

@@ -40,10 +40,12 @@ local function handle_unit_mount(smem, println_ts, iface, type, device, unit)
-- find disconnected device to reconnect
-- note: cannot check isFormed as that would yield this coroutine and consume events
if unit.name == iface then
local resend_advert = false
local faulted = false
local unknown = false
local invalid = false
local resend_advert, faulted, unknown, invalid = false, false, false, false
local function fail(msg)
invalid = true
log.error(msg .. " in config")
end
-- found, re-link
unit.device = device
@@ -52,79 +54,45 @@ local function handle_unit_mount(smem, println_ts, iface, type, device, unit)
resend_advert = true
if type == "boilerValve" then
-- boiler multiblock
if unit.reactor < 1 or unit.reactor > 4 then
invalid = true
log.error(util.c("boiler '", unit.name, "' cannot init, not assigned to a valid unit in config"))
end
if (unit.index == false) or unit.index < 1 or unit.index > 2 then
invalid = true
log.error(util.c("boiler '", unit.name, "' cannot init, invalid index provided in config"))
end
if unit.reactor < 1 or unit.reactor > 4 then fail(util.c("boiler '", unit.name, "' cannot init, not assigned to a valid unit")) end
if (unit.index == false) or unit.index < 1 or unit.index > 2 then fail(util.c("boiler '", unit.name, "' cannot init, invalid index provided")) end
unit.type = RTU_UNIT_TYPE.BOILER_VALVE
elseif type == "turbineValve" then
-- turbine multiblock
if unit.reactor < 1 or unit.reactor > 4 then
invalid = true
log.error(util.c("turbine '", unit.name, "' cannot init, not assigned to a valid unit in config"))
end
if (unit.index == false) or unit.index < 1 or unit.index > 3 then
invalid = true
log.error(util.c("turbine '", unit.name, "' cannot init, invalid index provided in config"))
end
if unit.reactor < 1 or unit.reactor > 4 then fail(util.c("turbine '", unit.name, "' cannot init, not assigned to a valid unit")) end
if (unit.index == false) or unit.index < 1 or unit.index > 3 then fail(util.c("turbine '", unit.name, "' cannot init, invalid index provided")) end
unit.type = RTU_UNIT_TYPE.TURBINE_VALVE
elseif type == "dynamicValve" then
-- dynamic tank multiblock
if unit.reactor < 0 or unit.reactor > 4 then
invalid = true
log.error(util.c("dynamic tank '", unit.name, "' cannot init, no valid assignment provided in config"))
end
if unit.reactor < 0 or unit.reactor > 4 then fail(util.c("dynamic tank '", unit.name, "' cannot init, no valid assignment provided")) end
if (unit.reactor == 0 and ((unit.index == false) or unit.index < 1 or unit.index > 4)) or
(unit.reactor > 0 and unit.index ~= 1) then
invalid = true
log.error(util.c("dynamic tank '", unit.name, "' cannot init, invalid index provided in config"))
fail(util.c("dynamic tank '", unit.name, "' cannot init, invalid index provided"))
end
unit.type = RTU_UNIT_TYPE.DYNAMIC_VALVE
elseif type == "inductionPort" then
-- induction matrix multiblock
if unit.reactor ~= 0 then
invalid = true
log.error(util.c("induction matrix '", unit.name, "' cannot init, not assigned to facility in config"))
end
if unit.reactor ~= 0 then fail(util.c("induction matrix '", unit.name, "' cannot init, not assigned to facility")) end
unit.type = RTU_UNIT_TYPE.IMATRIX
elseif type == "spsPort" then
-- SPS multiblock
if unit.reactor ~= 0 then
invalid = true
log.error(util.c("SPS '", unit.name, "' cannot init, not assigned to facility in config"))
end
if unit.reactor ~= 0 then fail(util.c("SPS '", unit.name, "' cannot init, not assigned to facility")) end
unit.type = RTU_UNIT_TYPE.SPS
elseif type == "solarNeutronActivator" then
-- SNA
if unit.reactor < 1 or unit.reactor > 4 then
invalid = true
log.error(util.c("SNA '", unit.name, "' cannot init, not assigned to a valid unit in config"))
end
if unit.reactor < 1 or unit.reactor > 4 then fail(util.c("SNA '", unit.name, "' cannot init, not assigned to a valid unit")) end
unit.type = RTU_UNIT_TYPE.SNA
elseif type == "environmentDetector" then
-- advanced peripherals environment detector
if unit.reactor < 0 or unit.reactor > 4 then
invalid = true
log.error(util.c("environment detector '", unit.name, "' cannot init, no valid assignment provided in config"))
end
if (unit.index == false) or unit.index < 1 then
invalid = true
log.error(util.c("environment detector '", unit.name, "' cannot init, invalid index provided in config"))
end
if unit.reactor < 0 or unit.reactor > 4 then fail(util.c("environment detector '", unit.name, "' cannot init, no valid assignment provided")) end
if (unit.index == false) or unit.index < 1 then fail(util.c("environment detector '", unit.name, "' cannot init, invalid index provided")) end
unit.type = RTU_UNIT_TYPE.ENV_DETECTOR
else