-
Notifications
You must be signed in to change notification settings - Fork 10
/
gpsmanager.h
299 lines (233 loc) · 8.14 KB
/
gpsmanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#ifndef GPSMANAGER_H
#define GPSMANAGER_H
#include <QObject>
#include <QLabel>
#include <QMutex>
#include <QMutexLocker>
#include "qcustomplot.h"
#include "filenamegenerator.h"
// Shared Memory:
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "shm_gps.h"
#include "gpsGUI/qfi/qfi_EADI.h"
#include "gpsGUI/qfi/qfi_EHSI.h"
#include "gpsGUI/qfi/qfi_ASI.h"
#include "gpsGUI/qfi/qfi_VSI.h"
#include "gpsGUI/gpsnetwork.h"
#include "gpsGUI/qledlabel.h"
#include "gpsGUI/zupt.h"
#include "startupOptions.h"
struct utcTime {
int hour;
int minute;
int second;
float secondFloat;
QString UTCstr;
QString UTCValidityStr;
};
class gpsManager : public QObject
{
Q_OBJECT
const QString name = "lv:";
QThread *gpsThread;
gpsNetwork *gps;
gpsMessage m;
startupOptionsType options;
fileNameGenerator filenamegen;
void shmSetup();
bool shmValid = false;
shmGPSDataStruct *shm = NULL;
int shmFd = 0;
int currentSHMIndex = 0;
int priorSHMIndex = 0;
uint16_t shmCounter = 0;
zupt *zuptCommander = NULL;
QTimer zuptRetryTimer;
QString baseSaveDirectory;
QString gpsRecordingBinaryLogFilename;
bool createLoggingDirectory();
QTimer gpsReconnectTimer;
QString host;
int port;
QString gpsBinaryLogFilename;
// Update Frequency:
// data come in at 200 Hz
unsigned char updateLabelsInterval = 20;
unsigned char updatePlotsInverval = 90;
unsigned char updateAvionicsWidgetsInterval = 10;
// Status:
bool statusGNSSReceptionOk = true; // GNSS Info received on time or way too late
bool statusGNSSReceptionWarning = false; // GNSS Info received late
bool statusMessageDecodeOk = true; // message decoded ok
bool statusConnectedToGPS = true; // Connected at this time to the GPS unit
bool statusGPSHeartbeatOk = true; // Have received messages recently
bool statusGPSMessagesDropped = false; // true if messages being dropped
bool statusLinkStickyError = false; // stays true until cleared
bool statusTroubleStickyError = false; //
bool statusJustCleared = false; // True if we just cleared errors.
// Individual "now" errors which are made sticky by the process function:
// Algorithm Status 1:
bool navPhase = true; // warning
bool gpsReceived = true; // warning
bool gpsValid = true; // Error
bool gpsWaiting = false; // warning
bool gpsRejected = false; // Error
bool altitudeSaturation = false; // Error
bool speedSaturation = false; // Error
bool interpolationMissed = false; // Error
// Algorithm Status 2:
bool altitudeRejected = false; // Error
bool zuptActive = false; // Error
bool zuptOther = false; // Error, includes Valid, RotationMode, and RoValid
// Algorithm Status 3:
bool flashWriteError = false; // Error
bool flashEraseError = false; // Error
// INS System Status 1:
bool outputAFull = false; // Error
bool outputBFull = false; // Error
// INS System Status 2:
bool gpsDetected = true; // warning
// INS System Status 3:
bool systemReady = true; // warning
// Status Bits from the device:
// INS Algorithm Status
dword priorAlgorithmStatus1=0;
dword priorAlgorithmStatus2=0;
dword priorAlgorithmStatus3=0;
dword priorAlgorithmStatus4=0;
// INS System Status
dword priorSystemStatus1=0;
dword priorSystemStatus2=0;
dword priorSystemStatus3=0;
int consecutiveDecodeErrors = 0;
gpsQualityKinds gnssQualPrior = gpsQualityInvalid;
QString gnssQualStr = "";
QString gnssQualShortStr = "";
bool gnssAlignmentComplete = false;
QString gnssAlignmentPhase = "";
// Record 1 out of every 40 points for 5 Hz updates to plots
// therefore, for 90 seconds of data, we need 90*5 = 450 point vectors
uint16_t vecSize = 450;
uint16_t vecPosAltHeading = 0;
uint16_t vecPosPosition = 0;
uint16_t vecPosSpeed = 0;
void prepareVectors(); // resize
void prepareLEDs(); // initial state
void prepareLabels(); // initial state
void prepareGPS(); // thread connections
unsigned char getBit(dword d, unsigned char bit);
uint16_t msgsReceivedCount = 0;
// Heading
QVector<double> headingsMagnetic;
QVector<double> headingsCourse;
// Roll and Pitch:
QVector<double> rolls;
QVector<double> pitches;
// Position
QVector<double> lats;
QVector<double> longs;
QVector<double> alts;
// Speed
QVector<double> nVelos;
QVector<double> eVelos;
QVector<double> upVelos;
// Time axis:
QVector<double> timeAxis;
void updateUIelements();
void preparePlots();
void updatePlots();
void setTimeAxis(QCPAxis *x);
void setPlotTitle(QCustomPlot *p, QCPPlotTitle *t, QString title);
void setPlotColors(QCustomPlot *p, bool dark);
QTimer gpsMessageHeartbeat;
unsigned int hbErrorCount=0;
QElapsedTimer gnssStatusTime;
bool firstMessage;
void showStatusMessage(QString);
void processStatus();
void genStatusMessages();
QMutex messageMutex;
QStringList errorMessages;
QStringList warningMessages;
utcTime processUTCstamp(uint64_t t);
utcTime currentTime;
utcTime validityTime;
void updateLabel(QLabel *label, QString text);
void updateLED(QLedLabel *led, QLedLabel::State s);
// UI elements (set to NULL if unused):
QLedLabel *gpsLinkLED = NULL;
QLedLabel *gpsTroubleLED = NULL;
QCustomPlot *plotRollPitch = NULL;
QCustomPlot *plotHeading = NULL;
QCPPlotTitle *titleHeading = NULL;
bool usePlotTitle = false;
QCPPlotTitle *titleRollPitch = NULL;
QLabel *gpsLat = NULL;
QLabel *gpsLong = NULL;
QLabel *gpsAltitude = NULL;
QLabel *gpsUTCtime = NULL;
QLabel *gpsUTCdate = NULL;
QLabel *gpsUTCValidity = NULL;
QLabel *gpsGroundSpeed = NULL;
QLabel *gpsRateClimb = NULL;
QLabel *gpsHeading = NULL;
QLabel *gpsRoll = NULL;
QLabel *gpsPitch = NULL;
QLabel *gpsQuality = NULL;
QLabel *gpsAlignment = NULL;
// Avionics Widgets:
qfi_ASI *asi;
qfi_VSI *vsi;
qfi_EADI *eadi;
qfi_EHSI *ehsi;
public:
gpsManager(startupOptionsType opts);
~gpsManager();
void insertLEDs(QLedLabel *gpsLinkLED, QLedLabel *gpsTroubleLED);
void insertPlots(QCustomPlot *gpsRollPitchPlot, QCustomPlot *gpsHeadingPlot);
void insertLabels(QLabel *gpsLat, QLabel *gpsLong, QLabel *gpsAltitude,
QLabel *gpsUTCtime, QLabel *gpsUTCdate, QLabel *gpsUTCValidity,
QLabel *gpsGroundSpeed,
QLabel *gpsHeading, QLabel *gpsRoll, QLabel *gpsPitch,
QLabel *gpsQuality, QLabel *gpsAlignment,
QLabel *gpsRateClimb);
void insertAvionicsWidgets(qfi_ASI *asi, qfi_VSI *vsi,
qfi_EADI *eadi, qfi_EHSI *ehsi);
void prepareElements();
// no-effort logging elements:
double chk_longitude = 0;
double chk_latiitude = 0;
double chk_altitude = 0;
float chk_gndspeed = 0;
bool haveData = false;
public slots:
void initiateGPSConnection(QString host, int port, QString gpsBinaryLogFilename);
void initiateGPSDisconnect();
void handleGPSReconnectTimer();
void handleStartsecondaryLog(QString filename);
void handleStopSecondaryLog();
void receiveGPSMessage(gpsMessage m); // from GPS network thread
void clearStickyError();
void setPlotTheme(bool isDark);
signals:
void connectToGPS(QString host, int port, QString gpsBinaryLogFilename);
void startSecondaryLog(QString filename);
void gpsStatusMessage(QString statusMessage);
void gpsConnectionError(int errorNumber);
void stopSecondaryLog();
void disconnectFromGPS();
void getDebugInfo();
void statusMessagesSig(QStringList errorMessages,
QStringList warningMessages);
void turn_off_ZuPT(QString a7Host, int A7port);
private slots:
void handleGPSStatusMessage(QString message);
void handleGPSDataString(QString gpsString);
void handleGPSConnectionError(int error);
void handleGPSConnectionGood();
void handleGPSTimeout();
void handleZUpTRetryTimer();
};
#endif // GPSMANAGER_H