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

Last change on this file since 5486 was 5486, checked in by mervart, 11 years ago
File size: 4.2 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
[5467]38 shared_ptr<TSocket> socket(new TSocket(_host, _port));
[5409]39 shared_ptr<TTransport> transport(new TBufferedTransport(socket));
40 shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
[5424]41 shared_ptr<RtnetDataIf> dataHandler(new t_thriftHandler(_parent));
[5409]42 shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
43
44 try {
45 transport->open();
[5425]46 while (true) {
47 {
48 QMutexLocker locker(&_mutex);
49 if (_stop) {
50 break;
51 }
52 }
[5426]53 if (processor->process(protocol,protocol,0) == 0) {
54 break;
55 }
[5425]56 }
[5409]57 transport->close();
58 }
59 catch (TException& e) {
[5479]60 emit message(e.what());
[5409]61 }
62 catch (...) {
[5479]63 emit message("Unknown exception");
[5409]64 }
65}
66
[5424]67// Constructor
68//////////////////////////////////////////////////////////////////////////////
[5447]69t_thriftHandler::t_thriftHandler(t_monitor* parent) {
[5424]70 _parent = parent;
71}
72
73// Destructor
74//////////////////////////////////////////////////////////////////////////////
75t_thriftHandler::~t_thriftHandler() {
76}
77
[5407]78// Handle Satellite Positions
79//////////////////////////////////////////////////////////////////////////////
[5424]80void t_thriftHandler::
[5407]81handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
[5483]82 vector<t_thriftSatellite*>* satellites = new vector<t_thriftSatellite*>;
83 for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
84 const SatelliteXYZ& sat = svXYZList[ii];
85 t_thriftSatellite* satellite = new t_thriftSatellite;
86 char ch;
87 switch(sat.constellation) {
88 case (ConstellationType::GPS): ch = 'G'; break;
89 case (ConstellationType::GLONASS): ch = 'R'; break;
90 case (ConstellationType::SBAS): ch = 'S'; break;
91 case (ConstellationType::GALILEO): ch = 'E'; break;
92 case (ConstellationType::QZSS): ch = 'J'; break;
93 case (ConstellationType::COMPASS): ch = 'C'; break;
94 }
[5484]95 char prn[3];
[5485]96 sprintf(prn, "%c%2.2d", ch, sat.ID);
[5484]97 satellite->_prn = prn;
98 satellite->_x = sat.xyz.x;
99 satellite->_y = sat.xyz.y;
100 satellite->_z = sat.xyz.z;
[5486]101 satellites->push_back(satellite);
[5483]102 }
[5486]103 _parent->putThriftSatellites(satellites);
[5407]104}
105
106// Handle Station Info
107//////////////////////////////////////////////////////////////////////////////
[5424]108void t_thriftHandler::
[5407]109handleStationInfo(const vector<StationInfo>& stationList) {
110 for (unsigned ii = 0; ii < stationList.size(); ii++) {
111 const StationInfo& staInfo = stationList[ii];
112 _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
113 _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
114 _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
115 }
116}
117
[5424]118// Handle Epoch Results
[5407]119//////////////////////////////////////////////////////////////////////////////
[5424]120void t_thriftHandler::
[5407]121handleEpochResults(const RtnetEpoch& epoch) {
[5427]122 vector<t_thriftResult*>* results = new vector<t_thriftResult*>;
[5407]123 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
124 const StationResults& staRes = epoch.stationResultList[ii];
[5427]125 t_thriftResult* res = new t_thriftResult;
126 res->_name = staRes.stationName;
127 res->_nGPS = staRes.nsv_gps_used;
128 res->_nGLO = staRes.nsv_glonass_used;
[5407]129 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
[5427]130 res->_x = _stationCrd[staRes.stationName]._x;
131 res->_y = _stationCrd[staRes.stationName]._y;
132 res->_z = _stationCrd[staRes.stationName]._z;
[5407]133 }
[5427]134 results->push_back(res);
[5407]135 }
[5427]136 _parent->putThriftResults(results);
[5407]137}
Note: See TracBrowser for help on using the repository browser.