blob: 6cbcfe3cf72227eeac47cb6970567e5363a6298f [file] [log] [blame]
Pavel Maltseve2603e32016-10-25 16:03:23 -07001/*
2 * Copyright (C) 2016 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#include "DefaultVehicleHal.h"
18
Yifan Hongf9d30342016-11-30 13:45:34 -080019#define LOG_TAG "default_vehicle"
20#include <android/log.h>
21
Pavel Maltseve2603e32016-10-25 16:03:23 -070022namespace android {
23namespace hardware {
24namespace vehicle {
25namespace V2_0 {
26
27namespace impl {
28
Pavel Maltsevdb179c52016-10-27 15:43:06 -070029VehicleHal::VehiclePropValuePtr DefaultVehicleHal::get(
30 const VehiclePropValue& requestedPropValue, StatusCode* outStatus) {
31 *outStatus = StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -070032
33 VehiclePropValuePtr v;
Pavel Maltsevdb179c52016-10-27 15:43:06 -070034 VehicleProperty property = requestedPropValue.prop;
35 int32_t areaId = requestedPropValue.areaId;
Pavel Maltsev30c84c32016-11-14 16:23:36 -080036 auto& pool = *getValuePool();
Pavel Maltseve2603e32016-10-25 16:03:23 -070037
38 switch (property) {
39 case VehicleProperty::INFO_MAKE:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080040 v = pool.obtainString("Default Car");
Pavel Maltseve2603e32016-10-25 16:03:23 -070041 break;
42 case VehicleProperty::HVAC_FAN_SPEED:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080043 v = pool.obtainInt32(mFanSpeed);
44 break;
45 case VehicleProperty::HVAC_POWER_ON:
46 v = pool.obtainBoolean(mHvacPowerOn);
47 break;
48 case VehicleProperty::HVAC_RECIRC_ON:
49 v = pool.obtainBoolean(mHvacRecircOn);
50 break;
51 case VehicleProperty::HVAC_AC_ON:
52 v = pool.obtainBoolean(mHvacAcOn);
53 break;
54 case VehicleProperty::HVAC_AUTO_ON:
55 v = pool.obtainBoolean(mHvacAutoOn);
56 break;
57 case VehicleProperty::HVAC_FAN_DIRECTION:
58 v = pool.obtainInt32(toInt(mFanDirection));
59 break;
60 case VehicleProperty::HVAC_DEFROSTER:
61 bool defroster;
62 *outStatus = getHvacDefroster(areaId, &defroster);
Pavel Maltsevdb179c52016-10-27 15:43:06 -070063 if (StatusCode::OK == *outStatus) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -080064 v = pool.obtainBoolean(defroster);
65 }
66 break;
67 case VehicleProperty::HVAC_TEMPERATURE_SET:
68 float value;
69 *outStatus = getHvacTemperature(requestedPropValue.areaId,
70 &value);
71 if (StatusCode::OK == *outStatus) {
72 v = pool.obtainFloat(value);
Pavel Maltseve2603e32016-10-25 16:03:23 -070073 }
74 break;
75 case VehicleProperty::INFO_FUEL_CAPACITY:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080076 v = pool.obtainFloat(0.75f);
Pavel Maltseve2603e32016-10-25 16:03:23 -070077 break;
78 case VehicleProperty::DISPLAY_BRIGHTNESS:
Pavel Maltsev30c84c32016-11-14 16:23:36 -080079 v = pool.obtainInt32(mBrightness);
80 break;
81 case VehicleProperty::NIGHT_MODE:
82 v = pool.obtainBoolean(false);
83 break;
84 case VehicleProperty::GEAR_SELECTION:
85 v = pool.obtainInt32(toInt(VehicleGear::GEAR_PARK));
Pavel Maltseve2603e32016-10-25 16:03:23 -070086 break;
Pavel Maltsevb5e51092016-11-22 11:01:03 -080087 case VehicleProperty::DRIVING_STATUS:
88 v = pool.obtainInt32(toInt(VehicleDrivingStatus::UNRESTRICTED));
89 break;
Pavel Maltsevd567a2a2016-12-14 16:07:29 -080090 case VehicleProperty::IGNITION_STATE:
91 v = pool.obtainInt32(toInt(VehicleIgnitionState::ACC));
92 break;
Pavel Maltseve2603e32016-10-25 16:03:23 -070093 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -070094 *outStatus = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -070095 }
96
Pavel Maltsevdb179c52016-10-27 15:43:06 -070097 if (StatusCode::OK == *outStatus && v.get() != nullptr) {
Pavel Maltseve2603e32016-10-25 16:03:23 -070098 v->prop = property;
99 v->areaId = areaId;
100 v->timestamp = elapsedRealtimeNano();
101 }
102
103 return v;
104}
105
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700106StatusCode DefaultVehicleHal::set(const VehiclePropValue& propValue) {
Pavel Maltseve2603e32016-10-25 16:03:23 -0700107 auto property = propValue.prop;
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800108 const auto& v = propValue.value;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700109
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700110 StatusCode status = StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700111
112 switch (property) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800113 case VehicleProperty::HVAC_POWER_ON:
114 mHvacPowerOn = v.int32Values[0] == 1;
115 break;
116 case VehicleProperty::HVAC_RECIRC_ON:
117 mHvacRecircOn = v.int32Values[0] == 1;
118 break;
119 case VehicleProperty::HVAC_AC_ON:
120 mHvacAcOn = v.int32Values[0] == 1;
121 break;
122 case VehicleProperty::HVAC_AUTO_ON:
123 mHvacAutoOn = v.int32Values[0] == 1;
124 break;
125 case VehicleProperty::HVAC_DEFROSTER:
126 status = setHvacDefroster(propValue.areaId, v.int32Values[0] == 1);
127 break;
128 case VehicleProperty::HVAC_FAN_DIRECTION:
129 mFanDirection =
130 static_cast<VehicleHvacFanDirection>(v.int32Values[0]);
131 break;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700132 case VehicleProperty::HVAC_FAN_SPEED:
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800133 mFanSpeed = v.int32Values[0];
134 break;
135 case VehicleProperty::HVAC_TEMPERATURE_SET:
136 status = setHvacTemperature(propValue.areaId, v.floatValues[0]);
Pavel Maltseve2603e32016-10-25 16:03:23 -0700137 break;
138 case VehicleProperty::DISPLAY_BRIGHTNESS:
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800139 mBrightness = v.int32Values[0];
Pavel Maltseve2603e32016-10-25 16:03:23 -0700140 break;
141 default:
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700142 status = StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700143 }
144
145 return status;
146}
147
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800148StatusCode DefaultVehicleHal::getHvacTemperature(int32_t areaId,
149 float* outValue) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700150 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800151 *outValue = mRow1LeftHvacTemperatureSet;
152 } else if (areaId == toInt(VehicleAreaZone::ROW_1_RIGHT)) {
153 *outValue = mRow1RightHvacTemperatureSet;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700154 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700155 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700156 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700157 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700158}
159
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800160StatusCode DefaultVehicleHal::setHvacTemperature(
161 int32_t areaId, float value) {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700162 if (areaId == toInt(VehicleAreaZone::ROW_1_LEFT)) {
Pavel Maltsev30c84c32016-11-14 16:23:36 -0800163 mRow1LeftHvacTemperatureSet = value;
164 } else if (areaId == toInt(VehicleAreaZone::ROW_1_RIGHT)) {
165 mRow1RightHvacTemperatureSet = value;
166 } else {
167 return StatusCode::INVALID_ARG;
168 }
169 return StatusCode::OK;
170}
171
172StatusCode DefaultVehicleHal::getHvacDefroster(int32_t areaId,
173 bool* outValue) {
174 ALOGI("Getting Hvac defroster for area: 0x%x", areaId);
175
176 if (areaId == toInt(VehicleAreaWindow::FRONT_WINDSHIELD)) {
177 *outValue = mFrontDefroster;
178 } else if (areaId == toInt(VehicleAreaWindow::REAR_WINDSHIELD)) {
179 *outValue = mRearDefroster;
180 } else {
181 ALOGE("Unable to get hvac defroster for area: 0x%x", areaId);
182 return StatusCode::INVALID_ARG;
183 }
184
185 ALOGI("Getting Hvac defroster for area: 0x%x, OK", areaId);
186 return StatusCode::OK;
187}
188
189StatusCode DefaultVehicleHal::setHvacDefroster(int32_t areaId, bool value) {
190 if (areaId == toInt(VehicleAreaWindow::FRONT_WINDSHIELD)) {
191 mFrontDefroster = value;
192 } else if (areaId == toInt(VehicleAreaWindow::REAR_WINDSHIELD)) {
193 mRearDefroster = value;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700194 } else {
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700195 return StatusCode::INVALID_ARG;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700196 }
Pavel Maltsevdb179c52016-10-27 15:43:06 -0700197 return StatusCode::OK;
Pavel Maltseve2603e32016-10-25 16:03:23 -0700198}
199
200} // impl
201
202} // namespace V2_0
203} // namespace vehicle
204} // namespace hardware
205} // namespace android