mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#225 PLC/RTUs drop incoming packets from devices other than the configured supervisor while linked
This commit is contained in:
parent
b20d42ff38
commit
c536b823e7
@ -778,6 +778,7 @@ function plc.comms(id, version, modem, plc_channel, svr_channel, range, reactor,
|
|||||||
-- print a log message to the terminal as long as the UI isn't running
|
-- print a log message to the terminal as long as the UI isn't running
|
||||||
local function println_ts(message) if not plc_state.fp_ok then util.println_ts(message) end end
|
local function println_ts(message) if not plc_state.fp_ok then util.println_ts(message) end end
|
||||||
|
|
||||||
|
local protocol = packet.scada_frame.protocol()
|
||||||
local l_chan = packet.scada_frame.local_channel()
|
local l_chan = packet.scada_frame.local_channel()
|
||||||
local src_addr = packet.scada_frame.src_addr()
|
local src_addr = packet.scada_frame.src_addr()
|
||||||
|
|
||||||
@ -789,6 +790,9 @@ function plc.comms(id, version, modem, plc_channel, svr_channel, range, reactor,
|
|||||||
elseif self.linked and ((self.r_seq_num + 1) ~= packet.scada_frame.seq_num()) then
|
elseif self.linked and ((self.r_seq_num + 1) ~= packet.scada_frame.seq_num()) then
|
||||||
log.warning("sequence out-of-order: last = " .. self.r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
|
log.warning("sequence out-of-order: last = " .. self.r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
|
||||||
return
|
return
|
||||||
|
elseif self.linked and src_addr ~= self.sv_addr then
|
||||||
|
log.debug("received packet from unknown computer " .. src_addr .. " while linked; channel in use by another system?")
|
||||||
|
return
|
||||||
else
|
else
|
||||||
self.r_seq_num = packet.scada_frame.seq_num()
|
self.r_seq_num = packet.scada_frame.seq_num()
|
||||||
end
|
end
|
||||||
@ -796,8 +800,6 @@ function plc.comms(id, version, modem, plc_channel, svr_channel, range, reactor,
|
|||||||
-- feed the watchdog first so it doesn't uhh...eat our packets :)
|
-- feed the watchdog first so it doesn't uhh...eat our packets :)
|
||||||
conn_watchdog.feed()
|
conn_watchdog.feed()
|
||||||
|
|
||||||
local protocol = packet.scada_frame.protocol()
|
|
||||||
|
|
||||||
-- handle packet
|
-- handle packet
|
||||||
if protocol == PROTOCOL.RPLC then
|
if protocol == PROTOCOL.RPLC then
|
||||||
---@cast packet rplc_frame
|
---@cast packet rplc_frame
|
||||||
|
@ -18,7 +18,7 @@ local plc = require("reactor-plc.plc")
|
|||||||
local renderer = require("reactor-plc.renderer")
|
local renderer = require("reactor-plc.renderer")
|
||||||
local threads = require("reactor-plc.threads")
|
local threads = require("reactor-plc.threads")
|
||||||
|
|
||||||
local R_PLC_VERSION = "v1.4.2"
|
local R_PLC_VERSION = "v1.4.3"
|
||||||
|
|
||||||
local println = util.println
|
local println = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
|
14
rtu/rtu.lua
14
rtu/rtu.lua
@ -330,13 +330,20 @@ function rtu.comms(version, modem, rtu_channel, svr_channel, range, conn_watchdo
|
|||||||
-- print a log message to the terminal as long as the UI isn't running
|
-- print a log message to the terminal as long as the UI isn't running
|
||||||
local function println_ts(message) if not rtu_state.fp_ok then util.println_ts(message) end end
|
local function println_ts(message) if not rtu_state.fp_ok then util.println_ts(message) end end
|
||||||
|
|
||||||
if packet.scada_frame.local_channel() == rtu_channel then
|
local protocol = packet.scada_frame.protocol()
|
||||||
|
local l_chan = packet.scada_frame.local_channel()
|
||||||
|
local src_addr = packet.scada_frame.src_addr()
|
||||||
|
|
||||||
|
if l_chan == rtu_channel then
|
||||||
-- check sequence number
|
-- check sequence number
|
||||||
if self.r_seq_num == nil then
|
if self.r_seq_num == nil then
|
||||||
self.r_seq_num = packet.scada_frame.seq_num()
|
self.r_seq_num = packet.scada_frame.seq_num()
|
||||||
elseif rtu_state.linked and ((self.r_seq_num + 1) ~= packet.scada_frame.seq_num()) then
|
elseif rtu_state.linked and ((self.r_seq_num + 1) ~= packet.scada_frame.seq_num()) then
|
||||||
log.warning("sequence out-of-order: last = " .. self.r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
|
log.warning("sequence out-of-order: last = " .. self.r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
|
||||||
return
|
return
|
||||||
|
elseif rtu_state.linked and src_addr ~= self.sv_addr then
|
||||||
|
log.debug("received packet from unknown computer " .. src_addr .. " while linked; channel in use by another system?")
|
||||||
|
return
|
||||||
else
|
else
|
||||||
self.r_seq_num = packet.scada_frame.seq_num()
|
self.r_seq_num = packet.scada_frame.seq_num()
|
||||||
end
|
end
|
||||||
@ -344,8 +351,7 @@ function rtu.comms(version, modem, rtu_channel, svr_channel, range, conn_watchdo
|
|||||||
-- feed watchdog on valid sequence number
|
-- feed watchdog on valid sequence number
|
||||||
conn_watchdog.feed()
|
conn_watchdog.feed()
|
||||||
|
|
||||||
local protocol = packet.scada_frame.protocol()
|
-- handle packet
|
||||||
|
|
||||||
if protocol == PROTOCOL.MODBUS_TCP then
|
if protocol == PROTOCOL.MODBUS_TCP then
|
||||||
---@cast packet modbus_frame
|
---@cast packet modbus_frame
|
||||||
if rtu_state.linked then
|
if rtu_state.linked then
|
||||||
@ -465,6 +471,8 @@ function rtu.comms(version, modem, rtu_channel, svr_channel, range, conn_watchdo
|
|||||||
-- should be unreachable assuming packet is from parse_packet()
|
-- should be unreachable assuming packet is from parse_packet()
|
||||||
log.error("illegal packet type " .. protocol, true)
|
log.error("illegal packet type " .. protocol, true)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log.debug("received packet on unconfigured channel " .. l_chan, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
|
|||||||
local sps_rtu = require("rtu.dev.sps_rtu")
|
local sps_rtu = require("rtu.dev.sps_rtu")
|
||||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||||
|
|
||||||
local RTU_VERSION = "v1.3.2"
|
local RTU_VERSION = "v1.3.3"
|
||||||
|
|
||||||
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
|
||||||
local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE
|
local RTU_UNIT_HW_STATE = databus.RTU_UNIT_HW_STATE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user