1 /* 2 * Copyright (C) 2015 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 package android.car.hardware; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * A CarSensorEvent object corresponds to a single sensor event coming from the car. The sensor 24 * data is stored in a sensor-type specific format in the object's float and byte arrays. 25 * 26 * To aid unmarshalling the object's data arrays, this class provides static nested classes and 27 * conversion methods, for example {@link EnvironmentData} and {@link #getEnvironmentData}. The 28 * conversion methods each have an optional data parameter which, if not null, will be used and 29 * returned. This parameter should be used to avoid unnecessary object churn whenever possible. 30 * Additionally, calling a conversion method on a CarSensorEvent object with an inappropriate type 31 * will result in an {@code UnsupportedOperationException} being thrown. 32 * 33 * @deprecated consider using {@link android.car.hardware.property.CarPropertyEvent} instead. 34 */ 35 @Deprecated 36 public class CarSensorEvent implements Parcelable { 37 38 /** 39 * GEAR_* represents meaning of intValues[0] for {@link CarSensorManager#SENSOR_TYPE_GEAR} 40 * sensor type. 41 * GEAR_NEUTRAL means transmission gear is in neutral state, and the car may be moving. 42 */ 43 public static final int GEAR_NEUTRAL = 0x0001; 44 /** 45 * intValues[0] from 1 to 99 represents transmission gear number for moving forward. 46 * GEAR_FIRST is for gear number 1. 47 */ 48 public static final int GEAR_FIRST = 0x0010; 49 /** Gear number 2. */ 50 public static final int GEAR_SECOND = 0x0020; 51 /** Gear number 3. */ 52 public static final int GEAR_THIRD = 0x0040; 53 /** Gear number 4. */ 54 public static final int GEAR_FOURTH = 0x0080; 55 /** Gear number 5. */ 56 public static final int GEAR_FIFTH = 0x0100; 57 /** Gear number 6. */ 58 public static final int GEAR_SIXTH = 0x0200; 59 /** Gear number 7. */ 60 public static final int GEAR_SEVENTH = 0x0400; 61 /** Gear number 8. */ 62 public static final int GEAR_EIGHTH = 0x0800; 63 /** Gear number 9. */ 64 public static final int GEAR_NINTH = 0x1000; 65 /** Gear number 10. */ 66 public static final int GEAR_TENTH = 0x2000; 67 /** 68 * This is for transmission without specific gear number for moving forward like CVT. It tells 69 * that car is in a transmission state to move it forward. 70 */ 71 public static final int GEAR_DRIVE = 0x0008; 72 /** Gear in parking state */ 73 public static final int GEAR_PARK = 0x0004; 74 /** Gear in reverse */ 75 public static final int GEAR_REVERSE = 0x0002; 76 77 /** 78 * Ignition state is unknown. 79 * 80 * The constants that starts with IGNITION_STATE_ represent values for 81 * {@link CarSensorManager#SENSOR_TYPE_IGNITION_STATE} sensor. 82 * */ 83 public static final int IGNITION_STATE_UNDEFINED = 0; 84 /** 85 * Steering wheel is locked. 86 */ 87 public static final int IGNITION_STATE_LOCK = 1; 88 /** Typically engine is off, but steering wheel is unlocked. */ 89 public static final int IGNITION_STATE_OFF = 2; 90 /** Accessory is turned off, but engine is not running yet (for EV car is not ready to move). */ 91 public static final int IGNITION_STATE_ACC = 3; 92 /** In this state engine typically is running (for EV, car is ready to move). */ 93 public static final int IGNITION_STATE_ON = 4; 94 /** In this state engine is typically starting (cranking). */ 95 public static final int IGNITION_STATE_START = 5; 96 97 /** 98 * Index for {@link CarSensorManager#SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE} in floatValues. 99 * Temperature in Celsius degrees. 100 */ 101 public static final int INDEX_ENVIRONMENT_TEMPERATURE = 0; 102 103 /** 104 * Index for {@link CarSensorManager#SENSOR_TYPE_WHEEL_TICK_DISTANCE} in longValues. RESET_COUNT 105 * is incremented whenever the HAL detects that a sensor reset has occurred. It represents to 106 * the upper layer that the WHEEL_DISTANCE values will not be contiguous with other values 107 * reported with a different RESET_COUNT. 108 */ 109 public static final int INDEX_WHEEL_DISTANCE_RESET_COUNT = 0; 110 public static final int INDEX_WHEEL_DISTANCE_FRONT_LEFT = 1; 111 public static final int INDEX_WHEEL_DISTANCE_FRONT_RIGHT = 2; 112 public static final int INDEX_WHEEL_DISTANCE_REAR_RIGHT = 3; 113 public static final int INDEX_WHEEL_DISTANCE_REAR_LEFT = 4; 114 115 private static final long MILLI_IN_NANOS = 1000000L; 116 117 /** Sensor type for this event like {@link CarSensorManager#SENSOR_TYPE_CAR_SPEED}. */ 118 public int sensorType; 119 120 /** 121 * When this data was received from car. It is elapsed real-time of data reception from car in 122 * nanoseconds since system boot. 123 */ 124 public long timestamp; 125 /** 126 * array holding float type of sensor data. If the sensor has single value, only floatValues[0] 127 * should be used. */ 128 public final float[] floatValues; 129 /** array holding int type of sensor data */ 130 public final int[] intValues; 131 /** array holding long int type of sensor data */ 132 public final long[] longValues; 133 134 /** @hide */ CarSensorEvent(Parcel in)135 public CarSensorEvent(Parcel in) { 136 sensorType = in.readInt(); 137 timestamp = in.readLong(); 138 int len = in.readInt(); 139 floatValues = new float[len]; 140 in.readFloatArray(floatValues); 141 len = in.readInt(); 142 intValues = new int[len]; 143 in.readIntArray(intValues); 144 // version 1 up to here 145 len = in.readInt(); 146 longValues = new long[len]; 147 in.readLongArray(longValues); 148 } 149 150 @Override describeContents()151 public int describeContents() { 152 return 0; 153 } 154 155 @Override writeToParcel(Parcel dest, int flags)156 public void writeToParcel(Parcel dest, int flags) { 157 dest.writeInt(sensorType); 158 dest.writeLong(timestamp); 159 dest.writeInt(floatValues.length); 160 dest.writeFloatArray(floatValues); 161 dest.writeInt(intValues.length); 162 dest.writeIntArray(intValues); 163 dest.writeInt(longValues.length); 164 dest.writeLongArray(longValues); 165 } 166 167 public static final Parcelable.Creator<CarSensorEvent> CREATOR 168 = new Parcelable.Creator<CarSensorEvent>() { 169 public CarSensorEvent createFromParcel(Parcel in) { 170 return new CarSensorEvent(in); 171 } 172 173 public CarSensorEvent[] newArray(int size) { 174 return new CarSensorEvent[size]; 175 } 176 }; 177 178 /** @hide */ CarSensorEvent(int sensorType, long timestamp, int floatValueSize, int intValueSize, int longValueSize)179 public CarSensorEvent(int sensorType, long timestamp, int floatValueSize, int intValueSize, 180 int longValueSize) { 181 this.sensorType = sensorType; 182 this.timestamp = timestamp; 183 floatValues = new float[floatValueSize]; 184 intValues = new int[intValueSize]; 185 longValues = new long[longValueSize]; 186 } 187 188 /** @hide */ CarSensorEvent(int sensorType, long timestamp, float[] floatValues, int[] intValues, long[] longValues)189 CarSensorEvent(int sensorType, long timestamp, float[] floatValues, int[] intValues, 190 long[] longValues) { 191 this.sensorType = sensorType; 192 this.timestamp = timestamp; 193 this.floatValues = floatValues; 194 this.intValues = intValues; 195 this.longValues = longValues; 196 } 197 checkType(int type)198 private void checkType(int type) { 199 if (sensorType == type) { 200 return; 201 } 202 throw new UnsupportedOperationException(String.format( 203 "Invalid sensor type: expected %d, got %d", type, sensorType)); 204 } 205 206 public static class EnvironmentData { 207 public long timestamp; 208 /** If unsupported by the car, this value is NaN. */ 209 public float temperature; 210 211 /** @hide */ EnvironmentData()212 private EnvironmentData() {}; 213 } 214 215 /** 216 * Convenience method for obtaining an {@link EnvironmentData} object from a CarSensorEvent 217 * object with type {@link CarSensorManager#SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE}. 218 * 219 * @param data an optional output parameter which, if non-null, will be used by this method 220 * instead of a newly created object. 221 * @return an EnvironmentData object corresponding to the data contained in the CarSensorEvent. 222 * @hide 223 */ getEnvironmentData(EnvironmentData data)224 public EnvironmentData getEnvironmentData(EnvironmentData data) { 225 checkType(CarSensorManager.SENSOR_TYPE_ENV_OUTSIDE_TEMPERATURE); 226 if (data == null) { 227 data = new EnvironmentData(); 228 } 229 data.timestamp = timestamp; 230 data.temperature = floatValues[INDEX_ENVIRONMENT_TEMPERATURE]; 231 return data; 232 } 233 234 /** @hide*/ 235 public static class IgnitionStateData { 236 public long timestamp; 237 public int ignitionState; 238 239 /** @hide */ IgnitionStateData()240 private IgnitionStateData() {}; 241 } 242 243 /** 244 * Convenience method for obtaining a {@link IgnitionStateData} object from a CarSensorEvent 245 * object with type {@link CarSensorManager#SENSOR_TYPE_IGNITION_STATE}. 246 * 247 * @param data an optional output parameter which, if non-null, will be used by this method 248 * instead of a newly created object. 249 * @return a IgnitionStateData object corresponding to the data contained in the CarSensorEvent. 250 * @hide 251 */ getIgnitionStateData(IgnitionStateData data)252 public IgnitionStateData getIgnitionStateData(IgnitionStateData data) { 253 checkType(CarSensorManager.SENSOR_TYPE_IGNITION_STATE); 254 if (data == null) { 255 data = new IgnitionStateData(); 256 } 257 data.timestamp = timestamp; 258 data.ignitionState = intValues[0]; 259 return data; 260 } 261 262 /** @hide */ 263 public static class NightData { 264 public long timestamp; 265 public boolean isNightMode; 266 267 /** @hide */ NightData()268 private NightData() {}; 269 } 270 271 /** 272 * Convenience method for obtaining a {@link NightData} object from a CarSensorEvent 273 * object with type {@link CarSensorManager#SENSOR_TYPE_NIGHT}. 274 * 275 * @param data an optional output parameter which, if non-null, will be used by this method 276 * instead of a newly created object. 277 * @return a NightData object corresponding to the data contained in the CarSensorEvent. 278 * @hide 279 */ getNightData(NightData data)280 public NightData getNightData(NightData data) { 281 checkType(CarSensorManager.SENSOR_TYPE_NIGHT); 282 if (data == null) { 283 data = new NightData(); 284 } 285 data.timestamp = timestamp; 286 data.isNightMode = intValues[0] == 1; 287 return data; 288 } 289 290 /** @hide */ 291 public static class GearData { 292 public long timestamp; 293 public int gear; 294 295 /** @hide */ GearData()296 private GearData() {}; 297 } 298 299 /** 300 * Convenience method for obtaining a {@link GearData} object from a CarSensorEvent 301 * object with type {@link CarSensorManager#SENSOR_TYPE_GEAR}. 302 * 303 * @param data an optional output parameter which, if non-null, will be used by this method 304 * instead of a newly created object. 305 * @return a GearData object corresponding to the data contained in the CarSensorEvent. 306 * @hide 307 */ getGearData(GearData data)308 public GearData getGearData(GearData data) { 309 checkType(CarSensorManager.SENSOR_TYPE_GEAR); 310 if (data == null) { 311 data = new GearData(); 312 } 313 data.timestamp = timestamp; 314 data.gear = intValues[0]; 315 return data; 316 } 317 318 /** @hide */ 319 public static class ParkingBrakeData { 320 public long timestamp; 321 public boolean isEngaged; 322 323 /** @hide */ ParkingBrakeData()324 private ParkingBrakeData() {} 325 } 326 327 /** 328 * Convenience method for obtaining a {@link ParkingBrakeData} object from a CarSensorEvent 329 * object with type {@link CarSensorManager#SENSOR_TYPE_PARKING_BRAKE}. 330 * 331 * @param data an optional output parameter which, if non-null, will be used by this method 332 * instead of a newly created object. 333 * @return a ParkingBreakData object corresponding to the data contained in the CarSensorEvent. 334 * @hide 335 */ getParkingBrakeData(ParkingBrakeData data)336 public ParkingBrakeData getParkingBrakeData(ParkingBrakeData data) { 337 checkType(CarSensorManager.SENSOR_TYPE_PARKING_BRAKE); 338 if (data == null) { 339 data = new ParkingBrakeData(); 340 } 341 data.timestamp = timestamp; 342 data.isEngaged = intValues[0] == 1; 343 return data; 344 } 345 346 /** @hide */ 347 public static class FuelLevelData { 348 public long timestamp; 349 /** Fuel level in milliliters. Negative values indicate this property is unsupported. */ 350 public float level; 351 352 /** @hide */ FuelLevelData()353 private FuelLevelData() {}; 354 } 355 356 /** 357 * Convenience method for obtaining a {@link FuelLevelData} object from a CarSensorEvent 358 * object with type {@link CarSensorManager#SENSOR_TYPE_FUEL_LEVEL}. 359 * 360 * @param data an optional output parameter which, if non-null, will be used by this method 361 * instead of a newly created object. 362 * @return a FuelLevel object corresponding to the data contained in the CarSensorEvent. 363 * @hide 364 */ getFuelLevelData(FuelLevelData data)365 public FuelLevelData getFuelLevelData(FuelLevelData data) { 366 checkType(CarSensorManager.SENSOR_TYPE_FUEL_LEVEL); 367 if (data == null) { 368 data = new FuelLevelData(); 369 } 370 data.timestamp = timestamp; 371 if (floatValues == null) { 372 data.level = -1.0f; 373 } else { 374 if (floatValues[0] < 0) { 375 data.level = -1.0f; 376 } else { 377 data.level = floatValues[0]; 378 } 379 } 380 return data; 381 } 382 383 /** @hide */ 384 public static class OdometerData { 385 public long timestamp; 386 public float kms; 387 388 /** @hide */ OdometerData()389 private OdometerData() {}; 390 } 391 392 /** 393 * Convenience method for obtaining an {@link OdometerData} object from a CarSensorEvent 394 * object with type {@link CarSensorManager#SENSOR_TYPE_ODOMETER}. 395 * 396 * @param data an optional output parameter which, if non-null, will be used by this method 397 * instead of a newly created object. 398 * @return an OdometerData object corresponding to the data contained in the CarSensorEvent. 399 * @hide 400 */ getOdometerData(OdometerData data)401 public OdometerData getOdometerData(OdometerData data) { 402 checkType(CarSensorManager.SENSOR_TYPE_ODOMETER); 403 if (data == null) { 404 data = new OdometerData(); 405 } 406 data.timestamp = timestamp; 407 data.kms = floatValues[0]; 408 return data; 409 } 410 411 /** @hide */ 412 public static class RpmData { 413 public long timestamp; 414 public float rpm; 415 416 /** @hide */ RpmData()417 private RpmData() {}; 418 } 419 420 /** 421 * Convenience method for obtaining a {@link RpmData} object from a CarSensorEvent 422 * object with type {@link CarSensorManager#SENSOR_TYPE_RPM}. 423 * 424 * @param data an optional output parameter which, if non-null, will be used by this method 425 * instead of a newly created object. 426 * @return a RpmData object corresponding to the data contained in the CarSensorEvent. 427 * @hide 428 */ getRpmData(RpmData data)429 public RpmData getRpmData(RpmData data) { 430 checkType(CarSensorManager.SENSOR_TYPE_RPM); 431 if (data == null) { 432 data = new RpmData(); 433 } 434 data.timestamp = timestamp; 435 data.rpm = floatValues[0]; 436 return data; 437 } 438 439 /** @hide */ 440 public static class CarSpeedData { 441 public long timestamp; 442 public float carSpeed; 443 444 /** @hide */ CarSpeedData()445 private CarSpeedData() {}; 446 } 447 448 /** 449 * Convenience method for obtaining a {@link CarSpeedData} object from a CarSensorEvent 450 * object with type {@link CarSensorManager#SENSOR_TYPE_CAR_SPEED}. 451 * 452 * @param data an optional output parameter which, if non-null, will be used by this method 453 * instead of a newly created object. 454 * @return a CarSpeedData object corresponding to the data contained in the CarSensorEvent. 455 * @hide 456 */ getCarSpeedData(CarSpeedData data)457 public CarSpeedData getCarSpeedData(CarSpeedData data) { 458 checkType(CarSensorManager.SENSOR_TYPE_CAR_SPEED); 459 if (data == null) { 460 data = new CarSpeedData(); 461 } 462 data.timestamp = timestamp; 463 data.carSpeed = floatValues[0]; 464 return data; 465 } 466 467 /** @hide */ 468 public static class CarWheelTickDistanceData { 469 public long timestamp; 470 public long sensorResetCount; 471 public long frontLeftWheelDistanceMm; 472 public long frontRightWheelDistanceMm; 473 public long rearRightWheelDistanceMm; 474 public long rearLeftWheelDistanceMm; 475 476 /** @hide */ CarWheelTickDistanceData()477 private CarWheelTickDistanceData() {}; 478 } 479 480 /** 481 * Convenience method for obtaining a {@link CarWheelTickDistanceData} object from a 482 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_WHEEL_TICK_DISTANCE}. 483 * 484 * @param data an optional output parameter which, if non-null, will be used by this method 485 * instead of a newly created object. 486 * @return CarWheelTickDistanceData object corresponding to data contained in the CarSensorEvent 487 * @hide 488 */ getCarWheelTickDistanceData(CarWheelTickDistanceData data)489 public CarWheelTickDistanceData getCarWheelTickDistanceData(CarWheelTickDistanceData data) { 490 checkType(CarSensorManager.SENSOR_TYPE_WHEEL_TICK_DISTANCE); 491 if (data == null) { 492 data = new CarWheelTickDistanceData(); 493 } 494 data.timestamp = timestamp; 495 data.sensorResetCount = longValues[INDEX_WHEEL_DISTANCE_RESET_COUNT]; 496 data.frontLeftWheelDistanceMm = longValues[INDEX_WHEEL_DISTANCE_FRONT_LEFT]; 497 data.frontRightWheelDistanceMm = longValues[INDEX_WHEEL_DISTANCE_FRONT_RIGHT]; 498 data.rearRightWheelDistanceMm = longValues[INDEX_WHEEL_DISTANCE_REAR_RIGHT]; 499 data.rearLeftWheelDistanceMm = longValues[INDEX_WHEEL_DISTANCE_REAR_LEFT]; 500 return data; 501 } 502 503 /** @hide */ 504 public static class CarAbsActiveData { 505 public long timestamp; 506 public boolean absIsActive; 507 508 /** @hide */ CarAbsActiveData()509 private CarAbsActiveData() {}; 510 } 511 512 /** 513 * Convenience method for obtaining a {@link CarAbsActiveData} object from a CarSensorEvent 514 * object with type {@link CarSensorManager#SENSOR_TYPE_ABS_ACTIVE}. 515 * 516 * @param data an optional output parameter which, if non-null, will be used by this method 517 * instead of a newly created object. 518 * @return a CarAbsActiveData object corresponding to data contained in the CarSensorEvent. 519 * @hide 520 */ getCarAbsActiveData(CarAbsActiveData data)521 public CarAbsActiveData getCarAbsActiveData(CarAbsActiveData data) { 522 checkType(CarSensorManager.SENSOR_TYPE_ABS_ACTIVE); 523 if (data == null) { 524 data = new CarAbsActiveData(); 525 } 526 data.timestamp = timestamp; 527 data.absIsActive = intValues[0] == 1; 528 return data; 529 } 530 531 /** @hide */ 532 public static class CarTractionControlActiveData { 533 public long timestamp; 534 public boolean tractionControlIsActive; 535 536 /** @hide */ CarTractionControlActiveData()537 private CarTractionControlActiveData() {}; 538 } 539 540 /** 541 * Convenience method for obtaining a {@link CarTractionControlActiveData} object from a 542 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_TRACTION_CONTROL_ACTIVE}. 543 * 544 * @param data an optional output parameter which, if non-null, will be used by this method 545 * instead of a newly created object. 546 * @return a CarTractionControlActiveData object corresponding to data contained in the 547 * CarSensorEvent. 548 * @hide 549 */ getCarTractionControlActiveData( CarTractionControlActiveData data)550 public CarTractionControlActiveData getCarTractionControlActiveData( 551 CarTractionControlActiveData data) { 552 checkType(CarSensorManager.SENSOR_TYPE_TRACTION_CONTROL_ACTIVE); 553 if (data == null) { 554 data = new CarTractionControlActiveData(); 555 } 556 data.timestamp = timestamp; 557 data.tractionControlIsActive = intValues[0] == 1; 558 return data; 559 } 560 561 /** @hide */ 562 public static class CarFuelDoorOpenData { 563 public long timestamp; 564 public boolean fuelDoorIsOpen; 565 566 /** @hide */ CarFuelDoorOpenData()567 private CarFuelDoorOpenData() {}; 568 } 569 570 /** 571 * Convenience method for obtaining a {@link CarFuelDoorOpenData} object from a 572 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_FUEL_DOOR_OPEN}. 573 * 574 * @param data an optional output parameter which, if non-null, will be used by this method 575 * instead of a newly created object. 576 * @return a CarFuelDoorOpenData object corresponding to data contained in the 577 * CarSensorEvent. 578 * @hide 579 */ getCarFuelDoorOpenData( CarFuelDoorOpenData data)580 public CarFuelDoorOpenData getCarFuelDoorOpenData( 581 CarFuelDoorOpenData data) { 582 checkType(CarSensorManager.SENSOR_TYPE_FUEL_DOOR_OPEN); 583 if (data == null) { 584 data = new CarFuelDoorOpenData(); 585 } 586 data.timestamp = timestamp; 587 data.fuelDoorIsOpen = intValues[0] == 1; 588 return data; 589 } 590 591 /** @hide */ 592 public static class CarEvBatteryLevelData { 593 public long timestamp; 594 /** Battery Level in Watt-hours */ 595 public float evBatteryLevel; 596 597 /** @hide */ CarEvBatteryLevelData()598 private CarEvBatteryLevelData() {}; 599 } 600 601 /** 602 * Convenience method for obtaining a {@link CarEvBatteryLevelData} object from a 603 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_EV_BATTERY_LEVEL}. 604 * 605 * @param data an optional output parameter which, if non-null, will be used by this method 606 * instead of a newly created object. 607 * @return a CarEvBatteryLevelData object corresponding to data contained in the 608 * CarSensorEvent. 609 * @hide 610 */ getCarEvBatteryLevelData( CarEvBatteryLevelData data)611 public CarEvBatteryLevelData getCarEvBatteryLevelData( 612 CarEvBatteryLevelData data) { 613 checkType(CarSensorManager.SENSOR_TYPE_EV_BATTERY_LEVEL); 614 if (data == null) { 615 data = new CarEvBatteryLevelData(); 616 } 617 data.timestamp = timestamp; 618 if (floatValues == null) { 619 data.evBatteryLevel = -1.0f; 620 } else { 621 if (floatValues[0] < 0) { 622 data.evBatteryLevel = -1.0f; 623 } else { 624 data.evBatteryLevel = floatValues[0]; 625 } 626 } 627 return data; 628 } 629 630 /** @hide */ 631 public static class CarEvChargePortOpenData { 632 public long timestamp; 633 public boolean evChargePortIsOpen; 634 635 /** @hide */ CarEvChargePortOpenData()636 private CarEvChargePortOpenData() {}; 637 } 638 639 /** 640 * Convenience method for obtaining a {@link CarEvChargePortOpenData} object from a 641 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_EV_CHARGE_PORT_OPEN}. 642 * 643 * @param data an optional output parameter which, if non-null, will be used by this method 644 * instead of a newly created object. 645 * @return a CarEvChargePortOpenData object corresponding to data contained in the 646 * CarSensorEvent. 647 * @hide 648 */ getCarEvChargePortOpenData( CarEvChargePortOpenData data)649 public CarEvChargePortOpenData getCarEvChargePortOpenData( 650 CarEvChargePortOpenData data) { 651 checkType(CarSensorManager.SENSOR_TYPE_EV_CHARGE_PORT_OPEN); 652 if (data == null) { 653 data = new CarEvChargePortOpenData(); 654 } 655 data.timestamp = timestamp; 656 data.evChargePortIsOpen = intValues[0] == 1; 657 return data; 658 } 659 660 /** @hide */ 661 public static class CarEvChargePortConnectedData { 662 public long timestamp; 663 public boolean evChargePortIsConnected; 664 665 /** @hide */ CarEvChargePortConnectedData()666 private CarEvChargePortConnectedData() {}; 667 } 668 669 /** 670 * Convenience method for obtaining a {@link CarEvChargePortConnectedData} object from a 671 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_EV_CHARGE_PORT_CONNECTED}. 672 * 673 * @param data an optional output parameter which, if non-null, will be used by this method 674 * instead of a newly created object. 675 * @return a CarEvChargePortConnectedData object corresponding to data contained in the 676 * CarSensorEvent. 677 * @hide 678 */ getCarEvChargePortConnectedData( CarEvChargePortConnectedData data)679 public CarEvChargePortConnectedData getCarEvChargePortConnectedData( 680 CarEvChargePortConnectedData data) { 681 checkType(CarSensorManager.SENSOR_TYPE_EV_CHARGE_PORT_CONNECTED); 682 if (data == null) { 683 data = new CarEvChargePortConnectedData(); 684 } 685 data.timestamp = timestamp; 686 data.evChargePortIsConnected = intValues[0] == 1; 687 return data; 688 } 689 690 /** @hide */ 691 public static class CarEvBatteryChargeRateData { 692 public long timestamp; 693 /** EV battery charging rate in mW. 694 * Positive values indicates battery being charged. Negative values indicate discharge */ 695 public float evChargeRate; 696 697 /** @hide */ CarEvBatteryChargeRateData()698 private CarEvBatteryChargeRateData() {}; 699 } 700 701 /** 702 * Convenience method for obtaining a {@link CarEvBatteryChargeRateData} object from a 703 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_EV_BATTERY_CHARGE_RATE}. 704 * 705 * @param data an optional output parameter which, if non-null, will be used by this method 706 * instead of a newly created object. 707 * @return a CarEvBatteryChargeRateData object corresponding to data contained in the 708 * CarSensorEvent. 709 * @hide 710 */ getCarEvBatteryChargeRateData( CarEvBatteryChargeRateData data)711 public CarEvBatteryChargeRateData getCarEvBatteryChargeRateData( 712 CarEvBatteryChargeRateData data) { 713 checkType(CarSensorManager.SENSOR_TYPE_EV_BATTERY_CHARGE_RATE); 714 if (data == null) { 715 data = new CarEvBatteryChargeRateData(); 716 } 717 data.timestamp = timestamp; 718 data.evChargeRate = floatValues[0]; 719 return data; 720 } 721 722 /** @hide */ 723 public static class CarEngineOilLevelData { 724 public long timestamp; 725 public int engineOilLevel; 726 727 /** @hide */ CarEngineOilLevelData()728 private CarEngineOilLevelData() {}; 729 } 730 731 /** 732 * Convenience method for obtaining a {@link CarEngineOilLevelData} object from a 733 * CarSensorEvent object with type {@link CarSensorManager#SENSOR_TYPE_ENGINE_OIL_LEVEL}. 734 * 735 * @param data an optional output parameter, which, if non-null, will be used by this method 736 * instead of a newly created object. 737 * @return a CarEngineOilLEvelData object corresponding to data contained in the CarSensorEvent. 738 * @hide 739 */ getCarEngineOilLevelData(CarEngineOilLevelData data)740 public CarEngineOilLevelData getCarEngineOilLevelData(CarEngineOilLevelData data) { 741 checkType(CarSensorManager.SENSOR_TYPE_ENGINE_OIL_LEVEL); 742 if (data == null) { 743 data = new CarEngineOilLevelData(); 744 } 745 data.timestamp = timestamp; 746 data.engineOilLevel = intValues[0]; 747 return data; 748 } 749 750 /** @hide */ 751 @Override toString()752 public String toString() { 753 StringBuilder sb = new StringBuilder(); 754 sb.append(getClass().getName() + "["); 755 sb.append("type:" + Integer.toHexString(sensorType)); 756 if (floatValues != null && floatValues.length > 0) { 757 sb.append(" float values:"); 758 for (float v: floatValues) { 759 sb.append(" " + v); 760 } 761 } 762 if (intValues != null && intValues.length > 0) { 763 sb.append(" int values:"); 764 for (int v: intValues) { 765 sb.append(" " + v); 766 } 767 } 768 if (longValues != null && longValues.length > 0) { 769 sb.append(" long values:"); 770 for (long v: longValues) { 771 sb.append(" " + v); 772 } 773 } 774 sb.append("]"); 775 return sb.toString(); 776 } 777 } 778