Updated Modello Common libraries
[profile/ivi/sdk/web-ide-resources.git] / web-ui-fw / 0.0.2 / 0.0.2_Common / original / js / services / carIndicator.js
1 /**
2  * @module Services
3  */
4
5 /**
6  * Class provides AMB related functionality utilizing `navigator.vehicle` API for signals used in HTML applications. This component is usually initialized by {{#crossLink "Bootstrap"}}{{/crossLink}} class
7  * and can be later accessed using {{#crossLink "Bootstrap/carIndicator:property"}}{{/crossLink}} property. Signals recognized by this class needs to be registered in property
8  * {{#crossLink "CarIndicator/_mappingTable:property"}}{{/crossLink}}.
9  *
10  * To attach and detach to particular property register new callback object using {{#crossLink "Bootstrap/carIndicator:addListener"}}{{/crossLink}} method, e.g.:
11  *
12  *     var listenerId = bootstrap.carIndicator.addListener({
13  *        onSteeringWheelAngleChanged: function(newValue){
14  *           // Process new value
15  *        },
16  *        onWheelBrakeChanged : function(newValue){
17  *           // Process new value
18  *        }
19  *     });
20  *
21  *     // Unregister listener
22  *     bootstrap.carIndicator.removeListener(listenerId);
23  *
24  * Currently following signals are recognized:
25  *
26  * * SteeringWheelAngle
27  *   * SteeringWheelAngle
28  * * WheelBrake
29  *   * Engaged
30  * * TirePressure
31  *   * leftFront
32  *   * rightFront
33  *   * leftRear
34  *   * rightRear
35  * * DoorStatus
36  *   * ChildLockStatus
37  * * WindowStatus
38  *   * FrontDefrost
39  *   * RearDefrost
40  * * HVAC
41  *   * FanSpeed
42  *   * TargetTemperatureRight
43  *   * TargetTemperatureLeft
44  *   * SeatHeaterRight
45  *   * SeatHeaterLeft
46  *   * AirConditioning
47  *   * AirRecirculation
48  *   * AirflowDirection
49  * * LightStatus
50  *   * Hazard
51  *   * Head
52  *   * Parking
53  * * BatteryStatus
54  * * FullBatteryRange
55  * * ExteriorTemperature
56  *   * Exterior
57  * * InteriorTemperature
58  *   * Interior
59  * * WheelInformation
60  *   * FrontWheelRadius
61  * * AvgKW
62  *   * AvgKW
63  * * VehicleSpeed
64  * * Odometer
65  * * Transmission
66  *   * ShiftPosition
67  * * ExteriorBrightness
68  * * NightMode
69  * * DirectionIndicationINST
70  * * DirectionIndicationMS
71  * * ACCommand
72  * * RecircReq
73  * * FrontTSetRightCmd
74  * * FrontTSetLeftCmd
75  * * FrontBlwrSpeedCmd
76  * * HeatedSeatFRModeRequest
77  * * HeatedSeatFRRequest
78  * * HeatedSeatFLModeRequest
79  * * HeatedSeatFLRequest
80  * * FLHSDistrCmd
81  * * FRHSDistrCmd
82  *
83  * @class CarIndicator
84  * @constructor
85  */
86 var CarIndicator = function() {
87         "use strict";
88         console.info("Starting up service CarIndicator");
89 };
90
91 if (typeof Zone !== 'function')
92 {
93         window.Zone = function(){return undefined;};
94 }
95
96 function parseInteger(value) {
97         "use strict";
98         return parseInt(value, 10);
99 }
100
101 function kmhToMph(value) {
102         "use strict";
103         var kmh = parseInteger(value);
104         return Math.round(kmh * 0.621371);
105 }
106
107 function parseTirePressure(value) {
108         "use strict";
109         var floatValue = parseFloat(value).toFixed(2);
110         if (floatValue > 180 && floatValue < 220) {
111                 floatValue = "OK";
112         }
113         return floatValue;
114 }
115
116 /**
117  * Array of registered listeners
118  * @type Object
119  * @property _listeners
120  * @private
121  */
122 CarIndicator.prototype._listeners = {};
123
124 /**
125  * Array of registered listener IDs.
126  * @type Array
127  * @property _listenerIDs
128  * @private
129  */
130 CarIndicator.prototype._listenerIDs = [];
131
132 /**
133  * Signal mapping table.
134  * Each entry should form an object
135  * @property _mappingTable
136  * @private
137  * @type Object
138  */
139 CarIndicator.prototype._mappingTable = {
140         /*
141         ZONE_None   = 000000;
142         ZONE_Front  = 000001;
143         ZONE_Middle = 000010;
144         ZONE_Right  = 000100;
145         ZONE_Left   = 001000;
146         ZONE_Rear   = 010000;
147         ZONE_Center = 100000;
148         */
149         /* this is for steeringWheel game controler */
150         "SteeringWheelAngle" : {
151                 attributeName : "steeringWheelAngle",
152                 callBackPropertyName : "SteeringWheelAngle",
153                 interfaceName : "steeringWheel",
154                 conversionFunction : function(value) {
155                         "use strict";
156                         value = parseInt(value, 10);
157                         var returnValue = 0;
158                         if (value <= 180 && value > 0) {
159                                 returnValue = (1 * (value / 6)) - 30;
160                         } else if (value <= 360 && value > 180) {
161                                 returnValue = ((value - 179) / 6);
162                         } else if (value === 0) {
163                                 returnValue = -30;
164                         }
165                         return returnValue;
166                 }
167         },
168         "WheelBrake" : {
169                 attributeName : "engaged",
170                 callBackPropertyName : "WheelBrake",
171                 interfaceName : "brakeOperation"
172         },
173         /* end steeringWheel game controler*/
174         "TirePressureLeftFront" : {
175                 attributeName : "pressure",
176                 callBackPropertyName : "tirePressureLeftFront",
177                 interfaceName : "tire",
178                 conversionFunction : parseTirePressure
179                 //zone : new Zone(["Front","Left"])
180         },
181         "TirePressureRightFront" : {
182                 attributeName : "pressure",
183                 callBackPropertyName : "tirePressureRightFront",
184                 interfaceName : "tire",
185                 conversionFunction : parseTirePressure
186                 //zone : new Zone(["Front","Right"])
187         },
188         "TirePressureLeftRear" : {
189                 attributeName : "pressure",
190                 callBackPropertyName : "tirePressureLeftRear",
191                 interfaceName : "tire",
192                 conversionFunction : parseTirePressure
193                 //zone : new Zone(["Rear","Left"])
194         },
195         "TirePressureRightRear" : {
196                 attributeName : "pressure",
197                 callBackPropertyName : "tirePressureRightRear",
198                 interfaceName : "tire",
199                 conversionFunction : parseTirePressure
200                 //zone : new Zone(["Rear","Right"])
201         },
202         "ChildLock" : {
203                 attributeName : "lock",
204                 callBackPropertyName : "childLock",
205                 interfaceName : "childSafetyLock"
206         },
207         "FrontDefrost" : {
208                 attributeName : "defrostWindow",
209                 callBackPropertyName : "frontDefrost",
210                 interfaceName : "defrost",
211                 zone : new Zone(["front"])
212         },
213         "RearDefrost" : {
214                 attributeName : "defrostWindow",
215                 callBackPropertyName : "rearDefrost",
216                 interfaceName : "defrost",
217                 zone : new Zone(["rear"])
218         },
219         "FanSpeed" : {
220                 attributeName : "fanSpeedLevel",
221                 callBackPropertyName : "fanSpeed",
222                 interfaceName : "climateControl",
223                 conversionFunction : parseInteger
224         },
225         "TargetTemperatureRight" : {
226                 attributeName : "targetTemperature",
227                 callBackPropertyName : "targetTemperatureRight",
228                 interfaceName : "climateControl",
229                 conversionFunction : parseInteger,
230                 zone : new Zone(["front", "right"])
231         },
232         "TargetTemperatureLeft" : {
233                 attributeName : "targetTemperature",
234                 callBackPropertyName : "targetTemperatureLeft",
235                 interfaceName : "climateControl",
236                 conversionFunction : parseInteger,
237                 zone : new Zone(["front", "left"])
238         },
239         "Hazard" : {
240                 attributeName : "hazard",
241                 callBackPropertyName : "hazard",
242                 interfaceName : "lightStatus"
243         },
244         "Head" : {
245                 attributeName : "head",
246                 callBackPropertyName : "frontLights",
247                 interfaceName : "lightStatus"
248         },
249         "SeatHeaterRight" : {
250                 attributeName : "seatHeater",
251                 callBackPropertyName : "seatHeaterRight",
252                 interfaceName : "climateControl",
253                 zone : new Zone(["front", "right"])
254         },
255         "SeatHeaterLeft" : {
256                 attributeName : "seatHeater",
257                 callBackPropertyName : "seatHeaterLeft",
258                 interfaceName : "climateControl",
259                 zone : new Zone(["front", "left"])
260         },
261         "Parking" : {
262                 attributeName : "parking",
263                 callBackPropertyName : "rearLights",
264                 interfaceName : "lightStatus",
265         },
266         "AirConditioning" : {
267                 attributeName : "airConditioning",
268                 callBackPropertyName : "fan",
269                 interfaceName : "climateControl"
270         },
271         "AirRecirculation" : {
272                 attributeName : "airRecirculation",
273                 callBackPropertyName : "airRecirculation",
274                 interfaceName : "climateControl"
275         },
276         "AirflowDirection" : {
277                 attributeName : "airflowDirectionW3C",
278                 callBackPropertyName : "airflowDirection",
279                 interfaceName : "climateControl",
280                 conversionFunction : parseInteger
281         },
282         "BatteryStatus" : {
283                 attributeName : "chargeLevel",
284                 callBackPropertyName : "batteryStatus",
285                 interfaceName : "batteryStatus",
286                 conversionFunction : parseInteger
287         },
288         "FullBatteryRange" : {
289                 attributeName : "fullBatteryRange",
290                 callBackPropertyName : "fullBatteryRange",
291                 conversionFunction : parseInteger
292         },
293         "Exterior" : {
294                 attributeName : "exteriorTemperature",
295                 callBackPropertyName : "outsideTemp",
296                 interfaceName : "temperature",
297                 conversionFunction : parseInteger
298         },
299         "Interior" : {
300                 attributeName : "interiorTemperature",
301                 callBackPropertyName : "insideTemp",
302                 interfaceName : "temperature",
303                 conversionFunction : parseInteger
304         },
305         "WheelAngle" : {
306                 attributeName : "frontWheelRadius",
307                 callBackPropertyName : "wheelAngle",
308                 //interfaceName : "wheelConfiguration",
309                 conversionFunction : parseInteger
310         },
311         "Weather" : {
312                 attributeName : "weather",
313                 callBackPropertyName : "weather",
314                 conversionFunction : parseInteger
315         },
316         "AvgKW" : {
317                 attributeName : "avgKW",
318                 callBackPropertyName : "avgKW",
319                 //interfaceName : "AvgKW",
320                 conversionFunction : function(newValue) {
321                         "use strict";
322                         return parseFloat(newValue).toFixed(2);
323                 }
324         },
325         "VehicleSpeed" : {
326                 attributeName : "speed",
327                 callBackPropertyName : "speed",
328                 interfaceName : "vehicleSpeed",
329                 conversionFunction : kmhToMph
330         },
331         "Odometer" : {
332                 attributeName : "odometer",
333                 callBackPropertyName : "odoMeter",
334                 interfaceName : "odometer",
335                 conversionFunction : parseInteger
336         },
337         "TransmissionShiftPosition" : {
338                 attributeName : "mode",
339                 callBackPropertyName : "gear",
340                 conversionFunction : function(value) {
341                         "use strict";
342                         switch (value) {
343                         case "park":
344                                 value = "P";
345                                 break;
346                         case "reverse":
347                                 value = "R";
348                                 break;
349                         case "neutral":
350                                 value = "N";
351                                 break;
352                         case "low":
353                                 value = "L";
354                                 break;
355                         case "drive":
356                                 value = "D";
357                                 break;
358                         case "overdrive":
359                                 value = "OD";
360                                 break;
361                         default:
362                                 value = "D";
363                                 break;
364                         }
365                         return value;
366                 },
367                 interfaceName : "transmission"
368         },
369         "Randomize" : {
370                 attributeName : "randomize",
371                 callBackPropertyName : "randomize",
372                 interfaceName : "Randomize"
373         },
374         "ExteriorBrightness" : {
375                 attributeName : "exteriorBrightness",
376                 callBackPropertyName : "exteriorBrightness"
377         },
378         "NightMode" : {
379                 attributeName : "mode",
380                 callBackPropertyName : "nightMode",
381                 interfaceName : "nightMode"
382         },
383         "DirectionIndicationINST" : {
384                 attributeName : "DirectionIndicationINST",
385                 callBackPropertyName : "DirectionIndicationINST",
386                 //interfaceName : "DirectionIndicationINST"
387         },
388         "DirectionIndicationMS" : {
389                 attributeName : "DirectionIndicationMS",
390                 callBackPropertyName : "DirectionIndicationMS",
391                 //interfaceName : "DirectionIndicationMS"
392         },
393         "ACCommand" : {
394                 attributeName : "ACCommand",
395                 callBackPropertyName : "ACCommand",
396                 //interfaceName : "ACCommand"
397         },
398         "RecircReq" : {
399                 attributeName : "RecircReq",
400                 callBackPropertyName : "RecircReq",
401                 //interfaceName : "RecircReq"
402         },
403         "FrontTSetRightCmd" : {
404                 attributeName : "FrontTSetRightCmd",
405                 callBackPropertyName : "FrontTSetRightCmd",
406                 //interfaceName : "FrontTSetRightCmd"
407         },
408         "FrontTSetLeftCmd" : {
409                 attributeName : "FrontTSetLeftCmd",
410                 callBackPropertyName : "FrontTSetLeftCmd",
411                 //interfaceName : "FrontTSetLeftCmd"
412         },
413         "FrontBlwrSpeedCmd" : {
414                 attributeName : "FrontBlwrSpeedCmd",
415                 callBackPropertyName : "FrontBlwrSpeedCmd",
416                 //interfaceName : "FrontBlwrSpeedCmd"
417         },
418         "HeatedSeatFRRequest" : {
419                 attributeName : "seatHeater",
420                 callBackPropertyName : "HeatedSeatFRRequest",
421                 interfaceName : "climateControl",
422                 zone : new Zone(["front", "right"])
423         },
424         "HeatedSeatFLRequest" : {
425                 attributeName : "seatHeater",
426                 callBackPropertyName : "HeatedSeatFLRequest",
427                 interfaceName : "climateControl",
428                 zone : new Zone(["front", "left"])
429         },
430         "FLHSDistrCmd" : {
431                 attributeName : "FLHSDistrCmd",
432                 callBackPropertyName : "FLHSDistrCmd",
433                 //interfaceName : "FLHSDistrCmd"
434         },
435         "FRHSDistrCmd" : {
436                 attributeName : "FRHSDistrCmd",
437                 callBackPropertyName : "FRHSDistrCmd",
438                 //interfaceName : "FRHSDistrCmd"
439         }
440 };
441
442 /**
443  * This method adds listener object for car events. Object should define function callbacks taking signal names from mapping table, e.g.:
444  * @example
445  *     {
446  *        onBatteryChange: function(newValue, oldValue) {}
447  *     }
448  * Methods are called back with new and last known values.
449  * @method addListener
450  * @param callback {Object} object with callback functions.
451  * @return {Integer} WatchID for later removal of listener.
452  */
453 CarIndicator.prototype.addListener = function(aCallbackObject) {
454         "use strict";
455         var id = Math.floor(Math.random() * 1000000);
456         var self = this;
457         this._listeners[id] = aCallbackObject;
458         this._listenerIDs.push(id);
459
460         var subscribeCallback = function(data) {
461                 self.onDataUpdate(data, self);
462         };
463         for ( var i in aCallbackObject) {
464                 if (aCallbackObject.hasOwnProperty(i)) {
465                         var prop = i.replace("on", "").replace("Changed", "");
466
467                         for ( var signal in this._mappingTable) {
468                                 if (this._mappingTable.hasOwnProperty(signal)) {
469                                         var mapping = this._mappingTable[signal];
470                                         var zone = mapping.zone;
471                                         var interfaceName = signal;
472
473                                         if (mapping.interfaceName !== "undefined") {
474                                                 interfaceName = mapping.interfaceName;
475                                         }
476
477                                         if (mapping.callBackPropertyName.toLowerCase() === prop.toLowerCase() && !mapping.subscribeCount) {
478                                                 mapping.subscribeCount = typeof (mapping.subscribeCount) === "undefined" ? 0 : mapping.subscribeCount++;
479                                                 if (typeof (navigator.vehicle) !== 'undefined') {
480                                                         if (typeof (navigator.vehicle[interfaceName]) !== "undefined") {
481                                                                 if (!(interfaceName.toString().trim().toLowerCase() === "nightmode" && id === this._listenerIDs[0])) {
482                                                                         if (navigator.vehicle[interfaceName]){
483                                                                                 var setUpData = navigator.vehicle[interfaceName].get(zone);
484                                                                                 if (setUpData !== undefined)
485                                                                                         self.onDataUpdate(setUpData, self, id);
486                                                                         }
487                                                                 }
488                                                                 if (typeof (navigator.vehicle[interfaceName].subscribe) !== "undefined")
489                                                                 {
490                                                                         console.log("Modello: Subscribing to AMB signal - " + interfaceName);
491                                                                         navigator.vehicle[interfaceName].subscribe(subscribeCallback, zone);
492                                                                 }
493                                                         } else {
494                                                                 if (typeof (navigator.vehicle[interfaceName]) === "undefined")
495                                                                         console.warn(interfaceName + " is not available to subscribe to");
496                                                                 else
497                                                                         console.warn("Tizen API is not available, cannot subscribe to signal", signal);
498                                                         }
499                                                 } else {
500                                                         console.warn("Vehicle API is not available.");
501                                                 }
502                                         }
503                                 }
504                         }
505                 }
506         }
507
508         return id;
509 };
510 /**
511  * This method is call as callback if data oon navigator.vehicle was change onDataUpdate
512  * @method onDataUpdate
513  * @param data {object} object whit new data.
514  * @param self {object} this carIndicator Object.
515  * @param lisenersID {int} id of listener.
516  */
517 CarIndicator.prototype.onDataUpdate = function(data, self, lisenersID) {
518         "use strict";
519         if (data !== undefined) {
520                 if (data.zone !== undefined)
521                         var zone = data.zone.toString(2);
522                 else
523                         var zone = "0";
524                 var mapping;
525
526                 for ( var property in data) {
527                         if (data.hasOwnProperty(property)) {
528                                 mapping = undefined;
529                                 if (property !== "time" && property !== "zone" && property !== "interfaceName" && property.search("Sequence") === -1) {
530                                         for ( var element in self._mappingTable) {
531                                                 if (self._mappingTable.hasOwnProperty(element) && self._mappingTable[element].interfaceName !== undefined) {
532                                                         if (self._mappingTable[element].interfaceName.toLowerCase() === data.interfaceName.toLowerCase() &&
533                                                                 self._mappingTable[element].attributeName.toLowerCase() === property.toLowerCase() &&
534                                                                 ((!self._mappingTable[element].zone && (!data.zone || data.zone.value.length === 0)) ||
535                                                                         ((self._mappingTable[element].zone && data.zone) &&
536                                                                                 (typeof(self._mappingTable[element].zone.equals) === typeof(data.zone.equals)) &&
537                                                                                 self._mappingTable[element].zone.equals(data.zone)))
538                                                                 ) {
539                                                                         mapping = self._mappingTable[element];
540                                                                         break;
541                                                         }
542                                                 }
543                                         }
544
545                                         if (typeof (mapping) !== 'undefined') {
546                                                 var value = data[property];
547                                                 value = mapping.conversionFunction ? mapping.conversionFunction(value) : value;
548
549                                                 var oldValue = self.status[mapping.callBackPropertyName];
550                                                 if (oldValue !== value || property.toUpperCase() === "nightMode".toUpperCase()) {
551                                                         console.info("AMB property '" + property + "' has changed to new value:" + value);
552                                                         self.status[mapping.callBackPropertyName] = value;
553
554                                                         var callbackName = "on" + mapping.callBackPropertyName[0].toUpperCase() + mapping.callBackPropertyName.substring(1) + "Changed";
555                                                         var listener;
556
557                                                         if (lisenersID !== undefined) {
558                                                                 listener = self._listeners[lisenersID];
559
560                                                                 if (typeof (listener[callbackName]) === 'function') {
561                                                                         try {
562                                                                                 listener[callbackName](value, oldValue);
563                                                                         } catch (ex) {
564                                                                                 console.error("Error occured during executing listener", ex);
565                                                                         }
566                                                                 }
567                                                         } else {
568                                                                 for ( var i in self._listeners) {
569                                                                         if (self._listeners.hasOwnProperty(i)) {
570                                                                                 listener = self._listeners[i];
571
572                                                                                 if (typeof (listener[callbackName]) === 'function') {
573                                                                                         try {
574                                                                                                 listener[callbackName](value, oldValue);
575                                                                                         } catch (ex) {
576                                                                                                 console.error("Error occured during executing listener", ex);
577                                                                                         }
578                                                                                 }
579                                                                         }
580                                                                 }
581                                                         }
582                                                 }
583
584                                         } else {
585                                                 console.warn("Mapping for property '" + property + "' is not defined");
586                                         }
587                                 }
588                         }
589                 }
590         }
591 };
592
593 /**
594  * This method removes previosly added listener object. Use WatchID returned from addListener method.
595  * @method removeListener
596  * @param aId {Integer} WatchID.
597  */
598 CarIndicator.prototype.removeListener = function(aId) {
599         "use strict";
600         var listener = this._listeners[aId];
601
602         for ( var i in listener) {
603                 if (listener.hasOwnProperty(i)) {
604                         var prop = i.replace("on", "").replace("Changed", "");
605
606                         for ( var signal in this._mappingTable) {
607                                 if (this._mappingTable.hasOwnProperty(signal)) {
608                                         var mapping = this._mappingTable[signal];
609
610                                         if (mapping.subscribeCount === 0) { // Last signal, unscubscribe
611                                                 if (typeof (navigator.vehicle) !== 'undefined') {
612                                                         navigator.vehicle.unsubscribe(signal);
613                                                         mapping.subscribeCount = undefined;
614                                                 } else {
615                                                         console.warn("Vehicle API is not available.");
616                                                 }
617                                         } else if (typeof (mapping.subscribeCount) !== 'undefined') {
618                                                 mapping.subscribeCount--;
619                                         }
620                                 }
621                         }
622                 }
623         }
624
625         this._listeners[aId] = undefined;
626 };
627
628 /**
629  * status object
630  * @property status
631  * @type Object
632  * @private
633  */
634 CarIndicator.prototype.status = {
635         fanSpeed : 0,
636         targetTemperatureRight : 0,
637         targetTemperatureLeft : 0,
638         hazard : false,
639         frontDefrost : false,
640         rearDefrost : false,
641         frontLeftwhell : "",
642         frontRightwhell : "",
643         rearLeftwhell : "",
644         rearRightwhell : "",
645         childLock : false,
646         frontLights : false,
647         rearLights : false,
648         fan : false,
649         seatHeaterRight : 0,
650         seatHeaterLeft : 0,
651         airRecirculation : false,
652         airflowDirection : 0,
653         batteryStatus : 58,
654         fullBatteryRange : 350,
655         outsideTemp : 74.2,
656         insideTemp : 68.2,
657         wheelAngle : 0,
658         weather : 1,
659         avgKW : 0.28,
660         speed : 65,
661         odoMeter : 75126,
662         gear : "D",
663         nightMode : false,
664         randomize : false,
665         exteriorBrightness : 1000
666 };
667
668 /**
669  * This method return status object in callback
670  * @method getStatus
671  * @param callback {function} callback function.
672  */
673 CarIndicator.prototype.getStatus = function(callback) {
674         "use strict";
675         callback(this.status);
676 };
677
678 /**
679  * this method set status for property in navigator.vehicle and status object
680  * @method setStatus
681  * @param indicator {string} indicator name.
682  * @param status {??} ??.
683  * @param text_status {string} new status .
684  * @param callback {function} callback function.
685  */
686 CarIndicator.prototype.setStatus = function(indicator, newValue, zone) {
687         "use strict";
688         var mappingElement, mappingProperty;
689         for ( var element in this._mappingTable) {
690                 if (this._mappingTable.hasOwnProperty(element)) {
691                         mappingProperty = undefined;
692                         if (this._mappingTable[element].callBackPropertyName.toLowerCase() === indicator.toLowerCase()) {
693                                 mappingElement = this._mappingTable[element];
694                                 mappingProperty = this._mappingTable[element].attributeName;
695                                 break;
696                         }
697                 }
698         }
699
700         if (mappingProperty !== undefined) {
701                 var objectName = mappingElement.interfaceName;
702                 var zoneValue = (mappingElement.zone && mappingElement.zone.value) ? mappingElement.zone.value : undefined;
703
704                 if (typeof (navigator.vehicle) !== 'undefined') {
705                         if (typeof (navigator.vehicle[objectName]) !== 'undefined' && typeof (navigator.vehicle[objectName].set) !== 'undefined') {
706                                 console.log("trying to set: " + objectName + "." + mappingProperty + " in zone " + zoneValue + " to " + newValue);
707                                 var value = {};
708                                 value[mappingProperty] = newValue;
709                                 navigator.vehicle[objectName].set(value, mappingElement.zone).then(function() {
710                                     console.log("Set success!");
711                                 }, function(error) {
712                                     console.log("Set failed! " + error.message);
713                                 });
714                         }
715                         else
716                                 console.error("Can't set status for " + objectName + " because it doesn't exist " + indicator);
717
718                 } else {
719                         console.warn("Vehicle API is not available.");
720                 }
721         }
722
723 };