Browse Source

use of ring buffer in application - simplify process logic

Juraj Ďuďák 2 days ago
parent
commit
61b9ad932d
2 changed files with 5 additions and 8 deletions
  1. 1 1
      include/nbus_types.h
  2. 4 7
      src/nbus_app.c

+ 1 - 1
include/nbus_types.h

@@ -63,7 +63,7 @@
 /**
  * @brief Maximálna veľkosť komunikačného bufferu.
  */
-#define BUFF_SIZE (PAYLOAD_SIZE + META_SIZE)
+#define BUFF_SIZE (PAYLOAD_SIZE + META_SIZE)*2
 
 /**
  * @brief Symbolické konštanty pre príznak pripravenosti dát

+ 4 - 7
src/nbus_app.c

@@ -37,7 +37,7 @@ static uint8_t crc8x_fast(void const *mem, uint16_t len)
 
 inline static void receivePacket(void)
 {
-    nBus.hw_platform->uart_receive(nBus.rx_buffer, 64);
+    nBus.hw_platform->uart_receive(nBus.rx_buffer, BUFF_SIZE);
 }
 
 inline static void send_response()
@@ -93,7 +93,6 @@ static void process_request()
     if (crcC != nBus.rx_buffer[nBus.rx_length - 1])
     {
         nBus.send_response = NO_RESPONSE;
-        receivePacket();
         return;
     }
 
@@ -108,7 +107,6 @@ static void process_request()
     if (nBus.addressModule != MODULE_ADDRESS)
     {
         nBus.send_response = NO_RESPONSE;
-        receivePacket();
         return;
     }
 
@@ -251,6 +249,7 @@ void nbus_init_memory_driver(nBus_MemoryDriver *memDriver)
     }
 }
 
+
 /**
  * @brief Run protocol stack.
  * This is infinity protocol loop.
@@ -290,15 +289,13 @@ void nbus_stack(void)
 
         if (nBus.hw_platform->loop_callback != NULL)
         {
+
             if (nBus.hw_platform->loop_callback(CallbackType_SENSOR) == 1)
             {
                 nBus.interface->read();
             }
 
-            if (nBus.hw_platform->loop_callback(CallbackType_UART) == 1)
-            {
-                nBus.uart_state = UART_RX_WAIT;
-            }
+            nBus.hw_platform->loop_callback(CallbackType_UART);
         }
     }
 }