Update the VHal emulator protobuf + misc nits

Test: run vhal_emulator_test.py (continues to report same preexisting
errors)

Change-Id: Id02f34a5d9e3961cceb95ad60d473f8a8b0e9e1c
diff --git a/tools/emulator/VehicleHalProto_pb2.py b/tools/emulator/VehicleHalProto_pb2.py
index f972126..aaad547 100644
--- a/tools/emulator/VehicleHalProto_pb2.py
+++ b/tools/emulator/VehicleHalProto_pb2.py
@@ -1,28 +1,20 @@
 # Generated by the protocol buffer compiler.  DO NOT EDIT!
 # source: VehicleHalProto.proto
 
-import sys
-_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
 from google.protobuf.internal import enum_type_wrapper
 from google.protobuf import descriptor as _descriptor
 from google.protobuf import message as _message
 from google.protobuf import reflection as _reflection
-from google.protobuf import symbol_database as _symbol_database
 from google.protobuf import descriptor_pb2
 # @@protoc_insertion_point(imports)
 
-_sym_db = _symbol_database.Default()
-
 
 
 
 DESCRIPTOR = _descriptor.FileDescriptor(
   name='VehicleHalProto.proto',
   package='emulator',
-  syntax='proto2',
-  serialized_pb=_b('\n\x15VehicleHalProto.proto\x12\x08\x65mulator\"\xba\x01\n\x11VehicleAreaConfig\x12\x0f\n\x07\x61rea_id\x18\x01 \x02(\x05\x12\x17\n\x0fmin_int32_value\x18\x02 \x01(\x11\x12\x17\n\x0fmax_int32_value\x18\x03 \x01(\x11\x12\x17\n\x0fmin_int64_value\x18\x04 \x01(\x12\x12\x17\n\x0fmax_int64_value\x18\x05 \x01(\x12\x12\x17\n\x0fmin_float_value\x18\x06 \x01(\x02\x12\x17\n\x0fmax_float_value\x18\x07 \x01(\x02\"\x9b\x02\n\x11VehiclePropConfig\x12\x0c\n\x04prop\x18\x01 \x02(\x05\x12\x0e\n\x06\x61\x63\x63\x65ss\x18\x02 \x01(\x05\x12\x13\n\x0b\x63hange_mode\x18\x03 \x01(\x05\x12\x12\n\nvalue_type\x18\x04 \x01(\x05\x12\x17\n\x0fsupported_areas\x18\x05 \x01(\x05\x12\x31\n\x0c\x61rea_configs\x18\x06 \x03(\x0b\x32\x1b.emulator.VehicleAreaConfig\x12\x14\n\x0c\x63onfig_flags\x18\x07 \x01(\x05\x12\x14\n\x0c\x63onfig_array\x18\x08 \x03(\x05\x12\x15\n\rconfig_string\x18\t \x01(\t\x12\x17\n\x0fmin_sample_rate\x18\n \x01(\x02\x12\x17\n\x0fmax_sample_rate\x18\x0b \x01(\x02\"\xc5\x01\n\x10VehiclePropValue\x12\x0c\n\x04prop\x18\x01 \x02(\x05\x12\x12\n\nvalue_type\x18\x02 \x01(\x05\x12\x11\n\ttimestamp\x18\x03 \x01(\x03\x12\x0f\n\x07\x61rea_id\x18\x04 \x01(\x05\x12\x14\n\x0cint32_values\x18\x05 \x03(\x11\x12\x14\n\x0cint64_values\x18\x06 \x03(\x12\x12\x14\n\x0c\x66loat_values\x18\x07 \x03(\x02\x12\x14\n\x0cstring_value\x18\x08 \x01(\t\x12\x13\n\x0b\x62ytes_value\x18\t \x01(\x0c\"/\n\x0eVehiclePropGet\x12\x0c\n\x04prop\x18\x01 \x02(\x05\x12\x0f\n\x07\x61rea_id\x18\x02 \x01(\x05\"\xd8\x01\n\x0f\x45mulatorMessage\x12#\n\x08msg_type\x18\x01 \x02(\x0e\x32\x11.emulator.MsgType\x12 \n\x06status\x18\x02 \x01(\x0e\x32\x10.emulator.Status\x12&\n\x04prop\x18\x03 \x03(\x0b\x32\x18.emulator.VehiclePropGet\x12+\n\x06\x63onfig\x18\x04 \x03(\x0b\x32\x1b.emulator.VehiclePropConfig\x12)\n\x05value\x18\x05 \x03(\x0b\x32\x1a.emulator.VehiclePropValue*\x8a\x02\n\x07MsgType\x12\x12\n\x0eGET_CONFIG_CMD\x10\x00\x12\x13\n\x0fGET_CONFIG_RESP\x10\x01\x12\x16\n\x12GET_CONFIG_ALL_CMD\x10\x02\x12\x17\n\x13GET_CONFIG_ALL_RESP\x10\x03\x12\x14\n\x10GET_PROPERTY_CMD\x10\x04\x12\x15\n\x11GET_PROPERTY_RESP\x10\x05\x12\x18\n\x14GET_PROPERTY_ALL_CMD\x10\x06\x12\x19\n\x15GET_PROPERTY_ALL_RESP\x10\x07\x12\x14\n\x10SET_PROPERTY_CMD\x10\x08\x12\x15\n\x11SET_PROPERTY_RESP\x10\t\x12\x16\n\x12SET_PROPERTY_ASYNC\x10\n*\xfb\x01\n\x06Status\x12\r\n\tRESULT_OK\x10\x00\x12\x11\n\rERROR_UNKNOWN\x10\x01\x12\x1b\n\x17\x45RROR_UNIMPLEMENTED_CMD\x10\x02\x12\x1a\n\x16\x45RROR_INVALID_PROPERTY\x10\x03\x12\x19\n\x15\x45RROR_INVALID_AREA_ID\x10\x04\x12 \n\x1c\x45RROR_PROPERTY_UNINITIALIZED\x10\x05\x12\x1d\n\x19\x45RROR_WRITE_ONLY_PROPERTY\x10\x06\x12\x1d\n\x19\x45RROR_MEMORY_ALLOC_FAILED\x10\x07\x12\x1b\n\x17\x45RROR_INVALID_OPERATION\x10\x08\x42\x02H\x03')
-)
-_sym_db.RegisterFileDescriptor(DESCRIPTOR)
+  serialized_pb='\n\x15VehicleHalProto.proto\x12\x08\x65mulator\"\xba\x01\n\x11VehicleAreaConfig\x12\x0f\n\x07\x61rea_id\x18\x01 \x02(\x05\x12\x17\n\x0fmin_int32_value\x18\x02 \x01(\x11\x12\x17\n\x0fmax_int32_value\x18\x03 \x01(\x11\x12\x17\n\x0fmin_int64_value\x18\x04 \x01(\x12\x12\x17\n\x0fmax_int64_value\x18\x05 \x01(\x12\x12\x17\n\x0fmin_float_value\x18\x06 \x01(\x02\x12\x17\n\x0fmax_float_value\x18\x07 \x01(\x02\"\x9b\x02\n\x11VehiclePropConfig\x12\x0c\n\x04prop\x18\x01 \x02(\x05\x12\x0e\n\x06\x61\x63\x63\x65ss\x18\x02 \x01(\x05\x12\x13\n\x0b\x63hange_mode\x18\x03 \x01(\x05\x12\x12\n\nvalue_type\x18\x04 \x01(\x05\x12\x17\n\x0fsupported_areas\x18\x05 \x01(\x05\x12\x31\n\x0c\x61rea_configs\x18\x06 \x03(\x0b\x32\x1b.emulator.VehicleAreaConfig\x12\x14\n\x0c\x63onfig_flags\x18\x07 \x01(\x05\x12\x14\n\x0c\x63onfig_array\x18\x08 \x03(\x05\x12\x15\n\rconfig_string\x18\t \x01(\t\x12\x17\n\x0fmin_sample_rate\x18\n \x01(\x02\x12\x17\n\x0fmax_sample_rate\x18\x0b \x01(\x02\"\xc5\x01\n\x10VehiclePropValue\x12\x0c\n\x04prop\x18\x01 \x02(\x05\x12\x12\n\nvalue_type\x18\x02 \x01(\x05\x12\x11\n\ttimestamp\x18\x03 \x01(\x03\x12\x0f\n\x07\x61rea_id\x18\x04 \x01(\x05\x12\x14\n\x0cint32_values\x18\x05 \x03(\x11\x12\x14\n\x0cint64_values\x18\x06 \x03(\x12\x12\x14\n\x0c\x66loat_values\x18\x07 \x03(\x02\x12\x14\n\x0cstring_value\x18\x08 \x01(\t\x12\x13\n\x0b\x62ytes_value\x18\t \x01(\x0c\"/\n\x0eVehiclePropGet\x12\x0c\n\x04prop\x18\x01 \x02(\x05\x12\x0f\n\x07\x61rea_id\x18\x02 \x01(\x05\"\xd8\x01\n\x0f\x45mulatorMessage\x12#\n\x08msg_type\x18\x01 \x02(\x0e\x32\x11.emulator.MsgType\x12 \n\x06status\x18\x02 \x01(\x0e\x32\x10.emulator.Status\x12&\n\x04prop\x18\x03 \x03(\x0b\x32\x18.emulator.VehiclePropGet\x12+\n\x06\x63onfig\x18\x04 \x03(\x0b\x32\x1b.emulator.VehiclePropConfig\x12)\n\x05value\x18\x05 \x03(\x0b\x32\x1a.emulator.VehiclePropValue*\x8a\x02\n\x07MsgType\x12\x12\n\x0eGET_CONFIG_CMD\x10\x00\x12\x13\n\x0fGET_CONFIG_RESP\x10\x01\x12\x16\n\x12GET_CONFIG_ALL_CMD\x10\x02\x12\x17\n\x13GET_CONFIG_ALL_RESP\x10\x03\x12\x14\n\x10GET_PROPERTY_CMD\x10\x04\x12\x15\n\x11GET_PROPERTY_RESP\x10\x05\x12\x18\n\x14GET_PROPERTY_ALL_CMD\x10\x06\x12\x19\n\x15GET_PROPERTY_ALL_RESP\x10\x07\x12\x14\n\x10SET_PROPERTY_CMD\x10\x08\x12\x15\n\x11SET_PROPERTY_RESP\x10\t\x12\x16\n\x12SET_PROPERTY_ASYNC\x10\n*\xfb\x01\n\x06Status\x12\r\n\tRESULT_OK\x10\x00\x12\x11\n\rERROR_UNKNOWN\x10\x01\x12\x1b\n\x17\x45RROR_UNIMPLEMENTED_CMD\x10\x02\x12\x1a\n\x16\x45RROR_INVALID_PROPERTY\x10\x03\x12\x19\n\x15\x45RROR_INVALID_AREA_ID\x10\x04\x12 \n\x1c\x45RROR_PROPERTY_UNINITIALIZED\x10\x05\x12\x1d\n\x19\x45RROR_WRITE_ONLY_PROPERTY\x10\x06\x12\x1d\n\x19\x45RROR_MEMORY_ALLOC_FAILED\x10\x07\x12\x1b\n\x17\x45RROR_INVALID_OPERATION\x10\x08\x42\x02H\x03')
 
 _MSGTYPE = _descriptor.EnumDescriptor(
   name='MsgType',
@@ -80,7 +72,6 @@
   serialized_start=979,
   serialized_end=1245,
 )
