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:
Sun Dec 09 08:48:30 2012 +0000
Parent:
8:13360ec824a7
Child:
10:b13416bbb4cd
Commit message:
not tested... standard SD card implementation, not working

Changed in this revision

MODSERIAL.lib Show diff for this revision Revisions of this file
SDFileSystem.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.bld Show annotated file Show diff for this revision Revisions of this file
--- a/MODSERIAL.lib	Fri Dec 07 20:42:48 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/Sissors/code/MODSERIAL/#a69083fab43f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Sun Dec 09 08:48:30 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- a/main.cpp	Fri Dec 07 20:42:48 2012 +0000
+++ b/main.cpp	Sun Dec 09 08:48:30 2012 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "rtos.h"
-
-#include "MODSERIAL.h"
+#include "SDFileSystem.h"
+//#include "MODSERIAL.h"
 
 Serial pc(USBTX, USBRX);
 
@@ -9,11 +9,12 @@
 float test_long = -104.978226;
 
 // Connect the TX of the GPS module to p10 RX input
-MODSERIAL gps(NC, p14);
+Serial gps(NC, p14);
+
+SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
 
 DigitalOut irq_led(LED1);
 
-bool newline_detected = false;
 Semaphore newlines(0);
 
 // Called everytime a new character goes into
@@ -21,52 +22,89 @@
 // 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)
+char gps_buffer[1024];
+int buffer_counter = 0;
+int newline_pos = 0;
+
+void rxCallback()
 {
-    newline_detected = true;
-    //newlines++;
-    newlines.release();
-    irq_led = !irq_led;
+    char c;
+    while(gps.readable()) {
+        c = gps.getc();
+        gps_buffer[buffer_counter++] = c;
+        if(buffer_counter == 1024)
+        {
+            error("Buffer Overflow");
+            buffer_counter = 1023;
+        }
+        if(c == '\n') {
+            newlines.release();
+            newline_pos = buffer_counter - 1;
+            irq_led = !irq_led;
+        }
+    }
+}
+
+void gps_getline(char *buffer, int size)
+{
+    __disable_irq();
+    strncpy(buffer, gps_buffer, newline_pos+1);
+    memmove(gps_buffer,gps_buffer+(newline_pos+1), (buffer_counter - newline_pos - 1)); 
+    buffer_counter = (buffer_counter - newline_pos - 1);   
+    newline_pos = 0;    
+    __enable_irq();
 }
 
 void gps_thread(void const *args)
 {
     char buffer[512];
-    Timer t;
-    t.start();
-    float start;
-    int number_lines = 0;
-    float average_wait = 0.0;
-    float wait[10];
+    int counter = 0;
+    int file_counter = 0;
+    char filename[21];
+
+    DigitalOut gps_led(LED2);
 
     gps.baud(4800);
     pc.baud(9600);
-    gps.autoDetectChar('\n');
-    gps.attach(&rxCallback, MODSERIAL::RxAutoDetect);
+
+    //gps.autoDetectChar('\n');
+    gps.attach(&rxCallback, Serial::RxIrq);
+
+    gps_led = 1;
+
+    sprintf(filename, "/sd/hab/gps%03d.log", file_counter++);
+    pc.printf("Opening: %s\r\n", filename);
+
+    mkdir("/sd/hab", 0777);
+
+    FILE *gps_file = fopen(filename, "w");
+    if(gps_file == NULL) {
+        error("Could not open file for write\n");
+    }
+    pc.puts("File Open!\r\n");
+    gps_led = 0;
+
 
     while(true) {
-        // Wait here until we detect the \n going into the buffer.
-        //if(newlines == 0)
-            //pc.puts("Waiting... \r\n");
-        //while (!newline_detected) ; // 100ms wait
         newlines.wait(); // wait for next line
-        //pc.printf("%f\r\n",t.read());
-        //if(newlines > 1)
-            //pc.printf("Lines in buffer: %d\r\n",newlines);
-        // When we get here the RX buffer now contains a NMEA sentence.
-        // ...
         memset(buffer, 0, 512);
-        gps.move(buffer, 512);
+        gps_getline(buffer, 512);
         pc.puts(buffer);
-        //newlines--;
+        fputs(buffer, gps_file);
+
+        counter++;
+        if(counter >= 20) {
+            sprintf(filename, "/sd/hab/gps%03d.log", file_counter++);
+            pc.printf("Opening: %s\r\n", filename);
+            freopen(filename, "w", gps_file);
+            counter = 0;
+        }
     }
-
 }
 
-
 int main()
 {
-    Thread thread(gps_thread, NULL, osPriorityRealtime);
-    
+    Thread thread(gps_thread, NULL, osPriorityHigh);
+
     while(true);
 }
\ No newline at end of file
--- a/mbed.bld	Fri Dec 07 20:42:48 2012 +0000
+++ b/mbed.bld	Sun Dec 09 08:48:30 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1
\ No newline at end of file