source: ntrip/trunk/GnssCenter/thrift/test_rtnet/rtnetThriftClient.cpp@ 5399

Last change on this file since 5399 was 5399, checked in by mervart, 9 years ago
File size: 4.7 KB
Line 
1
2#include <iomanip>
3#include <sstream>
4#include <vector>
5#include <map>
6#include <string>
7#include <getopt.h>
8
9#include <transport/TSocket.h>
10#include <transport/TBufferTransports.h>
11#include <protocol/TBinaryProtocol.h>
12
13#include "gen-cpp/RtnetData.h"
14
15using namespace apache::thrift;
16using namespace apache::thrift::protocol;
17using namespace apache::thrift::transport;
18
19using namespace com::gpssolutions::rtnet;
20using namespace std;
21using namespace boost;
22
23class t_stationCrd {
24 public:
25 double _x;
26 double _y;
27 double _z;
28};
29
30map<string, t_stationCrd> _stationCrd;
31
32// Handler Class Definition
33//////////////////////////////////////////////////////////////////////////////
34class RtnetClientHandler : public RtnetDataIf {
35 public:
36 RtnetClientHandler() {}
37 ~RtnetClientHandler() {}
38
39 void startDataStream() {}
40 void registerRtnet(const RtnetInformation& info) {}
41 void handleZDAmb(const vector<ZDAmb>& ambList) {}
42 void handleDDAmbresBaselines(const vector<DDAmbresBaseline>& ambList) {}
43 void handleSatelliteXYZ(const vector< SatelliteXYZ>& svXYZList);
44 void handleStationInfo(const vector<StationInfo>& stationList);
45 void handleStationAuxInfo(const vector<StationAuxInfo>& stationAuxList) {}
46 void handleDGPSCorr(const vector<DGPSCorr>& dgpsList) {}
47 void handleSatelliteClock(const vector<SatelliteClock>& svList) {}
48 void handleEpochResults(const RtnetEpoch& epoch);
49};
50
51// Read Command-line Options
52////////////////////////////////////////////////////////////////////////////////
53void parseCmdLine(int argc, char* argv[], map<string, string>& OPT) {
54
55 static struct option longOptions[] = {
56 {"host", required_argument, 0, 'h'},
57 {"port", required_argument, 0, 'p'},
58 };
59
60 while (true) {
61 int index = 0;
62 int iarg = getopt_long(argc, argv, "h:p:", longOptions, &index);
63 if (iarg == -1) {
64 break;
65 }
66 if (optarg) {
67 OPT[longOptions[index].name] = string(optarg);
68 }
69 else {
70 OPT[longOptions[index].name] = "y";
71 }
72 }
73}
74
75// Program
76//////////////////////////////////////////////////////////////////////////////
77int main(int argc, char **argv) {
78
79 // Parse Input Options
80 // -------------------
81 map<string, string> OPT;
82 parseCmdLine(argc, argv, OPT);
83 if (OPT.find("port") == OPT.end()) {
84 cerr << "usage: rtnetThriftClient [--host <host>] --port <port>" << endl;
85 return 1;
86 }
87 string host = OPT.find("host") == OPT.end() ? "localhost" : OPT["host"];
88 int port; istringstream(OPT["port"]) >> port;
89
90 shared_ptr<TSocket> socket(new TSocket(host, port));
91 shared_ptr<TTransport> transport(new TBufferedTransport(socket));
92 shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
93 shared_ptr<RtnetDataIf> dataHandler(new RtnetClientHandler());
94 shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
95
96 try {
97 transport->open();
98
99 while (processor->process(protocol,protocol,0)) {}
100
101 transport->close();
102 }
103 catch (TException& e) {
104 cerr << "Caught an exception generated by Thrift: " << e.what() << endl;
105 return 1;
106 }
107 catch (...) {
108 cerr << "Unknown exception" << endl;
109 return 1;
110 }
111
112 return 0;
113}
114
115// Handle Satellite Positions
116//////////////////////////////////////////////////////////////////////////////
117void RtnetClientHandler::
118handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
119 cout.setf(ios::fixed);
120 for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
121// const SatelliteXYZ& sat = svXYZList[ii];
122// cout << unsigned(sat.ID) << ' '
123// << setprecision(3) << sat.xyz.x << ' '
124// << setprecision(3) << sat.xyz.y << ' '
125// << setprecision(3) << sat.xyz.z << endl;
126 }
127// cout << endl;
128}
129
130// Handle Station Info
131//////////////////////////////////////////////////////////////////////////////
132void RtnetClientHandler::
133handleStationInfo(const vector<StationInfo>& stationList) {
134 for (unsigned ii = 0; ii < stationList.size(); ii++) {
135 const StationInfo& staInfo = stationList[ii];
136 _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
137 _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
138 _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
139 }
140}
141
142// Handle Eoch Results
143//////////////////////////////////////////////////////////////////////////////
144void RtnetClientHandler::
145handleEpochResults(const RtnetEpoch& epoch) {
146 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
147 const StationResults& staRes = epoch.stationResultList[ii];
148 cout << staRes.stationName << ' '
149 << (int) staRes.nsv_gps_used << ' ' << (int) staRes.nsv_glonass_used << ' ';
150 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
151 cout << _stationCrd[staRes.stationName]._x << ' '
152 << _stationCrd[staRes.stationName]._y << ' '
153 << _stationCrd[staRes.stationName]._z;
154 }
155 cout << endl;
156 }
157}
Note: See TracBrowser for help on using the repository browser.