Skip to content

Commit

Permalink
fix uart_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
jaylikesbunda authored Nov 8, 2024
1 parent fc0afd7 commit 638a1ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sequential_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ bool sequential_file_open(

free(file_path);
return success;
}
}
33 changes: 27 additions & 6 deletions uart_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,37 @@ static void uart_rx_callback(FuriHalSerialHandle* handle, FuriHalSerialRxEvent e
void handle_uart_rx_data(uint8_t *buf, size_t len, void *context) {
AppState *state = (AppState *)context;
if(!state || !state->uart_context || !state->uart_context->is_serial_active ||
!buf || len == 0) return;
!buf || len == 0) {
FURI_LOG_W("UART", "Invalid parameters in handle_uart_rx_data");
return;
}

// Log if in capture mode and storage is enabled
if(state->uart_context->pcap &&
// Only log data if NOT in PCAP mode
if(!state->uart_context->pcap &&
state->uart_context->storageContext &&
state->uart_context->storageContext->log_file) {
storage_file_write(state->uart_context->storageContext->log_file, buf, len);
state->uart_context->storageContext->log_file &&
state->uart_context->storageContext->HasOpenedFile) {
static size_t bytes_since_sync = 0;

size_t written = storage_file_write(
state->uart_context->storageContext->log_file,
buf,
len
);

if(written != len) {
FURI_LOG_E("UART", "Failed to write log data: expected %zu, wrote %zu", len, written);
} else {
bytes_since_sync += written;
if(bytes_since_sync >= 8192) {
storage_file_sync(state->uart_context->storageContext->log_file);
bytes_since_sync = 0;
FURI_LOG_D("UART", "Synced log file to storage");
}
}
}

// Update display
// Update text display
text_buffer_add(state->uart_context->text_manager, (char*)buf, len);
text_buffer_update_view(state->uart_context->text_manager,
state->settings.view_logs_from_start_index);
Expand Down

0 comments on commit 638a1ac

Please sign in to comment.