xref: /aosp_15_r20/hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/LinearFakeValueGenerator.h (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
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 
17 #ifndef android_hardware_automotive_vehicle_V2_0_impl_LinearFakeValueGenerator_H_
18 #define android_hardware_automotive_vehicle_V2_0_impl_LinearFakeValueGenerator_H_
19 
20 #include "FakeValueGenerator.h"
21 
22 namespace android {
23 namespace hardware {
24 namespace automotive {
25 namespace vehicle {
26 namespace V2_0 {
27 
28 namespace impl {
29 
30 class LinearFakeValueGenerator : public FakeValueGenerator {
31 private:
32     // In every timer tick we may want to generate new value based on initial value for debug
33     // purpose. It's better to have sequential values to see if events gets delivered in order
34     // to the client.
35 
36     struct GeneratorCfg {
37         int32_t propId;
38         float middleValue;
39         float currentValue;  //  Should be in range (middleValue +/- dispersion).
40         float dispersion;    //  Defines minimum and maximum value based on initial value.
41         float increment;     //  Value that we will be added to currentValue with each timer tick.
42         Nanos interval;
43     };
44 
45 public:
46     LinearFakeValueGenerator(const VehiclePropValue& request);
47     // A linear value generator in range [middleValue - dispersion, middleValue + dispersion),
48     // starts at 'currentValue' and at each 'interval', increase by 'increment' and loop back if
49     // exceeds middleValue + dispersion.
50     LinearFakeValueGenerator(int32_t propId, float middleValue, float currentValue,
51                              float dispersion, float increment, int64_t interval);
52     ~LinearFakeValueGenerator() = default;
53 
54     VehiclePropValue nextEvent();
55 
56     bool hasNext();
57 
58 private:
59     GeneratorCfg mGenCfg;
60 
61     void initGenCfg(int32_t propId, float middleValue, float currentValue, float dispersion,
62                     float increment, int64_t interval);
63 };
64 
65 }  // namespace impl
66 
67 }  // namespace V2_0
68 }  // namespace vehicle
69 }  // namespace automotive
70 }  // namespace hardware
71 }  // namespace android
72 
73 #endif  // android_hardware_automotive_vehicle_V2_0_impl_LinearFakeValueGenerator_H_
74