|
35 | 35 | #include <map> |
36 | 36 | #include <set> |
37 | 37 | #include <string> |
| 38 | +#include <vector> |
| 39 | +#include <algorithm> |
38 | 40 | #include <functional> |
39 | 41 |
|
40 | 42 | //----------------------------------------------------------------------------- |
@@ -151,6 +153,35 @@ class sensor : protected device |
151 | 153 | // Human-readable name of the connected sensor. |
152 | 154 | std::string type_name() const; |
153 | 155 |
|
| 156 | + // Bin Data Format: read-only |
| 157 | + // Returns the format of the values in `bin_data` for the current mode. |
| 158 | + // Possible values are: |
| 159 | + // |
| 160 | + // - `u8`: Unsigned 8-bit integer (byte) |
| 161 | + // - `s8`: Signed 8-bit integer (sbyte) |
| 162 | + // - `u16`: Unsigned 16-bit integer (ushort) |
| 163 | + // - `s16`: Signed 16-bit integer (short) |
| 164 | + // - `s16_be`: Signed 16-bit integer, big endian |
| 165 | + // - `s32`: Signed 32-bit integer (int) |
| 166 | + // - `float`: IEEE 754 32-bit floating point (float) |
| 167 | + std::string bin_data_format() const { return get_attr_string("bin_data_format"); }; |
| 168 | + |
| 169 | + // Bin Data: read-only |
| 170 | + // Returns the unscaled raw values in the `value<N>` attributes as raw byte |
| 171 | + // array. Use `bin_data_format`, `num_values` and the individual sensor |
| 172 | + // documentation to determine how to interpret the data. |
| 173 | + const std::vector<char>& bin_data() const; |
| 174 | + |
| 175 | + // Bin Data: read-only |
| 176 | + // Writes the unscaled raw values in the `value<N>` attributes into the |
| 177 | + // user-provided struct/buffer. Use `bin_data_format`, `num_values` and the |
| 178 | + // individual sensor documentation to determine how to interpret the data. |
| 179 | + template <class T> |
| 180 | + void bin_data(T *buf) const { |
| 181 | + bin_data(); // fills _bin_data |
| 182 | + std::copy_n(_bin_data.data(), _bin_data.size(), static_cast<char*>(buf)); |
| 183 | + } |
| 184 | + |
154 | 185 | //~autogen cpp_generic-get-set classes.sensor>currentClass |
155 | 186 |
|
156 | 187 | // Command: write-only |
@@ -210,6 +241,8 @@ class sensor : protected device |
210 | 241 | sensor() {} |
211 | 242 |
|
212 | 243 | bool connect(const std::map<std::string, std::set<std::string>>&) noexcept; |
| 244 | + |
| 245 | + mutable std::vector<char> _bin_data; |
213 | 246 | }; |
214 | 247 |
|
215 | 248 | //----------------------------------------------------------------------------- |
|
0 commit comments