Hallo, ich parse den GPGGA GPS Satz und möchte die Uhrzeit am Display anzeigen. ich erhalte: Gps.utctime = 170552; Gps.hour = Gps.utctime / 10000; Gps.second = Gps.utctime % 100; Gps.minute =(Gps.utctime % 10000)/100; Gps.hour ist dann 17 Gps.second ist dann 52 Gps.minute ist dann 5 wenn ichs mit dem Taschenrechner nachrechne stimmt es, aber im Betrieb wird manchmal eine Sekunde ausgelassen. Ist die Umrechnung oben so korrekt oder würdet ihr das anderst machen?
Ist Gps.utctime tatsächlich ein int (bzw.long)? (und warum ?) in den NMEA-Daten steht's doch als string:
1 | char time_buffer[] = "170552"; // immer "hhmmss" |
2 | int8_t std = (time_buffer[0]-'0') *10; |
3 | std += time_buffer[1] - '0'; |
4 | int8_t min = (time_buffer[2]-'0') *10; |
5 | min += time_buffer[3] - '0'; |
6 | int8_t sec = (time_buffer[4]-'0') *10; |
7 | sec += time_buffer[5] - '0'; |
hth. Jörg ps.: das "-'0'" wird (spätestens dann) klar, wenn du einen Blick in die ASCII-Tabelle (in deinem C-Buch) wirfst ;)
1 | void nmeaGPGGA(char* packet) |
2 | {
|
3 | u08 i=6; |
4 | char time_buffer[7]; |
5 | |
6 | if(packet[i]==',' && packet[i+1]==',')return; |
7 | |
8 | while(packet[++i] != ',')time_buffer[i-7]=packet[i]; |
9 | |
10 | Gps.hour = (time_buffer[0] - '0') *10; |
11 | Gps.hour += time_buffer[1] - '0'; |
12 | Gps.minute = (time_buffer[2] - '0') *10; |
13 | Gps.minute += time_buffer[3] - '0'; |
14 | Gps.second = (time_buffer[4] - '0') *10; |
15 | Gps.second += time_buffer[5] - '0'; |
da ist wohl noch ein Fehler bei mir oder?
>> da ist wohl noch ein Fehler bei mir oder? Da hab ich keine Ahnung, DENN - ich weiß nicht, wie dein Programm aussieht - ich weiß nicht, was dein AVR (nicht) macht - ich weiß nicht, was dein AVR machen soll etc... Aber das Team von strcpy und strtok_r aus der Standardlib funktioniert bei mir
1 | // Header
|
2 | struct date {int h; int m; int s;}; |
3 | //Main:
|
4 | char s[] = "$GPGGA,191410,"\ |
5 | "4735.5634,N,00739.3538,E,"\
|
6 | "1,04,4.4,351.5,M,48.0,M,,*45"; |
7 | char *wort, *end; |
8 | char buffer[10]; |
9 | struct date test; |
10 | |
11 | wort = strtok_r(s, ",", &end); |
12 | wort = strtok_r(NULL, ",", &end); |
13 | |
14 | strncpy(buffer, wort, 7); |
15 | |
16 | test.h = (buffer[0] - '0') *10; |
17 | test.h += (buffer[1] - '0'); |
18 | test.m = (buffer[2] - '0') *10; |
19 | test.m += (buffer[3] - '0'); |
20 | test.s = (buffer[4] - '0') *10; |
21 | test.s += (buffer[5] - '0'); |
hth Jörg ps. (mingw-gcc) PC-Programm im Anhang (da heißt die Funktion "strtok" und hat weniger argumente)
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.