GPS GMS-6 Module
Diff: GPSGms6.cpp
- Revision:
- 4:fb1cd9893eb8
- Parent:
- 3:910f54a89372
- Child:
- 5:9dd9ab613497
diff -r 910f54a89372 -r fb1cd9893eb8 GPSGms6.cpp --- a/GPSGms6.cpp Wed May 18 09:02:45 2016 +0000 +++ b/GPSGms6.cpp Wed May 18 17:22:37 2016 +0000 @@ -124,17 +124,13 @@ if (index < (size - HEADER_SIZE)) { /* Check for GPRMC */ - if (buf[index] == 'G' && - buf[index+1] == 'P' && - buf[index+2] == 'R' && - buf[index+3] == 'M' && - buf[index+4] == 'C' - ) - { + if (IS_HEADER_GPRPC(buf)) + { /* Populate the header to the variable */ unsigned int h_index; - for(h_index = 0; h_index < HEADER_SIZE; h_index++) { + for(h_index = 0; h_index < HEADER_SIZE; h_index++) + { m_gprmc.header[h_index] = buf[index + h_index]; } @@ -173,10 +169,7 @@ } /* Check validity of the data */ - if (m_gprmc.indicator[0] == (char)'A' || - m_gprmc.indicator[0] == (char)'D' || - m_gprmc.indicator[0] == (char)'E' - ) + if (IS_INDICATOR_VALID(m_gprmc.indicator[0])) { /* If valid, populate to the valid variable */ m_available= true; @@ -225,7 +218,7 @@ m_available = false; /* Talking on 9600 bps */ - serial_gps.baud(9600); + serial_gps.baud(GPS_BAUD_RATE); } @@ -279,42 +272,42 @@ struct tm t; /* Check available of date and time */ - if (m_gprmc.date[0] != ' ' && m_gprmc.time[0] != ' ' ) + if (m_gprmc.date[GPS_TIME_DATE_OFFSET] != ' ' && m_gprmc.time[GPS_TIME_HOUR_OFFSET] != ' ' ) { /* Allocate buffer for buffering */ - char str[3]; + char str[GPS_STRING_BUFFER_SIZE]; /* populate the second */ - memcpy( str, &m_gprmc.time[4], 2 ); + memcpy( str, &m_gprmc.time[GPS_TIME_SECOND_OFFSET], GPS_TIME_SECOND_SIZE ); t.tm_sec = atoi(str); /* populate the minute */ - memcpy( str, &m_gprmc.time[2], 2 ); + memcpy( str, &m_gprmc.time[GPS_TIME_MINUTE_OFFSET], GPS_TIME_MINUTE_SIZE ); t.tm_min = atoi(str); /* populate the hour */ - memcpy( str, &m_gprmc.time[0], 2 ); + memcpy( str, &m_gprmc.time[GPS_TIME_HOUR_OFFSET], GPS_TIME_HOUR_SIZE ); t.tm_hour = atoi(str); /* populate the date */ - memcpy( str, &m_gprmc.date[0], 2 ); + memcpy( str, &m_gprmc.date[GPS_TIME_DATE_OFFSET], GPS_TIME_DATE_SIZE ); t.tm_mday = atoi(str); /* populate the month */ - memcpy( str, &m_gprmc.date[2], 2 ); + memcpy( str, &m_gprmc.date[GPS_TIME_MONTH_OFFSET], GPS_TIME_MONTH_SIZE ); t.tm_mon = atoi(str); /* populate the year */ - memcpy( str, &m_gprmc.date[4], 2 ); + memcpy( str, &m_gprmc.date[GPS_TIME_YEAR_OFFSET], GPS_TIME_YEAR_SIZE ); t.tm_year = atoi(str); } else { /* Found nothing */ - t.tm_mday = 0; - t.tm_mon = 0; - t.tm_year = 0; + t.tm_mday = INVALID_TIME_DATE; + t.tm_mon = INVALID_TIME_MONTH; + t.tm_year = INVALID_TIME_YEAR; } /* Return the time !! */