From 8e48f63cbe11eb17342d7c898ee9be4d4492f46b Mon Sep 17 00:00:00 2001 From: Egor Date: Mon, 6 Jan 2025 00:02:55 -0800 Subject: [PATCH] some fixes --- platformio.ini | 1 + rtl/rtl-scanner.py | 41 +++++++++++++++++++++++++++++++++-------- src/main.cpp | 6 ++++-- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7429ca6..81721e3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -55,6 +55,7 @@ build_flags = -DDEFAULT_RX=916 -DDEFAULT_TX=915 -DDEFAULT_LORA_ENABLED=true + -DDEFAULT_LORA_TX_POWER=22 [env:heltec_wifi_lora_32_V3-OSD] platform = espressif32 diff --git a/rtl/rtl-scanner.py b/rtl/rtl-scanner.py index 538f00c..0a4800e 100644 --- a/rtl/rtl-scanner.py +++ b/rtl/rtl-scanner.py @@ -5,6 +5,24 @@ import traceback import time 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='#'): """ 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 "" for i in range(len(data)) ] - print(" " * 8 + '-' * len(data)) # Bar separator - x_axis = " " * 8 + print(" " * 9 + '-' * len(data)) # Bar separator + x_axis = " " * 9 printed = 0 previous_label = "" 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 printed += 1 print(x_axis) + init=True 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) -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. """ @@ -59,6 +78,9 @@ async def scan_frequency_range(start_freq, end_freq, step, sdr1, sdr2, fft_size= rssi_values1 = [] rssi_values2 = [] + x=9 + y=20 + for freq in center_frequencies: sdr1.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_db1 = 10 * np.log10(power_spectrum1 + 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_rssi2 = np.percentile(power_db2, 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, 85) # 90th percentile RSSI for this frequency rssi_values1.append(avg_rssi1) + #bar_draw(x,y,avg_rssi1,20,"#") rssi_values2.append(avg_rssi2) + #bar_draw(x,y+24,avg_rssi2,20,"#") + x=x+1 return rssi_values1, rssi_values2 @@ -100,8 +125,8 @@ def process_samples(samples): async def main(): # Frequency range in Hz - start_freq = 860e6 # 800 MHz - end_freq = 1060e6 # 900 MHz + start_freq = 880e6 # 800 MHz + end_freq = 960e6 # 900 MHz step = 1e6 # 1 MHz steps # Initialize two RTL-SDR devices @@ -115,7 +140,7 @@ async def main(): # Set parameters for both devices for sdr in [sdr1, sdr2]: sdr.sample_rate = 2.048e6 # 2.048 MSPS - sdr.gain = 10 # Adjust gain as needed + sdr.gain = 40 # Adjust gain as needed try: while True: diff --git a/src/main.cpp b/src/main.cpp index 51bce55..6c0a1f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "WIFI_SERVER.h" @@ -153,7 +154,8 @@ typedef enum // String SCAN_RANGES = String("850..890,920..950"); String SCAN_RANGES = ""; -std::unordered_map ignoredFreq = {/*{916, true}, {915, true}*/}; +std::unordered_set ignoredFreq = {/*{916, true}, {915, true}*/}; +std::unordered_set frAlwaysShow = {915}; size_t scan_pages_sz = 0; ScanPage *scan_pages; @@ -2279,7 +2281,7 @@ std::unordered_map findMaxRssi(int16_t *rssis, uint32_t *freqs_khz if (maxRssiPerMHz.find(freq_mhz) == maxRssiPerMHz.end() || maxRssiPerMHz[freq_mhz] < rssi) { - if (abs(rssi) <= level) + if (abs(rssi) <= level || frAlwaysShow.find(freq_mhz) != frAlwaysShow.end()) { maxRssiPerMHz[freq_mhz] = rssi; }