123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include <stdio.h>
- #include <string.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "freertos/queue.h"
- #include "freertos/task.h"
- #include "esp_log.h"
- #include "serial.h"
- #include "uart.h"
- //#include "supervision.h"
- //#include "http_client.h"
- #include "wifi.h"
- #ifdef SERIAL_ENABLED
- // Defines
- // Global defines
- int serialRxCounter = 0;
- void serialRxTask(void *pvParameters)
- {
- const bool LOG_PRINT=true;
- int mode = -1; // Force a reset
- int reset = 1;
- unsigned char value[200];
- unsigned char *valP;
- printf( "serialRxTask Core:%d\n",xPortGetCoreID());
- while(1)
- {
-
- while( serialAvailable() ) {
-
- const unsigned char c = serialRead();
- //printf("%c",c);
- if( mode == 0 && c == '{' ) {
- if(LOG_PRINT) printf("Rx start ");
- mode = 1;
- }
- else if( mode == 1 ) {
-
- if( c == '}' ) { // Check for end of value
- *(valP) = '\0';
- reset = 1;
- printf("\nData:%s\n",value);
- char type[10];
- char id[12];
- char data[10];
- const int no = sscanf((const char *)value,"%s,%s,%s",type,id,data);
- printf("No:%d\n",no);
- if( no == 1 ) printf("%s\n",type);
- if( no == 3 ) printf("%d %s %s %s\n",no,type,id,data);
- }
- else if( c < ',' || c > 'Z') {
- if(LOG_PRINT) printf("ERROR 3\n");
- reset = 1;
- }
- else {
- *(valP++) = c;
- }
- }
- if( reset == 1 ) {
- serialRxCounter++;
- valP = value;
- value[0]='\0';
- mode = 0;
- reset = 0;
- }
- }
- vTaskDelay(100 / portTICK_PERIOD_MS);
- }
- vTaskDelete(NULL);
- }
- #endif
|