Skip to content

Commit

Permalink
uart back
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed May 10, 2022
1 parent b16fa6d commit 9c732ae
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 73 deletions.
124 changes: 62 additions & 62 deletions interface/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 4 additions & 11 deletions src/uart/emsuart_esp32.cpp
Expand Up @@ -39,28 +39,21 @@ uint8_t tx_mode_;
void EMSuart::uart_event_task(void * pvParameters) {
uart_event_t event;
uint8_t telegram[EMS_MAXBUFFERSIZE];
// size_t length;
uint8_t length = 0;
size_t length;

while (1) {
//Waiting for UART event.
if (xQueueReceive(uart_queue, (void *)&event, portMAX_DELAY)) {
if (event.type == UART_DATA) {
length += event.size;
} else if (event.type == UART_BREAK) {
// uart_get_buffered_data_len(EMSUART_NUM, &length);
if (event.type == UART_BREAK) {
uart_get_buffered_data_len(EMSUART_NUM, &length);
if (length == 2 || (length >= 6 && length <= EMS_MAXBUFFERSIZE)) {
uart_read_bytes(EMSUART_NUM, telegram, length, portMAX_DELAY);
if (telegram[0] && !telegram[length - 1]) {
EMSESP::incoming_telegram(telegram, (uint8_t)(length - 1));
}
} else {
// flush buffer up to break
uint8_t buf[length];
uart_read_bytes(EMSUART_NUM, buf, length, portMAX_DELAY);
// uart_flush_input(EMSUART_NUM);
uart_flush_input(EMSUART_NUM);
}
length = 0;
}
}
}
Expand Down

0 comments on commit 9c732ae

Please sign in to comment.