Improve LQM distance management 02/11/2023 (#705)

This commit is contained in:
Tim Wilkinson 2023-02-11 11:43:36 -08:00 committed by GitHub
parent 160345187d
commit c70a23f7a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 24 deletions

View File

@ -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