1 /*
2  * Copyright (C) 2021 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 #pragma once
18 
19 #include <android/hardware/automotive/vehicle/2.0/types.h>
20 #include <vhal_v2_0/VehicleUtils.h>
21 
22 namespace android::hardware::automotive::vehicle::V2_0::impl {
23 
24 // Some handy constants to avoid conversions from enum to int.
25 constexpr int ABS_ACTIVE = (int)VehicleProperty::ABS_ACTIVE;
26 constexpr int AP_POWER_STATE_REQ = (int)VehicleProperty::AP_POWER_STATE_REQ;
27 constexpr int AP_POWER_STATE_REPORT = (int)VehicleProperty::AP_POWER_STATE_REPORT;
28 constexpr int DOOR_1_LEFT = (int)VehicleAreaDoor::ROW_1_LEFT;
29 constexpr int DOOR_1_RIGHT = (int)VehicleAreaDoor::ROW_1_RIGHT;
30 constexpr int DOOR_2_LEFT = (int)VehicleAreaDoor::ROW_2_LEFT;
31 constexpr int DOOR_2_RIGHT = (int)VehicleAreaDoor::ROW_2_RIGHT;
32 constexpr int DOOR_REAR = (int)VehicleAreaDoor::REAR;
33 constexpr int WINDOW_1_LEFT = (int)VehicleAreaWindow::ROW_1_LEFT;
34 constexpr int WINDOW_1_RIGHT = (int)VehicleAreaWindow::ROW_1_RIGHT;
35 constexpr int WINDOW_2_LEFT = (int)VehicleAreaWindow::ROW_2_LEFT;
36 constexpr int WINDOW_2_RIGHT = (int)VehicleAreaWindow::ROW_2_RIGHT;
37 constexpr int WINDOW_ROOF_TOP_1 = (int)VehicleAreaWindow::ROOF_TOP_1;
38 constexpr int FAN_DIRECTION_FACE = (int)VehicleHvacFanDirection::FACE;
39 constexpr int FAN_DIRECTION_FLOOR = (int)VehicleHvacFanDirection::FLOOR;
40 constexpr int OBD2_LIVE_FRAME = (int)VehicleProperty::OBD2_LIVE_FRAME;
41 constexpr int OBD2_FREEZE_FRAME = (int)VehicleProperty::OBD2_FREEZE_FRAME;
42 constexpr int OBD2_FREEZE_FRAME_INFO = (int)VehicleProperty::OBD2_FREEZE_FRAME_INFO;
43 constexpr int OBD2_FREEZE_FRAME_CLEAR = (int)VehicleProperty::OBD2_FREEZE_FRAME_CLEAR;
44 constexpr int TRACTION_CONTROL_ACTIVE = (int)VehicleProperty::TRACTION_CONTROL_ACTIVE;
45 constexpr int VEHICLE_MAP_SERVICE = (int)VehicleProperty::VEHICLE_MAP_SERVICE;
46 constexpr int WHEEL_TICK = (int)VehicleProperty::WHEEL_TICK;
47 constexpr int ALL_WHEELS =
48     (int)(VehicleAreaWheel::LEFT_FRONT | VehicleAreaWheel::RIGHT_FRONT |
49           VehicleAreaWheel::LEFT_REAR | VehicleAreaWheel::RIGHT_REAR);
50 constexpr int SEAT_1_LEFT = (int)(VehicleAreaSeat::ROW_1_LEFT);
51 constexpr int SEAT_1_RIGHT = (int)(VehicleAreaSeat::ROW_1_RIGHT);
52 constexpr int HVAC_LEFT = (int)(VehicleAreaSeat::ROW_1_LEFT | VehicleAreaSeat::ROW_2_LEFT |
53                                 VehicleAreaSeat::ROW_2_CENTER);
54 constexpr int HVAC_RIGHT = (int)(VehicleAreaSeat::ROW_1_RIGHT | VehicleAreaSeat::ROW_2_RIGHT);
55 constexpr int HVAC_ALL = HVAC_LEFT | HVAC_RIGHT;
56 constexpr int VENDOR_EXTENSION_BOOLEAN_PROPERTY =
57     (int)(0x101 | VehiclePropertyGroup::VENDOR | VehiclePropertyType::BOOLEAN | VehicleArea::DOOR);
58 constexpr int VENDOR_EXTENSION_FLOAT_PROPERTY =
59     (int)(0x102 | VehiclePropertyGroup::VENDOR | VehiclePropertyType::FLOAT | VehicleArea::SEAT);
60 constexpr int VENDOR_EXTENSION_INT_PROPERTY =
61     (int)(0x103 | VehiclePropertyGroup::VENDOR | VehiclePropertyType::INT32 | VehicleArea::WINDOW);
62 constexpr int VENDOR_EXTENSION_STRING_PROPERTY =
63     (int)(0x104 | VehiclePropertyGroup::VENDOR | VehiclePropertyType::STRING | VehicleArea::GLOBAL);
64 constexpr int FUEL_DOOR_REAR_LEFT = (int)PortLocationType::REAR_LEFT;
65 constexpr int CHARGE_PORT_FRONT_LEFT = (int)PortLocationType::FRONT_LEFT;
66 constexpr int CHARGE_PORT_REAR_LEFT = (int)PortLocationType::REAR_LEFT;
67 constexpr int LIGHT_STATE_ON = (int)VehicleLightState::ON;
68 constexpr int LIGHT_SWITCH_AUTO = (int)VehicleLightSwitch::AUTOMATIC;
69 constexpr int WHEEL_FRONT_LEFT = (int)VehicleAreaWheel::LEFT_FRONT;
70 constexpr int WHEEL_FRONT_RIGHT = (int)VehicleAreaWheel::RIGHT_FRONT;
71 constexpr int WHEEL_REAR_LEFT = (int)VehicleAreaWheel::LEFT_REAR;
72 constexpr int WHEEL_REAR_RIGHT = (int)VehicleAreaWheel::RIGHT_REAR;
73 
74 /**
75  * This property is used for test purpose to generate fake events. Here is the test package that
76  * is referencing this property definition: packages/services/Car/tests/vehiclehal_test
77  */
78 const int32_t kGenerateFakeDataControllingProperty =
79     0x0666 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;
80 
81 /**
82  * This property is used for test purpose to set properties' value from vehicle.
83  * For example: Mocking hard button press triggering a HVAC fan speed change.
84  * Android set kSetPropertyFromVehicleForTest with an array of integer {HVAC_FAN_SPEED, value of
85  * fan speed} and a long value indicates the timestamp of the events .
86  * It only works with integer type properties.
87  */
88 const int32_t kSetIntPropertyFromVehicleForTest =
89         0x1112 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;
90 /**
91  * This property is used for test purpose to set properties' value from vehicle.
92  * It only works with float type properties.
93  */
94 const int32_t kSetFloatPropertyFromVehicleForTest =
95         0x1113 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;
96 /**
97  * This property is used for test purpose to set properties' value from vehicle.
98  * It only works with boolean type properties.
99  */
100 const int32_t kSetBooleanPropertyFromVehicleForTest =
101         0x1114 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;
102 
103 /**
104  * This property is used for test purpose. End to end tests use this property to test set and get
105  * method for MIXED type properties.
106  */
107 const int32_t kMixedTypePropertyForTest =
108         0x1111 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::MIXED;
109 
110 #ifdef ENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING
111 /**
112  * Converts the system property to the vendor property.
113  * WARNING: This is only for the end-to-end testing, Should NOT include in the
114  * user build */
toVendor(VehicleProperty prop)115 inline constexpr int32_t toVendor(VehicleProperty prop) {
116     return (toInt(prop) & ~toInt(VehiclePropertyGroup::MASK)) | VehiclePropertyGroup::VENDOR;
117 }
118 
119 /**
120  * These properties are used for the end-to-end testing of ClusterHomeService.
121  */
122 constexpr int32_t VENDOR_CLUSTER_SWITCH_UI = toVendor(VehicleProperty::CLUSTER_SWITCH_UI);
123 constexpr int32_t VENDOR_CLUSTER_DISPLAY_STATE = toVendor(VehicleProperty::CLUSTER_DISPLAY_STATE);
124 constexpr int32_t VENDOR_CLUSTER_REPORT_STATE = toVendor(VehicleProperty::CLUSTER_REPORT_STATE);
125 constexpr int32_t VENDOR_CLUSTER_REQUEST_DISPLAY =
126         toVendor(VehicleProperty::CLUSTER_REQUEST_DISPLAY);
127 constexpr int32_t VENDOR_CLUSTER_NAVIGATION_STATE =
128         toVendor(VehicleProperty::CLUSTER_NAVIGATION_STATE);
129 #endif  // ENABLE_VENDOR_CLUSTER_PROPERTY_FOR_TESTING
130 
131 /**
132  * FakeDataCommand enum defines the supported command type for kGenerateFakeDataControllingProperty.
133  * All those commands can be send independently with each other. And each will override the one sent
134  * previously.
135  *
136  * The controlling property has the following format:
137  *
138  *     int32Values[0] - command enum defined in FakeDataCommand
139  *
140  * The format of the arguments is defined for each command type as below:
141  */
142 enum class FakeDataCommand : int32_t {
143     /**
144      * Starts linear fake data generation. Caller must provide additional data:
145      *     int32Values[1] - vehicle property to which command applies
146      *     int64Values[0] - periodic interval in nanoseconds
147      *     floatValues[0] - initial value
148      *     floatValues[1] - dispersion defines the min/max value relative to initial value, where
149      *                      max = initial_value + dispersion, min = initial_value - dispersion.
150      *                      Dispersion should be non-negative, otherwise the behavior is undefined.
151      *     floatValues[2] - increment, with every timer tick the value will be incremented by this
152      *                      amount. When reaching to max value, the current value will be set to
153      *                      min. It should be non-negative, otherwise the behavior is undefined.
154      */
155     StartLinear = 0,
156 
157     /** Stops linear fake data generation that was triggered by StartLinear commands.
158      *     int32Values[1] - vehicle property to which command applies. VHAL will stop the
159      *                      corresponding linear generation for that property.
160      */
161     StopLinear = 1,
162 
163     /**
164      * Starts JSON-based fake data generation. It iterates through JSON-encoded VHAL events from a
165      * file and inject them to VHAL. The iteration can be repeated multiple times or infinitely.
166      * Caller must provide additional data:
167      *     int32Values[1] - number of iterations. If it is not provided or -1. The iteration will be
168      *                      repeated infinite times.
169      *     stringValue    - path to the fake values JSON file
170      */
171     StartJson = 2,
172 
173     /**
174      * Stops JSON-based fake data generation. As multiple JSON-based generation can happen at the
175      * same time. Caller must provide the path of fake value JSON file to stop the corresponding
176      * generation:
177      *     stringValue    - path to the fake values JSON file
178      */
179     StopJson = 3,
180 
181     /**
182      * Injects key press event (HAL incorporates UP/DOWN acction and triggers 2 HAL events for every
183      * key-press). We set the enum with high number to leave space for future start/stop commands.
184      * Caller must provide the following data:
185      *     int32Values[2] - Android key code
186      *     int32Values[3] - target display (0 - for main display, 1 - for instrument cluster, see
187      *                      VehicleDisplay)
188      */
189     KeyPress = 100,
190 };
191 
192 /**
193  * These properties are placeholder properties for developers to test new features without
194  * implementing a real property.
195  */
196 constexpr int32_t PLACEHOLDER_PROPERTY_INT =
197         0x2a11 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::INT32;
198 constexpr int32_t PLACEHOLDER_PROPERTY_FLOAT =
199         0x2a11 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::FLOAT;
200 constexpr int32_t PLACEHOLDER_PROPERTY_BOOLEAN =
201         0x2a11 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::BOOLEAN;
202 constexpr int32_t PLACEHOLDER_PROPERTY_STRING =
203         0x2a11 | VehiclePropertyGroup::VENDOR | VehicleArea::GLOBAL | VehiclePropertyType::STRING;
204 
205 const int32_t kHvacPowerProperties[] = {
206     toInt(VehicleProperty::HVAC_FAN_SPEED),
207     toInt(VehicleProperty::HVAC_FAN_DIRECTION),
208 };
209 
210 }  // namespace android::hardware::automotive::vehicle::V2_0::impl
211