[5407] | 1 |
|
---|
| 2 | #include <iomanip>
|
---|
| 3 | #include <sstream>
|
---|
| 4 | #include <vector>
|
---|
| 5 |
|
---|
| 6 | #include "thriftclient.h"
|
---|
| 7 |
|
---|
| 8 | using namespace apache::thrift;
|
---|
| 9 | using namespace apache::thrift::protocol;
|
---|
| 10 | using namespace apache::thrift::transport;
|
---|
| 11 |
|
---|
| 12 | using namespace com::gpssolutions::rtnet;
|
---|
| 13 | using namespace std;
|
---|
| 14 | using namespace boost;
|
---|
| 15 |
|
---|
[5409] | 16 | // Constructor
|
---|
| 17 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 18 | t_thriftClient::t_thriftClient() {
|
---|
[5414] | 19 | _stop = false;
|
---|
[5415] | 20 | qRegisterMetaType<t_thriftResult>("t_thriftResult");
|
---|
[5409] | 21 | }
|
---|
| 22 |
|
---|
| 23 | // Destructor
|
---|
| 24 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 25 | t_thriftClient::~t_thriftClient() {
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | // Run (virtual)
|
---|
| 29 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 30 | void t_thriftClient::run() {
|
---|
| 31 |
|
---|
| 32 | string host = "rtnet.rtcm-ntrip.org";
|
---|
| 33 | int port = 7777;
|
---|
| 34 |
|
---|
| 35 | shared_ptr<TSocket> socket(new TSocket(host, port));
|
---|
| 36 | shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
---|
| 37 | shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
---|
| 38 | shared_ptr<RtnetDataIf> dataHandler(new t_thriftClient());
|
---|
| 39 | shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
|
---|
| 40 |
|
---|
| 41 | try {
|
---|
| 42 | transport->open();
|
---|
[5414] | 43 | while (!_stop && processor->process(protocol,protocol,0)) {}
|
---|
[5409] | 44 | transport->close();
|
---|
| 45 | }
|
---|
| 46 | catch (TException& e) {
|
---|
| 47 | cerr << "Caught an exception generated by Thrift: " << e.what() << endl;
|
---|
| 48 | }
|
---|
| 49 | catch (...) {
|
---|
| 50 | cerr << "Unknown exception" << endl;
|
---|
| 51 | }
|
---|
[5414] | 52 | this->terminate();
|
---|
| 53 | this->deleteLater();
|
---|
[5409] | 54 | }
|
---|
| 55 |
|
---|
[5407] | 56 | // Handle Satellite Positions
|
---|
| 57 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 58 | void t_thriftClient::
|
---|
| 59 | handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
|
---|
| 60 | cout.setf(ios::fixed);
|
---|
| 61 | for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
|
---|
| 62 | // const SatelliteXYZ& sat = svXYZList[ii];
|
---|
| 63 | // cout << unsigned(sat.ID) << ' '
|
---|
| 64 | // << setprecision(3) << sat.xyz.x << ' '
|
---|
| 65 | // << setprecision(3) << sat.xyz.y << ' '
|
---|
| 66 | // << setprecision(3) << sat.xyz.z << endl;
|
---|
| 67 | }
|
---|
| 68 | // cout << endl;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | // Handle Station Info
|
---|
| 72 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 73 | void t_thriftClient::
|
---|
| 74 | handleStationInfo(const vector<StationInfo>& stationList) {
|
---|
| 75 | for (unsigned ii = 0; ii < stationList.size(); ii++) {
|
---|
| 76 | const StationInfo& staInfo = stationList[ii];
|
---|
| 77 | _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
|
---|
| 78 | _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
|
---|
| 79 | _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | // Handle Eoch Results
|
---|
| 84 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 85 | void t_thriftClient::
|
---|
| 86 | handleEpochResults(const RtnetEpoch& epoch) {
|
---|
| 87 | for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
|
---|
| 88 | const StationResults& staRes = epoch.stationResultList[ii];
|
---|
[5415] | 89 | t_thriftResult result;
|
---|
| 90 |
|
---|
| 91 | result._name = staRes.stationName;
|
---|
| 92 | result._nGPS = staRes.nsv_gps_used;
|
---|
| 93 | result._nGLO = staRes.nsv_glonass_used;
|
---|
[5407] | 94 | if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
|
---|
[5415] | 95 | result._x = _stationCrd[staRes.stationName]._x;
|
---|
| 96 | result._y = _stationCrd[staRes.stationName]._y;
|
---|
| 97 | result._z = _stationCrd[staRes.stationName]._z;
|
---|
[5407] | 98 | }
|
---|
[5415] | 99 |
|
---|
| 100 | emit newThriftResult(result);
|
---|
| 101 |
|
---|
| 102 | cout << result._name << ' ' << result._nGPS << ' ' << result._nGLO << endl;
|
---|
[5407] | 103 | }
|
---|
| 104 | }
|
---|