Add Modello web sample applications; version up
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / Modello_SDL / project / app / model / sdl / VehicleInfoModel.js
1 /*
2  * Copyright (c) 2013, Ford Motor Company All rights reserved.
3  *
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.
14  *
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.
26  */
27 /**
28  * @name SDL.SDLVehicleInfoModel
29  * @desc SDL model with vehicle information used instead of CAN network.
30  *       VehicleInfoModel is simulation of real CAN network.
31  * @category Model
32  * @filesource app/model/sdl/SDLVehicleInfoModel.js
33  * @version 1.0
34  */
35
36 SDL.SDLVehicleInfoModel = Em.Object.create( {
37
38     /**
39      * Stored VehicleInfo transmission state Data
40      *
41      * @type {Array}
42      */
43     vehicleInfoPRNDL:
44         [
45             "PARK",
46             "REVERSE",
47             "NEUTRAL",
48             "FORWARD_DRIVE_2",
49             "LOWGEAR"
50         ],
51
52     /**
53      * PRNDL state value
54      *
55      * @type {String}
56      */
57     prndlSelectState: 'PARK',
58
59     /**
60      * Stored VehicleInfo Data
61      *
62      * @type {Array}
63      */
64     ecuDIDData:
65         [
66             {
67                 'data': "ECU 1 Test Data"
68             },
69             {
70                 'data': "ECU 2 Test Data"
71             }
72         ],
73
74     /**
75      * Type of current vehicle: make of the vehicle, model of the vehicle, model
76      * Year of the vehicle, trim of the vehicle.
77      *
78      * @type {Object}
79      */
80     vehicleType: {
81         make: "Ford",
82         model: "Fiesta",
83         modelYear: "2013",
84         trim: "SE"
85     },
86
87     /**
88      * Stored VehicleInfo Data
89      *
90      * @type {Object}
91      */
92     vehicleData: {
93         'VEHICLEDATA_SPEED': {
94             data: 80.0,
95             type: 'speed'
96         },
97         'VEHICLEDATA_ENGINERPM': {
98             data: 5000,
99             type: 'rpm'
100         },
101         'VEHICLEDATA_FUELLEVEL': {
102             data: 0.2,
103             type: 'fuelLevel'
104         },
105         'VEHICLEDATA_FUELECONOMY': {
106             data: 0.1,
107             type: 'avgFuelEconomy'
108         },
109         'VEHICLEDATA_BATTVOLTS': {
110             data: 12.5,
111             type: 'batteryVoltage'
112         },
113         'VEHICLEDATA_EXTERNTEMP': {
114             data: 40.0,
115             type: 'externalTemperature'
116         },
117         'VEHICLEDATA_VIN': {
118             data: '52-452-52-752',
119             type: 'vin'
120         },
121         'VEHICLEDATA_PRNDLSTATUS': {
122             data: 'PARK',
123             type: 'prndl'
124         },
125         'VEHICLEDATA_BATTERYPACKVOLTAGE': {
126             data: 12.5,
127             type: 'batteryPackVoltage'
128         },
129         'VEHICLEDATA_BATTERYCURRENT': {
130             data: 7.0,
131             type: 'batteryPackCurrent'
132         },
133         'VEHICLEDATA_BATTERYTEMPERATURE': {
134             data: 30,
135             type: 'batteryPackTemperature'
136         },
137         'VEHICLEDATA_ENGINETORQUE': {
138             data: 650,
139             type: 'engineTorque'
140         },
141         'VEHICLEDATA_ODOMETER': {
142             data: 0,
143             type: 'odometer'
144         },
145         'VEHICLEDATA_TRIPODOMETER': {
146             data: 0,
147             type: 'tripOdometer'
148         },
149         'VEHICLEDATA_GENERICBINARY': {
150             data: '165165650',
151             type: 'genericbinary'
152         },
153         'VEHICLEDATA_SATESN': {
154             data: "165165650",
155             type: 'satRadioESN'
156         },
157         'VEHICLEDATA_RAINSENSOR': {
158             data: 165165650,
159             type: 'rainSensor'
160         },
161         'VEHICLEDATA_GPS': {
162             data: {
163                 'longitudeDegrees': 423293,
164                 'latitudeDegrees': -830464,
165                 'utcYear': 2013,
166                 'utcMonth': 2,
167                 'utcDay': 14,
168                 'utcHours': 13,
169                 'utcMinutes': 16,
170                 'utcSeconds': 54,
171                 'compassDirection': 'SOUTHWEST',
172                 'pdop': 15,
173                 'hdop': 5,
174                 'vdop': 30,
175                 'actual': false,
176                 'satellites': 8,
177                 'dimension': '2D',
178                 'altitude': 7,
179                 'heading': 173,
180                 'speed': 2
181             },
182             type: 'gps'
183         }
184     },
185
186     /**
187      * Method to set selected state of vehicle transmission to vehicleData
188      */
189     onPRNDLSelected: function() {
190         if( this.prndlSelectState ) {
191             this.set( 'vehicleData.VEHICLEDATA_PRNDLSTATUS.data', this.prndlSelectState );
192         }
193     }.observes( 'this.prndlSelectState' ),
194
195     /**
196      * Method calls GetVehicleType response
197      *
198      * @type {Number}
199      */
200     getVehicleType: function( id ) {
201         FFW.VehicleInfo.GetVehicleTypeResponse( this.vehicleType, id );
202     },
203
204     /**
205      * SDL VehicleInfo.GetDTCs handler fill data for response about vehicle
206      * errors
207      *
208      * @type {Object} params
209      * @type {Number} id
210      */
211     vehicleInfoGetDTCs: function( params, id ) {
212         var data = [], i = 0, info = "Inormation about reported DTC's", result = "";
213
214         for( i = 0; i < 3; i++ ){
215             data.push( params.encrypted ? "0" : {
216                 "identifier": '0',
217                 "statusByte": '0'
218             } );
219         }
220
221         result = "SUCCESS";
222
223         if( params.encrypted ){
224             result = 'ENCRYPTED';
225             FFW.BasicCommunication.SendData( data );
226             FFW.VehicleInfo.vehicleInfoGetDTCsResponse( null, info, result, id );
227         }else{
228             FFW.VehicleInfo.vehicleInfoGetDTCsResponse( data, info, result, id );
229         }
230     },
231
232     /**
233      * SDL VehicleInfo.ReadDID handler send response about vehicle conditions
234      *
235      * @type {Object} params
236      * @type {Number} id
237      */
238     vehicleInfoReadDID: function( params, id ) {
239         var data = [], i = 0, info = '', dataResult = [], resultCode = "";
240         // magic number used because there is no huge database on HMI of vehicle
241         // data
242         if( this.ecuDIDData[1].data ){
243             info = this.ecuDIDData[1].data;
244             result = "SUCCESS";
245         }else{
246             result = "INVALID_DATA";
247         }
248
249         for( i = 0; i < params.didLocation.length; i++ ){
250             if( i < 10 ){
251                 dataResult[i] = 'SUCCESS';
252                 data.push( '0' );
253             }else{
254                 dataResult[i] = "INVALID_DATA";
255                 data.push( '0' );
256             }
257         }
258
259         if( params.encrypted ){
260             result = 'ENCRYPTED';
261             FFW.BasicCommunication.SendData( data );
262             FFW.VehicleInfo.vehicleInfoReadDIDResponse( null, null, info, result, id );
263         }else{
264             FFW.VehicleInfo.vehicleInfoReadDIDResponse( dataResult, data, info, result, id );
265         }
266     },
267
268     /**
269      * Function returns response message to VehicleInfoRPC
270      *
271      * @type {Object} message
272      */
273     getVehicleData: function( message ) {
274
275         return this.vehicleData[message.dataType].data;
276
277     },
278
279     /**
280      * Function send all vehicle conditions on FFW.VehicleInfo.OnVehicleData fo
281      * notification when data changes
282      */
283     onVehicleDataChanged: function() {
284
285         var jsonData = {};
286         for( var i in this.vehicleData ){
287             jsonData[this.vehicleData[i].type] = this.vehicleData[i].data;
288         }
289         FFW.VehicleInfo.OnVehicleData( jsonData );
290
291     }.observes( 'this.vehicleData.VEHICLEDATA_PRNDLSTATUS.data' )
292 } );