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:
Tue Jan 28 14:22:48 2020 +0000
Revision:
72:67c5bce77999
Parent:
71:ca2425c0a864
Child:
73:974c1df98553
3 modi zum aussuchen

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 70:65b2f1cc2859 26 GPS::GPS(PinName tx, PinName rx, int Baud,DigitalOut *gps_off) : _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 70:65b2f1cc2859 31 this->gps_off = gps_off;
jacktractive 66:a11c79073f1f 32 //_gps.printf("$$PMTK161,0*28\r\n"); //sleep
jacktractive 70:65b2f1cc2859 33 _gps.printf("$$PMTK161,1*28\r\n"); //wake up
jacktractive 61:2b30d8e75fe7 34 }
jacktractive 61:2b30d8e75fe7 35
jacktractive 70:65b2f1cc2859 36 void GPS::idle(bool idle)
jacktractive 69:316fee01f5d9 37 {
jacktractive 72:67c5bce77999 38 this->is_idle = idle;
jacktractive 72:67c5bce77999 39 gps_off->write(!idle);
jacktractive 70:65b2f1cc2859 40 }
jacktractive 70:65b2f1cc2859 41
jacktractive 70:65b2f1cc2859 42
jacktractive 70:65b2f1cc2859 43 void GPS::set_manual_tracking(bool mt) {
jacktractive 70:65b2f1cc2859 44 this->manual_tracking = mt;
jacktractive 70:65b2f1cc2859 45 printf("\n[GPS] Manual Tracking %x",mt);
jacktractive 71:ca2425c0a864 46 gps_off->write(!mt);
jacktractive 66:a11c79073f1f 47 }
jacktractive 64:85fa08519e1e 48
jacktractive 61:2b30d8e75fe7 49 int GPS::sample()
jacktractive 70:65b2f1cc2859 50 {
jacktractive 61:2b30d8e75fe7 51 int lock;
jacktractive 70:65b2f1cc2859 52 int h;
jacktractive 70:65b2f1cc2859 53
jacktractive 70:65b2f1cc2859 54 lock = 0;
jacktractive 71:ca2425c0a864 55 for (h = 0; h < 3; h++) {
jacktractive 70:65b2f1cc2859 56 printf("\n[GPS] Line %i:",h);
jacktractive 66:a11c79073f1f 57 getline();
jacktractive 63:2bfceda4c30c 58
jacktractive 70:65b2f1cc2859 59 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 71:ca2425c0a864 60 printf(msg);
jacktractive 66:a11c79073f1f 61 if(!lock) {
jacktractive 70:65b2f1cc2859 62 printf("\n[GPS] Kein Lock: %f %ih %im %is\n",time,hour,minute,seconed);
jacktractive 70:65b2f1cc2859 63 //time = 0.0;
jacktractive 70:65b2f1cc2859 64 // longitude = 0.0;
jacktractive 70:65b2f1cc2859 65 // latitude = 0.0;
jacktractive 70:65b2f1cc2859 66 // sats = 0;
jacktractive 70:65b2f1cc2859 67 // //hdop = 0.0;
jacktractive 70:65b2f1cc2859 68 // alt = 0.0;
jacktractive 70:65b2f1cc2859 69 // geoid = 0.0;
jacktractive 71:ca2425c0a864 70 GPS_signal_okay=0;
jacktractive 61:2b30d8e75fe7 71 } else {
jacktractive 61:2b30d8e75fe7 72 //GPGGA format according http://aprs.gids.nl/nmea/#gga
jacktractive 61:2b30d8e75fe7 73 // time (float), lat (f), (N/S) (c), long (f), (E/W) (c), fix (d), sats (d),
jacktractive 61:2b30d8e75fe7 74 // hdop (float), altitude (float), M, geoid (float), M, , ,
jacktractive 61:2b30d8e75fe7 75 //GPGGA,092010.000,5210.9546,N,00008.8913,E,1,07,1.3,9.7,M,47.0,M,,0000*5D
jacktractive 61:2b30d8e75fe7 76
jacktractive 61:2b30d8e75fe7 77 //format utc time to beijing time,add 8 time zone
jacktractive 67:7bb75ed97500 78
jacktractive 61:2b30d8e75fe7 79 hour = int(time) / 10000;
jacktractive 61:2b30d8e75fe7 80 minute = (int(time) % 10000) / 100;
jacktractive 61:2b30d8e75fe7 81 seconed = int(time) % 100;
jacktractive 63:2bfceda4c30c 82
jacktractive 70:65b2f1cc2859 83 printf("\n[GPS] Lock: %ih %im %is lat:%, lon:%\n",hour,minute,seconed,latitude, longitude);
jacktractive 71:ca2425c0a864 84 GPS_signal_okay=1;
jacktractive 70:65b2f1cc2859 85 return lock ;
jacktractive 66:a11c79073f1f 86 }//endiflock
jacktractive 70:65b2f1cc2859 87 } //endifscan
jacktractive 70:65b2f1cc2859 88 } //endfor
jacktractive 70:65b2f1cc2859 89 return lock ;
jacktractive 61:2b30d8e75fe7 90 }
jacktractive 61:2b30d8e75fe7 91
jacktractive 66:a11c79073f1f 92
jacktractive 61:2b30d8e75fe7 93 float GPS::trunc(float v)
jacktractive 61:2b30d8e75fe7 94 {
jacktractive 61:2b30d8e75fe7 95 if(v < 0.0) {
jacktractive 61:2b30d8e75fe7 96 v*= -1.0;
jacktractive 61:2b30d8e75fe7 97 v = floor(v);
jacktractive 61:2b30d8e75fe7 98 v*=-1.0;
jacktractive 61:2b30d8e75fe7 99 } else {
jacktractive 61:2b30d8e75fe7 100 v = floor(v);
jacktractive 61:2b30d8e75fe7 101 }
jacktractive 61:2b30d8e75fe7 102 return v;
jacktractive 61:2b30d8e75fe7 103 }
jacktractive 61:2b30d8e75fe7 104
jacktractive 61:2b30d8e75fe7 105 void GPS::getline()
jacktractive 70:65b2f1cc2859 106 {
jacktractive 61:2b30d8e75fe7 107 while(_gps.getc() != '$'); // wait for the start of a line
jacktractive 61:2b30d8e75fe7 108 for(int i=0; i<256; i++) {
jacktractive 61:2b30d8e75fe7 109 msg[i] = _gps.getc();
jacktractive 71:ca2425c0a864 110 //printf("%c",msg[i]);
jacktractive 61:2b30d8e75fe7 111 if(msg[i] == '\r') {
jacktractive 66:a11c79073f1f 112 msg[i] = 0;
jacktractive 61:2b30d8e75fe7 113 return;
jacktractive 61:2b30d8e75fe7 114 }
jacktractive 61:2b30d8e75fe7 115 }
jacktractive 64:85fa08519e1e 116 error("GPS::getline Overflowed message limit");
jacktractive 69:316fee01f5d9 117 }
jacktractive 69:316fee01f5d9 118
jacktractive 69:316fee01f5d9 119
jacktractive 72:67c5bce77999 120 void GPS::get_Position()
jacktractive 70:65b2f1cc2859 121 {
jacktractive 72:67c5bce77999 122
jacktractive 72:67c5bce77999 123
jacktractive 70:65b2f1cc2859 124 if (manual_tracking or !is_idle){
jacktractive 72:67c5bce77999 125 gps_off->write(0);
jacktractive 70:65b2f1cc2859 126 printf("\n[GPS] active");
jacktractive 70:65b2f1cc2859 127 if (this->sample()) {
jacktractive 72:67c5bce77999 128 printf("\n[GPS] Position: %f , %f\n", longitude,latitude);
jacktractive 70:65b2f1cc2859 129 }
jacktractive 70:65b2f1cc2859 130 }
jacktractive 70:65b2f1cc2859 131 else {
jacktractive 72:67c5bce77999 132 gps_off->write(1);
jacktractive 72:67c5bce77999 133 printf("\n[GPS] idle");
jacktractive 70:65b2f1cc2859 134 }
jacktractive 70:65b2f1cc2859 135 }
jacktractive 70:65b2f1cc2859 136
jacktractive 70:65b2f1cc2859 137