This is an example application based on Mbed-OS LoRaWAN protocol APIs. The Mbed-OS LoRaWAN stack implementation is compliant with LoRaWAN v1.0.2 specification.

Dependencies:   Lorawan_Version_0_1

Dependents:   Lorawan_Version_0_1

Committer:
jacktractive
Date:
Thu Nov 28 15:44:17 2019 +0000
Revision:
61:2b30d8e75fe7
Child:
62:35d41c8b9419
V1.0 Laeuft

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jacktractive 61:2b30d8e75fe7 1 /* mbed GPS Module Library
jacktractive 61:2b30d8e75fe7 2 * Copyright (c) 2008-2010, sford
jacktractive 61:2b30d8e75fe7 3 * Copyright (c) 2013, B.Adryan
jacktractive 61:2b30d8e75fe7 4 *
jacktractive 61:2b30d8e75fe7 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
jacktractive 61:2b30d8e75fe7 6 * of this software and associated documentation files (the "Software"), to deal
jacktractive 61:2b30d8e75fe7 7 * in the Software without restriction, including without limitation the rights
jacktractive 61:2b30d8e75fe7 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jacktractive 61:2b30d8e75fe7 9 * copies of the Software, and to permit persons to whom the Software is
jacktractive 61:2b30d8e75fe7 10 * furnished to do so, subject to the following conditions:
jacktractive 61:2b30d8e75fe7 11 *
jacktractive 61:2b30d8e75fe7 12 * The above copyright notice and this permission notice shall be included in
jacktractive 61:2b30d8e75fe7 13 * all copies or substantial portions of the Software.
jacktractive 61:2b30d8e75fe7 14 *
jacktractive 61:2b30d8e75fe7 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jacktractive 61:2b30d8e75fe7 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jacktractive 61:2b30d8e75fe7 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jacktractive 61:2b30d8e75fe7 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jacktractive 61:2b30d8e75fe7 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jacktractive 61:2b30d8e75fe7 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jacktractive 61:2b30d8e75fe7 21 * THE SOFTWARE.
jacktractive 61:2b30d8e75fe7 22 */
jacktractive 61:2b30d8e75fe7 23
jacktractive 61:2b30d8e75fe7 24 #include "GPS.h"
jacktractive 61:2b30d8e75fe7 25
jacktractive 61:2b30d8e75fe7 26 GPS::GPS(PinName tx, PinName rx, int Baud) : _gps(tx, rx)
jacktractive 61:2b30d8e75fe7 27 {
jacktractive 61:2b30d8e75fe7 28 _gps.baud(Baud);
jacktractive 61:2b30d8e75fe7 29 longitude = 0.0;
jacktractive 61:2b30d8e75fe7 30 latitude = 0.0;
jacktractive 61:2b30d8e75fe7 31 }
jacktractive 61:2b30d8e75fe7 32
jacktractive 61:2b30d8e75fe7 33 int GPS::sample()
jacktractive 61:2b30d8e75fe7 34 {
jacktractive 61:2b30d8e75fe7 35
jacktractive 61:2b30d8e75fe7 36 int lock;
jacktractive 61:2b30d8e75fe7 37
jacktractive 61:2b30d8e75fe7 38 while(1) {
jacktractive 61:2b30d8e75fe7 39 getline();
jacktractive 61:2b30d8e75fe7 40
jacktractive 61:2b30d8e75fe7 41 // Check if it is a GPGGA msg (matches both locked and non-locked msg)
jacktractive 61:2b30d8e75fe7 42 if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c,%f", &time, &latitude, &ns, &longitude, &ew, &lock, &sats, &hdop, &alt, &unit, &geoid) >= 1) {
jacktractive 61:2b30d8e75fe7 43 if(!lock) {
jacktractive 61:2b30d8e75fe7 44 time = 0.0;
jacktractive 61:2b30d8e75fe7 45 longitude = 0.0;
jacktractive 61:2b30d8e75fe7 46 latitude = 0.0;
jacktractive 61:2b30d8e75fe7 47 sats = 0;
jacktractive 61:2b30d8e75fe7 48 hdop = 0.0;
jacktractive 61:2b30d8e75fe7 49 alt = 0.0;
jacktractive 61:2b30d8e75fe7 50 geoid = 0.0;
jacktractive 61:2b30d8e75fe7 51 return 0;
jacktractive 61:2b30d8e75fe7 52 } else {
jacktractive 61:2b30d8e75fe7 53 //GPGGA format according http://aprs.gids.nl/nmea/#gga
jacktractive 61:2b30d8e75fe7 54 // time (float), lat (f), (N/S) (c), long (f), (E/W) (c), fix (d), sats (d),
jacktractive 61:2b30d8e75fe7 55 // hdop (float), altitude (float), M, geoid (float), M, , ,
jacktractive 61:2b30d8e75fe7 56 //GPGGA,092010.000,5210.9546,N,00008.8913,E,1,07,1.3,9.7,M,47.0,M,,0000*5D
jacktractive 61:2b30d8e75fe7 57
jacktractive 61:2b30d8e75fe7 58 //format utc time to beijing time,add 8 time zone
jacktractive 61:2b30d8e75fe7 59 time = time + 80000.00f;
jacktractive 61:2b30d8e75fe7 60 hour = int(time) / 10000;
jacktractive 61:2b30d8e75fe7 61 minute = (int(time) % 10000) / 100;
jacktractive 61:2b30d8e75fe7 62 seconed = int(time) % 100;
jacktractive 61:2b30d8e75fe7 63
jacktractive 61:2b30d8e75fe7 64 return 1;
jacktractive 61:2b30d8e75fe7 65 }
jacktractive 61:2b30d8e75fe7 66 }
jacktractive 61:2b30d8e75fe7 67 }
jacktractive 61:2b30d8e75fe7 68 }
jacktractive 61:2b30d8e75fe7 69
jacktractive 61:2b30d8e75fe7 70 float GPS::trunc(float v)
jacktractive 61:2b30d8e75fe7 71 {
jacktractive 61:2b30d8e75fe7 72 if(v < 0.0) {
jacktractive 61:2b30d8e75fe7 73 v*= -1.0;
jacktractive 61:2b30d8e75fe7 74 v = floor(v);
jacktractive 61:2b30d8e75fe7 75 v*=-1.0;
jacktractive 61:2b30d8e75fe7 76 } else {
jacktractive 61:2b30d8e75fe7 77 v = floor(v);
jacktractive 61:2b30d8e75fe7 78 }
jacktractive 61:2b30d8e75fe7 79 return v;
jacktractive 61:2b30d8e75fe7 80 }
jacktractive 61:2b30d8e75fe7 81
jacktractive 61:2b30d8e75fe7 82 void GPS::getline()
jacktractive 61:2b30d8e75fe7 83 {
jacktractive 61:2b30d8e75fe7 84 while(_gps.getc() != '$'); // wait for the start of a line
jacktractive 61:2b30d8e75fe7 85 for(int i=0; i<256; i++) {
jacktractive 61:2b30d8e75fe7 86 msg[i] = _gps.getc();
jacktractive 61:2b30d8e75fe7 87 if(msg[i] == '\r') {
jacktractive 61:2b30d8e75fe7 88 msg[i] = 0;
jacktractive 61:2b30d8e75fe7 89 return;
jacktractive 61:2b30d8e75fe7 90 }
jacktractive 61:2b30d8e75fe7 91 }
jacktractive 61:2b30d8e75fe7 92 error("Overflowed message limit");
jacktractive 61:2b30d8e75fe7 93 }