@@ -288,6 +288,16 @@ function rtu.new_session(id, in_queue, out_queue, advertisement, facility_units)
|
||||
-- handle advertisement; this will re-create all unit sub-sessions
|
||||
self.advert = pkt.data
|
||||
_handle_advertisement()
|
||||
elseif pkt.type == SCADA_MGMT_TYPES.RTU_DEV_REMOUNT then
|
||||
if pkt.length == 1 then
|
||||
local unit_id = pkt[1]
|
||||
if self.units[unit_id] ~= nil then
|
||||
local unit = self.units[unit_id] ---@type unit_session
|
||||
unit.invalidate_cache()
|
||||
end
|
||||
else
|
||||
log.debug(log_header .. "SCADA RTU device re-mount packet length mismatch")
|
||||
end
|
||||
else
|
||||
log.debug(log_header .. "handler received unsupported SCADA_MGMT packet type " .. pkt.type)
|
||||
end
|
||||
|
||||
@@ -159,6 +159,8 @@ function boilerv.new(session_id, unit_id, advert, out_queue)
|
||||
self.db.build.max_boil_rate = m_pkt.data[12]
|
||||
self.db.build.env_loss = m_pkt.data[13]
|
||||
self.has_build = true
|
||||
|
||||
out_queue.push_command(unit_session.RTU_US_CMDS.BUILD_CHANGED)
|
||||
else
|
||||
log.debug(log_tag .. "MODBUS transaction reply length mismatch (" .. TXN_TAGS[txn_type] .. ")")
|
||||
end
|
||||
@@ -227,6 +229,13 @@ function boilerv.new(session_id, unit_id, advert, out_queue)
|
||||
self.session.post_update()
|
||||
end
|
||||
|
||||
-- invalidate build cache
|
||||
function public.invalidate_cache()
|
||||
self.periodics.next_formed_req = 0
|
||||
self.periodics.next_build_req = 0
|
||||
self.has_build = false
|
||||
end
|
||||
|
||||
-- get the unit session database
|
||||
function public.get_db() return self.db end
|
||||
|
||||
|
||||
@@ -94,6 +94,11 @@ function envd.new(session_id, unit_id, advert, out_queue)
|
||||
self.session.post_update()
|
||||
end
|
||||
|
||||
-- invalidate build cache
|
||||
function public.invalidate_cache()
|
||||
-- no build cache for this device
|
||||
end
|
||||
|
||||
-- get the unit session database
|
||||
function public.get_db() return self.db end
|
||||
|
||||
|
||||
@@ -142,6 +142,8 @@ function imatrix.new(session_id, unit_id, advert, out_queue)
|
||||
self.db.build.cells = m_pkt.data[8]
|
||||
self.db.build.providers = m_pkt.data[9]
|
||||
self.has_build = true
|
||||
|
||||
out_queue.push_command(unit_session.RTU_US_CMDS.BUILD_CHANGED)
|
||||
else
|
||||
log.debug(log_tag .. "MODBUS transaction reply length mismatch (" .. TXN_TAGS[txn_type] .. ")")
|
||||
end
|
||||
@@ -201,6 +203,13 @@ function imatrix.new(session_id, unit_id, advert, out_queue)
|
||||
self.session.post_update()
|
||||
end
|
||||
|
||||
-- invalidate build cache
|
||||
function public.invalidate_cache()
|
||||
self.periodics.next_formed_req = 0
|
||||
self.periodics.next_build_req = 0
|
||||
self.has_build = false
|
||||
end
|
||||
|
||||
-- get the unit session database
|
||||
function public.get_db() return self.db end
|
||||
|
||||
|
||||
@@ -254,6 +254,11 @@ function redstone.new(session_id, unit_id, advert, out_queue)
|
||||
self.session.post_update()
|
||||
end
|
||||
|
||||
-- invalidate build cache
|
||||
function public.invalidate_cache()
|
||||
-- no build cache for this device
|
||||
end
|
||||
|
||||
-- get the unit session database
|
||||
function public.get_db() return self.db end
|
||||
|
||||
|
||||
@@ -112,6 +112,8 @@ function sna.new(session_id, unit_id, advert, out_queue)
|
||||
self.db.build.input_cap = m_pkt.data[1]
|
||||
self.db.build.output_cap = m_pkt.data[2]
|
||||
self.has_build = true
|
||||
|
||||
out_queue.push_command(unit_session.RTU_US_CMDS.BUILD_CHANGED)
|
||||
else
|
||||
log.debug(log_tag .. "MODBUS transaction reply length mismatch (" .. TXN_TAGS[txn_type] .. ")")
|
||||
end
|
||||
@@ -167,6 +169,12 @@ function sna.new(session_id, unit_id, advert, out_queue)
|
||||
self.session.post_update()
|
||||
end
|
||||
|
||||
-- invalidate build cache
|
||||
function public.invalidate_cache()
|
||||
self.periodics.next_build_req = 0
|
||||
self.has_build = false
|
||||
end
|
||||
|
||||
-- get the unit session database
|
||||
function public.get_db() return self.db end
|
||||
|
||||
|
||||
@@ -147,6 +147,8 @@ function sps.new(session_id, unit_id, advert, out_queue)
|
||||
self.db.build.output_cap = m_pkt.data[8]
|
||||
self.db.build.max_energy = m_pkt.data[9]
|
||||
self.has_build = true
|
||||
|
||||
out_queue.push_command(unit_session.RTU_US_CMDS.BUILD_CHANGED)
|
||||
else
|
||||
log.debug(log_tag .. "MODBUS transaction reply length mismatch (" .. TXN_TAGS[txn_type] .. ")")
|
||||
end
|
||||
@@ -211,6 +213,13 @@ function sps.new(session_id, unit_id, advert, out_queue)
|
||||
self.session.post_update()
|
||||
end
|
||||
|
||||
-- invalidate build cache
|
||||
function public.invalidate_cache()
|
||||
self.periodics.next_formed_req = 0
|
||||
self.periodics.next_build_req = 0
|
||||
self.has_build = false
|
||||
end
|
||||
|
||||
-- get the unit session database
|
||||
function public.get_db() return self.db end
|
||||
|
||||
|
||||
@@ -198,6 +198,8 @@ function turbinev.new(session_id, unit_id, advert, out_queue)
|
||||
self.db.build.max_production = m_pkt.data[14]
|
||||
self.db.build.max_water_output = m_pkt.data[15]
|
||||
self.has_build = true
|
||||
|
||||
out_queue.push_command(unit_session.RTU_US_CMDS.BUILD_CHANGED)
|
||||
else
|
||||
log.debug(log_tag .. "MODBUS transaction reply length mismatch (" .. TXN_TAGS[txn_type] .. ")")
|
||||
end
|
||||
@@ -301,6 +303,13 @@ function turbinev.new(session_id, unit_id, advert, out_queue)
|
||||
self.session.post_update()
|
||||
end
|
||||
|
||||
-- invalidate build cache
|
||||
function public.invalidate_cache()
|
||||
self.periodics.next_formed_req = 0
|
||||
self.periodics.next_build_req = 0
|
||||
self.has_build = false
|
||||
end
|
||||
|
||||
-- get the unit session database
|
||||
function public.get_db() return self.db end
|
||||
|
||||
|
||||
@@ -11,6 +11,16 @@ local PROTOCOLS = comms.PROTOCOLS
|
||||
local MODBUS_FCODE = types.MODBUS_FCODE
|
||||
local MODBUS_EXCODE = types.MODBUS_EXCODE
|
||||
|
||||
local RTU_US_CMDS = {
|
||||
BUILD_CHANGED = 1
|
||||
}
|
||||
|
||||
local RTU_US_DATA = {
|
||||
}
|
||||
|
||||
unit_session.RTU_US_CMDS = RTU_US_CMDS
|
||||
unit_session.RTU_US_DATA = RTU_US_DATA
|
||||
|
||||
-- create a new unit session runner
|
||||
---@param unit_id integer MODBUS unit ID
|
||||
---@param advert rtu_advertisement RTU advertisement for this unit
|
||||
@@ -152,6 +162,11 @@ function unit_session.new(unit_id, advert, out_queue, log_tag, txn_tags)
|
||||
log.debug("template unit_session.update() called", true)
|
||||
end
|
||||
|
||||
-- invalidate build cache
|
||||
function public.invalidate_cache()
|
||||
log.debug("template unit_session.invalidate_cache() called", true)
|
||||
end
|
||||
|
||||
-- get the unit session database
|
||||
function public.get_db() return {} end
|
||||
|
||||
|
||||
@@ -429,13 +429,13 @@ function unit.new(for_reactor, num_boilers, num_turbines)
|
||||
build.boilers = {}
|
||||
for i = 1, #self.boilers do
|
||||
local boiler = self.boilers[i] ---@type unit_session
|
||||
build.boilers[boiler.get_device_idx()] = { boiler.get_db().build, boiler.get_db().formed }
|
||||
build.boilers[boiler.get_device_idx()] = { boiler.get_db().formed, boiler.get_db().build }
|
||||
end
|
||||
|
||||
build.turbines = {}
|
||||
for i = 1, #self.turbines do
|
||||
local turbine = self.turbines[i] ---@type unit_session
|
||||
build.turbines[turbine.get_device_idx()] = { turbine.get_db().build, turbine.get_db().formed }
|
||||
build.turbines[turbine.get_device_idx()] = { turbine.get_db().formed, turbine.get_db().build }
|
||||
end
|
||||
|
||||
return build
|
||||
@@ -461,14 +461,24 @@ function unit.new(for_reactor, num_boilers, num_turbines)
|
||||
status.boilers = {}
|
||||
for i = 1, #self.boilers do
|
||||
local boiler = self.boilers[i] ---@type unit_session
|
||||
status.boilers[boiler.get_device_idx()] = { boiler.get_db().state, boiler.get_db().tanks }
|
||||
status.boilers[boiler.get_device_idx()] = {
|
||||
boiler.is_faulted(),
|
||||
boiler.get_db().formed,
|
||||
boiler.get_db().state,
|
||||
boiler.get_db().tanks
|
||||
}
|
||||
end
|
||||
|
||||
-- status of turbines (including tanks)
|
||||
status.turbines = {}
|
||||
for i = 1, #self.turbines do
|
||||
local turbine = self.turbines[i] ---@type unit_session
|
||||
status.turbines[turbine.get_device_idx()] = { turbine.get_db().state, turbine.get_db().tanks }
|
||||
status.turbines[turbine.get_device_idx()] = {
|
||||
turbine.is_faulted(),
|
||||
turbine.get_db().formed,
|
||||
turbine.get_db().state,
|
||||
turbine.get_db().tanks
|
||||
}
|
||||
end
|
||||
|
||||
---@todo other RTU statuses
|
||||
|
||||
Reference in New Issue
Block a user