-_sym_db.RegisterEnumDescriptor(_MSGTYPE)
 
 MsgType = enum_type_wrapper.EnumTypeWrapper(_MSGTYPE)
 _STATUS = _descriptor.EnumDescriptor(
@@ -131,7 +122,6 @@
   serialized_start=1248,
   serialized_end=1499,
 )
-_sym_db.RegisterEnumDescriptor(_STATUS)
 
 Status = enum_type_wrapper.EnumTypeWrapper(_STATUS)
 GET_CONFIG_CMD = 0
@@ -202,14 +192,14 @@
     _descriptor.FieldDescriptor(
       name='min_float_value', full_name='emulator.VehicleAreaConfig.min_float_value', index=5,
       number=6, type=2, cpp_type=6, label=1,
-      has_default_value=False, default_value=float(0),
+      has_default_value=False, default_value=0,
       message_type=None, enum_type=None, containing_type=None,
       is_extension=False, extension_scope=None,
       options=None),
     _descriptor.FieldDescriptor(
       name='max_float_value', full_name='emulator.VehicleAreaConfig.max_float_value', index=6,
       number=7, type=2, cpp_type=6, label=1,
-      has_default_value=False, default_value=float(0),
+      has_default_value=False, default_value=0,
       message_type=None, enum_type=None, containing_type=None,
       is_extension=False, extension_scope=None,
       options=None),
