#NEWLINE# @ classmethod #NEWLINE# def _dict_to_protobuf( cls , data ) : #NEWLINE# #INDENT# message = openxc_pb2 . VehicleMessage ( ) #NEWLINE# if ( 'command' in data ) : #NEWLINE# #INDENT# command_name = data [ 'command' ] #NEWLINE# message . type = openxc_pb2 . VehicleMessage . CONTROL_COMMAND #NEWLINE# message . control_command . type = cls . _command_string_to_protobuf ( command_name ) #NEWLINE# if ( message . control_command . type == openxc_pb2 . ControlCommand . PASSTHROUGH ) : #NEWLINE# #INDENT# message . control_command . passthrough_mode_request . bus = data [ 'bus' ] #NEWLINE# message . control_command . passthrough_mode_request . enabled = data [ 'enabled' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( message . control_command . type == openxc_pb2 . ControlCommand . ACCEPTANCE_FILTER_BYPASS ) : #NEWLINE# #INDENT# message . control_command . acceptance_filter_bypass_command . bus = data [ 'bus' ] #NEWLINE# message . control_command . acceptance_filter_bypass_command . bypass = data [ 'bypass' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( message . control_command . type == openxc_pb2 . ControlCommand . PREDEFINED_OBD2_REQUESTS ) : #NEWLINE# #INDENT# message . control_command . predefined_obd2_requests_command . enabled = data [ 'enabled' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( message . control_command . type == openxc_pb2 . ControlCommand . PAYLOAD_FORMAT ) : #NEWLINE# #INDENT# if ( data [ 'format' ] == 'json' ) : #NEWLINE# #INDENT# message . control_command . payload_format_command . format = openxc_pb2 . PayloadFormatCommand . JSON #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( data [ 'format' ] == 'protobuf' ) : #NEWLINE# #INDENT# message . control_command . payload_format_command . format = openxc_pb2 . PayloadFormatCommand . PROTOBUF #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( message . control_command . type == openxc_pb2 . ControlCommand . DIAGNOSTIC ) : #NEWLINE# #INDENT# request_command = message . control_command . diagnostic_request #NEWLINE# action = data [ 'action' ] #NEWLINE# if ( action == 'add' ) : #NEWLINE# #INDENT# request_command . action = openxc_pb2 . DiagnosticControlCommand . ADD #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( action == 'cancel' ) : #NEWLINE# #INDENT# request_command . action = openxc_pb2 . DiagnosticControlCommand . CANCEL #NEWLINE# #UNINDENT# #UNINDENT# request = request_command . request #NEWLINE# request_data = data [ 'request' ] #NEWLINE# request . bus = request_data [ 'bus' ] #NEWLINE# request . message_id = request_data [ 'id' ] #NEWLINE# request . mode = request_data [ 'mode' ] #NEWLINE# if ( 'frequency' in request_data ) : #NEWLINE# #INDENT# request . frequency = request_data [ 'frequency' ] #NEWLINE# #UNINDENT# if ( 'name' in request_data ) : #NEWLINE# #INDENT# request . name = request_data [ 'name' ] #NEWLINE# #UNINDENT# if ( 'multiple_responses' in request_data ) : #NEWLINE# #INDENT# request . multiple_responses = request_data [ 'multiple_responses' ] #NEWLINE# #UNINDENT# if ( 'pid' in request_data ) : #NEWLINE# #INDENT# request . pid = request_data [ 'pid' ] #NEWLINE# #UNINDENT# if ( 'payload' in request_data ) : #NEWLINE# #INDENT# request . payload = binascii . unhexlify ( request_data [ 'payload' ] . split ( '0x' ) [ 1 ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'command_response' in data ) : #NEWLINE# #INDENT# message . type = openxc_pb2 . VehicleMessage . COMMAND_RESPONSE #NEWLINE# message . command_response . type = cls . _command_string_to_protobuf ( data [ 'command_response' ] ) #NEWLINE# if ( 'message' in data ) : #NEWLINE# #INDENT# message . command_response . message = data [ 'message' ] #NEWLINE# #UNINDENT# message . command_response . status = data [ 'status' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( 'id' in data ) and ( 'data' in data ) ) : #NEWLINE# #INDENT# message . type = openxc_pb2 . VehicleMessage . CAN #NEWLINE# if ( 'bus' in data ) : #NEWLINE# #INDENT# message . can_message . bus = data [ 'bus' ] #NEWLINE# #UNINDENT# if ( 'frame_format' in data ) : #NEWLINE# #INDENT# if ( data [ 'frame_format' ] == 'standard' ) : #NEWLINE# #INDENT# message . can_message . frame_format = openxc_pb2 . RawMessage . STANDARD #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( data [ 'frame_format' ] == 'extended' ) : #NEWLINE# #INDENT# message . can_message . frame_format = openxc_pb2 . RawMessage . EXTENDED #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# message . can_message . id = data [ 'id' ] #NEWLINE# message . can_message . data = binascii . unhexlify ( data [ 'data' ] . split ( '0x' ) [ 1 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( 'id' in data ) and ( 'bus' in data ) and ( 'mode' in data ) ) : #NEWLINE# #INDENT# message . type = openxc_pb2 . VehicleMessage . DIAGNOSTIC #NEWLINE# response = message . diagnostic_response #NEWLINE# response . bus = data [ 'bus' ] #NEWLINE# response . message_id = data [ 'id' ] #NEWLINE# response . mode = data [ 'mode' ] #NEWLINE# if ( 'pid' in data ) : #NEWLINE# #INDENT# response . pid = data [ 'pid' ] #NEWLINE# #UNINDENT# if ( 'success' in command_name ) : #NEWLINE# #INDENT# response . success = data [ 'success' ] #NEWLINE# #UNINDENT# if ( 'negative_response_code' in data ) : #NEWLINE# #INDENT# response . negative_response_code = data [ 'negative_response_code' ] #NEWLINE# #UNINDENT# if ( 'value' in data ) : #NEWLINE# #INDENT# response . value = data [ 'value' ] #NEWLINE# #UNINDENT# if ( 'payload' in data ) : #NEWLINE# #INDENT# response . payload = binascii . unhexlify ( data [ 'payload' ] . split ( '0x' ) [ 1 ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( 'name' in data ) and ( 'value' in data ) ) : #NEWLINE# #INDENT# message . type = openxc_pb2 . VehicleMessage . SIMPLE #NEWLINE# message . simple_message . name = data [ 'name' ] #NEWLINE# value = data [ 'value' ] #NEWLINE# if isinstance ( value , bool ) : #NEWLINE# #INDENT# message . simple_message . value . type = openxc_pb2 . DynamicField . BOOL #NEWLINE# message . simple_message . value . boolean_value = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , str ) : #NEWLINE# #INDENT# message . simple_message . value . type = openxc_pb2 . DynamicField . STRING #NEWLINE# message . simple_message . value . string_value = value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( value , numbers . Number ) : #NEWLINE# #INDENT# message . simple_message . value . type = openxc_pb2 . DynamicField . NUM #NEWLINE# message . simple_message . value . numeric_value = value #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( 'event' in data ) : #NEWLINE# #INDENT# event = data [ 'event' ] #NEWLINE# if isinstance ( event , bool ) : #NEWLINE# #INDENT# message . simple_message . event . type = openxc_pb2 . DynamicField . BOOL #NEWLINE# message . simple_message . event . boolean_value = event #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( event , str ) : #NEWLINE# #INDENT# message . simple_message . event . type = openxc_pb2 . DynamicField . STRING #NEWLINE# message . simple_message . event . string_value = event #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( event , numbers . Number ) : #NEWLINE# #INDENT# message . simple_message . event . type = openxc_pb2 . DynamicField . NUM #NEWLINE# message . simple_message . event . numeric_value = event #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return message