Add message framing (start, end, escape bytes) to UART

Same functionality as previous commit. But way more stable and clean.
Previous proof of concept approach had issues with random partial or
too large messages due to time based method
Rework send and receive functions to work more stable
- send: encode data with frame (start, end byte)
- receive: read each byte one after the other, assemble message,
  handle actual data in handle function
- add semaphore to write operation to prevent parallel write of
  different data when called from other tasks
This commit is contained in:
jonny_jr9
2023-08-30 17:58:01 +02:00
parent 1e544613ee
commit 446c246f43
8 changed files with 197 additions and 55 deletions

View File

@@ -142,7 +142,7 @@ void setLoglevels(void){
esp_log_level_set("wifi", ESP_LOG_INFO);
esp_log_level_set("http", ESP_LOG_INFO);
esp_log_level_set("automatedArmchair", ESP_LOG_DEBUG);
esp_log_level_set("uart_common", ESP_LOG_INFO);
esp_log_level_set("uart-common", ESP_LOG_INFO);
esp_log_level_set("uart", ESP_LOG_INFO);
//

View File

@@ -14,25 +14,17 @@ extern "C"
#include "freertos/queue.h"
#include "driver/uart.h"
}
#include "uart.hpp"
static const char * TAG = "uart";
//TESTING
#include "control.hpp"
#include "config.hpp"
//==============================
//====== task_uartReceive ======
//==============================
//TODO copy receive task from board_motorctl/uart.cpp
void task_uartReceive(void *arg){
//--- testing force http mode after startup ---
//TESTING
vTaskDelay(5000 / portTICK_PERIOD_MS);
control.changeMode(controlMode_t::HTTP);
while (1) {
vTaskDelay(200 / portTICK_PERIOD_MS);
}
@@ -43,13 +35,15 @@ void task_uartReceive(void *arg){
//=============================
//======= task_uartSend =======
//=============================
//repeatedly send structs to uart
//repeatedly send structs via uart
//note: uart_sendStruct() from uart_common.hpp can be used anywhere
void task_uartSend(void *arg){
static const char * TAG = "uart-send";
uartData_test_t data = {123, 0, 1.1};
ESP_LOGW(TAG, "startloop...");
ESP_LOGW(TAG, "send task started");
//repeatedly send data for testing uart
while (1) {
vTaskDelay(10000 / portTICK_PERIOD_MS);
vTaskDelay(5000 / portTICK_PERIOD_MS);
uart_sendStruct<uartData_test_t>(data);
//change data values

View File

@@ -1,8 +1,8 @@
#pragma once
#include "uart_common.hpp"
void uart_task_testing(void *arg);
//===== uart board CONTROL =====
//
void task_uartReceive(void *arg);
void task_uartSend(void *arg);