source: ntrip/trunk/BNC/combination/bnccomb.cpp@ 2927

Last change on this file since 2927 was 2927, checked in by mervart, 13 years ago
File size: 6.7 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncComb
6 *
7 * Purpose: Combinations of Orbit/Clock Corrections
8 *
9 * Author: L. Mervart
10 *
11 * Created: 22-Jan-2011
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iomanip>
18
19#include "bnccomb.h"
20#include "bncapp.h"
21#include "cmbcaster.h"
22#include "bncsettings.h"
23
24using namespace std;
25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
28bncComb::bncComb() {
29
30 bncSettings settings;
31
32 QStringList combineStreams = settings.value("combineStreams").toStringList();
33
34 if (combineStreams.size() >= 2) {
35 QListIterator<QString> it(combineStreams);
36 while (it.hasNext()) {
37 QStringList hlp = it.next().split(" ");
38 cmbAC* newAC = new cmbAC();
39 newAC->mountPoint = hlp[0];
40 newAC->name = hlp[1];
41 newAC->weight = hlp[2].toDouble();
42
43 _ACs[newAC->mountPoint] = newAC;
44 }
45 }
46
47 _caster = new cmbCaster();
48}
49
50// Destructor
51////////////////////////////////////////////////////////////////////////////
52bncComb::~bncComb() {
53 QMapIterator<QString, cmbAC*> it(_ACs);
54 while (it.hasNext()) {
55 it.next();
56 delete it.value();
57 }
58 delete _caster;
59}
60
61//
62////////////////////////////////////////////////////////////////////////////
63void bncComb::processCorrLine(const QString& staID, const QString& line) {
64 QMutexLocker locker(&_mutex);
65
66 // Find the relevant instance of cmbAC class
67 // -----------------------------------------
68 if (_ACs.find(staID) == _ACs.end()) {
69 return;
70 }
71 cmbAC* AC = _ACs[staID];
72
73 // Read the Correction
74 // -------------------
75 t_corr* newCorr = new t_corr();
76 if (!newCorr->readLine(line) == success) {
77 delete newCorr;
78 return;
79 }
80
81 // Reject delayed corrections
82 // --------------------------
83 if (_processedBeforeTime.valid() && newCorr->tt < _processedBeforeTime) {
84 delete newCorr;
85 return;
86 }
87
88 // Process all older Epochs (if there are any)
89 // -------------------------------------------
90 const double waitTime = 5.0; // wait 5 sec
91 _processedBeforeTime = newCorr->tt - waitTime;
92
93 QList<cmbEpoch*> epochsToProcess;
94
95 QMapIterator<QString, cmbAC*> itAC(_ACs);
96 while (itAC.hasNext()) {
97 itAC.next();
98 cmbAC* AC = itAC.value();
99
100 QMutableListIterator<cmbEpoch*> itEpo(AC->epochs);
101 while (itEpo.hasNext()) {
102 cmbEpoch* epoch = itEpo.next();
103 if (epoch->time < _processedBeforeTime) {
104 epochsToProcess.append(epoch);
105 itEpo.remove();
106 }
107 }
108 }
109
110 if (epochsToProcess.size()) {
111 processEpochs(epochsToProcess);
112 }
113
114 // Check Modulo Time
115 // -----------------
116 const int moduloTime = 10;
117 if (int(newCorr->tt.gpssec()) % moduloTime != 0.0) {
118 delete newCorr;
119 return;
120 }
121
122 // Find/Create the instance of cmbEpoch class
123 // ------------------------------------------
124 cmbEpoch* newEpoch = 0;
125 QListIterator<cmbEpoch*> it(AC->epochs);
126 while (it.hasNext()) {
127 cmbEpoch* hlpEpoch = it.next();
128 if (hlpEpoch->time == newCorr->tt) {
129 newEpoch = hlpEpoch;
130 break;
131 }
132 }
133 if (newEpoch == 0) {
134 newEpoch = new cmbEpoch(AC->name);
135 newEpoch->time = newCorr->tt;
136 AC->epochs.append(newEpoch);
137 }
138
139 // Merge or add the correction
140 // ---------------------------
141 if (newEpoch->corr.find(newCorr->prn) != newEpoch->corr.end()) {
142 newEpoch->corr[newCorr->prn]->readLine(line); // merge (multiple messages)
143 }
144 else {
145 newEpoch->corr[newCorr->prn] = newCorr;
146 }
147}
148
149//
150////////////////////////////////////////////////////////////////////////////
151void bncComb::processEpochs(const QList<cmbEpoch*>& epochs) {
152
153 QListIterator<cmbEpoch*> itEpo(epochs);
154 while (itEpo.hasNext()) {
155 cmbEpoch* epo = itEpo.next();
156 QMapIterator<QString, t_corr*> itCorr(epo->corr);
157 while (itCorr.hasNext()) {
158 itCorr.next();
159 t_corr* corr = itCorr.value();
160 printSingleCorr(epo->acName, corr);
161 }
162 }
163
164 cout << "Corrections processed" << endl << endl;
165}
166
167//
168////////////////////////////////////////////////////////////////////////////
169void bncComb::printSingleCorr(const QString& acName, const t_corr* corr) {
170 cout.setf(ios::fixed);
171 cout << acName.toAscii().data() << " "
172 << corr->prn.toAscii().data() << " "
173 << corr->tt.timestr() << " "
174 << setw(4) << corr->iod << " "
175 << setw(8) << setprecision(4) << corr->dClk * t_CST::c << " "
176 << setw(8) << setprecision(4) << corr->rao[0] << " "
177 << setw(8) << setprecision(4) << corr->rao[1] << " "
178 << setw(8) << setprecision(4) << corr->rao[2] << endl;
179}
180
181// //
182// ////////////////////////////////////////////////////////////////////////////
183// void bncComb::printResults() const {
184//
185// // _caster->open();
186// //
187// // //// beg test
188// // cmbEpoch* resEpoch = 0;
189// // if (_ACs->find("CLK10") != _ACs->end()) {
190// // cmbAC* AC = _ACs["CLK10"];
191// // QMutableListIterator<cmbEpoch*> itEpo(AC->epochs);
192// // while (itEpo.hasNext()) {
193// //
194// //
195// // }
196// // //// end test
197//
198// struct ClockOrbit co;
199//
200// // memset(&co, 0, sizeof(co));
201// // co.GPSEpochTime = (int)_GPSweeks;
202// // co.GLONASSEpochTime = (int)fmod(_GPSweeks, 86400.0)
203// // + 3 * 3600 - gnumleap(_year, _month, _day);
204// // co.ClockDataSupplied = 1;
205// // co.OrbitDataSupplied = 1;
206// // co.SatRefDatum = DATUM_ITRF;
207// //
208// // // struct ClockOrbit::SatData* sd = 0;
209// // if (prn[0] == 'G') {
210// // sd = co.Sat + co.NumberOfGPSSat;
211// // ++co.NumberOfGPSSat;
212// // }
213// // else if (prn[0] == 'R') {
214// // sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfGLONASSSat;
215// // ++co.NumberOfGLONASSSat;
216// // }
217//
218// // sd->ID = prn.mid(1).toInt();
219// // sd->IOD = ep->IOD();
220// // sd->Clock.DeltaA0 = dClk;
221// // sd->Orbit.DeltaRadial = rsw(1);
222// // sd->Orbit.DeltaAlongTrack = rsw(2);
223// // sd->Orbit.DeltaCrossTrack = rsw(3);
224// // sd->Orbit.DotDeltaRadial = (rsw2(1) - rsw(1)) / xx(11);
225// // sd->Orbit.DotDeltaAlongTrack = (rsw2(2) - rsw(2)) / xx(11);
226// // sd->Orbit.DotDeltaCrossTrack = (rsw2(3) - rsw(3)) / xx(11);
227//
228// if ( _caster->usedSocket() &&
229// (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) ) {
230// char obuffer[CLOCKORBIT_BUFFERSIZE];
231// int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
232// if (len > 0) {
233// _caster->write(obuffer, len);
234// }
235// }
236//
237// cout << "Corrections processed" << endl << endl;
238//
239// }
Note: See TracBrowser for help on using the repository browser.