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
GPS/GPS.cpp@70:65b2f1cc2859, 2020-01-21 (annotated)
- Committer:
- jacktractive
- Date:
- Tue Jan 21 13:20:59 2020 +0000
- Revision:
- 70:65b2f1cc2859
- Parent:
- 69:316fee01f5d9
- Child:
- 71:ca2425c0a864
Lora und GPS test mit Testdaten
Who changed what in which revision?
User | Revision | Line number | New 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 | 70:65b2f1cc2859 | 38 | this->is_idle = idle; |
jacktractive | 70:65b2f1cc2859 | 39 | } |
jacktractive | 70:65b2f1cc2859 | 40 | |
jacktractive | 70:65b2f1cc2859 | 41 | |
jacktractive | 70:65b2f1cc2859 | 42 | void GPS::set_manual_tracking(bool mt) { |
jacktractive | 70:65b2f1cc2859 | 43 | this->manual_tracking = mt; |
jacktractive | 70:65b2f1cc2859 | 44 | printf("\n[GPS] Manual Tracking %x",mt); |
jacktractive | 66:a11c79073f1f | 45 | } |
jacktractive | 64:85fa08519e1e | 46 | |
jacktractive | 61:2b30d8e75fe7 | 47 | int GPS::sample() |
jacktractive | 70:65b2f1cc2859 | 48 | { |
jacktractive | 61:2b30d8e75fe7 | 49 | int lock; |
jacktractive | 70:65b2f1cc2859 | 50 | int h; |
jacktractive | 70:65b2f1cc2859 | 51 | |
jacktractive | 70:65b2f1cc2859 | 52 | lock = 0; |
jacktractive | 70:65b2f1cc2859 | 53 | for (h = 0; h < 10; h++) { |
jacktractive | 70:65b2f1cc2859 | 54 | printf("\n[GPS] Line %i:",h); |
jacktractive | 66:a11c79073f1f | 55 | getline(); |
jacktractive | 63:2bfceda4c30c | 56 | |
jacktractive | 70:65b2f1cc2859 | 57 | 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 | 66:a11c79073f1f | 58 | if(!lock) { |
jacktractive | 70:65b2f1cc2859 | 59 | printf("\n[GPS] Kein Lock: %f %ih %im %is\n",time,hour,minute,seconed); |
jacktractive | 70:65b2f1cc2859 | 60 | //time = 0.0; |
jacktractive | 70:65b2f1cc2859 | 61 | // longitude = 0.0; |
jacktractive | 70:65b2f1cc2859 | 62 | // latitude = 0.0; |
jacktractive | 70:65b2f1cc2859 | 63 | // sats = 0; |
jacktractive | 70:65b2f1cc2859 | 64 | // //hdop = 0.0; |
jacktractive | 70:65b2f1cc2859 | 65 | // alt = 0.0; |
jacktractive | 70:65b2f1cc2859 | 66 | // geoid = 0.0; |
jacktractive | 61:2b30d8e75fe7 | 67 | } else { |
jacktractive | 61:2b30d8e75fe7 | 68 | //GPGGA format according http://aprs.gids.nl/nmea/#gga |
jacktractive | 61:2b30d8e75fe7 | 69 | // time (float), lat (f), (N/S) (c), long (f), (E/W) (c), fix (d), sats (d), |
jacktractive | 61:2b30d8e75fe7 | 70 | // hdop (float), altitude (float), M, geoid (float), M, , , |
jacktractive | 61:2b30d8e75fe7 | 71 | //GPGGA,092010.000,5210.9546,N,00008.8913,E,1,07,1.3,9.7,M,47.0,M,,0000*5D |
jacktractive | 61:2b30d8e75fe7 | 72 | |
jacktractive | 61:2b30d8e75fe7 | 73 | //format utc time to beijing time,add 8 time zone |
jacktractive | 67:7bb75ed97500 | 74 | |
jacktractive | 61:2b30d8e75fe7 | 75 | hour = int(time) / 10000; |
jacktractive | 61:2b30d8e75fe7 | 76 | minute = (int(time) % 10000) / 100; |
jacktractive | 61:2b30d8e75fe7 | 77 | seconed = int(time) % 100; |
jacktractive | 63:2bfceda4c30c | 78 | |
jacktractive | 70:65b2f1cc2859 | 79 | printf("\n[GPS] Lock: %ih %im %is lat:%, lon:%\n",hour,minute,seconed,latitude, longitude); |
jacktractive | 63:2bfceda4c30c | 80 | |
jacktractive | 70:65b2f1cc2859 | 81 | return lock ; |
jacktractive | 66:a11c79073f1f | 82 | }//endiflock |
jacktractive | 70:65b2f1cc2859 | 83 | } //endifscan |
jacktractive | 70:65b2f1cc2859 | 84 | } //endfor |
jacktractive | 70:65b2f1cc2859 | 85 | return lock ; |
jacktractive | 61:2b30d8e75fe7 | 86 | } |
jacktractive | 61:2b30d8e75fe7 | 87 | |
jacktractive | 66:a11c79073f1f | 88 | |
jacktractive | 61:2b30d8e75fe7 | 89 | float GPS::trunc(float v) |
jacktractive | 61:2b30d8e75fe7 | 90 | { |
jacktractive | 61:2b30d8e75fe7 | 91 | if(v < 0.0) { |
jacktractive | 61:2b30d8e75fe7 | 92 | v*= -1.0; |
jacktractive | 61:2b30d8e75fe7 | 93 | v = floor(v); |
jacktractive | 61:2b30d8e75fe7 | 94 | v*=-1.0; |
jacktractive | 61:2b30d8e75fe7 | 95 | } else { |
jacktractive | 61:2b30d8e75fe7 | 96 | v = floor(v); |
jacktractive | 61:2b30d8e75fe7 | 97 | } |
jacktractive | 61:2b30d8e75fe7 | 98 | return v; |
jacktractive | 61:2b30d8e75fe7 | 99 | } |
jacktractive | 61:2b30d8e75fe7 | 100 | |
jacktractive | 61:2b30d8e75fe7 | 101 | void GPS::getline() |
jacktractive | 70:65b2f1cc2859 | 102 | { |
jacktractive | 61:2b30d8e75fe7 | 103 | while(_gps.getc() != '$'); // wait for the start of a line |
jacktractive | 61:2b30d8e75fe7 | 104 | for(int i=0; i<256; i++) { |
jacktractive | 61:2b30d8e75fe7 | 105 | msg[i] = _gps.getc(); |
jacktractive | 63:2bfceda4c30c | 106 | printf("%c",msg[i]); |
jacktractive | 61:2b30d8e75fe7 | 107 | if(msg[i] == '\r') { |
jacktractive | 66:a11c79073f1f | 108 | msg[i] = 0; |
jacktractive | 61:2b30d8e75fe7 | 109 | return; |
jacktractive | 61:2b30d8e75fe7 | 110 | } |
jacktractive | 61:2b30d8e75fe7 | 111 | } |
jacktractive | 64:85fa08519e1e | 112 | error("GPS::getline Overflowed message limit"); |
jacktractive | 69:316fee01f5d9 | 113 | } |
jacktractive | 69:316fee01f5d9 | 114 | |
jacktractive | 69:316fee01f5d9 | 115 | |
jacktractive | 69:316fee01f5d9 | 116 | void GPS::GPS_aktiv() |
jacktractive | 70:65b2f1cc2859 | 117 | { |
jacktractive | 70:65b2f1cc2859 | 118 | if (manual_tracking or !is_idle){ |
jacktractive | 70:65b2f1cc2859 | 119 | printf("\n[GPS] active"); |
jacktractive | 70:65b2f1cc2859 | 120 | gps_off->write(0); |
jacktractive | 70:65b2f1cc2859 | 121 | // uint8_t GPS_MaxPerformance[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x00, 0x21, 0x91}; |
jacktractive | 70:65b2f1cc2859 | 122 | // _gps.printf("%c",GPS_MaxPerformance); |
jacktractive | 70:65b2f1cc2859 | 123 | if (this->sample()) { |
jacktractive | 70:65b2f1cc2859 | 124 | float Homelat = 52.143734; |
jacktractive | 70:65b2f1cc2859 | 125 | float Homelon = 7.323368; |
jacktractive | 70:65b2f1cc2859 | 126 | float dx,dy,distance; |
jacktractive | 70:65b2f1cc2859 | 127 | dx = 71.5 * abs(longitude /100 - Homelon); |
jacktractive | 70:65b2f1cc2859 | 128 | dy = 111.3 * abs(latitude /100 - Homelat); |
jacktractive | 70:65b2f1cc2859 | 129 | |
jacktractive | 70:65b2f1cc2859 | 130 | distance = sqrt(dx * dx + dy * dy) ; |
jacktractive | 70:65b2f1cc2859 | 131 | printf("[GPS] Position: %f , %f\n", longitude,latitude); |
jacktractive | 70:65b2f1cc2859 | 132 | printf("[GPS] HomeEntfernung: %f\n", distance); |
jacktractive | 70:65b2f1cc2859 | 133 | } |
jacktractive | 70:65b2f1cc2859 | 134 | } |
jacktractive | 70:65b2f1cc2859 | 135 | else { |
jacktractive | 70:65b2f1cc2859 | 136 | printf("[GPS] idle"); |
jacktractive | 70:65b2f1cc2859 | 137 | gps_off->write(1); |
jacktractive | 70:65b2f1cc2859 | 138 | } |
jacktractive | 70:65b2f1cc2859 | 139 | } |
jacktractive | 70:65b2f1cc2859 | 140 | |
jacktractive | 70:65b2f1cc2859 | 141 | |
jacktractive | 70:65b2f1cc2859 | 142 | |
jacktractive | 70:65b2f1cc2859 | 143 | // uint8_t GPSoff[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x08, 0x00, 0x16, 0x74}; |
jacktractive | 70:65b2f1cc2859 | 144 | // uint8_t GPSon[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x09, 0x00, 0x17, 0x76}; |
jacktractive | 70:65b2f1cc2859 | 145 | // uint8_t GPS_Powersafemode[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92}; |
jacktractive | 70:65b2f1cc2859 | 146 | // |
jacktractive | 70:65b2f1cc2859 | 147 | // uint8_t GPS_MaxPerformance[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x00, 0x21, 0x91}; |
jacktractive | 70:65b2f1cc2859 | 148 | // |
jacktractive | 70:65b2f1cc2859 | 149 | // 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 | 70:65b2f1cc2859 | 150 | // //_gps.printf((GPSoff, sizeof(GPSoff)/sizeof(uint8_t)); |
jacktractive | 69:316fee01f5d9 | 151 | |
jacktractive | 70:65b2f1cc2859 | 152 | // _gps.printf("%c",GPSoff); |
jacktractive | 69:316fee01f5d9 | 153 | |
jacktractive | 70:65b2f1cc2859 | 154 | // |
jacktractive | 70:65b2f1cc2859 | 155 | // uint8_t GPSon[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x09, 0x00, 0x17, 0x76}; |
jacktractive | 70:65b2f1cc2859 | 156 | // sendUBX(GPSon, sizeof(GPSon)/sizeof(uint8_t)); |