Dependencies:   mbed

Fork of test_GPS_15_mai by TeamLegrand

Committer:
the420team
Date:
Tue May 22 12:07:34 2018 +0000
Revision:
0:a75b3f56d863
Child:
1:5531e0a69c91

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
the420team 0:a75b3f56d863 1 #include "mbed.h"
the420team 0:a75b3f56d863 2 #include "stdio.h"
the420team 0:a75b3f56d863 3 #include "Serial.h"
the420team 0:a75b3f56d863 4 #include <string>
the420team 0:a75b3f56d863 5 #include <cstdlib>
the420team 0:a75b3f56d863 6
the420team 0:a75b3f56d863 7 DigitalOut led1(LED1);
the420team 0:a75b3f56d863 8 DigitalOut led2(LED2);
the420team 0:a75b3f56d863 9 DigitalOut led3(LED3);
the420team 0:a75b3f56d863 10 DigitalOut led4(LED4);
the420team 0:a75b3f56d863 11 DigitalOut led5(p7);
the420team 0:a75b3f56d863 12 Serial pc(USBTX, USBRX, 4800);
the420team 0:a75b3f56d863 13 Serial gps(p13, p14, 4800);
the420team 0:a75b3f56d863 14 char debut_trame[7]="XXXXXX";
the420team 0:a75b3f56d863 15 char trame[81] ;
the420team 0:a75b3f56d863 16 char lat[8];
the420team 0:a75b3f56d863 17 char lat_NS;
the420team 0:a75b3f56d863 18 char lon[9];
the420team 0:a75b3f56d863 19 char lon_EW;
the420team 0:a75b3f56d863 20 float lat_cnv;
the420team 0:a75b3f56d863 21 float lon_cnv;
the420team 0:a75b3f56d863 22 int lat_deg = 0;
the420team 0:a75b3f56d863 23 float lat_dec;
the420team 0:a75b3f56d863 24 int lon_deg = 0;
the420team 0:a75b3f56d863 25 float lon_dec;
the420team 0:a75b3f56d863 26 char rx ;
the420team 0:a75b3f56d863 27 int e ;
the420team 0:a75b3f56d863 28
the420team 0:a75b3f56d863 29 int main() {
the420team 0:a75b3f56d863 30
the420team 0:a75b3f56d863 31 led1=0;
the420team 0:a75b3f56d863 32 led5=0;
the420team 0:a75b3f56d863 33 pc.printf("debut ");
the420team 0:a75b3f56d863 34 e = 0 ;
the420team 0:a75b3f56d863 35 while(1) {
the420team 0:a75b3f56d863 36
the420team 0:a75b3f56d863 37 rx = gps.getc();
the420team 0:a75b3f56d863 38 for(int i = 0; i <80; i++)
the420team 0:a75b3f56d863 39 {
the420team 0:a75b3f56d863 40 trame[i] = trame[i+1];
the420team 0:a75b3f56d863 41 }
the420team 0:a75b3f56d863 42 trame[76]=rx ;
the420team 0:a75b3f56d863 43 strncpy(debut_trame,trame,6);
the420team 0:a75b3f56d863 44
the420team 0:a75b3f56d863 45 if (strcmp(debut_trame,"$GPGGA") == 0)
the420team 0:a75b3f56d863 46 {
the420team 0:a75b3f56d863 47 led1=1;
the420team 0:a75b3f56d863 48
the420team 0:a75b3f56d863 49 for (int i = 0; i<=8; i++)
the420team 0:a75b3f56d863 50 {
the420team 0:a75b3f56d863 51 lat[i] = trame [18+i];
the420team 0:a75b3f56d863 52 lat_cnv = atof(lat);
the420team 0:a75b3f56d863 53 }
the420team 0:a75b3f56d863 54 lat_NS = trame [28];
the420team 0:a75b3f56d863 55
the420team 0:a75b3f56d863 56 for (int a=0; a<=9; a++)
the420team 0:a75b3f56d863 57 {
the420team 0:a75b3f56d863 58 lon[a] = trame [30+a];
the420team 0:a75b3f56d863 59 lon_cnv = atof(lon);
the420team 0:a75b3f56d863 60 }
the420team 0:a75b3f56d863 61 lon_EW = trame [41];
the420team 0:a75b3f56d863 62
the420team 0:a75b3f56d863 63 lat_cnv = lat_cnv/100;
the420team 0:a75b3f56d863 64 lat_deg = (int)lat_cnv;
the420team 0:a75b3f56d863 65 lat_dec = lat_cnv - lat_deg;
the420team 0:a75b3f56d863 66 lat_dec = (lat_dec/60)*100;
the420team 0:a75b3f56d863 67 lat_cnv = lat_deg + lat_dec;
the420team 0:a75b3f56d863 68
the420team 0:a75b3f56d863 69 lon_cnv = lon_cnv/100;
the420team 0:a75b3f56d863 70 lon_deg = (int)lon_cnv;
the420team 0:a75b3f56d863 71 lon_dec = lon_cnv - lon_deg;
the420team 0:a75b3f56d863 72 lon_dec = (lon_dec/60)*100;
the420team 0:a75b3f56d863 73 lon_cnv = lon_deg + lon_dec;
the420team 0:a75b3f56d863 74
the420team 0:a75b3f56d863 75 if (lat_NS=='N')
the420team 0:a75b3f56d863 76 {
the420team 0:a75b3f56d863 77 lat_cnv = lat_cnv*1;
the420team 0:a75b3f56d863 78 }
the420team 0:a75b3f56d863 79
the420team 0:a75b3f56d863 80 else if (lat_NS=='S')
the420team 0:a75b3f56d863 81 {
the420team 0:a75b3f56d863 82 lat_cnv = lat_cnv*(-1);
the420team 0:a75b3f56d863 83 }
the420team 0:a75b3f56d863 84
the420team 0:a75b3f56d863 85 if (lon_EW=='E')
the420team 0:a75b3f56d863 86 {
the420team 0:a75b3f56d863 87 lat_cnv = lat_cnv*1;
the420team 0:a75b3f56d863 88 }
the420team 0:a75b3f56d863 89
the420team 0:a75b3f56d863 90 else if (lon_EW=='W')
the420team 0:a75b3f56d863 91 {
the420team 0:a75b3f56d863 92 lat_cnv = lat_cnv*(-1);
the420team 0:a75b3f56d863 93 }
the420team 0:a75b3f56d863 94 pc.printf("%f, %c, %f, %c \n\r", lat_cnv, lat_NS, lon_cnv, lon_EW);
the420team 0:a75b3f56d863 95 }
the420team 0:a75b3f56d863 96 }
the420team 0:a75b3f56d863 97 }