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

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