目录
1. ard11 vhal 设置属性的时序图 CarService > vhal > CarService
2. EmulatedVehicleHal::set(xxx) 的实现
本文介绍ard11的vhal属性设置流程图。
1. ard11 vhal 设置属性的时序图 CarService > vhal > CarService
2. EmulatedVehicleHal::set(xxx) 的实现
从client端来的set调用最后会调用到EmulatedVehicleHal中。再由它转到其他地方(车身、ECU),和传回CarService。
android11/hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/EmulatedVehicleHal.cpp
163 StatusCode EmulatedVehicleHal::set(const VehiclePropValue& propValue) {
164 constexpr bool updateStatus = false;
165
166 if (propValue.prop == kGenerateFakeDataControllingProperty) {
167 // Send the generator controlling request to the server.
168 // 'updateStatus' flag is only for the value sent by setProperty (propValue in this case)
169 // instead of the generated values triggered by it. 'propValue' works as a control signal
170 // here, since we never send the control signal back, the value of 'updateStatus' flag
171 // does not matter here.
172 auto status = mVehicleClient->setProperty(propValue, updateStatus);
173 return status;
174 } else if (mHvacPowerProps.count(propValue.prop)) {
175 auto hvacPowerOn = mPropStore->readValueOrNull(
176 toInt(VehicleProperty::HVAC_POWER_ON),
177 (VehicleAreaSeat::ROW_1_LEFT | VehicleAreaSeat::ROW_1_RIGHT |
178 VehicleAreaSeat::ROW_2_LEFT | VehicleAreaSeat::ROW_2_CENTER |
179 VehicleAreaSeat::ROW_2_RIGHT));
180
181 if (hvacPowerOn && hvacPowerOn->value.int32Values.size() == 1
182 && hvacPowerOn->value.int32Values[0] == 0) {
183 return StatusCode::NOT_AVAILABLE;
184 }
185 } else {
186 // Handle property specific code
187 switch (propValue.prop) {
188 case OBD2_FREEZE_FRAME_CLEAR:
189 return clearObd2FreezeFrames(propValue);
190 case VEHICLE_MAP_SERVICE:
191 // Placeholder for future implementation of VMS property in the default hal. For
192 // now, just returns OK; otherwise, hal clients crash with property not supported.
193 return StatusCode::OK;
194 }
195 }
196
197 if (propValue.status != VehiclePropertyStatus::AVAILABLE) {
198 // Android side cannot set property status - this value is the
199 // purview of the HAL implementation to reflect the state of
200 // its underlying hardware
201 return StatusCode::INVALID_ARG;
202 }
203 auto currentPropValue = mPropStore->readValueOrNull(propValue);
204
205 if (currentPropValue == nullptr) {
206 return StatusCode::INVALID_ARG;
207 }
208 if (currentPropValue->status != VehiclePropertyStatus::AVAILABLE) {
209 // do not allow Android side to set() a disabled/error property
210 return StatusCode::NOT_AVAILABLE;
211 }
212
213 /**
214 * After checking all conditions, such as the property is available, a real vhal will
215 * sent the events to Car ECU to take actions.
216 */
217
218 // Send the value to the vehicle server, the server will talk to the (real or emulated) car
219 auto setValueStatus = mVehicleClient->setProperty(propValue, updateStatus);//关键代码
220 if (setValueStatus != StatusCode::OK) {
221 return setValueStatus;
222 }
223
224 return StatusCode::OK;
225 }