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 |
|
---|
15 | using namespace apache::thrift;
|
---|
16 | using namespace apache::thrift::protocol;
|
---|
17 | using namespace apache::thrift::transport;
|
---|
18 |
|
---|
19 | using namespace com::gpssolutions::rtnet;
|
---|
20 | using namespace std;
|
---|
21 | using namespace boost;
|
---|
22 |
|
---|
23 | // Handler Class Definition
|
---|
24 | //////////////////////////////////////////////////////////////////////////////
|
---|
25 | class RtnetClientHandler : public RtnetDataIf {
|
---|
26 | public:
|
---|
27 | RtnetClientHandler() {}
|
---|
28 | ~RtnetClientHandler() {}
|
---|
29 |
|
---|
30 | void startDataStream() {}
|
---|
31 | void registerRtnet(const RtnetInformation& info) {}
|
---|
32 | void handleZDAmb(const vector<ZDAmb>& ambList) {}
|
---|
33 | void handleDDAmbresBaselines(const vector<DDAmbresBaseline>& ambList) {}
|
---|
34 | void handleSatelliteXYZ(const vector< SatelliteXYZ>& svXYZList);
|
---|
35 | void handleStationInfo(const vector<StationInfo>& stationList) {}
|
---|
36 | void handleStationAuxInfo(const vector<StationAuxInfo>& stationAuxList) {}
|
---|
37 | void handleDGPSCorr(const vector<DGPSCorr>& dgpsList) {}
|
---|
38 | void handleSatelliteClock(const vector<SatelliteClock>& svList) {}
|
---|
39 | void handleEpochResults(const RtnetEpoch& epoch) {}
|
---|
40 | };
|
---|
41 |
|
---|
42 | // Read Command-line Options
|
---|
43 | ////////////////////////////////////////////////////////////////////////////////
|
---|
44 | void parseCmdLine(int argc, char* argv[], map<string, string>& OPT) {
|
---|
45 |
|
---|
46 | static struct option longOptions[] = {
|
---|
47 | {"host", required_argument, 0, 'h'},
|
---|
48 | {"port", required_argument, 0, 'p'},
|
---|
49 | };
|
---|
50 |
|
---|
51 | while (true) {
|
---|
52 | int index = 0;
|
---|
53 | int iarg = getopt_long(argc, argv, "h:p:", longOptions, &index);
|
---|
54 | if (iarg == -1) {
|
---|
55 | break;
|
---|
56 | }
|
---|
57 | if (optarg) {
|
---|
58 | OPT[longOptions[index].name] = string(optarg);
|
---|
59 | }
|
---|
60 | else {
|
---|
61 | OPT[longOptions[index].name] = "y";
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | // Program
|
---|
67 | //////////////////////////////////////////////////////////////////////////////
|
---|
68 | int main(int argc, char **argv) {
|
---|
69 |
|
---|
70 | // Parse Input Options
|
---|
71 | // -------------------
|
---|
72 | map<string, string> OPT;
|
---|
73 | parseCmdLine(argc, argv, OPT);
|
---|
74 | if (OPT.find("port") == OPT.end()) {
|
---|
75 | cerr << "usage: rtnetThriftClient [--host <host>] --port <port>" << endl;
|
---|
76 | return 1;
|
---|
77 | }
|
---|
78 | string host = OPT.find("host") == OPT.end() ? "localhost" : OPT["host"];
|
---|
79 | int port; istringstream(OPT["port"]) >> port;
|
---|
80 |
|
---|
81 | shared_ptr<TSocket> socket(new TSocket(host, port));
|
---|
82 | shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
---|
83 | shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
---|
84 | shared_ptr<RtnetDataIf> dataHandler(new RtnetClientHandler());
|
---|
85 | shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
|
---|
86 |
|
---|
87 | try {
|
---|
88 | transport->open();
|
---|
89 |
|
---|
90 | while (processor->process(protocol,protocol,0)) {}
|
---|
91 |
|
---|
92 | transport->close();
|
---|
93 | }
|
---|
94 | catch (TException& e) {
|
---|
95 | cerr << "Caught an exception generated by Thrift: " << e.what() << endl;
|
---|
96 | return 1;
|
---|
97 | }
|
---|
98 | catch (...) {
|
---|
99 | cerr << "Unknown exception" << endl;
|
---|
100 | return 1;
|
---|
101 | }
|
---|
102 |
|
---|
103 | return 0;
|
---|
104 | }
|
---|
105 |
|
---|
106 | // Handle Satellite Positions
|
---|
107 | //////////////////////////////////////////////////////////////////////////////
|
---|
108 | void RtnetClientHandler::
|
---|
109 | handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
|
---|
110 | cout.setf(ios::fixed);
|
---|
111 | for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
|
---|
112 | const SatelliteXYZ& sat = svXYZList[ii];
|
---|
113 | cout << unsigned(sat.ID) << ' '
|
---|
114 | << setprecision(3) << sat.xyz.x << ' '
|
---|
115 | << setprecision(3) << sat.xyz.y << ' '
|
---|
116 | << setprecision(3) << sat.xyz.z << endl;
|
---|
117 | }
|
---|
118 | cout << endl;
|
---|
119 | }
|
---|
120 |
|
---|