#include <WaspGPS.h>
Public Member Functions | |
| WaspGPS () | |
| class constructor | |
| void | ON () |
| It opens UART1 and powers the GPS module. | |
| void | OFF () |
| It closes UART1 and powers off the GPS module. | |
| void | begin (void) |
| It powers up GPS module and opens UART1 to communicate with it. | |
| void | close (void) |
| It closes UART1. | |
| void | init (void) |
| It initializes GPS module with the default values. | |
| void | init (const char *, const char *, const char *, const char *, const char *, const char *, const char *, const char *) |
| It initializes GPS module with the values introduced as parameters. | |
| void | setMode (uint8_t) |
| It sets the current internal Power Mode on the GPS. | |
| uint8_t | getMode (void) |
| It gets the current internal Power Mode on the GPS. | |
| bool | check () |
| It checks if the receiver is connected to sattelites. | |
| char * | getTime (void) |
| It gets the current time given by GPS. | |
| char * | getDate (void) |
| It gets the current date given by GPS. | |
| char * | getLatitude (void) |
| It gets the Latitude from the GPS. | |
| char * | getLongitude (void) |
| It gets the Longitude from the GPS. | |
| char * | getSpeed (void) |
| It gets the Speed from the GPS. | |
| char * | getAltitude (void) |
| It gets the Altitude from the GPS. | |
| char * | getCourse (void) |
| It gets the Course from the GPS. | |
| uint8_t | saveEphems () |
| It saves ephemeris into a file in the SD card. This file is called 'FILE_EPHEMERIS'. | |
| uint8_t | saveEphems (const char *filename) |
| It saves ephemeris into a file in the SD card. | |
| uint8_t | loadEphems () |
| It loads ephemeris from the SD card to the GPS receiver. It loads from file called 'FILE_EPHEMERIS'. | |
| uint8_t | loadEphems (const char *filename) |
| It loads ephemeris from the SD card to the GPS receiver. | |
| const char * | getLibVersion (void) |
| It gets the library version. | |
| uint8_t | setCommMode (uint16_t) |
| It sets communication mode: Binary or NMEA. | |
| uint8_t | getCommMode (void) |
| It gets the communication mode on use. | |
| uint8_t | getPosition () |
| It gets the latitude, longitude, altitude, speed, course, time and date. | |
Data Fields | |
| long | _baudRate |
| Variable : Baudrate used to init the UART and communicate with GPS receiver. | |
| uint8_t | _uart |
| Variable : UART used to communicate with GPS receiver. | |
| bool | fixValid |
| Variable : Determines whether the last reading was valid or not. | |
| uint16_t | flag |
| Variable : Flag used to determine if an error occurred while executing some function. | |
| uint16_t | commMode |
| Variable : Communication mode. Two possibilities available --> binary mode or NMEA mode. | |
| uint8_t | pwrMode |
| Variable : Power mode used for GPS receiver. | |
| uint8_t | wakeMode |
| Variable : Waking up mode used for GPS receiver. | |
| char | timeGPS [MAX_ARGS] |
| Variable : Time extracted from NMEA GGA sentence received from GPS receiver. | |
| char | dateGPS [MAX_ARGS] |
| Variable : Date extracted from NMEA RMC sentence received from GPS receiver. | |
| char * | clkOffset |
| Variable : Clock drift of the GPS receiver used to initialize it. | |
| char * | timeOfWeek |
| Variable : GPS Time of Week used to initialize it. | |
| char * | weekNo |
| Variable : Extended GPS Week Number used to initialize it. | |
| char * | channel |
| Variable : Channel Counter used to initialize it. | |
| char * | resetCfg |
| Variable : Reset Configuration. | |
| char * | coordinateLat |
| Variable : Default Latitude. + = North (Range 90 to -90). Expressed in degrees. Example-->37.3875111. | |
| char * | coordinateLon |
| Variable : Default Longitude. + = East (Range 180 to -180). Expressed in degrees. Example-->-121.97232. | |
| char * | coordinateAl |
| Variable : Default Altitude position. Expressed in meters. Example-->0. | |
| uint8_t | checksum |
| Variable : the frame checksum. | |
| char | latitude [MAX_ARGS] |
| Variable : it stores the latitude given by the GPS module. | |
| char | longitude [MAX_ARGS] |
| Variable : it stores the longitude given by the GPS module. | |
| char | speed [MAX_ARGS] |
| Variable : it stores the speed given by the GPS module. | |
| char | altitude [MAX_ARGS] |
| Variable : it stores the altitude given by the GPS module. | |
| char | course [MAX_ARGS] |
| Variable : it stores the course given by the GPS module. | |
| uint8_t | reboot |
| Variable : for rebooting the GPS module. | |
| uint8_t | checkSUM [2] |
| Variable : for storing the frame checksum. | |
Private Member Functions | |
| void | extractDate (void) |
| It extracts Date from a NMEA RMC sentence. | |
| void | extractTime (void) |
| It extracts Time from a NMEA GGA sentence. | |
| long | parse_decimal (char *str) |
| It extracts a decimal number from a string. | |
| unsigned long | parse_degrees (char *str) |
| It extracts a degree number from a string. | |
| long | gpsatol (char *str) |
| It extracts a decimal number from a string, getting the integer part of a float number in case. | |
| bool | gpsisdigit (char c) |
| It specifies if a char is a number. | |
| uint8_t | checkSum (const char *gpsString) |
| It calculates the NMEA checkSum, leave out $, *, and the checkSum bytes. | |
| uint8_t | getChecksum (const char *gpsString) |
| It calculates the NMEA checkSum, leave out $, *, and the checkSum bytes. | |
| void | setChecksum () |
| It sets checksum to the end of Utils.inBuffer. | |
| void | getChecksum (uint8_t *buffer) |
| It calculates checksum for a secuence given as a parameter. | |
| bool | dataValid (void) |
| It gets if the last reading of data was valid or not. | |
| char * | getRaw (int) |
| It gets a data string from the GPS. | |
WaspGPS Class defines all the variables and functions used to manage GPS A1084 receiver
Definition at line 293 of file WaspGPS.h.
| WaspGPS::WaspGPS | ( | ) |
class constructor
It initializes the variables with the default values.
| void |
Definition at line 40 of file WaspGPS.cpp.
References _baudRate, _uart, ACK, channel, checksum, clkOffset, COLD, commMode, coordinateAl, coordinateLat, coordinateLon, flag, GPS_NMEA, GPS_ON, pwrMode, reboot, resetCfg, timeOfWeek, wakeMode, and weekNo.
00041 { 00042 _baudRate = 4800; // by default we choose NMEA's speed for the port 00043 //_baudRate = 9600; // by default we choose NMEA's speed for the port 00044 _uart=1; 00045 00046 // basic GPS configuration 00047 reboot=COLD; // reboot the system or init the system the first time 00048 flag = ACK; // init the flag at ACK 00049 commMode = GPS_NMEA; // communication mode: software or hardware serial 00050 pwrMode = GPS_ON; // power on the GPS 00051 wakeMode = COLD; // wake up erasing the internal data 00052 clkOffset= (char*) "96000"; 00053 timeOfWeek= (char*) "497260"; 00054 weekNo= (char*) "921"; 00055 channel= (char*) "12"; 00056 resetCfg= (char*) "1"; 00057 coordinateLat = (char*) "4140.8217"; // Zaragoza, Spain, coordinates for Libelium 00058 coordinateLon = (char*) "00053.1736"; // Zaragoza, Spain, coordinates for Libelium 00059 coordinateAl = (char*) "198"; // Zaragoza, Spain, coordinates for Libelium 00060 checksum=0; 00061 }
| void WaspGPS::extractDate | ( | void | ) | [private] |
It extracts Date from a NMEA RMC sentence.
| void |
Definition at line 84 of file WaspGPS.cpp.
References WaspUtils::arguments, commMode, dateGPS, delay(), flag, GPS_BINARY, GPS_BINARY_OFF, GPS_INVALID, GPS_NMEA_RMC, WaspUtils::inBuffer, MAX_ARGS, millis(), serialFlush(), setCommMode(), WaspUtils::strExplode(), and Utils.
Referenced by getDate().
00085 { 00086 // store current state to return to it later 00087 uint16_t currentSentences = commMode; 00088 long previous=0; 00089 00090 00091 // get Date information 00092 serialFlush(1); 00093 previous=millis(); 00094 while(!setCommMode(GPS_NMEA_RMC) && (millis()-previous)<3000); 00095 Utils.strExplode(Utils.inBuffer, ','); // separates all the subarrays from Utils.inBuffer into the Utils.arguments array 00096 if( !strcmp(Utils.arguments[0],"$GPRMC") ) 00097 { 00098 for(int i=0;i<MAX_ARGS;i++) dateGPS[i]=Utils.arguments[9][i]; 00099 } 00100 else 00101 { 00102 flag |=GPS_INVALID; 00103 } 00104 00105 // return to previous state 00106 previous=millis(); 00107 if (currentSentences == GPS_BINARY_OFF ) while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 00108 delay(100); 00109 previous=millis(); 00110 while(!setCommMode(currentSentences) && (millis()-previous)<3000); 00111 }


| void WaspGPS::extractTime | ( | void | ) | [private] |
It extracts Time from a NMEA GGA sentence.
| void |
Definition at line 124 of file WaspGPS.cpp.
References WaspUtils::arguments, commMode, delay(), flag, GPS_BINARY, GPS_BINARY_OFF, GPS_INVALID, GPS_NMEA_GGA, WaspUtils::inBuffer, MAX_ARGS, millis(), serialFlush(), setCommMode(), WaspUtils::strExplode(), timeGPS, and Utils.
Referenced by getTime().
00125 { 00126 // store current state to return to it later 00127 uint16_t currentSentences = commMode; 00128 long previous=0; 00129 00130 // get Time 00131 serialFlush(1); 00132 previous=millis(); 00133 while(!setCommMode(GPS_NMEA_GGA) && (millis()-previous)<3000); 00134 Utils.strExplode(Utils.inBuffer, ','); // separates all the subarrays from Utils.inBuffer into the Utils.arguments array 00135 if( !strcmp(Utils.arguments[0],"$GPGGA") ) 00136 { 00137 for(int i=0;i<MAX_ARGS;i++) timeGPS[i]=Utils.arguments[1][i]; 00138 } 00139 else 00140 { 00141 flag |= GPS_INVALID; 00142 } 00143 00144 // return to previous state 00145 previous=millis(); 00146 if (currentSentences == GPS_BINARY_OFF ) while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 00147 delay(100); 00148 previous=millis(); 00149 while(!setCommMode(currentSentences) && (millis()-previous)<3000); 00150 }


| long WaspGPS::parse_decimal | ( | char * | str | ) | [private] |
It extracts a decimal number from a string.
| char | *str: The string which contains the decimal number to extract |
Definition at line 158 of file WaspGPS.cpp.
References gpsatol(), and gpsisdigit().
00159 { 00160 bool isneg = *str == '-'; 00161 if (isneg) *str++; 00162 unsigned long ret = 100UL * gpsatol(str); 00163 while (gpsisdigit(*str)) ++str; 00164 if (*str == '.') 00165 { 00166 if (gpsisdigit(str[1])) 00167 { 00168 ret += 10 * (str[1] - '0'); 00169 if (gpsisdigit(str[2])) 00170 ret += str[2] - '0'; 00171 } 00172 } 00173 return isneg ? -ret : ret; 00174 }

| unsigned long WaspGPS::parse_degrees | ( | char * | str | ) | [private] |
It extracts a degree number from a string.
| char | *str: The string which contains the degree number to extract |
Definition at line 181 of file WaspGPS.cpp.
References gpsatol(), and gpsisdigit().
00182 { 00183 unsigned long left = gpsatol(str); 00184 unsigned long tenk_minutes = (left % 100UL) * 10000UL; 00185 while (gpsisdigit(*str)) ++str; 00186 if (*str == '.') 00187 { 00188 unsigned long mult = 1000; 00189 while (gpsisdigit(*++str)) 00190 { 00191 tenk_minutes += mult * (*str - '0'); 00192 mult /= 10; 00193 } 00194 } 00195 return (left / 100) * 100000 + tenk_minutes / 6; 00196 }

| long WaspGPS::gpsatol | ( | char * | str | ) | [private] |
It extracts a decimal number from a string, getting the integer part of a float number in case.
| char | *str: The string which contains the decimal or float number to extract |
Definition at line 203 of file WaspGPS.cpp.
References gpsisdigit().
Referenced by parse_decimal(), and parse_degrees().
00204 { 00205 long ret = 0; 00206 while (gpsisdigit(*str)) 00207 ret = 10 * ret + *str++ - '0'; 00208 return ret; 00209 }


| bool WaspGPS::gpsisdigit | ( | char | c | ) | [inline, private] |
It specifies if a char is a number.
| char | c: The char to get if it is a number |
Definition at line 343 of file WaspGPS.h.
Referenced by gpsatol(), parse_decimal(), and parse_degrees().

| uint8_t WaspGPS::checkSum | ( | const char * | gpsString | ) | [private] |
It calculates the NMEA checkSum, leave out $, *, and the checkSum bytes.
| char | *gpsString: the string containing the NMEA sentence to get the checksum from |
Definition at line 1289 of file WaspGPS.cpp.
References check(), flag, GPS_BAD_CHECKSUM, WaspUtils::sizeOf(), and Utils.
01290 { 01291 // clear the checksum flag 01292 flag &= ~(GPS_BAD_CHECKSUM); 01293 01294 // return error if there is no asterisk at the end of the string 01295 if (gpsString[Utils.sizeOf(gpsString)-3] != '*') return 0; 01296 01297 char check = 0; 01298 // iterate over the string, XOR each byte with the total sum: 01299 for (int c = 1; c < Utils.sizeOf(gpsString) - 3; c++) { 01300 check = char(check ^ gpsString[c]); 01301 } 01302 01303 // get the checksum character for the string itself 01304 char stringCheckSum = (gpsString[Utils.sizeOf(gpsString)-2] - '0') << 4 | (gpsString[Utils.sizeOf(gpsString)-1] - '0'); 01305 01306 uint8_t result = (check == stringCheckSum); 01307 01308 if (!result) flag |= GPS_BAD_CHECKSUM; 01309 01310 // return the result 01311 return result; 01312 }

| uint8_t WaspGPS::getChecksum | ( | const char * | gpsString | ) | [private] |
It calculates the NMEA checkSum, leave out $, *, and the checkSum bytes.
| char | *gpsString: the string containing the NMEA sentence to get the checksum from |
Definition at line 1321 of file WaspGPS.cpp.
References check(), WaspUtils::sizeOf(), and Utils.
Referenced by loadEphems(), saveEphems(), and setChecksum().
01322 { 01323 char check = 0; 01324 // iterate over the string, XOR each byte with the total sum: 01325 for (int c = 1; c < Utils.sizeOf(gpsString) - 3; c++) { 01326 check = char(check ^ gpsString[c]); 01327 } 01328 return check; 01329 }


| void WaspGPS::setChecksum | ( | ) | [private] |
It sets checksum to the end of Utils.inBuffer.
| void |
Definition at line 1336 of file WaspGPS.cpp.
References checksum, getChecksum(), WaspUtils::inBuffer, WaspUtils::sizeOf(), and Utils.
Referenced by init().
01337 { 01338 checksum= getChecksum(Utils.inBuffer); 01339 int aux=Utils.sizeOf(Utils.inBuffer); 01340 float aux2 = checksum%16; 01341 if(aux2==0.0) 01342 { 01343 Utils.inBuffer[aux-1]=48; 01344 Utils.inBuffer[aux-2]=(checksum/16)+48; 01345 } 01346 else 01347 { 01348 Utils.inBuffer[aux-2]=(int) (checksum/16) + 48; 01349 aux2 = checksum/16; 01350 Utils.inBuffer[aux-1]= (checksum-aux2*16)+48; 01351 01352 } 01353 }


| void WaspGPS::getChecksum | ( | uint8_t * | buffer | ) | [private] |
It calculates checksum for a secuence given as a parameter.
| uint8_t* | buffer: the secuence to get the checksum from |
Definition at line 892 of file WaspGPS.cpp.
References check(), and checkSUM.
00893 { 00894 int a=4; 00895 int check=0; 00896 uint8_t aux=0, aux2=0; 00897 while( (buffer[aux]!=0xB0) || (buffer[aux+1]!=0xB3) ) 00898 { 00899 aux++; 00900 } 00901 buffer[aux-1]=0x00; 00902 buffer[aux-2]=0x00; 00903 aux=0; 00904 while( (buffer[a]!=0xB0) || (buffer[a+1]!=0xB3) ) 00905 { 00906 check+=buffer[a]; 00907 check &= 0x7FFF; 00908 a++; 00909 } 00910 if(check>255) 00911 { 00912 aux=check/256; 00913 aux2=check-(aux*256); 00914 checkSUM[0]=aux; 00915 checkSUM[1]=aux2; 00916 } 00917 else 00918 { 00919 checkSUM[0]=0x00; 00920 checkSUM[1]=check; 00921 } 00922 }

| bool WaspGPS::dataValid | ( | void | ) | [inline, private] |
| char * WaspGPS::getRaw | ( | int | byteAmount | ) | [private] |
It gets a data string from the GPS.
| int | byteAmount: the number of bytes to read from GPS |
Definition at line 811 of file WaspGPS.cpp.
References _uart, WaspUtils::clearBuffer(), delay(), flag, GPS_BUFFER_SIZE, GPS_TIMEOUT, GPS_TIMEOUT_em, WaspUtils::inBuffer, serialAvailable(), serialFlush(), serialRead(), and Utils.
Referenced by setCommMode().
00812 { 00813 flag &= ~(GPS_TIMEOUT); 00814 00815 uint8_t byteGPS = 0; // the last byte coming through the port 00816 int i = 0; // count the amount of bytes read 00817 uint32_t timeout = 1000; // millis to wait before declaring timeout 00818 00819 if (byteAmount == 0) byteAmount = GPS_BUFFER_SIZE; 00820 00821 serialFlush(1); // empty the port 00822 Utils.clearBuffer(); 00823 // wait until arrival of a byte 00824 while(!serialAvailable(_uart) && timeout > 0) { delay(1); timeout--; }; 00825 00826 if (timeout <= 0) 00827 { 00828 flag |= GPS_TIMEOUT; 00829 return GPS_TIMEOUT_em; 00830 } 00831 00832 byteGPS = serialRead(_uart); // read the first byte coming through the port 00833 00834 while(byteGPS != '$') 00835 { 00836 if(serialAvailable(_uart) > 0) 00837 byteGPS = serialRead(_uart); // flush incomplete sentences 00838 } 00839 Utils.inBuffer[i]=byteGPS; 00840 i++; 00841 while(i <= 1 || (byteGPS != '*' && byteGPS != '$' && i < byteAmount)){ // read the GPS sentence 00842 // while(!i || (byteGPS != '*' && byteGPS != '$' && i < byteAmount)){ // read the GPS sentence 00843 if(serialAvailable(_uart) > 0) 00844 { 00845 byteGPS = serialRead(_uart); 00846 if (byteGPS != '*' && byteGPS != '$' && i < byteAmount) Utils.inBuffer[i]=byteGPS; 00847 /* if (byteGPS != '$' && i < byteAmount) Utils.inBuffer[i]=byteGPS; */ 00848 i++; 00849 } 00850 } 00851 // // add the checksum 00852 // if (byteGPS == '*' && i < byteAmount) 00853 // { 00854 // timeout = 1000; 00855 // while(!serialAvailable(1) && timeout > 0) { delay(1); timeout--; }; 00856 // if (timeout <= 0) 00857 // { 00858 // flag |= GPS_TIMEOUT; 00859 // return GPS_TIMEOUT_em; 00860 // } 00861 // byteGPS = serialRead(_uart); 00862 // Utils.inBuffer[i]=byteGPS; 00863 // i++; 00864 // if (i < byteAmount) 00865 // { 00866 // timeout = 1000; 00867 // while(!serialAvailable(1) && timeout > 0) { delay(1); timeout--; }; 00868 // if (timeout <= 0) 00869 // { 00870 // flag |= GPS_TIMEOUT; 00871 // return GPS_TIMEOUT_em; 00872 // } 00873 // byteGPS = serialRead(_uart); 00874 // Utils.inBuffer[i]=byteGPS; 00875 // i++; 00876 // } 00877 // } 00878 00879 if (byteGPS == '\n' || i == byteAmount) Utils.inBuffer[i-1] = '\0'; 00880 else Utils.inBuffer[i] = '\0'; 00881 00882 return Utils.inBuffer; 00883 }


| void WaspGPS::ON | ( | void | ) |
| void WaspGPS::OFF | ( | ) |
| void WaspGPS::begin | ( | void | ) |
It powers up GPS module and opens UART1 to communicate with it.
| void |
Definition at line 1255 of file WaspGPS.cpp.
References _baudRate, _uart, beginSerial(), WaspUtils::setMuxGPS(), and Utils.
Referenced by init(), and ON().
01256 { 01257 Utils.setMuxGPS(); 01258 beginSerial(_baudRate,_uart); 01259 01260 }


| void WaspGPS::close | ( | void | ) |
It closes UART1.
| void |
Definition at line 1275 of file WaspGPS.cpp.
References _uart, closeSerial(), COLD, MUX_TO_LOW, reboot, WaspUtils::setMux(), and Utils.
Referenced by OFF().
01276 { 01277 closeSerial(_uart); 01278 Utils.setMux(MUX_TO_LOW,MUX_TO_LOW); 01279 reboot=COLD; 01280 }


| void WaspGPS::init | ( | void | ) |
It initializes GPS module with the default values.
| void |
Definition at line 252 of file WaspGPS.cpp.
References channel, clkOffset, coordinateAl, coordinateLat, coordinateLon, resetCfg, timeOfWeek, and weekNo.
Referenced by ON().
00253 { 00254 init(coordinateLat, coordinateLon, coordinateAl, clkOffset, timeOfWeek, weekNo, channel, resetCfg); 00255 }

| void WaspGPS::init | ( | const char * | _coordinateLat, | |
| const char * | _coordinateLon, | |||
| const char * | _coordinateAl, | |||
| const char * | _clkOffset, | |||
| const char * | _timeOfWeek, | |||
| const char * | _weekNo, | |||
| const char * | _channel, | |||
| const char * | _resetCfg | |||
| ) |
It initializes GPS module with the values introduced as parameters.
| const | char* _coordinateLat : Latitude + = North (Range 90 to -90). Expressed in degrees. Example-->37.3875111 | |
| const | char* _coordinateLon : Longitude + = East (Range 180 to -180). Expressed in degrees. Example-->-121.97232 | |
| const | char* _coordinateAl : Altitude position. Expressed in meters. Example-->0 | |
| const | char* _clkOffset : Clock Drift of the Receiver. Expressed in Hz. Example-->96000 | |
| const | char* _timeOfWeek : GPS Time Of Week. Expressed in seconds. Example-->237759 | |
| const | char* _weekNo : Extended GPS Week Number. Example-->1946 | |
| const | char* _channel : Range 1 to 12 | |
| const | char* _resetCfg : Reset Configuration Bit |
Definition at line 267 of file WaspGPS.cpp.
References begin(), delay(), GPS_BINARY, GPS_BINARY_OFF, HOT, WaspUtils::inBuffer, millis(), printByte(), printString(), reboot, serialFlush(), setChecksum(), setCommMode(), and Utils.
00268 { 00269 long previous=0; 00270 // set up the initial coordinates, time and date 00271 if(reboot) 00272 { 00273 begin(); 00274 delay(3000); 00275 } 00276 sprintf(Utils.inBuffer,"$PSRF104,%s,%s,%s,%s,%s,%s,%s,%s*00",_coordinateLat,_coordinateLon,_coordinateAl,_clkOffset,_timeOfWeek,_weekNo,_channel,_resetCfg); 00277 00278 setChecksum(); 00279 serialFlush(1); 00280 printString(Utils.inBuffer,1); 00281 printByte('\r',1); 00282 printByte('\n',1); 00283 00284 // Set GPS on binary mode without sending data 00285 00286 previous=millis(); 00287 while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 00288 previous=millis(); 00289 while(!setCommMode(GPS_BINARY_OFF) && (millis()-previous)<3000); 00290 serialFlush(1); 00291 reboot=HOT; 00292 }

| void WaspGPS::setMode | ( | uint8_t | mode | ) |
It sets the current internal Power Mode on the GPS.
| uint8_t | mode : power mode to set the GPS. Possible values are GPS_ON, GPS_OFF |
Definition at line 469 of file WaspGPS.cpp.
References digitalWrite(), GPS_OFF, GPS_ON, GPS_PW, HIGH, LOW, OUTPUT, pinMode(), and pwrMode.
Referenced by OFF(), and ON().
00470 { 00471 pwrMode = mode; 00472 pinMode(GPS_PW,OUTPUT); 00473 00474 // set the GPS in the defined power mode 00475 switch (pwrMode) 00476 { 00477 case GPS_ON: 00478 digitalWrite(GPS_PW,HIGH); 00479 break; 00480 00481 case GPS_OFF: 00482 digitalWrite(GPS_PW,LOW); 00483 break; 00484 } 00485 }


| uint8_t WaspGPS::getMode | ( | void | ) |
It gets the current internal Power Mode on the GPS.
| void |
Definition at line 495 of file WaspGPS.cpp.
References pwrMode.
00496 { 00497 return pwrMode; 00498 }
| bool WaspGPS::check | ( | void | ) |
It checks if the receiver is connected to sattelites.
| void |
Definition at line 507 of file WaspGPS.cpp.
References WaspUtils::arguments, commMode, delay(), GPS_BINARY, GPS_BINARY_OFF, GPS_NMEA_GGA, WaspUtils::inBuffer, millis(), serialFlush(), setCommMode(), WaspUtils::strExplode(), and Utils.
Referenced by checkSum(), and getChecksum().
00508 { 00509 uint16_t currentSentences = commMode; 00510 bool connection=0; 00511 long previous=0; 00512 00513 serialFlush(1); 00514 while(!setCommMode(GPS_NMEA_GGA) && (millis()-previous)<3000); 00515 00516 // separates all the subarrays from Utils.inBuffer into the Utils.arguments array 00517 Utils.strExplode(Utils.inBuffer, ','); 00518 00519 // the data is valid only if the GPGGA position 7 is 1 or bigger 00520 if( !strcmp(Utils.arguments[0],"$GPGGA") ) 00521 { 00522 connection = (Utils.arguments[6][0] - '0'); 00523 } 00524 else connection=0; 00525 00526 // return to previous state 00527 previous=millis(); 00528 if (currentSentences == GPS_BINARY_OFF ) while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 00529 delay(100); 00530 previous=millis(); 00531 while(!setCommMode(currentSentences) && (millis()-previous)<3000); 00532 00533 return connection; 00534 }


| char * WaspGPS::getTime | ( | void | ) |
It gets the current time given by GPS.
| void |
Definition at line 545 of file WaspGPS.cpp.
References extractTime(), and timeGPS.
00546 { 00547 extractTime(); 00548 return timeGPS; 00549 }

| char * WaspGPS::getDate | ( | void | ) |
It gets the current date given by GPS.
| void |
Definition at line 560 of file WaspGPS.cpp.
References dateGPS, and extractDate().
00561 { 00562 extractDate(); 00563 return dateGPS; 00564 }

| char * WaspGPS::getLatitude | ( | void | ) |
It gets the Latitude from the GPS.
| void |
Definition at line 576 of file WaspGPS.cpp.
References WaspUtils::arguments, commMode, delay(), fixValid, flag, GPS_BINARY, GPS_BINARY_OFF, GPS_INVALID, GPS_NMEA_GGA, WaspUtils::inBuffer, latitude, MAX_ARGS, millis(), setCommMode(), WaspUtils::strExplode(), and Utils.
00577 { 00578 flag &= ~(GPS_INVALID); 00579 00580 // store current state to return to it later 00581 uint16_t currentSentences = commMode; 00582 long previous=0; 00583 00584 // get latitude, longitude, altitude, but NOT time 00585 while(!setCommMode(GPS_NMEA_GGA) && (millis()-previous)<3000); 00586 00587 // separates all the subarrays from Utils.inBuffer into the Utils.arguments array 00588 Utils.strExplode(Utils.inBuffer, ','); 00589 00590 if( !strcmp(Utils.arguments[0],"$GPGGA") ) 00591 { 00592 for(int i=0;i<MAX_ARGS;i++) latitude[i]=Utils.arguments[2][i]; 00593 } 00594 else 00595 { 00596 flag |=GPS_INVALID; 00597 } 00598 00599 00600 // the data is valid only if the GPGGA position 7 is 1 or bigger 00601 fixValid = (Utils.arguments[6][0] - '0'); 00602 if (!fixValid) flag |= GPS_INVALID; 00603 00604 // return to previous state 00605 previous=millis(); 00606 if (currentSentences == GPS_BINARY_OFF ) while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 00607 delay(100); 00608 previous=millis(); 00609 while(!setCommMode(currentSentences) && (millis()-previous)<3000); 00610 00611 return latitude; 00612 }

| char * WaspGPS::getLongitude | ( | void | ) |
It gets the Longitude from the GPS.
| void |
Definition at line 623 of file WaspGPS.cpp.
References WaspUtils::arguments, commMode, delay(), fixValid, flag, GPS_BINARY, GPS_BINARY_OFF, GPS_INVALID, GPS_NMEA_GGA, WaspUtils::inBuffer, longitude, MAX_ARGS, millis(), setCommMode(), WaspUtils::strExplode(), and Utils.
00624 { 00625 flag &= ~(GPS_INVALID); 00626 00627 // store current state to return to it later 00628 uint16_t currentSentences = commMode; 00629 long previous=0; 00630 00631 // get latitude, longitude, altitude, but NOT time 00632 while(!setCommMode(GPS_NMEA_GGA) && (millis()-previous)<3000); 00633 00634 // separates all the subarrays from Utils.inBuffer into the Utils.arguments array 00635 Utils.strExplode(Utils.inBuffer, ','); 00636 00637 if( !strcmp(Utils.arguments[0],"$GPGGA") ) 00638 { 00639 for(int i=0;i<MAX_ARGS;i++) longitude[i]=Utils.arguments[4][i]; 00640 } 00641 else 00642 { 00643 flag |=GPS_INVALID; 00644 } 00645 00646 // the data is valid only if the GPGGA position 7 is 1 or bigger 00647 fixValid = (Utils.arguments[6][0] - '0'); 00648 if (!fixValid) flag |= GPS_INVALID; 00649 00650 // return to previous state 00651 previous=millis(); 00652 if (currentSentences == GPS_BINARY_OFF ) while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 00653 delay(100); 00654 previous=millis(); 00655 while(!setCommMode(currentSentences) && (millis()-previous)<3000); 00656 00657 return longitude; 00658 }

| char * WaspGPS::getSpeed | ( | void | ) |
It gets the Speed from the GPS.
| void |
Definition at line 675 of file WaspGPS.cpp.
References WaspUtils::arguments, commMode, delay(), flag, GPS_BINARY, GPS_BINARY_OFF, GPS_INVALID, GPS_NMEA_VTG, WaspUtils::inBuffer, MAX_ARGS, millis(), setCommMode(), speed, WaspUtils::strExplode(), and Utils.
00676 { 00677 // store current state to return to it later 00678 uint16_t currentSentences = commMode; 00679 long previous=0; 00680 00681 // get speed and course 00682 while(!setCommMode(GPS_NMEA_VTG) && (millis()-previous)<3000); 00683 00684 // separates all the subarrays from Utils.inBuffer into the Utils.arguments array 00685 Utils.strExplode(Utils.inBuffer, ','); 00686 00687 if( !strcmp(Utils.arguments[0],"$GPVTG") ) 00688 { 00689 for(int i=0;i<MAX_ARGS;i++) speed[i]=Utils.arguments[7][i]; 00690 } 00691 else 00692 { 00693 flag |=GPS_INVALID; 00694 } 00695 00696 // return to previous state 00697 previous=millis(); 00698 if (currentSentences == GPS_BINARY_OFF ) while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 00699 delay(100); 00700 previous=millis(); 00701 while(!setCommMode(currentSentences) && (millis()-previous)<3000); 00702 00703 return speed; 00704 }

| char * WaspGPS::getAltitude | ( | void | ) |
It gets the Altitude from the GPS.
| void |
Definition at line 715 of file WaspGPS.cpp.
References altitude, WaspUtils::arguments, commMode, delay(), fixValid, flag, GPS_BINARY, GPS_BINARY_OFF, GPS_INVALID, GPS_NMEA_GGA, WaspUtils::inBuffer, MAX_ARGS, millis(), setCommMode(), WaspUtils::strExplode(), and Utils.
00716 { 00717 flag &= ~(GPS_INVALID); 00718 00719 // store current state to return to it later 00720 uint16_t currentSentences = commMode; 00721 long previous=0; 00722 00723 // get latitude, longitude, altitude, but NOT time 00724 while(!setCommMode(GPS_NMEA_GGA) && (millis()-previous)<3000); 00725 00726 // separates all the subarrays from Utils.inBuffer into the Utils.arguments array 00727 Utils.strExplode(Utils.inBuffer, ','); 00728 00729 if( !strcmp(Utils.arguments[0],"$GPGGA") ) 00730 { 00731 for(int i=0;i<MAX_ARGS;i++) altitude[i]=Utils.arguments[9][i]; 00732 } 00733 else 00734 { 00735 flag |=GPS_INVALID; 00736 } 00737 00738 // the data is valid only if the GPGGA position 7 is 1 or bigger 00739 fixValid = (Utils.arguments[6][0] - '0'); 00740 if (!fixValid) flag |= GPS_INVALID; 00741 00742 // return to previous state 00743 previous=millis(); 00744 if (currentSentences == GPS_BINARY_OFF ) while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 00745 delay(100); 00746 previous=millis(); 00747 while(!setCommMode(currentSentences) && (millis()-previous)<3000); 00748 00749 return altitude; 00750 }

| char * WaspGPS::getCourse | ( | void | ) |
It gets the Course from the GPS.
| void |
Definition at line 766 of file WaspGPS.cpp.
References WaspUtils::arguments, commMode, course, delay(), flag, GPS_BINARY, GPS_BINARY_OFF, GPS_INVALID, GPS_NMEA_VTG, WaspUtils::inBuffer, MAX_ARGS, millis(), setCommMode(), WaspUtils::strExplode(), and Utils.
00767 { 00768 // store current state to return to it later 00769 uint16_t currentSentences = commMode; 00770 long previous=0; 00771 00772 // get speed and course 00773 while(!setCommMode(GPS_NMEA_VTG) && (millis()-previous)<3000); 00774 00775 // separates all the subarrays from Utils.inBuffer into the Utils.arguments array 00776 Utils.strExplode(Utils.inBuffer, ','); 00777 00778 if( !strcmp(Utils.arguments[0],"$GPVTG") ) 00779 { 00780 for(int i=0;i<MAX_ARGS;i++) course[i]=Utils.arguments[1][i]; 00781 } 00782 else 00783 { 00784 flag |=GPS_INVALID; 00785 } 00786 00787 // return to previous state 00788 previous=millis(); 00789 if (currentSentences == GPS_BINARY_OFF ) while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 00790 delay(100); 00791 previous=millis(); 00792 while(!setCommMode(currentSentences) && (millis()-previous)<3000); 00793 00794 return course; 00795 }

| uint8_t WaspGPS::saveEphems | ( | ) |
It saves ephemeris into a file in the SD card. This file is called 'FILE_EPHEMERIS'.
| void |
Definition at line 930 of file WaspGPS.cpp.
References FILE_EPHEMERIS.
00931 { 00932 return saveEphems(FILE_EPHEMERIS); 00933 }
| uint8_t WaspGPS::saveEphems | ( | const char * | filename | ) |
It saves ephemeris into a file in the SD card.
| const | char* filename : The file name to store ephemeris in |
Definition at line 942 of file WaspGPS.cpp.
References _uart, checkSUM, WaspSD::create(), WaspSD::del(), delay(), WaspSD::flag, flag, getChecksum(), GPS_BINARY_OFF, WaspSD::isFile(), millis(), printByte(), SD, serialAvailable(), serialFlush(), serialRead(), setCommMode(), and WaspSD::writeSD().
00943 { 00944 uint8_t tempBuffer[11] ={0xA0,0xA2,0x00,0x03,0x93,0x00,0x00,0x00,0x00,0xB0,0xB3}; 00945 uint8_t* ByteIN = (uint8_t*) calloc(110,sizeof(uint8_t)); 00946 uint8_t* tempData = (uint8_t*) calloc(92,sizeof(uint8_t)); 00947 uint8_t endFile[7] ={0xAA,0xBB,0xCC,0xCC,0xBB,0xAA,0xAA}; 00948 uint8_t counter3=0; 00949 uint8_t end=0; 00950 uint16_t interval=1000; 00951 long previous=millis(); 00952 int8_t error=2; 00953 uint8_t est=1; 00954 // initialize the flags 00955 flag = 0; SD.flag = 0; 00956 uint8_t aux=0; 00957 00958 if (SD.isFile(filename)) SD.del(filename); 00959 SD.create(filename); 00960 00961 previous=millis(); 00962 while(!setCommMode(GPS_BINARY_OFF) && (millis()-previous)<3000); 00963 delay(100); 00964 while(serialAvailable(_uart)>0) 00965 { 00966 serialRead(_uart); 00967 } 00968 // Iterates asking the GPS about available ephemeris (0..32) 00969 for(int a=1;a<33;a++) 00970 { 00971 tempBuffer[5]=a; // set SV ID 00972 getChecksum(tempBuffer); 00973 tempBuffer[7]=checkSUM[0]; 00974 tempBuffer[8]=checkSUM[1]; 00975 for(int b=0;b<11;b++) 00976 { 00977 printByte(tempBuffer[b],_uart); 00978 } 00979 // read ephemeris data and store into ByteIN 00980 while(end==0) 00981 { 00982 if(serialAvailable(_uart)>0) 00983 { 00984 ByteIN[counter3]=serialRead(_uart); 00985 counter3++; 00986 previous=millis(); 00987 } 00988 if( (millis()-previous) > interval ) 00989 { 00990 end=1; 00991 serialFlush(_uart); 00992 } 00993 } 00994 if( counter3>100 ) // ephemeris available 00995 { 00996 counter3=6; 00997 if( (ByteIN[0]!=0xA0) || (ByteIN[1]!=0xA2) ) break; 00998 while( counter3<96 ) 00999 { 01000 tempData[counter3-6]=ByteIN[counter3]; 01001 counter3++; 01002 } 01003 tempData[counter3]=0xAA; 01004 tempData[counter3+1]=0xAA; 01005 if(SD.writeSD(filename,tempData,aux*90)) error=1; 01006 else error=0; 01007 aux++; 01008 } 01009 counter3=0; 01010 end=0; 01011 previous=millis(); 01012 } 01013 if (error==1) if(SD.writeSD(filename,endFile,aux*90)) error=1; 01014 free(ByteIN); 01015 free(tempData); 01016 ByteIN=NULL; 01017 tempData=NULL; 01018 return error; 01019 }

| uint8_t WaspGPS::loadEphems | ( | ) |
It loads ephemeris from the SD card to the GPS receiver. It loads from file called 'FILE_EPHEMERIS'.
| void |
Definition at line 1027 of file WaspGPS.cpp.
References FILE_EPHEMERIS.
01028 { 01029 return loadEphems(FILE_EPHEMERIS); 01030 }
| uint8_t WaspGPS::loadEphems | ( | const char * | filename | ) |
It loads ephemeris from the SD card to the GPS receiver.
| const | char* filename : The file name to get the ephemeris from |
Definition at line 1039 of file WaspGPS.cpp.
References _uart, WaspSD::bufferBin, WaspSD::catBin(), checkSUM, delay(), WaspSD::flag, getChecksum(), GPS_BINARY_OFF, millis(), printByte(), SD, serialAvailable(), serialFlush(), serialRead(), and setCommMode().
01040 { 01041 uint8_t* tempData = (uint8_t*) calloc(99,sizeof(uint8_t)); 01042 uint8_t* answer = (uint8_t*) calloc(10,sizeof(uint8_t)); 01043 uint8_t endFile=0; 01044 uint16_t offset=0; 01045 uint8_t counter3=0; 01046 uint8_t end=0; 01047 uint16_t interval=1000; 01048 long previous=millis(); 01049 int8_t error=2; 01050 SD.flag = 0; 01051 01052 /*** Disable All Binary Messages ***/ 01053 while(!setCommMode(GPS_BINARY_OFF) && (millis()-previous)<3000); 01054 delay(100); 01055 while(serialAvailable(_uart)>0) 01056 { 01057 serialRead(_uart); 01058 } 01059 while( !endFile ) 01060 { 01061 SD.catBin(filename,offset,5); 01062 01063 if( (SD.bufferBin[0]==0xAA) && (SD.bufferBin[1]==0xBB) && (SD.bufferBin[2]==0xCC) && 01064 (SD.bufferBin[3]==0xCC) && (SD.bufferBin[4]==0xBB) ) endFile=1; 01065 01066 if (!endFile) 01067 { 01068 for(int a=0;a<5;a++) // Copy first 5 already read bytes 01069 { 01070 tempData[a+5]=SD.bufferBin[a]; 01071 } 01072 offset+=5; 01073 SD.catBin(filename,offset,85); 01074 01075 tempData[0]=0xA0; 01076 tempData[1]=0xA2; 01077 tempData[2]=0x00; 01078 tempData[3]=0x5B; 01079 tempData[4]=0x95; 01080 for(int b=10;b<95;b++) 01081 { 01082 tempData[b]=SD.bufferBin[b-10]; 01083 } 01084 tempData[95]=0x00; 01085 tempData[96]=0x00; 01086 tempData[97]=0xB0; 01087 tempData[98]=0xB3; 01088 getChecksum(tempData); 01089 tempData[95]=checkSUM[0]; 01090 tempData[96]=checkSUM[1]; 01091 for(int c=0;c<99;c++) 01092 { 01093 printByte(tempData[c],_uart); 01094 } 01095 delay(100); 01096 while(end==0) 01097 { 01098 if(serialAvailable(_uart)>0) 01099 { 01100 answer[counter3]=serialRead(_uart); 01101 counter3++; 01102 previous=millis(); 01103 } 01104 if( (millis()-previous) > interval ) 01105 { 01106 end=1; 01107 serialFlush(_uart); 01108 } 01109 } 01110 counter3=0; 01111 end=0; 01112 previous=millis(); 01113 if( (answer[0]==0xA0) && (answer[1]==0xA2) && (answer[2]==0x00) && (answer[3]==0x02) && 01114 (answer[4]==0x0B) && (answer[5]==0x95) && (answer[6]==0x00) && 01115 (answer[7]==0xA0) && (answer[8]==0xB0) && (answer[9]==0xB3) ) error=1; 01116 else error=0; 01117 offset+=85; 01118 } 01119 } 01120 free(answer); 01121 free(tempData); 01122 answer=NULL; 01123 tempData=NULL; 01124 return error; 01125 01126 }

| const char* WaspGPS::getLibVersion | ( | void | ) | [inline] |
| uint8_t WaspGPS::setCommMode | ( | uint16_t | mode | ) |
It sets communication mode: Binary or NMEA.
| uint16_t | mode : the communication mode. Possible values are GPS_BINARY, GPS_NMEA_GGA, GPS_NMEA_GLL, GPS_NMEA_GSA, GPS_NMEA_GSV, GPS_NMEA_RMC, GPS_NMEA_VTG, GPS_NMEA, GPS_BINARY_OFF |
Definition at line 299 of file WaspGPS.cpp.
References _baudRate, _uart, WaspUtils::arguments, commMode, delay(), getRaw(), GPS_BINARY, GPS_BINARY_OFF, GPS_NMEA, GPS_NMEA_GGA, GPS_NMEA_GLL, GPS_NMEA_GSA, GPS_NMEA_GSV, GPS_NMEA_RMC, GPS_NMEA_VTG, WaspUtils::inBuffer, printByte(), printString(), serialAvailable(), serialFlush(), serialRead(), WaspUtils::strExplode(), and Utils.
Referenced by check(), extractDate(), extractTime(), getAltitude(), getCourse(), getLatitude(), getLongitude(), getPosition(), getSpeed(), init(), loadEphems(), and saveEphems().
00300 { 00301 uint8_t tempBuffer[32] = 00302 {0xA0,0xA2,0x00,0x18,0x81,0x02,0x01,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01, 00303 0x00,0x01,0x00,0x01,0x00,0x01,0x12,0xC0,0x01,0x60,0xB0,0xB3}; 00304 uint8_t tempBuffer2[16] ={0xA0,0xA2,0x00,0x08,0xA6,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0xAA,0xB0,0xB3}; 00305 uint8_t byteIN[10]; 00306 commMode = mode; 00307 uint8_t valid=0; 00308 00309 switch(commMode) 00310 { 00311 case GPS_BINARY: sprintf(Utils.inBuffer,"$PSRF100,0,%u,8,1,0*0F",_baudRate); 00312 serialFlush(_uart); 00313 printString(Utils.inBuffer,_uart); 00314 printByte('\r',_uart); 00315 printByte('\n',_uart); 00316 delay(10); 00317 serialFlush(_uart); 00318 delay(10); 00319 if(serialAvailable(_uart)){ 00320 byteIN[0]=serialRead(_uart); 00321 if( (byteIN[0]=='$') || ( (byteIN[0]>'0') && (byteIN[0]<'Z') ) ) valid=0; 00322 else valid=1; 00323 } 00324 break; 00325 case GPS_BINARY_OFF: serialFlush(_uart); 00326 for(int a=0;a<16;a++) 00327 { 00328 printByte(tempBuffer2[a],_uart); 00329 //if(a==14) serialFlush(_uart); 00330 } 00331 delay(100); 00332 if(serialAvailable(_uart)) 00333 { 00334 for(int a=0;a<10;a++) 00335 { 00336 byteIN[a]=serialRead(_uart); 00337 } 00338 } 00339 if(byteIN[5]==0xA6) valid=1; 00340 else valid=0; 00341 break; 00342 case GPS_NMEA: tempBuffer[8]=0x01; 00343 tempBuffer[10]=0x01; 00344 tempBuffer[12]=0x01; 00345 tempBuffer[14]=0x01; 00346 tempBuffer[16]=0x01; 00347 tempBuffer[29]=0x65; 00348 for(int b=0;b<32;b++) 00349 { 00350 printByte(tempBuffer[b],1); 00351 } 00352 delay(10); 00353 getRaw(100); 00354 Utils.strExplode(Utils.inBuffer, ','); 00355 if( strcmp(Utils.arguments[0],"$GPGGA") ) 00356 { 00357 valid=0; 00358 } 00359 else valid=1; 00360 break; 00361 case GPS_NMEA_GGA: for(int c=0;c<32;c++) 00362 { 00363 printByte(tempBuffer[c],1); 00364 } 00365 delay(10); 00366 getRaw(100); 00367 Utils.strExplode(Utils.inBuffer, ','); 00368 if( strcmp(Utils.arguments[0],"$GPGGA") ) 00369 { 00370 valid=0; 00371 } 00372 else valid=1; 00373 break; 00374 case GPS_NMEA_GLL: tempBuffer[6]=0x00; 00375 tempBuffer[8]=0x01; 00376 for(int d=0;d<32;d++) 00377 { 00378 printByte(tempBuffer[d],1); 00379 } 00380 getRaw(100); 00381 Utils.strExplode(Utils.inBuffer, ','); 00382 if( strcmp(Utils.arguments[0],"$GPGLL") ) 00383 { 00384 valid=0; 00385 } 00386 else valid=1; 00387 break; 00388 case GPS_NMEA_GSA: tempBuffer[6]=0x00; 00389 tempBuffer[10]=0x01; 00390 for(int e=0;e<32;e++) 00391 { 00392 printByte(tempBuffer[e],1); 00393 } 00394 getRaw(100); 00395 Utils.strExplode(Utils.inBuffer, ','); 00396 if( strcmp(Utils.arguments[0],"$GPGSA") ) 00397 { 00398 valid=0; 00399 } 00400 else valid=1; 00401 break; 00402 case GPS_NMEA_GSV: tempBuffer[6]=0x00; 00403 tempBuffer[12]=0x01; 00404 for(int f=0;f<32;f++) 00405 { 00406 printByte(tempBuffer[f],1); 00407 } 00408 getRaw(100); 00409 Utils.strExplode(Utils.inBuffer, ','); 00410 if( strcmp(Utils.arguments[0],"$GPGSV") ) 00411 { 00412 valid=0; 00413 } 00414 else valid=1; 00415 break; 00416 case GPS_NMEA_RMC: tempBuffer[6]=0x00; 00417 tempBuffer[14]=0x01; 00418 for(int g=0;g<32;g++) 00419 { 00420 printByte(tempBuffer[g],1); 00421 } 00422 getRaw(100); 00423 Utils.strExplode(Utils.inBuffer, ','); 00424 if( strcmp(Utils.arguments[0],"$GPRMC") ) 00425 { 00426 valid=0; 00427 } 00428 else valid=1; 00429 break; 00430 case GPS_NMEA_VTG: tempBuffer[6]=0x00; 00431 tempBuffer[16]=0x01; 00432 for(int h=0;h<32;h++) 00433 { 00434 printByte(tempBuffer[h],1); 00435 } 00436 getRaw(100); 00437 Utils.strExplode(Utils.inBuffer, ','); 00438 if( strcmp(Utils.arguments[0],"$GPVTG") ) 00439 { 00440 valid=0; 00441 } 00442 else valid=1; 00443 break; 00444 } 00445 return valid; 00446 }


| uint8_t WaspGPS::getCommMode | ( | void | ) |
It gets the communication mode on use.
| void |
Definition at line 452 of file WaspGPS.cpp.
References commMode.
00453 { 00454 return commMode; 00455 }
| uint8_t WaspGPS::getPosition | ( | ) |
It gets the latitude, longitude, altitude, speed, course, time and date.
| void |
Definition at line 1135 of file WaspGPS.cpp.
References _uart, altitude, WaspUtils::arguments, commMode, course, dateGPS, delay(), flag, GPS_BINARY, GPS_BINARY_OFF, GPS_INVALID, GPS_NMEA, GPS_TIMEOUT, WaspUtils::inBuffer, latitude, longitude, MAX_ARGS, millis(), serialAvailable(), serialRead(), setCommMode(), speed, WaspUtils::strExplode(), timeGPS, and Utils.
01136 { 01137 flag &= ~(GPS_INVALID); 01138 01139 uint16_t currentSentences = commMode; 01140 long previous=0; 01141 uint8_t complete = 0; 01142 01143 uint8_t byteGPS = 0; // the last byte coming through the port 01144 int i = 0; // count the amount of bytes read 01145 uint32_t timeout = 1000; // millis to wait before declaring timeout 01146 01147 // get all NMEA sentences 01148 while(!setCommMode(GPS_NMEA) && (millis()-previous)<3000); 01149 01150 // separates all the subarrays from Utils.inBuffer into the Utils.arguments array 01151 Utils.strExplode(Utils.inBuffer, ','); 01152 01153 01154 previous = millis(); 01155 while( complete<3 && (millis()-previous)<5000 ) 01156 { 01157 if( !strcmp(Utils.arguments[0],"$GPGGA") ) 01158 { 01159 for(int i=0;i<MAX_ARGS;i++) timeGPS[i]=Utils.arguments[1][i]; 01160 for(int i=0;i<MAX_ARGS;i++) latitude[i]=Utils.arguments[2][i]; 01161 for(int i=0;i<MAX_ARGS;i++) longitude[i]=Utils.arguments[4][i]; 01162 for(int i=0;i<MAX_ARGS;i++) altitude[i]=Utils.arguments[9][i]; 01163 complete++; 01164 } 01165 else if( !strcmp(Utils.arguments[0],"$GPRMC") ) 01166 { 01167 for(int i=0;i<MAX_ARGS;i++) dateGPS[i]=Utils.arguments[9][i]; 01168 for(int i=0;i<MAX_ARGS;i++) timeGPS[i]=Utils.arguments[1][i]; 01169 complete++; 01170 } 01171 else if( !strcmp(Utils.arguments[0],"$GPVTG") ) 01172 { 01173 for(int i=0;i<MAX_ARGS;i++) speed[i]=Utils.arguments[7][i]; 01174 for(int i=0;i<MAX_ARGS;i++) course[i]=Utils.arguments[1][i]; 01175 complete++; 01176 } 01177 01178 while(!serialAvailable(_uart) && timeout > 0) { delay(1); timeout--; }; 01179 01180 if (timeout <= 0) 01181 { 01182 flag |= GPS_TIMEOUT; 01183 return 1; 01184 } 01185 01186 byteGPS = serialRead(_uart); // read the first byte coming through the port 01187 01188 while(byteGPS != '$') 01189 { 01190 if(serialAvailable(_uart) > 0){ 01191 byteGPS = serialRead(_uart); // flush incomplete sentences 01192 } 01193 } 01194 Utils.inBuffer[i]=byteGPS; 01195 i++; 01196 while(i <= 1 || (byteGPS != '*' && byteGPS != '$' && i < 100)){ // read the GPS sentence 01197 if(serialAvailable(_uart) > 0) 01198 { 01199 byteGPS = serialRead(_uart); 01200 if (byteGPS != '*' && byteGPS != '$' && i < 100) Utils.inBuffer[i]=byteGPS; 01201 i++; 01202 } 01203 } 01204 01205 if (byteGPS == '\n' || i == 100) Utils.inBuffer[i-1] = '\0'; 01206 else Utils.inBuffer[i] = '\0'; 01207 01208 i=0; 01209 01210 Utils.strExplode(Utils.inBuffer, ','); 01211 } 01212 01213 // return to previous state 01214 previous=millis(); 01215 if (currentSentences == GPS_BINARY_OFF ) while( !setCommMode(GPS_BINARY) && (millis()-previous)<3000); 01216 delay(100); 01217 previous=millis(); 01218 while(!setCommMode(currentSentences) && (millis()-previous)<3000); 01219 01220 if( flag & GPS_INVALID ) return 0; 01221 else return 1; 01222 }

| long WaspGPS::_baudRate |
Variable : Baudrate used to init the UART and communicate with GPS receiver.
Possible values are 4800,9600,19200,38400,57600,115200.
4800 is the only value supported now by the API.
The reason is GPS receiver always starts at 4800bps, so it would be necessary to open UART at 4800, change speed, close UART and open it again at new speed.
If a higher speed wants to be used, previously explained reason has to be managed properly.
Definition at line 405 of file WaspGPS.h.
Referenced by begin(), setCommMode(), and WaspGPS().
| uint8_t WaspGPS::_uart |
Variable : UART used to communicate with GPS receiver.
Possible values are: 0 or 1.
UART used now to communicate with GPS is UART1, so '1' must be set.
Definition at line 413 of file WaspGPS.h.
Referenced by begin(), close(), getPosition(), getRaw(), loadEphems(), saveEphems(), setCommMode(), and WaspGPS().
| bool WaspGPS::fixValid |
Variable : Determines whether the last reading was valid or not.
TRUE if the last reading is valid.
FALSE if the last reading is not valid.
Definition at line 421 of file WaspGPS.h.
Referenced by dataValid(), getAltitude(), getLatitude(), and getLongitude().
| uint16_t WaspGPS::flag |
Variable : Flag used to determine if an error occurred while executing some function.
Possible values are related below.
Definition at line 431 of file WaspGPS.h.
Referenced by checkSum(), extractDate(), extractTime(), getAltitude(), getCourse(), getLatitude(), getLongitude(), getPosition(), getRaw(), getSpeed(), saveEphems(), and WaspGPS().
| uint16_t WaspGPS::commMode |
Variable : Communication mode. Two possibilities available --> binary mode or NMEA mode.
Possible values are related below.
Definition at line 440 of file WaspGPS.h.
Referenced by check(), extractDate(), extractTime(), getAltitude(), getCommMode(), getCourse(), getLatitude(), getLongitude(), getPosition(), getSpeed(), setCommMode(), and WaspGPS().
| uint8_t WaspGPS::pwrMode |
| uint8_t WaspGPS::wakeMode |
| char WaspGPS::timeGPS[MAX_ARGS] |
Variable : Time extracted from NMEA GGA sentence received from GPS receiver.
String that contains the time extracted from NMEA GGA sentence.
To store the time 13:30:00, it is stored in this way: '133000'
Definition at line 465 of file WaspGPS.h.
Referenced by extractTime(), getPosition(), getTime(), and WaspRTC::setTimeFromGPS().
| char WaspGPS::dateGPS[MAX_ARGS] |
Variable : Date extracted from NMEA RMC sentence received from GPS receiver.
String that contains the date extracted from NMEA RMC sentence.
To store the date 23rd of March 1994, it is stored in this way: '230394'
Definition at line 473 of file WaspGPS.h.
Referenced by extractDate(), getDate(), getPosition(), and WaspRTC::setTimeFromGPS().
| char* WaspGPS::clkOffset |
| char* WaspGPS::timeOfWeek |
| char* WaspGPS::weekNo |
| char* WaspGPS::channel |
| char* WaspGPS::resetCfg |
| char* WaspGPS::coordinateLat |
| char* WaspGPS::coordinateLon |
| char* WaspGPS::coordinateAl |
| uint8_t WaspGPS::checksum |
Variable : the frame checksum.
Definition at line 520 of file WaspGPS.h.
Referenced by setChecksum(), and WaspGPS().
| char WaspGPS::latitude[MAX_ARGS] |
Variable : it stores the latitude given by the GPS module.
Definition at line 525 of file WaspGPS.h.
Referenced by getLatitude(), and getPosition().
| char WaspGPS::longitude[MAX_ARGS] |
Variable : it stores the longitude given by the GPS module.
Definition at line 530 of file WaspGPS.h.
Referenced by getLongitude(), and getPosition().
| char WaspGPS::speed[MAX_ARGS] |
Variable : it stores the speed given by the GPS module.
Definition at line 535 of file WaspGPS.h.
Referenced by getPosition(), and getSpeed().
| char WaspGPS::altitude[MAX_ARGS] |
Variable : it stores the altitude given by the GPS module.
Definition at line 540 of file WaspGPS.h.
Referenced by getAltitude(), and getPosition().
| char WaspGPS::course[MAX_ARGS] |
Variable : it stores the course given by the GPS module.
Definition at line 545 of file WaspGPS.h.
Referenced by getCourse(), and getPosition().
| uint8_t WaspGPS::reboot |
| uint8_t WaspGPS::checkSUM[2] |
Variable : for storing the frame checksum.
Definition at line 555 of file WaspGPS.h.
Referenced by getChecksum(), loadEphems(), and saveEphems().
1.5.6