@@ -36,7 +36,7 @@ class IWearRemapper::impl
36
36
bool firstRun = true ;
37
37
bool terminationCall = false ;
38
38
bool inputDataPorts = false ;
39
-
39
+
40
40
bool allowDynamicData = true ;
41
41
42
42
// Flag to wait for first data received
@@ -148,7 +148,7 @@ IWearRemapper::~IWearRemapper() = default;
148
148
bool IWearRemapper::open (yarp::os::Searchable& config)
149
149
{
150
150
// =====================
151
- // CHECK THE INPUT PORTS
151
+ // CHECK THE INPUT PORTS
152
152
// =====================
153
153
154
154
// wait for attachAll
@@ -169,7 +169,7 @@ bool IWearRemapper::open(yarp::os::Searchable& config)
169
169
pImpl->allowDynamicData = config.find (" allowDynamicData" ).asBool ();
170
170
}
171
171
yInfo () << logPrefix << " Using allowDynamicData parameter:" <<pImpl->allowDynamicData ;
172
-
172
+
173
173
pImpl->inputDataPorts = config.check (" wearableDataPorts" );
174
174
175
175
if (pImpl->inputDataPorts ) {
@@ -183,16 +183,46 @@ bool IWearRemapper::open(yarp::os::Searchable& config)
183
183
yarp::os::Bottle* inputDataPortsNamesList = config.find (" wearableDataPorts" ).asList ();
184
184
185
185
if (inputDataPortsNamesList->size () == 0 ) {
186
- pImpl->inputDataPorts = false ;
186
+ pImpl->inputDataPorts = false ;
187
187
}
188
188
else {
189
189
for (unsigned i = 0 ; i < inputDataPortsNamesList->size (); ++i) {
190
190
if (!inputDataPortsNamesList->get (i).isString ()) {
191
- yError () << logPrefix << " ith entry of wearableDataPorts list is not a string" ;
191
+ yError () << logPrefix << i << " th entry of wearableDataPorts list is not a string" ;
192
192
return false ;
193
193
}
194
194
}
195
195
196
+ std::vector<std::string> localNames;
197
+ if (config.check (" wearableDataLocals" )) {
198
+ if (!config.find (" wearableDataLocals" ).isList ()) {
199
+ yError () << logPrefix << " wearableDataLocals option found, but it is not a list." ;
200
+ return false ;
201
+ }
202
+ yarp::os::Bottle* localDataPortsNamesList =
203
+ config.find (" wearableDataLocals" ).asList ();
204
+ if (localDataPortsNamesList->size () != inputDataPortsNamesList->size ()) {
205
+ yError () << logPrefix
206
+ << " wearableDataLocals and wearableDataPorts have different sizes." ;
207
+ return false ;
208
+ }
209
+ for (unsigned i = 0 ; i < localDataPortsNamesList->size (); ++i) {
210
+ if (!localDataPortsNamesList->get (i).isString ()) {
211
+ yError () << logPrefix << i
212
+ << " th entry of wearableDataLocals list is not a string." ;
213
+ return false ;
214
+ }
215
+ localNames.push_back (localDataPortsNamesList->get (i).asString ());
216
+ }
217
+ }
218
+ else {
219
+ yInfo () << logPrefix
220
+ << " wearableDataLocals option not found, using temporary port names for the local ports." ;
221
+ for (unsigned i = 0 ; i < inputDataPortsNamesList->size (); ++i) {
222
+ localNames.push_back (" ..." ); // use temporary port names
223
+ }
224
+ }
225
+
196
226
// ===============================
197
227
// PARSE THE CONFIGURATION OPTIONS
198
228
// ===============================
@@ -222,11 +252,11 @@ bool IWearRemapper::open(yarp::os::Searchable& config)
222
252
// ==========================
223
253
yDebug () << logPrefix << " Configuring input data ports" ;
224
254
225
- for (unsigned i = 0 ; i < config. find ( " wearableDataPorts " ). asList () ->size (); ++i) {
255
+ for (unsigned i = 0 ; i < inputDataPortsNamesList ->size (); ++i) {
226
256
pImpl->inputPortsWearData .emplace_back (new yarp::os::BufferedPort<msg::WearableData>());
227
257
pImpl->inputPortsWearData .back ()->useCallback (*this );
228
258
229
- if (!pImpl->inputPortsWearData .back ()->open (" ... " )) {
259
+ if (!pImpl->inputPortsWearData .back ()->open (localNames[i] )) {
230
260
yError () << logPrefix << " Failed to open local input port" ;
231
261
return false ;
232
262
}
@@ -238,7 +268,14 @@ bool IWearRemapper::open(yarp::os::Searchable& config)
238
268
// ================
239
269
yDebug () << logPrefix << " Opening input ports" ;
240
270
241
- for (unsigned i = 0 ; i < config.find (" wearableDataPorts" ).asList ()->size (); ++i) {
271
+ // Initialize the network
272
+ pImpl->network = yarp::os::Network ();
273
+ if (!yarp::os::Network::initialized () || !yarp::os::Network::checkNetwork (5.0 )) {
274
+ yError () << logPrefix << " YARP server wasn't found active." ;
275
+ return false ;
276
+ }
277
+
278
+ for (unsigned i = 0 ; i < inputDataPortsNamesList->size (); ++i) {
242
279
if (!yarp::os::Network::connect (inputDataPortsNamesVector[i],
243
280
pImpl->inputPortsWearData [i]->getName (),
244
281
carrier)) {
@@ -248,22 +285,15 @@ bool IWearRemapper::open(yarp::os::Searchable& config)
248
285
}
249
286
}
250
287
251
- // Initialize the network
252
- pImpl->network = yarp::os::Network ();
253
- if (!yarp::os::Network::initialized () || !yarp::os::Network::checkNetwork (5.0 )) {
254
- yError () << logPrefix << " YARP server wasn't found active." ;
255
- return false ;
256
- }
257
-
258
288
// If it not necessary to wait for the attachAll start the callbacks
259
289
// We use callbacks on the input ports, the loop is a no-op
260
290
if (!pImpl->waitForAttachAll ) {
261
291
start ();
262
292
}
263
-
293
+
264
294
}
265
295
}
266
-
296
+
267
297
268
298
yDebug () << logPrefix << " Opened correctly" ;
269
299
return true ;
@@ -311,7 +341,7 @@ bool IWearRemapper::impl::updateData(msg::WearableData& receivedWearData, bool c
311
341
// ====================
312
342
// EXPOSE THE INTERFACE
313
343
// ====================
314
-
344
+
315
345
auto isensor = getOrCreateSensor<const sensor::IAccelerometer, sensor::impl::Accelerometer>(
316
346
inputSensorName, sensor::SensorType::Accelerometer, accelerometers, create);
317
347
@@ -751,7 +781,7 @@ void IWearRemapper::onRead(msg::WearableData& wearData, const yarp::os::TypedRea
751
781
allRead = false ;
752
782
}
753
783
}
754
-
784
+
755
785
if (allRead)
756
786
{
757
787
pImpl->firstRun = false ;
@@ -985,7 +1015,7 @@ IWearRemapper::getSensors(const sensor::SensorType type) const
985
1015
{
986
1016
pImpl->mutex .lock ();
987
1017
}
988
-
1018
+
989
1019
switch (type) {
990
1020
case sensor::SensorType::Accelerometer:
991
1021
for (const auto & s : pImpl->accelerometers ) {
0 commit comments