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

Committer:
jekain314
Date:
Mon Mar 03 13:19:31 2014 +0000
Revision:
30:96d133f3008e
Parent:
29:dead10cce6e9
commit of RT_Download.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jekain314 21:37551baf69c6 1 #include "crc.h"
jekain314 21:37551baf69c6 2
jekain314 0:432b860b6ff7 3 //GPS-specific pins
jekain314 0:432b860b6ff7 4 DigitalOut GPS_Reset(p18); //GPS RESET line
jekain314 0:432b860b6ff7 5 InterruptIn PPSInt(p15); // GPS 1PPS (timemark) from the OEM615
jekain314 0:432b860b6ff7 6 InterruptIn IMUClock(p17);
jekain314 0:432b860b6ff7 7
jekain314 0:432b860b6ff7 8 Timer timeFromPPS;
jekain314 0:432b860b6ff7 9 unsigned long GPSTimemsecs = 0;
jekain314 0:432b860b6ff7 10
jekain314 0:432b860b6ff7 11 //mbed tx/rx interface to the GPS COM1 port
jekain314 0:432b860b6ff7 12 MODSERIAL GPS_COM1(p9,p10); //this serial port communicates with the GPS receiver serial port (COM1)
jekain314 0:432b860b6ff7 13
jekain314 29:dead10cce6e9 14 bool loadingMessageBuffer = false;
jekain314 29:dead10cce6e9 15
jekain314 30:96d133f3008e 16 const unsigned short maxGPSbytesPerSec = 2048;
jekain314 0:432b860b6ff7 17
jekain314 29:dead10cce6e9 18 int messagePerSecCounter = 0;
jekain314 30:96d133f3008e 19 char msgBuffer0[2048]; //array to contain one full second of GPS bytes
jekain314 30:96d133f3008e 20 char msgBuffer1[512]; //array to contain one full second of GPS bytes
jekain314 30:96d133f3008e 21 char msgBuffer2[512]; //array to contain one full second of GPS bytes
jekain314 29:dead10cce6e9 22 int GPSbyteCounter0 = 0;
jekain314 29:dead10cce6e9 23 int GPSbyteCounter1 = 0;
jekain314 29:dead10cce6e9 24 int GPSbyteCounter2 = 0;
jekain314 29:dead10cce6e9 25 bool message0Complete = false;
jekain314 29:dead10cce6e9 26 bool message1Complete = false;
jekain314 29:dead10cce6e9 27 bool message2Complete = false;
jekain314 0:432b860b6ff7 28
jekain314 30:96d133f3008e 29 ////////////////////////////////////////////////////////////
jekain314 30:96d133f3008e 30 //hotstart procedure
jekain314 30:96d133f3008e 31 ////////////////////////////////////////////////////////////
jekain314 30:96d133f3008e 32 // Novatel OEM615 startup messages:
jekain314 30:96d133f3008e 33 // setapproxtime 1605 425384 // GPSWeek & GPSSeconds
jekain314 30:96d133f3008e 34 // setapproxpos 51.116 -114.038 0 //lat, lon, alt
jekain314 30:96d133f3008e 35 ////////////////////////////////////////////////////////////
jekain314 30:96d133f3008e 36 // how to use?
jekain314 30:96d133f3008e 37 // Assumes a certain power-up sequence: WALDO_FCS must be running on the PC??
jekain314 30:96d133f3008e 38 // unlikely this start-up sequence will work!!
jekain314 30:96d133f3008e 39 // PC MAY generates a startUp message that is checked for before the GPS RX starts
jekain314 30:96d133f3008e 40 // mbed looks for the startup message for 1 sec.
jekain314 30:96d133f3008e 41 // startUp message contains: Last PCTime, lastLat, lastLon, LastAlt, LastGPSWeek, LastGPSSeconds
jekain314 30:96d133f3008e 42 // If it is found, send the startup messages to the receiver
jekain314 30:96d133f3008e 43 // if it is not found, then just start without the messages (cold start)
jekain314 30:96d133f3008e 44 // On the PC side, check for a startUp file stored within the .exe folder.
jekain314 30:96d133f3008e 45 // However, if the PC clock time between now and the lastStart is > 24 hours, ignore startup file
jekain314 30:96d133f3008e 46 // if the startUp file IS PRESENT, use it to send the startUp message
jekain314 30:96d133f3008e 47 // After reading the startUp file on the PC, always delete it.
jekain314 30:96d133f3008e 48 // Every time the system enters "FINESTEERING", save the StartUp file
jekain314 30:96d133f3008e 49
jekain314 0:432b860b6ff7 50 void sendASCII(char* ASCI_message, int numChars)
jekain314 0:432b860b6ff7 51 {
jekain314 0:432b860b6ff7 52 /////////////////////////////////////////////////
jekain314 0:432b860b6ff7 53 //send an ASCII command to the GPS receiver
jekain314 0:432b860b6ff7 54 /////////////////////////////////////////////////
jekain314 0:432b860b6ff7 55
jekain314 0:432b860b6ff7 56 //char ASCI_message[] = "unlogall COM1";
jekain314 0:432b860b6ff7 57 int as = numChars - 1;
jekain314 0:432b860b6ff7 58 unsigned char CR = 0x0d; //ASCII Carriage Return
jekain314 0:432b860b6ff7 59 unsigned char LF = 0x0a; //ASCII Line Feed
jekain314 0:432b860b6ff7 60
jekain314 0:432b860b6ff7 61 //printf("%s", ch);
jekain314 0:432b860b6ff7 62 //printf("\n");
jekain314 0:432b860b6ff7 63
jekain314 0:432b860b6ff7 64 for (int i=0; i<as; i++) GPS_COM1.putc(ASCI_message[i]);
jekain314 0:432b860b6ff7 65 GPS_COM1.putc(CR); //carriage return at end
jekain314 0:432b860b6ff7 66 GPS_COM1.putc(LF); //line feed at end
jekain314 0:432b860b6ff7 67 };
jekain314 0:432b860b6ff7 68
jekain314 0:432b860b6ff7 69
jekain314 0:432b860b6ff7 70 //see the mbed COOKBOOK for MODSERIAL
jekain314 0:432b860b6ff7 71 //MODSERIAL is an easy to use library that extends Serial to add fully buffered input and output.
jekain314 0:432b860b6ff7 72 void readSerialByte(MODSERIAL_IRQ_INFO *q)
jekain314 0:432b860b6ff7 73 {
jekain314 0:432b860b6ff7 74 MODSERIAL *serial = q->serial; //see example of MODSERIAL usage in cookbook
jekain314 0:432b860b6ff7 75 unsigned char synch0 = serial->getc(); //get the next byte
jekain314 0:432b860b6ff7 76
jekain314 29:dead10cce6e9 77 totalGPSBytes++;
jekain314 0:432b860b6ff7 78
jekain314 29:dead10cce6e9 79 //all OEM615 GPS ASCII messages begin with the unique character: "#"
jekain314 29:dead10cce6e9 80 //read til we get a "#" and then start storing the message
jekain314 29:dead10cce6e9 81 if (synch0 == '#')
jekain314 0:432b860b6ff7 82 {
jekain314 29:dead10cce6e9 83 if (messagePerSecCounter == 0) GPSbyteCounter0 = 0;
jekain314 29:dead10cce6e9 84 else if(messagePerSecCounter == 1) GPSbyteCounter1 = 0;
jekain314 29:dead10cce6e9 85 else if(messagePerSecCounter == 2) GPSbyteCounter2 = 0;
jekain314 30:96d133f3008e 86 //loadingMessageBuffer = true;
jekain314 29:dead10cce6e9 87 }
jekain314 29:dead10cce6e9 88
jekain314 30:96d133f3008e 89 if (messagePerSecCounter == 0) { msgBuffer0[GPSbyteCounter0 % 1024] = synch0; GPSbyteCounter0++; }
jekain314 30:96d133f3008e 90 else if(messagePerSecCounter == 1) { msgBuffer1[GPSbyteCounter1 % 512] = synch0; GPSbyteCounter1++; }
jekain314 30:96d133f3008e 91 else if(messagePerSecCounter == 2) { msgBuffer2[GPSbyteCounter2 % 512] = synch0; GPSbyteCounter2++; }
jekain314 29:dead10cce6e9 92
jekain314 29:dead10cce6e9 93 //stop storing the message when we get a LF
jekain314 29:dead10cce6e9 94 if (synch0 == 0x0a /* LF*/) //test for line feed
jekain314 29:dead10cce6e9 95 {
jekain314 30:96d133f3008e 96 //as further confirmation, we could test the prior byte for a CR = 0x0d;
jekain314 30:96d133f3008e 97
jekain314 30:96d133f3008e 98 if (messagePerSecCounter == 0)
jekain314 30:96d133f3008e 99 {
jekain314 30:96d133f3008e 100 if ( msgBuffer0[GPSbyteCounter0 - 2] == 0x0d) //ensure the two byte end of message
jekain314 30:96d133f3008e 101 message0Complete = true;
jekain314 30:96d133f3008e 102 }
jekain314 30:96d133f3008e 103 else if(messagePerSecCounter == 1)
jekain314 30:96d133f3008e 104 {
jekain314 30:96d133f3008e 105 if ( msgBuffer0[GPSbyteCounter0 - 2] == 0x0d) //ensure the two byte end of message
jekain314 30:96d133f3008e 106 message1Complete = true;
jekain314 30:96d133f3008e 107 }
jekain314 30:96d133f3008e 108 else if(messagePerSecCounter == 2)
jekain314 30:96d133f3008e 109 {
jekain314 30:96d133f3008e 110 if ( msgBuffer0[GPSbyteCounter0 - 2] == 0x0d) //ensure the two byte end of message
jekain314 30:96d133f3008e 111 message2Complete = true;
jekain314 30:96d133f3008e 112 }
jekain314 29:dead10cce6e9 113 messagePerSecCounter++; //count the messages per second
jekain314 29:dead10cce6e9 114 }
jekain314 29:dead10cce6e9 115
jekain314 29:dead10cce6e9 116 //how this can fail??
jekain314 29:dead10cce6e9 117 // 1) get noisy # occurrences (unique starting character)
jekain314 29:dead10cce6e9 118 // 2) get noisy LF occurrences (unique ending character)
jekain314 29:dead10cce6e9 119 // 3) get noisy data packet values or extra values
jekain314 29:dead10cce6e9 120 // 4) we will also need to vet the data on the PC side
jekain314 29:dead10cce6e9 121 // 5) here, we should do minimal testing and just pass the data as is
jekain314 29:dead10cce6e9 122
jekain314 0:432b860b6ff7 123 };
jekain314 0:432b860b6ff7 124