Generation 3 of the Harp project

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

Fork of HARP2 by Tyler Weaver

Files at this revision

API Documentation at this revision

Comitter:
tylerjw
Date:
Thu Feb 23 05:40:54 2012 +0000
Parent:
4:d47805009bbd
Child:
6:204487243310
Commit message:
0.3 - openLog working and nmea files convert to earth files

Changed in this revision

GPS/GPS.cpp Show annotated file Show diff for this revision Revisions of this file
GPS/GPS.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
openLog/openLog.cpp Show annotated file Show diff for this revision Revisions of this file
openLog/openLog.h Show annotated file Show diff for this revision Revisions of this file
--- a/GPS/GPS.cpp	Thu Feb 23 04:24:23 2012 +0000
+++ b/GPS/GPS.cpp	Thu Feb 23 05:40:54 2012 +0000
@@ -36,15 +36,15 @@
 }
 
 #ifdef OPEN_LOG
-void init_log(PinName tx, PinName rx, PinName reset_pin) : _openLog(tx, rx, reset_pin) {
+void GPS::start_log() {
     is_logging = true;
 }
 
-void new_file(void) {
+void GPS::new_file(void) {
     _openLog.newFile();
 }
 
-void stop_log(void) {
+void GPS::stop_log(void) {
     is_logging = false;
 }
 #endif
@@ -67,25 +67,25 @@
         getline();
 
 #ifdef OPEN_LOG
-        if (is_logging) {
+        if (is_logging && lock) {
             _openLog.write(msg);
         }
 #endif
 
         // Check if it is a GPGGA msg (matches both locked and non-locked msg)
-        if (sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c", &utc_time, &nmea_latitude, &ns, &nmea_longitude, &ew, &lock, &satelites, &hdop, &msl_altitude, &msl_units) >= 1) {
+        if (sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c", &utc_time, &nmea_latitude, &ns, &nmea_longitude, &ew, &lock, &satelites, &hdop, &msl_altitude, &msl_units) >= 1) {
             line_parsed = GGA;
         }
         // Check if it is a GPRMC msg
-        else if (sscanf(msg, "GPRMC,%f,%c,%f,%c,%f,%c,%f,%f,%d", &utc_time, &rmc_status, &nmea_latitude, &ns, &nmea_longitude, &ew, &speed_k, &course_d, &date) >= 1) {
+        else if (sscanf(msg, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,%f,%d", &utc_time, &rmc_status, &nmea_latitude, &ns, &nmea_longitude, &ew, &speed_k, &course_d, &date) >= 1) {
             line_parsed = RMC;
         }
         // GLL - Geographic Position-Lat/Lon
-        else if (sscanf(msg, "GPGLL,%f,%c,%f,%c,%f,%c", &nmea_latitude, &ns, &nmea_longitude, &ew, &utc_time, &gll_status) >= 1) {
+        else if (sscanf(msg, "$GPGLL,%f,%c,%f,%c,%f,%c", &nmea_latitude, &ns, &nmea_longitude, &ew, &utc_time, &gll_status) >= 1) {
             line_parsed = GLL;
         }
         // VTG-Course Over Ground and Ground Speed
-        else if (sscanf(msg, "GPVTG,%f,%c,%f,%c,%f,%c,%f,%c", &course_t, &course_t_unit, &course_m, &course_m_unit, &speed_k, &speed_k_unit, &speed_km, &speed_km_unit) >= 1) {
+        else if (sscanf(msg, "$GPVTG,%f,%c,%f,%c,%f,%c,%f,%c", &course_t, &course_t_unit, &course_m, &course_m_unit, &speed_k, &speed_k_unit, &speed_km, &speed_km_unit) >= 1) {
             line_parsed = VTG;
         }
     }
@@ -110,11 +110,11 @@
 }
 
 void GPS::getline() {
-    while (_gps.getc() != '$');   // wait for the start of a line
-    for (int i=0; i<256; i++) {
+    for(int i=0; i<1022; i++) {
         msg[i] = _gps.getc();
-        if (msg[i] == '\r') {
-            msg[i] = 0;
+        if(msg[i] == '\r') {
+            msg[i+1] = '\n';
+            msg[i+2] = 0;
             return;
         }
     }
--- a/GPS/GPS.h	Thu Feb 23 04:24:23 2012 +0000
+++ b/GPS/GPS.h	Thu Feb 23 05:40:54 2012 +0000
@@ -1,12 +1,9 @@
 #include "mbed.h"
+#include "openLog.h"
 
 #ifndef MBED_GPS_H
 #define MBED_GPS_H
 
-#ifdef OPEN_LOG
-#include "openLog.h"
-#endif
-
 #define NO_LOCK     1
 #define NOT_PARSED  2
 #define GGA         3
@@ -39,7 +36,7 @@
     int get_satelites();
     
 #ifdef OPEN_LOG
-    void init_log(PinName tx, PinName rx, PinName reset_pin);
+    void start_log(void);
     void new_file(void);
     void stop_log(void);
 #endif    
@@ -50,7 +47,7 @@
     void getline();
     
     Serial _gps;
-    char msg[256];
+    char msg[1024];
     bool is_logging;
 #ifdef OPEN_LOG
     Logger _openLog;
--- a/main.cpp	Thu Feb 23 04:24:23 2012 +0000
+++ b/main.cpp	Thu Feb 23 05:40:54 2012 +0000
@@ -1,4 +1,5 @@
 #include "mbed.h"
+#include "openLog.h"
 #include "GPS.h"
 
 Serial pc(USBTX, USBRX);
@@ -6,6 +7,7 @@
 
 int main() {
     int gps_message;
+    gps.start_log();
     while (1) {
         gps_message = gps.sample();
         if (gps_message == GGA) {
--- a/openLog/openLog.cpp	Thu Feb 23 04:24:23 2012 +0000
+++ b/openLog/openLog.cpp	Thu Feb 23 05:40:54 2012 +0000
@@ -1,5 +1,10 @@
 #include "openLog.h"
 
+Logger::Logger(): _openLog(DEF_TX, DEF_RX), _reset_pin(DEF_RESET) {
+    _openLog.baud(9600);
+    _reset_pin.write(1);
+}
+
 Logger::Logger(PinName tx, PinName rx, PinName reset) : _openLog(tx, rx), _reset_pin(reset) {
     _openLog.baud(9600);
     _reset_pin.write(1);
@@ -9,7 +14,7 @@
     _reset_pin = 0;
 }
 
-int Logger::write(char* data) {
+void Logger::write(char* data) {
     if(_reset_pin == 0) // if reset pin was just set
         _reset_pin = 1;
     
--- a/openLog/openLog.h	Thu Feb 23 04:24:23 2012 +0000
+++ b/openLog/openLog.h	Thu Feb 23 05:40:54 2012 +0000
@@ -3,13 +3,17 @@
 
 #include "mbed.h"
 
+#define DEF_TX     p13
+#define DEF_RX     p14
+#define DEF_RESET  p12
+
 class Logger {
 public:
-
+    Logger();
     Logger(PinName tx, PinName rx, PinName reset);
 
     void newFile(void);
-    int write(char*);
+    void write(char*);
 
 private:
     Serial _openLog;