[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 |
|
---|
| 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;
|
---|
[4935] | 21 | using namespace boost;
|
---|
[4925] | 22 |
|
---|
[5398] | 23 | class t_stationCrd {
|
---|
| 24 | public:
|
---|
| 25 | double _x;
|
---|
| 26 | double _y;
|
---|
| 27 | double _z;
|
---|
| 28 | };
|
---|
| 29 |
|
---|
| 30 | map<string, t_stationCrd> _stationCrd;
|
---|
| 31 |
|
---|
[5392] | 32 | // Handler Class Definition
|
---|
| 33 | //////////////////////////////////////////////////////////////////////////////
|
---|
[4935] | 34 | class 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 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 53 | void 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] | 77 | int 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 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 117 | void RtnetClientHandler::
|
---|
| 118 | handleSatelliteXYZ(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 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 132 | void RtnetClientHandler::
|
---|
| 133 | handleStationInfo(const vector<StationInfo>& stationList) {
|
---|
| 134 | for (unsigned ii = 0; ii < stationList.size(); ii++) {
|
---|
| 135 | const StationInfo& staInfo = stationList[ii];
|
---|
[5399] | 136 | _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
|
---|
| 137 | _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
|
---|
| 138 | _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
|
---|
[5398] | 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[5397] | 142 | // Handle Eoch Results
|
---|
| 143 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 144 | void RtnetClientHandler::
|
---|
| 145 | handleEpochResults(const RtnetEpoch& epoch) {
|
---|
| 146 | for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
|
---|
| 147 | const StationResults& staRes = epoch.stationResultList[ii];
|
---|
| 148 | cout << staRes.stationName << ' '
|
---|
[5398] | 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;
|
---|
[5397] | 156 | }
|
---|
| 157 | }
|
---|