#545 supervisor type annotation updates

This commit is contained in:
Mikayla 2024-09-13 02:23:16 +00:00
parent 3003e57531
commit a1dbc15d16
14 changed files with 178 additions and 163 deletions

View File

@ -77,19 +77,19 @@ local tool_ctl = {
auth_key_textbox = nil, ---@type graphics_element auth_key_textbox = nil, ---@type graphics_element
auth_key_value = "", auth_key_value = "",
cooling_elems = {}, cooling_elems = {}, ---@type { line: graphics_element, turbines: graphics_element, boilers: graphics_element, tank: graphics_element }[]
tank_elems = {}, tank_elems = {}, ---@type { div: graphics_element, tank_opt: graphics_element, no_tank: graphics_element }[]
vis_ftanks = {}, vis_ftanks = {}, ---@type { line: graphics_element, pipe_conn?: graphics_element, pipe_chain?: graphics_element, pipe_direct?: graphics_element, label?: graphics_element }[]
vis_utanks = {} vis_utanks = {} ---@type { line: graphics_element, label: graphics_element }[]
} }
---@class svr_config ---@class svr_config
local tmp_cfg = { local tmp_cfg = {
UnitCount = 1, UnitCount = 1,
CoolingConfig = {}, CoolingConfig = {}, ---@type { TurbineCount: integer, BoilerCount: integer, TankConnection: boolean }[]
FacilityTankMode = 0, FacilityTankMode = 0,
FacilityTankDefs = {}, FacilityTankDefs = {}, ---@type integer[]
ExtChargeIdling = false, ExtChargeIdling = false,
SVR_Channel = nil, ---@type integer SVR_Channel = nil, ---@type integer
PLC_Channel = nil, ---@type integer PLC_Channel = nil, ---@type integer
@ -294,6 +294,8 @@ local function config_view(display)
tmp_cfg.CoolingConfig = {} tmp_cfg.CoolingConfig = {}
for i = 1, tmp_cfg.UnitCount do for i = 1, tmp_cfg.UnitCount do
local conf = tool_ctl.cooling_elems[i] local conf = tool_ctl.cooling_elems[i]
-- already verified fields are numbers
---@diagnostic disable-next-line: assign-type-mismatch
tmp_cfg.CoolingConfig[i] = { TurbineCount = tonumber(conf.turbines.get_value()), BoilerCount = tonumber(conf.boilers.get_value()), TankConnection = conf.tank.get_value() } tmp_cfg.CoolingConfig[i] = { TurbineCount = tonumber(conf.turbines.get_value()), BoilerCount = tonumber(conf.boilers.get_value()), TankConnection = conf.tank.get_value() }
if conf.tank.get_value() then any_has_tank = true end if conf.tank.get_value() then any_has_tank = true end
end end

View File

@ -40,7 +40,7 @@ local facility = {}
function facility.new(config) function facility.new(config)
---@class _facility_self ---@class _facility_self
local self = { local self = {
units = {}, units = {}, ---@type reactor_unit[]
types = { AUTO_SCRAM = AUTO_SCRAM, START_STATUS = START_STATUS }, types = { AUTO_SCRAM = AUTO_SCRAM, START_STATUS = START_STATUS },
status_text = { "START UP", "initializing..." }, status_text = { "START UP", "initializing..." },
all_sys_ok = false, all_sys_ok = false,
@ -51,16 +51,16 @@ function facility.new(config)
r_cool = config.CoolingConfig, r_cool = config.CoolingConfig,
fac_tank_mode = config.FacilityTankMode, fac_tank_mode = config.FacilityTankMode,
fac_tank_defs = config.FacilityTankDefs, fac_tank_defs = config.FacilityTankDefs,
fac_tank_list = {} fac_tank_list = {} ---@type integer[]
}, },
-- rtus -- rtus
rtu_conn_count = 0, rtu_conn_count = 0,
rtu_list = {}, rtu_list = {}, ---@type unit_session[][]
redstone = {}, redstone = {}, ---@type unit_session[]
induction = {}, induction = {}, ---@type unit_session[]
sps = {}, sps = {}, ---@type unit_session[]
tanks = {}, tanks = {}, ---@type unit_session[]
envd = {}, envd = {}, ---@type unit_session[]
-- redstone I/O control -- redstone I/O control
io_ctl = nil, ---@type rs_controller io_ctl = nil, ---@type rs_controller
-- process control -- process control
@ -105,11 +105,11 @@ function facility.new(config)
sps_low_power = false, sps_low_power = false,
disabled_sps = false, disabled_sps = false,
-- alarm tones -- alarm tones
tone_states = {}, tone_states = {}, ---@type boolean[]
test_tone_set = false, test_tone_set = false,
test_tone_reset = false, test_tone_reset = false,
test_tone_states = {}, test_tone_states = {}, ---@type boolean[]
test_alarm_states = {}, test_alarm_states = {}, ---@type boolean[]
-- statistics -- statistics
im_stat_init = false, im_stat_init = false,
avg_charge = util.mov_avg(3), -- 3 seconds avg_charge = util.mov_avg(3), -- 3 seconds
@ -350,7 +350,7 @@ function facility.new(config)
-- additionally sets the requested auto waste mode if applicable -- additionally sets the requested auto waste mode if applicable
function public.update_units() function public.update_units()
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit local u = self.units[i]
u.auto_set_waste(self.current_waste_product) u.auto_set_waste(self.current_waste_product)
u.update() u.update()
end end
@ -363,16 +363,14 @@ function facility.new(config)
-- SCRAM all reactor units -- SCRAM all reactor units
function public.scram_all() function public.scram_all()
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit self.units[i].scram()
u.scram()
end end
end end
-- ack all alarms on all reactor units -- ack all alarms on all reactor units
function public.ack_all() function public.ack_all()
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit local u = self.units[i].ack_all()
u.ack_all()
end end
end end
@ -393,8 +391,7 @@ function facility.new(config)
-- load up current limits -- load up current limits
local limits = {} local limits = {}
for i = 1, config.UnitCount do for i = 1, config.UnitCount do
local u = self.units[i] ---@type reactor_unit limits[i] = self.units[i].get_control_inf().lim_br100 * 100
limits[i] = u.get_control_inf().lim_br100 * 100
end end
-- only allow changes if not running -- only allow changes if not running
@ -565,7 +562,7 @@ function facility.new(config)
if all or type == RTU_UNIT_TYPE.IMATRIX then if all or type == RTU_UNIT_TYPE.IMATRIX then
build.induction = {} build.induction = {}
for i = 1, #self.induction do for i = 1, #self.induction do
local matrix = self.induction[i] ---@type unit_session local matrix = self.induction[i]
build.induction[i] = { matrix.get_db().formed, matrix.get_db().build } build.induction[i] = { matrix.get_db().formed, matrix.get_db().build }
end end
end end
@ -573,7 +570,7 @@ function facility.new(config)
if all or type == RTU_UNIT_TYPE.SPS then if all or type == RTU_UNIT_TYPE.SPS then
build.sps = {} build.sps = {}
for i = 1, #self.sps do for i = 1, #self.sps do
local sps = self.sps[i] ---@type unit_session local sps = self.sps[i]
build.sps[i] = { sps.get_db().formed, sps.get_db().build } build.sps[i] = { sps.get_db().formed, sps.get_db().build }
end end
end end
@ -581,7 +578,7 @@ function facility.new(config)
if all or type == RTU_UNIT_TYPE.DYNAMIC_VALVE then if all or type == RTU_UNIT_TYPE.DYNAMIC_VALVE then
build.tanks = {} build.tanks = {}
for i = 1, #self.tanks do for i = 1, #self.tanks do
local tank = self.tanks[i] ---@type unit_session local tank = self.tanks[i]
build.tanks[tank.get_device_idx()] = { tank.get_db().formed, tank.get_db().build } build.tanks[tank.get_device_idx()] = { tank.get_db().formed, tank.get_db().build }
end end
end end
@ -649,7 +646,7 @@ function facility.new(config)
-- status of induction matricies (including tanks) -- status of induction matricies (including tanks)
status.induction = {} status.induction = {}
for i = 1, #self.induction do for i = 1, #self.induction do
local matrix = self.induction[i] ---@type unit_session local matrix = self.induction[i]
local db = matrix.get_db() ---@type imatrix_session_db local db = matrix.get_db() ---@type imatrix_session_db
status.induction[i] = { matrix.is_faulted(), db.formed, db.state, db.tanks } status.induction[i] = { matrix.is_faulted(), db.formed, db.state, db.tanks }
@ -662,7 +659,7 @@ function facility.new(config)
-- status of sps -- status of sps
status.sps = {} status.sps = {}
for i = 1, #self.sps do for i = 1, #self.sps do
local sps = self.sps[i] ---@type unit_session local sps = self.sps[i]
local db = sps.get_db() ---@type sps_session_db local db = sps.get_db() ---@type sps_session_db
status.sps[i] = { sps.is_faulted(), db.formed, db.state, db.tanks } status.sps[i] = { sps.is_faulted(), db.formed, db.state, db.tanks }
end end
@ -670,7 +667,7 @@ function facility.new(config)
-- status of dynamic tanks -- status of dynamic tanks
status.tanks = {} status.tanks = {}
for i = 1, #self.tanks do for i = 1, #self.tanks do
local tank = self.tanks[i] ---@type unit_session local tank = self.tanks[i]
local db = tank.get_db() ---@type dynamicv_session_db local db = tank.get_db() ---@type dynamicv_session_db
status.tanks[tank.get_device_idx()] = { tank.is_faulted(), db.formed, db.state, db.tanks } status.tanks[tank.get_device_idx()] = { tank.is_faulted(), db.formed, db.state, db.tanks }
end end
@ -678,7 +675,7 @@ function facility.new(config)
-- radiation monitors (environment detectors) -- radiation monitors (environment detectors)
status.envds = {} 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]
local db = envd.get_db() ---@type envd_session_db local db = envd.get_db() ---@type envd_session_db
status.envds[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

View File

@ -84,7 +84,7 @@ local function allocate_burn_rate(burn_rate, ramp, abort_on_fault)
-- go through all reactor units in this group -- go through all reactor units in this group
for id = 1, #units do for id = 1, #units do
local u = units[id] ---@type reactor_unit local u = units[id]
local ctl = u.get_control_inf() local ctl = u.get_control_inf()
local lim_br100 = u.auto_get_effective_limit() local lim_br100 = u.auto_get_effective_limit()
@ -139,7 +139,7 @@ function update.pre_auto()
-- check if test routines are allowed right now -- check if test routines are allowed right now
self.allow_testing = true self.allow_testing = true
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit local u = self.units[i]
self.allow_testing = self.allow_testing and u.is_safe_idle() self.allow_testing = self.allow_testing and u.is_safe_idle()
end end
@ -149,7 +149,7 @@ function update.pre_auto()
-- calculate moving averages for induction matrix -- calculate moving averages for induction matrix
if self.induction[1] ~= nil then if self.induction[1] ~= nil then
local matrix = self.induction[1] ---@type unit_session local matrix = self.induction[1]
local db = matrix.get_db() ---@type imatrix_session_db local db = matrix.get_db() ---@type imatrix_session_db
local build_update = db.build.last_update local build_update = db.build.last_update
@ -531,7 +531,7 @@ function update.auto_safety()
-- check for critical unit alarms -- check for critical unit alarms
astatus.crit_alarm = false astatus.crit_alarm = false
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit local u = self.units[i]
if u.has_alarm_min_prio(PRIO.CRITICAL) then if u.has_alarm_min_prio(PRIO.CRITICAL) then
astatus.crit_alarm = true astatus.crit_alarm = true
@ -544,7 +544,7 @@ function update.auto_safety()
local max_rad = 0 local max_rad = 0
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]
local e_db = envd.get_db() ---@type envd_session_db 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 if e_db.radiation_raw > max_rad then max_rad = e_db.radiation_raw end
end end
@ -620,7 +620,7 @@ function update.auto_safety()
-- reset PLC RPS trips if we should -- reset PLC RPS trips if we should
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit local u = self.units[i]
u.auto_cond_rps_reset() u.auto_cond_rps_reset()
end end
end end
@ -647,7 +647,7 @@ function update.alarm_audio()
else else
-- check all alarms for all units -- check all alarms for all units
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit local u = self.units[i]
for id, alarm in pairs(u.get_alarms()) do for id, alarm in pairs(u.get_alarms()) do
alarms[id] = alarms[id] or (alarm == ALARM_STATE.TRIPPED) alarms[id] = alarms[id] or (alarm == ALARM_STATE.TRIPPED)
end end
@ -730,7 +730,7 @@ function update.redstone(ack_all)
-- handle facility SCRAM -- handle facility SCRAM
if self.io_ctl.digital_read(IO.F_SCRAM) then if self.io_ctl.digital_read(IO.F_SCRAM) then
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit local u = self.units[i]
u.cond_scram() u.cond_scram()
end end
end end
@ -741,7 +741,7 @@ function update.redstone(ack_all)
-- update facility alarm outputs -- update facility alarm outputs
local has_prio_alarm, has_any_alarm = false, false local has_prio_alarm, has_any_alarm = false, false
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit local u = self.units[i]
if u.has_alarm_min_prio(PRIO.EMERGENCY) then if u.has_alarm_min_prio(PRIO.EMERGENCY) then
has_prio_alarm, has_any_alarm = true, true has_prio_alarm, has_any_alarm = true, true
@ -771,7 +771,7 @@ function update.unit_mgmt()
local need_emcool = false local need_emcool = false
for i = 1, #self.units do for i = 1, #self.units do
local u = self.units[i] ---@type reactor_unit local u = self.units[i]
-- update auto waste processing -- update auto waste processing
if u.get_control_inf().waste_mode == WASTE_MODE.AUTO then if u.get_control_inf().waste_mode == WASTE_MODE.AUTO then
@ -812,7 +812,7 @@ function update.unit_mgmt()
-- there should be no need for any to be in fill only mode -- there should be no need for any to be in fill only mode
if need_emcool then if need_emcool then
for i = 1, #self.tanks do for i = 1, #self.tanks do
local session = self.tanks[i] ---@type unit_session local session = self.tanks[i]
local tank = session.get_db() ---@type dynamicv_session_db local tank = session.get_db() ---@type dynamicv_session_db
if tank.state.container_mode == CONTAINER_MODE.FILL then if tank.state.container_mode == CONTAINER_MODE.FILL then

View File

@ -15,7 +15,12 @@ local data = {
pdg_entry = nil, ---@type function pdg_entry = nil, ---@type function
chk_entry = nil, ---@type function chk_entry = nil, ---@type function
-- list entries -- list entries
entries = { rtu = {}, pdg = {}, chk = {}, missing = {} } entries = {
rtu = {}, ---@type graphics_element[]
pdg = {}, ---@type graphics_element[]
chk = {}, ---@type graphics_element[][]
missing = {} ---@type graphics_element[]
}
} }
-- link list boxes -- link list boxes

