source: ntrip/trunk/GnssCenter/map_stations/thriftclient.cpp@ 5425

Last change on this file since 5425 was 5425, checked in by mervart, 11 years ago
File size: 3.6 KB
RevLine 
[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
10using namespace apache::thrift;
11using namespace apache::thrift::protocol;
12using namespace apache::thrift::transport;
13
14using namespace com::gpssolutions::rtnet;
15using namespace std;
16using namespace boost;
17
[5409]18// Constructor
19//////////////////////////////////////////////////////////////////////////////
[5416]20t_thriftClient::t_thriftClient(GnssCenter::t_map_stations* parent) {
21 _stop = false;
22 _parent = parent;
[5409]23}
24
25// Destructor
26//////////////////////////////////////////////////////////////////////////////
27t_thriftClient::~t_thriftClient() {
28}
29
30// Run (virtual)
31//////////////////////////////////////////////////////////////////////////////
32void 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 }
52 processor->process(protocol,protocol,0);
53 }
[5409]54 transport->close();
55 }
56 catch (TException& e) {
57 cerr << "Caught an exception generated by Thrift: " << e.what() << endl;
58 }
59 catch (...) {
60 cerr << "Unknown exception" << endl;
61 }
[5414]62 this->terminate();
63 this->deleteLater();
[5409]64}
65
[5424]66// Constructor
67//////////////////////////////////////////////////////////////////////////////
68t_thriftHandler::t_thriftHandler(GnssCenter::t_map_stations* parent) {
69 _parent = parent;
70}
71
72// Destructor
73//////////////////////////////////////////////////////////////////////////////
74t_thriftHandler::~t_thriftHandler() {
75}
76
[5407]77// Handle Satellite Positions
78//////////////////////////////////////////////////////////////////////////////
[5424]79void t_thriftHandler::
[5407]80handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
81 cout.setf(ios::fixed);
82 for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
83// const SatelliteXYZ& sat = svXYZList[ii];
84// cout << unsigned(sat.ID) << ' '
85// << setprecision(3) << sat.xyz.x << ' '
86// << setprecision(3) << sat.xyz.y << ' '
87// << setprecision(3) << sat.xyz.z << endl;
88 }
89// cout << endl;
90}
91
92// Handle Station Info
93//////////////////////////////////////////////////////////////////////////////
[5424]94void t_thriftHandler::
[5407]95handleStationInfo(const vector<StationInfo>& stationList) {
96 for (unsigned ii = 0; ii < stationList.size(); ii++) {
97 const StationInfo& staInfo = stationList[ii];
98 _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
99 _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
100 _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
101 }
102}
103
[5424]104// Handle Epoch Results
[5407]105//////////////////////////////////////////////////////////////////////////////
[5424]106void t_thriftHandler::
[5407]107handleEpochResults(const RtnetEpoch& epoch) {
108 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
109 const StationResults& staRes = epoch.stationResultList[ii];
[5415]110 t_thriftResult result;
111
112 result._name = staRes.stationName;
113 result._nGPS = staRes.nsv_gps_used;
114 result._nGLO = staRes.nsv_glonass_used;
[5407]115 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
[5415]116 result._x = _stationCrd[staRes.stationName]._x;
117 result._y = _stationCrd[staRes.stationName]._y;
118 result._z = _stationCrd[staRes.stationName]._z;
[5407]119 }
[5416]120 _parent->slotNewThriftResult(&result);
[5407]121 }
122}
Note: See TracBrowser for help on using the repository browser.