Test software for SatChat prototype hardware Platform - MAX32630FTHR
Dependencies: USBDevice max32630fthr
Diff: main.cpp
- Revision:
- 7:4218bb385ca4
- Parent:
- 6:af25f19eb4e6
- Child:
- 8:b4a6c632c809
--- a/main.cpp Sat Jul 01 02:02:38 2017 +0000 +++ b/main.cpp Sat Jul 01 05:23:43 2017 +0000 @@ -26,35 +26,33 @@ void gps_update(void) { - char nmea_descriptor[5] = {0}; 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 + //gps.format(8,Serial::None,1); + while (gps.getc()!='$'); //wait for start of sentence int nmea_index = 0; - nmea_sentence[nmea_index] = '$'; - while (nmea_sentence[nmea_index++] != '\n') { - char nmea_char = gps.getc(); - if ((nmea_sentence[nmea_index-1] == ',')&&(nmea_char == ',')) { - nmea_sentence[nmea_index++] = ' '; //Pad consecutive comma with a space + 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 + if ((nmea_sentence[nmea_index] == ',')&&(nmea_char == ',')) { + nmea_sentence[++nmea_index] = ' '; //Pad consecutive comma with a space } - if (nmea_char == '*'){ - nmea_sentence[nmea_index++] = ','; //inserting a comma before CS makes handling easier - } - nmea_sentence[nmea_index] = nmea_char; //build the sentence + nmea_sentence[++nmea_index] = nmea_char; //build the sentence with the next character if (nmea_index > 80) { nmea_index=80; //Don't overflow buffer } + nmea_char = gps.getc(); //get next char from GPS } - // Checksum - bool checksum_valid = FALSE; - int checksum = 0; - int i = 1; //After the '$' - while (nmea_sentence[i++] != '*'){ - checksum ^= nmea_sentence[i]; - } - pc.printf( "Checksum: %i\n\r", checksum ); + //read two hex digits of CS from gps + char msb_gps_checksum = gps.getc(); + char lsb_gps_checksum = gps.getc(); + + + // const char s[2] = ","; const char gprmc[7] = "$GPRMC"; char *token; @@ -63,8 +61,12 @@ pc.printf( " %s\n\r", token ); while (token != NULL) { token = strtok(NULL, ","); - pc.printf( " %s\n\r", token ); + // 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); } while (gps.readable()) { @@ -88,15 +90,16 @@ wait(2); while (1) { gps_update(); + + } } - - - - + + + - + - \ No newline at end of file +