info.cpp
Go to the documentation of this file.
1 #include "info.hpp"
2 
3 #include <limits>
4 
5 namespace hebi {
6 
7 Info::FloatField::FloatField(const HebiInfoRef& internal, HebiInfoFloatField field) : internal_(internal), field_(field) {}
8 
9 bool Info::FloatField::has() const { return (floatGetter(internal_, field_, nullptr) == HebiStatusSuccess); }
10 
11 float Info::FloatField::get() const {
12  float ret;
14  ret = std::numeric_limits<float>::quiet_NaN();
15  }
16  return ret;
17 }
18 
20  : internal_(internal), field_(field) {}
21 
23  return (highResAngleGetter(internal_, field_, nullptr, nullptr) == HebiStatusSuccess);
24 }
25 
27  int64_t revolutions;
28  float radian_offset;
29  if (highResAngleGetter(internal_, field_, &revolutions, &radian_offset) != HebiStatusSuccess) {
30  return std::numeric_limits<double>::quiet_NaN();
31  }
32  return (static_cast<double>(revolutions) * 2.0 * M_PI + static_cast<double>(radian_offset));
33 }
34 
35 void Info::HighResAngleField::get(int64_t* revolutions, float* radian_offset) const {
36  if (highResAngleGetter(internal_, field_, revolutions, radian_offset) != HebiStatusSuccess) {
37  *revolutions = 0;
38  *radian_offset = std::numeric_limits<float>::quiet_NaN();
39  }
40 }
41 
42 Info::BoolField::BoolField(const HebiInfoRef& internal, HebiInfoBoolField field) : internal_(internal), field_(field) {}
43 
44 bool Info::BoolField::has() const { return (boolGetter(internal_, field_, nullptr) == HebiStatusSuccess); }
45 
46 bool Info::BoolField::get() const {
47  bool ret{};
48  boolGetter(internal_, field_, &ret);
49  return static_cast<bool>(ret);
50 }
51 
53 
54 bool Info::StringField::has() const {
55  return (hebiInfoGetString(internal_, field_, nullptr, nullptr) == HebiStatusSuccess);
56 }
57 
58 std::string Info::StringField::get() const {
59  // Get the size first
60  size_t length;
61  if (hebiInfoGetString(internal_, field_, nullptr, &length) != HebiStatusSuccess) {
62  // String field doesn't exist -- return an empty string
63  return "";
64  }
65  auto buffer = new char[length];
66  hebiInfoGetString(internal_, field_, buffer, &length);
67  std::string tmp(buffer, length - 1);
68  delete[] buffer;
69  return tmp;
70 }
71 
72 Info::FlagField::FlagField(const HebiInfoRef& internal, HebiInfoFlagField field) : internal_(internal), field_(field) {}
73 
74 bool Info::FlagField::has() const { return (flagGetter(internal_, field_) == 1); }
75 
76 Info::LedField::LedField(const HebiInfoRef& internal, HebiInfoLedField field) : internal_(internal), field_(field) {}
77 
79  return ledGetter(internal_, field_, nullptr, nullptr, nullptr, nullptr) == HebiStatusSuccess;
80 }
81 
83  uint8_t r, g, b, a;
84  if (ledGetter(internal_, field_, &r, &g, &b, &a) != HebiStatusSuccess) {
85  r = 0;
86  g = 0;
87  b = 0;
88  a = 0;
89  }
90  return Color(r, g, b, a);
91 }
92 
94  : internal_(info),
100 }
101 
102 Info::Info(Info&& other)
103  : internal_(other.internal_),
108  // NOTE: it would be nice to also cleanup the actual internal pointer of other
109  // but alas we cannot change a const variable.
111 }
112 
113 } // namespace hebi
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:54
const HebiInfoRef & internal_
Definition: info.hpp:110
std::string get() const
If the field has a value, returns a copy of that value; otherwise, returns a default.
Definition: info.cpp:58
HebiStatusCode ledGetter(const RefT &ref, MetadataT &metadata, int field, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
FlagField(const HebiInfoRef &internal, HebiInfoFlagField field)
Definition: info.cpp:72
void hebiInfoGetReference(HebiInfoPtr info, HebiInfoRef *ref)
HebiInfoRef internal_ref_
Definition: info.hpp:477
bool hasColor() const
Returns true if the LED color is set, and false otherwise.
Definition: info.cpp:78
StringField serial_
Definition: info.hpp:521
Definition: arm.cpp:5
float get() const
If the field has a value, returns that value; otherwise, returns a default.
Definition: info.cpp:11
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:22
BoolField(const HebiInfoRef &internal, HebiInfoBoolField field)
Definition: info.cpp:42
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:44
Info objects have various fields representing the module state; which fields are populated depends on...
Definition: info.hpp:33
HebiStatusCode floatGetter(const RefT &ref, MetadataT &metadata, int field, float *value)
HebiInfoFloatField const field_
Definition: info.hpp:111
struct HebiInfo_ * HebiInfoPtr
The C-style&#39;s API representation of info.
Definition: hebi.h:458
HebiInfoFlagField const field_
Definition: info.hpp:238
HebiInfoStringField
Definition: hebi.h:297
The family for this module. The string must be null-terminated and less than 21 characters.
Definition: hebi.h:300
HebiInfoHighResAngleField
Definition: hebi.h:285
HebiStatusCode boolGetter(const RefT &ref, MetadataT &metadata, int field, bool *value)
Settings settings_
Definition: info.hpp:518
HebiInfoFlagField
Definition: hebi.h:303
LedField(const HebiInfoRef &internal, HebiInfoLedField field)
Definition: info.cpp:76
HebiInfoBoolField
Definition: hebi.h:290
HebiInfoLedField
Definition: hebi.h:315
#define M_PI
Definition: hebi.h:13
HebiStatusCode highResAngleGetter(const RefT &ref, MetadataT &metadata, int field, int64_t *revs, float *offset)
HebiInfoPtr const internal_
Definition: info.hpp:209
bool get() const
If the field has a value, returns that value; otherwise, returns false.
Definition: info.cpp:46
bool has() const
Returns true if the flag is set, false if it is cleared.
Definition: info.cpp:74
const HebiInfoRef & internal_
Definition: info.hpp:160
HebiInfoFloatField
Info Enums.
Definition: hebi.h:238
const HebiInfoRef & internal_
Definition: info.hpp:237
HighResAngleField(const HebiInfoRef &internal, HebiInfoHighResAngleField field)
Definition: info.cpp:19
bool flagGetter(const RefT &ref, MetadataT &metadata, int field)
double get() const
If the field has a value, returns that value as a double; otherwise, returns a default.
Definition: info.cpp:26
Info(HebiInfoPtr)
Wraps an existing C-style object that is managed by its parent. NOTE: this should not be used except ...
Definition: info.cpp:93
const HebiInfoRef & internal_
Definition: info.hpp:178
HebiInfoPtr internal_
Definition: info.hpp:476
const HebiInfoRef & internal_
Definition: info.hpp:305
StringField(HebiInfoPtr internal, HebiInfoStringField field)
Definition: info.cpp:52
HebiInfoLedField const field_
Definition: info.hpp:306
Color getColor() const
Returns the led color.
Definition: info.cpp:82
HebiStatusCode hebiInfoGetString(HebiInfoPtr info, HebiInfoStringField field, char *buffer, size_t *length)
Info API.
HebiInfoStringField const field_
Definition: info.hpp:210
LedField led_
Definition: info.hpp:522
FloatField(const HebiInfoRef &internal, HebiInfoFloatField field)
Definition: info.cpp:7
Actuator actuator_
Definition: info.hpp:519
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:9
Structure to describe an RGB color.
Definition: color.hpp:8
HebiInfoHighResAngleField const field_
Definition: info.hpp:161
HebiInfoBoolField const field_
Definition: info.hpp:179


hebi_cpp_api_ros
Author(s): Chris Bollinger , Matthew Tesch
autogenerated on Thu May 28 2020 03:14:45