| 1 |
|
|---|
| 2 | /* -------------------------------------------------------------------------
|
|---|
| 3 | * BKG NTRIP Client
|
|---|
| 4 | * -------------------------------------------------------------------------
|
|---|
| 5 | *
|
|---|
| 6 | * Class: RTIGSDecoder
|
|---|
| 7 | *
|
|---|
| 8 | * Purpose: RTIGS Decoder
|
|---|
| 9 | *
|
|---|
| 10 | * Author: L. Mervart
|
|---|
| 11 | *
|
|---|
| 12 | * Created: 24-Aug-2006
|
|---|
| 13 | *
|
|---|
| 14 | * Changes:
|
|---|
| 15 | *
|
|---|
| 16 | * -----------------------------------------------------------------------*/
|
|---|
| 17 |
|
|---|
| 18 | #include "RTIGSDecoder.h"
|
|---|
| 19 | #include "bncconst.h"
|
|---|
| 20 | #include "rtigs.h"
|
|---|
| 21 |
|
|---|
| 22 | using namespace std;
|
|---|
| 23 |
|
|---|
| 24 | // Constructor
|
|---|
| 25 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | RTIGSDecoder::RTIGSDecoder() {
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | // Destructor
|
|---|
| 30 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 31 | RTIGSDecoder::~RTIGSDecoder() {
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | //
|
|---|
| 35 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 36 | void RTIGSDecoder::Decode(char* buffer, int bufLen) {
|
|---|
| 37 |
|
|---|
| 38 | // Append the incomming data to the internal buffer
|
|---|
| 39 | // ------------------------------------------------
|
|---|
| 40 | _buffer.append( QByteArray(buffer, bufLen) );
|
|---|
| 41 |
|
|---|
| 42 | // Find the beginning of the message
|
|---|
| 43 | // ---------------------------------
|
|---|
| 44 | bool found = false;
|
|---|
| 45 | for (int ii = 0; ii < _buffer.size(); ii++) {
|
|---|
| 46 | unsigned short xx;
|
|---|
| 47 | memcpy( (void*) &xx, &_buffer.data()[ii], sizeof(xx) );
|
|---|
| 48 | revbytes( (unsigned char*) &xx, sizeof(xx) );
|
|---|
| 49 | if (xx == 200) {
|
|---|
| 50 | _buffer = _buffer.mid(ii);
|
|---|
| 51 | found = true;
|
|---|
| 52 | break;
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 | if (! found) {
|
|---|
| 56 | _buffer.clear();
|
|---|
| 57 | return;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | // Read the Header
|
|---|
| 61 | // ---------------
|
|---|
| 62 | if (_buffer.size() < (int) sizeof(RTIGSH)) {
|
|---|
| 63 | return;
|
|---|
| 64 | }
|
|---|
| 65 | RTIGSH rtigs_header;
|
|---|
| 66 | bytes_to_rtigsh(&rtigs_header, (unsigned char*) _buffer.data());
|
|---|
| 67 |
|
|---|
| 68 | // Read the Observations
|
|---|
| 69 | // ---------------------
|
|---|
| 70 | int numBytes = sizeof(RTIGSH) + rtigs_header.num_bytes;
|
|---|
| 71 | if (_buffer.size() < numBytes) {
|
|---|
| 72 | return;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | if (rtigs_header.rec_id == 200) {
|
|---|
| 76 | RTIGSO rtigs_obs;
|
|---|
| 77 | memcpy(&rtigs_obs, &rtigs_header, sizeof(RTIGSH));
|
|---|
| 78 | memcpy((unsigned char*) &rtigs_obs.data, _buffer.data(),
|
|---|
| 79 | rtigs_header.num_bytes - sizeof(RTIGSH));
|
|---|
| 80 |
|
|---|
| 81 | GPSEpoch epoch;
|
|---|
| 82 | rtigso_to_raw(&rtigs_obs, &epoch);
|
|---|
| 83 |
|
|---|
| 84 | for (short ii = 0; ii < epoch.num_sv; ii++) {
|
|---|
| 85 | Observation* obs = new Observation();
|
|---|
| 86 |
|
|---|
| 87 | obs->SVPRN = epoch.sv[ii].prn;
|
|---|
| 88 | obs->GPSWeek = epoch.GPSTime / (7 * 86400);
|
|---|
| 89 | obs->GPSWeeks = epoch.GPSTime % (7 * 86400);
|
|---|
| 90 | obs->C1 = epoch.sv[ii].CARange;
|
|---|
| 91 | obs->P1 = epoch.sv[ii].P1Range;
|
|---|
| 92 | obs->P2 = epoch.sv[ii].P2Range;
|
|---|
| 93 | obs->L1 = epoch.sv[ii].L1Phase;
|
|---|
| 94 | obs->L2 = epoch.sv[ii].L2Phase;
|
|---|
| 95 | obs->SNR1 = int(epoch.sv[ii].L1Snr * 10);
|
|---|
| 96 | obs->SNR2 = int(epoch.sv[ii].L2Snr * 10);
|
|---|
| 97 |
|
|---|
| 98 | _obsList.push_back(obs);
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | // Unprocessed bytes remain in buffer
|
|---|
| 103 | // ----------------------------------
|
|---|
| 104 | _buffer = _buffer.mid(numBytes);
|
|---|
| 105 | }
|
|---|