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

Last change on this file since 5415 was 5415, checked in by mervart, 9 years ago
File size: 3.2 KB
Line 
1
2#include <iomanip>
3#include <sstream>
4#include <vector>
5
6#include "thriftclient.h"
7
8using namespace apache::thrift;
9using namespace apache::thrift::protocol;
10using namespace apache::thrift::transport;
11
12using namespace com::gpssolutions::rtnet;
13using namespace std;
14using namespace boost;
15
16// Constructor
17//////////////////////////////////////////////////////////////////////////////
18t_thriftClient::t_thriftClient() {
19 _stop = false;
20 qRegisterMetaType<t_thriftResult>("t_thriftResult");
21}
22
23// Destructor
24//////////////////////////////////////////////////////////////////////////////
25t_thriftClient::~t_thriftClient() {
26}
27
28// Run (virtual)
29//////////////////////////////////////////////////////////////////////////////
30void 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();
43 while (!_stop && processor->process(protocol,protocol,0)) {}
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 }
52 this->terminate();
53 this->deleteLater();
54}
55
56// Handle Satellite Positions
57//////////////////////////////////////////////////////////////////////////////
58void t_thriftClient::
59handleSatelliteXYZ(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//////////////////////////////////////////////////////////////////////////////
73void t_thriftClient::
74handleStationInfo(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//////////////////////////////////////////////////////////////////////////////
85void t_thriftClient::
86handleEpochResults(const RtnetEpoch& epoch) {
87 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
88 const StationResults& staRes = epoch.stationResultList[ii];
89 t_thriftResult result;
90
91 result._name = staRes.stationName;
92 result._nGPS = staRes.nsv_gps_used;
93 result._nGLO = staRes.nsv_glonass_used;
94 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
95 result._x = _stationCrd[staRes.stationName]._x;
96 result._y = _stationCrd[staRes.stationName]._y;
97 result._z = _stationCrd[staRes.stationName]._z;
98 }
99
100 emit newThriftResult(result);
101
102 cout << result._name << ' ' << result._nGPS << ' ' << result._nGLO << endl;
103 }
104}
Note: See TracBrowser for help on using the repository browser.