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
Diff: main.cpp
- Revision:
- 14:009d4671f0e3
- Parent:
- 13:d5026299c54e
- Child:
- 15:f3b92958cf5a
diff -r d5026299c54e -r 009d4671f0e3 main.cpp --- a/main.cpp Mon May 06 04:28:57 2013 +0000 +++ b/main.cpp Mon May 06 20:32:01 2013 +0000 @@ -6,6 +6,7 @@ #include "MODSERIAL.h" #include "SDFileSystem.h" //imported using the import utility +#include "SDShell.h" //general digital I/O specifications for this application //SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); @@ -43,12 +44,16 @@ volatile int PPSTimeOffset = 0; -// get files from the SD Card - bcat has some problems.... -#include "SDShell.h" -void transferFile(void) +// stuff to send the SD file to the PC +void transferFile() { SDShell emulate; emulate.init(); + // just indicate that we're in here + trig1led = ppsled = rxMsg = txMsg = 1; + + toPC.printf("Entering Shell Emulator...\n"); + wait(0.1f); emulate.shell(toPC, sd, "/sd"); } @@ -181,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; @@ -241,25 +247,30 @@ /////////////////////////////////////////////////////////////////////////// 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 { + unsigned long triggerTime = GPSTimemsecs + PPSTimeOffset*1000 + timeFromPPS.read_us()/1000.0; + toPC.printf("WMsg TRIGGERTIME %10d \n", triggerTime); //pre-fire the trigger using the mid-body 2.5mm connection (T2i) pre_fire = 0; //pin30 (midbody of connector) set to zero wait(.01f); //wait for 0.25 secs @@ -276,8 +287,6 @@ { fire = 1; pre_fire = 1; - unsigned long triggerTime = GPSTimemsecs + PPSTimeOffset*1000 + timeFromPPS.read_us()/1000.0; - toPC.printf("WMsg TRIGGERTIME %10d \n", triggerTime); triggerInterval.reset(); finishTrigger = false; } @@ -387,18 +396,27 @@ IMURecordCounter = 0; detectedGPS1PPS = false; } - - if(get_file_msg) - { - get_file_msg = false; - ADIS_RST = 0; - GPS_Reset = 0; - fclose(fpNav); - 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