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

Last change on this file since 8455 was 5499, checked in by mervart, 11 years ago
File size: 4.8 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// 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
38// Constructor
39//////////////////////////////////////////////////////////////////////////////
40t_thriftClient::t_thriftClient(t_monitor* parent, const QString& host, int port) {
41 _stop = false;
42 _parent = parent;
43 _host = host.toAscii().data();
44 _port = port;
45}
46
47// Destructor
48//////////////////////////////////////////////////////////////////////////////
49t_thriftClient::~t_thriftClient() {
50}
51
52// Run (virtual)
53//////////////////////////////////////////////////////////////////////////////
54void t_thriftClient::run() {
55
56 shared_ptr<TSocket> socket(new TSocket(_host, _port));
57 shared_ptr<TTransport> transport(new TBufferedTransport(socket));
58 shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
59 shared_ptr<RtnetDataIf> dataHandler(new t_thriftHandler(_parent));
60 shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
61
62 try {
63 transport->open();
64 while (true) {
65 {
66 QMutexLocker locker(&_mutex);
67 if (_stop) {
68 break;
69 }
70 }
71 if (processor->process(protocol,protocol,0) == 0) {
72 break;
73 }
74 }
75 transport->close();
76 }
77 catch (TException& e) {
78 emit message(e.what());
79 }
80 catch (...) {
81 emit message("Unknown exception");
82 }
83}
84
85// Constructor
86//////////////////////////////////////////////////////////////////////////////
87t_thriftHandler::t_thriftHandler(t_monitor* parent) {
88 _parent = parent;
89}
90
91// Destructor
92//////////////////////////////////////////////////////////////////////////////
93t_thriftHandler::~t_thriftHandler() {
94}
95
96// Handle Satellite Positions
97//////////////////////////////////////////////////////////////////////////////
98void t_thriftHandler::
99handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
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;
104 satellite->_prn = id2prn(sat.constellation, sat.ID);
105 satellite->_x = sat.xyz.x;
106 satellite->_y = sat.xyz.y;
107 satellite->_z = sat.xyz.z;
108 satellites->push_back(satellite);
109 }
110 _parent->putThriftSatellites(satellites);
111}
112
113// Handle Station Info
114//////////////////////////////////////////////////////////////////////////////
115void t_thriftHandler::
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
125// Handle Epoch Results
126//////////////////////////////////////////////////////////////////////////////
127void t_thriftHandler::
128handleEpochResults(const RtnetEpoch& epoch) {
129 vector<t_thriftResult*>* results = new vector<t_thriftResult*>;
130 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
131 const StationResults& staRes = epoch.stationResultList[ii];
132
133 t_thriftResult* res = new t_thriftResult;
134
135 res->_name = staRes.stationName;
136 res->_nGPS = staRes.nsv_gps_used;
137 res->_nGLO = staRes.nsv_glonass_used;
138 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
139 res->_x = _stationCrd[staRes.stationName]._x;
140 res->_y = _stationCrd[staRes.stationName]._y;
141 res->_z = _stationCrd[staRes.stationName]._z;
142 }
143
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);
150 }
151 }
152
153 results->push_back(res);
154 }
155 _parent->putThriftResults(results);
156}
Note: See TracBrowser for help on using the repository browser.