فهرست منبع

Add timer to POST, PUT, and DELETE requests

jblanked 1 سال پیش
والد
کامیت
21db6141d9
4فایلهای تغییر یافته به همراه28 افزوده شده و 6 حذف شده
  1. BIN
      .DS_Store
  2. BIN
      assets/.DS_Store
  3. 16 5
      assets/FlipperHTTP/flipper_http.h
  4. 12 1
      flipper_http.h

BIN
.DS_Store


BIN
assets/.DS_Store


+ 16 - 5
assets/FlipperHTTP/flipper_http.h

@@ -680,7 +680,11 @@ void flipper_http_rx_callback(const char *line, void *context)
         return;
     }
 
-    fhttp.last_response = (char *)line;
+    // if line isnt empty save it
+    if (line[0] != '\0')
+    {
+        fhttp.last_response = (char *)line;
+    }
 
     // the only way for the state to change from INACTIVE to RECEIVING is if a PONG is received
     if (fhttp.state != INACTIVE)
@@ -705,7 +709,8 @@ void flipper_http_rx_callback(const char *line, void *context)
 
             if (fhttp.received_data)
             {
-                flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
+                // uncomment if you want to save the received data to the external storage
+                // flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
                 free(fhttp.received_data);
                 fhttp.received_data = NULL;
                 fhttp.started_receiving_get = false;
@@ -768,7 +773,8 @@ void flipper_http_rx_callback(const char *line, void *context)
 
             if (fhttp.received_data)
             {
-                flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
+                // uncomment if you want to save the received data to the external storage
+                // flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
                 free(fhttp.received_data);
                 fhttp.received_data = NULL;
                 fhttp.started_receiving_post = false;
@@ -831,7 +837,8 @@ void flipper_http_rx_callback(const char *line, void *context)
 
             if (fhttp.received_data)
             {
-                flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
+                // uncomment if you want to save the received data to the external storage
+                // flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
                 free(fhttp.received_data);
                 fhttp.received_data = NULL;
                 fhttp.started_receiving_put = false;
@@ -894,7 +901,8 @@ void flipper_http_rx_callback(const char *line, void *context)
 
             if (fhttp.received_data)
             {
-                flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
+                // uncomment if you want to save the received data to the external storage
+                // flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
                 free(fhttp.received_data);
                 fhttp.received_data = NULL;
                 fhttp.started_receiving_delete = false;
@@ -969,6 +977,7 @@ void flipper_http_rx_callback(const char *line, void *context)
     {
         FURI_LOG_I(HTTP_TAG, "POST request succeeded.");
         fhttp.started_receiving_post = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
         return;
     }
@@ -976,6 +985,7 @@ void flipper_http_rx_callback(const char *line, void *context)
     {
         FURI_LOG_I(HTTP_TAG, "PUT request succeeded.");
         fhttp.started_receiving_put = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
         return;
     }
@@ -983,6 +993,7 @@ void flipper_http_rx_callback(const char *line, void *context)
     {
         FURI_LOG_I(HTTP_TAG, "DELETE request succeeded.");
         fhttp.started_receiving_delete = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
         return;
     }

+ 12 - 1
flipper_http.h

@@ -680,7 +680,11 @@ void flipper_http_rx_callback(const char *line, void *context)
         return;
     }
 
-    fhttp.last_response = (char *)line;
+    // if line isnt empty save it
+    if (line[0] != '\0')
+    {
+        fhttp.last_response = (char *)line;
+    }
 
     // the only way for the state to change from INACTIVE to RECEIVING is if a PONG is received
     if (fhttp.state != INACTIVE)
@@ -705,6 +709,7 @@ void flipper_http_rx_callback(const char *line, void *context)
 
             if (fhttp.received_data)
             {
+                // uncomment if you want to save the received data to the external storage
                 flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
                 free(fhttp.received_data);
                 fhttp.received_data = NULL;
@@ -768,6 +773,7 @@ void flipper_http_rx_callback(const char *line, void *context)
 
             if (fhttp.received_data)
             {
+                // uncomment if you want to save the received data to the external storage
                 flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
                 free(fhttp.received_data);
                 fhttp.received_data = NULL;
@@ -831,6 +837,7 @@ void flipper_http_rx_callback(const char *line, void *context)
 
             if (fhttp.received_data)
             {
+                // uncomment if you want to save the received data to the external storage
                 flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
                 free(fhttp.received_data);
                 fhttp.received_data = NULL;
@@ -894,6 +901,7 @@ void flipper_http_rx_callback(const char *line, void *context)
 
             if (fhttp.received_data)
             {
+                // uncomment if you want to save the received data to the external storage
                 flipper_http_save_received_data(strlen(fhttp.received_data), fhttp.received_data);
                 free(fhttp.received_data);
                 fhttp.received_data = NULL;
@@ -969,6 +977,7 @@ void flipper_http_rx_callback(const char *line, void *context)
     {
         FURI_LOG_I(HTTP_TAG, "POST request succeeded.");
         fhttp.started_receiving_post = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
         return;
     }
@@ -976,6 +985,7 @@ void flipper_http_rx_callback(const char *line, void *context)
     {
         FURI_LOG_I(HTTP_TAG, "PUT request succeeded.");
         fhttp.started_receiving_put = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
         return;
     }
@@ -983,6 +993,7 @@ void flipper_http_rx_callback(const char *line, void *context)
     {
         FURI_LOG_I(HTTP_TAG, "DELETE request succeeded.");
         fhttp.started_receiving_delete = true;
+        furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
         return;
     }