tito tito
/
GPS
programme GPS pour ERS4
Fork of GPS_IUT_Nice by
main.cpp@1:f24af888e699, 2016-03-11 (annotated)
- Committer:
- pierrick
- Date:
- Fri Mar 11 10:18:09 2016 +0000
- Revision:
- 1:f24af888e699
- Parent:
- 0:2c0686a07ab8
- Child:
- 2:addb687a4e73
code simple gps ers4 iut nice
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreday20 | 0:2c0686a07ab8 | 1 | #include "mbed.h" |
pierrick | 1:f24af888e699 | 2 | //#include "GPS.h" |
pierrick | 1:f24af888e699 | 3 | #include <Serial.h> |
pierrick | 1:f24af888e699 | 4 | #include "getline.h" |
pierrick | 1:f24af888e699 | 5 | #include <math.h> |
pierrick | 1:f24af888e699 | 6 | //#include "stream.h" |
dreday20 | 0:2c0686a07ab8 | 7 | |
dreday20 | 0:2c0686a07ab8 | 8 | Serial pc(USBTX, USBRX); |
pierrick | 1:f24af888e699 | 9 | //GPS gps(p13, p14); |
dreday20 | 0:2c0686a07ab8 | 10 | |
pierrick | 1:f24af888e699 | 11 | Serial uart1(p13, p14); |
pierrick | 1:f24af888e699 | 12 | char c; |
pierrick | 1:f24af888e699 | 13 | int event_callback_t ; |
pierrick | 1:f24af888e699 | 14 | int event; |
pierrick | 1:f24af888e699 | 15 | unsigned char char_match ; |
pierrick | 1:f24af888e699 | 16 | char msg[1000]; |
pierrick | 1:f24af888e699 | 17 | /** The longitude (call sample() to set) */ |
pierrick | 1:f24af888e699 | 18 | float longitude; |
pierrick | 1:f24af888e699 | 19 | |
pierrick | 1:f24af888e699 | 20 | /** The latitude (call sample() to set) */ |
pierrick | 1:f24af888e699 | 21 | float latitude,time2; |
pierrick | 1:f24af888e699 | 22 | |
pierrick | 1:f24af888e699 | 23 | char ns, ew; |
pierrick | 1:f24af888e699 | 24 | int lock; |
dreday20 | 0:2c0686a07ab8 | 25 | int main() { |
pierrick | 1:f24af888e699 | 26 | uart1.baud(9600); |
pierrick | 1:f24af888e699 | 27 | printf("hello\n"); |
pierrick | 1:f24af888e699 | 28 | while (1){ |
pierrick | 1:f24af888e699 | 29 | if (uart1.readable()) |
pierrick | 1:f24af888e699 | 30 | { |
pierrick | 1:f24af888e699 | 31 | |
pierrick | 1:f24af888e699 | 32 | getline(uart1,msg,999); |
pierrick | 1:f24af888e699 | 33 | // pc.printf("\n %s",msg); |
pierrick | 1:f24af888e699 | 34 | //pc.printf("long= %f %c latitude= %f %c\n",&longitude, &ew, &latitude, &ns); |
pierrick | 1:f24af888e699 | 35 | // Check if it is a GPGGA msg (matches both locked and non-locked msg) |
pierrick | 1:f24af888e699 | 36 | if ( sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d", &time2, &latitude, &ns, &longitude, &ew, &lock )>=1) |
pierrick | 1:f24af888e699 | 37 | { |
pierrick | 1:f24af888e699 | 38 | if(!lock) { |
pierrick | 1:f24af888e699 | 39 | longitude = 0.0; |
pierrick | 1:f24af888e699 | 40 | latitude = 0.0; |
pierrick | 1:f24af888e699 | 41 | pc.printf("long= %f %c latitude= %f %c\n",&longitude, &ew, &latitude, &ns); |
pierrick | 1:f24af888e699 | 42 | //return 0; |
pierrick | 1:f24af888e699 | 43 | } else { |
pierrick | 1:f24af888e699 | 44 | if(ns == 'S') { latitude *= -1.0; } |
pierrick | 1:f24af888e699 | 45 | if(ew == 'W') { longitude *= -1.0; } |
pierrick | 1:f24af888e699 | 46 | float degrees =(latitude / 100.0f); |
pierrick | 1:f24af888e699 | 47 | float minutes = latitude - (degrees * 100.0f); |
pierrick | 1:f24af888e699 | 48 | latitude = degrees + minutes / 60.0f; |
pierrick | 1:f24af888e699 | 49 | degrees = (longitude / 100.0f * 0.01f); |
pierrick | 1:f24af888e699 | 50 | minutes = longitude - (degrees * 100.0f); |
pierrick | 1:f24af888e699 | 51 | longitude = degrees + minutes / 60.0f; |
pierrick | 1:f24af888e699 | 52 | printf("time = %f \n", time2); |
pierrick | 1:f24af888e699 | 53 | pc.printf("long= %f %c latitude= %f %c\n",longitude, ew, latitude, ns); |
pierrick | 1:f24af888e699 | 54 | //return 1; |
pierrick | 1:f24af888e699 | 55 | }//end else |
pierrick | 1:f24af888e699 | 56 | }//end if |
pierrick | 1:f24af888e699 | 57 | }//end if |
pierrick | 1:f24af888e699 | 58 | } //end while |
pierrick | 1:f24af888e699 | 59 | } //end main |
pierrick | 1:f24af888e699 | 60 | |
pierrick | 1:f24af888e699 | 61 | /* |
pierrick | 1:f24af888e699 | 62 | c=uart1.getc(); |
pierrick | 1:f24af888e699 | 63 | pc.printf("%c",c); |
pierrick | 1:f24af888e699 | 64 | */ |
pierrick | 1:f24af888e699 | 65 | /* } |
pierrick | 1:f24af888e699 | 66 | |
pierrick | 1:f24af888e699 | 67 | |
pierrick | 1:f24af888e699 | 68 | */ |
pierrick | 1:f24af888e699 | 69 | /* |
dreday20 | 0:2c0686a07ab8 | 70 | while(1) { |
pierrick | 1:f24af888e699 | 71 | //wait(1.0); |
pierrick | 1:f24af888e699 | 72 | //printf("hello bis\n"); |
pierrick | 1:f24af888e699 | 73 | |
dreday20 | 0:2c0686a07ab8 | 74 | if(gps.sample()) { |
pierrick | 1:f24af888e699 | 75 | printf("I'm at %f, %f\n", gps.longitude, gps.latitude); |
dreday20 | 0:2c0686a07ab8 | 76 | } else { |
pierrick | 1:f24af888e699 | 77 | printf("Oh Dear! No lock :(\n"); |
dreday20 | 0:2c0686a07ab8 | 78 | } |
dreday20 | 0:2c0686a07ab8 | 79 | } |
pierrick | 1:f24af888e699 | 80 | } |
pierrick | 1:f24af888e699 | 81 | |
pierrick | 1:f24af888e699 | 82 | |
pierrick | 1:f24af888e699 | 83 | // Print "Hello World" to the PC |
pierrick | 1:f24af888e699 | 84 | |
pierrick | 1:f24af888e699 | 85 | #include "mbed.h" |
pierrick | 1:f24af888e699 | 86 | */ |
pierrick | 1:f24af888e699 | 87 |