info.cpp
Go to the documentation of this file.
1 #include "info.hpp"
2 #include <limits>
3 
4 namespace hebi {
5 
7  : internal_(internal), field_(field)
8 {
9 }
10 
11 Info::FloatField::operator bool() const
12 {
13  return has();
14 }
15 
17 {
18  return (hebiInfoGetFloat(internal_, field_, nullptr) == HebiStatusSuccess);
19 }
20 
21 float Info::FloatField::get() const
22 {
23  float ret;
25  {
26  ret = std::numeric_limits<float>::quiet_NaN();
27  }
28  return ret;
29 }
30 
32  : internal_(internal), field_(field) {}
33 
34 Info::HighResAngleField::operator bool() const
35 {
36  return has();
37 }
38 
40 {
41  return (hebiInfoGetHighResAngle(internal_, field_, nullptr, nullptr) == HebiStatusSuccess);
42 }
43 
45 {
46  int64_t revolutions;
47  float radian_offset;
48  if (hebiInfoGetHighResAngle(internal_, field_, &revolutions, &radian_offset) != HebiStatusSuccess)
49  {
50  return std::numeric_limits<double>::quiet_NaN();
51  }
52  return (
53  static_cast<double>(revolutions) * 2.0 * M_PI +
54  static_cast<double>(radian_offset)
55  );
56 }
57 
58 void Info::HighResAngleField::get(int64_t* revolutions, float* radian_offset) const
59 {
60  if (hebiInfoGetHighResAngle(internal_, field_, revolutions, radian_offset) != HebiStatusSuccess)
61  {
62  *revolutions = 0;
63  *radian_offset = std::numeric_limits<float>::quiet_NaN();
64  }
65 }
66 
68  : internal_(internal), field_(field)
69 {
70 }
71 
73 {
74  return (hebiInfoGetBool(internal_, field_, nullptr) == HebiStatusSuccess);
75 }
76 
78 {
79  int ret;
81  {
82  ret = 0;
83  }
84  return static_cast<bool>(ret);
85 }
86 
88  : internal_(internal), field_(field)
89 {
90 }
91 
92 Info::StringField::operator bool() const
93 {
94  return has();
95 }
96 
98 {
99  return (hebiInfoGetString(internal_, field_, nullptr, nullptr) == HebiStatusSuccess);
100 }
101 
102 std::string Info::StringField::get() const
103 {
104  // Get the size first
105  size_t length;
106  if (hebiInfoGetString(internal_, field_, nullptr, &length) != HebiStatusSuccess)
107  {
108  // String field doesn't exist -- return an empty string
109  return "";
110  }
111  auto buffer = new char [length];
112  hebiInfoGetString(internal_, field_, buffer, &length);
113  std::string tmp(buffer, length - 1);
114  delete[] buffer;
115  return tmp;
116 }
117 
119  : internal_(internal), field_(field)
120 {
121 }
122 
123 Info::FlagField::operator bool() const
124 {
125  return has();
126 }
127 
129 {
130  return (hebiInfoGetFlag(internal_, field_) == 1);
131 }
132 
134  : internal_(internal), field_(field)
135 {
136 }
137 
139 {
140  return (hebiInfoGetLedColor(internal_, field_, nullptr, nullptr, nullptr) == HebiStatusSuccess);
141 }
142 
144 {
145  uint8_t r, g, b;
147  {
148  r = 0;
149  g = 0;
150  b = 0;
151  }
152  return Color(r, g, b);
153 }
154 
156  : internal_(info),
161 {
162 }
163 Info::~Info() noexcept
164 {
165 }
166 
167 Info::Info(Info&& other)
168  : internal_(other.internal_),
173 {
174  // NOTE: it would be nice to also cleanup the actual internal pointer of other
175  // but alas we cannot change a const variable.
176 }
177 
178 const Info::LedField& Info::led() const
179 {
180  return led_;
181 }
182 
183 } // namespace hebi
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:97
std::string get() const
If the field has a value, returns a copy of that value; otherwise, returns a default.
Definition: info.cpp:102
FloatField(HebiInfoPtr internal, HebiInfoFloatField field)
Definition: info.cpp:6
LedField(HebiInfoPtr internal, HebiInfoLedField field)
Definition: info.cpp:133
HebiInfoPtr const internal_
Definition: info.hpp:86
HebiStatusCode hebiInfoGetFloat(HebiInfoPtr info, HebiInfoFloatField field, float *value)
int32_t hebiInfoGetFlag(HebiInfoPtr info, HebiInfoFlagField field)
bool hasColor() const
Returns true if the LED color is set, and false otherwise.
Definition: info.cpp:138
StringField serial_
Definition: info.hpp:473
HebiStatusCode hebiInfoGetHighResAngle(HebiInfoPtr, HebiInfoHighResAngleField, int64_t *int_part, float *dec_part)
Definition: color.hpp:5
float get() const
If the field has a value, returns that value; otherwise, returns a default.
Definition: info.cpp:21
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:39
~Info() noexcept
Cleans up info object as necessary.
Definition: info.cpp:163
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:72
Info objects have various fields representing the module state; which fields are populated depends on...
Definition: info.hpp:30
HebiInfoFloatField const field_
Definition: info.hpp:87
HebiInfoFlagField const field_
Definition: info.hpp:221
A message field for interfacing with an LED.
Definition: info.hpp:262
HebiInfoStringField
Definition: hebi.h:253
Gets the family for this module.
Definition: hebi.h:256
HebiInfoHighResAngleField
Definition: hebi.h:242
Settings settings_
Definition: info.hpp:468
HebiInfoFlagField
Definition: hebi.h:259
const LedField & led() const
The module&#39;s LED.
Definition: info.cpp:178
HebiInfoBoolField
Definition: hebi.h:247
HebiInfoLedField
Definition: hebi.h:268
HebiInfoPtr const internal_
Definition: info.hpp:220
#define M_PI
Definition: hebi.h:12
HebiInfoPtr const internal_
Definition: info.hpp:190
HighResAngleField(HebiInfoPtr internal, HebiInfoHighResAngleField field)
Definition: info.cpp:31
bool get() const
If the field has a value, returns that value; otherwise, returns false.
Definition: info.cpp:77
bool has() const
Returns true if the flag is set, false if it is cleared.
Definition: info.cpp:128
HebiInfoFloatField
Definition: hebi.h:199
double get() const
If the field has a value, returns that value as a double; otherwise, returns a default.
Definition: info.cpp:44
HebiInfoPtr const internal_
Definition: info.hpp:137
Info(HebiInfoPtr)
Wraps an existing C-style object that is managed by its parent. NOTE: this should not be used except ...
Definition: info.cpp:155
HebiInfoPtr internal_
Definition: info.hpp:430
StringField(HebiInfoPtr internal, HebiInfoStringField field)
Definition: info.cpp:87
HebiInfoLedField const field_
Definition: info.hpp:288
Color getColor() const
Returns the led color.
Definition: info.cpp:143
HebiStatusCode hebiInfoGetString(HebiInfoPtr info, HebiInfoStringField field, char *buffer, size_t *length)
HebiStatusCode hebiInfoGetBool(HebiInfoPtr info, HebiInfoBoolField field, int32_t *value)
HebiInfoStringField const field_
Definition: info.hpp:191
LedField led_
Definition: info.hpp:471
Actuator actuator_
Definition: info.hpp:469
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
struct _HebiInfo * HebiInfoPtr
The C-style&#39;s API representation of a group.
Definition: hebi.h:362
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:16
BoolField(HebiInfoPtr internal, HebiInfoBoolField field)
Definition: info.cpp:67
Structure to describe an RGB color.
Definition: color.hpp:8
EIGEN_DEVICE_FUNC const Scalar & b
HebiStatusCode hebiInfoGetLedColor(HebiInfoPtr info, HebiInfoLedField field, uint8_t *r, uint8_t *g, uint8_t *b)
HebiInfoHighResAngleField const field_
Definition: info.hpp:138
HebiInfoPtr const internal_
Definition: info.hpp:157
HebiInfoPtr const internal_
Definition: info.hpp:287
FlagField(HebiInfoPtr internal, HebiInfoFlagField field)
Definition: info.cpp:118
HebiInfoBoolField const field_
Definition: info.hpp:158


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:15