Просмотр исходного кода

Switched to using second serial channel to receive packets

tcpassos 2 лет назад
Родитель
Сommit
5b4234a648

+ 22 - 16
applications/plugins/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c

@@ -1,17 +1,5 @@
 #include "../wifi_marauder_app_i.h"
 
-void wifi_marauder_print_message(uint8_t* buf, size_t len, WifiMarauderApp* app) {
-    // If text box store gets too big, then truncate it
-    app->text_box_store_strlen += len;
-    if(app->text_box_store_strlen >= WIFI_MARAUDER_TEXT_BOX_STORE_SIZE - 1) {
-        furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
-        app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
-    }
-    // Null-terminate buf and append to text box store
-    buf[len] = '\0';
-    furi_string_cat_printf(app->text_box_store, "%s", buf);
-}
-
 void wifi_marauder_get_prefix_from_cmd(char* dest, const char* command) {
     int start, end, delta;
     start = strlen("sniff");
@@ -41,6 +29,23 @@ void wifi_marauder_create_pcap_file(WifiMarauderApp* app) {
 void wifi_marauder_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) {
     furi_assert(context);
     WifiMarauderApp* app = context;
+    
+    // If text box store gets too big, then truncate it
+    app->text_box_store_strlen += len;
+    if(app->text_box_store_strlen >= WIFI_MARAUDER_TEXT_BOX_STORE_SIZE - 1) {
+        furi_string_right(app->text_box_store, app->text_box_store_strlen / 2);
+        app->text_box_store_strlen = furi_string_size(app->text_box_store) + len;
+    }
+
+    // Null-terminate buf and append to text box store
+    buf[len] = '\0';
+    furi_string_cat_printf(app->text_box_store, "%s", buf);
+    view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshConsoleOutput);
+}
+
+void wifi_marauder_console_output_handle_rx_packets_cb(uint8_t* buf, size_t len, void* context) {
+    furi_assert(context);
+    WifiMarauderApp* app = context;
 
     // If it is a sniff function, open the pcap file for recording
     if (strncmp("sniff", app->selected_tx_string, strlen("sniff")) == 0 && !app->is_writing) {
@@ -52,8 +57,6 @@ void wifi_marauder_console_output_handle_rx_data_cb(uint8_t* buf, size_t len, vo
 
     if (app->is_writing) {
         storage_file_write(app->capture_file, buf, len);
-    } else {
-        wifi_marauder_print_message(buf, len, app);
     }
 
     view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshConsoleOutput);
@@ -75,7 +78,7 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
         app->text_box_store_strlen = 0;
         if(0 == strncmp("help", app->selected_tx_string, strlen("help"))) {
             const char* help_msg =
-                "Marauder companion " WIFI_MARAUDER_APP_VERSION "\nFor app support/feedback,\nreach out to me:\n@cococode#6011 (discord)\n0xchocolate (github)\n";
+                "Marauder companion " WIFI_MARAUDER_APP_VERSION "\n";
             furi_string_cat_str(app->text_box_store, help_msg);
             app->text_box_store_strlen += strlen(help_msg);
         }
@@ -95,7 +98,9 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
 
     // Register callback to receive data
     wifi_marauder_uart_set_handle_rx_data_cb(
-        app->uart, wifi_marauder_console_output_handle_rx_data_cb); // setup callback for rx thread
+        app->uart, wifi_marauder_console_output_handle_rx_data_cb); // setup callback for general log rx thread
+    wifi_marauder_uart_set_handle_rx_data_cb(
+        app->lp_uart, wifi_marauder_console_output_handle_rx_packets_cb); // setup callback for packets rx thread
 
     // Send command with newline '\n'
     if(app->is_command && app->selected_tx_string) {
@@ -125,6 +130,7 @@ void wifi_marauder_scene_console_output_on_exit(void* context) {
 
     // Unregister rx callback
     wifi_marauder_uart_set_handle_rx_data_cb(app->uart, NULL);
+    wifi_marauder_uart_set_handle_rx_data_cb(app->lp_uart, NULL);
 
     // Automatically stop the scan when exiting view
     if(app->is_command) {

+ 3 - 1
applications/plugins/wifi_marauder_companion/wifi_marauder_app.c

@@ -93,6 +93,7 @@ void wifi_marauder_app_free(WifiMarauderApp* app) {
     scene_manager_free(app->scene_manager);
 
     wifi_marauder_uart_free(app->uart);
+    wifi_marauder_uart_free(app->lp_uart);
 
     // Close records
     furi_record_close(RECORD_GUI);
@@ -108,7 +109,8 @@ int32_t wifi_marauder_app(void* p) {
 
     wifi_marauder_make_app_folder(wifi_marauder_app);
 
-    wifi_marauder_app->uart = wifi_marauder_uart_init(wifi_marauder_app);
+    wifi_marauder_app->uart = wifi_marauder_usart_init(wifi_marauder_app);
+    wifi_marauder_app->lp_uart = wifi_marauder_lp_uart_init(wifi_marauder_app);
 
     view_dispatcher_run(wifi_marauder_app->view_dispatcher);
 

+ 1 - 0
applications/plugins/wifi_marauder_companion/wifi_marauder_app_i.h

@@ -41,6 +41,7 @@ struct WifiMarauderApp {
     VariableItemList* var_item_list;
 
     WifiMarauderUart* uart;
+    WifiMarauderUart* lp_uart;
     int selected_menu_index;
     int selected_option_index[NUM_MENU_ITEMS];
     const char* selected_tx_string;

+ 25 - 7
applications/plugins/wifi_marauder_companion/wifi_marauder_uart.c

@@ -2,10 +2,12 @@
 #include "wifi_marauder_uart.h"
 
 #define UART_CH (FuriHalUartIdUSART1)
+#define LP_UART_CH (FuriHalUartIdLPUART1)
 #define BAUDRATE (115200)
 
 struct WifiMarauderUart {
     WifiMarauderApp* app;
+    FuriHalUartId channel;
     FuriThread* rx_thread;
     FuriStreamBuffer* rx_stream;
     uint8_t rx_buf[RX_BUF_SIZE + 1];
@@ -60,25 +62,41 @@ void wifi_marauder_uart_tx(uint8_t* data, size_t len) {
     furi_hal_uart_tx(UART_CH, data, len);
 }
 
-WifiMarauderUart* wifi_marauder_uart_init(WifiMarauderApp* app) {
+void wifi_marauder_lp_uart_tx(uint8_t* data, size_t len) {
+    furi_hal_uart_tx(LP_UART_CH, data, len);
+}
+
+WifiMarauderUart* wifi_marauder_uart_init(WifiMarauderApp* app, FuriHalUartId channel, const char* thread_name) {
     WifiMarauderUart* uart = malloc(sizeof(WifiMarauderUart));
 
     uart->app = app;
+    uart->channel = channel;
     uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
     uart->rx_thread = furi_thread_alloc();
-    furi_thread_set_name(uart->rx_thread, "WifiMarauderUartRxThread");
+    furi_thread_set_name(uart->rx_thread, thread_name);
     furi_thread_set_stack_size(uart->rx_thread, 1024);
     furi_thread_set_context(uart->rx_thread, uart);
     furi_thread_set_callback(uart->rx_thread, uart_worker);
     furi_thread_start(uart->rx_thread);
-
-    furi_hal_console_disable();
-    furi_hal_uart_set_br(UART_CH, BAUDRATE);
-    furi_hal_uart_set_irq_cb(UART_CH, wifi_marauder_uart_on_irq_cb, uart);
+    if(channel == FuriHalUartIdUSART1) {
+        furi_hal_console_disable();
+    } else if(channel == FuriHalUartIdLPUART1) {
+        furi_hal_uart_init(channel, BAUDRATE);
+    }
+    furi_hal_uart_set_br(channel, BAUDRATE);
+    furi_hal_uart_set_irq_cb(channel, wifi_marauder_uart_on_irq_cb, uart);
 
     return uart;
 }
 
+WifiMarauderUart* wifi_marauder_usart_init(WifiMarauderApp* app) {
+    return wifi_marauder_uart_init(app, UART_CH,"WifiMarauderUartRxThread");
+}
+
+WifiMarauderUart* wifi_marauder_lp_uart_init(WifiMarauderApp* app) {
+    return wifi_marauder_uart_init(app, LP_UART_CH,"WifiMarauderLPUartRxThread");
+}
+
 void wifi_marauder_uart_free(WifiMarauderUart* uart) {
     furi_assert(uart);
 
@@ -86,7 +104,7 @@ void wifi_marauder_uart_free(WifiMarauderUart* uart) {
     furi_thread_join(uart->rx_thread);
     furi_thread_free(uart->rx_thread);
 
-    furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
+    furi_hal_uart_set_irq_cb(uart->channel, NULL, NULL);
     furi_hal_console_enable();
 
     free(uart);

+ 3 - 1
applications/plugins/wifi_marauder_companion/wifi_marauder_uart.h

@@ -10,5 +10,7 @@ void wifi_marauder_uart_set_handle_rx_data_cb(
     WifiMarauderUart* uart,
     void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context));
 void wifi_marauder_uart_tx(uint8_t* data, size_t len);
-WifiMarauderUart* wifi_marauder_uart_init(WifiMarauderApp* app);
+void wifi_marauder_lp_uart_tx(uint8_t* data, size_t len);
+WifiMarauderUart* wifi_marauder_usart_init(WifiMarauderApp* app);
+WifiMarauderUart* wifi_marauder_lp_uart_init(WifiMarauderApp* app);
 void wifi_marauder_uart_free(WifiMarauderUart* uart);