#580 RTU gateway changes for wired comms modems

This commit is contained in:
Mikayla 2025-05-05 17:57:54 +00:00
parent 454d166ac9
commit 028a161af0
6 changed files with 32 additions and 16 deletions

View File

@ -167,7 +167,7 @@ function threads.thread__main(smem, init)
end end
end end
else else
log.warning("a non-comms modem was disconnected") log.warning("non-comms modem disconnected")
end end
end end
end end

View File

@ -88,8 +88,9 @@ local tmp_cfg = {
SVR_Channel = nil, ---@type integer SVR_Channel = nil, ---@type integer
RTU_Channel = nil, ---@type integer RTU_Channel = nil, ---@type integer
ConnTimeout = nil, ---@type number ConnTimeout = nil, ---@type number
WiredModem = false, ---@type string|false
TrustedRange = nil, ---@type number TrustedRange = nil, ---@type number
AuthKey = nil, ---@type string|nil AuthKey = nil, ---@type string
LogMode = 0, ---@type LOG_MODE LogMode = 0, ---@type LOG_MODE
LogPath = "", LogPath = "",
LogDebug = false, LogDebug = false,
@ -107,6 +108,7 @@ local fields = {
{ "SVR_Channel", "SVR Channel", 16240 }, { "SVR_Channel", "SVR Channel", 16240 },
{ "RTU_Channel", "RTU Channel", 16242 }, { "RTU_Channel", "RTU Channel", 16242 },
{ "ConnTimeout", "Connection Timeout", 5 }, { "ConnTimeout", "Connection Timeout", 5 },
{ "WiredModem", "Wired Modem", false },
{ "TrustedRange", "Trusted Range", 0 }, { "TrustedRange", "Trusted Range", 0 },
{ "AuthKey", "Facility Auth Key", "" }, { "AuthKey", "Facility Auth Key", "" },
{ "LogMode", "Log Mode", log.MODE.APPEND }, { "LogMode", "Log Mode", log.MODE.APPEND },

View File

@ -31,7 +31,7 @@ function databus.tx_versions(rtu_v, comms_v)
databus.ps.publish("comms_version", comms_v) databus.ps.publish("comms_version", comms_v)
end end
-- transmit hardware status for modem connection state -- transmit hardware status for comms modem connection state
---@param has_modem boolean ---@param has_modem boolean
function databus.tx_hw_modem(has_modem) function databus.tx_hw_modem(has_modem)
databus.ps.publish("has_modem", has_modem) databus.ps.publish("has_modem", has_modem)

View File

@ -36,6 +36,7 @@ function rtu.load_config()
config.SVR_Channel = settings.get("SVR_Channel") config.SVR_Channel = settings.get("SVR_Channel")
config.RTU_Channel = settings.get("RTU_Channel") config.RTU_Channel = settings.get("RTU_Channel")
config.ConnTimeout = settings.get("ConnTimeout") config.ConnTimeout = settings.get("ConnTimeout")
config.WiredModem = settings.get("WiredModem")
config.TrustedRange = settings.get("TrustedRange") config.TrustedRange = settings.get("TrustedRange")
config.AuthKey = settings.get("AuthKey") config.AuthKey = settings.get("AuthKey")
@ -61,6 +62,7 @@ function rtu.validate_config(cfg)
cfv.assert_channel(cfg.RTU_Channel) cfv.assert_channel(cfg.RTU_Channel)
cfv.assert_type_num(cfg.ConnTimeout) cfv.assert_type_num(cfg.ConnTimeout)
cfv.assert_min(cfg.ConnTimeout, 2) cfv.assert_min(cfg.ConnTimeout, 2)
cfv.assert((cfg.WiredModem == false) or (type(cfg.WiredModem) == "string"))
cfv.assert_type_num(cfg.TrustedRange) cfv.assert_type_num(cfg.TrustedRange)
cfv.assert_min(cfg.TrustedRange, 0) cfv.assert_min(cfg.TrustedRange, 0)
cfv.assert_type_str(cfg.AuthKey) cfv.assert_type_str(cfg.AuthKey)
@ -299,7 +301,9 @@ function rtu.comms(version, nic, conn_watchdog)
local insert = table.insert local insert = table.insert
if nic.isWireless() then
comms.set_trusted_range(config.TrustedRange) comms.set_trusted_range(config.TrustedRange)
end
-- PRIVATE FUNCTIONS -- -- PRIVATE FUNCTIONS --

View File

@ -31,7 +31,7 @@ local sna_rtu = require("rtu.dev.sna_rtu")
local sps_rtu = require("rtu.dev.sps_rtu") local sps_rtu = require("rtu.dev.sps_rtu")
local turbinev_rtu = require("rtu.dev.turbinev_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu")
local RTU_VERSION = "v1.11.8" local RTU_VERSION = "v1.12.0"
local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE local RTU_UNIT_TYPE = types.RTU_UNIT_TYPE
local RTU_HW_STATE = databus.RTU_HW_STATE local RTU_HW_STATE = databus.RTU_HW_STATE
@ -108,7 +108,9 @@ local function main()
-- RTU gateway devices (not RTU units) -- RTU gateway devices (not RTU units)
rtu_dev = { rtu_dev = {
modem = ppm.get_wireless_modem(), modem_wired = type(config.WiredModem) == "string",
modem_iface = config.WiredModem,
modem = nil,
sounders = {} ---@type rtu_speaker_sounder[] sounders = {} ---@type rtu_speaker_sounder[]
}, },
@ -131,8 +133,13 @@ local function main()
local rtu_state = __shared_memory.rtu_state local rtu_state = __shared_memory.rtu_state
-- get the configured modem
if smem_dev.modem_wired then
smem_dev.modem = ppm.get_wired_modem(smem_dev.modem_iface)
else smem_dev.modem = ppm.get_wireless_modem() end
---------------------------------------- ----------------------------------------
-- interpret config and init units -- interpret RTU configs and init units
---------------------------------------- ----------------------------------------
local units = __shared_memory.rtu_sys.units local units = __shared_memory.rtu_sys.units
@ -506,10 +513,10 @@ local function main()
log.info("startup> running in headless mode without front panel") log.info("startup> running in headless mode without front panel")
end end
-- check modem -- check comms modem
if smem_dev.modem == nil then if smem_dev.modem == nil then
println("startup> wireless modem not found") println("startup> comms modem not found")
log.fatal("no wireless modem on startup") log.fatal("no comms modem on startup")
return return
end end

View File

@ -189,6 +189,7 @@ function threads.thread__main(smem)
-- load in from shared memory -- load in from shared memory
local rtu_state = smem.rtu_state local rtu_state = smem.rtu_state
local rtu_dev = smem.rtu_dev
local sounders = smem.rtu_dev.sounders local sounders = smem.rtu_dev.sounders
local nic = smem.rtu_sys.nic local nic = smem.rtu_sys.nic
local rtu_comms = smem.rtu_sys.rtu_comms local rtu_comms = smem.rtu_sys.rtu_comms
@ -246,11 +247,11 @@ function threads.thread__main(smem)
if type ~= nil and device ~= nil then if type ~= nil and device ~= nil then
if type == "modem" then if type == "modem" then
---@cast device Modem ---@cast device Modem
-- we only care if this is our wireless modem -- we only care if this is our comms modem
if nic.is_modem(device) then if nic.is_modem(device) then
nic.disconnect() nic.disconnect()
println_ts("wireless modem disconnected!") println_ts("comms modem disconnected!")
log.warning("comms modem disconnected") log.warning("comms modem disconnected")
local other_modem = ppm.get_wireless_modem() local other_modem = ppm.get_wireless_modem()
@ -301,18 +302,20 @@ function threads.thread__main(smem)
if type ~= nil and device ~= nil then if type ~= nil and device ~= nil then
if type == "modem" then if type == "modem" then
---@cast device Modem ---@cast device Modem
if device.isWireless() and not nic.is_connected() then local is_comms_modem = util.trinary(rtu_dev.modem_wired, rtu_dev.modem_iface == param1, device.isWireless())
if is_comms_modem and not nic.is_connected() then
-- reconnected modem -- reconnected modem
nic.connect(device) nic.connect(device)
println_ts("wireless modem reconnected.") println_ts("comms modem reconnected.")
log.info("comms modem reconnected") log.info("comms modem reconnected")
databus.tx_hw_modem(true) databus.tx_hw_modem(true)
elseif device.isWireless() then elseif device.isWireless() then
log.info("unused wireless modem reconnected") log.info("unused wireless modem connected")
else else
log.info("wired modem reconnected") log.info("non-comms wired modem connected")
end end
elseif type == "speaker" then elseif type == "speaker" then
---@cast device Speaker ---@cast device Speaker