affichage d m s

Dependencies:   mbed

Fork of GPS by tito tito

Committer:
vallarjohann
Date:
Fri Mar 18 10:09:38 2016 +0000
Revision:
3:8234e0d5854e
Parent:
2:addb687a4e73
GPS_IUT avec affichage  d m s

Who changed what in which revision?

UserRevisionLine numberNew 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) */
vallarjohann 3:8234e0d5854e 15 float longitude,longitude2;
pierrick 1:f24af888e699 16
pierrick 1:f24af888e699 17 /** The latitude (call sample() to set) */
vallarjohann 3:8234e0d5854e 18 float latitude,latitude2,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)
vallarjohann 3:8234e0d5854e 31 { pc.printf("long= %f %c latitude= %f %c\n",longitude, ew, latitude, ns);
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; }
vallarjohann 3:8234e0d5854e 39 int iDeg=(int) latitude/100;
vallarjohann 3:8234e0d5854e 40 int iMin=(int) (latitude-iDeg*100);
vallarjohann 3:8234e0d5854e 41 float iSec= ((latitude-(iDeg*100+iMin))*60);
vallarjohann 3:8234e0d5854e 42 pc.printf(" latitude degree= %d minutes=%d secondes=%f \n", iDeg,iMin,iSec);
vallarjohann 3:8234e0d5854e 43 int iDeg2=(int) longitude/100;
vallarjohann 3:8234e0d5854e 44 int iMin2=(int) (longitude-iDeg2*100);
vallarjohann 3:8234e0d5854e 45 float iSec2= ((longitude-(iDeg2*100+iMin2))*60);
vallarjohann 3:8234e0d5854e 46 pc.printf(" longitude= %d minutes=%d secondes=%f \n", iDeg2,iMin2,iSec2);
vallarjohann 3:8234e0d5854e 47
vallarjohann 3:8234e0d5854e 48
vallarjohann 3:8234e0d5854e 49
vallarjohann 3:8234e0d5854e 50
pierrick 1:f24af888e699 51 }//end else
pierrick 1:f24af888e699 52 }//end if
pierrick 1:f24af888e699 53 }//end if
pierrick 1:f24af888e699 54 } //end while
pierrick 1:f24af888e699 55 } //end main
pierrick 1:f24af888e699 56
pierrick 1:f24af888e699 57 /*
pierrick 1:f24af888e699 58 c=uart1.getc();
pierrick 1:f24af888e699 59 pc.printf("%c",c);
pierrick 1:f24af888e699 60 */
pierrick 1:f24af888e699 61 /* }
pierrick 1:f24af888e699 62
pierrick 1:f24af888e699 63
pierrick 1:f24af888e699 64 */
pierrick 1:f24af888e699 65 /*
dreday20 0:2c0686a07ab8 66 while(1) {
pierrick 1:f24af888e699 67 //wait(1.0);
pierrick 1:f24af888e699 68 //printf("hello bis\n");
pierrick 1:f24af888e699 69
dreday20 0:2c0686a07ab8 70 if(gps.sample()) {
pierrick 1:f24af888e699 71 printf("I'm at %f, %f\n", gps.longitude, gps.latitude);
dreday20 0:2c0686a07ab8 72 } else {
pierrick 1:f24af888e699 73 printf("Oh Dear! No lock :(\n");
dreday20 0:2c0686a07ab8 74 }
dreday20 0:2c0686a07ab8 75 }
pierrick 1:f24af888e699 76 }
pierrick 1:f24af888e699 77
pierrick 1:f24af888e699 78
pierrick 1:f24af888e699 79 // Print "Hello World" to the PC
pierrick 1:f24af888e699 80
pierrick 1:f24af888e699 81 #include "mbed.h"
pierrick 1:f24af888e699 82 */
pierrick 1:f24af888e699 83