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

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