From c70a23f7a893c5787f365df34ba240dac34e92bf Mon Sep 17 00:00:00 2001 From: Tim Wilkinson Date: Sat, 11 Feb 2023 11:43:36 -0800 Subject: [PATCH] Improve LQM distance management 02/11/2023 (#705) --- files/usr/local/bin/mgr/lqm.lua | 44 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/files/usr/local/bin/mgr/lqm.lua b/files/usr/local/bin/mgr/lqm.lua index 3e61af86..6189f718 100755 --- a/files/usr/local/bin/mgr/lqm.lua +++ b/files/usr/local/bin/mgr/lqm.lua @@ -247,6 +247,7 @@ function lqm() local dtdlinks = {} local rflinks = {} local hidden_nodes = {} + local last_coverage = -1 while true do now = nixio.sysinfo().uptime @@ -506,10 +507,6 @@ function lqm() end end - local distance = -1 - local alt_distance = -1 - local coverage = -1 - -- Count the RF links we have local rfcount = 0 for _, track in pairs(tracker) @@ -816,6 +813,8 @@ function lqm() end end + local distance = -1 + -- Update the block state and calculate the routable distance for _, track in pairs(tracker) do @@ -825,16 +824,14 @@ function lqm() track.pending = now + pending_timeout end - -- Find the most distant, unblocked, routable, RF node - if track.type == "RF" and not track.blocked and track.distance then - if not is_pending(track) and track.routable then - if track.distance > distance then + -- Find the most distant, unblocked, RF node + if track.type == "RF" then + if track.distance then + if track.distance > distance and (not track.blocked or is_pending(track)) then distance = track.distance end - else - if track.distance > alt_distance then - alt_distance = track.distance - end + elseif is_pending(track) then + distance = config.max_distance end end end @@ -846,20 +843,19 @@ function lqm() end end - distance = distance + 1 - alt_distance = alt_distance + 1 - + -- Default distances if we haven't calcuated anything + if distance < 0 then + if config.auto_distance > 0 then + distance = config.auto_distance + else + distance = config.max_distance + end + end -- Update the wifi distance - if distance > 0 then - coverage = math.min(255, math.floor((distance * 2 * 0.0033) / 3)) -- airtime + local coverage = math.min(255, math.floor((distance * 2 * 0.0033) / 3)) + if coverage ~= last_coverage then os.execute(IW .. " " .. phy .. " set coverage " .. coverage .. " > /dev/null 2>&1") - elseif alt_distance > 1 then - coverage = math.min(255, math.floor((alt_distance * 2 * 0.0033) / 3)) - os.execute(IW .. " " .. phy .. " set coverage " .. coverage .. " > /dev/null 2>&1") - elseif config.auto_distance > 0 then - os.execute(IW .. " " .. phy .. " set distance " .. config.auto_distance .. " > /dev/null 2>&1") - else - os.execute(IW .. " " .. phy .. " set distance auto > /dev/null 2>&1") + last_coverage = coverage end -- Set the RTS/CTS state depending on whether everyone can see everyone