mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
optimized session lookup
This commit is contained in:
parent
bf0e92d6e4
commit
72da718015
@ -125,10 +125,38 @@ svsessions.link_modem = function (modem)
|
|||||||
self.modem = modem
|
self.modem = modem
|
||||||
end
|
end
|
||||||
|
|
||||||
-- find a session by the remote port
|
-- find an RTU session by the remote port
|
||||||
|
---@param remote_port integer
|
||||||
|
---@return rtu_session_struct|nil
|
||||||
|
svsessions.find_rtu_session = function (remote_port)
|
||||||
|
-- check RTU sessions
|
||||||
|
for i = 1, #self.rtu_sessions do
|
||||||
|
if self.rtu_sessions[i].r_port == remote_port then
|
||||||
|
return self.rtu_sessions[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- find a PLC session by the remote port
|
||||||
|
---@param remote_port integer
|
||||||
|
---@return plc_session_struct|nil
|
||||||
|
svsessions.find_plc_session = function (remote_port)
|
||||||
|
-- check PLC sessions
|
||||||
|
for i = 1, #self.plc_sessions do
|
||||||
|
if self.plc_sessions[i].r_port == remote_port then
|
||||||
|
return self.plc_sessions[i]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- find a PLC/RTU session by the remote port
|
||||||
---@param remote_port integer
|
---@param remote_port integer
|
||||||
---@return plc_session_struct|rtu_session_struct|nil
|
---@return plc_session_struct|rtu_session_struct|nil
|
||||||
svsessions.find_session = function (remote_port)
|
svsessions.find_device_session = function (remote_port)
|
||||||
-- check RTU sessions
|
-- check RTU sessions
|
||||||
for i = 1, #self.rtu_sessions do
|
for i = 1, #self.rtu_sessions do
|
||||||
if self.rtu_sessions[i].r_port == remote_port then
|
if self.rtu_sessions[i].r_port == remote_port then
|
||||||
@ -143,6 +171,13 @@ svsessions.find_session = function (remote_port)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- find a coordinator session by the remote port
|
||||||
|
---@param remote_port integer
|
||||||
|
---@return nil
|
||||||
|
svsessions.find_coord_session = function (remote_port)
|
||||||
-- check coordinator sessions
|
-- check coordinator sessions
|
||||||
for i = 1, #self.coord_sessions do
|
for i = 1, #self.coord_sessions do
|
||||||
if self.coord_sessions[i].r_port == remote_port then
|
if self.coord_sessions[i].r_port == remote_port then
|
||||||
@ -155,7 +190,7 @@ end
|
|||||||
|
|
||||||
-- get a session by reactor ID
|
-- get a session by reactor ID
|
||||||
---@param reactor integer
|
---@param reactor integer
|
||||||
---@return plc_session_struct session
|
---@return plc_session_struct|nil session
|
||||||
svsessions.get_reactor_session = function (reactor)
|
svsessions.get_reactor_session = function (reactor)
|
||||||
local session = nil
|
local session = nil
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ local svsessions = require("supervisor.session.svsessions")
|
|||||||
local config = require("supervisor.config")
|
local config = require("supervisor.config")
|
||||||
local supervisor = require("supervisor.supervisor")
|
local supervisor = require("supervisor.supervisor")
|
||||||
|
|
||||||
local SUPERVISOR_VERSION = "alpha-v0.3.6"
|
local SUPERVISOR_VERSION = "alpha-v0.3.7"
|
||||||
|
|
||||||
local print = util.print
|
local print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
|
@ -149,10 +149,10 @@ supervisor.comms = function (num_reactors, modem, dev_listen, coord_listen)
|
|||||||
|
|
||||||
-- device (RTU/PLC) listening channel
|
-- device (RTU/PLC) listening channel
|
||||||
if l_port == self.dev_listen then
|
if l_port == self.dev_listen then
|
||||||
-- look for an associated session
|
|
||||||
local session = svsessions.find_session(r_port)
|
|
||||||
|
|
||||||
if protocol == PROTOCOLS.MODBUS_TCP then
|
if protocol == PROTOCOLS.MODBUS_TCP then
|
||||||
|
-- look for an associated session
|
||||||
|
local session = svsessions.find_rtu_session(r_port)
|
||||||
|
|
||||||
-- MODBUS response
|
-- MODBUS response
|
||||||
if session ~= nil then
|
if session ~= nil then
|
||||||
-- pass the packet onto the session handler
|
-- pass the packet onto the session handler
|
||||||
@ -162,6 +162,9 @@ supervisor.comms = function (num_reactors, modem, dev_listen, coord_listen)
|
|||||||
log.debug("discarding MODBUS_TCP packet without a known session")
|
log.debug("discarding MODBUS_TCP packet without a known session")
|
||||||
end
|
end
|
||||||
elseif protocol == PROTOCOLS.RPLC then
|
elseif protocol == PROTOCOLS.RPLC then
|
||||||
|
-- look for an associated session
|
||||||
|
local session = svsessions.find_plc_session(r_port)
|
||||||
|
|
||||||
-- reactor PLC packet
|
-- reactor PLC packet
|
||||||
if session ~= nil then
|
if session ~= nil then
|
||||||
if packet.type == RPLC_TYPES.LINK_REQ then
|
if packet.type == RPLC_TYPES.LINK_REQ then
|
||||||
@ -200,6 +203,9 @@ supervisor.comms = function (num_reactors, modem, dev_listen, coord_listen)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif protocol == PROTOCOLS.SCADA_MGMT then
|
elseif protocol == PROTOCOLS.SCADA_MGMT then
|
||||||
|
-- look for an associated session
|
||||||
|
local session = svsessions.find_device_session(r_port)
|
||||||
|
|
||||||
-- SCADA management packet
|
-- SCADA management packet
|
||||||
if session ~= nil then
|
if session ~= nil then
|
||||||
-- pass the packet onto the session handler
|
-- pass the packet onto the session handler
|
||||||
@ -222,6 +228,9 @@ supervisor.comms = function (num_reactors, modem, dev_listen, coord_listen)
|
|||||||
end
|
end
|
||||||
-- coordinator listening channel
|
-- coordinator listening channel
|
||||||
elseif l_port == self.coord_listen then
|
elseif l_port == self.coord_listen then
|
||||||
|
-- look for an associated session
|
||||||
|
local session = svsessions.find_coord_session(r_port)
|
||||||
|
|
||||||
if protocol == PROTOCOLS.SCADA_MGMT then
|
if protocol == PROTOCOLS.SCADA_MGMT then
|
||||||
-- SCADA management packet
|
-- SCADA management packet
|
||||||
elseif protocol == PROTOCOLS.COORD_DATA then
|
elseif protocol == PROTOCOLS.COORD_DATA then
|
||||||
|
Loading…
Reference in New Issue
Block a user