mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2025-07-26 03:22:51 +00:00
@ -65,7 +65,7 @@ function types.new_zero_coordinate() return { x = 0, y = 0, z = 0 } end
|
||||
---@field type RTU_UNIT_TYPE
|
||||
---@field index integer|false
|
||||
---@field reactor integer
|
||||
---@field rsio table|nil
|
||||
---@field rsio IO_PORT[]|nil
|
||||
|
||||
--#endregion
|
||||
|
||||
|
@ -54,13 +54,13 @@ function facility.new(config)
|
||||
fac_tank_list = {} ---@type integer[]
|
||||
},
|
||||
-- rtus
|
||||
rtu_conn_count = 0,
|
||||
rtu_gw_conn_count = 0,
|
||||
rtu_list = {}, ---@type unit_session[][]
|
||||
redstone = {}, ---@type unit_session[]
|
||||
induction = {}, ---@type unit_session[]
|
||||
sps = {}, ---@type unit_session[]
|
||||
tanks = {}, ---@type unit_session[]
|
||||
envd = {}, ---@type unit_session[]
|
||||
redstone = {}, ---@type redstone_session[]
|
||||
induction = {}, ---@type imatrix_session[]
|
||||
sps = {}, ---@type sps_session[]
|
||||
tanks = {}, ---@type dynamicv_session[]
|
||||
envd = {}, ---@type envd_session[]
|
||||
-- redstone I/O control
|
||||
io_ctl = nil, ---@type rs_controller
|
||||
-- process control
|
||||
@ -509,7 +509,7 @@ function facility.new(config)
|
||||
-- attempt to set a test tone state
|
||||
---@param id TONE|0 tone ID or 0 to disable all
|
||||
---@param state boolean state
|
||||
---@return boolean allow_testing, table test_tone_states
|
||||
---@return boolean allow_testing, { [TONE]: boolean } test_tone_states
|
||||
function public.diag_set_test_tone(id, state)
|
||||
if self.allow_testing then
|
||||
self.test_tone_set = true
|
||||
@ -528,7 +528,7 @@ function facility.new(config)
|
||||
-- attempt to set a test alarm state
|
||||
---@param id ALARM|0 alarm ID or 0 to disable all
|
||||
---@param state boolean state
|
||||
---@return boolean allow_testing, table test_alarm_states
|
||||
---@return boolean allow_testing, { [ALARM]: boolean } test_alarm_states
|
||||
function public.diag_set_test_alarm(id, state)
|
||||
if self.allow_testing then
|
||||
self.test_tone_set = true
|
||||
@ -633,7 +633,7 @@ function facility.new(config)
|
||||
local status = {}
|
||||
|
||||
-- total count of all connected RTUs in the facility
|
||||
status.count = self.rtu_conn_count
|
||||
status.count = self.rtu_gw_conn_count
|
||||
|
||||
-- power averages from induction matricies
|
||||
status.power = {
|
||||
@ -647,7 +647,7 @@ function facility.new(config)
|
||||
status.induction = {}
|
||||
for i = 1, #self.induction do
|
||||
local matrix = self.induction[i]
|
||||
local db = matrix.get_db() ---@type imatrix_session_db
|
||||
local db = matrix.get_db()
|
||||
|
||||
status.induction[i] = { matrix.is_faulted(), db.formed, db.state, db.tanks }
|
||||
|
||||
@ -660,7 +660,7 @@ function facility.new(config)
|
||||
status.sps = {}
|
||||
for i = 1, #self.sps do
|
||||
local sps = self.sps[i]
|
||||
local db = sps.get_db() ---@type sps_session_db
|
||||
local db = sps.get_db()
|
||||
status.sps[i] = { sps.is_faulted(), db.formed, db.state, db.tanks }
|
||||
end
|
||||
|
||||
@ -668,7 +668,7 @@ function facility.new(config)
|
||||
status.tanks = {}
|
||||
for i = 1, #self.tanks do
|
||||
local tank = self.tanks[i]
|
||||
local db = tank.get_db() ---@type dynamicv_session_db
|
||||
local db = tank.get_db()
|
||||
status.tanks[tank.get_device_idx()] = { tank.is_faulted(), db.formed, db.state, db.tanks }
|
||||
end
|
||||
|
||||
@ -676,7 +676,7 @@ function facility.new(config)
|
||||
status.envds = {}
|
||||
for i = 1, #self.envd do
|
||||
local envd = self.envd[i]
|
||||
local db = envd.get_db() ---@type envd_session_db
|
||||
local db = envd.get_db()
|
||||
status.envds[envd.get_device_idx()] = { envd.is_faulted(), db.radiation, db.radiation_raw }
|
||||
end
|
||||
|
||||
@ -685,9 +685,9 @@ function facility.new(config)
|
||||
|
||||
--#endregion
|
||||
|
||||
-- supervisor sessions reporting the list of active RTU sessions
|
||||
---@param rtu_sessions table session list of all connected RTUs
|
||||
function public.report_rtus(rtu_sessions) self.rtu_conn_count = #rtu_sessions end
|
||||
-- supervisor sessions reporting the list of active RTU gateway sessions
|
||||
---@param sessions rtu_session_struct[] session list of all connected RTU gateways
|
||||
function public.report_rtu_gateways(sessions) self.rtu_gw_conn_count = #sessions end
|
||||
|
||||
-- get the facility cooling configuration
|
||||
function public.get_cooling_conf() return self.cooling_conf end
|
||||
|
@ -150,7 +150,7 @@ function update.pre_auto()
|
||||
-- calculate moving averages for induction matrix
|
||||
if self.induction[1] ~= nil then
|
||||
local matrix = self.induction[1]
|
||||
local db = matrix.get_db() ---@type imatrix_session_db
|
||||
local db = matrix.get_db()
|
||||
|
||||
local build_update = db.build.last_update
|
||||
rate_update = db.state.last_update
|
||||
@ -512,7 +512,7 @@ function update.auto_safety()
|
||||
local astatus = self.ascram_status
|
||||
|
||||
if self.induction[1] ~= nil then
|
||||
local db = self.induction[1].get_db() ---@type imatrix_session_db
|
||||
local db = self.induction[1].get_db()
|
||||
|
||||
-- clear matrix disconnected
|
||||
if astatus.matrix_dc then
|
||||
@ -545,7 +545,7 @@ function update.auto_safety()
|
||||
|
||||
for i = 1, #self.envd do
|
||||
local envd = self.envd[i]
|
||||
local e_db = envd.get_db() ---@type envd_session_db
|
||||
local e_db = envd.get_db()
|
||||
if e_db.radiation_raw > max_rad then max_rad = e_db.radiation_raw end
|
||||
end
|
||||
|
||||
@ -756,7 +756,7 @@ function update.redstone(ack_all)
|
||||
|
||||
-- update induction matrix related outputs
|
||||
if self.induction[1] ~= nil then
|
||||
local db = self.induction[1].get_db() ---@type imatrix_session_db
|
||||
local db = self.induction[1].get_db()
|
||||
|
||||
self.io_ctl.digital_write(IO.F_MATRIX_LOW, db.tanks.energy_fill < const.RS_THRESHOLDS.IMATRIX_CHARGE_LOW)
|
||||
self.io_ctl.digital_write(IO.F_MATRIX_HIGH, db.tanks.energy_fill > const.RS_THRESHOLDS.IMATRIX_CHARGE_HIGH)
|
||||
@ -791,7 +791,7 @@ function update.unit_mgmt()
|
||||
self.current_waste_product = self.waste_product
|
||||
|
||||
if (not self.sps_low_power) and (self.waste_product == WASTE.ANTI_MATTER) and (self.induction[1] ~= nil) then
|
||||
local db = self.induction[1].get_db() ---@type imatrix_session_db
|
||||
local db = self.induction[1].get_db()
|
||||
|
||||
if db.tanks.energy_fill >= 0.15 then
|
||||
self.disabled_sps = false
|
||||
@ -813,7 +813,7 @@ function update.unit_mgmt()
|
||||
if need_emcool then
|
||||
for i = 1, #self.tanks do
|
||||
local session = self.tanks[i]
|
||||
local tank = session.get_db() ---@type dynamicv_session_db
|
||||
local tank = session.get_db()
|
||||
|
||||
if tank.state.container_mode == CONTAINER_MODE.FILL then
|
||||
session.get_cmd_queue().push_data(DTV_RTU_S_DATA.SET_CONT_MODE, CONTAINER_MODE.BOTH)
|
||||
|
@ -8,7 +8,7 @@ local rsctl = {}
|
||||
|
||||
-- create a new redstone RTU I/O controller
|
||||
---@nodiscard
|
||||
---@param redstone_rtus table redstone RTU sessions
|
||||
---@param redstone_rtus redstone_session[] redstone RTU sessions
|
||||
function rsctl.new(redstone_rtus)
|
||||
---@class rs_controller
|
||||
local public = {}
|
||||
@ -18,8 +18,7 @@ function rsctl.new(redstone_rtus)
|
||||
---@return boolean
|
||||
function public.is_connected(port)
|
||||
for i = 1, #redstone_rtus do
|
||||
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
|
||||
if db.io[port] ~= nil then return true end
|
||||
if redstone_rtus[i].get_db().io[port] ~= nil then return true end
|
||||
end
|
||||
|
||||
return false
|
||||
@ -30,8 +29,7 @@ function rsctl.new(redstone_rtus)
|
||||
---@param value boolean
|
||||
function public.digital_write(port, value)
|
||||
for i = 1, #redstone_rtus do
|
||||
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
|
||||
local io = db.io[port] ---@type rs_db_dig_io|nil
|
||||
local io = redstone_rtus[i].get_db().io[port]
|
||||
if io ~= nil then io.write(value) end
|
||||
end
|
||||
end
|
||||
@ -42,8 +40,9 @@ function rsctl.new(redstone_rtus)
|
||||
---@return boolean|nil
|
||||
function public.digital_read(port)
|
||||
for i = 1, #redstone_rtus do
|
||||
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
|
||||
local io = db.io[port] ---@type rs_db_dig_io|nil
|
||||
local io = redstone_rtus[i].get_db().io[port]
|
||||
-- this would only be digital, so it would only return boolean or nil
|
||||
---@diagnostic disable-next-line: return-type-mismatch
|
||||
if io ~= nil then return io.read() end
|
||||
end
|
||||
end
|
||||
@ -55,8 +54,7 @@ function rsctl.new(redstone_rtus)
|
||||
---@param max number maximum value for scaling 0 to 15
|
||||
function public.analog_write(port, value, min, max)
|
||||
for i = 1, #redstone_rtus do
|
||||
local db = redstone_rtus[i].get_db() ---@type redstone_session_db
|
||||
local io = db.io[port] ---@type rs_db_ana_io|nil
|
||||
local io = redstone_rtus[i].get_db().io[port]
|
||||
if io ~= nil then io.write(rsio.analog_write(value, min, max)) end
|
||||
end
|
||||
end
|
||||
|
@ -99,6 +99,7 @@ function boilerv.new(session_id, unit_id, advert, out_queue)
|
||||
}
|
||||
}
|
||||
|
||||
---@class boilerv_session:unit_session
|
||||
local public = self.session.get()
|
||||
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
@ -94,6 +94,7 @@ function dynamicv.new(session_id, unit_id, advert, out_queue)
|
||||
}
|
||||
}
|
||||
|
||||
---@class dynamicv_session:unit_session
|
||||
local public = self.session.get()
|
||||
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
@ -52,6 +52,7 @@ function envd.new(session_id, unit_id, advert, out_queue)
|
||||
}
|
||||
}
|
||||
|
||||
---@class envd_session:unit_session
|
||||
local public = self.session.get()
|
||||
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
@ -83,6 +83,7 @@ function imatrix.new(session_id, unit_id, advert, out_queue)
|
||||
}
|
||||
}
|
||||
|
||||
---@class imatrix_session:unit_session
|
||||
local public = self.session.get()
|
||||
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
@ -39,9 +39,13 @@ local PERIODICS = {
|
||||
OUTPUT_SYNC = 200
|
||||
}
|
||||
|
||||
---@class phy_entry
|
||||
---@field phy IO_LVL
|
||||
---@field req IO_LVL
|
||||
---@class dig_phy_entry
|
||||
---@field phy IO_LVL actual value
|
||||
---@field req IO_LVL commanded value
|
||||
|
||||
---@class ana_phy_entry
|
||||
---@field phy number actual value
|
||||
---@field req number commanded value
|
||||
|
||||
-- create a new redstone rtu session runner
|
||||
---@nodiscard
|
||||
@ -72,27 +76,29 @@ function redstone.new(session_id, unit_id, advert, out_queue)
|
||||
},
|
||||
---@class rs_io_list
|
||||
io_list = {
|
||||
digital_in = {}, -- discrete inputs
|
||||
digital_out = {}, -- coils
|
||||
analog_in = {}, -- input registers
|
||||
analog_out = {} -- holding registers
|
||||
digital_in = {}, ---@type IO_PORT[] discrete inputs
|
||||
digital_out = {}, ---@type IO_PORT[] coils
|
||||
analog_in = {}, ---@type IO_PORT[] input registers
|
||||
analog_out = {} ---@type IO_PORT[] holding registers
|
||||
},
|
||||
phy_trans = { coils = -1, hold_regs = -1 },
|
||||
-- last set/read ports (reflecting the current state of the RTU)
|
||||
---@class rs_io_states
|
||||
phy_io = {
|
||||
digital_in = {}, -- discrete inputs
|
||||
digital_out = {}, -- coils
|
||||
analog_in = {}, -- input registers
|
||||
analog_out = {} -- holding registers
|
||||
digital_in = {}, ---@type dig_phy_entry[] discrete inputs
|
||||
digital_out = {}, ---@type dig_phy_entry[] coils
|
||||
analog_in = {}, ---@type ana_phy_entry[] input registers
|
||||
analog_out = {} ---@type ana_phy_entry[] holding registers
|
||||
},
|
||||
---@class redstone_session_db
|
||||
db = {
|
||||
-- read/write functions for connected I/O
|
||||
---@type (rs_db_dig_io|rs_db_ana_io)[]
|
||||
io = {}
|
||||
}
|
||||
}
|
||||
|
||||
---@class redstone_session:unit_session
|
||||
local public = self.session.get()
|
||||
|
||||
-- INITIALIZE --
|
||||
|
@ -74,6 +74,7 @@ function sna.new(session_id, unit_id, advert, out_queue)
|
||||
}
|
||||
}
|
||||
|
||||
---@class sna_session:unit_session
|
||||
local public = self.session.get()
|
||||
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
@ -88,6 +88,7 @@ function sps.new(session_id, unit_id, advert, out_queue)
|
||||
}
|
||||
}
|
||||
|
||||
---@class sps_session:unit_session
|
||||
local public = self.session.get()
|
||||
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
@ -109,6 +109,7 @@ function turbinev.new(session_id, unit_id, advert, out_queue)
|
||||
}
|
||||
}
|
||||
|
||||
---@class turbinev_session:unit_session
|
||||
local public = self.session.get()
|
||||
|
||||
-- PRIVATE FUNCTIONS --
|
||||
|
@ -29,7 +29,7 @@ unit_session.RTU_US_DATA = RTU_US_DATA
|
||||
---@param advert rtu_advertisement RTU advertisement for this unit
|
||||
---@param out_queue mqueue send queue
|
||||
---@param log_tag string logging tag
|
||||
---@param txn_tags table transaction log tags
|
||||
---@param txn_tags string[] transaction log tags
|
||||
function unit_session.new(session_id, unit_id, advert, out_queue, log_tag, txn_tags)
|
||||
local self = {
|
||||
device_index = advert.index,
|
||||
@ -52,7 +52,7 @@ function unit_session.new(session_id, unit_id, advert, out_queue, log_tag, txn_t
|
||||
-- send a MODBUS message, creating a transaction in the process
|
||||
---@param txn_type integer transaction type
|
||||
---@param f_code MODBUS_FCODE function code
|
||||
---@param register_param table register range or register and values
|
||||
---@param register_param (number|string)[] register range or register and values
|
||||
---@return integer txn_id transaction ID of this transaction
|
||||
function protected.send_request(txn_type, f_code, register_param)
|
||||
local m_pkt = comms.modbus_packet()
|
||||
|
@ -287,7 +287,7 @@ end
|
||||
|
||||
-- on attempted link of an RTU to a facility or unit object, verify its ID and report a problem if it can't be accepted
|
||||
---@param unit unit_session RTU session
|
||||
---@param list table table of RTU sessions
|
||||
---@param list unit_session[] table of RTU sessions
|
||||
---@param max integer max of this type of RTU
|
||||
---@return RTU_ID_FAIL fail_code, string fail_str
|
||||
function svsessions.check_rtu_id(unit, list, max)
|
||||
@ -647,8 +647,8 @@ function svsessions.iterate_all()
|
||||
-- iterate sessions
|
||||
for _, list in pairs(self.sessions) do _iterate(list) end
|
||||
|
||||
-- report RTU sessions to facility
|
||||
self.facility.report_rtus(self.sessions.rtu)
|
||||
-- report RTU gateway sessions to facility
|
||||
self.facility.report_rtu_gateways(self.sessions.rtu)
|
||||
|
||||
-- iterate facility
|
||||
self.facility.update()
|
||||
|
@ -82,12 +82,12 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
types = { DT_KEYS = DT_KEYS, AISTATE = AISTATE },
|
||||
-- rtus
|
||||
rtu_list = {}, ---@type unit_session[][]
|
||||
redstone = {}, ---@type unit_session[]
|
||||
boilers = {}, ---@type unit_session[]
|
||||
turbines = {}, ---@type unit_session[]
|
||||
tanks = {}, ---@type unit_session[]
|
||||
snas = {}, ---@type unit_session[]
|
||||
envd = {}, ---@type unit_session[]
|
||||
redstone = {}, ---@type redstone_session[]
|
||||
boilers = {}, ---@type boilerv_session[]
|
||||
turbines = {}, ---@type turbinev_session[]
|
||||
tanks = {}, ---@type dynamicv_session[]
|
||||
snas = {}, ---@type sna_session[]
|
||||
envd = {}, ---@type envd_session[]
|
||||
-- redstone control
|
||||
io_ctl = nil, ---@type rs_controller
|
||||
valves = {}, ---@type unit_valves
|
||||
@ -154,7 +154,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
waste = 0,
|
||||
high_temp_lim = 1150
|
||||
},
|
||||
---@class alarm_monitors
|
||||
---@type { [string]: alarm_def }
|
||||
alarms = {
|
||||
-- reactor lost under the condition of meltdown imminent
|
||||
ContainmentBreach = { state = AISTATE.INACTIVE, trip_time = 0, hold_time = 0, id = ALARM.ContainmentBreach, tier = PRIO.CRITICAL },
|
||||
@ -221,7 +221,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
GeneratorTrip = {}, ---@type boolean[]
|
||||
TurbineTrip = {} ---@type boolean[]
|
||||
},
|
||||
---@class alarms
|
||||
---@type { [ALARM]: ALARM_STATE }
|
||||
alarm_states = {
|
||||
ALARM_STATE.INACTIVE,
|
||||
ALARM_STATE.INACTIVE,
|
||||
@ -325,7 +325,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
|
||||
for i = 1, #self.boilers do
|
||||
local boiler = self.boilers[i]
|
||||
local db = boiler.get_db() ---@type boilerv_session_db
|
||||
local db = boiler.get_db()
|
||||
|
||||
local last_update_s = db.tanks.last_update / 1000.0
|
||||
|
||||
@ -337,7 +337,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
|
||||
for i = 1, #self.turbines do
|
||||
local turbine = self.turbines[i]
|
||||
local db = turbine.get_db() ---@type turbinev_session_db
|
||||
local db = turbine.get_db()
|
||||
|
||||
local last_update_s = db.tanks.last_update / 1000.0
|
||||
|
||||
@ -554,7 +554,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
-- check boilers formed/faulted
|
||||
for i = 1, #self.boilers do
|
||||
local sess = self.boilers[i]
|
||||
local boiler = sess.get_db() ---@type boilerv_session_db
|
||||
local boiler = sess.get_db()
|
||||
if sess.is_faulted() or not boiler.formed then
|
||||
self.db.control.degraded = true
|
||||
end
|
||||
@ -563,7 +563,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
-- check turbines formed/faulted
|
||||
for i = 1, #self.turbines do
|
||||
local sess = self.turbines[i]
|
||||
local turbine = sess.get_db() ---@type turbinev_session_db
|
||||
local turbine = sess.get_db()
|
||||
if sess.is_faulted() or not turbine.formed then
|
||||
self.db.control.degraded = true
|
||||
end
|
||||
@ -928,19 +928,22 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
---@nodiscard
|
||||
function public.check_rtu_conns()
|
||||
---@class unit_connections
|
||||
---@field boilers boolean[]
|
||||
---@field turbines boolean[]
|
||||
---@field tanks boolean[]
|
||||
local conns = {}
|
||||
|
||||
conns.boilers = {} ---@type boolean[]
|
||||
conns.boilers = {}
|
||||
for i = 1, #self.boilers do
|
||||
conns.boilers[self.boilers[i].get_device_idx()] = true
|
||||
end
|
||||
|
||||
conns.turbines = {} ---@type boolean[]
|
||||
conns.turbines = {}
|
||||
for i = 1, #self.turbines do
|
||||
conns.turbines[self.turbines[i].get_device_idx()] = true
|
||||
end
|
||||
|
||||
conns.tanks = {} ---@type boolean[]
|
||||
conns.tanks = {}
|
||||
for i = 1, #self.tanks do
|
||||
conns.tanks[self.tanks[i].get_device_idx()] = true
|
||||
end
|
||||
@ -957,7 +960,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
status.boilers = {}
|
||||
for i = 1, #self.boilers do
|
||||
local boiler = self.boilers[i]
|
||||
local db = boiler.get_db() ---@type boilerv_session_db
|
||||
local db = boiler.get_db()
|
||||
status.boilers[boiler.get_device_idx()] = { boiler.is_faulted(), db.formed, db.state, db.tanks }
|
||||
end
|
||||
|
||||
@ -965,7 +968,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
status.turbines = {}
|
||||
for i = 1, #self.turbines do
|
||||
local turbine = self.turbines[i]
|
||||
local db = turbine.get_db() ---@type turbinev_session_db
|
||||
local db = turbine.get_db()
|
||||
status.turbines[turbine.get_device_idx()] = { turbine.is_faulted(), db.formed, db.state, db.tanks }
|
||||
end
|
||||
|
||||
@ -973,14 +976,14 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
status.tanks = {}
|
||||
for i = 1, #self.tanks do
|
||||
local tank = self.tanks[i]
|
||||
local db = tank.get_db() ---@type dynamicv_session_db
|
||||
local db = tank.get_db()
|
||||
status.tanks[tank.get_device_idx()] = { tank.is_faulted(), db.formed, db.state, db.tanks }
|
||||
end
|
||||
|
||||
-- SNA statistical information
|
||||
local total_peak, total_avail, total_out = 0, 0, 0
|
||||
for i = 1, #self.snas do
|
||||
local db = self.snas[i].get_db() ---@type sna_session_db
|
||||
local db = self.snas[i].get_db()
|
||||
total_peak = total_peak + db.state.peak_production
|
||||
total_avail = total_avail + db.state.production_rate
|
||||
total_out = total_out + math.min(db.tanks.input.amount / 10, db.state.production_rate)
|
||||
@ -991,7 +994,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
status.envds = {}
|
||||
for i = 1, #self.envd do
|
||||
local envd = self.envd[i]
|
||||
local db = envd.get_db() ---@type envd_session_db
|
||||
local db = envd.get_db()
|
||||
status.envds[envd.get_device_idx()] = { envd.is_faulted(), db.radiation, db.radiation_raw }
|
||||
end
|
||||
|
||||
@ -1005,7 +1008,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle)
|
||||
local total_avail_rate = 0
|
||||
|
||||
for i = 1, #self.snas do
|
||||
local db = self.snas[i].get_db() ---@type sna_session_db
|
||||
local db = self.snas[i].get_db()
|
||||
total_avail_rate = total_avail_rate + db.state.production_rate
|
||||
end
|
||||
|
||||
|
@ -162,7 +162,7 @@ function logic.update_annunciator(self)
|
||||
|
||||
for i = 1, #self.envd do
|
||||
local envd = self.envd[i]
|
||||
local db = envd.get_db() ---@type envd_session_db
|
||||
local db = envd.get_db()
|
||||
any_faulted = any_faulted or envd.is_faulted()
|
||||
if db.radiation_raw > max_rad then max_rad = db.radiation_raw end
|
||||
end
|
||||
@ -173,8 +173,7 @@ function logic.update_annunciator(self)
|
||||
annunc.EmergencyCoolant = 1
|
||||
|
||||
for i = 1, #self.redstone do
|
||||
local db = self.redstone[i].get_db() ---@type redstone_session_db
|
||||
local io = db.io[IO.U_EMER_COOL] ---@type rs_db_dig_io|nil
|
||||
local io = self.redstone[i].get_db().io[IO.U_EMER_COOL]
|
||||
if io ~= nil then
|
||||
annunc.EmergencyCoolant = util.trinary(io.read(), 3, 2)
|
||||
break
|
||||
@ -198,7 +197,7 @@ function logic.update_annunciator(self)
|
||||
-- go through boilers for stats and online
|
||||
for i = 1, #self.boilers do
|
||||
local session = self.boilers[i]
|
||||
local boiler = session.get_db() ---@type boilerv_session_db
|
||||
local boiler = session.get_db()
|
||||
local idx = session.get_device_idx()
|
||||
|
||||
annunc.RCSFault = annunc.RCSFault or (not boiler.formed) or session.is_faulted()
|
||||
@ -227,7 +226,7 @@ function logic.update_annunciator(self)
|
||||
for i = 1, #self.boilers do
|
||||
local boiler = self.boilers[i]
|
||||
local idx = boiler.get_device_idx()
|
||||
local db = boiler.get_db() ---@type boilerv_session_db
|
||||
local db = boiler.get_db()
|
||||
|
||||
if r_db.mek_status.status then
|
||||
annunc.HeatingRateLow[idx] = db.state.boil_rate == 0
|
||||
@ -252,7 +251,7 @@ function logic.update_annunciator(self)
|
||||
for i = 1, #self.boilers do
|
||||
local boiler = self.boilers[i]
|
||||
local idx = boiler.get_device_idx()
|
||||
local db = boiler.get_db() ---@type boilerv_session_db
|
||||
local db = boiler.get_db()
|
||||
|
||||
local gaining_hc = _get_dt(DT_KEYS.BoilerHCool .. idx) > 10.0 or db.tanks.hcool_fill == 1
|
||||
|
||||
@ -295,7 +294,7 @@ function logic.update_annunciator(self)
|
||||
-- go through turbines for stats and online
|
||||
for i = 1, #self.turbines do
|
||||
local session = self.turbines[i]
|
||||
local turbine = session.get_db() ---@type turbinev_session_db
|
||||
local turbine = session.get_db()
|
||||
local idx = session.get_device_idx()
|
||||
|
||||
annunc.RCSFault = annunc.RCSFault or (not turbine.formed) or session.is_faulted()
|
||||
@ -381,7 +380,7 @@ function logic.update_annunciator(self)
|
||||
-- turbine safety checks
|
||||
for i = 1, #self.turbines do
|
||||
local turbine = self.turbines[i]
|
||||
local db = turbine.get_db() ---@type turbinev_session_db
|
||||
local db = turbine.get_db()
|
||||
local idx = turbine.get_device_idx()
|
||||
|
||||
-- check if steam dumps are open
|
||||
@ -652,7 +651,7 @@ function logic.update_status_text(self)
|
||||
|
||||
-- check if an alarm is active (tripped or ack'd)
|
||||
---@nodiscard
|
||||
---@param alarm table alarm entry
|
||||
---@param alarm alarm_def alarm entry
|
||||
---@return boolean active
|
||||
local function is_active(alarm)
|
||||
return alarm.state == AISTATE.TRIPPED or alarm.state == AISTATE.ACKED
|
||||
@ -818,7 +817,7 @@ function logic.handle_redstone(self)
|
||||
|
||||
-- check if an alarm is active (tripped or ack'd)
|
||||
---@nodiscard
|
||||
---@param alarm table alarm entry
|
||||
---@param alarm alarm_def alarm entry
|
||||
---@return boolean active
|
||||
local function is_active(alarm)
|
||||
return alarm.state == AISTATE.TRIPPED or alarm.state == AISTATE.ACKED
|
||||
@ -905,7 +904,7 @@ function logic.handle_redstone(self)
|
||||
-- set turbines to not dump steam
|
||||
for i = 1, #self.turbines do
|
||||
local session = self.turbines[i]
|
||||
local turbine = session.get_db() ---@type turbinev_session_db
|
||||
local turbine = session.get_db()
|
||||
|
||||
if turbine.state.dumping_mode ~= DUMPING_MODE.IDLE then
|
||||
session.get_cmd_queue().push_data(TBV_RTU_S_DATA.SET_DUMP_MODE, DUMPING_MODE.IDLE)
|
||||
@ -922,7 +921,7 @@ function logic.handle_redstone(self)
|
||||
-- set turbines to dump excess steam
|
||||
for i = 1, #self.turbines do
|
||||
local session = self.turbines[i]
|
||||
local turbine = session.get_db() ---@type turbinev_session_db
|
||||
local turbine = session.get_db()
|
||||
|
||||
if turbine.state.dumping_mode ~= DUMPING_MODE.DUMPING_EXCESS then
|
||||
session.get_cmd_queue().push_data(TBV_RTU_S_DATA.SET_DUMP_MODE, DUMPING_MODE.DUMPING_EXCESS)
|
||||
@ -932,7 +931,7 @@ function logic.handle_redstone(self)
|
||||
-- make sure dynamic tanks are allowing outflow
|
||||
for i = 1, #self.tanks do
|
||||
local session = self.tanks[i]
|
||||
local tank = session.get_db() ---@type dynamicv_session_db
|
||||
local tank = session.get_db()
|
||||
|
||||
if tank.state.container_mode == CONTAINER_MODE.FILL then
|
||||
session.get_cmd_queue().push_data(DTV_RTU_S_DATA.SET_CONT_MODE, CONTAINER_MODE.BOTH)
|
||||
|
Reference in New Issue
Block a user