Guest User

UART2 Read

a guest
Aug 24th, 2017
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. void CheckGPS(void *param) {
  2. static char line[1024];
  3. Nubot *temp = malloc(sizeof(Nubot));
  4. temp = (Nubot *) param;
  5. memset(line, 0, sizeof(line));
  6. char *dtmp = line;
  7.  
  8. while (1) {
  9. dtmp = readLine(UART_NUM_2);
  10. if (!strncmp(dtmp, "$GPRMC,", 7)) {
  11. ESP_LOGW(TAG, "%s", (char* ) dtmp);
  12. bzero(temp->RawGPS, sizeof(temp->RawGPS));
  13. sprintf(temp->RawGPS, "%s", dtmp);
  14. DecomposeGPS(temp, 0);
  15. ESP_LOGE(TAG , "Flushing UART2");
  16. uart_flush(UART_NUM_2);
  17. }
  18. memset(dtmp, 0, sizeof(line));
  19. vTaskDelay(10 / portTICK_PERIOD_MS);
  20. }
  21. }
  22.  
  23.  
  24. char *readLine(uart_port_t uart) {
  25. static char line[1024];
  26. int size;
  27. memset(line , 0 , sizeof(line));
  28. char *ptr = line;
  29. while (1) {
  30. size = uart_read_bytes(uart, (unsigned char *) ptr, 1, 1000/portMAX_DELAY);
  31. if (size == 1) {
  32. printf("%c" , ptr[0]);
  33. if (*ptr == '\n') {
  34. ptr++;
  35. *ptr = 0;
  36. return line;
  37. }
  38. ptr++;
  39. } // End of read a character
  40. } // End of loop
  41. } // End of readLine
Add Comment
Please, Sign In to add comment