diff --git a/coordinator/coordinator.lua b/coordinator/coordinator.lua index fa065ce..4374b3c 100644 --- a/coordinator/coordinator.lua +++ b/coordinator/coordinator.lua @@ -250,7 +250,10 @@ 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 = act_nic end + function public.switch_nic(act_nic) + public.close() + 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) diff --git a/reactor-plc/plc.lua b/reactor-plc/plc.lua index a630570..f7f92b9 100644 --- a/reactor-plc/plc.lua +++ b/reactor-plc/plc.lua @@ -830,7 +830,10 @@ 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 = act_nic end + function public.switch_nic(act_nic) + public.close() + nic = act_nic + end -- reconnect a newly connected reactor ---@param new_reactor table diff --git a/rtu/backplane.lua b/rtu/backplane.lua index 990c0df..92289b5 100644 --- a/rtu/backplane.lua +++ b/rtu/backplane.lua @@ -136,7 +136,7 @@ function backplane.attach(type, device, iface, print_no_fp) -- switch back to preferred wired _bp.act_nic = wd_nic - comms.switch_nic(_bp.act_nic) + comms.switch_nic(_bp.act_nic, _bp.smem.rtu_state) log.info("BKPLN: switched comms to wired modem (preferred)") end elseif wl_nic and (not wl_nic.is_connected()) and m_is_wl then @@ -152,7 +152,7 @@ function backplane.attach(type, device, iface, print_no_fp) -- switch back to preferred wireless _bp.act_nic = wl_nic - comms.switch_nic(_bp.act_nic) + comms.switch_nic(_bp.act_nic, _bp.smem.rtu_state) log.info("BKPLN: switched comms to wireless modem (preferred)") end elseif wl_nic and m_is_wl then @@ -227,14 +227,14 @@ function backplane.detach(type, device, iface, print_no_fp) elseif wd_nic and wd_nic.is_connected() then _bp.act_nic = wd_nic - comms.switch_nic(_bp.act_nic) + comms.switch_nic(_bp.act_nic, _bp.smem.rtu_state) log.info("BKPLN: switched comms to wired modem") end elseif wl_nic and wl_nic.is_connected() then -- wired active disconnected, wireless available _bp.act_nic = wl_nic - comms.switch_nic(_bp.act_nic) + comms.switch_nic(_bp.act_nic, _bp.smem.rtu_state) log.info("BKPLN: switched comms to wireless modem") else -- wired active disconnected, wireless unavailable diff --git a/rtu/rtu.lua b/rtu/rtu.lua index 2c4c9d4..fa9908f 100644 --- a/rtu/rtu.lua +++ b/rtu/rtu.lua @@ -359,7 +359,11 @@ function rtu.comms(version, nic, conn_watchdog) -- switch the current active NIC ---@param act_nic nic - function public.switch_nic(act_nic) nic = act_nic end + ---@param rtu_state rtu_state + function public.switch_nic(act_nic, rtu_state) + public.close(rtu_state) + nic = act_nic + end -- unlink from the server ---@param rtu_state rtu_state