some fixes

This commit is contained in:
Egor
2025-01-06 00:02:55 -08:00
parent 83d580c2c4
commit 8e48f63cbe
3 changed files with 38 additions and 10 deletions

View File

@@ -55,6 +55,7 @@ build_flags =
-DDEFAULT_RX=916 -DDEFAULT_RX=916
-DDEFAULT_TX=915 -DDEFAULT_TX=915
-DDEFAULT_LORA_ENABLED=true -DDEFAULT_LORA_ENABLED=true
-DDEFAULT_LORA_TX_POWER=22
[env:heltec_wifi_lora_32_V3-OSD] [env:heltec_wifi_lora_32_V3-OSD]
platform = espressif32 platform = espressif32

View File

@@ -5,6 +5,24 @@ import traceback
import time import time
import os import os
def printxy(x, y, text):
"""
Print text at a specific (x, y) coordinate in the console.
:param x: Column number (1-based)
:param y: Row number (1-based)
:param text: The text to print
"""
# ANSI escape code to move the cursor to (y, x)
print(f"\033[{y};{x}H{text}", end="", flush=True)
def bar_draw(x,y,rssi,max_height=20,symbol="#"):
normalized = rssi / (rssi + 1e-6) # Normalize to 0-1
height = int(normalized * max_height)
for i in range(max_height):
printxy(x,y-i," ")
for i in range(height):
printxy(x,y-i,symbol)
def ascii_bar_chart(data, start_freq, step, max_height=20, symbol='#'): def ascii_bar_chart(data, start_freq, step, max_height=20, symbol='#'):
""" """
Converts an array of RSSI values into an ASCII vertical bar chart with RSSI labels on the left and MHz labels under every 5th step. Converts an array of RSSI values into an ASCII vertical bar chart with RSSI labels on the left and MHz labels under every 5th step.
@@ -30,8 +48,8 @@ def ascii_bar_chart(data, start_freq, step, max_height=20, symbol='#'):
f"{(start_freq + step * i) / 1e6:.0f}" if i % 5 == 0 else "" f"{(start_freq + step * i) / 1e6:.0f}" if i % 5 == 0 else ""
for i in range(len(data)) for i in range(len(data))
] ]
print(" " * 8 + '-' * len(data)) # Bar separator print(" " * 9 + '-' * len(data)) # Bar separator
x_axis = " " * 8 x_axis = " " * 9
printed = 0 printed = 0
previous_label = "" previous_label = ""
for i, label in enumerate(freq_labels): for i, label in enumerate(freq_labels):
@@ -44,6 +62,7 @@ def ascii_bar_chart(data, start_freq, step, max_height=20, symbol='#'):
x_axis += "|" # No space between bars x_axis += "|" # No space between bars
printed += 1 printed += 1
print(x_axis) print(x_axis)
init=True
async def read_samples_async(sdr, fft_size): async def read_samples_async(sdr, fft_size):
""" """
@@ -51,7 +70,7 @@ async def read_samples_async(sdr, fft_size):
""" """
return await asyncio.to_thread(sdr.read_samples, fft_size) return await asyncio.to_thread(sdr.read_samples, fft_size)
async def scan_frequency_range(start_freq, end_freq, step, sdr1, sdr2, fft_size=2*1024): async def scan_frequency_range(start_freq, end_freq, step, sdr1, sdr2, fft_size=1024*4):
""" """
Scans a frequency range using two RTL-SDR devices and calculates RSSI for each frequency. Scans a frequency range using two RTL-SDR devices and calculates RSSI for each frequency.
""" """
@@ -59,6 +78,9 @@ async def scan_frequency_range(start_freq, end_freq, step, sdr1, sdr2, fft_size=
rssi_values1 = [] rssi_values1 = []
rssi_values2 = [] rssi_values2 = []
x=9
y=20
for freq in center_frequencies: for freq in center_frequencies:
sdr1.center_freq = freq sdr1.center_freq = freq
sdr2.center_freq = freq sdr2.center_freq = freq
@@ -77,10 +99,13 @@ async def scan_frequency_range(start_freq, end_freq, step, sdr1, sdr2, fft_size=
power_spectrum2 = np.abs(np.fft.fft(samples2))**2 power_spectrum2 = np.abs(np.fft.fft(samples2))**2
power_db1 = 10 * np.log10(power_spectrum1 + 1e-6) # Convert to dB power_db1 = 10 * np.log10(power_spectrum1 + 1e-6) # Convert to dB
power_db2 = 10 * np.log10(power_spectrum2 + 1e-6) # Convert to dB power_db2 = 10 * np.log10(power_spectrum2 + 1e-6) # Convert to dB
avg_rssi1 = np.percentile(power_db1, 90) # 90th percentile RSSI for this frequency avg_rssi1 = np.percentile(power_db1, 85) # 90th percentile RSSI for this frequency
avg_rssi2 = np.percentile(power_db2, 90) # 90th percentile RSSI for this frequency avg_rssi2 = np.percentile(power_db2, 85) # 90th percentile RSSI for this frequency
rssi_values1.append(avg_rssi1) rssi_values1.append(avg_rssi1)
#bar_draw(x,y,avg_rssi1,20,"#")
rssi_values2.append(avg_rssi2) rssi_values2.append(avg_rssi2)
#bar_draw(x,y+24,avg_rssi2,20,"#")
x=x+1
return rssi_values1, rssi_values2 return rssi_values1, rssi_values2
@@ -100,8 +125,8 @@ def process_samples(samples):
async def main(): async def main():
# Frequency range in Hz # Frequency range in Hz
start_freq = 860e6 # 800 MHz start_freq = 880e6 # 800 MHz
end_freq = 1060e6 # 900 MHz end_freq = 960e6 # 900 MHz
step = 1e6 # 1 MHz steps step = 1e6 # 1 MHz steps
# Initialize two RTL-SDR devices # Initialize two RTL-SDR devices
@@ -115,7 +140,7 @@ async def main():
# Set parameters for both devices # Set parameters for both devices
for sdr in [sdr1, sdr2]: for sdr in [sdr1, sdr2]:
sdr.sample_rate = 2.048e6 # 2.048 MSPS sdr.sample_rate = 2.048e6 # 2.048 MSPS
sdr.gain = 10 # Adjust gain as needed sdr.gain = 40 # Adjust gain as needed
try: try:
while True: while True:

View File

@@ -32,6 +32,7 @@
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/task.h> #include <freertos/task.h>
#include <unordered_map> #include <unordered_map>
#include <unordered_set>
#include "WIFI_SERVER.h" #include "WIFI_SERVER.h"
@@ -153,7 +154,8 @@ typedef enum
// String SCAN_RANGES = String("850..890,920..950"); // String SCAN_RANGES = String("850..890,920..950");
String SCAN_RANGES = ""; String SCAN_RANGES = "";
std::unordered_map<int, bool> ignoredFreq = {/*{916, true}, {915, true}*/}; std::unordered_set<int> ignoredFreq = {/*{916, true}, {915, true}*/};
std::unordered_set<int> frAlwaysShow = {915};
size_t scan_pages_sz = 0; size_t scan_pages_sz = 0;
ScanPage *scan_pages; ScanPage *scan_pages;
@@ -2279,7 +2281,7 @@ std::unordered_map<int, int16_t> findMaxRssi(int16_t *rssis, uint32_t *freqs_khz
if (maxRssiPerMHz.find(freq_mhz) == maxRssiPerMHz.end() || if (maxRssiPerMHz.find(freq_mhz) == maxRssiPerMHz.end() ||
maxRssiPerMHz[freq_mhz] < rssi) maxRssiPerMHz[freq_mhz] < rssi)
{ {
if (abs(rssi) <= level) if (abs(rssi) <= level || frAlwaysShow.find(freq_mhz) != frAlwaysShow.end())
{ {
maxRssiPerMHz[freq_mhz] = rssi; maxRssiPerMHz[freq_mhz] = rssi;
} }