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
OEM615.h
- Committer:
- jekain314
- Date:
- 2014-01-09
- Revision:
- 29:dead10cce6e9
- Parent:
- 28:fcea53fcc712
- Child:
- 30:96d133f3008e
File content as of revision 29:dead10cce6e9:
#include "crc.h" //GPS-specific pins DigitalOut GPS_Reset(p18); //GPS RESET line InterruptIn PPSInt(p15); // GPS 1PPS (timemark) from the OEM615 InterruptIn IMUClock(p17); Timer timeFromPPS; unsigned long GPSTimemsecs = 0; //mbed tx/rx interface to the GPS COM1 port MODSERIAL GPS_COM1(p9,p10); //this serial port communicates with the GPS receiver serial port (COM1) bool loadingMessageBuffer = false; const unsigned short maxGPSbytesPerSec = 512; int messagePerSecCounter = 0; unsigned char msgBuffer0[maxGPSbytesPerSec]; //array to contain one full second of GPS bytes unsigned char msgBuffer1[maxGPSbytesPerSec]; //array to contain one full second of GPS bytes unsigned char msgBuffer2[maxGPSbytesPerSec]; //array to contain one full second of GPS bytes int GPSbyteCounter0 = 0; int GPSbyteCounter1 = 0; int GPSbyteCounter2 = 0; bool message0Complete = false; bool message1Complete = false; bool message2Complete = false; void sendASCII(char* ASCI_message, int numChars) { ///////////////////////////////////////////////// //send an ASCII command to the GPS receiver ///////////////////////////////////////////////// //char ASCI_message[] = "unlogall COM1"; int as = numChars - 1; unsigned char CR = 0x0d; //ASCII Carriage Return unsigned char LF = 0x0a; //ASCII Line Feed //printf("%s", ch); //printf("\n"); for (int i=0; i<as; i++) GPS_COM1.putc(ASCI_message[i]); GPS_COM1.putc(CR); //carriage return at end GPS_COM1.putc(LF); //line feed at end }; //see the mbed COOKBOOK for MODSERIAL //MODSERIAL is an easy to use library that extends Serial to add fully buffered input and output. void readSerialByte(MODSERIAL_IRQ_INFO *q) { MODSERIAL *serial = q->serial; //see example of MODSERIAL usage in cookbook unsigned char synch0 = serial->getc(); //get the next byte totalGPSBytes++; //all OEM615 GPS ASCII messages begin with the unique character: "#" //read til we get a "#" and then start storing the message if (synch0 == '#') { if (messagePerSecCounter == 0) GPSbyteCounter0 = 0; else if(messagePerSecCounter == 1) GPSbyteCounter1 = 0; else if(messagePerSecCounter == 2) GPSbyteCounter2 = 0; loadingMessageBuffer = true; } if (messagePerSecCounter == 0) { msgBuffer0[GPSbyteCounter0 % maxGPSbytesPerSec] = synch0; GPSbyteCounter0++; } else if(messagePerSecCounter == 1) { msgBuffer1[GPSbyteCounter1 % maxGPSbytesPerSec] = synch0; GPSbyteCounter1++; } else if(messagePerSecCounter == 2) { msgBuffer2[GPSbyteCounter2 % maxGPSbytesPerSec] = synch0; GPSbyteCounter2++; } //stop storing the message when we get a LF if (synch0 == 0x0a /* LF*/) //test for line feed { if (messagePerSecCounter == 0) message0Complete = true; else if(messagePerSecCounter == 1) message1Complete = true; else if(messagePerSecCounter == 2) message2Complete = true; messagePerSecCounter++; //count the messages per second } //how this can fail?? // 1) get noisy # occurrences (unique starting character) // 2) get noisy LF occurrences (unique ending character) // 3) get noisy data packet values or extra values // 4) we will also need to vet the data on the PC side // 5) here, we should do minimal testing and just pass the data as is };