1 | /* -------------------------------------------------------------------------
|
---|
2 | * BKG NTRIP Server
|
---|
3 | * -------------------------------------------------------------------------
|
---|
4 | *
|
---|
5 | * Class: bnseph
|
---|
6 | *
|
---|
7 | * Purpose: Retrieve broadcast ephemeris from BNC
|
---|
8 | *
|
---|
9 | * Author: L. Mervart
|
---|
10 | *
|
---|
11 | * Created: 29-Mar-2008
|
---|
12 | *
|
---|
13 | * Changes:
|
---|
14 | *
|
---|
15 | * -----------------------------------------------------------------------*/
|
---|
16 |
|
---|
17 | #include <iostream>
|
---|
18 | #include <math.h>
|
---|
19 |
|
---|
20 | #include "bnseph.h"
|
---|
21 | #include "bnsutils.h"
|
---|
22 |
|
---|
23 | using namespace std;
|
---|
24 |
|
---|
25 | // Constructor
|
---|
26 | ////////////////////////////////////////////////////////////////////////////
|
---|
27 | t_bnseph::t_bnseph(QObject* parent) : QThread(parent) {
|
---|
28 |
|
---|
29 | QSettings settings;
|
---|
30 | QString host = "localhost";
|
---|
31 | int port = settings.value("ephPort").toInt();
|
---|
32 |
|
---|
33 | _socket = new QTcpSocket();
|
---|
34 | _socket->connectToHost(host, port);
|
---|
35 |
|
---|
36 | const int timeOut = 3*1000; // 3 seconds
|
---|
37 | if (!_socket->waitForConnected(timeOut)) {
|
---|
38 | emit(error("bnseph::run Connect Timeout"));
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | // Destructor
|
---|
43 | ////////////////////////////////////////////////////////////////////////////
|
---|
44 | t_bnseph::~t_bnseph() {
|
---|
45 | delete _socket;
|
---|
46 | }
|
---|
47 |
|
---|
48 | // Start
|
---|
49 | ////////////////////////////////////////////////////////////////////////////
|
---|
50 | void t_bnseph::run() {
|
---|
51 |
|
---|
52 | emit(newMessage("bnseph::run Start"));
|
---|
53 |
|
---|
54 | while (true) {
|
---|
55 | if (_socket->state() != QAbstractSocket::ConnectedState) {
|
---|
56 | emit(error("bnseph::not connected"));
|
---|
57 | break;
|
---|
58 | }
|
---|
59 | if (_socket->canReadLine()) {
|
---|
60 | readEph();
|
---|
61 | }
|
---|
62 | else {
|
---|
63 | _socket->waitForReadyRead(10);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | // Read One Ephemeris
|
---|
69 | ////////////////////////////////////////////////////////////////////////////
|
---|
70 | void t_bnseph::readEph() {
|
---|
71 |
|
---|
72 | gpsEph* ep = new gpsEph;
|
---|
73 |
|
---|
74 | bool flagGlonass = false;
|
---|
75 |
|
---|
76 | const int NUMLINES = 8;
|
---|
77 |
|
---|
78 | for (int ii = 1; ii <= NUMLINES; ii++) {
|
---|
79 |
|
---|
80 | QByteArray line = _socket->readLine();
|
---|
81 |
|
---|
82 | if (flagGlonass) {
|
---|
83 | if (ii == 4) {
|
---|
84 | delete ep;
|
---|
85 | return;
|
---|
86 | }
|
---|
87 | else {
|
---|
88 | continue;
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | QTextStream in(line);
|
---|
93 |
|
---|
94 | if (ii == 1) {
|
---|
95 | in >> ep->prn;
|
---|
96 |
|
---|
97 | if (ep->prn.indexOf('R') != -1) {
|
---|
98 | flagGlonass = true;
|
---|
99 | continue;
|
---|
100 | }
|
---|
101 |
|
---|
102 | double year, month, day, hour, minute, second;
|
---|
103 | in >> year >> month >> day >> hour >> minute >> second
|
---|
104 | >> ep->clock_bias >> ep->clock_drift >> ep->clock_driftrate;
|
---|
105 |
|
---|
106 | if (year < 100) year += 2000;
|
---|
107 |
|
---|
108 | QDateTime dateTime(QDate(int(year), int(month), int(day)),
|
---|
109 | QTime(int(hour), int(minute), int(second)), Qt::UTC);
|
---|
110 | int week;
|
---|
111 | GPSweekFromDateAndTime(dateTime, week, ep->TOC);
|
---|
112 | ep->GPSweek = week;
|
---|
113 | }
|
---|
114 | else if (ii == 2) {
|
---|
115 | in >> ep->IODE >> ep->Crs >> ep->Delta_n >> ep->M0;
|
---|
116 | }
|
---|
117 | else if (ii == 3) {
|
---|
118 | in >> ep->Cuc >> ep->e >> ep->Cus >> ep->sqrt_A;
|
---|
119 | }
|
---|
120 | else if (ii == 4) {
|
---|
121 | in >> ep->TOE >> ep->Cic >> ep->OMEGA0 >> ep->Cis;
|
---|
122 | }
|
---|
123 | else if (ii == 5) {
|
---|
124 | in >> ep->i0 >> ep->Crc >> ep->omega >> ep->OMEGADOT;
|
---|
125 | }
|
---|
126 | else if (ii == 6) {
|
---|
127 | in >> ep->IDOT;
|
---|
128 | }
|
---|
129 | else if (ii == 7) {
|
---|
130 | double hlp, health;
|
---|
131 | in >> hlp >> health >> ep->TGD >> ep->IODC;
|
---|
132 | }
|
---|
133 | else if (ii == 8) {
|
---|
134 | in >> ep->TOW;
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | emit(newEph(ep));
|
---|
139 | }
|
---|