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