|
@@ -8,290 +8,405 @@
|
|
|
|
|
|
|
|
#define TAG "RadioScannerApp"
|
|
#define TAG "RadioScannerApp"
|
|
|
|
|
|
|
|
|
|
+#define RADIO_SCANNER_DEFAULT_FREQ 433920000
|
|
|
|
|
+#define RADIO_SCANNER_DEFAULT_RSSI (-100.0f)
|
|
|
|
|
+#define RADIO_SCANNER_DEFAULT_SENSITIVITY (-85.0f)
|
|
|
|
|
+#define RADIO_SCANNER_BUFFER_SZ 32
|
|
|
|
|
+
|
|
|
#define SUBGHZ_FREQUENCY_MIN 300000000
|
|
#define SUBGHZ_FREQUENCY_MIN 300000000
|
|
|
#define SUBGHZ_FREQUENCY_MAX 928000000
|
|
#define SUBGHZ_FREQUENCY_MAX 928000000
|
|
|
#define SUBGHZ_FREQUENCY_STEP 10000
|
|
#define SUBGHZ_FREQUENCY_STEP 10000
|
|
|
#define SUBGHZ_DEVICE_NAME "cc1101_int"
|
|
#define SUBGHZ_DEVICE_NAME "cc1101_int"
|
|
|
|
|
|
|
|
static void radio_scanner_draw_callback(Canvas* canvas, void* context) {
|
|
static void radio_scanner_draw_callback(Canvas* canvas, void* context) {
|
|
|
|
|
+ furi_assert(canvas);
|
|
|
|
|
+ furi_assert(context);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_draw_callback");
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_draw_callback");
|
|
|
- RadioScannerApp* app = context;
|
|
|
|
|
|
|
+#endif
|
|
|
|
|
+ RadioScannerApp* app = (RadioScannerApp*)context;
|
|
|
canvas_clear(canvas);
|
|
canvas_clear(canvas);
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Radio Scanner");
|
|
canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Radio Scanner");
|
|
|
|
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
- char freq_str[32];
|
|
|
|
|
- snprintf(freq_str, sizeof(freq_str), "Freq: %.2f MHz", (double)app->frequency / 1000000);
|
|
|
|
|
|
|
+ char freq_str[RADIO_SCANNER_BUFFER_SZ + 1] = {0};
|
|
|
|
|
+ snprintf(freq_str, RADIO_SCANNER_BUFFER_SZ, "Freq: %.2f MHz", (double)app->frequency / 1000000);
|
|
|
canvas_draw_str_aligned(canvas, 64, 18, AlignCenter, AlignTop, freq_str);
|
|
canvas_draw_str_aligned(canvas, 64, 18, AlignCenter, AlignTop, freq_str);
|
|
|
|
|
|
|
|
- char rssi_str[32];
|
|
|
|
|
- snprintf(rssi_str, sizeof(rssi_str), "RSSI: %.2f", (double)app->rssi);
|
|
|
|
|
|
|
+ char rssi_str[RADIO_SCANNER_BUFFER_SZ + 1] = {0};
|
|
|
|
|
+ snprintf(rssi_str, RADIO_SCANNER_BUFFER_SZ, "RSSI: %.2f", (double)app->rssi);
|
|
|
canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignTop, rssi_str);
|
|
canvas_draw_str_aligned(canvas, 64, 30, AlignCenter, AlignTop, rssi_str);
|
|
|
|
|
|
|
|
- char sensitivity_str[32];
|
|
|
|
|
- snprintf(sensitivity_str, sizeof(sensitivity_str), "Sens: %.2f", (double)app->sensitivity);
|
|
|
|
|
|
|
+ char sensitivity_str[RADIO_SCANNER_BUFFER_SZ + 1] = {0};
|
|
|
|
|
+ snprintf(sensitivity_str, RADIO_SCANNER_BUFFER_SZ, "Sens: %.2f", (double)app->sensitivity);
|
|
|
canvas_draw_str_aligned(canvas, 64, 42, AlignCenter, AlignTop, sensitivity_str);
|
|
canvas_draw_str_aligned(canvas, 64, 42, AlignCenter, AlignTop, sensitivity_str);
|
|
|
|
|
|
|
|
canvas_draw_str_aligned(
|
|
canvas_draw_str_aligned(
|
|
|
canvas, 64, 54, AlignCenter, AlignTop, app->scanning ? "Scanning..." : "Locked");
|
|
canvas, 64, 54, AlignCenter, AlignTop, app->scanning ? "Scanning..." : "Locked");
|
|
|
-
|
|
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_draw_callback");
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_draw_callback");
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void radio_scanner_input_callback(InputEvent* input_event, void* context) {
|
|
static void radio_scanner_input_callback(InputEvent* input_event, void* context) {
|
|
|
furi_assert(context);
|
|
furi_assert(context);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_input_callback");
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_input_callback");
|
|
|
FURI_LOG_D(TAG, "Input event: type=%d, key=%d", input_event->type, input_event->key);
|
|
FURI_LOG_D(TAG, "Input event: type=%d, key=%d", input_event->type, input_event->key);
|
|
|
|
|
+#endif
|
|
|
FuriMessageQueue* event_queue = context;
|
|
FuriMessageQueue* event_queue = context;
|
|
|
furi_message_queue_put(event_queue, input_event, FuriWaitForever);
|
|
furi_message_queue_put(event_queue, input_event, FuriWaitForever);
|
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_input_callback");
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_input_callback");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void radio_scanner_rx_callback(const void* data, size_t size, void* context) {
|
|
static void radio_scanner_rx_callback(const void* data, size_t size, void* context) {
|
|
|
- (void)data;
|
|
|
|
|
- (void)context;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ UNUSED(data);
|
|
|
|
|
+ UNUSED(context);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "radio_scanner_rx_callback called with size: %zu", size);
|
|
FURI_LOG_D(TAG, "radio_scanner_rx_callback called with size: %zu", size);
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void radio_scanner_update_rssi(RadioScannerApp* app) {
|
|
static void radio_scanner_update_rssi(RadioScannerApp* app) {
|
|
|
|
|
+ furi_assert(app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_update_rssi");
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_update_rssi");
|
|
|
|
|
+#endif
|
|
|
if(app->radio_device) {
|
|
if(app->radio_device) {
|
|
|
app->rssi = subghz_devices_get_rssi(app->radio_device);
|
|
app->rssi = subghz_devices_get_rssi(app->radio_device);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Updated RSSI: %f", (double)app->rssi);
|
|
FURI_LOG_D(TAG, "Updated RSSI: %f", (double)app->rssi);
|
|
|
|
|
+#endif
|
|
|
} else {
|
|
} else {
|
|
|
FURI_LOG_E(TAG, "Radio device is NULL");
|
|
FURI_LOG_E(TAG, "Radio device is NULL");
|
|
|
- app->rssi = -127.0f;
|
|
|
|
|
|
|
+ app->rssi = RADIO_SCANNER_DEFAULT_RSSI;
|
|
|
}
|
|
}
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_update_rssi");
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_update_rssi");
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static bool radio_scanner_init_subghz(RadioScannerApp* app) {
|
|
static bool radio_scanner_init_subghz(RadioScannerApp* app) {
|
|
|
|
|
+ furi_assert(app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_init_subghz");
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_init_subghz");
|
|
|
|
|
+#endif
|
|
|
subghz_devices_init();
|
|
subghz_devices_init();
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "SubGHz devices initialized");
|
|
FURI_LOG_D(TAG, "SubGHz devices initialized");
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
const SubGhzDevice* device = subghz_devices_get_by_name(SUBGHZ_DEVICE_NAME);
|
|
const SubGhzDevice* device = subghz_devices_get_by_name(SUBGHZ_DEVICE_NAME);
|
|
|
if(!device) {
|
|
if(!device) {
|
|
|
FURI_LOG_E(TAG, "Failed to get SubGhzDevice");
|
|
FURI_LOG_E(TAG, "Failed to get SubGhzDevice");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- FURI_LOG_D(TAG, "SubGhzDevice obtained: %s", subghz_devices_get_name(device));
|
|
|
|
|
|
|
+ FURI_LOG_I(TAG, "SubGhzDevice obtained: %s", subghz_devices_get_name(device));
|
|
|
|
|
|
|
|
app->radio_device = device;
|
|
app->radio_device = device;
|
|
|
|
|
|
|
|
subghz_devices_begin(device);
|
|
subghz_devices_begin(device);
|
|
|
|
|
+ subghz_devices_reset(device);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "SubGhzDevice begun");
|
|
FURI_LOG_D(TAG, "SubGhzDevice begun");
|
|
|
-
|
|
|
|
|
|
|
+#endif
|
|
|
if(!subghz_devices_is_frequency_valid(device, app->frequency)) {
|
|
if(!subghz_devices_is_frequency_valid(device, app->frequency)) {
|
|
|
FURI_LOG_E(TAG, "Invalid frequency: %lu", app->frequency);
|
|
FURI_LOG_E(TAG, "Invalid frequency: %lu", app->frequency);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Frequency is valid: %lu", app->frequency);
|
|
FURI_LOG_D(TAG, "Frequency is valid: %lu", app->frequency);
|
|
|
-
|
|
|
|
|
|
|
+#endif
|
|
|
subghz_devices_load_preset(device, FuriHalSubGhzPreset2FSKDev238Async, NULL);
|
|
subghz_devices_load_preset(device, FuriHalSubGhzPreset2FSKDev238Async, NULL);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Preset loaded");
|
|
FURI_LOG_D(TAG, "Preset loaded");
|
|
|
-
|
|
|
|
|
|
|
+#endif
|
|
|
subghz_devices_set_frequency(device, app->frequency);
|
|
subghz_devices_set_frequency(device, app->frequency);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Frequency set to %lu", app->frequency);
|
|
FURI_LOG_D(TAG, "Frequency set to %lu", app->frequency);
|
|
|
-
|
|
|
|
|
|
|
+#endif
|
|
|
subghz_devices_start_async_rx(device, radio_scanner_rx_callback, app);
|
|
subghz_devices_start_async_rx(device, radio_scanner_rx_callback, app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Asynchronous RX started");
|
|
FURI_LOG_D(TAG, "Asynchronous RX started");
|
|
|
-
|
|
|
|
|
|
|
+#endif
|
|
|
if(furi_hal_speaker_acquire(30)) {
|
|
if(furi_hal_speaker_acquire(30)) {
|
|
|
app->speaker_acquired = true;
|
|
app->speaker_acquired = true;
|
|
|
subghz_devices_set_async_mirror_pin(device, &gpio_speaker);
|
|
subghz_devices_set_async_mirror_pin(device, &gpio_speaker);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Speaker acquired and async mirror pin set");
|
|
FURI_LOG_D(TAG, "Speaker acquired and async mirror pin set");
|
|
|
|
|
+#endif
|
|
|
} else {
|
|
} else {
|
|
|
app->speaker_acquired = false;
|
|
app->speaker_acquired = false;
|
|
|
FURI_LOG_E(TAG, "Failed to acquire speaker");
|
|
FURI_LOG_E(TAG, "Failed to acquire speaker");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_init_subghz");
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_init_subghz");
|
|
|
|
|
+#endif
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void radio_scanner_process_scanning(RadioScannerApp* app) {
|
|
static void radio_scanner_process_scanning(RadioScannerApp* app) {
|
|
|
|
|
+ furi_assert(app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_process_scanning");
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_process_scanning");
|
|
|
|
|
+#endif
|
|
|
radio_scanner_update_rssi(app);
|
|
radio_scanner_update_rssi(app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "RSSI after update: %f", (double)app->rssi);
|
|
FURI_LOG_D(TAG, "RSSI after update: %f", (double)app->rssi);
|
|
|
|
|
+#endif
|
|
|
bool signal_detected = (app->rssi > app->sensitivity);
|
|
bool signal_detected = (app->rssi > app->sensitivity);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Signal detected: %d", signal_detected);
|
|
FURI_LOG_D(TAG, "Signal detected: %d", signal_detected);
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
if(signal_detected) {
|
|
if(signal_detected) {
|
|
|
if(app->scanning) {
|
|
if(app->scanning) {
|
|
|
app->scanning = false;
|
|
app->scanning = false;
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Scanning stopped");
|
|
FURI_LOG_D(TAG, "Scanning stopped");
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
if(!app->scanning) {
|
|
if(!app->scanning) {
|
|
|
app->scanning = true;
|
|
app->scanning = true;
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Scanning started");
|
|
FURI_LOG_D(TAG, "Scanning started");
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(app->scanning) {
|
|
|
|
|
- uint32_t new_frequency = (app->scan_direction == ScanDirectionUp) ?
|
|
|
|
|
- app->frequency + SUBGHZ_FREQUENCY_STEP :
|
|
|
|
|
- app->frequency - SUBGHZ_FREQUENCY_STEP;
|
|
|
|
|
-
|
|
|
|
|
- if(!subghz_devices_is_frequency_valid(app->radio_device, new_frequency)) {
|
|
|
|
|
- if(app->scan_direction == ScanDirectionUp) {
|
|
|
|
|
- if(new_frequency < 387000000) {
|
|
|
|
|
- new_frequency = 387000000;
|
|
|
|
|
- } else if(new_frequency < 779000000) {
|
|
|
|
|
- new_frequency = 779000000;
|
|
|
|
|
- } else if(new_frequency > 928000000) {
|
|
|
|
|
- new_frequency = 300000000;
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- if(new_frequency > 464000000) {
|
|
|
|
|
- new_frequency = 464000000;
|
|
|
|
|
- } else if(new_frequency > 348000000) {
|
|
|
|
|
- new_frequency = 348000000;
|
|
|
|
|
- } else if(new_frequency < 300000000) {
|
|
|
|
|
- new_frequency = 928000000;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if(!app->scanning) {
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "Exit radio_scanner_process_scanning");
|
|
|
|
|
+ return;
|
|
|
|
|
+#endif
|
|
|
|
|
+ }
|
|
|
|
|
+ uint32_t new_frequency = (app->scan_direction == ScanDirectionUp) ?
|
|
|
|
|
+ app->frequency + SUBGHZ_FREQUENCY_STEP :
|
|
|
|
|
+ app->frequency - SUBGHZ_FREQUENCY_STEP;
|
|
|
|
|
+
|
|
|
|
|
+ if(!subghz_devices_is_frequency_valid(app->radio_device, new_frequency)) {
|
|
|
|
|
+ if(app->scan_direction == ScanDirectionUp) {
|
|
|
|
|
+ if(new_frequency < 387000000) {
|
|
|
|
|
+ new_frequency = 387000000;
|
|
|
|
|
+ } else if(new_frequency < 779000000) {
|
|
|
|
|
+ new_frequency = 779000000;
|
|
|
|
|
+ } else if(new_frequency > SUBGHZ_FREQUENCY_MAX) {
|
|
|
|
|
+ new_frequency = SUBGHZ_FREQUENCY_MIN;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if(new_frequency > 464000000) {
|
|
|
|
|
+ new_frequency = 464000000;
|
|
|
|
|
+ } else if(new_frequency > 348000000) {
|
|
|
|
|
+ new_frequency = 348000000;
|
|
|
|
|
+ } else if(new_frequency < SUBGHZ_FREQUENCY_MIN) {
|
|
|
|
|
+ new_frequency = SUBGHZ_FREQUENCY_MAX;
|
|
|
}
|
|
}
|
|
|
- FURI_LOG_D(TAG, "Adjusted frequency to next valid range: %lu", new_frequency);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "Adjusted frequency to next valid range: %lu", new_frequency);
|
|
|
|
|
+#endif
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- subghz_devices_stop_async_rx(app->radio_device);
|
|
|
|
|
- FURI_LOG_D(TAG, "Asynchronous RX stopped");
|
|
|
|
|
-
|
|
|
|
|
- subghz_devices_idle(app->radio_device);
|
|
|
|
|
- FURI_LOG_D(TAG, "Device set to idle");
|
|
|
|
|
-
|
|
|
|
|
- app->frequency = new_frequency;
|
|
|
|
|
- subghz_devices_set_frequency(app->radio_device, app->frequency);
|
|
|
|
|
- FURI_LOG_D(TAG, "Frequency set to %lu", app->frequency);
|
|
|
|
|
|
|
+ subghz_devices_flush_rx(app->radio_device);
|
|
|
|
|
+ subghz_devices_stop_async_rx(app->radio_device);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "Asynchronous RX stopped");
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+ subghz_devices_idle(app->radio_device);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "Device set to idle");
|
|
|
|
|
+#endif
|
|
|
|
|
+ app->frequency = new_frequency;
|
|
|
|
|
+ subghz_devices_set_frequency(app->radio_device, app->frequency);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "Frequency set to %lu", app->frequency);
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
- subghz_devices_start_async_rx(app->radio_device, radio_scanner_rx_callback, app);
|
|
|
|
|
- FURI_LOG_D(TAG, "Asynchronous RX restarted");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ subghz_devices_start_async_rx(app->radio_device, radio_scanner_rx_callback, app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "Asynchronous RX restarted");
|
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_process_scanning");
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_process_scanning");
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
RadioScannerApp* radio_scanner_app_alloc() {
|
|
RadioScannerApp* radio_scanner_app_alloc() {
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_app_alloc");
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_app_alloc");
|
|
|
|
|
+#endif
|
|
|
RadioScannerApp* app = malloc(sizeof(RadioScannerApp));
|
|
RadioScannerApp* app = malloc(sizeof(RadioScannerApp));
|
|
|
if(!app) {
|
|
if(!app) {
|
|
|
FURI_LOG_E(TAG, "Failed to allocate RadioScannerApp");
|
|
FURI_LOG_E(TAG, "Failed to allocate RadioScannerApp");
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "RadioScannerApp allocated");
|
|
FURI_LOG_D(TAG, "RadioScannerApp allocated");
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
app->view_port = view_port_alloc();
|
|
app->view_port = view_port_alloc();
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "ViewPort allocated");
|
|
FURI_LOG_D(TAG, "ViewPort allocated");
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
|
app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Event queue allocated");
|
|
FURI_LOG_D(TAG, "Event queue allocated");
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
app->running = true;
|
|
app->running = true;
|
|
|
- app->frequency = 433920000;
|
|
|
|
|
- app->rssi = -100.0f;
|
|
|
|
|
- app->sensitivity = -85.0f;
|
|
|
|
|
|
|
+ app->frequency = RADIO_SCANNER_DEFAULT_FREQ;
|
|
|
|
|
+ app->rssi = RADIO_SCANNER_DEFAULT_RSSI;
|
|
|
|
|
+ app->sensitivity = RADIO_SCANNER_DEFAULT_SENSITIVITY;
|
|
|
app->scanning = true;
|
|
app->scanning = true;
|
|
|
app->scan_direction = ScanDirectionUp;
|
|
app->scan_direction = ScanDirectionUp;
|
|
|
app->speaker_acquired = false;
|
|
app->speaker_acquired = false;
|
|
|
app->radio_device = NULL;
|
|
app->radio_device = NULL;
|
|
|
|
|
|
|
|
view_port_draw_callback_set(app->view_port, radio_scanner_draw_callback, app);
|
|
view_port_draw_callback_set(app->view_port, radio_scanner_draw_callback, app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Draw callback set");
|
|
FURI_LOG_D(TAG, "Draw callback set");
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
view_port_input_callback_set(app->view_port, radio_scanner_input_callback, app->event_queue);
|
|
view_port_input_callback_set(app->view_port, radio_scanner_input_callback, app->event_queue);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Input callback set");
|
|
FURI_LOG_D(TAG, "Input callback set");
|
|
|
-
|
|
|
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_app_alloc");
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_app_alloc");
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+ app->gui = furi_record_open(RECORD_GUI);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "GUI record opened");
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+ gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "ViewPort added to GUI");
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
return app;
|
|
return app;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void radio_scanner_app_free(RadioScannerApp* app) {
|
|
void radio_scanner_app_free(RadioScannerApp* app) {
|
|
|
|
|
+ furi_assert(app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_app_free");
|
|
FURI_LOG_D(TAG, "Enter radio_scanner_app_free");
|
|
|
|
|
+#endif
|
|
|
if(app->speaker_acquired && furi_hal_speaker_is_mine()) {
|
|
if(app->speaker_acquired && furi_hal_speaker_is_mine()) {
|
|
|
subghz_devices_set_async_mirror_pin(app->radio_device, NULL);
|
|
subghz_devices_set_async_mirror_pin(app->radio_device, NULL);
|
|
|
furi_hal_speaker_release();
|
|
furi_hal_speaker_release();
|
|
|
app->speaker_acquired = false;
|
|
app->speaker_acquired = false;
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Speaker released");
|
|
FURI_LOG_D(TAG, "Speaker released");
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(app->radio_device) {
|
|
if(app->radio_device) {
|
|
|
|
|
+ subghz_devices_flush_rx(app->radio_device);
|
|
|
subghz_devices_stop_async_rx(app->radio_device);
|
|
subghz_devices_stop_async_rx(app->radio_device);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Asynchronous RX stopped");
|
|
FURI_LOG_D(TAG, "Asynchronous RX stopped");
|
|
|
|
|
+#endif
|
|
|
|
|
+ subghz_devices_idle(app->radio_device);
|
|
|
|
|
+ subghz_devices_sleep(app->radio_device);
|
|
|
subghz_devices_end(app->radio_device);
|
|
subghz_devices_end(app->radio_device);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "SubGhzDevice stopped and ended");
|
|
FURI_LOG_D(TAG, "SubGhzDevice stopped and ended");
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
subghz_devices_deinit();
|
|
subghz_devices_deinit();
|
|
|
- FURI_LOG_D(TAG, "SubGHz devices deinitialized");
|
|
|
|
|
-
|
|
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "SubGHz devices de-initialized");
|
|
|
|
|
+#endif
|
|
|
|
|
+ gui_remove_view_port(app->gui, app->view_port);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "ViewPort removed from GUI");
|
|
|
|
|
+#endif
|
|
|
view_port_free(app->view_port);
|
|
view_port_free(app->view_port);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "ViewPort freed");
|
|
FURI_LOG_D(TAG, "ViewPort freed");
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
furi_message_queue_free(app->event_queue);
|
|
furi_message_queue_free(app->event_queue);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Event queue freed");
|
|
FURI_LOG_D(TAG, "Event queue freed");
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+ furi_record_close(RECORD_GUI);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
|
|
+ FURI_LOG_D(TAG, "GUI record closed");
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
free(app);
|
|
free(app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "RadioScannerApp memory freed");
|
|
FURI_LOG_D(TAG, "RadioScannerApp memory freed");
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int32_t radio_scanner_app(void* p) {
|
|
int32_t radio_scanner_app(void* p) {
|
|
|
UNUSED(p);
|
|
UNUSED(p);
|
|
|
- FURI_LOG_D(TAG, "Enter radio_scanner_app");
|
|
|
|
|
|
|
+ FURI_LOG_I(TAG, "Enter radio_scanner_app");
|
|
|
|
|
|
|
|
RadioScannerApp* app = radio_scanner_app_alloc();
|
|
RadioScannerApp* app = radio_scanner_app_alloc();
|
|
|
if(!app) {
|
|
if(!app) {
|
|
|
FURI_LOG_E(TAG, "Failed to allocate app");
|
|
FURI_LOG_E(TAG, "Failed to allocate app");
|
|
|
- return -1;
|
|
|
|
|
|
|
+ return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Gui* gui = furi_record_open(RECORD_GUI);
|
|
|
|
|
- FURI_LOG_D(TAG, "GUI record opened");
|
|
|
|
|
-
|
|
|
|
|
- gui_add_view_port(gui, app->view_port, GuiLayerFullscreen);
|
|
|
|
|
- FURI_LOG_D(TAG, "ViewPort added to GUI");
|
|
|
|
|
-
|
|
|
|
|
if(!radio_scanner_init_subghz(app)) {
|
|
if(!radio_scanner_init_subghz(app)) {
|
|
|
FURI_LOG_E(TAG, "Failed to initialize SubGHz");
|
|
FURI_LOG_E(TAG, "Failed to initialize SubGHz");
|
|
|
radio_scanner_app_free(app);
|
|
radio_scanner_app_free(app);
|
|
|
return 255;
|
|
return 255;
|
|
|
}
|
|
}
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "SubGHz initialized successfully");
|
|
FURI_LOG_D(TAG, "SubGHz initialized successfully");
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
InputEvent event;
|
|
InputEvent event;
|
|
|
while(app->running) {
|
|
while(app->running) {
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Main loop iteration");
|
|
FURI_LOG_D(TAG, "Main loop iteration");
|
|
|
|
|
+#endif
|
|
|
if(app->scanning) {
|
|
if(app->scanning) {
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Scanning is active");
|
|
FURI_LOG_D(TAG, "Scanning is active");
|
|
|
|
|
+#endif
|
|
|
radio_scanner_process_scanning(app);
|
|
radio_scanner_process_scanning(app);
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Scanning is inactive, updating RSSI");
|
|
FURI_LOG_D(TAG, "Scanning is inactive, updating RSSI");
|
|
|
|
|
+#endif
|
|
|
radio_scanner_update_rssi(app);
|
|
radio_scanner_update_rssi(app);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Checking for input events");
|
|
FURI_LOG_D(TAG, "Checking for input events");
|
|
|
|
|
+#endif
|
|
|
if(furi_message_queue_get(app->event_queue, &event, 10) == FuriStatusOk) {
|
|
if(furi_message_queue_get(app->event_queue, &event, 10) == FuriStatusOk) {
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Input event received: type=%d, key=%d", event.type, event.key);
|
|
FURI_LOG_D(TAG, "Input event received: type=%d, key=%d", event.type, event.key);
|
|
|
|
|
+#endif
|
|
|
if(event.type == InputTypeShort) {
|
|
if(event.type == InputTypeShort) {
|
|
|
if(event.key == InputKeyOk) {
|
|
if(event.key == InputKeyOk) {
|
|
|
app->scanning = !app->scanning;
|
|
app->scanning = !app->scanning;
|
|
|
- FURI_LOG_D(TAG, "Toggled scanning: %d", app->scanning);
|
|
|
|
|
|
|
+ FURI_LOG_I(TAG, "Toggled scanning: %d", app->scanning);
|
|
|
} else if(event.key == InputKeyUp) {
|
|
} else if(event.key == InputKeyUp) {
|
|
|
app->sensitivity += 1.0f;
|
|
app->sensitivity += 1.0f;
|
|
|
- FURI_LOG_D(TAG, "Increased sensitivity: %f", (double)app->sensitivity);
|
|
|
|
|
|
|
+ FURI_LOG_I(TAG, "Increased sensitivity: %f", (double)app->sensitivity);
|
|
|
} else if(event.key == InputKeyDown) {
|
|
} else if(event.key == InputKeyDown) {
|
|
|
app->sensitivity -= 1.0f;
|
|
app->sensitivity -= 1.0f;
|
|
|
- FURI_LOG_D(TAG, "Decreased sensitivity: %f", (double)app->sensitivity);
|
|
|
|
|
|
|
+ FURI_LOG_I(TAG, "Decreased sensitivity: %f", (double)app->sensitivity);
|
|
|
} else if(event.key == InputKeyLeft) {
|
|
} else if(event.key == InputKeyLeft) {
|
|
|
app->scan_direction = ScanDirectionDown;
|
|
app->scan_direction = ScanDirectionDown;
|
|
|
- FURI_LOG_D(TAG, "Scan direction set to down");
|
|
|
|
|
|
|
+ FURI_LOG_I(TAG, "Scan direction set to down");
|
|
|
} else if(event.key == InputKeyRight) {
|
|
} else if(event.key == InputKeyRight) {
|
|
|
app->scan_direction = ScanDirectionUp;
|
|
app->scan_direction = ScanDirectionUp;
|
|
|
- FURI_LOG_D(TAG, "Scan direction set to up");
|
|
|
|
|
|
|
+ FURI_LOG_I(TAG, "Scan direction set to up");
|
|
|
} else if(event.key == InputKeyBack) {
|
|
} else if(event.key == InputKeyBack) {
|
|
|
app->running = false;
|
|
app->running = false;
|
|
|
- FURI_LOG_D(TAG, "Exiting app");
|
|
|
|
|
|
|
+ FURI_LOG_I(TAG, "Exiting app");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -300,20 +415,9 @@ int32_t radio_scanner_app(void* p) {
|
|
|
furi_delay_ms(10);
|
|
furi_delay_ms(10);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(app->speaker_acquired && furi_hal_speaker_is_mine()) {
|
|
|
|
|
- subghz_devices_set_async_mirror_pin(app->radio_device, NULL);
|
|
|
|
|
- furi_hal_speaker_release();
|
|
|
|
|
- app->speaker_acquired = false;
|
|
|
|
|
- FURI_LOG_D(TAG, "Speaker released at app exit");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- gui_remove_view_port(gui, app->view_port);
|
|
|
|
|
- FURI_LOG_D(TAG, "ViewPort removed from GUI");
|
|
|
|
|
-
|
|
|
|
|
- furi_record_close(RECORD_GUI);
|
|
|
|
|
- FURI_LOG_D(TAG, "GUI record closed");
|
|
|
|
|
-
|
|
|
|
|
radio_scanner_app_free(app);
|
|
radio_scanner_app_free(app);
|
|
|
|
|
+#ifdef FURI_DEBUG
|
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_app");
|
|
FURI_LOG_D(TAG, "Exit radio_scanner_app");
|
|
|
|
|
+#endif
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|