| 1 |
|
|---|
| 2 | #include <iostream>
|
|---|
| 3 | #include <iomanip>
|
|---|
| 4 | #include <sstream>
|
|---|
| 5 | #include <vector>
|
|---|
| 6 |
|
|---|
| 7 | #include "thriftclient.h"
|
|---|
| 8 | #include "monitor.h"
|
|---|
| 9 |
|
|---|
| 10 | using namespace apache::thrift;
|
|---|
| 11 | using namespace apache::thrift::protocol;
|
|---|
| 12 | using namespace apache::thrift::transport;
|
|---|
| 13 |
|
|---|
| 14 | using namespace com::gpssolutions::rtnet;
|
|---|
| 15 | using namespace std;
|
|---|
| 16 | using namespace boost;
|
|---|
| 17 |
|
|---|
| 18 | using namespace GnssCenter;
|
|---|
| 19 |
|
|---|
| 20 | // Constructor
|
|---|
| 21 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 22 | t_thriftClient::t_thriftClient(t_monitor* parent, const QString& host, int port) {
|
|---|
| 23 | _stop = false;
|
|---|
| 24 | _parent = parent;
|
|---|
| 25 | _host = host.toAscii().data();
|
|---|
| 26 | _port = port;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | // Destructor
|
|---|
| 30 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 31 | t_thriftClient::~t_thriftClient() {
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | // Run (virtual)
|
|---|
| 35 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 36 | void t_thriftClient::run() {
|
|---|
| 37 |
|
|---|
| 38 | shared_ptr<TSocket> socket(new TSocket(_host, _port));
|
|---|
| 39 | shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
|---|
| 40 | shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
|---|
| 41 | shared_ptr<RtnetDataIf> dataHandler(new t_thriftHandler(_parent));
|
|---|
| 42 | shared_ptr<TProcessor> processor(new RtnetDataProcessor(dataHandler));
|
|---|
| 43 |
|
|---|
| 44 | try {
|
|---|
| 45 | transport->open();
|
|---|
| 46 | while (true) {
|
|---|
| 47 | {
|
|---|
| 48 | QMutexLocker locker(&_mutex);
|
|---|
| 49 | if (_stop) {
|
|---|
| 50 | break;
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 | if (processor->process(protocol,protocol,0) == 0) {
|
|---|
| 54 | break;
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 | transport->close();
|
|---|
| 58 | }
|
|---|
| 59 | catch (TException& e) {
|
|---|
| 60 | emit message(e.what());
|
|---|
| 61 | }
|
|---|
| 62 | catch (...) {
|
|---|
| 63 | emit message("Unknown exception");
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | // Constructor
|
|---|
| 68 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 69 | t_thriftHandler::t_thriftHandler(t_monitor* parent) {
|
|---|
| 70 | _parent = parent;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | // Destructor
|
|---|
| 74 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 75 | t_thriftHandler::~t_thriftHandler() {
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | // Handle Satellite Positions
|
|---|
| 79 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 80 | void t_thriftHandler::
|
|---|
| 81 | handleSatelliteXYZ(const vector<SatelliteXYZ>& svXYZList) {
|
|---|
| 82 | vector<t_thriftSatellite*>* satellites = new vector<t_thriftSatellite*>;
|
|---|
| 83 | for (unsigned ii = 0; ii < svXYZList.size(); ii++) {
|
|---|
| 84 | const SatelliteXYZ& sat = svXYZList[ii];
|
|---|
| 85 | t_thriftSatellite* satellite = new t_thriftSatellite;
|
|---|
| 86 | char ch;
|
|---|
| 87 | switch(sat.constellation) {
|
|---|
| 88 | case (ConstellationType::GPS): ch = 'G'; break;
|
|---|
| 89 | case (ConstellationType::GLONASS): ch = 'R'; break;
|
|---|
| 90 | case (ConstellationType::SBAS): ch = 'S'; break;
|
|---|
| 91 | case (ConstellationType::GALILEO): ch = 'E'; break;
|
|---|
| 92 | case (ConstellationType::QZSS): ch = 'J'; break;
|
|---|
| 93 | case (ConstellationType::COMPASS): ch = 'C'; break;
|
|---|
| 94 | }
|
|---|
| 95 | char prn[3];
|
|---|
| 96 | sprintf(prn, "%c%2d", ch, sat.ID);
|
|---|
| 97 | satellite->_prn = prn;
|
|---|
| 98 | satellite->_x = sat.xyz.x;
|
|---|
| 99 | satellite->_y = sat.xyz.y;
|
|---|
| 100 | satellite->_z = sat.xyz.z;
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | // Handle Station Info
|
|---|
| 105 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 106 | void t_thriftHandler::
|
|---|
| 107 | handleStationInfo(const vector<StationInfo>& stationList) {
|
|---|
| 108 | for (unsigned ii = 0; ii < stationList.size(); ii++) {
|
|---|
| 109 | const StationInfo& staInfo = stationList[ii];
|
|---|
| 110 | _stationCrd[staInfo.ID]._x = staInfo.xyz.x;
|
|---|
| 111 | _stationCrd[staInfo.ID]._y = staInfo.xyz.y;
|
|---|
| 112 | _stationCrd[staInfo.ID]._z = staInfo.xyz.z;
|
|---|
| 113 | }
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | // Handle Epoch Results
|
|---|
| 117 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 118 | void t_thriftHandler::
|
|---|
| 119 | handleEpochResults(const RtnetEpoch& epoch) {
|
|---|
| 120 | vector<t_thriftResult*>* results = new vector<t_thriftResult*>;
|
|---|
| 121 | for (unsigned ii = 0; ii < epoch.stationResultList.size(); ii++) {
|
|---|
| 122 | const StationResults& staRes = epoch.stationResultList[ii];
|
|---|
| 123 | t_thriftResult* res = new t_thriftResult;
|
|---|
| 124 | res->_name = staRes.stationName;
|
|---|
| 125 | res->_nGPS = staRes.nsv_gps_used;
|
|---|
| 126 | res->_nGLO = staRes.nsv_glonass_used;
|
|---|
| 127 | if (_stationCrd.find(staRes.stationName) != _stationCrd.end()) {
|
|---|
| 128 | res->_x = _stationCrd[staRes.stationName]._x;
|
|---|
| 129 | res->_y = _stationCrd[staRes.stationName]._y;
|
|---|
| 130 | res->_z = _stationCrd[staRes.stationName]._z;
|
|---|
| 131 | }
|
|---|
| 132 | results->push_back(res);
|
|---|
| 133 | }
|
|---|
| 134 | _parent->putThriftResults(results);
|
|---|
| 135 | }
|
|---|