[1310] | 1 |
|
---|
| 2 | /* -------------------------------------------------------------------------
|
---|
| 3 | * BKG NTRIP Client
|
---|
| 4 | * -------------------------------------------------------------------------
|
---|
| 5 | *
|
---|
| 6 | * Class: gpssDecoder
|
---|
| 7 | *
|
---|
| 8 | * Purpose: Decode Data in GPSS Format
|
---|
| 9 | *
|
---|
| 10 | * Author: L. Mervart
|
---|
| 11 | *
|
---|
| 12 | * Created: 20-Dec-2008
|
---|
| 13 | *
|
---|
| 14 | * Changes:
|
---|
| 15 | *
|
---|
| 16 | * -----------------------------------------------------------------------*/
|
---|
| 17 |
|
---|
| 18 | #include "gpssDecoder.h"
|
---|
[1314] | 19 | #include "bncapp.h"
|
---|
[1310] | 20 |
|
---|
[1312] | 21 | #define MODE_SEARCH 0
|
---|
| 22 | #define MODE_TYPE 1
|
---|
| 23 | #define MODE_EPOCH 2
|
---|
| 24 | #define MODE_EPOCH_BODY 3
|
---|
| 25 | #define MODE_EPOCH_CRC 4
|
---|
| 26 | #define MODE_EPOCH_ETX 5
|
---|
| 27 | #define MODE_EPH 6
|
---|
| 28 | #define MODE_EPH_BODY 7
|
---|
| 29 | #define MODE_EPH_CRC 8
|
---|
| 30 | #define MODE_EPH_ETX 9
|
---|
[1311] | 31 |
|
---|
[1310] | 32 | using namespace std;
|
---|
| 33 |
|
---|
[1311] | 34 | typedef struct epochHeader {
|
---|
| 35 | double t_epoch;
|
---|
| 36 | int n_svs;
|
---|
| 37 | } EPOCHHEADER;
|
---|
| 38 |
|
---|
[1310] | 39 | // Constructor
|
---|
| 40 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 41 | gpssDecoder::gpssDecoder() : GPSDecoder() {
|
---|
[1313] | 42 | _mode = MODE_SEARCH;
|
---|
| 43 | _recordSize = 0;
|
---|
[1314] | 44 |
|
---|
| 45 | connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
|
---|
| 46 | (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
|
---|
[1310] | 47 | }
|
---|
| 48 |
|
---|
| 49 | // Destructor
|
---|
| 50 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 51 | gpssDecoder::~gpssDecoder() {
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | //
|
---|
| 55 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1311] | 56 | t_irc gpssDecoder::Decode(char* data, int dataLen, vector<string>& errmsg) {
|
---|
| 57 |
|
---|
[1310] | 58 | errmsg.clear();
|
---|
| 59 |
|
---|
[1313] | 60 | if (_mode == MODE_SEARCH) {
|
---|
| 61 | _buffer.clear();
|
---|
[1315] | 62 | _recordSize = 0;
|
---|
[1313] | 63 | }
|
---|
[1311] | 64 | _buffer.append(data, dataLen);
|
---|
| 65 |
|
---|
[1312] | 66 | unsigned offset = 0;
|
---|
[1311] | 67 | for (offset = 0; offset < _buffer.size(); offset++) {
|
---|
| 68 |
|
---|
| 69 | switch(_mode) {
|
---|
| 70 |
|
---|
| 71 | case MODE_SEARCH:
|
---|
| 72 | if (_buffer[offset] == 0x02) {
|
---|
| 73 | _mode = MODE_TYPE;
|
---|
| 74 | }
|
---|
| 75 | continue;
|
---|
| 76 |
|
---|
| 77 | case MODE_TYPE:
|
---|
| 78 | if (_buffer[offset] == 0x00) {
|
---|
| 79 | _mode = MODE_EPOCH;
|
---|
| 80 | } else if (_buffer[offset] == 0x01) {
|
---|
| 81 | _mode = MODE_EPH;
|
---|
| 82 | } else {
|
---|
| 83 | errmsg.push_back("Unknown record type");
|
---|
| 84 | _mode = MODE_SEARCH;
|
---|
| 85 | }
|
---|
| 86 | continue;
|
---|
| 87 |
|
---|
| 88 | case MODE_EPOCH:
|
---|
| 89 | case MODE_EPH:
|
---|
[1313] | 90 | if (offset+sizeof(_recordSize) > _buffer.size()) {
|
---|
[1311] | 91 | errmsg.push_back("Record size too large (A)");
|
---|
| 92 | _mode = MODE_SEARCH;
|
---|
| 93 | } else {
|
---|
[1313] | 94 | memcpy(&_recordSize, &_buffer[offset], sizeof(_recordSize));
|
---|
[1311] | 95 | if (_mode == MODE_EPOCH) {
|
---|
| 96 | _mode = MODE_EPOCH_BODY;
|
---|
| 97 | }
|
---|
| 98 | if (_mode == MODE_EPH) {
|
---|
| 99 | _mode = MODE_EPH_BODY;
|
---|
| 100 | }
|
---|
[1313] | 101 | offset += sizeof(_recordSize) - 1;
|
---|
[1311] | 102 | }
|
---|
| 103 | continue;
|
---|
| 104 |
|
---|
| 105 | case MODE_EPOCH_BODY:
|
---|
[1313] | 106 | if (offset + _recordSize > _buffer.size()) {
|
---|
[1311] | 107 | errmsg.push_back("Record size too large (B)");
|
---|
| 108 | _mode = MODE_SEARCH;
|
---|
| 109 | } else {
|
---|
[1315] | 110 | EPOCHHEADER epochHdr;
|
---|
[1312] | 111 | memcpy(&epochHdr, &_buffer[offset], sizeof(epochHdr));
|
---|
| 112 | offset += sizeof(epochHdr);
|
---|
| 113 | for (int is = 1; is <= epochHdr.n_svs; is++) {
|
---|
[1313] | 114 | t_obs* obs = new t_obs();
|
---|
| 115 | memcpy(&(obs->_o), &_buffer[offset], sizeof(obs->_o));
|
---|
| 116 | _obsList.push_back(obs);
|
---|
| 117 | offset += sizeof(obs->_o);
|
---|
[1312] | 118 | }
|
---|
[1311] | 119 | _mode = MODE_EPOCH_CRC;
|
---|
[1312] | 120 | --offset;
|
---|
[1311] | 121 | }
|
---|
| 122 | continue;
|
---|
| 123 |
|
---|
| 124 | case MODE_EPH_BODY:
|
---|
[1313] | 125 | if (offset + _recordSize > _buffer.size()) {
|
---|
[1312] | 126 | errmsg.push_back("Record size too large (C)");
|
---|
[1311] | 127 | _mode = MODE_SEARCH;
|
---|
| 128 | } else {
|
---|
[1314] | 129 | gpsephemeris* gpsEph = new gpsephemeris;
|
---|
| 130 | memcpy(gpsEph, &_buffer[offset], sizeof(gpsephemeris));
|
---|
| 131 | emit newGPSEph(gpsEph);
|
---|
| 132 | offset += sizeof(gpsephemeris) - 1;
|
---|
[1311] | 133 | _mode = MODE_EPH_CRC;
|
---|
| 134 | }
|
---|
| 135 | continue;
|
---|
| 136 |
|
---|
| 137 | case MODE_EPOCH_CRC:
|
---|
| 138 | _mode = MODE_EPOCH_ETX; // TODO: CRC check
|
---|
| 139 | continue;
|
---|
| 140 |
|
---|
| 141 | case MODE_EPH_CRC:
|
---|
| 142 | _mode = MODE_EPH_ETX; // TODO: CRC check
|
---|
| 143 | continue;
|
---|
| 144 |
|
---|
| 145 | case MODE_EPOCH_ETX:
|
---|
| 146 | _mode = MODE_SEARCH;
|
---|
| 147 | continue;
|
---|
| 148 |
|
---|
| 149 | case MODE_EPH_ETX:
|
---|
| 150 | _mode = MODE_SEARCH;
|
---|
| 151 | continue;
|
---|
| 152 | }
|
---|
[1312] | 153 | }
|
---|
[1311] | 154 |
|
---|
[1313] | 155 | if (errmsg.size() == 0) {
|
---|
| 156 | return success;
|
---|
| 157 | }
|
---|
| 158 | else {
|
---|
| 159 | return failure;
|
---|
| 160 | }
|
---|
[1310] | 161 | }
|
---|