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:
Sun Jan 19 15:53:57 2020 +0000
Revision:
69:316fee01f5d9
Parent:
68:41fff9c3fb4f
Child:
70:65b2f1cc2859
Objectorientiert

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 66:a11c79073f1f 31 //_gps.printf("$$PMTK161,0*28\r\n"); //sleep
jacktractive 64:85fa08519e1e 32 //_gps.printf("$$PMTK161,1*28\r\n"); //wake up
jacktractive 61:2b30d8e75fe7 33 }
jacktractive 61:2b30d8e75fe7 34
jacktractive 66:a11c79073f1f 35
jacktractive 69:316fee01f5d9 36 void GPS::idle(bool idle)
jacktractive 69:316fee01f5d9 37 {
jacktractive 69:316fee01f5d9 38 this->is_idle = idle;
jacktractive 69:316fee01f5d9 39 this->idle_time=0;
jacktractive 69:316fee01f5d9 40
jacktractive 69:316fee01f5d9 41 //
jacktractive 69:316fee01f5d9 42 // uint8_t GPSoff[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x08, 0x00, 0x16, 0x74};
jacktractive 69:316fee01f5d9 43 // uint8_t GPSon[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x09, 0x00, 0x17, 0x76};
jacktractive 69:316fee01f5d9 44 // uint8_t GPS_Powersafemode[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92};
jacktractive 69:316fee01f5d9 45 //
jacktractive 69:316fee01f5d9 46 // uint8_t GPS_MaxPerformance[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x00, 0x21, 0x91};
jacktractive 69:316fee01f5d9 47 //
jacktractive 69:316fee01f5d9 48 // uint8_t GPS_10s_Period[] ={0xB5, 0x62, 0x06, 0x3B, 0x2C, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x10, 0x27, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x4F, 0xC1, 0x03, 0x00, 0x87, 0x02, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x64, 0x40, 0x01, 0x00, 0xE4, 0x8B};
jacktractive 69:316fee01f5d9 49 // //_gps.printf((GPSoff, sizeof(GPSoff)/sizeof(uint8_t));
jacktractive 66:a11c79073f1f 50
jacktractive 69:316fee01f5d9 51 // _gps.printf("%c",GPSoff);
jacktractive 66:a11c79073f1f 52
jacktractive 66:a11c79073f1f 53 //
jacktractive 66:a11c79073f1f 54 // uint8_t GPSon[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x09, 0x00, 0x17, 0x76};
jacktractive 66:a11c79073f1f 55 // sendUBX(GPSon, sizeof(GPSon)/sizeof(uint8_t));
jacktractive 66:a11c79073f1f 56 }
jacktractive 64:85fa08519e1e 57
jacktractive 61:2b30d8e75fe7 58 int GPS::sample()
jacktractive 61:2b30d8e75fe7 59 {
jacktractive 61:2b30d8e75fe7 60
jacktractive 61:2b30d8e75fe7 61 int lock;
jacktractive 63:2bfceda4c30c 62 int h;
jacktractive 61:2b30d8e75fe7 63
jacktractive 66:a11c79073f1f 64
jacktractive 67:7bb75ed97500 65 for (h = 0; h < 10; h++)
jacktractive 66:a11c79073f1f 66 {
jacktractive 68:41fff9c3fb4f 67 //printf("\n[GPS] Line %i:",h);
jacktractive 66:a11c79073f1f 68 getline();
jacktractive 63:2bfceda4c30c 69
jacktractive 63:2bfceda4c30c 70 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 66:a11c79073f1f 71 if(!lock) {
jacktractive 66:a11c79073f1f 72 printf("[GPS] Kein Lock: %f %ih %im %is\n",time,hour,minute,seconed);
jacktractive 66:a11c79073f1f 73 time = 0.0;
jacktractive 66:a11c79073f1f 74 longitude = 0.0;
jacktractive 66:a11c79073f1f 75 latitude = 0.0;
jacktractive 66:a11c79073f1f 76 sats = 0;
jacktractive 66:a11c79073f1f 77 //hdop = 0.0;
jacktractive 66:a11c79073f1f 78 alt = 0.0;
jacktractive 66:a11c79073f1f 79 geoid = 0.0;
jacktractive 61:2b30d8e75fe7 80 } else {
jacktractive 61:2b30d8e75fe7 81 //GPGGA format according http://aprs.gids.nl/nmea/#gga
jacktractive 61:2b30d8e75fe7 82 // time (float), lat (f), (N/S) (c), long (f), (E/W) (c), fix (d), sats (d),
jacktractive 61:2b30d8e75fe7 83 // hdop (float), altitude (float), M, geoid (float), M, , ,
jacktractive 61:2b30d8e75fe7 84 //GPGGA,092010.000,5210.9546,N,00008.8913,E,1,07,1.3,9.7,M,47.0,M,,0000*5D
jacktractive 61:2b30d8e75fe7 85
jacktractive 61:2b30d8e75fe7 86 //format utc time to beijing time,add 8 time zone
jacktractive 67:7bb75ed97500 87
jacktractive 61:2b30d8e75fe7 88 hour = int(time) / 10000;
jacktractive 61:2b30d8e75fe7 89 minute = (int(time) % 10000) / 100;
jacktractive 61:2b30d8e75fe7 90 seconed = int(time) % 100;
jacktractive 63:2bfceda4c30c 91
jacktractive 67:7bb75ed97500 92 printf("\n[GPS] Lock: %ih %im %is\n",hour,minute,seconed);
jacktractive 63:2bfceda4c30c 93
jacktractive 66:a11c79073f1f 94 }//endiflock
jacktractive 66:a11c79073f1f 95 } //endifscan
jacktractive 63:2bfceda4c30c 96
jacktractive 66:a11c79073f1f 97 } //endfor
jacktractive 63:2bfceda4c30c 98
jacktractive 66:a11c79073f1f 99 return lock ;
jacktractive 63:2bfceda4c30c 100
jacktractive 63:2bfceda4c30c 101
jacktractive 61:2b30d8e75fe7 102 }
jacktractive 61:2b30d8e75fe7 103
jacktractive 66:a11c79073f1f 104
jacktractive 61:2b30d8e75fe7 105 float GPS::trunc(float v)
jacktractive 61:2b30d8e75fe7 106 {
jacktractive 61:2b30d8e75fe7 107 if(v < 0.0) {
jacktractive 61:2b30d8e75fe7 108 v*= -1.0;
jacktractive 61:2b30d8e75fe7 109 v = floor(v);
jacktractive 61:2b30d8e75fe7 110 v*=-1.0;
jacktractive 61:2b30d8e75fe7 111 } else {
jacktractive 61:2b30d8e75fe7 112 v = floor(v);
jacktractive 61:2b30d8e75fe7 113 }
jacktractive 61:2b30d8e75fe7 114 return v;
jacktractive 61:2b30d8e75fe7 115 }
jacktractive 61:2b30d8e75fe7 116
jacktractive 61:2b30d8e75fe7 117 void GPS::getline()
jacktractive 61:2b30d8e75fe7 118 {
jacktractive 63:2bfceda4c30c 119
jacktractive 61:2b30d8e75fe7 120 while(_gps.getc() != '$'); // wait for the start of a line
jacktractive 61:2b30d8e75fe7 121 for(int i=0; i<256; i++) {
jacktractive 61:2b30d8e75fe7 122 msg[i] = _gps.getc();
jacktractive 63:2bfceda4c30c 123 printf("%c",msg[i]);
jacktractive 61:2b30d8e75fe7 124 if(msg[i] == '\r') {
jacktractive 66:a11c79073f1f 125 msg[i] = 0;
jacktractive 61:2b30d8e75fe7 126 return;
jacktractive 61:2b30d8e75fe7 127 }
jacktractive 61:2b30d8e75fe7 128 }
jacktractive 64:85fa08519e1e 129 error("GPS::getline Overflowed message limit");
jacktractive 69:316fee01f5d9 130 }
jacktractive 69:316fee01f5d9 131
jacktractive 69:316fee01f5d9 132
jacktractive 69:316fee01f5d9 133 void GPS::GPS_aktiv()
jacktractive 69:316fee01f5d9 134 {
jacktractive 69:316fee01f5d9 135
jacktractive 69:316fee01f5d9 136
jacktractive 69:316fee01f5d9 137
jacktractive 69:316fee01f5d9 138 if (this->sample())
jacktractive 69:316fee01f5d9 139 {
jacktractive 69:316fee01f5d9 140
jacktractive 69:316fee01f5d9 141 // current_Position.Zeitstempel = gpsAda.time;
jacktractive 69:316fee01f5d9 142 // current_Position.Longitude = gpsAda.longitude /100;
jacktractive 69:316fee01f5d9 143 // current_Position.Latitude = gpsAda.latitude /100;
jacktractive 69:316fee01f5d9 144
jacktractive 69:316fee01f5d9 145 float Homelat = 52.143734;
jacktractive 69:316fee01f5d9 146 float Homelon = 7.323368;
jacktractive 69:316fee01f5d9 147 float dx,dy,distance;
jacktractive 69:316fee01f5d9 148 dx = 71.5 * abs(longitude /100 - Homelon);
jacktractive 69:316fee01f5d9 149 dy = 111.3 * abs(latitude /100 - Homelat);
jacktractive 69:316fee01f5d9 150
jacktractive 69:316fee01f5d9 151 distance = sqrt(dx * dx + dy * dy) ;
jacktractive 69:316fee01f5d9 152 printf("[GPS] HomeEntfernung: %f\n", distance);
jacktractive 69:316fee01f5d9 153
jacktractive 69:316fee01f5d9 154
jacktractive 69:316fee01f5d9 155
jacktractive 69:316fee01f5d9 156 // printf("%f\t%c\t%f\t%c\t%f\t%f\t%f\n\r", gpsAda.longitude, gpsAda.ns, gpsAda.latitude, gpsAda.ew, gpsAda.alt, gpsAda.geoid, gpsAda.time);
jacktractive 69:316fee01f5d9 157 // printf("%d:%d:%d\n", gpsAda.hour, gpsAda.minute, gpsAda.seconed);
jacktractive 69:316fee01f5d9 158
jacktractive 69:316fee01f5d9 159 //packet_len = sprintf((char *) tx_buffer, "%i %f, %i %f\n", Breitengrad, Breitenminuten, Laengengrad, Laengenminuten);
jacktractive 69:316fee01f5d9 160
jacktractive 69:316fee01f5d9 161 //retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len,
jacktractive 69:316fee01f5d9 162 // MSG_UNCONFIRMED_FLAG);
jacktractive 69:316fee01f5d9 163
jacktractive 69:316fee01f5d9 164
jacktractive 69:316fee01f5d9 165 }
jacktractive 69:316fee01f5d9 166 else
jacktractive 69:316fee01f5d9 167 {
jacktractive 69:316fee01f5d9 168 //gpsAda.printf("$$PMTK161,0*28\r\n"); //go to sleep
jacktractive 69:316fee01f5d9 169 //gpsAda.printf("$$PMTK161,1*28\r\n"); //wake up
jacktractive 69:316fee01f5d9 170
jacktractive 69:316fee01f5d9 171 // current_Position.Zeitstempel = gpsAda.time;
jacktractive 69:316fee01f5d9 172 // current_Position.Longitude = 50.123;
jacktractive 69:316fee01f5d9 173 // current_Position.Latitude = 7.456;
jacktractive 69:316fee01f5d9 174 //
jacktractive 69:316fee01f5d9 175
jacktractive 69:316fee01f5d9 176 }
jacktractive 61:2b30d8e75fe7 177 }