Dependencies:   mbed

Fork of test_GPS_15_mai by TeamLegrand

Committer:
the420team
Date:
Mon May 28 13:34:18 2018 +0000
Revision:
1:5531e0a69c91
Parent:
0:a75b3f56d863

        

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 1:5531e0a69c91 26 char GPS [25];
the420team 0:a75b3f56d863 27 char rx ;
the420team 0:a75b3f56d863 28 int e ;
the420team 0:a75b3f56d863 29
the420team 0:a75b3f56d863 30 int main() {
the420team 0:a75b3f56d863 31
the420team 0:a75b3f56d863 32 led1=0;
the420team 0:a75b3f56d863 33 led5=0;
the420team 0:a75b3f56d863 34 pc.printf("debut ");
the420team 0:a75b3f56d863 35 e = 0 ;
the420team 0:a75b3f56d863 36 while(1) {
the420team 0:a75b3f56d863 37
the420team 0:a75b3f56d863 38 rx = gps.getc();
the420team 0:a75b3f56d863 39 for(int i = 0; i <80; i++)
the420team 0:a75b3f56d863 40 {
the420team 0:a75b3f56d863 41 trame[i] = trame[i+1];
the420team 0:a75b3f56d863 42 }
the420team 0:a75b3f56d863 43 trame[76]=rx ;
the420team 0:a75b3f56d863 44 strncpy(debut_trame,trame,6);
the420team 0:a75b3f56d863 45
the420team 0:a75b3f56d863 46 if (strcmp(debut_trame,"$GPGGA") == 0)
the420team 0:a75b3f56d863 47 {
the420team 0:a75b3f56d863 48 led1=1;
the420team 0:a75b3f56d863 49
the420team 0:a75b3f56d863 50 for (int i = 0; i<=8; i++)
the420team 0:a75b3f56d863 51 {
the420team 0:a75b3f56d863 52 lat[i] = trame [18+i];
the420team 0:a75b3f56d863 53 lat_cnv = atof(lat);
the420team 0:a75b3f56d863 54 }
the420team 0:a75b3f56d863 55 lat_NS = trame [28];
the420team 0:a75b3f56d863 56
the420team 0:a75b3f56d863 57 for (int a=0; a<=9; a++)
the420team 0:a75b3f56d863 58 {
the420team 0:a75b3f56d863 59 lon[a] = trame [30+a];
the420team 0:a75b3f56d863 60 lon_cnv = atof(lon);
the420team 0:a75b3f56d863 61 }
the420team 0:a75b3f56d863 62 lon_EW = trame [41];
the420team 0:a75b3f56d863 63
the420team 0:a75b3f56d863 64 lat_cnv = lat_cnv/100;
the420team 0:a75b3f56d863 65 lat_deg = (int)lat_cnv;
the420team 0:a75b3f56d863 66 lat_dec = lat_cnv - lat_deg;
the420team 0:a75b3f56d863 67 lat_dec = (lat_dec/60)*100;
the420team 0:a75b3f56d863 68 lat_cnv = lat_deg + lat_dec;
the420team 0:a75b3f56d863 69
the420team 0:a75b3f56d863 70 lon_cnv = lon_cnv/100;
the420team 0:a75b3f56d863 71 lon_deg = (int)lon_cnv;
the420team 0:a75b3f56d863 72 lon_dec = lon_cnv - lon_deg;
the420team 0:a75b3f56d863 73 lon_dec = (lon_dec/60)*100;
the420team 0:a75b3f56d863 74 lon_cnv = lon_deg + lon_dec;
the420team 0:a75b3f56d863 75
the420team 0:a75b3f56d863 76 if (lat_NS=='N')
the420team 0:a75b3f56d863 77 {
the420team 0:a75b3f56d863 78 lat_cnv = lat_cnv*1;
the420team 0:a75b3f56d863 79 }
the420team 0:a75b3f56d863 80
the420team 0:a75b3f56d863 81 else if (lat_NS=='S')
the420team 0:a75b3f56d863 82 {
the420team 0:a75b3f56d863 83 lat_cnv = lat_cnv*(-1);
the420team 0:a75b3f56d863 84 }
the420team 0:a75b3f56d863 85
the420team 0:a75b3f56d863 86 if (lon_EW=='E')
the420team 0:a75b3f56d863 87 {
the420team 0:a75b3f56d863 88 lat_cnv = lat_cnv*1;
the420team 0:a75b3f56d863 89 }
the420team 0:a75b3f56d863 90
the420team 0:a75b3f56d863 91 else if (lon_EW=='W')
the420team 0:a75b3f56d863 92 {
the420team 0:a75b3f56d863 93 lat_cnv = lat_cnv*(-1);
the420team 0:a75b3f56d863 94 }
the420team 1:5531e0a69c91 95 sprintf(GPS, "POS: %f,%f", lat_cnv, lon_cnv);
the420team 1:5531e0a69c91 96 pc.printf("%s \n\r", GPS);
the420team 0:a75b3f56d863 97 }
the420team 0:a75b3f56d863 98 }
the420team 0:a75b3f56d863 99 }