#580 fixed supervisor listen mode logic

This commit is contained in:
Mikayla Fischler
2025-11-02 13:05:07 -05:00
parent d7a280bb04
commit 8bbf385c41
2 changed files with 22 additions and 23 deletions

View File

@@ -5,13 +5,10 @@
local log = require("scada-common.log")
local network = require("scada-common.network")
local ppm = require("scada-common.ppm")
local types = require("scada-common.types")
local util = require("scada-common.util")
local databus = require("supervisor.databus")
local LISTEN_MODE = types.LISTEN_MODE
local println = util.println
---@class supervisor_backplane
@@ -47,11 +44,10 @@ function backplane.init(config)
_bp.wd_nic = nic
_bp.nic_map[_bp.lan_iface] = nic
nic.closeAll()
log.info("BKPLN: WIRED PHY_UP " .. _bp.lan_iface)
if config.PLC_Listen ~= LISTEN_MODE.WIRELESS then nic.open(config.PLC_Channel) end
if config.RTU_Listen ~= LISTEN_MODE.WIRELESS then nic.open(config.RTU_Channel) end
if config.CRD_Listen ~= LISTEN_MODE.WIRELESS then nic.open(config.CRD_Channel) end
nic.closeAll()
nic.open(config.SVR_Channel)
databus.tx_hw_wd_modem(true)
end
@@ -69,23 +65,14 @@ function backplane.init(config)
_bp.wl_nic = nic
_bp.nic_map[iface] = nic
nic.closeAll()
log.info("BKPLN: WIRELESS PHY_UP " .. iface)
if config.PLC_Listen ~= LISTEN_MODE.WIRED then nic.open(config.PLC_Channel) end
if config.RTU_Listen ~= LISTEN_MODE.WIRED then nic.open(config.RTU_Channel) end
if config.CRD_Listen ~= LISTEN_MODE.WIRED then nic.open(config.CRD_Channel) end
if config.PocketEnabled then nic.open(config.PKT_Channel) end
nic.closeAll()
nic.open(config.SVR_Channel)
databus.tx_hw_wl_modem(true)
end
---@todo this should be a config check check
if not ((type(config.WiredModem) == "string" or config.WirelessModem)) then
println("startup> no modems configured")
log.fatal("BKPLN: no modems configured")
return false
end
return true
end

View File

@@ -1,5 +1,6 @@
local comms = require("scada-common.comms")
local log = require("scada-common.log")
local types = require("scada-common.types")
local util = require("scada-common.util")
local themes = require("graphics.themes")
@@ -16,6 +17,8 @@ local ESTABLISH_ACK = comms.ESTABLISH_ACK
local PROBE_ACK = comms.PROBE_ACK
local MGMT_TYPE = comms.MGMT_TYPE
local LISTEN_MODE = types.LISTEN_MODE
---@type svr_config
---@diagnostic disable-next-line: missing-fields
local config = {}
@@ -114,6 +117,7 @@ function supervisor.load_config()
cfv.assert_type_bool(config.WirelessModem)
cfv.assert((config.WiredModem == false) or (type(config.WiredModem) == "string"))
cfv.assert((config.WirelessModem == true) or (type(config.WiredModem) == "string"))
cfv.assert_type_num(config.PLC_Listen)
cfv.assert_range(config.PLC_Listen, 0, 2)
@@ -208,7 +212,9 @@ function supervisor.comms(_version, fp_ok, facility)
local firmware_v = packet.data[2]
local dev_type = packet.data[3]
if comms_v ~= comms.version then
if (config.PLC_Listen ~= LISTEN_MODE.ALL) and (nic.isWireless() ~= (config.PLC_Listen == LISTEN_MODE.WIRELESS)) and periphemu == nil then
-- 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, ")"))
end
@@ -266,7 +272,9 @@ function supervisor.comms(_version, fp_ok, facility)
local firmware_v = packet.data[2]
local dev_type = packet.data[3]
if comms_v ~= comms.version then
if (config.RTU_Listen ~= LISTEN_MODE.ALL) and (nic.isWireless() ~= (config.RTU_Listen == LISTEN_MODE.WIRELESS)) and periphemu == nil then
-- drop if not listening
elseif comms_v ~= comms.version then
if last_ack ~= ESTABLISH_ACK.BAD_VERSION then
log.info(util.c("dropping RTU_GW establish packet with incorrect comms version v", comms_v, " (expected v", comms.version, ")"))
end
@@ -302,7 +310,9 @@ function supervisor.comms(_version, fp_ok, facility)
local firmware_v = packet.data[2]
local dev_type = packet.data[3]
if comms_v ~= comms.version then
if (config.CRD_Listen ~= LISTEN_MODE.ALL) and (nic.isWireless() ~= (config.CRD_Listen == LISTEN_MODE.WIRELESS)) and periphemu == nil then
-- drop if not listening
elseif comms_v ~= comms.version then
if last_ack ~= ESTABLISH_ACK.BAD_VERSION then
log.info(util.c("dropping coordinator establish packet with incorrect comms version v", comms_v, " (expected v", comms.version, ")"))
end
@@ -341,7 +351,9 @@ function supervisor.comms(_version, fp_ok, facility)
local firmware_v = packet.data[2]
local dev_type = packet.data[3]
if comms_v ~= comms.version then
if not config.PocketEnabled then
-- drop if not listening
elseif comms_v ~= comms.version then
if last_ack ~= ESTABLISH_ACK.BAD_VERSION then
log.info(util.c("dropping PKT establish packet with incorrect comms version v", comms_v, " (expected v", comms.version, ")"))
end