@@ -221,10 +211,7 @@
   ],
   options=None,
   is_extendable=False,
-  syntax='proto2',
   extension_ranges=[],
-  oneofs=[
-  ],
   serialized_start=36,
   serialized_end=222,
 )
@@ -296,21 +283,21 @@
     _descriptor.FieldDescriptor(
       name='config_string', full_name='emulator.VehiclePropConfig.config_string', index=8,
       number=9, type=9, cpp_type=9, label=1,
-      has_default_value=False, default_value=_b("").decode('utf-8'),
+      has_default_value=False, default_value=unicode("", "utf-8"),
       message_type=None, enum_type=None, containing_type=None,
       is_extension=False, extension_scope=None,
       options=None),
     _descriptor.FieldDescriptor(
       name='min_sample_rate', full_name='emulator.VehiclePropConfig.min_sample_rate', index=9,
       number=10, type=2, cpp_type=6, label=1,
-      has_default_value=False, default_value=float(0),
+      has_default_value=False, default_value=0,
       message_type=None, enum_type=None, containing_type=None,
       is_extension=False, extension_scope=None,
       options=None),
     _descriptor.FieldDescriptor(
       name='max_sample_rate', full_name='emulator.VehiclePropConfig.max_sample_rate', index=10,
       number=11, type=2, cpp_type=6, label=1,
-      has_default_value=False, default_value=float(0),
+      has_default_value=False, default_value=0,
       message_type=None, enum_type=None, containing_type=None,
       is_extension=False, extension_scope=None,
       options=None),
