PLC check sequence numbers, corrected trip time to ms

This commit is contained in:
Mikayla Fischler 2022-04-23 21:10:25 -04:00
parent fa19af308d
commit 416255f41a
2 changed files with 15 additions and 3 deletions

View File

@ -202,6 +202,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
local self = {
id = id,
seq_num = 0,
r_seq_num = nil,
modem = modem,
s_port = server_port,
l_port = local_port,
@ -363,6 +364,17 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
-- handle an RPLC packet
local handle_packet = function (packet, plc_state)
if packet ~= nil then
-- check sequence number
if self.r_seq_num == nil then
self.r_seq_num = packet.scada_frame.seq_num()
elseif self.r_seq_num >= packet.scada_frame.seq_num() then
log._warning("sequence out-of-order: last = " .. self.r_seq_num .. ", new = " .. packet.scada_frame.seq_num())
return
else
self.r_seq_num = packet.scada_frame.seq_num()
end
-- handle packet
if packet.scada_frame.protocol() == PROTOCOLS.RPLC then
if self.linked then
if packet.type == RPLC_TYPES.KEEP_ALIVE then
@ -372,7 +384,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
if trip_time < 0 then
log._warning("PLC KEEP_ALIVE trip time less than 0 (" .. trip_time .. ")")
elseif trip_time > 1 then
elseif trip_time > 1000 then
log._warning("PLC KEEP_ALIVE trip time > 1s (" .. trip_time .. ")")
end

View File

@ -190,11 +190,11 @@ function new_session(id, for_reactor, in_queue, out_queue)
if self.last_rtt < 0 then
log._warning(log_header .. "PLC KEEP_ALIVE round trip time less than 0 (" .. trip_time .. ")")
elseif trip_time > 1 then
elseif trip_time > 1000 then
log._warning(log_header .. "PLC KEEP_ALIVE round trip time > 1s (" .. trip_time .. ")")
end
log._debug(log_header .. "RPLC RTT = ".. trip_time)
log._debug(log_header .. "RPLC RTT = ".. trip_time .. "ms")
else
log._debug(log_header .. "RPLC keep alive packet length mismatch")
end