aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-07-08 16:01:44 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-07-08 16:01:44 +0200
commitf42e24266ef347c5fbdfc224dfd6933c5b6e23dd (patch)
tree70a41be1a14bca09b2ce12906496a7a6534842dd /src
parent558449a87d0fb36481e69b70e06beee6009e217c (diff)
downgrade cmake to 3.3
Change-Id: I1bed50e53ea1bd5c34ff494c14fff01862d832e8 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt12
-rw-r--r--src/af-gps-binding.c49
2 files changed, 41 insertions, 20 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 38e82ed..5badd01 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,7 +16,7 @@
# limitations under the License.
###########################################################################
-cmake_minimum_required(VERSION 3.4)
+cmake_minimum_required(VERSION 3.3)
###########################################################################
@@ -50,11 +50,11 @@ link_libraries(${EXTRAS_LIBRARIES})
message(STATUS "Creation af-gps-binding for AFB-DAEMON")
###############################################################
-pkg_get_variable(afb_binding_install_dir afb-daemon binding_install_dir)
-#execute_process(
-# COMMAND pkg-config --variable binding_install_dir afb-daemon
-# OUTPUT_VARIABLE afb_binding_install_dir OUTPUT_STRIP_TRAILING_WHITESPACE
-#)
+#pkg_get_variable(afb_binding_install_dir afb-daemon binding_install_dir)
+execute_process(
+ COMMAND pkg-config --variable binding_install_dir afb-daemon
+ OUTPUT_VARIABLE afb_binding_install_dir OUTPUT_STRIP_TRAILING_WHITESPACE
+)
###############################################################
add_library(af-gps-binding MODULE af-gps-binding.c)
diff --git a/src/af-gps-binding.c b/src/af-gps-binding.c
index 668a10f..2eee437 100644
--- a/src/af-gps-binding.c
+++ b/src/af-gps-binding.c
@@ -151,9 +151,6 @@ static struct json_object *positions[type_COUNT]; /* computed positions by type
/* head of the list of periods */
static struct period *list_of_periods;
-/* declare the connection routine */
-static int nmea_connect();
-
/***************************************************************************************/
/***************************************************************************************/
/** **/
@@ -472,7 +469,7 @@ static void event_send()
/***************************************************************************************/
/** **/
/** **/
-/** SECTION: HANDLING NMEA SENTENCES **/
+/** SECTION: HANDLING NMEA **/
/** **/
/** **/
/***************************************************************************************/
@@ -772,10 +769,22 @@ static int nmea_read(int fd)
}
}
+/***************************************************************************************/
+/***************************************************************************************/
+/** **/
+/** **/
+/** SECTION: HANDLING OF CONNECTION **/
+/** **/
+/** **/
+/***************************************************************************************/
+/***************************************************************************************/
+/* declare the connection routine */
+static int connection();
+
/*
* called on an event on the NMEA stream
*/
-static int nmea_on_event(sd_event_source *s, int fd, uint32_t revents, void *userdata)
+static int on_event(sd_event_source *s, int fd, uint32_t revents, void *userdata)
{
/* read available data */
if ((revents & EPOLLIN) != 0) {
@@ -787,7 +796,7 @@ static int nmea_on_event(sd_event_source *s, int fd, uint32_t revents, void *use
if ((revents & (EPOLLERR|EPOLLRDHUP|EPOLLHUP)) != 0) {
sd_event_source_unref(s);
close(fd);
- nmea_connect(fd);
+ connection(fd);
}
return 0;
@@ -829,18 +838,14 @@ static int open_socket_to(const char *host, const char *service)
}
/*
- * connection to nmea stream
+ * connection to nmea stream for the host and the port
*/
-static int nmea_connect()
+static int connect_to(const char *host, const char *service, int isgpsd)
{
sd_event_source *source;
int rc, fd;
- const char *host;
- const char *service;
/* TODO connect to somewhere else */
- host = "sinagot.net";
- service = "5001";
fd = open_socket_to(host, service);
if (fd < 0) {
ERROR(afbitf, "can't connect to host %s, service %s", host, service);
@@ -848,7 +853,7 @@ static int nmea_connect()
}
/* adds to the event loop */
- rc = sd_event_add_io(afb_daemon_get_event_loop(afbitf->daemon), &source, fd, EPOLLIN, nmea_on_event, NULL);
+ rc = sd_event_add_io(afb_daemon_get_event_loop(afbitf->daemon), &source, fd, EPOLLIN, on_event, NULL);
if (rc < 0) {
close(fd);
ERROR(afbitf, "can't coonect host %s, service %s to the event loop", host, service);
@@ -856,6 +861,22 @@ static int nmea_connect()
return rc;
}
+/*
+ * connection to nmea stream
+ */
+static int connection()
+{
+ const char *host;
+ const char *service;
+ int isgpsd;
+
+ /* TODO connect to somewhere else */
+ host = getenv("AFBGPS_HOST") ? : "sinagot.net";
+ service = getenv("AFBGPS_SERVICE") ? : "5001";
+ isgpsd = getenv("AFBGPS_ISNMEA") ? 0 : 1;
+ return connect_to(host, service, isgpsd);
+}
+
/***************************************************************************************/
/***************************************************************************************/
/** **/
@@ -980,7 +1001,7 @@ const struct afb_binding *afbBindingV1Register(const struct afb_binding_interfac
{
afbitf = itf; /* records the interface for accessing afb-daemon */
- nmea_connect();
+ connection();
return &binding_description; /* returns the description of the binding */
}