From 384545eff2c455e8db21c6e2d486a8776e577c0b Mon Sep 17 00:00:00 2001 From: Marek Timko Date: Mon, 11 Nov 2013 13:20:10 +0100 Subject: [PATCH] TIVI-1465 Update websocket plugin and protocol to handle zones and sources Websocket plugin with zone support MapPropertyType::fromString fixed Change-Id: I4993e015a31d91a4ac3bfda45ca41d5a2e9485a3 Signed-off-by: Marek Timko --- lib/mappropertytype.hpp | 2 +- plugins/websocketsink/test/events.js | 225 ++-------------- plugins/websocketsink/test/index.html | 2 +- plugins/websocketsink/test/style.css | 16 +- plugins/websocketsink/test/test.js | 298 ++++++++++++---------- plugins/websocketsink/test/{api.js => vehicle.js} | 66 +++-- plugins/websocketsink/websocketsink.cpp | 5 +- plugins/websocketsink/websocketsinkmanager.cpp | 207 ++++++--------- plugins/websocketsink/websocketsinkmanager.h | 6 +- plugins/websocketsourceplugin/websocketsource.cpp | 28 +- 10 files changed, 356 insertions(+), 499 deletions(-) rename plugins/websocketsink/test/{api.js => vehicle.js} (88%) diff --git a/lib/mappropertytype.hpp b/lib/mappropertytype.hpp index 35bcffb..694400b 100644 --- a/lib/mappropertytype.hpp +++ b/lib/mappropertytype.hpp @@ -78,7 +78,7 @@ public: json_object_object_foreach(rootobject, key, val) { T one(key); - N two(json_object_get_string(val)); + N two(std::string(json_object_get_string(val))); append(one,two); } diff --git a/plugins/websocketsink/test/events.js b/plugins/websocketsink/test/events.js index a669f09..cb0cfd5 100644 --- a/plugins/websocketsink/test/events.js +++ b/plugins/websocketsink/test/events.js @@ -12,207 +12,30 @@ function VehicleEventType() { this.event = [ - "vehicle_info", - "vehicle_info_wmi", - "vehicle_info_vin", - "vehicle_info_vehicle_type", - "vehicle_info_door_type", - "vehicle_info_door_type_1st_row", - "vehicle_info_door_type_2nd_row", - "vehicle_info_door_type_3rd_row", - "vehicle_info_fuel_type", - "vehicle_info_transmission_gear_type", - "vehicle_info_wheel_info", - "vehicle_info_wheel_info_radius", - "vehicle_info_wheel_info_track", - "running_status", - "running_status_vehicle_power_mode", - "running_status_speedometer", - "running_status_engine_speed", - "running_status_trip_meter", - "running_status_trip_meter_1", - "running_status_trip_meter_2", - "running_status_trip_meter_1_mileage", - "running_status_trip_meter_2_mileage", - "running_status_trip_meter_1_average_speed", - "running_status_trip_meter_2_average_speed", - "running_status_trip_meter_1_fuel_consumption", - "running_status_trip_meter_2_fuel_consumption", - "running_status_transmission_gear_status", - "running_status_cruise_control", - "running_status_cruise_control_status", - "running_status_cruise_control_speed", - "running_status_wheel_brake", - "running_status_lights_status", - "running_status_lights_status_head", - "running_status_lights_status_high_beam", - "running_status_lights_status_turn_left", - "running_status_lights_status_turn_right", - "running_status_lights_status_brake", - "running_status_lights_status_fog_front", - "running_status_lights_status_fog_rear", - "running_status_lights_status_hazard", - "running_status_lights_status_parking", - "running_status_interior_lights_status", - "running_status_interior_lights_status_driver", - "running_status_interior_lights_status_passenger", - "running_status_interior_lights_status_center", - "running_status_automatic_headlights", - "running_status_dynamic_high_beam", - "running_status_horn", - "running_status_chime", - "running_status_fuel", - "running_status_estimated_range", - "running_status_engine_oil", - "running_status_engine_oil_remaining", - "running_status_engine_oil_change", - "running_status_engine_oil_temp", - "running_status_engine_coolant", - "running_status_engine_coolant_level", - "running_status_engine_coolant_temp", - "running_status_steering_wheel_angle", - "maintenance", - "maintenance_odometer", - "maintenance_transmission_oil", - "maintenance_transmission_oil_life_level", - "maintenance_transmission_oil_temp", - "maintenance_brake_fluid_level", - "maintenance_washer_fluid_level", - "maintenance_malfunction_indicator_lamp", - "maintenance_battery", - "maintenance_battery_voltage", - "maintenance_battery_current", - "maintenance_tire_pressure", - "maintenance_tire_pressure_front_left", - "maintenance_tire_pressure_front_right", - "maintenance_tire_pressure_rear_left", - "maintenance_tire_pressure_rear_right", - "maintenance_tire_pressure_status", - "maintenance_tire_pressure_status_front_left", - "maintenance_tire_pressure_status_front_right", - "maintenance_tire_pressure_status_rear_left", - "maintenance_tire_pressure_status_rear_right", - "personalization", - "personalization_key_id", - "personalization_language", - "personalization_measurement_system", - "personalization_measurement_system_string", - "personalization_measurement_system_string_fuel", - "personalization_measurement_system_string_distance", - "personalization_measurement_system_string_speed", - "personalization_measurement_system_string_consumption", - "personalization_mirror", - "personalization_mirror_driver", - "personalization_mirror_passenger", - "personalization_mirror_inside", - "personalization_steering_wheel_position", - "personalization_steering_wheel_position_slide", - "personalization_steering_wheel_position_tilt", - "personalization_driving_mode", - "personalization_driver_seat_position", - "personalization_driver_seat_position_recline_seatback", - "personalization_driver_seat_position_slide", - "personalization_driver_seat_position_cushion_height", - "personalization_driver_seat_position_headrest", - "personalization_driver_seat_position_back_cushion", - "personalization_driver_seat_position_side_cushion", - "personalization_passenger_seat_position", - "personalization_passenger_seat_position_recline_seatback", - "personalization_passenger_seat_position_slide", - "personalization_passenger_seat_position_cushion_height", - "personalization_passenger_seat_position_headrest", - "personalization_passenger_seat_position_back_cushion", - "personalization_passenger_seat_position_side_cushion", - "personalization_dashboard_illumination", - "personalization_generated_vehicle_sound_mode", - "driving_safety", - "driving_safety_antilock_braking_system", - "driving_safety_traction_control_system", - "driving_safety_electronic_stability_control", - "driving_safety_vehicle_top_speed_limit", - "driving_safety_airbag_status", - "driving_safety_airbag_status_driver", - "driving_safety_airbag_status_passenger", - "driving_safety_airbag_status_side", - "driving_safety_door_open_status", - "driving_safety_door_open_status_driver", - "driving_safety_door_open_status_passenger", - "driving_safety_door_open_status_rear_left", - "driving_safety_door_open_status_rear_right", - "driving_safety_door_open_status_trunk", - "driving_safety_door_open_status_fuel_filter_cap", - "driving_safety_door_open_status_hood", - "driving_safety_door_lock_status", - "driving_safety_door_lock_status_driver", - "driving_safety_door_lock_status_passenger", - "driving_safety_door_lock_status_rear_left", - "driving_safety_door_lock_status_rear_right", - "driving_safety_child_safety_lock", - "driving_safety_occupants_status", - "driving_safety_occupants_status_driver", - "driving_safety_occupants_status_passenger", - "driving_safety_occupants_status_rear_left", - "driving_safety_occupants_status_rear_right", - "driving_safety_seat_belt", - "driving_safety_seat_belt_driver", - "driving_safety_seat_belt_passenger", - "driving_safety_seat_belt_rear_left", - "driving_safety_seat_belt_rear_right", - "driving_safety_window_lock", - "driving_safety_window_lock_driver", - "driving_safety_window_lock_passenger", - "driving_safety_window_lock_rear_left", - "driving_safety_window_lock_rear_right", - "driving_safety_obstacle_distance", - "driving_safety_obstacle_distance_sensor_status", - "driving_safety_obstacle_distance_front_center", - "driving_safety_obstacle_distance_rear_center", - "driving_safety_obstacle_distance_front_left", - "driving_safety_obstacle_distance_front_right", - "driving_safety_obstacle_distance_middle_left", - "driving_safety_obstacle_distance_middle_right", - "driving_safety_obstacle_distance_rear_left", - "driving_safety_obstacle_distance_rear_right", - "driving_safety_front_collision_detection", - "driving_safety_front_collision_detection_status", - "driving_safety_front_collision_detection_distance", - "driving_safety_front_collision_detection_time", - "vision_system", - "vision_system_lane_departure_detection_status", - "vision_system_lane_departed", - "parking", - "parking_security_alert", - "parking_parking_brake", - "parking_parking_lights", - "climate_environment_interior_temp", - "climate_environment_exterior_temp", - "climate_environment_exterior_brightness", - "climate_environment_rain_sensor", - "climate_environment_windshield_wiper", - "climate_environment_rear_wiper", - "climate_environment_hvac_fan", - "climate_environment_hvac_fan_direction", - "climate_environment_hvac_fan_speed", - "climate_environment_hvac_fan_target_temp", - "climate_environment_air_conditioning", - "climate_environment_air_recirculation", - "climate_environment_heater", - "climate_environment_defrost", - "climate_environment_defrost_windshield", - "climate_environment_defrost_rear_window", - "climate_environment_defrost_side_mirrors", - "climate_environment_steering_wheel_heater", - "climate_environment_seat_heater", - "climate_environment_seat_cooler", - "climate_environment_window", - "climate_environment_window_driver", - "climate_environment_window_passenger", - "climate_environment_window_rear_left", - "climate_environment_window_rear_right", - "climate_environment_sunroof", - "climate_environment_sunroof_openness", - "climate_environment_sunroof_tilt", - "climate_environment_convertible_roof" +"Randomize", +"AirConditioning", +"AirRecirculation", +"AirflowDirection", +"AvgKW", +"BatteryStatus", +"ChildLock", +"Defrost", +"ExteriorBrightness", +"ExteriorTemperature", +"FanSpeed", +"FrontWheelRadius", +"FullBatteryRange", +"InteriorTemperature", +"LightHazard", +"LightHead", +"LightParking", +"NightMode", +"Odometer", +"SeatHeater", +"TargetTemperature", +"TransmissionShiftPosition", +"VehicleSpeed", +"Weather" ]; this.value = []; diff --git a/plugins/websocketsink/test/index.html b/plugins/websocketsink/test/index.html index a94ee39..9a5daef 100644 --- a/plugins/websocketsink/test/index.html +++ b/plugins/websocketsink/test/index.html @@ -4,7 +4,7 @@ IVI API Tester - +
diff --git a/plugins/websocketsink/test/style.css b/plugins/websocketsink/test/style.css index a3bf655..8456fd1 100644 --- a/plugins/websocketsink/test/style.css +++ b/plugins/websocketsink/test/style.css @@ -19,14 +19,14 @@ top: 0px; left: 0%; height: 100%; - width: 520px; + width: 620px; overflow-y: auto; } #result { position: absolute; top: 0px; - left: 520px; + left: 620px; height: 98%; width: 1380px; padding-top: 1%; @@ -40,7 +40,7 @@ position: relative; left: 0px; height: 67px; - width: 500px; + width: 700px; overflow: hidden; } @@ -49,15 +49,21 @@ top: 32px; left: 0px; height: 35px; - width: 430px; + width: 630px; } +.smallText { + text-align: left; + color: #FFFFFF; + font: 18px Arial; + display: inline; +} .propinfo { position: absolute; top: 0px; left: 0px; height: 67px; - width: 500px; + width: 600px; text-align: left; color: #FFFFFF; font: 18px Arial; diff --git a/plugins/websocketsink/test/test.js b/plugins/websocketsink/test/test.js index 72383ee..90106f2 100644 --- a/plugins/websocketsink/test/test.js +++ b/plugins/websocketsink/test/test.js @@ -10,30 +10,30 @@ /* --------------------------- utility code ------------------------------- */ var PRINT = { - logElement : null, - init : function(log_id) { + logElement: null, + init: function(log_id) { this.logElement = document.getElementById(log_id); }, - scrollToBottom : function() { + scrollToBottom: function() { this.logElement.scrollTop = this.logElement.scrollHeight; }, - clear : function() { + clear: function() { this.logElement.innerHTML = ""; }, - pass : function(msg) { + pass: function(msg) { this.logElement.innerHTML += "
PASS: " + msg + "
"; this.scrollToBottom(); }, - fail : function(msg) { + fail: function(msg) { this.logElement.innerHTML += "
FAIL: " + msg + "
"; this.scrollToBottom(); }, - log : function(msg) { + log: function(msg) { this.logElement.innerHTML += "
" + msg + "
"; this.scrollToBottom(); }, @@ -44,39 +44,30 @@ var PRINT = { var vehicleEventType = new VehicleEventType(); var selected = []; -function getTypes(event) -{ +function getTypes(event) { var types = window.vehicle.getSupportedEventTypes(event, false, function(data) { - if(data && data.length > 1) - { - PRINT.pass(event+" is a set of "+data.length+" events:"); - for(i in data) - { + if (data && data.length > 1) { + PRINT.pass(event + " is a set of " + data.length + " events:"); + for (i in data) { PRINT.log(data[i]); } - } - else if(data && data.length > 0) - { - PRINT.pass(event+" is a single event:"); - for(i in data) - { + } else if (data && data.length > 0) { + PRINT.pass(event + " is a single event:"); + for (i in data) { PRINT.log(data[i]); } - } - else - { - PRINT.fail(event+" unexcepted empty data field"); + } else { + PRINT.fail(event + " unexcepted empty data field"); } }, function(msg) { - PRINT.fail(((event === "")?"all events":event)+":
"+msg); + PRINT.fail(((event === "") ? "all events" : event) + ":
" + msg); } ); } -function updateInput(input, value) -{ +function updateInput(input, value) { input.value = value; input.className = "change"; input.addEventListener('webkitTransitionEnd', function callback(e) { @@ -85,35 +76,48 @@ function updateInput(input, value) }, false); } -function getValue(eventlist) -{ - var types = window.vehicle.get(eventlist, +function getValue(eventlist) { + var zoneList = getZone(eventlist); + var types = window.vehicle.get(eventlist, zoneList, function(data) { - if(data && data.length > 0) - { + if (data) { PRINT.pass("values received:"); - var list = []; - for(var i = 0; i < data.length; i++) - { - list[i] = data[i].name; - PRINT.log(data[i].name+": "+data[i].value); - } + if (eventlist.length > 1 && !! data.length && data.length > 0) { + var list = []; + for (var i = 0; i < data.length; i++) { + list[i] = data[i].property; + //list[i] = data[i].name; ??? + PRINT.log(data[i].property + ": " + data[i].value + ", zone: " + data[i].zone); + //PRINT.log(data[i].name+": "+data[i].value); ??? + } - var elements = document.getElementsByClassName('proptest'); - for (var i = 0; i < elements.length; i++) { - var propinfo = elements[i].getElementsByClassName('propinfo')[0]; - var name = propinfo.innerHTML; - var idx = list.indexOf(name); - if(idx >= 0) - { - var input = elements[i].getElementsByTagName('input')[0]; - updateInput(input, data[idx].value); + var elements = document.getElementsByClassName('proptest'); + for (var i = 0; i < elements.length; i++) { + var propinfo = elements[i].getElementsByClassName('propinfo')[0]; + var name = propinfo.innerHTML; + var idx = list.indexOf(name); + if (idx >= 0) { + var zone = elements[i].getElementsByTagName('input')[1]; + updateInput(zone, zone.value); + var input = elements[i].getElementsByTagName('input')[0]; + updateInput(input, data[idx].value); + } + } + } else { + PRINT.log(JSON.stringify(data)); + var elements = document.getElementsByClassName('proptest'); + for (var i = 0; i < elements.length; i++) { + var propinfo = elements[i].getElementsByClassName('propinfo')[0]; + if (data.property == propinfo.innerHTML) { + var zone = elements[i].getElementsByTagName('input')[1]; + updateInput(zone, zone.value); + var input = elements[i].getElementsByTagName('input')[0]; + updateInput(input, data.value); + } } } - } - else - { - PRINT.fail("no values retrieved for "+eventlist); + } else { + PRINT.fail("no values retrieved for " + eventlist); } }, function(msg) { @@ -122,10 +126,10 @@ function getValue(eventlist) ); } -function setValue(eventlist) -{ +function setValue(eventlist) { + var zoneList = getZone(eventlist); var elements = document.getElementsByClassName('proptest'); - var i, valuelist = []; + var i, valuelist = [] ; /* initialize the value list */ for (i = 0; i < eventlist.length; i++) { @@ -136,154 +140,177 @@ function setValue(eventlist) var propinfo = elements[i].getElementsByClassName('propinfo')[0]; var name = propinfo.innerHTML; var idx = eventlist.indexOf(name); - if(idx >= 0) - { - var input = elements[i].getElementsByTagName('input')[0]; - valuelist[idx] = input.value; + if (idx >= 0) { + + var input = elements[i].getElementsByTagName('input')[0]; + valuelist[idx] = input.value; } } - var types = window.vehicle.set(eventlist, valuelist, + var types = window.vehicle.set(eventlist, valuelist, zoneList, function(msg) { - PRINT.pass(msg); + PRINT.pass("Set success for: " + JSON.stringify(msg)); }, function(msg) { - PRINT.fail(msg); + PRINT.fail("Set error: " + JSON.stringify(msg)); } ); } -function eventListener(e) -{ +function eventListener(e) { + PRINT.log(e.name + " update: " + JSON.stringify(e.value)); var elements = document.getElementsByClassName('proptest'); for (var i = 0; i < elements.length; i++) { var propinfo = elements[i].getElementsByClassName('propinfo')[0]; var name = propinfo.innerHTML; - if(name === e.name) - { + if (name === e.name) { var input = elements[i].getElementsByTagName('input')[0]; - updateInput(input, e.value); + updateInput(input, e.value.value); + var zone = elements[i].getElementsByTagName('input')[1]; + updateInput(zone, e.value.zone); } } } -function subscribe(eventlist) -{ - window.vehicle.subscribe(eventlist, +function subscribe(eventlist) { + var zoneList = getZone(eventlist); + window.vehicle.subscribe(eventlist, zoneList, function(data) { - PRINT.pass("Subscribe success for: "+data); - for(var i = 0; i < data.length; i++) - { - var sub = data[i]+"_subscribe"; - var unsub = data[i]+"_unsubscribe"; -// document.getElementById(sub).className = "testbutton subscribe disable" -// document.getElementById(unsub).className = "testbutton unsubscribe"; + PRINT.pass("Subscribe success for: " + data); + for (var i = 0; i < data.length; i++) { + var sub = data[i] + "_subscribe"; + var unsub = data[i] + "_unsubscribe"; + // document.getElementById(sub).className = "testbutton subscribe disable" + // document.getElementById(unsub).className = "testbutton unsubscribe"; document.addEventListener(data[i], eventListener, false); } }, function(msg) { - PRINT.fail("Subscribe failed for: "+msg); + PRINT.fail("Subscribe failed for: " + msg); } ); } -function unsubscribe(eventlist) -{ +function unsubscribe(eventlist, zoneList) { + zoneList = getZone(eventlist); /* kill the handers first, so even if the service fails to acknowledge */ /* we've stopped listening */ - for(var i = 0; i < eventlist.length; i++) - { + for (var i = 0; i < eventlist.length; i++) { document.removeEventListener(eventlist[i], eventListener, false); } - window.vehicle.unsubscribe(eventlist, + window.vehicle.unsubscribe(eventlist, zoneList, function(data) { - PRINT.pass("Unsubscribe success for: "+data); - for(var i = 0; i < data.length; i++) - { - var sub = data[i]+"_subscribe"; - var unsub = data[i]+"_unsubscribe"; -// document.getElementById(unsub).className = "testbutton unsubscribe disable"; -// document.getElementById(sub).className = "testbutton subscribe"; + PRINT.pass("Unsubscribe success for: " + data); + for (var i = 0; i < data.length; i++) { + var sub = data[i] + "_subscribe"; + var unsub = data[i] + "_unsubscribe"; + // document.getElementById(unsub).className = "testbutton unsubscribe disable"; + // document.getElementById(sub).className = "testbutton subscribe"; } }, function(msg) { - PRINT.fail("Unsubscribe failed for: "+msg); + PRINT.fail("Unsubscribe failed for: " + msg); } ); } -function select(elem) -{ +function getZone(eventlist) { + var list = []; + if (eventlist.length > 1) { + + // for (var i = 0; i < data.length; i++) { + // list[i] = data[i].property; + // //list[i] = data[i].name; ??? + // PRINT.log(data[i].property + ": " + data[i].value); + // //PRINT.log(data[i].name+": "+data[i].value); ??? + // } + + var elements = document.getElementsByClassName('proptest'); + for (var i = 0; i < elements.length; i++) { + var propinfo = elements[i].getElementsByClassName('propinfo')[0]; + var name = propinfo.innerHTML; + var idx = eventlist.indexOf(name); + if (idx >= 0) { + var zone = elements[i].getElementsByTagName('input')[1]; + list.push(zone.value); + } + } + } else { + var elements = document.getElementsByClassName('proptest'); + for (var i = 0; i < elements.length; i++) { + var propinfo = elements[i].getElementsByClassName('propinfo')[0]; + if (eventlist[0] == propinfo.innerHTML) { + var zone = elements[i].getElementsByTagName('input')[1]; + list.push(zone.value); + } + } + } + return list.join(); +} + +function select(elem) { var name = elem.innerHTML; - if(!vehicleEventType.isValid(name)) + if (!vehicleEventType.isValid(name)) return; var idx = selected.indexOf(name); - if(elem.className == "propinfo") - { - if(idx < 0) - { + if (elem.className == "propinfo") { + if (idx < 0) { selected[selected.length] = name; } elem.className = "propinfo select"; - } - else if(elem.className == "propinfo select") - { - if(idx >= 0) - { + } else if (elem.className == "propinfo select") { + if (idx >= 0) { selected.splice(idx, 1); } elem.className = "propinfo"; } } -function start(msg) -{ - if(window.vehicle && window.vehicle.getSupportedEventTypes) - { - PRINT.pass("vehicle interface online "+msg); - } - else - { +function start(msg) { + if (window.vehicle && window.vehicle.getSupportedEventTypes) { + PRINT.pass("vehicle interface online " + msg); + } else { PRINT.fail("vehicle interface not found"); return; } var tester = document.getElementById("tester"); var part = ['
', - '
' + '
Zone:
' ]; var events = vehicleEventType.event; /* apply on all selected events */ - var html = '
apply on all selected events'+ - '
'+ - ''+ - '
'+ - '
'+ - '
' + var html = '
apply on all selected events' + + '
' + + '' + + '
' + + '
' + + '
'; /* all events */ - html += '
all events'+ - '
'; + html += '
all events'; + html += '
'; /* events */ - for(var i = 0; i < events.length; i++) - { + for (var i = 0; i < events.length; i++) { var piece = ""; - for(var j = 0; j < part.length - 1; j++) - { + for (var j = 0; j < part.length - 1; j++) { piece += part[j] + events[i]; } html += piece + part[j]; @@ -291,8 +318,7 @@ function start(msg) tester.innerHTML = html; } -function error(msg) -{ +function error(msg) { PRINT.fail(msg); } diff --git a/plugins/websocketsink/test/api.js b/plugins/websocketsink/test/vehicle.js similarity index 88% rename from plugins/websocketsink/test/api.js rename to plugins/websocketsink/test/vehicle.js index 5c0d836..6b8e600 100644 --- a/plugins/websocketsink/test/api.js +++ b/plugins/websocketsink/test/vehicle.js @@ -91,7 +91,9 @@ * errorCB: error callback, called with the eventlist that failed to unsubscribe * ******************************************************************************/ - +/* +(function () { +*/ function Vehicle(sCB, eCB, url, protocol) { /* store a copy of Vehicle this for reference in callbacks */ @@ -120,8 +122,8 @@ function Vehicle(sCB, eCB, url, protocol) this.socketProtocol = "http-only"; /* override the websocket address if parameters are given */ - if(url != undefined) this.socketUrl = url; - if(protocol != undefined) this.socketProtocol = protocol; + if(url !== undefined) this.socketUrl = url; + if(protocol !== undefined) this.socketProtocol = protocol; this.VehicleMethodCall = function(id, name, successCB, errorCB) { @@ -134,7 +136,7 @@ function Vehicle(sCB, eCB, url, protocol) this.start = function() { me.timeout = setTimeout(function(){ - if(me.errorCB != undefined) + if(me.errorCB !== undefined) { me.errorCB("\""+me.name+"\" method timed out after "+self.timeouttime+"ms"); } @@ -143,7 +145,7 @@ function Vehicle(sCB, eCB, url, protocol) } this.finish = function() { - if(me.timeout != undefined) + if(me.timeout !== undefined) { clearTimeout(me.timeout); } @@ -215,7 +217,7 @@ Vehicle.prototype.send = function(obj, successCB, errorCB) { if(!this.connected) { - if(errorCB != undefined) + if(errorCB !== undefined) { errorCB("\""+obj.name+"\" method failed because socket is closed"); } @@ -242,18 +244,24 @@ Vehicle.prototype.getSupportedEventTypes = function(type, writeable, successCB, this.send(obj, successCB, errorCB); } -Vehicle.prototype.get = function(namelist, successCB, errorCB) +Vehicle.prototype.get = function(namelist, zone, successCB, errorCB) { if(namelist.length <= 0) { return; } + var properties = []; + + for(var i = 0; i < namelist.length; i++) + { + properties[i] = {"property" : namelist[i], "zone" : zone}; + } var obj = { "type" : "method", "name": "get", "transactionid" : this.generateTransactionId(), - "data" : namelist + "data" : properties }; this.send(obj, successCB, errorCB); } @@ -271,7 +279,7 @@ Vehicle.prototype.getHistory = function(event, startTime, endTime, successCB, er } -Vehicle.prototype.set = function(namelist, valuelist, successCB, errorCB) +Vehicle.prototype.set = function(namelist, valuelist, zoneList, successCB, errorCB) { if((namelist.length != valuelist.length)||(namelist.length <= 0)) { @@ -287,31 +295,33 @@ Vehicle.prototype.set = function(namelist, valuelist, successCB, errorCB) var list = []; for(var i = 0; i < namelist.length; i++) { - var val = {"property" : namelist[i], "value" : valuelist[i]}; + var val = {"property" : namelist[i], "value" : valuelist[i],"zone" : zoneList[i]}; list[list.length] = val; } obj.data = list; this.send(obj, successCB, errorCB); } -Vehicle.prototype.subscribe = function(namelist, successCB, errorCB) +Vehicle.prototype.subscribe = function(namelist, zoneList, successCB, errorCB) { var obj = { "type" : "method", "name": "subscribe", "transactionid" : this.generateTransactionId(), - "data" : namelist + "data" : namelist, + "zone" : zoneList }; this.send(obj, successCB, errorCB); } -Vehicle.prototype.unsubscribe = function(namelist, successCB, errorCB) +Vehicle.prototype.unsubscribe = function(namelist, zoneList, successCB, errorCB) { var obj = { "type" : "method", "name": "unsubscribe", "transactionid" : this.generateTransactionId(), - "data" : namelist + "data" : namelist, + "zone" : zoneList }; this.send(obj, successCB, errorCB); } @@ -355,11 +365,11 @@ Vehicle.prototype.receive = function(msg) if(call&&(!call.done)&&(call.transactionid === event.transactionid)) { call.finish(); - if(event.error != undefined) + if(event.error !== undefined) { call.errorCB(event.error); } - if(event.data != undefined) + else if(event.data !== undefined && call.successCB !== undefined) { call.successCB(event.data); } @@ -373,3 +383,27 @@ Vehicle.prototype.receive = function(msg) } } } + +/* + // AMD / RequireJS + if (typeof define !== 'undefined' && define.amd) { + define([], function () { + return { + Vehicle: Vehicle + }; + }); + } + // Node.js + else if (typeof module !== 'undefined' && module.exports) { + module.exports = { + Vehicle: Vehicle + }; + } + // included directly via