Test software for SatChat prototype hardware Platform - MAX32630FTHR
Dependencies: USBDevice max32630fthr
Diff: main.cpp
- Revision:
- 8:b4a6c632c809
- Parent:
- 7:4218bb385ca4
- Child:
- 9:b8a60ade343e
diff -r 4218bb385ca4 -r b4a6c632c809 main.cpp --- a/main.cpp Sat Jul 01 05:23:43 2017 +0000 +++ b/main.cpp Sat Jul 01 06:33:58 2017 +0000 @@ -27,19 +27,18 @@ void gps_update(void) { gps_power(on); + while (1) { int checksum = 0; - char nmea_sentence[82] = {0}; //Fill with NULL terminators - //gps.format(8,Serial::None,1); - while (gps.getc()!='$'); //wait for start of sentence + char nmea_sentence[82] = {0}; //Fill with NULL terminators to save doing it later + while (gps.getc()!='$'); //wait for start of sentence int nmea_index = 0; nmea_sentence[nmea_index] = '$'; //Manually insert the '$' because we don't want it included in the checksum loop - char nmea_char = gps.getc(); //get sentence first char from GPS - while (nmea_char != '*') { - // pc.putc(nmea_char); - checksum ^= nmea_char; //Calc checksum as we read sentence + char nmea_char = gps.getc(); //get sentence first char from GPS + while (nmea_char != '*') { //Loop building sentence and calc'ing CS until * + checksum ^= nmea_char; //Calc checksum as we read sentence if ((nmea_sentence[nmea_index] == ',')&&(nmea_char == ',')) { - nmea_sentence[++nmea_index] = ' '; //Pad consecutive comma with a space + nmea_sentence[++nmea_index] = ' '; //Pad consecutive comma with a space to make it possible to use strtok with empty values } nmea_sentence[++nmea_index] = nmea_char; //build the sentence with the next character if (nmea_index > 80) { @@ -47,11 +46,13 @@ } nmea_char = gps.getc(); //get next char from GPS } - //read two hex digits of CS from gps - char msb_gps_checksum = gps.getc(); - char lsb_gps_checksum = gps.getc(); - - + //Last character was the '*' so read the two hex digits of CS from gps + char hex_checksum[3] = {0}; + hex_checksum[0] = gps.getc(); + hex_checksum[1] = gps.getc(); + if (checksum == (int)strtol(hex_checksum, NULL, 16) ){ + pc.printf("Match\n\r"); + } // const char s[2] = ","; const char gprmc[7] = "$GPRMC"; @@ -64,8 +65,7 @@ // pc.printf( " %s\n\r", token ); } // pc.printf("GPS CS:"); - pc.putc(msb_gps_checksum); - pc.putc(lsb_gps_checksum); + pc.printf("%d \n\r",checksum); }