latest vehicle api supports getevent types and get
authorTodd Brandt <tebrandt@frontier.com>
Wed, 22 Aug 2012 09:03:49 +0000 (02:03 -0700)
committerMichael Carpenter <malcom2073@gmail.com>
Thu, 23 Aug 2012 09:51:23 +0000 (05:51 -0400)
plugins/websocketsink/test/api.js
plugins/websocketsink/test/events.js [new file with mode: 0644]
plugins/websocketsink/test/index.html
plugins/websocketsink/test/server.html [new file with mode: 0644]
plugins/websocketsink/test/server.js [new file with mode: 0644]
plugins/websocketsink/test/style.css
plugins/websocketsink/test/test.js [new file with mode: 0644]

index f191a72..71e085d 100644 (file)
-/*\r
- * Copyright (c) 2012, Intel Corporation.\r
- *\r
- * This program is licensed under the terms and conditions of the\r
- * Apache License, version 2.0.  The full text of the Apache License is at\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- */\r
-\r
-var vehicle;\r
-var PRINT = {\r
-    moduleName : "IVI API",\r
-    logElement : null,\r
-    init : function(log_id) {\r
-        this.logElement = document.getElementById(log_id);\r
-    },\r
-\r
-    setModule : function(moduleName) {\r
-        this.moduleName = moduleName;\r
-    },\r
-\r
-    pass : function(msg) {\r
-        this.logElement.innerHTML += "<div class='PassClass'> " + this.moduleName + " : Pass : " + msg + "</div>";\r
-    },\r
-\r
-    fail : function(msg) {\r
-        this.logElement.innerHTML += "<div class='FailClass'> " + this.moduleName + " : Fail : " + msg + "</div>";\r
-    },\r
-\r
-    log : function(msg) {\r
-        this.logElement.innerHTML += "<div class='LogClass'> " + msg + "</div>";\r
-    },\r
-}\r
-\r
-var myJSONObject = {\r
-    "type" : "method",\r
-    "name": "GetProperty",\r
-    "Arguments": [\r
-         "Velocity"\r
-    ],\r
-    "transactionid": "0f234002-95b8-48ac-aa06-cb49e372cc1c"\r
-};\r
-\r
-function Vehicle()\r
-{\r
-    var self = this;\r
\r
-    function init() {\r
-       if ("WebSocket" in window)\r
-        {\r
-            PRINT.pass("The browser is websocket capable");\r
-           \r
-            this.socket = new WebSocket("ws://localhost:7681","http-only");\r
-            this.socket.onopen = function()\r
-            {\r
-                PRINT.pass("Connection OPEN");\r
-                this.send(JSON.stringify(myJSONObject));\r
-            };\r
-            this.socket.onmessage = function (e) \r
-            {\r
-                self.receive(e.data);\r
-            };\r
-            this.socket.onclose = function(e)\r
-            {\r
-                PRINT.fail("Connection CLOSED: " + e.reason + " code: " + e.code);\r
-            };\r
-            this.socket.onerror = function(evt) {\r
-               alert(evt);\r
-            }\r
-        }\r
-        else\r
-        {\r
-            PRINT.fail("This browser doesn't ppear to support websockets!");\r
-        }\r
-    }\r
-    init();\r
-}\r
-\r
-Vehicle.prototype.send = function(msg)\r
-{\r
-\r
-}\r
-\r
-Vehicle.prototype.receive = function(msg)\r
-{\r
-    PRINT.log("Message Received: "+msg);\r
-    var data = JSON.parse(msg);\r
-    console.log(data);\r
-}\r
-\r
-function init() {\r
-    PRINT.init("result");\r
-    vehicle = new Vehicle();\r
-}\r
+/*
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+/* ------------------------ vehicle interface ----------------------------- */
+
+function Vehicle(socketUrl, sCB, eCB, tout)
+{
+    var self = this;
+    this.successCB = sCB;
+    this.errorCB = eCB;
+    this.transactionid = 0;
+    this.methodCalls = [];
+    this.timeouttime = (tout == undefined)?2000:tout;
+    this.retries = 5;
+    this.connected = false;
+
+    this.VehicleMethodCall = function(n, sCB, eCB)
+    {
+        var me = this;
+        this.name = n;
+        this.successCB = sCB;
+        this.errorCB = eCB;
+        this.transactionid = self.transactionid++;
+
+        this.send = function(msg)
+        {
+            var errCB = (me.errorCB == undefined)?self.errorCB:me.errorCB;
+            if(!self.connected)
+            {
+                if(errCB != undefined)
+                {
+                    errCB("\""+me.name+"\" method failed because socket is closed");
+                }
+                self.methodCalls.pop(this);
+            }
+            me.timeout = setTimeout(function(){
+                if(errCB != undefined)
+                {
+                    errCB("\""+me.name+"\" method timed out after "+self.timeouttime+"ms");
+                }
+                self.methodCalls.pop(this);
+            }, self.timeouttime);
+            self.socket.send(msg);
+        }
+        this.done = function()
+        {
+            if(me.timeout != undefined)
+            {
+                clearTimeout(me.timeout);
+            }
+        }
+    }
+
+    function init() {
+        if ("WebSocket" in window)
+        {
+            self.socket = new WebSocket(socketUrl);
+            self.socket.onopen = function()
+            {
+                self.connected = true;
+                this.send("client");
+                self.successCB((self.retries < 5)?"(RECONNECTED)":"");
+                self.retries = 5;
+            };
+            self.socket.onclose = function()
+            {
+                self.connected = false;
+                self.errorCB("socket closed "+((self.retries > 0)?"retrying in 5 seconds ...":""));
+                if(self.retries > 0)
+                {
+                    setTimeout(function(){
+                        self.retries--;
+                        init();
+                    }, 5000);
+                }
+            };
+            self.socket.onerror = function(e)
+            {
+                self.errorCB(e.data);
+            };
+            self.socket.onmessage = function (e) 
+            {
+                self.receive(e.data);
+            };
+        }
+        else
+        {
+            console.log("This browser doesn't appear to support websockets!");
+        }
+    }
+    init();
+}
+
+Vehicle.prototype.getSupportedEventTypes = function(type, writeable, successCB, errorCB)
+{
+    var call = new this.VehicleMethodCall("getSupportedEventTypes", successCB, errorCB);
+    this.methodCalls.push(call);
+    var obj = {
+        "type" : "method",
+        "name": "getSupportedEventTypes",
+        "transactionid" : call.transactionid,
+        "data" : type
+    };
+    call.send(JSON.stringify(obj));
+}
+
+Vehicle.prototype.get = function(type, successCB, errorCB)
+{
+    var call = new this.VehicleMethodCall("get", successCB, errorCB);
+    this.methodCalls.push(call);
+    var obj = {
+        "type" : "method",
+        "name": "get",
+        "transactionid" : call.transactionid,
+        "data" : type
+    };
+    call.send(JSON.stringify(obj));
+}
+
+Vehicle.prototype.receive = function(msg)
+{
+    var self = this;
+    var event;
+    try {
+        event = JSON.parse(msg);
+    }
+    catch(e) {
+        self.errCB("GARBAGE MESSAGE: "+msg);
+        return;
+    }
+
+    if((event == undefined)||(event.type == undefined)||
+       (event.name == undefined)||(event.transactionid == undefined))
+    {
+        self.errCB("BADLY FORMED MESSAGE: "+msg);
+        return;
+    }
+    else
+    {
+        if(event.type === "methodReply")
+        {
+            var calls = this.methodCalls;
+            for(i in calls)
+            {
+                var call = calls[i];
+                if((call.transactionid == event.transactionid)&&
+                   (call.name === event.name))
+                {
+                    call.done();
+                    if(event.error != undefined)
+                    {
+                        call.errorCB(event.error);
+                    }
+                    else
+                    {
+                        call.successCB(event.data);
+                    }
+                    this.methodCalls.pop(call);
+                    return;
+                }
+            }
+        }
+    }
+}
diff --git a/plugins/websocketsink/test/events.js b/plugins/websocketsink/test/events.js
new file mode 100644 (file)
index 0000000..422d0ce
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+/* ---------------------- vehicle event typedef --------------------------- */
+
+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"
+    ];
+    this.value = [];
+
+    /* set random initial values for all the props */
+    for(i in this.event)
+    {
+        var prop = this.event[i];
+        this.value[prop] = Math.floor(Math.random() * 1000000);
+    }
+}
+
+VehicleEventType.prototype.getSupportedEventList = function(val)
+{
+    /* for undefined just assume everything */
+    if((val == undefined)||(val === ""))
+        return this.event;
+
+    /* grab every event with case insensitive prefix of val */
+    var value = val.toLowerCase();
+    var list = [];
+    for(i in this.event)
+    {
+        var prop = this.event[i].toLowerCase();
+        if(prop.indexOf(value) === 0)
+        {
+            list[list.length] = prop;
+        }
+    }
+
+    /* if the target val isn't alone, remove it, it's a grouping */
+    var idx = list.indexOf(value);
+    if((idx >= 0)&&(list.length > 1))
+    {
+        list.splice(idx, 1);
+    }
+    return list;
+}
+
+VehicleEventType.prototype.getValueEventList = function(val)
+{
+    var i, j, list = this.getSupportedEventList(val);
+    for(i = 0; i < list.length; i++)
+    {
+        for(j = i + 1; j < list.length; j++)
+        {
+            if(list[j].indexOf(list[i]) === 0)
+            {
+                list.splice(i, 1);
+                i--;
+            }
+        }
+    }
+    return list;
+}
+
+VehicleEventType.prototype.getValue = function(prop)
+{
+    return this.value[prop];
+}
index c02273e..a94ee39 100644 (file)
@@ -1,13 +1,17 @@
-<!doctype html>\r
-<html lang="en">\r
-<head>\r
-    <title>IVI API Tester</title>\r
-    <meta charset="utf-8">\r
-    <link rel="stylesheet" href="style.css"/>\r
-</head>\r
-<body onload="init()">\r
-    <div id="result">\r
-    </div>\r
-    <script src="api.js"></script>\r
-</body>\r
-</html>\r
+<!doctype html>
+<html lang="en">
+<head>
+    <title>IVI API Tester</title>
+    <meta charset="utf-8">
+    <link rel="stylesheet" href="style.css"/>
+    <script src="api.js"></script>
+</head>
+<body onload="init()">
+    <div id="result">
+    </div>
+    <div id="tester">
+    </div>
+    <script src="events.js"></script>
+    <script src="test.js"></script>
+</body>
+</html>
diff --git a/plugins/websocketsink/test/server.html b/plugins/websocketsink/test/server.html
new file mode 100644 (file)
index 0000000..0e5d50c
--- /dev/null
@@ -0,0 +1,22 @@
+<!doctype html>
+<html lang="en">
+<head>
+    <title>IVI API Server Test</title>
+    <meta charset="utf-8">
+    <style>
+#result {
+    position: absolute;
+    height: 99%;
+    width: 99%;
+    overflow-y: auto;
+    word-wrap: break-word;
+}
+    </style>
+    <script src="events.js"></script>
+    <script src="server.js"></script>
+</head>
+<body>
+    <div id="result">
+    </div>
+</body>
+</html>
diff --git a/plugins/websocketsink/test/server.js b/plugins/websocketsink/test/server.js
new file mode 100644 (file)
index 0000000..2d4fc44
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+/* --------------------------- utility code ------------------------------- */
+
+var PRINT = {
+    logElement : null,
+    init : function(log_id) {
+        this.logElement = document.getElementById(log_id);
+    },
+
+    scrollToBottom : function() {
+        this.logElement.scrollTop = this.logElement.scrollHeight;
+    },
+
+    incoming : function(msg) {
+        this.logElement.innerHTML += "<div style='color: blue'> REQUEST: " + msg + "</div>";
+        this.scrollToBottom();
+    },
+
+    outgoing : function(msg) {
+        this.logElement.innerHTML += "<div style='color: purple'> RESPONSE: " + msg + "</div>";
+        this.scrollToBottom();
+    },
+
+    pass : function(msg) {
+        this.logElement.innerHTML += "<div style='color: green'> SUCCESS: " + msg + "</div>";
+        this.scrollToBottom();
+    },
+
+    fail : function(msg) {
+        this.logElement.innerHTML += "<div style='color: red'> FAIL: " + msg + "</div>";
+        this.scrollToBottom();
+    },
+
+    log : function(msg) {
+        this.logElement.innerHTML += "<div class='LogClass'> " + msg + "</div>";
+        this.scrollToBottom();
+    },
+}
+
+/* ----------------------------- test code --------------------------------- */
+
+function VehicleServer(socketUrl)
+{
+    var self = this;
+    this.vehicleEventType = new VehicleEventType();
+    function init() {
+        if ("WebSocket" in window)
+        {
+            self.socket = new WebSocket(socketUrl);
+            self.socket.onopen = function()
+            {
+                PRINT.pass("Server READY");
+                this.send("server");
+            };
+            self.socket.onclose = function()
+            {
+                PRINT.fail("Server CLOSED");
+            };
+            self.socket.onerror = function(e)
+            {
+                PRINT.fail("Server ERROR: "+e.data);
+            };
+            self.socket.onmessage = function (e) 
+            {
+                self.receive(e.data);
+            };
+        }
+        else
+        {
+            PRINT.fail("This browser doesn't appear to support websockets!");
+        }
+    }
+    init();
+}
+
+VehicleServer.prototype.receive = function(msg)
+{
+    var event = JSON.parse(msg);
+    /* accept only methods with transaction ids */
+    if((event == undefined)||(event.transactionid == undefined)||
+       (event.type != "method"))
+    {
+        return;
+    }
+
+    var obj;
+    PRINT.incoming(msg);
+    if(event.name === "getSupportedEventTypes")
+    {
+        obj = {
+            "type" : "methodReply",
+            "name": event.name,
+            "transactionid" : event.transactionid,
+            "data" : this.vehicleEventType.getSupportedEventList(event.data)
+        };
+    }
+    else if(event.name === "get")
+    {
+        var names = this.vehicleEventType.getValueEventList(event.data);
+        if(names.length > 0)
+        {
+            obj = {
+                "type" : "methodReply",
+                "name": event.name,
+                "transactionid" : event.transactionid,
+                "data" : []
+            };
+            for(i in names)
+            {
+                var value = this.vehicleEventType.getValue(names[i]);
+                obj.data.push({"name" : names[i], "value" : value});
+            }
+        }
+        else
+        {
+            obj = {
+                "type" : "methodReply",
+                "name": event.name,
+                "transactionid" : event.transactionid,
+                "error" : event.data + " is not a valid event"
+            };
+        }
+    }
+    else
+    {
+        obj = {
+            "type" : "methodReply",
+            "name": event.name,
+            "transactionid" : event.transactionid,
+            "error" : event.name + " is not a valid method"
+        };
+    }
+    PRINT.outgoing(JSON.stringify(obj));
+    this.socket.send(JSON.stringify(obj));
+}
+
+window.addEventListener('load', function () {
+    "use strict";
+    PRINT.init("result");
+    var server = new VehicleServer("ws://localhost:23000/vehicle");
+});
index fd7ef72..4302ade 100644 (file)
@@ -1,8 +1,99 @@
-\r
-.PassClass {\r
-    color: green;\r
-}\r
-\r
-.FailClass {\r
-    color: red;\r
-}\r
+.PassClass {
+    font: bold 16px Arial;
+    color: green;
+}
+
+.FailClass {
+    font: bold 16px Arial;
+    color: red;
+}
+
+.LogClass {
+    font: 16px Arial;
+    color: black;
+}
+
+#tester {
+    position: absolute;
+    -webkit-user-select: none;
+    top: 0px;
+    left: 0%;
+    height: 100%;
+    width: 60%;
+    overflow-y: auto;
+}
+
+#result {
+    position: absolute;
+    top: 0px;
+    left: 60%;
+    height: 98%;
+    width: 39%;
+    padding-top: 1%;
+    background-color: #eeeeee;
+    padding-left: 1%;
+    overflow-y: auto;
+}
+
+.proptest {
+    position: relative;
+    text-align: left;
+    left: 0px;
+    width: 98%;
+    color: #ffffff;
+    font: 18px Arial;
+    line-height: 30px;
+    margin-left: 1%;
+    margin-right: 1%;
+    border: solid 1px #333;
+    background-color: #aaaaaa;
+    overflow: hidden;
+}
+
+.proptest .buttons {
+    position: relative;
+    float: right;
+    width: 240px;
+}
+
+.testbutton {
+    position: relative;
+    float: right;
+    color: #d7d7d7;
+    border: solid 1px #333;
+    text-align: center;
+    text-decoration: none;
+    font: 16px/100% Arial, Helvetica, sans-serif;
+    text-shadow: 0 1px 1px rgba(0,0,0,.3);
+    -webkit-border-radius: 12px;
+    border-radius: 12px;
+    background: -webkit-gradient(linear, left top, left bottom, from(#666), to(#000));
+    height: 25px;
+    line-height: 24px;
+    cursor: pointer;
+    box-shadow: 2px 2px 14px #000;
+    margin-top: 1%;
+    margin-bottom: 1%;
+    margin-right: 5px;
+}
+
+.testbutton.types {
+    width: 180px;
+}
+
+.testbutton.types:after {
+    content: 'getSupportedEventTypes';
+}
+
+.testbutton.get {
+    width: 40px;
+}
+
+.testbutton.get:after {
+    content: 'get';
+}
+
+.testbutton:active {
+    color: #666;
+    background: -webkit-gradient(linear, left top, left bottom, from(#000), to(#444));
+}
diff --git a/plugins/websocketsink/test/test.js b/plugins/websocketsink/test/test.js
new file mode 100644 (file)
index 0000000..f041e93
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0.  The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+
+/* --------------------------- utility code ------------------------------- */
+
+var PRINT = {
+    logElement : null,
+    init : function(log_id) {
+        this.logElement = document.getElementById(log_id);
+    },
+
+    scrollToBottom : function() {
+        this.logElement.scrollTop = this.logElement.scrollHeight;
+    },
+
+    clear : function() {
+        this.logElement.innerHTML = "";
+    },
+
+    pass : function(msg) {
+        this.logElement.innerHTML += "<div class='PassClass'>PASS: " + msg + "</div>";
+    },
+
+    fail : function(msg) {
+        this.logElement.innerHTML += "<div class='FailClass'>FAIL: " + msg + "</div>";
+        this.scrollToBottom();
+    },
+
+    log : function(msg) {
+        this.logElement.innerHTML += "<div class='LogClass'> " + msg + "</div>";
+    },
+}
+
+/* ----------------------------- test code --------------------------------- */
+
+function getTypes(event)
+{
+    var types = window.vehicle.getSupportedEventTypes(event, false,
+        function(data) {
+            PRINT.clear();
+            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)
+                {
+                    PRINT.log(data[i]);
+                }
+            }
+            else
+            {
+                PRINT.fail(event+" unexcepted empty data field");
+            }
+        },
+        function(msg) {
+            PRINT.fail(((event === "")?"all events":event)+":<br>"+msg);
+        }
+    );
+}
+
+function getValue(event)
+{
+    var types = window.vehicle.get(event,
+        function(data) {
+            PRINT.clear();
+            if(data && data.length > 0)
+            {
+                PRINT.pass(event+" values received");
+                for(i in data)
+                {
+                    PRINT.log(data[i].name+": "+data[i].value);
+                }
+            }
+            else
+            {
+                PRINT.fail("no values retrieved for "+event);
+            }
+        },
+        function(msg) {
+            PRINT.fail(((event === "")?"all events":event)+":<br>"+msg);
+        }
+    );
+}
+
+function start(msg)
+{
+    if(window.vehicle && window.vehicle.getSupportedEventTypes)
+    {
+        PRINT.pass("vehicle interface online "+msg);
+    }
+    else
+    {
+        PRINT.fail("vehicle interface not found");
+        return;
+    }
+
+    var vehicleEventType = new VehicleEventType();
+    var tester = document.getElementById("tester");
+    var part1 = '<div class="proptest">';
+    var part2 = '<div class="buttons"><div class="testbutton types" onclick=getTypes("';
+    var part3 = '")></div><div class="testbutton get" onclick=getValue("'
+    var part4 = '")></div></div></div>';
+    var events = vehicleEventType.event;
+    var html = part1 + "all events" + part2 + part3 + part4;
+    for(i in events)
+    {
+        html += part1 + events[i] + part2 + events[i] + 
+                part3 + events[i] + part4;
+    }
+    tester.innerHTML = html;
+}
+
+function error(msg)
+{
+    PRINT.fail(msg);
+}
+
+function init() {
+    PRINT.init("result");
+    window.vehicle = new Vehicle("ws://localhost:23000/vehicle",
+        start, error);
+}