#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

@ -202,19 +202,14 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
-- PRIVATE FUNCTIONS --
-- open all channels
local function _open_channels()
if not self.modem.isOpen(sv_listen) then
self.modem.open(sv_listen)
end
if not self.modem.isOpen(api_listen) then
self.modem.open(api_listen)
end
-- configure modem channels
local function _conf_channels()
self.modem.closeAll()
self.modem.open(sv_listen)
self.modem.open(api_listen)
end
-- open at construct time
_open_channels()
_conf_channels()
-- send a packet to the supervisor
---@param msg_type SCADA_MGMT_TYPES|SCADA_CRDN_TYPES
@ -256,7 +251,7 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
---@diagnostic disable-next-line: redefined-local
function public.reconnect_modem(modem)
self.modem = modem
_open_channels()
_conf_channels()
end
-- close the connection to the server
@ -364,11 +359,16 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
function public.handle_packet(packet)
if packet ~= nil then
local protocol = packet.scada_frame.protocol()
local l_port = packet.scada_frame.local_port()
if protocol == PROTOCOLS.COORD_API then
if l_port == api_listen then
if protocol == PROTOCOLS.COORD_API then
---@diagnostic disable-next-line: param-type-mismatch
apisessions.handle_packet(packet)
else
apisessions.handle_packet(packet)
else
log.debug("illegal packet type " .. protocol .. " on api listening channel", true)
end
elseif l_port == sv_listen then
-- check sequence number
if self.sv_r_seq_num == nil then
self.sv_r_seq_num = packet.scada_frame.seq_num()
@ -456,9 +456,10 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
log.warning("received unknown SCADA_MGMT packet type " .. packet.type)
end
else
-- should be unreachable assuming packet is from parse_packet()
log.error("illegal packet type " .. protocol, true)
log.debug("illegal packet type " .. protocol .. " on supervisor listening channel", true)
end
else
log.debug("received packet on unconfigured channel " .. l_port, true)
end
end
end

View File

@ -16,7 +16,7 @@ local config = require("coordinator.config")
local coordinator = require("coordinator.coordinator")
local renderer = require("coordinator.renderer")
local COORDINATOR_VERSION = "alpha-v0.4.13"
local COORDINATOR_VERSION = "alpha-v0.4.14"
local print = util.print
local println = util.println

View File

@ -303,14 +303,17 @@ function plc.comms(id, version, modem, local_port, server_port, reactor, rps, co
max_burn_rate = nil
}
---@class plc_comms
local public = {}
-- open modem
if not self.modem.isOpen(self.l_port) then
-- configure modem channels
local function _conf_channels()
self.modem.closeAll()
self.modem.open(self.l_port)
end
_conf_channels()
---@class plc_comms
local public = {}
-- PRIVATE FUNCTIONS --
-- send an RPLC packet
@ -484,11 +487,7 @@ function plc.comms(id, version, modem, local_port, server_port, reactor, rps, co
---@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
-- reconnect a newly connected reactor
@ -605,7 +604,7 @@ function plc.comms(id, version, modem, local_port, server_port, reactor, rps, co
---@param plc_state plc_state
---@param setpoints setpoints
function public.handle_packet(packet, plc_state, setpoints)
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()

View File

@ -13,7 +13,7 @@ local config = require("reactor-plc.config")
local plc = require("reactor-plc.plc")
local threads = require("reactor-plc.threads")
local R_PLC_VERSION = "beta-v0.8.3"
local R_PLC_VERSION = "beta-v0.8.4"
local print = util.print
local println = util.println

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()

View File

@ -24,7 +24,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
local sps_rtu = require("rtu.dev.sps_rtu")
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
local RTU_VERSION = "beta-v0.8.0"
local RTU_VERSION = "beta-v0.8.1"
local rtu_t = types.rtu_t

View File

@ -13,7 +13,7 @@ local svsessions = require("supervisor.session.svsessions")
local config = require("supervisor.config")
local supervisor = require("supervisor.supervisor")
local SUPERVISOR_VERSION = "beta-v0.5.12"
local SUPERVISOR_VERSION = "beta-v0.5.13"
local print = util.print
local println = util.println

View File

@ -9,12 +9,9 @@ local supervisor = {}
local PROTOCOLS = comms.PROTOCOLS
local RPLC_TYPES = comms.RPLC_TYPES
local RPLC_LINKING = comms.RPLC_LINKING
local RTU_UNIT_TYPES = comms.RTU_UNIT_TYPES
local SCADA_MGMT_TYPES = comms.SCADA_MGMT_TYPES
local SCADA_CRDN_TYPES = comms.SCADA_CRDN_TYPES
local SESSION_TYPE = svsessions.SESSION_TYPE
local print = util.print
local println = util.println
local print_ts = util.print_ts
@ -42,19 +39,14 @@ function supervisor.comms(version, num_reactors, cooling_conf, modem, dev_listen
-- PRIVATE FUNCTIONS --
-- open all channels
local function _open_channels()
if not self.modem.isOpen(self.dev_listen) then
self.modem.open(self.dev_listen)
end
if not self.modem.isOpen(self.coord_listen) then
self.modem.open(self.coord_listen)
end
-- configure modem channels
local function _conf_channels()
self.modem.closeAll()
self.modem.open(self.dev_listen)
self.modem.open(self.coord_listen)
end
-- open at construct time
_open_channels()
_conf_channels()
-- link modem to svsessions
svsessions.init(self.modem, num_reactors, cooling_conf)
@ -113,7 +105,7 @@ function supervisor.comms(version, num_reactors, cooling_conf, modem, dev_listen
function public.reconnect_modem(modem)
self.modem = modem
svsessions.relink_modem(self.modem)
_open_channels()
_conf_channels()
end
-- parse a packet
@ -292,7 +284,7 @@ function supervisor.comms(version, num_reactors, cooling_conf, modem, dev_listen
log.debug("illegal packet type " .. protocol .. " on coordinator listening channel")
end
else
log.warning("received packet on unused channel " .. l_port)
log.warning("received packet on unconfigured channel " .. l_port)
end
end
end