Hi,
leider funtzt das bei mir nicht so richtig.
Als test benutzte ich diesen NMEA Satz.
1 | $GPRMC,191410,A,4735.5634,N,00739.3538,E,0.0,0.0,181102,0.4,E,A*19
|
Ich habe die Funktion noch erweitert, dass groß und Kleinbuchstaben
verwendet werden können.
Hier der Code: Die letzten beiden Chars lasse ich mit auch ausgeben und
bekomme auch 19 angezeigt, also ist das nicht das Problem und er gehts
in
der Abfrage in 0-9, also das auch richtig.
1 | unsigned char checksum = 0x00;
|
2 |
|
3 | printf("Last chars: %c, %c\n",this->buffer[this->indexer-1],this->buffer[this->indexer]);
|
4 | unsigned char chk = 0x00;
|
5 | if ((this->buffer[this->indexer-1] >= '0') && (this->buffer[this->indexer-1] <= '9' ))
|
6 | {
|
7 | chk+=(this->buffer[this->indexer-1] - '0');
|
8 | printf("\nChar 1: 0-9\n");
|
9 | }
|
10 | else if ((this->buffer[this->indexer-1] >= 'A') && (this->buffer[this->indexer-1] <= 'F'))
|
11 | {
|
12 | chk+=(this->buffer[this->indexer-1] - 'A' + 10);
|
13 | printf("\nChar 1: A-F\n");
|
14 | }
|
15 | else if ((this->buffer[this->indexer-1] >= 'a') && (this->buffer[this->indexer-1] <= 'f'))
|
16 | {
|
17 | chk+=(this->buffer[this->indexer-1] - 'a' + 10);
|
18 | printf("\nChar 1: a-f\n");
|
19 | }
|
20 |
|
21 |
|
22 | if ((this->buffer[this->indexer] >= '0') && (this->buffer[this->indexer] <= '9' ))
|
23 | {
|
24 | chk+=(this->buffer[this->indexer] - '0');
|
25 | printf("\nChar 2: 0-9\n");
|
26 | }
|
27 | else if ((this->buffer[this->indexer] >= 'A') && (this->buffer[this->indexer] <= 'F'))
|
28 | {
|
29 | chk+=(this->buffer[this->indexer] - 'A' + 10);
|
30 | printf("\nChar 2: A-F\n");
|
31 | }
|
32 | else if ((this->buffer[this->indexer] >= 'a') && (this->buffer[this->indexer] <= 'f'))
|
33 | {
|
34 | chk+=(this->buffer[this->indexer] - 'a' + 10);
|
35 | printf("\nChar 2: a-f\n");
|
36 | }
|
37 | printf("Check: %x\n",chk);
|
Wenn ich mir das am ende ausgeben lasse, bekomme ich als Hex nur 'a'
ausgeben.
Was ist falsch?
MfG
Philipp