17 YARP_LOG_COMPONENT(MULTIPLEANALOGSENSORSCLIENT,
"yarp.device.multipleanalogsensorsclient")
22 std::lock_guard<std::mutex> guard(
dataMutex);
35 yCError(MULTIPLEANALOGSENSORSCLIENT,
36 "No data received in the last %lf seconds, timeout enabled.",
46 if (!config.
check(
"remote"))
48 yCError(MULTIPLEANALOGSENSORSCLIENT,
"Missing name parameter, exiting.");
52 if (!config.
check(
"local"))
54 yCError(MULTIPLEANALOGSENSORSCLIENT,
"Missing local parameter, exiting.");
60 yCError(MULTIPLEANALOGSENSORSCLIENT,
"'timeout' parameter is present but is not double, exiting.");
70 m_localRPCPortName = local +
"/rpc:i";
71 m_localStreamingPortName = local +
"/measures:i";
72 m_remoteRPCPortName = remote +
"/rpc:o";
73 m_remoteStreamingPortName = remote +
"/measures:o";
79 bool ok = m_rpcPort.
open(m_localRPCPortName);
82 yCError(MULTIPLEANALOGSENSORSCLIENT,
83 "Failure to open the port %s.",
84 m_localRPCPortName.c_str());
89 ok = m_streamingPort.
open(m_localStreamingPortName);
93 yCError(MULTIPLEANALOGSENSORSCLIENT,
94 "Failure to open the port %s.",
95 m_localStreamingPortName.c_str());
101 if (!m_externalConnection) {
104 yCError(MULTIPLEANALOGSENSORSCLIENT,
105 "Failure connecting port %s to %s.",
106 m_localRPCPortName.c_str(),
107 m_remoteRPCPortName.c_str());
108 yCError(MULTIPLEANALOGSENSORSCLIENT,
"Check that the specified MultipleAnalogSensorsServer is up.");
112 m_RPCConnectionActive =
true;
116 yCError(MULTIPLEANALOGSENSORSCLIENT,
117 "Failure connecting port %s to %s.",
118 m_remoteStreamingPortName.c_str(),
119 m_localStreamingPortName.c_str());
120 yCError(MULTIPLEANALOGSENSORSCLIENT,
"Check that the specified MultipleAnalogSensorsServer is up.");
124 m_StreamingConnectionActive =
true;
129 yCError(MULTIPLEANALOGSENSORSCLIENT,
"Failure opening Thrift-based RPC interface.");
146 if (m_StreamingConnectionActive)
150 if (m_RPCConnectionActive)
155 m_streamingPort.
close();
161 size_t MultipleAnalogSensorsClient::genericGetNrOfSensors(
const std::vector<SensorMetadata>& metadataVector,
164 if (!m_externalConnection) {
165 return metadataVector.size();
167 std::lock_guard<std::mutex> guard(m_streamingPort.
dataMutex);
179 std::lock_guard<std::mutex> guard(m_streamingPort.
dataMutex);
181 return m_streamingPort.
status;
184 bool MultipleAnalogSensorsClient::genericGetName(
const std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
185 size_t sens_index, std::string& name)
const
187 if (m_externalConnection) {
188 yCError(MULTIPLEANALOGSENSORSCLIENT,
189 "Missing metadata, the device has been configured with the option"
190 "externalConnection set to true.");
193 if (sens_index >= metadataVector.size())
195 yCError(MULTIPLEANALOGSENSORSCLIENT,
196 "No sensor of type %s with index %lu (nr of sensors: %lu).",
199 metadataVector.size());
203 name = metadataVector[sens_index].name;
207 bool MultipleAnalogSensorsClient::genericGetFrameName(
const std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
208 size_t sens_index, std::string& frameName)
const
210 if (m_externalConnection) {
211 yCError(MULTIPLEANALOGSENSORSCLIENT,
212 "Missing metadata, the device has been configured with the option"
213 "externalConnection set to true.");
216 if (sens_index >= metadataVector.size())
218 yCError(MULTIPLEANALOGSENSORSCLIENT,
219 "No sensor of type %s with index %lu (nr of sensors: %lu).",
222 metadataVector.size());
226 frameName = metadataVector[sens_index].frameName;
230 bool MultipleAnalogSensorsClient::genericGetMeasure(
const std::vector<SensorMetadata>& metadataVector,
const std::string& tag,
235 std::lock_guard<std::mutex> guard(m_streamingPort.
dataMutex);
239 yCError(MULTIPLEANALOGSENSORSCLIENT,
240 "Sensor of type %s with index %lu has non-MAS_OK status.",
248 yCError(MULTIPLEANALOGSENSORSCLIENT,
249 "No sensor of type %s with index %lu (nr of sensors: %lu).",
252 metadataVector.size());
256 if (!m_externalConnection)
257 assert(metadataVector.size() == measurementsVector.
measurements.size());
259 timestamp = measurementsVector.
measurements[sens_index].timestamp;
260 out = measurementsVector.
measurements[sens_index].measurement;
265 size_t MultipleAnalogSensorsClient::genericGetSize(
const std::vector<SensorMetadata>& metadataVector,
266 const std::string& tag,
const SensorMeasurements& measurementsVector,
size_t sens_index)
const
268 std::lock_guard<std::mutex> guard(m_streamingPort.
dataMutex);
271 yCError(MULTIPLEANALOGSENSORSCLIENT,
"No data received, no information on the size of the specified sensor.");
276 if (sens_index >= measurementsVector.
measurements.size())
278 yCError(MULTIPLEANALOGSENSORSCLIENT,
279 "No sensor of type %s with index %lu (nr of sensors: %lu).",
282 metadataVector.size());
286 return measurementsVector.
measurements[sens_index].measurement.size();
333 return genericGetStatus();
338 return genericGetName(m_sensorsMetadata.
ThreeAxisGyroscopes,
"ThreeAxisGyroscopes", sens_index, name);
343 return genericGetFrameName(m_sensorsMetadata.
ThreeAxisGyroscopes,
"ThreeAxisGyroscopes", sens_index, frameName);
360 return genericGetStatus();
387 return genericGetStatus();
392 return genericGetName(m_sensorsMetadata.
ThreeAxisMagnetometers,
"ThreeAxisMagnetometers", sens_index, name);
397 return genericGetFrameName(m_sensorsMetadata.
ThreeAxisMagnetometers,
"ThreeAxisMagnetometers", sens_index, frameName);
414 return genericGetStatus();
419 return genericGetName(m_sensorsMetadata.
OrientationSensors,
"OrientationSensors", sens_index, name);
424 return genericGetFrameName(m_sensorsMetadata.
OrientationSensors,
"OrientationSensors", sens_index, frameName);
441 return genericGetStatus();
446 return genericGetName(m_sensorsMetadata.
PositionSensors,
"PositionSensors", sens_index, name);
451 return genericGetFrameName(m_sensorsMetadata.
PositionSensors,
"PositionSensors", sens_index, frameName);
467 return genericGetStatus();
472 return genericGetName(m_sensorsMetadata.
TemperatureSensors,
"TemperatureSensors", sens_index, name);
477 return genericGetFrameName(m_sensorsMetadata.
TemperatureSensors,
"TemperatureSensors", sens_index, frameName);
502 return genericGetStatus();
512 return genericGetFrameName(m_sensorsMetadata.
SixAxisForceTorqueSensors,
"SixAxisForceTorqueSensors", sens_index, frameName);
529 return genericGetStatus();
534 return genericGetName(m_sensorsMetadata.
ContactLoadCellArrays,
"ContactLoadCellArrays", sens_index, name);
551 return genericGetNrOfSensors(m_sensorsMetadata.
EncoderArrays,
557 return genericGetStatus();
562 return genericGetName(m_sensorsMetadata.
EncoderArrays,
"EncoderArrays", sens_index, name);
567 return genericGetMeasure(m_sensorsMetadata.
EncoderArrays,
"EncoderArrays",
573 return genericGetSize(m_sensorsMetadata.
EncoderArrays,
"EncoderArrays",
579 return genericGetNrOfSensors(m_sensorsMetadata.
SkinPatches,
585 return genericGetStatus();
590 return genericGetName(m_sensorsMetadata.
SkinPatches,
"SkinPatches", sens_index, name);
595 return genericGetMeasure(m_sensorsMetadata.
SkinPatches,
"SkinPatches",
601 return genericGetSize(m_sensorsMetadata.
SkinPatches,
"SkinPatches",