View File

@ -128,7 +128,7 @@ function coordinator.new_session(id, s_addr, i_seq_num, in_queue, out_queue, tim
local unit_builds = {} local unit_builds = {}
for i = 1, #self.units do for i = 1, #self.units do
local unit = self.units[i] ---@type reactor_unit local unit = self.units[i]
unit_builds[unit.get_id()] = unit.get_build() unit_builds[unit.get_id()] = unit.get_build()
end end
@ -145,7 +145,7 @@ function coordinator.new_session(id, s_addr, i_seq_num, in_queue, out_queue, tim
local builds = {} local builds = {}
for i = 1, #self.units do for i = 1, #self.units do
local unit = self.units[i] ---@type reactor_unit local unit = self.units[i]
builds[unit.get_id()] = unit.get_build() builds[unit.get_id()] = unit.get_build()
end end
@ -168,7 +168,7 @@ function coordinator.new_session(id, s_addr, i_seq_num, in_queue, out_queue, tim
local status = {} local status = {}
for i = 1, #self.units do for i = 1, #self.units do
local unit = self.units[i] ---@type reactor_unit local unit = self.units[i]
status[unit.get_id()] = { status[unit.get_id()] = {
unit.get_reactor_status(), unit.get_reactor_status(),
@ -308,7 +308,7 @@ function coordinator.new_session(id, s_addr, i_seq_num, in_queue, out_queue, tim
-- continue if valid unit id -- continue if valid unit id
if util.is_int(uid) and uid > 0 and uid <= #self.units then if util.is_int(uid) and uid > 0 and uid <= #self.units then
local unit = self.units[uid] ---@type reactor_unit local unit = self.units[uid]
local manual = facility.get_group(uid) == AUTO_GROUP.MANUAL local manual = facility.get_group(uid) == AUTO_GROUP.MANUAL
if cmd == UNIT_COMMAND.SCRAM then if cmd == UNIT_COMMAND.SCRAM then
@ -432,8 +432,7 @@ function coordinator.new_session(id, s_addr, i_seq_num, in_queue, out_queue, tim
local unit_id = cmd.val local unit_id = cmd.val
local builds = {} local builds = {}
local unit = self.units[unit_id] ---@type reactor_unit builds[unit_id] = self.units[unit_id].get_build(-1)
builds[unit_id] = unit.get_build(-1)
_send(CRDN_TYPE.UNIT_BUILDS, { builds }) _send(CRDN_TYPE.UNIT_BUILDS, { builds })
elseif cmd.key == CRD_S_DATA.RESEND_RTU_BUILD then elseif cmd.key == CRD_S_DATA.RESEND_RTU_BUILD then
@ -446,8 +445,7 @@ function coordinator.new_session(id, s_addr, i_seq_num, in_queue, out_queue, tim
local builds = {} local builds = {}
local unit = self.units[unit_id] ---@type reactor_unit builds[unit_id] = self.units[unit_id].get_build(cmd.val.type)
builds[unit_id] = unit.get_build(cmd.val.type)
_send(CRDN_TYPE.UNIT_BUILDS, { builds }) _send(CRDN_TYPE.UNIT_BUILDS, { builds })
else else

View File

@ -63,7 +63,7 @@ function rtu.new_session(id, s_addr, i_seq_num, in_queue, out_queue, timeout, ad
keep_alive = 0, keep_alive = 0,
alarm_tones = 0 alarm_tones = 0
}, },
units = {} units = {} ---@type unit_session[]
} }
---@class rtu_session ---@class rtu_session
@ -80,13 +80,13 @@ function rtu.new_session(id, s_addr, i_seq_num, in_queue, out_queue, timeout, ad
_reset_config() _reset_config()
for i = 1, #self.fac_units do for i = 1, #self.fac_units do
local unit = self.fac_units[i] ---@type reactor_unit local unit = self.fac_units[i]
unit.purge_rtu_devices(id) unit.purge_rtu_devices(id)
facility.purge_rtu_devices(id) facility.purge_rtu_devices(id)
end end
for i = 1, #self.advert do for i = 1, #self.advert do
local unit = nil ---@type unit_session|nil local unit = nil
---@type rtu_advertisement ---@type rtu_advertisement
local unit_advert = { local unit_advert = {
@ -96,7 +96,7 @@ function rtu.new_session(id, s_addr, i_seq_num, in_queue, out_queue, timeout, ad
rsio = self.advert[i][4] rsio = self.advert[i][4]
} }
local u_type = unit_advert.type ---@type integer|boolean local u_type = unit_advert.type ---@type RTU_UNIT_TYPE|boolean
-- validate unit advertisement -- validate unit advertisement
@ -127,7 +127,7 @@ function rtu.new_session(id, s_addr, i_seq_num, in_queue, out_queue, timeout, ad
log.debug(log_tag .. "_handle_advertisement(): advertisement unit validation failure") log.debug(log_tag .. "_handle_advertisement(): advertisement unit validation failure")
else else
if unit_advert.reactor > 0 then if unit_advert.reactor > 0 then
local target_unit = self.fac_units[unit_advert.reactor] ---@type reactor_unit local target_unit = self.fac_units[unit_advert.reactor]
-- unit RTUs -- unit RTUs
if u_type == RTU_UNIT_TYPE.REDSTONE then if u_type == RTU_UNIT_TYPE.REDSTONE then
@ -255,8 +255,7 @@ function rtu.new_session(id, s_addr, i_seq_num, in_queue, out_queue, timeout, ad
if pkt.scada_frame.protocol() == PROTOCOL.MODBUS_TCP then if pkt.scada_frame.protocol() == PROTOCOL.MODBUS_TCP then
---@cast pkt modbus_frame ---@cast pkt modbus_frame
if self.units[pkt.unit_id] ~= nil then if self.units[pkt.unit_id] ~= nil then
local unit = self.units[pkt.unit_id] ---@type unit_session self.units[pkt.unit_id].handle_packet(pkt)
unit.handle_packet(pkt)
end end
elseif pkt.scada_frame.protocol() == PROTOCOL.SCADA_MGMT then elseif pkt.scada_frame.protocol() == PROTOCOL.SCADA_MGMT then
---@cast pkt mgmt_frame ---@cast pkt mgmt_frame
@ -298,8 +297,7 @@ function rtu.new_session(id, s_addr, i_seq_num, in_queue, out_queue, timeout, ad
if pkt.length == 1 then if pkt.length == 1 then
local unit_id = pkt.data[1] local unit_id = pkt.data[1]
if self.units[unit_id] ~= nil then if self.units[unit_id] ~= nil then
local unit = self.units[unit_id] ---@type unit_session self.units[unit_id].invalidate_cache()
unit.invalidate_cache()
end end
else else
log.debug(log_tag .. "SCADA RTU GW device re-mount packet length mismatch") log.debug(log_tag .. "SCADA RTU GW device re-mount packet length mismatch")

View File

@ -6,7 +6,8 @@ local util = require("scada-common.util")
local txnctrl = {} local txnctrl = {}
local TIMEOUT = 2000 -- 2000ms max wait -- 2000ms max wait
local TIMEOUT = 2000
-- create a new transaction controller -- create a new transaction controller
---@nodiscard ---@nodiscard

View File

@ -164,7 +164,6 @@ function unit_session.new(session_id, unit_id, advert, out_queue, log_tag, txn_t
function public.get_cmd_queue() return protected.in_q end function public.get_cmd_queue() return protected.in_q end
-- close this unit -- close this unit
---@nodiscard
function public.close() self.connected = false end function public.close() self.connected = false end
-- check if this unit is connected -- check if this unit is connected
---@nodiscard ---@nodiscard

View File

@ -40,13 +40,26 @@ local SESSION_TYPE = {
svsessions.SESSION_TYPE = SESSION_TYPE svsessions.SESSION_TYPE = SESSION_TYPE
local self = { local self = {
-- references to supervisor state and other data
nic = nil, ---@type nic|nil nic = nil, ---@type nic|nil
fp_ok = false, fp_ok = false,
config = nil, ---@type svr_config config = nil, ---@type svr_config
facility = nil, ---@type facility|nil facility = nil, ---@type facility|nil
sessions = { rtu = {}, plc = {}, crd = {}, pdg = {} }, -- lists of connected sessions
sessions = {
rtu = {}, ---@type rtu_session_struct
plc = {}, ---@type plc_session_struct
crd = {}, ---@type crd_session_struct
pdg = {} ---@type pdg_session_struct
},
-- next session IDs
next_ids = { rtu = 0, plc = 0, crd = 0, pdg = 0 }, next_ids = { rtu = 0, plc = 0, crd = 0, pdg = 0 },
dev_dbg = { duplicate = {}, out_of_range = {}, connected = {} } -- rtu device tracking and invalid assignment detection
dev_dbg = {
duplicate = {}, ---@type unit_session
out_of_range = {}, ---@type unit_session
connected = {} ---@type { induction: boolean, sps: boolean, tanks: boolean[], units: unit_connections[] }
}
} }
---@alias sv_session_structs plc_session_struct|rtu_session_struct|crd_session_struct|pdg_session_struct ---@alias sv_session_structs plc_session_struct|rtu_session_struct|crd_session_struct|pdg_session_struct
@ -119,10 +132,10 @@ local function _sv_handle_outq(session)
end end
-- iterate all the given sessions -- iterate all the given sessions
---@param sessions table ---@param sessions sv_session_structs[]
local function _iterate(sessions) local function _iterate(sessions)
for i = 1, #sessions do for i = 1, #sessions do
local session = sessions[i] ---@type sv_session_structs local session = sessions[i]
if session.open and session.instance.iterate() then if session.open and session.instance.iterate() then
_sv_handle_outq(session) _sv_handle_outq(session)
@ -150,20 +163,20 @@ local function _shutdown(session)
end end
-- close connections -- close connections
---@param sessions table ---@param sessions sv_session_structs[]
local function _close(sessions) local function _close(sessions)
for i = 1, #sessions do for i = 1, #sessions do
local session = sessions[i] ---@type sv_session_structs local session = sessions[i]
if session.open then _shutdown(session) end if session.open then _shutdown(session) end
end end
end end
-- check if a watchdog timer event matches that of one of the provided sessions -- check if a watchdog timer event matches that of one of the provided sessions
---@param sessions table ---@param sessions sv_session_structs[]
---@param timer_event number ---@param timer_event number
local function _check_watchdogs(sessions, timer_event) local function _check_watchdogs(sessions, timer_event)
for i = 1, #sessions do for i = 1, #sessions do
local session = sessions[i] ---@type sv_session_structs local session = sessions[i]
if session.open then if session.open then
local triggered = session.instance.check_wd(timer_event) local triggered = session.instance.check_wd(timer_event)
if triggered then if triggered then
@ -175,8 +188,9 @@ local function _check_watchdogs(sessions, timer_event)
end end
-- delete any closed sessions -- delete any closed sessions
---@param sessions table ---@param sessions sv_session_structs[]
local function _free_closed(sessions) local function _free_closed(sessions)
---@param session sv_session_structs
local f = function (session) return session.open end local f = function (session) return session.open end
---@param session sv_session_structs ---@param session sv_session_structs
@ -189,7 +203,7 @@ end
-- find a session by computer ID -- find a session by computer ID
---@nodiscard ---@nodiscard
---@param list table ---@param list sv_session_structs[]
---@param s_addr integer ---@param s_addr integer
---@return sv_session_structs|nil ---@return sv_session_structs|nil
local function _find_session(list, s_addr) local function _find_session(list, s_addr)
@ -366,7 +380,7 @@ function svsessions.init(nic, fp_ok, config, facility)
for i = 1, config.UnitCount do for i = 1, config.UnitCount do
local r_cool = cool_conf.r_cool[i] local r_cool = cool_conf.r_cool[i]
local conns = { boilers = {}, turbines = {}, tanks = {} } local conns = { boilers = {}, turbines = {}, tanks = {} } ---@type unit_connections
for b = 1, r_cool.BoilerCount do conns.boilers[b] = true end for b = 1, r_cool.BoilerCount do conns.boilers[b] = true end
for t = 1, r_cool.TurbineCount do conns.turbines[t] = true end for t = 1, r_cool.TurbineCount do conns.turbines[t] = true end

View File

@ -22,7 +22,7 @@ local supervisor = require("supervisor.supervisor")
local svsessions = require("supervisor.session.svsessions") local svsessions = require("supervisor.session.svsessions")
local SUPERVISOR_VERSION = "v1.5.3" local SUPERVISOR_VERSION = "v1.5.4"
local println = util.println local println = util.println
local println_ts = util.println_ts local println_ts = util.println_ts

View File

@ -81,13 +81,13 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
num_turbines = num_turbines, num_turbines = num_turbines,
types = { DT_KEYS = DT_KEYS, AISTATE = AISTATE }, types = { DT_KEYS = DT_KEYS, AISTATE = AISTATE },
-- rtus -- rtus
rtu_list = {}, rtu_list = {}, ---@type unit_session[][]
redstone = {}, redstone = {}, ---@type unit_session[]
boilers = {}, boilers = {}, ---@type unit_session[]
turbines = {}, turbines = {}, ---@type unit_session[]
tanks = {}, tanks = {}, ---@type unit_session[]
snas = {}, snas = {}, ---@type unit_session[]
envd = {}, envd = {}, ---@type unit_session[]
-- redstone control -- redstone control
io_ctl = nil, ---@type rs_controller io_ctl = nil, ---@type rs_controller
valves = {}, ---@type unit_valves valves = {}, ---@type unit_valves
@ -100,7 +100,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
auto_was_alarmed = false, auto_was_alarmed = false,
ramp_target_br100 = 0, ramp_target_br100 = 0,
-- state tracking -- state tracking
deltas = {}, deltas = {}, ---@type { last_t: number, last_v: number, dt: number }[]
last_heartbeat = 0, last_heartbeat = 0,
last_radiation = 0, last_radiation = 0,
damage_decreasing = false, damage_decreasing = false,
@ -113,7 +113,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
-- logic for alarms -- logic for alarms
had_reactor = false, had_reactor = false,
turbine_flow_stable = false, turbine_flow_stable = false,
turbine_stability_data = {}, turbine_stability_data = {}, ---@type { time_state: integer, time_tanks: integer, rotation: number, input_rate: integer }[]
last_rate_change_ms = 0, last_rate_change_ms = 0,
---@type rps_status ---@type rps_status
last_rps_trips = { last_rps_trips = {
@ -211,15 +211,15 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
SteamFeedMismatch = false, SteamFeedMismatch = false,
MaxWaterReturnFeed = false, MaxWaterReturnFeed = false,
-- boilers -- boilers
BoilerOnline = {}, BoilerOnline = {}, ---@type boolean[]
HeatingRateLow = {}, HeatingRateLow = {}, ---@type boolean[]
WaterLevelLow = {}, WaterLevelLow = {}, ---@type boolean[]
-- turbines -- turbines
TurbineOnline = {}, TurbineOnline = {}, ---@type boolean[]
SteamDumpOpen = {}, SteamDumpOpen = {}, ---@type integer[]
TurbineOverSpeed = {}, TurbineOverSpeed = {}, ---@type boolean[]
GeneratorTrip = {}, GeneratorTrip = {}, ---@type boolean[]
TurbineTrip = {} TurbineTrip = {} ---@type boolean[]
}, },
---@class alarms ---@class alarms
alarm_states = { alarm_states = {
@ -324,7 +324,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
end end
for i = 1, #self.boilers do for i = 1, #self.boilers do
local boiler = self.boilers[i] ---@type unit_session local boiler = self.boilers[i]
local db = boiler.get_db() ---@type boilerv_session_db local db = boiler.get_db() ---@type boilerv_session_db
local last_update_s = db.tanks.last_update / 1000.0 local last_update_s = db.tanks.last_update / 1000.0
@ -336,7 +336,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
end end
for i = 1, #self.turbines do for i = 1, #self.turbines do
local turbine = self.turbines[i] ---@type unit_session local turbine = self.turbines[i]
local db = turbine.get_db() ---@type turbinev_session_db local db = turbine.get_db() ---@type turbinev_session_db
local last_update_s = db.tanks.last_update / 1000.0 local last_update_s = db.tanks.last_update / 1000.0
@ -553,7 +553,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
-- check boilers formed/faulted -- check boilers formed/faulted
for i = 1, #self.boilers do for i = 1, #self.boilers do
local sess = self.boilers[i] ---@type unit_session local sess = self.boilers[i]
local boiler = sess.get_db() ---@type boilerv_session_db local boiler = sess.get_db() ---@type boilerv_session_db
if sess.is_faulted() or not boiler.formed then if sess.is_faulted() or not boiler.formed then
self.db.control.degraded = true self.db.control.degraded = true
@ -562,7 +562,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
-- check turbines formed/faulted -- check turbines formed/faulted
for i = 1, #self.turbines do for i = 1, #self.turbines do
local sess = self.turbines[i] ---@type unit_session local sess = self.turbines[i]
local turbine = sess.get_db() ---@type turbinev_session_db local turbine = sess.get_db() ---@type turbinev_session_db
if sess.is_faulted() or not turbine.formed then if sess.is_faulted() or not turbine.formed then
self.db.control.degraded = true self.db.control.degraded = true
@ -881,7 +881,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
if all or (filter == RTU_UNIT_TYPE.BOILER_VALVE) then if all or (filter == RTU_UNIT_TYPE.BOILER_VALVE) then
build.boilers = {} build.boilers = {}
for i = 1, #self.boilers do for i = 1, #self.boilers do
local boiler = self.boilers[i] ---@type unit_session local boiler = self.boilers[i]
build.boilers[boiler.get_device_idx()] = { boiler.get_db().formed, boiler.get_db().build } build.boilers[boiler.get_device_idx()] = { boiler.get_db().formed, boiler.get_db().build }
end end
end end
@ -889,7 +889,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
if all or (filter == RTU_UNIT_TYPE.TURBINE_VALVE) then if all or (filter == RTU_UNIT_TYPE.TURBINE_VALVE) then
build.turbines = {} build.turbines = {}
for i = 1, #self.turbines do for i = 1, #self.turbines do
local turbine = self.turbines[i] ---@type unit_session local turbine = self.turbines[i]
build.turbines[turbine.get_device_idx()] = { turbine.get_db().formed, turbine.get_db().build } build.turbines[turbine.get_device_idx()] = { turbine.get_db().formed, turbine.get_db().build }
end end
end end
@ -897,7 +897,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
if all or (filter == RTU_UNIT_TYPE.DYNAMIC_VALVE) then if all or (filter == RTU_UNIT_TYPE.DYNAMIC_VALVE) then
build.tanks = {} build.tanks = {}
for i = 1, #self.tanks do for i = 1, #self.tanks do
local tank = self.tanks[i] ---@type unit_session local tank = self.tanks[i]
build.tanks[tank.get_device_idx()] = { tank.get_db().formed, tank.get_db().build } build.tanks[tank.get_device_idx()] = { tank.get_db().formed, tank.get_db().build }
end end
end end
@ -927,19 +927,20 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
-- check which RTUs are connected -- check which RTUs are connected
---@nodiscard ---@nodiscard
function public.check_rtu_conns() function public.check_rtu_conns()
---@class unit_connections
local conns = {} local conns = {}
conns.boilers = {} conns.boilers = {} ---@type boolean[]
for i = 1, #self.boilers do for i = 1, #self.boilers do
conns.boilers[self.boilers[i].get_device_idx()] = true conns.boilers[self.boilers[i].get_device_idx()] = true
end end
conns.turbines = {} conns.turbines = {} ---@type boolean[]
for i = 1, #self.turbines do for i = 1, #self.turbines do
conns.turbines[self.turbines[i].get_device_idx()] = true conns.turbines[self.turbines[i].get_device_idx()] = true
end end
conns.tanks = {} conns.tanks = {} ---@type boolean[]
for i = 1, #self.tanks do for i = 1, #self.tanks do
conns.tanks[self.tanks[i].get_device_idx()] = true conns.tanks[self.tanks[i].get_device_idx()] = true
end end
@ -955,7 +956,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
-- status of boilers (including tanks) -- status of boilers (including tanks)
status.boilers = {} status.boilers = {}
for i = 1, #self.boilers do for i = 1, #self.boilers do
local boiler = self.boilers[i] ---@type unit_session local boiler = self.boilers[i]
local db = boiler.get_db() ---@type boilerv_session_db local db = boiler.get_db() ---@type boilerv_session_db
status.boilers[boiler.get_device_idx()] = { boiler.is_faulted(), db.formed, db.state, db.tanks } status.boilers[boiler.get_device_idx()] = { boiler.is_faulted(), db.formed, db.state, db.tanks }
end end
@ -963,7 +964,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
-- status of turbines (including tanks) -- status of turbines (including tanks)
status.turbines = {} status.turbines = {}
for i = 1, #self.turbines do for i = 1, #self.turbines do
local turbine = self.turbines[i] ---@type unit_session local turbine = self.turbines[i]
local db = turbine.get_db() ---@type turbinev_session_db local db = turbine.get_db() ---@type turbinev_session_db
status.turbines[turbine.get_device_idx()] = { turbine.is_faulted(), db.formed, db.state, db.tanks } status.turbines[turbine.get_device_idx()] = { turbine.is_faulted(), db.formed, db.state, db.tanks }
end end
@ -971,7 +972,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
-- status of dynamic tanks -- status of dynamic tanks
status.tanks = {} status.tanks = {}
for i = 1, #self.tanks do for i = 1, #self.tanks do
local tank = self.tanks[i] ---@type unit_session local tank = self.tanks[i]
local db = tank.get_db() ---@type dynamicv_session_db local db = tank.get_db() ---@type dynamicv_session_db
status.tanks[tank.get_device_idx()] = { tank.is_faulted(), db.formed, db.state, db.tanks } status.tanks[tank.get_device_idx()] = { tank.is_faulted(), db.formed, db.state, db.tanks }
end end
@ -989,7 +990,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
-- radiation monitors (environment detectors) -- radiation monitors (environment detectors)
status.envds = {} 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]
local db = envd.get_db() ---@type envd_session_db local db = envd.get_db() ---@type envd_session_db
status.envds[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

View File

@ -161,7 +161,7 @@ function logic.update_annunciator(self)
local max_rad, any_faulted = 0, false local max_rad, any_faulted = 0, false
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]
local db = envd.get_db() ---@type envd_session_db local db = envd.get_db() ---@type envd_session_db
any_faulted = any_faulted or envd.is_faulted() any_faulted = any_faulted or envd.is_faulted()
if db.radiation_raw > max_rad then max_rad = db.radiation_raw end if db.radiation_raw > max_rad then max_rad = db.radiation_raw end
@ -197,7 +197,7 @@ function logic.update_annunciator(self)
if num_boilers > 0 then if num_boilers > 0 then
-- go through boilers for stats and online -- go through boilers for stats and online
for i = 1, #self.boilers do for i = 1, #self.boilers do
local session = self.boilers[i] ---@type unit_session local session = self.boilers[i]
local boiler = session.get_db() ---@type boilerv_session_db local boiler = session.get_db() ---@type boilerv_session_db
local idx = session.get_device_idx() local idx = session.get_device_idx()
@ -225,7 +225,7 @@ function logic.update_annunciator(self)
-- check for inactive boilers while reactor is active -- check for inactive boilers while reactor is active
for i = 1, #self.boilers do for i = 1, #self.boilers do
local boiler = self.boilers[i] ---@type unit_session local boiler = self.boilers[i]
local idx = boiler.get_device_idx() local idx = boiler.get_device_idx()
local db = boiler.get_db() ---@type boilerv_session_db local db = boiler.get_db() ---@type boilerv_session_db
@ -250,7 +250,7 @@ function logic.update_annunciator(self)
if num_boilers > 0 then if num_boilers > 0 then
for i = 1, #self.boilers do for i = 1, #self.boilers do
local boiler = self.boilers[i] ---@type unit_session local boiler = self.boilers[i]
local idx = boiler.get_device_idx() local idx = boiler.get_device_idx()
local db = boiler.get_db() ---@type boilerv_session_db local db = boiler.get_db() ---@type boilerv_session_db
@ -294,7 +294,7 @@ function logic.update_annunciator(self)
-- go through turbines for stats and online -- go through turbines for stats and online
for i = 1, #self.turbines do for i = 1, #self.turbines do
local session = self.turbines[i] ---@type unit_session local session = self.turbines[i]
local turbine = session.get_db() ---@type turbinev_session_db local turbine = session.get_db() ---@type turbinev_session_db
local idx = session.get_device_idx() local idx = session.get_device_idx()
@ -380,7 +380,7 @@ function logic.update_annunciator(self)
-- turbine safety checks -- turbine safety checks
for i = 1, #self.turbines do for i = 1, #self.turbines do
local turbine = self.turbines[i] ---@type unit_session local turbine = self.turbines[i]
local db = turbine.get_db() ---@type turbinev_session_db local db = turbine.get_db() ---@type turbinev_session_db
local idx = turbine.get_device_idx() local idx = turbine.get_device_idx()
@ -904,7 +904,7 @@ function logic.handle_redstone(self)
if not cache.rps_trip then if not cache.rps_trip then
-- set turbines to not dump steam -- set turbines to not dump steam
for i = 1, #self.turbines do for i = 1, #self.turbines do
local session = self.turbines[i] ---@type unit_session local session = self.turbines[i]
local turbine = session.get_db() ---@type turbinev_session_db local turbine = session.get_db() ---@type turbinev_session_db
if turbine.state.dumping_mode ~= DUMPING_MODE.IDLE then if turbine.state.dumping_mode ~= DUMPING_MODE.IDLE then
@ -921,7 +921,7 @@ function logic.handle_redstone(self)
elseif enable_emer_cool or self.emcool_opened then elseif enable_emer_cool or self.emcool_opened then
-- set turbines to dump excess steam -- set turbines to dump excess steam
for i = 1, #self.turbines do for i = 1, #self.turbines do
local session = self.turbines[i] ---@type unit_session local session = self.turbines[i]
local turbine = session.get_db() ---@type turbinev_session_db local turbine = session.get_db() ---@type turbinev_session_db
if turbine.state.dumping_mode ~= DUMPING_MODE.DUMPING_EXCESS then if turbine.state.dumping_mode ~= DUMPING_MODE.DUMPING_EXCESS then
@ -931,7 +931,7 @@ function logic.handle_redstone(self)
-- make sure dynamic tanks are allowing outflow -- make sure dynamic tanks are allowing outflow
for i = 1, #self.tanks do for i = 1, #self.tanks do
local session = self.tanks[i] ---@type unit_session local session = self.tanks[i]
local tank = session.get_db() ---@type dynamicv_session_db local tank = session.get_db() ---@type dynamicv_session_db
if tank.state.container_mode == CONTAINER_MODE.FILL then if tank.state.container_mode == CONTAINER_MODE.FILL then