this version has all of Jim's fixes for reading the GPS and IMU data synchronously

Dependencies:   MODSERIAL SDFileSystem mbed SDShell CRC CommHandler FP LinkedList LogUtil

Files at this revision

API Documentation at this revision

Comitter:
jekain314
Date:
Sun May 05 22:03:52 2013 +0000
Parent:
9:893481b2e488
Child:
11:88efc6048237
Commit message:
tinkered with the termination process.

Changed in this revision

PCMessaging.h Show annotated file Show diff for this revision Revisions of this file
SDShell.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
--- a/PCMessaging.h	Sun May 05 17:05:02 2013 +0000
+++ b/PCMessaging.h	Sun May 05 22:03:52 2013 +0000
@@ -9,7 +9,7 @@
 const unsigned char  STOPSTREAM_MSG     =6;
 const unsigned char  STARTLOGINFO_MSG   =7;
 const unsigned char  STOPLOGINFO_MSG    =8;
-const unsigned char  GETFILE_MSG        =9;
+const unsigned char  GETFILE_MSG        =9;   //used to initiate the retrieval of a SD card data file
 
 const double  DEGREES_TO_RADIANS = acos(-1.0)/180.0;
 const double eccen          = 0.0818191908426;  //WGS84 earth eccentricity
@@ -95,6 +95,7 @@
                 serBufChars = 0;  //if they dont match -- restart the search for a preamble
                 continue;
             }
+            //toPC.printf("WMsg  found a message header \n");
         }
         
         //if we get here, we have found a preamble and we are looking for a complete message
@@ -165,6 +166,7 @@
                     
                     case GETFILE_MSG:
                         get_file_msg = true;
+                        toPC.printf("MBED received GETFILE message \n"); 
                     break;
                     
                 }  //end Switch statement
@@ -344,6 +346,20 @@
                          );
         }
         
+        if (get_file_msg)  //terminate all data recording, close the data file, and exit the while(1) loop
+        {
+            if (fpNav != NULL)  //if the file is open -- close it
+            {
+                toPC.printf(" closing the SD card file \n\n");
+                fflush(fpNav);
+                fclose(fpNav);
+                wait_ms(1000);
+                //toPC.printf("\n after closing the SD card file \n\n");
+                fpNav = NULL;
+             } 
+             recordData = false;  
+        }
+        
         if (sendStreamPos)  //stream the position data to the PC
         {
             sendStreamPos=false;
--- a/SDShell.lib	Sun May 05 17:05:02 2013 +0000
+++ b/SDShell.lib	Sun May 05 22:03:52 2013 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/sam_grove/code/SDShell/#254c2fe9c101
+https://mbed.org/users/sam_grove/code/SDShell/#6ff0a3d92778
--- a/main.cpp	Sun May 05 17:05:02 2013 +0000
+++ b/main.cpp	Sun May 05 22:03:52 2013 +0000
@@ -49,12 +49,12 @@
 {
     SDShell emulate;
     emulate.init();
-    
+    // just indicate that we're in here
     trig1led = ppsled = rxMsg = txMsg = 1;
-    while(1)
-    {
-        emulate.shell(toPC, sd, "/sd");
-    }
+    
+    toPC.printf("Entering Shell Emulator...\n");
+    wait(0.1f);
+    emulate.shell(toPC, sd, "/sd");
 }
 
 //////////////////////////////////////////////////////////////////////
@@ -186,7 +186,8 @@
 /////////////////////////////////////////////////////////////////////
 //  mbed main to support the Waldo_FCS
 /////////////////////////////////////////////////////////////////////
-int main() {
+int main() 
+{
     
     //these are structures for the to GPS messages that must be parsed
     MESSAGEHEADER msgHdr;
@@ -246,23 +247,26 @@
     ///////////////////////////////////////////////////////////////////////////
     while(1)
     {        
+            
         //read the USB serial data from the PC to check for commands
         //in the primary real-time portion, there are no bytes from the PC so this has no impact
         readFromPC();
         
-        /*
+        //
         //this will close the fpNav file on the SD card if the file is open 
         //and the elapsed time from PosVel messages is > 60 secs
         //this prevents loosing the fpNav file if the PC goes down
-        if (fpNav && (timeFromPosVelMessageReceipt.read() > 60) )
+        if (fpNav && (timeFromPosVelMessageReceipt.read() > 10) )
         {
             sendRecData = true;
             recordData  = false;
         }
-        */
+        //
                 
         processPCmessages(fpNav, posMsg, velMsg);
         
+        if (get_file_msg) break;  //terminate the while loop when we receive this message from the PC
+        
         if(fireTrigger)  //comes from a PC request message
         {
             //pre-fire the trigger using the mid-body 2.5mm connection (T2i)
@@ -392,18 +396,27 @@
             IMURecordCounter = 0;
             detectedGPS1PPS = false;
         }
-        if(get_file_msg)
-        {
-            // stop hardware
-            ADIS_RST = 0;
-            GPS_Reset = 0;
-            // reset the flag
-            get_file_msg = false;
-            // transfer the file
-            transferFile();
-        }
     }
       
-    fclose(fpNav);
+    if (fpNav != NULL) fclose(fpNav);  //insurance
     toPC.printf(" normal termination \n");
+    
+    /*
+    //at this point we have terminated the dat collection and we need to send the stored nav file to the PC 
+    FILE* fpNavStored = fopen("/sd/Data/NAV.bin", "rb");
+    unsigned char tempArray[512];
+    toPC.printf(" beginning the file transfer \n");
+    int i = 0;
+    while(!feof(fpNavStored) )
+    {
+        
+        toPC.printf(" reading the 512 bytes: %3d  \n", i);
+        fread(tempArray, 1, 512, fpNavStored);
+        toPC.printf(" writing the 512 bytes: %3d  \n", i);
+        fwrite(tempArray, 1, 512, toPC); 
+        i++;
+    }
+    */
+
+    
 }
\ No newline at end of file