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/sdk/common/proto_value.hpp>
9#include <viam/sdk/common/utils.hpp>
10#include <viam/sdk/config/resource.hpp>
11
12namespace viam {
13namespace sdk {
14
16
22class PowerSensor : public Component {
23 public:
25 struct voltage {
27 double volts = 0.0;
29 bool is_ac = false;
30 friend bool operator==(const voltage&, const voltage&) = default;
31 };
32
34 struct current {
36 double amperes = 0.0;
38 bool is_ac = false;
39 friend bool operator==(const current&, const current&) = default;
40 };
41
42 API api() const override;
43
47 return get_voltage({});
48 }
49
53 virtual voltage get_voltage(const ProtoStruct& extra) = 0;
54
58 return get_current({});
59 }
60
64 virtual current get_current(const ProtoStruct& extra) = 0;
65
68 inline double get_power() {
69 return get_power({});
70 }
71
75 virtual double get_power(const ProtoStruct& extra) = 0;
76
79 inline ProtoStruct get_readings() {
80 return get_readings({});
81 }
82
86 virtual ProtoStruct get_readings(const ProtoStruct& extra) = 0;
87
91 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
92
95 virtual ProtoStruct get_status() = 0;
96
97 protected:
98 explicit PowerSensor(std::string name) : Component(std::move(name)) {}
99
100 explicit PowerSensor(const ResourceConfig& cfg) : Component(cfg) {}
101};
102
103template <>
105 static API api();
106};
107
108} // namespace sdk
109} // namespace viam
Definition resource_api.hpp:21
Definition component.hpp:10
Definition power_sensor.hpp:22
current get_current()
Returns the current reading of this sensor.
Definition power_sensor.hpp:57
virtual ProtoStruct get_status()=0
Get the status of the power sensor.
API api() const override
Returns the API associated with a particular resource.
virtual current get_current(const ProtoStruct &extra)=0
Returns the current reading of this sensor.
virtual double get_power(const ProtoStruct &extra)=0
Returns the power reading of this sensor.
virtual voltage get_voltage(const ProtoStruct &extra)=0
Returns the voltage reading of this sensor.
double get_power()
Returns the power reading of this sensor.
Definition power_sensor.hpp:68
ProtoStruct get_readings()
Returns the measurements/data specific to this sensor.
Definition power_sensor.hpp:79
virtual ProtoStruct get_readings(const ProtoStruct &extra)=0
Returns the measurements/data specific to this sensor.
voltage get_voltage()
Returns the voltage reading of this sensor.
Definition power_sensor.hpp:46
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
Definition resource.hpp:42
virtual std::string name() const
Return the resource's name.
Definition resource_api.hpp:46
Definition power_sensor.hpp:34
double amperes
Current in amperes.
Definition power_sensor.hpp:36
bool is_ac
Whether the current is DC or AC.
Definition power_sensor.hpp:38
Definition power_sensor.hpp:25
double volts
Voltage in volts.
Definition power_sensor.hpp:27
bool is_ac
Whether the voltage is DC or AC.
Definition power_sensor.hpp:29