2021-09-01 23:22:40 +00:00
|
|
|
#include "bt_debug_app.h"
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal_bt.h>
|
2021-09-01 23:22:40 +00:00
|
|
|
|
2022-01-02 22:36:42 +00:00
|
|
|
#define TAG "BtDebugApp"
|
|
|
|
|
2021-09-01 23:22:40 +00:00
|
|
|
enum BtDebugSubmenuIndex {
|
|
|
|
BtDebugSubmenuIndexCarrierTest,
|
|
|
|
BtDebugSubmenuIndexPacketTest,
|
|
|
|
};
|
|
|
|
|
|
|
|
void bt_debug_submenu_callback(void* context, uint32_t index) {
|
|
|
|
furi_assert(context);
|
|
|
|
BtDebugApp* app = context;
|
|
|
|
if(index == BtDebugSubmenuIndexCarrierTest) {
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, BtDebugAppViewCarrierTest);
|
|
|
|
} else if(index == BtDebugSubmenuIndexPacketTest) {
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, BtDebugAppViewPacketTest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t bt_debug_exit(void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-09-01 23:22:40 +00:00
|
|
|
return VIEW_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t bt_debug_start_view(void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-09-01 23:22:40 +00:00
|
|
|
return BtDebugAppViewSubmenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
BtDebugApp* bt_debug_app_alloc() {
|
2022-02-18 19:53:46 +00:00
|
|
|
BtDebugApp* app = malloc(sizeof(BtDebugApp));
|
2021-09-15 16:58:32 +00:00
|
|
|
|
|
|
|
// Load settings
|
|
|
|
bt_settings_load(&app->settings);
|
|
|
|
|
2021-09-01 23:22:40 +00:00
|
|
|
// Gui
|
|
|
|
app->gui = furi_record_open("gui");
|
|
|
|
|
|
|
|
// View dispatcher
|
|
|
|
app->view_dispatcher = view_dispatcher_alloc();
|
|
|
|
view_dispatcher_enable_queue(app->view_dispatcher);
|
|
|
|
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
|
|
|
|
|
|
|
// Views
|
|
|
|
app->submenu = submenu_alloc();
|
|
|
|
submenu_add_item(
|
|
|
|
app->submenu,
|
|
|
|
"Carrier test",
|
|
|
|
BtDebugSubmenuIndexCarrierTest,
|
|
|
|
bt_debug_submenu_callback,
|
|
|
|
app);
|
|
|
|
submenu_add_item(
|
|
|
|
app->submenu, "Packet test", BtDebugSubmenuIndexPacketTest, bt_debug_submenu_callback, app);
|
|
|
|
view_set_previous_callback(submenu_get_view(app->submenu), bt_debug_exit);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
app->view_dispatcher, BtDebugAppViewSubmenu, submenu_get_view(app->submenu));
|
|
|
|
app->bt_carrier_test = bt_carrier_test_alloc();
|
|
|
|
view_set_previous_callback(
|
|
|
|
bt_carrier_test_get_view(app->bt_carrier_test), bt_debug_start_view);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
app->view_dispatcher,
|
|
|
|
BtDebugAppViewCarrierTest,
|
|
|
|
bt_carrier_test_get_view(app->bt_carrier_test));
|
|
|
|
app->bt_packet_test = bt_packet_test_alloc();
|
|
|
|
view_set_previous_callback(bt_packet_test_get_view(app->bt_packet_test), bt_debug_start_view);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
app->view_dispatcher,
|
|
|
|
BtDebugAppViewPacketTest,
|
|
|
|
bt_packet_test_get_view(app->bt_packet_test));
|
|
|
|
|
|
|
|
// Switch to menu
|
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, BtDebugAppViewSubmenu);
|
|
|
|
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bt_debug_app_free(BtDebugApp* app) {
|
|
|
|
furi_assert(app);
|
|
|
|
|
|
|
|
// Free views
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, BtDebugAppViewSubmenu);
|
|
|
|
submenu_free(app->submenu);
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, BtDebugAppViewCarrierTest);
|
|
|
|
bt_carrier_test_free(app->bt_carrier_test);
|
|
|
|
view_dispatcher_remove_view(app->view_dispatcher, BtDebugAppViewPacketTest);
|
|
|
|
bt_packet_test_free(app->bt_packet_test);
|
|
|
|
view_dispatcher_free(app->view_dispatcher);
|
|
|
|
|
|
|
|
// Close gui record
|
|
|
|
furi_record_close("gui");
|
|
|
|
app->gui = NULL;
|
|
|
|
|
|
|
|
// Free rest
|
|
|
|
free(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t bt_debug_app(void* p) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(p);
|
2022-01-02 22:36:42 +00:00
|
|
|
if(furi_hal_bt_get_radio_stack() != FuriHalBtStackHciLayer) {
|
|
|
|
FURI_LOG_E(TAG, "Incorrect radio stack, replace with HciLayer for tests.");
|
|
|
|
DialogsApp* dialogs = furi_record_open("dialogs");
|
|
|
|
dialog_message_show_storage_error(dialogs, "Incorrect\nRadioStack");
|
|
|
|
return 255;
|
|
|
|
}
|
|
|
|
|
2021-09-01 23:22:40 +00:00
|
|
|
BtDebugApp* app = bt_debug_app_alloc();
|
2021-09-15 16:58:32 +00:00
|
|
|
// Stop advertising
|
|
|
|
furi_hal_bt_stop_advertising();
|
|
|
|
|
2021-09-01 23:22:40 +00:00
|
|
|
view_dispatcher_run(app->view_dispatcher);
|
2021-09-15 16:58:32 +00:00
|
|
|
|
|
|
|
// Restart advertising
|
|
|
|
if(app->settings.enabled) {
|
|
|
|
furi_hal_bt_start_advertising();
|
|
|
|
}
|
2021-09-01 23:22:40 +00:00
|
|
|
bt_debug_app_free(app);
|
|
|
|
return 0;
|
|
|
|
}
|