@@ -322,10 +309,7 @@
   ],
   options=None,
   is_extendable=False,
-  syntax='proto2',
   extension_ranges=[],
-  oneofs=[
-  ],
   serialized_start=225,
   serialized_end=508,
 )
@@ -390,14 +374,14 @@
     _descriptor.FieldDescriptor(
       name='string_value', full_name='emulator.VehiclePropValue.string_value', index=7,
       number=8, type=9, cpp_type=9, label=1,
-      has_default_value=False, default_value=_b("").decode('utf-8'),
+      has_default_value=False, default_value=unicode("", "utf-8"),
       message_type=None, enum_type=None, containing_type=None,
       is_extension=False, extension_scope=None,
       options=None),
     _descriptor.FieldDescriptor(
       name='bytes_value', full_name='emulator.VehiclePropValue.bytes_value', index=8,
       number=9, type=12, cpp_type=9, label=1,
-      has_default_value=False, default_value=_b(""),
+      has_default_value=False, default_value="",
       message_type=None, enum_type=None, containing_type=None,
       is_extension=False, extension_scope=None,
       options=None),
@@ -409,10 +393,7 @@
   ],
   options=None,
   is_extendable=False,
-  syntax='proto2',
   extension_ranges=[],
-  oneofs=[
-  ],
   serialized_start=511,
   serialized_end=708,
 )
@@ -447,10 +428,7 @@
   ],
   options=None,
   is_extendable=False,
-  syntax='proto2',
   extension_ranges=[],
-  oneofs=[
-  ],
   serialized_start=710,
   serialized_end=757,
 )
@@ -506,10 +484,7 @@
   ],
   options=None,
   is_extendable=False,
-  syntax='proto2',
   extension_ranges=[],
-  oneofs=[
-  ],
   serialized_start=760,
   serialized_end=976,
 )
@@ -525,45 +500,38 @@
 DESCRIPTOR.message_types_by_name['VehiclePropValue'] = _VEHICLEPROPVALUE
 DESCRIPTOR.message_types_by_name['VehiclePropGet'] = _VEHICLEPROPGET
 DESCRIPTOR.message_types_by_name['EmulatorMessage'] = _EMULATORMESSAGE
-DESCRIPTOR.enum_types_by_name['MsgType'] = _MSGTYPE
-DESCRIPTOR.enum_types_by_name['Status'] = _STATUS
 
-VehicleAreaConfig = _reflection.GeneratedProtocolMessageType('VehicleAreaConfig', (_message.Message,), dict(
-  DESCRIPTOR = _VEHICLEAREACONFIG,
-  __module__ = 'VehicleHalProto_pb2'
+class VehicleAreaConfig(_message.Message):
+  __metaclass__ = _reflection.GeneratedProtocolMessageType
+  DESCRIPTOR = _VEHICLEAREACONFIG
+
   # @@protoc_insertion_point(class_scope:emulator.VehicleAreaConfig)
-  ))
-_sym_db.RegisterMessage(VehicleAreaConfig)
 
