From 4e8f64656e1308e357da81f86d2225480f620db5 Mon Sep 17 00:00:00 2001 From: Stefano Date: Tue, 10 Sep 2024 12:18:21 +0200 Subject: [PATCH 1/4] Updated gitignore to remove Visual Studio files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c57f9989..889aca1d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ CMakeLists.txt.* *.*~ .vscode/c_cpp_properties.json .vscode/settings.json +.vs/* +CMakeSettings.json From 17b85118bff346a54b78a2f0f96bde6db9f61c29 Mon Sep 17 00:00:00 2001 From: Stefano Date: Tue, 10 Sep 2024 12:19:23 +0200 Subject: [PATCH 2/4] Removed trailing whitespaces --- devices/IWearRemapper/src/IWearRemapper.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/devices/IWearRemapper/src/IWearRemapper.cpp b/devices/IWearRemapper/src/IWearRemapper.cpp index 0b8b5315..145ad643 100644 --- a/devices/IWearRemapper/src/IWearRemapper.cpp +++ b/devices/IWearRemapper/src/IWearRemapper.cpp @@ -36,7 +36,7 @@ class IWearRemapper::impl bool firstRun = true; bool terminationCall = false; bool inputDataPorts = false; - + bool allowDynamicData = true; // Flag to wait for first data received @@ -148,7 +148,7 @@ IWearRemapper::~IWearRemapper() = default; bool IWearRemapper::open(yarp::os::Searchable& config) { // ===================== - // CHECK THE INPUT PORTS + // CHECK THE INPUT PORTS // ===================== // wait for attachAll @@ -169,7 +169,7 @@ bool IWearRemapper::open(yarp::os::Searchable& config) pImpl->allowDynamicData = config.find("allowDynamicData").asBool(); } yInfo() << logPrefix << "Using allowDynamicData parameter:"<allowDynamicData; - + pImpl->inputDataPorts = config.check("wearableDataPorts"); if (pImpl->inputDataPorts) { @@ -183,7 +183,7 @@ bool IWearRemapper::open(yarp::os::Searchable& config) yarp::os::Bottle* inputDataPortsNamesList = config.find("wearableDataPorts").asList(); if (inputDataPortsNamesList->size() == 0) { - pImpl->inputDataPorts = false; + pImpl->inputDataPorts = false; } else { for (unsigned i = 0; i < inputDataPortsNamesList->size(); ++i) { @@ -260,10 +260,10 @@ bool IWearRemapper::open(yarp::os::Searchable& config) if (!pImpl->waitForAttachAll) { start(); } - + } } - + yDebug() << logPrefix << "Opened correctly"; return true; @@ -311,7 +311,7 @@ bool IWearRemapper::impl::updateData(msg::WearableData& receivedWearData, bool c // ==================== // EXPOSE THE INTERFACE // ==================== - + auto isensor = getOrCreateSensor( inputSensorName, sensor::SensorType::Accelerometer, accelerometers, create); @@ -751,7 +751,7 @@ void IWearRemapper::onRead(msg::WearableData& wearData, const yarp::os::TypedRea allRead = false; } } - + if(allRead) { pImpl->firstRun = false; @@ -985,7 +985,7 @@ IWearRemapper::getSensors(const sensor::SensorType type) const { pImpl->mutex.lock(); } - + switch (type) { case sensor::SensorType::Accelerometer: for (const auto& s : pImpl->accelerometers) { From eccaa68b8ebc08ef7d9b3ece667b7ff641070d8d Mon Sep 17 00:00:00 2001 From: Stefano Date: Tue, 10 Sep 2024 12:42:34 +0200 Subject: [PATCH 3/4] Allowed specifying local ports when opening IWearRemapper --- devices/IWearRemapper/src/IWearRemapper.cpp | 38 ++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/devices/IWearRemapper/src/IWearRemapper.cpp b/devices/IWearRemapper/src/IWearRemapper.cpp index 145ad643..e078d3e4 100644 --- a/devices/IWearRemapper/src/IWearRemapper.cpp +++ b/devices/IWearRemapper/src/IWearRemapper.cpp @@ -188,11 +188,41 @@ bool IWearRemapper::open(yarp::os::Searchable& config) else { for (unsigned i = 0; i < inputDataPortsNamesList->size(); ++i) { if (!inputDataPortsNamesList->get(i).isString()) { - yError() << logPrefix << "ith entry of wearableDataPorts list is not a string"; + yError() << logPrefix << i << "th entry of wearableDataPorts list is not a string"; return false; } } + std::vector localNames; + if (config.check("wearableDataLocals")) { + if (!config.find("wearableDataLocals").isList()) { + yError() << logPrefix << "wearableDataLocals option found, but it is not a list."; + return false; + } + yarp::os::Bottle* localDataPortsNamesList = + config.find("wearableDataLocals").asList(); + if (localDataPortsNamesList->size() != inputDataPortsNamesList->size()) { + yError() << logPrefix + << "wearableDataLocals and wearableDataPorts have different sizes."; + return false; + } + for (unsigned i = 0; i < localDataPortsNamesList->size(); ++i) { + if (!localDataPortsNamesList->get(i).isString()) { + yError() << logPrefix << i + << "th entry of wearableDataLocals list is not a string."; + return false; + } + localNames.push_back(localDataPortsNamesList->get(i).asString()); + } + } + else { + yInfo() << logPrefix + << "wearableDataLocals option not found, using temporary port names for the local ports."; + for (unsigned i = 0; i < inputDataPortsNamesList->size(); ++i) { + localNames.push_back("..."); // use temporary port names + } + } + // =============================== // PARSE THE CONFIGURATION OPTIONS // =============================== @@ -222,11 +252,11 @@ bool IWearRemapper::open(yarp::os::Searchable& config) // ========================== yDebug() << logPrefix << "Configuring input data ports"; - for (unsigned i = 0; i < config.find("wearableDataPorts").asList()->size(); ++i) { + for (unsigned i = 0; i < inputDataPortsNamesList->size(); ++i) { pImpl->inputPortsWearData.emplace_back(new yarp::os::BufferedPort()); pImpl->inputPortsWearData.back()->useCallback(*this); - if (!pImpl->inputPortsWearData.back()->open("...")) { + if (!pImpl->inputPortsWearData.back()->open(localNames[i])) { yError() << logPrefix << "Failed to open local input port"; return false; } @@ -238,7 +268,7 @@ bool IWearRemapper::open(yarp::os::Searchable& config) // ================ yDebug() << logPrefix << "Opening input ports"; - for (unsigned i = 0; i < config.find("wearableDataPorts").asList()->size(); ++i) { + for (unsigned i = 0; i < inputDataPortsNamesList->size(); ++i) { if (!yarp::os::Network::connect(inputDataPortsNamesVector[i], pImpl->inputPortsWearData[i]->getName(), carrier)) { From 77c8b8f41c1e142dd277c6539b884f4c37b9ff80 Mon Sep 17 00:00:00 2001 From: Stefano Date: Tue, 10 Sep 2024 12:43:53 +0200 Subject: [PATCH 4/4] Moved network initialization before the connection of ports in IWearRemapper --- devices/IWearRemapper/src/IWearRemapper.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/devices/IWearRemapper/src/IWearRemapper.cpp b/devices/IWearRemapper/src/IWearRemapper.cpp index e078d3e4..2c7d80b0 100644 --- a/devices/IWearRemapper/src/IWearRemapper.cpp +++ b/devices/IWearRemapper/src/IWearRemapper.cpp @@ -268,6 +268,13 @@ bool IWearRemapper::open(yarp::os::Searchable& config) // ================ yDebug() << logPrefix << "Opening input ports"; + // Initialize the network + pImpl->network = yarp::os::Network(); + if (!yarp::os::Network::initialized() || !yarp::os::Network::checkNetwork(5.0)) { + yError() << logPrefix << "YARP server wasn't found active."; + return false; + } + for (unsigned i = 0; i < inputDataPortsNamesList->size(); ++i) { if (!yarp::os::Network::connect(inputDataPortsNamesVector[i], pImpl->inputPortsWearData[i]->getName(), @@ -278,13 +285,6 @@ bool IWearRemapper::open(yarp::os::Searchable& config) } } - // Initialize the network - pImpl->network = yarp::os::Network(); - if (!yarp::os::Network::initialized() || !yarp::os::Network::checkNetwork(5.0)) { - yError() << logPrefix << "YARP server wasn't found active."; - return false; - } - // If it not necessary to wait for the attachAll start the callbacks // We use callbacks on the input ports, the loop is a no-op if (!pImpl->waitForAttachAll) {