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@68:41fff9c3fb4f, 2020-01-17 (annotated)
- Committer:
- jacktractive
- Date:
- Fri Jan 17 13:46:31 2020 +0000
- Revision:
- 68:41fff9c3fb4f
- Parent:
- 67:7bb75ed97500
- Child:
- 69:316fee01f5d9
Events an funktionen uebergeben
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 | 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 | 66:a11c79073f1f | 36 | void GPS::GPS_OFF() |
jacktractive | 66:a11c79073f1f | 37 | { |
jacktractive | 66:a11c79073f1f | 38 | |
jacktractive | 66:a11c79073f1f | 39 | |
jacktractive | 66:a11c79073f1f | 40 | |
jacktractive | 66:a11c79073f1f | 41 | uint8_t GPSoff[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x08, 0x00, 0x16, 0x74}; |
jacktractive | 66:a11c79073f1f | 42 | uint8_t GPSon[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x09, 0x00, 0x17, 0x76}; |
jacktractive | 66:a11c79073f1f | 43 | uint8_t GPS_Powersafemode[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92}; |
jacktractive | 66:a11c79073f1f | 44 | |
jacktractive | 66:a11c79073f1f | 45 | uint8_t GPS_MaxPerformance[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x00, 0x21, 0x91}; |
jacktractive | 66:a11c79073f1f | 46 | |
jacktractive | 66:a11c79073f1f | 47 | 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 | 66:a11c79073f1f | 48 | //_gps.printf((GPSoff, sizeof(GPSoff)/sizeof(uint8_t)); |
jacktractive | 66:a11c79073f1f | 49 | |
jacktractive | 66:a11c79073f1f | 50 | _gps.printf("%c",GPSoff); |
jacktractive | 66:a11c79073f1f | 51 | |
jacktractive | 66:a11c79073f1f | 52 | // |
jacktractive | 66:a11c79073f1f | 53 | // uint8_t GPSon[] = {0xB5, 0x62, 0x06, 0x04, 0x04, 0x00, 0x00, 0x00,0x09, 0x00, 0x17, 0x76}; |
jacktractive | 66:a11c79073f1f | 54 | // sendUBX(GPSon, sizeof(GPSon)/sizeof(uint8_t)); |
jacktractive | 66:a11c79073f1f | 55 | } |
jacktractive | 64:85fa08519e1e | 56 | |
jacktractive | 61:2b30d8e75fe7 | 57 | int GPS::sample() |
jacktractive | 61:2b30d8e75fe7 | 58 | { |
jacktractive | 61:2b30d8e75fe7 | 59 | |
jacktractive | 61:2b30d8e75fe7 | 60 | int lock; |
jacktractive | 63:2bfceda4c30c | 61 | int h; |
jacktractive | 61:2b30d8e75fe7 | 62 | |
jacktractive | 66:a11c79073f1f | 63 | |
jacktractive | 67:7bb75ed97500 | 64 | for (h = 0; h < 10; h++) |
jacktractive | 66:a11c79073f1f | 65 | { |
jacktractive | 68:41fff9c3fb4f | 66 | //printf("\n[GPS] Line %i:",h); |
jacktractive | 66:a11c79073f1f | 67 | getline(); |
jacktractive | 63:2bfceda4c30c | 68 | |
jacktractive | 63:2bfceda4c30c | 69 | 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 | 70 | if(!lock) { |
jacktractive | 66:a11c79073f1f | 71 | printf("[GPS] Kein Lock: %f %ih %im %is\n",time,hour,minute,seconed); |
jacktractive | 66:a11c79073f1f | 72 | time = 0.0; |
jacktractive | 66:a11c79073f1f | 73 | longitude = 0.0; |
jacktractive | 66:a11c79073f1f | 74 | latitude = 0.0; |
jacktractive | 66:a11c79073f1f | 75 | sats = 0; |
jacktractive | 66:a11c79073f1f | 76 | //hdop = 0.0; |
jacktractive | 66:a11c79073f1f | 77 | alt = 0.0; |
jacktractive | 66:a11c79073f1f | 78 | geoid = 0.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 | 67:7bb75ed97500 | 86 | |
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 | 67:7bb75ed97500 | 91 | printf("\n[GPS] Lock: %ih %im %is\n",hour,minute,seconed); |
jacktractive | 63:2bfceda4c30c | 92 | |
jacktractive | 66:a11c79073f1f | 93 | }//endiflock |
jacktractive | 66:a11c79073f1f | 94 | } //endifscan |
jacktractive | 63:2bfceda4c30c | 95 | |
jacktractive | 66:a11c79073f1f | 96 | } //endfor |
jacktractive | 63:2bfceda4c30c | 97 | |
jacktractive | 66:a11c79073f1f | 98 | return lock ; |
jacktractive | 63:2bfceda4c30c | 99 | |
jacktractive | 63:2bfceda4c30c | 100 | |
jacktractive | 61:2b30d8e75fe7 | 101 | } |
jacktractive | 61:2b30d8e75fe7 | 102 | |
jacktractive | 66:a11c79073f1f | 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 | 66:a11c79073f1f | 124 | msg[i] = 0; |
jacktractive | 61:2b30d8e75fe7 | 125 | return; |
jacktractive | 61:2b30d8e75fe7 | 126 | } |
jacktractive | 61:2b30d8e75fe7 | 127 | } |
jacktractive | 64:85fa08519e1e | 128 | error("GPS::getline Overflowed message limit"); |
jacktractive | 61:2b30d8e75fe7 | 129 | } |