#634 RTU gateway backplane rework
This commit is contained in:
@@ -10,6 +10,8 @@ local util = require("scada-common.util")
|
|||||||
local databus = require("rtu.databus")
|
local databus = require("rtu.databus")
|
||||||
local rtu = require("rtu.rtu")
|
local rtu = require("rtu.rtu")
|
||||||
|
|
||||||
|
local println = util.println
|
||||||
|
|
||||||
---@class rtu_backplane
|
---@class rtu_backplane
|
||||||
local backplane = {}
|
local backplane = {}
|
||||||
|
|
||||||
@@ -19,8 +21,7 @@ local _bp = {
|
|||||||
wlan_pref = true,
|
wlan_pref = true,
|
||||||
lan_iface = "",
|
lan_iface = "",
|
||||||
|
|
||||||
act_nic = nil, ---@type nic|nil
|
act_nic = nil, ---@type nic
|
||||||
wl_act = true,
|
|
||||||
wd_nic = nil, ---@type nic|nil
|
wd_nic = nil, ---@type nic|nil
|
||||||
wl_nic = nil, ---@type nic|nil
|
wl_nic = nil, ---@type nic|nil
|
||||||
|
|
||||||
@@ -30,41 +31,51 @@ local _bp = {
|
|||||||
-- initialize the system peripheral backplane
|
-- initialize the system peripheral backplane
|
||||||
---@param config rtu_config
|
---@param config rtu_config
|
||||||
---@param __shared_memory rtu_shared_memory
|
---@param __shared_memory rtu_shared_memory
|
||||||
|
---@return boolean success
|
||||||
function backplane.init(config, __shared_memory)
|
function backplane.init(config, __shared_memory)
|
||||||
_bp.smem = __shared_memory
|
_bp.smem = __shared_memory
|
||||||
_bp.wlan_pref = config.PreferWireless
|
_bp.wlan_pref = config.PreferWireless
|
||||||
_bp.lan_iface = config.WiredModem
|
_bp.lan_iface = config.WiredModem
|
||||||
|
|
||||||
|
-- Modem Init
|
||||||
|
|
||||||
-- init wired NIC
|
-- init wired NIC
|
||||||
if type(config.WiredModem) == "string" then
|
if type(config.WiredModem) == "string" then
|
||||||
local modem = ppm.get_modem(_bp.lan_iface)
|
local modem = ppm.get_modem(_bp.lan_iface)
|
||||||
|
local wd_nic = network.nic(modem)
|
||||||
|
|
||||||
if modem then
|
log.info("BKPLN: WIRED PHY_" .. util.trinary(modem, "UP ", "DOWN ") .. _bp.lan_iface)
|
||||||
_bp.wd_nic = network.nic(modem)
|
|
||||||
log.info("BKPLN: WIRED PHY_UP " .. _bp.lan_iface)
|
-- set this as active for now
|
||||||
end
|
_bp.act_nic = wd_nic
|
||||||
|
_bp.wd_nic = wd_nic
|
||||||
end
|
end
|
||||||
|
|
||||||
-- init wireless NIC(s)
|
-- init wireless NIC(s)
|
||||||
if config.WirelessModem then
|
if config.WirelessModem then
|
||||||
local modem, iface = ppm.get_wireless_modem()
|
local modem, iface = ppm.get_wireless_modem()
|
||||||
|
local wl_nic = network.nic(modem)
|
||||||
|
|
||||||
if modem then
|
log.info("BKPLN: WIRELESS PHY_" .. util.trinary(modem, "UP ", "DOWN ") .. iface)
|
||||||
_bp.wl_nic = network.nic(modem)
|
|
||||||
log.info("BKPLN: WIRELESS PHY_UP " .. iface)
|
-- set this as active if connected or if both modems are disconnected and this is preferred
|
||||||
|
if (modem and _bp.wlan_pref) or not (_bp.act_nic and _bp.act_nic.is_connected()) then
|
||||||
|
_bp.act_nic = wl_nic
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_bp.wl_nic = wl_nic
|
||||||
end
|
end
|
||||||
|
|
||||||
-- grab the preferred active NIC
|
databus.tx_hw_modem(_bp.act_nic.is_connected())
|
||||||
if _bp.wlan_pref then
|
|
||||||
_bp.wl_act = true
|
-- at least one comms modem is required
|
||||||
_bp.act_nic = _bp.wl_nic
|
if not ((_bp.wd_nic and _bp.wd_nic.is_connected()) or (_bp.wl_nic and _bp.wl_nic.is_connected())) then
|
||||||
else
|
println("startup> comms modem not found")
|
||||||
_bp.wl_act = false
|
log.warning("BKPLN: no comms modem on startup")
|
||||||
_bp.act_nic = _bp.wd_nic
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
databus.tx_hw_modem(_bp.act_nic ~= nil)
|
-- Speaker Init
|
||||||
|
|
||||||
-- find and setup all speakers
|
-- find and setup all speakers
|
||||||
local speakers = ppm.get_all_devices("speaker")
|
local speakers = ppm.get_all_devices("speaker")
|
||||||
@@ -77,10 +88,12 @@ function backplane.init(config, __shared_memory)
|
|||||||
end
|
end
|
||||||
|
|
||||||
databus.tx_hw_spkr_count(#_bp.sounders)
|
databus.tx_hw_spkr_count(#_bp.sounders)
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get the active NIC
|
-- get the active NIC
|
||||||
---@return nic|nil
|
---@return nic
|
||||||
function backplane.active_nic() return _bp.act_nic end
|
function backplane.active_nic() return _bp.act_nic end
|
||||||
|
|
||||||
-- get the sounder interfaces
|
-- get the sounder interfaces
|
||||||
@@ -91,9 +104,8 @@ function backplane.sounders() return _bp.sounders end
|
|||||||
---@param type string
|
---@param type string
|
||||||
---@param device table
|
---@param device table
|
||||||
---@param iface string
|
---@param iface string
|
||||||
function backplane.detach(type, device, iface)
|
---@param print_no_fp function
|
||||||
local function println_ts(message) if not _bp.smem.rtu_state.fp_ok then util.println_ts(message) end end
|
function backplane.detach(type, device, iface, print_no_fp)
|
||||||
|
|
||||||
local wl_nic, wd_nic = _bp.wl_nic, _bp.wd_nic
|
local wl_nic, wd_nic = _bp.wl_nic, _bp.wd_nic
|
||||||
|
|
||||||
local comms = _bp.smem.rtu_sys.rtu_comms
|
local comms = _bp.smem.rtu_sys.rtu_comms
|
||||||
@@ -101,72 +113,58 @@ function backplane.detach(type, device, iface)
|
|||||||
if type == "modem" then
|
if type == "modem" then
|
||||||
---@cast device Modem
|
---@cast device Modem
|
||||||
|
|
||||||
local m_is_wl = device.isWireless()
|
local m_is_wl = device.isWireless()
|
||||||
local was_active = _bp.act_nic and _bp.act_nic.is_modem(device)
|
|
||||||
local was_wd = wd_nic and wd_nic.is_modem(device)
|
|
||||||
local was_wl = wl_nic and wl_nic.is_modem(device)
|
|
||||||
|
|
||||||
log.info(util.c("BKPLN: ", util.trinary(m_is_wl, "WIRELESS", "WIRED"), " PHY_DETACH ", iface))
|
log.info(util.c("BKPLN: ", util.trinary(m_is_wl, "WIRELESS", "WIRED"), " PHY_DETACH ", iface))
|
||||||
|
|
||||||
if wd_nic and was_wd then
|
if wd_nic and wd_nic.is_modem(device) then
|
||||||
wd_nic.disconnect()
|
wd_nic.disconnect()
|
||||||
log.info("BKPLN: WIRED PHY_DOWN " .. iface)
|
log.info("BKPLN: WIRED PHY_DOWN " .. iface)
|
||||||
elseif wl_nic and was_wl then
|
elseif wl_nic and wl_nic.is_modem(device) then
|
||||||
wl_nic.disconnect()
|
wl_nic.disconnect()
|
||||||
log.info("BKPLN: WIRELESS PHY_DOWN " .. iface)
|
log.info("BKPLN: WIRELESS PHY_DOWN " .. iface)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- we only care if this is our active comms modem
|
-- we only care if this is our active comms modem
|
||||||
if was_active then
|
if _bp.act_nic.is_modem(device) then
|
||||||
println_ts("active comms modem disconnected")
|
print_no_fp("active comms modem disconnected")
|
||||||
log.warning("BKPLN: active comms modem disconnected")
|
log.warning("BKPLN: active comms modem disconnected")
|
||||||
|
|
||||||
-- failover and try to find a new comms modem
|
-- failover and try to find a new comms modem
|
||||||
if _bp.wl_act then
|
if _bp.act_nic == wl_nic then
|
||||||
|
-- wireless active disconnected
|
||||||
-- try to find another wireless modem, otherwise switch to wired
|
-- try to find another wireless modem, otherwise switch to wired
|
||||||
local modem, m_iface = ppm.get_wireless_modem()
|
local modem, m_iface = ppm.get_wireless_modem()
|
||||||
if modem then
|
if wl_nic and modem then
|
||||||
log.info("BKPLN: found another wireless modem, using it for comms")
|
log.info("BKPLN: found another wireless modem, using it for comms")
|
||||||
|
|
||||||
-- note: must assign to self.wl_nic if creating a nic, otherwise it only changes locally
|
wl_nic.connect(modem)
|
||||||
if wl_nic then
|
|
||||||
wl_nic.connect(modem)
|
|
||||||
else _bp.wl_nic = network.nic(modem) end
|
|
||||||
|
|
||||||
log.info("BKPLN: WIRELESS PHY_UP " .. m_iface)
|
log.info("BKPLN: WIRELESS PHY_UP " .. m_iface)
|
||||||
|
|
||||||
_bp.act_nic = wl_nic
|
|
||||||
comms.assign_nic(_bp.act_nic)
|
|
||||||
log.info("BKPLN: switched comms to new wireless modem")
|
|
||||||
elseif wd_nic and wd_nic.is_connected() then
|
elseif wd_nic and wd_nic.is_connected() then
|
||||||
_bp.wl_act = false
|
|
||||||
_bp.act_nic = _bp.wd_nic
|
_bp.act_nic = _bp.wd_nic
|
||||||
|
|
||||||
comms.assign_nic(_bp.act_nic)
|
comms.switch_nic(_bp.act_nic)
|
||||||
log.info("BKPLN: switched comms to wired modem")
|
log.info("BKPLN: switched comms to wired modem")
|
||||||
else
|
else
|
||||||
_bp.act_nic = nil
|
|
||||||
databus.tx_hw_modem(false)
|
databus.tx_hw_modem(false)
|
||||||
comms.unassign_nic()
|
|
||||||
end
|
end
|
||||||
else
|
elseif wl_nic and wl_nic.is_connected() then
|
||||||
-- switch to wireless if able
|
-- wired active disconnected, wireless available
|
||||||
if wl_nic then
|
_bp.act_nic = wl_nic
|
||||||
_bp.wl_act = true
|
|
||||||
_bp.act_nic = wl_nic
|
|
||||||
|
|
||||||
comms.assign_nic(_bp.act_nic)
|
comms.switch_nic(_bp.act_nic)
|
||||||
log.info("BKPLN: switched comms to wireless modem")
|
log.info("BKPLN: switched comms to wireless modem")
|
||||||
else
|
else
|
||||||
_bp.act_nic = nil
|
-- wired active disconnected, wireless unavailable
|
||||||
databus.tx_hw_modem(false)
|
databus.tx_hw_modem(false)
|
||||||
comms.unassign_nic()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
elseif _bp.wl_nic and m_is_wl then
|
elseif _bp.wl_nic and m_is_wl then
|
||||||
-- wireless, but not active
|
-- wireless, but not active
|
||||||
|
print_no_fp("standby wireless modem disconnected")
|
||||||
log.info("BKPLN: standby wireless modem disconnected")
|
log.info("BKPLN: standby wireless modem disconnected")
|
||||||
else
|
else
|
||||||
|
print_no_fp("unassigned modem disconnected")
|
||||||
log.warning("BKPLN: unassigned modem disconnected")
|
log.warning("BKPLN: unassigned modem disconnected")
|
||||||
end
|
end
|
||||||
elseif type == "speaker" then
|
elseif type == "speaker" then
|
||||||
@@ -175,8 +173,8 @@ function backplane.detach(type, device, iface)
|
|||||||
if _bp.sounders[i].speaker == device then
|
if _bp.sounders[i].speaker == device then
|
||||||
table.remove(_bp.sounders, i)
|
table.remove(_bp.sounders, i)
|
||||||
|
|
||||||
|
print_no_fp("a speaker was disconnected")
|
||||||
log.warning(util.c("BKPLN: speaker ", iface, " disconnected"))
|
log.warning(util.c("BKPLN: speaker ", iface, " disconnected"))
|
||||||
println_ts("speaker disconnected")
|
|
||||||
|
|
||||||
databus.tx_hw_spkr_count(#_bp.sounders)
|
databus.tx_hw_spkr_count(#_bp.sounders)
|
||||||
break
|
break
|
||||||
@@ -189,8 +187,9 @@ end
|
|||||||
---@param type string
|
---@param type string
|
||||||
---@param device table
|
---@param device table
|
||||||
---@param iface string
|
---@param iface string
|
||||||
function backplane.attach(type, device, iface)
|
---@param print_no_fp function
|
||||||
local function println_ts(message) if not _bp.smem.rtu_state.fp_ok then util.println_ts(message) end end
|
function backplane.attach(type, device, iface, print_no_fp)
|
||||||
|
local wl_nic, wd_nic = _bp.wl_nic, _bp.wd_nic
|
||||||
|
|
||||||
local comms = _bp.smem.rtu_sys.rtu_comms
|
local comms = _bp.smem.rtu_sys.rtu_comms
|
||||||
|
|
||||||
@@ -201,71 +200,51 @@ function backplane.attach(type, device, iface)
|
|||||||
|
|
||||||
log.info(util.c("BKPLN: ", util.trinary(m_is_wl, "WIRELESS", "WIRED"), " PHY_ATTACH ", iface))
|
log.info(util.c("BKPLN: ", util.trinary(m_is_wl, "WIRELESS", "WIRED"), " PHY_ATTACH ", iface))
|
||||||
|
|
||||||
local is_wd = _bp.lan_iface == iface
|
if wd_nic and (_bp.lan_iface == iface) then
|
||||||
local is_wl = ((not _bp.wl_nic) or (not _bp.wl_nic.is_connected())) and m_is_wl
|
|
||||||
|
|
||||||
if is_wd then
|
|
||||||
-- connect this as the wired NIC
|
-- connect this as the wired NIC
|
||||||
if _bp.wd_nic then
|
wd_nic.connect(device)
|
||||||
_bp.wd_nic.connect(device)
|
|
||||||
else _bp.wd_nic = network.nic(device) end
|
|
||||||
|
|
||||||
log.info("BKPLN: WIRED PHY_UP " .. iface)
|
log.info("BKPLN: WIRED PHY_UP " .. iface)
|
||||||
|
print_no_fp("wired comms modem reconnected")
|
||||||
|
|
||||||
if _bp.act_nic == nil then
|
if (_bp.act_nic ~= wd_nic) and not _bp.wlan_pref then
|
||||||
-- set as active
|
|
||||||
_bp.wl_act = false
|
|
||||||
_bp.act_nic = _bp.wd_nic
|
|
||||||
|
|
||||||
comms.assign_nic(_bp.act_nic)
|
|
||||||
databus.tx_hw_modem(true)
|
|
||||||
println_ts("comms modem reconnected")
|
|
||||||
log.info("BKPLN: switched comms to wired modem")
|
|
||||||
elseif _bp.wl_act and not _bp.wlan_pref then
|
|
||||||
-- switch back to preferred wired
|
-- switch back to preferred wired
|
||||||
_bp.wl_act = false
|
_bp.act_nic = wd_nic
|
||||||
_bp.act_nic = _bp.wd_nic
|
|
||||||
|
|
||||||
comms.assign_nic(_bp.act_nic)
|
comms.switch_nic(_bp.act_nic)
|
||||||
log.info("BKPLN: switched comms to wired modem (preferred)")
|
log.info("BKPLN: switched comms to wired modem (preferred)")
|
||||||
|
|
||||||
|
databus.tx_hw_modem(true)
|
||||||
end
|
end
|
||||||
elseif is_wl then
|
elseif wl_nic and (not wl_nic.is_connected()) and m_is_wl then
|
||||||
-- connect this as the wireless NIC
|
-- connect this as the wireless NIC
|
||||||
if _bp.wl_nic then
|
wl_nic.connect(device)
|
||||||
_bp.wl_nic.connect(device)
|
|
||||||
else _bp.wl_nic = network.nic(device) end
|
|
||||||
|
|
||||||
log.info("BKPLN: WIRELESS PHY_UP " .. iface)
|
log.info("BKPLN: WIRELESS PHY_UP " .. iface)
|
||||||
|
|
||||||
if _bp.act_nic == nil then
|
if (_bp.act_nic ~= wl_nic) and _bp.wlan_pref then
|
||||||
-- set as active
|
|
||||||
_bp.wl_act = true
|
|
||||||
_bp.act_nic = _bp.wl_nic
|
|
||||||
|
|
||||||
comms.assign_nic(_bp.act_nic)
|
|
||||||
databus.tx_hw_modem(true)
|
|
||||||
println_ts("comms modem reconnected")
|
|
||||||
log.info("BKPLN: switched comms to wireless modem")
|
|
||||||
elseif (not _bp.wl_act) and _bp.wlan_pref then
|
|
||||||
-- switch back to preferred wireless
|
-- switch back to preferred wireless
|
||||||
_bp.wl_act = true
|
_bp.act_nic = wl_nic
|
||||||
_bp.act_nic = _bp.wl_nic
|
|
||||||
|
|
||||||
comms.assign_nic(_bp.act_nic)
|
comms.switch_nic(_bp.act_nic)
|
||||||
log.info("BKPLN: switched comms to wireless modem (preferred)")
|
log.info("BKPLN: switched comms to wireless modem (preferred)")
|
||||||
|
|
||||||
|
databus.tx_hw_modem(true)
|
||||||
end
|
end
|
||||||
elseif m_is_wl then
|
elseif wl_nic and m_is_wl then
|
||||||
-- the wireless NIC already has a modem
|
-- the wireless NIC already has a modem
|
||||||
log.info("standby wireless modem connected")
|
print_no_fp("standby wireless modem connected")
|
||||||
|
log.info("BKPLN: standby wireless modem connected")
|
||||||
else
|
else
|
||||||
log.info("wired modem connected")
|
print_no_fp("unassigned modem connected")
|
||||||
|
log.warning("BKPLN: unassigned modem connected")
|
||||||
end
|
end
|
||||||
elseif type == "speaker" then
|
elseif type == "speaker" then
|
||||||
---@cast device Speaker
|
---@cast device Speaker
|
||||||
table.insert(_bp.sounders, rtu.init_sounder(device))
|
table.insert(_bp.sounders, rtu.init_sounder(device))
|
||||||
|
|
||||||
println_ts("speaker connected")
|
print_no_fp("a speaker was connected")
|
||||||
log.info(util.c("connected speaker ", iface))
|
log.info(util.c("BKPLN: connected speaker ", iface))
|
||||||
|
|
||||||
databus.tx_hw_spkr_count(#_bp.sounders)
|
databus.tx_hw_spkr_count(#_bp.sounders)
|
||||||
end
|
end
|
||||||
|
|||||||
83
rtu/rtu.lua
83
rtu/rtu.lua
@@ -293,7 +293,7 @@ end
|
|||||||
-- RTU Communications
|
-- RTU Communications
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
---@param version string RTU version
|
---@param version string RTU version
|
||||||
---@param nic nic|nil network interface device
|
---@param nic nic network interface device
|
||||||
---@param conn_watchdog watchdog watchdog reference
|
---@param conn_watchdog watchdog watchdog reference
|
||||||
function rtu.comms(version, nic, conn_watchdog)
|
function rtu.comms(version, nic, conn_watchdog)
|
||||||
local self = {
|
local self = {
|
||||||
@@ -306,15 +306,12 @@ function rtu.comms(version, nic, conn_watchdog)
|
|||||||
|
|
||||||
local insert = table.insert
|
local insert = table.insert
|
||||||
|
|
||||||
-- CONDITIONAL PRIVATE FUNCTIONS --
|
-- PRIVATE FUNCTIONS --
|
||||||
|
|
||||||
-- these don't check for nic to be nil to save execution time on functions called extremely often
|
|
||||||
-- when the nic isn't present, the aliases _send and _send_modbus are cleared
|
|
||||||
|
|
||||||
-- send a scada management packet
|
-- send a scada management packet
|
||||||
---@param msg_type MGMT_TYPE
|
---@param msg_type MGMT_TYPE
|
||||||
---@param msg table
|
---@param msg table
|
||||||
local function _nic_send(msg_type, msg)
|
local function _send(msg_type, msg)
|
||||||
local s_pkt = comms.scada_packet()
|
local s_pkt = comms.scada_packet()
|
||||||
local m_pkt = comms.mgmt_packet()
|
local m_pkt = comms.mgmt_packet()
|
||||||
|
|
||||||
@@ -326,23 +323,6 @@ function rtu.comms(version, nic, conn_watchdog)
|
|||||||
self.seq_num = self.seq_num + 1
|
self.seq_num = self.seq_num + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- send a MODBUS TCP packet
|
|
||||||
---@param m_pkt modbus_packet
|
|
||||||
local function _nic_send_modbus(m_pkt)
|
|
||||||
local s_pkt = comms.scada_packet()
|
|
||||||
|
|
||||||
s_pkt.make(self.sv_addr, self.seq_num, PROTOCOL.MODBUS_TCP, m_pkt.raw_sendable())
|
|
||||||
|
|
||||||
---@diagnostic disable-next-line: need-check-nil
|
|
||||||
nic.transmit(config.SVR_Channel, config.RTU_Channel, s_pkt)
|
|
||||||
self.seq_num = self.seq_num + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
-- PRIVATE FUNCTIONS --
|
|
||||||
|
|
||||||
-- send a scada management packet
|
|
||||||
local _send = _nic_send
|
|
||||||
|
|
||||||
-- keep alive ack
|
-- keep alive ack
|
||||||
---@param srv_time integer
|
---@param srv_time integer
|
||||||
local function _send_keep_alive_ack(srv_time)
|
local function _send_keep_alive_ack(srv_time)
|
||||||
@@ -372,8 +352,21 @@ function rtu.comms(version, nic, conn_watchdog)
|
|||||||
---@class rtu_comms
|
---@class rtu_comms
|
||||||
local public = {}
|
local public = {}
|
||||||
|
|
||||||
-- send a MODBUS TCP packet
|
-- switch the current active NIC
|
||||||
public.send_modbus = _nic_send_modbus
|
---@param _nic nic
|
||||||
|
function public.switch_nic(_nic)
|
||||||
|
nic.closeAll()
|
||||||
|
|
||||||
|
if _nic.isWireless() then
|
||||||
|
comms.set_trusted_range(config.TrustedRange)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- configure receive channels
|
||||||
|
_nic.closeAll()
|
||||||
|
_nic.open(config.RTU_Channel)
|
||||||
|
|
||||||
|
nic = _nic
|
||||||
|
end
|
||||||
|
|
||||||
-- unlink from the server
|
-- unlink from the server
|
||||||
---@param rtu_state rtu_state
|
---@param rtu_state rtu_state
|
||||||
@@ -392,6 +385,18 @@ function rtu.comms(version, nic, conn_watchdog)
|
|||||||
_send(MGMT_TYPE.CLOSE, {})
|
_send(MGMT_TYPE.CLOSE, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- send a MODBUS TCP packet
|
||||||
|
---@param m_pkt modbus_packet
|
||||||
|
function public.send_modbus(m_pkt)
|
||||||
|
local s_pkt = comms.scada_packet()
|
||||||
|
|
||||||
|
s_pkt.make(self.sv_addr, self.seq_num, PROTOCOL.MODBUS_TCP, m_pkt.raw_sendable())
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: need-check-nil
|
||||||
|
nic.transmit(config.SVR_Channel, config.RTU_Channel, s_pkt)
|
||||||
|
self.seq_num = self.seq_num + 1
|
||||||
|
end
|
||||||
|
|
||||||
-- send establish request (includes advertisement)
|
-- send establish request (includes advertisement)
|
||||||
---@param units table
|
---@param units table
|
||||||
function public.send_establish(units)
|
function public.send_establish(units)
|
||||||
@@ -612,34 +617,6 @@ function rtu.comms(version, nic, conn_watchdog)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set the current NIC
|
|
||||||
---@param _nic nic
|
|
||||||
function public.assign_nic(_nic)
|
|
||||||
if nic then nic.closeAll() end
|
|
||||||
|
|
||||||
if _nic.isWireless() then
|
|
||||||
comms.set_trusted_range(config.TrustedRange)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- configure receive channels
|
|
||||||
_nic.closeAll()
|
|
||||||
_nic.open(config.RTU_Channel)
|
|
||||||
|
|
||||||
nic = _nic
|
|
||||||
_send = _nic_send
|
|
||||||
public.send_modbus = _nic_send_modbus
|
|
||||||
end
|
|
||||||
|
|
||||||
-- clear the current NIC
|
|
||||||
function public.unassign_nic()
|
|
||||||
_send = function () end
|
|
||||||
public.send_modbus = function () end
|
|
||||||
nic = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- set the NIC if one was given
|
|
||||||
if nic then public.assign_nic(nic) else public.unassign_nic() end
|
|
||||||
|
|
||||||
return public
|
return public
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -112,14 +112,15 @@ local function main()
|
|||||||
local units = __shared_memory.rtu_sys.units
|
local units = __shared_memory.rtu_sys.units
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
-- start system
|
-- init and start system
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
|
-- modem and speaker initialization
|
||||||
|
if not backplane.init(config, __shared_memory) then return end
|
||||||
|
|
||||||
log.debug("boot> running uinit()")
|
log.debug("boot> running uinit()")
|
||||||
|
|
||||||
if uinit(config, __shared_memory) then
|
if uinit(config, __shared_memory) then
|
||||||
-- init backplane peripherals
|
|
||||||
backplane.init(config, __shared_memory)
|
|
||||||
|
|
||||||
-- start UI
|
-- start UI
|
||||||
local message
|
local message
|
||||||
@@ -139,11 +140,7 @@ local function main()
|
|||||||
-- setup comms
|
-- setup comms
|
||||||
local nic = backplane.active_nic()
|
local nic = backplane.active_nic()
|
||||||
smem_sys.rtu_comms = rtu.comms(RTU_VERSION, nic, smem_sys.conn_watchdog)
|
smem_sys.rtu_comms = rtu.comms(RTU_VERSION, nic, smem_sys.conn_watchdog)
|
||||||
if nic then
|
log.debug("startup> comms init")
|
||||||
log.debug("startup> comms init")
|
|
||||||
else
|
|
||||||
log.warning("startup> no comms modem on startup")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- init threads
|
-- init threads
|
||||||
local main_thread = threads.thread__main(__shared_memory)
|
local main_thread = threads.thread__main(__shared_memory)
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ function threads.thread__main(smem)
|
|||||||
|
|
||||||
if type ~= nil and device ~= nil then
|
if type ~= nil and device ~= nil then
|
||||||
if type == "modem" or type == "speaker" then
|
if type == "modem" or type == "speaker" then
|
||||||
backplane.detach(type, device, param1)
|
backplane.detach(type, device, param1, println_ts)
|
||||||
else
|
else
|
||||||
for i = 1, #units do
|
for i = 1, #units do
|
||||||
-- find disconnected device
|
-- find disconnected device
|
||||||
@@ -272,7 +272,7 @@ function threads.thread__main(smem)
|
|||||||
|
|
||||||
if type ~= nil and device ~= nil then
|
if type ~= nil and device ~= nil then
|
||||||
if type == "modem" or type == "speaker" then
|
if type == "modem" or type == "speaker" then
|
||||||
backplane.attach(type, device, param1)
|
backplane.attach(type, device, param1, println_ts)
|
||||||
else
|
else
|
||||||
-- relink lost peripheral to correct unit entry
|
-- relink lost peripheral to correct unit entry
|
||||||
for i = 1, #units do
|
for i = 1, #units do
|
||||||
|
|||||||
Reference in New Issue
Block a user