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

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

* empty log message *

File size: 3.3 KB
RevLine 
[758]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
[761]17#include <iostream>
[776]18#include <math.h>
[761]19
[758]20#include "bnseph.h"
[776]21#include "bnsutils.h"
[758]22
23using namespace std;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27t_bnseph::t_bnseph(QObject* parent) : QThread(parent) {
[759]28 _socket = 0;
[758]29}
30
31// Destructor
32////////////////////////////////////////////////////////////////////////////
33t_bnseph::~t_bnseph() {
[759]34 delete _socket;
[758]35}
36
37// Start
38////////////////////////////////////////////////////////////////////////////
39void t_bnseph::run() {
[759]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
[760]52 const int timeOut = 3*1000; // 3 seconds
[759]53 if (!_socket->waitForConnected(timeOut)) {
[760]54 emit(error("bnseph::run Connect Timeout"));
[759]55 }
[760]56 else {
57 while (true) {
[783]58 if (_socket->state() != QAbstractSocket::ConnectedState) {
59 emit(error("bnseph::not connected"));
60 break;
61 }
[760]62 if (_socket->canReadLine()) {
[771]63 readEph();
[760]64 }
65 else {
[796]66 _socket->waitForReadyRead(10);
[760]67 }
[759]68 }
69 }
[758]70}
71
[771]72// Read One Ephemeris
73////////////////////////////////////////////////////////////////////////////
74void t_bnseph::readEph() {
75
[778]76 gpsEph* ep = new gpsEph;
[771]77
[782]78 bool flagGlonass = false;
79
[781]80 const int NUMLINES = 8;
[771]81
[781]82 for (int ii = 1; ii <= NUMLINES; ii++) {
[771]83
[781]84 QByteArray line = _socket->readLine();
[782]85
86 if (flagGlonass) {
87 if (ii == 4) {
88 delete ep;
89 return;
90 }
91 else {
92 continue;
93 }
94 }
95
[781]96 QTextStream in(line);
[778]97
[781]98 if (ii == 1) {
[782]99 in >> ep->prn;
100
101 if (ep->prn.indexOf('R') != -1) {
102 flagGlonass = true;
103 continue;
104 }
105
[800]106 double year, month, day, hour, minute, second;
[782]107 in >> year >> month >> day >> hour >> minute >> second
[781]108 >> ep->clock_bias >> ep->clock_drift >> ep->clock_driftrate;
109
110 if (year < 100) year += 2000;
111
[805]112 QDateTime dateTime(QDate(int(year), int(month), int(day)),
113 QTime(int(hour), int(minute), int(second)), Qt::UTC);
[800]114 int week;
115 GPSweekFromDateAndTime(dateTime, week, ep->TOC);
116 ep->GPSweek = week;
[781]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) {
[800]131 in >> ep->IDOT;
[781]132 }
133 else if (ii == 7) {
[800]134 double hlp, health;
135 in >> hlp >> health >> ep->TGD >> ep->IODC;
[781]136 }
137 else if (ii == 8) {
138 in >> ep->TOW;
139 }
140 }
[773]141
[778]142 emit(newEph(ep));
[771]143}
Note: See TracBrowser for help on using the repository browser.