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

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

* empty log message *

File size: 2.9 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->canReadLine()) {
59 readEph();
60 }
61 else {
62 _socket->waitForReadyRead(10);
63 }
64 }
65 }
66}
67
68// Read One Ephemeris
69////////////////////////////////////////////////////////////////////////////
70void t_bnseph::readEph() {
71
72 gpsEph* ep = new gpsEph;
73
74 QByteArray line = _socket->readLine();
75 QTextStream in1(line);
76
77 int year, month, day, hour, minute, second;
78
79 in1 >> ep->prn >> year >> month >> day >> hour >> minute >> second
80 >> ep->clock_bias >> ep->clock_drift >> ep->clock_driftrate;
81
82 if (year < 100) year += 2000;
83
84 QDateTime dateTime(QDate(year,month,day), QTime(hour, minute, second),
85 Qt::UTC);
86 double toc;
87 GPSweekFromDateAndTime(dateTime, ep->GPSweek, toc);
88 ep->TOC = int(floor(toc+0.5));
89
90 line = _socket->readLine();
91 QTextStream in2(line);
92 in2 >> ep->IODE >> ep->Crs >> ep->Delta_n >> ep->M0;
93
94 line = _socket->readLine();
95 QTextStream in3(line);
96 in3 >> ep->Cuc >> ep->e >> ep->Cus >> ep->sqrt_A;
97
98 line = _socket->readLine();
99 QTextStream in4(line);
100 in4 >> ep->TOE >> ep->Cic >> ep->OMEGA0 >> ep->Cis;
101
102 line = _socket->readLine();
103 QTextStream in5(line);
104 in5 >> ep->i0 >> ep->Crc >> ep->omega >> ep->OMEGADOT;
105
106 line = _socket->readLine();
107 QTextStream in6(line);
108
109 double dd;
110 int GPSweek;
111 int ii;
112 in6 >> ep->IDOT >> dd >> GPSweek >> ii;
113
114 line = _socket->readLine();
115 QTextStream in7(line);
116
117 double hlp;
118 double health;
119 in7 >> hlp >> health >> ep->TGD >> ep->IODC;
120
121 line = _socket->readLine();
122 QTextStream in8(line);
123 in8 >> ep->TOW;
124
125 emit(newEph(ep));
126}
Note: See TracBrowser for help on using the repository browser.