From 569358a4e15cfefaa8cb8882c8f6010c0d43b8f3 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sat, 8 Nov 2025 17:20:24 -0500 Subject: [PATCH] #642 updated reactor PLC connection test --- scada-common/comms.lua | 5 ++++- scada-common/types.lua | 2 +- scada-common/util.lua | 2 +- supervisor/session/svsessions.lua | 6 +++++- supervisor/supervisor.lua | 12 ++++++++---- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/scada-common/comms.lua b/scada-common/comms.lua index e3e7403..716ea1b 100644 --- a/scada-common/comms.lua +++ b/scada-common/comms.lua @@ -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 diff --git a/scada-common/types.lua b/scada-common/types.lua index 32bf265..bb7c4a4 100644 --- a/scada-common/types.lua +++ b/scada-common/types.lua @@ -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" diff --git a/scada-common/util.lua b/scada-common/util.lua index fe661be..a5d4830 100644 --- a/scada-common/util.lua +++ b/scada-common/util.lua @@ -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 diff --git a/supervisor/session/svsessions.lua b/supervisor/session/svsessions.lua index 402ea58..d57b7bf 100644 --- a/supervisor/session/svsessions.lua +++ b/supervisor/session/svsessions.lua @@ -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", diff --git a/supervisor/supervisor.lua b/supervisor/supervisor.lua index f182578..a90693d 100644 --- a/supervisor/supervisor.lua +++ b/supervisor/supervisor.lua @@ -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