$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 
24 #include <cloe/component.hpp> // for Component
25 #include <fable/json.hpp> // for Json
26 
27 namespace cloe {
28 
29 class PowertrainSensor : public Component {
30  public:
31  using Component::Component;
32  PowertrainSensor() : Component("powertrain_sensor") {}
33  virtual ~PowertrainSensor() noexcept = default;
34 
40  virtual double pedal_position_acceleration() const = 0;
41 
51  virtual int gear_transmission() const = 0;
52 
56  fable::Json active_state() const override {
57  return fable::Json{
58  {"pedal_position_acceleration", pedal_position_acceleration()},
59  {"gear_transmission", gear_transmission()},
60  };
61  }
62 };
63 
68  public:
69  using PowertrainSensor::PowertrainSensor;
70  NopPowertrainSensor() : PowertrainSensor("nop_powertrain_sensor") {}
71  virtual ~NopPowertrainSensor() noexcept {};
72 
73  double pedal_position_acceleration() const override { return pedal_position_acceleration_; }
74 
75  int gear_transmission() const override { return gear_transmission_; }
76 
77  void reset() override {
78  pedal_position_acceleration_ = 0.0;
79  gear_transmission_ = 0;
80  }
81 
82  protected:
83  double pedal_position_acceleration_{0.0};
84  int gear_transmission_{0};
85 };
86 
87 } // namespace cloe
Definition: component.hpp:143
Definition: powertrain_sensor.hpp:67
void reset() override
Definition: powertrain_sensor.hpp:77
double pedal_position_acceleration() const override
Definition: powertrain_sensor.hpp:73
int gear_transmission() const override
Definition: powertrain_sensor.hpp:75
Definition: powertrain_sensor.hpp:29
virtual double pedal_position_acceleration() const =0
virtual int gear_transmission() const =0
fable::Json active_state() const override
Definition: powertrain_sensor.hpp:56
nlohmann::json Json
Definition: fable_fwd.hpp:35