mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#55 correctly use device IDs vs unit IDs
This commit is contained in:
parent
cc856d4d80
commit
790571b6fc
@ -88,17 +88,17 @@ rtu.new_session = function (id, in_queue, out_queue, advertisement)
|
||||
|
||||
-- create unit by type
|
||||
if u_type == RTU_UNIT_TYPES.REDSTONE then
|
||||
unit, rs_in_q = svrs_redstone.new(self.id, unit_advert, self.out_q)
|
||||
unit, rs_in_q = svrs_redstone.new(self.id, i, unit_advert, self.out_q)
|
||||
elseif u_type == RTU_UNIT_TYPES.BOILER then
|
||||
unit = svrs_boiler.new(self.id, unit_advert, self.out_q)
|
||||
unit = svrs_boiler.new(self.id, i, unit_advert, self.out_q)
|
||||
elseif u_type == RTU_UNIT_TYPES.BOILER_VALVE then
|
||||
-- @todo Mekanism 10.1+
|
||||
elseif u_type == RTU_UNIT_TYPES.TURBINE then
|
||||
unit = svrs_turbine.new(self.id, unit_advert, self.out_q)
|
||||
unit = svrs_turbine.new(self.id, i, unit_advert, self.out_q)
|
||||
elseif u_type == RTU_UNIT_TYPES.TURBINE_VALVE then
|
||||
-- @todo Mekanism 10.1+
|
||||
elseif u_type == RTU_UNIT_TYPES.EMACHINE then
|
||||
unit = svrs_emachine.new(self.id, unit_advert, self.out_q)
|
||||
unit = svrs_emachine.new(self.id, i, unit_advert, self.out_q)
|
||||
elseif u_type == RTU_UNIT_TYPES.IMATRIX then
|
||||
-- @todo Mekanism 10.1+
|
||||
else
|
||||
|
@ -29,9 +29,10 @@ local PERIODICS = {
|
||||
|
||||
-- create a new boiler rtu session runner
|
||||
---@param session_id integer
|
||||
---@param unit_id integer
|
||||
---@param advert rtu_advertisement
|
||||
---@param out_queue mqueue
|
||||
boiler.new = function (session_id, advert, out_queue)
|
||||
boiler.new = function (session_id, unit_id, advert, out_queue)
|
||||
-- type check
|
||||
if advert.type ~= RTU_UNIT_TYPES.BOILER then
|
||||
log.error("attempt to instantiate boiler RTU for type '" .. advert.type .. "'. this is a bug.")
|
||||
@ -41,7 +42,7 @@ boiler.new = function (session_id, advert, out_queue)
|
||||
local log_tag = "session.rtu(" .. session_id .. ").boiler(" .. advert.index .. "): "
|
||||
|
||||
local self = {
|
||||
session = unit_session.new(log_tag, advert, out_queue, TXN_TAGS),
|
||||
session = unit_session.new(unit_id, advert, out_queue, log_tag, TXN_TAGS),
|
||||
has_build = false,
|
||||
periodics = {
|
||||
next_build_req = 0,
|
||||
|
@ -26,9 +26,10 @@ local PERIODICS = {
|
||||
|
||||
-- create a new energy machine rtu session runner
|
||||
---@param session_id integer
|
||||
---@param unit_id integer
|
||||
---@param advert rtu_advertisement
|
||||
---@param out_queue mqueue
|
||||
emachine.new = function (session_id, advert, out_queue)
|
||||
emachine.new = function (session_id, unit_id, advert, out_queue)
|
||||
-- type check
|
||||
if advert.type ~= RTU_UNIT_TYPES.EMACHINE then
|
||||
log.error("attempt to instantiate emachine RTU for type '" .. advert.type .. "'. this is a bug.")
|
||||
@ -38,7 +39,7 @@ emachine.new = function (session_id, advert, out_queue)
|
||||
local log_tag = "session.rtu(" .. session_id .. ").emachine(" .. advert.index .. "): "
|
||||
|
||||
local self = {
|
||||
session = unit_session.new(log_tag, advert, out_queue, TXN_TAGS),
|
||||
session = unit_session.new(unit_id, advert, out_queue, log_tag, TXN_TAGS),
|
||||
has_build = false,
|
||||
periodics = {
|
||||
next_build_req = 0,
|
||||
|
@ -47,19 +47,21 @@ local PERIODICS = {
|
||||
|
||||
-- create a new redstone rtu session runner
|
||||
---@param session_id integer
|
||||
---@param unit_id integer
|
||||
---@param advert rtu_advertisement
|
||||
---@param out_queue mqueue
|
||||
redstone.new = function (session_id, advert, out_queue)
|
||||
redstone.new = function (session_id, unit_id, advert, out_queue)
|
||||
-- type check
|
||||
if advert.type ~= RTU_UNIT_TYPES.REDSTONE then
|
||||
log.error("attempt to instantiate redstone RTU for type '" .. advert.type .. "'. this is a bug.")
|
||||
return nil
|
||||
end
|
||||
|
||||
local log_tag = "session.rtu(" .. session_id .. ").redstone(" .. advert.index .. "): "
|
||||
-- for redstone, use unit ID not device index
|
||||
local log_tag = "session.rtu(" .. session_id .. ").redstone(" .. unit_id .. "): "
|
||||
|
||||
local self = {
|
||||
session = unit_session.new(log_tag, advert, out_queue, TXN_TAGS),
|
||||
session = unit_session.new(unit_id, advert, out_queue, log_tag, TXN_TAGS),
|
||||
has_di = false,
|
||||
has_ai = false,
|
||||
periodics = {
|
||||
|
@ -30,9 +30,10 @@ local PERIODICS = {
|
||||
|
||||
-- create a new turbine rtu session runner
|
||||
---@param session_id integer
|
||||
---@param unit_id integer
|
||||
---@param advert rtu_advertisement
|
||||
---@param out_queue mqueue
|
||||
turbine.new = function (session_id, advert, out_queue)
|
||||
turbine.new = function (session_id, unit_id, advert, out_queue)
|
||||
-- type check
|
||||
if advert.type ~= RTU_UNIT_TYPES.TURBINE then
|
||||
log.error("attempt to instantiate turbine RTU for type '" .. advert.type .. "'. this is a bug.")
|
||||
@ -42,7 +43,7 @@ turbine.new = function (session_id, advert, out_queue)
|
||||
local log_tag = "session.rtu(" .. session_id .. ").turbine(" .. advert.index .. "): "
|
||||
|
||||
local self = {
|
||||
session = unit_session.new(log_tag, advert, out_queue, TXN_TAGS),
|
||||
session = unit_session.new(unit_id, advert, out_queue, log_tag, TXN_TAGS),
|
||||
has_build = false,
|
||||
periodics = {
|
||||
next_build_req = 0,
|
||||
|
@ -11,15 +11,17 @@ local MODBUS_FCODE = types.MODBUS_FCODE
|
||||
local MODBUS_EXCODE = types.MODBUS_EXCODE
|
||||
|
||||
-- create a new unit session runner
|
||||
---@param log_tag string
|
||||
---@param advert rtu_advertisement
|
||||
---@param out_queue mqueue
|
||||
---@param txn_tags table
|
||||
unit_session.new = function (log_tag, advert, out_queue, txn_tags)
|
||||
---@param unit_id integer MODBUS unit ID
|
||||
---@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
|
||||
unit_session.new = function (unit_id, advert, out_queue, log_tag, txn_tags)
|
||||
local self = {
|
||||
log_tag = log_tag,
|
||||
txn_tags = txn_tags,
|
||||
uid = advert.index,
|
||||
unit_id = unit_id,
|
||||
device_index = advert.index,
|
||||
reactor = advert.reactor,
|
||||
out_q = out_queue,
|
||||
transaction_controller = txnctrl.new(),
|
||||
@ -43,7 +45,7 @@ unit_session.new = function (log_tag, advert, out_queue, txn_tags)
|
||||
local m_pkt = comms.modbus_packet()
|
||||
local txn_id = self.transaction_controller.create(txn_type)
|
||||
|
||||
m_pkt.make(txn_id, self.uid, f_code, register_param)
|
||||
m_pkt.make(txn_id, self.unit_id, f_code, register_param)
|
||||
|
||||
self.out_q.push_packet(m_pkt)
|
||||
end
|
||||
@ -53,7 +55,7 @@ unit_session.new = function (log_tag, advert, out_queue, txn_tags)
|
||||
---@return integer|false txn_type transaction type or false on error/busy
|
||||
protected.try_resolve = function (m_pkt)
|
||||
if m_pkt.scada_frame.protocol() == PROTOCOLS.MODBUS_TCP then
|
||||
if m_pkt.unit_id == self.uid then
|
||||
if m_pkt.unit_id == self.unit_id then
|
||||
local txn_type = self.transaction_controller.resolve(m_pkt.txn_id)
|
||||
local txn_tag = " (" .. self.txn_tags[txn_type] .. ")"
|
||||
|
||||
@ -115,7 +117,9 @@ unit_session.new = function (log_tag, advert, out_queue, txn_tags)
|
||||
-- PUBLIC FUNCTIONS --
|
||||
|
||||
-- get the unit ID
|
||||
public.get_uid = function () return self.uid end
|
||||
public.get_unit_id = function () return self.unit_id end
|
||||
-- get the device index
|
||||
public.get_device_idx = function () return self.device_index end
|
||||
-- get the reactor ID
|
||||
public.get_reactor = function () return self.reactor end
|
||||
|
||||
@ -126,6 +130,22 @@ unit_session.new = function (log_tag, advert, out_queue, txn_tags)
|
||||
-- check if this unit is faulted
|
||||
public.is_faulted = function () return self.device_fail end
|
||||
|
||||
-- PUBLIC TEMPLATE FUNCTIONS --
|
||||
|
||||
-- handle a packet
|
||||
---@param m_pkt modbus_frame
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
public.handle_packet = function (m_pkt)
|
||||
log.debug("template unit_session.handle_packet() called", true)
|
||||
end
|
||||
|
||||
-- update this runner
|
||||
---@param time_now integer milliseconds
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
public.update = function (time_now)
|
||||
log.debug("template unit_session.update() called", true)
|
||||
end
|
||||
|
||||
return protected
|
||||
end
|
||||
|
||||
|
@ -13,7 +13,7 @@ local svsessions = require("supervisor.session.svsessions")
|
||||
local config = require("supervisor.config")
|
||||
local supervisor = require("supervisor.supervisor")
|
||||
|
||||
local SUPERVISOR_VERSION = "alpha-v0.3.8"
|
||||
local SUPERVISOR_VERSION = "alpha-v0.3.9"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
|
Loading…
Reference in New Issue
Block a user