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

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