OSDN Git Service

vehicle hal update
authorKeun-young Park <keunyoung@google.com>
Fri, 11 Mar 2016 00:28:42 +0000 (16:28 -0800)
committerKeun-young Park <keunyoung@google.com>
Tue, 15 Mar 2016 00:00:36 +0000 (17:00 -0700)
- add release_memory_from_get to allow hal to release
  memory it has allocated in get call
- clear get call's behavior: If data is not available, should
  return immediately with VEHICLE_ERROR_NOT_READY error
- make zone separate in vehicle_prop_config_t and
  vehicle_prop_value_t: Handing of zoned property becomes
  simpler
- cleanup some data type definitions for zoned properties

bug: 2759733827596281
Change-Id: I7a8454b86555270fb2211e5d36b3ee06d350f8ed

include/hardware/vehicle.h
modules/vehicle/vehicle.c
tests/vehicle/vehicle-hal-tool.c

index 4a080a1..9086d1c 100644 (file)
@@ -1030,9 +1030,11 @@ enum vehicle_value_type {
     VEHICLE_VALUE_TYPE_ZONED_FLOAT              = 0x30,
     VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC2         = 0x31,
     VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC3         = 0x32,
+    VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC4         = 0x33,
     VEHICLE_VALUE_TYPE_ZONED_INT32              = 0x40,
     VEHICLE_VALUE_TYPE_ZONED_INT32_VEC2         = 0x41,
     VEHICLE_VALUE_TYPE_ZONED_INT32_VEC3         = 0x42,
+    VEHICLE_VALUE_TYPE_ZONED_INT32_VEC4         = 0x43,
 };
 
 /**
@@ -1061,30 +1063,6 @@ enum vehicle_unit_type {
 };
 
 /**
- * Error code used in HAL implemnentation. Follows utils/Errors.h
- */
-enum vehicle_error_code {
-    VEHICLE_NO_ERROR    = 0x0,
-    VEHICLE_ERROR_UNKNOWN       = (-2147483647 - 1), // INT32_MIN value
-    VEHICLE_ERROR_NO_MEMORY           = -12, //ENOMEM
-    VEHICLE_ERROR_INVALID_OPERATION   = -38, //ENOSYS
-    VEHICLE_ERROR_BAD_VALUE           = -22, //EINVAL
-    VEHICLE_ERROR_BAD_TYPE            = (VEHICLE_ERROR_UNKNOWN + 1),
-    VEHICLE_ERROR_NAME_NOT_FOUND      = -2, //ENOENT
-    VEHICLE_ERROR_PERMISSION_DENIED   = -1, //EPERM
-    VEHICLE_ERROR_NO_INIT             = -19, //ENODEV
-    VEHICLE_ERROR_ALREADY_EXISTS      = -17, //EEXIST
-    VEHICLE_ERROR_DEAD_OBJECT         = -32, //EPIPE
-    VEHICLE_ERROR_FAILED_TRANSACTION  = (VEHICLE_ERROR_UNKNOWN + 2),
-    VEHICLE_ERROR_BAD_INDEX           = -75, //EOVERFLOW
-    VEHICLE_ERROR_NOT_ENOUGH_DATA     = -61, //ENODATA
-    VEHICLE_ERROR_WOULD_BLOCK         = -11, //EWOULDBLOCK
-    VEHICLE_ERROR_TIMED_OUT           = -110, //ETIMEDOUT
-    VEHICLE_ERROR_UNKNOWN_TRANSACTION = -74, //EBADMSG
-    VEHICLE_FDS_NOT_ALLOWED     = (VEHICLE_ERROR_UNKNOWN + 7),
-};
-
-/**
  * This describes how value of property can change.
  */
 enum vehicle_prop_change_mode {
@@ -1287,52 +1265,6 @@ typedef struct vehicle_str {
  */
 typedef vehicle_str_t vehicle_bytes_t;
 
-typedef struct vehicle_zoned_int32 {
-    union {
-        int32_t zone;
-        int32_t seat;
-        int32_t window;
-    };
-    int32_t value;
-} vehicle_zoned_int32_t;
-
-typedef struct vehicle_zoned_int32_array {
-    union {
-        int32_t zone;
-        int32_t seat;
-        int32_t window;
-    };
-    int32_t values[3];
-} vehicle_zoned_int32_array_t;
-
-typedef struct vehicle_zoned_float {
-    union {
-        int32_t zone;
-        int32_t seat;
-        int32_t window;
-    };
-    float value;
-} vehicle_zoned_float_t;
-
-typedef struct vehicle_zoned_float_array {
-    union {
-        int32_t zone;
-        int32_t seat;
-        int32_t window;
-    };
-    float values[3];
-} vehicle_zoned_float_array_t;
-
-typedef struct vehicle_zoned_boolean {
-    union {
-        int32_t zone;
-        int32_t seat;
-        int32_t window;
-    };
-    vehicle_boolean_t value;
-} vehicle_zoned_boolean_t;
-
-
 typedef struct vehicle_prop_config {
     int32_t prop;
 
@@ -1358,17 +1290,13 @@ typedef struct vehicle_prop_config {
      * Define necessary permission model to access the data.
      */
     int32_t permission_model;
+
     /**
      * Some of the properties may have associated zones (such as hvac), in these
      * cases the config should contain an ORed value for the associated zone.
      */
     union {
         /**
-         * For generic configuration information
-         */
-        int32_t config_flags;
-
-        /**
          * The value is derived by ORing one or more of enum vehicle_zone members.
          */
         int32_t vehicle_zone_flags;
@@ -1376,7 +1304,16 @@ typedef struct vehicle_prop_config {
         int32_t vehicle_seat_flags;
         /** The value is derived by ORing one or more of enum vehicle_window members. */
         int32_t vehicle_window_flags;
+    };
 
+    /**
+     * Property specific configuration information. Usage of this will be defined per each property.
+     */
+    union {
+        /**
+         * For generic configuration information
+         */
+        int32_t config_flags;
         /** The number of presets that are stored by the radio module. Pass 0 if
          * there are no presets available. The range of presets is defined to be
          * from 1 (see VEHICLE_RADIO_PRESET_MIN_VALUE) to vehicle_radio_num_presets.
@@ -1419,6 +1356,8 @@ typedef struct vehicle_prop_config {
      *      array should be set to NULL.
      *   2. All zones having separate min / max value: *_min/max_values array should be populated
      *      and its length should be the same as number of active zones specified by *_zone_flags.
+     *
+     * Should be NULL if each zone does not have separate max values.
      */
     union {
         float* float_min_values;
@@ -1428,6 +1367,8 @@ typedef struct vehicle_prop_config {
 
     /**
      * Array of max values for zoned properties. See above for its usage.
+     * Should be NULL if each zone does not have separate max values.
+     * If not NULL, length of array should match that of min_values.
      */
     union {
         float* float_max_values;
@@ -1457,59 +1398,30 @@ typedef struct vehicle_prop_config {
  * below). We define these properties outside in global scope so that HAL
  * implementation and HAL users (JNI) can typecast vehicle_hvac correctly.
  */
-typedef vehicle_zoned_int32_t vehicle_hvac_fan_speed_t;
-
-typedef vehicle_zoned_int32_t vehicle_hvac_fan_direction_t;
-
-typedef vehicle_zoned_float_t vehicle_hvac_zone_temperature_t;
-
-//TODO Typical seat heat/cooling is done in fixed steps. Needs better definition.
-//typedef struct vehicle_hvac_seat_temperature {
-//    // Value should be one of enum vehicle_seat.
-//    int32_t seat;
-//    float temperature;
-//} vehicle_hvac_heated_seat_temperature_t;
-
-typedef vehicle_zoned_boolean_t vehicle_hvac_defrost_on_t;
-
-typedef vehicle_zoned_boolean_t vehicle_hvac_ac_on_t;
-
-typedef vehicle_boolean_t vehicle_hvac_max_ac_on_t;
-
-typedef vehicle_boolean_t vehicle_hvac_max_defrost_on_t;
-
-typedef vehicle_boolean_t vehicle_hvac_recirc_on_t;
-
-typedef vehicle_boolean_t vehicle_hvac_dual_on_t;
-
 typedef struct vehicle_hvac {
     /**
      * Define one structure for each possible HVAC property.
      * NOTES:
-     * a) Zone is defined in enum vehicle_zone.
-     * b) Fan speed is a number from (0 - 6) where 6 is the highest speed. (TODO define enum)
-     * c) Temperature is a floating point Celcius scale.
-     * d) Direction is defined in enum vehicle_fan_direction.
+     * a) Fan speed is a number from (0 - 6) where 6 is the highest speed. (TODO define enum)
+     * b) Temperature is a floating point Celcius scale.
+     * c) Direction is defined in enum vehicle_fan_direction.
      *
      * The HAL should create #entries number of vehicle_hvac_properties and
      * assign it to "properties" variable below.
      */
     union {
-        vehicle_hvac_fan_speed_t fan_speed;
-        vehicle_hvac_fan_direction_t fan_direction;
-        vehicle_hvac_ac_on_t ac_on;
-        vehicle_hvac_max_ac_on_t max_ac_on;
-        vehicle_hvac_max_defrost_on_t max_defrost_on;
-        vehicle_hvac_recirc_on_t recirc_on;
-        vehicle_hvac_dual_on_t dual_on;
-
-        vehicle_hvac_zone_temperature_t temperature_current;
-        vehicle_hvac_zone_temperature_t temperature_set;
-
-        //TODO Heated seat.
-        //vehicle_hvac_heated_seat_t heated_seat;
-
-        vehicle_hvac_defrost_on_t defrost_on;
+        int32_t fan_speed;
+        int32_t fan_direction;
+        vehicle_boolean_t ac_on;
+        vehicle_boolean_t max_ac_on;
+        vehicle_boolean_t max_defrost_on;
+        vehicle_boolean_t recirc_on;
+        vehicle_boolean_t dual_on;
+
+        float temperature_current;
+        float temperature_set;
+
+        vehicle_boolean_t defrost_on;
     };
 } vehicle_hvac_t;
 
@@ -1540,11 +1452,6 @@ typedef union vehicle_value {
     vehicle_str_t str_value;
     vehicle_bytes_t bytes_value;
     vehicle_boolean_t boolean_value;
-    vehicle_zoned_int32_t zoned_int32_value;
-    vehicle_zoned_int32_array_t zoned_int32_array;
-    vehicle_zoned_float_t zoned_float_value;
-    vehicle_zoned_float_array_t zoned_float_array;
-    vehicle_zoned_boolean_t zoned_boolean_value;
 
     // Vehicle Information.
     vehicle_str_t info_vin;
@@ -1615,6 +1522,15 @@ typedef struct vehicle_prop_value {
     /** time is elapsed nanoseconds since boot */
     int64_t timestamp;
 
+    /**
+     * Zone information for zoned property. For non-zoned property, this should be ignored.
+     */
+    union {
+        int32_t zone;
+        int32_t seat;
+        int32_t window;
+    };
+
     vehicle_value_t value;
 } vehicle_prop_value_t;
 
@@ -1645,11 +1561,10 @@ enum vehicle_property_operation {
 };
 
 /*
- * Suggests that an error condition has occured. error_code should be one of
- * enum vehicle_error_code.
+ * Suggests that an error condition has occurred.
  *
- * @param error_code Error code. It should be one of enum vehicle_error_code.
- *                   See error code for details.
+ * @param error_code Error code. error_code should be standard error code with
+ *                negative value like -EINVAL.
  * @parm property Note a property where error has happened. If this is generic error, property
  *                should be VEHICLE_PROPERTY_INVALID.
  * @param operation Represent the operation where the error has happened. Should be one of
@@ -1703,14 +1618,29 @@ typedef struct vehicle_hw_device {
      * Caller will set data->prop, data->value_type, and optionally zone value for zoned property.
      * But HAL implementation needs to fill all entries properly when returning.
      * For pointer type, HAL implementation should allocate necessary memory and caller is
-     * responsible for freeing memory for the pointer.
+     * responsible for calling release_memory_from_get, which allows HAL to release allocated
+     * memory.
      * For VEHICLE_PROP_CHANGE_MODE_STATIC type of property, get should return the same value
      * always.
      * For VEHICLE_PROP_CHANGE_MODE_ON_CHANGE type of property, it should return the latest value.
+     * If there is no data available yet, which can happen during initial stage, this call should
+     * return immediately with error code of -EAGAIN.
      */
     int (*get)(struct vehicle_hw_device* device, vehicle_prop_value_t *data);
 
     /**
+     * Release memory allocated to data in previous get call. get call for byte or string involves
+     * allocating necessary memory from vehicle hal.
+     * To be safe, memory allocated by vehicle hal should be released by vehicle hal and vehicle
+     * network service will call this when data from vehicle hal is no longer necessary.
+     * vehicle hal implementation should only release member of vehicle_prop_value_t like
+     * data->str_value.data or data->bytes_value.data but not data itself as data itself is
+     * allocated from vehicle network service. Once memory is freed, corresponding pointer should
+     * be set to NULL bu vehicle hal.
+     */
+    void (*release_memory_from_get)(struct vehicle_hw_device* device, vehicle_prop_value_t *data);
+
+    /**
      * Set a vehicle property value.  data should be allocated properly and not
      * NULL.
      * The caller of the API OWNS the data field.
index 564630c..d8aa2cb 100644 (file)
@@ -245,6 +245,21 @@ static int vdev_get(vehicle_hw_device_t* device UNUSED, vehicle_prop_value_t* da
     return 0;
 }
 
+static void vdev_release_memory_from_get(struct vehicle_hw_device* device UNUSED,
+        vehicle_prop_value_t *data) {
+    switch (data->value_type) {
+        case VEHICLE_VALUE_TYPE_STRING:
+        case VEHICLE_VALUE_TYPE_BYTES:
+            free(data->value.str_value.data);
+            data->value.str_value.data = NULL;
+            break;
+        default:
+            ALOGW("release_memory_from_get for property 0x%x which is not string or bytes type 0x%x"
+                    , data->prop, data->value_type);
+            break;
+    }
+}
+
 static int vdev_set(vehicle_hw_device_t* device UNUSED, const vehicle_prop_value_t* data) {
     ALOGD("vdev_set.");
     // Just print what data will be setting here.
@@ -377,7 +392,7 @@ void fake_event_thread(struct subscription *sub) {
                     return;
                 }
                 if (sub->impl->error_fn_ != NULL) {
-                    sub->impl->error_fn_(VEHICLE_ERROR_UNKNOWN, VEHICLE_PROPERTY_INVALID,
+                    sub->impl->error_fn_(-EINVAL, VEHICLE_PROPERTY_INVALID,
                             VEHICLE_OPERATION_GENERIC);
                 } else {
                     ALOGE("Error function is null");
@@ -538,6 +553,7 @@ static int vdev_open(const hw_module_t* module, const char* name UNUSED,
     vdev->vehicle_device.init = vdev_init;
     vdev->vehicle_device.release = vdev_release;
     vdev->vehicle_device.get = vdev_get;
+    vdev->vehicle_device.release_memory_from_get = vdev_release_memory_from_get;
     vdev->vehicle_device.set = vdev_set;
     vdev->vehicle_device.subscribe = vdev_subscribe;
     vdev->vehicle_device.unsubscribe = vdev_unsubscribe;
index 8cc8476..6bd7b2d 100755 (executable)
@@ -144,8 +144,8 @@ void get_property(
             printf("Value: %s\n", ascii_out);
             break;
         case VEHICLE_VALUE_TYPE_ZONED_FLOAT:
-            printf("Value type: ZONED_FLOAT\nZone: %d\n", data->value.zoned_float_value.zone);
-            printf("Value type: ZONED_FLOAT\nValue: %f\n", data->value.zoned_float_value.value);
+            printf("Value type: ZONED_FLOAT\nZone: %d\n", data->zone);
+            printf("Value type: ZONED_FLOAT\nValue: %f\n", data->value.float_value);
             break;
         case VEHICLE_VALUE_TYPE_INT32_VEC3:
             printf("Value type: INT32_VEC3\nValue[0]: %d\n", data->value.int32_array[0]);
@@ -195,10 +195,10 @@ void set_property(vehicle_hw_device_t *device,
             break;
         case VEHICLE_VALUE_TYPE_ZONED_FLOAT:
             sscanf(data, "%d %f", &zone, &value);
-            vehicle_data.value.zoned_float_value.zone = zone;
-            vehicle_data.value.zoned_float_value.value = value;
-            printf("Value type: ZONED_FLOAT\nZone: %d\n", vehicle_data.value.zoned_float_value.zone);
-            printf("Value type: ZONED_FLOAT\nValue: %f\n", vehicle_data.value.zoned_float_value.value);
+            vehicle_data.zone = zone;
+            vehicle_data.value.float_value = value;
+            printf("Value type: ZONED_FLOAT\nZone: %d\n", vehicle_data.zone);
+            printf("Value type: ZONED_FLOAT\nValue: %f\n", vehicle_data.value.float_value);
             break;
         case VEHICLE_VALUE_TYPE_INT32_VEC2:
             sscanf(data, "%d %d", &vehicle_data.value.int32_array[0],
@@ -265,8 +265,8 @@ int vehicle_event_callback(const vehicle_prop_value_t *event_data) {
             printf("Ascii value: %s\n", ascii_out);
             break;
         case VEHICLE_VALUE_TYPE_ZONED_FLOAT:
-            printf("Value type: ZONED_FLOAT\nZone: %d\n", event_data->value.zoned_float_value.zone);
-            printf("Value type: ZONED_FLOAT\nValue: %f\n", event_data->value.zoned_float_value.value);
+            printf("Value type: ZONED_FLOAT\nZone: %d\n", event_data->zone);
+            printf("Value type: ZONED_FLOAT\nValue: %f\n", event_data->value.float_value);
             break;
         case VEHICLE_VALUE_TYPE_INT32_VEC2:
             printf("Value type: INT32_VEC2\nValue[0]: %d Value[1] %d\n",