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 29 #include <IVehicleNetwork.h> 30 31 namespace android { 32 33 class VechilePropertyUtil { 34 public: dumpProperty(String8 & msg,const vehicle_prop_config_t & config)35 static void dumpProperty(String8& msg, const vehicle_prop_config_t& config) { 36 msg.appendFormat("property 0x%x, access:0x%x, change_mode:0x%x, value_type:0x%x", 37 config.prop, config.access, config.change_mode, config.value_type); 38 msg.appendFormat(",permission:0x%x, zones:0x%x, conflg_flag:0x%x, fsmin:%f, fsmax:%f", 39 config.permission_model, config.vehicle_zone_flags, config.config_flags, 40 config.min_sample_rate, config.max_sample_rate); 41 switch (config.value_type) { 42 case VEHICLE_VALUE_TYPE_FLOAT: 43 case VEHICLE_VALUE_TYPE_FLOAT_VEC2: 44 case VEHICLE_VALUE_TYPE_FLOAT_VEC3: 45 case VEHICLE_VALUE_TYPE_FLOAT_VEC4: { 46 msg.appendFormat(",v min:%f, v max:%f\n", config.float_min_value, 47 config.float_max_value); 48 } break; 49 case VEHICLE_VALUE_TYPE_ZONED_FLOAT: 50 case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC2: 51 case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC3: 52 case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC4: { 53 if (config.float_min_values == NULL) { 54 if (config.float_max_values == NULL) { 55 msg.appendFormat(",v min:%f, v max:%f\n", config.float_min_value, 56 config.float_max_value); 57 } else { 58 msg.appendFormat(", ERROR: float_max_values not NULL while min is NULL"); 59 60 } 61 } else { 62 if (config.float_max_values == NULL) { 63 msg.appendFormat(", ERROR: float_min_values not NULL while max is NULL"); 64 } else { 65 int n = VehicleNetworkUtil::countNumberOfZones( 66 config.vehicle_zone_flags); 67 msg.appendFormat(", v min:"); 68 for (int i = 0; i < n; i++) { 69 msg.appendFormat("%f,", config.float_min_values[i]); 70 } 71 msg.appendFormat(", v max:"); 72 for (int i = 0; i < n; i++) { 73 msg.appendFormat("%f,", config.float_max_values[i]); 74 } 75 } 76 } 77 } break; 78 case VEHICLE_VALUE_TYPE_INT64: { 79 msg.appendFormat(",v min:%" PRId64 " max:%" PRId64 "\n", config.int64_min_value, 80 config.int64_max_value); 81 } break; 82 case VEHICLE_VALUE_TYPE_INT32: 83 case VEHICLE_VALUE_TYPE_INT32_VEC2: 84 case VEHICLE_VALUE_TYPE_INT32_VEC3: 85 case VEHICLE_VALUE_TYPE_INT32_VEC4: { 86 msg.appendFormat(",v min:%d, v max:%d\n", config.int32_min_value, 87 config.int32_max_value); 88 } break; 89 case VEHICLE_VALUE_TYPE_ZONED_INT32: 90 case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC2: 91 case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC3: 92 case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC4: { 93 if (config.int32_min_values == NULL) { 94 if (config.int32_max_values == NULL) { 95 msg.appendFormat(",v min:%d, v max:%d\n", config.int32_min_value, 96 config.int32_max_value); 97 } else { 98 msg.appendFormat(", ERROR: int32_max_values not NULL while min is NULL"); 99 100 } 101 } else { 102 if (config.int32_max_values == NULL) { 103 msg.appendFormat(", ERROR: int32_min_values not NULL while max is NULL"); 104 } else { 105 int n = VehicleNetworkUtil::countNumberOfZones( 106 config.vehicle_zone_flags); 107 msg.appendFormat(", v min:"); 108 for (int i = 0; i < n; i++) { 109 msg.appendFormat("%d,", config.int32_min_values[i]); 110 } 111 msg.appendFormat(", v max:"); 112 for (int i = 0; i < n; i++) { 113 msg.appendFormat("%d,", config.int32_max_values[i]); 114 } 115 } 116 } 117 } break; 118 default: 119 msg.appendFormat("\n"); 120 } 121 } 122 }; 123 124 125 }; 126 127 #endif /* CAR_VEHICLE_HAL_PROPERTY_UTIL_H_ */ 128