source: ntrip/trunk/BNS/bnseph.cpp@ 838

Last change on this file since 838 was 838, checked in by mervart, 16 years ago

* empty log message *

File size: 3.4 KB
Line 
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
23using namespace std;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27t_bnseph::t_bnseph(QObject* parent) : QThread(parent) {
28 _socket = 0;
29}
30
31// Destructor
32////////////////////////////////////////////////////////////////////////////
33t_bnseph::~t_bnseph() {
34 delete _socket;
35}
36
37// Connect the Socket
38////////////////////////////////////////////////////////////////////////////
39void t_bnseph::reconnect() {
40
41 delete _socket;
42
43 QSettings settings;
44 QString host = "localhost";
45 int port = settings.value("ephPort").toInt();
46
47 _socket = new QTcpSocket();
48 _socket->connectToHost(host, port);
49
50 const int timeOut = 10*1000; // 10 seconds
51 if (!_socket->waitForConnected(timeOut)) {
52 emit(newMessage("bnseph::run Connect Timeout"));
53 }
54}
55
56// Start
57////////////////////////////////////////////////////////////////////////////
58void t_bnseph::run() {
59
60 emit(newMessage("bnseph::run Start"));
61
62 while (true) {
63 if (_socket == 0 || _socket->state() != QAbstractSocket::ConnectedState) {
64 reconnect();
65 }
66 if (_socket && _socket->state() == QAbstractSocket::ConnectedState) {
67 if (_socket->canReadLine()) {
68 readEph();
69 }
70 else {
71 _socket->waitForReadyRead(10);
72 }
73 }
74 else {
75 msleep(10);
76 }
77 }
78}
79
80// Read One Ephemeris
81////////////////////////////////////////////////////////////////////////////
82void t_bnseph::readEph() {
83
84 gpsEph* ep = new gpsEph;
85
86 bool flagGlonass = false;
87
88 const int NUMLINES = 8;
89
90 for (int ii = 1; ii <= NUMLINES; ii++) {
91
92 QByteArray line = _socket->readLine();
93
94 if (flagGlonass) {
95 if (ii == 4) {
96 delete ep;
97 return;
98 }
99 else {
100 continue;
101 }
102 }
103
104 QTextStream in(line);
105
106 if (ii == 1) {
107 in >> ep->prn;
108
109 if (ep->prn.indexOf('R') != -1) {
110 flagGlonass = true;
111 continue;
112 }
113
114 double year, month, day, hour, minute, second;
115 in >> year >> month >> day >> hour >> minute >> second
116 >> ep->clock_bias >> ep->clock_drift >> ep->clock_driftrate;
117
118 if (year < 100) year += 2000;
119
120 QDateTime dateTime(QDate(int(year), int(month), int(day)),
121 QTime(int(hour), int(minute), int(second)), Qt::UTC);
122 int week;
123 GPSweekFromDateAndTime(dateTime, week, ep->TOC);
124 ep->GPSweek = week;
125 }
126 else if (ii == 2) {
127 in >> ep->IODE >> ep->Crs >> ep->Delta_n >> ep->M0;
128 }
129 else if (ii == 3) {
130 in >> ep->Cuc >> ep->e >> ep->Cus >> ep->sqrt_A;
131 }
132 else if (ii == 4) {
133 in >> ep->TOE >> ep->Cic >> ep->OMEGA0 >> ep->Cis;
134 }
135 else if (ii == 5) {
136 in >> ep->i0 >> ep->Crc >> ep->omega >> ep->OMEGADOT;
137 }
138 else if (ii == 6) {
139 in >> ep->IDOT;
140 }
141 else if (ii == 7) {
142 double hlp, health;
143 in >> hlp >> health >> ep->TGD >> ep->IODC;
144 }
145 else if (ii == 8) {
146 in >> ep->TOW;
147 }
148 }
149
150 emit(newEph(ep));
151}
Note: See TracBrowser for help on using the repository browser.