johann vallar
/
GPS
affichage d m s
Fork of GPS by
main.cpp@2:addb687a4e73, 2016-03-11 (annotated)
- Committer:
- pierrick
- Date:
- Fri Mar 11 10:25:05 2016 +0000
- Revision:
- 2:addb687a4e73
- Parent:
- 1:f24af888e699
- Child:
- 3:8234e0d5854e
GPS for IUT
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 <Serial.h> |
pierrick | 1:f24af888e699 | 3 | #include "getline.h" |
pierrick | 2:addb687a4e73 | 4 | |
dreday20 | 0:2c0686a07ab8 | 5 | Serial pc(USBTX, USBRX); |
pierrick | 1:f24af888e699 | 6 | //GPS gps(p13, p14); |
dreday20 | 0:2c0686a07ab8 | 7 | |
pierrick | 2:addb687a4e73 | 8 | Serial uart1(p13, p14); //pin RX et TX du GPS |
pierrick | 1:f24af888e699 | 9 | char c; |
pierrick | 1:f24af888e699 | 10 | int event_callback_t ; |
pierrick | 1:f24af888e699 | 11 | int event; |
pierrick | 1:f24af888e699 | 12 | unsigned char char_match ; |
pierrick | 1:f24af888e699 | 13 | char msg[1000]; |
pierrick | 1:f24af888e699 | 14 | /** The longitude (call sample() to set) */ |
pierrick | 1:f24af888e699 | 15 | float longitude; |
pierrick | 1:f24af888e699 | 16 | |
pierrick | 1:f24af888e699 | 17 | /** The latitude (call sample() to set) */ |
pierrick | 1:f24af888e699 | 18 | float latitude,time2; |
pierrick | 1:f24af888e699 | 19 | |
pierrick | 1:f24af888e699 | 20 | char ns, ew; |
pierrick | 1:f24af888e699 | 21 | int lock; |
dreday20 | 0:2c0686a07ab8 | 22 | int main() { |
pierrick | 2:addb687a4e73 | 23 | uart1.baud(9600); //vitesse de transmission de informations |
pierrick | 2:addb687a4e73 | 24 | printf("hello\n"); //test |
pierrick | 1:f24af888e699 | 25 | while (1){ |
pierrick | 1:f24af888e699 | 26 | if (uart1.readable()) |
pierrick | 1:f24af888e699 | 27 | { |
pierrick | 1:f24af888e699 | 28 | |
pierrick | 1:f24af888e699 | 29 | getline(uart1,msg,999); |
pierrick | 1:f24af888e699 | 30 | if ( sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d", &time2, &latitude, &ns, &longitude, &ew, &lock )>=1) |
pierrick | 1:f24af888e699 | 31 | { |
pierrick | 1:f24af888e699 | 32 | if(!lock) { |
pierrick | 2:addb687a4e73 | 33 | longitude = 0.0; |
pierrick | 2:addb687a4e73 | 34 | latitude = 0.0; |
pierrick | 2:addb687a4e73 | 35 | pc.printf("long= %f %c latitude= %f %c\n",&longitude, &ew, &latitude, &ns); |
pierrick | 1:f24af888e699 | 36 | } else { |
pierrick | 2:addb687a4e73 | 37 | if(ns == 'S') { latitude *= -1.0; } |
pierrick | 2:addb687a4e73 | 38 | if(ew == 'W') { longitude *= -1.0; } |
pierrick | 2:addb687a4e73 | 39 | float degrees =(latitude / 100.0f); |
pierrick | 2:addb687a4e73 | 40 | float minutes = latitude - (degrees * 100.0f); |
pierrick | 2:addb687a4e73 | 41 | latitude = degrees + minutes / 60.0f; |
pierrick | 2:addb687a4e73 | 42 | degrees = (longitude / 100.0f * 0.01f); |
pierrick | 2:addb687a4e73 | 43 | minutes = longitude - (degrees * 100.0f); |
pierrick | 2:addb687a4e73 | 44 | longitude = degrees + minutes / 60.0f; |
pierrick | 2:addb687a4e73 | 45 | pc.printf("time = %f \n", time2); |
pierrick | 2:addb687a4e73 | 46 | pc.printf("long= %f %c latitude= %f %c\n",longitude, ew, latitude, ns); |
pierrick | 1:f24af888e699 | 47 | }//end else |
pierrick | 1:f24af888e699 | 48 | }//end if |
pierrick | 1:f24af888e699 | 49 | }//end if |
pierrick | 1:f24af888e699 | 50 | } //end while |
pierrick | 1:f24af888e699 | 51 | } //end main |
pierrick | 1:f24af888e699 | 52 | |
pierrick | 1:f24af888e699 | 53 | /* |
pierrick | 1:f24af888e699 | 54 | c=uart1.getc(); |
pierrick | 1:f24af888e699 | 55 | pc.printf("%c",c); |
pierrick | 1:f24af888e699 | 56 | */ |
pierrick | 1:f24af888e699 | 57 | /* } |
pierrick | 1:f24af888e699 | 58 | |
pierrick | 1:f24af888e699 | 59 | |
pierrick | 1:f24af888e699 | 60 | */ |
pierrick | 1:f24af888e699 | 61 | /* |
dreday20 | 0:2c0686a07ab8 | 62 | while(1) { |
pierrick | 1:f24af888e699 | 63 | //wait(1.0); |
pierrick | 1:f24af888e699 | 64 | //printf("hello bis\n"); |
pierrick | 1:f24af888e699 | 65 | |
dreday20 | 0:2c0686a07ab8 | 66 | if(gps.sample()) { |
pierrick | 1:f24af888e699 | 67 | printf("I'm at %f, %f\n", gps.longitude, gps.latitude); |
dreday20 | 0:2c0686a07ab8 | 68 | } else { |
pierrick | 1:f24af888e699 | 69 | printf("Oh Dear! No lock :(\n"); |
dreday20 | 0:2c0686a07ab8 | 70 | } |
dreday20 | 0:2c0686a07ab8 | 71 | } |
pierrick | 1:f24af888e699 | 72 | } |
pierrick | 1:f24af888e699 | 73 | |
pierrick | 1:f24af888e699 | 74 | |
pierrick | 1:f24af888e699 | 75 | // Print "Hello World" to the PC |
pierrick | 1:f24af888e699 | 76 | |
pierrick | 1:f24af888e699 | 77 | #include "mbed.h" |
pierrick | 1:f24af888e699 | 78 | */ |
pierrick | 1:f24af888e699 | 79 |