source: ntrip/trunk/GnssCenter/monitor/thriftclient.cpp@ 5447

Last change on this file since 5447 was 5447, checked in by mervart, 11 years ago
File size: 3.7 KB
Line 
1
2#include <iostream>
3#include <iomanip>
4#include <sstream>
5#include <vector>
6
7#include "thriftclient.h"
8#include "monitor.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
18using namespace GnssCenter;
19
20// Constructor
21//////////////////////////////////////////////////////////////////////////////
22t_thriftClient::t_thriftClient(t_monitor* parent) {
23 _stop = false;
24 _parent = parent;
25}
26
27// Destructor
28//////////////////////////////////////////////////////////////////////////////
29t_thriftClient::~t_thriftClient() {
30}
31
32// Run (virtual)
33//////////////////////////////////////////////////////////////////////////////
34void t_thriftClient::run() {
35
36 string host = "rtnet.rtcm-ntrip.org";
37 int port = 7777;
38
39 shared_ptr<TSocket> socket(new TSocket(host, port));
40 shared_ptr<TTransport> transport(new TBufferedTransport(socket));
41 shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
42 shared_ptr<RtnetDataIf> dataHandler(new t_thriftHandler(_parent));
43 shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
44
45 try {
46 transport->open();
47 while (true) {
48 {
49 QMutexLocker locker(&_mutex);
50 if (_stop) {
51 break;
52 }
53 }
54 if (processor->process(protocol,protocol,0) == 0) {
55 break;
56 }
57 }
58 transport->close();
59 }
60 catch (TException& e) {
61 cerr << "Caught an exception generated by Thrift: " << e.what() << endl;
62 }
63 catch (...) {
64 cerr << "Unknown exception" << endl;
65 }
66}
67
68// Constructor
69//////////////////////////////////////////////////////////////////////////////
70t_thriftHandler::t_thriftHandler(t_monitor* parent) {
71 _parent = parent;
72}
73
74// Destructor
75//////////////////////////////////////////////////////////////////////////////
76t_thriftHandler::~t_thriftHandler() {
77}
78
79// Handle Satellite Positions
80//////////////////////////////////////////////////////////////////////////////
81void t_thriftHandler::
82handleSatelliteXYZ(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//////////////////////////////////////////////////////////////////////////////
96void t_thriftHandler::
97handleStationInfo(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
106// Handle Epoch Results
107//////////////////////////////////////////////////////////////////////////////
108void t_thriftHandler::
109handleEpochResults(const RtnetEpoch& epoch) {
110 vector<t_thriftResult*>* results = new vector<t_thriftResult*>;
111 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
112 const StationResults& staRes = epoch.stationResultList[ii];
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;
117 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
118 res->_x = _stationCrd[staRes.stationName]._x;
119 res->_y = _stationCrd[staRes.stationName]._y;
120 res->_z = _stationCrd[staRes.stationName]._z;
121 }
122 results->push_back(res);
123 }
124 _parent->putThriftResults(results);
125}
Note: See TracBrowser for help on using the repository browser.