Gps

Dependencies:   mbed

Fork of GPS_System_with_Google_Maps by fadi ladhari

Committer:
jijou
Date:
Wed Jan 18 17:04:49 2017 +0000
Revision:
8:c0a52f5de10d
Parent:
7:73d911fc2bfa
gps trame ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jijou 8:c0a52f5de10d 1 // Provide a serial pass-through between the PC and an external UART
jijou 8:c0a52f5de10d 2
samux 1:31e50fea8be8 3 #include "mbed.h"
jijou 8:c0a52f5de10d 4
jijou 8:c0a52f5de10d 5 Serial pc(PA_0,PA_1); // tx, rx
jijou 8:c0a52f5de10d 6 //Serial gps(PA_9, PA_10); // tx, rx
jijou 8:c0a52f5de10d 7
jijou 8:c0a52f5de10d 8 uint8_t buffer[64]; // buffer array for data receive over serial port
jijou 8:c0a52f5de10d 9 uint8_t count=0;
Ifrah 3:3c7906d60f89 10
jijou 8:c0a52f5de10d 11 typedef struct {
jijou 8:c0a52f5de10d 12 uint8_t heure;
jijou 8:c0a52f5de10d 13 uint8_t minute;
jijou 8:c0a52f5de10d 14 uint8_t seconde;
jijou 8:c0a52f5de10d 15 } temps;
jijou 8:c0a52f5de10d 16
jijou 8:c0a52f5de10d 17 typedef struct {
jijou 8:c0a52f5de10d 18 uint8_t degre;
jijou 8:c0a52f5de10d 19 uint8_t minut;
jijou 8:c0a52f5de10d 20 double secon;
jijou 8:c0a52f5de10d 21 char azimut;
jijou 8:c0a52f5de10d 22 } latitude;
jijou 8:c0a52f5de10d 23
jijou 8:c0a52f5de10d 24 typedef struct {
jijou 8:c0a52f5de10d 25 uint8_t degre;
jijou 8:c0a52f5de10d 26 uint8_t minut;
jijou 8:c0a52f5de10d 27 double secon;
jijou 8:c0a52f5de10d 28 char azimut;
jijou 8:c0a52f5de10d 29 } longiture;
Ifrah 3:3c7906d60f89 30
jijou 8:c0a52f5de10d 31 void initSerial()
jijou 8:c0a52f5de10d 32 {
jijou 8:c0a52f5de10d 33 pc.baud(9600);
jijou 8:c0a52f5de10d 34 pc.format(8,SerialBase::None,1);
jijou 8:c0a52f5de10d 35 //gps.baud(9600);
jijou 8:c0a52f5de10d 36 //gps.format(8,SerialBase::None,1);
jijou 8:c0a52f5de10d 37 }
jijou 8:c0a52f5de10d 38
jijou 8:c0a52f5de10d 39 void clearBufferArray() // function to clear buffer array
Ifrah 3:3c7906d60f89 40 {
jijou 8:c0a52f5de10d 41 for (int i=0; i<count;i++)
jijou 8:c0a52f5de10d 42 {
jijou 8:c0a52f5de10d 43 buffer[i]=NULL;
jijou 8:c0a52f5de10d 44 } // clear all index of array with command NULL
jijou 8:c0a52f5de10d 45 }
jijou 8:c0a52f5de10d 46
jijou 8:c0a52f5de10d 47 void writeBufferArray()
jijou 8:c0a52f5de10d 48 {
jijou 8:c0a52f5de10d 49 for (int i=0; i<count;i++)
jijou 8:c0a52f5de10d 50 {
jijou 8:c0a52f5de10d 51 pc.putc(buffer[i]);
jijou 8:c0a52f5de10d 52 } // write all index of array
jijou 8:c0a52f5de10d 53 }
jijou 8:c0a52f5de10d 54
jijou 8:c0a52f5de10d 55 int main()
jijou 8:c0a52f5de10d 56 {
jijou 8:c0a52f5de10d 57 initSerial();
jijou 8:c0a52f5de10d 58 while(1)
jijou 8:c0a52f5de10d 59 {
jijou 8:c0a52f5de10d 60 temps tmp;
jijou 8:c0a52f5de10d 61 if (pc.readable()) // if date is coming from software serial port ==> data is coming from SoftSerial shield
jijou 8:c0a52f5de10d 62 {
jijou 8:c0a52f5de10d 63 while(pc.readable()) // reading data into char array
jijou 8:c0a52f5de10d 64 {
jijou 8:c0a52f5de10d 65 buffer[count++]=pc.getc(); // writing data into array
jijou 8:c0a52f5de10d 66 if(count == 64)break;
jijou 8:c0a52f5de10d 67 }
jijou 8:c0a52f5de10d 68 /*
jijou 8:c0a52f5de10d 69 if (sscanf(buffer, "$GPGGA, %2d%2D%lf", &tmp.heure, &tmp.minute, &tmp.seconde) == 3)
jijou 8:c0a52f5de10d 70 {
jijou 8:c0a52f5de10d 71 pc.printf("%dh, %dm, %fs\n", tmp.heure, tmp.minute, tmp.seconde);
jijou 8:c0a52f5de10d 72 }
jijou 8:c0a52f5de10d 73 else
jijou 8:c0a52f5de10d 74 {
jijou 8:c0a52f5de10d 75 pc.printf("error parsing message bro\n");
jijou 8:c0a52f5de10d 76 }
jijou 8:c0a52f5de10d 77 */
jijou 8:c0a52f5de10d 78
jijou 8:c0a52f5de10d 79 writeBufferArray();
jijou 8:c0a52f5de10d 80 //pc.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
jijou 8:c0a52f5de10d 81 clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
jijou 8:c0a52f5de10d 82 count = 0; // set counter of while loop to zero
jijou 8:c0a52f5de10d 83
jijou 8:c0a52f5de10d 84
Ifrah 3:3c7906d60f89 85 }
jijou 8:c0a52f5de10d 86 //if (Serial.available()) // if data is available on hardware serial port ==> data is coming from PC or notebook
jijou 8:c0a52f5de10d 87 //SoftSerial.write(Serial.read()); // write it to the SoftSerial shield
Ifrah 3:3c7906d60f89 88 }
jijou 8:c0a52f5de10d 89
jijou 8:c0a52f5de10d 90 }