source: ntrip/trunk/BNC/GPSS/gpssDecoder.cpp@ 1377

Last change on this file since 1377 was 1315, checked in by mervart, 16 years ago

* empty log message *

File size: 4.0 KB
Line 
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"
19#include "bncapp.h"
20
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
31
32using namespace std;
33
34typedef struct epochHeader {
35 double t_epoch;
36 int n_svs;
37} EPOCHHEADER;
38
39// Constructor
40////////////////////////////////////////////////////////////////////////////
41gpssDecoder::gpssDecoder() : GPSDecoder() {
42 _mode = MODE_SEARCH;
43 _recordSize = 0;
44
45 connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
46 (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
47}
48
49// Destructor
50////////////////////////////////////////////////////////////////////////////
51gpssDecoder::~gpssDecoder() {
52}
53
54//
55////////////////////////////////////////////////////////////////////////////
56t_irc gpssDecoder::Decode(char* data, int dataLen, vector<string>& errmsg) {
57
58 errmsg.clear();
59
60 if (_mode == MODE_SEARCH) {
61 _buffer.clear();
62 _recordSize = 0;
63 }
64 _buffer.append(data, dataLen);
65
66 unsigned offset = 0;
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:
90 if (offset+sizeof(_recordSize) > _buffer.size()) {
91 errmsg.push_back("Record size too large (A)");
92 _mode = MODE_SEARCH;
93 } else {
94 memcpy(&_recordSize, &_buffer[offset], sizeof(_recordSize));
95 if (_mode == MODE_EPOCH) {
96 _mode = MODE_EPOCH_BODY;
97 }
98 if (_mode == MODE_EPH) {
99 _mode = MODE_EPH_BODY;
100 }
101 offset += sizeof(_recordSize) - 1;
102 }
103 continue;
104
105 case MODE_EPOCH_BODY:
106 if (offset + _recordSize > _buffer.size()) {
107 errmsg.push_back("Record size too large (B)");
108 _mode = MODE_SEARCH;
109 } else {
110 EPOCHHEADER epochHdr;
111 memcpy(&epochHdr, &_buffer[offset], sizeof(epochHdr));
112 offset += sizeof(epochHdr);
113 for (int is = 1; is <= epochHdr.n_svs; is++) {
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);
118 }
119 _mode = MODE_EPOCH_CRC;
120 --offset;
121 }
122 continue;
123
124 case MODE_EPH_BODY:
125 if (offset + _recordSize > _buffer.size()) {
126 errmsg.push_back("Record size too large (C)");
127 _mode = MODE_SEARCH;
128 } else {
129 gpsephemeris* gpsEph = new gpsephemeris;
130 memcpy(gpsEph, &_buffer[offset], sizeof(gpsephemeris));
131 emit newGPSEph(gpsEph);
132 offset += sizeof(gpsephemeris) - 1;
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 }
153 }
154
155 if (errmsg.size() == 0) {
156 return success;
157 }
158 else {
159 return failure;
160 }
161}
Note: See TracBrowser for help on using the repository browser.