source: ntrip/trunk/BNC/src/RTRover/bncrtrover.cpp@ 4757

Last change on this file since 4757 was 4757, checked in by mervart, 12 years ago
File size: 9.5 KB
Line 
1
2#include <iostream>
3#include <string.h>
4
5#include "dllinterface.h"
6#include "bncapp.h"
7#include "bncsettings.h"
8#include "bnctime.h"
9
10#include "../GPC.h"
11
12using namespace std;
13
14// Constructor
15////////////////////////////////////////////////////////////////////////////
16t_dllInterface::t_dllInterface() {
17
18 bncSettings settings;
19
20 // Processed Station, Corrections Source
21 // -------------------------------------
22 _pppCorrMount = settings.value("pppCorrMount").toString();
23
24 // Define Input Options
25 // --------------------
26 GPSS::gpcOpt opt;
27 opt.sigmaCode = settings.value("pppSigmaCode").toDouble();
28 opt.sigmaPhase = settings.value("pppSigmaPhase").toDouble();
29 opt.sigCrd0 = settings.value("pppSigCrd0").toDouble();
30 opt.sigCrdP = settings.value("pppSigCrdP").toDouble();
31 opt.sigTrp0 = settings.value("pppSigTrp0").toDouble();
32 opt.sigTrpP = settings.value("pppSigTrpP").toDouble();
33 opt.refCrd[0] = settings.value("pppRefCrdX").toDouble();
34 opt.refCrd[1] = settings.value("pppRefCrdY").toDouble();
35 opt.refCrd[2] = settings.value("pppRefCrdZ").toDouble();
36 opt.antEccNEU[0] = settings.value("pppRefdN").toDouble();
37 opt.antEccNEU[1] = settings.value("pppRefdE").toDouble();
38 opt.antEccNEU[2] = settings.value("pppRefdU").toDouble();
39 opt.maxSolGap = settings.value("pppMaxSolGap").toInt();
40 opt.corrSync = settings.value("pppSync").toDouble();
41 opt.quickStart = settings.value("pppQuickStart").toInt();
42 opt.pppMode = (settings.value("pppSPP").toString() == "PPP") ? 1 : 0;
43 opt.usePhase = (Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) ? 1 : 0;
44 opt.estTropo = (Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) ? 1 : 0;
45 opt.useGlonass = (Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) ? 1 : 0;
46 opt.useGalileo = 0;
47 opt.antexFileName = strdup(settings.value("pppAntex").toByteArray().constData());
48 opt.antennaName = strdup(settings.value("pppAntenna").toByteArray().constData());
49
50 // Initialize DLL Client
51 // ---------------------
52 GPSS::gpcInit(&opt);
53
54 free(opt.antexFileName);
55 free(opt.antennaName);
56
57 // Connect to BNC Signals
58 // ----------------------
59 connect(((bncApp*)qApp), SIGNAL(newCorrections(QList<QString>)),
60 this, SLOT(slotNewCorrections(QList<QString>)));
61
62 connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
63 this, SLOT(slotNewEphGPS(gpsephemeris)));
64
65 connect(((bncApp*)qApp), SIGNAL(newEphGlonass(glonassephemeris)),
66 this, SLOT(slotNewEphGlonass(glonassephemeris)));
67
68 connect(((bncApp*)qApp), SIGNAL(newEphGalileo(galileoephemeris)),
69 this, SLOT(slotNewEphGalileo(galileoephemeris)));
70}
71
72// Destructor
73////////////////////////////////////////////////////////////////////////////
74t_dllInterface::~t_dllInterface() {
75 QMapIterator<QString, t_corr*> ic(_corr);
76 while (ic.hasNext()) {
77 ic.next();
78 delete ic.value();
79 }
80 GPSS::gpcDestroy();
81}
82
83//
84////////////////////////////////////////////////////////////////////////////
85void t_dllInterface::slotNewEphGPS(gpsephemeris gpseph) {
86 QMutexLocker locker(&_mutex);
87
88 GPSS::gpcEphGPS eph;
89 eph.prn = gpseph.satellite;
90 eph.GPSweek = gpseph.GPSweek;
91 eph.GPSweeks = gpseph.TOC;
92 eph.TOE = gpseph.TOE;
93 eph.IODC = gpseph.IODC;
94 eph.clock_bias = gpseph.clock_bias;
95 eph.clock_drift = gpseph.clock_drift;
96 eph.clock_driftrate = gpseph.clock_driftrate;
97 eph.Crs = gpseph.Crs;
98 eph.Delta_n = gpseph.Delta_n;
99 eph.M0 = gpseph.M0;
100 eph.Cuc = gpseph.Cuc;
101 eph.ee = gpseph.e;
102 eph.Cus = gpseph.Cus;
103 eph.sqrt_A = gpseph.sqrt_A;
104 eph.Cic = gpseph.Cic;
105 eph.OMEGA0 = gpseph.OMEGA0;
106 eph.Cis = gpseph.Cis;
107 eph.i0 = gpseph.i0;
108 eph.Crc = gpseph.Crc;
109 eph.omega = gpseph.omega;
110 eph.OMEGADOT = gpseph.OMEGADOT;
111 eph.IDOT = gpseph.IDOT;
112
113 GPSS::gpcPutEphGPS(&eph);
114}
115
116//
117////////////////////////////////////////////////////////////////////////////
118void t_dllInterface::slotNewEphGlonass(glonassephemeris gloeph) {
119 QMutexLocker locker(&_mutex);
120
121 int wwUTC = gloeph.GPSWeek;
122 int towUTC = gloeph.GPSTOW;
123 updatetime(&wwUTC, &towUTC, gloeph.tb*1000, 1); // Moscow -> UTC
124 bncTime tUTC(wwUTC,towUTC);
125
126 int wwGPS = gloeph.GPSWeek;
127 int towGPS = gloeph.GPSTOW;
128 updatetime(&wwGPS, &towGPS, gloeph.tb*1000, 0); // Moscow -> GPS
129 bncTime tGPS(wwGPS,towGPS);
130
131 GPSS::gpcEphGLO eph;
132 eph.satSlotNumber = gloeph.almanac_number;
133 eph.mjdUTC = tUTC.mjd();
134 eph.secUTC = tUTC.daysec();
135 eph.gps_utc = tGPS - tUTC;
136 eph.tau = gloeph.tau;
137 eph.gamma = gloeph.gamma;
138 eph.x_pos = gloeph.x_pos;
139 eph.x_velocity = gloeph.x_velocity;
140 eph.x_acceleration = gloeph.x_acceleration;
141 eph.y_pos = gloeph.y_pos;
142 eph.y_velocity = gloeph.y_velocity;
143 eph.y_acceleration = gloeph.y_acceleration;
144 eph.z_pos = gloeph.z_pos;
145 eph.z_velocity = gloeph.z_velocity;
146 eph.z_acceleration = gloeph.z_acceleration;
147
148 GPSS::gpcPutEphGLO(&eph);
149}
150
151//
152////////////////////////////////////////////////////////////////////////////
153void t_dllInterface::slotNewEphGalileo(galileoephemeris /* galeph */) {
154 // not yet implemented
155}
156
157//
158////////////////////////////////////////////////////////////////////////////
159void t_dllInterface::slotNewCorrections(QList<QString> corrList) {
160 QMutexLocker locker(&_mutex);
161
162 // Check the Mountpoint (source of corrections)
163 // --------------------------------------------
164 if (!_pppCorrMount.isEmpty()) {
165 QMutableListIterator<QString> itm(corrList);
166 while (itm.hasNext()) {
167 QStringList hlp = itm.next().split(" ");
168 if (hlp.size() > 0) {
169 QString mountpoint = hlp[hlp.size()-1];
170 if (mountpoint != _pppCorrMount) {
171 itm.remove();
172 }
173 }
174 }
175 }
176
177 if (corrList.size() == 0) {
178 return;
179 }
180
181 QListIterator<QString> it(corrList);
182 while (it.hasNext()) {
183 QString line = it.next();
184
185 QTextStream in(&line);
186 int messageType;
187 int updateInterval;
188 int GPSweek;
189 double GPSweeks;
190 QString prn;
191 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
192
193 if ( t_corr::relevantMessageType(messageType) ) {
194 t_corr* cc = 0;
195 if (_corr.contains(prn)) {
196 cc = _corr.value(prn);
197 }
198 else {
199 cc = new t_corr();
200 _corr[prn] = cc;
201 }
202
203 cc->readLine(line);
204 }
205 }
206
207 QMapIterator<QString, t_corr*> ic(_corr);
208 while (ic.hasNext()) {
209 ic.next();
210 t_corr* cc = ic.value();
211 if (cc->ready()) {
212
213 GPSS::gpcCorr corr;
214 corr.satSys = cc->prn[0].toAscii();
215 corr.satNum = cc->prn.mid(1).toInt();
216 corr.GPSweek = cc->tt.gpsw();
217 corr.GPSweeks = cc->tt.gpssec();
218 corr.iod = cc->iod;
219 corr.dClk = cc->dClk;
220 corr.dotDClk = cc->dotDClk;
221 corr.dotDotDClk = cc->dotDotDClk;
222 corr.rao[0] = cc->rao[0];
223 corr.rao[1] = cc->rao[1];
224 corr.rao[2] = cc->rao[2];
225 corr.dotRao[0] = cc->dotRao[0];
226 corr.dotRao[1] = cc->dotRao[1];
227 corr.dotRao[2] = cc->dotRao[2];
228 corr.dotDotRao[0] = cc->dotDotRao[0];
229 corr.dotDotRao[1] = cc->dotDotRao[1];
230 corr.dotDotRao[2] = cc->dotDotRao[2];
231 corr.raoSet = cc->raoSet ? 1 : 0;
232 corr.dClkSet = cc->dClkSet ? 1 : 0;
233
234 GPSS::gpcPutCorr(&corr);
235 }
236 }
237
238}
239
240//
241////////////////////////////////////////////////////////////////////////////
242void t_dllInterface::putNewObs(const t_obs& obsIn) {
243 QMutexLocker locker(&_mutex);
244
245 bncTime obsTime(obsIn.GPSWeek, obsIn.GPSWeeks);
246
247 if (_epoch.size() != 0) {
248 bncTime epoTime(_epoch[0].GPSWeek, _epoch[0].GPSWeeks);
249 if (epoTime != obsTime) {
250 const GPSS::gpcObs* allObs[_epoch.size()];
251 for (unsigned iObs = 0; iObs < _epoch.size(); iObs++) {
252 t_obs& obs = _epoch[iObs];
253 GPSS::gpcObs* gpcObs = new GPSS::gpcObs();
254
255 gpcObs->satSys = obs.satSys;
256 gpcObs->satNum = obs.satNum;
257 gpcObs->slotNum = obs.slotNum;
258 gpcObs->GPSweek = obs.GPSWeek;
259 gpcObs->GPSweeks = obs.GPSWeeks;
260 gpcObs->C1 = obs.C1;
261 gpcObs->L1C = obs.L1C;
262 gpcObs->D1C = obs.D1C;
263 gpcObs->S1C = obs.S1C;
264 gpcObs->P1 = obs.P1;
265 gpcObs->L1P = obs.L1P;
266 gpcObs->D1P = obs.D1P;
267 gpcObs->S1P = obs.S1P;
268 gpcObs->C2 = obs.C2;
269 gpcObs->L2C = obs.L2C;
270 gpcObs->D2C = obs.D2C;
271 gpcObs->S2C = obs.S2C;
272 gpcObs->P2 = obs.P2;
273 gpcObs->L2P = obs.L2P;
274 gpcObs->D2P = obs.D2P;
275 gpcObs->S2P = obs.S2P;
276 gpcObs->C5 = obs.C5;
277 gpcObs->L5 = obs.L5;
278 gpcObs->D5 = obs.D5;
279 gpcObs->S5 = obs.S5;
280 gpcObs->slip_cnt_L1 = obs.slip_cnt_L1;
281 gpcObs->slip_cnt_L2 = obs.slip_cnt_L2;
282 gpcObs->slip_cnt_L5 = obs.slip_cnt_L5;
283
284 allObs[iObs] = gpcObs;
285 }
286
287 GPSS::gpcResult res;
288 GPSS::gpcProcessEpoch(_epoch.size(), allObs, &res);
289
290 for (unsigned iObs = 0; iObs < _epoch.size(); iObs++) {
291 delete allObs[iObs];
292 }
293
294 _epoch.clear();
295 }
296 }
297
298 t_obs newObs(obsIn);
299 _epoch.push_back(newObs);
300}
Note: See TracBrowser for help on using the repository browser.