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
Diff: aconnoHelpers/aconnoHelpers.cpp
- Revision:
- 9:f943c09d9173
- Parent:
- 8:2bf886335fd0
diff -r 2bf886335fd0 -r f943c09d9173 aconnoHelpers/aconnoHelpers.cpp
--- a/aconnoHelpers/aconnoHelpers.cpp Fri Nov 30 16:19:41 2018 +0100
+++ b/aconnoHelpers/aconnoHelpers.cpp Wed Dec 19 15:12:25 2018 +0100
@@ -10,13 +10,24 @@
#include "gnss.h"
#include "aconnoConfig.h"
-bool getGPSData(char *location, GnssSerial *gnss)
+bool getGPSData(char *location, GnssSerial *gnss, uint32_t timeoutS)
{
int gnssReturnCode;
- int length;
- char buffer[505];
+ int length;
+ char buffer[505];
bool gotLocationFlag = false;
-
+ int begin;
+ int end;
+
+ if(!timeoutS)
+ {
+ // Max number of seconds
+ timeoutS -= 1;
+ }
+
+ Timer timeoutTimer;
+ timeoutTimer.start();
+ begin = timeoutTimer.read();
do
{
gnssReturnCode = gnss->getMessage(buffer, sizeof(buffer));
@@ -26,50 +37,32 @@
length = LENGTH(gnssReturnCode);
if ((PROTOCOL(gnssReturnCode) == GnssParser::NMEA) && (length > 6))
{
- // Talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GNSS
+ // Talker is $GA=Galileo $GB=Beidou $GL=Glonass
+ // $GN=Combined $GP=GNSS
if ((buffer[0] == '$') || buffer[1] == 'G')
{
- if (CHECK_TALKER("GLL"))
- {
-
+ 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);
+ gnss->getNmeaItem(6, buffer, length, ch) &&
+ (ch == 'A'))
+ {
+ sprintf(location, "%.5f %.5f", 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);
+ end = timeoutTimer.read();
+ } while (!gotLocationFlag && (end - begin) < timeoutS);
+
+ printf("Location time: %d\r\n", (end - begin));
+ return gotLocationFlag;
}
+
