#580 review changes/fixes
This commit is contained in:
@@ -158,16 +158,18 @@ function backplane.init(config, __shared_memory)
|
||||
-- Modem Init
|
||||
|
||||
-- init wired NIC
|
||||
if type(config.WiredModem) == "string" then
|
||||
if type(_bp.lan_iface) == "string" then
|
||||
local modem = ppm.get_modem(_bp.lan_iface)
|
||||
local wd_nic = network.nic(modem)
|
||||
|
||||
log.info("BKPLN: WIRED PHY_" .. util.trinary(modem, "UP ", "DOWN ") .. _bp.lan_iface)
|
||||
log_comms("wired comms modem " .. util.trinary(modem, "connected", "not found"))
|
||||
|
||||
-- set this as active for now
|
||||
_bp.act_nic = wd_nic
|
||||
_bp.wd_nic = wd_nic
|
||||
_bp.act_nic = wd_nic -- set this as active for now
|
||||
|
||||
wd_nic.closeAll()
|
||||
wd_nic.open(config.CRD_Channel)
|
||||
|
||||
iocontrol.fp_has_wd_modem(modem ~= nil)
|
||||
end
|
||||
@@ -339,11 +341,13 @@ function backplane.attach(type, device, iface)
|
||||
end
|
||||
elseif type == "speaker" then
|
||||
---@cast device Speaker
|
||||
log_sys("alarm sounder speaker reconnected")
|
||||
|
||||
log.info("BKPLN: SPEAKER LINK_UP " .. iface)
|
||||
|
||||
sounder.reconnect(device)
|
||||
|
||||
log_sys("alarm sounder speaker reconnected")
|
||||
|
||||
iocontrol.fp_has_speaker(true)
|
||||
end
|
||||
end
|
||||
@@ -465,10 +469,11 @@ function backplane.detach(type, device, iface)
|
||||
end
|
||||
elseif type == "speaker" then
|
||||
---@cast device Speaker
|
||||
log_sys("lost alarm sounder speaker")
|
||||
|
||||
log.info("BKPLN: SPEAKER LINK_DOWN " .. iface)
|
||||
|
||||
log_sys("alarm sounder speaker disconnected")
|
||||
|
||||
iocontrol.fp_has_speaker(false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -184,10 +184,6 @@ function coordinator.comms(version, nic, wl_nic, sv_watchdog)
|
||||
comms.set_trusted_range(config.TrustedRange)
|
||||
end
|
||||
|
||||
-- configure network channels
|
||||
nic.closeAll()
|
||||
nic.open(config.CRD_Channel)
|
||||
|
||||
-- pass config to apisessions
|
||||
if config.API_Enabled and wl_nic then
|
||||
apisessions.init(wl_nic, config)
|
||||
@@ -254,15 +250,7 @@ function coordinator.comms(version, nic, wl_nic, sv_watchdog)
|
||||
|
||||
-- switch the current active NIC
|
||||
---@param act_nic nic
|
||||
function public.switch_nic(act_nic)
|
||||
nic.closeAll()
|
||||
|
||||
-- configure receive channels
|
||||
act_nic.closeAll()
|
||||
act_nic.open(config.CRD_Channel)
|
||||
|
||||
nic = act_nic
|
||||
end
|
||||
function public.switch_nic(act_nic) nic = act_nic end
|
||||
|
||||
-- try to connect to the supervisor if not already linked
|
||||
---@param abort boolean? true to print out cancel info if not linked (use on program terminate)
|
||||
|
||||
@@ -71,7 +71,6 @@ local function init(panel, config)
|
||||
wl_modem.register(ps, "has_wl_modem", wl_modem.update)
|
||||
else
|
||||
local modem = LED{parent=system,label="MODEM",colors=led_grn}
|
||||
modem.register(ps, "has_modem", modem.update)
|
||||
modem.register(ps, util.trinary(config.WirelessModem, "has_wl_modem", "has_wd_modem"), modem.update)
|
||||
end
|
||||
|
||||
|
||||
@@ -39,17 +39,19 @@ function backplane.init(config, __shared_memory)
|
||||
|
||||
if _bp.smem.networked then
|
||||
-- init wired NIC
|
||||
if type(config.WiredModem) == "string" then
|
||||
if type(_bp.lan_iface) == "string" then
|
||||
local modem = ppm.get_modem(_bp.lan_iface)
|
||||
local wd_nic = network.nic(modem)
|
||||
|
||||
log.info("BKPLN: WIRED PHY_" .. util.trinary(modem, "UP ", "DOWN ") .. _bp.lan_iface)
|
||||
|
||||
plc_state.wd_modem = wd_nic.is_connected()
|
||||
|
||||
-- set this as active for now
|
||||
_bp.act_nic = wd_nic
|
||||
_bp.wd_nic = wd_nic
|
||||
_bp.act_nic = wd_nic -- set this as active for now
|
||||
|
||||
wd_nic.closeAll()
|
||||
wd_nic.open(config.PLC_Channel)
|
||||
|
||||
plc_state.wd_modem = wd_nic.is_connected()
|
||||
end
|
||||
|
||||
-- init wireless NIC(s)
|
||||
@@ -59,14 +61,17 @@ function backplane.init(config, __shared_memory)
|
||||
|
||||
log.info("BKPLN: WIRELESS PHY_" .. util.trinary(modem, "UP ", "DOWN ") .. iface)
|
||||
|
||||
plc_state.wl_modem = wl_nic.is_connected()
|
||||
|
||||
-- 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
|
||||
|
||||
_bp.wl_nic = wl_nic
|
||||
|
||||
wl_nic.closeAll()
|
||||
wl_nic.open(config.PLC_Channel)
|
||||
|
||||
plc_state.wl_modem = wl_nic.is_connected()
|
||||
end
|
||||
|
||||
-- comms modem is required if networked
|
||||
@@ -86,6 +91,8 @@ function backplane.init(config, __shared_memory)
|
||||
|
||||
-- we need a reactor, can at least do some things even if it isn't formed though
|
||||
if plc_state.no_reactor then
|
||||
log.info("BKPLN: REACTOR LINK_DOWN")
|
||||
|
||||
println("startup> fission reactor not found")
|
||||
log.warning("BKPLN: no reactor on startup")
|
||||
|
||||
@@ -97,14 +104,16 @@ function backplane.init(config, __shared_memory)
|
||||
plc_dev.reactor = dev
|
||||
|
||||
log.info("BKPLN: mounted virtual device as reactor")
|
||||
elseif not plc_dev.reactor.isFormed() then
|
||||
println("startup> fission reactor is not formed")
|
||||
log.warning("BKPLN: reactor logic adapter present, but reactor is not formed")
|
||||
|
||||
plc_state.degraded = true
|
||||
plc_state.reactor_formed = false
|
||||
else
|
||||
log.info("BKPLN: reactor detected")
|
||||
log.info("BKPLN: REACTOR LINK_UP " .. ppm.get_iface(plc_dev.reactor))
|
||||
|
||||
if not plc_dev.reactor.isFormed() then
|
||||
println("startup> fission reactor is not formed")
|
||||
log.warning("BKPLN: reactor logic adapter detected, but reactor is not formed")
|
||||
|
||||
plc_state.degraded = true
|
||||
plc_state.reactor_formed = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -129,6 +138,8 @@ function backplane.attach(iface, type, device, print_no_fp)
|
||||
if type ~= nil and device ~= nil then
|
||||
if state.no_reactor and (type == "fissionReactorLogicAdapter") then
|
||||
-- reconnected reactor
|
||||
log.info("BKPLN: REACTOR LINK_UP " .. iface)
|
||||
|
||||
dev.reactor = device
|
||||
state.no_reactor = false
|
||||
|
||||
@@ -225,6 +236,8 @@ function backplane.detach(iface, type, device, print_no_fp)
|
||||
local sys = _bp.smem.plc_sys
|
||||
|
||||
if device == dev.reactor then
|
||||
log.info("BKPLN: REACTOR LINK_DOWN " .. iface)
|
||||
|
||||
print_no_fp("reactor disconnected")
|
||||
log.warning("BKPLN: reactor disconnected")
|
||||
|
||||
|
||||
@@ -563,10 +563,6 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
|
||||
comms.set_trusted_range(config.TrustedRange)
|
||||
end
|
||||
|
||||
-- configure network channels
|
||||
nic.closeAll()
|
||||
nic.open(config.PLC_Channel)
|
||||
|
||||
--#region PRIVATE FUNCTIONS --
|
||||
|
||||
-- send an RPLC packet
|
||||
@@ -834,15 +830,7 @@ function plc.comms(version, nic, reactor, rps, conn_watchdog)
|
||||
|
||||
-- switch the current active NIC
|
||||
---@param act_nic nic
|
||||
function public.switch_nic(act_nic)
|
||||
nic.closeAll()
|
||||
|
||||
-- configure receive channels
|
||||
act_nic.closeAll()
|
||||
act_nic.open(config.PLC_Channel)
|
||||
|
||||
nic = act_nic
|
||||
end
|
||||
function public.switch_nic(act_nic) nic = act_nic end
|
||||
|
||||
-- reconnect a newly connected reactor
|
||||
---@param new_reactor table
|
||||
|
||||
@@ -40,15 +40,17 @@ function backplane.init(config, __shared_memory)
|
||||
-- Modem Init
|
||||
|
||||
-- init wired NIC
|
||||
if type(config.WiredModem) == "string" then
|
||||
if type(_bp.lan_iface) == "string" then
|
||||
local modem = ppm.get_modem(_bp.lan_iface)
|
||||
local wd_nic = network.nic(modem)
|
||||
|
||||
log.info("BKPLN: WIRED PHY_" .. util.trinary(modem, "UP ", "DOWN ") .. _bp.lan_iface)
|
||||
|
||||
-- set this as active for now
|
||||
_bp.act_nic = wd_nic
|
||||
_bp.wd_nic = wd_nic
|
||||
_bp.act_nic = wd_nic -- set this as active for now
|
||||
|
||||
wd_nic.closeAll()
|
||||
wd_nic.open(config.RTU_Channel)
|
||||
|
||||
databus.tx_hw_wd_modem(modem ~= nil)
|
||||
end
|
||||
@@ -67,6 +69,9 @@ function backplane.init(config, __shared_memory)
|
||||
|
||||
_bp.wl_nic = wl_nic
|
||||
|
||||
wl_nic.closeAll()
|
||||
wl_nic.open(config.RTU_Channel)
|
||||
|
||||
databus.tx_hw_wl_modem(modem ~= nil)
|
||||
end
|
||||
|
||||
@@ -82,10 +87,9 @@ function backplane.init(config, __shared_memory)
|
||||
-- find and setup all speakers
|
||||
local speakers = ppm.get_all_devices("speaker")
|
||||
for _, s in pairs(speakers) do
|
||||
log.info("BKPLN: SPEAKER LINK_UP " .. ppm.get_iface(s))
|
||||
|
||||
local sounder = rtu.init_sounder(s)
|
||||
|
||||
log.info("BKPLN: SPEAKER LINK_UP " .. sounder.name)
|
||||
|
||||
table.insert(_bp.sounders, sounder)
|
||||
|
||||
log.debug(util.c("BKPLN: added speaker sounder, attached as ", sounder.name))
|
||||
|
||||
14
rtu/rtu.lua
14
rtu/rtu.lua
@@ -310,10 +310,6 @@ function rtu.comms(version, nic, conn_watchdog)
|
||||
comms.set_trusted_range(config.TrustedRange)
|
||||
end
|
||||
|
||||
-- configure network channels
|
||||
nic.closeAll()
|
||||
nic.open(config.RTU_Channel)
|
||||
|
||||
--#region PRIVATE FUNCTIONS --
|
||||
|
||||
-- send a scada management packet
|
||||
@@ -363,15 +359,7 @@ function rtu.comms(version, nic, conn_watchdog)
|
||||
|
||||
-- switch the current active NIC
|
||||
---@param act_nic nic
|
||||
function public.switch_nic(act_nic)
|
||||
nic.closeAll()
|
||||
|
||||
-- configure receive channels
|
||||
act_nic.closeAll()
|
||||
act_nic.open(config.RTU_Channel)
|
||||
|
||||
nic = act_nic
|
||||
end
|
||||
function public.switch_nic(act_nic) nic = act_nic end
|
||||
|
||||
-- unlink from the server
|
||||
---@param rtu_state rtu_state
|
||||
|
||||
@@ -23,31 +23,33 @@ local _bp = {
|
||||
nic_map = {} ---@type nic[] connected nics
|
||||
}
|
||||
|
||||
-- network interfaces indexed by peripheral names
|
||||
backplane.nics = _bp.nic_map
|
||||
|
||||
-- initialize the system peripheral backplane
|
||||
---@param config svr_config
|
||||
---@return boolean success
|
||||
function backplane.init(config)
|
||||
-- setup the wired modem, if configured
|
||||
if type(config.WiredModem) == "string" then
|
||||
_bp.lan_iface = config.WiredModem
|
||||
_bp.lan_iface = config.WiredModem
|
||||
|
||||
-- setup the wired modem, if configured
|
||||
if type(_bp.lan_iface) == "string" then
|
||||
local modem = ppm.get_modem(_bp.lan_iface)
|
||||
local wd_nic = network.nic(modem)
|
||||
|
||||
log.info("BKPLN: WIRED PHY_" .. util.trinary(modem, "UP ", "DOWN ") .. _bp.lan_iface)
|
||||
|
||||
local modem = ppm.get_modem(_bp.lan_iface)
|
||||
if not (modem and _bp.lan_iface) then
|
||||
println("startup> wired comms modem not found")
|
||||
log.fatal("BKPLN: no wired comms modem on startup")
|
||||
return false
|
||||
end
|
||||
|
||||
local nic = network.nic(modem)
|
||||
_bp.wd_nic = nic
|
||||
_bp.nic_map[_bp.lan_iface] = nic
|
||||
_bp.wd_nic = wd_nic
|
||||
_bp.nic_map[_bp.lan_iface] = wd_nic
|
||||
|
||||
log.info("BKPLN: WIRED PHY_UP " .. _bp.lan_iface)
|
||||
|
||||
nic.closeAll()
|
||||
nic.open(config.SVR_Channel)
|
||||
wd_nic.closeAll()
|
||||
wd_nic.open(config.SVR_Channel)
|
||||
|
||||
databus.tx_hw_wd_modem(true)
|
||||
end
|
||||
@@ -55,20 +57,21 @@ function backplane.init(config)
|
||||
-- setup the wireless modem, if configured
|
||||
if config.WirelessModem then
|
||||
local modem, iface = ppm.get_wireless_modem()
|
||||
local wl_nic = network.nic(modem)
|
||||
|
||||
log.info("BKPLN: WIRELESS PHY_" .. util.trinary(modem, "UP ", "DOWN ") .. iface)
|
||||
|
||||
if not (modem and iface) then
|
||||
println("startup> wireless comms modem not found")
|
||||
log.fatal("BKPLN: no wireless comms modem on startup")
|
||||
return false
|
||||
end
|
||||
|
||||
local nic = network.nic(modem)
|
||||
_bp.wl_nic = nic
|
||||
_bp.nic_map[iface] = nic
|
||||
_bp.wl_nic = wl_nic
|
||||
_bp.nic_map[iface] = wl_nic
|
||||
|
||||
log.info("BKPLN: WIRELESS PHY_UP " .. iface)
|
||||
|
||||
nic.closeAll()
|
||||
nic.open(config.SVR_Channel)
|
||||
wl_nic.closeAll()
|
||||
wl_nic.open(config.SVR_Channel)
|
||||
|
||||
databus.tx_hw_wl_modem(true)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user