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

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