blob: 17319696b43f57d491f6bdc2d54d701d03421ba3 [file] [log] [blame]
Keun-young Park450faba2016-02-10 18:15:12 -08001/*
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 Park71b2f5c2016-03-10 18:44:40 -080029#include <IVehicleNetwork.h>
30
Keun-young Park450faba2016-02-10 18:15:12 -080031namespace android {
32
Keun-young Parka4f44e12016-07-08 14:27:29 -070033#ifndef MIN
34#define MIN(a,b) (((a)<(b))?(a):(b))
35#endif
36
Keun-young Park450faba2016-02-10 18:15:12 -080037class VechilePropertyUtil {
38public:
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 Parka4f44e12016-07-08 14:27:29 -070042 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 Park71b2f5c2016-03-10 18:44:40 -080050 config.permission_model, config.vehicle_zone_flags, config.config_flags,
Keun-young Parka4f44e12016-07-08 14:27:29 -070051 (config.config_string.len > 0) ? configString : "N/A",
Keun-young Park71b2f5c2016-03-10 18:44:40 -080052 config.min_sample_rate, config.max_sample_rate);
Keun-young Park450faba2016-02-10 18:15:12 -080053 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 Park71b2f5c2016-03-10 18:44:40 -080057 case VEHICLE_VALUE_TYPE_FLOAT_VEC4: {
Keun-young Park450faba2016-02-10 18:15:12 -080058 msg.appendFormat(",v min:%f, v max:%f\n", config.float_min_value,
59 config.float_max_value);
60 } break;
Keun-young Park71b2f5c2016-03-10 18:44:40 -080061 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 Park450faba2016-02-10 18:15:12 -080090 case VEHICLE_VALUE_TYPE_INT64: {
Keun-young Park558e9b12016-02-26 13:52:45 -080091 msg.appendFormat(",v min:%" PRId64 " max:%" PRId64 "\n", config.int64_min_value,
Keun-young Park450faba2016-02-10 18:15:12 -080092 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 Park71b2f5c2016-03-10 18:44:40 -080097 case VEHICLE_VALUE_TYPE_INT32_VEC4: {
Keun-young Park450faba2016-02-10 18:15:12 -080098 msg.appendFormat(",v min:%d, v max:%d\n", config.int32_min_value,
99 config.int32_max_value);
100 } break;
Keun-young Park71b2f5c2016-03-10 18:44:40 -0800101 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 Park450faba2016-02-10 18:15:12 -0800130 default:
131 msg.appendFormat("\n");
132 }
133 }
134};
135
136
137};
138
139#endif /* CAR_VEHICLE_HAL_PROPERTY_UTIL_H_ */