[866] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2007
|
---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
| 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: RTCM3coDecoder
|
---|
| 30 | *
|
---|
| 31 | * Purpose: RTCM3 Clock Orbit Decoder
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 05-May-2008
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[868] | 41 | #include <stdio.h>
|
---|
| 42 |
|
---|
[866] | 43 | #include "RTCM3coDecoder.h"
|
---|
[918] | 44 | #include "bncutils.h"
|
---|
[866] | 45 |
|
---|
| 46 | using namespace std;
|
---|
| 47 |
|
---|
| 48 | // Constructor
|
---|
| 49 | ////////////////////////////////////////////////////////////////////////////
|
---|
[875] | 50 | RTCM3coDecoder::RTCM3coDecoder(const QString& fileName)
|
---|
| 51 | : bncZeroDecoder(fileName) {
|
---|
[866] | 52 | }
|
---|
| 53 |
|
---|
| 54 | // Destructor
|
---|
| 55 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 56 | RTCM3coDecoder::~RTCM3coDecoder() {
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | //
|
---|
| 60 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 61 | t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen) {
|
---|
[868] | 62 |
|
---|
[869] | 63 | _buffer.append(buffer, bufLen);
|
---|
[868] | 64 |
|
---|
[869] | 65 | while (true) {
|
---|
[908] | 66 |
|
---|
| 67 | memset(&_co, 0, sizeof(_co));
|
---|
[906] | 68 |
|
---|
[879] | 69 | int bytesused = 0;
|
---|
| 70 | GCOB_RETURN irc = GetClockOrbitBias(&_co, &_bias, _buffer.data(),
|
---|
| 71 | _buffer.size(), &bytesused);
|
---|
| 72 |
|
---|
[906] | 73 | // Not enough Data
|
---|
| 74 | // ---------------
|
---|
[879] | 75 | if (irc == GCOBR_SHORTBUFFER ||
|
---|
[906] | 76 | irc == GCOBR_MESSAGEEXCEEDSBUFFER) {
|
---|
[869] | 77 | return failure;
|
---|
| 78 | }
|
---|
[879] | 79 |
|
---|
[906] | 80 | // Message correctly decoded
|
---|
| 81 | // -------------------------
|
---|
[908] | 82 | else if ( (irc == GCOBR_OK || irc == GCOBR_MESSAGEFOLLOWS) &&
|
---|
| 83 | bytesused > 0) {
|
---|
[881] | 84 | reopen();
|
---|
[918] | 85 |
|
---|
| 86 | int GPSweek;
|
---|
| 87 | double GPSweeks;
|
---|
| 88 | currentGPSWeeks(GPSweek, GPSweeks);
|
---|
[919] | 89 |
|
---|
| 90 | if (_co.NumberOfGPSSat > 0) {
|
---|
| 91 | if (GPSweeks > _co.GPSEpochTime + 86400.0) {
|
---|
| 92 | GPSweek += 1;
|
---|
| 93 | }
|
---|
| 94 | else if (GPSweeks < _co.GPSEpochTime - 86400.0) {
|
---|
| 95 | GPSweek -= 1;
|
---|
| 96 | }
|
---|
| 97 | GPSweeks = _co.GPSEpochTime;
|
---|
[918] | 98 | }
|
---|
[919] | 99 | else {
|
---|
| 100 | double GPSdaysec = fmod(GPSweeks, 86400.0);
|
---|
| 101 | int weekDay = int((GPSweeks - GPSdaysec) / 86400.0);
|
---|
| 102 | if (GPSdaysec > _co.GLONASSEpochTime + 3600.0) {
|
---|
| 103 | weekDay += 1;
|
---|
| 104 | if (weekDay > 6) {
|
---|
| 105 | weekDay = 0;
|
---|
| 106 | GPSweek += 1;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | else if (GPSdaysec < _co.GLONASSEpochTime - 3600.0) {
|
---|
| 110 | weekDay -= 1;
|
---|
| 111 | if (weekDay < 0) {
|
---|
| 112 | weekDay = 6;
|
---|
| 113 | GPSweek -= 1;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | GPSweeks = weekDay * 86400.0 + _co.GLONASSEpochTime;
|
---|
[918] | 117 | }
|
---|
| 118 |
|
---|
[869] | 119 | for(int ii = 0; ii < _co.NumberOfGPSSat; ++ii) {
|
---|
[875] | 120 | QString line;
|
---|
[919] | 121 | line.sprintf("%d %.1f G%2.2d %3d %8.3f %8.3f %8.3f %8.3f\n",
|
---|
[918] | 122 | GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
|
---|
| 123 | _co.Sat[ii].Clock.DeltaA0,
|
---|
| 124 | _co.Sat[ii].Orbit.DeltaRadial,
|
---|
| 125 | _co.Sat[ii].Orbit.DeltaAlongTrack,
|
---|
[869] | 126 | _co.Sat[ii].Orbit.DeltaCrossTrack);
|
---|
[876] | 127 | *_out << line.toAscii().data();
|
---|
[869] | 128 | }
|
---|
[903] | 129 | for(int ii = CLOCKORBIT_NUMGPS;
|
---|
| 130 | ii < CLOCKORBIT_NUMGPS + _co.NumberOfGLONASSSat; ++ii) {
|
---|
| 131 | QString line;
|
---|
[919] | 132 | line.sprintf("%d %.1f R%2.2d %3d %8.3f %8.3f %8.3f %8.3f\n",
|
---|
[918] | 133 | GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
|
---|
| 134 | _co.Sat[ii].Clock.DeltaA0,
|
---|
| 135 | _co.Sat[ii].Orbit.DeltaRadial,
|
---|
| 136 | _co.Sat[ii].Orbit.DeltaAlongTrack,
|
---|
[903] | 137 | _co.Sat[ii].Orbit.DeltaCrossTrack);
|
---|
| 138 | *_out << line.toAscii().data();
|
---|
| 139 | }
|
---|
| 140 | _out->flush();
|
---|
[879] | 141 | _buffer = _buffer.substr(bytesused);
|
---|
[869] | 142 | return success;
|
---|
| 143 | }
|
---|
[879] | 144 |
|
---|
[906] | 145 | // All other Cases
|
---|
| 146 | // ---------------
|
---|
[869] | 147 | else {
|
---|
[879] | 148 | _buffer = _buffer.substr(1);
|
---|
[869] | 149 | }
|
---|
[868] | 150 | }
|
---|
[866] | 151 | }
|
---|