summaryrefslogtreecommitdiff
path: root/src/tripcomputer
diff options
context:
space:
mode:
authorMartin Schaller <martin.schaller@it-schaller.de>2014-05-09 08:53:46 -0700
committerMartin Schaller <martin.schaller@it-schaller.de>2014-05-09 08:53:46 -0700
commit48736ceaf27d809f241a3f9643b2203456f4a454 (patch)
tree9df3f781ad5515b335811168cb6acab45de2b019 /src/tripcomputer
parent0129b373b871ca103f7005ba09d917285a3b10a4 (diff)
downloadnavigation-48736ceaf27d809f241a3f9643b2203456f4a454.tar.gz
Improved tripcomputer
Diffstat (limited to 'src/tripcomputer')
-rw-r--r--src/tripcomputer/CMakeLists.txt6
-rw-r--r--src/tripcomputer/amb.xml68
-rw-r--r--src/tripcomputer/tripcomputer.cpp109
-rw-r--r--src/tripcomputer/tripcomputer.xml2
4 files changed, 180 insertions, 5 deletions
diff --git a/src/tripcomputer/CMakeLists.txt b/src/tripcomputer/CMakeLists.txt
index c82e72a..af95435 100644
--- a/src/tripcomputer/CMakeLists.txt
+++ b/src/tripcomputer/CMakeLists.txt
@@ -27,9 +27,13 @@ ADD_CUSTOM_COMMAND(OUTPUT tripcomputer.h
COMMAND dbusxx-xml2cpp ${PROJECT_SOURCE_DIR}/tripcomputer.xml --adaptor=tripcomputer.h
DEPENDS tripcomputer.xml
)
+ADD_CUSTOM_COMMAND(OUTPUT amb.h
+ COMMAND dbusxx-xml2cpp ${PROJECT_SOURCE_DIR}/amb.xml --proxy=amb.h
+ DEPENDS amb.xml
+ )
ADD_CUSTOM_COMMAND(OUTPUT constants.h
COMMAND xsltproc ${PROJECT_SOURCE_DIR}/enum.xsl ${PROJECT_SOURCE_DIR}/constants.xml >constants.h
DEPENDS constants.xml
)
-add_executable(tripcomputer tripcomputer.cpp tripcomputer.h constants.h)
+add_executable(tripcomputer tripcomputer.cpp tripcomputer.h constants.h amb.h)
target_link_libraries(tripcomputer ${DBUS_CPP_LDFLAGS} ${GLIB_LDFLAGS})
diff --git a/src/tripcomputer/amb.xml b/src/tripcomputer/amb.xml
new file mode 100644
index 0000000..966ec3f
--- /dev/null
+++ b/src/tripcomputer/amb.xml
@@ -0,0 +1,68 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<!-- GDBus 2.40.0 -->
+<node>
+ <interface name="org.freedesktop.DBus.Properties">
+ <method name="Get">
+ <arg type="s" name="interface_name" direction="in"/>
+ <arg type="s" name="property_name" direction="in"/>
+ <arg type="v" name="value" direction="out"/>
+ </method>
+ <method name="GetAll">
+ <arg type="s" name="interface_name" direction="in"/>
+ <arg type="a{sv}" name="properties" direction="out"/>
+ </method>
+ <method name="Set">
+ <arg type="s" name="interface_name" direction="in"/>
+ <arg type="s" name="property_name" direction="in"/>
+ <arg type="v" name="value" direction="in"/>
+ </method>
+ <signal name="PropertiesChanged">
+ <arg type="s" name="interface_name"/>
+ <arg type="a{sv}" name="changed_properties"/>
+ <arg type="as" name="invalidated_properties"/>
+ </signal>
+ </interface>
+ <interface name="org.automotive.Manager">
+ <method name="FindObject">
+ <arg type="s" name="searchstring" direction="in">
+ </arg>
+ <arg type="ao" name="response" direction="out">
+ </arg>
+ </method>
+ <method name="FindObjectForZone">
+ <arg type="s" name="searchstring" direction="in">
+ </arg>
+ <arg type="i" name="zone" direction="in">
+ </arg>
+ <arg type="o" name="response" direction="out">
+ </arg>
+ </method>
+ <method name="FindObjectForSourceZone">
+ <arg type="s" name="searchstring" direction="in">
+ </arg>
+ <arg type="s" name="source" direction="in">
+ </arg>
+ <arg type="i" name="zone" direction="in">
+ </arg>
+ <arg type="o" name="response" direction="out">
+ </arg>
+ </method>
+ <method name="List">
+ <arg type="as" name="response" direction="out">
+ </arg>
+ </method>
+ <method name="ZonesForObjectName">
+ <arg type="s" name="searchstring" direction="in">
+ </arg>
+ <arg type="ai" name="response" direction="out">
+ </arg>
+ </method>
+ <method name="SourcesForObjectName">
+ <arg type="s" name="searchstring" direction="in">
+ </arg>
+ <arg type="as" name="response" direction="out">
+ </arg>
+ </method>
+ </interface>
+</node>
diff --git a/src/tripcomputer/tripcomputer.cpp b/src/tripcomputer/tripcomputer.cpp
index a51f395..3f52126 100644
--- a/src/tripcomputer/tripcomputer.cpp
+++ b/src/tripcomputer/tripcomputer.cpp
@@ -1,12 +1,77 @@
#include <dbus-c++/glib-integration.h>
#include <glib.h>
+#include <stdio.h>
+#include <unistd.h>
#include "tripcomputer.h"
+#include "constants.h"
+#include "amb.h"
-static DBus::Glib::BusDispatcher dispatcher;
-static DBus::Connection *conn;
+static DBus::Glib::BusDispatcher dispatcher,amb_dispatcher;
+static DBus::Connection *conn,*amb_conn;
static class TripComputer *server;
+static class AutomotiveMessageBroker *amb;
static GMainLoop *loop;
+static DBus::Variant
+variant_uint16(uint16_t i)
+{
+ DBus::Variant variant;
+ DBus::MessageIter iter=variant.writer();
+ iter << i;
+ return variant;
+}
+
+static DBus::Variant
+variant_uint32(uint32_t i)
+{
+ DBus::Variant variant;
+ DBus::MessageIter iter=variant.writer();
+ iter << i;
+ return variant;
+}
+
+
+class Properties
+: public ::DBus::InterfaceProxy,
+ public ::DBus::ObjectProxy
+{
+ public:
+
+ Properties(::DBus::Connection &connection, ::DBus::Path path)
+ : ::DBus::InterfaceProxy("org.freedesktop.DBus.Properties"),
+ ::DBus::ObjectProxy(connection, path,"org.automotive.message.broker")
+ {
+ }
+ ::DBus::Variant Get(const std::string &iface, const std::string &property)
+ {
+ ::DBus::CallMessage call;
+ ::DBus::MessageIter wi = call.writer();
+
+ wi << iface;
+ wi << property;
+ call.member("Get");
+ ::DBus::Message ret = invoke_method (call);
+ ::DBus::MessageIter ri = ret.reader();
+ ::DBus::Variant argout;
+ ri >> argout;
+ return argout;
+ }
+};
+
+
+class AutomotiveMessageBroker
+: public org::automotive::Manager_proxy,
+ public DBus::ObjectProxy
+{
+ public:
+
+ AutomotiveMessageBroker(DBus::Connection &connection)
+ : DBus::ObjectProxy(connection, "/","org.automotive.message.broker")
+ {
+ }
+};
+
+
class TripComputer
: public org::genivi::demonstrator::TripComputer_adaptor,
public DBus::IntrospectableAdaptor,
@@ -14,7 +79,7 @@ class TripComputer
{
public:
TripComputer(DBus::Connection &connection)
- : DBus::ObjectAdaptor(connection, "/org/genivi/demonstrator")
+ : DBus::ObjectAdaptor(connection, "/org/genivi/demonstrator/TripComputer")
{
}
@@ -41,6 +106,11 @@ class TripComputer
std::map< uint16_t, ::DBus::Variant >
GetTripData(const uint8_t& number)
{
+ std::map< uint16_t, ::DBus::Variant > ret;
+ ret[GENIVI_TRIPCOMPUTER_AVERAGE_SPEED]=variant_uint16(470);
+ ret[GENIVI_TRIPCOMPUTER_AVERAGE_FUEL_CONSUMPTION]=variant_uint16(58);
+ ret[GENIVI_TRIPCOMPUTER_ODOMETER]=variant_uint32(1300);
+ return ret;
}
void ResetTripData(const uint8_t& number)
@@ -59,5 +129,38 @@ int main(int argc, char **argv)
conn->setup(&dispatcher);
conn->request_name("org.genivi.demonstrator.TripComputer");
server=new TripComputer(*conn);
+
+ amb_dispatcher.attach(NULL);
+ amb_conn = new DBus::Connection(DBus::Connection::SessionBus());
+ amb_conn->setup(&amb_dispatcher);
+ amb=new AutomotiveMessageBroker(*amb_conn);
+
+ std::vector< ::DBus::Path > fuel = amb->FindObject("Fuel");
+ std::vector< ::DBus::Path > odometer = amb->FindObject("Odometer");
+ printf("%d %d\n",fuel.size(), odometer.size());
+
+ Properties *fuel_properties=new Properties(*amb_conn,fuel[0]);
+ Properties *odometer_properties=new Properties(*amb_conn,odometer[0]);
+#if 0
+ for (;;) {
+ DBus::Variant variant=fuel_properties->Get("org.automotive.Fuel","Level");
+ DBus::MessageIter it=variant.reader();
+ uint16_t res;
+ it >> res;
+ printf("%d\n",res);
+ variant=fuel_properties->Get("org.automotive.Fuel","InstantConsumption");
+ it=variant.reader();
+ it >> res;
+ printf("%d\n",res);
+ variant=odometer_properties->Get("org.automotive.Odometer","Odometer");
+ it=variant.reader();
+ uint32_t res2;
+ it >> res2;
+ printf("%d\n",res2);
+ sleep(1);
+ }
+#endif
+
+
g_main_loop_run(loop);
}
diff --git a/src/tripcomputer/tripcomputer.xml b/src/tripcomputer/tripcomputer.xml
index d811a29..9c1517f 100644
--- a/src/tripcomputer/tripcomputer.xml
+++ b/src/tripcomputer/tripcomputer.xml
@@ -2,7 +2,7 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<?xml-stylesheet type="text/xsl" href="introspect.xsl"?>
-<node name="/org/genivi/demonstrator" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="introspect.xsd">
+<node name="/org/genivi/demonstrator/TripComputer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="introspect.xsd">
<interface name="org.genivi.demonstrator.TripComputer">
<version>beta (29-11-2013)</version>