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

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

* empty log message *

File size: 3.2 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 = "localhost";
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 QByteArray line = _socket->readLine();
85
86 if (flagGlonass) {
87 if (ii == 4) {
88 delete ep;
89 return;
90 }
91 else {
92 continue;
93 }
94 }
95
96 QTextStream in(line);
97
98 if (ii == 1) {
99 in >> ep->prn;
100
101 if (ep->prn.indexOf('R') != -1) {
102 flagGlonass = true;
103 continue;
104 }
105
106 double year, month, day, hour, minute, second;
107 in >> year >> month >> day >> hour >> minute >> second
108 >> ep->clock_bias >> ep->clock_drift >> ep->clock_driftrate;
109
110 if (year < 100) year += 2000;
111
112 QDateTime dateTime(QDate(int(year), int(month), int(day)),
113 QTime(int(hour), int(minute), int(second)), Qt::UTC);
114 int week;
115 GPSweekFromDateAndTime(dateTime, week, ep->TOC);
116 ep->GPSweek = week;
117 }
118 else if (ii == 2) {
119 in >> ep->IODE >> ep->Crs >> ep->Delta_n >> ep->M0;
120 }
121 else if (ii == 3) {
122 in >> ep->Cuc >> ep->e >> ep->Cus >> ep->sqrt_A;
123 }
124 else if (ii == 4) {
125 in >> ep->TOE >> ep->Cic >> ep->OMEGA0 >> ep->Cis;
126 }
127 else if (ii == 5) {
128 in >> ep->i0 >> ep->Crc >> ep->omega >> ep->OMEGADOT;
129 }
130 else if (ii == 6) {
131 in >> ep->IDOT;
132 }
133 else if (ii == 7) {
134 double hlp, health;
135 in >> hlp >> health >> ep->TGD >> ep->IODC;
136 }
137 else if (ii == 8) {
138 in >> ep->TOW;
139 }
140 }
141
142 emit(newEph(ep));
143}
Note: See TracBrowser for help on using the repository browser.