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

Last change on this file since 776 was 776, 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 gpsephemeris* ep = new gpsephemeris;
73
74 QByteArray line = _socket->readLine();
75 QTextStream in1(line);
76
77 QString prn;
78 int year, month, day, hour, minute, second;
79
80 in1 >> prn >> year >> month >> day >> hour >> minute >> second
81 >> ep->clock_bias >> ep->clock_drift >> ep->clock_driftrate;
82
83 QDateTime dateTime(QDate(year,month,day), QTime(hour, minute, second),
84 Qt::UTC);
85 double toc;
86 GPSweekFromDateAndTime(dateTime, ep->GPSweek, toc);
87 ep->TOC = int(floor(toc+0.5));
88
89 line = _socket->readLine();
90 QTextStream in2(line);
91 in2 >> ep->IODE >> ep->Crs >> ep->Delta_n >> ep->M0;
92
93 line = _socket->readLine();
94 QTextStream in3(line);
95 in3 >> ep->Cuc >> ep->e >> ep->Cus >> ep->sqrt_A;
96
97 line = _socket->readLine();
98 QTextStream in4(line);
99 in4 >> ep->TOE >> ep->Cic >> ep->OMEGA0 >> ep->Cis;
100
101 line = _socket->readLine();
102 QTextStream in5(line);
103 in5 >> ep->i0 >> ep->Crc >> ep->omega >> ep->OMEGADOT;
104
105 line = _socket->readLine();
106 QTextStream in6(line);
107
108 double dd;
109 int ii;
110 in6 >> ep->IDOT >> dd >> ep->GPSweek >> ii;
111
112 line = _socket->readLine();
113 QTextStream in7(line);
114
115 double hlp;
116 in7 >> hlp >> ep->SVhealth >> ep->TGD >> ep->IODC;
117
118 line = _socket->readLine();
119 QTextStream in8(line);
120 in8 >> ep->TOW;
121}
Note: See TracBrowser for help on using the repository browser.