YARP
Yet Another Robot Platform
FrameGrabberControls_Responder.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/LogStream.h>
10 
12 
13 FrameGrabberControls_Responder::FrameGrabberControls_Responder() :
14  fgCtrl(nullptr)
15 {
16 }
17 
19 {
20  bool ret = false;
21  if (interface) {
22  fgCtrl = interface;
23  ret = true;
24  } else {
25  fgCtrl = nullptr;
26  ret = false;
27  }
28  return ret;
29 }
30 
31 
33 {
34  bool ok = false;
35  int action = cmd.get(1).asVocab32();
36  int param = cmd.get(2).asVocab32();
37 
38  if (!fgCtrl) {
39  yError() << " Selected camera device has no IFrameGrabberControl interface";
40  return false;
41  }
42 
43  response.clear();
44 
45  switch (action) {
46  case VOCAB_HAS: {
48  response.addVocab32(VOCAB_HAS);
49  response.addVocab32(VOCAB_FEATURE);
50  response.addInt32(param);
51 
52  switch (param) {
53  case VOCAB_FEATURE: {
54  bool _hasFeat;
55  ok = fgCtrl->hasFeature(cmd.get(3).asInt32(), &_hasFeat);
56  response.addInt32(_hasFeat);
57  } break;
58 
59  case VOCAB_ONOFF: {
60  bool _hasOnOff;
61  ok = fgCtrl->hasOnOff(cmd.get(3).asInt32(), &_hasOnOff);
62  response.addInt32(_hasOnOff);
63  } break;
64 
65  case VOCAB_AUTO: {
66  bool _hasAuto;
67 
68  ok = fgCtrl->hasAuto(cmd.get(3).asInt32(), &_hasAuto);
69  response.addInt32(_hasAuto);
70  } break;
71 
72  case VOCAB_MANUAL: {
73  bool _hasManual;
74  ok = fgCtrl->hasManual(cmd.get(3).asInt32(), &_hasManual);
75  response.addInt32(_hasManual);
76  } break;
77 
78  case VOCAB_ONEPUSH: {
79  bool _hasOnePush;
80  ok = fgCtrl->hasOnePush(cmd.get(3).asInt32(), &_hasOnePush);
81  response.addInt32(_hasOnePush);
82  } break;
83 
84  default:
85  {
86  yError() << "Unknown command 'HAS " << yarp::os::Vocab32::decode(param) << "' received on IFrameGrabber2 interface";
87  response.clear();
88  ok = false;
89  } break;
90  }
91  break; // end switch (param)
92 
93  } break; // end VOCAB_HAS
94 
95  case VOCAB_SET: {
96  switch (param) {
97  case VOCAB_FEATURE: {
98  ok = fgCtrl->setFeature(cmd.get(3).asInt32(), cmd.get(4).asFloat64());
99  } break;
100 
101  case VOCAB_FEATURE2: {
102  ok = fgCtrl->setFeature(cmd.get(3).asInt32(), cmd.get(4).asFloat64(), cmd.get(5).asFloat64());
103  } break;
104 
105  case VOCAB_ACTIVE: {
106  ok = fgCtrl->setActive(cmd.get(3).asInt32(), cmd.get(4).asInt32());
107  } break;
108 
109  case VOCAB_MODE: {
110  ok = fgCtrl->setMode(cmd.get(3).asInt32(), static_cast<FeatureMode>(cmd.get(4).asInt32()));
111  } break;
112 
113  case VOCAB_ONEPUSH: {
114  ok = fgCtrl->setOnePush(cmd.get(3).asInt32());
115  } break;
116 
117  default:
118  {
119  yError() << "Unknown command 'SET " << yarp::os::Vocab32::decode(param) << "' received on IFrameGrabber2 interface";
120  response.clear();
121  ok = false;
122  }
123  }
124  break; // end switch (param)
125 
126  } break; // end VOCAB_SET
127 
128  case VOCAB_GET: {
130  response.addVocab32(param);
131  response.addVocab32(VOCAB_IS);
132  switch (param) {
134  CameraDescriptor camera;
135  ok = fgCtrl->getCameraDescription(&camera);
136  response.addInt32(camera.busType);
137  response.addString(camera.deviceDescription);
138  yDebug() << "Response is " << response.toString();
139  } break;
140 
141  case VOCAB_FEATURE: {
142  double value;
143  ok = fgCtrl->getFeature(cmd.get(3).asInt32(), &value);
144  response.addFloat64(value);
145  } break;
146 
147  case VOCAB_FEATURE2: {
148  double value1;
149  double value2;
150  ok = fgCtrl->getFeature(cmd.get(3).asInt32(), &value1, &value2);
151  response.addFloat64(value1);
152  response.addFloat64(value2);
153  } break;
154 
155  case VOCAB_ACTIVE: {
156  bool _isActive;
157  ok = fgCtrl->getActive(cmd.get(3).asInt32(), &_isActive);
158  response.addInt32(_isActive);
159  } break;
160 
161  case VOCAB_MODE: {
162  FeatureMode _mode;
163  ok = fgCtrl->getMode(cmd.get(3).asInt32(), &_mode);
164  response.addInt32(_mode);
165  } break;
166 
167  default:
168  {
169  yError() << "Unknown command 'GET " << yarp::os::Vocab32::decode(param) << "' received on IFrameGrabber2 interface";
170  response.clear();
171  ok = false;
172  }
173  }
174  break; // end switch (param)
175 
176  } break; // end VOCAB_GET
177  }
178  // yTrace() << "response is\n\t" << response.toString().c_str();
179  return ok;
180 }
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_MANUAL
Definition: CameraVocabs.h:47
constexpr yarp::conf::vocab32_t VOCAB_ONEPUSH
Definition: CameraVocabs.h:48
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_CAMERA_DESCRIPTION
Definition: CameraVocabs.h:41
constexpr yarp::conf::vocab32_t VOCAB_HAS
Definition: CameraVocabs.h:42
constexpr yarp::conf::vocab32_t VOCAB_AUTO
Definition: CameraVocabs.h:46
constexpr yarp::conf::vocab32_t VOCAB_FRAMEGRABBER_CONTROL
Definition: CameraVocabs.h:39
constexpr yarp::conf::vocab32_t VOCAB_IS
Definition: GenericVocabs.h:14
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 yError(...)
Definition: Log.h:279
#define yDebug(...)
Definition: Log.h:234
Control interface for frame grabber devices.
virtual bool setFeature(int feature, double value)=0
Set the requested feature to a value (saturation, brightness ...
virtual bool setOnePush(int feature)=0
Set the requested feature to a value (saturation, brightness ...
virtual bool getFeature(int feature, double *value)=0
Get the current value for the requested feature.
virtual bool hasManual(int feature, bool *hasManual)=0
Check if the requested feature has the 'manual' mode.
virtual bool setMode(int feature, FeatureMode mode)=0
Set the requested mode for the feature.
virtual bool hasOnOff(int feature, bool *HasOnOff)=0
Check if the camera has the ability to turn on/off the requested feature.
virtual bool hasAuto(int feature, bool *hasAuto)=0
Check if the requested feature has the 'auto' mode.
virtual bool getMode(int feature, FeatureMode *mode)=0
Get the current mode for the feature.
virtual bool getCameraDescription(CameraDescriptor *camera)=0
Get a basic description of the camera hw.
virtual bool getActive(int feature, bool *isActive)=0
Get the current status of the feature, on or off.
virtual bool setActive(int feature, bool onoff)=0
Set the requested feature on or off.
virtual bool hasFeature(int feature, bool *hasFeature)=0
Check if camera has the requested feature (saturation, brightness ...
virtual bool hasOnePush(int feature, bool *hasOnePush)=0
Check if the requested feature has the 'onePush' mode.
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
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 clear()
Empties the bottle of any objects it contains.
Definition: Bottle.cpp:121
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
Definition: Bottle.cpp:140
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition: Bottle.cpp:170
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Definition: Bottle.cpp:211
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:222
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
Definition: Value.cpp:228
virtual std::int32_t asInt32() const
Get 32-bit integer value.
Definition: Value.cpp:204
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
bool configure(yarp::dev::IFrameGrabberControls *interface)
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition: Vocab.cpp:33
std::string deviceDescription