@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user