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 |
|
---|
19 | #include "bnseph.h"
|
---|
20 |
|
---|
21 | using namespace std;
|
---|
22 |
|
---|
23 | // Constructor
|
---|
24 | ////////////////////////////////////////////////////////////////////////////
|
---|
25 | t_bnseph::t_bnseph(QObject* parent) : QThread(parent) {
|
---|
26 | _socket = 0;
|
---|
27 | }
|
---|
28 |
|
---|
29 | // Destructor
|
---|
30 | ////////////////////////////////////////////////////////////////////////////
|
---|
31 | t_bnseph::~t_bnseph() {
|
---|
32 | delete _socket;
|
---|
33 | }
|
---|
34 |
|
---|
35 | // Start
|
---|
36 | ////////////////////////////////////////////////////////////////////////////
|
---|
37 | void t_bnseph::run() {
|
---|
38 |
|
---|
39 | emit(newMessage("bnseph::run Start"));
|
---|
40 |
|
---|
41 | // Connect the Socket
|
---|
42 | // ------------------
|
---|
43 | QSettings settings;
|
---|
44 | QString host = settings.value("ephHost").toString();
|
---|
45 | int port = settings.value("ephPort").toInt();
|
---|
46 |
|
---|
47 | _socket = new QTcpSocket();
|
---|
48 | _socket->connectToHost(host, port);
|
---|
49 |
|
---|
50 | const int timeOut = 3*1000; // 3 seconds
|
---|
51 | if (!_socket->waitForConnected(timeOut)) {
|
---|
52 | emit(error("bnseph::run Connect Timeout"));
|
---|
53 | }
|
---|
54 | else {
|
---|
55 | while (true) {
|
---|
56 | if (_socket->canReadLine()) {
|
---|
57 | readEph();
|
---|
58 | }
|
---|
59 | else {
|
---|
60 | _socket->waitForReadyRead(10);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | // Read One Ephemeris
|
---|
67 | ////////////////////////////////////////////////////////////////////////////
|
---|
68 | void t_bnseph::readEph() {
|
---|
69 |
|
---|
70 | gpsephemeris* ep = new gpsephemeris;
|
---|
71 |
|
---|
72 | QByteArray line = _socket->readLine();
|
---|
73 | QTextStream in1(line);
|
---|
74 |
|
---|
75 | QString prn;
|
---|
76 | int year, month, day, hour, minute, second;
|
---|
77 |
|
---|
78 | in1 >> prn >> year >> month >> day >> hour >> minute >> second
|
---|
79 | >> ep->clock_bias >> ep->clock_drift >> ep->clock_driftrate;
|
---|
80 |
|
---|
81 | QDate
|
---|
82 |
|
---|
83 |
|
---|
84 | line = _socket->readLine();
|
---|
85 | QTextStream in2(line);
|
---|
86 | in2 >> ep->IODE >> ep->Crs >> ep->Delta_n >> ep->M0;
|
---|
87 |
|
---|
88 | line = _socket->readLine();
|
---|
89 | QTextStream in3(line);
|
---|
90 | in3 >> ep->Cuc >> ep->e >> ep->Cus >> ep->sqrt_A;
|
---|
91 |
|
---|
92 | line = _socket->readLine();
|
---|
93 | QTextStream in4(line);
|
---|
94 | in4 >> ep->TOE >> ep->Cic >> ep->OMEGA0 >> ep->Cis;
|
---|
95 |
|
---|
96 | line = _socket->readLine();
|
---|
97 | QTextStream in5(line);
|
---|
98 | in5 >> ep->i0 >> ep->Crc >> ep->omega >> ep->OMEGADOT;
|
---|
99 |
|
---|
100 | line = _socket->readLine();
|
---|
101 | QTextStream in6(line);
|
---|
102 |
|
---|
103 | double dd;
|
---|
104 | int ii;
|
---|
105 | in6 >> ep->IDOT >> dd >> ep->GPSweek >> ii;
|
---|
106 |
|
---|
107 | line = _socket->readLine();
|
---|
108 | QTextStream in7(line);
|
---|
109 |
|
---|
110 | double hlp;
|
---|
111 | in7 >> hlp >> ep->SVhealth >> ep->TGD >> ep->IODC;
|
---|
112 |
|
---|
113 | line = _socket->readLine();
|
---|
114 | QTextStream in8(line);
|
---|
115 | in8 >> ep->TOW;
|
---|
116 | }
|
---|