summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevron Rees <tripzero.kev@gmail.com>2015-04-15 12:21:09 -0700
committerKevron Rees <tripzero.kev@gmail.com>2015-04-15 12:21:09 -0700
commit244dec37a08d4c6de0ae9a49540aff2212a2b225 (patch)
tree76e13fd3110f2c9637ed6a8a4d741a750138c785
parent4279804ec1986e918af017c8110dd5caf64e4887 (diff)
parentfde2d69782a5b99b35ec0a92815383814fe7d279 (diff)
downloadautomotive-message-broker-244dec37a08d4c6de0ae9a49540aff2212a2b225.tar.gz
Merge pull request #57 from OlivierDelbeke/chrony_for_master
Chrony for master - This has already been reviewed on 0.14. Merging
-rw-r--r--CMakeLists.txt1
-rw-r--r--examples/CMakeLists.txt4
-rw-r--r--examples/chrony.in.json16
-rw-r--r--plugins/CMakeLists.txt1
-rw-r--r--plugins/chrony/CMakeLists.txt19
-rw-r--r--plugins/chrony/README24
-rw-r--r--plugins/chrony/chrony.cpp81
-rw-r--r--plugins/chrony/chrony.h50
-rw-r--r--plugins/chrony/chrony.in.json5
-rw-r--r--plugins/gpsnmea/gpsnmea.cpp4
10 files changed, 202 insertions, 3 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..5a666284
--- /dev/null
+++ b/plugins/chrony/CMakeLists.txt
@@ -0,0 +1,19 @@
+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)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/chrony.in.json ${CMAKE_CURRENT_BINARY_DIR}/chrony @ONLY)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/chrony DESTINATION ${PLUGIN_SEGMENT_INSTALL_PATH})
+
+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..aa7737c9
--- /dev/null
+++ b/plugins/chrony/chrony.cpp
@@ -0,0 +1,81 @@
+/*
+ Copyright (C) 2012 Intel Corporation
+ Copyright (C) 2015 AWTC Europe
+
+ 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 "ambplugin.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>
+
+extern "C" void create(AbstractRoutingEngine* routingEngine, map<string, string> config)
+{
+ auto plugin = new AmbPlugin<ChronySink>(routingEngine, config);
+ plugin->init();
+}
+
+ChronySink::ChronySink(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config, AbstractSource& parent)
+ :AmbPluginImpl(re, config, parent)
+{
+}
+
+void ChronySink::init()
+{
+ routingEngine->subscribeToProperty("GpsTime", &source);
+}
+
+PropertyList ChronySink::subscriptions()
+{
+}
+
+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);
+}
+
diff --git a/plugins/chrony/chrony.h b/plugins/chrony/chrony.h
new file mode 100644
index 00000000..f694c5a0
--- /dev/null
+++ b/plugins/chrony/chrony.h
@@ -0,0 +1,50 @@
+/*
+ Copyright (C) 2012 Intel Corporation
+ Copyright (C) 2015 AWTC Europe
+
+ 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 "ambpluginimpl.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 AmbPluginImpl
+{
+
+public:
+ ChronySink(AbstractRoutingEngine* re, const std::map<std::string, std::string>& config, AbstractSource& parent);
+ ~ChronySink() { };
+ const std::string uuid() const { return "35324592-db72-11e4-b432-0022684a4a24"; }
+ virtual void init();
+ virtual PropertyList subscriptions();
+ virtual void propertyChanged( AbstractPropertyType* value);
+
+};
+
+#endif // CHRONYSINK_H
diff --git a/plugins/chrony/chrony.in.json b/plugins/chrony/chrony.in.json
new file mode 100644
index 00000000..8bd53518
--- /dev/null
+++ b/plugins/chrony/chrony.in.json
@@ -0,0 +1,5 @@
+{
+ "name" : "Chrony plugin",
+ "path" : "@PLUGIN_INSTALL_PATH@/chrony.so",
+ "enabled" : true
+}
diff --git a/plugins/gpsnmea/gpsnmea.cpp b/plugins/gpsnmea/gpsnmea.cpp
index 7663e772..8a547b4e 100644
--- a/plugins/gpsnmea/gpsnmea.cpp
+++ b/plugins/gpsnmea/gpsnmea.cpp
@@ -303,10 +303,10 @@ void Location::parseTime(string h, string m, string s, string dd, string mm, str
t.tm_min = boost::lexical_cast<int>(m);
t.tm_sec = boost::lexical_cast<int>(s);
t.tm_mday = boost::lexical_cast<int>(dd);
- t.tm_mon = boost::lexical_cast<int>(mm);
+ t.tm_mon = boost::lexical_cast<int>(mm) - 1;
t.tm_year = boost::lexical_cast<int>(yy) + 100;
- time_t time = mktime(&t);
+ time_t time = timegm(&t);
if(mGpsTime->value<double>() != (double(time)))
{