Skip to content

Commit

Permalink
WIP: Attempts to fix FlipperHTTP dropping bytes
Browse files Browse the repository at this point in the history
still drops bytes like this
  • Loading branch information
Willy-JL committed Nov 11, 2024
1 parent 96df8de commit c90c876
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
41 changes: 23 additions & 18 deletions flip_store/flipper_http/flipper_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,14 @@ void _flipper_http_rx_callback(
FuriHalSerialRxEvent event,
void* context) {
UNUSED(context);
if(event == FuriHalSerialRxEventData) {
uint8_t data = furi_hal_serial_async_rx(handle);
furi_stream_buffer_send(fhttp.flipper_http_stream, &data, 1, 0);
if(event & FuriHalSerialRxEventData) {
while(furi_hal_serial_async_rx_available(handle)) {
const uint8_t data = furi_hal_serial_async_rx(handle);
if(!furi_stream_buffer_send(fhttp.flipper_http_stream, &data, 1, 0)) {
// Uncomment below to check whether bytes are being dropped
// furi_crash("UART buffer full");
}
}
furi_thread_flags_set(fhttp.rx_thread_id, WorkerEvtRxDone);
}
}
Expand Down Expand Up @@ -943,17 +948,17 @@ void flipper_http_rx_callback(const char* line, size_t line_len, void* context)
}

// Trim the received line to check if it's empty
char* trimmed_line = trim(line);
if(trimmed_line != NULL && trimmed_line[0] != '\0') {
// if the line is not [GET/END] or [POST/END] or [PUT/END] or [DELETE/END]
if(strstr(trimmed_line, "[GET/END]") == NULL &&
strstr(trimmed_line, "[POST/END]") == NULL &&
strstr(trimmed_line, "[PUT/END]") == NULL &&
strstr(trimmed_line, "[DELETE/END]") == NULL) {
strncpy(fhttp.last_response, trimmed_line, RX_BUF_SIZE);
}
}
free(trimmed_line); // Free the allocated memory for trimmed_line
// char* trimmed_line = trim(line);
// if(trimmed_line != NULL && trimmed_line[0] != '\0') {
// // if the line is not [GET/END] or [POST/END] or [PUT/END] or [DELETE/END]
// if(strstr(trimmed_line, "[GET/END]") == NULL &&
// strstr(trimmed_line, "[POST/END]") == NULL &&
// strstr(trimmed_line, "[PUT/END]") == NULL &&
// strstr(trimmed_line, "[DELETE/END]") == NULL) {
// strncpy(fhttp.last_response, trimmed_line, RX_BUF_SIZE);
// }
// }
// free(trimmed_line); // Free the allocated memory for trimmed_line

if(fhttp.state != INACTIVE && fhttp.state != ISSUE) {
fhttp.state = RECEIVING;
Expand All @@ -967,7 +972,7 @@ void flipper_http_rx_callback(const char* line, size_t line_len, void* context)
// Restart the timeout timer each time new data is received
furi_timer_restart(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);

if(strstr(line, "[GET/END]") != NULL) {
if(!strncmp(line, "[GET/END]", strlen("[GET/END]"))) {
FURI_LOG_I(HTTP_TAG, "GET request completed.");
// Stop the timer since we've completed the GET request
furi_timer_stop(fhttp.get_timeout_timer);
Expand Down Expand Up @@ -1002,7 +1007,7 @@ void flipper_http_rx_callback(const char* line, size_t line_len, void* context)
// Restart the timeout timer each time new data is received
furi_timer_restart(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);

if(strstr(line, "[POST/END]") != NULL) {
if(!strncmp(line, "[POST/END]", strlen("[POST/END]"))) {
FURI_LOG_I(HTTP_TAG, "POST request completed.");
// Stop the timer since we've completed the POST request
furi_timer_stop(fhttp.get_timeout_timer);
Expand Down Expand Up @@ -1038,7 +1043,7 @@ void flipper_http_rx_callback(const char* line, size_t line_len, void* context)
// Restart the timeout timer each time new data is received
furi_timer_restart(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);

if(strstr(line, "[PUT/END]") != NULL) {
if(!strncmp(line, "[PUT/END]", strlen("[PUT/END]"))) {
FURI_LOG_I(HTTP_TAG, "PUT request completed.");
// Stop the timer since we've completed the PUT request
furi_timer_stop(fhttp.get_timeout_timer);
Expand Down Expand Up @@ -1073,7 +1078,7 @@ void flipper_http_rx_callback(const char* line, size_t line_len, void* context)
// Restart the timeout timer each time new data is received
furi_timer_restart(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);

if(strstr(line, "[DELETE/END]") != NULL) {
if(!strncmp(line, "[DELETE/END]", strlen("[DELETE/END]"))) {
FURI_LOG_I(HTTP_TAG, "DELETE request completed.");
// Stop the timer since we've completed the DELETE request
furi_timer_stop(fhttp.get_timeout_timer);
Expand Down
2 changes: 1 addition & 1 deletion flip_store/flipper_http/flipper_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define UART_CH (momentum_settings.uart_esp_channel) // UART channel
#define TIMEOUT_DURATION_TICKS (5 * 1000) // 5 seconds
#define BAUDRATE (115200) // UART baudrate
#define RX_BUF_SIZE 1024 // UART RX buffer size
#define RX_BUF_SIZE 2048 // UART RX buffer size
#define RX_LINE_BUFFER_SIZE 8192 // UART RX line buffer size (increase for large responses)
#define MAX_FILE_SHOW 8192 // Maximum data from file to show

Expand Down

0 comments on commit c90c876

Please sign in to comment.