Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:166cb8335ad5, 2019-01-25 (annotated)
- Committer:
- olivrela
- Date:
- Fri Jan 25 14:37:06 2019 +0000
- Revision:
- 0:166cb8335ad5
gps_tom
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| olivrela | 0:166cb8335ad5 | 1 | #include "mbed.h" |
| olivrela | 0:166cb8335ad5 | 2 | |
| olivrela | 0:166cb8335ad5 | 3 | DigitalOut myled(LED1); |
| olivrela | 0:166cb8335ad5 | 4 | Serial pc(USBTX, USBRX); |
| olivrela | 0:166cb8335ad5 | 5 | //Serial GPS(A4, A5); //uart1 |
| olivrela | 0:166cb8335ad5 | 6 | Serial GPS(A0, A1); //uart4 |
| olivrela | 0:166cb8335ad5 | 7 | |
| olivrela | 0:166cb8335ad5 | 8 | int main() { |
| olivrela | 0:166cb8335ad5 | 9 | GPS.baud(4800); |
| olivrela | 0:166cb8335ad5 | 10 | //int a=0; |
| olivrela | 0:166cb8335ad5 | 11 | //char z; |
| olivrela | 0:166cb8335ad5 | 12 | char msg[256]; |
| olivrela | 0:166cb8335ad5 | 13 | float time, latitude, longitude; |
| olivrela | 0:166cb8335ad5 | 14 | int lock; |
| olivrela | 0:166cb8335ad5 | 15 | char ns, ew; |
| olivrela | 0:166cb8335ad5 | 16 | float trunc; |
| olivrela | 0:166cb8335ad5 | 17 | |
| olivrela | 0:166cb8335ad5 | 18 | pc.printf(" -------------- debut ------------------\n\r"); |
| olivrela | 0:166cb8335ad5 | 19 | while(1) { |
| olivrela | 0:166cb8335ad5 | 20 | |
| olivrela | 0:166cb8335ad5 | 21 | if(GPS.readable()){ |
| olivrela | 0:166cb8335ad5 | 22 | //pc.printf(" -------------- qq chose -\n\r"); |
| olivrela | 0:166cb8335ad5 | 23 | while(GPS.getc() != '$'); // s'il n'y a pas de dollar on récupère ce qui suit |
| olivrela | 0:166cb8335ad5 | 24 | //pc.printf(" -------------- un $ ---\n\r"); |
| olivrela | 0:166cb8335ad5 | 25 | for(int i=0; i<256; i++) { // on récupère les 256 caractères (trame =256 caractères peut-être) |
| olivrela | 0:166cb8335ad5 | 26 | msg[i] = GPS.getc(); |
| olivrela | 0:166cb8335ad5 | 27 | if(msg[i] == '\r') { //on rempli le buffer msg par les caractères récupérés |
| olivrela | 0:166cb8335ad5 | 28 | msg[i] = 0;} |
| olivrela | 0:166cb8335ad5 | 29 | } |
| olivrela | 0:166cb8335ad5 | 30 | } |
| olivrela | 0:166cb8335ad5 | 31 | pc.printf(" %s \n\r",msg); |
| olivrela | 0:166cb8335ad5 | 32 | if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d", &time, &latitude, &ns, &longitude, &ew, &lock) >= 1) { // on scan s'il y a du float etc dans "GPGGA"... dans "msg" |
| olivrela | 0:166cb8335ad5 | 33 | |
| olivrela | 0:166cb8335ad5 | 34 | pc.printf("####################### LAT ET LONG #####################\n\r"); |
| olivrela | 0:166cb8335ad5 | 35 | pc.printf("%f,%f\n\n\r",latitude,longitude); |
| olivrela | 0:166cb8335ad5 | 36 | //pc.printf("%f",altitude); |
| olivrela | 0:166cb8335ad5 | 37 | |
| olivrela | 0:166cb8335ad5 | 38 | if(!lock) { // si on capte aucun satellite |
| olivrela | 0:166cb8335ad5 | 39 | longitude = 0.0; |
| olivrela | 0:166cb8335ad5 | 40 | latitude = 0.0; |
| olivrela | 0:166cb8335ad5 | 41 | |
| olivrela | 0:166cb8335ad5 | 42 | } |
| olivrela | 0:166cb8335ad5 | 43 | /* else { // si on en capte |
| olivrela | 0:166cb8335ad5 | 44 | if(ns == 'S') { latitude *= -1.0; } |
| olivrela | 0:166cb8335ad5 | 45 | if(ew == 'W') { longitude *= -1.0; } |
| olivrela | 0:166cb8335ad5 | 46 | float degrees = trunc * (latitude / 100.0f); |
| olivrela | 0:166cb8335ad5 | 47 | float minutes = latitude - (degrees * 100.0f); |
| olivrela | 0:166cb8335ad5 | 48 | latitude = degrees + minutes / 60.0f; |
| olivrela | 0:166cb8335ad5 | 49 | degrees = trunc * (longitude / (100.0f * 0.01f)); |
| olivrela | 0:166cb8335ad5 | 50 | |
| olivrela | 0:166cb8335ad5 | 51 | minutes = longitude - (degrees * 100.0f); |
| olivrela | 0:166cb8335ad5 | 52 | longitude = degrees + minutes / 60.0f; |
| olivrela | 0:166cb8335ad5 | 53 | |
| olivrela | 0:166cb8335ad5 | 54 | pc.printf("%f\n\r",degrees); |
| olivrela | 0:166cb8335ad5 | 55 | pc.printf("%f,%f\n\r",latitude,longitude); |
| olivrela | 0:166cb8335ad5 | 56 | } |
| olivrela | 0:166cb8335ad5 | 57 | |
| olivrela | 0:166cb8335ad5 | 58 | //pc.printf("%f,%f\n\r",latitude,longitude); |
| olivrela | 0:166cb8335ad5 | 59 | */ } //if |
| olivrela | 0:166cb8335ad5 | 60 | |
| olivrela | 0:166cb8335ad5 | 61 | |
| olivrela | 0:166cb8335ad5 | 62 | |
| olivrela | 0:166cb8335ad5 | 63 | |
| olivrela | 0:166cb8335ad5 | 64 | |
| olivrela | 0:166cb8335ad5 | 65 | |
| olivrela | 0:166cb8335ad5 | 66 | } //while |
| olivrela | 0:166cb8335ad5 | 67 | } |
| olivrela | 0:166cb8335ad5 | 68 | |
| olivrela | 0:166cb8335ad5 | 69 | |
| olivrela | 0:166cb8335ad5 | 70 | |
| olivrela | 0:166cb8335ad5 | 71 | |
| olivrela | 0:166cb8335ad5 | 72 | |
| olivrela | 0:166cb8335ad5 | 73 | |
| olivrela | 0:166cb8335ad5 | 74 | |
| olivrela | 0:166cb8335ad5 | 75 | //if(pc.readable()){pc.printf("%c",pc.getc());} |
| olivrela | 0:166cb8335ad5 | 76 | //pc.printf("%d ", a); |