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

Last change on this file since 2924 was 2924, checked in by mervart, 13 years ago
File size: 4.8 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 "bncsettings.h"
22
23using namespace std;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27bncComb::bncComb() {
28
29 bncSettings settings;
30
31 QStringList combineStreams = settings.value("combineStreams").toStringList();
32
33 if (combineStreams.size() >= 2) {
34 QListIterator<QString> it(combineStreams);
35 while (it.hasNext()) {
36 QStringList hlp = it.next().split(" ");
37 cmbAC* newAC = new cmbAC();
38 newAC->mountPoint = hlp[0];
39 newAC->name = hlp[1];
40 newAC->weight = hlp[2].toDouble();
41
42 _ACs[newAC->mountPoint] = newAC;
43 }
44 }
45}
46
47// Destructor
48////////////////////////////////////////////////////////////////////////////
49bncComb::~bncComb() {
50 QMapIterator<QString, cmbAC*> it(_ACs);
51 while (it.hasNext()) {
52 it.next();
53 delete it.value();
54 }
55}
56
57//
58////////////////////////////////////////////////////////////////////////////
59void bncComb::processCorrLine(const QString& staID, const QString& line) {
60 QMutexLocker locker(&_mutex);
61
62 // Find the relevant instance of cmbAC class
63 // -----------------------------------------
64 if (_ACs.find(staID) == _ACs.end()) {
65 return;
66 }
67 cmbAC* AC = _ACs[staID];
68
69 // Read the Correction
70 // -------------------
71 t_corr* newCorr = new t_corr();
72 if (!newCorr->readLine(line) == success) {
73 delete newCorr;
74 return;
75 }
76
77 // Reject delayed corrections
78 // --------------------------
79 if (_processedBeforeTime.valid() && newCorr->tt < _processedBeforeTime) {
80 delete newCorr;
81 return;
82 }
83
84 // Process all older Epochs (if there are any)
85 // -------------------------------------------
86 const double waitTime = 5.0; // wait 5 sec
87 _processedBeforeTime = newCorr->tt - waitTime;
88 processEpochs();
89
90 // Check Modulo Time
91 // -----------------
92 const int moduloTime = 10;
93 if (int(newCorr->tt.gpssec()) % moduloTime != 0.0) {
94 delete newCorr;
95 return;
96 }
97
98 // Find/Create the instance of cmbEpoch class
99 // ------------------------------------------
100 cmbEpoch* newEpoch = 0;
101 QListIterator<cmbEpoch*> it(AC->epochs);
102 while (it.hasNext()) {
103 cmbEpoch* hlpEpoch = it.next();
104 if (hlpEpoch->time == newCorr->tt) {
105 newEpoch = hlpEpoch;
106 break;
107 }
108 }
109 if (newEpoch == 0) {
110 newEpoch = new cmbEpoch();
111 newEpoch->time = newCorr->tt;
112 AC->epochs.append(newEpoch);
113 }
114
115 // Merge or add the correction
116 // ---------------------------
117 if (newEpoch->corr.find(newCorr->prn) != newEpoch->corr.end()) {
118 newEpoch->corr[newCorr->prn]->readLine(line); // merge (multiple messages)
119 }
120 else {
121 newEpoch->corr[newCorr->prn] = newCorr;
122 }
123}
124
125//
126////////////////////////////////////////////////////////////////////////////
127void bncComb::processEpochs() {
128
129 bool corrProcessed = false;
130
131 QMapIterator<QString, cmbAC*> itAC(_ACs);
132 while (itAC.hasNext()) {
133 itAC.next();
134 cmbAC* AC = itAC.value();
135
136 QMutableListIterator<cmbEpoch*> itEpo(AC->epochs);
137 while (itEpo.hasNext()) {
138 cmbEpoch* epoch = itEpo.next();
139 if (epoch->time < _processedBeforeTime) {
140 QMapIterator<QString, t_corr*> itCorr(epoch->corr);
141 while (itCorr.hasNext()) {
142 itCorr.next();
143 t_corr* corr = itCorr.value();
144 processSingleCorr(AC, corr);
145 corrProcessed = true;
146 }
147 delete epoch;
148 itEpo.remove();
149 }
150 }
151 }
152
153 if (corrProcessed) {
154 printResults();
155 }
156}
157
158//
159////////////////////////////////////////////////////////////////////////////
160void bncComb::processSingleCorr(const cmbAC* AC, const t_corr* corr) {
161 cout.setf(ios::fixed);
162 cout << AC->name.toAscii().data() << " "
163 << AC->mountPoint.toAscii().data() << " "
164 << corr->prn.toAscii().data() << " "
165 << corr->tt.timestr() << " "
166 << setw(4) << corr->iod << " "
167 << setw(8) << setprecision(4) << corr->dClk * t_CST::c << " "
168 << setw(8) << setprecision(4) << corr->rao[0] << " "
169 << setw(8) << setprecision(4) << corr->rao[1] << " "
170 << setw(8) << setprecision(4) << corr->rao[2] << endl;
171}
172
173//
174////////////////////////////////////////////////////////////////////////////
175void bncComb::printResults() const {
176
177 cout << "Corrections processed" << endl << endl;
178
179}
Note: See TracBrowser for help on using the repository browser.