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 | // Constructor
|
---|
21 | //////////////////////////////////////////////////////////////////////////////
|
---|
22 | t_thriftClient::t_thriftClient(t_monitor* parent, const QString& host, int port) {
|
---|
23 | _stop = false;
|
---|
24 | _parent = parent;
|
---|
25 | _host = host.toAscii().data();
|
---|
26 | _port = port;
|
---|
27 | }
|
---|
28 |
|
---|
29 | // Destructor
|
---|
30 | //////////////////////////////////////////////////////////////////////////////
|
---|
31 | t_thriftClient::~t_thriftClient() {
|
---|
32 | }
|
---|
33 |
|
---|
34 | // Run (virtual)
|
---|
35 | //////////////////////////////////////////////////////////////////////////////
|
---|
36 | void 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));
|
---|
44 | shared_ptr<RtnetDataIf> dataHandler(new t_thriftHandler(_parent));
|
---|
45 | shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
|
---|
46 |
|
---|
47 | try {
|
---|
48 | transport->open();
|
---|
49 | while (true) {
|
---|
50 | {
|
---|
51 | QMutexLocker locker(&_mutex);
|
---|
52 | if (_stop) {
|
---|
53 | break;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | if (processor->process(protocol,protocol,0) == 0) {
|
---|
57 | break;
|
---|
58 | }
|
---|
59 | }
|
---|
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 |
|
---|
70 | // Constructor
|
---|
71 | //////////////////////////////////////////////////////////////////////////////
|
---|
72 | t_thriftHandler::t_thriftHandler(t_monitor* parent) {
|
---|
73 | _parent = parent;
|
---|
74 | }
|
---|
75 |
|
---|
76 | // Destructor
|
---|
77 | //////////////////////////////////////////////////////////////////////////////
|
---|
78 | t_thriftHandler::~t_thriftHandler() {
|
---|
79 | }
|
---|
80 |
|
---|
81 | // Handle Satellite Positions
|
---|
82 | //////////////////////////////////////////////////////////////////////////////
|
---|
83 | void t_thriftHandler::
|
---|
84 | handleSatelliteXYZ(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 | //////////////////////////////////////////////////////////////////////////////
|
---|
98 | void t_thriftHandler::
|
---|
99 | handleStationInfo(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 |
|
---|
108 | // Handle Epoch Results
|
---|
109 | //////////////////////////////////////////////////////////////////////////////
|
---|
110 | void t_thriftHandler::
|
---|
111 | handleEpochResults(const RtnetEpoch& epoch) {
|
---|
112 | vector<t_thriftResult*>* results = new vector<t_thriftResult*>;
|
---|
113 | for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
|
---|
114 | const StationResults& staRes = epoch.stationResultList[ii];
|
---|
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;
|
---|
119 | if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
|
---|
120 | res->_x = _stationCrd[staRes.stationName]._x;
|
---|
121 | res->_y = _stationCrd[staRes.stationName]._y;
|
---|
122 | res->_z = _stationCrd[staRes.stationName]._z;
|
---|
123 | }
|
---|
124 | results->push_back(res);
|
---|
125 | }
|
---|
126 | _parent->putThriftResults(results);
|
---|
127 | }
|
---|