gps code
Dependencies: 4DGL-uLCD-SE mbed
Revision 0:a063a20f5d24, committed 2015-04-20
- Comitter:
- ottaviano3
- Date:
- Mon Apr 20 18:52:03 2015 +0000
- Commit message:
- Perfect gps code
Changed in this revision
diff -r 000000000000 -r a063a20f5d24 4DGL-uLCD-SE.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Mon Apr 20 18:52:03 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
diff -r 000000000000 -r a063a20f5d24 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 20 18:52:03 2015 +0000 @@ -0,0 +1,100 @@ +#include "mbed.h" +#include <iostream> + +Serial pc(p9,p10); + +Serial gps(p28, p27); + +DigitalIn button(p21); + +void getline(); + +char gpsmsg[256]; + +int main() +{ + while(1) { + + // Flush output buffer + char char1; + while (pc.readable()) { + char1 = pc.getc(); + } + + char nodeid[4] = "190"; + float altitude; + + char startkey[12] = "SentinelOn"; + char endkey[13] = "SentinelOff"; + char buffer[30]; + char ns, ew; + int lock; + int satsused; + float hdop; + float latitude, longitude; + + float time; + + gps.baud(4800); + + do { + if (pc.readable() == true) { + // Get bytes from computer + pc.scanf("%s",buffer); + } + } while (strcmp( startkey, buffer ) != 0); + + // Flush output buffer + while (pc.readable()) { + char1 = pc.getc(); + } + + pc.printf("Sentinel Is On\n"); + + + while(1) { + getline(); + if(sscanf(gpsmsg, "GPGGA,%f,%f,%c,%f,%c,%i,%i,%f,%f", &time, &latitude, &ns, &longitude, &ew, &lock, &satsused, &hdop, &altitude) >= 1) { + if((lock != 1) && (lock != 2) && (lock != 6)) { + pc.printf("DNLK,%s,NOLOCK\n",nodeid, latitude, longitude, altitude); + } else { + double degrees; + double minutes = modf(latitude/100.0f, °rees); + minutes = (minutes*100.0f)/60.0f; + latitude = degrees + minutes; + + minutes = modf(longitude/100.0f, °rees); + minutes = (minutes*100.0f)/60.0f; + longitude = degrees + minutes; + + if(ns == 'S') { + latitude *= -1.0; + } + if(ew == 'W') { + longitude *= -1.0; + } + pc.printf("DLIN,%s,%f,%f,%f\n",nodeid, latitude, longitude, altitude); + } + } + if (pc.readable() == true) { + pc.scanf("%s",buffer); + if (strcmp( endkey, buffer ) != 0) { + break; + } + } + } + } +} + +void getline() +{ + while(gps.getc() != '$'); // wait for the start of a line + for(int i=0; i<256; i++) { + gpsmsg[i] = gps.getc(); + if(gpsmsg[i] == '\r') { + gpsmsg[i] = 0; + return ; + } + } + error("Overflowed message limit"); +} \ No newline at end of file
diff -r 000000000000 -r a063a20f5d24 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Apr 20 18:52:03 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0 \ No newline at end of file