[206] | 1 | //------------------------------------------------------------------------------
|
---|
| 2 | //
|
---|
| 3 | // RTCM2.cpp
|
---|
| 4 | //
|
---|
| 5 | // Purpose:
|
---|
| 6 | //
|
---|
| 7 | // Module for extraction of RTCM2 messages
|
---|
| 8 | //
|
---|
[254] | 9 | // References:
|
---|
| 10 | //
|
---|
| 11 | // RTCM 10402.3 Recommended Standards for Differential GNSS (Global
|
---|
| 12 | // Navigation Satellite Systems) Service; RTCM Paper 136-2001/SC104-STD,
|
---|
| 13 | // Version 2.3, 20 Aug. 2001; Radio Technical Commission For Maritime
|
---|
| 14 | // Services, Alexandria, Virgina (2001).
|
---|
| 15 | // ICD-GPS-200; Navstar GPS Space Segment / Navigation User Interfaces;
|
---|
| 16 | // Revison C; 25 Sept. 1997; Arinc Research Corp., El Segundo (1997).
|
---|
| 17 | // Jensen M.; RTCM2ASC Documentation;
|
---|
| 18 | // URL http://kom.aau.dk/~borre/masters/receiver/rtcm2asc.htm;
|
---|
| 19 | // last accessed 17 Sep. 2006
|
---|
| 20 | // Sager J.; Decoder for RTCM SC-104 data from a DGPS beacon receiver;
|
---|
| 21 | // URL http://www.wsrcc.com/wolfgang/ftp/rtcm-0.3.tar.gz;
|
---|
| 22 | // last accessed 17 Sep. 2006
|
---|
| 23 | //
|
---|
[206] | 24 | // Notes:
|
---|
| 25 | //
|
---|
| 26 | // - The host computer is assumed to use little endian (Intel) byte order
|
---|
| 27 | //
|
---|
| 28 | // Last modified:
|
---|
| 29 | //
|
---|
| 30 | // 2006/09/17 OMO Created
|
---|
| 31 | // 2006/09/19 OMO Fixed getHeader() methods
|
---|
| 32 | // 2006/09/21 OMO Reduced phase ambiguity to 2^23 cycles
|
---|
[242] | 33 | // 2006/10/05 OMO Specified const'ness of various member functions
|
---|
| 34 | // 2006/10/13 LMV Fixed resolvedPhase to handle missing C1 range
|
---|
[253] | 35 | // 2006/10/14 LMV Fixed loop cunter in ThirtyBitWord
|
---|
| 36 | // 2006/10/14 LMV Exception handling
|
---|
| 37 | // 2006/10/17 OMO Removed obsolete check of multiple message indicator
|
---|
[254] | 38 | // 2006/10/17 OMO Fixed parity handling
|
---|
[206] | 39 | //
|
---|
| 40 | // (c) DLR/GSOC
|
---|
| 41 | //
|
---|
| 42 | //------------------------------------------------------------------------------
|
---|
| 43 |
|
---|
[254] | 44 | #include <bitset>
|
---|
[206] | 45 | #include <cmath>
|
---|
| 46 | #include <fstream>
|
---|
| 47 | #include <iomanip>
|
---|
| 48 | #include <iostream>
|
---|
| 49 | #include <string>
|
---|
| 50 | #include <vector>
|
---|
| 51 |
|
---|
| 52 | #include "RTCM2.h"
|
---|
| 53 |
|
---|
[254] | 54 | // Activate (1) or deactivate (0) debug output for tracing parity errors and
|
---|
| 55 | // undersized packets in get(Unsigned)Bits
|
---|
[242] | 56 |
|
---|
[254] | 57 | #define DEBUG 0
|
---|
| 58 |
|
---|
[206] | 59 | using namespace std;
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | // GPS constants
|
---|
| 63 |
|
---|
| 64 | const double c_light = 299792458.0; // Speed of light [m/s]; IAU 1976
|
---|
| 65 | const double f_L1 = 1575.42e6; // L1 frequency [Hz] (10.23MHz*154)
|
---|
| 66 | const double f_L2 = 1227.60e6; // L2 frequency [Hz] (10.23MHz*120)
|
---|
| 67 |
|
---|
| 68 | const double lambda_L1 = c_light/f_L1; // L1 wavelength [m] (0.1903m)
|
---|
| 69 | const double lambda_L2 = c_light/f_L2; // L2 wavelength [m]
|
---|
| 70 |
|
---|
| 71 | //
|
---|
| 72 | // Bits for message availability checks
|
---|
| 73 | //
|
---|
| 74 |
|
---|
| 75 | const int bit_L1rngGPS = 0;
|
---|
| 76 | const int bit_L2rngGPS = 1;
|
---|
| 77 | const int bit_L1cphGPS = 2;
|
---|
| 78 | const int bit_L2cphGPS = 3;
|
---|
| 79 | const int bit_L1rngGLO = 4;
|
---|
| 80 | const int bit_L2rngGLO = 5;
|
---|
| 81 | const int bit_L1cphGLO = 6;
|
---|
| 82 | const int bit_L2cphGLO = 7;
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | //
|
---|
| 86 | // namespace rtcm2
|
---|
| 87 | //
|
---|
| 88 |
|
---|
| 89 | namespace rtcm2 {
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | //------------------------------------------------------------------------------
|
---|
| 93 | //
|
---|
| 94 | // class ThirtyBitWord (implementation)
|
---|
| 95 | //
|
---|
| 96 | // Purpose:
|
---|
| 97 | //
|
---|
| 98 | // Handling of RTCM2 30bit words
|
---|
| 99 | //
|
---|
| 100 | //------------------------------------------------------------------------------
|
---|
| 101 |
|
---|
| 102 | // Constructor
|
---|
| 103 |
|
---|
| 104 | ThirtyBitWord::ThirtyBitWord() : W(0) {
|
---|
| 105 | };
|
---|
| 106 |
|
---|
| 107 | // Clear entire 30-bit word and 2-bit parity from previous word
|
---|
| 108 |
|
---|
| 109 | void ThirtyBitWord::clear() {
|
---|
| 110 | W = 0;
|
---|
| 111 | };
|
---|
| 112 |
|
---|
| 113 | // Failure indicator for input operations
|
---|
| 114 |
|
---|
| 115 | bool ThirtyBitWord::fail() const {
|
---|
| 116 | return failure;
|
---|
| 117 | };
|
---|
| 118 |
|
---|
| 119 | // Parity check
|
---|
| 120 |
|
---|
| 121 | bool ThirtyBitWord::validParity() const {
|
---|
| 122 |
|
---|
| 123 | // Parity stuff
|
---|
| 124 |
|
---|
| 125 | static const unsigned int PARITY_25 = 0xBB1F3480;
|
---|
| 126 | static const unsigned int PARITY_26 = 0x5D8F9A40;
|
---|
| 127 | static const unsigned int PARITY_27 = 0xAEC7CD00;
|
---|
| 128 | static const unsigned int PARITY_28 = 0x5763E680;
|
---|
| 129 | static const unsigned int PARITY_29 = 0x6BB1F340;
|
---|
| 130 | static const unsigned int PARITY_30 = 0x8B7A89C0;
|
---|
| 131 |
|
---|
| 132 | // Look-up table for parity of eight bit bytes
|
---|
| 133 | // (parity=0 if the number of 0s and 1s is equal, else parity=1)
|
---|
| 134 | static unsigned char byteParity[] = {
|
---|
| 135 | 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
|
---|
| 136 | 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
|
---|
| 137 | 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
|
---|
| 138 | 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
|
---|
| 139 | 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
|
---|
| 140 | 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
|
---|
| 141 | 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
|
---|
| 142 | 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0
|
---|
| 143 | };
|
---|
| 144 |
|
---|
| 145 | // Local variables
|
---|
| 146 |
|
---|
| 147 | unsigned int t, w, p;
|
---|
| 148 |
|
---|
| 149 | // The sign of the data is determined by the D30* parity bit
|
---|
| 150 | // of the previous data word. If D30* is set, invert the data
|
---|
| 151 | // bits D01..D24 to obtain the d01..d24 (but leave all other
|
---|
| 152 | // bits untouched).
|
---|
| 153 |
|
---|
| 154 | w = W;
|
---|
| 155 | if ( w & 0x40000000 ) w ^= 0x3FFFFFC0;
|
---|
| 156 |
|
---|
| 157 | // Compute the parity of the sign corrected data bits d01..d24
|
---|
| 158 | // as described in the ICD-GPS-200
|
---|
| 159 |
|
---|
| 160 | t = w & PARITY_25;
|
---|
| 161 | p = ( byteParity[t &0xff] ^ byteParity[(t>> 8)&0xff] ^
|
---|
| 162 | byteParity[(t>>16)&0xff] ^ byteParity[(t>>24) ] );
|
---|
| 163 |
|
---|
| 164 | t = w & PARITY_26;
|
---|
| 165 | p = (p<<1) |
|
---|
| 166 | ( byteParity[t &0xff] ^ byteParity[(t>> 8)&0xff] ^
|
---|
| 167 | byteParity[(t>>16)&0xff] ^ byteParity[(t>>24) ] );
|
---|
| 168 |
|
---|
| 169 | t = w & PARITY_27;
|
---|
| 170 | p = (p<<1) |
|
---|
| 171 | ( byteParity[t &0xff] ^ byteParity[(t>> 8)&0xff] ^
|
---|
| 172 | byteParity[(t>>16)&0xff] ^ byteParity[(t>>24) ] );
|
---|
| 173 |
|
---|
| 174 | t = w & PARITY_28;
|
---|
| 175 | p = (p<<1) |
|
---|
| 176 | ( byteParity[t &0xff] ^ byteParity[(t>> 8)&0xff] ^
|
---|
| 177 | byteParity[(t>>16)&0xff] ^ byteParity[(t>>24) ] );
|
---|
| 178 |
|
---|
| 179 | t = w & PARITY_29;
|
---|
| 180 | p = (p<<1) |
|
---|
| 181 | ( byteParity[t &0xff] ^ byteParity[(t>> 8)&0xff] ^
|
---|
| 182 | byteParity[(t>>16)&0xff] ^ byteParity[(t>>24) ] );
|
---|
| 183 |
|
---|
| 184 | t = w & PARITY_30;
|
---|
| 185 | p = (p<<1) |
|
---|
| 186 | ( byteParity[t &0xff] ^ byteParity[(t>> 8)&0xff] ^
|
---|
| 187 | byteParity[(t>>16)&0xff] ^ byteParity[(t>>24) ] );
|
---|
| 188 |
|
---|
[254] | 189 | return ( (W & 0x3f) == p);
|
---|
[206] | 190 |
|
---|
| 191 | };
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | // Check preamble
|
---|
| 195 |
|
---|
| 196 | bool ThirtyBitWord::isHeader() const {
|
---|
| 197 |
|
---|
| 198 | const unsigned char Preamble = 0x66;
|
---|
| 199 |
|
---|
| 200 | unsigned char b = (value()>>22) & 0xFF;
|
---|
| 201 |
|
---|
| 202 | return ( b==Preamble );
|
---|
| 203 |
|
---|
| 204 | };
|
---|
| 205 |
|
---|
| 206 |
|
---|
| 207 | // Return entire 32-bit (current word and previous parity)
|
---|
| 208 |
|
---|
| 209 | unsigned int ThirtyBitWord::all() const {
|
---|
| 210 | return W;
|
---|
| 211 | };
|
---|
| 212 |
|
---|
| 213 |
|
---|
| 214 | // Return sign-corrected 30-bit (or zero if parity mismatch)
|
---|
| 215 |
|
---|
| 216 | unsigned int ThirtyBitWord::value() const {
|
---|
| 217 |
|
---|
| 218 | unsigned int w = W;
|
---|
| 219 |
|
---|
| 220 | if (validParity()) {
|
---|
| 221 | // Return data and current parity bits. Invert data bits if D30*
|
---|
| 222 | // is set and discard old parity bits.
|
---|
| 223 | if ( w & 0x40000000 ) w ^= 0x3FFFFFC0;
|
---|
| 224 | return (w & 0x3FFFFFFF);
|
---|
| 225 | }
|
---|
| 226 | else {
|
---|
| 227 | // Error; invalid parity
|
---|
| 228 | return 0;
|
---|
| 229 | };
|
---|
| 230 |
|
---|
| 231 | };
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 |
|
---|
| 235 | // Append a byte with six data bits
|
---|
| 236 |
|
---|
| 237 | void ThirtyBitWord::append(unsigned char b) {
|
---|
| 238 |
|
---|
| 239 | // Look up table for swap (left-right) of 6 data bits
|
---|
| 240 | static const unsigned char
|
---|
| 241 | swap[] = {
|
---|
| 242 | 0,32,16,48, 8,40,24,56, 4,36,20,52,12,44,28,60,
|
---|
| 243 | 2,34,18,50,10,42,26,58, 6,38,22,54,14,46,30,62,
|
---|
| 244 | 1,33,17,49, 9,41,25,57, 5,37,21,53,13,45,29,61,
|
---|
| 245 | 3,35,19,51,11,43,27,59, 7,39,23,55,15,47,31,63
|
---|
| 246 | };
|
---|
| 247 |
|
---|
| 248 | // Bits 7 and 6 (of 0..7) must be "01" for valid data bytes
|
---|
| 249 | if ( (b & 0x40) != 0x40 ) {
|
---|
| 250 | failure = true;
|
---|
| 251 | return;
|
---|
| 252 | };
|
---|
| 253 |
|
---|
| 254 | // Swap bits 0..5 to restore proper bit order for 30bit words
|
---|
| 255 | b = swap[ b & 0x3f];
|
---|
| 256 |
|
---|
| 257 | // Fill word
|
---|
| 258 | W = ( (W <<6) | (b & 0x3f) ) ;
|
---|
| 259 |
|
---|
| 260 | };
|
---|
| 261 |
|
---|
| 262 |
|
---|
| 263 | // Get next 30bit word from string
|
---|
| 264 |
|
---|
| 265 | void ThirtyBitWord::get(string& buf) {
|
---|
| 266 |
|
---|
| 267 | // Check if string is long enough
|
---|
| 268 |
|
---|
| 269 | if (buf.size()<5) {
|
---|
| 270 | failure = true;
|
---|
| 271 | return;
|
---|
| 272 | };
|
---|
| 273 |
|
---|
| 274 | // Process 5 bytes and remove them from the input
|
---|
| 275 |
|
---|
| 276 | for (int i=0; i<5; i++) append(buf[i]);
|
---|
| 277 | buf.erase(0,5);
|
---|
| 278 |
|
---|
[254] | 279 | #if (DEBUG>0)
|
---|
| 280 | if (!validParity()) {
|
---|
| 281 | cout << "Parity error "
|
---|
| 282 | << bitset<32>(all()) << endl;
|
---|
| 283 | };
|
---|
| 284 | #endif
|
---|
[206] | 285 | failure = false;
|
---|
| 286 |
|
---|
| 287 | };
|
---|
| 288 |
|
---|
| 289 | // Get next 30bit word from file
|
---|
| 290 |
|
---|
| 291 | void ThirtyBitWord::get(istream& inp) {
|
---|
| 292 |
|
---|
| 293 | unsigned char b;
|
---|
| 294 |
|
---|
| 295 | for (int i=0; i<5; i++) {
|
---|
| 296 | inp >> b;
|
---|
| 297 | if (inp.fail()) { clear(); return; };
|
---|
| 298 | append(b);
|
---|
| 299 | };
|
---|
| 300 |
|
---|
[254] | 301 | #if (DEBUG>0)
|
---|
| 302 | if (!validParity()) {
|
---|
| 303 | cout << "Parity error "
|
---|
| 304 | << bitset<32>(all()) << endl;
|
---|
| 305 | };
|
---|
| 306 | #endif
|
---|
[206] | 307 | failure = false;
|
---|
| 308 |
|
---|
| 309 | };
|
---|
| 310 |
|
---|
| 311 | // Get next header word from string
|
---|
| 312 |
|
---|
| 313 | void ThirtyBitWord::getHeader(string& buf) {
|
---|
| 314 |
|
---|
| 315 | unsigned int W_old = W;
|
---|
| 316 | unsigned int i;
|
---|
| 317 |
|
---|
| 318 | i=0;
|
---|
| 319 | while (!isHeader() || i<5 ) {
|
---|
| 320 | // Check if string is long enough; if not restore old word and exit
|
---|
[248] | 321 | if (buf.size()<i+1) {
|
---|
[206] | 322 | W = W_old;
|
---|
| 323 | failure = true;
|
---|
| 324 | return;
|
---|
| 325 | };
|
---|
| 326 | // Process byte
|
---|
| 327 | append(buf[i]); i++;
|
---|
| 328 | };
|
---|
| 329 |
|
---|
| 330 | // Remove processed bytes from buffer
|
---|
| 331 |
|
---|
| 332 | buf.erase(0,i);
|
---|
| 333 |
|
---|
[254] | 334 | #if (DEBUG>0)
|
---|
| 335 | if (!validParity()) {
|
---|
| 336 | cout << "Parity error "
|
---|
| 337 | << bitset<32>(all()) << endl;
|
---|
| 338 | };
|
---|
| 339 | #endif
|
---|
[206] | 340 | failure = false;
|
---|
| 341 |
|
---|
| 342 | };
|
---|
| 343 |
|
---|
| 344 | // Get next header word from file
|
---|
| 345 |
|
---|
| 346 | void ThirtyBitWord::getHeader(istream& inp) {
|
---|
| 347 |
|
---|
| 348 | unsigned char b;
|
---|
| 349 | unsigned int i;
|
---|
| 350 |
|
---|
| 351 | i=0;
|
---|
| 352 | while ( !isHeader() || i<5 ) {
|
---|
| 353 | inp >> b;
|
---|
| 354 | if (inp.fail()) { clear(); return; };
|
---|
| 355 | append(b); i++;
|
---|
| 356 | };
|
---|
| 357 |
|
---|
[254] | 358 | #if (DEBUG>0)
|
---|
| 359 | if (!validParity()) {
|
---|
| 360 | cout << "Parity error "
|
---|
| 361 | << bitset<32>(all()) << endl;
|
---|
| 362 | };
|
---|
| 363 | #endif
|
---|
[206] | 364 | failure = false;
|
---|
| 365 |
|
---|
| 366 | };
|
---|
| 367 |
|
---|
| 368 |
|
---|
| 369 | //------------------------------------------------------------------------------
|
---|
| 370 | //
|
---|
| 371 | // RTCM2packet (class implementation)
|
---|
| 372 | //
|
---|
| 373 | // Purpose:
|
---|
| 374 | //
|
---|
| 375 | // A class for handling RTCM2 data packets
|
---|
| 376 | //
|
---|
| 377 | //------------------------------------------------------------------------------
|
---|
| 378 |
|
---|
| 379 | // Constructor
|
---|
| 380 |
|
---|
| 381 | RTCM2packet::RTCM2packet() {
|
---|
| 382 | clear();
|
---|
| 383 | };
|
---|
| 384 |
|
---|
| 385 | // Initialization
|
---|
| 386 |
|
---|
| 387 | void RTCM2packet::clear() {
|
---|
| 388 |
|
---|
| 389 | W.clear();
|
---|
| 390 |
|
---|
| 391 | H1=0;
|
---|
| 392 | H2=0;
|
---|
| 393 |
|
---|
| 394 | DW.resize(0,0);
|
---|
| 395 |
|
---|
| 396 | };
|
---|
| 397 |
|
---|
| 398 | // Complete packet, valid parity
|
---|
| 399 |
|
---|
| 400 | bool RTCM2packet::valid() const {
|
---|
| 401 |
|
---|
| 402 | // The methods for creating a packet (get,">>") ensure
|
---|
| 403 | // that a packet has a consistent number of data words
|
---|
| 404 | // and a valid parity in all header and data words.
|
---|
| 405 | // Therefore a packet is either empty or valid.
|
---|
| 406 |
|
---|
| 407 | return (H1!=0);
|
---|
| 408 |
|
---|
| 409 | };
|
---|
| 410 |
|
---|
| 411 |
|
---|
| 412 | //
|
---|
| 413 | // Gets the next packet from the buffer
|
---|
| 414 | //
|
---|
| 415 |
|
---|
| 416 | void RTCM2packet::getPacket(std::string& buf) {
|
---|
| 417 |
|
---|
| 418 | int n;
|
---|
| 419 | ThirtyBitWord W_old = W;
|
---|
| 420 | string buf_old = buf;
|
---|
| 421 |
|
---|
| 422 | // Try to read a full packet. If the input buffer is too short
|
---|
| 423 | // clear all data and restore the latest 30-bit word prior to
|
---|
| 424 | // the getPacket call. The empty header word will indicate
|
---|
| 425 | // an invalid message, which signals an unsuccessful getPacket()
|
---|
| 426 | // call.
|
---|
| 427 |
|
---|
| 428 | W.getHeader(buf);
|
---|
| 429 | H1 = W.value();
|
---|
[254] | 430 | if (W.fail()) { clear(); W=W_old; buf=buf_old; return; };
|
---|
| 431 | if (!W.validParity()) { clear(); return; };
|
---|
[206] | 432 |
|
---|
| 433 | W.get(buf);
|
---|
| 434 | H2 = W.value();
|
---|
[254] | 435 | if (W.fail()) { clear(); W=W_old; buf=buf_old; return; };
|
---|
| 436 | if (!W.validParity()) { clear(); return; };
|
---|
[206] | 437 |
|
---|
| 438 | n = nDataWords();
|
---|
| 439 | DW.resize(n);
|
---|
| 440 | for (int i=0; i<n; i++) {
|
---|
| 441 | W.get(buf);
|
---|
| 442 | DW[i] = W.value();
|
---|
[254] | 443 | if (W.fail()) { clear(); W=W_old; buf=buf_old; return; };
|
---|
| 444 | if (!W.validParity()) { clear(); return; };
|
---|
[206] | 445 | };
|
---|
| 446 |
|
---|
| 447 | return;
|
---|
| 448 |
|
---|
| 449 | };
|
---|
| 450 |
|
---|
| 451 |
|
---|
| 452 | //
|
---|
| 453 | // Gets the next packet from the input stream
|
---|
| 454 | //
|
---|
| 455 |
|
---|
| 456 | void RTCM2packet::getPacket(std::istream& inp) {
|
---|
| 457 |
|
---|
| 458 | int n;
|
---|
| 459 |
|
---|
| 460 | W.getHeader(inp);
|
---|
| 461 | H1 = W.value();
|
---|
[254] | 462 | if (W.fail() || !W.validParity()) { clear(); return; }
|
---|
[206] | 463 |
|
---|
| 464 | W.get(inp);
|
---|
| 465 | H2 = W.value();
|
---|
[254] | 466 | if (W.fail() || !W.validParity()) { clear(); return; }
|
---|
[206] | 467 |
|
---|
| 468 | n = nDataWords();
|
---|
| 469 | DW.resize(n);
|
---|
| 470 | for (int i=0; i<n; i++) {
|
---|
| 471 | W.get(inp);
|
---|
| 472 | DW[i] = W.value();
|
---|
[254] | 473 | if (W.fail() || !W.validParity()) { clear(); return; }
|
---|
[206] | 474 | };
|
---|
| 475 |
|
---|
| 476 | return;
|
---|
| 477 |
|
---|
| 478 | };
|
---|
| 479 |
|
---|
| 480 | //
|
---|
| 481 | // Input operator
|
---|
| 482 | //
|
---|
[254] | 483 | // Reads an RTCM2 packet from the input stream.
|
---|
[206] | 484 | //
|
---|
| 485 |
|
---|
| 486 | istream& operator >> (istream& is, RTCM2packet& p) {
|
---|
| 487 |
|
---|
| 488 | p.getPacket(is);
|
---|
| 489 |
|
---|
| 490 | return is;
|
---|
| 491 |
|
---|
| 492 | };
|
---|
| 493 |
|
---|
| 494 | // Access methods
|
---|
| 495 |
|
---|
| 496 | unsigned int RTCM2packet::header1() const {
|
---|
| 497 | return H1;
|
---|
| 498 | };
|
---|
| 499 |
|
---|
| 500 | unsigned int RTCM2packet::header2() const {
|
---|
| 501 | return H2;
|
---|
| 502 | };
|
---|
| 503 |
|
---|
| 504 | unsigned int RTCM2packet::dataWord(int i) const {
|
---|
| 505 | if ( (unsigned int)i < DW.size() ) {
|
---|
| 506 | return DW[i];
|
---|
| 507 | }
|
---|
| 508 | else {
|
---|
| 509 | return 0;
|
---|
| 510 | }
|
---|
| 511 | };
|
---|
| 512 |
|
---|
| 513 | unsigned int RTCM2packet::msgType() const {
|
---|
| 514 | return ( H1>>16 & 0x003F );
|
---|
| 515 | };
|
---|
| 516 |
|
---|
| 517 | unsigned int RTCM2packet::stationID() const {
|
---|
| 518 | return ( H1>> 6 & 0x03FF );
|
---|
| 519 | };
|
---|
| 520 |
|
---|
| 521 | unsigned int RTCM2packet::modZCount() const {
|
---|
| 522 | return ( H2>>17 & 0x01FFF );
|
---|
| 523 | };
|
---|
| 524 |
|
---|
| 525 | unsigned int RTCM2packet::seqNumber() const {
|
---|
| 526 | return ( H2>>14 & 0x0007 );
|
---|
| 527 | };
|
---|
| 528 |
|
---|
| 529 | unsigned int RTCM2packet::nDataWords() const {
|
---|
| 530 | return ( H2>> 9 & 0x001F );
|
---|
| 531 | };
|
---|
| 532 |
|
---|
| 533 | unsigned int RTCM2packet::staHealth() const {
|
---|
| 534 | return ( H2>> 6 & 0x0003 );
|
---|
| 535 | };
|
---|
| 536 |
|
---|
| 537 |
|
---|
| 538 | //
|
---|
| 539 | // Get unsigned bit field
|
---|
| 540 | //
|
---|
| 541 | // Bits are numbered from left (msb) to right (lsb) starting at bit 0
|
---|
| 542 | //
|
---|
| 543 |
|
---|
| 544 | unsigned int RTCM2packet::getUnsignedBits ( unsigned int start,
|
---|
| 545 | unsigned int n ) const {
|
---|
| 546 |
|
---|
| 547 | unsigned int iFirst = start/24; // Index of first data word
|
---|
| 548 | unsigned int iLast = (start+n-1)/24; // Index of last data word
|
---|
| 549 | unsigned int bitField = 0;
|
---|
| 550 | unsigned int tmp;
|
---|
| 551 |
|
---|
| 552 | // Checks
|
---|
| 553 |
|
---|
| 554 | if (n>32) {
|
---|
[249] | 555 | throw("Error: can't handle >32 bits in RTCM2packet::getUnsignedBits");
|
---|
[206] | 556 | };
|
---|
| 557 |
|
---|
| 558 | if ( 24*DW.size() < start+n-1 ) {
|
---|
[254] | 559 | #if (DEBUG>0)
|
---|
| 560 | cerr << "Debug output RTCM2packet::getUnsignedBits" << endl
|
---|
| 561 | << " P.msgType: " << setw(5) << msgType() << endl
|
---|
| 562 | << " P.nDataWords: " << setw(5) << nDataWords() << endl
|
---|
| 563 | << " start: " << setw(5) << start << endl
|
---|
| 564 | << " n: " << setw(5) << n << endl
|
---|
| 565 | << " P.H1: " << setw(5) << bitset<32>(H1) << endl
|
---|
| 566 | << " P.H2: " << setw(5) << bitset<32>(H2) << endl
|
---|
| 567 | << endl
|
---|
| 568 | << flush;
|
---|
| 569 | #endif
|
---|
[249] | 570 | throw("Error: Packet too short in RTCM2packet::getUnsignedBits");
|
---|
[206] | 571 | }
|
---|
| 572 |
|
---|
| 573 | // Handle initial data word
|
---|
| 574 | // Get all data bits. Strip parity and unwanted leading bits.
|
---|
| 575 | // Store result in 24 lsb bits of tmp.
|
---|
| 576 |
|
---|
| 577 | tmp = (DW[iFirst]>>6) & 0xFFFFFF;
|
---|
| 578 | tmp = ( ( tmp << start%24) & 0xFFFFFF ) >> start%24 ;
|
---|
| 579 |
|
---|
| 580 | // Handle central data word
|
---|
| 581 |
|
---|
| 582 | if ( iFirst<iLast ) {
|
---|
| 583 | bitField = tmp;
|
---|
| 584 | for (unsigned int iWord=iFirst+1; iWord<iLast; iWord++) {
|
---|
| 585 | tmp = (DW[iWord]>>6) & 0xFFFFFF;
|
---|
| 586 | bitField = (bitField << 24) | tmp;
|
---|
| 587 | };
|
---|
| 588 | tmp = (DW[iLast]>>6) & 0xFFFFFF;
|
---|
| 589 | };
|
---|
| 590 |
|
---|
| 591 | // Handle last data word
|
---|
| 592 |
|
---|
| 593 | tmp = tmp >> (23-(start+n-1)%24);
|
---|
| 594 | bitField = (bitField << ((start+n-1)%24+1)) | tmp;
|
---|
| 595 |
|
---|
| 596 | // Done
|
---|
| 597 |
|
---|
| 598 | return bitField;
|
---|
| 599 |
|
---|
| 600 | };
|
---|
| 601 |
|
---|
| 602 | //
|
---|
| 603 | // Get signed bit field
|
---|
| 604 | //
|
---|
| 605 | // Bits are numbered from left (msb) to right (lsb) starting at bit 0
|
---|
| 606 | //
|
---|
| 607 |
|
---|
| 608 | int RTCM2packet::getBits ( unsigned int start,
|
---|
| 609 | unsigned int n ) const {
|
---|
| 610 |
|
---|
| 611 |
|
---|
| 612 | // Checks
|
---|
| 613 |
|
---|
| 614 | if (n>32) {
|
---|
[249] | 615 | throw("Error: can't handle >32 bits in RTCM2packet::getBits");
|
---|
[206] | 616 | };
|
---|
| 617 |
|
---|
| 618 | if ( 24*DW.size() < start+n-1 ) {
|
---|
[254] | 619 | #if (DEBUG>0)
|
---|
| 620 | cerr << "Debug output RTCM2packet::getUnsignedBits" << endl
|
---|
| 621 | << " P.msgType: " << setw(5) << msgType() << endl
|
---|
| 622 | << " P.nDataWords: " << setw(5) << nDataWords() << endl
|
---|
| 623 | << " start: " << setw(5) << start << endl
|
---|
| 624 | << " n: " << setw(5) << n << endl
|
---|
| 625 | << " P.H1: " << setw(5) << bitset<32>(H1) << endl
|
---|
| 626 | << " P.H2: " << setw(5) << bitset<32>(H2) << endl
|
---|
| 627 | << endl
|
---|
| 628 | << flush;
|
---|
| 629 | #endif
|
---|
[249] | 630 | throw("Error: Packet too short in RTCM2packet::getBits");
|
---|
[206] | 631 | }
|
---|
| 632 |
|
---|
| 633 | return ((int)(getUnsignedBits(start,n)<<(32-n))>>(32-n));
|
---|
| 634 |
|
---|
| 635 | };
|
---|
| 636 |
|
---|
| 637 |
|
---|
| 638 | //------------------------------------------------------------------------------
|
---|
| 639 | //
|
---|
| 640 | // RTCM2_03 (class implementation)
|
---|
| 641 | //
|
---|
| 642 | // Purpose:
|
---|
| 643 | //
|
---|
| 644 | // A class for handling RTCM 2 GPS Reference Station Parameters messages
|
---|
| 645 | //
|
---|
| 646 | //------------------------------------------------------------------------------
|
---|
| 647 |
|
---|
| 648 | void RTCM2_03::extract(const RTCM2packet& P) {
|
---|
| 649 |
|
---|
| 650 | // Check validity and packet type
|
---|
| 651 |
|
---|
| 652 | validMsg = (P.valid());
|
---|
| 653 | if (!validMsg) return;
|
---|
| 654 |
|
---|
| 655 | validMsg = (P.ID()==03);
|
---|
| 656 | if (!validMsg) return;
|
---|
| 657 |
|
---|
| 658 | // Antenna reference point coordinates
|
---|
| 659 |
|
---|
| 660 | x = P.getBits( 0,32)*0.01; // X [m]
|
---|
| 661 | y = P.getBits(32,32)*0.01; // Y [m]
|
---|
| 662 | z = P.getBits(64,32)*0.01; // Z [m]
|
---|
| 663 |
|
---|
| 664 | };
|
---|
| 665 |
|
---|
| 666 | //------------------------------------------------------------------------------
|
---|
| 667 | //
|
---|
| 668 | // RTCM2_23 (class implementation)
|
---|
| 669 | //
|
---|
| 670 | // Purpose:
|
---|
| 671 | //
|
---|
| 672 | // A class for handling RTCM 2 Antenna Type Definition messages
|
---|
| 673 | //
|
---|
| 674 | //------------------------------------------------------------------------------
|
---|
| 675 |
|
---|
| 676 | void RTCM2_23::extract(const RTCM2packet& P) {
|
---|
| 677 |
|
---|
| 678 | int nad, nas;
|
---|
| 679 |
|
---|
| 680 | // Check validity and packet type
|
---|
| 681 |
|
---|
| 682 | validMsg = (P.valid());
|
---|
| 683 | if (!validMsg) return;
|
---|
| 684 |
|
---|
| 685 | validMsg = (P.ID()==23);
|
---|
| 686 | if (!validMsg) return;
|
---|
| 687 |
|
---|
| 688 | // Antenna descriptor
|
---|
| 689 | antType = "";
|
---|
| 690 | nad = P.getUnsignedBits(3,5);
|
---|
| 691 | for (int i=0;i<nad;i++)
|
---|
| 692 | antType += (char)P.getUnsignedBits(8+i*8,8);
|
---|
| 693 |
|
---|
| 694 | // Optional antenna serial numbers
|
---|
| 695 | if (P.getUnsignedBits(2,1)==1) {
|
---|
| 696 | nas = P.getUnsignedBits(19+8*nad,5);
|
---|
| 697 | antSN = "";
|
---|
| 698 | for (int i=0;i<nas;i++)
|
---|
| 699 | antSN += (char)P.getUnsignedBits(24+8*nas+i*8,8);
|
---|
| 700 | };
|
---|
| 701 |
|
---|
| 702 | };
|
---|
| 703 |
|
---|
| 704 |
|
---|
| 705 | //------------------------------------------------------------------------------
|
---|
| 706 | //
|
---|
| 707 | // RTCM2_24 (class implementation)
|
---|
| 708 | //
|
---|
| 709 | // Purpose:
|
---|
| 710 | //
|
---|
| 711 | // A class for handling RTCM 2 Reference Station Antenna
|
---|
| 712 | // Reference Point Parameter messages
|
---|
| 713 | //
|
---|
| 714 | //------------------------------------------------------------------------------
|
---|
| 715 |
|
---|
| 716 | void RTCM2_24::extract(const RTCM2packet& P) {
|
---|
| 717 |
|
---|
| 718 | double dx,dy,dz;
|
---|
| 719 |
|
---|
| 720 | // Check validity and packet type
|
---|
| 721 |
|
---|
| 722 | validMsg = (P.valid());
|
---|
| 723 | if (!validMsg) return;
|
---|
| 724 |
|
---|
| 725 | validMsg = (P.ID()==24);
|
---|
| 726 | if (!validMsg) return;
|
---|
| 727 |
|
---|
| 728 | // System indicator
|
---|
| 729 |
|
---|
| 730 | isGPS = (P.getUnsignedBits(118,1)==0);
|
---|
| 731 | isGLONASS = (P.getUnsignedBits(118,1)==1);
|
---|
| 732 |
|
---|
| 733 | // Antenna reference point coordinates
|
---|
| 734 |
|
---|
| 735 | x = 64.0*P.getBits( 0,32);
|
---|
| 736 | y = 64.0*P.getBits(40,32);
|
---|
| 737 | z = 64.0*P.getBits(80,32);
|
---|
| 738 | dx = P.getUnsignedBits( 32,6);
|
---|
| 739 | dy = P.getUnsignedBits( 72,6);
|
---|
| 740 | dz = P.getUnsignedBits(112,6);
|
---|
| 741 | x = 0.0001*( x + (x<0? -dx:+dx) );
|
---|
| 742 | y = 0.0001*( y + (y<0? -dy:+dy) );
|
---|
| 743 | z = 0.0001*( z + (z<0? -dz:+dz) );
|
---|
| 744 |
|
---|
| 745 | // Antenna Height
|
---|
| 746 |
|
---|
| 747 | if (P.getUnsignedBits(119,1)==1) {
|
---|
| 748 | h= P.getUnsignedBits(120,18)*0.0001;
|
---|
| 749 | };
|
---|
| 750 |
|
---|
| 751 |
|
---|
| 752 | };
|
---|
| 753 |
|
---|
| 754 |
|
---|
| 755 | //------------------------------------------------------------------------------
|
---|
| 756 | //
|
---|
| 757 | // RTCM2_Obs (class definition)
|
---|
| 758 | //
|
---|
| 759 | // Purpose:
|
---|
| 760 | //
|
---|
| 761 | // A class for handling blocks of RTCM2 18 & 19 packets that need to be
|
---|
| 762 | // combined to get a complete set of measurements
|
---|
| 763 | //
|
---|
| 764 | // Notes:
|
---|
| 765 | //
|
---|
| 766 | // The class collects L1/L2 code and phase measurements for GPS and GLONASS.
|
---|
| 767 | // Since the Multiple Message Indicator is inconsistently handled by various
|
---|
| 768 | // receivers we simply require code and phase on L1 and L2 for a complete
|
---|
| 769 | // set ob observations at a given epoch. GLONASS observations are optional,
|
---|
| 770 | // but all four types (code+phase,L1+L2) must be provided, if at least one
|
---|
| 771 | // is given. Also, the GLONASS message must follow the corresponding GPS
|
---|
| 772 | // message.
|
---|
| 773 | //
|
---|
| 774 | //------------------------------------------------------------------------------
|
---|
| 775 |
|
---|
| 776 | // Constructor
|
---|
| 777 |
|
---|
| 778 | RTCM2_Obs::RTCM2_Obs() {
|
---|
| 779 |
|
---|
| 780 | clear();
|
---|
| 781 |
|
---|
| 782 | };
|
---|
| 783 |
|
---|
| 784 | // Reset entire block
|
---|
| 785 |
|
---|
| 786 | void RTCM2_Obs::clear() {
|
---|
| 787 |
|
---|
| 788 | secs=0.0; // Seconds of hour (GPS time)
|
---|
| 789 | nSat=0; // Number of space vehicles
|
---|
| 790 | PRN.resize(0); // Pseudorange [m]
|
---|
| 791 | rng_C1.resize(0); // Pseudorange [m]
|
---|
| 792 | rng_P1.resize(0); // Pseudorange [m]
|
---|
| 793 | rng_P2.resize(0); // Pseudorange [m]
|
---|
| 794 | cph_L1.resize(0); // Carrier phase [m]
|
---|
| 795 | cph_L2.resize(0); // Carrier phase [m]
|
---|
| 796 |
|
---|
| 797 | availability.reset(); // Message status flags
|
---|
| 798 |
|
---|
| 799 | };
|
---|
| 800 |
|
---|
| 801 | // Availability checks
|
---|
| 802 |
|
---|
[242] | 803 | bool RTCM2_Obs::anyGPS() const {
|
---|
[206] | 804 |
|
---|
| 805 | return availability.test(bit_L1rngGPS) ||
|
---|
| 806 | availability.test(bit_L2rngGPS) ||
|
---|
| 807 | availability.test(bit_L1cphGPS) ||
|
---|
| 808 | availability.test(bit_L2cphGPS);
|
---|
| 809 |
|
---|
| 810 | };
|
---|
| 811 |
|
---|
[242] | 812 | bool RTCM2_Obs::anyGLONASS() const {
|
---|
[206] | 813 |
|
---|
| 814 | return availability.test(bit_L1rngGLO) ||
|
---|
| 815 | availability.test(bit_L2rngGLO) ||
|
---|
| 816 | availability.test(bit_L1cphGLO) ||
|
---|
| 817 | availability.test(bit_L2cphGLO);
|
---|
| 818 |
|
---|
| 819 | };
|
---|
| 820 |
|
---|
[242] | 821 | bool RTCM2_Obs::allGPS() const {
|
---|
[206] | 822 |
|
---|
| 823 | return availability.test(bit_L1rngGPS) &&
|
---|
| 824 | availability.test(bit_L2rngGPS) &&
|
---|
| 825 | availability.test(bit_L1cphGPS) &&
|
---|
| 826 | availability.test(bit_L2cphGPS);
|
---|
| 827 |
|
---|
| 828 | };
|
---|
| 829 |
|
---|
[242] | 830 | bool RTCM2_Obs::allGLONASS() const {
|
---|
[206] | 831 |
|
---|
| 832 | return availability.test(bit_L1rngGLO) &&
|
---|
| 833 | availability.test(bit_L2rngGLO) &&
|
---|
| 834 | availability.test(bit_L1cphGLO) &&
|
---|
| 835 | availability.test(bit_L2cphGLO);
|
---|
| 836 |
|
---|
| 837 | };
|
---|
| 838 |
|
---|
| 839 | // Validity
|
---|
| 840 |
|
---|
[242] | 841 | bool RTCM2_Obs::valid() const {
|
---|
[206] | 842 |
|
---|
[253] | 843 | return ( allGPS() && (allGLONASS() || !anyGLONASS()) );
|
---|
[206] | 844 |
|
---|
| 845 | };
|
---|
| 846 |
|
---|
| 847 |
|
---|
| 848 | //
|
---|
| 849 | // Extract RTCM2 18 & 19 messages and store relevant data for future use
|
---|
| 850 | //
|
---|
| 851 |
|
---|
| 852 | void RTCM2_Obs::extract(const RTCM2packet& P) {
|
---|
| 853 |
|
---|
| 854 | bool isGPS,isCAcode,isL1,isOth;
|
---|
| 855 | int NSat,idx;
|
---|
| 856 | int sid,prn;
|
---|
| 857 | double t,rng,cph;
|
---|
| 858 |
|
---|
| 859 | // Check validity and packet type
|
---|
| 860 |
|
---|
| 861 | if (!P.valid()) return;
|
---|
| 862 |
|
---|
| 863 | // Clear previous data if block was already complete
|
---|
| 864 |
|
---|
| 865 | if (valid()) clear();
|
---|
| 866 |
|
---|
| 867 | // Process carrier phase message
|
---|
| 868 |
|
---|
| 869 | if ( P.ID()==18 ) {
|
---|
| 870 |
|
---|
| 871 | // Number of satellites in current message
|
---|
| 872 | NSat = (P.nDataWords()-1)/2;
|
---|
| 873 |
|
---|
| 874 | // Current epoch (mod 3600 sec)
|
---|
| 875 | t = 0.6*P.modZCount()
|
---|
| 876 | + P.getUnsignedBits(4,20)*1.0e-6;
|
---|
| 877 |
|
---|
| 878 | // Frequency (exit if neither L1 nor L2)
|
---|
| 879 | isL1 = ( P.getUnsignedBits(0,1)==0 );
|
---|
| 880 | isOth = ( P.getUnsignedBits(1,1)==1 );
|
---|
| 881 | if (isOth) return;
|
---|
| 882 |
|
---|
| 883 | // Constellation (for first satellite in message)
|
---|
| 884 | isGPS = ( P.getUnsignedBits(26,1)==0 );
|
---|
| 885 |
|
---|
| 886 | // Multiple Message Indicator (only checked for first satellite)
|
---|
[253] | 887 | // pendingMsg = ( P.getUnsignedBits(24,1)==1 );
|
---|
[206] | 888 |
|
---|
| 889 | // Handle epoch: store epoch of first GPS message and
|
---|
| 890 | // check consistency of subsequent messages. GLONASS time tags
|
---|
| 891 | // are different and have to be ignored
|
---|
| 892 | if (isGPS) {
|
---|
| 893 | if ( nSat==0 ) {
|
---|
| 894 | secs = t; // Store epoch
|
---|
| 895 | }
|
---|
| 896 | else if (t!=secs) {
|
---|
| 897 | clear(); secs = t; // Clear all data, then store epoch
|
---|
| 898 | };
|
---|
| 899 | };
|
---|
| 900 |
|
---|
| 901 | // Discard GLONASS obseravtions if no prior GPS observations
|
---|
| 902 | // are available
|
---|
| 903 | if (!isGPS && !anyGPS() ) return;
|
---|
| 904 |
|
---|
| 905 | // Set availability flags
|
---|
| 906 |
|
---|
| 907 | if ( isL1 && isGPS) availability.set(bit_L1cphGPS);
|
---|
| 908 | if (!isL1 && isGPS) availability.set(bit_L2cphGPS);
|
---|
| 909 | if ( isL1 && !isGPS) availability.set(bit_L1cphGLO);
|
---|
| 910 | if (!isL1 && !isGPS) availability.set(bit_L2cphGLO);
|
---|
| 911 |
|
---|
| 912 | // Process all satellites
|
---|
| 913 |
|
---|
| 914 | for (int iSat=0;iSat<NSat;iSat++){
|
---|
| 915 |
|
---|
| 916 | // Code type
|
---|
| 917 | isCAcode = ( P.getUnsignedBits(iSat*48+25,1)==0 );
|
---|
| 918 |
|
---|
| 919 | // Satellite
|
---|
| 920 | sid = P.getUnsignedBits(iSat*48+27,5);
|
---|
| 921 | prn = (isGPS? sid : sid+200 );
|
---|
| 922 |
|
---|
| 923 | // Carrier phase measurement (mod 2^23 [cy]; sign matched to range)
|
---|
| 924 | cph = -P.getBits(iSat*48+40,32)/256.0;
|
---|
| 925 |
|
---|
| 926 | // Is this a new PRN?
|
---|
| 927 | idx=-1;
|
---|
| 928 | for (unsigned int i=0;i<PRN.size();i++) {
|
---|
| 929 | if (PRN[i]==prn) { idx=i; break; };
|
---|
| 930 | };
|
---|
| 931 | if (idx==-1) {
|
---|
| 932 | // Insert new sat at end of list
|
---|
| 933 | nSat++; idx = nSat-1;
|
---|
| 934 | PRN.push_back(prn);
|
---|
| 935 | rng_C1.push_back(0.0);
|
---|
| 936 | rng_P1.push_back(0.0);
|
---|
| 937 | rng_P2.push_back(0.0);
|
---|
| 938 | cph_L1.push_back(0.0);
|
---|
| 939 | cph_L2.push_back(0.0);
|
---|
| 940 | };
|
---|
| 941 |
|
---|
| 942 | // Store measurement
|
---|
| 943 | if (isL1) {
|
---|
| 944 | cph_L1[idx] = cph;
|
---|
| 945 | }
|
---|
| 946 | else {
|
---|
| 947 | cph_L2[idx] = cph;
|
---|
| 948 | };
|
---|
| 949 |
|
---|
| 950 | };
|
---|
| 951 |
|
---|
| 952 | };
|
---|
| 953 |
|
---|
| 954 |
|
---|
| 955 | // Process pseudorange message
|
---|
| 956 |
|
---|
| 957 | if ( P.ID()==19 ) {
|
---|
| 958 |
|
---|
| 959 | // Number of satellites in current message
|
---|
| 960 | NSat = (P.nDataWords()-1)/2;
|
---|
| 961 |
|
---|
| 962 | // Current epoch (mod 3600 sec)
|
---|
| 963 | t = 0.6*P.modZCount()
|
---|
| 964 | + P.getUnsignedBits(4,20)*1.0e-6;
|
---|
| 965 |
|
---|
| 966 | // Frequency (exit if neither L1 nor L2)
|
---|
| 967 | isL1 = ( P.getUnsignedBits(0,1)==0 );
|
---|
| 968 | isOth = ( P.getUnsignedBits(1,1)==1 );
|
---|
| 969 | if (isOth) return;
|
---|
| 970 |
|
---|
| 971 | // Constellation (for first satellite in message)
|
---|
| 972 | isGPS = ( P.getUnsignedBits(26,1)==0 );
|
---|
| 973 |
|
---|
| 974 | // Multiple Message Indicator (only checked for first satellite)
|
---|
[253] | 975 | // pendingMsg = ( P.getUnsignedBits(24,1)==1 );
|
---|
[206] | 976 |
|
---|
| 977 | // Handle epoch: store epoch of first GPS message and
|
---|
| 978 | // check consistency of subsequent messages. GLONASS time tags
|
---|
| 979 | // are different and have to be ignored
|
---|
| 980 | if (isGPS) {
|
---|
| 981 | if ( nSat==0 ) {
|
---|
| 982 | secs = t; // Store epoch
|
---|
| 983 | }
|
---|
| 984 | else if (t!=secs) {
|
---|
| 985 | clear(); secs = t; // Clear all data, then store epoch
|
---|
| 986 | };
|
---|
| 987 | };
|
---|
| 988 |
|
---|
| 989 | // Discard GLONASS obseravtions if nor prior GPS observations
|
---|
| 990 | // are available
|
---|
| 991 | if (!isGPS && !anyGPS() ) return;
|
---|
| 992 |
|
---|
| 993 | // Set availability flags
|
---|
| 994 | if ( isL1 && isGPS) availability.set(bit_L1rngGPS);
|
---|
| 995 | if (!isL1 && isGPS) availability.set(bit_L2rngGPS);
|
---|
| 996 | if ( isL1 && !isGPS) availability.set(bit_L1rngGLO);
|
---|
| 997 | if (!isL1 && !isGPS) availability.set(bit_L2rngGLO);
|
---|
| 998 |
|
---|
| 999 | // Process all satellites
|
---|
| 1000 |
|
---|
| 1001 | for (int iSat=0;iSat<NSat;iSat++){
|
---|
| 1002 |
|
---|
| 1003 | // Code type
|
---|
| 1004 | isCAcode = ( P.getUnsignedBits(iSat*48+25,1)==0 );
|
---|
| 1005 |
|
---|
| 1006 | // Satellite
|
---|
| 1007 | sid = P.getUnsignedBits(iSat*48+27,5);
|
---|
| 1008 | prn = (isGPS? sid : sid+200 );
|
---|
| 1009 |
|
---|
| 1010 | // Pseudorange measurement [m]
|
---|
| 1011 | rng = P.getUnsignedBits(iSat*48+40,32)*0.02;
|
---|
| 1012 |
|
---|
| 1013 | // Is this a new PRN?
|
---|
| 1014 | idx=-1;
|
---|
| 1015 | for (unsigned int i=0;i<PRN.size();i++) {
|
---|
| 1016 | if (PRN[i]==prn) { idx=i; break; };
|
---|
| 1017 | };
|
---|
| 1018 | if (idx==-1) {
|
---|
| 1019 | // Insert new sat at end of list
|
---|
| 1020 | nSat++; idx = nSat-1;
|
---|
| 1021 | PRN.push_back(prn);
|
---|
| 1022 | rng_C1.push_back(0.0);
|
---|
| 1023 | rng_P1.push_back(0.0);
|
---|
| 1024 | rng_P2.push_back(0.0);
|
---|
| 1025 | cph_L1.push_back(0.0);
|
---|
| 1026 | cph_L2.push_back(0.0);
|
---|
| 1027 | };
|
---|
| 1028 |
|
---|
| 1029 | // Store measurement
|
---|
| 1030 | if (isL1) {
|
---|
| 1031 | if (isCAcode) rng_C1[idx] = rng;
|
---|
| 1032 | rng_P1[idx] = rng;
|
---|
| 1033 | }
|
---|
| 1034 | else {
|
---|
| 1035 | rng_P2[idx] = rng;
|
---|
| 1036 | };
|
---|
| 1037 |
|
---|
| 1038 | };
|
---|
| 1039 |
|
---|
| 1040 | };
|
---|
| 1041 |
|
---|
| 1042 | };
|
---|
| 1043 |
|
---|
| 1044 | //
|
---|
| 1045 | // Resolution of 2^24 cy carrier phase ambiguity
|
---|
| 1046 | // caused by 32-bit data field restrictions
|
---|
| 1047 | //
|
---|
| 1048 | // Note: the RTCM standard specifies an ambiguity of +/-2^23 cy.
|
---|
| 1049 | // However, numerous receivers generate data in the +/-2^22 cy range.
|
---|
| 1050 | // A reduced ambiguity of 2^23 cy appears compatible with both cases.
|
---|
| 1051 | //
|
---|
| 1052 |
|
---|
[242] | 1053 | double RTCM2_Obs::resolvedPhase_L1(int i) const {
|
---|
[206] | 1054 |
|
---|
| 1055 | //const double ambig = pow(2.0,24); // as per RTCM2 spec
|
---|
| 1056 | const double ambig = pow(2.0,23); // used by many receivers
|
---|
| 1057 |
|
---|
| 1058 | double rng;
|
---|
| 1059 | double n;
|
---|
| 1060 |
|
---|
| 1061 | if (!valid() || i<0 || i>nSat-1) return 0.0;
|
---|
| 1062 |
|
---|
| 1063 | rng = rng_C1[i];
|
---|
[227] | 1064 | if (rng==0.0) rng = rng_P1[i];
|
---|
[206] | 1065 | if (rng==0.0) return 0.0;
|
---|
| 1066 |
|
---|
| 1067 | n = floor( (rng/lambda_L1-cph_L1[i]) / ambig + 0.5 );
|
---|
| 1068 |
|
---|
| 1069 | return cph_L1[i] + n*ambig;
|
---|
| 1070 |
|
---|
| 1071 | };
|
---|
| 1072 |
|
---|
[242] | 1073 | double RTCM2_Obs::resolvedPhase_L2(int i) const {
|
---|
[206] | 1074 |
|
---|
| 1075 | //const double ambig = pow(2.0,24); // as per RTCM2 spec
|
---|
| 1076 | const double ambig = pow(2.0,23); // used by many receivers
|
---|
| 1077 |
|
---|
| 1078 | double rng;
|
---|
| 1079 | double n;
|
---|
| 1080 |
|
---|
| 1081 | if (!valid() || i<0 || i>nSat-1) return 0.0;
|
---|
| 1082 |
|
---|
| 1083 | rng = rng_C1[i];
|
---|
[227] | 1084 | if (rng==0.0) rng = rng_P1[i];
|
---|
[206] | 1085 | if (rng==0.0) return 0.0;
|
---|
| 1086 |
|
---|
| 1087 | n = floor( (rng/lambda_L2-cph_L2[i]) / ambig + 0.5 );
|
---|
| 1088 |
|
---|
| 1089 | return cph_L2[i] + n*ambig;
|
---|
| 1090 |
|
---|
| 1091 | };
|
---|
| 1092 |
|
---|
| 1093 | //
|
---|
| 1094 | // Resolution of epoch using reference date (GPS week and secs)
|
---|
| 1095 | //
|
---|
| 1096 |
|
---|
| 1097 | void RTCM2_Obs::resolveEpoch (int refWeek, double refSecs,
|
---|
[242] | 1098 | int& epochWeek, double& epochSecs ) const {
|
---|
[206] | 1099 |
|
---|
| 1100 | const double secsPerWeek = 604800.0;
|
---|
| 1101 |
|
---|
| 1102 | epochWeek = refWeek;
|
---|
| 1103 | epochSecs = secs + 3600.0*(floor((refSecs-secs)/3600.0+0.5));
|
---|
| 1104 |
|
---|
| 1105 | if (epochSecs<0 ) { epochWeek--; epochSecs+=secsPerWeek; };
|
---|
| 1106 | if (epochSecs>secsPerWeek) { epochWeek++; epochSecs-=secsPerWeek; };
|
---|
| 1107 |
|
---|
| 1108 | };
|
---|
| 1109 |
|
---|
| 1110 | }; // End of namespace rtcm2
|
---|