3GHz fixes and optimizations (#411)

This commit is contained in:
Tim Wilkinson 2022-06-24 20:24:28 -07:00 committed by GitHub
parent 4b37c6a033
commit b4c5691110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 29 deletions

View File

@ -275,17 +275,23 @@ end
local nf = iwinfo.nl80211.noise(wifiiface) or -95 local nf = iwinfo.nl80211.noise(wifiiface) or -95
local start_freq local start_freq
local end_freq
if rfband == "900" then if rfband == "900" then
start_freq = 902 start_freq = 902
end_freq = 925
html.print("const freq2chan = (f) => (f - 887) / 5;"); html.print("const freq2chan = (f) => (f - 887) / 5;");
elseif rfband == "2400" then elseif rfband == "2400" then
start_freq = 2377 start_freq = 2377
end_freq = 2477
html.print("const freq2chan = (f) => (f - 2407) / 5;"); html.print("const freq2chan = (f) => (f - 2407) / 5;");
elseif rfband == "3400" then elseif rfband == "3400" then
start_freq = 3375 -- transverted
html.print("const freq2chan = (f) => (f - 3000) / 5;"); start_freq = 5370
end_freq = 5505
html.print("const freq2chan = (f) => (f - 5000) / 5;");
else else
start_freq = 5650 start_freq = 5650
end_freq = 5925
html.print("const freq2chan = (f) => (f - 5000) / 5;"); html.print("const freq2chan = (f) => (f - 5000) / 5;");
end end
local bw local bw
@ -298,37 +304,19 @@ do
end end
bw = tonumber(bw) or 10 bw = tonumber(bw) or 10
local min_freq = math.huge local xscale = cwidth / (end_freq - start_freq)
local max_freq = 0
local min_sig = nf local min_sig = nf
local max_sig = -60 local max_sig = -60
local i = 1 local i = 1
while i < #samples
do
local t = samples:byte(i)
local l = samples:byte(i + 1) * 256 + samples:byte(i + 2)
if t == 1 then
local freq = samples:byte(i + 4) * 256 + samples:byte(i + 5)
if freq >= start_freq then
if freq < min_freq then
min_freq = freq
elseif freq > max_freq then
max_freq = freq
end
end
end
i = i + 3 + l
end
html.write("const p = [") html.write("const p = [")
i = 1
while i < #samples while i < #samples
do do
local t = samples:byte(i) local t = samples:byte(i)
local l = samples:byte(i + 1) * 256 + samples:byte(i + 2) local l = samples:byte(i + 1) * 256 + samples:byte(i + 2)
if t == 1 then if t == 1 then
local max_exp = samples:byte(i + 3) local max_exp = samples:byte(i + 3)
local freq = samples:byte(i + 4) * 256 + samples:byte(i + 5) - bw / 2 local freq = samples:byte(i + 4) * 256 + samples:byte(i + 5)
if freq >= start_freq then if freq >= start_freq and freq <= end_freq then
local rssi = u8tos8(samples:byte(i + 6)) local rssi = u8tos8(samples:byte(i + 6))
local noise = u8tos8(samples:byte(i + 7)) local noise = u8tos8(samples:byte(i + 7))
local datasqsum = 0 local datasqsum = 0
@ -348,7 +336,7 @@ do
do do
local data = v[dptr] local data = v[dptr]
local sig = noise + rssi + 20 * math.log10(data) - datasqsum local sig = noise + rssi + 20 * math.log10(data) - datasqsum
local fr = freq - min_freq + (bw * dptr / dlen) local fr = freq + bw * (dptr / dlen - 0.5) - start_freq
if sig >= -125 then if sig >= -125 then
if sig < min_sig then if sig < min_sig then
min_sig = sig min_sig = sig
@ -356,7 +344,7 @@ do
if sig > max_sig then if sig > max_sig then
max_sig = sig max_sig = sig
end end
html.write(math.floor(fr) .. "," .. math.floor(-sig * 4) .. ",") html.write(math.floor(fr * xscale) .. "," .. math.floor(-sig * 4) .. ",")
end end
end end
end end
@ -364,7 +352,6 @@ do
i = i + 3 + l i = i + 3 + l
end end
html.print("-1,-1];"); html.print("-1,-1];");
html.print("const xscale = " .. (cwidth / (max_freq - min_freq)) .. ";")
html.print("const yscale = " .. (-cheight / (max_sig - min_sig) / 4) .. ";") html.print("const yscale = " .. (-cheight / (max_sig - min_sig) / 4) .. ";")
html.print("const ytran = " .. (-max_sig * 4) .. ";") html.print("const ytran = " .. (-max_sig * 4) .. ";")
html.print([[ html.print([[
@ -372,7 +359,7 @@ html.print([[
const d = img.data; const d = img.data;
for (let i = 0; i < p.length; i += 2) { for (let i = 0; i < p.length; i += 2) {
const sig = p[i+1]; const sig = p[i+1];
const idx = 4 * (Math.floor(xscale * p[i]) + ]] .. cwidth .. [[ * Math.floor(yscale * (ytran - sig))); const idx = 4 * (p[i] + ]] .. cwidth .. [[ * Math.floor(yscale * (ytran - sig)));
if (sig < ]] .. (-4 * nf) .. [[) { if (sig < ]] .. (-4 * nf) .. [[) {
d[idx] = 0; d[idx] = 0;
d[idx+1] = 0; d[idx+1] = 0;
@ -398,8 +385,8 @@ html.print([[
ctx.font = "12px Arial"; ctx.font = "12px Arial";
ctx.textAlign = "center"; ctx.textAlign = "center";
ctx.beginPath() ctx.beginPath()
for (let f = ]] .. start_freq .. [[; f < ]] .. (max_freq + bw) .. [[; f += 10) { for (let f = ]] .. start_freq .. [[; f < ]] .. end_freq .. [[; f += 10) {
const x = Math.floor((f - ]] .. min_freq .. [[) * xscale); const x = Math.floor((f - ]] .. start_freq .. [[) * ]] .. xscale .. [[);
ctx.moveTo(x, 0); ctx.moveTo(x, 0);
ctx.lineTo(x, ]] .. (cheight - 20) .. [[); ctx.lineTo(x, ]] .. (cheight - 20) .. [[);
ctx.fillText("" + freq2chan(f), x, ]] .. cheight - 4 .. [[); ctx.fillText("" + freq2chan(f), x, ]] .. cheight - 4 .. [[);