From 020d97ca4a249fa59e7b18c7b1681c2b066ef6ed Mon Sep 17 00:00:00 2001 From: Ankur Date: Tue, 23 Dec 2014 15:36:40 +0530 Subject: [PATCH 01/16] Removed warning - use of deprecated function -The function g_type_init() has been deprecated in glib from version 2.36. So no need to call this for version 2.36 and above. -There is a macro for the glib version called - GLIB_VERSION_2_36 (2_36 can be replaced by the version number) -So, used this macro to check if the glib version is old or new and based on that function call should be placed. Change-Id: I291c32825ade29375b46df4ba2cef3a3fc13503e --- src/server/dbus_util.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/server/dbus_util.cpp b/src/server/dbus_util.cpp index f3a0ca5..662be73 100755 --- a/src/server/dbus_util.cpp +++ b/src/server/dbus_util.cpp @@ -103,7 +103,10 @@ static void on_name_lost(GDBusConnection *conn, void init_dbus(void) { + + #ifndef GLIB_VERSION_2_36 g_type_init(); + #endif introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL); if (introspection_data == NULL) { -- 2.7.4 From 3357e9c9ca08a1ac689ad51b5841747722cc05f4 Mon Sep 17 00:00:00 2001 From: Ankur Date: Tue, 23 Dec 2014 18:52:50 +0530 Subject: [PATCH 02/16] Removed compiler warning - Comparison between signed and unsigned integers -In client.cpp, the variable was an index for 'for' loop, and was always positive, so can be changed on unsigned. -In sensor_plugin_loader.cpp, the variable was intialized with a variable which was unsigned int, and later was right shifted which will remain positive, so can be changed to unsigned int Change-Id: I9efeea4c4a90186378eefbe24f76eb945ae9a3db --- src/libsensord/client.cpp | 2 +- src/shared/sensor_plugin_loader.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsensord/client.cpp b/src/libsensord/client.cpp index 79245d7..de31c85 100755 --- a/src/libsensord/client.cpp +++ b/src/libsensord/client.cpp @@ -413,7 +413,7 @@ API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *senso *list = (sensor_t *) malloc(sizeof(sensor_info *) * sensor_infos.size()); retvm_if(!*list, false, "Failed to allocate memory"); - for (int i = 0; i < sensor_infos.size(); ++i) + for (unsigned int i = 0; i < sensor_infos.size(); ++i) *(*list + i) = sensor_info_to_sensor(sensor_infos[i]); *sensor_count = sensor_infos.size(); diff --git a/src/shared/sensor_plugin_loader.cpp b/src/shared/sensor_plugin_loader.cpp index 8aa70d1..5a096a9 100755 --- a/src/shared/sensor_plugin_loader.cpp +++ b/src/shared/sensor_plugin_loader.cpp @@ -373,7 +373,7 @@ sensor_base* sensor_plugin_loader::get_sensor(sensor_id_t id) vector sensors; sensor_type_t type = (sensor_type_t) (id & SENSOR_TYPE_MASK); - int index = id >> SENSOR_INDEX_SHIFT; + unsigned int index = id >> SENSOR_INDEX_SHIFT; sensors = get_sensors(type); -- 2.7.4 From 871b3b505d0420f4dc492380e558a439eb6cf1bb Mon Sep 17 00:00:00 2001 From: Ankur Date: Wed, 24 Dec 2014 17:31:20 +0530 Subject: [PATCH 03/16] Removed compiler warning - dereferencing type-punned pointer will break strict-aliasing rules -Tested the change. Works fine. Change-Id: Ib2dfbd9fb67fe1c634df84ef833953db471fbd74 --- src/shared/sensor_info.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shared/sensor_info.cpp b/src/shared/sensor_info.cpp index 0521aea..fe8303c 100755 --- a/src/shared/sensor_info.cpp +++ b/src/shared/sensor_info.cpp @@ -237,7 +237,8 @@ void sensor_info::put(raw_data_t &data, int value) { char buffer[sizeof(value)]; - (*(int *) buffer) = value; + int *temp = (int *) buffer; + *temp = value; copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data)); } @@ -246,7 +247,8 @@ void sensor_info::put(raw_data_t &data, float value) { char buffer[sizeof(value)]; - (*(float *) buffer) = value; + float *temp = (float *) buffer; + *temp = value; copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data)); } -- 2.7.4 From 0e2b8fc58245907dda8983fa0aea19fd4be37aa0 Mon Sep 17 00:00:00 2001 From: Ankur Date: Wed, 24 Dec 2014 17:34:20 +0530 Subject: [PATCH 04/16] Removed compiler warning - pointer of type 'void *' used in arithmetic -The void * pointer was being directly used in the calculation without type cast. -Tested after change. Seems to work fine. Change-Id: I483f946d870b3b5b1415139dbd0f442796b18059 --- src/shared/csocket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 63eaa47..5a04ce3 100755 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -215,7 +215,7 @@ ssize_t csocket::send_for_stream(void const* buffer, size_t size) const ssize_t total_sent_size = 0; do { - len = ::send(m_sock_fd, buffer + total_sent_size, size - total_sent_size, m_send_flags); + len = ::send(m_sock_fd, (void const*)((uint8_t *)buffer + total_sent_size), size - total_sent_size, m_send_flags); if (len >= 0) { total_sent_size += len; @@ -242,7 +242,7 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const ssize_t total_recv_size = 0; do { - len = ::recv(m_sock_fd, buffer + total_recv_size, size - total_recv_size, m_recv_flags); + len = ::recv(m_sock_fd, (void *)((uint8_t *)buffer + total_recv_size), size - total_recv_size, m_recv_flags); if (len > 0) { total_recv_size += len; -- 2.7.4 From 2793615c50e9f072b0cf38897c7f3b17a7ac8c9f Mon Sep 17 00:00:00 2001 From: Ankur Date: Wed, 24 Dec 2014 17:37:22 +0530 Subject: [PATCH 05/16] Removed compiler warning - comparison between signed and unsigned integers -The signed variables were positive the whole time. So, converted them from ssize_t to size_t Change-Id: I743cd86f864ac22820951302679f2889e42e11b9 --- src/shared/csocket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 63eaa47..67c7642 100755 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -212,7 +212,7 @@ ssize_t csocket::send_for_stream(void const* buffer, size_t size) const { ssize_t len; ssize_t err = 0; - ssize_t total_sent_size = 0; + size_t total_sent_size = 0; do { len = ::send(m_sock_fd, buffer + total_sent_size, size - total_sent_size, m_send_flags); @@ -239,7 +239,7 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const { ssize_t len; ssize_t err = 0; - ssize_t total_recv_size = 0; + size_t total_recv_size = 0; do { len = ::recv(m_sock_fd, buffer + total_recv_size, size - total_recv_size, m_recv_flags); -- 2.7.4 From 6749fe38425410aa54500081a4cae0f135ac3a0a Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 2 Jan 2015 08:50:16 +0530 Subject: [PATCH 06/16] Fix for orientation values being set to Nan - Fixing issue where low floating point values are rounded of to zero. - indexing issue. - Cleanup Change-Id: Ief4a37395b50f8946bf1d622c0895a881c3a7619 --- src/sensor_fusion/orientation_filter.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/sensor_fusion/orientation_filter.cpp b/src/sensor_fusion/orientation_filter.cpp index 05537a3..5e0a354 100644 --- a/src/sensor_fusion/orientation_filter.cpp +++ b/src/sensor_fusion/orientation_filter.cpp @@ -40,6 +40,10 @@ #define QWB_CONST ((2 * (ZIGMA_W * ZIGMA_W)) / TAU_W) #define F_CONST (-1 / TAU_W) +#define NEGLIGIBLE_VAL 0.0000001 + +#define ABS(val) (((val) < 0) ? -(val) : (val)) + // M-matrix, V-vector, MxN=> matrix dimension, R-RowCount, C-Column count #define M3X3R 3 #define M3X3C 3 @@ -96,8 +100,6 @@ template inline void orientation_filter::initialize_sensor_data(const sensor_data accel, const sensor_data gyro, const sensor_data magnetic) { - vect acc_data(V1x3S); - vect gyr_data(V1x3S); unsigned long long sample_interval_gyro = SAMPLE_INTV; m_accel.m_data = accel.m_data; @@ -258,10 +260,8 @@ inline void orientation_filter::measurement_update() matrix gain(M6X6R, M6X6C); TYPE iden = 0; - for (int j = 0; j < M6X6C; j++) - { - for (int i = 0; i < M6X6R; i++) - { + for (int j=0; j::measurement_update() else iden = 0; - m_pred_cov.m_mat[i][j] = (iden - (gain.m_mat[i][j] * m_measure_mat.m_mat[j][i])) * - m_pred_cov.m_mat[i][j]; + m_pred_cov.m_mat[j][i] = (iden - (gain.m_mat[i][j] * m_measure_mat.m_mat[j][i])) * + m_pred_cov.m_mat[j][i]; + + if (ABS(m_pred_cov.m_mat[j][i]) < NEGLIGIBLE_VAL) + m_pred_cov.m_mat[j][i] = NEGLIGIBLE_VAL; } } -- 2.7.4 From 537339baada31e06a10bc201e4ccdab002f0afc9 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 2 Jan 2015 09:05:11 +0530 Subject: [PATCH 07/16] Updating linear acceleration range in get_properties - Updating the min_range and max_range values in get_properties to to shown according to accelerometer range. - cleanup Change-Id: I2f2c68b8e29aad658d1cea1eed8ef7fc3bd0a2c4 --- src/linear_accel/linear_accel_sensor.cpp | 4 +--- src/orientation/orientation_sensor.cpp | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/linear_accel/linear_accel_sensor.cpp b/src/linear_accel/linear_accel_sensor.cpp index 1af20bc..fb2dabd 100755 --- a/src/linear_accel/linear_accel_sensor.cpp +++ b/src/linear_accel/linear_accel_sensor.cpp @@ -273,11 +273,9 @@ int linear_accel_sensor::get_sensor_data(const unsigned int event_type, sensor_d bool linear_accel_sensor::get_properties(sensor_properties_t &properties) { - m_gravity_sensor->get_properties(properties); + m_accel_sensor->get_properties(properties); properties.name = "Linear Acceleration Sensor"; properties.vendor = m_vendor; - properties.min_range = - 2 * GRAVITY; - properties.max_range = 2 * GRAVITY; properties.resolution = 0.000001; return true; diff --git a/src/orientation/orientation_sensor.cpp b/src/orientation/orientation_sensor.cpp index dd0f818..7653ef3 100755 --- a/src/orientation/orientation_sensor.cpp +++ b/src/orientation/orientation_sensor.cpp @@ -436,7 +436,7 @@ bool orientation_sensor::get_properties(sensor_properties_t &properties) properties.min_range = -PI; properties.max_range = 2 * PI; } - properties.resolution = 0.000001;; + properties.resolution = 0.000001; properties.vendor = m_vendor; properties.name = SENSOR_NAME; -- 2.7.4 From 7cd4ed8647a5a0b42fdb8eec6b3f289472b8a204 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 2 Jan 2015 09:35:02 +0530 Subject: [PATCH 08/16] Adding Rotation Vector virtual sensor - Added 9-axis rotation vector based on sensor fusion - Added xml configuration support for virtual sensor - Added xml configuration for loading rotation vector library - Updated build and spec files Change-Id: I540b277019aa9a946e267b89c39a15e168dbe9f0 --- packaging/sensord.spec | 3 +- sensor_plugins.xml.in | 1 + src/libsensord/sensor_internal.h | 1 + src/libsensord/sensor_internal_deprecated.h | 1 + src/rotation_vector/CMakeLists.txt | 4 + src/rotation_vector/rv/CMakeLists.txt | 47 ++++ src/rotation_vector/rv/rv_sensor.cpp | 390 ++++++++++++++++++++++++++++ src/rotation_vector/rv/rv_sensor.h | 87 +++++++ virtual_sensors.xml.in | 16 ++ 9 files changed, 549 insertions(+), 1 deletion(-) create mode 100644 src/rotation_vector/CMakeLists.txt create mode 100755 src/rotation_vector/rv/CMakeLists.txt create mode 100755 src/rotation_vector/rv/rv_sensor.cpp create mode 100755 src/rotation_vector/rv/rv_sensor.h diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 2e1fff7..1d305ff 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -18,6 +18,7 @@ Source2: sensord.socket %define orientation_state ON %define gravity_state ON %define linear_accel_state ON +%define rv_state ON %define build_test_suite OFF @@ -79,7 +80,7 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DACCEL=%{accel_state} \ -DGYRO=%{gyro_state} -DPROXI=%{proxi_state} -DLIGHT=%{light_state} \ -DGEO=%{geo_state} -DPRESSURE=%{pressure_state} -DTEMPERATURE=%{temperature_state} \ -DORIENTATION=%{orientation_state} -DGRAVITY=%{gravity_state} \ - -DLINEAR_ACCEL=%{linear_accel_state} \ + -DLINEAR_ACCEL=%{linear_accel_state} -DRV=%{rv_state} \ -DTEST_SUITE=%{build_test_suite} make %{?jobs:-j%jobs} diff --git a/sensor_plugins.xml.in b/sensor_plugins.xml.in index f40f79a..aca8a81 100755 --- a/sensor_plugins.xml.in +++ b/sensor_plugins.xml.in @@ -20,5 +20,6 @@ + diff --git a/src/libsensord/sensor_internal.h b/src/libsensord/sensor_internal.h index bec1487..3bc8311 100755 --- a/src/libsensord/sensor_internal.h +++ b/src/libsensord/sensor_internal.h @@ -49,6 +49,7 @@ extern "C" #include #include #include +#include #include diff --git a/src/libsensord/sensor_internal_deprecated.h b/src/libsensord/sensor_internal_deprecated.h index f0a1a74..dc4a8b3 100755 --- a/src/libsensord/sensor_internal_deprecated.h +++ b/src/libsensord/sensor_internal_deprecated.h @@ -48,6 +48,7 @@ extern "C" #include #include #include +#include typedef struct { condition_op_t cond_op; diff --git a/src/rotation_vector/CMakeLists.txt b/src/rotation_vector/CMakeLists.txt new file mode 100644 index 0000000..c111931 --- /dev/null +++ b/src/rotation_vector/CMakeLists.txt @@ -0,0 +1,4 @@ +IF("${RV}" STREQUAL "ON") +add_subdirectory(rv) +ENDIF() + diff --git a/src/rotation_vector/rv/CMakeLists.txt b/src/rotation_vector/rv/CMakeLists.txt new file mode 100755 index 0000000..33ac289 --- /dev/null +++ b/src/rotation_vector/rv/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 2.6) +project(rv CXX) + +# to install pkgconfig setup file. +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include") +SET(VERSION 1.0) + +SET(SENSOR_NAME rv_sensor) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_SOURCE_DIR}/src/libsensord) +include_directories(${CMAKE_SOURCE_DIR}/src/sensor_fusion) + +include(FindPkgConfig) +pkg_check_modules(rpkgs REQUIRED vconf) +add_definitions(${rpkgs_CFLAGS} -DUSE_ONLY_ONE_MODULE -DUSE_LCD_TYPE_CHECK) + +set(PROJECT_MAJOR_VERSION "0") +set(PROJECT_MINOR_VERSION "0") +set(PROJECT_RELEASE_VERSION "1") +set(CMAKE_VERBOSE_MAKEFILE OFF) + + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" MATCHES "^arm.*") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") +ELSE("${ARCH}" MATCHES "^arm.*") + ADD_DEFINITIONS("-DSIMULATOR") + MESSAGE("add -DSIMULATOR") +ENDIF("${ARCH}" MATCHES "^arm.*") + +add_definitions(-Wall -O3 -omit-frame-pointer) +add_definitions(-DUSE_DLOG_LOG) +#add_definitions(-Wall -g -D_DEBUG) +add_definitions(-Iinclude) + +add_library(${SENSOR_NAME} SHARED + rv_sensor.cpp +) + +target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") + +install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) diff --git a/src/rotation_vector/rv/rv_sensor.cpp b/src/rotation_vector/rv/rv_sensor.cpp new file mode 100755 index 0000000..cee3a94 --- /dev/null +++ b/src/rotation_vector/rv/rv_sensor.cpp @@ -0,0 +1,390 @@ +/* + * sensord + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SENSOR_NAME "RV_SENSOR" +#define SENSOR_TYPE_RV "ROTATION_VECTOR" + +#define ACCELEROMETER_ENABLED 0x01 +#define GYROSCOPE_ENABLED 0x02 +#define GEOMAGNETIC_ENABLED 0x04 +#define ORIENTATION_ENABLED 7 + +#define INITIAL_VALUE -1 + +#define MS_TO_US 1000 + +#define ELEMENT_NAME "NAME" +#define ELEMENT_VENDOR "VENDOR" +#define ELEMENT_RAW_DATA_UNIT "RAW_DATA_UNIT" +#define ELEMENT_DEFAULT_SAMPLING_TIME "DEFAULT_SAMPLING_TIME" +#define ELEMENT_ACCEL_STATIC_BIAS "ACCEL_STATIC_BIAS" +#define ELEMENT_GYRO_STATIC_BIAS "GYRO_STATIC_BIAS" +#define ELEMENT_GEOMAGNETIC_STATIC_BIAS "GEOMAGNETIC_STATIC_BIAS" +#define ELEMENT_ACCEL_ROTATION_DIRECTION_COMPENSATION "ACCEL_ROTATION_DIRECTION_COMPENSATION" +#define ELEMENT_GYRO_ROTATION_DIRECTION_COMPENSATION "GYRO_ROTATION_DIRECTION_COMPENSATION" +#define ELEMENT_GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION "GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION" +#define ELEMENT_ACCEL_SCALE "ACCEL_SCALE" +#define ELEMENT_GYRO_SCALE "GYRO_SCALE" +#define ELEMENT_GEOMAGNETIC_SCALE "GEOMAGNETIC_SCALE" +#define ELEMENT_MAGNETIC_ALIGNMENT_FACTOR "MAGNETIC_ALIGNMENT_FACTOR" + +void pre_process_data(sensor_data &data_out, const float *data_in, float *bias, int *sign, float scale) +{ + data_out.m_data.m_vec[0] = sign[0] * (data_in[0] - bias[0]) / scale; + data_out.m_data.m_vec[1] = sign[1] * (data_in[1] - bias[1]) / scale; + data_out.m_data.m_vec[2] = sign[2] * (data_in[2] - bias[2]) / scale; +} + +rv_sensor::rv_sensor() +: m_accel_sensor(NULL) +, m_gyro_sensor(NULL) +, m_magnetic_sensor(NULL) +, m_x(-1) +, m_y(-1) +, m_z(-1) +, m_w(-1) +, m_accuracy(-1) +, m_time(0) +{ + cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); + + m_name = string(SENSOR_NAME); + register_supported_event(ROTATION_VECTOR_EVENT_RAW_DATA_REPORT_ON_TIME); + m_enable_orientation = 0; + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_VENDOR, m_vendor)) { + ERR("[VENDOR] is empty\n"); + throw ENXIO; + } + + INFO("m_vendor = %s", m_vendor.c_str()); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_DEFAULT_SAMPLING_TIME, &m_default_sampling_time)) { + ERR("[DEFAULT_SAMPLING_TIME] is empty\n"); + throw ENXIO; + } + + INFO("m_default_sampling_time = %d", m_default_sampling_time); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_ACCEL_STATIC_BIAS, m_accel_static_bias, 3)) { + ERR("[ACCEL_STATIC_BIAS] is empty\n"); + throw ENXIO; + } + + INFO("m_accel_static_bias = (%f, %f, %f)", m_accel_static_bias[0], m_accel_static_bias[1], m_accel_static_bias[2]); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_GYRO_STATIC_BIAS, m_gyro_static_bias,3)) { + ERR("[GYRO_STATIC_BIAS] is empty\n"); + throw ENXIO; + } + + INFO("m_gyro_static_bias = (%f, %f, %f)", m_gyro_static_bias[0], m_gyro_static_bias[1], m_gyro_static_bias[2]); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_GEOMAGNETIC_STATIC_BIAS, m_geomagnetic_static_bias, 3)) { + ERR("[GEOMAGNETIC_STATIC_BIAS] is empty\n"); + throw ENXIO; + } + + INFO("m_geomagnetic_static_bias = (%f, %f, %f)", m_geomagnetic_static_bias[0], m_geomagnetic_static_bias[1], m_geomagnetic_static_bias[2]); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_ACCEL_ROTATION_DIRECTION_COMPENSATION, m_accel_rotation_direction_compensation, 3)) { + ERR("[ACCEL_ROTATION_DIRECTION_COMPENSATION] is empty\n"); + throw ENXIO; + } + + INFO("m_accel_rotation_direction_compensation = (%d, %d, %d)", m_accel_rotation_direction_compensation[0], m_accel_rotation_direction_compensation[1], m_accel_rotation_direction_compensation[2]); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_GYRO_ROTATION_DIRECTION_COMPENSATION, m_gyro_rotation_direction_compensation, 3)) { + ERR("[GYRO_ROTATION_DIRECTION_COMPENSATION] is empty\n"); + throw ENXIO; + } + + INFO("m_gyro_rotation_direction_compensation = (%d, %d, %d)", m_gyro_rotation_direction_compensation[0], m_gyro_rotation_direction_compensation[1], m_gyro_rotation_direction_compensation[2]); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION, m_geomagnetic_rotation_direction_compensation, 3)) { + ERR("[GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION] is empty\n"); + throw ENXIO; + } + + INFO("m_geomagnetic_rotation_direction_compensation = (%d, %d, %d)", m_geomagnetic_rotation_direction_compensation[0], m_geomagnetic_rotation_direction_compensation[1], m_geomagnetic_rotation_direction_compensation[2]); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_ACCEL_SCALE, &m_accel_scale)) { + ERR("[ACCEL_SCALE] is empty\n"); + throw ENXIO; + } + + INFO("m_accel_scale = %f", m_accel_scale); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_GYRO_SCALE, &m_gyro_scale)) { + ERR("[GYRO_SCALE] is empty\n"); + throw ENXIO; + } + + INFO("m_gyro_scale = %f", m_gyro_scale); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_GEOMAGNETIC_SCALE, &m_geomagnetic_scale)) { + ERR("[GEOMAGNETIC_SCALE] is empty\n"); + throw ENXIO; + } + + INFO("m_geomagnetic_scale = %f", m_geomagnetic_scale); + + if (!config.get(SENSOR_TYPE_RV, ELEMENT_MAGNETIC_ALIGNMENT_FACTOR, &m_magnetic_alignment_factor)) { + ERR("[MAGNETIC_ALIGNMENT_FACTOR] is empty\n"); + throw ENXIO; + } + + INFO("m_magnetic_alignment_factor = %d", m_magnetic_alignment_factor); + + m_interval = m_default_sampling_time * MS_TO_US; + +} + +rv_sensor::~rv_sensor() +{ + INFO("rv_sensor is destroyed!\n"); +} + +bool rv_sensor::init() +{ + m_accel_sensor = sensor_plugin_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); + m_gyro_sensor = sensor_plugin_loader::get_instance().get_sensor(GYROSCOPE_SENSOR); + m_magnetic_sensor = sensor_plugin_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); + + if (!m_accel_sensor || !m_gyro_sensor || !m_magnetic_sensor) { + ERR("Failed to load sensors, accel: 0x%x, gyro: 0x%x, mag: 0x%x", + m_accel_sensor, m_gyro_sensor, m_magnetic_sensor); + return false; + } + + INFO("%s is created!\n", sensor_base::get_name()); + + return true; +} + +sensor_type_t rv_sensor::get_type(void) +{ + return ROTATION_VECTOR_SENSOR; +} + +bool rv_sensor::on_start(void) +{ + AUTOLOCK(m_mutex); + + m_accel_sensor->add_client(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME); + m_accel_sensor->add_interval((int)this, (m_interval/MS_TO_US), false); + m_accel_sensor->start(); + m_gyro_sensor->add_client(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME); + m_gyro_sensor->add_interval((int)this, (m_interval/MS_TO_US), false); + m_gyro_sensor->start(); + m_magnetic_sensor->add_client(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME); + m_magnetic_sensor->add_interval((int)this, (m_interval/MS_TO_US), false); + m_magnetic_sensor->start(); + + activate(); + return true; +} + +bool rv_sensor::on_stop(void) +{ + AUTOLOCK(m_mutex); + + m_accel_sensor->delete_client(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME); + m_accel_sensor->delete_interval((int)this, false); + m_accel_sensor->stop(); + m_gyro_sensor->delete_client(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME); + m_gyro_sensor->delete_interval((int)this, false); + m_gyro_sensor->stop(); + m_magnetic_sensor->delete_client(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME); + m_magnetic_sensor->delete_interval((int)this, false); + m_magnetic_sensor->stop(); + + deactivate(); + return true; +} + +bool rv_sensor::add_interval(int client_id, unsigned int interval) +{ + AUTOLOCK(m_mutex); + + m_accel_sensor->add_interval(client_id, interval, false); + m_gyro_sensor->add_interval(client_id, interval, false); + m_magnetic_sensor->add_interval(client_id, interval, false); + + return sensor_base::add_interval(client_id, interval, false); +} + +bool rv_sensor::delete_interval(int client_id) +{ + AUTOLOCK(m_mutex); + + m_accel_sensor->delete_interval(client_id, false); + m_gyro_sensor->delete_interval(client_id, false); + m_magnetic_sensor->delete_interval(client_id, false); + + return sensor_base::delete_interval(client_id, false); +} + +void rv_sensor::synthesize(const sensor_event_t& event, vector &outs) +{ + const float MIN_DELIVERY_DIFF_FACTOR = 0.75f; + unsigned long long diff_time; + + sensor_event_t rv_event; + quaternion quaternion_orientation; + + if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) { + diff_time = event.data.timestamp - m_time; + + if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) + return; + + pre_process_data(m_accel, event.data.values, m_accel_static_bias, m_accel_rotation_direction_compensation, m_accel_scale); + + m_accel.m_time_stamp = event.data.timestamp; + + m_enable_orientation |= ACCELEROMETER_ENABLED; + } + else if (event.event_type == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) { + diff_time = event.data.timestamp - m_time; + + if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) + return; + + pre_process_data(m_gyro, event.data.values, m_gyro_static_bias, m_gyro_rotation_direction_compensation, m_gyro_scale); + + m_gyro.m_time_stamp = event.data.timestamp; + + m_enable_orientation |= GYROSCOPE_ENABLED; + } + else if (event.event_type == GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME) { + diff_time = event.data.timestamp - m_time; + + if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) + return; + + pre_process_data(m_magnetic, event.data.values, m_geomagnetic_static_bias, m_geomagnetic_rotation_direction_compensation, m_geomagnetic_scale); + + m_magnetic.m_time_stamp = event.data.timestamp; + + m_enable_orientation |= GEOMAGNETIC_ENABLED; + } + + if (m_enable_orientation == ORIENTATION_ENABLED) { + m_enable_orientation = 0; + + m_orientation.m_pitch_phase_compensation = m_pitch_rotation_compensation; + m_orientation.m_roll_phase_compensation = m_roll_rotation_compensation; + m_orientation.m_azimuth_phase_compensation = m_azimuth_rotation_compensation; + m_orientation.m_magnetic_alignment_factor = m_magnetic_alignment_factor; + + { + AUTOLOCK(m_fusion_mutex); + quaternion_orientation = m_orientation.get_quaternion(m_accel, m_gyro, m_magnetic); + } + + rv_event.sensor_id = get_id(); + rv_event.event_type = ROTATION_VECTOR_EVENT_RAW_DATA_REPORT_ON_TIME; + rv_event.data.accuracy = SENSOR_ACCURACY_GOOD; + rv_event.data.timestamp = get_timestamp(); + rv_event.data.value_count = 4; + rv_event.data.values[0] = quaternion_orientation.m_quat.m_vec[1]; + rv_event.data.values[1] = quaternion_orientation.m_quat.m_vec[2]; + rv_event.data.values[2] = quaternion_orientation.m_quat.m_vec[3]; + rv_event.data.values[3] = quaternion_orientation.m_quat.m_vec[0]; + + push(rv_event); + + { + AUTOLOCK(m_value_mutex); + m_time = rv_event.data.value_count; + m_x = rv_event.data.values[0]; + m_y = rv_event.data.values[1]; + m_z = rv_event.data.values[2]; + m_w = rv_event.data.values[3]; + } + } + + return; +} + +int rv_sensor::get_sensor_data(unsigned int data_id, sensor_data_t &data) +{ + if (data_id != ROTATION_VECTOR_BASE_DATA_SET) + return -1; + + data.accuracy = SENSOR_ACCURACY_GOOD; + + AUTOLOCK(m_value_mutex); + data.timestamp = m_time; + data.values[0] = m_x; + data.values[1] = m_y; + data.values[2] = m_z; + data.values[3] = m_w; + data.value_count = 4; + + return 0; +} + +bool rv_sensor::get_properties(sensor_properties_t &properties) +{ + properties.vendor = m_vendor; + properties.name = SENSOR_NAME; + properties.min_range = 0; + properties.max_range = 1; + properties.resolution = 0.000001; + properties.fifo_count = 0; + properties.max_batch_count = 0; + properties.min_interval = 1; + + return true; +} + +extern "C" sensor_module* create(void) +{ + rv_sensor *sensor; + + try { + sensor = new(std::nothrow) rv_sensor; + } catch (int err) { + ERR("Failed to create module, err: %d, cause: %s", err, strerror(err)); + return NULL; + } + + sensor_module *module = new(std::nothrow) sensor_module; + retvm_if(!module || !sensor, NULL, "Failed to allocate memory"); + + module->sensors.push_back(sensor); + return module; +} diff --git a/src/rotation_vector/rv/rv_sensor.h b/src/rotation_vector/rv/rv_sensor.h new file mode 100755 index 0000000..3d84a80 --- /dev/null +++ b/src/rotation_vector/rv/rv_sensor.h @@ -0,0 +1,87 @@ +/* + * sensord + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _RV_SENSOR_H_ +#define _RV_SENSOR_H_ + +#include +#include +#include + +class rv_sensor : public virtual_sensor { +public: + rv_sensor(); + virtual ~rv_sensor(); + + bool init(void); + + void synthesize(const sensor_event_t &event, vector &outs); + + bool add_interval(int client_id, unsigned int interval); + bool delete_interval(int client_id); + bool get_properties(sensor_properties_t &properties); + sensor_type_t get_type(void); + + int get_sensor_data(const unsigned int data_id, sensor_data_t &data); + +private: + sensor_base *m_accel_sensor; + sensor_base *m_gyro_sensor; + sensor_base *m_magnetic_sensor; + + sensor_data m_accel; + sensor_data m_gyro; + sensor_data m_magnetic; + + cmutex m_value_mutex; + + orientation_filter m_orientation; + + unsigned int m_enable_orientation; + + float m_x; + float m_y; + float m_z; + float m_w; + int m_accuracy; + unsigned long long m_time; + unsigned int m_interval; + + string m_vendor; + string m_raw_data_unit; + int m_default_sampling_time; + float m_accel_static_bias[3]; + float m_gyro_static_bias[3]; + float m_geomagnetic_static_bias[3]; + int m_accel_rotation_direction_compensation[3]; + int m_gyro_rotation_direction_compensation[3]; + int m_geomagnetic_rotation_direction_compensation[3]; + float m_accel_scale; + float m_gyro_scale; + float m_geomagnetic_scale; + int m_magnetic_alignment_factor; + int m_azimuth_rotation_compensation; + int m_pitch_rotation_compensation; + int m_roll_rotation_compensation; + + bool on_start(void); + bool on_stop(void); +}; + +#endif /*_RV_SENSOR_H_*/ diff --git a/virtual_sensors.xml.in b/virtual_sensors.xml.in index 42c9d72..680745e 100644 --- a/virtual_sensors.xml.in +++ b/virtual_sensors.xml.in @@ -38,4 +38,20 @@ + + + + + + + + + + + + + + + + -- 2.7.4 From 4612a07cb5158eeaadd089e18524260eaf942977 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 2 Jan 2015 09:53:28 +0530 Subject: [PATCH 09/16] Updating virtual sensor xml configuration for multiple devices - Updated virtual sensor xml configuration file to support multiple devices and emulators - Updated virtual sensor xml parser to support additional functionality Change-Id: I647958a6010e7ecebfc282ba72bf61ac6706d5cf --- src/shared/cvirtual_sensor_config.cpp | 117 ++++++++++++++++--------- src/shared/cvirtual_sensor_config.h | 13 ++- virtual_sensors.xml.in | 160 +++++++++++++++++++++++----------- 3 files changed, 195 insertions(+), 95 deletions(-) diff --git a/src/shared/cvirtual_sensor_config.cpp b/src/shared/cvirtual_sensor_config.cpp index c0d0f0b..a636e87 100755 --- a/src/shared/cvirtual_sensor_config.cpp +++ b/src/shared/cvirtual_sensor_config.cpp @@ -28,13 +28,13 @@ using std::string; using std::stringstream; -#define ROOT_ELEMENT "VIRTUAL_SENSOR" -#define TEXT_ELEMENT "text" -#define MODEL_ID_ATTR "id" -#define DEFAULT_ATTR "value" -#define DEFAULT_ATTR1 "value1" -#define DEFAULT_ATTR2 "value2" -#define DEFAULT_ATTR3 "value3" +#define ROOT_ELEMENT "VIRTUAL_SENSOR" +#define DEVICE_TYPE_ATTR "type" +#define TEXT_ELEMENT "text" +#define DEFAULT_ATTR "value" +#define DEFAULT_ATTR1 "value1" +#define DEFAULT_ATTR2 "value2" +#define DEFAULT_ATTR3 "value3" cvirtual_sensor_config::cvirtual_sensor_config() { @@ -85,57 +85,78 @@ bool cvirtual_sensor_config::load_config(const string& config_path) return false; } + xmlNodePtr device_node_ptr; xmlNodePtr virtual_sensor_node_ptr; xmlNodePtr element_node_ptr; xmlAttrPtr attr_ptr; char* prop = NULL; - virtual_sensor_node_ptr = cur->xmlChildrenNode; - - while (virtual_sensor_node_ptr != NULL) { + device_node_ptr = cur->xmlChildrenNode; + while (device_node_ptr != NULL){ //skip garbage element, [text] - if (!xmlStrcmp(virtual_sensor_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) { - virtual_sensor_node_ptr = virtual_sensor_node_ptr->next; + if (!xmlStrcmp(device_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) { + device_node_ptr = device_node_ptr->next; continue; } - //insert Model_list to config map - m_virtual_sensor_config[(const char*)virtual_sensor_node_ptr->name]; - DBG("<%s>\n",(const char*)virtual_sensor_node_ptr->name); - element_node_ptr = virtual_sensor_node_ptr->xmlChildrenNode; - while (element_node_ptr != NULL) { + string device_type; + prop = (char*)xmlGetProp(device_node_ptr,(const xmlChar*)DEVICE_TYPE_ATTR); + device_type = prop; + free(prop); + + //insert device to device_list + m_virtual_sensor_config[device_type]; + DBG("\n",device_type.c_str()); + + virtual_sensor_node_ptr = device_node_ptr->xmlChildrenNode; + + while (virtual_sensor_node_ptr != NULL) { //skip garbage element, [text] - if (!xmlStrcmp(element_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) { - element_node_ptr = element_node_ptr->next; + if (!xmlStrcmp(virtual_sensor_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) { + virtual_sensor_node_ptr = virtual_sensor_node_ptr->next; continue; } - //insert Element to Model - m_virtual_sensor_config[(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name]; - DBG("<%s><%s>\n",(const char*)virtual_sensor_node_ptr->name,(const char*)element_node_ptr->name); + m_virtual_sensor_config[device_type][(const char*)virtual_sensor_node_ptr->name]; + DBG("<%s>\n",device_type.c_str(),(const char*)virtual_sensor_node_ptr->name); - attr_ptr = element_node_ptr->properties; - while (attr_ptr != NULL) { + element_node_ptr = virtual_sensor_node_ptr->xmlChildrenNode; + while (element_node_ptr != NULL) { + //skip garbage element, [text] + if (!xmlStrcmp(element_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) { + element_node_ptr = element_node_ptr->next; + continue; + } - string key,value; - key = (char*)attr_ptr->name; - prop = (char*)xmlGetProp(element_node_ptr,attr_ptr->name); - value = prop; - free(prop); + //insert Element to Model + m_virtual_sensor_config[device_type][(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name]; + DBG("<%s><%s>\n",device_type.c_str(),(const char*)virtual_sensor_node_ptr->name,(const char*)element_node_ptr->name); + + attr_ptr = element_node_ptr->properties; + while (attr_ptr != NULL) { + + string key,value; + key = (char*)attr_ptr->name; + prop = (char*)xmlGetProp(element_node_ptr,attr_ptr->name); + value = prop; + free(prop); + + //insert attribute to Element + m_virtual_sensor_config[device_type][(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name][key]=value; + DBG("<%s><%s \"%s\"=\"%s\">\n",device_type.c_str(),(const char*)virtual_sensor_node_ptr->name,(const char*)element_node_ptr->name,key.c_str(),value.c_str()); + attr_ptr = attr_ptr->next; + } - //insert attribute to Element - m_virtual_sensor_config[(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name][key]=value; - DBG("<%s><%s \"%s\"=\"%s\">\n",(const char*)virtual_sensor_node_ptr->name,(const char*)element_node_ptr->name,key.c_str(),value.c_str()); - attr_ptr = attr_ptr->next; - } + element_node_ptr = element_node_ptr->next; + } - element_node_ptr = element_node_ptr->next; + DBG("\n"); + virtual_sensor_node_ptr = virtual_sensor_node_ptr->next; } - DBG("\n"); - virtual_sensor_node_ptr = virtual_sensor_node_ptr->next; + device_node_ptr = device_node_ptr->next; } xmlFreeDoc(doc); @@ -144,10 +165,17 @@ bool cvirtual_sensor_config::load_config(const string& config_path) bool cvirtual_sensor_config::get(const string& sensor_type, const string& element, const string& attr, string& value) { - auto it_virtual_sensor_list = m_virtual_sensor_config.find(sensor_type); + auto it_device_list = m_virtual_sensor_config.find(m_device_id); + + if (it_device_list == m_virtual_sensor_config.end()) { + ERR("There is no <%s> device\n",m_device_id.c_str()); + return false; + } + + auto it_virtual_sensor_list = it_device_list->second.find(sensor_type); - if (it_virtual_sensor_list == m_virtual_sensor_config.end()) { - ERR("There is no <%s> element\n",sensor_type.c_str()); + if (it_virtual_sensor_list == it_device_list->second.end()) { + ERR("There is no <%s> sensor\n",sensor_type.c_str()); return false; } @@ -272,9 +300,14 @@ bool cvirtual_sensor_config::get(const string& sensor_type, const string& elemen bool cvirtual_sensor_config::is_supported(const string& sensor_type) { - auto it_virtual_sensor_list = m_virtual_sensor_config.find(sensor_type); + auto it_device_list = m_virtual_sensor_config.find(m_device_id); + + if (it_device_list == m_virtual_sensor_config.end()) + return false; + + auto it_virtual_sensor_list = it_device_list->second.find(sensor_type); - if (it_virtual_sensor_list == m_virtual_sensor_config.end()) + if (it_virtual_sensor_list == it_device_list->second.end()) return false; return true; diff --git a/src/shared/cvirtual_sensor_config.h b/src/shared/cvirtual_sensor_config.h index 7cfbcb6..b3c5f7d 100755 --- a/src/shared/cvirtual_sensor_config.h +++ b/src/shared/cvirtual_sensor_config.h @@ -40,7 +40,7 @@ typedef unordered_map Virtual_sensor; * ... */ -typedef unordered_map Virtual_sensor_config; +typedef unordered_map virtual_sensor_config; /* * a Virtual_sensor_config represents virtual_sensors.xml * @@ -49,6 +49,14 @@ typedef unordered_map Virtual_sensor_config; * */ +typedef unordered_map virtual_sensor_device_config; +/* +* a virtual_sensor_device_config represents virtual_sensors.xml +* +* +* +*/ + class cvirtual_sensor_config : public cconfig { private: @@ -58,7 +66,8 @@ private: bool load_config(const string& config_path); - Virtual_sensor_config m_virtual_sensor_config; + virtual_sensor_device_config m_virtual_sensor_config; + public: static cvirtual_sensor_config& get_instance(void); diff --git a/virtual_sensors.xml.in b/virtual_sensors.xml.in index 680745e..1c20c0d 100644 --- a/virtual_sensors.xml.in +++ b/virtual_sensors.xml.in @@ -1,57 +1,115 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.7.4 From 30340892dbba88cb6705648789fa69b2c3dddff5 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 2 Jan 2015 10:13:05 +0530 Subject: [PATCH 10/16] Adding lock in virtual sensor layer for sensor fusion library - Adding mutex lock in virtual sensor layer to restrict usage and access to sensor fusion library. - adding lock for event driven and polling based calls Change-Id: I2202d046544de4d8474606179a516a5e38b77548 --- src/orientation/orientation_sensor.cpp | 10 ++++++-- src/rotation_vector/rv/rv_sensor.cpp | 42 +++++++++++++++++++++++++++------- src/shared/virtual_sensor.h | 2 ++ 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/orientation/orientation_sensor.cpp b/src/orientation/orientation_sensor.cpp index 7653ef3..02afcd1 100755 --- a/src/orientation/orientation_sensor.cpp +++ b/src/orientation/orientation_sensor.cpp @@ -343,7 +343,10 @@ void orientation_sensor::synthesize(const sensor_event_t &event, vector & int rv_sensor::get_sensor_data(unsigned int data_id, sensor_data_t &data) { - if (data_id != ROTATION_VECTOR_BASE_DATA_SET) - return -1; + sensor_data accel; + sensor_data gyro; + sensor_data magnetic; - data.accuracy = SENSOR_ACCURACY_GOOD; + sensor_data_t accel_data; + sensor_data_t gyro_data; + sensor_data_t magnetic_data; + + quaternion quaternion_orientation; - AUTOLOCK(m_value_mutex); + m_accel_sensor->get_sensor_data(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME, accel_data); + m_gyro_sensor->get_sensor_data(GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME, gyro_data); + m_magnetic_sensor->get_sensor_data(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME, magnetic_data); + + pre_process_data(accel, accel_data.values, m_accel_static_bias, m_accel_rotation_direction_compensation, m_accel_scale); + pre_process_data(gyro, gyro_data.values, m_gyro_static_bias, m_gyro_rotation_direction_compensation, m_gyro_scale); + pre_process_data(magnetic, magnetic_data.values, m_geomagnetic_static_bias, m_geomagnetic_rotation_direction_compensation, m_geomagnetic_scale); + accel.m_time_stamp = accel_data.timestamp; + gyro.m_time_stamp = gyro_data.timestamp; + magnetic.m_time_stamp = magnetic_data.timestamp; + + m_orientation.m_pitch_phase_compensation = m_pitch_rotation_compensation; + m_orientation.m_roll_phase_compensation = m_roll_rotation_compensation; + m_orientation.m_azimuth_phase_compensation = m_azimuth_rotation_compensation; + m_orientation.m_magnetic_alignment_factor = m_magnetic_alignment_factor; + + { + AUTOLOCK(m_fusion_mutex); + quaternion_orientation = m_orientation.get_quaternion(m_accel, m_gyro, m_magnetic); + } + + data.accuracy = SENSOR_ACCURACY_GOOD; data.timestamp = m_time; - data.values[0] = m_x; - data.values[1] = m_y; - data.values[2] = m_z; - data.values[3] = m_w; data.value_count = 4; + data.values[0] = quaternion_orientation.m_quat.m_vec[1]; + data.values[1] = quaternion_orientation.m_quat.m_vec[2]; + data.values[2] = quaternion_orientation.m_quat.m_vec[3]; + data.values[3] = quaternion_orientation.m_quat.m_vec[0]; return 0; } diff --git a/src/shared/virtual_sensor.h b/src/shared/virtual_sensor.h index d592ce6..3cb79fb 100755 --- a/src/shared/virtual_sensor.h +++ b/src/shared/virtual_sensor.h @@ -33,6 +33,8 @@ public: bool is_virtual(void); protected: + cmutex m_fusion_mutex; + bool activate(void); bool deactivate(void); -- 2.7.4 From 55eab417e1a92e1beeaf21065fd957ff8c6d582d Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 2 Jan 2015 10:46:09 +0530 Subject: [PATCH 11/16] Adding Makelist support for virtual sensor configuration - Added xml configuration support for CMakelist - Updated spec file for virtual sensor xml Change-Id: I8b9be20f0f3d4ae728a172237640454e4880de36 --- CMakeLists.txt | 4 ++++ packaging/sensord.spec | 1 + src/libsensord/CMakeLists.txt | 1 + 3 files changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b555de8..edc7d9b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,16 +33,20 @@ ENDIF("${ARCH}" MATCHES "^arm.*") IF("${ARCH}" MATCHES "^arm.*") CONFIGURE_FILE(sensor_plugins.xml.in sensor_plugins.xml @ONLY) CONFIGURE_FILE(sensors.xml.in sensors.xml @ONLY) + CONFIGURE_FILE(virtual_sensors.xml.in virtual_sensors.xml @ONLY) install(FILES sensor_plugins.xml sensors.xml + virtual_sensors.xml DESTINATION etc) ELSE("${ARCH}" MATCHES "^arm.*") CONFIGURE_FILE(sensor_plugins_sim.xml.in sensor_plugins.xml @ONLY) CONFIGURE_FILE(sensors.xml.in sensors.xml @ONLY) + CONFIGURE_FILE(virtual_sensors.xml.in virtual_sensors.xml @ONLY) install(FILES sensor_plugins.xml sensors.xml + virtual_sensors.xml DESTINATION etc) ENDIF("${ARCH}" MATCHES "^arm.*") diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 1d305ff..88d4f71 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -108,6 +108,7 @@ systemctl daemon-reload %{_bindir}/sensord %attr(0644,root,root)/usr/etc/sensor_plugins.xml %attr(0644,root,root)/usr/etc/sensors.xml +%attr(0644,root,root)/usr/etc/virtual_sensors.xml %{_unitdir}/sensord.service %{_unitdir}/sensord.socket %{_unitdir}/multi-user.target.wants/sensord.service diff --git a/src/libsensord/CMakeLists.txt b/src/libsensord/CMakeLists.txt index 6686be2..87dac4e 100755 --- a/src/libsensord/CMakeLists.txt +++ b/src/libsensord/CMakeLists.txt @@ -70,5 +70,6 @@ install(FILES sensor_context.h DESTINATION include/sensor/) install(FILES sensor_gravity.h DESTINATION include/sensor/) install(FILES sensor_linear_accel.h DESTINATION include/sensor/) install(FILES sensor_orientation.h DESTINATION include/sensor/) +install(FILES sensor_rv.h DESTINATION include/sensor/) install(FILES sensor_temperature.h DESTINATION include/sensor/) install(FILES ${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) -- 2.7.4 From 806a06b231d2c3072772a0354fc34aca17082a60 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 2 Jan 2015 11:31:45 +0530 Subject: [PATCH 12/16] Updated sensor framework common files for RV sensor - Updated sensor_common.h file for RV sensor - Updated client_common.cpp file for RV sensor Change-Id: I8c246a45b5ea99a4ae46837115842b3fe1240d40 --- src/libsensord/client_common.cpp | 3 +++ src/shared/sensor_common.h | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libsensord/client_common.cpp b/src/libsensord/client_common.cpp index 24932bb..dcf85d4 100755 --- a/src/libsensord/client_common.cpp +++ b/src/libsensord/client_common.cpp @@ -39,6 +39,7 @@ log_element g_log_elements[] = { FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, LINEAR_ACCEL_SENSOR, 0, 1), FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ORIENTATION_SENSOR, 0, 1), FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, TEMPERATURE_SENSOR, 0, 1), + FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ROTATION_VECTOR_SENSOR, 0, 1), FILL_LOG_ELEMENT(LOG_ID_EVENT, GEOMAGNETIC_EVENT_CALIBRATION_NEEDED, 0, 1), FILL_LOG_ELEMENT(LOG_ID_EVENT, PROXIMITY_EVENT_CHANGE_STATE, 0,1), @@ -59,6 +60,7 @@ log_element g_log_elements[] = { FILL_LOG_ELEMENT(LOG_ID_EVENT, ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME, 0, 10), FILL_LOG_ELEMENT(LOG_ID_EVENT, PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME, 0, 10), FILL_LOG_ELEMENT(LOG_ID_EVENT, TEMPERATURE_EVENT_RAW_DATA_REPORT_ON_TIME, 0, 10), + FILL_LOG_ELEMENT(LOG_ID_EVENT, ROTATION_VECTOR_EVENT_RAW_DATA_REPORT_ON_TIME, 0, 10), FILL_LOG_ELEMENT(LOG_ID_DATA, ACCELEROMETER_BASE_DATA_SET, 0, 25), FILL_LOG_ELEMENT(LOG_ID_DATA, GYRO_BASE_DATA_SET, 0, 25), @@ -74,6 +76,7 @@ log_element g_log_elements[] = { FILL_LOG_ELEMENT(LOG_ID_DATA, ORIENTATION_BASE_DATA_SET, 0, 25), FILL_LOG_ELEMENT(LOG_ID_DATA, PRESSURE_BASE_DATA_SET, 0, 25), FILL_LOG_ELEMENT(LOG_ID_DATA, TEMPERATURE_BASE_DATA_SET, 0, 25), + FILL_LOG_ELEMENT(LOG_ID_DATA, ROTATION_VECTOR_BASE_DATA_SET, 0, 25), }; typedef unordered_map log_map; diff --git a/src/shared/sensor_common.h b/src/shared/sensor_common.h index c819197..cfecead 100755 --- a/src/shared/sensor_common.h +++ b/src/shared/sensor_common.h @@ -55,7 +55,8 @@ typedef enum { GRAVITY_SENSOR, LINEAR_ACCEL_SENSOR, ORIENTATION_SENSOR, - TEMPERATURE_SENSOR + TEMPERATURE_SENSOR, + ROTATION_VECTOR_SENSOR } sensor_type_t; typedef unsigned int sensor_id_t; -- 2.7.4 From 999f1b7ac14682a3d8654b6be3f91d999021c8b7 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 2 Jan 2015 12:02:53 +0530 Subject: [PATCH 13/16] Adding missing sensor_rv.h file - Adding missing sensor_rv.h from local machine to repository to avoid compiler errors. Change-Id: I679ba00b31ca07a799ad0c8b4fc0b7753c02bb47 --- src/libsensord/sensor_rv.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/libsensord/sensor_rv.h diff --git a/src/libsensord/sensor_rv.h b/src/libsensord/sensor_rv.h new file mode 100644 index 0000000..cad7977 --- /dev/null +++ b/src/libsensord/sensor_rv.h @@ -0,0 +1,58 @@ +/* + * libsensord + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __SENSOR_ROTATION_VECTOR_H__ +#define __SENSOR_ROTATION_VECTOR_H__ + +//! Pre-defined events for the rotation vector sensor +//! Sensor Plugin developer can add more event to their own headers + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @defgroup SENSOR_RV Rotation Vector Sensor + * @ingroup SENSOR_FRAMEWORK + * + * These APIs are used to control the Rotation Vector sensor. + * @{ + */ + +enum rot_data_id { + ROTATION_VECTOR_BASE_DATA_SET = (ROTATION_VECTOR_SENSOR << 16) | 0x0001, +}; + +enum rot_event_type { + ROTATION_VECTOR_EVENT_RAW_DATA_REPORT_ON_TIME = (ROTATION_VECTOR_SENSOR << 16) | 0x0001, + ROTATION_VECTOR_EVENT_CALIBRATION_NEEDED = (ROTATION_VECTOR_SENSOR << 16) | 0x0002, +}; + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif +//! End of a file + -- 2.7.4 From 2a4525b35cbeb686d3dec5b0316d0efbdec1a1ef Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 2 Jan 2015 14:09:39 +0530 Subject: [PATCH 14/16] Adding test case for rotation_vector sensor - Adding test case for rotation vector sensor - updated spec and cmake files for new test case Change-Id: I9fd81a5d05c07f2f3ed0be0b7165f8a11a782ab6 --- packaging/sensord.spec | 1 + test/CMakeLists.txt | 4 ++ test/src/rotation_vector.c | 143 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 test/src/rotation_vector.c diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 88d4f71..7fed2e6 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -148,6 +148,7 @@ systemctl daemon-reload /usr/bin/pressure /usr/bin/temperature /usr/bin/light +/usr/bin/rotation_vector %license LICENSE.APLv2 %{_datadir}/license/test diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3c103cc..ff215c3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -37,6 +37,7 @@ add_executable(proxi src/proxi.c) add_executable(pressure src/pressure.c) add_executable(temperature src/temperature.c) add_executable(light src/light.c) +add_executable(rotation_vector src/rotation_vector.c) SET_TARGET_PROPERTIES(accelerometer PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(geomagnetic PROPERTIES LINKER_LANGUAGE C) @@ -48,6 +49,7 @@ SET_TARGET_PROPERTIES(proxi PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(pressure PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(temperature PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(light PROPERTIES LINKER_LANGUAGE C) +SET_TARGET_PROPERTIES(rotation_vector PROPERTIES LINKER_LANGUAGE C) target_link_libraries(accelerometer glib-2.0 dlog sensor) target_link_libraries(geomagnetic glib-2.0 dlog sensor) @@ -59,6 +61,7 @@ target_link_libraries(proxi glib-2.0 dlog sensor) target_link_libraries(pressure glib-2.0 dlog sensor) target_link_libraries(temperature glib-2.0 dlog sensor) target_link_libraries(light glib-2.0 dlog sensor) +target_link_libraries(rotation_vector glib-2.0 dlog sensor) INSTALL(TARGETS accelerometer DESTINATION /usr/bin/) INSTALL(TARGETS geomagnetic DESTINATION /usr/bin/) @@ -70,4 +73,5 @@ INSTALL(TARGETS proxi DESTINATION /usr/bin/) INSTALL(TARGETS pressure DESTINATION /usr/bin/) INSTALL(TARGETS temperature DESTINATION /usr/bin/) INSTALL(TARGETS light DESTINATION /usr/bin/) +INSTALL(TARGETS rotation_vector DESTINATION /usr/bin/) diff --git a/test/src/rotation_vector.c b/test/src/rotation_vector.c new file mode 100644 index 0000000..093b828 --- /dev/null +++ b/test/src/rotation_vector.c @@ -0,0 +1,143 @@ +/* + * sensord + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include + +static GMainLoop *mainloop; + +void callback(unsigned int event_type, sensor_event_data_t *event, void *user_data) +{ + sensor_data_t *data = (sensor_data_t *)event->event_data; + printf("Rotation Vector [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data->timestamp, data->values[0], + data->values[1], data->values[2]); +} + +void printformat() +{ + printf("Usage : ./rotation_vector (optional) (optional)\n\n"); + + printf("mode:"); + printf("[-p]\n"); + printf("p is for polling based,default mode is event driven\n"); + + printf("event:"); + printf("[RAW_DATA_REPORT_ON_TIME]\n"); + + printf("interval:\n"); + printf("The time interval should be entered based on the sampling frequencies supported by " + "accelerometer, gyroscope and geomagnetic sensors driver on the device in ms. If " + "no value for rotation vector sensor is entered, a default value will be used.\n"); +} + +int main(int argc,char **argv) +{ + int result, handle, start_handle, stop_handle; + unsigned int event; + mainloop = g_main_loop_new(NULL, FALSE); + event = ROTATION_VECTOR_EVENT_RAW_DATA_REPORT_ON_TIME; + event_condition_t *event_condition = (event_condition_t*) malloc(sizeof(event_condition_t)); + event_condition->cond_op = CONDITION_EQUAL; + + sensor_type_t type = ROTATION_VECTOR_SENSOR; + + if (argc != 2 && argc != 3 && argc!=4) { + printformat(); + free(event_condition); + return 0; + } + + else if (argc>=3 && strcmp(argv[1], "-p") == 0 && strcmp(argv[2], "RAW_DATA_REPORT_ON_TIME") == 0) { + printf("Polling based\n"); + handle = sf_connect(type); + result = sf_start(handle, 1); + + if (result < 0) { + printf("Can't start Rotation Vector SENSOR\n"); + printf("Error\n\n\n\n"); + return -1; + } + + sensor_data_t data; + + while(1) { + result = sf_get_data(handle, ACCELEROMETER_BASE_DATA_SET , &data); + printf("Rotation Vector [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); + usleep(100000); + } + + result = sf_disconnect(handle); + + if (result < 0) { + printf("Can't disconnect ROTATION VECTOR sensor\n"); + printf("Error\n\n\n\n"); + return -1; + } + } + + else if (strcmp(argv[1], "RAW_DATA_REPORT_ON_TIME") == 0) { + printf("Event based\n"); + + event_condition->cond_value1 = 100; + if (argc == 3) + event_condition->cond_value1 = atof(argv[2]); + + handle = sf_connect(type); + result = sf_register_event(handle, event, event_condition, callback, NULL); + + if (result < 0) + printf("Can't register rotation vector event\n"); + + start_handle = sf_start(handle,0); + + if (start_handle < 0) { + printf("Error\n\n\n\n"); + sf_unregister_event(handle, event); + sf_disconnect(handle); + return -1; + } + + g_main_loop_run(mainloop); + g_main_loop_unref(mainloop); + + sf_unregister_event(handle, event); + + stop_handle = sf_stop(handle); + + if (stop_handle < 0) { + printf("Error\n\n"); + return -1; + } + + sf_disconnect(handle); + free(event_condition); + } + + else { + printformat(); + } + + return 0; +} + -- 2.7.4 From b272c33e00270c2fb57afaa58a4cde4505f8fb0e Mon Sep 17 00:00:00 2001 From: Kibak Yoon Date: Thu, 18 Dec 2014 21:27:11 +0900 Subject: [PATCH 15/16] sensord: update for being the compatible with the x32 and x64 * replaced "/usr/lib" by %{_libdir} * replaced "/usr/include" by %{_includedir} refered from the below url: https://wiki.tizen.org/wiki/HOW-TO_Build_a_Tizen_distribution_for_x64_arch Signed-off-by: Kibak Yoon Change-Id: I4c57f6ec79754aa20cd103d34e6a00ebfffff42c --- CMakeLists.txt | 2 -- packaging/sensord.spec | 3 ++- src/CMakeLists.txt | 2 -- src/accel/CMakeLists.txt | 6 ++--- src/geo/CMakeLists.txt | 6 ++--- src/gravity/CMakeLists.txt | 3 +-- src/gyro/CMakeLists.txt | 6 ++--- src/libsensord/CMakeLists.txt | 48 +++++++++++++++++++--------------------- src/light/CMakeLists.txt | 6 ++--- src/linear_accel/CMakeLists.txt | 3 +-- src/orientation/CMakeLists.txt | 3 +-- src/pressure/CMakeLists.txt | 6 ++--- src/proxi/CMakeLists.txt | 6 ++--- src/sensor_fusion/CMakeLists.txt | 3 +-- src/shared/CMakeLists.txt | 14 +++++------- src/temperature/CMakeLists.txt | 6 ++--- test/CMakeLists.txt | 2 -- test/sensor-tc.pc | 2 +- 18 files changed, 50 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index edc7d9b..5381991 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,6 @@ add_definitions(${rpkgs_CFLAGS}) # to install pkgconfig setup file. SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) set(PROJECT_MAJOR_VERSION "0") diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 7fed2e6..86e131e 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -81,7 +81,8 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DACCEL=%{accel_state} \ -DGEO=%{geo_state} -DPRESSURE=%{pressure_state} -DTEMPERATURE=%{temperature_state} \ -DORIENTATION=%{orientation_state} -DGRAVITY=%{gravity_state} \ -DLINEAR_ACCEL=%{linear_accel_state} -DRV=%{rv_state} \ - -DTEST_SUITE=%{build_test_suite} + -DTEST_SUITE=%{build_test_suite} \ + -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir} make %{?jobs:-j%jobs} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a55315..ff35867 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,8 +3,6 @@ project(sensord_src CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) include_directories(${CMAKE_SOURCE_DIR}/src/shared) diff --git a/src/accel/CMakeLists.txt b/src/accel/CMakeLists.txt index 56e9119..948d42a 100755 --- a/src/accel/CMakeLists.txt +++ b/src/accel/CMakeLists.txt @@ -3,8 +3,6 @@ project(accel CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) SET(SENSOR_NAME accel_sensor) @@ -48,5 +46,5 @@ add_library(${SENSOR_HAL_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") target_link_libraries(${SENSOR_HAL_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS}) -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) -install(TARGETS ${SENSOR_HAL_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) +install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/geo/CMakeLists.txt b/src/geo/CMakeLists.txt index d011093..e089fbe 100755 --- a/src/geo/CMakeLists.txt +++ b/src/geo/CMakeLists.txt @@ -3,8 +3,6 @@ project(geo CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) SET(SENSOR_NAME geo_sensor) @@ -49,5 +47,5 @@ add_library(${SENSOR_HAL_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") target_link_libraries(${SENSOR_HAL_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS}) -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) -install(TARGETS ${SENSOR_HAL_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) +install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/gravity/CMakeLists.txt b/src/gravity/CMakeLists.txt index 466f54b..42cf604 100755 --- a/src/gravity/CMakeLists.txt +++ b/src/gravity/CMakeLists.txt @@ -3,7 +3,6 @@ project(gravity CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") SET(VERSION 1.0) SET(SENSOR_NAME gravity_sensor) @@ -40,4 +39,4 @@ add_library(${SENSOR_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/gyro/CMakeLists.txt b/src/gyro/CMakeLists.txt index afef9f0..b8af818 100755 --- a/src/gyro/CMakeLists.txt +++ b/src/gyro/CMakeLists.txt @@ -3,8 +3,6 @@ project(gyro CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) SET(SENSOR_NAME gyro_sensor) @@ -48,5 +46,5 @@ add_library(${SENSOR_HAL_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") target_link_libraries(${SENSOR_HAL_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS}) -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) -install(TARGETS ${SENSOR_HAL_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) +install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/libsensord/CMakeLists.txt b/src/libsensord/CMakeLists.txt index 87dac4e..6eccd7b 100755 --- a/src/libsensord/CMakeLists.txt +++ b/src/libsensord/CMakeLists.txt @@ -4,8 +4,6 @@ project(sensor CXX) # to install pkgconfig setup file. SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION_MAJOR 1) SET(VERSION "${VERSION_MAJOR}.1.0") @@ -49,27 +47,27 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) configure_file(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY) -#install(DIRECTORY include/ DESTINATION include/ FILES_MATCHING PATTERN "*.h") -install(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries) +#install(DIRECTORY include/ DESTINATION ${INCLUDEDIR} FILES_MATCHING PATTERN "*.h") +install(TARGETS ${PROJECT_NAME} DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries) -install(FILES sensor_internal_deprecated.h DESTINATION include/sensor/) -install(FILES sensor_internal.h DESTINATION include/sensor/) -install(FILES poller.h DESTINATION include/sensor/) -install(FILES creg_event_info.h DESTINATION include/sensor/) -install(FILES csensor_event_listener.h DESTINATION include/sensor/) -install(FILES sensor_info_manager.h DESTINATION include/sensor/) -install(FILES csensor_handle_info.h DESTINATION include/sensor/) -install(FILES client_common.h DESTINATION include/sensor/) -install(FILES sensor_accel.h DESTINATION include/sensor/) -install(FILES sensor_geomag.h DESTINATION include/sensor/) -install(FILES sensor_light.h DESTINATION include/sensor/) -install(FILES sensor_proxi.h DESTINATION include/sensor/) -install(FILES sensor_gyro.h DESTINATION include/sensor/) -install(FILES sensor_pressure.h DESTINATION include/sensor/) -install(FILES sensor_context.h DESTINATION include/sensor/) -install(FILES sensor_gravity.h DESTINATION include/sensor/) -install(FILES sensor_linear_accel.h DESTINATION include/sensor/) -install(FILES sensor_orientation.h DESTINATION include/sensor/) -install(FILES sensor_rv.h DESTINATION include/sensor/) -install(FILES sensor_temperature.h DESTINATION include/sensor/) -install(FILES ${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) +install(FILES sensor_internal_deprecated.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_internal.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES poller.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES creg_event_info.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES csensor_event_listener.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_info_manager.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES csensor_handle_info.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES client_common.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_accel.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_geomag.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_light.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_proxi.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_gyro.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_pressure.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_context.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_gravity.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_linear_accel.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_orientation.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_rv.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES sensor_temperature.h DESTINATION ${INCLUDEDIR}/sensor/) +install(FILES ${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) diff --git a/src/light/CMakeLists.txt b/src/light/CMakeLists.txt index e32223b..ca8cd53 100755 --- a/src/light/CMakeLists.txt +++ b/src/light/CMakeLists.txt @@ -3,8 +3,6 @@ project(light CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) SET(SENSOR_NAME light_sensor) @@ -49,5 +47,5 @@ add_library(${SENSOR_HAL_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") target_link_libraries(${SENSOR_HAL_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS}) -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) -install(TARGETS ${SENSOR_HAL_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) +install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/linear_accel/CMakeLists.txt b/src/linear_accel/CMakeLists.txt index 6601d90..2295b67 100755 --- a/src/linear_accel/CMakeLists.txt +++ b/src/linear_accel/CMakeLists.txt @@ -3,7 +3,6 @@ project(linear_accel CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") SET(VERSION 1.0) SET(SENSOR_NAME linear_accel_sensor) @@ -42,4 +41,4 @@ add_library(${SENSOR_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/orientation/CMakeLists.txt b/src/orientation/CMakeLists.txt index 2ef7592..0896f56 100755 --- a/src/orientation/CMakeLists.txt +++ b/src/orientation/CMakeLists.txt @@ -3,7 +3,6 @@ project(orientation CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") SET(VERSION 1.0) SET(SENSOR_NAME orientation_sensor) @@ -42,4 +41,4 @@ add_library(${SENSOR_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/pressure/CMakeLists.txt b/src/pressure/CMakeLists.txt index ea13698..090d748 100755 --- a/src/pressure/CMakeLists.txt +++ b/src/pressure/CMakeLists.txt @@ -3,8 +3,6 @@ project(pressure CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) SET(SENSOR_NAME pressure_sensor) @@ -49,5 +47,5 @@ add_library(${SENSOR_HAL_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") target_link_libraries(${SENSOR_HAL_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS}) -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) -install(TARGETS ${SENSOR_HAL_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) +install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/proxi/CMakeLists.txt b/src/proxi/CMakeLists.txt index f679e41..d41eb8d 100755 --- a/src/proxi/CMakeLists.txt +++ b/src/proxi/CMakeLists.txt @@ -3,8 +3,6 @@ project(proxi CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) SET(SENSOR_NAME proxi_sensor) @@ -49,5 +47,5 @@ add_library(${SENSOR_HAL_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") target_link_libraries(${SENSOR_HAL_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS}) -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) -install(TARGETS ${SENSOR_HAL_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) +install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/sensor_fusion/CMakeLists.txt b/src/sensor_fusion/CMakeLists.txt index da05d86..0a753db 100755 --- a/src/sensor_fusion/CMakeLists.txt +++ b/src/sensor_fusion/CMakeLists.txt @@ -3,7 +3,6 @@ project(sensor_fusion CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") SET(VERSION 1.0) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) @@ -46,4 +45,4 @@ add_library(${SENSOR_FUSION_NAME} SHARED target_link_libraries(${SENSOR_FUSION_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") -install(TARGETS ${SENSOR_FUSION_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_FUSION_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 2653782..8c5d1c8 100755 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -3,8 +3,6 @@ project(sf_common CXX) # to install pkgconfig setup file. SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) #set(CMAKE_INSTALL_PREFIX "$ENV{DATAFS}") @@ -69,10 +67,10 @@ target_link_libraries(sensord-share ${rpkgs_LDFLAGS} "-lrt -ldl -pthread") configure_file(sensord-server.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/sensord-server.pc @ONLY) configure_file(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY) -install(TARGETS sensord-server DESTINATION lib) -install(TARGETS sensord-share DESTINATION lib) -install(FILES sensord-server.pc DESTINATION lib/pkgconfig) -install(FILES ${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) +install(TARGETS sensord-server DESTINATION ${LIBDIR}) +install(TARGETS sensord-share DESTINATION ${LIBDIR}) +install(FILES sensord-server.pc DESTINATION ${LIBDIR}/pkgconfig) +install(FILES ${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) install(FILES crw_lock.h worker_thread.h @@ -94,11 +92,11 @@ install(FILES common.h sensor_info.h iio_common.h - DESTINATION include/${PROJECT_NAME} + DESTINATION ${INCLUDEDIR}/${PROJECT_NAME} ) install(FILES sensor_common.h - DESTINATION include/sensor + DESTINATION ${INCLUDEDIR}/sensor ) diff --git a/src/temperature/CMakeLists.txt b/src/temperature/CMakeLists.txt index b8b8392..f67773e 100755 --- a/src/temperature/CMakeLists.txt +++ b/src/temperature/CMakeLists.txt @@ -3,8 +3,6 @@ project(temperature CXX) # to install pkgconfig setup file. SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) SET(SENSOR_NAME temperature_sensor) @@ -49,5 +47,5 @@ add_library(${SENSOR_HAL_NAME} SHARED target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") target_link_libraries(${SENSOR_HAL_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS}) -install(TARGETS ${SENSOR_NAME} DESTINATION lib/sensord) -install(TARGETS ${SENSOR_HAL_NAME} DESTINATION lib/sensord) +install(TARGETS ${SENSOR_NAME} DESTINATION ${LIBDIR}/sensord) +install(TARGETS ${SENSOR_HAL_NAME} DESTINATION ${LIBDIR}/sensord) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ff215c3..6fb5085 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,8 +3,6 @@ project(sensor-tc C) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") -SET(LIBDIR "\${prefix}/lib") -SET(INCLUDEDIR "\${prefix}/include") SET(VERSION 1.0) INCLUDE(FindPkgConfig) diff --git a/test/sensor-tc.pc b/test/sensor-tc.pc index 33b2994..c8c0d3c 100644 --- a/test/sensor-tc.pc +++ b/test/sensor-tc.pc @@ -2,7 +2,7 @@ prefix=/usr/bin exec_prefix=${prefix} -libdir=${prefix}/lib +libdir=${prefix}/${_libdir} includedir=${prefix}/include/sensor-tc Name: sensor-tc -- 2.7.4 From d18a17b19127c78c9fdcf6aa0d1d244913443a8d Mon Sep 17 00:00:00 2001 From: Kibak Yoon Date: Mon, 5 Jan 2015 23:57:27 +0900 Subject: [PATCH 16/16] sensord: add sensor api for avoiding build break Signed-off-by: Kibak Yoon Change-Id: Icb6934702fcef2c10e72c513d682caa1ed08c21e --- src/libsensord/CMakeLists.txt | 1 + src/libsensord/client.cpp | 7 +++++++ src/libsensord/sensor.h | 25 +++++++++++++++++++++++++ src/libsensord/sensor_internal_deprecated.h | 16 ++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100755 src/libsensord/sensor.h diff --git a/src/libsensord/CMakeLists.txt b/src/libsensord/CMakeLists.txt index 6eccd7b..50550ee 100755 --- a/src/libsensord/CMakeLists.txt +++ b/src/libsensord/CMakeLists.txt @@ -50,6 +50,7 @@ configure_file(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME} #install(DIRECTORY include/ DESTINATION ${INCLUDEDIR} FILES_MATCHING PATTERN "*.h") install(TARGETS ${PROJECT_NAME} DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries) +install(FILES sensor.h DESTINATION ${INCLUDEDIR}/sensor/) install(FILES sensor_internal_deprecated.h DESTINATION ${INCLUDEDIR}/sensor/) install(FILES sensor_internal.h DESTINATION ${INCLUDEDIR}/sensor/) install(FILES poller.h DESTINATION ${INCLUDEDIR}/sensor/) diff --git a/src/libsensord/client.cpp b/src/libsensord/client.cpp index de31c85..3132921 100755 --- a/src/libsensord/client.cpp +++ b/src/libsensord/client.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -381,6 +382,12 @@ API int sf_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data return sensord_get_data(handle, data_id, sensor_data) ? OP_SUCCESS : OP_ERROR; } +API int sf_check_rotation(unsigned long *rotation) +{ + rotation = 0; + return 0; +} + static bool get_sensor_list(void) { static cmutex l; diff --git a/src/libsensord/sensor.h b/src/libsensord/sensor.h new file mode 100755 index 0000000..2885a01 --- /dev/null +++ b/src/libsensord/sensor.h @@ -0,0 +1,25 @@ +/* + * libsensord + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __SENSOR_IN_H__ +#define __SENSOR_IN_H__ + +#include + +#endif diff --git a/src/libsensord/sensor_internal_deprecated.h b/src/libsensord/sensor_internal_deprecated.h index dc4a8b3..c2fab32 100755 --- a/src/libsensord/sensor_internal_deprecated.h +++ b/src/libsensord/sensor_internal_deprecated.h @@ -69,6 +69,22 @@ typedef struct { int z; } sensor_panning_data_t; +#define ACCELEROMETER_EVENT_ROTATION_CHECK ((ACCELEROMETER_SENSOR << 16) | 0x0001) + +enum accelerometer_rotate_state { + ROTATION_UNKNOWN = 0, + ROTATION_LANDSCAPE_LEFT = 1, + ROTATION_PORTRAIT_TOP = 2, + ROTATION_PORTRAIT_BTM = 3, + ROTATION_LANDSCAPE_RIGHT = 4, + ROTATION_EVENT_0 = 2, + ROTATION_EVENT_90 = 1, + ROTATION_EVENT_180 = 3, + ROTATION_EVENT_270 = 4, +}; + +int sf_check_rotation(unsigned long *rotation); + /** * @fn int sf_connect(sensor_type_t sensor) * @brief This API connects a sensor type to respective sensor. The application calls with the type of the sensor (ex. ACCELEROMETER_SENSOR) and on basis of that server takes decision of which plug-in to be connected. Once sensor connected application can proceed for data processing. This API returns a positive handle which should be used by application to communicate on sensor type. -- 2.7.4