[1429] | 1 | \
|
---|
[1310] | 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 |
|
---|
[1431] | 18 | #include <iostream>
|
---|
| 19 |
|
---|
[1310] | 20 | #include "gpssDecoder.h"
|
---|
[1314] | 21 | #include "bncapp.h"
|
---|
[1310] | 22 |
|
---|
[1312] | 23 | #define MODE_SEARCH 0
|
---|
| 24 | #define MODE_TYPE 1
|
---|
| 25 | #define MODE_EPOCH 2
|
---|
| 26 | #define MODE_EPOCH_BODY 3
|
---|
| 27 | #define MODE_EPOCH_CRC 4
|
---|
| 28 | #define MODE_EPOCH_ETX 5
|
---|
| 29 | #define MODE_EPH 6
|
---|
| 30 | #define MODE_EPH_BODY 7
|
---|
| 31 | #define MODE_EPH_CRC 8
|
---|
| 32 | #define MODE_EPH_ETX 9
|
---|
[1311] | 33 |
|
---|
[1310] | 34 | using namespace std;
|
---|
| 35 |
|
---|
[1311] | 36 | typedef struct epochHeader {
|
---|
| 37 | double t_epoch;
|
---|
| 38 | int n_svs;
|
---|
| 39 | } EPOCHHEADER;
|
---|
| 40 |
|
---|
[1434] | 41 | // Cyclic Redundancy Check
|
---|
| 42 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 43 | unsigned short cal_crc(char *buf, int num) {
|
---|
| 44 | unsigned short polynomial = 0x8408;
|
---|
| 45 | unsigned short crc = 0;
|
---|
| 46 | int i;
|
---|
| 47 | while ( num-- ) {
|
---|
| 48 | crc = ( crc & 0xFF00 ) | ( *buf++^( crc & 0x00FF ) );
|
---|
| 49 | for( i=0; i<8; i++ ){
|
---|
| 50 | if( crc & 0x0001 ){
|
---|
| 51 | crc >>= 1;
|
---|
| 52 | crc ^= polynomial;
|
---|
| 53 | }
|
---|
| 54 | else{
|
---|
| 55 | crc >>= 1;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | return (crc);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[1310] | 62 | // Constructor
|
---|
| 63 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 64 | gpssDecoder::gpssDecoder() : GPSDecoder() {
|
---|
[1313] | 65 | _mode = MODE_SEARCH;
|
---|
[1314] | 66 |
|
---|
| 67 | connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
|
---|
| 68 | (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
|
---|
[1310] | 69 | }
|
---|
| 70 |
|
---|
| 71 | // Destructor
|
---|
| 72 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 73 | gpssDecoder::~gpssDecoder() {
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | //
|
---|
| 77 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1311] | 78 | t_irc gpssDecoder::Decode(char* data, int dataLen, vector<string>& errmsg) {
|
---|
| 79 |
|
---|
[1310] | 80 | errmsg.clear();
|
---|
| 81 |
|
---|
[1429] | 82 | _buffer += QByteArray(data, dataLen);
|
---|
[1311] | 83 |
|
---|
[1434] | 84 | cout << "Decode: buffer length = " << _buffer.length() << endl;
|
---|
| 85 |
|
---|
[1429] | 86 | int iBeg;
|
---|
| 87 | while ( (iBeg = _buffer.indexOf(0x02)) != -1) {
|
---|
| 88 | _buffer = _buffer.mid(iBeg);
|
---|
[1311] | 89 |
|
---|
[1429] | 90 | int recordSize;
|
---|
[1430] | 91 | int crc;
|
---|
[1429] | 92 |
|
---|
| 93 | // Observations
|
---|
| 94 | // ------------
|
---|
| 95 | if (char(_buffer[1]) == 0x00) {
|
---|
[1431] | 96 |
|
---|
| 97 | int reqLength = 2 + sizeof(recordSize) + sizeof(EPOCHHEADER);
|
---|
| 98 |
|
---|
| 99 | if (_buffer.length() >= reqLength) {
|
---|
| 100 | EPOCHHEADER epochHdr;
|
---|
[1429] | 101 | memcpy(&epochHdr, _buffer.data() + 2 + sizeof(recordSize),
|
---|
| 102 | sizeof(epochHdr));
|
---|
[1431] | 103 |
|
---|
| 104 | reqLength += epochHdr.n_svs * sizeof(t_obsInternal) + sizeof(crc) + 1;
|
---|
[1311] | 105 |
|
---|
[1430] | 106 | if (_buffer.length() >= reqLength) {
|
---|
[1434] | 107 |
|
---|
| 108 | int checkLen = 2 + sizeof(recordSize) + sizeof(EPOCHHEADER) +
|
---|
| 109 | epochHdr.n_svs * sizeof(t_obsInternal);
|
---|
| 110 | memcpy(&crc, _buffer.data() + checkLen, sizeof(crc));
|
---|
| 111 | int crdCal = cal_crc(_buffer.data(), checkLen);
|
---|
| 112 |
|
---|
| 113 | cout << "Obs: " << crc << " " << crdCal << endl;
|
---|
| 114 |
|
---|
[1430] | 115 | for (int is = 0; is < epochHdr.n_svs; is++) {
|
---|
[1429] | 116 | t_obs* obs = new t_obs();
|
---|
[1430] | 117 | memcpy(&(obs->_o), _buffer.data() + 2 + sizeof(recordSize) +
|
---|
| 118 | sizeof(epochHdr) + is * sizeof(t_obsInternal),
|
---|
| 119 | sizeof(t_obsInternal));
|
---|
[1429] | 120 | _obsList.push_back(obs);
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
[1425] | 123 | }
|
---|
[1433] | 124 | _buffer = _buffer.mid(reqLength);
|
---|
[1425] | 125 | }
|
---|
[1311] | 126 |
|
---|
[1429] | 127 | // Ephemeris
|
---|
| 128 | // ---------
|
---|
| 129 | else if (char(_buffer[1]) == 0x01) {
|
---|
[1430] | 130 | int reqLength = 2 + sizeof(recordSize) + sizeof(gpsephemeris) +
|
---|
| 131 | sizeof(crc) + 1;
|
---|
[1431] | 132 |
|
---|
[1434] | 133 | if (_buffer.length() >= reqLength) {
|
---|
[1431] | 134 |
|
---|
[1434] | 135 | int checkLen = 2 + sizeof(recordSize) + sizeof(gpsephemeris);
|
---|
| 136 | memcpy(&crc, _buffer.data() + checkLen, sizeof(crc));
|
---|
| 137 | int crdCal = cal_crc(_buffer.data(), checkLen);
|
---|
| 138 |
|
---|
| 139 | cout << "Obs: " << crc << " " << crdCal << endl;
|
---|
| 140 |
|
---|
[1429] | 141 | gpsephemeris* gpsEph = new gpsephemeris;
|
---|
[1432] | 142 | memcpy(gpsEph, _buffer.data() + 2 + sizeof(recordSize),
|
---|
| 143 | sizeof(gpsephemeris));
|
---|
[1429] | 144 | emit newGPSEph(gpsEph);
|
---|
[1426] | 145 | }
|
---|
[1433] | 146 | _buffer = _buffer.mid(reqLength);
|
---|
[1425] | 147 | }
|
---|
[1311] | 148 |
|
---|
[1425] | 149 | else {
|
---|
[1429] | 150 | _buffer == _buffer.mid(1);
|
---|
[1311] | 151 | }
|
---|
[1312] | 152 | }
|
---|
[1311] | 153 |
|
---|
[1425] | 154 | return success;
|
---|
[1310] | 155 | }
|
---|