Merge "Script to automatically generate vhal_consts_ for use in the emulator"
diff --git a/tools/emulator/vhal_const_generate.py b/tools/emulator/vhal_const_generate.py
new file mode 100755
index 0000000..dd9e3e6
--- /dev/null
+++ b/tools/emulator/vhal_const_generate.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python3.4
+#
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This script generates vhal_consts_x_y.py files for use in vhal_emulator
+# They are generated from corresponding data in Vehicle HAL types.hal files
+# To run, invoke at a shell by saying:
+# $ packages/services/Car/tools/emulator/vhal_const_generate.py
+# The script will automatically locate itself and the required HAL files and will write next
+# to itself vhal_consts_x.y.py for any version of Vehicle HAL that it knows about
+# Those files can then be used with vhal_emulator.py as per that script's documentation
+
+import datetime
+
+def printHeader(dest):
+ year = datetime.datetime.now().year
+ print("# Copyright (C) %s The Android Open Source Project" % year, file=dest)
+ print("#", file=dest)
+ print("# Licensed under the Apache License, Version 2.0 (the \"License\");", file=dest)
+ print("# you may not use this file except in compliance with the License.", file=dest)
+ print("# You may obtain a copy of the License at", file=dest)
+ print("#", file=dest)
+ print("# http://www.apache.org/licenses/LICENSE-2.0", file=dest)
+ print("#", file=dest)
+ print("# Unless required by applicable law or agreed to in writing, software", file=dest)
+ print("# distributed under the License is distributed on an \"AS IS\" BASIS,", file=dest)
+ print("# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", file=dest)
+ print("# See the License for the specific language governing permissions and", file=dest)
+ print("# limitations under the License.", file=dest)
+ print("#", file=dest)
+ print("# DO NOT EDIT MANUALLY", file=dest)
+ print("# This file was autogenerated by vhal_const_generate.py", file=dest)
+
+def printEnum(doc, name, prefix, dest, postprocess=lambda x: x):
+ enum_object = doc['enums'][name]
+ print("\n# %s" % name, file=dest)
+ for case in enum_object.cases:
+ print('%s%s = %s' % (prefix, case.name,
+ postprocess(case.value.resolve(enum_object, doc))),
+ file=dest)
+
+import os, os.path
+import sys
+
+script_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)))
+parent_location = os.path.abspath(os.path.join(script_directory, '..'))
+sys.path.append(parent_location)
+
+from hidl_parser import parser
+
+android_build_top = os.environ.get("ANDROID_BUILD_TOP", None)
+if android_build_top is not None:
+ vhal_location = os.path.join(android_build_top, 'hardware','interfaces','automotive','vehicle')
+else:
+ vhal_location = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),
+ '..','..','..','..','..','hardware','interfaces','automotive','vehicle'
+ ))
+if not(os.path.exists(vhal_location) and os.path.isdir(vhal_location)):
+ print("Vehicle HAL was not found at %s. lunch may provide a correct environment, or files moved" % vhal_location)
+ sys.exit(1)
+
+vhal_20_file = os.path.join(vhal_location, '2.0', 'types.hal')
+vhal_21_file = os.path.join(vhal_location, '2.1', 'types.hal')
+
+print("Generating content from Vehicle HAL 2.0 (%s) and 2.1 (%s)" % (vhal_20_file, vhal_21_file))
+
+vhal_20_doc = parser.parse(vhal_20_file)
+vhal_21_doc = parser.parse(vhal_21_file)
+vhal_21_doc['enums']['VehiclePropertyGroup'] = vhal_20_doc['enums']['VehiclePropertyGroup']
+vhal_21_doc['enums']['VehiclePropertyType'] = vhal_20_doc['enums']['VehiclePropertyType']
+vhal_21_doc['enums']['VehicleArea'] = vhal_20_doc['enums']['VehicleArea']
+
+def generateHal20():
+ vhal_20_file = open(os.path.join(script_directory, 'vhal_consts_2_0.py'), 'w')
+
+ printHeader(vhal_20_file)
+ printEnum(vhal_20_doc, 'VehicleProperty', 'VEHICLE_PROPERTY_', vhal_20_file)
+ printEnum(vhal_20_doc, 'VehiclePropertyType', 'VEHICLE_VALUE_TYPE_', vhal_20_file, lambda x : hex(x))
+ printEnum(vhal_20_doc, 'VehicleAreaZone', 'VEHICLE_ZONE_', vhal_20_file, lambda x : hex(x))
+
+ print("\n# Create a container of value_type constants to be used by vhal_emulator", file=vhal_20_file)
+ print("class vhal_types_2_0:", file=vhal_20_file)
+ print(" TYPE_STRING = [VEHICLE_VALUE_TYPE_STRING]", file=vhal_20_file)
+ print(" TYPE_BYTES = [VEHICLE_VALUE_TYPE_BYTES]", file=vhal_20_file)
+ print(" TYPE_INT32 = [VEHICLE_VALUE_TYPE_BOOLEAN,", file=vhal_20_file)
+ print(" VEHICLE_VALUE_TYPE_INT32]", file=vhal_20_file)
+ print(" TYPE_INT64 = [VEHICLE_VALUE_TYPE_INT64]", file=vhal_20_file)
+ print(" TYPE_FLOAT = [VEHICLE_VALUE_TYPE_FLOAT]", file=vhal_20_file)
+ print(" TYPE_INT32S = [VEHICLE_VALUE_TYPE_INT32_VEC]", file=vhal_20_file)
+ print(" TYPE_FLOATS = [VEHICLE_VALUE_TYPE_FLOAT_VEC]", file=vhal_20_file)
+ print(" TYPE_COMPLEX = [VEHICLE_VALUE_TYPE_COMPLEX]", file=vhal_20_file)
+
+def generateHal21():
+ vhal_21_file = open(os.path.join(script_directory, 'vhal_consts_2_1.py'), 'w')
+ printHeader(vhal_21_file)
+ print('from vhal_consts_2_0 import *', file=vhal_21_file)
+ printEnum(vhal_21_doc, 'VehicleProperty', 'VEHICLE_PROPERTY_', vhal_21_file)
+
+generateHal20()
+generateHal21()
diff --git a/tools/emulator/vhal_consts_2_0.py b/tools/emulator/vhal_consts_2_0.py
index c33a198..8c7d037 100644
--- a/tools/emulator/vhal_consts_2_0.py
+++ b/tools/emulator/vhal_consts_2_0.py
@@ -1,10 +1,10 @@
-# Copyright 2017 Google Inc.
+# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -12,25 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+# DO NOT EDIT MANUALLY
+# This file was autogenerated by vhal_const_generate.py
-"""
- This file contains constants defined in hardware/interfaces/vehicle/2.0/types.hal
-
- Constants in this file are parsed from:
- out/soong/.intermediates/hardware/interfaces/automotive/vehicle/2.0/android.hardware.automotive.vehicle@2.0_genc++_headers/gen/android/hardware/automotive/vehicle/2.0/types.h
-
- Currently, there is no script to auto-generate this constants file. The file is generated by
- copying enum fields into an editor and running a macro to format it. The elements being used
- are shown in the following table:
-
- type.h file: this file:
- VehiclePropertyType enum --> VEHICLE_VALUE_TYPE_*
- VehicleProperty enum --> VEHICLE_PROPERTY_*
- VehicleAreaZone enum --> VEHICLE_ZONE_*
- VehiclePropertyType enum --> class vhal_types_2_0
-"""
-
-# Vehicle Property ID
+# VehicleProperty
+VEHICLE_PROPERTY_INVALID = 0
VEHICLE_PROPERTY_INFO_VIN = 286261504
VEHICLE_PROPERTY_INFO_MAKE = 286261505
VEHICLE_PROPERTY_INFO_MODEL = 286261506
@@ -80,7 +66,7 @@
VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_HINT = 289474821
VEHICLE_PROPERTY_AUDIO_STREAM_STATE = 289474822
VEHICLE_PROPERTY_AUDIO_PARAMETERS = 286263559
-VEHICLE_PROPERTY_AP_POWER_STATE = 2560
+VEHICLE_PROPERTY_AP_POWER_STATE = 289475072
VEHICLE_PROPERTY_DISPLAY_BRIGHTNESS = 289409537
VEHICLE_PROPERTY_AP_POWER_BOOTUP_REASON = 289409538
VEHICLE_PROPERTY_HW_KEY_INPUT = 289475088
@@ -128,39 +114,37 @@
VEHICLE_PROPERTY_WINDOW_VENT_POS = 289409986
VEHICLE_PROPERTY_WINDOW_VENT_MOVE = 289409987
VEHICLE_PROPERTY_WINDOW_LOCK = 287312836
-VEHICLE_PROPERTY_VEHICLE_MAPS_DATA_SERVICE = 299895808
-VEHICLE_PROPERTY_OBD2_LIVE_FRAME = 299896064
-VEHICLE_PROPERTY_OBD2_FREEZE_FRAME = 299896065
-# Vehicle Value Type
-VEHICLE_VALUE_TYPE_STRING = 0x00100000
-VEHICLE_VALUE_TYPE_BOOLEAN = 0x00200000
-VEHICLE_VALUE_TYPE_INT32 = 0x00400000
-VEHICLE_VALUE_TYPE_INT32_VEC = 0x00410000
-VEHICLE_VALUE_TYPE_INT64 = 0x00500000
-VEHICLE_VALUE_TYPE_FLOAT = 0x00600000
-VEHICLE_VALUE_TYPE_FLOAT_VEC = 0x00610000
-VEHICLE_VALUE_TYPE_BYTES = 0x00700000
-VEHICLE_VALUE_TYPE_COMPLEX = 0x00E00000
+# VehiclePropertyType
+VEHICLE_VALUE_TYPE_STRING = 0x100000
+VEHICLE_VALUE_TYPE_BOOLEAN = 0x200000
+VEHICLE_VALUE_TYPE_INT32 = 0x400000
+VEHICLE_VALUE_TYPE_INT32_VEC = 0x410000
+VEHICLE_VALUE_TYPE_INT64 = 0x500000
+VEHICLE_VALUE_TYPE_FLOAT = 0x600000
+VEHICLE_VALUE_TYPE_FLOAT_VEC = 0x610000
+VEHICLE_VALUE_TYPE_BYTES = 0x700000
+VEHICLE_VALUE_TYPE_COMPLEX = 0xe00000
+VEHICLE_VALUE_TYPE_MASK = 0xff0000
-# Vehicle zone / area definitions
-VEHICLE_ZONE_ROW_1_LEFT = 0x00000001
-VEHICLE_ZONE_ROW_1_CENTER = 0x00000002
-VEHICLE_ZONE_ROW_1_RIGHT = 0x00000004
-VEHICLE_ZONE_ROW_1_ALL = 0x00000008
-VEHICLE_ZONE_ROW_2_LEFT = 0x00000010
-VEHICLE_ZONE_ROW_2_CENTER = 0x00000020
-VEHICLE_ZONE_ROW_2_RIGHT = 0x00000040
-VEHICLE_ZONE_ROW_2_ALL = 0x00000080
-VEHICLE_ZONE_ROW_3_LEFT = 0x00000100
-VEHICLE_ZONE_ROW_3_CENTER = 0x00000200
-VEHICLE_ZONE_ROW_3_RIGHT = 0x00000400
-VEHICLE_ZONE_ROW_3_ALL = 0x00000800
-VEHICLE_ZONE_ROW_4_LEFT = 0x00001000
-VEHICLE_ZONE_ROW_4_CENTER = 0x00002000
-VEHICLE_ZONE_ROW_4_RIGHT = 0x00004000
-VEHICLE_ZONE_ROW_4_ALL = 0x00008000
-VEHICLE_ZONE_ALL = 0x80000000
+# VehicleAreaZone
+VEHICLE_ZONE_ROW_1_LEFT = 0x1
+VEHICLE_ZONE_ROW_1_CENTER = 0x2
+VEHICLE_ZONE_ROW_1_RIGHT = 0x4
+VEHICLE_ZONE_ROW_1 = 0x8
+VEHICLE_ZONE_ROW_2_LEFT = 0x10
+VEHICLE_ZONE_ROW_2_CENTER = 0x20
+VEHICLE_ZONE_ROW_2_RIGHT = 0x40
+VEHICLE_ZONE_ROW_2 = 0x80
+VEHICLE_ZONE_ROW_3_LEFT = 0x100
+VEHICLE_ZONE_ROW_3_CENTER = 0x200
+VEHICLE_ZONE_ROW_3_RIGHT = 0x400
+VEHICLE_ZONE_ROW_3 = 0x800
+VEHICLE_ZONE_ROW_4_LEFT = 0x1000
+VEHICLE_ZONE_ROW_4_CENTER = 0x2000
+VEHICLE_ZONE_ROW_4_RIGHT = 0x4000
+VEHICLE_ZONE_ROW_4 = 0x8000
+VEHICLE_ZONE_WHOLE_CABIN = 0x80000000
# Create a container of value_type constants to be used by vhal_emulator
class vhal_types_2_0:
diff --git a/tools/emulator/vhal_consts_2_1.py b/tools/emulator/vhal_consts_2_1.py
new file mode 100644
index 0000000..72f48ef
--- /dev/null
+++ b/tools/emulator/vhal_consts_2_1.py
@@ -0,0 +1,25 @@
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# DO NOT EDIT MANUALLY
+# This file was autogenerated by vhal_const_generate.py
+from vhal_consts_2_0 import *
+
+# VehicleProperty
+VEHICLE_PROPERTY_WHEEL_TICK = 291570438
+VEHICLE_PROPERTY_OBD2_LIVE_FRAME = 299896064
+VEHICLE_PROPERTY_OBD2_FREEZE_FRAME = 299896065
+VEHICLE_PROPERTY_OBD2_FREEZE_FRAME_INFO = 299896066
+VEHICLE_PROPERTY_OBD2_FREEZE_FRAME_CLEAR = 299896067
+VEHICLE_PROPERTY_VEHICLE_MAP_SERVICE = 299895808