blob: 38c38ee049aca3d889c77aa837c5ae8c51025797 [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_hw_default"
18#define LOG_NDEBUG 1
19#define RADIO_PRESET_NUM 6
20
Keun-young Park08c255e2015-12-09 13:47:30 -080021#define UNUSED __attribute__((__unused__))
22
Sanket Agarwalfb636682015-08-11 14:34:29 -070023#include <errno.h>
Keun-young Park08c255e2015-12-09 13:47:30 -080024#include <inttypes.h>
Sanket Agarwalfb636682015-08-11 14:34:29 -070025#include <malloc.h>
26#include <pthread.h>
27#include <stdint.h>
28#include <stdlib.h>
29#include <string.h>
30#include <sys/prctl.h>
31#include <sys/time.h>
32#include <time.h>
33
34#include <cutils/log.h>
35#include <system/radio.h>
36#include <hardware/hardware.h>
37#include <hardware/vehicle.h>
38
39extern int64_t elapsedRealtimeNano();
40
41static char VEHICLE_MAKE[] = "android_car";
42
43typedef struct vehicle_device_impl {
44 vehicle_hw_device_t vehicle_device;
45 uint32_t initialized_;
46 vehicle_event_callback_fn event_fn_;
47 vehicle_error_callback_fn error_fn_;
48} vehicle_device_impl_t ;
49
50static pthread_mutex_t lock_;
51
52typedef struct subscription {
53 // Each subscription has it's own thread.
54 pthread_t thread_id;
55 int32_t prop;
56 float sample_rate;
57 pthread_mutex_t lock;
58 // This field should be protected by the above mutex.
59 // TODO change this to something better as flag alone takes long time to finish.
60 uint32_t stop_thread;
61 vehicle_device_impl_t* impl;
62 pthread_t thread;
63 pthread_cond_t cond;
64 char name[100];
65} subscription_t;
66
67static vehicle_prop_config_t CONFIGS[] = {
68 {
69 .prop = VEHICLE_PROPERTY_INFO_MAKE,
70 .access = VEHICLE_PROP_ACCESS_READ,
71 .change_mode = VEHICLE_PROP_CHANGE_MODE_STATIC,
72 .value_type = VEHICLE_VALUE_TYPE_STRING,
73 .min_sample_rate = 0,
74 .max_sample_rate = 0,
75 .hal_data = NULL,
76 },
77 {
78 .prop = VEHICLE_PROPERTY_GEAR_SELECTION,
79 .access = VEHICLE_PROP_ACCESS_READ,
80 .change_mode = VEHICLE_PROP_CHANGE_MODE_ON_CHANGE,
81 .value_type = VEHICLE_VALUE_TYPE_INT32,
82 .min_sample_rate = 0,
83 .max_sample_rate = 0,
84 .hal_data = NULL,
85 },
86 {
87 .prop = VEHICLE_PROPERTY_DRIVING_STATUS,
88 .access = VEHICLE_PROP_ACCESS_READ,
89 .change_mode = VEHICLE_PROP_CHANGE_MODE_ON_CHANGE,
90 .value_type = VEHICLE_VALUE_TYPE_INT32,
91 .min_sample_rate = 0,
92 .max_sample_rate = 0,
93 .hal_data = NULL,
94 },
95 {
96 .prop = VEHICLE_PROPERTY_PARKING_BRAKE_ON,
97 .access = VEHICLE_PROP_ACCESS_READ,
98 .change_mode = VEHICLE_PROP_CHANGE_MODE_ON_CHANGE,
99 .value_type = VEHICLE_VALUE_TYPE_BOOLEAN,
100 .min_sample_rate = 0,
101 .max_sample_rate = 0,
102 .hal_data = NULL,
103 },
104 {
105 .prop = VEHICLE_PROPERTY_PERF_VEHICLE_SPEED,
106 .access = VEHICLE_PROP_ACCESS_READ,
107 .change_mode = VEHICLE_PROP_CHANGE_MODE_CONTINUOUS,
108 .value_type = VEHICLE_VALUE_TYPE_FLOAT,
109 .min_sample_rate = 0.1,
110 .max_sample_rate = 10.0,
111 .hal_data = NULL,
112 },
113 {
114 .prop = VEHICLE_PROPERTY_RADIO_PRESET,
115 .access = VEHICLE_PROP_ACCESS_READ_WRITE,
116 .change_mode = VEHICLE_PROP_CHANGE_MODE_ON_CHANGE,
117 .value_type = VEHICLE_VALUE_TYPE_INT32_VEC4,
118 .vehicle_radio_num_presets = RADIO_PRESET_NUM,
119 .min_sample_rate = 0,
120 .max_sample_rate = 0,
121 .hal_data = NULL,
122 },
123};
124
125vehicle_prop_config_t* find_config(int prop) {
Keun-young Park08c255e2015-12-09 13:47:30 -0800126 unsigned int i;
Sanket Agarwalfb636682015-08-11 14:34:29 -0700127 for (i = 0; i < sizeof(CONFIGS) / sizeof(vehicle_prop_config_t); i++) {
128 if (CONFIGS[i].prop == prop) {
129 return &CONFIGS[i];
130 }
131 }
132 return NULL;
133}
134
135static int alloc_vehicle_str_from_cstr(const char* string, vehicle_str_t* vehicle_str) {
136 int len = strlen(string);
137 vehicle_str->data = (uint8_t*) malloc(len);
138 if (vehicle_str->data == NULL) {
139 return -ENOMEM;
140 }
141 memcpy(vehicle_str->data, string, len);
142 vehicle_str->len = len;
143 return 0;
144}
145
Keun-young Park08c255e2015-12-09 13:47:30 -0800146static vehicle_prop_config_t const * vdev_list_properties(vehicle_hw_device_t* device UNUSED,
Sanket Agarwalfb636682015-08-11 14:34:29 -0700147 int* num_properties) {
148 ALOGD("vdev_list_properties.");
149
150 *num_properties = sizeof(CONFIGS) / sizeof(vehicle_prop_config_t);
151 return CONFIGS;
152}
153
154static int vdev_init(vehicle_hw_device_t* device,
155 vehicle_event_callback_fn event_callback_fn,
156 vehicle_error_callback_fn error_callback_fn) {
157 ALOGD("vdev_init.");
158 vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
159 pthread_mutex_lock(&lock_);
160 if (impl->initialized_) {
161 ALOGE("vdev_init: Callback and Error functions are already existing.");
162 pthread_mutex_unlock(&lock_);
163 return -EEXIST;
164 }
165
166 impl->initialized_ = 1;
167 impl->event_fn_ = event_callback_fn;
168 impl->error_fn_ = error_callback_fn;
169 pthread_mutex_unlock(&lock_);
170 return 0;
171}
172
173static int vdev_release(vehicle_hw_device_t* device) {
174 vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
175 pthread_mutex_lock(&lock_);
176 if (!impl->initialized_) {
177 ALOGD("vdev_release: Already released before, returning early.");
178 } else {
179 // unsubscribe_all()
180 impl->initialized_ = 0;
181 }
182 pthread_mutex_unlock(&lock_);
183 return 0;
184}
185
Keun-young Park08c255e2015-12-09 13:47:30 -0800186static int vdev_get(vehicle_hw_device_t* device UNUSED, vehicle_prop_value_t* data) {
Sanket Agarwalfb636682015-08-11 14:34:29 -0700187 ALOGD("vdev_get.");
188 //TODO all data supporting read should support get
189 if (!data) {
190 ALOGE("vdev_get: Data cannot be null.");
191 return -EINVAL;
192 }
193 vehicle_prop_config_t* config = find_config(data->prop);
194 if (config == NULL) {
195 ALOGE("vdev_get: cannot find config 0x%x", data->prop);
196 return -EINVAL;
197 }
198 data->value_type = config->value_type;
199 // for STATIC type, time can be just 0 instead
200 data->timestamp = elapsedRealtimeNano();
201 int r;
202 switch (data->prop) {
203 case VEHICLE_PROPERTY_INFO_MAKE:
204 r = alloc_vehicle_str_from_cstr(VEHICLE_MAKE, &(data->value.str_value));
205 if (r != 0) {
206 ALOGE("vdev_get: alloc failed");
207 return r;
208 }
209 break;
210
211 case VEHICLE_PROPERTY_RADIO_PRESET: {
212 int radio_preset = data->value.int32_array[0];
213 if (radio_preset < VEHICLE_RADIO_PRESET_MIN_VALUE ||
214 radio_preset >= RADIO_PRESET_NUM) {
215 ALOGE("%s Invalid radio preset: %d\n", __func__, radio_preset);
216 return -1;
217 }
218 ALOGD("%s Radio Preset number: %d", __func__, radio_preset);
219 int32_t selector = radio_preset % 2 == 0;
220 // Populate the channel and subchannel to be some variation of the
221 // preset number for mocking.
222
223 // Restore the preset number.
224 data->value.int32_array[0] = radio_preset;
225 // Channel type values taken from
226 // system/core/include/system/radio.h
227 data->value.int32_array[1] = selector ? RADIO_BAND_FM : RADIO_BAND_AM;
228 // For FM set a value in Mhz and for AM set a value in Khz range
229 // (channel).
230 data->value.int32_array[2] = selector ? 99000000 : 100000;
231 // For FM we have a sub-channel and we care about it, for AM pass
232 // a dummy value.
233 data->value.int32_array[3] = selector ? radio_preset : -1;
234 break;
235 }
236
237 default:
238 // actual implementation will be much complex than this. It should track proper last
239 // state. Here just fill with zero.
240 memset(&(data->value), 0, sizeof(data->value));
241 break;
242 }
Keun-young Park08c255e2015-12-09 13:47:30 -0800243 ALOGI("vdev_get, type 0x%x, time %" PRId64 ", value_type %d", data->prop, data->timestamp,
Sanket Agarwalfb636682015-08-11 14:34:29 -0700244 data->value_type);
245 return 0;
246}
247
Keun-young Park08c255e2015-12-09 13:47:30 -0800248static int vdev_set(vehicle_hw_device_t* device UNUSED, const vehicle_prop_value_t* data) {
Sanket Agarwalfb636682015-08-11 14:34:29 -0700249 ALOGD("vdev_set.");
250 // Just print what data will be setting here.
251 ALOGD("Setting property %d with value type %d\n", data->prop, data->value_type);
252 vehicle_prop_config_t* config = find_config(data->prop);
253 if (config == NULL) {
254 ALOGE("vdev_set: cannot find config 0x%x", data->prop);
255 return -EINVAL;
256 }
257 if (config->value_type != data->value_type) {
258 ALOGE("vdev_set: type mismatch, passed 0x%x expecting 0x%x", data->value_type,
259 config->value_type);
260 return -EINVAL;
261 }
262 switch (data->value_type) {
263 case VEHICLE_VALUE_TYPE_FLOAT:
264 ALOGD("Value type: FLOAT\nValue: %f\n", data->value.float_value);
265 break;
266 case VEHICLE_VALUE_TYPE_INT32:
267 ALOGD("Value type: INT32\nValue: %d\n", data->value.int32_value);
268 break;
269 case VEHICLE_VALUE_TYPE_INT64:
270 ALOGD("Value type: INT64\nValue: %lld\n", data->value.int64_value);
271 break;
272 case VEHICLE_VALUE_TYPE_BOOLEAN:
273 ALOGD("Value type: BOOLEAN\nValue: %d\n", data->value.boolean_value);
274 break;
275 case VEHICLE_VALUE_TYPE_STRING:
276 ALOGD("Value type: STRING\n Size: %d\n", data->value.str_value.len);
277 // NOTE: We only handle ASCII strings here.
278 // Print the UTF-8 string.
279 char *ascii_out = (char *) malloc ((data->value.str_value.len + 1) * sizeof (char));
280 memcpy(ascii_out, data->value.str_value.data, data->value.str_value.len);
281 ascii_out[data->value.str_value.len] = '\0';
282 ALOGD("Value: %s\n", ascii_out);
283 break;
284 case VEHICLE_VALUE_TYPE_INT32_VEC4:
285 ALOGD("Value type: INT32_VEC4\nValue[0]: %d Value[1] %d Value[2] %d Value[3] %d",
286 data->value.int32_array[0], data->value.int32_array[1],
287 data->value.int32_array[2], data->value.int32_array[3]);
288 break;
289 default:
290 ALOGD("Value type not yet handled: %d.\n", data->value_type);
291 }
292 return 0;
293}
294
Keun-young Park08c255e2015-12-09 13:47:30 -0800295void print_subscribe_info(vehicle_device_impl_t* impl UNUSED) {
296 unsigned int i;
Sanket Agarwalfb636682015-08-11 14:34:29 -0700297 for (i = 0; i < sizeof(CONFIGS) / sizeof(vehicle_prop_config_t); i++) {
298 subscription_t* sub = (subscription_t*)CONFIGS[i].hal_data;
299 if (sub != NULL) {
keunyoung4529d7e2015-11-13 14:58:01 -0800300 ALOGD("prop: %d rate: %f", sub->prop, sub->sample_rate);
Sanket Agarwalfb636682015-08-11 14:34:29 -0700301 }
302 }
303}
304
305// This should be run in a separate thread always.
306void fake_event_thread(struct subscription *sub) {
307 if (!sub) {
308 ALOGE("oops! subscription object cannot be NULL.");
309 exit(-1);
310 }
311 prctl(PR_SET_NAME, (unsigned long)sub->name, 0, 0, 0);
312 // Emit values in a loop, every 2 seconds.
313 while (1) {
314 // Create a random value depending on the property type.
315 vehicle_prop_value_t event;
316 event.prop = sub->prop;
317 event.timestamp = elapsedRealtimeNano();
318 switch (sub->prop) {
319 case VEHICLE_PROPERTY_DRIVING_STATUS:
320 event.value_type = VEHICLE_VALUE_TYPE_INT32;
321 switch ((event.timestamp & 0x30000000)>>28) {
322 case 0:
323 event.value.driving_status = VEHICLE_DRIVING_STATUS_UNRESTRICTED;
324 break;
325 case 1:
326 event.value.driving_status = VEHICLE_DRIVING_STATUS_NO_VIDEO;
327 break;
328 case 2:
329 event.value.driving_status = VEHICLE_DRIVING_STATUS_NO_KEYBOARD_INPUT;
330 break;
331 default:
332 event.value.driving_status = VEHICLE_DRIVING_STATUS_NO_CONFIG;
333 }
334 break;
335 case VEHICLE_PROPERTY_GEAR_SELECTION:
336 event.value_type = VEHICLE_VALUE_TYPE_INT32;
337 switch ((event.timestamp & 0x30000000)>>28) {
338 case 0:
339 event.value.gear_selection = VEHICLE_GEAR_PARKING;
340 break;
341 case 1:
342 event.value.gear_selection = VEHICLE_GEAR_NEUTRAL;
343 break;
344 case 2:
345 event.value.gear_selection = VEHICLE_GEAR_DRIVE;
346 break;
347 case 3:
348 event.value.gear_selection = VEHICLE_GEAR_REVERSE;
349 break;
350 }
351 break;
352 case VEHICLE_PROPERTY_PARKING_BRAKE_ON:
353 event.value_type = VEHICLE_VALUE_TYPE_BOOLEAN;
354 if (event.timestamp & 0x20000000) {
355 event.value.parking_brake = VEHICLE_FALSE;
356 } else {
357 event.value.parking_brake = VEHICLE_TRUE;
358 }
359 break;
360 case VEHICLE_PROPERTY_PERF_VEHICLE_SPEED:
361 event.value_type = VEHICLE_VALUE_TYPE_FLOAT;
362 event.value.vehicle_speed = (float) ((event.timestamp & 0xff000000)>>24);
363 break;
364 case VEHICLE_PROPERTY_RADIO_PRESET:
365 event.value_type = VEHICLE_VALUE_TYPE_INT32_VEC4;
366 int presetInfo1[4] = {1 /* preset number */, 0 /* AM Band */, 1000, 0};
367 int presetInfo2[4] = {2 /* preset number */, 1 /* FM Band */, 1000, 0};
368 if (event.timestamp & 0x20000000) {
369 memcpy(event.value.int32_array, presetInfo1, sizeof(presetInfo1));
370 } else {
371 memcpy(event.value.int32_array, presetInfo2, sizeof(presetInfo2));
372 }
373 break;
374 default: // unsupported
Keun-young Parkbf877a72015-12-21 14:16:05 -0800375 if (sub->impl == NULL) {
376 ALOGE("subscription impl NULL");
377 return;
378 }
Sanket Agarwalfb636682015-08-11 14:34:29 -0700379 if (sub->impl->error_fn_ != NULL) {
380 sub->impl->error_fn_(VEHICLE_ERROR_UNKNOWN, VEHICLE_PROPERTY_INVALID,
381 VEHICLE_OPERATION_GENERIC);
382 } else {
383 ALOGE("Error function is null");
384 }
385 ALOGE("Unsupported prop 0x%x, quit", sub->prop);
386 return;
387 }
388 if (sub->impl->event_fn_ != NULL) {
389 sub->impl->event_fn_(&event);
390 } else {
391 ALOGE("Event function is null");
392 return;
393 }
394 pthread_mutex_lock(&sub->lock);
395 if (sub->stop_thread) {
396 ALOGD("exiting subscription request here.");
397 // Do any cleanup here.
398 pthread_mutex_unlock(&sub->lock);
keunyoung4529d7e2015-11-13 14:58:01 -0800399 return;
Sanket Agarwalfb636682015-08-11 14:34:29 -0700400 }
401 struct timespec now;
402 clock_gettime(CLOCK_REALTIME, &now);
403 now.tv_sec += 1; // sleep for one sec
404 pthread_cond_timedwait(&sub->cond, &sub->lock, &now);
405 pthread_mutex_unlock(&sub->lock);
406 }
407}
408
Keun-young Parkbf877a72015-12-21 14:16:05 -0800409static int vdev_subscribe(vehicle_hw_device_t* device, int32_t prop, float sample_rate,
410 int32_t zones) {
Sanket Agarwalfb636682015-08-11 14:34:29 -0700411 ALOGD("vdev_subscribe 0x%x, %f", prop, sample_rate);
412 vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
413 // Check that the device is initialized.
414 pthread_mutex_lock(&lock_);
415 if (!impl->initialized_) {
416 pthread_mutex_unlock(&lock_);
417 ALOGE("vdev_subscribe: have you called init()?");
418 return -EINVAL;
419 }
420 vehicle_prop_config_t* config = find_config(prop);
421 if (config == NULL) {
422 pthread_mutex_unlock(&lock_);
423 ALOGE("vdev_subscribe not supported property 0x%x", prop);
424 return -EINVAL;
425 }
426 if ((config->access != VEHICLE_PROP_ACCESS_READ) &&
427 (config->access != VEHICLE_PROP_ACCESS_READ_WRITE)) {
428 pthread_mutex_unlock(&lock_);
429 ALOGE("vdev_subscribe read not supported on the property 0x%x", prop);
430 return -EINVAL;
431 }
432 if (config->change_mode == VEHICLE_PROP_CHANGE_MODE_STATIC) {
433 pthread_mutex_unlock(&lock_);
434 ALOGE("vdev_subscribe cannot subscribe static property 0x%x", prop);
435 return -EINVAL;
436 }
437 if ((config->change_mode == VEHICLE_PROP_CHANGE_MODE_ON_CHANGE) && (sample_rate != 0)) {
438 pthread_mutex_unlock(&lock_);
439 ALOGE("vdev_subscribe on change type should have 0 sample rate, property 0x%x, sample rate %f",
440 prop, sample_rate);
441 return -EINVAL;
442 }
443 if ((config->max_sample_rate < sample_rate) || (config->min_sample_rate > sample_rate)) {
444
445 ALOGE("vdev_subscribe property 0x%x, invalid sample rate %f, min:%f, max:%f",
446 prop, sample_rate, config->min_sample_rate, config->max_sample_rate);
447 pthread_mutex_unlock(&lock_);
448 return -EINVAL;
449 }
450 subscription_t* sub = (subscription_t*)config->hal_data;
451 if (sub == NULL) {
452 sub = calloc(1, sizeof(subscription_t));
453 sub->prop = prop;
454 sub->sample_rate = sample_rate;
455 sub->stop_thread = 0;
456 sub->impl = impl;
457 pthread_mutex_init(&sub->lock, NULL);
458 pthread_cond_init(&sub->cond, NULL);
459 config->hal_data = sub;
460 sprintf(sub->name, "vhal0x%x", prop);
461 } else if (sub->sample_rate != sample_rate){ // sample rate changed
462 //TODO notify this to fake sensor thread
463 sub->sample_rate = sample_rate;
464 pthread_mutex_unlock(&lock_);
465 return 0;
466 }
467 int ret_code = pthread_create(
Keun-young Park08c255e2015-12-09 13:47:30 -0800468 &sub->thread, NULL, (void *(*)(void*))fake_event_thread, sub);
Sanket Agarwalfb636682015-08-11 14:34:29 -0700469 print_subscribe_info(impl);
470 pthread_mutex_unlock(&lock_);
471 return 0;
472}
473
474static int vdev_unsubscribe(vehicle_hw_device_t* device, int32_t prop) {
475 ALOGD("vdev_unsubscribe 0x%x", prop);
476 vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
477 pthread_mutex_lock(&lock_);
478 vehicle_prop_config_t* config = find_config(prop);
479 if (config == NULL) {
480 pthread_mutex_unlock(&lock_);
481 return -EINVAL;
482 }
483 subscription_t* sub = (subscription_t*)config->hal_data;
484 if (sub == NULL) {
485 pthread_mutex_unlock(&lock_);
486 return -EINVAL;
487 }
488 config->hal_data = NULL;
489 pthread_mutex_unlock(&lock_);
490 pthread_mutex_lock(&sub->lock);
491 sub->stop_thread = 1;
492 pthread_cond_signal(&sub->cond);
493 pthread_mutex_unlock(&sub->lock);
494 pthread_join(sub->thread, NULL);
495 pthread_cond_destroy(&sub->cond);
496 pthread_mutex_destroy(&sub->lock);
497 free(sub);
498 pthread_mutex_lock(&lock_);
499 print_subscribe_info(impl);
500 pthread_mutex_unlock(&lock_);
501 return 0;
502}
503
504static int vdev_close(hw_device_t* device) {
505 vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
506 if (impl) {
507 free(impl);
508 return 0;
509 } else {
510 return -1;
511 }
512}
513
514/*
515 * The open function is provided as an interface in harwdare.h which fills in
516 * all the information about specific implementations and version specific
517 * informations in hw_device_t structure. After calling open() the client should
518 * use the hw_device_t to execute any Vehicle HAL device specific functions.
519 */
Keun-young Park08c255e2015-12-09 13:47:30 -0800520static int vdev_open(const hw_module_t* module, const char* name UNUSED,
Sanket Agarwalfb636682015-08-11 14:34:29 -0700521 hw_device_t** device) {
522 ALOGD("vdev_open");
523
524 // Oops, out of memory!
525 vehicle_device_impl_t* vdev = calloc(1, sizeof(vehicle_device_impl_t));
526 if (vdev == NULL) {
527 return -ENOMEM;
528 }
529
530 // Common functions provided by harware.h to access module and device(s).
531 vdev->vehicle_device.common.tag = HARDWARE_DEVICE_TAG;
532 vdev->vehicle_device.common.version = VEHICLE_DEVICE_API_VERSION_1_0;
533 vdev->vehicle_device.common.module = (hw_module_t *) module;
534 vdev->vehicle_device.common.close = vdev_close;
535
536 // Define the Vehicle HAL device specific functions.
537 vdev->vehicle_device.list_properties = vdev_list_properties;
538 vdev->vehicle_device.init = vdev_init;
539 vdev->vehicle_device.release = vdev_release;
540 vdev->vehicle_device.get = vdev_get;
541 vdev->vehicle_device.set = vdev_set;
542 vdev->vehicle_device.subscribe = vdev_subscribe;
543 vdev->vehicle_device.unsubscribe = vdev_unsubscribe;
544
545 *device = (hw_device_t *) vdev;
546 return 0;
547}
548
549static struct hw_module_methods_t hal_module_methods = {
550 .open = vdev_open,
551};
552
553/*
554 * This structure is mandatory to be implemented by each HAL implementation. It
555 * exposes the open method (see hw_module_methods_t above) which opens a device.
556 * The vehicle HAL is supposed to be used as a single device HAL hence all the
557 * functions should be implemented inside of the vehicle_hw_device_t struct (see
558 * the vehicle.h in include/ folder.
559 */
560vehicle_module_t HAL_MODULE_INFO_SYM = {
561 .common = {
562 .tag = HARDWARE_MODULE_TAG,
563 .module_api_version = VEHICLE_MODULE_API_VERSION_1_0,
564 .hal_api_version = HARDWARE_HAL_API_VERSION,
565 .id = VEHICLE_HARDWARE_MODULE_ID,
566 .name = "Default vehicle HW HAL",
567 .author = "",
568 .methods = &hal_module_methods,
569 },
570};