From fdfc5cfbf57d82c99e0e5c447611eb1be37b90e2 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Fri, 5 Dec 2014 09:23:44 -0800 Subject: [PATCH] removed unmaintained plugins --- CMakeLists.txt | 2 - RELEASE | 6 +- plugins/CMakeLists.txt | 3 - plugins/bluemonkey/irccoms.h | 4 +- plugins/tpms/CMakeLists.txt | 18 - plugins/tpms/README | 41 -- plugins/tpms/tpmsplugin.cpp | 352 ---------- plugins/tpms/tpmsplugin.h | 62 -- plugins/websocketsink/CMakeLists.txt | 16 - plugins/websocketsink/protocol | 25 - plugins/websocketsink/test/events.js | 130 ---- plugins/websocketsink/test/index.html | 17 - plugins/websocketsink/test/servertest/client.html | 17 - plugins/websocketsink/test/servertest/server.html | 22 - plugins/websocketsink/test/servertest/server.js | 312 --------- plugins/websocketsink/test/style.css | 182 ----- plugins/websocketsink/test/test.js | 328 --------- plugins/websocketsink/test/vehicle.js | 409 ------------ plugins/websocketsink/websocketsink.cpp | 94 --- plugins/websocketsink/websocketsink.h | 46 -- plugins/websocketsink/websocketsinkmanager.cpp | 769 ---------------------- plugins/websocketsink/websocketsinkmanager.h | 56 -- plugins/websocketsourceplugin/CMakeLists.txt | 16 - plugins/websocketsourceplugin/websocketsource.cpp | 638 ------------------ plugins/websocketsourceplugin/websocketsource.h | 69 -- 25 files changed, 7 insertions(+), 3627 deletions(-) delete mode 100644 plugins/tpms/CMakeLists.txt delete mode 100644 plugins/tpms/README delete mode 100644 plugins/tpms/tpmsplugin.cpp delete mode 100644 plugins/tpms/tpmsplugin.h delete mode 100644 plugins/websocketsink/CMakeLists.txt delete mode 100644 plugins/websocketsink/protocol delete mode 100644 plugins/websocketsink/test/events.js delete mode 100644 plugins/websocketsink/test/index.html delete mode 100644 plugins/websocketsink/test/servertest/client.html delete mode 100644 plugins/websocketsink/test/servertest/server.html delete mode 100644 plugins/websocketsink/test/servertest/server.js delete mode 100644 plugins/websocketsink/test/style.css delete mode 100644 plugins/websocketsink/test/test.js delete mode 100644 plugins/websocketsink/test/vehicle.js delete mode 100644 plugins/websocketsink/websocketsink.cpp delete mode 100644 plugins/websocketsink/websocketsink.h delete mode 100644 plugins/websocketsink/websocketsinkmanager.cpp delete mode 100644 plugins/websocketsink/websocketsinkmanager.h delete mode 100644 plugins/websocketsourceplugin/CMakeLists.txt delete mode 100644 plugins/websocketsourceplugin/websocketsource.cpp delete mode 100644 plugins/websocketsourceplugin/websocketsource.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b5d8b3e..504ada7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,6 @@ set (DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/packages/${PROJECT_NAME} option(qtmainloop "Use QCoreApplication mainloop " OFF) option(websocket_plugin "websocket source and sink plugins" OFF) -option(websocketold_plugin "old websocket sink plugin" OFF) -option(tpms_plugin "TPMS plugin " OFF) option(obd2_plugin "OBD-II plugin" OFF) option(database_plugin "Database plugins" OFF) option(qt_bindings "AMB Qt DBus bindings" OFF) diff --git a/RELEASE b/RELEASE index 83e6e02..8d818a4 100644 --- a/RELEASE +++ b/RELEASE @@ -1,12 +1,14 @@ Release notes for release 0.13 New features: -- [OpenCV plugin] code updated to the new 3.0 API -- [OpenCV plugin] driver drowsiness detection test code - [xwalk extension] implements full W3C automotive BG vehicle and data APIs +- [OpenCV plugin] code updated to the new 3.0 beta API +- [OpenCV plugin] driver drowsiness detection test code - [Bluemonkey plugin] support for zones in JS API. +- [Bluemonkey plugin] database module. Changes: - OpenCV plugin experimental options for cuda and kinect are removed +- Removed unmaintained plugins: tpms, websocket{sink,source} Fixes: diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index f75c527..b7b9b24 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -24,11 +24,8 @@ add_subdirectory(common) add_subdirectory(wheel) add_subdirectory(dbus) add_subdirectory(websocket) -add_subdirectory(websocketsink) -add_subdirectory(websocketsourceplugin) add_subdirectory(obd2plugin) add_subdirectory(demosink) -add_subdirectory(tpms) add_subdirectory(database) add_subdirectory(opencvlux) add_subdirectory(murphyplugin) diff --git a/plugins/bluemonkey/irccoms.h b/plugins/bluemonkey/irccoms.h index 0adc53c..cf0ef0b 100644 --- a/plugins/bluemonkey/irccoms.h +++ b/plugins/bluemonkey/irccoms.h @@ -14,7 +14,7 @@ class IrcCommunication: public IrcSession { Q_OBJECT Q_PROPERTY(QStringList channels READ channels WRITE setChannels) - Q_PROPERTY(bool ssl WRITE setSsl) + Q_PROPERTY(bool ssl READ ssl WRITE setSsl) public: IrcCommunication(std::map config, QObject* parent=0); QStringList channels() { return mChannels; } @@ -22,6 +22,8 @@ public: void announceDequeue(); + bool ssl() { return isSecure(); } + public Q_SLOTS: void respond(QString target, QString msg); void announce(QString); diff --git a/plugins/tpms/CMakeLists.txt b/plugins/tpms/CMakeLists.txt deleted file mode 100644 index c879d43..0000000 --- a/plugins/tpms/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -if(tpms_plugin) - - include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs}) - - pkg_check_modules(libusb REQUIRED libusb-1.0) - set(link_libraries ${link_libraries} ${libusb_LIBRARIES}) - include_directories(${libusb_INCLUDE_DIRS}) -#check_include_files(libusb.h HAVE_USB) -#set(CMAKE_CXX_FLAGS "-g -I/usr/include/libusb-1.0/ -lusb-1.0") - - set(tpmsplugin_headers tpmsplugin.h) - set(tpmsplugin_sources tpmsplugin.cpp) - - add_library(tpmsplugin MODULE ${tpmsplugin_sources}) - set_target_properties(tpmsplugin PROPERTIES PREFIX "") - target_link_libraries(tpmsplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) - -endif(tpms_plugin) \ No newline at end of file diff --git a/plugins/tpms/README b/plugins/tpms/README deleted file mode 100644 index be4aa49..0000000 --- a/plugins/tpms/README +++ /dev/null @@ -1,41 +0,0 @@ -TPMS - Tire Pressure Monitoring System - -INTRO -===== -This plugin is a source module to support four-wheel tire pressure and temperature reading. -Right now, it only supports the USB TPMS module available here: -http://store.mp3car.com/USB_TPMS_Version_2_20_4_Sensor_Kit_p/com-090.htm (also available -on Amazon). - -CONFIGURATION -============= -The configuration for the module is contained within the source code, so all that is required -to run is adding the following source module to an ambd config file: - "sources" : [ - { - "name" : "Tpms", - "path" : "/usr/local/lib/automotive-message-broker/tpmsplugin.so", - } - ], - -HOW TO USE -========== -Depending on system configuration, the ambd module may need to be run as root to get access -to the USB driver. Once loaded, the module reads data every 5 seconds for broadcasting. The -tire pressure is in kPa and the tire temperature in degrees Celsius. - -KNOWN ISSUES -============ -This is very much an alpha version. Things which should probably be looked at: -1) Better handling when root access is required -2) Usage of mode strings from USB module -3) Generalizing the framework somewhat more to allow usage of other modules (I am not aware -of any others with easy USB though) -4) Pulling hardcoded configuration parameters into the ambd config file, e.g. device pids, -which scale to use, read interval, etc. -5) Others I'm sure... - - -Enjoy! -Tim Trampedach -tim@timtt.com \ No newline at end of file diff --git a/plugins/tpms/tpmsplugin.cpp b/plugins/tpms/tpmsplugin.cpp deleted file mode 100644 index 2dea1fd..0000000 --- a/plugins/tpms/tpmsplugin.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/* -Copyright (C) 2012 Intel Corporation - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "tpmsplugin.h" - -#include -#include -#include -#include - -using namespace std; - -#include "debugout.h" -#include "timestamp.h" - -#define ENDPOINT_IN 0x81 -#define ENDPOINT_OUT 0x01 - -#define DEVICE_VID 0x0000 -#define DEVICE_PID 0x0001 - -#define MAX_SENSORS 4 - -//timeout for performing interrupt r/w operations in milliseconds -#define INTR_TIMEOUT 1000 - -#define PSI_MULTIPLIER 14.5038 -#define KPA_MULTIPLIER 100 -#define PRESSURE_SCALE 0.025 - -#define FARENHEIT_MULTIPLIER 1.8 - - -static gboolean timeoutCallback(gpointer data) -{ - TpmsPlugin* src = (TpmsPlugin*)data; - - int r = src->readValues(); - - return true; -} - -TpmsPlugin::TpmsPlugin(AbstractRoutingEngine* re, map config) -:AbstractSource(re, config) -{ - lfPressure = rfPressure = lrPressure = rrPressure = 0; - lfTemperature = rfTemperature = lrTemperature = rrTemperature = 0; - - int r = 1; - - r = libusb_init(NULL); - if (r < 0) { - DebugOut() << "TPMS: Plugin load failure. Failed to initialize libusb" << endl; - } - else { - r = findDevice(); - if (r < 0) { - DebugOut() << "TPMS: Plugin load failure. Could not find/open device - run as root?" << endl; - } - else { - // need to detach device from kernel driver before claiming the interface - r = detachDevice(); - if (r < 0) { - DebugOut() << "TPMS: Plugin load failure. USB device detach failed with code " << r << endl; - } - else { - r = libusb_claim_interface(mDeviceHandle, 0); - if (r < 0) { - DebugOut() << "TPMS: Plugin load failure. usb_claim_interface error " << r << endl; - } - else { - DebugOut() << "TPMS: USB interface initialized" << endl; - - re->setSupported(supported(), this); - g_timeout_add(5000, timeoutCallback, this ); - DebugOut() << "TPMS: set to read sensor every 5 seconds" << endl; - } - } - } - } -} - - -extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map config) -{ - return new TpmsPlugin(routingengine, config); - -} - -const string TpmsPlugin::uuid() -{ - return "5e896a00-15b3-11e3-8ffd-0800200c9a66"; -} - - -void TpmsPlugin::getPropertyAsync(AsyncPropertyReply *reply) -{ - DebugOut() << "TPMS: getPropertyAsync called for property: " << reply->property << endl; - - if(reply->property == VehicleProperty::TirePressureLeftFront) { - VehicleProperty::TirePressureLeftFrontType temp(lfPressure); - reply->success = true; - reply->value = &temp; - reply->completed(reply); - } - else if(reply->property == VehicleProperty::TirePressureRightFront) { - VehicleProperty::TirePressureRightFrontType temp(rfPressure); - reply->success = true; - reply->value = &temp; - reply->completed(reply); - } - else if(reply->property == VehicleProperty::TirePressureLeftRear) { - VehicleProperty::TirePressureLeftRearType temp(lrPressure); - reply->success = true; - reply->value = &temp; - reply->completed(reply); - } - else if(reply->property == VehicleProperty::TirePressureRightRear) { - VehicleProperty::TirePressureRightRearType temp(rrPressure); - reply->success = true; - reply->value = &temp; - reply->completed(reply); - } - else if(reply->property == VehicleProperty::TireTemperatureLeftFront) { - VehicleProperty::TireTemperatureLeftFrontType temp(lfTemperature); - reply->success = true; - reply->value = &temp; - reply->completed(reply); - } - else if(reply->property == VehicleProperty::TireTemperatureRightFront) { - VehicleProperty::TireTemperatureRightFrontType temp(rfTemperature); - reply->success = true; - reply->value = &temp; - reply->completed(reply); - } - else if(reply->property == VehicleProperty::TireTemperatureLeftRear) { - VehicleProperty::TireTemperatureLeftRearType temp(lrTemperature); - reply->success = true; - reply->value = &temp; - reply->completed(reply); - } - else if(reply->property == VehicleProperty::TireTemperatureRightRear) { - VehicleProperty::TireTemperatureRightRearType temp(rrTemperature); - reply->success = true; - reply->value = &temp; - reply->completed(reply); - } - - else { - DebugOut() << "TPMS: no such getProperty type: " << reply->property << endl; - reply->success = false; - reply->error = AsyncPropertyReply::InvalidOperation; - reply->value = nullptr; - reply->completed(reply); - } -} - -void TpmsPlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply) -{ - ///not supported - reply->completed(reply); -} - -AsyncPropertyReply *TpmsPlugin::setProperty(AsyncSetPropertyRequest request ) -{ - return NULL; -} - -void TpmsPlugin::subscribeToPropertyChanges(VehicleProperty::Property property) -{ - mRequests.push_back(property); -} - -PropertyList TpmsPlugin::supported() -{ - PropertyList props; - props.push_back(VehicleProperty::TirePressureLeftFront); - props.push_back(VehicleProperty::TirePressureRightFront); - props.push_back(VehicleProperty::TirePressureLeftRear); - props.push_back(VehicleProperty::TirePressureRightRear); - props.push_back(VehicleProperty::TireTemperatureLeftFront); - props.push_back(VehicleProperty::TireTemperatureRightFront); - props.push_back(VehicleProperty::TireTemperatureLeftRear); - props.push_back(VehicleProperty::TireTemperatureRightRear); - - return props; -} - -void TpmsPlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property) -{ - mRequests.remove(property); -} - -int TpmsPlugin::findDevice(void) -{ - int deviceVid = DEVICE_VID; - int devicePid = DEVICE_PID; - - DebugOut() << "TPMS: Trying to open USB device with VID: " << deviceVid << " PID: " << devicePid << endl; - mDeviceHandle = libusb_open_device_with_vid_pid(NULL, DEVICE_VID, DEVICE_PID); - - return mDeviceHandle ? 0 : -1; -} - - -int TpmsPlugin::detachDevice(void) -{ - int r; - r = libusb_kernel_driver_active(mDeviceHandle, 0); - if (r == 1) { - DebugOut() << "TPMS: USB device seems to be kernel driven, trying to detach" << endl; - r = libusb_detach_kernel_driver(mDeviceHandle, 0); - } - return r; -} - - -int TpmsPlugin::exitClean(int deinit) -{ - if (deinit) { - libusb_release_interface(mDeviceHandle, 0); - libusb_attach_kernel_driver(mDeviceHandle, 0); - libusb_close(mDeviceHandle); - } - libusb_exit(NULL); -} - - -int TpmsPlugin::readValues() -{ - int snum; - unsigned char buf[4]; - - // Sensor 1 = Left Front - // Sensor 2 = Right Front - // Sensor 3 = Left Rear - // Sensor 4 = Right Rear - - for (snum = 1; snum <= MAX_SENSORS; snum++) { - readUsbSensor(snum, buf); - - // only do this if sensor is available - if (buf[3] != 0xff) { - string mode_string; - char print_string[100]; - - switch (snum) { - case 1: - lfPressure = ((float)buf[0]-40) * PRESSURE_SCALE * KPA_MULTIPLIER; - lfTemperature = (float)buf[1]-40; - sprintf(print_string, "TPMS: Left front pressure = %5.1f kPa, temperature = %5.1f degrees Celsius", lfPressure, lfTemperature); - DebugOut() << print_string << endl; - break; - case 2: - rfPressure = (buf[0]-40) * PRESSURE_SCALE * KPA_MULTIPLIER; - rfTemperature = buf[1]-40; - sprintf(print_string, "TPMS: Right front pressure = %5.1f kPa, temperature = %5.1f degrees Celsius", rfPressure, rfTemperature); - DebugOut() << print_string << endl; - break; - case 3: - lrPressure = (buf[0]-40) * PRESSURE_SCALE * KPA_MULTIPLIER; - lrTemperature = buf[1]-40; - sprintf(print_string, "TPMS: Left rear pressure = %5.1f kPa, temperature = %5.1f degrees Celsius", lrPressure, lrTemperature); - DebugOut() << print_string << endl; - break; - case 4: - rrPressure = (buf[0]-40) * PRESSURE_SCALE * KPA_MULTIPLIER; - rrTemperature = buf[1]-40; - sprintf(print_string, "TPMS: Right rear pressure = %5.1f kPa, temperature = %5.1f degrees Celsius", rrPressure, rrTemperature); - DebugOut() << print_string << endl; - break; - } - - // make sensor mode human-readable - // FIXME: for future reference, modes not being used - switch (buf[3]) { - case 0x01: mode_string = "normal"; break; - case 0x02: mode_string = "pressure_alert"; break; - // more to add here... - default: mode_string = "unknown"; break; - } - } - else { - DebugOut() << "TPMS: Unable to read sensor " << sensorNumberToString(snum) << " (" << snum << ")" << endl; - } - } - - VehicleProperty::TirePressureLeftFrontType lfPres(lfPressure); - VehicleProperty::TirePressureRightFrontType rfPres(rfPressure); - VehicleProperty::TirePressureLeftRearType lrPres(lrPressure); - VehicleProperty::TirePressureRightRearType rrPres(rrPressure); - VehicleProperty::TireTemperatureLeftFrontType lfTemp(lfTemperature); - VehicleProperty::TireTemperatureRightFrontType rfTemp(rfTemperature); - VehicleProperty::TireTemperatureLeftRearType lrTemp(lrTemperature); - VehicleProperty::TireTemperatureRightRearType rrTemp(rrTemperature); - - routingEngine->updateProperty(&lfPres, uuid()); - routingEngine->updateProperty(&rfPres, uuid()); - routingEngine->updateProperty(&lrPres, uuid()); - routingEngine->updateProperty(&rrPres, uuid()); - routingEngine->updateProperty(&lfTemp, uuid()); - routingEngine->updateProperty(&rfTemp, uuid()); - routingEngine->updateProperty(&lrTemp, uuid()); - routingEngine->updateProperty(&rrTemp, uuid()); - - return 0; -} - -int TpmsPlugin::readUsbSensor(int sid, unsigned char *buf) -{ - int r, transferred; - - buf[0] = 0x20 + sid; - r = libusb_interrupt_transfer(mDeviceHandle, ENDPOINT_OUT, buf, 1, &transferred, INTR_TIMEOUT); - if (r < 0) { - DebugOut() << "TPMS: USB write interrupt failed, code " << r << endl; - } - - r = libusb_interrupt_transfer(mDeviceHandle, ENDPOINT_IN, buf, 4, &transferred, INTR_TIMEOUT); - if (r < 0) { - DebugOut() << "TPMS: USB read interrupt failed, code " << r << endl; - } - - return r; -} - - -string TpmsPlugin::sensorNumberToString(int snid) -{ - switch (snid) { - case 1: return "left front"; break; - case 2: return "right front"; break; - case 3: return "left rear"; break; - case 4: return "right rear"; break; - default: return "unknown"; - } -} diff --git a/plugins/tpms/tpmsplugin.h b/plugins/tpms/tpmsplugin.h deleted file mode 100644 index 7ed87af..0000000 --- a/plugins/tpms/tpmsplugin.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright (C) 2012 Tim Trampedach - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef TPMSPLUGIN_H -#define TPMSPLUGIN_H - -#include -#include - -using namespace std; - -class TpmsPlugin: public AbstractSource -{ - -public: - TpmsPlugin(AbstractRoutingEngine* re, map config); - - const string uuid(); - void getPropertyAsync(AsyncPropertyReply *reply); - void getRangePropertyAsync(AsyncRangePropertyReply *reply); - AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request); - void subscribeToPropertyChanges(VehicleProperty::Property property); - void unsubscribeToPropertyChanges(VehicleProperty::Property property); - PropertyList supported(); - - void supportedChanged(PropertyList) {} - - int readValues(); - - int supportedOperations() { return Get; } - -private: - PropertyList mRequests; - float lfPressure, rfPressure, lrPressure, rrPressure; - float lfTemperature, rfTemperature, lrTemperature, rrTemperature; - struct libusb_device_handle *mDeviceHandle; - - int findDevice(); - int detachDevice(); - int exitClean(int deinit); - - int readUsbSensor(int sid, unsigned char *buf); - - string sensorNumberToString(int snid); -}; - -#endif // TPMSPLUGIN_H diff --git a/plugins/websocketsink/CMakeLists.txt b/plugins/websocketsink/CMakeLists.txt deleted file mode 100644 index d4b1c31..0000000 --- a/plugins/websocketsink/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -if(websocketold_plugin) - -include(CheckIncludeFiles) -include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs}) - -pkg_check_modules(websockets REQUIRED libwebsockets) - -set(websocketsinkplugin_headers websocketsink.h websocketmanager.h) -set(websocketsinkplugin_sources websocketsinkmanager.cpp websocketsink.cpp) -add_library(websocketsinkplugin MODULE ${websocketsinkplugin_sources}) -set_target_properties(websocketsinkplugin PROPERTIES PREFIX "") -target_link_libraries(websocketsinkplugin amb ${websockets_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) - -install(TARGETS websocketsinkplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) - -endif(websocketold_plugin) diff --git a/plugins/websocketsink/protocol b/plugins/websocketsink/protocol deleted file mode 100644 index 5250b11..0000000 --- a/plugins/websocketsink/protocol +++ /dev/null @@ -1,25 +0,0 @@ -Example protocol messages - -Property changed event: -{"type":"valuechanged","name":"VehicleSpeed","data":"217","transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66", "timestamp":"1354521964.60253","sequence":"0"} - -Get property request: -{"type":"method","name":"get","data":["VehicleSpeed"],"transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"} - -Get property reply: -{"type":"methodReply","name":"get","data":[{"property":"VehicleSpeed","value":"17"}],"transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66", "timestamp" : "1354521964.24962", "sequence": "0" } - -Get supported request: -{"type":"method","name":"getSupportedEventTypes","data":[],"transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"} - -Get supported reply: -{"type":"methodReply","name":"getSupportedEventTypes","data":["running_status_speedometer","running_status_engine_speed","running_status_steering_wheel_angle","running_status_transmission_gear_status","EngineSpeed","VehicleSpeed","AccelerationX","TransmissionShiftPosition","SteeringWheelAngle","ThrottlePosition","EngineCoolantTemperature","VIN","WMI","BatteryVoltage","MachineGunTurretStatus"],"transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"} - -Subscribe to data: -{"type":"method","name":"subscribe","data":["EngineSpeed"],"transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"} - -Subscribe to data reply: -{"type":"methodReply","name":"subscribe","data":["EngineSpeed"],"transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"} - -Get History request: -{"type":"method","name":"getRange","data": {"timeBegin":"1368825008.35948","timeEnd":"1368825018.35948","sequenceBegin":"-1","sequenceEnd":"-1"},"transactionid":"b07589ba-417c-4604-80c6-01c0dcbd524d"} diff --git a/plugins/websocketsink/test/events.js b/plugins/websocketsink/test/events.js deleted file mode 100644 index cb0cfd5..0000000 --- a/plugins/websocketsink/test/events.js +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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 = [ -"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 = []; - - /* 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.getValuesEventList = function(vals) -{ - var i, j, list = []; - for(i = 0; i < vals.length; i++) - { - var sublist = this.getValueEventList(vals[i]); - for(j = 0; j < sublist.length; j++) - { - if(list.indexOf(sublist[j]) < 0) - { - list[list.length] = sublist[j]; - } - } - } - return list; -} - -VehicleEventType.prototype.isValueEvent = function(val) -{ - var list = this.getValueEventList(val); - return(list.length === 1); -} - -VehicleEventType.prototype.getValue = function(prop) -{ - return this.value[prop]; -} - -VehicleEventType.prototype.isValid = function(prop) -{ - return (this.event.indexOf(prop) >= 0); -} - -VehicleEventType.prototype.setValue = function(prop, newval) -{ - this.value[prop] = newval; -} diff --git a/plugins/websocketsink/test/index.html b/plugins/websocketsink/test/index.html deleted file mode 100644 index 9a5daef..0000000 --- a/plugins/websocketsink/test/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - IVI API Tester - - - - - -
-
-
-
- - - - diff --git a/plugins/websocketsink/test/servertest/client.html b/plugins/websocketsink/test/servertest/client.html deleted file mode 100644 index 9ef2ee3..0000000 --- a/plugins/websocketsink/test/servertest/client.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - IVI API Tester - - - - - -
-
-
-
- - - - diff --git a/plugins/websocketsink/test/servertest/server.html b/plugins/websocketsink/test/servertest/server.html deleted file mode 100644 index 43dc72a..0000000 --- a/plugins/websocketsink/test/servertest/server.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - IVI API Server Test - - - - - - -
-
- - diff --git a/plugins/websocketsink/test/servertest/server.js b/plugins/websocketsink/test/servertest/server.js deleted file mode 100644 index 3fcda40..0000000 --- a/plugins/websocketsink/test/servertest/server.js +++ /dev/null @@ -1,312 +0,0 @@ -/* - * 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 += "
REQUEST: " + msg + "
"; - this.scrollToBottom(); - }, - - outgoing : function(msg) { - this.logElement.innerHTML += "
RESPONSE: " + msg + "
"; - this.scrollToBottom(); - }, - - pass : function(msg) { - this.logElement.innerHTML += "
SUCCESS: " + msg + "
"; - this.scrollToBottom(); - }, - - fail : function(msg) { - this.logElement.innerHTML += "
FAIL: " + msg + "
"; - this.scrollToBottom(); - }, - - log : function(msg) { - this.logElement.innerHTML += "
" + msg + "
"; - this.scrollToBottom(); - }, -} - -/* ----------------------------- test code --------------------------------- */ - -function VehicleServer(socketUrl) -{ - var self = this; - this.vehicleEventType = new VehicleEventType(); - this.subscriptions = []; - - this.Signal = function(name) - { - var me = this; - this.users = 0; - this.name = name; - this.start = function() { - if(me.users <= 0) - { - var interval = Math.floor(Math.random()*5000) + 1000; - me.timer = setInterval(function() { - var value = parseInt(self.vehicleEventType.getValue(me.name)) + 1; - self.vehicleEventType.setValue(me.name, value); - var obj = { - "type" : "valuechanged", - "name": me.name, - "data" : value - }; - self.socket.send(JSON.stringify(obj)); - }, interval); - } - me.users = 1; - } - this.stop = function() { - me.users--; - if((me.users <= 0)&&(me.timer != undefined)) - { - clearInterval(me.timer); - } - } - } - - function init() { - if ("WebSocket" in window) - { - var list = self.vehicleEventType.getValueEventList(); - for(var i = 0; i < list.length; i++) - { - self.subscriptions[i] = new self.Signal(list[i]); - } - - self.socket = new WebSocket(socketUrl); - self.socket.onopen = function() - { - PRINT.pass("Server READY"); - }; - 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.subscribe = function(list) -{ - for(var i = 0; i < this.subscriptions.length; i++) - { - if(list.indexOf(this.subscriptions[i].name) >= 0) - { - this.subscriptions[i].start(); - } - } -} - -VehicleServer.prototype.unsubscribe = function(list) -{ - for(var i = 0; i < this.subscriptions.length; i++) - { - if(list.indexOf(this.subscriptions[i].name) >= 0) - { - this.subscriptions[i].stop(); - } - } -} - -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") - { - var data; - if(event.writeable) - { - data = this.vehicleEventType.getValueEventList(event.data); - } - else - { - data = this.vehicleEventType.getSupportedEventList(event.data); - } - obj = { - "type" : "methodReply", - "name": event.name, - "transactionid" : event.transactionid, - "data" : data - }; - } - else if(event.name === "get") - { - var names = this.vehicleEventType.getValuesEventList(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 if(event.name === "set") - { - var bad = []; - var good = []; - for(var i = 0; i < event.data.length; i++) - { - if((event.data[i].value != undefined) && - this.vehicleEventType.isValueEvent(event.data[i].property)) - { - this.vehicleEventType.setValue(event.data[i].property, parseInt(event.data[i].value)); - good[good.length] = event.data[i].property; - } - else - { - bad[bad.length] = event.data[i].property; - } - } - - obj = { - "type" : "methodReply", - "name": event.name, - "transactionid" : event.transactionid - }; - - if(bad.length > 0) - { - obj.error = "Failed to set:"; - for(var i = 0; i < bad.length; i++) - { - obj.error += " "+bad[i]; - } - } - - if(good.length > 0) - { - obj.data = "Successfully set:"; - for(var i = 0; i < good.length; i++) - { - obj.data += " "+good[i]; - } - } - } - else if(event.name === "subscribe") - { - var names = this.vehicleEventType.getValuesEventList(event.data); - if(names.length > 0) - { - obj = { - "type" : "methodReply", - "name": event.name, - "transactionid" : event.transactionid, - "data" : names - }; - for(i in names) - { - this.subscribe(names[i]); - } - } - else - { - obj = { - "type" : "methodReply", - "name": event.name, - "transactionid" : event.transactionid, - "error" : "no valid events provided" - }; - } - } - else if(event.name === "unsubscribe") - { - var names = this.vehicleEventType.getValuesEventList(event.data); - if(names.length > 0) - { - obj = { - "type" : "methodReply", - "name": event.name, - "transactionid" : event.transactionid, - "data" : names - }; - for(i in names) - { - this.unsubscribe(names[i]); - } - } - else - { - obj = { - "type" : "methodReply", - "name": event.name, - "transactionid" : event.transactionid, - "error" : "no valid events provided" - }; - } - } - 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:23023/vehicle?server"); -}); diff --git a/plugins/websocketsink/test/style.css b/plugins/websocketsink/test/style.css deleted file mode 100644 index 8456fd1..0000000 --- a/plugins/websocketsink/test/style.css +++ /dev/null @@ -1,182 +0,0 @@ -.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: 620px; - overflow-y: auto; -} - -#result { - position: absolute; - top: 0px; - left: 620px; - height: 98%; - width: 1380px; - padding-top: 1%; - background-color: #eeeeee; - padding-left: 1%; - word-wrap:break-word; - overflow-y: auto; -} - -.proptest { - position: relative; - left: 0px; - height: 67px; - width: 700px; - overflow: hidden; -} - -.proptest .buttons { - position: absolute; - top: 32px; - left: 0px; - height: 35px; - width: 630px; -} - -.smallText { - text-align: left; - color: #FFFFFF; - font: 18px Arial; - display: inline; -} -.propinfo { - position: absolute; - top: 0px; - left: 0px; - height: 67px; - width: 600px; - text-align: left; - color: #FFFFFF; - font: 18px Arial; - line-height: 30px; - padding-left: 5px; - background: -webkit-gradient(linear, left top, left bottom, from(#444), to(#000)); - cursor: pointer; -} - -.propinfo.select { - background: -webkit-gradient(linear, left top, left bottom, from(#444), to(#aaa)); -} - -.propinfo.unselectable { - cursor: auto; - background: #000000; - border-bottom: solid 1px #444; -} - -input[type='text'] { - margin-top: 5px; - color: black; - font: bold 18px Arial; - height: 19px; - width: 100px; - background: -webkit-gradient(linear, left top, left bottom, from(#aaa), to(#fff)); - -webkit-transition: all 2s linear; -} - -input[type='text'].change { - -webkit-transition: all 0.1s linear; - color: red; -} - -.testbutton { - position: relative; - float: left; - 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: 5px; - margin-bottom: 5px; - margin-right: 2px; -} - -.testbutton.types { - width: 50px; - background: -webkit-gradient(linear, left top, left bottom, from(blue), to(#000)); -} - -.testbutton.types:after { - content: 'types'; -} - -.testbutton.get { - width: 35px; - background: -webkit-gradient(linear, left top, left bottom, from(green), to(#000)); -} - -.testbutton.get:after { - content: 'get'; -} - -.testbutton.set { - width: 35px; - background: -webkit-gradient(linear, left top, left bottom, from(green), to(#000)); -} - -.testbutton.set:after { - content: 'set'; -} - -.testbutton.subscribe { - width: 80px; - background: -webkit-gradient(linear, left top, left bottom, from(purple), to(#000)); -} - -.testbutton.subscribe.disable { - pointer-events: none; - color: #999999; - background: -webkit-gradient(linear, left top, left bottom, from(#000), to(#111)); -} - -.testbutton.subscribe:after { - content: 'subscribe'; -} - -.testbutton.unsubscribe { - width: 100px; - background: -webkit-gradient(linear, left top, left bottom, from(purple), to(#000)); -} - -.testbutton.unsubscribe.disable { - pointer-events: none; - color: #999999; - background: -webkit-gradient(linear, left top, left bottom, from(#000), to(#111)); -} - -.testbutton.unsubscribe:after { - content: 'unsubscribe'; -} - -.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 deleted file mode 100644 index 90106f2..0000000 --- a/plugins/websocketsink/test/test.js +++ /dev/null @@ -1,328 +0,0 @@ -/* - * 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 += "
PASS: " + msg + "
"; - this.scrollToBottom(); - }, - - fail: function(msg) { - this.logElement.innerHTML += "
FAIL: " + msg + "
"; - this.scrollToBottom(); - }, - - log: function(msg) { - this.logElement.innerHTML += "
" + msg + "
"; - this.scrollToBottom(); - }, -} - -/* ----------------------------- test code --------------------------------- */ - -var vehicleEventType = new VehicleEventType(); -var selected = []; - -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) { - 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) + ":
" + msg); - } - ); -} - -function updateInput(input, value) { - input.value = value; - input.className = "change"; - input.addEventListener('webkitTransitionEnd', function callback(e) { - e.target.removeEventListener('webkitTransitionEnd', callback, false); - e.target.className = ""; - }, false); -} - -function getValue(eventlist) { - var zoneList = getZone(eventlist); - var types = window.vehicle.get(eventlist, zoneList, - function(data) { - if (data) { - PRINT.pass("values received:"); - 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 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); - } - }, - function(msg) { - PRINT.fail(msg); - } - ); -} - -function setValue(eventlist) { - var zoneList = getZone(eventlist); - var elements = document.getElementsByClassName('proptest'); - var i, valuelist = [] ; - - /* initialize the value list */ - for (i = 0; i < eventlist.length; i++) { - valuelist[i] = 0; - } - - 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 input = elements[i].getElementsByTagName('input')[0]; - valuelist[idx] = input.value; - } - } - - var types = window.vehicle.set(eventlist, valuelist, zoneList, - function(msg) { - PRINT.pass("Set success for: " + JSON.stringify(msg)); - }, - function(msg) { - PRINT.fail("Set error: " + JSON.stringify(msg)); - } - ); -} - -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) { - var input = elements[i].getElementsByTagName('input')[0]; - updateInput(input, e.value.value); - var zone = elements[i].getElementsByTagName('input')[1]; - updateInput(zone, e.value.zone); - } - } -} - -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"; - document.addEventListener(data[i], eventListener, false); - } - }, - function(msg) { - PRINT.fail("Subscribe failed for: " + msg); - } - ); -} - -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++) { - document.removeEventListener(eventlist[i], eventListener, false); - } - 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"; - } - }, - function(msg) { - PRINT.fail("Unsubscribe failed for: " + msg); - } - ); -} - -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)) - return; - - var idx = selected.indexOf(name); - if (elem.className == "propinfo") { - if (idx < 0) { - selected[selected.length] = name; - } - elem.className = "propinfo select"; - } 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 { - 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' + - '
' + - '' + - '
' + - '
' + - '
'; - - /* all events */ - html += '
all events'; - html += '
'; - - /* events */ - for (var i = 0; i < events.length; i++) { - var piece = ""; - for (var j = 0; j < part.length - 1; j++) { - piece += part[j] + events[i]; - } - html += piece + part[j]; - } - tester.innerHTML = html; -} - -function error(msg) { - PRINT.fail(msg); -} - -function init(url, protocol) { - PRINT.init("result"); - window.vehicle = new Vehicle(start, error, url, protocol); -} diff --git a/plugins/websocketsink/test/vehicle.js b/plugins/websocketsink/test/vehicle.js deleted file mode 100644 index 6b8e600..0000000 --- a/plugins/websocketsink/test/vehicle.js +++ /dev/null @@ -1,409 +0,0 @@ -/* - * 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 - * - */ - -/***************************************************************************** -* Class name: Vehicle -* Description: -* A javascript implementation of the IVI vehicle API that communicates -* to the automotive message broker through a websocket -* Optional constructor arguments: -* sCB: success callback, called when socket is connected, argument is -* success message string -* eCB: error callback, called on socket close or error, argument is error -* message string -* url: the URL to use for the websocket, in the form "ws://host:port/script" -* protocol: the protocol to use for the websocket, default is "http-only" -* -* [Public Member functions] -* Function name: getSupportedEventTypes(type, writeable, successCB, errorCB) -* Description: -* Retrieves a list of vehicle events for the requested type -* Required arguments: -* type: target event or group to query (use empty string for all events) -* writeable: if true, return only writeable events, otherwise get all -* successCB: success callback, gets called with a string list of names -* for all the events and event groups that are children of the -* target. e.g. "vehicle_info" returns all events/groups with the -* vehicle_info prefix. If the target is an event group, it's -* omitted from the returned list -* errorCB: error callback, called with error message string -* -* Function name: get(eventlist, successCB, errorCB) -* Description: -* Retrieves a list of event/value pairs for a target list of event names -* Required arguments: -* eventlist[]: list of events to read (use empty string for all events) -* successCB: success callback, gets called with the event/value pair list -* for all requested events. The list is the in the -* form of data[n].name/data[n].value -* errorCB: error callback, called with error message string -* -* Function name: getHistory(event, startTime, endTime, successCB, errorCB) -* Description: -* Retrieves a list of event/value pairs for a target list of event names -* Required arguments: -* event: event to read -* startTime: start date/time -* endTime: end date/time -* successCB: success callback, gets called with the event/value pair list -* for all requested events. The list is the in the -* form of data[n].name/data[n].value -* errorCB: error callback, called with error message string -* -* -* Function name: set(eventlist, valuelist, successCB, errorCB) -* Description: -* Sets a gourp of event's values (triggers error on read-only events) -* Required arguments: -* eventlist: target events to set -* valuelist: target event values -* successCB: success callback, gets called with the eventlist -* that was successfully set -* errorCB: error callback, called with error message string -* -* Function name: subscribe(eventlist, successCB, errorCB) -* Description: -* Subscribe to a list of events so you can listen to value changes, they -* can be monitored with document.addEventListener(eventname, callback, false); -* The Event object passed to the callback has two parameters, e.name and -* e.value. Events are sent to the handler individually. -* Required arguments: -* eventlist: target events to listen to -* successCB: success callback, gets called with the eventlist -* that was successfully subscribed -* errorCB: error callback, called with the eventlist that failed to subscribe -* -* Function name: unsubscribe(eventlist, successCB, errorCB) -* Description: -* Unsubscribe to a list of events to let the server know you're not listening, -* they should stop being sent from the server if no other clients are using them, -* but will at least stop being triggered in your app. -* Required arguments: -* eventlist: target events to stop listening to -* successCB: success callback, gets called with the eventlist -* that was successfully unsubscribed -* 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 */ - var self = this; - - this.iSuccessCB = sCB; - this.iErrorCB = eCB; - - /* variables for call management, supports up to 100 simultaneously */ - this.methodIdx = 0; - this.methodCalls = []; - for(var i = 0; i < 100; i++) - { - this.methodCalls[i] = null; - } - - /* number of connection retries to attempt if the socket closes */ - this.retries = 5; - this.connected = false; - - /* timeout for method calls in milliseconds */ - this.timeouttime = 5000; - - /* default values for WebSocket */ - this.socketUrl = "ws://localhost:23000/vehicle"; - this.socketProtocol = "http-only"; - - /* override the websocket address if parameters are given */ - if(url !== undefined) this.socketUrl = url; - if(protocol !== undefined) this.socketProtocol = protocol; - - this.VehicleMethodCall = function(id, name, successCB, errorCB) - { - var me = this; - this.successCB = successCB; - this.errorCB = errorCB; - this.transactionid = id; - this.name = name; - this.done = false; - this.start = function() - { - me.timeout = setTimeout(function(){ - if(me.errorCB !== undefined) - { - me.errorCB("\""+me.name+"\" method timed out after "+self.timeouttime+"ms"); - } - me.finish(); - }, self.timeouttime); - } - this.finish = function() - { - if(me.timeout !== undefined) - { - clearTimeout(me.timeout); - } - me.done = true; - } - } - - function init() { - if ("WebSocket" in window) - { - if(self.socketProtocol.length > 0) - { - self.socket = new WebSocket(self.socketUrl, self.socketProtocol); - } - else - { - self.socket = new WebSocket(self.socketUrl); - } - self.socket.onopen = function() - { - self.connected = true; - self.iSuccessCB((self.retries < 5)?"(RECONNECTED)":""); - self.retries = 5; - }; - self.socket.onclose = function() - { - self.connected = false; - self.iErrorCB("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.iErrorCB(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.generateTransactionId = function() -{ - var i, val = []; - for(i = 0; i < 8; i++) - { - var num = Math.floor((Math.random()+1)*65536); - val[i] = num.toString(16).substring(1); - } - var uuid = val[0]+val[1]+"-"+ - val[2]+"-"+val[3]+"-"+val[4]+"-"+ - val[5]+val[6]+val[7]; - return uuid; -} - -Vehicle.prototype.send = function(obj, successCB, errorCB) -{ - if(!this.connected) - { - if(errorCB !== undefined) - { - errorCB("\""+obj.name+"\" method failed because socket is closed"); - } - return; - } - var i = this.methodIdx; - this.methodIdx = (this.methodIdx + 1)%100; - this.methodCalls[i] = new this.VehicleMethodCall(obj.transactionid, - obj.name, successCB, errorCB); - this.socket.send(JSON.stringify(obj)); - this.methodCalls[i].start(); -} - - -Vehicle.prototype.getSupportedEventTypes = function(type, writeable, successCB, errorCB) -{ - var obj = { - "type" : "method", - "name" : "getSupportedEventTypes", - "writeable" : writeable, - "transactionid" : this.generateTransactionId(), - "data" : type - }; - this.send(obj, 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" : properties - }; - this.send(obj, successCB, errorCB); -} - -Vehicle.prototype.getHistory = function(event, startTime, endTime, successCB, errorCB) -{ - var obj = { - "type" : "method", - "name": "getHistory", - "transactionid" : this.generateTransactionId(), - "data" : [event, (startTime.getTime()/1000).toString(), (endTime.getTime()/1000).toString()] - }; - - this.send(obj, successCB, errorCB); - -} - -Vehicle.prototype.set = function(namelist, valuelist, zoneList, successCB, errorCB) -{ - if((namelist.length != valuelist.length)||(namelist.length <= 0)) - { - return; - } - - var obj = { - "type" : "method", - "name": "set", - "transactionid" : this.generateTransactionId(), - "data" : [] - }; - var list = []; - for(var i = 0; i < namelist.length; 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, zoneList, successCB, errorCB) -{ - var obj = { - "type" : "method", - "name": "subscribe", - "transactionid" : this.generateTransactionId(), - "data" : namelist, - "zone" : zoneList - }; - this.send(obj, successCB, errorCB); -} - -Vehicle.prototype.unsubscribe = function(namelist, zoneList, successCB, errorCB) -{ - var obj = { - "type" : "method", - "name": "unsubscribe", - "transactionid" : this.generateTransactionId(), - "data" : namelist, - "zone" : zoneList - }; - this.send(obj, successCB, errorCB); -} - -Vehicle.prototype.sendEvent = function(name, value) -{ - var evt = document.createEvent("Event"); - evt.initEvent(name, true, true); - evt.name = name; - evt.value = value; - document.dispatchEvent(evt); - console.log(evt); -} - -Vehicle.prototype.receive = function(msg) -{ - var self = this; - var event; - try { - event = JSON.parse(msg); - } - catch(e) { - self.iErrorCB("GARBAGE MESSAGE: "+msg); - return; - } - - if((event === undefined)||(event.type === undefined)|| - (event.name === undefined)) - { - self.iErrorCB("BADLY FORMED MESSAGE: "+msg); - return; - } - else - { - if(event.type === "methodReply") - { - var calls = this.methodCalls; - for(var i = 0; i < calls.length; i++) - { - var call = calls[i]; - if(call&&(!call.done)&&(call.transactionid === event.transactionid)) - { - call.finish(); - if(event.error !== undefined) - { - call.errorCB(event.error); - } - else if(event.data !== undefined && call.successCB !== undefined) - { - call.successCB(event.data); - } - return; - } - } - } - else if(event.type === "valuechanged") - { - self.sendEvent(event.name, event.data); - } - } -} - -/* - // 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