1 /*global amblog, vehicle, ScriptController*/
4 * @module AMBSimulatorApplication
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`:
11 * Simulator.set("vcan0", "TransmissionShiftPosition", "1", 0);
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):
17 * Simulator.set("vcan0", "HVACTargetTemperature", "1", 8);
19 * Zones are mapped as follows:
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).
35 function Simulator() {
39 * Holds AMB console jQuery object for inserting logs.
41 * @property ambConsole
46 Simulator.ambConsole = null;
49 * Signal set enclosuring function for transmitting signals into AMB plugin.
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.
57 Simulator.set = function(source, property, value, zone) {
59 vehicle.set(source, [ property ], [ value ], [ zone ], amblog, amblog);
63 * Removes old logs from amblog console, leaves 200 newest. Runs in intervals
64 * every 5s. Called after starting user script.
66 * @method startConsoleCleaningInterval
69 Simulator.startConsoleCleaningInterval = function() {
71 var cleaninIntervalId, logCount;
73 cleaninIntervalId = setInterval(function() {
74 if (ScriptController.stop) {
75 clearInterval(cleaninIntervalId);
77 logCount = $('.logItem').length;
80 Simulator.ambConsole.find('.logItem:lt(' + logCount + ')').remove();
86 * Global scope function for printing arguments into amblog console.
89 * @param arguments {Array} Arguments array.
94 var d, text, timeStamp, miliseconds;
96 for ( var i = 0; i < arguments.length; i++) {
99 miliseconds = d.getMilliseconds().toString();
100 if (miliseconds.length < 3) {
101 miliseconds = ('00' + miliseconds).slice(-3);
103 timeStamp = d.toTimeString().substr(0, 8) + '.' + miliseconds;
104 if (arguments[i][0].property) {
105 text = arguments[i][0].property;
109 Simulator.ambConsole.append('<span class="logItem">' + text + '<span class="timestamp">' + timeStamp + '</span></span>');
110 Simulator.ambConsole.scrollTop(Simulator.ambConsole[0].scrollHeight);