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
PCMessaging.h@29:dead10cce6e9, 2014-01-09 (annotated)
- Committer:
- jekain314
- Date:
- Thu Jan 09 14:09:05 2014 +0000
- Revision:
- 29:dead10cce6e9
- Parent:
- 26:c2208b0ff78b
- Child:
- 30:96d133f3008e
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jekain314 | 0:432b860b6ff7 | 1 | //these are defines for the messages that are sent from the PC across the USB |
jekain314 | 0:432b860b6ff7 | 2 | //these messages produce reactions on the mbed |
jekain314 | 29:dead10cce6e9 | 3 | const unsigned char FIRE_TRIGGER_MSG = 1; |
jekain314 | 0:432b860b6ff7 | 4 | |
jekain314 | 6:71da5b99de97 | 5 | const unsigned short serBuffMax = 18; |
jekain314 | 1:8e24e633f8d8 | 6 | char serBuf[serBuffMax]; |
jekain314 | 0:432b860b6ff7 | 7 | int serBufChars=0; |
jekain314 | 0:432b860b6ff7 | 8 | |
jekain314 | 0:432b860b6ff7 | 9 | //flags to control the PC command actions |
jekain314 | 1:8e24e633f8d8 | 10 | bool fireTrigger =false; |
jekain314 | 0:432b860b6ff7 | 11 | |
jekain314 | 0:432b860b6ff7 | 12 | unsigned char CR = 0x0d; //ASCII Carriage Return |
jekain314 | 0:432b860b6ff7 | 13 | unsigned char LF = 0x0a; //ASCII Line Feed |
jekain314 | 0:432b860b6ff7 | 14 | |
jekain314 | 17:71900da6ced6 | 15 | bool validMessage = false; |
jekain314 | 17:71900da6ced6 | 16 | |
jekain314 | 6:71da5b99de97 | 17 | |
jekain314 | 0:432b860b6ff7 | 18 | void readFromPC() |
jekain314 | 0:432b860b6ff7 | 19 | { |
jekain314 | 6:71da5b99de97 | 20 | // should this be a while rather than if ??? -- may have multiple bytes in buffer |
jekain314 | 0:432b860b6ff7 | 21 | if (toPC.readable()) //read a PC serial byte and test it for a command |
jekain314 | 0:432b860b6ff7 | 22 | { |
jekain314 | 29:dead10cce6e9 | 23 | // Read in next character |
jekain314 | 29:dead10cce6e9 | 24 | // why not read all available bytes |
jekain314 | 1:8e24e633f8d8 | 25 | unsigned char inChar = 0; |
jekain314 | 6:71da5b99de97 | 26 | inChar = toPC.getc(); //read char from the USB serial link to the PC |
jekain314 | 0:432b860b6ff7 | 27 | |
jekain314 | 0:432b860b6ff7 | 28 | //incoming messages will end witb a CR / LF -- disregard these chars |
jekain314 | 0:432b860b6ff7 | 29 | if (inChar == CR || inChar == LF) return; //CR is a 0x0a |
jekain314 | 0:432b860b6ff7 | 30 | |
jekain314 | 29:dead10cce6e9 | 31 | //all incoming messages will start with "mbedMessage", "messageType", numberDataBytes, and will end with CR & LF |
jekain314 | 29:dead10cce6e9 | 32 | //1) look for the mbedMessage and then get the next byte as numberDataBytes; |
jekain314 | 29:dead10cce6e9 | 33 | //2) read the next numberDataBytes and then look for CR & LF |
jekain314 | 29:dead10cce6e9 | 34 | //if 1) & 2) are successful, declare a valid incoming message |
jekain314 | 29:dead10cce6e9 | 35 | //if message is valid, then send a response as a repeat of the original message |
jekain314 | 29:dead10cce6e9 | 36 | // |
jekain314 | 6:71da5b99de97 | 37 | |
jekain314 | 0:432b860b6ff7 | 38 | } //end pc.readable |
jekain314 | 0:432b860b6ff7 | 39 | }; |
jekain314 | 0:432b860b6ff7 | 40 |