Commit b098b99a authored by Valentin Platzgummer's avatar Valentin Platzgummer

tile id int64_t > QString, for robustness

parent 9e620065
...@@ -517,8 +517,6 @@ HEADERS += \ ...@@ -517,8 +517,6 @@ HEADERS += \
src/comm/ros_bridge/include/messages/nemo_msgs/heartbeat.h \ src/comm/ros_bridge/include/messages/nemo_msgs/heartbeat.h \
src/comm/ros_bridge/include/messages/nemo_msgs/progress_array.h \ src/comm/ros_bridge/include/messages/nemo_msgs/progress_array.h \
src/comm/ros_bridge/include/messages/nemo_msgs/tile.h \ src/comm/ros_bridge/include/messages/nemo_msgs/tile.h \
src/comm/ros_bridge/include/messages/std_msgs/header.h \
src/comm/ros_bridge/include/messages/std_msgs/time.h \
src/comm/utilities.h src/comm/utilities.h
contains (DEFINES, QGC_ENABLE_PAIRING) { contains (DEFINES, QGC_ENABLE_PAIRING) {
...@@ -560,8 +558,6 @@ SOURCES += \ ...@@ -560,8 +558,6 @@ SOURCES += \
src/comm/ros_bridge/include/messages/nemo_msgs/labeled_progress.cpp \ src/comm/ros_bridge/include/messages/nemo_msgs/labeled_progress.cpp \
src/comm/ros_bridge/include/messages/nemo_msgs/progress_array.cpp \ src/comm/ros_bridge/include/messages/nemo_msgs/progress_array.cpp \
src/comm/ros_bridge/include/messages/nemo_msgs/tile.cpp \ src/comm/ros_bridge/include/messages/nemo_msgs/tile.cpp \
src/comm/ros_bridge/include/messages/std_msgs/header.cpp \
src/comm/ros_bridge/include/messages/std_msgs/time.cpp \
src/Settings/WimaSettings.cc \ src/Settings/WimaSettings.cc \
contains (DEFINES, QGC_ENABLE_PAIRING) { contains (DEFINES, QGC_ENABLE_PAIRING) {
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
#include <QVector> #include <QVector>
typedef QVector<std::int64_t> IDArray; typedef QVector<QString> IDArray;
#endif // IDARRAY_H #endif // IDARRAY_H
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "SettingsFact.h" #include "SettingsFact.h"
#include "AreaData.h" #include "AreaData.h"
#include "ProgressArray.h" #include "geometry/ProgressArray.h"
class RoutingThread; class RoutingThread;
class RoutingResult; class RoutingResult;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <shared_mutex> #include <shared_mutex>
#include <QJsonArray>
#include <QJsonObject>
#include <QTimer> #include <QTimer>
#include <QUrl> #include <QUrl>
...@@ -24,9 +26,6 @@ ...@@ -24,9 +26,6 @@
#include "ros_bridge/include/messages/nemo_msgs/heartbeat.h" #include "ros_bridge/include/messages/nemo_msgs/heartbeat.h"
#include "ros_bridge/include/messages/nemo_msgs/progress_array.h" #include "ros_bridge/include/messages/nemo_msgs/progress_array.h"
#include "ros_bridge/include/messages/nemo_msgs/tile.h" #include "ros_bridge/include/messages/nemo_msgs/tile.h"
#include "ros_bridge/rapidjson/include/rapidjson/document.h"
#include "ros_bridge/rapidjson/include/rapidjson/ostreamwrapper.h"
#include "ros_bridge/rapidjson/include/rapidjson/writer.h"
#include "rosbridge/rosbridge.h" #include "rosbridge/rosbridge.h"
QGC_LOGGING_CATEGORY(NemoInterfaceLog, "NemoInterfaceLog") QGC_LOGGING_CATEGORY(NemoInterfaceLog, "NemoInterfaceLog")
...@@ -44,8 +43,8 @@ using ROSBridgePtr = std::shared_ptr<Rosbridge>; ...@@ -44,8 +43,8 @@ using ROSBridgePtr = std::shared_ptr<Rosbridge>;
typedef ros_bridge::messages::nemo_msgs::tile::GenericTile<QGeoCoordinate, typedef ros_bridge::messages::nemo_msgs::tile::GenericTile<QGeoCoordinate,
QList> QList>
Tile; Tile;
typedef std::map<std::int64_t, std::shared_ptr<Tile>> TileMap; typedef std::map<QString, std::shared_ptr<Tile>> TileMap;
typedef std::map<std::int64_t, std::shared_ptr<const Tile>> TileMapConst; typedef std::map<QString, std::shared_ptr<const Tile>> TileMapConst;
typedef ros_bridge::messages::nemo_msgs::heartbeat::Heartbeat Heartbeat; typedef ros_bridge::messages::nemo_msgs::heartbeat::Heartbeat Heartbeat;
typedef nemo_interface::TaskDispatcher Dispatcher; typedef nemo_interface::TaskDispatcher Dispatcher;
typedef nemo_interface::FutureWatcher<QVariant, std::shared_future> typedef nemo_interface::FutureWatcher<QVariant, std::shared_future>
...@@ -599,19 +598,10 @@ void NemoInterface::Impl::_doTopicServiceSetup() { ...@@ -599,19 +598,10 @@ void NemoInterface::Impl::_doTopicServiceSetup() {
using namespace ros_bridge::messages; using namespace ros_bridge::messages;
// Subscribe nemo progress. // Subscribe nemo progress.
this->_pRosbridge->subscribeTopic(progressTopic, [this]( this->_pRosbridge->subscribeTopic(
const QJsonObject &o) { progressTopic, [this](const QJsonObject &o) {
QString msg = QJsonDocument(o).toJson(QJsonDocument::JsonFormat::Compact);
// parse in_message
rapidjson::Document d;
d.Parse(msg.toUtf8());
if (!d.HasParseError()) {
if (d.HasMember("msg") && d["msg"].IsObject()) {
// create obj from json
nemo_msgs::progress_array::ProgressArray progressArray; nemo_msgs::progress_array::ProgressArray progressArray;
if (nemo_msgs::progress_array::fromJson(d["msg"], progressArray)) { if (nemo_msgs::progress_array::fromJson(o, progressArray)) {
// correct range errors of progress // correct range errors of progress
for (auto &lp : progressArray.progress_array()) { for (auto &lp : progressArray.progress_array()) {
...@@ -645,32 +635,15 @@ void NemoInterface::Impl::_doTopicServiceSetup() { ...@@ -645,32 +635,15 @@ void NemoInterface::Impl::_doTopicServiceSetup() {
} else { } else {
qCWarning(NemoInterfaceLog) << "/nemo/progress not able to " qCWarning(NemoInterfaceLog) << "/nemo/progress not able to "
"create ProgressArray form json: " "create ProgressArray form json: "
<< msg; << o;
}
} else {
qCWarning(NemoInterfaceLog)
<< "/nemo/progress no \"msg\" key or wrong type: " << msg;
}
} else {
qCWarning(NemoInterfaceLog) << "/nemo/progress message parse error ("
<< d.GetParseError() << "): " << msg;
} }
}); });
// Subscribe heartbeat msg. // Subscribe heartbeat msg.
this->_pRosbridge->subscribeTopic(heartbeatTopic, [this]( this->_pRosbridge->subscribeTopic(
const QJsonObject &o) { heartbeatTopic, [this](const QJsonObject &o) {
QString msg = QJsonDocument(o).toJson(QJsonDocument::JsonFormat::Compact);
// parse in_message
rapidjson::Document d;
d.Parse(msg.toUtf8());
if (!d.HasParseError()) {
if (d.HasMember("msg") && d["msg"].IsObject()) {
// create obj from json
nemo_msgs::heartbeat::Heartbeat heartbeat; nemo_msgs::heartbeat::Heartbeat heartbeat;
if (nemo_msgs::heartbeat::fromJson(d["msg"], heartbeat)) { if (nemo_msgs::heartbeat::fromJson(o, heartbeat)) {
std::promise<bool> promise; std::promise<bool> promise;
auto future = promise.get_future(); auto future = promise.get_future();
bool value = QMetaObject::invokeMethod( bool value = QMetaObject::invokeMethod(
...@@ -683,15 +656,7 @@ void NemoInterface::Impl::_doTopicServiceSetup() { ...@@ -683,15 +656,7 @@ void NemoInterface::Impl::_doTopicServiceSetup() {
} else { } else {
qCWarning(NemoInterfaceLog) << "/nemo/heartbeat not able to " qCWarning(NemoInterfaceLog) << "/nemo/heartbeat not able to "
"create Heartbeat form json: " "create Heartbeat form json: "
<< msg; << o;
}
} else {
qCWarning(NemoInterfaceLog)
<< "/nemo/heartbeat no \"msg\" key or wrong type: " << msg;
}
} else {
qCWarning(NemoInterfaceLog) << "/nemo/heartbeat message parse error ("
<< d.GetParseError() << "): " << msg;
} }
}); });
} }
...@@ -701,6 +666,11 @@ void NemoInterface::Impl::_trySynchronize() { ...@@ -701,6 +666,11 @@ void NemoInterface::Impl::_trySynchronize() {
this->_state == STATE::USER_SYNC) && this->_state == STATE::USER_SYNC) &&
!_isSynchronized()) { !_isSynchronized()) {
if (!_dispatcher.idle()) {
QTimer::singleShot(5000, [this] { this->_trySynchronize(); });
return;
}
qCWarning(NemoInterfaceLog) << "trying to synchronize"; qCWarning(NemoInterfaceLog) << "trying to synchronize";
this->_setState(STATE::SYS_SYNC); this->_setState(STATE::SYS_SYNC);
...@@ -711,8 +681,6 @@ void NemoInterface::Impl::_trySynchronize() { ...@@ -711,8 +681,6 @@ void NemoInterface::Impl::_trySynchronize() {
std::bind(&Impl::_callClearTiles, this)); std::bind(&Impl::_callClearTiles, this));
// dispatch command. // dispatch command.
_dispatcher.clear();
_dispatcher.stop();
Q_ASSERT(_dispatcher.pendingTasks() == 0); Q_ASSERT(_dispatcher.pendingTasks() == 0);
auto ret = _dispatcher.dispatch(std::move(pTask)); auto ret = _dispatcher.dispatch(std::move(pTask));
auto clearFuture = ret.share(); auto clearFuture = ret.share();
...@@ -775,7 +743,6 @@ void NemoInterface::Impl::_doAction() { ...@@ -775,7 +743,6 @@ void NemoInterface::Impl::_doAction() {
case STATE::START_BRIDGE: case STATE::START_BRIDGE:
this->_pRosbridge->start(); this->_pRosbridge->start();
break; break;
break;
case STATE::WEBSOCKET_DETECTED: case STATE::WEBSOCKET_DETECTED:
resetDone = false; resetDone = false;
this->_setState(STATE::TRY_TOPIC_SERVICE_SETUP); this->_setState(STATE::TRY_TOPIC_SERVICE_SETUP);
...@@ -814,62 +781,38 @@ QVariant NemoInterface::Impl::_callAddTiles( ...@@ -814,62 +781,38 @@ QVariant NemoInterface::Impl::_callAddTiles(
this->_lastCall = CALL_NAME::ADD_TILES; this->_lastCall = CALL_NAME::ADD_TILES;
// create json object // create json object
rapidjson::Document request(rapidjson::kObjectType); QJsonArray jsonTileArray;
auto &allocator = request.GetAllocator();
rapidjson::Value jsonTileArray(rapidjson::kArrayType);
for (const auto &tile : *pTileArray) { for (const auto &tile : *pTileArray) {
using namespace ros_bridge::messages; using namespace ros_bridge::messages;
rapidjson::Value jsonTile(rapidjson::kObjectType); QJsonObject jsonTile;
if (!nemo_msgs::tile::toJson(*tile, jsonTile, allocator)) { if (!nemo_msgs::tile::toJson(*tile, jsonTile)) {
qCDebug(NemoInterfaceLog) qCDebug(NemoInterfaceLog)
<< "addTiles(): not able to create json object: tile id: " << "addTiles(): not able to create json object: tile id: "
<< tile->id() << " progress: " << tile->progress() << tile->id() << " progress: " << tile->progress()
<< " points: " << tile->tile(); << " points: " << tile->tile();
} }
jsonTileArray.PushBack(jsonTile, allocator); jsonTileArray.append(std::move(jsonTile));
} // for } // for
rapidjson::Value tileKey("in_tile_array"); QJsonObject req;
request.AddMember(tileKey, jsonTileArray, allocator); req["in_tile_array"] = std::move(jsonTileArray);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
request.Accept(writer);
QJsonDocument req = QJsonDocument::fromJson(buffer.GetString());
// create response handler. // create response handler.
auto promise_response = std::make_shared<std::promise<bool>>(); auto promise_response = std::make_shared<std::promise<bool>>();
auto future_response = promise_response->get_future(); auto future_response = promise_response->get_future();
auto responseHandler = [promise_response](const QJsonObject &o) mutable { auto responseHandler = [promise_response](const QJsonObject &o) mutable {
// check if transaction was successfull // check if transaction was successfull
QString msg = QJsonDocument(o).toJson(QJsonDocument::JsonFormat::Compact); if (o.contains("success") && o["success"].isBool()) {
rapidjson::Document d; promise_response->set_value(o["success"].toBool());
d.Parse(msg.toUtf8());
if (!d.HasParseError()) {
if (d.HasMember("values") && d["values"].IsObject()) {
auto values = d["values"].GetObject();
if (values.HasMember("success") && values["success"].IsBool()) {
promise_response->set_value(values["success"].GetBool());
} else {
qCWarning(NemoInterfaceLog)
<< "/nemo/add_tiles no \"success\" key or wrong type: " << msg;
promise_response->set_value(false);
}
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemoInterfaceLog)
<< "/nemo/add_tiles no \"values\" key or wrong type: " << msg; << "/nemo/add_tiles no \"success\" key or wrong type: " << o;
promise_response->set_value(false);
}
} else {
qCWarning(NemoInterfaceLog) << "/nemo/add_tiles message parse error ("
<< d.GetParseError() << "): " << msg;
promise_response->set_value(false); promise_response->set_value(false);
} }
}; };
// call service. // call service.
this->_pRosbridge->callService("/nemo/add_tiles", responseHandler, this->_pRosbridge->callService("/nemo/add_tiles", responseHandler, req);
req.object());
// wait for response. // wait for response.
auto tStart = hrc::now(); auto tStart = hrc::now();
...@@ -915,20 +858,13 @@ NemoInterface::Impl::_callRemoveTiles(std::shared_ptr<IDArray> pIdArray) { ...@@ -915,20 +858,13 @@ NemoInterface::Impl::_callRemoveTiles(std::shared_ptr<IDArray> pIdArray) {
this->_lastCall = CALL_NAME::REMOVE_TILES; this->_lastCall = CALL_NAME::REMOVE_TILES;
// create json object // create json object
rapidjson::Document request(rapidjson::kObjectType); QJsonArray jsonIdArray;
auto &allocator = request.GetAllocator();
rapidjson::Value jsonIdArray(rapidjson::kArrayType);
for (const auto id : *pIdArray) { for (const auto id : *pIdArray) {
using namespace ros_bridge::messages; using namespace ros_bridge::messages;
jsonIdArray.PushBack(rapidjson::Value(id), allocator); jsonIdArray.append(id);
} // for } // for
rapidjson::Value tileKey("ids"); QJsonObject req;
request.AddMember(tileKey, jsonIdArray, allocator); req["ids"] = std::move(jsonIdArray);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
request.Accept(writer);
QJsonDocument req = QJsonDocument::fromJson(buffer.GetString());
// create response handler. // create response handler.
auto promise_response = std::make_shared<std::promise<bool>>(); auto promise_response = std::make_shared<std::promise<bool>>();
...@@ -936,33 +872,17 @@ NemoInterface::Impl::_callRemoveTiles(std::shared_ptr<IDArray> pIdArray) { ...@@ -936,33 +872,17 @@ NemoInterface::Impl::_callRemoveTiles(std::shared_ptr<IDArray> pIdArray) {
auto responseHandler = [promise_response](const QJsonObject &o) mutable { auto responseHandler = [promise_response](const QJsonObject &o) mutable {
// check if transaction was successfull // check if transaction was successfull
QString msg = QJsonDocument(o).toJson(QJsonDocument::JsonFormat::Compact); QString msg = QJsonDocument(o).toJson(QJsonDocument::JsonFormat::Compact);
rapidjson::Document d; if (o.contains("success") && o["success"].isBool()) {
d.Parse(msg.toUtf8()); promise_response->set_value(o["success"].toBool());
if (!d.HasParseError()) {
if (d.HasMember("values") && d["values"].IsObject()) {
auto values = d["values"].GetObject();
if (values.HasMember("success") && values["success"].IsBool()) {
promise_response->set_value(values["success"].GetBool());
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemoInterfaceLog)
<< "/nemo/remove_tiles no \"success\" key or wrong type: " << msg; << "/nemo/remove_tiles no \"success\" key or wrong type: " << msg;
promise_response->set_value(false); promise_response->set_value(false);
} }
} else {
qCWarning(NemoInterfaceLog)
<< "/nemo/remove_tiles no \"values\" key or wrong type: " << msg;
promise_response->set_value(false);
}
} else {
qCWarning(NemoInterfaceLog) << "/nemo/remove_tiles message parse error ("
<< d.GetParseError() << "): " << msg;
promise_response->set_value(false);
}
}; };
// call service. // call service.
this->_pRosbridge->callService("/nemo/remove_tiles", responseHandler, this->_pRosbridge->callService("/nemo/remove_tiles", responseHandler, req);
req.object());
// wait for response. // wait for response.
auto tStart = hrc::now(); auto tStart = hrc::now();
...@@ -1011,22 +931,7 @@ QVariant NemoInterface::Impl::_callClearTiles() { ...@@ -1011,22 +931,7 @@ QVariant NemoInterface::Impl::_callClearTiles() {
auto future_response = promise_response->get_future(); auto future_response = promise_response->get_future();
auto responseHandler = [promise_response](const QJsonObject &o) mutable { auto responseHandler = [promise_response](const QJsonObject &o) mutable {
// check if transaction was successfull // check if transaction was successfull
QString msg = QJsonDocument(o).toJson(QJsonDocument::JsonFormat::Compact); promise_response->set_value(true);
rapidjson::Document d;
d.Parse(msg.toUtf8());
if (!d.HasParseError()) {
if (d.HasMember("result") && d["result"].IsBool()) {
promise_response->set_value(d["result"].GetBool());
} else {
qCWarning(NemoInterfaceLog)
<< "/nemo/clear_tiles no \"result\" key or wrong type: " << msg;
promise_response->set_value(false);
}
} else {
qCWarning(NemoInterfaceLog) << "/nemo/clear_tiles message parse error ("
<< d.GetParseError() << "): " << msg;
promise_response->set_value(false);
}
}; };
// call service. // call service.
...@@ -1075,20 +980,13 @@ NemoInterface::Impl::_callGetProgress(std::shared_ptr<IDArray> pIdArray) { ...@@ -1075,20 +980,13 @@ NemoInterface::Impl::_callGetProgress(std::shared_ptr<IDArray> pIdArray) {
this->_lastCall = CALL_NAME::GET_PROGRESS; this->_lastCall = CALL_NAME::GET_PROGRESS;
// create json object // create json object
rapidjson::Document request(rapidjson::kObjectType); QJsonArray jsonIdArray;
auto &allocator = request.GetAllocator();
rapidjson::Value jsonIdArray(rapidjson::kArrayType);
for (const auto id : *pIdArray) { for (const auto id : *pIdArray) {
using namespace ros_bridge::messages; using namespace ros_bridge::messages;
jsonIdArray.PushBack(rapidjson::Value(id), allocator); jsonIdArray.append(id);
} // for } // for
rapidjson::Value tileKey("ids"); QJsonObject req;
request.AddMember(tileKey, jsonIdArray, allocator); req["ids"] = std::move(jsonIdArray);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
request.Accept(writer);
QJsonDocument req = QJsonDocument::fromJson(buffer.GetString());
// create response handler. // create response handler.
typedef std::shared_ptr<ProgressArray> ResponseType; typedef std::shared_ptr<ProgressArray> ResponseType;
...@@ -1096,16 +994,10 @@ NemoInterface::Impl::_callGetProgress(std::shared_ptr<IDArray> pIdArray) { ...@@ -1096,16 +994,10 @@ NemoInterface::Impl::_callGetProgress(std::shared_ptr<IDArray> pIdArray) {
auto future_response = promise_response->get_future(); auto future_response = promise_response->get_future();
auto responseHandler = [promise_response](const QJsonObject &o) mutable { auto responseHandler = [promise_response](const QJsonObject &o) mutable {
// check if transaction was successfull // check if transaction was successfull
QString msg = QJsonDocument(o).toJson(QJsonDocument::JsonFormat::Compact);
rapidjson::Document d;
d.Parse(msg.toUtf8());
if (!d.HasParseError()) {
if (d.HasMember("values") && d["values"].IsObject()) {
auto values = d["values"].GetObject();
ros_bridge::messages::nemo_msgs::progress_array::ProgressArray ros_bridge::messages::nemo_msgs::progress_array::ProgressArray
progressArrayMsg; progressArrayMsg;
if (ros_bridge::messages::nemo_msgs::progress_array::fromJson( if (ros_bridge::messages::nemo_msgs::progress_array::fromJson(
d["values"], progressArrayMsg)) { o, progressArrayMsg)) {
auto pArray = std::make_shared<ProgressArray>(); auto pArray = std::make_shared<ProgressArray>();
*pArray = std::move(progressArrayMsg.progress_array()); *pArray = std::move(progressArrayMsg.progress_array());
promise_response->set_value(pArray); promise_response->set_value(pArray);
...@@ -1115,21 +1007,10 @@ NemoInterface::Impl::_callGetProgress(std::shared_ptr<IDArray> pIdArray) { ...@@ -1115,21 +1007,10 @@ NemoInterface::Impl::_callGetProgress(std::shared_ptr<IDArray> pIdArray) {
"from json."; "from json.";
promise_response->set_value(nullptr); promise_response->set_value(nullptr);
} }
} else {
qCWarning(NemoInterfaceLog)
<< "/nemo/get_progress no \"values\" key or wrong type: " << msg;
promise_response->set_value(nullptr);
}
} else {
qCWarning(NemoInterfaceLog) << "/nemo/get_progress message parse error ("
<< d.GetParseError() << "): " << msg;
promise_response->set_value(nullptr);
}
}; };
// call service. // call service.
this->_pRosbridge->callService("/nemo/get_progress", responseHandler, this->_pRosbridge->callService("/nemo/get_progress", responseHandler, req);
req.object());
// wait for response. // wait for response.
auto tStart = hrc::now(); auto tStart = hrc::now();
...@@ -1179,34 +1060,18 @@ QVariant NemoInterface::Impl::_callGetAllProgress() { ...@@ -1179,34 +1060,18 @@ QVariant NemoInterface::Impl::_callGetAllProgress() {
auto future_response = promise_response->get_future(); auto future_response = promise_response->get_future();
auto responseHandler = [promise_response](const QJsonObject &o) mutable { auto responseHandler = [promise_response](const QJsonObject &o) mutable {
// check if transaction was successfull // check if transaction was successfull
QString msg = QJsonDocument(o).toJson(QJsonDocument::JsonFormat::Compact);
rapidjson::Document d;
d.Parse(msg.toUtf8());
if (!d.HasParseError()) {
if (d.HasMember("values") && d["values"].IsObject()) {
ros_bridge::messages::nemo_msgs::progress_array::ProgressArray ros_bridge::messages::nemo_msgs::progress_array::ProgressArray
progressArrayMsg; progressArrayMsg;
if (ros_bridge::messages::nemo_msgs::progress_array::fromJson( if (ros_bridge::messages::nemo_msgs::progress_array::fromJson(
d["values"], progressArrayMsg)) { o, progressArrayMsg)) {
auto pArray = std::make_shared<ProgressArray>(); auto pArray = std::make_shared<ProgressArray>();
*pArray = std::move(progressArrayMsg.progress_array()); *pArray = std::move(progressArrayMsg.progress_array());
promise_response->set_value(pArray); promise_response->set_value(pArray);
} else { } else {
qCWarning(NemoInterfaceLog) qCWarning(NemoInterfaceLog)
<< "/nemo/all_get_progress error while creating ProgressArray " << "/nemo/get_all_progress error while creating ProgressArray "
"from json."; "from json. msg: "
promise_response->set_value(nullptr); << o;
}
} else {
qCWarning(NemoInterfaceLog)
<< "/nemo/all_get_progress no \"values\" key or wrong type: "
<< msg;
promise_response->set_value(nullptr);
}
} else {
qCWarning(NemoInterfaceLog)
<< "/nemo/all_get_progress message parse error (" << d.GetParseError()
<< "): " << msg;
promise_response->set_value(nullptr); promise_response->set_value(nullptr);
} }
}; };
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#define MAX_TILES 1000 #define MAX_TILES 1000
#endif #endif
QString randomId();
using namespace geometry; using namespace geometry;
namespace trans = bg::strategy::transform; namespace trans = bg::strategy::transform;
...@@ -261,7 +263,7 @@ bool MeasurementArea::loadFromJson(const QJsonObject &json, ...@@ -261,7 +263,7 @@ bool MeasurementArea::loadFromJson(const QJsonObject &json,
// find unique id // find unique id
if (it != _indexMap.end()) { if (it != _indexMap.end()) {
auto newId = tile->id() + 1; auto newId = MeasurementTile::randomId();
constexpr long counterMax = 1e6; constexpr long counterMax = 1e6;
unsigned long counter = 0; unsigned long counter = 0;
for (; counter <= counterMax; ++counter) { for (; counter <= counterMax; ++counter) {
...@@ -269,7 +271,7 @@ bool MeasurementArea::loadFromJson(const QJsonObject &json, ...@@ -269,7 +271,7 @@ bool MeasurementArea::loadFromJson(const QJsonObject &json,
if (it == _indexMap.end()) { if (it == _indexMap.end()) {
break; break;
} else { } else {
++newId; newId = MeasurementTile::randomId();
} }
} }
...@@ -431,15 +433,11 @@ void MeasurementArea::doUpdate() { ...@@ -431,15 +433,11 @@ void MeasurementArea::doUpdate() {
// Convert to geo system. // Convert to geo system.
for (const auto &t : tilesENU) { for (const auto &t : tilesENU) {
auto geoTile = new MeasurementTile(pData.get()); auto geoTile = new MeasurementTile(pData.get());
std::size_t hashValue = 0;
std::hash<QGeoCoordinate> hashFun;
for (const auto &v : t.outer()) { for (const auto &v : t.outer()) {
QGeoCoordinate geoVertex; QGeoCoordinate geoVertex;
fromENU(origin, v, geoVertex); fromENU(origin, v, geoVertex);
geoTile->push_back(geoVertex); geoTile->push_back(geoVertex);
hashValue ^= hashFun(geoVertex);
} }
geoTile->setId(std::int64_t(hashValue));
pData->append(geoTile); pData->append(geoTile);
} }
} }
...@@ -504,7 +502,7 @@ void MeasurementArea::storeTiles() { ...@@ -504,7 +502,7 @@ void MeasurementArea::storeTiles() {
// find unique id // find unique id
if (it != _indexMap.end()) { if (it != _indexMap.end()) {
auto newId = tile->id() + 1; auto newId = MeasurementTile::randomId();
constexpr long counterMax = 1e6; constexpr long counterMax = 1e6;
unsigned long counter = 0; unsigned long counter = 0;
for (; counter <= counterMax; ++counter) { for (; counter <= counterMax; ++counter) {
...@@ -512,7 +510,7 @@ void MeasurementArea::storeTiles() { ...@@ -512,7 +510,7 @@ void MeasurementArea::storeTiles() {
if (it == _indexMap.end()) { if (it == _indexMap.end()) {
break; break;
} else { } else {
++newId; newId = MeasurementTile::randomId();
} }
} }
...@@ -710,3 +708,14 @@ bool getTiles(const FPolygon &area, Length tileHeight, Length tileWidth, ...@@ -710,3 +708,14 @@ bool getTiles(const FPolygon &area, Length tileHeight, Length tileWidth,
return true; return true;
} }
QString randomId() {
std::srand(std::time(nullptr));
std::int64_t r = 0;
for (int i = 0; i < 10; ++i) {
r ^= std::rand();
}
return QString::number(r);
}
...@@ -107,7 +107,7 @@ private: ...@@ -107,7 +107,7 @@ private:
// Tile stuff. // Tile stuff.
TilePtr _tiles; TilePtr _tiles;
std::map<std::int64_t /*id*/, int> _indexMap; std::map<QString /*id*/, int> _indexMap;
QTimer _timer; QTimer _timer;
STATE _state; STATE _state;
QFutureWatcher<TilePtr> _watcher;