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:
Fri Dec 07 19:19:00 2012 +0000
Parent:
6:204487243310
Child:
8:13360ec824a7
Commit message:
rtos, MODSERIAL implementation demo

Changed in this revision

GPS.lib Show annotated file Show diff for this revision Revisions of this file
GPS/.lib Show diff for this revision Revisions of this file
GPS/GPS.cpp Show diff for this revision Revisions of this file
GPS/GPS.h Show diff for this revision Revisions of this file
MODSERIAL.lib 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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show diff for this revision Revisions of this file
openLog/.lib Show diff for this revision Revisions of this file
openLog/openLog.cpp Show diff for this revision Revisions of this file
openLog/openLog.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS.lib	Fri Dec 07 19:19:00 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/tylerjw/code/GPS/#465354a08ff8
--- a/GPS/.lib	Fri Feb 24 21:28:33 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/simon/programs/GPS/5zv5x
\ No newline at end of file
--- a/GPS/GPS.cpp	Fri Feb 24 21:28:33 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,218 +0,0 @@
-#include "GPS.h"
-
-GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
-    _gps.baud(4800);
-    nmea_longitude = 0.0;
-    nmea_latitude = 0.0;
-    utc_time = 0;
-    ns = ' ';
-    ew = ' ';
-    lock = 0;
-    satelites = 0;
-    hdop = 0.0;
-    msl_altitude = 0.0;
-    msl_units = ' ';
-
-    rmc_status = ' ';
-    speed_k = 0.0;
-    course_d = 0.0;
-    date = 0;
-
-    dec_longitude = 0.0;
-    dec_latitude = 0.0;
-
-    gll_status = ' ';
-
-    course_t = 0.0; // ground speed true
-    course_t_unit = ' ';
-    course_m = 0.0; // magnetic
-    course_m_unit = ' ';
-    speed_k_unit = ' ';
-    speed_km = 0.0; // speek km/hr
-    speed_km_unit = ' ';
-
-    altitude_ft = 0.0;
-#ifdef OPEN_LOG
-    is_logging = false;
-#endif
-}
-
-#ifdef OPEN_LOG
-void GPS::start_log() {
-    is_logging = true;
-}
-
-void GPS::new_file(void) {
-    _openLog.newFile();
-}
-
-void GPS::stop_log(void) {
-    is_logging = false;
-}
-#endif
-
-float GPS::nmea_to_dec(float deg_coord, char nsew) {
-    int degree = (int)(deg_coord/100);
-    float minutes = deg_coord - degree*100;
-    float dec_deg = minutes / 60;
-    float decimal = degree + dec_deg;
-    if (nsew == 'S' || nsew == 'W') { // return negative
-        decimal *= -1;
-    }
-    return decimal;
-}
-
-int GPS::sample() {
-    int line_parsed = 0;
-
-    if (_gps.readable()) {
-        getline();
-    
-#ifdef OPEN_LOG
-        if (is_logging && lock) {
-            format_for_log();
-            _openLog.write(bfr);
-        }
-#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) {
-            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) {
-            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) {
-            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) {
-            line_parsed = VTG;
-        }
-    }
-    if (!lock) {
-        return NO_LOCK;
-    } else if (line_parsed) {
-        return line_parsed;
-    } else {
-        return NOT_PARSED;
-    }
-}
-
-float GPS::trunc(float v) {
-    if (v < 0.0) {
-        v*= -1.0;
-        v = floor(v);
-        v*=-1.0;
-    } else {
-        v = floor(v);
-    }
-    return v;
-}
-
-void GPS::getline() {
-    while (_gps.getc() != '$');   // wait for the start of a line
-    for (int i=0; i<1022; i++) {
-        msg[i] = _gps.getc();
-        if (msg[i] == '\r') {
-            msg[i] = 0;
-            return;
-        }
-    }
-    error("Overflow in getline");
-}
-
-void GPS::format_for_log() {
-    bfr[0] = '$';
-    for (int i = 0; i < 1022; i++) {
-        bfr[i+1] = msg[i];
-        if (msg[i] == 0) {
-            bfr[i+1] = '\r';
-            bfr[i+2] = '\n';
-            bfr[i+3] = 0;
-            return;
-        }
-    }
-    error("Overflow in format");
-}
-
-float GPS::get_msl_altitude() {
-    if (!lock)
-        return 0.0;
-    else
-        return msl_altitude;
-}
-
-int GPS::get_satelites() {
-    if (!lock)
-        return 0;
-    else
-        return satelites;
-}
-
-float GPS::get_nmea_longitude() {
-    if (!lock)
-        return 0.0;
-    else
-        return nmea_longitude;
-}
-
-float GPS::get_dec_longitude() {
-    dec_longitude = nmea_to_dec(nmea_longitude, ew);
-    if (!lock)
-        return 0.0;
-    else
-        return dec_longitude;
-}
-
-float GPS::get_nmea_latitude() {
-    if (!lock)
-        return 0.0;
-    else
-        return nmea_latitude;
-}
-
-float GPS::get_dec_latitude() {
-    dec_latitude = nmea_to_dec(nmea_latitude, ns);
-    if (!lock)
-        return 0.0;
-    else
-        return dec_latitude;
-}
-
-float GPS::get_course_t() {
-    if (!lock)
-        return 0.0;
-    else
-        return course_t;
-}
-
-float GPS::get_course_m() {
-    if (!lock)
-        return 0.0;
-    else
-        return course_m;
-}
-
-float GPS::get_speed_k() {
-    if (!lock)
-        return 0.0;
-    else
-        return speed_k;
-}
-
-float GPS::get_speed_km() {
-    if (!lock)
-        return 0.0;
-    else
-        return speed_km;
-}
-
-float GPS::get_altitude_ft() {
-    if (!lock)
-        return 0.0;
-    else
-        return 3.280839895*msl_altitude;
-}
\ No newline at end of file
--- a/GPS/GPS.h	Fri Feb 24 21:28:33 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-#include "mbed.h"
-#include "openLog.h"
-
-#ifndef MBED_GPS_H
-#define MBED_GPS_H
-
-#define NO_LOCK     1
-#define NOT_PARSED  2
-#define GGA         3
-#define GLL         4
-#define RMC         5
-#define VTG         6
-
-/**  A GPS interface for reading from a Globalsat EM-406 GPS Module */
-class GPS {
-public:
-
-    /** Create the GPS interface, connected to the specified serial port
-     */    
-    GPS(PinName tx, PinName rx);
-    
-    /** Sample the incoming GPS data, returning whether there is a lock
-     * 
-     * @return 1 if there was a lock when the sample was taken (and therefore .longitude and .latitude are valid), else 0
-     */
-    int sample();
-    float get_nmea_longitude();
-    float get_nmea_latitude();
-    float get_dec_longitude();
-    float get_dec_latitude();
-    float get_msl_altitude();
-    float get_course_t();
-    float get_course_m();
-    float get_speed_k();
-    float get_speed_km();
-    int get_satelites();
-    float get_altitude_ft();
-    
-    //float calc_course_to(float, float);
-    //float calc_dist_to(float, float);
-    
-#ifdef OPEN_LOG
-    void start_log(void);
-    void new_file(void);
-    void stop_log(void);
-#endif    
-    
-private:
-    float nmea_to_dec(float, char);
-    float trunc(float v);
-    void getline();
-    void format_for_log(void);
-    
-    Serial _gps;
-    char msg[1024];
-    char bfr[1030];
-    bool is_logging;
-#ifdef OPEN_LOG
-    Logger _openLog;
-#endif
-    // calculated values
-    float dec_longitude;
-    float dec_latitude;
-    float altitude_ft;
-    
-    // GGA - Global Positioning System Fixed Data
-    float nmea_longitude;
-    float nmea_latitude;    
-    float utc_time;
-    char ns, ew;
-    int lock;
-    int satelites;
-    float hdop;
-    float msl_altitude;
-    char msl_units;
-    
-    // RMC - Recommended Minimmum Specific GNS Data
-    char rmc_status;
-    float speed_k;
-    float course_d;
-    int date;
-    
-    // GLL
-    char gll_status;
-    
-    // VTG - Course over ground, ground speed
-    float course_t; // ground speed true
-    char course_t_unit;
-    float course_m; // magnetic
-    char course_m_unit;
-    char speed_k_unit;
-    float speed_km; // speek km/hr
-    char speed_km_unit;
-};
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Fri Dec 07 19:19:00 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#a69083fab43f
--- 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Dec 07 19:19:00 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#88a1a9c26ae3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Dec 07 19:19:00 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06
\ No newline at end of file
--- a/mbed.lib	Fri Feb 24 21:28:33 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/projects/libraries/svn/mbed/trunk@22
\ No newline at end of file
--- a/openLog/.lib	Fri Feb 24 21:28:33 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
- 
\ No newline at end of file
--- a/openLog/openLog.cpp	Fri Feb 24 21:28:33 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#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);
-}
-
-void Logger::newFile(void) {
-    _reset_pin = 0;
-}
-
-void Logger::write(char* data) {
-    if(_reset_pin == 0) // if reset pin was just set
-        _reset_pin = 1;
-    
-    _openLog.printf(data);
-}
\ No newline at end of file
--- a/openLog/openLog.h	Fri Feb 24 21:28:33 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#ifndef OPEN_LOG
-#define OPEN_LOG
-
-#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);
-    void write(char*);
-
-private:
-    Serial _openLog;
-    DigitalOut _reset_pin;
-};
-#endif
\ No newline at end of file