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

Last change on this file since 5398 was 5398, checked in by mervart, 11 years ago
File size: 4.8 KB
RevLine 
[4925]1
[4927]2#include <iomanip>
[5393]3#include <sstream>
[4925]4#include <vector>
[5393]5#include <map>
[4925]6#include <string>
[5393]7#include <getopt.h>
[4925]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;
[4935]21using namespace boost;
[4925]22
[5398]23class t_stationCrd {
24 public:
25 double _x;
26 double _y;
27 double _z;
28};
29
30map<string, t_stationCrd> _stationCrd;
31
[5392]32// Handler Class Definition
33//////////////////////////////////////////////////////////////////////////////
[4935]34class RtnetClientHandler : public RtnetDataIf {
[4927]35 public:
36 RtnetClientHandler() {}
37 ~RtnetClientHandler() {}
[5392]38
[4927]39 void startDataStream() {}
40 void registerRtnet(const RtnetInformation& info) {}
41 void handleZDAmb(const vector<ZDAmb>& ambList) {}
42 void handleDDAmbresBaselines(const vector<DDAmbresBaseline>& ambList) {}
[5392]43 void handleSatelliteXYZ(const vector< SatelliteXYZ>& svXYZList);
[5398]44 void handleStationInfo(const vector<StationInfo>& stationList);
[4927]45 void handleStationAuxInfo(const vector<StationAuxInfo>& stationAuxList) {}
46 void handleDGPSCorr(const vector<DGPSCorr>& dgpsList) {}
47 void handleSatelliteClock(const vector<SatelliteClock>& svList) {}
[5397]48 void handleEpochResults(const RtnetEpoch& epoch);
[4925]49};
50
[5393]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
[5392]75// Program
76//////////////////////////////////////////////////////////////////////////////
[4925]77int main(int argc, char **argv) {
78
[5393]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));
[4935]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));
[4928]95
[4935]96 try {
97 transport->open();
[4925]98
[4935]99 while (processor->process(protocol,protocol,0)) {}
100
101 transport->close();
[4925]102 }
103 catch (TException& e) {
[4927]104 cerr << "Caught an exception generated by Thrift: " << e.what() << endl;
105 return 1;
[4925]106 }
107 catch (...) {
[4927]108 cerr << "Unknown exception" << endl;
109 return 1;
[4925]110 }
111
112 return 0;
113}
[5392]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++) {
[5397]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;
[5392]126 }
[5397]127// cout << endl;
[5392]128}
129
[5398]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 if (_stationCrd.find(staInfo.ID) == _stationCrd.end()) {
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
[5397]144// Handle Eoch Results
145//////////////////////////////////////////////////////////////////////////////
146void RtnetClientHandler::
147handleEpochResults(const RtnetEpoch& epoch) {
148 for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
149 const StationResults& staRes = epoch.stationResultList[ii];
150 cout << staRes.stationName << ' '
[5398]151 << (int) staRes.nsv_gps_used << ' ' << (int) staRes.nsv_glonass_used << ' ';
152 if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
153 cout << _stationCrd[staRes.stationName]._x << ' '
154 << _stationCrd[staRes.stationName]._y << ' '
155 << _stationCrd[staRes.stationName]._z;
156 }
157 cout << endl;
[5397]158 }
159}
Note: See TracBrowser for help on using the repository browser.