blob: 3c3922f69c3f11d73a69ac03efe308d8dddca872 [file] [log] [blame]
Sanket Agarwalfb636682015-08-11 14:34:29 -07001/*
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#define LOG_TAG "vehicle-hal-tool"
18
19#include <inttypes.h>
20#include <stdlib.h>
21#include <string.h>
22#include <hardware/hardware.h>
23#include <hardware/vehicle.h>
24
25#include <cutils/log.h>
26
27void usage() {
28 printf("Usage: "
29 "./vehicle-hal-tool [-l] [-m -p -t [-v]]\n"
30 "-l - List properties\n"
31 "-m - Mode (cannot be used with -l). Accepted strings: get, set or sub.\n"
32 "-p - Property (only used with -m)\n"
33 "-t - Type (only used with -m)\n"
34 "-w - Wait time in seconds (only used with -m set to sub)\n"
35 "-v - Value to which vehicle_prop_value is set\n"
36 "Depending on the type pass the value:\n"
37 "Int: pass a quoted integer\n"
38 "Float: pass a quoted float\n"
39 "Int array: pass a quoted space delimited int array, eg: \"1 2 3 4\" for\n:"
40 "setting int32_array's all 4 elements (see VEHICLE_VALUE_TYPE_INT32_VEC4\n"
41 "String: pass a normal string\n\n"
42 "The configurations to use the tool are as follows:\n"
43 "List Properties\n"
44 "---------------\n"
45 "./vehicle-hal-tool -l \n"
46 "Lists the various properties defined in HAL implementation. Use this to check if "
47 "the HAL implementation is correctly set up and exposing the capabilities correctly.\n"
48
49 "Get Properties\n"
50 "---------------\n"
51 "./vehicle-hal-tool -m get -p <prop> -t <type> [-v <vehicle_prop_value>]\n"
52 "Example: ./vehicle-hal-tool -m get -p 1028 -t 3 # VEHICLE_PROPERTY_DRIVING_STATUS\n"
53 "./vehicle-hal-tool -m get -p 257 -t 1 # VEHICLE_PROPERTY_INFO_MAKE\n"
54 "./vehicle-hal-tool -m get -p 2049 -t 19 -v \"3 0 0 0\"\n"
55 " # VEHICLE_PROPERTY_RADIO_PRESET\n"
56 "with preset value set to 3.\n\n"
57 "Set properties\n"
58 "--------------\n"
59 "./vehicle-hal-tool -m set -p 10 -t 1 -v random_property\n"
60 "Set properties may not be applicable to most properties\n\n"
61 "Subscribe properties\n"
62 "--------------------\n"
63 "Subscribes to be notified about a property change (depending on whether\n"
64 "it is a on change property or a continuous property) for seconds provided\n"
65 "as -w paramter.\n"
66 "./vehicle-hal-tool -m sub -p 1028 -w 10\n"
67 );
68}
69
70void list_all_properties(vehicle_hw_device_t *device) {
71 int num_configs = -1;
72 const vehicle_prop_config_t *configs = device->list_properties(device, &num_configs);
73 if (num_configs < 0) {
74 printf("List configs error. %d", num_configs);
75 exit(1);
76 }
77
78 printf("Listing configs\n--------------------\n");
79 int i = 0;
80 for (i = 0; i < num_configs; i++) {
81 const vehicle_prop_config_t *config_temp = configs + i;
82 printf("Property ID: %d\n"
83 "Property config_flags: %d\n"
84 "Property change mode: %d\n"
85 "Property min sample rate: %f\n"
86 "Property max sample rate: %f\n",
87 config_temp->prop, config_temp->config_flags, config_temp->change_mode,
88 config_temp->min_sample_rate, config_temp->max_sample_rate);
89 }
90}
91
Jamie Howarth8b61aac2016-03-10 18:58:53 -080092static void print_property(const vehicle_prop_value_t *data) {
93 switch (data->value_type) {
94 case VEHICLE_VALUE_TYPE_STRING:
95 printf("Value type: STRING\n Size: %d\n", data->value.str_value.len);
96 // This implementation only supports ASCII.
97 char *ascii_out = (char *) malloc((data->value.str_value.len + 1) * sizeof(char));
98 memcpy(ascii_out, data->value.str_value.data, data->value.str_value.len);
99 ascii_out[data->value.str_value.len] = '\0';
100 printf("Value Type: STRING %s\n", ascii_out);
101 break;
102 case VEHICLE_VALUE_TYPE_BYTES:
103 printf("Value type: BYTES\n Size: %d", data->value.bytes_value.len);
104 for (int i = 0; i < data->value.bytes_value.len; i++) {
105 if ((i % 16) == 0) {
106 printf("\n %04X: ", i);
107 }
108 printf("%02X ", data->value.bytes_value.data[i]);
109 }
110 printf("\n");
111 break;
112 case VEHICLE_VALUE_TYPE_BOOLEAN:
113 printf("Value type: BOOLEAN\nValue: %d\n", data->value.boolean_value);
114 break;
115 case VEHICLE_VALUE_TYPE_ZONED_BOOLEAN:
116 printf("Value type: ZONED_BOOLEAN\nZone: %d\n", data->zone);
117 printf("Value: %d\n", data->value.boolean_value);
118 break;
119 case VEHICLE_VALUE_TYPE_INT64:
120 printf("Value type: INT64\nValue: %" PRId64 "\n", data->value.int64_value);
121 break;
122 case VEHICLE_VALUE_TYPE_FLOAT:
123 printf("Value type: FLOAT\nValue: %f\n", data->value.float_value);
124 break;
125 case VEHICLE_VALUE_TYPE_FLOAT_VEC2:
126 printf("Value type: FLOAT_VEC2\nValue[0]: %f ", data->value.float_array[0]);
127 printf("Value[1]: %f\n", data->value.float_array[1]);
128 break;
129 case VEHICLE_VALUE_TYPE_FLOAT_VEC3:
130 printf("Value type: FLOAT_VEC3\nValue[0]: %f ", data->value.float_array[0]);
131 printf("Value[1]: %f ", data->value.float_array[1]);
132 printf("Value[2]: %f\n", data->value.float_array[2]);
133 break;
134 case VEHICLE_VALUE_TYPE_FLOAT_VEC4:
135 printf("Value type: FLOAT_VEC4\nValue[0]: %f ", data->value.float_array[0]);
136 printf("Value[1]: %f ", data->value.float_array[1]);
137 printf("Value[2]: %f ", data->value.float_array[2]);
138 printf("Value[3]: %f\n", data->value.float_array[3]);
139 break;
140 case VEHICLE_VALUE_TYPE_INT32:
141 printf("Value type: INT32\nValue: %d\n", data->value.int32_value);
142 break;
143 case VEHICLE_VALUE_TYPE_INT32_VEC2:
144 printf("Value type: INT32_VEC2\nValue[0]: %d ", data->value.int32_array[0]);
145 printf("Value[1]: %d\n", data->value.int32_array[1]);
146 break;
147 case VEHICLE_VALUE_TYPE_INT32_VEC3:
148 printf("Value type: INT32_VEC3\nValue[0]: %d ", data->value.int32_array[0]);
149 printf("Value[1]: %d ", data->value.int32_array[1]);
150 printf("Value[2]: %d\n", data->value.int32_array[2]);
151 break;
152 case VEHICLE_VALUE_TYPE_INT32_VEC4:
153 printf("Value type: INT32_VEC4\nValue[0]: %d ", data->value.int32_array[0]);
154 printf("Value[1]: %d ", data->value.int32_array[1]);
155 printf("Value[2]: %d ", data->value.int32_array[2]);
156 printf("Value[3]: %d\n", data->value.int32_array[3]);
157 break;
158 case VEHICLE_VALUE_TYPE_ZONED_FLOAT:
159 printf("Value type: ZONED_FLOAT\nZone: %d ", data->zone);
160 printf("Value: %f\n", data->value.float_value);
161 break;
162 case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC2:
163 printf("Value type: ZONED_FLOAT_VEC2\nZone: %d ", data->zone);
164 printf("Value[0]: %f", data->value.float_array[0]);
165 printf("Value[1]: %f\n", data->value.float_array[1]);
166 break;
167 case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC3:
168 printf("Value type: ZONED_FLOAT_VEC3\nZone: %d ", data->zone);
169 printf("Value[0]: %f ", data->value.float_array[0]);
170 printf("Value[1]: %f ", data->value.float_array[1]);
171 printf("Value[2]: %f\n", data->value.float_array[2]);
172 break;
173 case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC4:
174 printf("Value type: ZONED_FLOAT_VEC4\nZone: %d ", data->zone);
175 printf("Value[0]: %f ", data->value.float_array[0]);
176 printf("Value[1]: %f ", data->value.float_array[1]);
177 printf("Value[2]: %f ", data->value.float_array[2]);
178 printf("Value[3]: %f\n", data->value.float_array[3]);
179 break;
180 case VEHICLE_VALUE_TYPE_ZONED_INT32:
181 printf("Value type: ZONED_INT32\nZone: %d ", data->zone);
182 printf("Value: %d\n", data->value.int32_value);
183 break;
184 case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC2:
185 printf("Value type: ZONED_INT32_VEC2\nZone: %d ", data->zone);
186 printf("Value[0]: %d ", data->value.int32_array[0]);
187 printf("Value[1]: %d\n", data->value.int32_array[1]);
188 break;
189 case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC3:
190 printf("Value type: ZONED_INT32_VEC3\nZone: %d ", data->zone);
191 printf("Value[0]: %d ", data->value.int32_array[0]);
192 printf("Value[1]: %d ", data->value.int32_array[1]);
193 printf("Value[2]: %d\n", data->value.int32_array[2]);
194 break;
195 case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC4:
196 printf("Value type: ZONED_INT32_VEC4\nZone: %d ", data->zone);
197 printf("Value[0]: %d ", data->value.int32_array[0]);
198 printf("Value[1]: %d ", data->value.int32_array[1]);
199 printf("Value[2]: %d ", data->value.int32_array[2]);
200 printf("Value[3]: %d\n", data->value.int32_array[3]);
201 break;
202 default:
203 printf("Value type not yet handled: %d.\n", data->value_type);
204 }
205}
206
Sanket Agarwalfb636682015-08-11 14:34:29 -0700207void get_property(
208 vehicle_hw_device_t *device, int32_t property, int32_t type, char *value_string) {
209 vehicle_prop_value_t *data = (vehicle_prop_value_t *) malloc (sizeof(vehicle_prop_value_t));
210
211 // Parse the string according to type.
212 if (value_string != NULL && strlen(value_string) > 0) {
213 switch (type) {
214 case VEHICLE_VALUE_TYPE_INT32:
215 sscanf(value_string, "%d", &(data->value.int32_value));
216 break;
217 case VEHICLE_VALUE_TYPE_INT32_VEC4:
218 {
219 int32_t vec[4];
220 sscanf(value_string, "%d %d %d %d", &vec[0], &vec[1], &vec[2], &vec[3]);
221 memcpy(data->value.int32_array, vec, sizeof(vec));
222 break;
223 }
224 default:
225 printf("%s Setting value type not supported: %d\n", __func__, type);
226 exit(1);
227 }
228 }
229
230 data->prop = property;
231 int ret_code = device->get(device, data);
232 if (ret_code != 0) {
233 printf("Cannot get property: %d\n", ret_code);
234 exit(1);
235 }
236
237 // We simply convert the data into the type mentioned by the result of the
238 // get call.
239 printf("Get output\n------------\n");
Jamie Howarth8b61aac2016-03-10 18:58:53 -0800240 print_property(data);
Sanket Agarwalfb636682015-08-11 14:34:29 -0700241 free(data);
242}
243
244void set_property(vehicle_hw_device_t *device,
245 int32_t property,
246 int32_t type,
247 char *data) {
248 vehicle_prop_value_t vehicle_data;
249 vehicle_data.prop = property;
250 vehicle_data.value_type = type;
251 int32_t zone = 0;
252 float value = 0.0;
253 switch (type) {
Sanket Agarwalfb636682015-08-11 14:34:29 -0700254 case VEHICLE_VALUE_TYPE_STRING:
255 // TODO: Make the code generic to UTF8 characters.
256 vehicle_data.value.str_value.len = strlen(data);
257 vehicle_data.value.str_value.data =
258 (uint8_t *) malloc (strlen(data) * sizeof(uint8_t));
259 memcpy(vehicle_data.value.str_value.data, data, strlen(data) + 1);
260 break;
Jamie Howarth8b61aac2016-03-10 18:58:53 -0800261 case VEHICLE_VALUE_TYPE_BYTES: {
262 int len = strlen(data);
263 int numBytes = (len + 1) / 3;
264 uint8_t *buf = calloc(numBytes, sizeof(uint8_t));
265 char *byte = strtok(data, " ");
266 for (int i = 0; byte != NULL && i < numBytes; i++) {
267 buf[i] = strtol(data, NULL, 16);
268 byte = strtok(NULL, " ");
269 }
270 vehicle_data.value.bytes_value.len = numBytes;
271 vehicle_data.value.bytes_value.data = buf;
272 }
273 break;
274 case VEHICLE_VALUE_TYPE_BOOLEAN:
275 vehicle_data.value.boolean_value = atoi(data);
276 break;
277 case VEHICLE_VALUE_TYPE_ZONED_BOOLEAN:
278 sscanf(data, "%d %d", &vehicle_data.zone,
279 &vehicle_data.value.boolean_value);
280 break;
281 case VEHICLE_VALUE_TYPE_INT64:
282 vehicle_data.value.int64_value = atoi(data);
283 break;
284 case VEHICLE_VALUE_TYPE_FLOAT:
285 vehicle_data.value.float_value = atof(data);
286 break;
287 case VEHICLE_VALUE_TYPE_FLOAT_VEC2:
288 sscanf(data, "%f %f", &vehicle_data.value.float_array[0],
289 &vehicle_data.value.float_array[1]);
290 break;
291 case VEHICLE_VALUE_TYPE_FLOAT_VEC3:
292 sscanf(data, "%f %f %f", &vehicle_data.value.float_array[0],
293 &vehicle_data.value.float_array[1],
294 &vehicle_data.value.float_array[2]);
295 break;
296 case VEHICLE_VALUE_TYPE_FLOAT_VEC4:
297 sscanf(data, "%f %f %f %f", &vehicle_data.value.float_array[0],
298 &vehicle_data.value.float_array[1],
299 &vehicle_data.value.float_array[2],
300 &vehicle_data.value.float_array[3]);
301 break;
302 case VEHICLE_VALUE_TYPE_INT32:
303 vehicle_data.value.int32_value = atoi(data);
Sanket Agarwalfb636682015-08-11 14:34:29 -0700304 break;
305 case VEHICLE_VALUE_TYPE_INT32_VEC2:
306 sscanf(data, "%d %d", &vehicle_data.value.int32_array[0],
307 &vehicle_data.value.int32_array[1]);
Sanket Agarwalfb636682015-08-11 14:34:29 -0700308 break;
309 case VEHICLE_VALUE_TYPE_INT32_VEC3:
310 sscanf(data, "%d %d %d", &vehicle_data.value.int32_array[0],
311 &vehicle_data.value.int32_array[1],
312 &vehicle_data.value.int32_array[2]);
Sanket Agarwalfb636682015-08-11 14:34:29 -0700313 break;
314 case VEHICLE_VALUE_TYPE_INT32_VEC4:
315 sscanf(data, "%d %d %d %d", &vehicle_data.value.int32_array[0],
316 &vehicle_data.value.int32_array[1],
317 &vehicle_data.value.int32_array[2],
318 &vehicle_data.value.int32_array[3]);
Jamie Howarth8b61aac2016-03-10 18:58:53 -0800319 break;
320 case VEHICLE_VALUE_TYPE_ZONED_FLOAT:
321 sscanf(data, "%d %f", &zone, &value);
322 vehicle_data.zone = zone;
323 vehicle_data.value.float_value = value;
324 break;
325 case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC2:
326 sscanf(data, "%d %f %f", &vehicle_data.zone,
327 &vehicle_data.value.float_array[0],
328 &vehicle_data.value.float_array[1]);
329 break;
330 case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC3:
331 sscanf(data, "%d %f %f %f", &vehicle_data.zone,
332 &vehicle_data.value.float_array[0],
333 &vehicle_data.value.float_array[1],
334 &vehicle_data.value.float_array[2]);
335 break;
336 case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC4:
337 sscanf(data, "%d %f %f %f %f", &vehicle_data.zone,
338 &vehicle_data.value.float_array[0],
339 &vehicle_data.value.float_array[1],
340 &vehicle_data.value.float_array[2],
341 &vehicle_data.value.float_array[3]);
342 break;
343 case VEHICLE_VALUE_TYPE_ZONED_INT32:
344 sscanf(data, "%d %d", &vehicle_data.zone,
345 &vehicle_data.value.int32_value);
346 break;
347 case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC2:
348 sscanf(data, "%d %d %d", &vehicle_data.zone,
349 &vehicle_data.value.int32_array[0],
350 &vehicle_data.value.int32_array[1]);
351 break;
352 case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC3:
353 sscanf(data, "%d %d %d %d", &vehicle_data.zone,
354 &vehicle_data.value.int32_array[0],
355 &vehicle_data.value.int32_array[1],
356 &vehicle_data.value.int32_array[2]);
357 break;
358 case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC4:
359 sscanf(data, "%d %d %d %d %d", &vehicle_data.zone,
360 &vehicle_data.value.int32_array[0],
361 &vehicle_data.value.int32_array[1],
362 &vehicle_data.value.int32_array[2],
363 &vehicle_data.value.int32_array[3]);
Sanket Agarwalfb636682015-08-11 14:34:29 -0700364 break;
365 default:
366 printf("set_property: Value type not yet handled: %d\n", type);
367 exit(1);
368 }
Jamie Howarth8b61aac2016-03-10 18:58:53 -0800369 printf("Setting Property id: %d\n", vehicle_data.prop);
370 print_property(&vehicle_data);
371
Sanket Agarwalfb636682015-08-11 14:34:29 -0700372 int ret_code = device->set(device, &vehicle_data);
373 if (ret_code != 0) {
374 printf("Cannot set property: %d\n", ret_code);
375 exit(1);
376 }
377}
378
379int vehicle_event_callback(const vehicle_prop_value_t *event_data) {
380 // Print what we got.
381 printf("Got some value from callback property: %d\n", event_data->prop);
382 printf("Timestamp: %" PRId64 "\n", event_data->timestamp);
Jamie Howarth8b61aac2016-03-10 18:58:53 -0800383 print_property(event_data);
Sanket Agarwalfb636682015-08-11 14:34:29 -0700384 return 0;
385}
Jamie Howarth8b61aac2016-03-10 18:58:53 -0800386
Sanket Agarwalfb636682015-08-11 14:34:29 -0700387int vehicle_error_callback(int32_t error_code, int32_t property, int32_t operation) {
388 // Print what we got.
389 printf("Error code obtained: %d\n", error_code);
390 return 0;
391}
Jamie Howarth8b61aac2016-03-10 18:58:53 -0800392
Sanket Agarwalfb636682015-08-11 14:34:29 -0700393void subscribe_to_property(
394 vehicle_hw_device_t *device,
395 int32_t prop,
396 float sample_rate,
397 uint32_t wait_in_seconds) {
398 // Init the device with a callback.
399 device->init(device, vehicle_event_callback, vehicle_error_callback);
Keun-young Parkbf877a72015-12-21 14:16:05 -0800400 int ret_code = device->subscribe(device, prop, 0, 0);
Sanket Agarwalfb636682015-08-11 14:34:29 -0700401 if (ret_code != 0) {
402 printf("Could not subscribe: %d\n", ret_code);
403 exit(1);
404 }
405
406 // Callbacks will happen on one of the threads created by the HAL hence we
407 // can simply sleep here and see the output.
408 sleep(wait_in_seconds);
409
410 // Unsubscribe and uninit.
411 ret_code = device->unsubscribe(device, prop);
412 if (ret_code != 0) {
413 printf("Error unsubscribing the HAL, still continuining to uninit HAL ...");
414 }
415
416 ret_code = device->release(device);
417 if (ret_code != 0) {
418 printf("Error uniniting HAL, exiting anyways.");
419 }
420}
421
422int main(int argc, char* argv[]) {
423 // Open the vehicle module and just ask for the list of properties.
424 const hw_module_t *hw_module = NULL;
425 int ret_code = hw_get_module(VEHICLE_HARDWARE_MODULE_ID, &hw_module);
426 if (ret_code != 0) {
427 printf("Cannot open the hw module. Does the HAL exist? %d\n", ret_code);
428 return -1;
429 }
430
431 vehicle_module_t *vehicle_module = (vehicle_module_t *)(hw_module);
432 hw_device_t *device = NULL;
433 ret_code = vehicle_module->common.methods->open(hw_module, NULL, &device);
434 if (!device) {
435 printf("Cannot open the hw device: %d\n", ret_code);
436 return -1;
437 }
438 vehicle_hw_device_t *vehicle_device = (vehicle_hw_device_t *) (device);
439 printf("HAL Loaded!\n");
440
441 // If this is a list properties command - we check for -l command.
442 int list_properties = 0;
443 // Type of the property (see #defines in vehicle.h).
444 int property = -1;
445 // Type of the value of the property (see enum vehicle_value_type).
446 int type = -1;
447 // Whether the mode is "get" or "set".
448 char mode[100] = "";
449 // Actual value as a string representation (supports only PODs for now).
450 // TODO: Support structures and complex types in the tool.
451 char value[100] = "";
452 // Wait time for the subscribe type of calls.
453 // We keep a default in case the user does not specify one.
454 int wait_time_in_sec = 10;
455 // Sample rate for subscribe type of calls.
456 // Default value is 0 for onchange type of properties.
457 int sample_rate = 0;
458 // Int array string which represents the vehicle_value_t in array of
459 // numbers. See vehicle_prop_value_t.value.int32_array.
460 char int_array_string[1000]; int_array_string[0] = '\0';
461
462 int opt;
Sanket Agarwalfb636682015-08-11 14:34:29 -0700463 while ((opt = getopt(argc, argv, "lm:p:t:v:w:s:")) != -1) {
464 switch (opt) {
465 case 'l':
466 list_properties = 1;
467 break;
468 case 'm':
469 strcpy(mode, optarg);
470 break;
471 case 'p':
472 property = atoi(optarg);
473 break;
474 case 't':
475 type = atoi(optarg);
476 break;
477 case 'v':
478 strcpy(value, optarg);
479 break;
480 case 'w':
481 wait_time_in_sec = atoi(optarg);
482 break;
483 case 's':
484 sample_rate = atoi(optarg);
485 break;
486 }
487 }
488
489 // We should have atleast one of list properties or mode (for get or set).
490 if (!list_properties &&
491 !(!strcmp(mode, "get") || !strcmp(mode, "set") || !strcmp(mode, "sub"))) {
492 usage();
493 exit(1);
494 }
495
496 if (list_properties) {
497 printf("Listing properties...\n");
498 list_all_properties(vehicle_device);
499 } else if (!strcmp(mode, "get")) {
500 printf("Getting property ...\n");
501 if (property == -1) {
502 printf("Use -p to pass a valid Property.\n");
503 usage();
504 exit(1);
505 }
506
507 int32_t int_array_list[4];
508 int count = -1;
509 if (strlen(int_array_string) > 0) {
510 count = sscanf(int_array_string, "%d%d%d%d",
511 &int_array_list[0], &int_array_list[1], &int_array_list[2], &int_array_list[3]);
512 }
513
514 get_property(vehicle_device, property, type, value);
515 } else if (!strcmp(mode, "set")) {
516 printf("Setting property ...\n");
517 if (property == -1 || type == -1) {
518 printf("Use -p to pass a valid Property and -t to pass a valid Type.\n");
519 usage();
520 exit(1);
521 }
522 set_property(vehicle_device, property, type, value);
523 } else if (!strcmp(mode, "sub")) {
524 printf("Subscribing property ...\n");
525 if (property == -1 || wait_time_in_sec <= 0) {
526 printf("Use -p to pass a valid property and -w to pass a valid wait time(s)\n");
527 usage();
528 exit(1);
529 }
530 subscribe_to_property(vehicle_device, property, sample_rate, wait_time_in_sec);
531 }
532 return 0;
533}