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

Last change on this file since 796 was 796, 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 cout << "readEph" << endl;
64 readEph();
65 }
66 else {
67 _socket->waitForReadyRead(10);
68 }
69 }
70 }
71}
72
73// Read One Ephemeris
74////////////////////////////////////////////////////////////////////////////
75void t_bnseph::readEph() {
76
77 gpsEph* ep = new gpsEph;
78
79 bool flagGlonass = false;
80
81 const int NUMLINES = 8;
82
83 for (int ii = 1; ii <= NUMLINES; ii++) {
84
85 QByteArray line = _socket->readLine();
86
87 cout << line.data();
88
89 if (flagGlonass) {
90 if (ii == 4) {
91 delete ep;
92 return;
93 }
94 else {
95 continue;
96 }
97 }
98
99 QTextStream in(line);
100
101 if (ii == 1) {
102 in >> ep->prn;
103
104 if (ep->prn.indexOf('R') != -1) {
105 flagGlonass = true;
106 continue;
107 }
108
109 int year, month, day, hour, minute, second;
110 in >> year >> month >> day >> hour >> minute >> second
111 >> ep->clock_bias >> ep->clock_drift >> ep->clock_driftrate;
112
113 if (year < 100) year += 2000;
114
115 QDateTime dateTime(QDate(year,month,day), QTime(hour, minute, second),
116 Qt::UTC);
117 double toc;
118 GPSweekFromDateAndTime(dateTime, ep->GPSweek, toc);
119 ep->TOC = int(floor(toc+0.5));
120 }
121 else if (ii == 2) {
122 in >> ep->IODE >> ep->Crs >> ep->Delta_n >> ep->M0;
123 }
124 else if (ii == 3) {
125 in >> ep->Cuc >> ep->e >> ep->Cus >> ep->sqrt_A;
126 }
127 else if (ii == 4) {
128 in >> ep->TOE >> ep->Cic >> ep->OMEGA0 >> ep->Cis;
129 }
130 else if (ii == 5) {
131 in >> ep->i0 >> ep->Crc >> ep->omega >> ep->OMEGADOT;
132 }
133 else if (ii == 6) {
134 double dd;
135 int GPSweek;
136 int ii;
137 in >> ep->IDOT >> dd >> GPSweek >> ii;
138 }
139 else if (ii == 7) {
140 double hlp;
141 double health;
142 in >> hlp >> health >> ep->TGD >> ep->IODC;
143 }
144 else if (ii == 8) {
145 in >> ep->TOW;
146 }
147 }
148
149 emit(newEph(ep));
150}
Note: See TracBrowser for help on using the repository browser.