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:
Wed Dec 11 19:35:25 2019 +0000
Revision:
63:2bfceda4c30c
Parent:
62:35d41c8b9419
Child:
64:85fa08519e1e
GPS test output

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 62:35d41c8b9419 25 int i ;
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 63:2bfceda4c30c 31 _gps.printf("$$PMTK161,1*28\r\n"); //wake up
jacktractive 61:2b30d8e75fe7 32 }
jacktractive 61:2b30d8e75fe7 33
jacktractive 63:2bfceda4c30c 34
jacktractive 63:2bfceda4c30c 35
jacktractive 63:2bfceda4c30c 36
jacktractive 63:2bfceda4c30c 37
jacktractive 63:2bfceda4c30c 38
jacktractive 63:2bfceda4c30c 39
jacktractive 63:2bfceda4c30c 40
jacktractive 63:2bfceda4c30c 41
jacktractive 63:2bfceda4c30c 42
jacktractive 63:2bfceda4c30c 43
jacktractive 63:2bfceda4c30c 44
jacktractive 63:2bfceda4c30c 45
jacktractive 61:2b30d8e75fe7 46 int GPS::sample()
jacktractive 61:2b30d8e75fe7 47 {
jacktractive 61:2b30d8e75fe7 48
jacktractive 61:2b30d8e75fe7 49 int lock;
jacktractive 63:2bfceda4c30c 50 int h;
jacktractive 61:2b30d8e75fe7 51
jacktractive 63:2bfceda4c30c 52 printf("GPS suchen:");
jacktractive 63:2bfceda4c30c 53
jacktractive 63:2bfceda4c30c 54 for (h = 0; h < 6; h++)
jacktractive 63:2bfceda4c30c 55 {
jacktractive 63:2bfceda4c30c 56 printf("\n%Try: %i:",h);
jacktractive 61:2b30d8e75fe7 57 getline();
jacktractive 63:2bfceda4c30c 58
jacktractive 63:2bfceda4c30c 59
jacktractive 63:2bfceda4c30c 60
jacktractive 61:2b30d8e75fe7 61 // Check if it is a GPGGA msg (matches both locked and non-locked msg)
jacktractive 63:2bfceda4c30c 62 //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 63:2bfceda4c30c 63
jacktractive 63:2bfceda4c30c 64 //printf("\nQualität: %f %f %f\n",time,longitude,latitude);
jacktractive 63:2bfceda4c30c 65
jacktractive 63:2bfceda4c30c 66
jacktractive 63:2bfceda4c30c 67 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)>0) {
jacktractive 63:2bfceda4c30c 68 if(false) {
jacktractive 63:2bfceda4c30c 69 //time = 0.0;
jacktractive 63:2bfceda4c30c 70 //longitude = 0.0;
jacktractive 63:2bfceda4c30c 71 //latitude = 0.0;
jacktractive 63:2bfceda4c30c 72 //sats = 0;
jacktractive 63:2bfceda4c30c 73 ////hdop = 0.0;
jacktractive 63:2bfceda4c30c 74 //alt = 0.0;
jacktractive 63:2bfceda4c30c 75 //geoid = 0.0;
jacktractive 63:2bfceda4c30c 76
jacktractive 63:2bfceda4c30c 77 printf("\n Fehler: %f %ih %im %is\n",time,hour,minute,seconed);
jacktractive 61:2b30d8e75fe7 78 return 0;
jacktractive 61:2b30d8e75fe7 79 } else {
jacktractive 61:2b30d8e75fe7 80 //GPGGA format according http://aprs.gids.nl/nmea/#gga
jacktractive 61:2b30d8e75fe7 81 // time (float), lat (f), (N/S) (c), long (f), (E/W) (c), fix (d), sats (d),
jacktractive 61:2b30d8e75fe7 82 // hdop (float), altitude (float), M, geoid (float), M, , ,
jacktractive 61:2b30d8e75fe7 83 //GPGGA,092010.000,5210.9546,N,00008.8913,E,1,07,1.3,9.7,M,47.0,M,,0000*5D
jacktractive 61:2b30d8e75fe7 84
jacktractive 61:2b30d8e75fe7 85 //format utc time to beijing time,add 8 time zone
jacktractive 63:2bfceda4c30c 86 time = time;// + 80000.00f;
jacktractive 61:2b30d8e75fe7 87 hour = int(time) / 10000;
jacktractive 61:2b30d8e75fe7 88 minute = (int(time) % 10000) / 100;
jacktractive 61:2b30d8e75fe7 89 seconed = int(time) % 100;
jacktractive 63:2bfceda4c30c 90
jacktractive 63:2bfceda4c30c 91 printf("\n Erfolg: %f %ih %im %is\n",time,hour,minute,seconed);
jacktractive 63:2bfceda4c30c 92
jacktractive 61:2b30d8e75fe7 93 return 1;
jacktractive 61:2b30d8e75fe7 94 }
jacktractive 63:2bfceda4c30c 95 }
jacktractive 63:2bfceda4c30c 96
jacktractive 63:2bfceda4c30c 97 }
jacktractive 63:2bfceda4c30c 98
jacktractive 63:2bfceda4c30c 99 return 0 ;
jacktractive 63:2bfceda4c30c 100
jacktractive 63:2bfceda4c30c 101
jacktractive 61:2b30d8e75fe7 102 }
jacktractive 61:2b30d8e75fe7 103
jacktractive 61:2b30d8e75fe7 104 float GPS::trunc(float v)
jacktractive 61:2b30d8e75fe7 105 {
jacktractive 61:2b30d8e75fe7 106 if(v < 0.0) {
jacktractive 61:2b30d8e75fe7 107 v*= -1.0;
jacktractive 61:2b30d8e75fe7 108 v = floor(v);
jacktractive 61:2b30d8e75fe7 109 v*=-1.0;
jacktractive 61:2b30d8e75fe7 110 } else {
jacktractive 61:2b30d8e75fe7 111 v = floor(v);
jacktractive 61:2b30d8e75fe7 112 }
jacktractive 61:2b30d8e75fe7 113 return v;
jacktractive 61:2b30d8e75fe7 114 }
jacktractive 61:2b30d8e75fe7 115
jacktractive 61:2b30d8e75fe7 116 void GPS::getline()
jacktractive 61:2b30d8e75fe7 117 {
jacktractive 63:2bfceda4c30c 118
jacktractive 61:2b30d8e75fe7 119 while(_gps.getc() != '$'); // wait for the start of a line
jacktractive 61:2b30d8e75fe7 120 for(int i=0; i<256; i++) {
jacktractive 61:2b30d8e75fe7 121 msg[i] = _gps.getc();
jacktractive 63:2bfceda4c30c 122 printf("%c",msg[i]);
jacktractive 61:2b30d8e75fe7 123 if(msg[i] == '\r') {
jacktractive 61:2b30d8e75fe7 124 msg[i] = 0;
jacktractive 63:2bfceda4c30c 125
jacktractive 63:2bfceda4c30c 126 if (msg[3] == 'S' and msg[4] == 'V')
jacktractive 63:2bfceda4c30c 127 {printf("\nAnzahl Satelliten: %c",msg[11]); }
jacktractive 63:2bfceda4c30c 128
jacktractive 61:2b30d8e75fe7 129 return;
jacktractive 61:2b30d8e75fe7 130 }
jacktractive 61:2b30d8e75fe7 131 }
jacktractive 61:2b30d8e75fe7 132 error("Overflowed message limit");
jacktractive 61:2b30d8e75fe7 133 }