From 06486f2ad6268befa509b85cd36e3f32efa13c6e Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Wed, 19 Nov 2014 16:39:32 +0530 Subject: [PATCH 01/16] Updating sensor fusion library based on testing on Tizen SDK Updating sensor fusion library based on testing sensor fusion solution on Tizen SDK using emulator event injector inputs. Change-Id: I80179399aaa3a0b27cafdf0792c57443a098a067 --- src/sensor_fusion/euler_angles.cpp | 6 ++-- src/sensor_fusion/euler_angles.h | 2 +- src/sensor_fusion/orientation_filter.cpp | 35 +++++++++++++--------- src/sensor_fusion/orientation_filter.h | 4 +-- src/sensor_fusion/quaternion.cpp | 28 +++++++++++++++++ src/sensor_fusion/quaternion.h | 2 ++ src/sensor_fusion/standalone/gravity_sensor.cpp | 2 +- .../standalone/linear_acceleration_sensor.cpp | 2 +- .../standalone/orientation_sensor.cpp | 8 ++--- .../orientation_filter_main.cpp | 4 +-- 10 files changed, 65 insertions(+), 28 deletions(-) diff --git a/src/sensor_fusion/euler_angles.cpp b/src/sensor_fusion/euler_angles.cpp index 1ecce95..9189e6a 100644 --- a/src/sensor_fusion/euler_angles.cpp +++ b/src/sensor_fusion/euler_angles.cpp @@ -30,9 +30,9 @@ euler_angles::euler_angles() : m_ang(EULER_SIZE) } template -euler_angles::euler_angles(const TYPE roll, const TYPE pitch, const TYPE yaw) +euler_angles::euler_angles(const TYPE roll, const TYPE pitch, const TYPE azimuth) { - TYPE euler_data[EULER_SIZE] = {roll, pitch, yaw}; + TYPE euler_data[EULER_SIZE] = {roll, pitch, azimuth}; vect v(EULER_SIZE, euler_data); m_ang = v; @@ -83,7 +83,7 @@ euler_angles quat2euler(const quaternion q) R33 = 2 * (w * w) - 1 + 2 * (z * z); phi = atan2(R32, R33); - theta = -atan(R31 / sqrt(1 - (R31 * R31))); + theta = atan2(-R31 , sqrt((R32 * R32) + (R33 * R33))); psi = atan2(R21, R11); euler_angles e(phi, theta, psi); diff --git a/src/sensor_fusion/euler_angles.h b/src/sensor_fusion/euler_angles.h index 35d8abb..9c5af06 100644 --- a/src/sensor_fusion/euler_angles.h +++ b/src/sensor_fusion/euler_angles.h @@ -29,7 +29,7 @@ public: vect m_ang; euler_angles(); - euler_angles(const TYPE roll, const TYPE pitch, const TYPE yaw); + euler_angles(const TYPE roll, const TYPE pitch, const TYPE azimuth); euler_angles(const vect v); euler_angles(const euler_angles& e); ~euler_angles(); diff --git a/src/sensor_fusion/orientation_filter.cpp b/src/sensor_fusion/orientation_filter.cpp index 7d0cc5a..14058a6 100644 --- a/src/sensor_fusion/orientation_filter.cpp +++ b/src/sensor_fusion/orientation_filter.cpp @@ -22,18 +22,25 @@ #include "orientation_filter.h" +//Windowing is used for buffering of previous samples for statistical analysis #define MOVING_AVERAGE_WINDOW_LENGTH 20 +//Earth's Gravity #define GRAVITY 9.80665 #define PI 3.141593 +//Needed for non-zero initialization for statistical analysis #define NON_ZERO_VAL 0.1 +//microseconds to seconds #define US2S (1.0 / 1000000.0) -#define SAMPLE_FREQ 100000 +//Initialize sampling interval to 100000microseconds +#define SAMPLE_INTV 100000 +// constants for computation of covariance and transition matrices #define ZIGMA_W (0.05 * DEG2RAD) #define TAU_W 1000 #define QWB_CONST ((2 * (ZIGMA_W * ZIGMA_W)) / TAU_W) #define F_CONST (-1 / TAU_W) +// M-matrix, V-vector, MxN=> matrix dimension, R-RowCount, C-Column count #define M3X3R 3 #define M3X3C 3 #define M6X6R 6 @@ -59,7 +66,7 @@ orientation_filter::orientation_filter() m_var_gyr_z = vec; m_var_roll = vec; m_var_pitch = vec; - m_var_yaw = vec; + m_var_azimuth = vec; m_tran_mat = mat6x6; m_measure_mat = mat6x6; @@ -74,7 +81,7 @@ orientation_filter::orientation_filter() m_pitch_phase_compensation = 1; m_roll_phase_compensation = 1; - m_yaw_phase_compensation = 1; + m_azimuth_phase_compensation = 1; m_magnetic_alignment_factor = 1; m_gyro.m_time_stamp = 0; @@ -91,7 +98,7 @@ inline void orientation_filter::initialize_sensor_data(const sensor_data acc_data(V1x3S); vect gyr_data(V1x3S); - unsigned long long sample_interval_gyro = SAMPLE_FREQ; + unsigned long long sample_interval_gyro = SAMPLE_INTV; m_accel.m_data = accel.m_data; m_gyro.m_data = gyro.m_data; @@ -147,21 +154,21 @@ template inline void orientation_filter::compute_covariance() { TYPE var_gyr_x, var_gyr_y, var_gyr_z; - TYPE var_roll, var_pitch, var_yaw; + TYPE var_roll, var_pitch, var_azimuth; insert_end(m_var_gyr_x, m_gyro.m_data.m_vec[0]); insert_end(m_var_gyr_y, m_gyro.m_data.m_vec[1]); insert_end(m_var_gyr_z, m_gyro.m_data.m_vec[2]); insert_end(m_var_roll, m_orientation.m_ang.m_vec[0]); insert_end(m_var_pitch, m_orientation.m_ang.m_vec[1]); - insert_end(m_var_yaw, m_orientation.m_ang.m_vec[2]); + insert_end(m_var_azimuth, m_orientation.m_ang.m_vec[2]); var_gyr_x = var(m_var_gyr_x); var_gyr_y = var(m_var_gyr_y); var_gyr_z = var(m_var_gyr_z); var_roll = var(m_var_roll); var_pitch = var(m_var_pitch); - var_yaw = var(m_var_yaw); + var_azimuth = var(m_var_azimuth); m_driv_cov.m_mat[0][0] = var_gyr_x; m_driv_cov.m_mat[1][1] = var_gyr_y; @@ -172,13 +179,13 @@ inline void orientation_filter::compute_covariance() m_aid_cov.m_mat[0][0] = var_roll; m_aid_cov.m_mat[1][1] = var_pitch; - m_aid_cov.m_mat[2][2] = var_yaw; + m_aid_cov.m_mat[2][2] = var_azimuth; } template inline void orientation_filter::time_update() { - quaternion quat_diff, quat_error; + quaternion quat_diff, quat_error, quat_output; euler_angles euler_error; euler_angles orientation; @@ -210,14 +217,14 @@ inline void orientation_filter::time_update() quat_diff = (m_quat_driv * quat_rot_inc) * (TYPE) 0.5; m_quat_driv = m_quat_driv + (quat_diff * (TYPE) m_gyro_dt * (TYPE) PI); - m_quat_driv.quat_normalize(); + quat_output = phase_correction(m_quat_driv, m_quat_aid); - orientation = quat2euler(m_quat_driv); + orientation = rad2deg(quat2euler(quat_output)); - m_orientation.m_ang.m_vec[0] = orientation.m_ang.m_vec[0] * m_roll_phase_compensation; - m_orientation.m_ang.m_vec[1] = orientation.m_ang.m_vec[1] * m_pitch_phase_compensation; - m_orientation.m_ang.m_vec[2] = orientation.m_ang.m_vec[2] * m_yaw_phase_compensation; + m_orientation.m_ang.m_vec[0] = orientation.m_ang.m_vec[0] * m_pitch_phase_compensation; + m_orientation.m_ang.m_vec[1] = orientation.m_ang.m_vec[1] * m_roll_phase_compensation; + m_orientation.m_ang.m_vec[2] = orientation.m_ang.m_vec[2] * m_azimuth_phase_compensation; m_rot_matrix = quat2rot_mat(m_quat_driv); diff --git a/src/sensor_fusion/orientation_filter.h b/src/sensor_fusion/orientation_filter.h index 02ece6f..f7bc4d7 100644 --- a/src/sensor_fusion/orientation_filter.h +++ b/src/sensor_fusion/orientation_filter.h @@ -38,7 +38,7 @@ public: vect m_var_gyr_z; vect m_var_roll; vect m_var_pitch; - vect m_var_yaw; + vect m_var_azimuth; matrix m_driv_cov; matrix m_aid_cov; matrix m_tran_mat; @@ -56,7 +56,7 @@ public: int m_pitch_phase_compensation; int m_roll_phase_compensation; - int m_yaw_phase_compensation; + int m_azimuth_phase_compensation; int m_magnetic_alignment_factor; orientation_filter(); diff --git a/src/sensor_fusion/quaternion.cpp b/src/sensor_fusion/quaternion.cpp index 7272012..55da0db 100755 --- a/src/sensor_fusion/quaternion.cpp +++ b/src/sensor_fusion/quaternion.cpp @@ -23,6 +23,20 @@ #define QUAT_SIZE 4 +template int sgn(T val) { + if (val >= 0) + return 1; + else + return -1; +} + +template T mag(T val) { + if (val < 0) + return val * (T)-1; + else + return val; +} + template quaternion::quaternion() : m_quat(QUAT_SIZE) { @@ -117,4 +131,18 @@ quaternion operator +(const quaternion q1, const quaternion q2) return (q1.m_quat + q2.m_quat); } + +template +quaternion phase_correction(const quaternion q1, const quaternion q2) +{ + T w, x, y, z; + w = mag(q1.m_quat.m_vec[0]) * sgn(q2.m_quat.m_vec[0]); + x = mag(q1.m_quat.m_vec[1]) * sgn(q2.m_quat.m_vec[1]); + y = mag(q1.m_quat.m_vec[2]) * sgn(q2.m_quat.m_vec[2]); + z = mag(q1.m_quat.m_vec[3]) * sgn(q2.m_quat.m_vec[3]); + + quaternion q(w, x, y, z); + + return q; +} #endif //_QUATERNION_H_ diff --git a/src/sensor_fusion/quaternion.h b/src/sensor_fusion/quaternion.h index 44eaa58..225b129 100755 --- a/src/sensor_fusion/quaternion.h +++ b/src/sensor_fusion/quaternion.h @@ -42,6 +42,8 @@ public: const quaternion q2); template friend quaternion operator +(const quaternion q1, const quaternion q2); + template friend quaternion phase_correction(const quaternion q1, + const quaternion q2); }; #include "quaternion.cpp" diff --git a/src/sensor_fusion/standalone/gravity_sensor.cpp b/src/sensor_fusion/standalone/gravity_sensor.cpp index 8470e36..94a82e7 100644 --- a/src/sensor_fusion/standalone/gravity_sensor.cpp +++ b/src/sensor_fusion/standalone/gravity_sensor.cpp @@ -17,7 +17,7 @@ * */ -#ifdef _GRAVITY_SENSOR_H +#ifdef _GRAVITY_SENSOR_H_ #define GRAVITY 9.80665 diff --git a/src/sensor_fusion/standalone/linear_acceleration_sensor.cpp b/src/sensor_fusion/standalone/linear_acceleration_sensor.cpp index a29a9ca..b38a2d1 100644 --- a/src/sensor_fusion/standalone/linear_acceleration_sensor.cpp +++ b/src/sensor_fusion/standalone/linear_acceleration_sensor.cpp @@ -17,7 +17,7 @@ * */ -#ifdef _LINEAR_ACCELERATION_SENSOR_H +#ifdef _LINEAR_ACCELERATION_SENSOR_H_ sensor_data linear_acceleration_sensor::get_linear_acceleration(const sensor_data accel, const sensor_data gyro, const sensor_data magnetic) diff --git a/src/sensor_fusion/standalone/orientation_sensor.cpp b/src/sensor_fusion/standalone/orientation_sensor.cpp index 26412c2..c006922 100644 --- a/src/sensor_fusion/standalone/orientation_sensor.cpp +++ b/src/sensor_fusion/standalone/orientation_sensor.cpp @@ -17,7 +17,7 @@ * */ -#ifdef _ORIENTATION_SENSOR_H +#ifdef _ORIENTATION_SENSOR_H_ float bias_accel[] = {0.098586, 0.18385, (10.084 - GRAVITY)}; float bias_gyro[] = {-5.3539, 0.24325, 2.3391}; @@ -31,7 +31,7 @@ float scale_magnetic = 1; int pitch_phase_compensation = -1; int roll_phase_compensation = -1; -int yaw_phase_compensation = -1; +int azimuth_phase_compensation = -1; int magnetic_alignment_factor = -1; void pre_process_data(sensor_data &data_out, sensor_data &data_in, float *bias, int *sign, float scale) @@ -55,7 +55,7 @@ euler_angles orientation_sensor::get_orientation(sensor_data accel orien_filter.m_pitch_phase_compensation = pitch_phase_compensation; orien_filter.m_roll_phase_compensation = roll_phase_compensation; - orien_filter.m_yaw_phase_compensation = yaw_phase_compensation; + orien_filter.m_azimuth_phase_compensation = azimuth_phase_compensation; orien_filter.m_magnetic_alignment_factor = magnetic_alignment_factor; return orien_filter.get_orientation(accel_data, gyro_data, magnetic_data); @@ -73,7 +73,7 @@ rotation_matrix orientation_sensor::get_rotation_matrix(sensor_data &data_out, sensor_data &data_in, float *bias, int *sign, float scale) @@ -105,7 +105,7 @@ int main() orien_filter.m_pitch_phase_compensation = pitch_phase_compensation; orien_filter.m_roll_phase_compensation = roll_phase_compensation; - orien_filter.m_yaw_phase_compensation = yaw_phase_compensation; + orien_filter.m_azimuth_phase_compensation = azimuth_phase_compensation; orien_filter.m_magnetic_alignment_factor = magnetic_alignment_factor; orientation = orien_filter.get_orientation(accel_data, gyro_data, magnetic_data); -- 2.7.4 From 26b02228f39d46e722208e74223c514269e03594 Mon Sep 17 00:00:00 2001 From: Amit Dharmapurikar Date: Thu, 20 Nov 2014 10:29:04 +0530 Subject: [PATCH 02/16] Synchronizing proxi sensor plugin with addition of IIO interface support Change-Id: Ic505aab62f6a42572a6cf441a9eb18b196ccb524 Signed-off-by: Amit Dharmapurikar --- packaging/sensord.spec | 2 +- src/proxi/CMakeLists.txt | 4 +- src/proxi/proxi_sensor.cpp | 38 ++++--- src/proxi/proxi_sensor.h | 25 ++-- src/proxi/proxi_sensor_hal.cpp | 252 ++++++++++++++++------------------------- src/proxi/proxi_sensor_hal.h | 46 +++----- 6 files changed, 151 insertions(+), 216 deletions(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 7420325..eb9d4c2 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -10,7 +10,7 @@ Source2: sensord.socket %define accel_state ON %define gyro_state ON -%define proxi_state OFF +%define proxi_state ON %define light_state OFF %define geo_state ON %define pressure_state OFF diff --git a/src/proxi/CMakeLists.txt b/src/proxi/CMakeLists.txt index 6a52735..f679e41 100755 --- a/src/proxi/CMakeLists.txt +++ b/src/proxi/CMakeLists.txt @@ -15,7 +15,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src/libsensord) include(FindPkgConfig) pkg_check_modules(rpkgs REQUIRED vconf) -add_definitions(${rpkgs_CFLAGS} -DUSE_ONLY_ONE_MODULE) +add_definitions(${rpkgs_CFLAGS} -DUSE_ONLY_ONE_MODULE -DUSE_LCD_TYPE_CHECK) set(PROJECT_MAJOR_VERSION "0") set(PROJECT_MINOR_VERSION "0") @@ -43,7 +43,7 @@ add_library(${SENSOR_NAME} SHARED ) add_library(${SENSOR_HAL_NAME} SHARED - proxi_sensor_hal.cpp + proxi_sensor_hal.cpp ) target_link_libraries(${SENSOR_NAME} ${rpkgs_LDFLAGS} ${GLES_LDFLAGS} "-lm") diff --git a/src/proxi/proxi_sensor.cpp b/src/proxi/proxi_sensor.cpp index 4799da4..c55bc74 100755 --- a/src/proxi/proxi_sensor.cpp +++ b/src/proxi/proxi_sensor.cpp @@ -19,9 +19,11 @@ #include #include + #include #include + #define SENSOR_NAME "PROXI_SENSOR" proxi_sensor::proxi_sensor() @@ -39,7 +41,7 @@ proxi_sensor::proxi_sensor() proxi_sensor::~proxi_sensor() { - INFO("proxi_sensor is destroyed!"); + INFO("proxi_sensor is destroyed!\n"); } bool proxi_sensor::init() @@ -51,7 +53,7 @@ bool proxi_sensor::init() return false; } - INFO("%s is created!", sensor_base::get_name()); + INFO("%s is created!\n", sensor_base::get_name()); return true; } @@ -62,7 +64,7 @@ sensor_type_t proxi_sensor::get_type(void) bool proxi_sensor::working(void *inst) { - proxi_sensor *sensor = (proxi_sensor *)inst; + proxi_sensor *sensor = (proxi_sensor*)inst; return sensor->process_event(); } @@ -79,6 +81,7 @@ bool proxi_sensor::process_event(void) AUTOLOCK(m_client_info_mutex); AUTOLOCK(m_mutex); + event.sensor_id = get_id(); if (get_client_cnt(PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME)) { event.event_type = PROXIMITY_EVENT_DISTANCE_DATA_REPORT_ON_TIME; raw_to_base(event.data); @@ -103,10 +106,8 @@ bool proxi_sensor::process_event(void) bool proxi_sensor::on_start(void) { - AUTOLOCK(m_mutex); - if (!m_sensor_hal->enable()) { - ERR("m_sensor_hal start fail"); + ERR("m_sensor_hal start fail\n"); return false; } @@ -115,22 +116,25 @@ bool proxi_sensor::on_start(void) bool proxi_sensor::on_stop(void) { - AUTOLOCK(m_mutex); - if (!m_sensor_hal->disable()) { - ERR("m_sensor_hal stop fail"); + ERR("m_sensor_hal stop fail\n"); return false; } return stop_poll(); } -bool proxi_sensor::get_properties(const unsigned int type, sensor_properties_t &properties) +bool proxi_sensor::get_properties(sensor_properties_t &properties) { - return m_sensor_hal->get_properties(properties); + m_sensor_hal->get_properties(properties); + + properties.min_range = properties.min_range * 5; + properties.max_range = properties.max_range * 5; + + return true; } -int proxi_sensor::get_sensor_data(const unsigned int type, sensor_data_t &data) +int proxi_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) { int state; @@ -140,7 +144,7 @@ int proxi_sensor::get_sensor_data(const unsigned int type, sensor_data_t &data) state = m_sensor_hal->get_sensor_data(data); if (state < 0) { - ERR("m_sensor_hal get struct_data fail"); + ERR("m_sensor_hal get struct_data fail\n"); return -1; } @@ -159,7 +163,7 @@ void proxi_sensor::raw_to_base(sensor_data_t &data) void proxi_sensor::raw_to_state(sensor_data_t &data) { - data.values_num = 1; + data.value_count = 1; } extern "C" void *create(void) @@ -169,14 +173,14 @@ extern "C" void *create(void) try { inst = new proxi_sensor(); } catch (int err) { - ERR("Failed to create proxi_sensor class, errno : %d, errstr : %s", err, strerror(err)); + ERR("proxi_sensor class create fail , errno : %d , errstr : %s\n", err, strerror(err)); return NULL; } - return (void *)inst; + return (void*)inst; } extern "C" void destroy(void *inst) { - delete (proxi_sensor *)inst; + delete (proxi_sensor*)inst; } diff --git a/src/proxi/proxi_sensor.h b/src/proxi/proxi_sensor.h index 5b8a411..b61da04 100755 --- a/src/proxi/proxi_sensor.h +++ b/src/proxi/proxi_sensor.h @@ -21,33 +21,36 @@ #define _PROXI_SENSOR_H_ #include + #include #include -class proxi_sensor : public physical_sensor -{ +class proxi_sensor : public physical_sensor { public: proxi_sensor(); virtual ~proxi_sensor(); - virtual bool init(); - virtual sensor_type_t get_type(void); + bool init(); + sensor_type_t get_type(void); static bool working(void *inst); - virtual bool on_start(void); - virtual bool on_stop(void); - - virtual bool get_properties(const unsigned int type, sensor_properties_t &properties); - virtual int get_sensor_data(const unsigned int type, sensor_data_t &data); + virtual bool get_properties(sensor_properties_t &properties); + int get_sensor_data(unsigned int type, sensor_data_t &data); private: sensor_hal *m_sensor_hal; - cmutex m_value_mutex; int m_state; + cmutex m_value_mutex; + + + virtual bool on_start(void); + virtual bool on_stop(void); + void raw_to_base(sensor_data_t &data); void raw_to_state(sensor_data_t &data); bool process_event(void); }; -#endif /*_PROXI_SENSOR_H_*/ + +#endif diff --git a/src/proxi/proxi_sensor_hal.cpp b/src/proxi/proxi_sensor_hal.cpp index c1fb0d7..1701100 100755 --- a/src/proxi/proxi_sensor_hal.cpp +++ b/src/proxi/proxi_sensor_hal.cpp @@ -1,5 +1,5 @@ /* - * sensord + * proxi_sensor_hal * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * @@ -16,90 +16,111 @@ * limitations under the License. * */ - -#include #include #include -#include #include + #include #include + #include +#include +#include +#include #include -using std::ifstream; -using config::CConfig; +#define NO_FLAG 0 +#define PROXIMITY_TYPE 8 -#define INITIAL_VALUE -1 -#define INITIAL_TIME 0 +#define EVENT_DIR "events/" +#define EVENT_EN_NODE "in_proximity_thresh_either_en" #define SENSOR_TYPE_PROXI "PROXI" -#define ELEMENT_NAME "NAME" +#define ELEMENT_NAME "NAME" #define ELEMENT_VENDOR "VENDOR" -#define ATTR_VALUE "value" +#define ATTR_VALUE "value" -#define INPUT_NAME "proximity_sensor" +#define PROXI_CODE 0x0019 -#define NO_FLAG 0 -#define ENABLE_VAL true -#define DISABLE_VAL false +using std::ifstream; +using config::CConfig; proxi_sensor_hal::proxi_sensor_hal() : m_state(PROXIMITY_STATE_FAR) -, m_node_handle(INITIAL_VALUE) -, m_fired_time(INITIAL_TIME) -, m_sensorhub_supported(false) +, m_fired_time(0) +, m_node_handle(-1) { - int fd, ret; + const string sensorhub_interval_node_name = "prox_poll_delay"; + CConfig &config = CConfig::get_instance(); - if (!check_hw_node()) - { - ERR("check_hw_node() fail"); + node_path_info_query query; + node_path_info info; + int input_method = IIO_METHOD; + + if (!get_model_properties(SENSOR_TYPE_PROXI, m_model_id, input_method)) { + ERR("Failed to find model_properties"); throw ENXIO; + } - CConfig &config = CConfig::get_instance(); + query.input_method = input_method; + query.sensorhub_controlled = m_sensorhub_controlled = false; + query.sensor_type = SENSOR_TYPE_PROXI; + query.input_event_key = "proximity_sensor"; + query.iio_enable_node_name = "proximity_enable"; + query.sensorhub_interval_node_name = sensorhub_interval_node_name; - if (!config.get(SENSOR_TYPE_PROXI, m_model_id, ELEMENT_VENDOR, m_vendor)) - { - ERR("[VENDOR] is empty"); + if (!get_node_path_info(query, info)) { + ERR("Failed to get node info"); + throw ENXIO; + } + + m_data_node = info.data_node_path; + m_enable_node = info.base_dir + string(EVENT_DIR) + string(EVENT_EN_NODE); + + INFO("data node: %s",m_data_node.c_str()); + INFO("enable node: %s",m_enable_node.c_str()); + + if (!config.get(SENSOR_TYPE_PROXI, m_model_id, ELEMENT_VENDOR, m_vendor)) { + ERR("[VENDOR] is empty\n"); throw ENXIO; } INFO("m_vendor = %s", m_vendor.c_str()); - if (!config.get(SENSOR_TYPE_PROXI, m_model_id, ELEMENT_NAME, m_chip_name)) - { - ERR("[NAME] is empty"); + if (!config.get(SENSOR_TYPE_PROXI, m_model_id, ELEMENT_NAME, m_chip_name)) { + ERR("[NAME] is empty\n"); throw ENXIO; } - INFO("m_chip_name = %s", m_chip_name.c_str()); + INFO("m_chip_name = %s\n",m_chip_name.c_str()); - fd = open(m_event_resource.c_str(), NO_FLAG); - if (fd == -1) - { + int fd, ret; + fd = open(m_data_node.c_str(), NO_FLAG); + if (fd == -1) { ERR("Could not open event resource"); throw ENXIO; } - ret = ioctl(fd, IOCTL_IIO_EVENT_FD, &m_event_fd); + ret = ioctl(fd, IOCTL_IIO_EVENT_FD, &m_node_handle); close(fd); - if ((ret == -1) || (m_event_fd == -1)) - { + if ((ret == -1) || (m_node_handle == -1)) { ERR("Failed to retrieve event fd"); throw ENXIO; } - INFO("proxi_sensor_hal is created!"); + INFO("Proxi_sensor_hal is created!\n"); + } proxi_sensor_hal::~proxi_sensor_hal() { - close(m_event_fd); - INFO("proxi_sensor_hal is destroyed!"); + close(m_node_handle); + m_node_handle = -1; + + INFO("Proxi_sensor_hal is destroyed!\n"); } string proxi_sensor_hal::get_model_id(void) @@ -114,7 +135,7 @@ sensor_type_t proxi_sensor_hal::get_type(void) bool proxi_sensor_hal::enable_resource(bool enable) { - update_sysfs_num(m_enable_resource.c_str(), enable); + update_sysfs_num(m_enable_node.c_str(), enable); return true; } @@ -122,10 +143,10 @@ bool proxi_sensor_hal::enable(void) { AUTOLOCK(m_mutex); - enable_resource(ENABLE_VAL); + enable_resource(true); m_fired_time = 0; - INFO("Proximity sensor real starting"); + INFO("Proxi sensor real starting"); return true; } @@ -133,9 +154,9 @@ bool proxi_sensor_hal::disable(void) { AUTOLOCK(m_mutex); - enable_resource(DISABLE_VAL); + enable_resource(true); - INFO("Proximity sensor real stopping"); + INFO("Proxi sensor real stopping"); return true; } @@ -146,71 +167,60 @@ bool proxi_sensor_hal::update_value(bool wait) FD_ZERO(&readfds); FD_ZERO(&exceptfds); - FD_SET(m_event_fd, &readfds); - FD_SET(m_event_fd, &exceptfds); + FD_SET(m_node_handle, &readfds); + FD_SET(m_node_handle, &exceptfds); int ret; - ret = select(m_event_fd + 1, &readfds, NULL, &exceptfds, NULL); + ret = select(m_node_handle + 1, &readfds, NULL, &exceptfds, NULL); - if (ret == -1) - { - ERR("select error:%s m_event_fd:d", strerror(errno), m_event_fd); + if (ret == -1) { + ERR("select error:%s m_node_handle:%d", strerror(errno), m_node_handle); return false; } - else if (!ret) - { + else if (!ret) { DBG("select timeout"); return false; } - if (FD_ISSET(m_event_fd, &exceptfds)) - { + if (FD_ISSET(m_node_handle, &exceptfds)) { ERR("select exception occurred!"); return false; } - if (FD_ISSET(m_event_fd, &readfds)) - { + if (FD_ISSET(m_node_handle, &readfds)) { INFO("proximity event detection!"); - int len = read(m_event_fd, &proxi_event, sizeof(proxi_event)); + int len = read(m_node_handle, &proxi_event, sizeof(proxi_event)); - if (len == -1) - { - DBG("Error in read(m_event_fd):%s.", strerror(errno)); + if (len == -1) { + DBG("Error in read(m_node_handle):%s.", strerror(errno)); return false; } ull_bytes_t ev_data; ev_data.num = proxi_event.event_id; - if (ev_data.bytes[CH_TYPE] == PROXIMITY_TYPE) - { + if (ev_data.bytes[CH_TYPE] == PROXIMITY_TYPE) { AUTOLOCK(m_value_mutex); int temp; temp = GET_DIR_VAL(ev_data.bytes[DIRECTION]); - if (temp == PROXIMITY_NODE_STATE_FAR) - { + if (temp == PROXIMITY_NODE_STATE_FAR) { INFO("PROXIMITY_STATE_FAR state occurred"); m_state = PROXIMITY_STATE_FAR; } - else if (temp == PROXIMITY_NODE_STATE_NEAR) - { + else if (temp == PROXIMITY_NODE_STATE_NEAR) { INFO("PROXIMITY_STATE_NEAR state occurred"); m_state = PROXIMITY_STATE_NEAR; } - else - { + else { ERR("PROXIMITY_STATE Unknown: %d", proxi_event.event_id); return false; } } m_fired_time = proxi_event.timestamp; } - else - { + else { ERR("No proximity event data available to read"); return false; } - return true; } @@ -224,110 +234,42 @@ bool proxi_sensor_hal::is_data_ready(bool wait) int proxi_sensor_hal::get_sensor_data(sensor_data_t &data) { AUTOLOCK(m_value_mutex); - data.data_accuracy = SENSOR_ACCURACY_UNDEFINED; - data.data_unit_idx = SENSOR_UNIT_STATE_ON_OFF; + data.accuracy = SENSOR_ACCURACY_UNDEFINED; data.timestamp = m_fired_time; - data.values_num = 1; - data.values[0] = (float)(m_state); + data.value_count = 1; + data.values[0] = m_state; + return 0; } bool proxi_sensor_hal::get_properties(sensor_properties_t &properties) { - properties.sensor_unit_idx = SENSOR_UNIT_STATE_ON_OFF; - properties.sensor_min_range = 0; - properties.sensor_max_range = 1; - snprintf(properties.sensor_name, sizeof(properties.sensor_name), "%s", m_chip_name.c_str()); - snprintf(properties.sensor_vendor, sizeof(properties.sensor_vendor), "%s", m_vendor.c_str()); - properties.sensor_resolution = 1; + properties.name = m_chip_name; + properties.vendor = m_vendor; + properties.min_range = 0; + properties.max_range = 1; + properties.min_interval = 1; + properties.resolution = 1; + properties.fifo_count = 0; + properties.max_batch_count = 0; return true; } -bool proxi_sensor_hal::is_sensorhub_supported(void) -{ - return false; -} - -bool proxi_sensor_hal::check_hw_node(void) -{ - string name_node; - string hw_name; - string file_name; - DIR *main_dir = NULL; - struct dirent *dir_entry = NULL; - bool find_node = false; - - INFO("======================start check_hw_node============================="); - - m_sensorhub_supported = is_sensorhub_supported(); - main_dir = opendir(IIO_DIR); - - if (!main_dir) - { - ERR("Could not open IIO directory\n"); - return false; - } - - while (!find_node) - { - dir_entry = readdir(main_dir); - if(dir_entry == NULL) - break; - - if ((strncasecmp(dir_entry->d_name , ".", 1 ) != 0) && (strncasecmp(dir_entry->d_name , "..", 2 ) != 0) && (dir_entry->d_ino != 0)) - { - file_name = string(IIO_DIR) + string(dir_entry->d_name) + string(NAME_NODE); - - ifstream infile(file_name.c_str()); - - if (!infile) - continue; - - infile >> hw_name; - - if (strncmp(dir_entry->d_name, IIO_DEV_BASE_NAME, IIO_DEV_STR_LEN) == 0) - { - if (CConfig::get_instance().is_supported(SENSOR_TYPE_PROXI, hw_name) == true) - { - m_name = m_model_id = hw_name; - m_proxi_dir = string(dir_entry->d_name); - m_enable_resource = string(IIO_DIR) + m_proxi_dir + string(EVENT_DIR) + string(EVENT_EN_NODE); - m_event_resource = string(DEV_DIR) + m_proxi_dir; - - INFO("m_enable_resource = %s", m_enable_resource.c_str()); - INFO("m_model_id = %s", m_model_id.c_str()); - INFO("m_proxi_dir = %s", m_proxi_dir.c_str()); - INFO("m_event_resource = %s", m_event_resource.c_str()); - - find_node = true; - break; - } - } - } - } - - closedir(main_dir); - return find_node; -} - extern "C" void *create(void) { proxi_sensor_hal *inst; - try - { + try { inst = new proxi_sensor_hal(); - } - catch (int err) - { - ERR("Failed to create proxi_sensor_hal class, errno : %d, errstr : %s", err, strerror(err)); + } catch (int err) { + ERR("proxi_sensor class create fail , errno : %d , errstr : %s\n", err, strerror(err)); return NULL; } - return (void *)inst; + return (void*)inst; } extern "C" void destroy(void *inst) { - delete (proxi_sensor_hal *)inst; + delete (proxi_sensor_hal*)inst; } diff --git a/src/proxi/proxi_sensor_hal.h b/src/proxi/proxi_sensor_hal.h index bd273fa..6113397 100755 --- a/src/proxi/proxi_sensor_hal.h +++ b/src/proxi/proxi_sensor_hal.h @@ -1,5 +1,5 @@ /* - * sensord + * proxi_sensor_hal * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * @@ -23,24 +23,17 @@ #include #include -#define IIO_DIR "/sys/bus/iio/devices/" -#define NAME_NODE "/name" -#define EVENT_DIR "/events" -#define EVENT_EN_NODE "/in_proximity_thresh_either_en" -#define DEV_DIR "/dev/" - -#define IIO_DEV_BASE_NAME "iio:device" -#define IIO_DEV_STR_LEN 10 - -#define PROXIMITY_NODE_STATE_NEAR 1 -#define PROXIMITY_NODE_STATE_FAR 2 -#define PROXIMITY_TYPE 8 - using std::string; class proxi_sensor_hal : public sensor_hal { public: + enum proxi_node_state_event_t { //changed as per IIO definitions + PROXIMITY_NODE_STATE_NEAR = 1, + PROXIMITY_NODE_STATE_FAR = 2, + PROXIMITY_NODE_STATE_UNKNOWN = 0, + }; + proxi_sensor_hal(); virtual ~proxi_sensor_hal(); string get_model_id(void); @@ -49,31 +42,24 @@ public: bool disable(void); bool is_data_ready(bool wait); virtual int get_sensor_data(sensor_data_t &data); - bool get_properties(sensor_properties_t &properties); - bool check_hw_node(void); - + virtual bool get_properties(sensor_properties_t &properties); private: - unsigned int m_state; - int m_node_handle; - unsigned long long m_fired_time; - bool m_sensorhub_supported; - string m_model_id; - string m_name; string m_vendor; string m_chip_name; - string m_proxi_dir; + string m_enable_node; + string m_data_node; - string m_enable_resource; - string m_event_resource; + unsigned int m_state; - cmutex m_value_mutex; + unsigned long long m_fired_time; - int m_event_fd; + int m_node_handle; + bool m_sensorhub_controlled; + cmutex m_value_mutex; - bool enable_resource(bool enable); bool update_value(bool wait); - bool is_sensorhub_supported(void); + bool enable_resource(bool enable); }; #endif /*_PROXI_SENSOR_HAL_H_*/ -- 2.7.4 From 6bf910fdf6bf2e1cd212ccaf79bceecce1c67961 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Wed, 19 Nov 2014 17:41:05 +0530 Subject: [PATCH 03/16] Cleanup of sensor fusion related code Cleanup of legacy sensor fusion code remaining after private code sync with public code. Change-Id: I66673a52e23c67e4839a0abce1f10b959cb5610f --- src/shared/csensor_event_dispatcher.cpp | 4 --- src/shared/fusion_util.cpp | 56 --------------------------------- src/shared/fusion_util.h | 34 -------------------- src/shared/sensor_plugin_loader.cpp | 7 +---- src/shared/sensor_plugin_loader.h | 11 ------- src/shared/virtual_sensor.cpp | 7 +++++ src/shared/virtual_sensor.h | 5 ++- 7 files changed, 12 insertions(+), 112 deletions(-) delete mode 100644 src/shared/fusion_util.cpp delete mode 100755 src/shared/fusion_util.h diff --git a/src/shared/csensor_event_dispatcher.cpp b/src/shared/csensor_event_dispatcher.cpp index 3b90c34..f9f90d5 100755 --- a/src/shared/csensor_event_dispatcher.cpp +++ b/src/shared/csensor_event_dispatcher.cpp @@ -151,7 +151,6 @@ void csensor_event_dispatcher::dispatch_event(void) } else { sensor_event_t sensor_events[MAX_SENSOR_EVENT]; unsigned int event_cnt = 0; - sensor_events[event_cnt++] = *((sensor_event_t *)seed_event); virtual_sensors v_sensors = get_active_virtual_sensors(); @@ -160,11 +159,8 @@ void csensor_event_dispatcher::dispatch_event(void) while (it_v_sensor != v_sensors.end()) { int synthesized_cnt; - v_sensor_events.clear(); - (*it_v_sensor)->synthesize(*((sensor_event_t *)seed_event), v_sensor_events); - synthesized_cnt = v_sensor_events.size(); for (int i = 0; i < synthesized_cnt; ++i) diff --git a/src/shared/fusion_util.cpp b/src/shared/fusion_util.cpp deleted file mode 100644 index b6d2c14..0000000 --- a/src/shared/fusion_util.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * libsensord-share - * - * 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 - -int quat_to_matrix(const float *quat, float *R) -{ - if(quat == NULL || R == NULL) - return -1; - - float q0 = quat[3]; - float q1 = quat[0]; - float q2 = quat[1]; - float q3 = quat[2]; - - float sq_q1 = 2 * q1 * q1; - float sq_q2 = 2 * q2 * q2; - float sq_q3 = 2 * q3 * q3; - float q1_q2 = 2 * q1 * q2; - float q3_q0 = 2 * q3 * q0; - float q1_q3 = 2 * q1 * q3; - float q2_q0 = 2 * q2 * q0; - float q2_q3 = 2 * q2 * q3; - float q1_q0 = 2 * q1 * q0; - - R[0] = 1 - sq_q2 - sq_q3; - R[1] = q1_q2 - q3_q0; - R[2] = q1_q3 + q2_q0; - R[3] = q1_q2 + q3_q0; - R[4] = 1 - sq_q1 - sq_q3; - R[5] = q2_q3 - q1_q0; - R[6] = q1_q3 - q2_q0; - R[7] = q2_q3 + q1_q0; - R[8] = 1 - sq_q1 - sq_q2; - - return 0; -} - diff --git a/src/shared/fusion_util.h b/src/shared/fusion_util.h deleted file mode 100755 index 53310c1..0000000 --- a/src/shared/fusion_util.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * libsensord-share - * - * 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 _FUSION_UTIL_H_ -#define _FUSION_UTIL_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -int quat_to_matrix(const float *quat, float *R); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/shared/sensor_plugin_loader.cpp b/src/shared/sensor_plugin_loader.cpp index 9819a15..09f6711 100755 --- a/src/shared/sensor_plugin_loader.cpp +++ b/src/shared/sensor_plugin_loader.cpp @@ -17,15 +17,11 @@ * */ - #include - #include #include - #include #include - #include #include #include @@ -39,7 +35,6 @@ using std::unordered_set; #define ROOT_ELEMENT "PLUGIN" #define TEXT_ELEMENT "text" #define PATH_ATTR "path" - #define HAL_ELEMENT "HAL" #define SENSOR_ELEMENT "SENSOR" @@ -106,7 +101,7 @@ bool sensor_plugin_loader::load_module(const string &path, void** module, void** bool sensor_plugin_loader::insert_module(plugin_type type, const string &path) { if (type == PLUGIN_TYPE_HAL) { - DBG("insert sensor plugin [%s]", path); + DBG("insert sensor plugin [%s]", path.c_str()); sensor_hal *module; void *handle; diff --git a/src/shared/sensor_plugin_loader.h b/src/shared/sensor_plugin_loader.h index 332db4a..5964835 100755 --- a/src/shared/sensor_plugin_loader.h +++ b/src/shared/sensor_plugin_loader.h @@ -33,7 +33,6 @@ class sensor_hal; class sensor_base; -class sensor_fusion; using std::pair; using std::vector; @@ -60,15 +59,6 @@ typedef multimap sensor_plugins; * */ -typedef vector fusion_plugins; -/* -* a fusion_plugins is a group of fusion plugin -* -* ... -* -* -*/ - class sensor_plugin_loader { private: @@ -87,7 +77,6 @@ private: sensor_hal_plugins m_sensor_hals; sensor_plugins m_sensors; - fusion_plugins m_fusions; public: static sensor_plugin_loader& get_instance(); diff --git a/src/shared/virtual_sensor.cpp b/src/shared/virtual_sensor.cpp index 221884b..bd0aa84 100755 --- a/src/shared/virtual_sensor.cpp +++ b/src/shared/virtual_sensor.cpp @@ -46,3 +46,10 @@ bool virtual_sensor::deactivate(void) { return csensor_event_dispatcher::get_instance().delete_active_virtual_sensor(this); } + +bool virtual_sensor::push(sensor_event_t const &event) +{ + csensor_event_queue::get_instance().push(event); + return true; +} + diff --git a/src/shared/virtual_sensor.h b/src/shared/virtual_sensor.h index 94acc4c..d592ce6 100755 --- a/src/shared/virtual_sensor.h +++ b/src/shared/virtual_sensor.h @@ -28,12 +28,15 @@ public: virtual_sensor(); virtual ~virtual_sensor(); - virtual void synthesize(const sensor_event_t& event, vector &outs) = 0; + virtual void synthesize(const sensor_event_t &event, vector &outs) = 0; + virtual int get_sensor_data(const unsigned int event_type, sensor_data_t &data) = 0; bool is_virtual(void); protected: bool activate(void); bool deactivate(void); + + bool push(sensor_event_t const &event); }; #endif -- 2.7.4 From f0b884c4461d0bcaf247f70c260dd3e434c62b50 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Thu, 20 Nov 2014 11:08:23 +0530 Subject: [PATCH 04/16] Renaming cconfig files and references to csensor_config renaming cconfig to csensor_config to add cvirtual_sensor_config class for adding virtual sensor configuration. A virtual parent class cconfig will be added later. Change-Id: I801793991233a0b27cafdf0792c57443a098a067 --- src/accel/accel_sensor_hal.cpp | 6 ++--- src/geo/geo_sensor_hal.cpp | 9 +++----- src/gyro/gyro_sensor_hal.cpp | 7 +++--- src/light/light_sensor_hal.cpp | 6 ++--- src/pressure/pressure_sensor.cpp | 6 ++--- src/pressure/pressure_sensor_hal.cpp | 9 +++----- src/proxi/proxi_sensor.cpp | 2 -- src/proxi/proxi_sensor.h | 1 - src/proxi/proxi_sensor_hal.cpp | 12 ++++------ src/shared/CMakeLists.txt | 4 ++-- src/shared/{cconfig.cpp => csensor_config.cpp} | 32 +++++++++++++------------- src/shared/{cconfig.h => csensor_config.h} | 20 ++++++++-------- src/shared/sensor_hal.cpp | 6 ++--- src/temperature/temperature_sensor_hal.cpp | 9 +++----- 14 files changed, 57 insertions(+), 72 deletions(-) rename src/shared/{cconfig.cpp => csensor_config.cpp} (84%) rename src/shared/{cconfig.h => csensor_config.h} (85%) diff --git a/src/accel/accel_sensor_hal.cpp b/src/accel/accel_sensor_hal.cpp index f38a0ed..cb74385 100755 --- a/src/accel/accel_sensor_hal.cpp +++ b/src/accel/accel_sensor_hal.cpp @@ -20,13 +20,13 @@ #include #include -#include +#include #include #include using std::ifstream; -using config::CConfig; +using config::csensor_config; #define GRAVITY 9.80665 #define G_TO_MG 1000 @@ -63,7 +63,7 @@ accel_sensor_hal::accel_sensor_hal() , m_fired_time(0) { const string sensorhub_interval_node_name = "accel_poll_delay"; - CConfig &config = CConfig::get_instance(); + csensor_config &config = csensor_config::get_instance(); node_path_info_query query; node_path_info info; diff --git a/src/geo/geo_sensor_hal.cpp b/src/geo/geo_sensor_hal.cpp index 872525b..bfbb50e 100755 --- a/src/geo/geo_sensor_hal.cpp +++ b/src/geo/geo_sensor_hal.cpp @@ -19,18 +19,15 @@ #include #include #include - #include -#include - +#include #include #include #include -#include #include using std::ifstream; -using config::CConfig; +using config::csensor_config; #define SENSOR_TYPE_MAGNETIC "MAGNETIC" #define ELEMENT_NAME "NAME" @@ -53,7 +50,7 @@ geo_sensor_hal::geo_sensor_hal() , m_fired_time(INITIAL_TIME) { const string sensorhub_interval_node_name = "mag_poll_delay"; - CConfig &config = CConfig::get_instance(); + csensor_config &config = csensor_config::get_instance(); node_path_info_query query; node_path_info info; diff --git a/src/gyro/gyro_sensor_hal.cpp b/src/gyro/gyro_sensor_hal.cpp index fe04ca0..34184bc 100755 --- a/src/gyro/gyro_sensor_hal.cpp +++ b/src/gyro/gyro_sensor_hal.cpp @@ -21,16 +21,15 @@ #include #include -#include +#include #include #include #include -#include #include using std::ifstream; -using config::CConfig; +using config::csensor_config; #define DPS_TO_MDPS 1000 #define MIN_RANGE(RES) (-((1 << (RES))/2)) @@ -63,7 +62,7 @@ gyro_sensor_hal::gyro_sensor_hal() { const string sensorhub_interval_node_name = "gyro_poll_delay"; - CConfig &config = CConfig::get_instance(); + csensor_config &config = csensor_config::get_instance(); node_path_info_query query; node_path_info info; diff --git a/src/light/light_sensor_hal.cpp b/src/light/light_sensor_hal.cpp index 445828c..b429ffc 100755 --- a/src/light/light_sensor_hal.cpp +++ b/src/light/light_sensor_hal.cpp @@ -23,12 +23,12 @@ #include #include #include -#include +#include #include #include using std::ifstream; -using config::CConfig; +using config::csensor_config; #define BIAS 1 #define INITIAL_VALUE -1 @@ -52,7 +52,7 @@ light_sensor_hal::light_sensor_hal() throw ENXIO; } - CConfig &config = CConfig::get_instance(); + csensor_config &config = csensor_config::get_instance(); if (!config.get(SENSOR_TYPE_LIGHT, m_model_id, ELEMENT_VENDOR, m_vendor)) { diff --git a/src/pressure/pressure_sensor.cpp b/src/pressure/pressure_sensor.cpp index e13c3a4..35461a7 100755 --- a/src/pressure/pressure_sensor.cpp +++ b/src/pressure/pressure_sensor.cpp @@ -23,9 +23,9 @@ #include #include #include -#include +#include -using config::CConfig; +using config::csensor_config; using std::bind1st; using std::mem_fun; @@ -79,7 +79,7 @@ bool pressure_sensor::init() string model_id = m_sensor_hal->get_model_id(); - CConfig &config = CConfig::get_instance(); + csensor_config &config = csensor_config::get_instance(); double temperature_resolution; diff --git a/src/pressure/pressure_sensor_hal.cpp b/src/pressure/pressure_sensor_hal.cpp index 37dc7ac..764adc9 100755 --- a/src/pressure/pressure_sensor_hal.cpp +++ b/src/pressure/pressure_sensor_hal.cpp @@ -19,18 +19,15 @@ #include #include #include - #include -#include - +#include #include #include #include -#include #include using std::ifstream; -using config::CConfig; +using config::csensor_config; #define SENSOR_TYPE_PRESSURE "PRESSURE" #define ELEMENT_NAME "NAME" @@ -61,7 +58,7 @@ pressure_sensor_hal::pressure_sensor_hal() throw ENXIO; } - CConfig &config = CConfig::get_instance(); + csensor_config &config = csensor_config::get_instance(); if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_VENDOR, m_vendor)) { diff --git a/src/proxi/proxi_sensor.cpp b/src/proxi/proxi_sensor.cpp index c55bc74..37dfce6 100755 --- a/src/proxi/proxi_sensor.cpp +++ b/src/proxi/proxi_sensor.cpp @@ -19,11 +19,9 @@ #include #include - #include #include - #define SENSOR_NAME "PROXI_SENSOR" proxi_sensor::proxi_sensor() diff --git a/src/proxi/proxi_sensor.h b/src/proxi/proxi_sensor.h index b61da04..f058724 100755 --- a/src/proxi/proxi_sensor.h +++ b/src/proxi/proxi_sensor.h @@ -21,7 +21,6 @@ #define _PROXI_SENSOR_H_ #include - #include #include diff --git a/src/proxi/proxi_sensor_hal.cpp b/src/proxi/proxi_sensor_hal.cpp index 1701100..328211e 100755 --- a/src/proxi/proxi_sensor_hal.cpp +++ b/src/proxi/proxi_sensor_hal.cpp @@ -19,16 +19,16 @@ #include #include #include - #include -#include - +#include #include #include #include -#include #include +using std::ifstream; +using config::csensor_config; + #define NO_FLAG 0 #define PROXIMITY_TYPE 8 @@ -42,8 +42,6 @@ #define PROXI_CODE 0x0019 -using std::ifstream; -using config::CConfig; proxi_sensor_hal::proxi_sensor_hal() : m_state(PROXIMITY_STATE_FAR) @@ -51,7 +49,7 @@ proxi_sensor_hal::proxi_sensor_hal() , m_node_handle(-1) { const string sensorhub_interval_node_name = "prox_poll_delay"; - CConfig &config = CConfig::get_instance(); + csensor_config &config = csensor_config::get_instance(); node_path_info_query query; node_path_info info; diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 8ef03d8..9bad5a5 100755 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -38,7 +38,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src/libsensord) add_library(sensord-server SHARED crw_lock.cpp worker_thread.cpp - cconfig.cpp + csensor_config.cpp csensor_event_queue.cpp csensor_event_dispatcher.cpp csensor_usage.cpp @@ -74,7 +74,7 @@ install(FILES ${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) install(FILES crw_lock.h worker_thread.h - cconfig.h + csensor_config.h csensor_event_queue.h cinterval_info_list.h sensor_plugin_loader.h diff --git a/src/shared/cconfig.cpp b/src/shared/csensor_config.cpp similarity index 84% rename from src/shared/cconfig.cpp rename to src/shared/csensor_config.cpp index 34a7337..5c831b7 100755 --- a/src/shared/cconfig.cpp +++ b/src/shared/csensor_config.cpp @@ -1,7 +1,7 @@ /* * libsensord-share * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2013 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. @@ -17,7 +17,7 @@ * */ -#include +#include #include "common.h" #include #include @@ -33,17 +33,17 @@ using std::ifstream; #define MODEL_ID_ATTR "id" #define DEFAULT_ATTR "value" -CConfig::CConfig() +csensor_config::csensor_config() { } -CConfig& CConfig::get_instance(void) +csensor_config& csensor_config::get_instance(void) { static bool load_done = false; - static CConfig inst; + static csensor_config inst; if (!load_done) { - inst.load_config(); + inst.load_config(SENSOR_CONFIG_FILE_PATH); inst.get_device_id(); if (!inst.m_device_id.empty()) INFO("Device ID = %s", inst.m_device_id.c_str()); @@ -55,12 +55,12 @@ CConfig& CConfig::get_instance(void) return inst; } -bool CConfig::load_config(const string& config_path) +bool csensor_config::load_config(const string& config_path) { xmlDocPtr doc; xmlNodePtr cur; - DBG("CConfig::load_config(\"%s\") is called!\n",config_path.c_str()); + DBG("csensor_config::load_config(\"%s\") is called!\n",config_path.c_str()); doc = xmlParseFile(config_path.c_str()); @@ -163,7 +163,7 @@ bool CConfig::load_config(const string& config_path) } -bool CConfig::get(const string& sensor_type,const string& model_id, const string& element, const string& attr, string& value) +bool csensor_config::get(const string& sensor_type,const string& model_id, const string& element, const string& attr, string& value) { auto it_model_list = m_sensor_config.find(sensor_type); @@ -198,7 +198,7 @@ bool CConfig::get(const string& sensor_type,const string& model_id, const string return true; } -bool CConfig::get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value) +bool csensor_config::get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value) { string str_value; @@ -213,7 +213,7 @@ bool CConfig::get(const string& sensor_type, const string& model_id, const strin return true; } -bool CConfig::get(const string& sensor_type, const string& model_id, const string& element, const string& attr, long& value) +bool csensor_config::get(const string& sensor_type, const string& model_id, const string& element, const string& attr, long& value) { string str_value; @@ -228,7 +228,7 @@ bool CConfig::get(const string& sensor_type, const string& model_id, const strin return true; } -bool CConfig::get(const string& sensor_type, const string& model_id, const string& element, string& value) +bool csensor_config::get(const string& sensor_type, const string& model_id, const string& element, string& value) { if (get(sensor_type, model_id, element, m_device_id, value)) return true; @@ -239,7 +239,7 @@ bool CConfig::get(const string& sensor_type, const string& model_id, const strin return false; } -bool CConfig::get(const string& sensor_type, const string& model_id, const string& element, double& value) +bool csensor_config::get(const string& sensor_type, const string& model_id, const string& element, double& value) { if (get(sensor_type, model_id, element, m_device_id, value)) return true; @@ -250,7 +250,7 @@ bool CConfig::get(const string& sensor_type, const string& model_id, const strin return false; } -bool CConfig::get(const string& sensor_type, const string& model_id, const string& element, long& value) +bool csensor_config::get(const string& sensor_type, const string& model_id, const string& element, long& value) { if (get(sensor_type, model_id, element, m_device_id, value)) return true; @@ -261,7 +261,7 @@ bool CConfig::get(const string& sensor_type, const string& model_id, const strin return false; } -bool CConfig::is_supported(const string& sensor_type,const string& model_id) +bool csensor_config::is_supported(const string& sensor_type,const string& model_id) { auto it_model_list = m_sensor_config.find(sensor_type); @@ -276,7 +276,7 @@ bool CConfig::is_supported(const string& sensor_type,const string& model_id) return true; } -bool CConfig::get_device_id(void) +bool csensor_config::get_device_id(void) { const string INFO_INI_PATH = "/etc/info.ini"; const string START_DELIMETER = "Model="; diff --git a/src/shared/cconfig.h b/src/shared/csensor_config.h similarity index 85% rename from src/shared/cconfig.h rename to src/shared/csensor_config.h index 0017e27..03e72ea 100755 --- a/src/shared/cconfig.h +++ b/src/shared/csensor_config.h @@ -1,7 +1,7 @@ /* * libsensord-share * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2013 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. @@ -17,8 +17,8 @@ * */ -#if !defined(_CCONFIG_CLASS_H_) -#define _CCONFIG_CLASS_H_ +#if !defined(_CSENSOR_CONFIG_CLASS_H_) +#define _CSENSOR_CONFIG_CLASS_H_ #include #include @@ -28,7 +28,7 @@ using std::unordered_map; using std::string; using std::istringstream; -#define CONFIG_FILE_PATH "/usr/etc/sensors.xml" +#define SENSOR_CONFIG_FILE_PATH "/usr/etc/sensors.xml" typedef unordered_map Element; /* @@ -76,17 +76,17 @@ typedef unordered_map Sensor_config; namespace config { - class CConfig + class csensor_config { private: - CConfig(); - CConfig(CConfig const&) {}; - CConfig& operator=(CConfig const&); - bool load_config(const string& config_path = CONFIG_FILE_PATH); + csensor_config(); + csensor_config(csensor_config const&) {}; + csensor_config& operator=(csensor_config const&); + bool load_config(const string& config_path); Sensor_config m_sensor_config; string m_device_id; public: - static CConfig& get_instance(void); + static csensor_config& get_instance(void); bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, string& value); bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value); diff --git a/src/shared/sensor_hal.cpp b/src/shared/sensor_hal.cpp index e036203..55c20f7 100755 --- a/src/shared/sensor_hal.cpp +++ b/src/shared/sensor_hal.cpp @@ -21,11 +21,11 @@ #include #include #include -#include +#include using std::ifstream; using std::fstream; -using config::CConfig; +using config::csensor_config; cmutex sensor_hal::m_shared_mutex; @@ -310,7 +310,7 @@ bool sensor_hal::find_model_id(int method, const string &sensor_type, string &mo infile >> name; - if (CConfig::get_instance().is_supported(sensor_type, name)) { + if (csensor_config::get_instance().is_supported(sensor_type, name)) { model_id = name; find = true; break; diff --git a/src/temperature/temperature_sensor_hal.cpp b/src/temperature/temperature_sensor_hal.cpp index 2ba0b57..9d81381 100755 --- a/src/temperature/temperature_sensor_hal.cpp +++ b/src/temperature/temperature_sensor_hal.cpp @@ -19,17 +19,14 @@ #include #include #include - #include -#include - +#include #include #include -#include #include using std::ifstream; -using config::CConfig; +using config::csensor_config; #define SENSOR_TYPE_TEMPERATURE "TEMPERATURE" #define ELEMENT_NAME "NAME" @@ -56,7 +53,7 @@ temperature_sensor_hal::temperature_sensor_hal() throw ENXIO; } - CConfig &config = CConfig::get_instance(); + csensor_config &config = csensor_config::get_instance(); if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_VENDOR, m_vendor)) { -- 2.7.4 From c5d0338570c682b4f7d38882dd9a4232d5917422 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Thu, 20 Nov 2014 11:54:27 +0530 Subject: [PATCH 05/16] Adding virtual sensor XML and parser files Adding new virtual sensor XML file and XML parser files that are needed for configuration of the virtual sensors. Change-Id: I66673a52e23c67e1234a0abce1f10b959cb5610f --- src/shared/CMakeLists.txt | 2 + src/shared/cvirtual_sensor_config.cpp | 319 ++++++++++++++++++++++++++++++++++ src/shared/cvirtual_sensor_config.h | 82 +++++++++ virtual_sensors.xml.in | 41 +++++ 4 files changed, 444 insertions(+) create mode 100755 src/shared/cvirtual_sensor_config.cpp create mode 100755 src/shared/cvirtual_sensor_config.h create mode 100644 virtual_sensors.xml.in diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 9bad5a5..4a305da 100755 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -39,6 +39,7 @@ add_library(sensord-server SHARED crw_lock.cpp worker_thread.cpp csensor_config.cpp + cvirtual_sensor_config.cpp csensor_event_queue.cpp csensor_event_dispatcher.cpp csensor_usage.cpp @@ -75,6 +76,7 @@ install(FILES crw_lock.h worker_thread.h csensor_config.h + cvirtual_sensor_config.h csensor_event_queue.h cinterval_info_list.h sensor_plugin_loader.h diff --git a/src/shared/cvirtual_sensor_config.cpp b/src/shared/cvirtual_sensor_config.cpp new file mode 100755 index 0000000..1666430 --- /dev/null +++ b/src/shared/cvirtual_sensor_config.cpp @@ -0,0 +1,319 @@ +/* + * libsensord-share + * + * Copyright (c) 2013 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 "common.h" +#include +#include +#include +#include +#include +#include + +using std::ifstream; +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" + +cvirtual_sensor_config::cvirtual_sensor_config() +{ +} + +cvirtual_sensor_config& cvirtual_sensor_config::get_instance(void) +{ + static bool load_done = false; + static cvirtual_sensor_config inst; + + if (!load_done) { + inst.load_config(VIRTUAL_SENSOR_CONFIG_FILE_PATH); + inst.get_device_id(); + if (!inst.m_device_id.empty()) + INFO("Device ID = %s", inst.m_device_id.c_str()); + else + ERR("Failed to get Device ID"); + load_done = true; + } + + return inst; +} + +bool cvirtual_sensor_config::load_config(const string& config_path) +{ + xmlDocPtr doc; + xmlNodePtr cur; + + DBG("cvirtual_sensor_config::load_config(\"%s\") is called!\n",config_path.c_str()); + + doc = xmlParseFile(config_path.c_str()); + + if (doc == NULL) { + ERR("There is no %s\n",config_path.c_str()); + return false; + } + + cur = xmlDocGetRootElement(doc); + if(cur == NULL) { + ERR("There is no root element in %s\n",config_path.c_str()); + xmlFreeDoc(doc); + return false; + } + + if(xmlStrcmp(cur->name, (const xmlChar *)ROOT_ELEMENT)) { + ERR("Wrong type document: there is no [%s] root element in %s\n",ROOT_ELEMENT,config_path.c_str()); + xmlFreeDoc(doc); + return false; + } + + 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) { + //skip garbage element, [text] + if (!xmlStrcmp(virtual_sensor_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) { + virtual_sensor_node_ptr = virtual_sensor_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) { + //skip garbage element, [text] + if (!xmlStrcmp(element_node_ptr->name,(const xmlChar *)TEXT_ELEMENT)) { + element_node_ptr = element_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); + + 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[(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; + } + + DBG("\n"); + virtual_sensor_node_ptr = virtual_sensor_node_ptr->next; + } + + xmlFreeDoc(doc); + return true; +} + +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); + + if (it_virtual_sensor_list == m_virtual_sensor_config.end()) { + ERR("There is no <%s> element\n",sensor_type.c_str()); + return false; + } + + auto it_element = it_virtual_sensor_list->second.find(element); + + if (it_element == it_virtual_sensor_list->second.end()) { + ERR("There is no <%s><%s> element\n",sensor_type.c_str(),element.c_str()); + return false; + } + + auto it_attr = it_element->second.find(attr); + + if (it_attr == it_element->second.end()) { + DBG("There is no <%s><%s \"%s\">\n",sensor_type.c_str(),element.c_str(),attr.c_str()); + return false; + } + + value = it_attr->second; + + return true; +} + +bool cvirtual_sensor_config::get(const string& sensor_type, const string& element, const string& attr, float *value) +{ + string str_value; + + if (get(sensor_type,element,attr,str_value) == false) + return false; + + stringstream str_stream(str_value); + + str_stream >> *value; + + return true; +} + +bool cvirtual_sensor_config::get(const string& sensor_type, const string& element, const string& attr, int *value) +{ + string str_value; + + if (get(sensor_type,element,attr,str_value) == false) + return false; + + stringstream str_stream(str_value); + + str_stream >> *value; + + return true; +} + +bool cvirtual_sensor_config::get(const string& sensor_type, const string& element, string& value) +{ + if (get(sensor_type, element, DEFAULT_ATTR, value)) + return true; + + return false; +} + +bool cvirtual_sensor_config::get(const string& sensor_type, const string& element, float *value, int count) +{ + if (count == 1) + { + if (get(sensor_type, element, DEFAULT_ATTR, value)) + return true; + } + else if (count == 3) + { + if (!get(sensor_type, element, DEFAULT_ATTR1, value)) + return false; + + value++; + + if (!get(sensor_type, element, DEFAULT_ATTR2, value)) + return false; + + value++; + + if (!get(sensor_type, element, DEFAULT_ATTR3, value)) + return false; + + return true; + } + else + { + DBG("Count value not supported.\n"); + } + + return false; +} + +bool cvirtual_sensor_config::get(const string& sensor_type, const string& element, int *value, int count) +{ + if (count == 1) + { + if (get(sensor_type, element, DEFAULT_ATTR, value)) + return true; + } + else if (count == 3) + { + if (!get(sensor_type, element, DEFAULT_ATTR1, value)) + return false; + + value++; + + if (!get(sensor_type, element, DEFAULT_ATTR2, value)) + return false; + + value++; + + if (!get(sensor_type, element, DEFAULT_ATTR3, value)) + return false; + + return true; + } + else + { + DBG("Count value not supported.\n"); + } + + return false; +} + +bool cvirtual_sensor_config::is_supported(const string& sensor_type) +{ + auto it_virtual_sensor_list = m_virtual_sensor_config.find(sensor_type); + + if (it_virtual_sensor_list == m_virtual_sensor_config.end()) + return false; + + return true; +} + +bool cvirtual_sensor_config::get_device_id(void) +{ + const string INFO_INI_PATH = "/etc/info.ini"; + const string START_DELIMETER = "Model="; + const string END_DELIMETER = ";"; + string line; + ifstream in_file; + std::size_t start_pos, end_pos; + bool ret = false; + + in_file.open(INFO_INI_PATH); + + if (!in_file.is_open()) + return false; + + while (!in_file.eof()) { + getline(in_file, line); + start_pos = line.find(START_DELIMETER); + + if (start_pos != std::string::npos) { + start_pos = start_pos + START_DELIMETER.size(); + end_pos = line.find(END_DELIMETER, start_pos); + + if (end_pos != std::string::npos) { + m_device_id = line.substr(start_pos, end_pos - start_pos); + ret = true; + break; + } + } + } + + in_file.close(); + + return ret; +} diff --git a/src/shared/cvirtual_sensor_config.h b/src/shared/cvirtual_sensor_config.h new file mode 100755 index 0000000..35e93ad --- /dev/null +++ b/src/shared/cvirtual_sensor_config.h @@ -0,0 +1,82 @@ +/* + * libsensord-share + * + * Copyright (c) 2013 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. + * + */ + +#if !defined(_CVIRTUAL_SENSOR_CONFIG_CLASS_H_) +#define _CVIRTUAL_SENSOR_CONFIG_CLASS_H_ + +#include +#include +#include + +using std::unordered_map; +using std::string; +using std::istringstream; + +#define VIRTUAL_SENSOR_CONFIG_FILE_PATH "/usr/etc/virtual_sensors.xml" + +typedef unordered_map Element; +/* +* an Element is a group of attributes +* +* +*/ + +typedef unordered_map Virtual_sensor; +/* +* a Virtual_sensor is a group of elements to consist of one virtual sensor's configuration +* +* +* +* ... +*/ + +typedef unordered_map Virtual_sensor_config; +/* +* a Virtual_sensor_config represents virtual_sensors.xml +* +* +* +* +*/ + +class cvirtual_sensor_config +{ +private: + cvirtual_sensor_config(); + cvirtual_sensor_config(cvirtual_sensor_config const&) {}; + cvirtual_sensor_config& operator=(cvirtual_sensor_config const&); + bool load_config(const string& config_path); + Virtual_sensor_config m_virtual_sensor_config; + string m_device_id; +public: + static cvirtual_sensor_config& get_instance(void); + + bool get(const string& sensor_type, const string& element, const string& attr, string& value); + bool get(const string& sensor_type, const string& element, const string& attr, float *value); + bool get(const string& sensor_type, const string& element, const string& attr, int *value); + + bool get(const string& sensor_type, const string& element, string& value); + bool get(const string& sensor_type, const string& element, float *value, int count =1); + bool get(const string& sensor_type, const string& element, int *value, int count = 1); + + bool is_supported(const string &sensor_type); + bool get_device_id(void); +}; + +#endif diff --git a/virtual_sensors.xml.in b/virtual_sensors.xml.in new file mode 100644 index 0000000..42c9d72 --- /dev/null +++ b/virtual_sensors.xml.in @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.7.4 From 0a27751171b2bdef0c56d9626c950799a009a01d Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 21 Nov 2014 09:01:55 +0530 Subject: [PATCH 06/16] Updated year in license header to 2014 Updating license header year from 2013 to 2014 Change-Id: I11173a52e23c67e1234a0abce1f10b959cb5610f --- src/shared/csensor_config.cpp | 2 +- src/shared/csensor_config.h | 2 +- src/shared/cvirtual_sensor_config.cpp | 2 +- src/shared/cvirtual_sensor_config.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shared/csensor_config.cpp b/src/shared/csensor_config.cpp index 5c831b7..013a086 100755 --- a/src/shared/csensor_config.cpp +++ b/src/shared/csensor_config.cpp @@ -1,7 +1,7 @@ /* * libsensord-share * - * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/shared/csensor_config.h b/src/shared/csensor_config.h index 03e72ea..0c77f98 100755 --- a/src/shared/csensor_config.h +++ b/src/shared/csensor_config.h @@ -1,7 +1,7 @@ /* * libsensord-share * - * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/shared/cvirtual_sensor_config.cpp b/src/shared/cvirtual_sensor_config.cpp index 1666430..7aebd2d 100755 --- a/src/shared/cvirtual_sensor_config.cpp +++ b/src/shared/cvirtual_sensor_config.cpp @@ -1,7 +1,7 @@ /* * libsensord-share * - * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * 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. diff --git a/src/shared/cvirtual_sensor_config.h b/src/shared/cvirtual_sensor_config.h index 35e93ad..754fd00 100755 --- a/src/shared/cvirtual_sensor_config.h +++ b/src/shared/cvirtual_sensor_config.h @@ -1,7 +1,7 @@ /* * libsensord-share * - * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * 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. -- 2.7.4 From 453331489e51e420efa6b32102a7b376a209abe6 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 21 Nov 2014 09:27:29 +0530 Subject: [PATCH 07/16] Updating Orientation Virtual Sensor Code - Updating Orientation sensor after testing on SDK - Updating based on latest public code - Updating for new XML based configuration file Change-Id: I089d201406e03f283ed6a9bac2b1dbb8241bc219 --- packaging/sensord.spec | 2 +- src/orientation/orientation_sensor.cpp | 230 +++++++++++++++++++++++++-------- src/orientation/orientation_sensor.h | 30 ++++- 3 files changed, 202 insertions(+), 60 deletions(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index eb9d4c2..78f5b98 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -15,7 +15,7 @@ Source2: sensord.socket %define geo_state ON %define pressure_state OFF %define temperature_state OFF -%define orientation_state OFF +%define orientation_state ON %define gravity_state OFF %define linear_accel_state OFF diff --git a/src/orientation/orientation_sensor.cpp b/src/orientation/orientation_sensor.cpp index f4fbaa1..b1222e2 100755 --- a/src/orientation/orientation_sensor.cpp +++ b/src/orientation/orientation_sensor.cpp @@ -30,8 +30,10 @@ #include #include #include +#include #define SENSOR_NAME "ORIENTATION_SENSOR" +#define SENSOR_TYPE_ORIENTATION "ORIENTATION" #define ACCELEROMETER_ENABLED 0x01 #define GYROSCOPE_ENABLED 0x02 @@ -39,26 +41,28 @@ #define ORIENTATION_ENABLED 7 #define INITIAL_VALUE -1 -#define INITIAL_TIME 0 -// Below Defines const variables to be input from sensor config files once code is stabilized -#define SAMPLING_TIME 100 #define MS_TO_US 1000 -float bias_accel[] = {0.098586, 0.18385, (10.084 - GRAVITY)}; -float bias_gyro[] = {-5.3539, 0.24325, 2.3391}; -float bias_magnetic[] = {0, -37.6, +37.6}; -int sign_accel[] = {+1, +1, +1}; -int sign_gyro[] = {+1, +1, +1}; -int sign_magnetic[] = {+1, -1, +1}; -float scale_accel = 1; -float scale_gyro = 580 * 2; -float scale_magnetic = 1; - -int pitch_phase_compensation = 1; -int roll_phase_compensation = 1; -int yaw_phase_compensation = -1; -int magnetic_alignment_factor = 1; +#define AZIMUTH_OFFSET 360 + +#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" +#define ELEMENT_PITCH_ROTATION_COMPENSATION "PITCH_ROTATION_COMPENSATION" +#define ELEMENT_ROLL_ROTATION_COMPENSATION "ROLL_ROTATION_COMPENSATION" +#define ELEMENT_AZIMUTH_ROTATION_COMPENSATION "AZIMUTH_ROTATION_COMPENSATION" void pre_process_data(sensor_data &data_out, const float *data_in, float *bias, int *sign, float scale) { @@ -73,13 +77,129 @@ orientation_sensor::orientation_sensor() , m_magnetic_sensor(NULL) , m_roll(INITIAL_VALUE) , m_pitch(INITIAL_VALUE) -, m_yaw(INITIAL_VALUE) +, m_azimuth(INITIAL_VALUE) { + cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); + m_name = string(SENSOR_NAME); register_supported_event(ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME); - m_interval = SAMPLING_TIME * MS_TO_US; m_timestamp = get_timestamp(); m_enable_orientation = 0; + + if (!config.get(SENSOR_TYPE_ORIENTATION, ELEMENT_VENDOR, m_vendor)) { + ERR("[VENDOR] is empty\n"); + throw ENXIO; + } + + INFO("m_vendor = %s", m_vendor.c_str()); + + if (!config.get(SENSOR_TYPE_ORIENTATION, ELEMENT_RAW_DATA_UNIT, m_raw_data_unit)) { + ERR("[RAW_DATA_UNIT] is empty\n"); + throw ENXIO; + } + + INFO("m_raw_data_unit = %s", m_raw_data_unit.c_str()); + + if (!config.get(SENSOR_TYPE_ORIENTATION, 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_ORIENTATION, 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_ORIENTATION, 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_ORIENTATION, 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_ORIENTATION, 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_ORIENTATION, 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_ORIENTATION, 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_ORIENTATION, 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_ORIENTATION, 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_ORIENTATION, 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_ORIENTATION, 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); + + if (!config.get(SENSOR_TYPE_ORIENTATION, ELEMENT_AZIMUTH_ROTATION_COMPENSATION, &m_azimuth_rotation_compensation)) { + ERR("[AZIMUTH_ROTATION_COMPENSATION] is empty\n"); + throw ENXIO; + } + + INFO("m_azimuth_rotation_compensation = %d", m_azimuth_rotation_compensation); + + if (!config.get(SENSOR_TYPE_ORIENTATION, ELEMENT_PITCH_ROTATION_COMPENSATION, &m_pitch_rotation_compensation)) { + ERR("[PITCH_ROTATION_COMPENSATION] is empty\n"); + throw ENXIO; + } + + INFO("m_pitch_rotation_compensation = %d", m_pitch_rotation_compensation); + + if (!config.get(SENSOR_TYPE_ORIENTATION, ELEMENT_ROLL_ROTATION_COMPENSATION, &m_roll_rotation_compensation)) { + ERR("[ROLL_ROTATION_COMPENSATION] is empty\n"); + throw ENXIO; + } + + INFO("m_roll_rotation_compensation = %d", m_roll_rotation_compensation); + + m_interval = m_default_sampling_time * MS_TO_US; + } orientation_sensor::~orientation_sensor() @@ -181,7 +301,7 @@ void orientation_sensor::synthesize(const sensor_event_t &event, vector= 0) + orientation_event.data.values[0] = euler_orientation.m_ang.m_vec[2]; + else + orientation_event.data.values[0] = euler_orientation.m_ang.m_vec[2] + AZIMUTH_OFFSET; + + push(orientation_event); } return; @@ -257,40 +380,41 @@ int orientation_sensor::get_sensor_data(const unsigned int event_type, sensor_da 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, bias_accel, sign_accel, scale_accel); - pre_process_data(gyro, gyro_data.values, bias_gyro, sign_gyro, scale_gyro); - pre_process_data(magnetic, magnetic_data.values, bias_magnetic, sign_magnetic, scale_magnetic); + 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 = pitch_phase_compensation; - m_orientation.m_roll_phase_compensation = roll_phase_compensation; - m_orientation.m_yaw_phase_compensation = yaw_phase_compensation; - m_orientation.m_magnetic_alignment_factor = magnetic_alignment_factor; + 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; euler_orientation = m_orientation.get_orientation(accel, gyro, magnetic); - data.data_accuracy = SENSOR_ACCURACY_GOOD; - data.data_unit_idx = SENSOR_UNIT_DEGREE; + data.accuracy = SENSOR_ACCURACY_GOOD; data.timestamp = get_timestamp(); - data.values[0] = euler_orientation.m_ang.m_vec[0]; - data.values[1] = euler_orientation.m_ang.m_vec[1]; - data.values[2] = euler_orientation.m_ang.m_vec[2]; - data.values_num = 3; + data.values[1] = euler_orientation.m_ang.m_vec[0]; + data.values[2] = euler_orientation.m_ang.m_vec[1]; + if (euler_orientation.m_ang.m_vec[2] >= 0) + data.values[0] = euler_orientation.m_ang.m_vec[2]; + else + data.values[0] = euler_orientation.m_ang.m_vec[2] + AZIMUTH_OFFSET; + data.value_count = 3; return 0; } bool orientation_sensor::get_properties(sensor_properties_t &properties) { - properties.sensor_unit_idx = SENSOR_UNIT_DEGREE; - properties.sensor_min_range = -180; - properties.sensor_max_range = 180; - properties.sensor_resolution = 1; + properties.min_range = -180; + properties.max_range = 360; + properties.resolution = 1; - strncpy(properties.sensor_vendor, "Samsung", MAX_KEY_LENGTH); - strncpy(properties.sensor_name, SENSOR_NAME, MAX_KEY_LENGTH); + properties.vendor = "Samsung"; + properties.name = SENSOR_NAME; return true; } diff --git a/src/orientation/orientation_sensor.h b/src/orientation/orientation_sensor.h index f295ccc..ed61891 100755 --- a/src/orientation/orientation_sensor.h +++ b/src/orientation/orientation_sensor.h @@ -20,18 +20,16 @@ #ifndef _ORIENTATION_SENSOR_H_ #define _ORIENTATION_SENSOR_H_ -#include +#include #include #include class orientation_sensor : public virtual_sensor { public: orientation_sensor(); - ~orientation_sensor(); + virtual ~orientation_sensor(); bool init(void); - bool on_start(void); - bool on_stop(void); void synthesize(const sensor_event_t &event, vector &outs); @@ -59,9 +57,29 @@ private: float m_roll; float m_pitch; - float m_yaw; + float m_azimuth; unsigned long long m_timestamp; 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 /* _ORIENTATION_SENSOR_H_ */ +#endif -- 2.7.4 From b5bdddb579134867678d99e85a32827aee6be836 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 21 Nov 2014 09:39:34 +0530 Subject: [PATCH 08/16] Updating Gravity Virtual Sensor Code - Updating Gravity sensor after testing on SDK - Updating based on latest public code - Updating for new XML based configuration file Change-Id: I2000b0ce9a5a10525d54c3d6977075cd1f70e6d0 --- packaging/sensord.spec | 2 +- src/gravity/gravity_sensor.cpp | 116 ++++++++++++++++++++++++++++------------- src/gravity/gravity_sensor.h | 24 +++++---- 3 files changed, 96 insertions(+), 46 deletions(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 78f5b98..bfa8fa4 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -16,7 +16,7 @@ Source2: sensord.socket %define pressure_state OFF %define temperature_state OFF %define orientation_state ON -%define gravity_state OFF +%define gravity_state ON %define linear_accel_state OFF %define build_test_suite OFF diff --git a/src/gravity/gravity_sensor.cpp b/src/gravity/gravity_sensor.cpp index 5d574a0..08b70c5 100755 --- a/src/gravity/gravity_sensor.cpp +++ b/src/gravity/gravity_sensor.cpp @@ -27,31 +27,72 @@ #include #include #include -#include #include #include +#include #define INITIAL_VALUE -1 -#define INITIAL_TIME 0 #define GRAVITY 9.80665 +#define DEG2RAD (M_PI/180) + #define SENSOR_NAME "GRAVITY_SENSOR" +#define SENSOR_TYPE_GRAVITY "GRAVITY" + +#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_GRAVITY_SIGN_COMPENSATION "GRAVITY_SIGN_COMPENSATION" gravity_sensor::gravity_sensor() : m_orientation_sensor(NULL) , m_x(INITIAL_VALUE) , m_y(INITIAL_VALUE) , m_z(INITIAL_VALUE) -, m_timestamp(INITIAL_TIME) { - m_name = string(SENSOR_NAME); + cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); + m_name = string(SENSOR_NAME); + m_timestamp = get_timestamp(); register_supported_event(GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME); + + if (!config.get(SENSOR_TYPE_GRAVITY, ELEMENT_VENDOR, m_vendor)) { + ERR("[VENDOR] is empty\n"); + throw ENXIO; + } + + INFO("m_vendor = %s", m_vendor.c_str()); + + if (!config.get(SENSOR_TYPE_GRAVITY, ELEMENT_RAW_DATA_UNIT, m_raw_data_unit)) { + ERR("[RAW_DATA_UNIT] is empty\n"); + throw ENXIO; + } + + INFO("m_raw_data_unit = %s", m_raw_data_unit.c_str()); + + if (!config.get(SENSOR_TYPE_GRAVITY, 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_GRAVITY, ELEMENT_GRAVITY_SIGN_COMPENSATION, m_gravity_sign_compensation, 3)) { + ERR("[GRAVITY_SIGN_COMPENSATION] is empty\n"); + throw ENXIO; + } + + INFO("m_gravity_sign_compensation = (%d, %d, %d)", m_gravity_sign_compensation[0], m_gravity_sign_compensation[1], m_gravity_sign_compensation[2]); + + m_interval = m_default_sampling_time * MS_TO_US; } gravity_sensor::~gravity_sensor() { - INFO("gravity_sensor is destroyed!"); + INFO("gravity_sensor is destroyed!\n"); } bool gravity_sensor::init() @@ -77,6 +118,7 @@ bool gravity_sensor::on_start(void) AUTOLOCK(m_mutex); m_orientation_sensor->add_client(ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME); + m_orientation_sensor->add_interval((int)this, (m_interval/MS_TO_US), true); m_orientation_sensor->start(); activate(); @@ -88,6 +130,7 @@ bool gravity_sensor::on_stop(void) AUTOLOCK(m_mutex); m_orientation_sensor->delete_client(ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME); + m_orientation_sensor->delete_interval((int)this, true); m_orientation_sensor->stop(); deactivate(); @@ -113,24 +156,28 @@ bool gravity_sensor::delete_interval(int client_id) void gravity_sensor::synthesize(const sensor_event_t &event, vector &outs) { sensor_event_t gravity_event; - vector orientation_event; - ((virtual_sensor *)m_orientation_sensor)->synthesize(event, orientation_event); - - if (!orientation_event.empty()) { - AUTOLOCK(m_mutex); - - m_timestamp = orientation_event[0].data.timestamp; - gravity_event.data.values[0] = GRAVITY * sin(orientation_event[0].data.values[1]); - gravity_event.data.values[1] = GRAVITY * sin(orientation_event[0].data.values[0]); - gravity_event.data.values[2] = GRAVITY * cos(orientation_event[0].data.values[1] * - orientation_event[0].data.values[0]); - gravity_event.data.values_num = 3; + + const float MIN_DELIVERY_DIFF_FACTOR = 0.75f; + unsigned long long diff_time; + + if (event.event_type == ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME) { + diff_time = event.data.timestamp - m_timestamp; + + if (m_timestamp && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) + return; + + gravity_event.sensor_id = get_id(); + gravity_event.event_type = GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME; + m_timestamp = get_timestamp(); + gravity_event.data.values[0] = m_gravity_sign_compensation[0] * GRAVITY * sin(event.data.values[2] * DEG2RAD); + gravity_event.data.values[1] = m_gravity_sign_compensation[1] * GRAVITY * sin(event.data.values[1] * DEG2RAD); + gravity_event.data.values[2] = m_gravity_sign_compensation[2] * GRAVITY * cos(event.data.values[2] * DEG2RAD) * + cos(event.data.values[1] * DEG2RAD); + gravity_event.data.value_count = 3; gravity_event.data.timestamp = m_timestamp; - gravity_event.data.data_accuracy = SENSOR_ACCURACY_GOOD; - gravity_event.data.data_unit_idx = SENSOR_UNIT_METRE_PER_SECOND_SQUARED; + gravity_event.data.accuracy = SENSOR_ACCURACY_GOOD; - outs.push_back(gravity_event); - return; + push(gravity_event); } } @@ -143,25 +190,24 @@ int gravity_sensor::get_sensor_data(const unsigned int event_type, sensor_data_t m_orientation_sensor->get_sensor_data(ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME, orientation_data); - data.data_accuracy = SENSOR_ACCURACY_GOOD; - data.data_unit_idx = SENSOR_UNIT_METRE_PER_SECOND_SQUARED; - data.timestamp = orientation_data.timestamp; - data.values[0] = GRAVITY * sin(orientation_data.values[1]); - data.values[1] = GRAVITY * sin(orientation_data.values[0]); - data.values[2] = GRAVITY * cos(orientation_data.values[1] * orientation_data.values[0]); - data.values_num = 3; + data.accuracy = SENSOR_ACCURACY_GOOD; + data.timestamp = get_timestamp(); + data.values[0] = m_gravity_sign_compensation[0] * GRAVITY * sin(orientation_data.values[2] * DEG2RAD); + data.values[1] = m_gravity_sign_compensation[1] * GRAVITY * sin(orientation_data.values[1] * DEG2RAD); + data.values[2] = m_gravity_sign_compensation[2] * GRAVITY * cos(orientation_data.values[2] * DEG2RAD) * + cos(orientation_data.values[1] * DEG2RAD); + data.value_count = 3; return 0; } -bool gravity_sensor::get_properties(const unsigned int type, sensor_properties_t &properties) +bool gravity_sensor::get_properties(sensor_properties_t &properties) { - properties.sensor_unit_idx = SENSOR_UNIT_DEGREE; - properties.sensor_min_range = -GRAVITY; - properties.sensor_max_range = GRAVITY; - properties.sensor_resolution = 1; - strncpy(properties.sensor_vendor, "Samsung", MAX_KEY_LENGTH); - strncpy(properties.sensor_name, SENSOR_NAME, MAX_KEY_LENGTH); + properties.min_range = -GRAVITY; + properties.max_range = GRAVITY; + properties.resolution = 1; + properties.vendor = m_vendor; + properties.name = SENSOR_NAME; return true; } diff --git a/src/gravity/gravity_sensor.h b/src/gravity/gravity_sensor.h index 33e1eaa..d7aeacb 100755 --- a/src/gravity/gravity_sensor.h +++ b/src/gravity/gravity_sensor.h @@ -20,14 +20,13 @@ #ifndef _GRAVITY_SENSOR_H_ #define _GRAVITY_SENSOR_H_ -#include +#include #include #include using std::string; -class gravity_sensor : public virtual_sensor -{ +class gravity_sensor : public virtual_sensor { public: gravity_sensor(); virtual ~gravity_sensor(); @@ -35,25 +34,30 @@ public: bool init(); sensor_type_t get_type(void); - static bool working(void *inst); - - bool on_start(void); - bool on_stop(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); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); - bool get_properties(const unsigned int type, sensor_properties_t &properties); + bool get_properties(sensor_properties_t &properties); private: sensor_base *m_orientation_sensor; + cmutex m_value_mutex; float m_x; float m_y; float m_z; unsigned long long m_timestamp; + unsigned int m_interval; + + string m_vendor; + string m_raw_data_unit; + int m_default_sampling_time; + int m_gravity_sign_compensation[3]; + + bool on_start(void); + bool on_stop(void); }; -#endif /*_GRAVITY_SENSOR_H_*/ +#endif -- 2.7.4 From c5a3d394f5744ea7f13bde16a3a87cfd09c92952 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Fri, 21 Nov 2014 09:54:58 +0530 Subject: [PATCH 09/16] Updating Linear Acceleration Virtual Sensor Code - Updating Linear Acceleration sensor after testing on SDK - Updating based on latest public code - Updating for new XML based configuration file Change-Id: I1981b0ce9a5a10525d54c3d6977075cd1f70e6d0 --- packaging/sensord.spec | 2 +- src/linear_accel/CMakeLists.txt | 1 + src/linear_accel/linear_accel_sensor.cpp | 179 ++++++++++++++++++++++++++----- src/linear_accel/linear_accel_sensor.h | 38 ++++--- 4 files changed, 175 insertions(+), 45 deletions(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index bfa8fa4..a76daab 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -17,7 +17,7 @@ Source2: sensord.socket %define temperature_state OFF %define orientation_state ON %define gravity_state ON -%define linear_accel_state OFF +%define linear_accel_state ON %define build_test_suite OFF diff --git a/src/linear_accel/CMakeLists.txt b/src/linear_accel/CMakeLists.txt index b158f2b..6601d90 100755 --- a/src/linear_accel/CMakeLists.txt +++ b/src/linear_accel/CMakeLists.txt @@ -10,6 +10,7 @@ SET(SENSOR_NAME linear_accel_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) diff --git a/src/linear_accel/linear_accel_sensor.cpp b/src/linear_accel/linear_accel_sensor.cpp index 6967da0..794bef0 100755 --- a/src/linear_accel/linear_accel_sensor.cpp +++ b/src/linear_accel/linear_accel_sensor.cpp @@ -25,33 +25,104 @@ #include #include #include -#include #include #include -#include #include #include +#include #define SENSOR_NAME "LINEAR_ACCEL_SENSOR" +#define SENSOR_TYPE_LINEAR_ACCEL "LINEAR_ACCEL" + +#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_ACCEL_ROTATION_DIRECTION_COMPENSATION "ACCEL_ROTATION_DIRECTION_COMPENSATION" +#define ELEMENT_ACCEL_SCALE "ACCEL_SCALE" +#define ELEMENT_LINEAR_ACCEL_SIGN_COMPENSATION "LINEAR_ACCEL_SIGN_COMPENSATION" #define INITIAL_VALUE -1 -#define INITIAL_TIME 0 #define GRAVITY 9.80665 +#define MS_TO_US 1000 + +#define ACCELEROMETER_ENABLED 0x01 +#define GRAVITY_ENABLED 0x02 +#define LINEAR_ACCEL_ENABLED 3 + linear_accel_sensor::linear_accel_sensor() : m_gravity_sensor(NULL) +, m_accel_sensor(NULL) , m_x(INITIAL_VALUE) , m_y(INITIAL_VALUE) , m_z(INITIAL_VALUE) -, m_time(INITIAL_TIME) { + cvirtual_sensor_config &config = cvirtual_sensor_config::get_instance(); + m_name = string(SENSOR_NAME); + m_timestamp = get_timestamp(); + m_enable_linear_accel = 0; register_supported_event(LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME); + + + if (!config.get(SENSOR_TYPE_LINEAR_ACCEL, ELEMENT_VENDOR, m_vendor)) { + ERR("[VENDOR] is empty\n"); + throw ENXIO; + } + + INFO("m_vendor = %s", m_vendor.c_str()); + + if (!config.get(SENSOR_TYPE_LINEAR_ACCEL, ELEMENT_RAW_DATA_UNIT, m_raw_data_unit)) { + ERR("[RAW_DATA_UNIT] is empty\n"); + throw ENXIO; + } + + INFO("m_raw_data_unit = %s", m_raw_data_unit.c_str()); + + if (!config.get(SENSOR_TYPE_LINEAR_ACCEL, 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_LINEAR_ACCEL, ELEMENT_ACCEL_STATIC_BIAS, m_accel_static_bias, 3)) { + ERR("[ACCEL_STATIC_BIAS] is empty\n"); + throw ENXIO; + } + + if (!config.get(SENSOR_TYPE_LINEAR_ACCEL, 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_LINEAR_ACCEL, 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_LINEAR_ACCEL, ELEMENT_LINEAR_ACCEL_SIGN_COMPENSATION, m_linear_accel_sign_compensation, 3)) { + ERR("[LINEAR_ACCEL_SIGN_COMPENSATION] is empty\n"); + throw ENXIO; + } + + INFO("m_linear_accel_sign_compensation = (%d, %d, %d)", m_linear_accel_sign_compensation[0], m_linear_accel_sign_compensation[1], m_linear_accel_sign_compensation[2]); + + m_interval = m_default_sampling_time * MS_TO_US; + } linear_accel_sensor::~linear_accel_sensor() { - INFO("linear_accel_sensor is destroyed!"); + INFO("linear_accel_sensor is destroyed!\n"); } bool linear_accel_sensor::init() @@ -78,7 +149,13 @@ bool linear_accel_sensor::on_start(void) { AUTOLOCK(m_mutex); m_gravity_sensor->add_client(GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME); + m_gravity_sensor->add_interval((int)this, (m_interval/MS_TO_US), true); m_gravity_sensor->start(); + + m_accel_sensor->add_client(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME); + m_accel_sensor->add_interval((int)this, (m_interval/MS_TO_US), true); + m_accel_sensor->start(); + activate(); return true; } @@ -87,7 +164,13 @@ bool linear_accel_sensor::on_stop(void) { AUTOLOCK(m_mutex); m_gravity_sensor->delete_client(GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME); + m_gravity_sensor->delete_interval((int)this, true); m_gravity_sensor->stop(); + + m_accel_sensor->delete_client(ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME); + m_accel_sensor->delete_interval((int)this, true); + m_accel_sensor->stop(); + deactivate(); return true; } @@ -96,6 +179,8 @@ bool linear_accel_sensor::add_interval(int client_id, unsigned int interval) { AUTOLOCK(m_mutex); m_gravity_sensor->add_interval(client_id, interval, true); + m_accel_sensor->add_interval((int)this , interval, true); + return sensor_base::add_interval(client_id, interval, true); } @@ -103,27 +188,62 @@ bool linear_accel_sensor::delete_interval(int client_id) { AUTOLOCK(m_mutex); m_gravity_sensor->delete_interval(client_id, true); + m_accel_sensor->delete_interval(client_id, true); + return sensor_base::delete_interval(client_id, true); } void linear_accel_sensor::synthesize(const sensor_event_t &event, vector &outs) { - vector gravity_event; sensor_event_t lin_accel_event; - ((virtual_sensor *)m_gravity_sensor)->synthesize(event, gravity_event); - if (!gravity_event.empty() && event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) { + const float MIN_DELIVERY_DIFF_FACTOR = 0.75f; + unsigned long long diff_time; + + if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) { + diff_time = event.data.timestamp - m_timestamp; + + if (m_timestamp && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) + return; + + m_accel.m_data.m_vec[0] = m_accel_rotation_direction_compensation[0] * (event.data.values[0] - m_accel_static_bias[0]) / m_accel_scale; + m_accel.m_data.m_vec[1] = m_accel_rotation_direction_compensation[1] * (event.data.values[1] - m_accel_static_bias[1]) / m_accel_scale; + m_accel.m_data.m_vec[2] = m_accel_rotation_direction_compensation[2] * (event.data.values[2] - m_accel_static_bias[2]) / m_accel_scale; + + m_accel.m_time_stamp = event.data.timestamp; + + m_enable_linear_accel |= ACCELEROMETER_ENABLED; + } + else if (event.event_type == GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME) { + diff_time = event.data.timestamp - m_timestamp; + + if (m_timestamp && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) + return; + + m_gravity.m_data.m_vec[0] = event.data.values[0]; + m_gravity.m_data.m_vec[1] = event.data.values[1]; + m_gravity.m_data.m_vec[2] = event.data.values[2]; + + m_gravity.m_time_stamp = event.data.timestamp; + + m_enable_linear_accel |= GRAVITY_ENABLED; + } + + if (m_enable_linear_accel == LINEAR_ACCEL_ENABLED) { + m_enable_linear_accel = 0; + m_timestamp = get_timestamp(); + AUTOLOCK(m_value_mutex); - lin_accel_event.data.values_num = 3; - lin_accel_event.data.timestamp = gravity_event[0].data.timestamp; + lin_accel_event.sensor_id = get_id(); lin_accel_event.event_type = LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME; - lin_accel_event.data.data_accuracy = SENSOR_ACCURACY_GOOD; - lin_accel_event.data.data_unit_idx = SENSOR_UNIT_METRE_PER_SECOND_SQUARED; - lin_accel_event.data.values[0] = event.data.values[0] - gravity_event[0].data.values[0]; - lin_accel_event.data.values[1] = event.data.values[1] - gravity_event[0].data.values[1]; - lin_accel_event.data.values[2] = event.data.values[2] - gravity_event[0].data.values[2]; - outs.push_back(lin_accel_event); + lin_accel_event.data.value_count = 3; + lin_accel_event.data.timestamp = m_timestamp; + lin_accel_event.data.accuracy = SENSOR_ACCURACY_GOOD; + lin_accel_event.data.values[0] = m_linear_accel_sign_compensation[0] * (m_accel.m_data.m_vec[0] - m_gravity.m_data.m_vec[0]); + lin_accel_event.data.values[1] = m_linear_accel_sign_compensation[1] * (m_accel.m_data.m_vec[1] - m_gravity.m_data.m_vec[1]); + lin_accel_event.data.values[2] = m_linear_accel_sign_compensation[2] * (m_accel.m_data.m_vec[2] - m_gravity.m_data.m_vec[2]); + push(lin_accel_event); } return; @@ -135,27 +255,28 @@ int linear_accel_sensor::get_sensor_data(const unsigned int event_type, sensor_d ((virtual_sensor *)m_gravity_sensor)->get_sensor_data(GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME, gravity_data); m_accel_sensor->get_sensor_data(ACCELEROMETER_BASE_DATA_SET, accel_data); + accel_data.values[0] = m_accel_rotation_direction_compensation[0] * (accel_data.values[0] - m_accel_static_bias[0]) / m_accel_scale; + accel_data.values[1] = m_accel_rotation_direction_compensation[1] * (accel_data.values[1] - m_accel_static_bias[1]) / m_accel_scale; + accel_data.values[2] = m_accel_rotation_direction_compensation[2] * (accel_data.values[2] - m_accel_static_bias[2]) / m_accel_scale; + if (event_type != LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME) return -1; - data.data_accuracy = SENSOR_ACCURACY_GOOD; - data.data_unit_idx = SENSOR_UNIT_METRE_PER_SECOND_SQUARED; - data.timestamp = gravity_data.timestamp; - data.values[0] = accel_data.values[0] - gravity_data.values[0]; - data.values[1] = accel_data.values[1] - gravity_data.values[1]; - data.values[2] = accel_data.values[2] - gravity_data.values[2]; - data.values_num = 3; + data.accuracy = SENSOR_ACCURACY_GOOD; + data.timestamp = get_timestamp(); + data.values[0] = m_linear_accel_sign_compensation[0] * (accel_data.values[0] - gravity_data.values[0]); + data.values[1] = m_linear_accel_sign_compensation[1] * (accel_data.values[1] - gravity_data.values[1]); + data.values[2] = m_linear_accel_sign_compensation[2] * (accel_data.values[2] - gravity_data.values[2]); + data.value_count = 3; return 0; } -bool linear_accel_sensor::get_properties(const unsigned int type, sensor_properties_t &properties) +bool linear_accel_sensor::get_properties(sensor_properties_t &properties) { - m_gravity_sensor->get_properties(type, properties); - - if (type != LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME) - return true; + m_gravity_sensor->get_properties(properties); + properties.name = "Linear Acceleration Sensor"; + properties.vendor = m_vendor; - strncpy(properties.sensor_name, "Linear Accelerometer Sensor", MAX_KEY_LENGTH); return true; } diff --git a/src/linear_accel/linear_accel_sensor.h b/src/linear_accel/linear_accel_sensor.h index 1616392..273fa84 100755 --- a/src/linear_accel/linear_accel_sensor.h +++ b/src/linear_accel/linear_accel_sensor.h @@ -20,15 +20,11 @@ #ifndef _LINEAR_ACCEL_SENSOR_H_ #define _LINEAR_ACCEL_SENSOR_H_ -#include -#include -#include +#include #include +#include -using std::string; - -class linear_accel_sensor : public virtual_sensor -{ +class linear_accel_sensor : public virtual_sensor { public: linear_accel_sensor(); virtual ~linear_accel_sensor(); @@ -36,27 +32,39 @@ public: bool init(); sensor_type_t get_type(void); - static bool working(void *inst); - - bool on_start(void); - bool on_stop(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); int get_sensor_data(const unsigned int event_type, sensor_data_t &data); - bool get_properties(const unsigned int type, sensor_properties_t &properties); + bool get_properties(sensor_properties_t &properties); private: sensor_base *m_accel_sensor; sensor_base *m_gravity_sensor; cmutex m_value_mutex; + sensor_data m_accel; + sensor_data m_gravity; + float m_x; float m_y; float m_z; - unsigned long long m_time; + unsigned long long m_timestamp; + unsigned int m_interval; + + unsigned int m_enable_linear_accel; + + string m_vendor; + string m_raw_data_unit; + int m_default_sampling_time; + float m_accel_static_bias[3]; + int m_accel_rotation_direction_compensation[3]; + float m_accel_scale; + int m_linear_accel_sign_compensation[3]; + + bool on_start(void); + bool on_stop(void); }; -#endif /*_LINEAR_ACCEL_SENSOR_H_*/ +#endif -- 2.7.4 From fec0e8f54ebe88fb558f51566cdbb893dd2caeec Mon Sep 17 00:00:00 2001 From: Vibhor Gaur Date: Fri, 21 Nov 2014 15:35:04 +0530 Subject: [PATCH 10/16] Synchronizing light sensor plugin with addition of IIO interface support Change-Id: Icd70f7833feef03ce6d9daf7dd4aabf721d5d146 --- packaging/sensord.spec | 3 +- src/light/light_sensor.cpp | 8 +- src/light/light_sensor_hal.cpp | 192 +++++++++++++++++++---------------------- src/light/light_sensor_hal.h | 39 +++++---- 4 files changed, 114 insertions(+), 128 deletions(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index eb9d4c2..c7e8946 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -11,7 +11,7 @@ Source2: sensord.socket %define accel_state ON %define gyro_state ON %define proxi_state ON -%define light_state OFF +%define light_state ON %define geo_state ON %define pressure_state OFF %define temperature_state OFF @@ -144,6 +144,7 @@ systemctl daemon-reload /usr/bin/gyro /usr/bin/proxi /usr/bin/pressure + %license LICENSE.APLv2 %{_datadir}/license/test %endif diff --git a/src/light/light_sensor.cpp b/src/light/light_sensor.cpp index 4c8481d..af222e1 100755 --- a/src/light/light_sensor.cpp +++ b/src/light/light_sensor.cpp @@ -159,10 +159,9 @@ bool light_sensor::get_properties(const unsigned int type, sensor_properties_t & return 0; if (type == LIGHT_BASE_DATA_SET) { - properties.sensor_unit_idx = SENSOR_UNIT_LEVEL; - properties.sensor_min_range = 0; - properties.sensor_max_range = sizeof(m_light_level) / sizeof(m_light_level[0]) - 1; - properties.sensor_resolution = 1; + properties.min_range = 0; + properties.max_range = sizeof(m_light_level) / sizeof(m_light_level[0]) - 1; + properties.resolution = 1; return 0; } @@ -198,7 +197,6 @@ bool light_sensor::set_interval(unsigned long interval) void light_sensor::raw_to_level(sensor_data_t &data) { - data.data_unit_idx = SENSOR_UNIT_LEVEL; data.values[0] = (int) adc_to_light_level((int)data.values[0]); data.values_num = 1; } diff --git a/src/light/light_sensor_hal.cpp b/src/light/light_sensor_hal.cpp index b429ffc..6498728 100755 --- a/src/light/light_sensor_hal.cpp +++ b/src/light/light_sensor_hal.cpp @@ -1,5 +1,5 @@ /* - * sensord + * light_sensor_hal * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * @@ -16,65 +16,106 @@ * limitations under the License. * */ - #include #include #include -#include #include + #include #include + #include +#include #include using std::ifstream; using config::csensor_config; -#define BIAS 1 -#define INITIAL_VALUE -1 -#define INITIAL_TIME 0 -#define NO_OF_DATA_VAL 1 - #define SENSOR_TYPE_LIGHT "LIGHT" #define ELEMENT_NAME "NAME" #define ELEMENT_VENDOR "VENDOR" #define ELEMENT_RAW_DATA_UNIT "RAW_DATA_UNIT" #define ELEMENT_RESOLUTION "RESOLUTION" #define ATTR_VALUE "value" +#define INITIAL_TIME -1 +#define BIAS 1 +#define INVALID_VALUE -1 +#define INITIAL_VALUE -1 light_sensor_hal::light_sensor_hal() -: m_adc(INITIAL_VALUE) -, m_sensorhub_supported(false) +: m_polling_interval(POLL_1HZ_MS) +, m_adc(INVALID_VALUE) +, m_fired_time(INITIAL_TIME) +, m_node_handle(-1) { - if (!check_hw_node()) - { - ERR("check_hw_node() fail"); + const string sensorhub_interval_node_name = "light_poll_delay"; + csensor_config &config = csensor_config::get_instance(); + + node_path_info_query query; + node_path_info info; + int input_method = IIO_METHOD; + + if (!get_model_properties(SENSOR_TYPE_LIGHT, m_model_id, input_method)) { + ERR("Failed to find model_properties"); throw ENXIO; + } - csensor_config &config = csensor_config::get_instance(); + query.input_method = IIO_METHOD; + query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name); + query.sensor_type = SENSOR_TYPE_LIGHT; + query.input_event_key = "light_sensor"; + query.iio_enable_node_name = "light_enable"; + query.sensorhub_interval_node_name = sensorhub_interval_node_name; - if (!config.get(SENSOR_TYPE_LIGHT, m_model_id, ELEMENT_VENDOR, m_vendor)) - { - ERR("[VENDOR] is empty"); + if (!get_node_path_info(query, info)) { + ERR("Failed to get node info"); + throw ENXIO; + } + + show_node_path_info(info); + + m_data_node = info.data_node_path; + m_enable_node = info.enable_node_path; + m_interval_node = info.interval_node_path; + + if(input_method == IIO_METHOD) { + m_light_dir=info.base_dir; + m_light_node = m_light_dir + string(ILL_CLEAR_NODE); + + INFO("m_light_node = %s", m_light_node.c_str()); + INFO("m_light_dir = %s", m_light_dir.c_str()); + } + + if (!config.get(SENSOR_TYPE_LIGHT, m_model_id, ELEMENT_VENDOR, m_vendor)) { + ERR("[VENDOR] is empty\n"); throw ENXIO; } INFO("m_vendor = %s", m_vendor.c_str()); - if (!config.get(SENSOR_TYPE_LIGHT, m_model_id, ELEMENT_NAME, m_chip_name)) - { - ERR("[NAME] is empty"); + if (!config.get(SENSOR_TYPE_LIGHT, m_model_id, ELEMENT_NAME, m_chip_name)) { + ERR("[NAME] is empty\n"); throw ENXIO; } - INFO("m_chip_name = %s", m_chip_name.c_str()); - INFO("light_sensor_hal is created!"); + INFO("m_chip_name = %s\n",m_chip_name.c_str()); + + if ((m_node_handle = open(m_light_node.c_str(),O_RDWR)) < 0) { + ERR("Failed to open handle(%d)", m_node_handle); + throw ENXIO; + } + + INFO("light_sensor_hal is created!\n"); + } light_sensor_hal::~light_sensor_hal() { - INFO("light_sensor_hal is destroyed!"); + close(m_node_handle); + m_node_handle = -1; + + INFO("light_sensor_hal is destroyed!\n"); } string light_sensor_hal::get_model_id(void) @@ -82,6 +123,7 @@ string light_sensor_hal::get_model_id(void) return m_model_id; } + sensor_type_t light_sensor_hal::get_type(void) { return LIGHT_SENSOR; @@ -89,26 +131,28 @@ sensor_type_t light_sensor_hal::get_type(void) bool light_sensor_hal::enable(void) { - INFO("Resource already enabled. Enable not supported."); + m_fired_time = INITIAL_TIME; + INFO("Light sensor real starting"); return true; } bool light_sensor_hal::disable(void) { - INFO("Disable not supported."); + INFO("Light sensor real stopping"); return true; } bool light_sensor_hal::set_interval(unsigned long val) { - INFO("Polling not supported. Polling interval cannot be changed."); return true; } -bool light_sensor_hal::update_value(void) + +bool light_sensor_hal::update_value(bool wait) { + unsigned short int adc = INITIAL_VALUE; - if (!read_node_value(m_clear_raw_node, adc)) + if (!read_node_value(m_light_node, adc)) { INFO("Read Value Failed. clear val: %d", adc); return false; @@ -118,99 +162,41 @@ bool light_sensor_hal::update_value(void) m_adc = (int)adc; return true; + } bool light_sensor_hal::is_data_ready(bool wait) { bool ret; - ret = update_value(); + ret = update_value(wait); return ret; } int light_sensor_hal::get_sensor_data(sensor_data_t &data) { AUTOLOCK(m_value_mutex); - data.data_accuracy = SENSOR_ACCURACY_GOOD; - data.data_unit_idx = SENSOR_UNIT_LUX; - data.timestamp = INITIAL_TIME; - data.values_num = NO_OF_DATA_VAL; + data.accuracy = SENSOR_ACCURACY_GOOD; + data.timestamp = m_fired_time ; + data.value_count = 1; data.values[0] = (float) m_adc; return 0; } + bool light_sensor_hal::get_properties(sensor_properties_t &properties) { - properties.sensor_unit_idx = SENSOR_UNIT_LUX; - properties.sensor_min_range = 0; - properties.sensor_max_range = 65536; - snprintf(properties.sensor_name, sizeof(properties.sensor_name), "%s", m_chip_name.c_str()); - snprintf(properties.sensor_vendor, sizeof(properties.sensor_vendor), "%s", m_vendor.c_str()); - properties.sensor_resolution = 1.0f; + properties.name = m_chip_name; + properties.vendor = m_vendor; + properties.min_range = 0; + properties.max_range = 65536; + properties.min_interval = 1; + properties.resolution = 1; + properties.fifo_count = 0; + properties.max_batch_count = 0; return true; } -bool light_sensor_hal::is_sensorhub_supported(void) -{ - return false; -} - -bool light_sensor_hal::check_hw_node(void) -{ - string name_node; - string hw_name; - string file_name; - DIR *main_dir = NULL; - struct dirent *dir_entry = NULL; - bool find_node = false; - - INFO("======================start check_hw_node============================="); - - m_sensorhub_supported = is_sensorhub_supported(); - main_dir = opendir(IIO_DIR); - - if (!main_dir) - { - ERR("Directory open failed to collect data"); - return false; - } - - while (!find_node) - { - dir_entry = readdir(main_dir); - if(dir_entry == NULL) - break; - - if ((strncasecmp(dir_entry->d_name , ".", 1 ) != 0) && (strncasecmp(dir_entry->d_name , "..", 2 ) != 0) && (dir_entry->d_ino != 0)) - { - file_name = string(IIO_DIR) + string(dir_entry->d_name) + string(NAME_NODE); - - ifstream infile(file_name.c_str()); - - if (!infile) - continue; - - infile >> hw_name; - - if (strncmp(dir_entry->d_name, IIO_DEV_BASE_NAME, IIO_DEV_STR_LEN) == 0) - { - if (CConfig::get_instance().is_supported(SENSOR_TYPE_LIGHT, hw_name) == true) - { - m_name = m_model_id = hw_name; - m_clear_raw_node = string(IIO_DIR) + string(dir_entry->d_name) + string(ILL_CLEAR_NODE); - INFO("m_model_id = %s", m_model_id.c_str()); - INFO("m_clear_raw_node = %s", m_clear_raw_node.c_str()); - find_node = true; - break; - } - } - } - } - closedir(main_dir); - - return find_node; -} - extern "C" void *create(void) { light_sensor_hal *inst; @@ -218,14 +204,14 @@ extern "C" void *create(void) try { inst = new light_sensor_hal(); } catch (int err) { - ERR("Failed to create light_sensor_hal class, errno : %d, errstr : %s", err, strerror(err)); + ERR("light_sensor_hal class create fail , errno : %d , errstr : %s\n", err, strerror(err)); return NULL; } - return (void *)inst; + return (void*)inst; } extern "C" void destroy(void *inst) { - delete (light_sensor_hal *)inst; + delete (light_sensor_hal*)inst; } diff --git a/src/light/light_sensor_hal.h b/src/light/light_sensor_hal.h index 30c53f2..ec35104 100755 --- a/src/light/light_sensor_hal.h +++ b/src/light/light_sensor_hal.h @@ -1,5 +1,5 @@ /* - * sensord + * light_sensor_hal * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * @@ -19,17 +19,10 @@ #ifndef _LIGHT_SENSOR_HAL_H_ #define _LIGHT_SENSOR_HAL_H_ - +#define ILL_CLEAR_NODE "in_illuminance_clear_raw" #include #include -#define IIO_DIR "/sys/bus/iio/devices/" -#define NAME_NODE "/name" -#define ILL_CLEAR_NODE "/in_illuminance_clear_raw" - -#define IIO_DEV_BASE_NAME "iio:device" -#define IIO_DEV_STR_LEN 10 - using std::string; class light_sensor_hal : public sensor_hal @@ -45,21 +38,29 @@ public: bool is_data_ready(bool wait); virtual int get_sensor_data(sensor_data_t &data); bool get_properties(sensor_properties_t &properties); - bool check_hw_node(void); - private: - int m_adc; - bool m_sensorhub_supported; - string m_model_id; - string m_name; string m_vendor; string m_chip_name; - cmutex m_value_mutex; + unsigned long m_polling_interval; + + int m_adc; + + unsigned long long m_fired_time; + int m_node_handle; + + string m_enable_node; + string m_data_node; + string m_interval_node; string m_clear_raw_node; + string m_light_dir; + string m_light_node; + + bool m_sensorhub_controlled; + + cmutex m_value_mutex; - bool update_value(void); - bool is_sensorhub_supported(void); + bool update_value(bool wait); }; -#endif /*_LIGHT_SENSOR_HAL_H_*/ +#endif /*_GYRO_SENSOR_HAL_CLASS_H_*/ -- 2.7.4 From 4e843927e279ed03c43a8e4f17baf4a793439b62 Mon Sep 17 00:00:00 2001 From: Amit Dharmapurikar Date: Fri, 21 Nov 2014 18:08:58 +0530 Subject: [PATCH 11/16] Synchronizing pressure sensor plugin with addition of IIO interface support Change-Id: I298a4e11dd2944724988d0fce061f4fee7a3e459 Signed-off-by: Amit Dharmapurikar --- packaging/sensord.spec | 2 +- src/pressure/CMakeLists.txt | 2 +- src/pressure/pressure_sensor.cpp | 50 +++---- src/pressure/pressure_sensor.h | 8 +- src/pressure/pressure_sensor_hal.cpp | 248 ++++++++++++++--------------------- src/pressure/pressure_sensor_hal.h | 35 ++--- 6 files changed, 133 insertions(+), 212 deletions(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index eb9d4c2..c9e381a 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -13,7 +13,7 @@ Source2: sensord.socket %define proxi_state ON %define light_state OFF %define geo_state ON -%define pressure_state OFF +%define pressure_state ON %define temperature_state OFF %define orientation_state OFF %define gravity_state OFF diff --git a/src/pressure/CMakeLists.txt b/src/pressure/CMakeLists.txt index b1984d0..ea13698 100755 --- a/src/pressure/CMakeLists.txt +++ b/src/pressure/CMakeLists.txt @@ -15,7 +15,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src/libsensord) include(FindPkgConfig) pkg_check_modules(rpkgs REQUIRED vconf) -add_definitions(${rpkgs_CFLAGS} -DUSE_ONLY_ONE_MODULE) +add_definitions(${rpkgs_CFLAGS} -DUSE_ONLY_ONE_MODULE -DUSE_LCD_TYPE_CHECK) set(PROJECT_MAJOR_VERSION "0") set(PROJECT_MINOR_VERSION "0") diff --git a/src/pressure/pressure_sensor.cpp b/src/pressure/pressure_sensor.cpp index 35461a7..710c86a 100755 --- a/src/pressure/pressure_sensor.cpp +++ b/src/pressure/pressure_sensor.cpp @@ -29,17 +29,15 @@ using config::csensor_config; using std::bind1st; using std::mem_fun; -#define SENSOR_NAME "PRESSURE_SENSOR" -#define SENSOR_TYPE_PRESSURE "PRESSURE" +#define SENSOR_NAME "PRESSURE_SENSOR" +#define SENSOR_TYPE_PRESSURE "PRESSURE" #define ELEMENT_NAME "NAME" #define ELEMENT_VENDOR "VENDOR" #define ELEMENT_TEMPERATURE_RESOLUTION "TEMPERATURE_RESOLUTION" #define ELEMENT_TEMPERATURE_OFFSET "TEMPERATURE_OFFSET" #define ATTR_VALUE "value" -#define SEA_LEVEL_RESOLUTION 0.01 -#define ALT_CONST1 44330.0 -#define ALT_CONST2 (1.0f/5.255f) +#define SEA_LEVEL_RESOLUTION 0.01 pressure_sensor::pressure_sensor() : m_sensor_hal(NULL) @@ -61,21 +59,19 @@ bool pressure_sensor::init() { m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(PRESSURE_SENSOR); - if (!m_sensor_hal) - { + if (!m_sensor_hal) { ERR("cannot load sensor_hal[%s]", sensor_base::get_name()); return false; } sensor_properties_t properties; - if (m_sensor_hal->get_properties(properties) == false) - { + if (!m_sensor_hal->get_properties(properties)) { ERR("sensor->get_properties() is failed!\n"); return false; } - m_resolution = properties.sensor_resolution; + m_resolution = properties.resolution; string model_id = m_sensor_hal->get_model_id(); @@ -83,8 +79,7 @@ bool pressure_sensor::init() double temperature_resolution; - if (!config.get(SENSOR_TYPE_PRESSURE, model_id, ELEMENT_TEMPERATURE_RESOLUTION, temperature_resolution)) - { + if (!config.get(SENSOR_TYPE_PRESSURE, model_id, ELEMENT_TEMPERATURE_RESOLUTION, temperature_resolution)) { ERR("[TEMPERATURE_RESOLUTION] is empty\n"); throw ENXIO; } @@ -94,8 +89,7 @@ bool pressure_sensor::init() double temperature_offset; - if (!config.get(SENSOR_TYPE_PRESSURE, model_id, ELEMENT_TEMPERATURE_OFFSET, temperature_offset)) - { + if (!config.get(SENSOR_TYPE_PRESSURE, model_id, ELEMENT_TEMPERATURE_OFFSET, temperature_offset)) { ERR("[TEMPERATURE_OFFSET] is empty\n"); throw ENXIO; } @@ -122,7 +116,6 @@ bool pressure_sensor::working(void *inst) bool pressure_sensor::process_event(void) { sensor_event_t event; - int pressure; if (!m_sensor_hal->is_data_ready(true)) return true; @@ -131,8 +124,8 @@ bool pressure_sensor::process_event(void) AUTOLOCK(m_client_info_mutex); - if (get_client_cnt(PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME)) - { + if (get_client_cnt(PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME)) { + event.sensor_id = get_id(); event.event_type = PRESSURE_EVENT_RAW_DATA_REPORT_ON_TIME; raw_to_base(event.data); push(event); @@ -143,8 +136,7 @@ bool pressure_sensor::process_event(void) bool pressure_sensor::on_start(void) { - if (!m_sensor_hal->enable()) - { + if (!m_sensor_hal->enable()) { ERR("m_sensor_hal start fail\n"); return false; } @@ -154,8 +146,7 @@ bool pressure_sensor::on_start(void) bool pressure_sensor::on_stop(void) { - if (!m_sensor_hal->disable()) - { + if (!m_sensor_hal->disable()) { ERR("m_sensor_hal stop fail\n"); return false; } @@ -163,12 +154,12 @@ bool pressure_sensor::on_stop(void) return stop_poll(); } -bool pressure_sensor::get_properties(const unsigned int type, sensor_properties_t &properties) +bool pressure_sensor::get_properties(sensor_properties_t &properties) { return m_sensor_hal->get_properties(properties); } -int pressure_sensor::get_sensor_data(const unsigned int type, sensor_data_t &data) +int pressure_sensor::get_sensor_data(unsigned int type, sensor_data_t &data) { int ret; @@ -177,8 +168,7 @@ int pressure_sensor::get_sensor_data(const unsigned int type, sensor_data_t &dat if (ret < 0) return -1; - if (type == PRESSURE_BASE_DATA_SET) - { + if (type == PRESSURE_BASE_DATA_SET) { raw_to_base(data); return 0; } @@ -197,25 +187,23 @@ bool pressure_sensor::set_interval(unsigned long interval) float pressure_sensor::pressure_to_altitude(float pressure) { - return ALT_CONST1 * (1.0f - pow(pressure/m_sea_level_pressure, ALT_CONST2)); + return 44330.0f * (1.0f - pow(pressure/m_sea_level_pressure, 1.0f/5.255f)); } void pressure_sensor::raw_to_base(sensor_data_t &data) { m_sea_level_pressure = data.values[1] * SEA_LEVEL_RESOLUTION; data.values[1] = pressure_to_altitude(data.values[0]); + data.value_count = 3; } extern "C" void *create(void) { pressure_sensor *inst; - try - { + try { inst = new pressure_sensor(); - } - catch (int err) - { + } catch (int err) { ERR("pressure_sensor class create fail , errno : %d , errstr : %s\n", err, strerror(err)); return NULL; } diff --git a/src/pressure/pressure_sensor.h b/src/pressure/pressure_sensor.h index 2124f6c..1da5cab 100755 --- a/src/pressure/pressure_sensor.h +++ b/src/pressure/pressure_sensor.h @@ -25,8 +25,7 @@ #include #include -class pressure_sensor : public physical_sensor -{ +class pressure_sensor : public physical_sensor { public: pressure_sensor(); virtual ~pressure_sensor(); @@ -37,8 +36,8 @@ public: static bool working(void *inst); bool set_interval(unsigned long interval); - bool get_properties(const unsigned int type, sensor_properties_t &properties); - int get_sensor_data(const unsigned int type, sensor_data_t &data); + virtual bool get_properties(sensor_properties_t &properties); + int get_sensor_data(unsigned int type, sensor_data_t &data); private: sensor_hal *m_sensor_hal; @@ -53,6 +52,7 @@ private: bool process_event(void); float pressure_to_altitude(float pressure); void raw_to_base(sensor_data_t &data); + }; #endif diff --git a/src/pressure/pressure_sensor_hal.cpp b/src/pressure/pressure_sensor_hal.cpp index 764adc9..2823baa 100755 --- a/src/pressure/pressure_sensor_hal.cpp +++ b/src/pressure/pressure_sensor_hal.cpp @@ -21,55 +21,87 @@ #include #include #include -#include #include +#include #include +#include #include using std::ifstream; +using std::string; using config::csensor_config; #define SENSOR_TYPE_PRESSURE "PRESSURE" #define ELEMENT_NAME "NAME" #define ELEMENT_VENDOR "VENDOR" #define ELEMENT_RAW_DATA_UNIT "RAW_DATA_UNIT" +#define ELEMENT_RESOLUTION "RESOLUTION" #define ELEMENT_MIN_RANGE "MIN_RANGE" #define ELEMENT_MAX_RANGE "MAX_RANGE" +#define ELEMENT_TEMPERATURE_RESOLUTION "TEMPERATURE_RESOLUTION" +#define ELEMENT_TEMPERATURE_OFFSET "TEMPERATURE_OFFSET" +#define ATTR_VALUE "value" + +#define SEA_LEVEL_PRESSURE 101325.0 -#define ENABLE_VAL true -#define DISABLE_VAL false -#define SEA_LEVEL_PRESSURE 101325.0 -#define NO_FLAG 0 -#define TIMEOUT 1 +#define EVENT_EN_NODE "events/in_pressure_mag_either_en" +#define PRESSURE_SCALE "/in_pressure_scale" +#define PRESSURE_RAW "/in_pressure_raw" +#define TEMP_OFFSET "/in_temp_offset" +#define TEMP_SCALE "/in_temp_scale" +#define TEMP_RAW "/in_temp_raw" +#define NO_FLAG 0 +#define TIMEOUT 1 pressure_sensor_hal::pressure_sensor_hal() : m_pressure(0) , m_temperature(0) , m_polling_interval(POLL_1HZ_MS) , m_fired_time(0) -, m_sensorhub_supported(false) +, m_node_handle(-1) { - int fd, ret; - string file_name; + const string sensorhub_interval_node_name = "pressure_poll_delay"; + csensor_config &config = csensor_config::get_instance(); - if (!check_hw_node()) - { - ERR("check_hw_node() fail"); + node_path_info_query query; + node_path_info info; + int input_method = IIO_METHOD; + + if (!get_model_properties(SENSOR_TYPE_PRESSURE, m_model_id, input_method)) { + ERR("Failed to find model_properties"); throw ENXIO; + } - csensor_config &config = csensor_config::get_instance(); + query.input_method = input_method; + query.sensorhub_controlled = m_sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name); + query.sensor_type = SENSOR_TYPE_PRESSURE; + query.input_event_key = "pressure_sensor"; + query.iio_enable_node_name = EVENT_EN_NODE; + query.sensorhub_interval_node_name = sensorhub_interval_node_name; + + if (!get_node_path_info(query, info)) { + ERR("Failed to get node info"); + throw ENXIO; + } + m_data_node = info.data_node_path; + m_pressure_dir = info.base_dir; + m_enable_node = info.enable_node_path; + m_pressure_node = m_pressure_dir + string(PRESSURE_RAW); + m_temp_node = m_pressure_dir + string(TEMP_RAW); + + INFO("m_data_node:%s",m_data_node.c_str()); + INFO("m_pressure_dir:%s",m_pressure_dir.c_str()); + INFO("m_enable_node:%s",m_enable_node.c_str()); - if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_VENDOR, m_vendor)) - { + if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_VENDOR, m_vendor)) { ERR("[VENDOR] is empty\n"); throw ENXIO; } INFO("m_vendor = %s", m_vendor.c_str()); - if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_NAME, m_chip_name)) - { + if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_NAME, m_chip_name)) { ERR("[NAME] is empty\n"); throw ENXIO; } @@ -78,8 +110,7 @@ pressure_sensor_hal::pressure_sensor_hal() double min_range; - if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_MIN_RANGE, min_range)) - { + if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_MIN_RANGE, min_range)) { ERR("[MIN_RANGE] is empty\n"); throw ENXIO; } @@ -89,8 +120,7 @@ pressure_sensor_hal::pressure_sensor_hal() double max_range; - if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_MAX_RANGE, max_range)) - { + if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_MAX_RANGE, max_range)) { ERR("[MAX_RANGE] is empty\n"); throw ENXIO; } @@ -100,8 +130,7 @@ pressure_sensor_hal::pressure_sensor_hal() double raw_data_unit; - if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit)) - { + if (!config.get(SENSOR_TYPE_PRESSURE, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit)) { ERR("[RAW_DATA_UNIT] is empty\n"); throw ENXIO; } @@ -109,15 +138,17 @@ pressure_sensor_hal::pressure_sensor_hal() m_raw_data_unit = (float)(raw_data_unit); INFO("m_raw_data_unit = %f\n", m_raw_data_unit); - file_name = string(IIO_DIR) + m_pressure_dir + string(TEMP_SCALE); + string file_name; + + file_name = m_pressure_dir + string(TEMP_SCALE); if (!read_node_value(file_name, m_temp_scale)) throw ENXIO; - file_name = string(IIO_DIR) + m_pressure_dir + string(TEMP_OFFSET); + file_name = m_pressure_dir + string(TEMP_OFFSET); if (!read_node_value(file_name, m_temp_offset)) throw ENXIO; - file_name = string(IIO_DIR) + m_pressure_dir + string(PRESSURE_SCALE); + file_name = m_pressure_dir + string(PRESSURE_SCALE); if (!read_node_value(file_name, m_pressure_scale)) throw ENXIO; @@ -125,20 +156,19 @@ pressure_sensor_hal::pressure_sensor_hal() INFO("Temperature offset:%f", m_temp_offset); INFO("Pressure scale:%d", m_pressure_scale); - fd = open(m_event_resource.c_str(), NO_FLAG); - if (fd == -1) - { + int fd, ret; + fd = open(m_data_node.c_str(), NO_FLAG); + if (fd == -1) { ERR("Could not open event resource"); throw ENXIO; } - ret = ioctl(fd, IOCTL_IIO_EVENT_FD, &m_event_fd); + ret = ioctl(fd, IOCTL_IIO_EVENT_FD, &m_node_handle); close(fd); - if ((ret == -1) || (m_event_fd == -1)) - { - ERR("Failed to retrieve event fd"); + if ((ret == -1) || (m_node_handle == -1)) { + ERR("Failed to retrieve node handle from event node: %s", m_data_node.c_str()); throw ENXIO; } @@ -147,7 +177,9 @@ pressure_sensor_hal::pressure_sensor_hal() pressure_sensor_hal::~pressure_sensor_hal() { - close(m_event_fd); + close(m_node_handle); + m_node_handle = -1; + INFO("pressure_sensor_hal is destroyed!\n"); } @@ -161,17 +193,11 @@ sensor_type_t pressure_sensor_hal::get_type(void) return PRESSURE_SENSOR; } -bool pressure_sensor_hal::enable_resource(bool enable) -{ - update_sysfs_num(m_enable_resource.c_str(), enable); - return true; -} - bool pressure_sensor_hal::enable(void) { AUTOLOCK(m_mutex); - - enable_resource(ENABLE_VAL); + update_sysfs_num(m_enable_node.c_str(), true); + set_interval(m_polling_interval); m_fired_time = 0; INFO("Pressure sensor real starting"); @@ -182,7 +208,7 @@ bool pressure_sensor_hal::disable(void) { AUTOLOCK(m_mutex); - enable_resource(DISABLE_VAL); + update_sysfs_num(m_enable_node.c_str(), false); INFO("Pressure sensor real stopping"); return true; @@ -190,6 +216,7 @@ bool pressure_sensor_hal::disable(void) bool pressure_sensor_hal::set_interval(unsigned long val) { + INFO("set_interval not supported"); return true; } @@ -204,47 +231,40 @@ bool pressure_sensor_hal::update_value(bool wait) FD_ZERO(&readfds); FD_ZERO(&exceptfds); - FD_SET(m_event_fd, &readfds); - FD_SET(m_event_fd, &exceptfds); + FD_SET(m_node_handle, &readfds); + FD_SET(m_node_handle, &exceptfds); - if (wait) - { + if (wait) { tv.tv_sec = TIMEOUT; tv.tv_usec = 0; } - else - { + else { tv.tv_sec = 0; tv.tv_usec = 0; } - ret = select(m_event_fd + 1, &readfds, NULL, &exceptfds, &tv); + ret = select(m_node_handle + 1, &readfds, NULL, &exceptfds, &tv); - if (ret == -1) - { - ERR("select error:%s m_event_fd:d", strerror(errno), m_event_fd); + if (ret == -1) { + ERR("select error:%s m_node_handle:d", strerror(errno), m_node_handle); return false; } - else if (!ret) - { + else if (!ret) { DBG("select timeout"); return false; } - if (FD_ISSET(m_event_fd, &exceptfds)) - { + if (FD_ISSET(m_node_handle, &exceptfds)) { ERR("select exception occurred!"); return false; } - if (FD_ISSET(m_event_fd, &readfds)) - { + if (FD_ISSET(m_node_handle, &readfds)) { INFO("pressure event detection!"); - int len = read(m_event_fd, &pressure_event, sizeof(pressure_event)); + int len = read(m_node_handle, &pressure_event, sizeof(pressure_event)); - if (len == -1) - { - DBG("Error in read(m_event_fd):%s.", strerror(errno)); + if (len == -1) { + ERR("Error in read(m_event_fd):%s.", strerror(errno)); return false; } m_fired_time = pressure_event.timestamp; @@ -255,12 +275,12 @@ bool pressure_sensor_hal::update_value(bool wait) m_pressure = ((float)raw_pressure_count)/((float)m_pressure_scale); m_temperature = m_temp_offset + ((float)raw_temp_count)/((float)m_temp_scale); } - else - { + else { ERR("No pressure event data available to read"); return false; } return true; + } bool pressure_sensor_hal::is_data_ready(bool wait) @@ -273,10 +293,9 @@ bool pressure_sensor_hal::is_data_ready(bool wait) int pressure_sensor_hal::get_sensor_data(sensor_data_t &data) { AUTOLOCK(m_value_mutex); - data.data_accuracy = SENSOR_ACCURACY_GOOD; - data.data_unit_idx = SENSOR_UNIT_HECTOPASCAL; + data.accuracy = SENSOR_ACCURACY_GOOD; data.timestamp = m_fired_time ; - data.values_num = 3; + data.value_count = 3; data.values[0] = m_pressure; data.values[1] = SEA_LEVEL_PRESSURE; data.values[2] = m_temperature; @@ -284,98 +303,27 @@ int pressure_sensor_hal::get_sensor_data(sensor_data_t &data) return 0; } + bool pressure_sensor_hal::get_properties(sensor_properties_t &properties) { - properties.sensor_unit_idx = SENSOR_UNIT_HECTOPASCAL; - properties.sensor_min_range = m_min_range; - properties.sensor_max_range = m_max_range; - snprintf(properties.sensor_name, sizeof(properties.sensor_name), "%s", m_chip_name.c_str()); - snprintf(properties.sensor_vendor, sizeof(properties.sensor_vendor), "%s", m_vendor.c_str()); - properties.sensor_resolution = m_raw_data_unit; + properties.name = m_chip_name; + properties.vendor = m_vendor; + properties.min_range = m_min_range; + properties.max_range = m_max_range; + properties.min_interval = 1; + properties.resolution = m_raw_data_unit; + properties.fifo_count = 0; + properties.max_batch_count = 0; return true; } -bool pressure_sensor_hal::is_sensorhub_supported(void) -{ - return false; -} - -bool pressure_sensor_hal::check_hw_node(void) -{ - string name_node; - string hw_name; - string file_name; - - DIR *main_dir = NULL; - struct dirent *dir_entry = NULL; - bool find_node = false; - - INFO("======================start check_hw_node=============================\n"); - - m_sensorhub_supported = is_sensorhub_supported(); - - main_dir = opendir(IIO_DIR); - - if (!main_dir) - { - ERR("Could not open IIO directory\n"); - return false; - } - - while (!find_node) - { - dir_entry = readdir(main_dir); - if(dir_entry == NULL) - break; - - if ((strncasecmp(dir_entry->d_name ,".",1 ) != 0) && (strncasecmp(dir_entry->d_name ,"..",2 ) != 0) && (dir_entry->d_ino != 0)) - { - file_name = string(IIO_DIR) + string(dir_entry->d_name) + string(NAME_NODE); - - ifstream infile(file_name.c_str()); - - if (!infile) - continue; - - infile >> hw_name; - - if (strncmp(dir_entry->d_name, IIO_DEV_BASE_NAME, IIO_DEV_STR_LEN) == 0) - { - if (CConfig::get_instance().is_supported(SENSOR_TYPE_PRESSURE, hw_name) == true) - { - m_name = m_model_id = hw_name; - m_pressure_dir = string(dir_entry->d_name); - m_enable_resource = string(IIO_DIR) + m_pressure_dir + string(EVENT_DIR) + string(EVENT_EN_NODE); - m_event_resource = string(DEV_DIR) + m_pressure_dir; - m_pressure_node = string(IIO_DIR) + m_pressure_dir + string(PRESSURE_RAW); - m_temp_node = string(IIO_DIR) + m_pressure_dir + string(TEMP_RAW); - - INFO("m_enable_resource = %s", m_enable_resource.c_str()); - INFO("m_model_id = %s", m_model_id.c_str()); - INFO("m_pressure_dir = %s", m_pressure_dir.c_str()); - INFO("m_event_resource = %s", m_event_resource.c_str()); - - find_node = true; - break; - } - } - } - } - - closedir(main_dir); - return find_node; -} - extern "C" void *create(void) { pressure_sensor_hal *inst; - try - { + try { inst = new pressure_sensor_hal(); - } - catch (int err) - { + } catch (int err) { ERR("pressure_sensor_hal class create fail , errno : %d , errstr : %s\n", err, strerror(err)); return NULL; } diff --git a/src/pressure/pressure_sensor_hal.h b/src/pressure/pressure_sensor_hal.h index 96fc362..42e5310 100755 --- a/src/pressure/pressure_sensor_hal.h +++ b/src/pressure/pressure_sensor_hal.h @@ -23,20 +23,6 @@ #include #include -#define IIO_DIR "/sys/bus/iio/devices/" -#define NAME_NODE "/name" -#define EVENT_DIR "/events" -#define EVENT_EN_NODE "/in_pressure_mag_either_en" -#define DEV_DIR "/dev/" -#define PRESSURE_SCALE "/in_pressure_scale" -#define PRESSURE_RAW "/in_pressure_raw" -#define TEMP_OFFSET "/in_temp_offset" -#define TEMP_SCALE "/in_temp_scale" -#define TEMP_RAW "/in_temp_raw" - -#define IIO_DEV_BASE_NAME "iio:device" -#define IIO_DEV_STR_LEN 10 - using std::string; class pressure_sensor_hal : public sensor_hal @@ -46,17 +32,15 @@ public: virtual ~pressure_sensor_hal(); string get_model_id(void); sensor_type_t get_type(void); - bool enable(void); bool disable(void); bool set_interval(unsigned long val); bool is_data_ready(bool wait); virtual int get_sensor_data(sensor_data_t &data); - bool get_properties(sensor_properties_t &properties); + virtual bool get_properties(sensor_properties_t &properties); private: string m_model_id; - string m_name; string m_vendor; string m_chip_name; @@ -67,6 +51,8 @@ private: float m_temp_offset; float m_temperature; + int m_resolution; + float m_min_range; float m_max_range; float m_raw_data_unit; @@ -74,21 +60,20 @@ private: unsigned long m_polling_interval; unsigned long long m_fired_time; - int m_event_fd; + int m_node_handle; + + string m_enable_node; + string m_data_node; + string m_interval_node; string m_pressure_dir; string m_pressure_node; string m_temp_node; - string m_event_resource; - string m_enable_resource; - cmutex m_value_mutex; + bool m_sensorhub_controlled; - bool m_sensorhub_supported; + cmutex m_value_mutex; - bool check_hw_node(void); bool update_value(bool wait); - bool enable_resource(bool enable); - bool is_sensorhub_supported(void); }; #endif /*_PRESSURE_SENSOR_HAL_CLASS_H_*/ -- 2.7.4 From 312b2adf6397cceec85052438939bd9742794d46 Mon Sep 17 00:00:00 2001 From: Vibhor Gaur Date: Mon, 24 Nov 2014 11:54:00 +0530 Subject: [PATCH 12/16] Synchronizing temperature sensor plugin with addition of IIO interface support Change-Id: I8e10ad057ac667cf7576560875cb2572a9efb7df --- packaging/sensord.spec | 2 +- src/temperature/temperature_sensor.cpp | 2 +- src/temperature/temperature_sensor_hal.cpp | 202 +++++++++++++---------------- src/temperature/temperature_sensor_hal.h | 24 ++-- 4 files changed, 101 insertions(+), 129 deletions(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 74e9594..f5aefe8 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -14,7 +14,7 @@ Source2: sensord.socket %define light_state ON %define geo_state ON %define pressure_state ON -%define temperature_state OFF +%define temperature_state ON %define orientation_state ON %define gravity_state ON %define linear_accel_state ON diff --git a/src/temperature/temperature_sensor.cpp b/src/temperature/temperature_sensor.cpp index 4e0d66a..944d3c5 100755 --- a/src/temperature/temperature_sensor.cpp +++ b/src/temperature/temperature_sensor.cpp @@ -59,7 +59,7 @@ bool temperature_sensor::init() return false; } - m_resolution = properties.sensor_resolution; + m_resolution = properties.resolution; INFO("%s is created!", sensor_base::get_name()); diff --git a/src/temperature/temperature_sensor_hal.cpp b/src/temperature/temperature_sensor_hal.cpp index 9d81381..350d530 100755 --- a/src/temperature/temperature_sensor_hal.cpp +++ b/src/temperature/temperature_sensor_hal.cpp @@ -21,10 +21,12 @@ #include #include #include -#include #include +#include +#include #include + using std::ifstream; using config::csensor_config; @@ -33,71 +35,104 @@ using config::csensor_config; #define ELEMENT_VENDOR "VENDOR" #define ELEMENT_RAW_DATA_UNIT "RAW_DATA_UNIT" -#define ENABLE_VAL true -#define DISABLE_VAL false -#define NO_FLAG 0 -#define TIMEOUT 1 -#define INITIAL_TIME 0 -#define NO_OF_DATA_VAL 1 +#define TEMP_INPUT_NAME "temperature_sensor" +#define TEMP_IIO_ENABLE_NODE_NAME "temp_enable" +#define TEMP_SENSORHUB_POLL_NODE_NAME "temp_poll_delay" +#define INITIAL_TIME -1 temperature_sensor_hal::temperature_sensor_hal() : m_temperature(0) -, m_sensorhub_supported(false) +, m_node_handle(-1) +, m_polling_interval(POLL_1HZ_MS) +, m_fired_time(INITIAL_TIME) { - int fd, ret; + const string sensorhub_interval_node_name = TEMP_SENSORHUB_POLL_NODE_NAME; string file_name; + node_path_info_query query; + node_path_info info; + int input_method = IIO_METHOD; + + if (!get_model_properties(SENSOR_TYPE_TEMPERATURE, m_model_id, input_method)) { + ERR("Failed to find model_properties"); + throw ENXIO; + } - if (!check_hw_node()) - { - ERR("check_hw_node() fail"); + query.input_method = input_method; + query.sensorhub_controlled = is_sensorhub_controlled(sensorhub_interval_node_name); + query.sensor_type = SENSOR_TYPE_TEMPERATURE; + query.input_event_key = TEMP_INPUT_NAME; + query.iio_enable_node_name = TEMP_IIO_ENABLE_NODE_NAME; + query.sensorhub_interval_node_name = sensorhub_interval_node_name; + + if (!get_node_path_info(query, info)) { + ERR("Failed to get node info"); throw ENXIO; } + show_node_path_info(info); + + m_data_node = info.data_node_path; + m_enable_node = info.enable_node_path; + m_interval_node = info.interval_node_path; + + if(input_method == IIO_METHOD) { + m_temperature_dir=info.base_dir; + m_temp_node = m_temperature_dir + string(TEMP_RAW); + INFO("m_temperature_dir = %s", m_temperature_dir.c_str()); + INFO("m_temp_node = %s", m_temp_node.c_str()); + } csensor_config &config = csensor_config::get_instance(); - if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_VENDOR, m_vendor)) - { + if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_VENDOR, m_vendor)) { ERR("[VENDOR] is empty\n"); throw ENXIO; } - INFO("m_vendor = %s", m_vendor.c_str()); - - if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_NAME, m_chip_name)) - { + if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_NAME, m_chip_name)) { ERR("[NAME] is empty\n"); throw ENXIO; } - INFO("m_chip_name = %s", m_chip_name.c_str()); - double raw_data_unit; - if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit)) - { + if (!config.get(SENSOR_TYPE_TEMPERATURE, m_model_id, ELEMENT_RAW_DATA_UNIT, raw_data_unit)) { ERR("[RAW_DATA_UNIT] is empty\n"); throw ENXIO; } m_raw_data_unit = (float)(raw_data_unit); + + INFO("m_data_node = %s\n",m_data_node.c_str()); + + if ((m_node_handle = open(m_temp_node.c_str(),O_RDWR)) < 0) { + ERR("Failed to open handle(%d)", m_node_handle); + throw ENXIO; + } + + INFO("m_data_node = %s\n",m_data_node.c_str()); INFO("m_raw_data_unit = %f\n", m_raw_data_unit); - file_name = string(IIO_DIR) + m_temperature_dir + string(TEMP_SCALE); + file_name = m_temperature_dir + string(TEMP_SCALE); if (!read_node_value(file_name, m_temp_scale)) throw ENXIO; - file_name = string(IIO_DIR) + m_temperature_dir + string(TEMP_OFFSET); + file_name = m_temperature_dir + string(TEMP_OFFSET); if (!read_node_value(file_name, m_temp_offset)) throw ENXIO; - INFO("Temperature scale:%d", m_temp_scale); - INFO("Temperature offset:%f", m_temp_offset); - + INFO("m_temp_offset %f",m_temp_offset); + INFO("m_temp_scale %d",m_temp_scale); + INFO("m_vendor = %s", m_vendor.c_str()); + INFO("m_chip_name = %s", m_chip_name.c_str()); + INFO("m_raw_data_unit = %f\n", m_raw_data_unit); INFO("temperature_sensor_hal is created!\n"); } temperature_sensor_hal::~temperature_sensor_hal() { + close(m_node_handle); + m_node_handle = -1; + INFO("temperature_sensor_hal is destroyed!\n"); } @@ -111,27 +146,23 @@ sensor_type_t temperature_sensor_hal::get_type(void) return TEMPERATURE_SENSOR; } -bool temperature_sensor_hal::enable_resource(bool enable) -{ - INFO("Enable not supported"); - return true; -} - bool temperature_sensor_hal::enable(void) { - enable_resource(ENABLE_VAL); + m_fired_time = INITIAL_TIME; + INFO("Temperature sensor real starting"); return true; } bool temperature_sensor_hal::disable(void) { - enable_resource(DISABLE_VAL); + INFO("Temperature sensor real stopping"); return true; } bool temperature_sensor_hal::set_interval(unsigned long val) { return true; + } bool temperature_sensor_hal::update_value(bool wait) @@ -141,6 +172,10 @@ bool temperature_sensor_hal::update_value(bool wait) if (!read_node_value(m_temp_node, raw_temp_count)) return false; m_temperature = m_temp_offset + ((float)raw_temp_count)/((float)m_temp_scale); + INFO("m_temperature %f",m_temperature); + INFO("m_temp_offset %f",m_temp_offset); + INFO("raw_temp_count %d",raw_temp_count); + INFO("m_temp_scale %d",m_temp_scale); return true; } @@ -154,99 +189,36 @@ bool temperature_sensor_hal::is_data_ready(bool wait) int temperature_sensor_hal::get_sensor_data(sensor_data_t &data) { AUTOLOCK(m_value_mutex); - data.data_accuracy = SENSOR_ACCURACY_GOOD; - data.data_unit_idx = SENSOR_UNIT_CELSIUS; - data.timestamp = INITIAL_TIME; - data.values_num = NO_OF_DATA_VAL; - data.values[0] = m_temperature; - return 0; -} + data.accuracy = SENSOR_ACCURACY_GOOD; + data.timestamp = m_fired_time ; + data.value_count = 1; + data.values[0] = (float) m_temperature; -bool temperature_sensor_hal::get_properties(sensor_properties_t &properties) -{ - properties.sensor_unit_idx = SENSOR_UNIT_CELSIUS; - snprintf(properties.sensor_name, sizeof(properties.sensor_name), "%s", m_chip_name.c_str()); - snprintf(properties.sensor_vendor, sizeof(properties.sensor_vendor), "%s", m_vendor.c_str()); - properties.sensor_resolution = m_raw_data_unit; - return true; + return 0; } -bool temperature_sensor_hal::is_sensorhub_supported(void) -{ - return false; -} -bool temperature_sensor_hal::check_hw_node(void) +bool temperature_sensor_hal::get_properties(sensor_properties_t &properties) { - string name_node; - string hw_name; - string file_name; - - DIR *main_dir = NULL; - struct dirent *dir_entry = NULL; - bool find_node = false; - - INFO("======================start check_hw_node=============================\n"); - - m_sensorhub_supported = is_sensorhub_supported(); - - main_dir = opendir(IIO_DIR); + properties.name = m_chip_name; + properties.vendor = m_vendor; + properties.min_range = -45; + properties.max_range = 130; + properties.min_interval = 1; + properties.resolution = 1; + properties.fifo_count = 0; + properties.max_batch_count = 0; - if (!main_dir) - { - ERR("Could not open IIO directory\n"); - return false; - } - - while (!find_node) - { - dir_entry = readdir(main_dir); - if(dir_entry == NULL) - break; - - if ((strncasecmp(dir_entry->d_name ,".",1 ) != 0) && (strncasecmp(dir_entry->d_name ,"..",2 ) != 0) && (dir_entry->d_ino != 0)) - { - file_name = string(IIO_DIR) + string(dir_entry->d_name) + string(NAME_NODE); - - ifstream infile(file_name.c_str()); - - if (!infile) - continue; - - infile >> hw_name; - - if (strncmp(dir_entry->d_name, IIO_DEV_BASE_NAME, IIO_DEV_STR_LEN) == 0) - { - if (CConfig::get_instance().is_supported(SENSOR_TYPE_TEMPERATURE, hw_name) == true) - { - m_model_id = hw_name; - m_temperature_dir = string(dir_entry->d_name); - m_temp_node = string(IIO_DIR) + m_temperature_dir + string(TEMP_RAW); - - INFO("m_model_id = %s", m_model_id.c_str()); - INFO("m_temperature_dir = %s", m_temperature_dir.c_str()); - - find_node = true; - break; - } - } - } - } - - closedir(main_dir); - return find_node; + return true; } extern "C" void *create(void) { temperature_sensor_hal *inst; - try - { + try { inst = new temperature_sensor_hal(); - } - catch (int err) - { + } catch (int err) { ERR("temperature_sensor_hal class create fail , errno : %d , errstr : %s\n", err, strerror(err)); return NULL; } diff --git a/src/temperature/temperature_sensor_hal.h b/src/temperature/temperature_sensor_hal.h index 7c86c49..f492ee4 100755 --- a/src/temperature/temperature_sensor_hal.h +++ b/src/temperature/temperature_sensor_hal.h @@ -22,15 +22,13 @@ #include #include - - #define IIO_DIR "/sys/bus/iio/devices/" #define IIO_DEV_BASE_NAME "iio:device" #define IIO_DEV_STR_LEN 10 #define NAME_NODE "/name" -#define TEMP_OFFSET "/in_temp_offset" -#define TEMP_SCALE "/in_temp_scale" -#define TEMP_RAW "/in_temp_raw" +#define TEMP_OFFSET "in_temp_offset" +#define TEMP_SCALE "in_temp_scale" +#define TEMP_RAW "in_temp_raw" using std::string; @@ -47,9 +45,11 @@ public: bool is_data_ready(bool wait); virtual int get_sensor_data(sensor_data_t &data); bool get_properties(sensor_properties_t &properties); - private: - int m_temperature; + float m_temperature; + int m_node_handle; + unsigned long m_polling_interval; + unsigned long long m_fired_time; string m_model_id; string m_vendor; @@ -59,16 +59,16 @@ private: float m_raw_data_unit; float m_temp_offset; - string m_temp_node; + string m_data_node; + string m_enable_node; + string m_interval_node; string m_temperature_dir; + string m_temp_node; - bool m_sensorhub_supported; + bool m_sensorhub_controlled; cmutex m_value_mutex; bool update_value(bool wait); - bool is_sensorhub_supported(void); - bool check_hw_node(void); - bool enable_resource(bool enable); }; #endif /*_TEMPERATURE_SENSOR_HAL_CLASS_H_*/ -- 2.7.4 From 4115585f5d82c120f055a933e7db32c14d7b97f0 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Mon, 24 Nov 2014 13:16:58 +0530 Subject: [PATCH 13/16] Adding cconfig parent class for XML configuration Adding cconfig parent class for XML configuration Added cconfig parent class for cvirtual_sensor_config and csensor_config. Removed config namespace as XML configuration related code is small to have a separate namespace. Cleanup of namespace related code. Changed derived class cvirtual_sensor_config and csensor_config classes code based on new cconfig parent class Change-Id: I296dc7be45b201c70d040e7dac2e2b5325d5abc5 --- src/accel/accel_sensor_hal.cpp | 3 -- src/geo/geo_sensor_hal.cpp | 1 - src/gyro/gyro_sensor_hal.cpp | 3 -- src/light/light_sensor_hal.cpp | 3 -- src/pressure/pressure_sensor.cpp | 2 - src/pressure/pressure_sensor.h | 4 +- src/pressure/pressure_sensor_hal.cpp | 1 - src/proxi/proxi_sensor_hal.cpp | 2 - src/shared/CMakeLists.txt | 2 + src/shared/cconfig.cpp | 69 ++++++++++++++++++++++++++++++ src/shared/cconfig.h | 45 +++++++++++++++++++ src/shared/csensor_config.cpp | 37 ---------------- src/shared/csensor_config.h | 50 +++++++++------------- src/shared/cvirtual_sensor_config.cpp | 37 ---------------- src/shared/cvirtual_sensor_config.h | 14 ++---- src/shared/sensor_hal.cpp | 1 - src/temperature/temperature_sensor_hal.cpp | 2 - 17 files changed, 143 insertions(+), 133 deletions(-) create mode 100644 src/shared/cconfig.cpp create mode 100644 src/shared/cconfig.h diff --git a/src/accel/accel_sensor_hal.cpp b/src/accel/accel_sensor_hal.cpp index cb74385..53bb2d7 100755 --- a/src/accel/accel_sensor_hal.cpp +++ b/src/accel/accel_sensor_hal.cpp @@ -18,15 +18,12 @@ */ #include #include - #include #include - #include #include using std::ifstream; -using config::csensor_config; #define GRAVITY 9.80665 #define G_TO_MG 1000 diff --git a/src/geo/geo_sensor_hal.cpp b/src/geo/geo_sensor_hal.cpp index bfbb50e..d742b26 100755 --- a/src/geo/geo_sensor_hal.cpp +++ b/src/geo/geo_sensor_hal.cpp @@ -27,7 +27,6 @@ #include using std::ifstream; -using config::csensor_config; #define SENSOR_TYPE_MAGNETIC "MAGNETIC" #define ELEMENT_NAME "NAME" diff --git a/src/gyro/gyro_sensor_hal.cpp b/src/gyro/gyro_sensor_hal.cpp index 34184bc..c9bf135 100755 --- a/src/gyro/gyro_sensor_hal.cpp +++ b/src/gyro/gyro_sensor_hal.cpp @@ -19,17 +19,14 @@ #include #include #include - #include #include - #include #include #include #include using std::ifstream; -using config::csensor_config; #define DPS_TO_MDPS 1000 #define MIN_RANGE(RES) (-((1 << (RES))/2)) diff --git a/src/light/light_sensor_hal.cpp b/src/light/light_sensor_hal.cpp index 6498728..4cc630c 100755 --- a/src/light/light_sensor_hal.cpp +++ b/src/light/light_sensor_hal.cpp @@ -20,16 +20,13 @@ #include #include #include - #include #include - #include #include #include using std::ifstream; -using config::csensor_config; #define SENSOR_TYPE_LIGHT "LIGHT" #define ELEMENT_NAME "NAME" diff --git a/src/pressure/pressure_sensor.cpp b/src/pressure/pressure_sensor.cpp index 710c86a..d29311c 100755 --- a/src/pressure/pressure_sensor.cpp +++ b/src/pressure/pressure_sensor.cpp @@ -19,13 +19,11 @@ #include #include - #include #include #include #include -using config::csensor_config; using std::bind1st; using std::mem_fun; diff --git a/src/pressure/pressure_sensor.h b/src/pressure/pressure_sensor.h index 1da5cab..1bd8df2 100755 --- a/src/pressure/pressure_sensor.h +++ b/src/pressure/pressure_sensor.h @@ -25,7 +25,8 @@ #include #include -class pressure_sensor : public physical_sensor { +class pressure_sensor : public physical_sensor +{ public: pressure_sensor(); virtual ~pressure_sensor(); @@ -52,7 +53,6 @@ private: bool process_event(void); float pressure_to_altitude(float pressure); void raw_to_base(sensor_data_t &data); - }; #endif diff --git a/src/pressure/pressure_sensor_hal.cpp b/src/pressure/pressure_sensor_hal.cpp index 2823baa..c899d3e 100755 --- a/src/pressure/pressure_sensor_hal.cpp +++ b/src/pressure/pressure_sensor_hal.cpp @@ -29,7 +29,6 @@ using std::ifstream; using std::string; -using config::csensor_config; #define SENSOR_TYPE_PRESSURE "PRESSURE" #define ELEMENT_NAME "NAME" diff --git a/src/proxi/proxi_sensor_hal.cpp b/src/proxi/proxi_sensor_hal.cpp index 328211e..3154c18 100755 --- a/src/proxi/proxi_sensor_hal.cpp +++ b/src/proxi/proxi_sensor_hal.cpp @@ -27,7 +27,6 @@ #include using std::ifstream; -using config::csensor_config; #define NO_FLAG 0 #define PROXIMITY_TYPE 8 @@ -42,7 +41,6 @@ using config::csensor_config; #define PROXI_CODE 0x0019 - proxi_sensor_hal::proxi_sensor_hal() : m_state(PROXIMITY_STATE_FAR) , m_fired_time(0) diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 4a305da..2653782 100755 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -38,6 +38,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src/libsensord) add_library(sensord-server SHARED crw_lock.cpp worker_thread.cpp + cconfig.cpp csensor_config.cpp cvirtual_sensor_config.cpp csensor_event_queue.cpp @@ -75,6 +76,7 @@ install(FILES ${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) install(FILES crw_lock.h worker_thread.h + cconfig.h csensor_config.h cvirtual_sensor_config.h csensor_event_queue.h diff --git a/src/shared/cconfig.cpp b/src/shared/cconfig.cpp new file mode 100644 index 0000000..23d11a5 --- /dev/null +++ b/src/shared/cconfig.cpp @@ -0,0 +1,69 @@ +/* + * libsensord-share + * + * 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 + +using std::ifstream; + +cconfig::cconfig(void) +{ + +} + +cconfig::~cconfig(void) +{ + +} + +bool cconfig::get_device_id(void) +{ + const string INFO_INI_PATH = "/etc/info.ini"; + const string START_DELIMETER = "Model="; + const string END_DELIMETER = ";"; + string line; + ifstream in_file; + std::size_t start_pos, end_pos; + bool ret = false; + + in_file.open(INFO_INI_PATH); + + if (!in_file.is_open()) + return false; + + while (!in_file.eof()) { + getline(in_file, line); + start_pos = line.find(START_DELIMETER); + + if (start_pos != std::string::npos) { + start_pos = start_pos + START_DELIMETER.size(); + end_pos = line.find(END_DELIMETER, start_pos); + + if (end_pos != std::string::npos) { + m_device_id = line.substr(start_pos, end_pos - start_pos); + ret = true; + break; + } + } + } + + in_file.close(); + + return ret; +} diff --git a/src/shared/cconfig.h b/src/shared/cconfig.h new file mode 100644 index 0000000..aa92fdd --- /dev/null +++ b/src/shared/cconfig.h @@ -0,0 +1,45 @@ +/* + * libsensord-share + * + * 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 _CCONFIG_H_ +#define _CCONFIG_H_ + +#include +#include +#include + +using std::unordered_map; +using std::string; +using std::istringstream; + +class cconfig +{ +protected: + virtual bool load_config(const string& config_path) = 0; + + string m_device_id; +public: + cconfig(); + virtual ~cconfig(); + + bool get_device_id(void); + +}; + +#endif /* _CCONFIG_H_ */ diff --git a/src/shared/csensor_config.cpp b/src/shared/csensor_config.cpp index 013a086..1f193a7 100755 --- a/src/shared/csensor_config.cpp +++ b/src/shared/csensor_config.cpp @@ -25,7 +25,6 @@ #include #include -using namespace config; using std::ifstream; #define ROOT_ELEMENT "SENSOR" @@ -275,39 +274,3 @@ bool csensor_config::is_supported(const string& sensor_type,const string& model_ return true; } - -bool csensor_config::get_device_id(void) -{ - const string INFO_INI_PATH = "/etc/info.ini"; - const string START_DELIMETER = "Model="; - const string END_DELIMETER = ";"; - string line; - ifstream in_file; - std::size_t start_pos, end_pos; - bool ret = false; - - in_file.open(INFO_INI_PATH); - - if (!in_file.is_open()) - return false; - - while (!in_file.eof()) { - getline(in_file, line); - start_pos = line.find(START_DELIMETER); - - if (start_pos != std::string::npos) { - start_pos = start_pos + START_DELIMETER.size(); - end_pos = line.find(END_DELIMETER, start_pos); - - if (end_pos != std::string::npos) { - m_device_id = line.substr(start_pos, end_pos - start_pos); - ret = true; - break; - } - } - } - - in_file.close(); - - return ret; -} diff --git a/src/shared/csensor_config.h b/src/shared/csensor_config.h index 0c77f98..d4c69a5 100755 --- a/src/shared/csensor_config.h +++ b/src/shared/csensor_config.h @@ -20,13 +20,7 @@ #if !defined(_CSENSOR_CONFIG_CLASS_H_) #define _CSENSOR_CONFIG_CLASS_H_ -#include -#include -#include - -using std::unordered_map; -using std::string; -using std::istringstream; +#include #define SENSOR_CONFIG_FILE_PATH "/usr/etc/sensors.xml" @@ -74,30 +68,28 @@ typedef unordered_map Sensor_config; * */ -namespace config +class csensor_config : public cconfig { - class csensor_config - { - private: - csensor_config(); - csensor_config(csensor_config const&) {}; - csensor_config& operator=(csensor_config const&); - bool load_config(const string& config_path); - Sensor_config m_sensor_config; - string m_device_id; - public: - static csensor_config& get_instance(void); +private: + csensor_config(); + csensor_config(csensor_config const&) {}; + csensor_config& operator=(csensor_config const&); + + bool load_config(const string& config_path); + + Sensor_config m_sensor_config; +public: + static csensor_config& get_instance(void); + + bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, string& value); + bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value); + bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, long& value); - bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, string& value); - bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, double& value); - bool get(const string& sensor_type, const string& model_id, const string& element, const string& attr, long& value); + bool get(const string& sensor_type, const string& model_id, const string& element, string& value); + bool get(const string& sensor_type, const string& model_id, const string& element, double& value); + bool get(const string& sensor_type, const string& model_id, const string& element, long& value); - bool get(const string& sensor_type, const string& model_id, const string& element, string& value); - bool get(const string& sensor_type, const string& model_id, const string& element, double& value); - bool get(const string& sensor_type, const string& model_id, const string& element, long& value); + bool is_supported(const string &sensor_type, const string &model_id); +}; - bool is_supported(const string &sensor_type, const string &model_id); - bool get_device_id(void); - }; -} #endif diff --git a/src/shared/cvirtual_sensor_config.cpp b/src/shared/cvirtual_sensor_config.cpp index 7aebd2d..c0d0f0b 100755 --- a/src/shared/cvirtual_sensor_config.cpp +++ b/src/shared/cvirtual_sensor_config.cpp @@ -24,9 +24,7 @@ #include #include #include -#include -using std::ifstream; using std::string; using std::stringstream; @@ -282,38 +280,3 @@ bool cvirtual_sensor_config::is_supported(const string& sensor_type) return true; } -bool cvirtual_sensor_config::get_device_id(void) -{ - const string INFO_INI_PATH = "/etc/info.ini"; - const string START_DELIMETER = "Model="; - const string END_DELIMETER = ";"; - string line; - ifstream in_file; - std::size_t start_pos, end_pos; - bool ret = false; - - in_file.open(INFO_INI_PATH); - - if (!in_file.is_open()) - return false; - - while (!in_file.eof()) { - getline(in_file, line); - start_pos = line.find(START_DELIMETER); - - if (start_pos != std::string::npos) { - start_pos = start_pos + START_DELIMETER.size(); - end_pos = line.find(END_DELIMETER, start_pos); - - if (end_pos != std::string::npos) { - m_device_id = line.substr(start_pos, end_pos - start_pos); - ret = true; - break; - } - } - } - - in_file.close(); - - return ret; -} diff --git a/src/shared/cvirtual_sensor_config.h b/src/shared/cvirtual_sensor_config.h index 754fd00..7cfbcb6 100755 --- a/src/shared/cvirtual_sensor_config.h +++ b/src/shared/cvirtual_sensor_config.h @@ -20,13 +20,7 @@ #if !defined(_CVIRTUAL_SENSOR_CONFIG_CLASS_H_) #define _CVIRTUAL_SENSOR_CONFIG_CLASS_H_ -#include -#include -#include - -using std::unordered_map; -using std::string; -using std::istringstream; +#include #define VIRTUAL_SENSOR_CONFIG_FILE_PATH "/usr/etc/virtual_sensors.xml" @@ -55,15 +49,16 @@ typedef unordered_map Virtual_sensor_config; * */ -class cvirtual_sensor_config +class cvirtual_sensor_config : public cconfig { private: cvirtual_sensor_config(); cvirtual_sensor_config(cvirtual_sensor_config const&) {}; cvirtual_sensor_config& operator=(cvirtual_sensor_config const&); + bool load_config(const string& config_path); + Virtual_sensor_config m_virtual_sensor_config; - string m_device_id; public: static cvirtual_sensor_config& get_instance(void); @@ -76,7 +71,6 @@ public: bool get(const string& sensor_type, const string& element, int *value, int count = 1); bool is_supported(const string &sensor_type); - bool get_device_id(void); }; #endif diff --git a/src/shared/sensor_hal.cpp b/src/shared/sensor_hal.cpp index 55c20f7..a312162 100755 --- a/src/shared/sensor_hal.cpp +++ b/src/shared/sensor_hal.cpp @@ -25,7 +25,6 @@ using std::ifstream; using std::fstream; -using config::csensor_config; cmutex sensor_hal::m_shared_mutex; diff --git a/src/temperature/temperature_sensor_hal.cpp b/src/temperature/temperature_sensor_hal.cpp index 350d530..cf562bb 100755 --- a/src/temperature/temperature_sensor_hal.cpp +++ b/src/temperature/temperature_sensor_hal.cpp @@ -26,9 +26,7 @@ #include #include - using std::ifstream; -using config::csensor_config; #define SENSOR_TYPE_TEMPERATURE "TEMPERATURE" #define ELEMENT_NAME "NAME" -- 2.7.4 From b857b3f8962a12646ee9afba0c0008db29096783 Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Mon, 24 Nov 2014 13:31:46 +0530 Subject: [PATCH 14/16] Updating configurability support for Orientation Sensor - Added support for getting output orientation as both radians and degrees - Updating orientation sensor properties Change-Id: I296dc7be45b201c70d151e7dac2e2b5325d5abc5 --- src/orientation/orientation_sensor.cpp | 40 ++++++++++++++++++++++++++------ src/sensor_fusion/orientation_filter.cpp | 2 +- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/orientation/orientation_sensor.cpp b/src/orientation/orientation_sensor.cpp index b1222e2..72145b0 100755 --- a/src/orientation/orientation_sensor.cpp +++ b/src/orientation/orientation_sensor.cpp @@ -44,7 +44,9 @@ #define MS_TO_US 1000 -#define AZIMUTH_OFFSET 360 +#define PI 3.141593 +#define AZIMUTH_OFFSET_DEGREES 360 +#define AZIMUTH_OFFSET_RADIANS (2 * PI) #define ELEMENT_NAME "NAME" #define ELEMENT_VENDOR "VENDOR" @@ -294,6 +296,7 @@ void orientation_sensor::synthesize(const sensor_event_t &event, vector euler_orientation; float raw_data[3]; + float azimuth_offset; if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) { diff_time = event.data.timestamp - m_timestamp; @@ -343,6 +346,14 @@ void orientation_sensor::synthesize(const sensor_event_t &event, vector= 0) orientation_event.data.values[0] = euler_orientation.m_ang.m_vec[2]; else - orientation_event.data.values[0] = euler_orientation.m_ang.m_vec[2] + AZIMUTH_OFFSET; + orientation_event.data.values[0] = euler_orientation.m_ang.m_vec[2] + azimuth_offset; push(orientation_event); } @@ -372,6 +383,7 @@ int orientation_sensor::get_sensor_data(const unsigned int event_type, sensor_da sensor_data_t magnetic_data; euler_angles euler_orientation; + float azimuth_offset; if (event_type != ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME) return -1; @@ -394,6 +406,14 @@ int orientation_sensor::get_sensor_data(const unsigned int event_type, sensor_da euler_orientation = m_orientation.get_orientation(accel, gyro, magnetic); + if(m_raw_data_unit == "DEGREES") { + euler_orientation = rad2deg(euler_orientation); + azimuth_offset = AZIMUTH_OFFSET_DEGREES; + } + else { + azimuth_offset = AZIMUTH_OFFSET_RADIANS; + } + data.accuracy = SENSOR_ACCURACY_GOOD; data.timestamp = get_timestamp(); data.values[1] = euler_orientation.m_ang.m_vec[0]; @@ -401,7 +421,7 @@ int orientation_sensor::get_sensor_data(const unsigned int event_type, sensor_da if (euler_orientation.m_ang.m_vec[2] >= 0) data.values[0] = euler_orientation.m_ang.m_vec[2]; else - data.values[0] = euler_orientation.m_ang.m_vec[2] + AZIMUTH_OFFSET; + data.values[0] = euler_orientation.m_ang.m_vec[2] + azimuth_offset; data.value_count = 3; return 0; @@ -409,11 +429,17 @@ int orientation_sensor::get_sensor_data(const unsigned int event_type, sensor_da bool orientation_sensor::get_properties(sensor_properties_t &properties) { - properties.min_range = -180; - properties.max_range = 360; - properties.resolution = 1; + if(m_raw_data_unit == "DEGREES") { + properties.min_range = -180; + properties.max_range = 360; + } + else { + properties.min_range = -PI; + properties.max_range = 2 * PI; + } + properties.resolution = 0.000001;; - properties.vendor = "Samsung"; + properties.vendor = m_vendor; properties.name = SENSOR_NAME; return true; diff --git a/src/sensor_fusion/orientation_filter.cpp b/src/sensor_fusion/orientation_filter.cpp index 14058a6..a615217 100644 --- a/src/sensor_fusion/orientation_filter.cpp +++ b/src/sensor_fusion/orientation_filter.cpp @@ -220,7 +220,7 @@ inline void orientation_filter::time_update() m_quat_driv.quat_normalize(); quat_output = phase_correction(m_quat_driv, m_quat_aid); - orientation = rad2deg(quat2euler(quat_output)); + orientation = quat2euler(quat_output); m_orientation.m_ang.m_vec[0] = orientation.m_ang.m_vec[0] * m_pitch_phase_compensation; m_orientation.m_ang.m_vec[1] = orientation.m_ang.m_vec[1] * m_roll_phase_compensation; -- 2.7.4 From 2b50ed33632907e91e1d73923c0d97cc50e6094f Mon Sep 17 00:00:00 2001 From: Ramasamy Date: Mon, 24 Nov 2014 13:39:01 +0530 Subject: [PATCH 15/16] Updating the get_properties method - Updating get_properties method for gravity and linear acceleration Change-Id: I296dc7be45b201c55d151e7dac2e2b5325d5abc5 --- src/gravity/gravity_sensor.cpp | 2 +- src/linear_accel/linear_accel_sensor.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gravity/gravity_sensor.cpp b/src/gravity/gravity_sensor.cpp index 08b70c5..328cab8 100755 --- a/src/gravity/gravity_sensor.cpp +++ b/src/gravity/gravity_sensor.cpp @@ -205,7 +205,7 @@ bool gravity_sensor::get_properties(sensor_properties_t &properties) { properties.min_range = -GRAVITY; properties.max_range = GRAVITY; - properties.resolution = 1; + properties.resolution = 0.000001;; properties.vendor = m_vendor; properties.name = SENSOR_NAME; diff --git a/src/linear_accel/linear_accel_sensor.cpp b/src/linear_accel/linear_accel_sensor.cpp index 794bef0..f975733 100755 --- a/src/linear_accel/linear_accel_sensor.cpp +++ b/src/linear_accel/linear_accel_sensor.cpp @@ -276,6 +276,9 @@ bool linear_accel_sensor::get_properties(sensor_properties_t &properties) m_gravity_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; } -- 2.7.4 From 250a4a7c164ffe8e7738680115830417e4058456 Mon Sep 17 00:00:00 2001 From: Vibhor Gaur Date: Mon, 24 Nov 2014 18:06:16 +0530 Subject: [PATCH 16/16] Updating pressure test file for compatibility with changes in public code Change-Id: I7f70f6ca7ac5641fc03e6fea9b8f82616e6a875d --- test/src/pressure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/pressure.c b/test/src/pressure.c index 112c016..0ac4e6d 100644 --- a/test/src/pressure.c +++ b/test/src/pressure.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include static GMainLoop *mainloop; -- 2.7.4