[4925] | 1 |
|
---|
[5434] | 2 | #include <iostream>
|
---|
[4927] | 3 | #include <iomanip>
|
---|
[5393] | 4 | #include <sstream>
|
---|
[4925] | 5 | #include <vector>
|
---|
[5393] | 6 | #include <map>
|
---|
[4925] | 7 | #include <string>
|
---|
[5393] | 8 | #include <getopt.h>
|
---|
[4925] | 9 |
|
---|
| 10 | #include <transport/TSocket.h>
|
---|
| 11 | #include <transport/TBufferTransports.h>
|
---|
| 12 | #include <protocol/TBinaryProtocol.h>
|
---|
| 13 |
|
---|
| 14 | #include "gen-cpp/RtnetData.h"
|
---|
| 15 |
|
---|
| 16 | using namespace apache::thrift;
|
---|
| 17 | using namespace apache::thrift::protocol;
|
---|
| 18 | using namespace apache::thrift::transport;
|
---|
| 19 |
|
---|
| 20 | using namespace com::gpssolutions::rtnet;
|
---|
| 21 | using namespace std;
|
---|
[4935] | 22 | using namespace boost;
|
---|
[4925] | 23 |
|
---|
[5398] | 24 | class t_stationCrd {
|
---|
| 25 | public:
|
---|
| 26 | double _x;
|
---|
| 27 | double _y;
|
---|
| 28 | double _z;
|
---|
| 29 | };
|
---|
| 30 |
|
---|
| 31 | map<string, t_stationCrd> _stationCrd;
|
---|
| 32 |
|
---|
[5392] | 33 | // Handler Class Definition
|
---|
| 34 | //////////////////////////////////////////////////////////////////////////////
|
---|
[4935] | 35 | class RtnetClientHandler : public RtnetDataIf {
|
---|
[4927] | 36 | public:
|
---|
| 37 | RtnetClientHandler() {}
|
---|
| 38 | ~RtnetClientHandler() {}
|
---|
[5392] | 39 |
|
---|
[4927] | 40 | void startDataStream() {}
|
---|
| 41 | void registerRtnet(const RtnetInformation& info) {}
|
---|
| 42 | void handleZDAmb(const vector<ZDAmb>& ambList) {}
|
---|
| 43 | void handleDDAmbresBaselines(const vector<DDAmbresBaseline>& ambList) {}
|
---|
[5392] | 44 | void handleSatelliteXYZ(const vector< SatelliteXYZ>& svXYZList);
|
---|
[5398] | 45 | void handleStationInfo(const vector<StationInfo>& stationList);
|
---|
[4927] | 46 | void handleStationAuxInfo(const vector<StationAuxInfo>& stationAuxList) {}
|
---|
| 47 | void handleDGPSCorr(const vector<DGPSCorr>& dgpsList) {}
|
---|
| 48 | void handleSatelliteClock(const vector<SatelliteClock>& svList) {}
|
---|
[5397] | 49 | void handleEpochResults(const RtnetEpoch& epoch);
|
---|
[4925] | 50 | };
|
---|
| 51 |
|
---|
[5393] | 52 | // Read Command-line Options
|
---|
| 53 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 54 | void 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 |
|
---|
[5392] | 76 | // Program
|
---|
| 77 | //////////////////////////////////////////////////////////////////////////////
|
---|
[4925] | 78 | int main(int argc, char **argv) {
|
---|
| 79 |
|
---|
[5393] | 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));
|
---|
[4935] | 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));
|
---|
[4928] | 96 |
|
---|
[4935] | 97 | try {
|
---|
| 98 | transport->open();
|
---|
[4925] | 99 |
|
---|
[4935] | 100 | while (processor->process(protocol,protocol,0)) {}
|
---|
| 101 |
|
---|
| 102 | transport->close();
|
---|
[4925] | 103 | }
|
---|
| 104 | catch (TException& e) {
|
---|
[4927] | 105 | cerr << "Caught an exception generated by Thrift: " << e.what() << endl;
|
---|
| 106 | return 1;
|
---|
[4925] | 107 | }
|
---|
| 108 | catch (...) {
|
---|
[4927] | 109 | cerr << "Unknown exception" << endl;
|
---|
| 110 | return 1;
|
---|
[4925] | 111 | }
|
---|
| 112 |
|
---|
| 113 | return 0;
|
---|
| 114 | }
|
---|
[5392] | 115 |
|
---|
| 116 | // Handle Satellite Positions
|
---|
| 117 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 118 | void RtnetClientHandler::
|
---|
| 119 | handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
|
---|
| 120 | cout.setf(ios::fixed);
|
---|
| 121 | for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
|
---|
[5397] | 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;
|
---|
[5392] | 127 | }
|
---|
[5397] | 128 | // cout << endl;
|
---|
[5392] | 129 | }
|
---|
| 130 |
|
---|
[5398] | 131 | // Handle Station Info
|
---|
| 132 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 133 | void RtnetClientHandler::
|
---|
| 134 | handleStationInfo(const vector<StationInfo>& stationList) {
|
---|
| 135 | for (unsigned ii = 0; ii < stationList.size(); ii++) {
|
---|
| 136 | const StationInfo& staInfo = stationList[ii];
|
---|
[5399] | 137 | _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
|
---|
| 138 | _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
|
---|
| 139 | _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
|
---|
[5398] | 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[5397] | 143 | // Handle Eoch Results
|
---|
| 144 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 145 | void RtnetClientHandler::
|
---|
| 146 | handleEpochResults(const RtnetEpoch& epoch) {
|
---|
| 147 | for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
|
---|
| 148 | const StationResults& staRes = epoch.stationResultList[ii];
|
---|
| 149 | cout << staRes.stationName << ' '
|
---|
[5398] | 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;
|
---|
[5397] | 157 | }
|
---|
| 158 | }
|
---|