The program sends the current location over the cellular network.
Dependencies: aconno_I2C ublox-at-cellular-interface gnss ublox-cellular-base Lis2dh12 ublox-cellular-base-n2xx ublox-at-cellular-interface-n2xx low-power-sleep
Fork of example-gnss by
aconnoHelpers/aconnoHelpers.cpp
- Committer:
- jurica238814
- Date:
- 2018-11-30
- Revision:
- 8:2bf886335fd0
- Child:
- 9:f943c09d9173
File content as of revision 8:2bf886335fd0:
/**
* aconno helpers
* Set of general purpose fuctions used within aconno projects
*
*/
#include "mbed.h"
#include "aconnoHelpers.h"
#include "stdlib.h"
#include "gnss.h"
#include "aconnoConfig.h"
bool getGPSData(char *location, GnssSerial *gnss)
{
int gnssReturnCode;
int length;
char buffer[505];
bool gotLocationFlag = false;
do
{
gnssReturnCode = gnss->getMessage(buffer, sizeof(buffer));
if (gnssReturnCode > 0)
{
// Msg from GNSS module received
length = LENGTH(gnssReturnCode);
if ((PROTOCOL(gnssReturnCode) == GnssParser::NMEA) && (length > 6))
{
// Talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GNSS
if ((buffer[0] == '$') || buffer[1] == 'G')
{
if (CHECK_TALKER("GLL"))
{
double latitude = 0, longitude = 0;
char ch;
if (gnss->getNmeaAngle(1, buffer, length, latitude) &&
gnss->getNmeaAngle(3, buffer, length, longitude) &&
gnss->getNmeaItem(6, buffer, length, ch) && (ch == 'A')) {
sprintf(location, "GNSS: location is %.5f %.5f.", latitude, longitude);
//printf("I am here: https://maps.google.com/?q=%.5f,%.5f\r\n\r\n",
// latitude, longitude);
printf("Got location!\r\n");
gotLocationFlag = true;
}
}
else if (CHECK_TALKER("GGA"))
{
double altitude = 0;
const char *timeString = NULL;
// Altitude
if (gnss->getNmeaItem(9, buffer, length, altitude))
{
printf("\r\nGNSS: altitude is %.1f m.\r\n", altitude);
}
// Time
timeString = gnss->findNmeaItemPos(1, buffer, buffer + length);
if (timeString != NULL) {
printf("\r\nGNSS: time is %.6s.\r\n\r\n", timeString);
}
}
else if (CHECK_TALKER("VTG"))
{
double speed = 0;
// Speed
if (gnss->getNmeaItem(7, buffer, length, speed))
{
printf("\r\nGNSS: speed is %.1f km/h.\r\n\r\n", speed);
}
}
}
}
}
}while(!gotLocationFlag);
}
