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

Last change on this file since 7332 was 5499, checked in by mervart, 11 years ago
File size: 4.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
[5495]20// Auxiliary Function
21//////////////////////////////////////////////////////////////////////////////
22string id2prn(ConstellationType::type constellation, int ID) {
23 char ch;
24 switch(constellation) {
25 case (ConstellationType::GPS): ch = 'G'; break;
26 case (ConstellationType::GLONASS): ch = 'R'; break;
27 case (ConstellationType::SBAS): ch = 'S'; break;
28 case (ConstellationType::GALILEO): ch = 'E'; break;
29 case (ConstellationType::QZSS): ch = 'J'; break;
30 case (ConstellationType::COMPASS): ch = 'C'; break;
31 default: return "";
32 }
33 char prn[3];
34 sprintf(prn, "%c%2.2d", ch, ID);
35 return string(prn);
36}
37
[5409]38// Constructor
39//////////////////////////////////////////////////////////////////////////////
[5452]40t_thriftClient::t_thriftClient(t_monitor* parent, const QString& host, int port) {
[5416]41 _stop = false;
42 _parent = parent;
[5452]43 _host = host.toAscii().data();
44 _port = port;
[5409]45}
46
47// Destructor
48//////////////////////////////////////////////////////////////////////////////
49t_thriftClient::~t_thriftClient() {
50}
51
52// Run (virtual)
53//////////////////////////////////////////////////////////////////////////////
54void t_thriftClient::run() {
55
[5467]56 shared_ptr<TSocket> socket(new TSocket(_host, _port));
[5409]57 shared_ptr<TTransport> transport(new TBufferedTransport(socket));
58 shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
[5424]59 shared_ptr<RtnetDataIf> dataHandler(new t_thriftHandler(_parent));
[5409]60 shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
61
62 try {
63 transport->open();
[5425]64 while (true) {
65 {
66 QMutexLocker locker(&_mutex);
67 if (_stop) {
68 break;
69 }
70 }
[5426]71 if (processor->process(protocol,protocol,0) == 0) {
72 break;
73 }
[5425]74 }
[5409]75 transport->close();
76 }
77 catch (TException& e) {
[5479]78 emit message(e.what());
[5409]79 }
80 catch (...) {
[5479]81 emit message("Unknown exception");
[5409]82 }
83}
84
[5424]85// Constructor
86//////////////////////////////////////////////////////////////////////////////
[5447]87t_thriftHandler::t_thriftHandler(t_monitor* parent) {
[5424]88 _parent = parent;
89}
90
91// Destructor
92//////////////////////////////////////////////////////////////////////////////
93t_thriftHandler::~t_thriftHandler() {
94}
95
[5407]96// Handle Satellite Positions
97//////////////////////////////////////////////////////////////////////////////
[5424]98void t_thriftHandler::
[5407]99handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
[5483]100 vector<t_thriftSatellite*>* satellites = new vector<t_thriftSatellite*>;
101 for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
102 const SatelliteXYZ& sat = svXYZList[ii];
103 t_thriftSatellite* satellite = new t_thriftSatellite;
[5495]104 satellite->_prn = id2prn(sat.constellation, sat.ID);
[5484]105 satellite->_x = sat.xyz.x;
106 satellite->_y = sat.xyz.y;
107 satellite->_z = sat.xyz.z;
[5486]108 satellites->push_back(satellite);
[5483]109 }
[5486]110 _parent->putThriftSatellites(satellites);
[5407]111}
112
113// Handle Station Info
114//////////////////////////////////////////////////////////////////////////////
[5424]115void t_thriftHandler::
[5407]116handleStationInfo(const vector<StationInfo>& stationList) {
117 for (unsigned ii = 0; ii < stationList.size(); ii++) {
118 const StationInfo& staInfo = stationList[ii];
119 _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
120 _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
121 _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
122 }
123}
124
[5424]125// Handle Epoch Results
[5407]126//////////////////////////////////////////////////////////////////////////////
[5424]127void t_thriftHandler::
[5407]128handleEpochResults(const RtnetEpoch& epoch) {
[5427]129 vector<t_thriftResult*>* results = new vector<t_thriftResult*>;
[5407]130 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
131 const StationResults& staRes = epoch.stationResultList[ii];
[5495]132
[5496]133 t_thriftResult* res = new t_thriftResult;
[5495]134
[5427]135 res->_name = staRes.stationName;
136 res->_nGPS = staRes.nsv_gps_used;
137 res->_nGLO = staRes.nsv_glonass_used;
[5407]138 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
[5427]139 res->_x = _stationCrd[staRes.stationName]._x;
140 res->_y = _stationCrd[staRes.stationName]._y;
141 res->_z = _stationCrd[staRes.stationName]._z;
[5407]142 }
[5496]143
[5499]144 for (unsigned ic = 0; ic < staRes.residList.size(); ic++) {
145 const ResidualInfo& info = staRes.residList[ic];
146 for (unsigned is = 0; is < info.svResid.size(); is++) {
147 const SvResidualInfo& sat = info.svResid[is];
148 string prn = id2prn(sat.constellation, sat.ID);
149 res->_prns.insert(prn);
[5498]150 }
[5496]151 }
152
[5427]153 results->push_back(res);
[5407]154 }
[5427]155 _parent->putThriftResults(results);
[5407]156}
Note: See TracBrowser for help on using the repository browser.