[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>
|
---|
| 18 |
|
---|
[758] | 19 | #include "bnseph.h"
|
---|
| 20 |
|
---|
| 21 | using namespace std;
|
---|
| 22 |
|
---|
| 23 | // Constructor
|
---|
| 24 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 25 | t_bnseph::t_bnseph(QObject* parent) : QThread(parent) {
|
---|
[759] | 26 | _socket = 0;
|
---|
[758] | 27 | }
|
---|
| 28 |
|
---|
| 29 | // Destructor
|
---|
| 30 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 31 | t_bnseph::~t_bnseph() {
|
---|
[759] | 32 | delete _socket;
|
---|
[758] | 33 | }
|
---|
| 34 |
|
---|
| 35 | // Start
|
---|
| 36 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 37 | void t_bnseph::run() {
|
---|
[759] | 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 |
|
---|
[760] | 50 | const int timeOut = 3*1000; // 3 seconds
|
---|
[759] | 51 | if (!_socket->waitForConnected(timeOut)) {
|
---|
[760] | 52 | emit(error("bnseph::run Connect Timeout"));
|
---|
[759] | 53 | }
|
---|
[760] | 54 | else {
|
---|
| 55 | while (true) {
|
---|
| 56 | if (_socket->canReadLine()) {
|
---|
[771] | 57 | readEph();
|
---|
[760] | 58 | }
|
---|
| 59 | else {
|
---|
| 60 | _socket->waitForReadyRead(10);
|
---|
| 61 | }
|
---|
[759] | 62 | }
|
---|
| 63 | }
|
---|
[758] | 64 | }
|
---|
| 65 |
|
---|
[771] | 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 |
|
---|
[773] | 81 |
|
---|
[771] | 82 | line = _socket->readLine();
|
---|
| 83 | QTextStream in2(line);
|
---|
| 84 | in2 >> ep->IODE >> ep->Crs >> ep->Delta_n >> ep->M0;
|
---|
| 85 |
|
---|
| 86 | line = _socket->readLine();
|
---|
| 87 | QTextStream in3(line);
|
---|
| 88 | in3 >> ep->Cuc >> ep->e >> ep->Cus >> ep->sqrt_A;
|
---|
| 89 |
|
---|
| 90 | line = _socket->readLine();
|
---|
| 91 | QTextStream in4(line);
|
---|
| 92 | in4 >> ep->TOE >> ep->Cic >> ep->OMEGA0 >> ep->Cis;
|
---|
| 93 |
|
---|
| 94 | line = _socket->readLine();
|
---|
| 95 | QTextStream in5(line);
|
---|
| 96 | in5 >> ep->i0 >> ep->Crc >> ep->omega >> ep->OMEGADOT;
|
---|
| 97 |
|
---|
| 98 | line = _socket->readLine();
|
---|
| 99 | QTextStream in6(line);
|
---|
| 100 |
|
---|
| 101 | double dd;
|
---|
| 102 | int ii;
|
---|
| 103 | in6 >> ep->IDOT >> dd >> ep->GPSweek >> ii;
|
---|
| 104 |
|
---|
| 105 | line = _socket->readLine();
|
---|
| 106 | QTextStream in7(line);
|
---|
| 107 |
|
---|
| 108 | double hlp;
|
---|
| 109 | in7 >> hlp >> ep->SVhealth >> ep->TGD >> ep->IODC;
|
---|
| 110 |
|
---|
| 111 | line = _socket->readLine();
|
---|
| 112 | QTextStream in8(line);
|
---|
| 113 | in8 >> ep->TOW;
|
---|
| 114 | }
|
---|