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

Last change on this file since 5424 was 5424, checked in by mervart, 9 years ago
File size: 3.5 KB
Line 
1
2#include <iostream>
3#include <iomanip>
4#include <sstream>
5#include <vector>
6
7#include "thriftclient.h"
8#include "map_stations.h"
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
18// Constructor
19//////////////////////////////////////////////////////////////////////////////
20t_thriftClient::t_thriftClient(GnssCenter::t_map_stations* parent) {
21 _stop = false;
22 _parent = parent;
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));
40 shared_ptr<RtnetDataIf> dataHandler(new t_thriftHandler(_parent));
41 shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
42
43 try {
44 transport->open();
45 while (!_stop && processor->process(protocol,protocol,0)) {}
46 transport->close();
47 }
48 catch (TException& e) {
49 cerr << "Caught an exception generated by Thrift: " << e.what() << endl;
50 }
51 catch (...) {
52 cerr << "Unknown exception" << endl;
53 }
54 this->terminate();
55 this->deleteLater();
56}
57
58// Constructor
59//////////////////////////////////////////////////////////////////////////////
60t_thriftHandler::t_thriftHandler(GnssCenter::t_map_stations* parent) {
61 _parent = parent;
62}
63
64// Destructor
65//////////////////////////////////////////////////////////////////////////////
66t_thriftHandler::~t_thriftHandler() {
67}
68
69// Handle Satellite Positions
70//////////////////////////////////////////////////////////////////////////////
71void t_thriftHandler::
72handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
73 cout.setf(ios::fixed);
74 for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
75// const SatelliteXYZ& sat = svXYZList[ii];
76// cout << unsigned(sat.ID) << ' '
77// << setprecision(3) << sat.xyz.x << ' '
78// << setprecision(3) << sat.xyz.y << ' '
79// << setprecision(3) << sat.xyz.z << endl;
80 }
81// cout << endl;
82}
83
84// Handle Station Info
85//////////////////////////////////////////////////////////////////////////////
86void t_thriftHandler::
87handleStationInfo(const vector<StationInfo>& stationList) {
88 for (unsigned ii = 0; ii < stationList.size(); ii++) {
89 const StationInfo& staInfo = stationList[ii];
90 _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
91 _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
92 _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
93 }
94}
95
96// Handle Epoch Results
97//////////////////////////////////////////////////////////////////////////////
98void t_thriftHandler::
99handleEpochResults(const RtnetEpoch& epoch) {
100 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
101 const StationResults& staRes = epoch.stationResultList[ii];
102 t_thriftResult result;
103
104 result._name = staRes.stationName;
105 result._nGPS = staRes.nsv_gps_used;
106 result._nGLO = staRes.nsv_glonass_used;
107 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
108 result._x = _stationCrd[staRes.stationName]._x;
109 result._y = _stationCrd[staRes.stationName]._y;
110 result._z = _stationCrd[staRes.stationName]._z;
111 }
112 _parent->slotNewThriftResult(&result);
113 }
114}
Note: See TracBrowser for help on using the repository browser.