#642 updated reactor PLC connection test
This commit is contained in:
@@ -17,7 +17,7 @@ local max_distance = nil
|
||||
local comms = {}
|
||||
|
||||
-- protocol/data versions (protocol/data independent changes tracked by util.lua version)
|
||||
comms.version = "3.0.9"
|
||||
comms.version = "3.1.0"
|
||||
comms.api_version = "0.0.10"
|
||||
|
||||
---@enum PROTOCOL
|
||||
@@ -147,6 +147,9 @@ comms.FAC_COMMAND = FAC_COMMAND
|
||||
-- destination broadcast address (to all devices)
|
||||
comms.BROADCAST = -1
|
||||
|
||||
-- firmware version used to indicate an establish packet is a connection test
|
||||
comms.CONN_TEST_FWV = "CONN_TEST"
|
||||
|
||||
---@alias packet scada_packet|modbus_packet|rplc_packet|mgmt_packet|crdn_packet
|
||||
---@alias frame modbus_frame|rplc_frame|mgmt_frame|crdn_frame
|
||||
|
||||
|
||||
@@ -568,7 +568,7 @@ types.ALARM_STATE_NAMES = {
|
||||
---| "websocket_failure"
|
||||
---| "websocket_message"
|
||||
---| "websocket_success"
|
||||
---| "clock_start" (custom)
|
||||
---| "conn_test_complete" (custom)
|
||||
|
||||
---@alias fluid
|
||||
---| "mekanism:empty_gas"
|
||||
|
||||
@@ -24,7 +24,7 @@ local t_pack = table.pack
|
||||
local util = {}
|
||||
|
||||
-- scada-common version
|
||||
util.version = "1.5.6"
|
||||
util.version = "1.6.0"
|
||||
|
||||
util.TICK_TIME_S = 0.05
|
||||
util.TICK_TIME_MS = 50
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
-- Supervisor Sessions Handler
|
||||
--
|
||||
|
||||
local comms = require("scada-common.comms")
|
||||
local log = require("scada-common.log")
|
||||
local mqueue = require("scada-common.mqueue")
|
||||
local types = require("scada-common.types")
|
||||
@@ -465,9 +466,12 @@ end
|
||||
---@param i_seq_num integer initial (most recent) sequence number
|
||||
---@param for_reactor integer unit ID
|
||||
---@param version string PLC version
|
||||
---@return integer|false session_id
|
||||
---@return integer|boolean session_id session ID, false if unit is already connected, and true if this is a successful connection test
|
||||
function svsessions.establish_plc_session(nic, source_addr, i_seq_num, for_reactor, version)
|
||||
if svsessions.get_reactor_session(for_reactor) == nil and for_reactor >= 1 and for_reactor <= self.config.UnitCount then
|
||||
-- don't actually establish this if it is a connection test
|
||||
if version == comms.CONN_TEST_FWV then return true end
|
||||
|
||||
---@class plc_session_struct
|
||||
local plc_s = {
|
||||
s_type = "plc",
|
||||
|
||||
@@ -218,7 +218,7 @@ function supervisor.comms(_version, fp_ok, facility)
|
||||
-- drop if not listening
|
||||
elseif comms_v ~= comms.version then
|
||||
if last_ack ~= ESTABLISH_ACK.BAD_VERSION then
|
||||
log.info(util.c("dropping PLC establish packet with incorrect comms version v", comms_v, " (expected v", comms.version, ")"))
|
||||
log.info(util.c("PLC_ESTABLISH: PLC [@", src_addr, "] dropping PLC establish packet with incorrect comms version v", comms_v, " (expected v", comms.version, ")"))
|
||||
end
|
||||
|
||||
_send_establish(nic, packet.scada_frame, ESTABLISH_ACK.BAD_VERSION)
|
||||
@@ -231,7 +231,7 @@ function supervisor.comms(_version, fp_ok, facility)
|
||||
if reactor_id < 1 or reactor_id > config.UnitCount then
|
||||
-- reactor index out of range
|
||||
if last_ack ~= ESTABLISH_ACK.DENY then
|
||||
log.warning(util.c("PLC_ESTABLISH: denied assignment ", reactor_id, " outside of configured unit count ", config.UnitCount))
|
||||
log.warning(util.c("PLC_ESTABLISH: PLC [@", src_addr, "] denied assignment ", reactor_id, " outside of configured unit count ", config.UnitCount))
|
||||
end
|
||||
|
||||
_send_establish(nic, packet.scada_frame, ESTABLISH_ACK.DENY)
|
||||
@@ -242,14 +242,18 @@ function supervisor.comms(_version, fp_ok, facility)
|
||||
if plc_id == false then
|
||||
-- reactor already has a PLC assigned
|
||||
if last_ack ~= ESTABLISH_ACK.COLLISION then
|
||||
log.warning(util.c("PLC_ESTABLISH: assignment collision with reactor ", reactor_id))
|
||||
log.warning(util.c("PLC_ESTABLISH: PLC [@", src_addr, "] assignment collision with reactor ", reactor_id))
|
||||
end
|
||||
|
||||
_send_establish(nic, packet.scada_frame, ESTABLISH_ACK.COLLISION)
|
||||
elseif plc_id == true then
|
||||
-- valid, but this was just a test
|
||||
log.info(util.c("PLC_ESTABLISH: PLC [@", src_addr, "] sending connection test success response on ", nic.phy_name()))
|
||||
_send_establish(nic, packet.scada_frame, ESTABLISH_ACK.ALLOW)
|
||||
else
|
||||
-- got an ID; assigned to a reactor successfully
|
||||
println(util.c("PLC (", firmware_v, ") [@", src_addr, "] \xbb reactor ", reactor_id, " connected"))
|
||||
log.info(util.c("PLC_ESTABLISH: PLC (", firmware_v, ") [@", src_addr, "] reactor unit ", reactor_id, " PLC connected with session ID ", plc_id, " on ", nic.phy_name()))
|
||||
log.info(util.c("PLC_ESTABLISH: PLC [@", src_addr, "] (", firmware_v, ") reactor unit ", reactor_id, " PLC connected with session ID ", plc_id, " on ", nic.phy_name()))
|
||||
_send_establish(nic, packet.scada_frame, ESTABLISH_ACK.ALLOW)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user