1# VHAL Host Emulator 2This is a collection of python modules as tools for VHAL development. 3 4[TOC] 5 6## vhal_emulator.py 7This allow you to create script to interate with the Vehicle HAL in an AAOS 8device from a host. 9 10* It sends and receives messages to/from the Vehicle HAL via port forwarding 11over ADB to communicate with the AAOS device. 12* On the device side, VHAL module VehicleService creates VehicleEmulator to 13setup SocketComm to serve the requests. 14 * hardware/interfaces/automotive/vehicle/2.0/default/VehicleService.cpp 15 * hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/VehicleEmulator.cpp 16 * hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/SocketComm.cpp 17* vhal_emulator_test.py tests the Vehicle HAL via adb socket. 18 * Note: This may outdated becuase there is no dedicated resrouce. Contribution is welcome. 19 20## vhal_const_generate.py 21This generates vhal_consts_2_0.py to update definitions for property ID, value 22type, zone, etc. from the types.hal. Run this script whenever types.hal is 23changed. 24 25* Must re-generate when the types.hal file changes. 26 27``` 28packages/services/Car/tools/emulator/vhal_const_generate.py 29``` 30 31* hardware/interfaces/automotive/vehicle/2.0/types.hal 32 33## VehicleHalProto_pb2.py 34This defines message interface to VHAL Emulator from VehicleHalProto.proto. 35 36* Must re-generate whenever the proto file changes. 37* Generated from hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto/VehicleHalProto.proto 38 39``` 40protoDir=$ANDROID_BUILD_TOP/hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto 41outDir=$ANDROID_BUILD_TOP/packages/services/Car/tools/emulator 42# or protoc if perferred 43aprotoc -I=$protoDir --python_out=$outDir $protoDir/VehicleHalProto.proto 44 45``` 46 47* It requires Protocol Buffers. You may build one from Android, e.g. 48 49``` 50. build/envsetup.sh 51lunch sdk_gcar_x86-userdebug 52m aprotoc -j16 53``` 54 55 56## OBD2 Diagnostic Injector 57These scripts are useful for testing the Diagnostics API 58 59### diagnostic_builder.py 60 61* Helper class used by diagnostic_injector.py 62* Stores diagnostic sensor values and bitmasks 63* VehiclePropValue-compatible 64 65### diagnostic_injector.py 66 67* Deserializes JSON into diagnostic events 68* Sends over HAL Emulator Interface 69* Diagnostic JSON Format example: diagjson.example 70 71``` 72./diagnostic_injector.py ./diagjson.example 73``` 74 75## Python GUI Example 76gui.py is an example to create an GUI to set the property. 77 78* packages/services/Car/tools/emulator/gui.py 79* GUI runs on host machine (PyQt4-based widgets) 80* Drives VHAL on target 81 * Works only with default VHAL 82 * Interactions generate SET messages 83* Supports bench testing of apps 84* Easy to add support for more properties 85