1
0

serial.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/task.h"
  5. #include "freertos/queue.h"
  6. #include "freertos/task.h"
  7. #include "esp_log.h"
  8. #include "serial.h"
  9. #include "uart.h"
  10. //#include "supervision.h"
  11. //#include "http_client.h"
  12. #include "wifi.h"
  13. #ifdef SERIAL_ENABLED
  14. // Defines
  15. // Global defines
  16. int serialRxCounter = 0;
  17. void serialRxTask(void *pvParameters)
  18. {
  19. const bool LOG_PRINT=true;
  20. int mode = -1; // Force a reset
  21. int reset = 1;
  22. unsigned char value[200];
  23. unsigned char *valP;
  24. printf( "serialRxTask Core:%d\n",xPortGetCoreID());
  25. while(1)
  26. {
  27. while( serialAvailable() ) {
  28. const unsigned char c = serialRead();
  29. //printf("%c",c);
  30. if( mode == 0 && c == '{' ) {
  31. if(LOG_PRINT) printf("Rx start ");
  32. mode = 1;
  33. }
  34. else if( mode == 1 ) {
  35. if( c == '}' ) { // Check for end of value
  36. *(valP) = '\0';
  37. reset = 1;
  38. printf("\nData:%s\n",value);
  39. char type[10];
  40. char id[12];
  41. char data[10];
  42. const int no = sscanf((const char *)value,"%s,%s,%s",type,id,data);
  43. printf("No:%d\n",no);
  44. if( no == 1 ) printf("%s\n",type);
  45. if( no == 3 ) printf("%d %s %s %s\n",no,type,id,data);
  46. }
  47. else if( c < ',' || c > 'Z') {
  48. if(LOG_PRINT) printf("ERROR 3\n");
  49. reset = 1;
  50. }
  51. else {
  52. *(valP++) = c;
  53. }
  54. }
  55. if( reset == 1 ) {
  56. serialRxCounter++;
  57. valP = value;
  58. value[0]='\0';
  59. mode = 0;
  60. reset = 0;
  61. }
  62. }
  63. vTaskDelay(100 / portTICK_PERIOD_MS);
  64. }
  65. vTaskDelete(NULL);
  66. }
  67. #endif