-VehiclePropConfig = _reflection.GeneratedProtocolMessageType('VehiclePropConfig', (_message.Message,), dict(
-  DESCRIPTOR = _VEHICLEPROPCONFIG,
-  __module__ = 'VehicleHalProto_pb2'
+class VehiclePropConfig(_message.Message):
+  __metaclass__ = _reflection.GeneratedProtocolMessageType
+  DESCRIPTOR = _VEHICLEPROPCONFIG
+
   # @@protoc_insertion_point(class_scope:emulator.VehiclePropConfig)
-  ))
-_sym_db.RegisterMessage(VehiclePropConfig)
 
-VehiclePropValue = _reflection.GeneratedProtocolMessageType('VehiclePropValue', (_message.Message,), dict(
-  DESCRIPTOR = _VEHICLEPROPVALUE,
-  __module__ = 'VehicleHalProto_pb2'
+class VehiclePropValue(_message.Message):
+  __metaclass__ = _reflection.GeneratedProtocolMessageType
+  DESCRIPTOR = _VEHICLEPROPVALUE
+
   # @@protoc_insertion_point(class_scope:emulator.VehiclePropValue)
-  ))
-_sym_db.RegisterMessage(VehiclePropValue)
 
-VehiclePropGet = _reflection.GeneratedProtocolMessageType('VehiclePropGet', (_message.Message,), dict(
-  DESCRIPTOR = _VEHICLEPROPGET,
-  __module__ = 'VehicleHalProto_pb2'
+class VehiclePropGet(_message.Message):
+  __metaclass__ = _reflection.GeneratedProtocolMessageType
+  DESCRIPTOR = _VEHICLEPROPGET
+
   # @@protoc_insertion_point(class_scope:emulator.VehiclePropGet)
-  ))
-_sym_db.RegisterMessage(VehiclePropGet)
 
-EmulatorMessage = _reflection.GeneratedProtocolMessageType('EmulatorMessage', (_message.Message,), dict(
-  DESCRIPTOR = _EMULATORMESSAGE,
-  __module__ = 'VehicleHalProto_pb2'
+class EmulatorMessage(_message.Message):
+  __metaclass__ = _reflection.GeneratedProtocolMessageType
+  DESCRIPTOR = _EMULATORMESSAGE
+
   # @@protoc_insertion_point(class_scope:emulator.EmulatorMessage)
-  ))
-_sym_db.RegisterMessage(EmulatorMessage)
 
 
 DESCRIPTOR.has_options = True
-DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('H\003'))
+DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), 'H\003')
 # @@protoc_insertion_point(module_scope)
diff --git a/tools/emulator/vhal_emulator.py b/tools/emulator/vhal_emulator.py
index bd9fd20..b8b1e75 100644
--- a/tools/emulator/vhal_emulator.py
+++ b/tools/emulator/vhal_emulator.py
@@ -118,9 +118,9 @@
         # Convert the message length into int32 byte array
         msgHdr = struct.pack('!I', msgLen)
         # Send the message length first
-        self.sock.send(msgHdr)
+        self.sock.sendall(msgHdr)
         # Then send the protobuf
-        self.sock.send(msgStr)
+        self.sock.sendall(msgStr)
 
     ### Public Functions
     def printHex(self, data):
@@ -159,6 +159,8 @@
                     msg = VehicleHalProto_pb2.EmulatorMessage()
                     msg.ParseFromString(b)
                     return msg
+                else:
+                    print("Ignored message fragment")
 
     def getConfig(self, prop):
         """
diff --git a/tools/emulator/vhal_emulator_test.py b/tools/emulator/vhal_emulator_test.py
index 7590783..1d0ada0 100755
--- a/tools/emulator/vhal_emulator_test.py
+++ b/tools/emulator/vhal_emulator_test.py
@@ -21,10 +21,13 @@
 
     Protocol Buffer:
         This module relies on VehicleHalProto_pb2.py being in sync with the protobuf in the VHAL.
-        If the VehicleHalProto.proto file has changed, re-generate the python version using:
-
+        If the VehicleHalProto.proto file has changed, re-generate the python version using
+        a command of the form:
             protoc -I=<proto_dir> --python_out=<out_dir> <proto_dir>/VehicleHalProto.proto
-            protoc -I=proto --python_out=proto proto/VehicleHalProto.proto
+        For example:
+            protoDir=~/android/master/hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/proto
+            outDir=~/android/master/packages/services/Car/tools/emulator
+            protoc -I=$protoDir --python_out=$outDir $protoDir/VehicleHalProto.proto
 """
 
 from __future__ import print_function