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: PCMessaging.h
- Revision:
- 9:893481b2e488
- Parent:
- 6:71da5b99de97
- Child:
- 10:37ff5b97cf98
--- a/PCMessaging.h Sun May 05 14:35:25 2013 +0000 +++ b/PCMessaging.h Sun May 05 17:05:02 2013 +0000 @@ -9,6 +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 double DEGREES_TO_RADIANS = acos(-1.0)/180.0; const double eccen = 0.0818191908426; //WGS84 earth eccentricity @@ -28,9 +29,10 @@ bool sendLogMsgInfo =false; bool recordData =false; bool fireTrigger =false; +bool get_file_msg =false; -const unsigned char numMessages = 9; //number of potential messages +const unsigned char numMessages = 10; //number of potential messages char msgList[numMessages][32]; //text array storing the command messages from the PC char minMessageSize = 11; //minimum size of a text message unsigned char CR = 0x0d; //ASCII Carriage Return @@ -51,6 +53,7 @@ sprintf(msgList[STARTLOGINFO_MSG], "WMsg LOGINFO Y"); sprintf(msgList[STOPLOGINFO_MSG], "WMsg LOGINFO N"); sprintf(msgList[FIRE_TRIGGER_MSG], "WMsg TRIGGER"); + sprintf(msgList[GETFILE_MSG], "WMsg GETFILE"); //message length is from 10 to 16 chars // toPC.printf(" finished setting up messages \n"); @@ -59,7 +62,7 @@ void readFromPC() { // should this be a while rather than if ??? -- may have multiple bytes in buffer - if (toPC.readable()) //read a PC serial byte and test it for a command + while (toPC.readable()) //read a PC serial byte and test it for a command { // Read in next character -- why not read all available?? unsigned char inChar = 0; @@ -67,7 +70,7 @@ //toPC.printf("%02x ",inChar); //incoming messages will end witb a CR / LF -- disregard these chars - if (inChar == CR || inChar == LF) return; //CR is a 0x0a + if (inChar == CR || inChar == LF) continue; //CR is a 0x0a //all received messages assumed to have a WMsg preamble //if we have read 4 chars, test these for "WMsg", if they are not WMsg, reset the buffer counter @@ -90,13 +93,13 @@ { toPC.printf("WMsg preamble mismatch \n"); serBufChars = 0; //if they dont match -- restart the search for a preamble - return; + continue; } } //if we get here, we have found a preamble and we are looking for a complete message //no need to continue if numChars are less than the shortest candidate message - if (serBufChars < minMessageSize) return; + if (serBufChars < minMessageSize) continue; // Append end of string // We always assume we have a complete message string and test for this below @@ -126,33 +129,44 @@ { case STATUS_MSG: sendStatus = true; //send a status message back to PC - break; + break; + case POSVEL_MSG: sendPosVel = true; //send a posvel message back to PC timeFromPosVelMessageReceipt.reset(); //start time and close SD card file if too long - break; + break; + case STARTDATA_MSG: //start the data recording to the SD card recordData = true; sendRecData = true; break; + case STOPDATA_MSG: //stop the data recording to the SD card recordData = false; sendRecData = true; break; + case STARTSTREAM_MSG: case STOPSTREAM_MSG: streamPos = (m == STARTSTREAM_MSG); sendStreamPos = true; - break; + break; + case STARTLOGINFO_MSG: case STOPLOGINFO_MSG: logMsgInfo = (m == STARTLOGINFO_MSG); sendLogMsgInfo = true; - break; + break; + case FIRE_TRIGGER_MSG: fireTrigger = true; toPC.printf("MBED received trigger command \n"); + break; + + case GETFILE_MSG: + get_file_msg = true; break; + } //end Switch statement break; } //end test for a valid message