1 |
|
---|
2 | #include <iostream>
|
---|
3 | #include <string.h>
|
---|
4 |
|
---|
5 | #include "bncrtrover.h"
|
---|
6 | #include "bncapp.h"
|
---|
7 | #include "bncsettings.h"
|
---|
8 | #include "bnctime.h"
|
---|
9 |
|
---|
10 | #include "rtrover_interface.h"
|
---|
11 |
|
---|
12 | using namespace std;
|
---|
13 |
|
---|
14 | // Constructor
|
---|
15 | ////////////////////////////////////////////////////////////////////////////
|
---|
16 | t_bncRtrover::t_bncRtrover() : QThread(0) {
|
---|
17 | }
|
---|
18 |
|
---|
19 | // Destructor
|
---|
20 | ////////////////////////////////////////////////////////////////////////////
|
---|
21 | t_bncRtrover::~t_bncRtrover() {
|
---|
22 | rtrover_destroy();
|
---|
23 | }
|
---|
24 |
|
---|
25 | // Run (virtual)
|
---|
26 | ////////////////////////////////////////////////////////////////////////////
|
---|
27 | void t_bncRtrover::run() {
|
---|
28 | bncSettings settings;
|
---|
29 |
|
---|
30 | // User Options
|
---|
31 | // ------------
|
---|
32 | _mode = settings.value("rtroverMode").toByteArray();
|
---|
33 | _roverMount = settings.value("rtroverRoverMount").toByteArray();
|
---|
34 | _baseMount = settings.value("rtroverBaseMount").toByteArray();
|
---|
35 | _corrMount = settings.value("rtroverCorrMount").toByteArray();
|
---|
36 | _outputFile.setFileName(settings.value("rtroverOutput").toString());
|
---|
37 | _outputFile.open(QIODevice::WriteOnly | QIODevice::Text);
|
---|
38 |
|
---|
39 | // Define Input Options
|
---|
40 | // --------------------
|
---|
41 | rtrover_opt opt;
|
---|
42 | opt._roverName = strdup(_roverMount.data());
|
---|
43 | opt._baseName = strdup(_baseMount.data());
|
---|
44 | opt._xyzAprRover[0] = settings.value("rtroverRoverRefCrdX").toDouble();
|
---|
45 | opt._xyzAprRover[1] = settings.value("rtroverRoverRefCrdY").toDouble();
|
---|
46 | opt._xyzAprRover[2] = settings.value("rtroverRoverRefCrdZ").toDouble();
|
---|
47 | opt._xyzAprBase[0] = settings.value("rtroverBaseRefCrdX").toDouble();
|
---|
48 | opt._xyzAprBase[1] = settings.value("rtroverBaseRefCrdY").toDouble();
|
---|
49 | opt._xyzAprBase[2] = settings.value("rtroverBaseRefCrdZ").toDouble();
|
---|
50 | opt._sigmaPhase = 0.002; // TODO
|
---|
51 | opt._sigmaCode = 2.0; // TODO
|
---|
52 | rtrover_setOptions(&opt);
|
---|
53 |
|
---|
54 | // Connect to BNC Signals
|
---|
55 | // ----------------------
|
---|
56 | connect(((bncApp*)qApp), SIGNAL(newCorrections(QList<QString>)),
|
---|
57 | this, SLOT(slotNewCorrections(QList<QString>)));
|
---|
58 |
|
---|
59 | connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
|
---|
60 | this, SLOT(slotNewEphGPS(gpsephemeris)));
|
---|
61 |
|
---|
62 | connect(((bncApp*)qApp), SIGNAL(newEphGlonass(glonassephemeris)),
|
---|
63 | this, SLOT(slotNewEphGlonass(glonassephemeris)));
|
---|
64 |
|
---|
65 | connect(((bncApp*)qApp), SIGNAL(newEphGalileo(galileoephemeris)),
|
---|
66 | this, SLOT(slotNewEphGalileo(galileoephemeris)));
|
---|
67 |
|
---|
68 | // Start processing loop
|
---|
69 | // ---------------------
|
---|
70 | QThread::exec();
|
---|
71 | }
|
---|
72 |
|
---|
73 | //
|
---|
74 | ////////////////////////////////////////////////////////////////////////////
|
---|
75 | void t_bncRtrover::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
76 | QMutexLocker locker(&_mutex);
|
---|
77 |
|
---|
78 | bncTime toc(gpseph.GPSweek, gpseph.TOC);
|
---|
79 | bncTime toe(gpseph.GPSweek, gpseph.TOE);
|
---|
80 |
|
---|
81 | rtrover_ephGPS eph;
|
---|
82 | eph._satellite._system = 'G';
|
---|
83 | eph._satellite._number = gpseph.satellite;
|
---|
84 | eph._TOC._mjd = toc.mjd();
|
---|
85 | eph._TOC._sec = toc.daysec();
|
---|
86 | eph._TOE._mjd = toe.mjd();
|
---|
87 | eph._TOE._sec = toe.daysec();
|
---|
88 | eph._IODE = gpseph.IODE;
|
---|
89 | eph._IODC = gpseph.IODC;
|
---|
90 | eph._clock_bias = gpseph.clock_bias;
|
---|
91 | eph._clock_drift = gpseph.clock_drift;
|
---|
92 | eph._clock_driftrate = gpseph.clock_driftrate;
|
---|
93 | eph._Crs = gpseph.Crs;
|
---|
94 | eph._Delta_n = gpseph.Delta_n;
|
---|
95 | eph._M0 = gpseph.M0;
|
---|
96 | eph._Cuc = gpseph.Cuc;
|
---|
97 | eph._e = gpseph.e;
|
---|
98 | eph._Cus = gpseph.Cus;
|
---|
99 | eph._sqrt_A = gpseph.sqrt_A;
|
---|
100 | eph._Cic = gpseph.Cic;
|
---|
101 | eph._OMEGA0 = gpseph.OMEGA0;
|
---|
102 | eph._Cis = gpseph.Cis;
|
---|
103 | eph._i0 = gpseph.i0;
|
---|
104 | eph._Crc = gpseph.Crc;
|
---|
105 | eph._omega = gpseph.omega;
|
---|
106 | eph._OMEGADOT = gpseph.OMEGADOT;
|
---|
107 | eph._IDOT = gpseph.IDOT;
|
---|
108 | eph._TGD = gpseph.TGD;
|
---|
109 | eph._health = gpseph.SVhealth;
|
---|
110 |
|
---|
111 | rtrover_putGPSEphemeris(&eph);
|
---|
112 | }
|
---|
113 |
|
---|
114 | //
|
---|
115 | ////////////////////////////////////////////////////////////////////////////
|
---|
116 | void t_bncRtrover::slotNewEphGlonass(glonassephemeris gloeph) {
|
---|
117 | QMutexLocker locker(&_mutex);
|
---|
118 |
|
---|
119 | int wwUTC = gloeph.GPSWeek;
|
---|
120 | int towUTC = gloeph.GPSTOW;
|
---|
121 | updatetime(&wwUTC, &towUTC, gloeph.tb*1000, 1); // Moscow -> UTC
|
---|
122 | bncTime tUTC(wwUTC,towUTC);
|
---|
123 |
|
---|
124 | int wwGPS = gloeph.GPSWeek;
|
---|
125 | int towGPS = gloeph.GPSTOW;
|
---|
126 | updatetime(&wwGPS, &towGPS, gloeph.tb*1000, 0); // Moscow -> GPS
|
---|
127 | bncTime tGPS(wwGPS,towGPS);
|
---|
128 |
|
---|
129 | rtrover_ephGlo eph;
|
---|
130 | eph._satellite._system = 'R';
|
---|
131 | eph._satellite._number = gloeph.almanac_number;
|
---|
132 | eph._timeUTC._mjd = tUTC.mjd();
|
---|
133 | eph._timeUTC._sec = tUTC.daysec();
|
---|
134 | eph._gps_utc = int(tGPS-tUTC);
|
---|
135 | eph._E = gloeph.E;
|
---|
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 | eph._health = 0; // TODO ?
|
---|
148 | eph._frequency_number = gloeph.frequency_number;
|
---|
149 |
|
---|
150 | rtrover_putGloEphemeris(&eph);
|
---|
151 | }
|
---|
152 |
|
---|
153 | //
|
---|
154 | ////////////////////////////////////////////////////////////////////////////
|
---|
155 | void t_bncRtrover::slotNewEphGalileo(galileoephemeris /* galeph */) {
|
---|
156 | // not yet implemented
|
---|
157 | }
|
---|
158 |
|
---|
159 | //
|
---|
160 | ////////////////////////////////////////////////////////////////////////////
|
---|
161 | void t_bncRtrover::slotNewCorrections(QList<QString> corrList) {
|
---|
162 | QMutexLocker locker(&_mutex);
|
---|
163 |
|
---|
164 | // Check the Mountpoint (source of corrections)
|
---|
165 | // --------------------------------------------
|
---|
166 | QMutableListIterator<QString> itm(corrList);
|
---|
167 | while (itm.hasNext()) {
|
---|
168 | QStringList hlp = itm.next().split(" ");
|
---|
169 | if (hlp.size() > 0) {
|
---|
170 | QString mountpoint = hlp[hlp.size()-1];
|
---|
171 | if (mountpoint != _corrMount) {
|
---|
172 | itm.remove();
|
---|
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 | }
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | //
|
---|
199 | ////////////////////////////////////////////////////////////////////////////
|
---|
200 | void t_bncRtrover::slotNewObs(QByteArray staID, bool /* firstObs */, t_obs obsIn) {
|
---|
201 | QMutexLocker locker(&_mutex);
|
---|
202 |
|
---|
203 | if (staID != _roverMount && staID != _baseMount) {
|
---|
204 | return;
|
---|
205 | }
|
---|
206 |
|
---|
207 | bncTime obsTime(obsIn.GPSWeek, obsIn.GPSWeeks);
|
---|
208 | int numSatRover = 1;
|
---|
209 | rtrover_satObs satObsRover[numSatRover];
|
---|
210 | for (int ii = 0; ii < numSatRover; ii++) {
|
---|
211 |
|
---|
212 | }
|
---|
213 | rtrover_output output;
|
---|
214 | rtrover_processEpoch(numSatRover, satObsRover, 0, 0, &output);
|
---|
215 |
|
---|
216 | _outputFile.write(output._log);
|
---|
217 | _outputFile.flush();
|
---|
218 | }
|
---|