2 * Copyright (c) 2013, Ford Motor Company All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * · Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * · Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * · Neither the name of the Ford Motor Company nor the names of its
12 * contributors may be used to endorse or promote products derived from this
13 * software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
28 * Reference implementation of VehicleInfo component.
30 * Interface to get or set some essential information sent from SDLCore.
31 * VehicleInfo is responsible for sending a data about the condition of the
32 * vehicle between SDLCore and CAN network. Instead CAN network used
37 FFW.VehicleInfo = FFW.RPCObserver.create( {
40 * access to basic RPC functionality
42 client: FFW.RPCClient.create( {
43 componentName: "VehicleInfo"
50 this.client.connect( this, 600 );
54 * disconnect from RPC bus
56 disconnect: function() {
57 this.client.disconnect();
61 * Client is registered - we can send request starting from this point of
64 onRPCRegistered: function() {
65 Em.Logger.log( "FFW.VehicleInfo.onRPCRegistered" );
70 * Client is unregistered - no more requests
72 onRPCUnregistered: function() {
73 Em.Logger.log( "FFW.VehicleInfo.onRPCUnregistered" );
78 * Client disconnected.
80 onRPCDisconnected: function() {
85 * when result is received from RPC component this function is called It is
86 * the propriate place to check results of reuqest execution Please use
87 * previously store reuqestID to determine to which request repsonse belongs
90 onRPCResult: function( response ) {
91 Em.Logger.log( "FFW.VehicleInfo.onRPCResult" );
96 * handle RPC erros here
98 onRPCError: function( error ) {
99 Em.Logger.log( "FFW.VehicleInfo.onRPCError" );
104 * handle RPC notifications here
106 onRPCNotification: function( notification ) {
107 Em.Logger.log( "FFW.VehicleInfo.onRPCNotification" );
112 * handle RPC requests here
114 * @type {Object} request
116 onRPCRequest: function( request ) {
117 Em.Logger.log( "FFW.VehicleInfo.onRPCRequest" );
120 if( request.method == "VehicleInfo.GetVehicleData" ){
122 var vehicleData = SDL.SDLVehicleInfoModel.getVehicleData( request.params ), resultCode;
125 resultCode = "SUCCESS";
127 resultCode = "GENERIC_ERROR";
135 "resultCode": resultCode, // type (enum) from SDL protocol
136 "method": "VehicleInfo.GetVehicleDataResponse"
137 // request.params.dataType: vehicleData
140 JSONMessage.result[SDL.SDLVehicleInfoModel.vehicleData[request.params.dataType].type] = vehicleData;
141 this.client.send( JSONMessage );
144 if( request.method == "VehicleInfo.ReadDID" ){
146 SDL.SDLVehicleInfoModel.vehicleInfoReadDID( request.params, request.id );
150 if( request.method == "VehicleInfo.GetDTCs" ){
152 SDL.SDLVehicleInfoModel.vehicleInfoGetDTCs( request.params, request.id );
156 if( request.method == "VehicleInfo.GetVehicleType" ){
158 SDL.SDLVehicleInfoModel.getVehicleType( request.id );
164 * Notifies if data was changed
166 * @type {Object} params
168 OnVehicleData: function( params ) {
169 Em.Logger.log( "FFW.VehicleInfo.OnVehicleData" );
174 "method": "VehicleInfo.OnVehicleData",
177 this.client.send( JSONMessage );
181 * GetVehicleType Response
183 * @type {string} vehicleType
186 GetVehicleTypeResponse: function( vehicleType, id ) {
187 Em.Logger.log( "FFW.VehicleInfo.GetVehicleType" );
193 "resultCode": "SUCCESS", // type (enum) from SDL protocol
194 "method": "VehicleInfo.GetVehicleTypeResponse",
195 "vehicleType": vehicleType
199 this.client.send( JSONMessage );
205 * @type {array} dataResult
207 * @type {string} info
208 * @type {string} result
211 vehicleInfoReadDIDResponse: function( dataResult, data, info, result, id ) {
212 Em.Logger.log( "FFW.VehicleInfo.ReadDID" );
216 if( result != 'ENCRYPTED' ){
221 "resultCode": result, // type (enum) from SDL protocol
222 "method": "VehicleInfo.ReadDIDResponse",
224 "dataResult": dataResult,
233 "resultCode": result, // type (enum) from SDL protocol
234 "method": "VehicleInfo.ReadDIDResponse",
239 this.client.send( JSONMessage );
246 * @type {string} info
247 * @type {string} result
250 vehicleInfoGetDTCsResponse: function( data, info, result, id ) {
251 Em.Logger.log( "FFW.VehicleInfo.GetDTCs" );
255 if( result != 'ENCRYPTED' ){
260 "resultCode": result, // type (enum) from SDL protocol
261 "method": "VehicleInfo.GetDTCsResponse",
271 "resultCode": result, // type (enum) from SDL protocol
272 "method": "VehicleInfo.GetDTCsResponse",
277 this.client.send( JSONMessage );