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;
13  if (floatGetter(internal_, field_, &ret) != HebiStatusSuccess) {
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 
52 Info::StringField::StringField(HebiInfoPtr internal, HebiInfoStringField field) : internal_(internal), field_(field) {}
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_),
104  settings_(internal_, internal_ref_),
105  actuator_(internal_ref_),
106  serial_(internal_, HebiInfoStringSerial),
107  led_(internal_ref_, HebiInfoLedLed) {
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
hebi::Info::FlagField::has
bool has() const
Returns true if the flag is set, false if it is cleared.
Definition: info.cpp:74
hebi::Info::StringField::has
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:54
hebiInfoGetString
HebiStatusCode hebiInfoGetString(HebiInfoPtr info, HebiInfoStringField field, char *buffer, size_t *length)
Info API.
HebiInfoLedLed
@ HebiInfoLedLed
Definition: hebi.h:316
hebi::Info
Info objects have various fields representing the module state; which fields are populated depends on...
Definition: info.hpp:33
hebi::floatGetter
HebiStatusCode floatGetter(const RefT &ref, MetadataT &metadata, int field, float *value)
Definition: message_helpers.cpp:21
hebi::Color
Structure to describe an RGB color.
Definition: color.hpp:8
M_PI
#define M_PI
Definition: hebi.h:13
HebiStatusSuccess
@ HebiStatusSuccess
Definition: hebi.h:24
HebiInfoStringField
HebiInfoStringField
Definition: hebi.h:297
hebi::Info::Info
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
hebi::Info::FloatField::has
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:9
HebiInfoPtr
struct HebiInfo_ * HebiInfoPtr
The C-style's API representation of info.
Definition: hebi.h:458
hebi::Info::LedField::LedField
LedField(const HebiInfoRef &internal, HebiInfoLedField field)
Definition: info.cpp:76
hebi::Info::internal_
HebiInfoPtr internal_
Definition: info.hpp:476
hebi::Info::StringField::StringField
StringField(HebiInfoPtr internal, HebiInfoStringField field)
Definition: info.cpp:52
hebi::ledGetter
HebiStatusCode ledGetter(const RefT &ref, MetadataT &metadata, int field, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
Definition: message_helpers.cpp:356
hebi::Info::internal_ref_
HebiInfoRef internal_ref_
Definition: info.hpp:477
hebi::Info::FloatField::get
float get() const
If the field has a value, returns that value; otherwise, returns a default.
Definition: info.cpp:11
hebi::Info::BoolField::BoolField
BoolField(const HebiInfoRef &internal, HebiInfoBoolField field)
Definition: info.cpp:42
hebi::Info::FlagField::FlagField
FlagField(const HebiInfoRef &internal, HebiInfoFlagField field)
Definition: info.cpp:72
HebiInfoBoolField
HebiInfoBoolField
Definition: hebi.h:290
hebi::Info::StringField::get
std::string get() const
If the field has a value, returns a copy of that value; otherwise, returns a default.
Definition: info.cpp:58
hebi::flagGetter
bool flagGetter(const RefT &ref, MetadataT &metadata, int field)
Definition: message_helpers.cpp:246
hebi::Info::LedField::hasColor
bool hasColor() const
Returns true if the LED color is set, and false otherwise.
Definition: info.cpp:78
hebi::Info::led_
LedField led_
Definition: info.hpp:522
HebiInfoFloatField
HebiInfoFloatField
Info Enums.
Definition: hebi.h:238
HebiInfoFlagField
HebiInfoFlagField
Definition: hebi.h:303
hebi::highResAngleGetter
HebiStatusCode highResAngleGetter(const RefT &ref, MetadataT &metadata, int field, int64_t *revs, float *offset)
Definition: message_helpers.cpp:50
hebi::Info::actuator_
Actuator actuator_
Definition: info.hpp:519
info.hpp
hebi
Definition: arm.cpp:5
HebiInfoHighResAngleField
HebiInfoHighResAngleField
Definition: hebi.h:285
hebiInfoGetReference
void hebiInfoGetReference(HebiInfoPtr info, HebiInfoRef *ref)
hebi::boolGetter
HebiStatusCode boolGetter(const RefT &ref, MetadataT &metadata, int field, bool *value)
Definition: message_helpers.cpp:269
hebi::Info::settings_
Settings settings_
Definition: info.hpp:518
hebi::Info::HighResAngleField::get
double get() const
If the field has a value, returns that value as a double; otherwise, returns a default.
Definition: info.cpp:26
hebi::Info::BoolField::get
bool get() const
If the field has a value, returns that value; otherwise, returns false.
Definition: info.cpp:46
HebiInfoStringSerial
@ HebiInfoStringSerial
The family for this module. The string must be null-terminated and less than 21 characters.
Definition: hebi.h:300
HebiInfoRef_
Definition: hebi.h:748
hebi::Info::FloatField::FloatField
FloatField(const HebiInfoRef &internal, HebiInfoFloatField field)
Definition: info.cpp:7
hebi::Info::HighResAngleField::HighResAngleField
HighResAngleField(const HebiInfoRef &internal, HebiInfoHighResAngleField field)
Definition: info.cpp:19
HebiInfoLedField
HebiInfoLedField
Definition: hebi.h:315
hebi::Info::serial_
StringField serial_
Definition: info.hpp:521
hebi::Info::HighResAngleField::has
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:22
hebi::Info::BoolField::has
bool has() const
True if (and only if) the field has a value.
Definition: info.cpp:44
hebi::Info::LedField::getColor
Color getColor() const
Returns the led color.
Definition: info.cpp:82


hebi_cpp_api_ros
Author(s): Chris Bollinger , Matthew Tesch
autogenerated on Fri Aug 2 2024 08:35:18