1 |
|
---|
2 | #include <iostream>
|
---|
3 | #include <iomanip>
|
---|
4 | #include <sstream>
|
---|
5 | #include <vector>
|
---|
6 |
|
---|
7 | #include "thriftclient.h"
|
---|
8 | #include "monitor.h"
|
---|
9 |
|
---|
10 | using namespace apache::thrift;
|
---|
11 | using namespace apache::thrift::protocol;
|
---|
12 | using namespace apache::thrift::transport;
|
---|
13 |
|
---|
14 | using namespace com::gpssolutions::rtnet;
|
---|
15 | using namespace std;
|
---|
16 | using namespace boost;
|
---|
17 |
|
---|
18 | using namespace GnssCenter;
|
---|
19 |
|
---|
20 | // Auxiliary Function
|
---|
21 | //////////////////////////////////////////////////////////////////////////////
|
---|
22 | string 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 | //////////////////////////////////////////////////////////////////////////////
|
---|
40 | t_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 | //////////////////////////////////////////////////////////////////////////////
|
---|
49 | t_thriftClient::~t_thriftClient() {
|
---|
50 | }
|
---|
51 |
|
---|
52 | // Run (virtual)
|
---|
53 | //////////////////////////////////////////////////////////////////////////////
|
---|
54 | void 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 | //////////////////////////////////////////////////////////////////////////////
|
---|
87 | t_thriftHandler::t_thriftHandler(t_monitor* parent) {
|
---|
88 | _parent = parent;
|
---|
89 | }
|
---|
90 |
|
---|
91 | // Destructor
|
---|
92 | //////////////////////////////////////////////////////////////////////////////
|
---|
93 | t_thriftHandler::~t_thriftHandler() {
|
---|
94 | }
|
---|
95 |
|
---|
96 | // Handle Satellite Positions
|
---|
97 | //////////////////////////////////////////////////////////////////////////////
|
---|
98 | void t_thriftHandler::
|
---|
99 | handleSatelliteXYZ(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 | //////////////////////////////////////////////////////////////////////////////
|
---|
115 | void t_thriftHandler::
|
---|
116 | handleStationInfo(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 | //////////////////////////////////////////////////////////////////////////////
|
---|
127 | void t_thriftHandler::
|
---|
128 | handleEpochResults(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 | }
|
---|