diff options
author | Kevron Rees <kevron.m.rees@intel.com> | 2014-11-10 10:13:51 -0800 |
---|---|---|
committer | Kevron Rees <kevron.m.rees@intel.com> | 2014-11-10 10:13:51 -0800 |
commit | bfea899d72d056aebb8d903c96136ca4c4c84819 (patch) | |
tree | 2f0c19389aa12a15b7ffe1f5191cf7259824d0d5 | |
parent | 2d15f3f6b4357f20a151966887e52758812fec9c (diff) | |
download | automotive-message-broker-bfea899d72d056aebb8d903c96136ca4c4c84819.tar.gz |
added more tests to xwalk
-rw-r--r-- | lib/listplusplus.h | 1 | ||||
-rw-r--r-- | lib/mappropertytype.hpp | 9 | ||||
-rw-r--r-- | plugins/bluemonkey/bluemonkey.cpp | 56 | ||||
-rw-r--r-- | plugins/bluemonkey/config.js | 70 | ||||
-rw-r--r-- | plugins/opencvlux/opencvluxplugin.cpp | 72 | ||||
-rw-r--r-- | plugins/opencvlux/opencvluxplugin.h | 2 | ||||
-rw-r--r-- | xwalk/vehicle.html | 82 |
7 files changed, 208 insertions, 84 deletions
diff --git a/lib/listplusplus.h b/lib/listplusplus.h index 23826df4..750f3211 100644 --- a/lib/listplusplus.h +++ b/lib/listplusplus.h @@ -22,6 +22,7 @@ #include <list> #include <algorithm> +#include <functional> template <class T, class V> bool contains(const T & iteratable, V value) diff --git a/lib/mappropertytype.hpp b/lib/mappropertytype.hpp index ff0cc0af..4ddbfbb7 100644 --- a/lib/mappropertytype.hpp +++ b/lib/mappropertytype.hpp @@ -44,9 +44,9 @@ public: if(str.str() != "{") str << ", "; - auto t = *itr; + auto t = *itr; - str <<"'"<< t.first.toString() <<"':'"<<t.second.toString()<<"'"; + str <<"'"<< t.first.toString() <<"':'"<<t.second.toString()<<"'"; } str << "}"; @@ -81,7 +81,7 @@ public: { T one("", key); N two("", std::string(json_object_get_string(val))); - append(one,two); + append(one, two); } json_object_put(rootobject); @@ -107,7 +107,6 @@ public: void fromVariant(GVariant* variant) { clear(); - /// TODO: fill this in gsize dictsize = g_variant_n_children(variant); for (int i=0;i<dictsize;i++) { @@ -125,7 +124,7 @@ public: appendPriv(t,n); } } - + } void setMap(std::map<T, N> m) diff --git a/plugins/bluemonkey/bluemonkey.cpp b/plugins/bluemonkey/bluemonkey.cpp index f2fb0489..3b820c07 100644 --- a/plugins/bluemonkey/bluemonkey.cpp +++ b/plugins/bluemonkey/bluemonkey.cpp @@ -1,19 +1,19 @@ /* - Copyright (C) 2012 Intel Corporation + 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 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. + 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 + 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 */ @@ -327,24 +327,24 @@ void BluemonkeySink::createCustomProperty(QString name, QJSValue defaultValue, i auto create = [defaultValue, name]() -> AbstractPropertyType* { - QVariant var = defaultValue.toVariant(); + QVariant var = defaultValue.toVariant(); - if(!var.isValid()) - return nullptr; + if(!var.isValid()) + return nullptr; - if(var.type() == QVariant::UInt) - return new BasicPropertyType<uint>(name.toStdString(), var.toUInt()); - else if(var.type() == QVariant::Double) - return new BasicPropertyType<double>(name.toStdString(), var.toDouble()); - else if(var.type() == QVariant::Bool) - return new BasicPropertyType<bool>(name.toStdString(), var.toBool()); - else if(var.type() == QVariant::Int) - return new BasicPropertyType<int>(name.toStdString(), var.toInt()); - else if(var.type() == QVariant::String) - return new StringPropertyType(name.toStdString(), var.toString().toStdString()); + if(var.type() == QVariant::UInt) + return new BasicPropertyType<uint>(name.toStdString(), var.toUInt()); + else if(var.type() == QVariant::Double) + return new BasicPropertyType<double>(name.toStdString(), var.toDouble()); + else if(var.type() == QVariant::Bool) + return new BasicPropertyType<bool>(name.toStdString(), var.toBool()); + else if(var.type() == QVariant::Int) + return new BasicPropertyType<int>(name.toStdString(), var.toInt()); + else if(var.type() == QVariant::String) + return new StringPropertyType(name.toStdString(), var.toString().toStdString()); - return nullptr; + return nullptr; }; addPropertySupport(zone, create); @@ -384,6 +384,10 @@ void Property::setValue(QVariant v) { propertyChanged(reply->value); } + else + { + DebugOut(DebugOut::Warning) << "Error, trying to set value: " << reply->error << endl; + } delete reply; }; routingEngine->setProperty(request); diff --git a/plugins/bluemonkey/config.js b/plugins/bluemonkey/config.js index dd51234e..ee2c168b 100644 --- a/plugins/bluemonkey/config.js +++ b/plugins/bluemonkey/config.js @@ -1,19 +1,65 @@ -var speedProperty = bluemonkey.subscribeTo("VehicleSpeed"); +bluemonkey.createCustomProperty("VehicleSpeed", 10); +bluemonkey.createCustomProperty("EngineSpeed", 5000); +bluemonkey.createCustomProperty("PowertrainTorque", 324); +bluemonkey.createCustomProperty("AcceleratorPedalPosition", 50); +bluemonkey.createCustomProperty("ThrottlePosition", 50); +bluemonkey.createCustomProperty("TransmissionModeW3C", "park"); +bluemonkey.createCustomProperty("TransmissionGearPosition", 1); +bluemonkey.createCustomProperty("CruiseControlActive", false); +bluemonkey.createCustomProperty("CruiseControlSpeed", 10); + +///LightStatus: +bluemonkey.createCustomProperty("LightHead", false); +bluemonkey.createCustomProperty("LightRightTurn", false); +bluemonkey.createCustomProperty("LightLeftTurn", false); +bluemonkey.createCustomProperty("LightBrake", false); +bluemonkey.createCustomProperty("LightFog", true); +bluemonkey.createCustomProperty("LightHazard", false); +bluemonkey.createCustomProperty("LightParking", false); +bluemonkey.createCustomProperty("LightHighBeam", false); +bluemonkey.createCustomProperty("LightAutomatic", true); +bluemonkey.createCustomProperty("LightDynamicHighBeam", false); + +bluemonkey.createCustomProperty("Horn", false); +bluemonkey.createCustomProperty("Chime", false); -bluemonkey.log("Javascript engine works!!!!"); +///Fuel: +bluemonkey.createCustomProperty("FuelLevel", 90); +bluemonkey.createCustomProperty("FuelRange", 100); +bluemonkey.createCustomProperty("FuelConsumption", 10); +bluemonkey.createCustomProperty("FuelEconomy", 10); +bluemonkey.createCustomProperty("FuelAverageEconomy", 10); +bluemonkey.createCustomProperty("FuelAverageConsumption", 10); +bluemonkey.createCustomProperty("FuelConsumptionSinceRestart", 10); +bluemonkey.createCustomProperty("LightHighBeam", false); +bluemonkey.createCustomProperty("LightAutomatic", true); +bluemonkey.createCustomProperty("FuelTimeSinceRestart", 10000); -bluemonkey.createCustomProperty("BluemonkeyTest", false); +///EngineOil: +bluemonkey.createCustomProperty("EngineOilTemperature", 60); +bluemonkey.createCustomProperty("EngineOilPressure", 60); +bluemonkey.createCustomProperty("EngineOilChangeIndicator", false); +bluemonkey.createCustomProperty("EngineOilLifeRemaining", 30); -var bluemonkeyTest = bluemonkey.subscribeTo("BluemonkeyTest"); +bluemonkey.createCustomProperty("AccelerationX", 0); +bluemonkey.createCustomProperty("AccelerationY", 0); +bluemonkey.createCustomProperty("AccelerationZ", 10); -bluemonkeyTest.value = true; +bluemonkey.createCustomProperty("SteeringWheelAngleW3C", 10); +bluemonkey.createCustomProperty("WheelTick", 1000); -var timer = bluemonkey.createTimer(); +bluemonkey.createCustomProperty("IgnitionTimeOn", 5000); +bluemonkey.createCustomProperty("IgnitionTimeOff", 5000); -timer.interval = 1000; -timer.singleShot = false; -timer.timeout.connect(function() { - bluemonkeyTest.value = !bluemonkeyTest.value; -}); +bluemonkey.createCustomProperty("YawRate", 128); +bluemonkey.createCustomProperty("WheelBrake", false); + +var speedProperty = bluemonkey.subscribeTo("VehicleSpeed"); -timer.start(); +var testTimer = bluemonkey.createTimer(); + testTimer.interval = 3000; + testTimer.singleShot = false; + testTimer.timeout.connect(function() { + //VehicleSpeed + speedProperty.value = Math.floor((Math.random() * 100) + 1); + }); diff --git a/plugins/opencvlux/opencvluxplugin.cpp b/plugins/opencvlux/opencvluxplugin.cpp index 69385391..b0caf1b4 100644 --- a/plugins/opencvlux/opencvluxplugin.cpp +++ b/plugins/opencvlux/opencvluxplugin.cpp @@ -42,6 +42,7 @@ using namespace std; const std::string VideoLogging = "VideoLogging"; const std::string DriverDrowsiness = "DriverDrowsiness"; +const std::string OpenCL = "OpenCL"; #include "debugout.h" @@ -55,6 +56,10 @@ extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<str return new OpenCvLuxPlugin::DriverDrowsinessType(DriverDrowsiness, false); }); + VehicleProperty::registerProperty(OpenCL, [](){ + return new BasicPropertyType<bool>(OpenCL, false); + }); + return new OpenCvLuxPlugin(routingengine, config); } @@ -62,6 +67,7 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> :AbstractSource(re, config), lastLux(0), speed(0), latitude(0), longitude(0), extBrightness(new VehicleProperty::ExteriorBrightnessType(0)) { driverDrowsiness = amb::make_unique(new DriverDrowsinessType(DriverDrowsiness, false)); + openCl = amb::make_unique(new BasicPropertyType<bool>(OpenCL, false)); shared = amb::make_unique(new Shared); shared->parent = this; @@ -112,7 +118,6 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> } } - if(config.find("pixelUpperBound") != config.end()) { shared->pixelUpperBound = boost::lexical_cast<int>(config["pixelUpperBound"]); @@ -125,6 +130,7 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> { #ifdef OPENCL shared->useOpenCl = config["opencl"] == "true"; + openCl->setValue(shared->useOpenCl); #else DebugOut(DebugOut::Warning) << "You really don't have openCL support. Disabling." << endl; shared->useOpenCl = false; @@ -151,39 +157,38 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> #ifdef OPENCL - if(shared->useOpenCl) - { - cv::ocl::PlatformsInfo platforms; - cv::ocl::getOpenCLPlatforms(platforms); - for(auto p : platforms) - { - DebugOut(1)<<"platform: "<<p->platformName<<" vendor: "<<p->platformVendor<<endl; - } + cv::ocl::PlatformsInfo platforms; + cv::ocl::getOpenCLPlatforms(platforms); + + for(auto p : platforms) + { + DebugOut(1)<<"platform: "<<p->platformName<<" vendor: "<<p->platformVendor<<endl; + } - cv::ocl::DevicesInfo info; - cv::ocl::getOpenCLDevices(info, cv::ocl::CVCL_DEVICE_TYPE_ALL); + cv::ocl::DevicesInfo info; + cv::ocl::getOpenCLDevices(info, cv::ocl::CVCL_DEVICE_TYPE_ALL); - DebugOut(1)<<"There are "<<info.size()<<" OpenCL devices on this system"<<endl; + DebugOut(1)<<"There are "<<info.size()<<" OpenCL devices on this system"<<endl; - if(!info.size()) - { - DebugOut(1)<<"No CL devices. Disabling OpenCL"<<endl; - shared->useOpenCl = false; - } - else - { - cv::ocl::setDevice(info[0]); - } + if(!info.size()) + { + DebugOut(1)<<"No CL devices. Disabling OpenCL"<<endl; + shared->useOpenCl = false; + } + else + { + cv::ocl::setDevice(info[0]); + } - for(auto i : info) + for(auto i : info) + { + for(auto name : i->deviceName) { - for(auto name : i->deviceName) - { - DebugOut(1)<<"OpenCLDeviceName: "<<name<<endl; - } + DebugOut(1)<<"OpenCLDeviceName: "<<name<<endl; } } + #endif #ifdef CUDA @@ -211,17 +216,12 @@ OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> if(shared->ddd) { #ifdef OPENCL - if(shared->useOpenCl) - { - faceCascade = amb::make_unique(new cv::ocl::OclCascadeClassifier()); - eyeCascade = amb::make_unique(new cv::ocl::OclCascadeClassifier()); - } - else + faceCascade = amb::make_unique(new cv::ocl::OclCascadeClassifier()); + eyeCascade = amb::make_unique(new cv::ocl::OclCascadeClassifier()); +#else + faceCascade = amb::make_unique(new cv::CascadeClassifier()); + eyeCascade = amb::make_unique(new cv::CascadeClassifier()); #endif - { - faceCascade = amb::make_unique(new cv::CascadeClassifier()); - eyeCascade = amb::make_unique(new cv::CascadeClassifier()); - } std::string faceFile = CV_DATA "/haarcascades/haarcascade_frontalface_alt.xml"; if(!faceCascade->load(faceFile)) diff --git a/plugins/opencvlux/opencvluxplugin.h b/plugins/opencvlux/opencvluxplugin.h index 9bb79302..7fbee9ac 100644 --- a/plugins/opencvlux/opencvluxplugin.h +++ b/plugins/opencvlux/opencvluxplugin.h @@ -107,6 +107,8 @@ private: std::unique_ptr<cv::CascadeClassifier> eyeCascade; std::unique_ptr<DriverDrowsinessType> driverDrowsiness; + + std::unique_ptr<BasicPropertyType<bool>> openCl; }; static int grabImage(void *data); diff --git a/xwalk/vehicle.html b/xwalk/vehicle.html index 65f600c0..badd1194 100644 --- a/xwalk/vehicle.html +++ b/xwalk/vehicle.html @@ -8,11 +8,24 @@ vehicle = navigator.vehicle; -debug('vehicle.vehicleSpeed ' + vehicle.vehicleSpeed); +function get(objName) { + vehicle[objName].get().then(function(data) { + try { + debug("get " + objName + ": " + JSON.stringify(data)); + } catch(error) { + debug("error " + error.message); + } + }, + function(error) { + debug("There was an error"); + }); +} + +debug("testing zones..."); var zone = new Zone; -console.log('Driver zone: ' + zone.driver.value); +debug('Driver zone: ' + zone.driver.value); var zone1 = new Zone(["Front", "Left"]); var zone2 = new Zone(["Left", "Front"]); @@ -24,19 +37,21 @@ debug("zone1 == zone3 ? " + zone1.equals(zone3)); debug("zone1 == zone1 ? " + zone1.equals(zone1)); debug("zone1 == empty zone ? " + zone1.equals(zone4)); +debug("testing get()"); vehicle.vehicleSpeed.get().then(function(vehicleSpeed) { try { console.log("vehicle speed " + JSON.stringify(vehicleSpeed)); debug("Vehicle speed: " + vehicleSpeed.speed); } catch(error) { - console.log("error " + error.message); + debug("error " + error.message); } }, function(error) { debug("There was an error"); }); -//test subscribe: +debug("testing subscribe()"); + var subReplies = 0; var handle = vehicle.vehicleSpeed.subscribe(function(data) { console.log("got subscribe callback"); @@ -49,10 +64,67 @@ var handle = vehicle.vehicleSpeed.subscribe(function(data) { } }); -//test errors: +debug("test invalid zone error"); vehicle.vehicleSpeed.get("invalidzone").then(function() { }, function(error) { debug("Invalid zone: " + error.message); }); +///test set() +debug("testing set()"); + +vehicle.lightStatus.set({"fog" : true}).then(function() { + debug("set success!"); +}, function(error) { + debug("set fail! " + error.message); +}); + +debug("testing running status api's"); +debug("vehicle.vehicleSpeed " + vehicle.vehicleSpeed); +debug("vehicle.engineSpeed " + vehicle.engineSpeed); +debug("vehicle.powertrainTorque " + vehicle.powertrainTorque); +debug("vehicle.acceleratorPedalPosition " + vehicle.acceleratorPedalPosition); +debug("vehicle.throttlePosition " + vehicle.throttlePosition); +debug("vehicle.transmission " + vehicle.transmission); +debug("vehicle.cruiseControlStatus " + vehicle.cruiseControlStatus); +debug("vehicle.lightStatus " + vehicle.lightStatus); +debug("vehicle.horn " + vehicle.horn); +debug("vehicle.chime " + vehicle.chime); +debug("vehicle.fuel " + vehicle.fuel); +debug("vehicle.engineOil " + vehicle.engineOil); +debug("vehicle.acceleration " + vehicle.acceleration); +debug("vehicle.engineCoolant " + vehicle.engineCoolant); +debug("vehicle.steeringWheel " + vehicle.steeringWheel); +debug("vehicle.wheelTick " + vehicle.wheelTick); +debug("vehicle.ignitionTime " + vehicle.ignitionTime); +debug("vehicle.yawRate " + vehicle.yawRate); +debug("vehicle.brakeOperation " + vehicle.brakeOperation); +debug("vehicle.buttonEvent " + vehicle.buttonEvent); +debug("vehicle.nightMode " + vehicle.nightMode); +debug("vehicle.drivingMode " + vehicle.drivingMode); + +debug("getting data from running status attributes"); + +get("vehicleSpeed"); +get("engineSpeed"); +get("powertrainTorque"); +get("acceleratorPedalPosition"); +get("throttlePosition"); +get("transmission"); +get("cruiseControlStatus"); +get("lightStatus"); +get("horn"); +get("chime"); +get("fuel"); +get("engineOil"); +get("acceleration"); +get("engineCoolant"); +get("steeringWheel"); +get("wheelTick"); +get("ignitionTime"); +get("yawRate"); +get("brakeOperation"); +get("nightMode"); +get("drivingMode"); + </script> <script src="js/js-test-post.js"></script> </body> |