aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-automotive/ambdbusaccess/files/ambdbusaccess.cpp
diff options
context:
space:
mode:
authorMatthew Vick <mvick@jaguarlandrover.com>2015-12-17 13:37:25 -0800
committerGerrit Code Review <gerrit@172.30.200.200>2015-12-21 16:23:04 +0000
commit762181dff011efbaf3d40edb1b3d573c5aceab01 (patch)
treec24b68c6a4a60577dbbfdb107a8c40ccd160b2da /recipes-automotive/ambdbusaccess/files/ambdbusaccess.cpp
parentee2a49c5adc2bc545df6f616f235af42589f1655 (diff)
Add a QML plugin to expose AMB's ClimateControl objects.
To expose the AMB ClimateControl objects to the application layer, add a QML plugin so the application developers can natively configure the vehicle's climate controls based on user input. Because the potential compatibility issue between AMB and Qt being discussed on the AGL mailing list has not yet been resolved, this commit also adds a helper program that the climate control plugin will use as a workaround to access AMB that may be removed in the future. To include support for this plugin, it is necessary for users to add "climatecontrolplugin" to their conf/local.conf when building the image. Change-Id: I6117f0a13e4195e460e3b552befb6e326cdf0f6a Signed-off-by: Matthew Vick <mvick@jaguarlandrover.com>
Diffstat (limited to 'recipes-automotive/ambdbusaccess/files/ambdbusaccess.cpp')
-rw-r--r--recipes-automotive/ambdbusaccess/files/ambdbusaccess.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/recipes-automotive/ambdbusaccess/files/ambdbusaccess.cpp b/recipes-automotive/ambdbusaccess/files/ambdbusaccess.cpp
new file mode 100644
index 00000000..6f2a7b81
--- /dev/null
+++ b/recipes-automotive/ambdbusaccess/files/ambdbusaccess.cpp
@@ -0,0 +1,120 @@
+/* Copyright (C) 2015, Jaguar Land Rover. All Rights Reserved.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <QCoreApplication>
+#include <QDBusConnection>
+#include <QDBusInterface>
+#include <QDBusObjectPath>
+#include <QDBusReply>
+#include <QDebug>
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+ // TODO: Clean this up, update API, etc.
+ if (argc < 5 || argc > 6)
+ {
+ qWarning() << "Error detected! Insufficient number of arguments.";
+ qWarning() << "";
+ qWarning() << "Usage: ambdbusaccess <R/W> <Object> <Property> <Zone> [Value]";
+ qWarning() << "- <R/W>";
+ qWarning() << " Used for specifying [R]ead or [W]rite.";
+ qWarning() << "- <Object>";
+ qWarning() << " The AMB object to access.";
+ qWarning() << "- <Property>";
+ qWarning() << " The property within the object to access.";
+ qWarning() << "- <Zone>";
+ qWarning() << " The AMB zone to access.";
+ qWarning() << "- [Value]";
+ qWarning() << " The value to write, if writing.";
+ qWarning() << "Example: ambdbusaccess Write ClimateControl FanSpeedLevel 0 7";
+ qWarning() << "";
+ qWarning() << "This program returns an int under the following conditions:";
+ qWarning() << "Successful Read: <Value Read>";
+ qWarning() << "Unsuccessful Read: -1";
+ qWarning() << "Successful Write: <Value Written>";
+ qWarning() << "Unsuccessful Write: -1";
+
+ return -1;
+ }
+
+ // TODO: Error check input.
+ bool read = !strncmp(argv[1], "R", 1);
+ QString object = argv[2];
+ QString property = argv[3];
+ qint32 zone = atoi(argv[4]);
+ qint32 value = 0;
+
+ if (argc == 6)
+ {
+ value = atoi(argv[5]);
+ }
+
+ // Necessary to suppress Qt messages about touching the D-Bus before the application was created.
+ QCoreApplication a(argc, argv);
+
+ // Sanity check that the system bus is actually present.
+ if (!QDBusConnection::systemBus().isConnected())
+ {
+ qCritical() << "Could not access system D-Bus!";
+ return -1;
+ }
+
+ // Get ahold of the manager object.
+ QDBusInterface *manager = new QDBusInterface("org.automotive.message.broker", "/", "org.automotive.Manager",
+ QDBusConnection::systemBus());
+
+ // Go fetch the path for the AMB object we are concerned with.
+ qDebug().nospace() << "Looking for property " << property.toStdString().c_str() << " of object " <<
+ object.toStdString().c_str() << " in zone " << zone << ".";
+ QDBusReply<QDBusObjectPath> propertyPath = manager->call("FindObjectForZone", object.toStdString().c_str(), zone);
+ if (!propertyPath.isValid())
+ {
+ qDebug() << "Invalid reply!" << propertyPath.error() << "Got the path:" << propertyPath.value().path();
+ }
+
+ // Now that we have the path, open an interface to the object.
+ QDBusInterface *propertyInterface = new QDBusInterface("org.automotive.message.broker", propertyPath.value().path(),
+ "org.automotive.ClimateControl", QDBusConnection::systemBus());
+
+ // Perform our read or write operation.
+ if (read)
+ {
+ QVariant reply = propertyInterface->property(property.toStdString().c_str());
+ if (!reply.isValid())
+ {
+ qDebug() << "Invalid reply when reading the property!" << propertyInterface->lastError() << "Property:" <<
+ reply.toString();
+ value = -1;
+ }
+ else
+ {
+ qDebug().nospace() << "Got a valid reply for the property of " << reply.toString().toStdString().c_str() << ".";
+ value = reply.toInt();
+ }
+ }
+ else
+ {
+ QVariant reply = propertyInterface->setProperty(property.toStdString().c_str(), value);
+ if (reply.toBool())
+ {
+ qDebug() << "Successfully wrote the property.";
+ }
+ else
+ {
+ qDebug() << "Failed to write the property.";
+ value = -1;
+ }
+ }
+
+ // Clean up.
+ delete propertyInterface;
+ delete manager;
+
+ // Either provide the read value or some feedback to the calling application.
+ return value;
+}
+