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