mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
function for duplicate session search code
This commit is contained in:
@ -106,6 +106,17 @@ local function _free_closed(sessions)
|
|||||||
util.filter_table(sessions, f, on_delete)
|
util.filter_table(sessions, f, on_delete)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- find a session by remote port
|
||||||
|
---@param list table
|
||||||
|
---@param port integer
|
||||||
|
---@return plc_session_struct|rtu_session_struct|nil
|
||||||
|
local function _find_session(list, port)
|
||||||
|
for i = 1, #list do
|
||||||
|
if list[i].r_port == port then return list[i] end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
-- PUBLIC FUNCTIONS --
|
-- PUBLIC FUNCTIONS --
|
||||||
|
|
||||||
-- link the modem
|
-- link the modem
|
||||||
@ -119,13 +130,7 @@ end
|
|||||||
---@return rtu_session_struct|nil
|
---@return rtu_session_struct|nil
|
||||||
svsessions.find_rtu_session = function (remote_port)
|
svsessions.find_rtu_session = function (remote_port)
|
||||||
-- check RTU sessions
|
-- check RTU sessions
|
||||||
for i = 1, #self.rtu_sessions do
|
return _find_session(self.rtu_sessions, remote_port)
|
||||||
if self.rtu_sessions[i].r_port == remote_port then
|
|
||||||
return self.rtu_sessions[i]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- find a PLC session by the remote port
|
-- find a PLC session by the remote port
|
||||||
@ -133,13 +138,7 @@ end
|
|||||||
---@return plc_session_struct|nil
|
---@return plc_session_struct|nil
|
||||||
svsessions.find_plc_session = function (remote_port)
|
svsessions.find_plc_session = function (remote_port)
|
||||||
-- check PLC sessions
|
-- check PLC sessions
|
||||||
for i = 1, #self.plc_sessions do
|
return _find_session(self.plc_sessions, remote_port)
|
||||||
if self.plc_sessions[i].r_port == remote_port then
|
|
||||||
return self.plc_sessions[i]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- find a PLC/RTU session by the remote port
|
-- find a PLC/RTU session by the remote port
|
||||||
@ -147,20 +146,12 @@ end
|
|||||||
---@return plc_session_struct|rtu_session_struct|nil
|
---@return plc_session_struct|rtu_session_struct|nil
|
||||||
svsessions.find_device_session = function (remote_port)
|
svsessions.find_device_session = function (remote_port)
|
||||||
-- check RTU sessions
|
-- check RTU sessions
|
||||||
for i = 1, #self.rtu_sessions do
|
local s = _find_session(self.rtu_sessions, remote_port)
|
||||||
if self.rtu_sessions[i].r_port == remote_port then
|
|
||||||
return self.rtu_sessions[i]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check PLC sessions
|
-- check PLC sessions
|
||||||
for i = 1, #self.plc_sessions do
|
if s == nil then s = _find_session(self.plc_sessions, remote_port) end
|
||||||
if self.plc_sessions[i].r_port == remote_port then
|
|
||||||
return self.plc_sessions[i]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
-- find a coordinator session by the remote port
|
-- find a coordinator session by the remote port
|
||||||
@ -168,13 +159,7 @@ end
|
|||||||
---@return nil
|
---@return nil
|
||||||
svsessions.find_coord_session = function (remote_port)
|
svsessions.find_coord_session = function (remote_port)
|
||||||
-- check coordinator sessions
|
-- check coordinator sessions
|
||||||
for i = 1, #self.coord_sessions do
|
return _find_session(self.coord_sessions, remote_port)
|
||||||
if self.coord_sessions[i].r_port == remote_port then
|
|
||||||
return self.coord_sessions[i]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get a session by reactor ID
|
-- get a session by reactor ID
|
||||||
|
Reference in New Issue
Block a user