Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 08/06/2015
- # Este programa capta todas as informações pegadas por um gps e imprime a hora local.
- # Instalar gpsd , python-gps , gpsd-clients
- # Na pasta usr/bin - Abrir o documento gpscat e modificá-lo:
- # 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.
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <time.h>
- #include <unistd.h>
- void readFile();
- int main()
- {
- system("gpscat -s 9600 /dev/ttyUSB0 > gpsinfo.txt");
- readFile();
- /* Colocar algo para excluir o arquivo */
- return EXIT_SUCCESS;
- }
- void readFile() {
- bool endPlease = false;
- char line[256];
- char time[10];
- FILE *r;
- r = fopen("gpsinfo.txt", "r");
- if(r != NULL) {
- while(!feof(r) && endPlease == false) {
- if(fgets( line, sizeof line, r) != NULL) {
- for(int i = 2; i < 256; i++) {
- if((line[i] == 'G' && line[i+1] == 'G' && line[i+2] == 'A')
- || (line[i] == 'R' && line[i+1] == 'M' && line[i+2] == 'C')) {
- for(int j = i + 4; j < 10 + i + 4; j++) {
- time[j - i - 4] = line[j];
- }
- i += sizeof line;
- endPlease = true;
- }
- }
- }
- }
- }
- else {
- printf("Erro.");
- }
- int theTime = 0;
- theTime += 100000000 * ((int)time[0] - 48);
- theTime += 10000000 * ((int)time[1] - 48);
- theTime += 1000000 * ((int)time[2] - 48);
- theTime += 100000 * ((int)time[3] - 48);
- theTime += 10000 * ((int)time[4] - 48);
- theTime += 1000 * ((int)time[5] - 48);
- theTime += 100 * ((int)time[7] - 48);
- theTime += 10 * ((int)time[8] - 48);
- theTime += (int)time[9] - 48;
- printf("\n%d\n", theTime);
- fclose(r);
- }
Advertisement
Add Comment
Please, Sign In to add comment