Pavel Maltsev | a2f426a | 2016-10-04 10:17:05 -0700 | [diff] [blame] | 1 | /* |
| 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 "Vehicle.h" |
| 18 | #include "VehicleUtils.h" |
| 19 | |
| 20 | #include <utils/SystemClock.h> |
| 21 | |
| 22 | namespace android { |
| 23 | namespace hardware { |
| 24 | namespace vehicle { |
| 25 | namespace V2_0 { |
| 26 | namespace implementation { |
| 27 | |
| 28 | const VehiclePropConfig kVehicleProperties[] = { |
| 29 | { |
| 30 | .prop = VehicleProperty::INFO_MAKE, |
| 31 | .access = VehiclePropertyAccess::READ, |
| 32 | .changeMode = VehiclePropertyChangeMode::STATIC, |
| 33 | .permissionModel = VehiclePermissionModel::OEM_ONLY, |
| 34 | .configString = init_hidl_string("Some=configuration,options=if,you=have,any=?"), |
| 35 | }, |
| 36 | |
| 37 | { |
| 38 | .prop = VehicleProperty::HVAC_FAN_SPEED, |
| 39 | .access = VehiclePropertyAccess::READ_WRITE, |
| 40 | .changeMode = VehiclePropertyChangeMode::ON_CHANGE, |
| 41 | .permissionModel = VehiclePermissionModel::NO_RESTRICTION, |
| 42 | .supportedAreas = static_cast<int32_t>( |
| 43 | VehicleAreaZone::ROW_1_LEFT | VehicleAreaZone::ROW_1_RIGHT), |
| 44 | .areaConfigs = init_hidl_vec({ |
| 45 | VehicleAreaConfig { |
| 46 | .areaId = enum_val(VehicleAreaZone::ROW_2_LEFT), |
| 47 | .minInt32Value = 1, |
| 48 | .maxInt32Value = 7}, |
| 49 | VehicleAreaConfig { |
| 50 | .areaId = enum_val(VehicleAreaZone::ROW_1_RIGHT), |
| 51 | .minInt32Value = 1, |
| 52 | .maxInt32Value = 5, |
| 53 | } |
| 54 | }), |
| 55 | }, |
| 56 | |
| 57 | { |
| 58 | .prop = VehicleProperty::INFO_FUEL_CAPACITY, |
| 59 | .access = VehiclePropertyAccess::READ, |
| 60 | .changeMode = VehiclePropertyChangeMode::ON_CHANGE, |
| 61 | .permissionModel = VehiclePermissionModel::OEM_ONLY, |
| 62 | .areaConfigs = init_hidl_vec({ |
| 63 | VehicleAreaConfig { |
| 64 | .minFloatValue = 0, |
| 65 | .maxFloatValue = 1.0 |
| 66 | } |
| 67 | }) |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | const char kInfoMake[] = "Android Super Car"; |
| 72 | |
| 73 | |
| 74 | Return<void> Vehicle::getAllPropConfigs(getAllPropConfigs_cb _hidl_cb) { |
| 75 | hidl_vec<VehiclePropConfig> configs; |
| 76 | |
| 77 | configs.setToExternal(const_cast<VehiclePropConfig*>(kVehicleProperties), |
| 78 | arraysize(kVehicleProperties)); |
| 79 | |
| 80 | _hidl_cb(configs); |
| 81 | return Void(); |
| 82 | } |
| 83 | |
| 84 | Return<void> Vehicle::getPropConfigs(const hidl_vec<VehicleProperty>& properties, |
| 85 | getAllPropConfigs_cb _hidl_cb) { |
| 86 | // TODO(pavelm): add default implementation |
| 87 | hidl_vec<VehiclePropConfig> configs; |
| 88 | _hidl_cb(configs); |
| 89 | return Void(); |
| 90 | } |
| 91 | |
| 92 | Return<void> Vehicle::get(VehicleProperty propId, int32_t areaId, get_cb _hidl_cb) { |
| 93 | VehiclePropValue v { |
| 94 | .prop = propId, |
| 95 | .areaId = areaId, |
| 96 | .timestamp = elapsedRealtimeNano(), |
| 97 | }; |
| 98 | |
| 99 | StatusCode status = StatusCode::OK; |
| 100 | |
| 101 | if (propId == VehicleProperty::INFO_MAKE) { |
| 102 | v.value.stringValue.setToExternal(kInfoMake, strlen(kInfoMake)); |
| 103 | } else if (propId == VehicleProperty::HVAC_FAN_SPEED) { |
| 104 | v.value.int32Values = init_hidl_vec({42}); |
| 105 | } else { |
| 106 | status = StatusCode::INVALID_ARG; |
| 107 | } |
| 108 | |
| 109 | _hidl_cb(status, v); |
| 110 | |
| 111 | return Void(); |
| 112 | } |
| 113 | |
| 114 | Return<StatusCode> Vehicle::set(const VehiclePropValue& value) { |
| 115 | // TODO(pavelm): add default implementation |
| 116 | return StatusCode::OK; |
| 117 | } |
| 118 | |
| 119 | Return<StatusCode> Vehicle::subscribe(const sp<IVehicleCallback>& listener, |
| 120 | const hidl_vec<SubscribeOptions>& options) { |
| 121 | // TODO(pavelm): add default implementation |
| 122 | return StatusCode::OK; |
| 123 | } |
| 124 | |
| 125 | Return<StatusCode> Vehicle::unsubscribe(VehicleProperty propId) { |
| 126 | // TODO(pavelm): add default implementation |
| 127 | return StatusCode::OK; |
| 128 | } |
| 129 | |
| 130 | Return<void> Vehicle::debugDump(debugDump_cb _hidl_cb) { |
| 131 | hidl_string debug; |
| 132 | debug = "Put debug data here"; |
| 133 | |
| 134 | _hidl_cb(debug); |
| 135 | |
| 136 | return Void(); |
| 137 | } |
| 138 | |
| 139 | IVehicle* HIDL_FETCH_IVehicle(const char* /* name */) { |
| 140 | return new Vehicle(); |
| 141 | } |
| 142 | |
| 143 | } // namespace implementation |
| 144 | } // namespace V2_0 |
| 145 | } // namespace vehicle |
| 146 | } // namespace hardware |
| 147 | } // namespace android |