Viam C++ SDK current
Loading...
Searching...
No Matches
power_sensor.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <string>
7
8#include <viam/api/component/powersensor/v1/powersensor.pb.h>
9
10#include <viam/sdk/common/proto_type.hpp>
11#include <viam/sdk/common/utils.hpp>
12#include <viam/sdk/config/resource.hpp>
13
14using namespace viam::component::powersensor::v1;
15
16namespace viam {
17namespace sdk {
18
20
26class PowerSensor : public Component {
27 public:
29 struct voltage {
31 double volts;
33 bool is_ac;
34 };
35
37 struct current {
39 double amperes;
41 bool is_ac;
42 };
43
44 API api() const override;
45
47 static voltage from_proto(const GetVoltageResponse& proto);
48
50 static current from_proto(const GetCurrentResponse& proto);
51
53 static GetVoltageResponse to_proto(const voltage& v);
54
56 static GetCurrentResponse to_proto(const current& c);
57
61 return get_voltage({});
62 }
63
67 virtual voltage get_voltage(const AttributeMap& extra) = 0;
68
72 return get_current({});
73 }
74
78 virtual current get_current(const AttributeMap& extra) = 0;
79
82 inline double get_power() {
83 return get_power({});
84 }
85
89 virtual double get_power(const AttributeMap& extra) = 0;
90
93 inline AttributeMap get_readings() {
94 return get_readings({});
95 }
96
100 virtual AttributeMap get_readings(const AttributeMap& extra) = 0;
101
105 virtual AttributeMap do_command(const AttributeMap& command) = 0;
106
107 protected:
108 explicit PowerSensor(std::string name) : Component(std::move(name)){};
109};
110
111template <>
113 static API api();
114};
115
116bool operator==(const PowerSensor::voltage& lhs, const PowerSensor::voltage& rhs);
117bool operator==(const PowerSensor::current& lhs, const PowerSensor::current& rhs);
118} // namespace sdk
119} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
Definition component.hpp:14
Definition power_sensor.hpp:26
static voltage from_proto(const GetVoltageResponse &proto)
Creates a voltage struct from its proto representation.
static GetCurrentResponse to_proto(const current &c)
Converts a current struct to its proto representation.
virtual AttributeMap do_command(const AttributeMap &command)=0
Send/receive arbitrary commands to the resource.
current get_current()
Returns the current reading of this sensor.
Definition power_sensor.hpp:71
API api() const override
Returns the API associated with a particular resource.
virtual voltage get_voltage(const AttributeMap &extra)=0
Returns the voltage reading of this sensor.
static current from_proto(const GetCurrentResponse &proto)
Creates a current struct from its proto representation.
virtual current get_current(const AttributeMap &extra)=0
Returns the current reading of this sensor.
static GetVoltageResponse to_proto(const voltage &v)
Converts a voltage struct to its proto representation.
double get_power()
Returns the power reading of this sensor.
Definition power_sensor.hpp:82
virtual AttributeMap get_readings(const AttributeMap &extra)=0
Returns the measurements/data specific to this sensor.
voltage get_voltage()
Returns the voltage reading of this sensor.
Definition power_sensor.hpp:60
AttributeMap get_readings()
Returns the measurements/data specific to this sensor.
Definition power_sensor.hpp:93
virtual double get_power(const AttributeMap &extra)=0
Returns the power reading of this sensor.
virtual std::string name() const
Return the resource's name.
Definition resource_api.hpp:50
Definition power_sensor.hpp:37
double amperes
Current in amperes.
Definition power_sensor.hpp:39
bool is_ac
Whether the current is DC or AC.
Definition power_sensor.hpp:41
Definition power_sensor.hpp:29
double volts
Voltage in volts.
Definition power_sensor.hpp:31
bool is_ac
Whether the voltage is DC or AC.
Definition power_sensor.hpp:33