User manual

LPCXpresso Experiment Kit - User’s Guide
Page 121
Copyright 2013 © Embedded Artists AB
**
** Descriptions: Reads and parses the next set of GPS data.
**
** parameters: None
** Returned value: The parsed information
**
*****************************************************************************/
const gpsData* GPSRetreiveData(void)
{
uint8_t * pattern = (uint8_t*)"GPGGA";
while (1) {
uint8_t buf[100];
uint8_t ch = 0;
uint8_t *ptr = 0;
int index = 0;
// Retrieve the first byte
if (!UARTGetChar(&ch))
continue;
// look for "$GPGGA," header
if (ch != '$') {
continue;
}
// Retrieve the next six bytes
for (index=0; index<6; index++) {
buf[index] = UARTGetCharBlock();
}
//Check if its Global Positioning System fixed Data
if (hasPattern((uint8_t*)&buf, pattern) == 0) {
continue;
}
//Retrieve the data from the GPS module
for (index=0; index<100; index++) {
buf[index] = UARTGetCharBlock();
if (buf[index] == '\r') {
buf[index] = END_OF_MESSAGE;
break;
}
}
ptr = &buf[0];
//parse UTC time
parseUTC(&ptr);
//parse Latitude
parseLatitude(&ptr);
break;
}
return &data;
}
int main (void)
{
//Set LED1-LED8 pins as outputs
...
//Set SW2/SW3 pins as inputs
...
//initialize the UART to 9600bps 8N1
UARTInit(9600);
printf((uint8_t*)"\nWaiting for GPS data...");