Generation 2 of the Harp project

Dependencies:   Servo TMP36 GZ chan_fatfs_sd buffered-serial1 nmea_parser watchdog mbed-rtos mbed

Revision:
7:d8ecabe16c9e
Parent:
6:204487243310
Child:
8:13360ec824a7
diff -r 204487243310 -r d8ecabe16c9e main.cpp
--- a/main.cpp	Fri Feb 24 21:28:33 2012 +0000
+++ b/main.cpp	Fri Dec 07 19:19:00 2012 +0000
@@ -1,40 +1,56 @@
 #include "mbed.h"
-#include "openLog.h"
-#include "GPS.h"
+#include "rtos.h"
+#include "MODSERIAL.h"
 
 Serial pc(USBTX, USBRX);
-GPS gps(p9, p10);
+
+float test_lat =  39.943039;
+float test_long = -104.978226;
+
+// Connect the TX of the GPS module to p10 RX input
+MODSERIAL gps(NC, p14);
+
+DigitalOut irq_led(LED1);
+
+bool newline_detected = false;
 
-int main() {
+// Called everytime a new character goes into
+// the RX buffer. Test that character for \n
+// Note, rxGetLastChar() gets the last char that
+// we received but it does NOT remove it from
+// the RX buffer.
+void rxCallback(MODSERIAL_IRQ_INFO *q)
+{
+    newline_detected = true;
+    irq_led = !irq_led;
+}
+
+void gps_thread(void const *args)
+{
+    char buffer[512];
+
+    gps.baud(4800);
     pc.baud(9600);
-    int gps_message;
-    gps.start_log();
-    while (1) {
-        gps_message = gps.sample();
-        if (gps_message == GGA) {
-            pc.printf("Responding to GGA message.\n");
-            pc.printf("I'm at %f, %f\n", gps.get_dec_latitude(), gps.get_dec_longitude());
-            pc.printf("%d satelites used\n", gps.get_satelites());
-            pc.printf("altitude = %f ft\n", gps.get_altitude_ft());
-            pc.printf("altitude = %f M\n\n", gps.get_msl_altitude());
-        } else if (gps_message == VTG) {
-            pc.printf("Responding to VTG message.\n");
-            pc.printf("True heading = %f deg\n", gps.get_course_t());
-            pc.printf("Magnetic heading = %f deg\n", gps.get_course_m());
-            pc.printf("Speed = %f knots\n", gps.get_speed_k());
-            pc.printf("Speed = %f Km/hr\n\n", gps.get_speed_km());
-        } else if (gps_message == GLL) {
-            pc.printf("Responding to GLL message.\n");
-            pc.printf("I'm at %f, %f\n", gps.get_dec_latitude(), gps.get_dec_longitude());
-        } else if (gps_message == RMC) {
-            pc.printf("Responding to RMC message.\n");
-            pc.printf("I'm at %f, %f\n", gps.get_dec_latitude(), gps.get_dec_longitude());
-            pc.printf("True heading = %f deg\n", gps.get_course_t());
-            pc.printf("Speed = %f knots\n\n", gps.get_speed_k());
-        } else if (gps_message == NOT_PARSED) {
-            pc.printf("Message not parsed!\n");
-        } else if (gps_message == NO_LOCK) {
-            pc.printf("Oh Dear! No lock :(\n");
-        }
+    gps.autoDetectChar('\n');
+    gps.attach(&rxCallback, MODSERIAL::RxAutoDetect);
+
+    while(true) {
+        // Wait here until we detect the \n going into the buffer.
+        while (! newline_detected ) ;
+
+        // When we get here the RX buffer now contains a NMEA sentence.
+        // ...
+        memset(buffer, 0, 512);
+        gps.move(buffer, 512);
+        pc.puts(buffer);
     }
+
+}
+
+
+int main()
+{
+    Thread thread(gps_thread);
+    
+    while(true);
 }
\ No newline at end of file