diff options
author | Olivier Delbeke <olivier.delbeke@awtce.be> | 2015-04-08 11:25:07 +0200 |
---|---|---|
committer | Olivier Delbeke <olivier.delbeke@gmail.com> | 2015-04-15 20:15:28 +0200 |
commit | 7d26c469f4ccc3387ba8eaf37ad8108c8ae72686 (patch) | |
tree | 96a9216625b72fb77cef5667089ac6d981748c22 | |
parent | 9a0b4a8c0f1039959ce42c195d7176d8cf9744f5 (diff) | |
download | automotive-message-broker-7d26c469f4ccc3387ba8eaf37ad8108c8ae72686.tar.gz |
Added chrony sink plugin
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | examples/CMakeLists.txt | 4 | ||||
-rw-r--r-- | examples/chrony.in.json | 16 | ||||
-rw-r--r-- | plugins/CMakeLists.txt | 1 | ||||
-rw-r--r-- | plugins/chrony/CMakeLists.txt | 16 | ||||
-rw-r--r-- | plugins/chrony/README | 24 | ||||
-rw-r--r-- | plugins/chrony/chrony.cpp | 85 | ||||
-rw-r--r-- | plugins/chrony/chrony.h | 47 |
8 files changed, 193 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e46c3642..3f92b391 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ option(murphy_plugin "murphy policy framework plugin" OFF) option(test_plugin "Test Plugin" ON) option(bluemonkey_plugin "bluemonkey plugin" OFF) option(gpsnmea_plugin "gps NMEA location plugin" OFF) +option(chrony_plugin "chrony plugin" OFF) option(openxc_plugin "OpenXC plugin" OFF) option(bluetooth_plugin "bluetooth plugin" OFF) option(cansim_plugin "Can simulator plugin" OFF) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 5437a9f5..08672330 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -11,7 +11,8 @@ set(amb_examples ${CMAKE_CURRENT_BINARY_DIR}/configwheel ${CMAKE_CURRENT_BINARY_DIR}/websocketsource2 ${CMAKE_CURRENT_BINARY_DIR}/testsourceconfig ${CMAKE_CURRENT_BINARY_DIR}/bluemonkey/bluemonkeyconfig - ${CMAKE_CURRENT_BINARY_DIR}/bluetooth) + ${CMAKE_CURRENT_BINARY_DIR}/bluetooth + ${CMAKE_CURRENT_BINARY_DIR}/chrony) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/configwheel.in.json ${CMAKE_CURRENT_BINARY_DIR}/configwheel @ONLY) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/databasesource.in.json ${CMAKE_CURRENT_BINARY_DIR}/databasesource @ONLY) @@ -31,6 +32,7 @@ configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cangenconfig.in.json ${CMAKE_CURRENT configure_file (${CMAKE_CURRENT_SOURCE_DIR}/bluemonkey/bluemonkeyconfig.in.json ${CMAKE_CURRENT_BINARY_DIR}/bluemonkey/bluemonkeyconfig @ONLY) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/bluetooth.in.json ${CMAKE_CURRENT_BINARY_DIR}/bluetooth @ONLY) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/testplugins.d.in.json ${CMAKE_CURRENT_SOURCE_DIR}/testplugins.d.json @ONLY) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/chrony.in.json ${CMAKE_CURRENT_BINARY_DIR}/chrony @ONLY) install (FILES ${amb_examples} DESTINATION /etc/ambd/examples) diff --git a/examples/chrony.in.json b/examples/chrony.in.json new file mode 100644 index 00000000..360ceecd --- /dev/null +++ b/examples/chrony.in.json @@ -0,0 +1,16 @@ +{ + "sources" : [ + { + "name" : "gps nmea plugin", + "path" : "@PLUGIN_INSTALL_PATH@/gpsnmea.so", + "device" : "/dev/ttyUSB0", + "baudrate" : "4800" + } + ], + "sinks": [ + { + "path" : "@PLUGIN_INSTALL_PATH@/chrony.so" + } + ] +} + diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index ed744e09..6b119c83 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -50,3 +50,4 @@ add_subdirectory(openxc) add_subdirectory(bluetooth) add_subdirectory(cansimplugin) add_subdirectory(cangenplugin) +add_subdirectory(chrony) diff --git a/plugins/chrony/CMakeLists.txt b/plugins/chrony/CMakeLists.txt new file mode 100644 index 00000000..a66a1965 --- /dev/null +++ b/plugins/chrony/CMakeLists.txt @@ -0,0 +1,16 @@ +if(chrony_plugin) + +set(chrony_headers chrony.h) +set(chrony_sources chrony.cpp ) + +add_library(chrony MODULE ${chrony_sources}) +set_target_properties(chrony PROPERTIES PREFIX "") +target_link_libraries(chrony amb -L${CMAKE_CURRENT_BINARY_DIR}/lib amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} ${gio_LIBRARIES}) + +install(TARGETS chrony LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README ${CMAKE_CURRENT_BINARY_DIR}/chrony.README @ONLY) + +install (FILES ${CMAKE_CURRENT_BINARY_DIR}/chrony.README DESTINATION ${DOC_INSTALL_DIR}/plugins) + +endif(chrony_plugin) diff --git a/plugins/chrony/README b/plugins/chrony/README new file mode 100644 index 00000000..a9f28c24 --- /dev/null +++ b/plugins/chrony/README @@ -0,0 +1,24 @@ +CHRONY plugin +Version: @PROJECT_VERSION@ + +This plugin will forward the GpsTime property to the CHRONYD daemon. + +To enable the CHRONY plugin, run cmake and enable the chrony_plugin option: + +cmake -Dchrony_plugin=On .. + +To use this plugin, add the following to the "sinks" array in /etc/ambd/config: + +{ + "name" : "chrony", + "path" : "@PLUGIN_INSTALL_PATH@/chrony.so", +} + +Configuration Key Definitions: + +"name" +name of plugin. This key is not used by the plugin at this moment. + +"path" +path to plugin on the filesystem. + diff --git a/plugins/chrony/chrony.cpp b/plugins/chrony/chrony.cpp new file mode 100644 index 00000000..0674427e --- /dev/null +++ b/plugins/chrony/chrony.cpp @@ -0,0 +1,85 @@ +/* + 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 "chrony.h" +#include "abstractroutingengine.h" +#include "debugout.h" +#include "listplusplus.h" + +#include <glib.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/time.h> +#include <math.h> + +#define GPSTIME "GpsTime" + +extern "C" void create(AbstractRoutingEngine* routingEngine, map<string, string> config) +{ + new ChronySink(routingEngine, config); +} + +ChronySink::ChronySink(AbstractRoutingEngine* engine, map<string, string> config): AbstractSink(engine, config) +{ + routingEngine->subscribeToProperty(GPSTIME, this); + supportedChanged(engine->supported()); +} + +PropertyList ChronySink::subscriptions() +{ +} + +void ChronySink::supportedChanged(const PropertyList & supportedProperties) +{ + DebugOut()<<"Support changed!"<<endl; +} + +void ChronySink::propertyChanged(AbstractPropertyType *value) +{ + int sockfd; + struct sockaddr_un s; + struct chrony_sock_sample chronydata; + + sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); + if (sockfd < 0) return; + + s.sun_family = AF_UNIX; + strcpy(s.sun_path, CHRONYD_SOCKET ); + + if(connect(sockfd, (struct sockaddr *)&s, sizeof(s)) == -1) + { + return; + } + + gettimeofday(&(chronydata.tv), NULL); + chronydata.offset = (value->value<double>() - chronydata.tv.tv_sec) - (chronydata.tv.tv_usec / 1000000.0); + chronydata.offset -= (amb::currentTime()-value->timestamp); + chronydata.pulse = 0; + chronydata.leap = 0; + chronydata.magic = 0x534f434b; + send(sockfd,&chronydata,sizeof(chronydata),0); + + close(sockfd); +} + +const string ChronySink::uuid() +{ + return "35324592-db72-11e4-b432-0022684a4a24"; +} diff --git a/plugins/chrony/chrony.h b/plugins/chrony/chrony.h new file mode 100644 index 00000000..aca57a3a --- /dev/null +++ b/plugins/chrony/chrony.h @@ -0,0 +1,47 @@ +/* + 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 +*/ + + +#ifndef CHRONYSINK_H +#define CHRONYSINK_H + +#include "abstractsink.h" + +#define CHRONYD_SOCKET "/tmp/chrony.gps.sock" + +struct chrony_sock_sample { + struct timeval tv; + double offset; + int pulse; + int leap; + int _pad; + int magic; +}; + +class ChronySink : public AbstractSink +{ + +public: + ChronySink(AbstractRoutingEngine* engine, map<string, string> config); + virtual PropertyList subscriptions(); + virtual void supportedChanged(const PropertyList & supportedProperties); + virtual void propertyChanged( AbstractPropertyType* value); + virtual const std::string uuid(); +}; + +#endif // CHRONYSINK_H |