Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GPS_Incremental by
OEM615.h
00001 00002 #pragma pack(1) //this forces the structure to be packed on byte boundaries (with no byte filler) 00003 //set up the GPS message header in a structure to enable easy reading -- see the OEM615 manual (Table 4, page 24) 00004 struct MESSAGEHEADER 00005 { 00006 char synchAA; //1st synch word 00007 char synch44; //2nd synch word 00008 char synch12; //3rd synch word 00009 unsigned char headerLength; //always 28 00010 unsigned short messageID; //42 (BESTPOS) , 43 (RANGE) , or 99 (BESTVEL), 00011 char messageType; //always = 0 for binary 00012 unsigned char portAddress; //0x20 for COM1 00013 unsigned short messageLength; //not including header or CRC 00014 unsigned short sequence; //typically 0 00015 unsigned char idleTime; //Time the processor is idle, in the last second 00016 unsigned char timeStatus; //Enum Indicating quality of the GPS reference time 00017 unsigned short GPSweek; //GPS reference week 00018 unsigned long GPSTime_msecs; //from beginning of week 00019 unsigned long receiverStatus; //32-bits representing the status of hardware and software 00020 unsigned short reserved; 00021 unsigned short receiverSWversion; //receiver software build number 00022 }; 00023 MESSAGEHEADER *msgHeader[4]; 00024 00025 #pragma pack(1) 00026 //structure for OEM615 BESTVEL log message (page 314) 00027 struct OEM615BESTVEL 00028 { 00029 MESSAGEHEADER msgHeader; 00030 int solStatus; //solution status 00031 //solutionStatusOEMStar solStatus; //solution status 00032 int velType; //position or velocity type 00033 //velTypeOEMStar posType; //position or velocity type 00034 float latency; 00035 float age; 00036 double horizontalSpeed; //horizontal velocity vector magnitude (m/s) 00037 double heading; //deg from North called TRK GND in specification 00038 double verticalSpeed; //vertical velocity magnitude (m/s) 00039 float reserved; 00040 unsigned long CRC; 00041 }; 00042 00043 /* Solution Status descritpion from OEMV manual 00044 0 SOL_COMPUTED Solution computed 00045 1 INSUFFICIENT_OBS Insufficient observations 00046 2 NO_CONVERGENCE No convergence 00047 3 SINGULARITY Singularity at parameters matrix 00048 4 COV_TRACE Covariance trace exceeds maximum (trace > 1000 m) 00049 5 TEST_DIST Test distance exceeded (maximum of 3 rejections if distance >10 km) 00050 6 COLD_START Not yet converged from cold start 00051 7 V_H_LIMIT Height or velocity limits exceeded 00052 8 VARIANCE Variance exceeds limits 00053 9 RESIDUALS Residuals are too large 00054 10 DELTA_POS Delta position is too large 00055 11 NEGATIVE_VAR Negative variance 00056 12 Reserved 00057 13 INTEGRITY_WARNING Large residuals make position unreliable 00058 18 PENDING 00059 19 INVALID_FIX The fixed position, entered using the FIX POSITION command, is not valid 00060 20 UNAUTHORIZED Position type is unauthorized - HP or XP 00061 */ 00062 00063 #pragma pack(1) 00064 //structure for BESTPOS message 00065 struct OEM615BESTPOS 00066 { 00067 MESSAGEHEADER msgHeader; 00068 int solStatus; //solution status 00069 //solutionStatusOEMStar solStatus; //solution status 00070 int posType; //position or velocity type 00071 //posTypeOEMStar posType; //position or velocity type 00072 double latitude; //latitude 00073 double longitude; //longitude 00074 double height; //height above mean sea level 00075 float undulation; //the realtionship between the geoid and the 00076 //ellipsoid of the chosen datum (m) 00077 char datumID[4]; //datum ID is actually an enum that is not implemented 00078 float latitudeSTD; //latitude standard deviation 00079 float longitudeSTD; //longitude standard deviation 00080 float heightSTD; //height standard deviation 00081 char baseStationID[4]; //base station ID 00082 float diffAge; //differential age (s) 00083 float solutionAge; //solution age (s) 00084 unsigned char numSV; //number of satellite vehicles tracked 00085 unsigned char numSolSV; //number of satellite vehicles used in solution 00086 unsigned char numGGL1; //number of GPS plus Glonass L1 00087 unsigned char res1; 00088 unsigned char res2; 00089 unsigned char extSolStatus; //extended solution status 00090 unsigned char res3; 00091 unsigned char sigMask; //signals used mask 00092 unsigned long CRC; 00093 }; 00094 00095 //GPS-specific pins 00096 DigitalOut GPS_Reset(p18); //GPS RESET line 00097 InterruptIn PPSInt(p15); // GPS 1PPS (timemark) from the OEM615 00098 InterruptIn IMUClock(p17); 00099 00100 Timer timeFromPPS; 00101 unsigned long GPSTimemsecs = 0; 00102 double GPSTime = 0; 00103 int PPSTimeOffset = 0; 00104 00105 //mbed tx/rx interface to the GPS COM1 port 00106 MODSERIAL GPS_COM1(p9,p10); //this serial port communicates with the GPS receiver serial port (COM1) 00107 00108 int test = 0; 00109 unsigned short messageCounter = 0; 00110 unsigned short savedMessageCounter = 0; 00111 const unsigned short maxGPSbytesPerSec = 1536; 00112 unsigned char msgBuffer[maxGPSbytesPerSec]; //array to contain one full second of GPS bytes 00113 const unsigned char maxGPSMessagesPerSec = 12; 00114 unsigned short messageLocation[maxGPSMessagesPerSec] = {0}; //stores the message location start within the message buffer 00115 00116 //this code was taken from the Novatel Firmware document page 35 00117 #define CRC32_POLYNOMIAL 0xEDB88320L 00118 /* -------------------------------------------------------------------------- 00119 Calculate a CRC value to be used by CRC calculation functions. 00120 -------------------------------------------------------------------------- */ 00121 unsigned long CRC32Value(int i) 00122 { 00123 int j; 00124 unsigned long ulCRC; 00125 ulCRC = i; 00126 for ( j = 8 ; j > 0; j-- ) 00127 { 00128 if ( ulCRC & 1 ) 00129 ulCRC = ( ulCRC >> 1 ) ^ CRC32_POLYNOMIAL; 00130 else 00131 ulCRC >>= 1; 00132 } 00133 return ulCRC; 00134 } 00135 00136 /* -------------------------------------------------------------------------- 00137 Calculates the CRC-32 of a block of data all at once 00138 //the CRC is c from the complete message (header plus data) but excluding (of course) the CRC at the end 00139 -------------------------------------------------------------------------- */ 00140 unsigned long CalculateBlockCRC32( 00141 unsigned long ulCount, /* Number of bytes in the data block */ 00142 unsigned char *ucBuffer ) /* Data block */ 00143 { 00144 unsigned long ulTemp1; 00145 unsigned long ulTemp2; 00146 unsigned long ulCRC = 0; 00147 while ( ulCount-- != 0 ) 00148 { 00149 ulTemp1 = ( ulCRC >> 8 ) & 0x00FFFFFFL; 00150 ulTemp2 = CRC32Value( ((int) ulCRC ^ *ucBuffer++ ) & 0xff ); 00151 ulCRC = ulTemp1 ^ ulTemp2; 00152 } 00153 return( ulCRC ); 00154 } 00155 00156 00157 void sendASCII(char* ASCI_message, int numChars) 00158 { 00159 ///////////////////////////////////////////////// 00160 //send an ASCII command to the GPS receiver 00161 ///////////////////////////////////////////////// 00162 00163 //char ASCI_message[] = "unlogall COM1"; 00164 int as = numChars - 1; 00165 unsigned char CR = 0x0d; //ASCII Carriage Return 00166 unsigned char LF = 0x0a; //ASCII Line Feed 00167 00168 //printf("%s", ch); 00169 //printf("\n"); 00170 00171 for (int i=0; i<as; i++) GPS_COM1.putc(ASCI_message[i]); 00172 GPS_COM1.putc(CR); //carriage return at end 00173 GPS_COM1.putc(LF); //line feed at end 00174 }; 00175 00176 00177 //see the mbed COOKBOOK for MODSERIAL 00178 //MODSERIAL is an easy to use library that extends Serial to add fully buffered input and output. 00179 void readSerialByte(MODSERIAL_IRQ_INFO *q) 00180 { 00181 MODSERIAL *serial = q->serial; 00182 unsigned char synch0 = serial->getc(); 00183 msgBuffer[byteCounter % maxGPSbytesPerSec] = synch0; 00184 00185 //we need to trap the GPS message header byte-string 0xAA44121C 00186 //generate a 4-byte sliding-window sequence from the input bytes 00187 //shift last 4-byte value left 8 bits & push recently read byte (synch0) into low-order byte 00188 test = (test<<8) | synch0; // 00189 00190 if (test == 0xAA44121C) //test for the Receiver message header signature 00191 { 00192 messageLocation[perSecMessageCounter % maxGPSMessagesPerSec] = byteCounter-3; //store the location of this message (with 4 synch words) 00193 perSecMessageCounter++; 00194 messageDetected = true; 00195 } 00196 //byteCounter reset to zero in main after the 1PPS is detected -- its NOT reset in the 1PPS ISR 00197 byteCounter++; //total per-sec byte counter (reset to zero in main when 1PPS detected) 00198 00199 }; 00200 00201 00202 00203 00204 00205 00206
Generated on Wed Jul 13 2022 09:36:22 by
1.7.2
