Changed web samples' name and updated snapshots
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / ModelloAMBSimulator / project / js / simulator.js
1 /*global amblog, vehicle, ScriptController*/
2
3 /**
4  * @module AMBSimulatorApplication
5  */
6
7 /**
8  * Enclosures functionality of vehicle.js for setting signals to AMB plugin through WebSocket interface via {{#crossLink "Simulator/set:method"}}{{/crossLink}}.
9  * method. For example, to request update of AMB property `TransmissionShiftPosition` to position `1`:
10  *
11  *     Simulator.set("vcan0", "TransmissionShiftPosition", "1", 0);
12  *
13  * First parameter defines CAN bus to which CAN frame simulating setting AMB property should be set. Since `TransmissionShiftPosition` is not zoned
14  * use `0` as zone parameter which means `No zone`. In case that AMB property is zoned (e.g. `HVACTargetTemperature`) is't necessary to specify also zone
15  * (in this case left zone):
16  *
17  *     Simulator.set("vcan0", "HVACTargetTemperature", "1", 8);
18  *
19  * Zones are mapped as follows:
20  *
21  * * 0 - No zone
22  * * 1 - Front zone
23  * * 2 - Middle zone
24  * * 4 - Right zone
25  * * 8 - Left zone
26  * * 16 - Rear zone
27  * * 32 - Center zone
28  *
29  * These basic zones can be combined to specify exact position by adding values together, e.g. to specify front-left zone use value 9 (1 = front, 8 = left).
30  *
31  * @class Simulator
32  * @constructor
33  */
34
35 function Simulator() {
36 }
37
38 /**
39  * Holds AMB console jQuery object for inserting logs.
40  *
41  * @property ambConsole
42  * @type {JQuery}
43  * @static
44  * @default null
45  */
46 Simulator.ambConsole = null;
47
48 /**
49  * Signal set enclosuring function for transmitting signals into AMB plugin.
50  *
51  * @method set
52  * @param source {String} Target CAN bus name (e.g. `vcan0`).
53  * @param property {String} AMB property name.
54  * @param value {Number} New property value.
55  * @param zone {Number} Property zone (see {{#crossLink "Simulator"}}{{/crossLink}}) for zones description.
56  */
57 Simulator.set = function(source, property, value, zone) {
58         "use strict";
59         vehicle.set(source, [ property ], [ value ], [ zone ], amblog, amblog);
60 };
61
62 /**
63  * Removes old logs from amblog console, leaves 200 newest. Runs in intervals
64  * every 5s. Called after starting user script.
65  *
66  * @method startConsoleCleaningInterval
67  * @static
68  */
69 Simulator.startConsoleCleaningInterval = function() {
70         "use strict";
71         var cleaninIntervalId, logCount;
72
73         cleaninIntervalId = setInterval(function() {
74                 if (ScriptController.stop) {
75                         clearInterval(cleaninIntervalId);
76                 }
77                 logCount = $('.logItem').length;
78                 if (logCount > 200) {
79                         logCount -= 200;
80                         Simulator.ambConsole.find('.logItem:lt(' + logCount + ')').remove();
81                 }
82         }, 5000);
83 };
84
85 /**
86  * Global scope function for printing arguments into amblog console.
87  *
88  * @method amblog
89  * @param arguments {Array} Arguments array.
90  * @static
91  */
92 function amblog() {
93         "use strict";
94         var d, text, timeStamp, miliseconds;
95
96         for ( var i = 0; i < arguments.length; i++) {
97                 text = '';
98                 d = new Date();
99                 miliseconds = d.getMilliseconds().toString();
100                 if (miliseconds.length < 3) {
101                         miliseconds = ('00' + miliseconds).slice(-3);
102                 }
103                 timeStamp = d.toTimeString().substr(0, 8) + '.' + miliseconds;
104                 if (arguments[i][0].property) {
105                         text = arguments[i][0].property;
106                 } else {
107                         text = arguments[i];
108                 }
109                 Simulator.ambConsole.append('<span class="logItem">' + text + '<span class="timestamp">' + timeStamp + '</span></span>');
110                 Simulator.ambConsole.scrollTop(Simulator.ambConsole[0].scrollHeight);
111         }
112 }