#71 validate frame data types
This commit is contained in:
@@ -13,7 +13,7 @@ local config = require("reactor-plc.config")
|
|||||||
local plc = require("reactor-plc.plc")
|
local plc = require("reactor-plc.plc")
|
||||||
local threads = require("reactor-plc.threads")
|
local threads = require("reactor-plc.threads")
|
||||||
|
|
||||||
local R_PLC_VERSION = "beta-v0.7.5"
|
local R_PLC_VERSION = "beta-v0.7.6"
|
||||||
|
|
||||||
local print = util.print
|
local print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ local imatrix_rtu = require("rtu.dev.imatrix_rtu")
|
|||||||
local turbine_rtu = require("rtu.dev.turbine_rtu")
|
local turbine_rtu = require("rtu.dev.turbine_rtu")
|
||||||
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
local turbinev_rtu = require("rtu.dev.turbinev_rtu")
|
||||||
|
|
||||||
local RTU_VERSION = "beta-v0.7.5"
|
local RTU_VERSION = "beta-v0.7.6"
|
||||||
|
|
||||||
local rtu_t = types.rtu_t
|
local rtu_t = types.rtu_t
|
||||||
|
|
||||||
|
|||||||
@@ -115,12 +115,15 @@ function comms.scada_packet()
|
|||||||
|
|
||||||
if type(self.raw) == "table" then
|
if type(self.raw) == "table" then
|
||||||
if #self.raw >= 3 then
|
if #self.raw >= 3 then
|
||||||
self.valid = true
|
|
||||||
self.seq_num = self.raw[1]
|
self.seq_num = self.raw[1]
|
||||||
self.protocol = self.raw[2]
|
self.protocol = self.raw[2]
|
||||||
self.length = #self.raw[3]
|
self.length = #self.raw[3]
|
||||||
self.payload = self.raw[3]
|
self.payload = self.raw[3]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.valid = type(self.seq_num) == "number" and
|
||||||
|
type(self.protocol) == "number" and
|
||||||
|
type(self.payload) == "table"
|
||||||
end
|
end
|
||||||
|
|
||||||
return self.valid
|
return self.valid
|
||||||
@@ -166,6 +169,7 @@ function comms.modbus_packet()
|
|||||||
---@param func_code MODBUS_FCODE
|
---@param func_code MODBUS_FCODE
|
||||||
---@param data table
|
---@param data table
|
||||||
function public.make(txn_id, unit_id, func_code, data)
|
function public.make(txn_id, unit_id, func_code, data)
|
||||||
|
if type(data) == "table" then
|
||||||
self.txn_id = txn_id
|
self.txn_id = txn_id
|
||||||
self.length = #data
|
self.length = #data
|
||||||
self.unit_id = unit_id
|
self.unit_id = unit_id
|
||||||
@@ -177,6 +181,9 @@ function comms.modbus_packet()
|
|||||||
for i = 1, self.length do
|
for i = 1, self.length do
|
||||||
insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log.error("comms.modbus_packet.make(): data not table")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- decode a MODBUS packet from a SCADA frame
|
-- decode a MODBUS packet from a SCADA frame
|
||||||
@@ -194,7 +201,11 @@ function comms.modbus_packet()
|
|||||||
public.make(data[1], data[2], data[3], { table.unpack(data, 4, #data) })
|
public.make(data[1], data[2], data[3], { table.unpack(data, 4, #data) })
|
||||||
end
|
end
|
||||||
|
|
||||||
return size_ok
|
local valid = type(self.txn_id) == "number" and
|
||||||
|
type(self.unit_id) == "number" and
|
||||||
|
type(self.func_code) == "number"
|
||||||
|
|
||||||
|
return size_ok and valid
|
||||||
else
|
else
|
||||||
log.debug("attempted MODBUS_TCP parse of incorrect protocol " .. frame.protocol(), true)
|
log.debug("attempted MODBUS_TCP parse of incorrect protocol " .. frame.protocol(), true)
|
||||||
return false
|
return false
|
||||||
@@ -258,6 +269,7 @@ function comms.rplc_packet()
|
|||||||
---@param packet_type RPLC_TYPES
|
---@param packet_type RPLC_TYPES
|
||||||
---@param data table
|
---@param data table
|
||||||
function public.make(id, packet_type, data)
|
function public.make(id, packet_type, data)
|
||||||
|
if type(data) == "table" then
|
||||||
-- packet accessor properties
|
-- packet accessor properties
|
||||||
self.id = id
|
self.id = id
|
||||||
self.type = packet_type
|
self.type = packet_type
|
||||||
@@ -269,6 +281,9 @@ function comms.rplc_packet()
|
|||||||
for i = 1, #data do
|
for i = 1, #data do
|
||||||
insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log.error("comms.rplc_packet.make(): data not table")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- decode an RPLC packet from a SCADA frame
|
-- decode an RPLC packet from a SCADA frame
|
||||||
@@ -287,6 +302,8 @@ function comms.rplc_packet()
|
|||||||
ok = _rplc_type_valid()
|
ok = _rplc_type_valid()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ok = ok and type(self.id) == "number"
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
else
|
else
|
||||||
log.debug("attempted RPLC parse of incorrect protocol " .. frame.protocol(), true)
|
log.debug("attempted RPLC parse of incorrect protocol " .. frame.protocol(), true)
|
||||||
@@ -343,6 +360,7 @@ function comms.mgmt_packet()
|
|||||||
---@param packet_type SCADA_MGMT_TYPES
|
---@param packet_type SCADA_MGMT_TYPES
|
||||||
---@param data table
|
---@param data table
|
||||||
function public.make(packet_type, data)
|
function public.make(packet_type, data)
|
||||||
|
if type(data) == "table" then
|
||||||
-- packet accessor properties
|
-- packet accessor properties
|
||||||
self.type = packet_type
|
self.type = packet_type
|
||||||
self.length = #data
|
self.length = #data
|
||||||
@@ -353,6 +371,9 @@ function comms.mgmt_packet()
|
|||||||
for i = 1, #data do
|
for i = 1, #data do
|
||||||
insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log.error("comms.mgmt_packet.make(): data not table")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- decode a SCADA management packet from a SCADA frame
|
-- decode a SCADA management packet from a SCADA frame
|
||||||
@@ -424,6 +445,7 @@ function comms.coord_packet()
|
|||||||
---@param packet_type any
|
---@param packet_type any
|
||||||
---@param data table
|
---@param data table
|
||||||
function public.make(packet_type, data)
|
function public.make(packet_type, data)
|
||||||
|
if type(data) == "table" then
|
||||||
-- packet accessor properties
|
-- packet accessor properties
|
||||||
self.type = packet_type
|
self.type = packet_type
|
||||||
self.length = #data
|
self.length = #data
|
||||||
@@ -434,6 +456,9 @@ function comms.coord_packet()
|
|||||||
for i = 1, #data do
|
for i = 1, #data do
|
||||||
insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log.error("comms.coord_packet.make(): data not table")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- decode a coordinator packet from a SCADA frame
|
-- decode a coordinator packet from a SCADA frame
|
||||||
@@ -505,6 +530,7 @@ function comms.capi_packet()
|
|||||||
---@param packet_type any
|
---@param packet_type any
|
||||||
---@param data table
|
---@param data table
|
||||||
function public.make(packet_type, data)
|
function public.make(packet_type, data)
|
||||||
|
if type(data) == "table" then
|
||||||
-- packet accessor properties
|
-- packet accessor properties
|
||||||
self.type = packet_type
|
self.type = packet_type
|
||||||
self.length = #data
|
self.length = #data
|
||||||
@@ -515,6 +541,9 @@ function comms.capi_packet()
|
|||||||
for i = 1, #data do
|
for i = 1, #data do
|
||||||
insert(self.raw, data[i])
|
insert(self.raw, data[i])
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log.error("comms.capi_packet.make(): data not table")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- decode a coordinator API packet from a SCADA frame
|
-- decode a coordinator API packet from a SCADA frame
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ local svsessions = require("supervisor.session.svsessions")
|
|||||||
local config = require("supervisor.config")
|
local config = require("supervisor.config")
|
||||||
local supervisor = require("supervisor.supervisor")
|
local supervisor = require("supervisor.supervisor")
|
||||||
|
|
||||||
local SUPERVISOR_VERSION = "beta-v0.4.11"
|
local SUPERVISOR_VERSION = "beta-v0.4.12"
|
||||||
|
|
||||||
local print = util.print
|
local print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
|
|||||||
Reference in New Issue
Block a user