#97 fixed issue where traffic on other channels gets processed if channels are left open

This commit is contained in:
Mikayla Fischler
2022-09-22 20:42:06 -04:00
parent a87e557d2d
commit 50be7f9ca2
8 changed files with 50 additions and 59 deletions

View File

@@ -175,16 +175,19 @@ function rtu.comms(version, modem, local_port, server_port, conn_watchdog)
conn_watchdog = conn_watchdog
}
-- configure modem channels
local function _conf_channels()
self.modem.closeAll()
self.modem.open(self.l_port)
end
_conf_channels()
---@class rtu_comms
local public = {}
local insert = table.insert
-- open modem
if not self.modem.isOpen(self.l_port) then
self.modem.open(self.l_port)
end
-- PRIVATE FUNCTIONS --
-- send a scada management packet
@@ -223,11 +226,7 @@ function rtu.comms(version, modem, local_port, server_port, conn_watchdog)
---@diagnostic disable-next-line: redefined-local
function public.reconnect_modem(modem)
self.modem = modem
-- open modem
if not self.modem.isOpen(self.l_port) then
self.modem.open(self.l_port)
end
_conf_channels()
end
-- unlink from the server
@@ -312,7 +311,7 @@ function rtu.comms(version, modem, local_port, server_port, conn_watchdog)
---@param units table
---@param rtu_state rtu_state
function public.handle_packet(packet, units, rtu_state)
if packet ~= nil then
if packet ~= nil and packet.scada_frame.local_port() == self.l_port then
-- check sequence number
if self.r_seq_num == nil then
self.r_seq_num = packet.scada_frame.seq_num()