mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
PLC comms packet length checks
This commit is contained in:
parent
d688f9a1c6
commit
4d5cbcf475
@ -431,6 +431,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
if self.linked then
|
||||
if packet.type == RPLC_TYPES.KEEP_ALIVE then
|
||||
-- keep alive request received, echo back
|
||||
if packet.length == 1 then
|
||||
local timestamp = packet.data[1]
|
||||
local trip_time = util.time() - timestamp
|
||||
|
||||
@ -441,8 +442,12 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
-- log._debug("RPLC RTT = ".. trip_time .. "ms")
|
||||
|
||||
_send_keep_alive_ack(timestamp)
|
||||
else
|
||||
log._debug(log_header .. "RPLC keep alive packet length mismatch")
|
||||
end
|
||||
elseif packet.type == RPLC_TYPES.LINK_REQ then
|
||||
-- link request confirmation
|
||||
if packet.length == 1 then
|
||||
log._debug("received unsolicited link request response")
|
||||
|
||||
local link_ack = packet.data[1]
|
||||
@ -465,6 +470,9 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
end
|
||||
|
||||
self.linked = link_ack == RPLC_LINKING.ALLOW
|
||||
else
|
||||
log._debug(log_header .. "RPLC link req packet length mismatch")
|
||||
end
|
||||
elseif packet.type == RPLC_TYPES.MEK_STRUCT then
|
||||
-- request for physical structure
|
||||
_send_struct()
|
||||
@ -482,6 +490,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
_send_ack(packet.type, self.reactor.__p_is_ok())
|
||||
elseif packet.type == RPLC_TYPES.MEK_BURN_RATE then
|
||||
-- set the burn rate
|
||||
if packet.length == 1 then
|
||||
local success = false
|
||||
local burn_rate = packet.data[1]
|
||||
local max_burn_rate = self.max_burn_rate
|
||||
@ -501,6 +510,9 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
end
|
||||
|
||||
_send_ack(packet.type, success)
|
||||
else
|
||||
log._debug(log_header .. "RPLC set burn rate packet length mismatch")
|
||||
end
|
||||
elseif packet.type == RPLC_TYPES.ISS_CLEAR then
|
||||
-- clear the ISS status
|
||||
iss.reset()
|
||||
@ -510,6 +522,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
end
|
||||
elseif packet.type == RPLC_TYPES.LINK_REQ then
|
||||
-- link request confirmation
|
||||
if packet.length == 1 then
|
||||
local link_ack = packet.data[1]
|
||||
|
||||
if link_ack == RPLC_LINKING.ALLOW then
|
||||
@ -535,6 +548,9 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
end
|
||||
|
||||
self.linked = link_ack == RPLC_LINKING.ALLOW
|
||||
else
|
||||
log._debug(log_header .. "RPLC link req packet length mismatch")
|
||||
end
|
||||
else
|
||||
log._debug("discarding non-link packet before linked")
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ os.loadAPI("config.lua")
|
||||
os.loadAPI("plc.lua")
|
||||
os.loadAPI("threads.lua")
|
||||
|
||||
local R_PLC_VERSION = "alpha-v0.4.7"
|
||||
local R_PLC_VERSION = "alpha-v0.4.8"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
|
Loading…
x
Reference in New Issue
Block a user