$darkmode
powertrain_sensor.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
22 #pragma once
23 #ifndef CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_
24 #define CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_
25 
26 #include <cloe/component.hpp> // for Component, Json
27 
28 namespace cloe {
29 
30 class PowertrainSensor : public Component {
31  public:
32  using Component::Component;
33  PowertrainSensor() : Component("powertrain_sensor") {}
34  virtual ~PowertrainSensor() noexcept = default;
35 
41  virtual double pedal_position_acceleration() const = 0;
42 
52  virtual int gear_transmission() const = 0;
53 
57  Json active_state() const override {
58  return Json{
59  {"pedal_position_acceleration", pedal_position_acceleration()},
60  {"gear_transmission", gear_transmission()},
61  };
62  }
63 };
64 
69  public:
70  using PowertrainSensor::PowertrainSensor;
71  NopPowertrainSensor() : PowertrainSensor("nop_powertrain_sensor") {}
72  virtual ~NopPowertrainSensor() noexcept {};
73 
74  double pedal_position_acceleration() const override { return pedal_position_acceleration_; }
75 
76  int gear_transmission() const override { return gear_transmission_; }
77 
78  void reset() override {
79  pedal_position_acceleration_ = 0.0;
80  gear_transmission_ = 0;
81  }
82 
83  protected:
84  double pedal_position_acceleration_{0.0};
85  int gear_transmission_{0};
86 };
87 
88 } // namespace cloe
89 
90 #endif // CLOE_COMPONENT_POWERTRAIN_SENSOR_HPP_
int gear_transmission() const override
Definition: powertrain_sensor.hpp:76
double pedal_position_acceleration() const override
Definition: powertrain_sensor.hpp:74
Definition: powertrain_sensor.hpp:68
virtual int gear_transmission() const =0
Definition: powertrain_sensor.hpp:30
Definition: coordinator.hpp:36
Json active_state() const override
Definition: powertrain_sensor.hpp:57
void reset() override
Definition: powertrain_sensor.hpp:78
virtual double pedal_position_acceleration() const =0
Definition: component.hpp:144