Liba

GPS Hour

Jun 1st, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. # 08/06/2015
  2.  
  3. # Este programa capta todas as informações pegadas por um gps e imprime a hora local.
  4.  
  5.  
  6. # Instalar gpsd , python-gps , gpsd-clients
  7. # Na pasta usr/bin - Abrir o documento gpscat e modificá-lo:
  8. #       Em baixo do while True, colocar um contador até 15 com um if(ou mais se quiser), no else coloca break. Para o pipe não quebrar.
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <iostream>
  13.  
  14. #include <time.h>
  15. #include <unistd.h>
  16.  
  17.  
  18.  
  19. void readFile();
  20.  
  21. int main()
  22. {
  23.    system("gpscat -s 9600 /dev/ttyUSB0 > gpsinfo.txt");
  24.    readFile();
  25. /* Colocar algo para excluir o arquivo */
  26.    return EXIT_SUCCESS;
  27. }
  28.  
  29. void readFile() {
  30.     bool endPlease = false;
  31.     char line[256];
  32.     char time[10];
  33.     FILE *r;
  34.     r = fopen("gpsinfo.txt", "r");
  35.     if(r != NULL) {
  36.         while(!feof(r) && endPlease == false) {
  37.             if(fgets( line, sizeof line, r) != NULL) {
  38.                 for(int i = 2; i < 256; i++) {
  39.                     if((line[i] == 'G' && line[i+1] == 'G' && line[i+2] == 'A')
  40.                     || (line[i] == 'R' && line[i+1] == 'M' && line[i+2] == 'C')) {
  41.                         for(int j = i + 4; j < 10 + i + 4; j++) {
  42.                             time[j - i - 4] = line[j];
  43.                         }
  44.                         i += sizeof line;
  45.                         endPlease = true;
  46.                     }      
  47.                 }
  48.             }
  49.         }
  50.     }
  51.     else {
  52.         printf("Erro.");
  53.     }
  54.     int theTime = 0;
  55.     theTime += 100000000 * ((int)time[0] - 48);
  56.     theTime += 10000000 * ((int)time[1] - 48);
  57.     theTime += 1000000 * ((int)time[2] - 48);
  58.     theTime += 100000 * ((int)time[3] - 48);
  59.     theTime += 10000 * ((int)time[4] - 48);
  60.     theTime += 1000 * ((int)time[5] - 48);
  61.     theTime += 100 * ((int)time[7] - 48);
  62.     theTime += 10 * ((int)time[8] - 48);
  63.     theTime += (int)time[9] - 48;
  64.     printf("\n%d\n", theTime);
  65.     fclose(r);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment