roo_monitoring
API Documentation for roo_monitoring
Loading...
Searching...
No Matches
transform.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4
5namespace roo_monitoring {
6
7/// Maps application-domain floats to 16-bit stored values.
8///
9/// Currently implemented as a linear transformation.
10class Transform {
11 public:
12 /// Creates a linear transformation ax+b.
13 ///
14 /// The result is rounded to the nearest integer.
15 static Transform Linear(float multiplier, float offset);
16
17 /// Creates a linear transform from min/max representable values.
18 ///
19 /// The minimum maps to 0 and the maximum maps to 65535.
20 static Transform LinearRange(float min_value, float max_value);
21
22 /// Applies the transform and clamps to [0, 65535].
23 uint16_t apply(float value) const;
24
25 /// Recovers the application-domain value from encoded data.
26 float unapply(uint16_t value) const;
27
28 /// Returns the multiplier used by the transform.
29 float multiplier() const { return multiplier_; }
30 /// Returns the offset used by the transform.
31 float offset() const { return offset_; }
32
33 private:
34 Transform(float multiplier, float offset)
35 : multiplier_(multiplier), offset_(offset) {}
36
37 float multiplier_;
38 float offset_;
39};
40
41} // namespace roo_monitoring
Maps application-domain floats to 16-bit stored values.
Definition transform.h:10
float offset() const
Returns the offset used by the transform.
Definition transform.h:31
float unapply(uint16_t value) const
Recovers the application-domain value from encoded data.
Definition transform.cpp:24
static Transform LinearRange(float min_value, float max_value)
Creates a linear transform from min/max representable values.
Definition transform.cpp:9
uint16_t apply(float value) const
Applies the transform and clamps to [0, 65535].
Definition transform.cpp:13
float multiplier() const
Returns the multiplier used by the transform.
Definition transform.h:29
static Transform Linear(float multiplier, float offset)
Creates a linear transformation ax+b.
Definition transform.cpp:5
Umbrella header for the roo_monitoring module.