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@9:f943c09d9173, 2018-12-19 (annotated)
- Committer:
- jurica238814
- Date:
- Wed Dec 19 15:12:25 2018 +0100
- Revision:
- 9:f943c09d9173
- Parent:
- 8:2bf886335fd0
Stable version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 8:2bf886335fd0 | 1 | /** |
jurica238814 | 8:2bf886335fd0 | 2 | * aconno helpers |
jurica238814 | 8:2bf886335fd0 | 3 | * Set of general purpose fuctions used within aconno projects |
jurica238814 | 8:2bf886335fd0 | 4 | * |
jurica238814 | 8:2bf886335fd0 | 5 | */ |
jurica238814 | 8:2bf886335fd0 | 6 | |
jurica238814 | 8:2bf886335fd0 | 7 | #include "mbed.h" |
jurica238814 | 8:2bf886335fd0 | 8 | #include "aconnoHelpers.h" |
jurica238814 | 8:2bf886335fd0 | 9 | #include "stdlib.h" |
jurica238814 | 8:2bf886335fd0 | 10 | #include "gnss.h" |
jurica238814 | 8:2bf886335fd0 | 11 | #include "aconnoConfig.h" |
jurica238814 | 8:2bf886335fd0 | 12 | |
jurica238814 | 9:f943c09d9173 | 13 | bool getGPSData(char *location, GnssSerial *gnss, uint32_t timeoutS) |
jurica238814 | 8:2bf886335fd0 | 14 | { |
jurica238814 | 8:2bf886335fd0 | 15 | int gnssReturnCode; |
jurica238814 | 9:f943c09d9173 | 16 | int length; |
jurica238814 | 9:f943c09d9173 | 17 | char buffer[505]; |
jurica238814 | 8:2bf886335fd0 | 18 | bool gotLocationFlag = false; |
jurica238814 | 9:f943c09d9173 | 19 | int begin; |
jurica238814 | 9:f943c09d9173 | 20 | int end; |
jurica238814 | 9:f943c09d9173 | 21 | |
jurica238814 | 9:f943c09d9173 | 22 | if(!timeoutS) |
jurica238814 | 9:f943c09d9173 | 23 | { |
jurica238814 | 9:f943c09d9173 | 24 | // Max number of seconds |
jurica238814 | 9:f943c09d9173 | 25 | timeoutS -= 1; |
jurica238814 | 9:f943c09d9173 | 26 | } |
jurica238814 | 9:f943c09d9173 | 27 | |
jurica238814 | 9:f943c09d9173 | 28 | Timer timeoutTimer; |
jurica238814 | 9:f943c09d9173 | 29 | timeoutTimer.start(); |
jurica238814 | 9:f943c09d9173 | 30 | begin = timeoutTimer.read(); |
jurica238814 | 8:2bf886335fd0 | 31 | do |
jurica238814 | 8:2bf886335fd0 | 32 | { |
jurica238814 | 8:2bf886335fd0 | 33 | gnssReturnCode = gnss->getMessage(buffer, sizeof(buffer)); |
jurica238814 | 8:2bf886335fd0 | 34 | if (gnssReturnCode > 0) |
jurica238814 | 8:2bf886335fd0 | 35 | { |
jurica238814 | 8:2bf886335fd0 | 36 | // Msg from GNSS module received |
jurica238814 | 8:2bf886335fd0 | 37 | length = LENGTH(gnssReturnCode); |
jurica238814 | 8:2bf886335fd0 | 38 | if ((PROTOCOL(gnssReturnCode) == GnssParser::NMEA) && (length > 6)) |
jurica238814 | 8:2bf886335fd0 | 39 | { |
jurica238814 | 9:f943c09d9173 | 40 | // Talker is $GA=Galileo $GB=Beidou $GL=Glonass |
jurica238814 | 9:f943c09d9173 | 41 | // $GN=Combined $GP=GNSS |
jurica238814 | 8:2bf886335fd0 | 42 | if ((buffer[0] == '$') || buffer[1] == 'G') |
jurica238814 | 8:2bf886335fd0 | 43 | { |
jurica238814 | 9:f943c09d9173 | 44 | if (CHECK_TALKER("GLL")) |
jurica238814 | 9:f943c09d9173 | 45 | { |
jurica238814 | 9:f943c09d9173 | 46 | |
jurica238814 | 8:2bf886335fd0 | 47 | double latitude = 0, longitude = 0; |
jurica238814 | 8:2bf886335fd0 | 48 | char ch; |
jurica238814 | 8:2bf886335fd0 | 49 | if (gnss->getNmeaAngle(1, buffer, length, latitude) && |
jurica238814 | 8:2bf886335fd0 | 50 | gnss->getNmeaAngle(3, buffer, length, longitude) && |
jurica238814 | 9:f943c09d9173 | 51 | gnss->getNmeaItem(6, buffer, length, ch) && |
jurica238814 | 9:f943c09d9173 | 52 | (ch == 'A')) |
jurica238814 | 9:f943c09d9173 | 53 | { |
jurica238814 | 9:f943c09d9173 | 54 | sprintf(location, "%.5f %.5f", latitude, longitude); |
jurica238814 | 8:2bf886335fd0 | 55 | printf("Got location!\r\n"); |
jurica238814 | 8:2bf886335fd0 | 56 | gotLocationFlag = true; |
jurica238814 | 8:2bf886335fd0 | 57 | } |
jurica238814 | 8:2bf886335fd0 | 58 | } |
jurica238814 | 8:2bf886335fd0 | 59 | } |
jurica238814 | 8:2bf886335fd0 | 60 | } |
jurica238814 | 8:2bf886335fd0 | 61 | } |
jurica238814 | 9:f943c09d9173 | 62 | end = timeoutTimer.read(); |
jurica238814 | 9:f943c09d9173 | 63 | } while (!gotLocationFlag && (end - begin) < timeoutS); |
jurica238814 | 9:f943c09d9173 | 64 | |
jurica238814 | 9:f943c09d9173 | 65 | printf("Location time: %d\r\n", (end - begin)); |
jurica238814 | 9:f943c09d9173 | 66 | return gotLocationFlag; |
jurica238814 | 8:2bf886335fd0 | 67 | } |
jurica238814 | 9:f943c09d9173 | 68 |