|
19 | 19 | * \file speedometer.cpp
|
20 | 20 | */
|
21 | 21 |
|
| 22 | +#include <memory> // for shared_ptr<> |
| 23 | + |
| 24 | +#include <fable/confable.hpp> // for Confable, CONFABLE_FRIENDS |
| 25 | +#include <fable/json.hpp> // for Json |
| 26 | + |
22 | 27 | #include <cloe/component.hpp> // for Component, ComponentFactory, ...
|
23 | 28 | #include <cloe/component/utility/ego_sensor_canon.hpp> // for EgoSensorCanon
|
| 29 | +#include <cloe/data_broker.hpp> // for DataBroker |
24 | 30 | #include <cloe/plugin.hpp> // for EXPORT_CLOE_PLUGIN
|
25 | 31 | #include <cloe/registrar.hpp> // for Registrar
|
26 | 32 | #include <cloe/trigger/evaluate_event.hpp> // for EvaluateCallback
|
27 | 33 | #include <cloe/vehicle.hpp> // for Vehicle
|
28 |
| -using namespace cloe; |
29 | 34 |
|
30 |
| -struct SpeedometerConf : public Confable { |
| 35 | +struct SpeedometerConf : public fable::Confable { |
31 | 36 | CONFABLE_FRIENDS(SpeedometerConf)
|
32 | 37 | };
|
33 | 38 |
|
34 |
| -class Speedometer : public Component { |
| 39 | +class Speedometer : public cloe::Component { |
35 | 40 | public:
|
36 |
| - Speedometer(const std::string& name, const SpeedometerConf&, std::shared_ptr<EgoSensor> ego) |
| 41 | + Speedometer(const std::string& name, const SpeedometerConf&, std::shared_ptr<cloe::EgoSensor> ego) |
37 | 42 | : Component(name, "provides an event trigger to evaluate speed in km/h"), sensor_(ego) {}
|
38 | 43 |
|
39 | 44 | virtual ~Speedometer() noexcept = default;
|
40 | 45 |
|
41 |
| - void enroll(Registrar& r) override { |
| 46 | + void enroll(cloe::Registrar& r) override { |
42 | 47 | callback_kmph_ =
|
43 |
| - r.register_event<events::EvaluateFactory, double>("kmph", "vehicle speed in km/h"); |
| 48 | + r.register_event<cloe::events::EvaluateFactory, double>("kmph", "vehicle speed in km/h"); |
| 49 | + |
| 50 | + auto& db = r.data_broker(); |
| 51 | + { |
| 52 | + std::string signal_name = fmt::format("components.{}.kmph", name()); |
| 53 | + auto signal = db.declare<double>(signal_name); |
| 54 | + signal->set_getter<double>( |
| 55 | + [this]() -> double { return cloe::utility::EgoSensorCanon(sensor_).velocity_as_kmph(); }); |
| 56 | + } |
44 | 57 | }
|
45 | 58 |
|
46 |
| - Duration process(const Sync& sync) override { |
47 |
| - auto ego = utility::EgoSensorCanon(sensor_); |
| 59 | + cloe::Duration process(const cloe::Sync& sync) override { |
| 60 | + auto ego = cloe::utility::EgoSensorCanon(sensor_); |
48 | 61 | callback_kmph_->trigger(sync, ego.velocity_as_kmph());
|
49 | 62 | return sync.time();
|
50 | 63 | }
|
51 | 64 |
|
52 |
| - Json active_state() const override { return nullptr; } |
| 65 | + fable::Json active_state() const override { |
| 66 | + return fable::Json{{"kmph", utility::EgoSensorCanon(sensor_).velocity_as_kmph()}}; |
| 67 | + } |
53 | 68 |
|
54 | 69 | private:
|
55 | 70 | // State:
|
56 |
| - std::shared_ptr<events::EvaluateCallback> callback_kmph_; |
57 |
| - std::shared_ptr<EgoSensor> sensor_; |
| 71 | + std::shared_ptr<cloe::events::EvaluateCallback> callback_kmph_; |
| 72 | + std::shared_ptr<cloe::EgoSensor> sensor_; |
58 | 73 | };
|
59 | 74 |
|
60 | 75 | DEFINE_COMPONENT_FACTORY(SpeedometerFactory, SpeedometerConf, "speedometer",
|
|
0 commit comments