YARP
Yet Another Robot Platform
FrameGrabberControls_Forwarder.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
7 #include "CameraVocabs.h"
8 
9 #include <yarp/os/Bottle.h>
10 #include <yarp/os/LogStream.h>
11 
13 
14 FrameGrabberControls_Forwarder::FrameGrabberControls_Forwarder(yarp::os::Port& m_port) :
15  m_port(m_port)
16 {
17 };
18 
19 
21 {
22  yarp::os::Bottle cmd;
23  yarp::os::Bottle response;
25  cmd.addVocab32(VOCAB_GET);
27  yInfo() << m_port.isOpen();
28  bool ret = m_port.write(cmd, response);
29 
30  // response should be [fgc2] [camd] [is] [busType] [description]
31  camera->busType = static_cast<BusType>(response.get(3).asInt32());
32  camera->deviceDescription = response.get(4).asString();
33  return ret;
34 }
35 
36 bool FrameGrabberControls_Forwarder::hasFeature(int feature, bool* hasFeature)
37 {
38  yarp::os::Bottle cmd;
39  yarp::os::Bottle response;
41  cmd.addVocab32(VOCAB_HAS);
43  cmd.addInt32(feature);
44  bool ret = m_port.write(cmd, response);
45 
46  *hasFeature = response.get(4).asInt32() != 0 ? true : false;
47  return ret;
48 }
49 
50 bool FrameGrabberControls_Forwarder::setFeature(int feature, double value)
51 {
52  yarp::os::Bottle cmd;
53  yarp::os::Bottle response;
55  cmd.addVocab32(VOCAB_SET);
57  cmd.addInt32(feature);
58  cmd.addFloat64(value);
59  return m_port.write(cmd, response);
60 }
61 
62 bool FrameGrabberControls_Forwarder::setFeature(int feature, double value1, double value2)
63 {
64  yarp::os::Bottle cmd;
65  yarp::os::Bottle response;
67  cmd.addVocab32(VOCAB_SET);
69  cmd.addInt32(feature);
70  cmd.addFloat64(value1);
71  cmd.addFloat64(value2);
72  return m_port.write(cmd, response);
73 }
74 
75 bool FrameGrabberControls_Forwarder::getFeature(int feature, double* value)
76 {
77  yarp::os::Bottle cmd;
78  yarp::os::Bottle response;
80  cmd.addVocab32(VOCAB_GET);
82  cmd.addInt32(feature);
83  bool ret = m_port.write(cmd, response);
84 
85  *value = response.get(3).asFloat64();
86  return ret;
87 }
88 
89 bool FrameGrabberControls_Forwarder::getFeature(int feature, double* value1, double* value2)
90 {
91  yarp::os::Bottle cmd;
92  yarp::os::Bottle response;
94  cmd.addVocab32(VOCAB_GET);
96  cmd.addInt32(feature);
97  bool ret = m_port.write(cmd, response);
98 
99  *value1 = response.get(3).asFloat64();
100  *value2 = response.get(4).asFloat64();
101  return ret;
102 }
103 
104 bool FrameGrabberControls_Forwarder::hasOnOff(int feature, bool* hasOnOff)
105 {
106  yarp::os::Bottle cmd;
107  yarp::os::Bottle response;
109  cmd.addVocab32(VOCAB_HAS);
110  cmd.addVocab32(VOCAB_ONOFF);
111  cmd.addInt32(feature);
112  bool ret = m_port.write(cmd, response);
113 
114  *hasOnOff = response.get(4).asInt32() != 0 ? true : false;
115  return ret;
116 }
117 
118 bool FrameGrabberControls_Forwarder::setActive(int feature, bool onoff)
119 {
120  yarp::os::Bottle cmd;
121  yarp::os::Bottle response;
123  cmd.addVocab32(VOCAB_SET);
125  cmd.addInt32(feature);
126  cmd.addInt32(onoff);
127  return m_port.write(cmd, response);
128 }
129 
130 bool FrameGrabberControls_Forwarder::getActive(int feature, bool* isActive)
131 {
132  yarp::os::Bottle cmd;
133  yarp::os::Bottle response;
135  cmd.addVocab32(VOCAB_GET);
137  cmd.addInt32(feature);
138  bool ret = m_port.write(cmd, response);
139 
140  *isActive = response.get(3).asInt32() != 0 ? true : false;
141  return ret;
142 }
143 
144 bool FrameGrabberControls_Forwarder::hasAuto(int feature, bool* hasAuto)
145 {
146  yarp::os::Bottle cmd;
147  yarp::os::Bottle response;
149  cmd.addVocab32(VOCAB_HAS);
150  cmd.addVocab32(VOCAB_AUTO);
151  cmd.addInt32(feature);
152  bool ret = m_port.write(cmd, response);
153 
154  *hasAuto = response.get(4).asInt32() != 0 ? true : false;
155  return ret;
156 }
157 
158 bool FrameGrabberControls_Forwarder::hasManual(int feature, bool* hasManual)
159 {
160  yarp::os::Bottle cmd;
161  yarp::os::Bottle response;
163  cmd.addVocab32(VOCAB_HAS);
165  cmd.addInt32(feature);
166  bool ret = m_port.write(cmd, response);
167 
168  *hasManual = response.get(4).asInt32() != 0 ? true : false;
169  return ret;
170 }
171 
172 bool FrameGrabberControls_Forwarder::hasOnePush(int feature, bool* hasOnePush)
173 {
174  yarp::os::Bottle cmd;
175  yarp::os::Bottle response;
177  cmd.addVocab32(VOCAB_HAS);
179  cmd.addInt32(feature);
180  bool ret = m_port.write(cmd, response);
181 
182  *hasOnePush = response.get(4).asInt32() != 0 ? true : false;
183  return ret;
184 }
185 
187 {
188  yarp::os::Bottle cmd;
189  yarp::os::Bottle response;
191  cmd.addVocab32(VOCAB_SET);
192  cmd.addVocab32(VOCAB_MODE);
193  cmd.addInt32(feature);
194  cmd.addInt32(mode);
195  return m_port.write(cmd, response);
196 }
197 
199 {
200  yarp::os::Bottle cmd;
201  yarp::os::Bottle response;
203  cmd.addVocab32(VOCAB_GET);
204  cmd.addVocab32(VOCAB_MODE);
205  cmd.addInt32(feature);
206  bool ret = m_port.write(cmd, response);
207 
208  *mode = static_cast<FeatureMode>(response.get(3).asInt32());
209  return ret;
210 }
211 
213 {
214  yarp::os::Bottle cmd;
215  yarp::os::Bottle response;
217  cmd.addVocab32(VOCAB_SET);
219  cmd.addInt32(feature);
220  return m_port.write(cmd, response);
221 }
222 
223 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
224 bool FrameGrabberControls_Forwarder::setCommand(int code, double v)
225 {
226  yarp::os::Bottle cmd;
227  yarp::os::Bottle response;
229  cmd.addVocab32(VOCAB_SET);
230  cmd.addVocab32(code);
231  cmd.addFloat64(v);
232  return m_port.write(cmd, response);
233 }
234 
235 bool FrameGrabberControls_Forwarder::setCommand(int code, double b, double r)
236 {
237  yarp::os::Bottle cmd;
238  yarp::os::Bottle response;
240  cmd.addVocab32(VOCAB_SET);
241  cmd.addVocab32(code);
242  cmd.addFloat64(b);
243  cmd.addFloat64(r);
244  return m_port.write(cmd, response);
245 }
246 
247 double FrameGrabberControls_Forwarder::getCommand(int code) const
248 {
249  yarp::os::Bottle cmd;
250  yarp::os::Bottle response;
252  cmd.addVocab32(VOCAB_GET);
253  cmd.addVocab32(code);
254  m_port.write(cmd,response);
255  // response should be [cmd] [name] value
256  return response.get(2).asFloat64();
257 }
258 
259 bool FrameGrabberControls_Forwarder::getCommand(int code, double &b, double &r) const
260 {
261  yarp::os::Bottle cmd;
262  yarp::os::Bottle response;
264  cmd.addVocab32(VOCAB_GET);
265  cmd.addVocab32(code);
266  m_port.write(cmd,response);
267  // response should be [cmd] [name] value
268  b=response.get(2).asFloat64();
269  r=response.get(3).asFloat64();
270  return true;
271 }
272 
274 {
275  return setCommand(VOCAB_BRIGHTNESS, v);
276 }
277 
279 {
280  return getCommand(VOCAB_BRIGHTNESS);
281 }
282 
284 {
285  return setCommand(VOCAB_EXPOSURE, v);
286 }
287 
289 {
290  return getCommand(VOCAB_EXPOSURE);
291 }
292 
294 {
295  return setCommand(VOCAB_SHARPNESS, v);
296 }
297 
299 {
300  return getCommand(VOCAB_SHARPNESS);
301 }
302 
304 {
305  return setCommand(VOCAB_WHITE, blue, red);
306 }
307 
308 bool FrameGrabberControls_Forwarder::getWhiteBalance(double &blue, double &red)
309 {
310  return getCommand(VOCAB_WHITE, blue, red);
311 }
312 
314 {
315  return setCommand(VOCAB_HUE,v);
316 }
317 
319 {
320  return getCommand(VOCAB_HUE);
321 }
322 
324 {
325  return setCommand(VOCAB_SATURATION,v);
326 }
327 
329 {
330  return getCommand(VOCAB_SATURATION);
331 }
332 
334 {
335  return setCommand(VOCAB_GAMMA,v);
336 }
337 
339 {
340  return getCommand(VOCAB_GAMMA);
341 }
342 
344 {
345  return setCommand(VOCAB_SHUTTER,v);
346 }
347 
349 {
350  return getCommand(VOCAB_SHUTTER);
351 }
352 
354 {
355  return setCommand(VOCAB_GAIN,v);
356 }
357 
359 {
360  return getCommand(VOCAB_GAIN);
361 }
362 
364 {
365  return setCommand(VOCAB_IRIS,v);
366 }
367 
369 {
370  return getCommand(VOCAB_IRIS);
371 }
372 #endif // YARP_NO_DEPRECATED
constexpr yarp::conf::vocab32_t VOCAB_ACTIVE
Definition: CameraVocabs.h:49
constexpr yarp::conf::vocab32_t VOCAB_FEATURE2
Definition: CameraVocabs.h:44
constexpr yarp::conf::vocab32_t VOCAB_FEATURE
Definition: CameraVocabs.h:43
constexpr yarp::conf::vocab32_t VOCAB_GAMMA
Definition: CameraVocabs.h:32
constexpr yarp::conf::vocab32_t VOCAB_MANUAL
Definition: CameraVocabs.h:47
constexpr yarp::conf::vocab32_t VOCAB_GAIN
Definition: CameraVocabs.h:34
constexpr yarp::conf::vocab32_t VOCAB_ONEPUSH
Definition: CameraVocabs.h:48
constexpr yarp::conf::vocab32_t VOCAB_SHUTTER
Definition: CameraVocabs.h:33
constexpr yarp::conf::vocab32_t VOCAB_MODE
Definition: CameraVocabs.h:50
constexpr yarp::conf::vocab32_t VOCAB_ONOFF
Definition: CameraVocabs.h:45
constexpr yarp::conf::vocab32_t VOCAB_WHITE
Definition: CameraVocabs.h:29
constexpr yarp::conf::vocab32_t VOCAB_IRIS
Definition: CameraVocabs.h:35
constexpr yarp::conf::vocab32_t VOCAB_CAMERA_DESCRIPTION
Definition: CameraVocabs.h:41
constexpr yarp::conf::vocab32_t VOCAB_HUE
Definition: CameraVocabs.h:30
constexpr yarp::conf::vocab32_t VOCAB_SHARPNESS
Definition: CameraVocabs.h:28
constexpr yarp::conf::vocab32_t VOCAB_HAS
Definition: CameraVocabs.h:42
constexpr yarp::conf::vocab32_t VOCAB_BRIGHTNESS
Definition: CameraVocabs.h:26
constexpr yarp::conf::vocab32_t VOCAB_AUTO
Definition: CameraVocabs.h:46
constexpr yarp::conf::vocab32_t VOCAB_SATURATION
Definition: CameraVocabs.h:31
constexpr yarp::conf::vocab32_t VOCAB_FRAMEGRABBER_CONTROL
Definition: CameraVocabs.h:39
constexpr yarp::conf::vocab32_t VOCAB_EXPOSURE
Definition: CameraVocabs.h:27
constexpr yarp::conf::vocab32_t VOCAB_GET
Definition: GenericVocabs.h:13
constexpr yarp::conf::vocab32_t VOCAB_SET
Definition: GenericVocabs.h:12
bool ret
#define yInfo(...)
Definition: Log.h:314
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.cpp:164
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Definition: Bottle.cpp:158
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition: Bottle.cpp:246
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:140
A mini-server for network communication.
Definition: Port.h:46
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
Definition: Port.cpp:436
bool isOpen() const
Check if the port has been opened.
Definition: Port.cpp:677
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:222
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
virtual std::string asString() const
Get string value.
Definition: Value.cpp:234
This classes implement a sender / parser for IFrameGrabberControls interface messages.
bool hasAuto(int feature, bool *hasAuto) override
Check if the requested feature has the 'auto' mode.
bool setActive(int feature, bool onoff) override
Set the requested feature on or off.
bool hasFeature(int feature, bool *hasFeature) override
Check if camera has the requested feature (saturation, brightness ...
bool getActive(int feature, bool *isActive) override
Get the current status of the feature, on or off.
bool setOnePush(int feature) override
Set the requested feature to a value (saturation, brightness ...
bool hasOnePush(int feature, bool *hasOnePush) override
Check if the requested feature has the 'onePush' mode.
bool setFeature(int feature, double value) override
Set the requested feature to a value (saturation, brightness ...
bool setShutter(double v) override
Set the shutter parameter.
bool getWhiteBalance(double &blue, double &red) override
Read the white balance parameters.
bool getFeature(int feature, double *value) override
Get the current value for the requested feature.
bool setWhiteBalance(double blue, double red) override
Set the white balance for the frame grabber.
bool hasManual(int feature, bool *hasManual) override
Check if the requested feature has the 'manual' mode.
bool getMode(int feature, FeatureMode *mode) override
Get the current mode for the feature.
bool hasOnOff(int feature, bool *HasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
bool getCameraDescription(CameraDescriptor *camera) override
Get a basic description of the camera hw.
bool setMode(int feature, FeatureMode mode) override
Set the requested mode for the feature.
std::string deviceDescription