bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
mqtt_infrared_backend.h
Go to the documentation of this file.
1#ifndef BITSIM_SENSORS_BACKENDS_MQTT_INFRARED_BACKEND_H
2#define BITSIM_SENSORS_BACKENDS_MQTT_INFRARED_BACKEND_H
3
4#include "bitsim/bitsim_config.h"
5
6#ifdef BITSIM_MQTT
7
12
13#include <string>
14#include <vector>
15
16namespace bitsim
17{
18namespace sensors::backends
19{
20
38{
39 public:
40 static const std::string BACKEND_TYPE;
41
47
49
55
60 void load(const nlohmann::json &j) override;
61
63 {
64 channel_.set_config(config);
65 }
66
70 void connect() { channel_.connect(); }
71
77 std::vector<real_t> read_values() override;
78
84 bool receive(const std::string &text);
85
86 bool is_alive() const { return channel_.is_alive(); }
87
88 const MQTT_SensorChannel &channel() const noexcept { return channel_; }
89
93 const InfraredMessage &last_value_read() const noexcept { return last_message_; }
94
95 private:
96 bool accept_(const std::string &text);
97
98 MQTT_SensorChannel channel_;
99 InfraredMessage last_message_;
100 bool has_message_{false};
101};
102
103} // namespace sensors::backends
104} // namespace bitsim
105
106#endif
107#endif // BITSIM_SENSORS_BACKENDS_MQTT_INFRARED_BACKEND_H
Definition mqtt_subscriber.h:24
InfraredBackendBase(const std::string &backend_type)
Definition infrared_backend_base.h:108
void connect()
Connect to the broker, unless the subscriber already is.
Definition mqtt_infrared_backend.h:70
std::vector< real_t > read_values() override
Take the readings that have arrived.
Definition mqtt_infrared_backend.cpp:65
MQTT_InfraredBackend()
A backend that subscribes on its own, see connect(). Give it a topic with set_channel_config() or loa...
Definition mqtt_infrared_backend.cpp:18
const InfraredMessage & last_value_read() const noexcept
Definition mqtt_infrared_backend.h:93
void set_channel_config(const MQTT_SensorChannel::Config &config)
Definition mqtt_infrared_backend.h:62
static const std::string BACKEND_TYPE
Definition mqtt_infrared_backend.h:40
void load(const nlohmann::json &j) override
Read the settings, see InfraredBackendBase::load(). Also reads broker, topic and timeout [s],...
Definition mqtt_infrared_backend.cpp:31
bool is_alive() const
Definition mqtt_infrared_backend.h:86
const MQTT_SensorChannel & channel() const noexcept
Definition mqtt_infrared_backend.h:88
bool receive(const std::string &text)
Take one message, as read_values() does for each message that arrives. Use it to feed the backend wit...
Definition mqtt_infrared_backend.cpp:40
The topic a sensor on a board publishes its readings to.
Definition mqtt_sensor_channel.h:34
Definition camera_backend_base.h:19
Definition dc_motor_backend_base.h:9
Models a message from an array of infrared reflectance sensors, one value per element:
Definition infrared.h:31