Keun-young Park | 450faba | 2016-02-10 18:15:12 -0800 | [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 | #ifndef CAR_VEHICLE_HAL_PROPERTY_UTIL_H_ |
| 18 | #define CAR_VEHICLE_HAL_PROPERTY_UTIL_H_ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <inttypes.h> |
| 23 | |
| 24 | #include <hardware/hardware.h> |
| 25 | #include <hardware/vehicle.h> |
| 26 | |
| 27 | #include <utils/String8.h> |
| 28 | |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 29 | #include <IVehicleNetwork.h> |
| 30 | |
Keun-young Park | 450faba | 2016-02-10 18:15:12 -0800 | [diff] [blame] | 31 | namespace android { |
| 32 | |
Keun-young Park | a4f44e1 | 2016-07-08 14:27:29 -0700 | [diff] [blame] | 33 | #ifndef MIN |
| 34 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
| 35 | #endif |
| 36 | |
Keun-young Park | 450faba | 2016-02-10 18:15:12 -0800 | [diff] [blame] | 37 | class VechilePropertyUtil { |
| 38 | public: |
| 39 | static void dumpProperty(String8& msg, const vehicle_prop_config_t& config) { |
| 40 | msg.appendFormat("property 0x%x, access:0x%x, change_mode:0x%x, value_type:0x%x", |
| 41 | config.prop, config.access, config.change_mode, config.value_type); |
Keun-young Park | a4f44e1 | 2016-07-08 14:27:29 -0700 | [diff] [blame] | 42 | char configString[100]; |
| 43 | if (config.config_string.len > 0 && config.config_string.data != NULL) { |
| 44 | int stringLen = MIN(config.config_string.len, (int32_t) sizeof(configString) - 1); |
| 45 | memcpy(configString, config.config_string.data, stringLen); |
| 46 | configString[stringLen] = 0; |
| 47 | } |
| 48 | msg.appendFormat(",permission:0x%x, zones:0x%x, conflg_flag:0x%x, config_string:%s, " \ |
| 49 | "fsmin:%f, fsmax:%f", |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 50 | config.permission_model, config.vehicle_zone_flags, config.config_flags, |
Keun-young Park | a4f44e1 | 2016-07-08 14:27:29 -0700 | [diff] [blame] | 51 | (config.config_string.len > 0) ? configString : "N/A", |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 52 | config.min_sample_rate, config.max_sample_rate); |
Keun-young Park | 450faba | 2016-02-10 18:15:12 -0800 | [diff] [blame] | 53 | switch (config.value_type) { |
| 54 | case VEHICLE_VALUE_TYPE_FLOAT: |
| 55 | case VEHICLE_VALUE_TYPE_FLOAT_VEC2: |
| 56 | case VEHICLE_VALUE_TYPE_FLOAT_VEC3: |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 57 | case VEHICLE_VALUE_TYPE_FLOAT_VEC4: { |
Keun-young Park | 450faba | 2016-02-10 18:15:12 -0800 | [diff] [blame] | 58 | msg.appendFormat(",v min:%f, v max:%f\n", config.float_min_value, |
| 59 | config.float_max_value); |
| 60 | } break; |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 61 | case VEHICLE_VALUE_TYPE_ZONED_FLOAT: |
| 62 | case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC2: |
| 63 | case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC3: |
| 64 | case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC4: { |
| 65 | if (config.float_min_values == NULL) { |
| 66 | if (config.float_max_values == NULL) { |
| 67 | msg.appendFormat(",v min:%f, v max:%f\n", config.float_min_value, |
| 68 | config.float_max_value); |
| 69 | } else { |
| 70 | msg.appendFormat(", ERROR: float_max_values not NULL while min is NULL"); |
| 71 | |
| 72 | } |
| 73 | } else { |
| 74 | if (config.float_max_values == NULL) { |
| 75 | msg.appendFormat(", ERROR: float_min_values not NULL while max is NULL"); |
| 76 | } else { |
| 77 | int n = VehicleNetworkUtil::countNumberOfZones( |
| 78 | config.vehicle_zone_flags); |
| 79 | msg.appendFormat(", v min:"); |
| 80 | for (int i = 0; i < n; i++) { |
| 81 | msg.appendFormat("%f,", config.float_min_values[i]); |
| 82 | } |
| 83 | msg.appendFormat(", v max:"); |
| 84 | for (int i = 0; i < n; i++) { |
| 85 | msg.appendFormat("%f,", config.float_max_values[i]); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } break; |
Keun-young Park | 450faba | 2016-02-10 18:15:12 -0800 | [diff] [blame] | 90 | case VEHICLE_VALUE_TYPE_INT64: { |
Keun-young Park | 558e9b1 | 2016-02-26 13:52:45 -0800 | [diff] [blame] | 91 | msg.appendFormat(",v min:%" PRId64 " max:%" PRId64 "\n", config.int64_min_value, |
Keun-young Park | 450faba | 2016-02-10 18:15:12 -0800 | [diff] [blame] | 92 | config.int64_max_value); |
| 93 | } break; |
| 94 | case VEHICLE_VALUE_TYPE_INT32: |
| 95 | case VEHICLE_VALUE_TYPE_INT32_VEC2: |
| 96 | case VEHICLE_VALUE_TYPE_INT32_VEC3: |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 97 | case VEHICLE_VALUE_TYPE_INT32_VEC4: { |
Keun-young Park | 450faba | 2016-02-10 18:15:12 -0800 | [diff] [blame] | 98 | msg.appendFormat(",v min:%d, v max:%d\n", config.int32_min_value, |
| 99 | config.int32_max_value); |
| 100 | } break; |
Keun-young Park | 71b2f5c | 2016-03-10 18:44:40 -0800 | [diff] [blame] | 101 | case VEHICLE_VALUE_TYPE_ZONED_INT32: |
| 102 | case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC2: |
| 103 | case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC3: |
| 104 | case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC4: { |
| 105 | if (config.int32_min_values == NULL) { |
| 106 | if (config.int32_max_values == NULL) { |
| 107 | msg.appendFormat(",v min:%d, v max:%d\n", config.int32_min_value, |
| 108 | config.int32_max_value); |
| 109 | } else { |
| 110 | msg.appendFormat(", ERROR: int32_max_values not NULL while min is NULL"); |
| 111 | |
| 112 | } |
| 113 | } else { |
| 114 | if (config.int32_max_values == NULL) { |
| 115 | msg.appendFormat(", ERROR: int32_min_values not NULL while max is NULL"); |
| 116 | } else { |
| 117 | int n = VehicleNetworkUtil::countNumberOfZones( |
| 118 | config.vehicle_zone_flags); |
| 119 | msg.appendFormat(", v min:"); |
| 120 | for (int i = 0; i < n; i++) { |
| 121 | msg.appendFormat("%d,", config.int32_min_values[i]); |
| 122 | } |
| 123 | msg.appendFormat(", v max:"); |
| 124 | for (int i = 0; i < n; i++) { |
| 125 | msg.appendFormat("%d,", config.int32_max_values[i]); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } break; |
Keun-young Park | 450faba | 2016-02-10 18:15:12 -0800 | [diff] [blame] | 130 | default: |
| 131 | msg.appendFormat("\n"); |
| 132 | } |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | |
| 137 | }; |
| 138 | |
| 139 | #endif /* CAR_VEHICLE_HAL_PROPERTY_UTIL_H_ */ |