From a305da78e60760135f49e9783b8d6f39cb04d791 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 2 Jun 2016 14:11:04 +0900 Subject: [PATCH 01/16] sensord: support the passive mode which listens sensor event only if a client wants to be listening sensor event which other clients start sensor, use sensord_set_passive_mode() before sensord_register_event(). Change-Id: Idbe59ed663c8a0bc268c406afcdc8cac13286b98 Signed-off-by: kibak.yoon --- src/client/client.cpp | 34 ++++++++++++++++++++++++++++++++++ src/client/sensor_client_info.cpp | 30 ++++++++++++++++++++++++++++++ src/client/sensor_client_info.h | 4 ++++ src/client/sensor_handle_info.cpp | 13 ++++++++++++- src/client/sensor_handle_info.h | 21 ++++++++++++--------- src/client/sensor_internal.h | 1 + 6 files changed, 93 insertions(+), 10 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index e818bd8..769aa9d 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -682,6 +682,28 @@ API bool sensord_disconnect(int handle) _I("%s disconnects with %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle); + if (sensor_client_info::get_instance().get_passive_mode(handle)) { + _W("%s[%d] for %s is on passive mode while disconnecting.", + get_sensor_name(sensor_id), handle, get_client_name()); + + command_channel *cmd_channel; + event_type_vector event_types; + sensor_client_info::get_instance().get_active_event_types(sensor_id, event_types); + + for (auto it = event_types.begin(); it != event_types.end(); ++it) + sensord_unregister_event(handle, *it); + + if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) { + _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id)); + return false; + } + + if (!cmd_channel->cmd_unset_batch()) { + _E("Sending cmd_unset_interval(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name()); + return false; + } + } + if (sensor_state != SENSOR_STATE_STOPPED) { _W("%s[%d] for %s is not stopped before disconnecting.", get_sensor_name(sensor_id), handle, get_client_name()); @@ -781,6 +803,9 @@ API bool sensord_unregister_event(int handle, unsigned int event_type) sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep); ret = change_sensor_rep(sensor_id, prev_rep, cur_rep); + if (sensor_client_info::get_instance().get_passive_mode(handle)) + sensor_client_info::get_instance().set_passive_mode(handle, false); + if (!ret) sensor_client_info::get_instance().register_event(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data); @@ -1197,3 +1222,12 @@ API bool sensord_register_hub_event(int handle, unsigned int event_type, unsigne return false; } +API bool sensord_set_passive_mode(int handle, bool passive) +{ + if (!sensor_client_info::get_instance().set_passive_mode(handle, passive)) { + _E("Failed to set passive mode %d", passive); + return false; + } + + return true; +} diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index 62de536..08b5a9d 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -213,6 +213,36 @@ bool sensor_client_info::set_sensor_state(int handle, int sensor_state) return true; } +bool sensor_client_info::get_passive_mode(int handle) +{ + AUTOLOCK(m_handle_info_lock); + + auto it_handle = m_sensor_handle_infos.find(handle); + + if (it_handle == m_sensor_handle_infos.end()) { + _E("Handle[%d] is not found for client %s", handle, get_client_name()); + return false; + } + + return it_handle->second.get_passive_mode(); +} + +bool sensor_client_info::set_passive_mode(int handle, bool passive) +{ + AUTOLOCK(m_handle_info_lock); + + auto it_handle = m_sensor_handle_infos.find(handle); + + if (it_handle == m_sensor_handle_infos.end()) { + _E("Handle[%d] is not found for client %s", handle, get_client_name()); + return false; + } + + it_handle->second.set_passive_mode(passive); + + return true; +} + bool sensor_client_info::set_sensor_pause_policy(int handle, int pause_policy) { AUTOLOCK(m_handle_info_lock); diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index 1d2ba9b..7c46323 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -74,6 +74,10 @@ public: bool set_sensor_params(int handle, int sensor_state, int sensor_pause_policy); bool get_sensor_params(int handle, int &sensor_state, int &sensor_pause_policy); bool set_sensor_state(int handle, int sensor_state); + + bool get_passive_mode(int handle); + bool set_passive_mode(int handle, bool passive); + bool set_sensor_pause_policy(int handle, int pause_policy); bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency); bool set_accuracy(int handle, int accuracy); diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index b394990..f1e9c65 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -34,6 +34,7 @@ sensor_handle_info::sensor_handle_info() , m_accuracy(-1) , m_accuracy_cb(NULL) , m_accuracy_user_data(NULL) +, m_passive(false) { } @@ -161,7 +162,17 @@ unsigned int sensor_handle_info::get_reg_event_count(void) return m_reg_event_infos.size(); } +bool sensor_handle_info::get_passive_mode(void) +{ + return m_passive; +} + +void sensor_handle_info::set_passive_mode(bool passive) +{ + m_passive = passive; +} + bool sensor_handle_info::is_started(void) { - return (m_sensor_state == SENSOR_STATE_STARTED); + return (m_sensor_state == SENSOR_STATE_STARTED) || m_passive; } diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index 28e5a01..c74c3a5 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -30,15 +30,6 @@ typedef std::unordered_map event_info_map; class sensor_handle_info { public: - int m_handle; - sensor_id_t m_sensor_id; - int m_sensor_state; - int m_pause_policy; - int m_bad_accuracy; - int m_accuracy; - sensor_accuracy_changed_cb_t m_accuracy_cb; - void *m_accuracy_user_data; - sensor_handle_info(); ~sensor_handle_info(); @@ -55,8 +46,20 @@ public: void clear_all_events(void); static unsigned long long renew_event_id(void); + bool get_passive_mode(void); + void set_passive_mode(bool passive); bool is_started(void); + int m_handle; + sensor_id_t m_sensor_id; + int m_sensor_state; + int m_pause_policy; + int m_bad_accuracy; + int m_accuracy; + sensor_accuracy_changed_cb_t m_accuracy_cb; + void *m_accuracy_user_data; + bool m_passive; + private: event_info_map m_reg_event_infos; static unsigned long long m_event_id; diff --git a/src/client/sensor_internal.h b/src/client/sensor_internal.h index c4c3fce..3cc6641 100644 --- a/src/client/sensor_internal.h +++ b/src/client/sensor_internal.h @@ -386,6 +386,7 @@ int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, v bool sensord_external_disconnect(int handle); bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt); +bool sensord_set_passive_mode(int handle, bool passive); /** * @} */ -- 2.7.4 From da9123180996923a1449f47d5a4965ca4780ffc2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 8 Jun 2016 20:18:58 +0900 Subject: [PATCH 02/16] sensord: restore attributes after sensor daemon is restarted sensor attributes also has to restored when daemon is restarted, like listener, interval, batch latency. Change-Id: Id9bfb37fc9ab9b71caca08639f2106710a65741f Signed-off-by: kibak.yoon --- src/client/client.cpp | 42 +++++++++++++++++++++++++++++++++++++++ src/client/sensor_client_info.cpp | 32 +++++++++++++++++++++++++++++ src/client/sensor_client_info.h | 24 +++++++--------------- src/client/sensor_handle_info.h | 6 ++++++ 4 files changed, 87 insertions(+), 17 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 769aa9d..e26ba85 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -172,6 +172,40 @@ static void power_save_state_cb(keynode_t *node, void *data) } } +bool restore_attributes(int client_id, sensor_id_t sensor, command_channel *cmd_channel) +{ + sensor_handle_info_map handle_infos; + + sensor_client_info::get_instance().get_sensor_handle_info(sensor, handle_infos); + + for (auto it_handles = handle_infos.begin(); it_handles != handle_infos.end(); ++it_handles) { + sensor_handle_info info = it_handles->second; + + for (auto it = info.attributes_int.begin(); it != info.attributes_int.end(); ++it) { + int attribute = it->first; + int value = it->second; + if (!cmd_channel->cmd_set_attribute_int(attribute, value)) { + _E("Failed to send cmd_set_attribute_int(%d, %d) for %s", + client_id, value, get_client_name()); + return false; + } + } + + for (auto it = info.attributes_str.begin(); it != info.attributes_str.end(); ++it) { + int attribute = it->first; + const char *value = it->second.c_str(); + int value_len = it->second.size(); + if (!cmd_channel->cmd_set_attribute_str(attribute, value, value_len)) { + _E("Failed to send cmd_set_attribute_str(%d, %d, %s) for %s", + client_id, value_len, value, get_client_name()); + return false; + } + } + } + + return true; +} + void restore_session(void) { AUTOLOCK(lock); @@ -233,6 +267,10 @@ void restore_session(void) goto FAILED; } + if (!restore_attributes(client_id, *it_sensor, cmd_channel)) { + _E("Failed to restore attributes(%s) for %s", get_sensor_name(*it_sensor), get_client_name()); + goto FAILED; + } ++it_sensor; } @@ -1074,6 +1112,8 @@ static int change_attribute_int(int handle, int attribute, int value) return -EPERM; } + sensor_client_info::get_instance().set_attribute(handle, attribute, value); + return OP_SUCCESS; } @@ -1130,6 +1170,8 @@ API int sensord_set_attribute_str(int handle, int attribute, const char *value, return -EPERM; } + sensor_client_info::get_instance().set_attribute(handle, attribute, value); + return OP_SUCCESS; } diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index 08b5a9d..54a6d7e 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -666,6 +666,38 @@ void sensor_client_info::set_pause_policy(sensor_id_t sensor, int pause_policy) } } +bool sensor_client_info::set_attribute(int handle, int attribute, int value) +{ + AUTOLOCK(m_handle_info_lock); + + auto it_handle = m_sensor_handle_infos.find(handle); + + if (it_handle == m_sensor_handle_infos.end()) { + _E("Handle[%d] is not found for client %s", handle, get_client_name()); + return false; + } + + it_handle->second.attributes_int[attribute] = value; + + return true; +} + +bool sensor_client_info::set_attribute(int handle, int attribute, std::string value) +{ + AUTOLOCK(m_handle_info_lock); + + auto it_handle = m_sensor_handle_infos.find(handle); + + if (it_handle == m_sensor_handle_infos.end()) { + _E("Handle[%d] is not found for client %s", handle, get_client_name()); + return false; + } + + it_handle->second.attributes_str[attribute] = value; + + return true; +} + void sensor_client_info::clear(void) { close_command_channel(); diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index 7c46323..ab3a384 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -29,27 +29,14 @@ #include #include #include -#include -#include -#include -#include #include #include #include -using std::unordered_map; -using std::vector; -using std::string; -using std::queue; -using std::mutex; -using std::lock_guard; -using std::unique_lock; -using std::condition_variable; - -typedef vector handle_vector; -typedef vector sensor_id_vector; -typedef unordered_map sensor_handle_info_map; -typedef unordered_map sensor_command_channel_map; +typedef std::vector handle_vector; +typedef std::vector sensor_id_vector; +typedef std::unordered_map sensor_handle_info_map; +typedef std::unordered_map sensor_command_channel_map; typedef struct sensor_rep { bool active; @@ -78,6 +65,9 @@ public: bool get_passive_mode(int handle); bool set_passive_mode(int handle, bool passive); + bool set_attribute(int handle, int attribute, int value); + bool set_attribute(int handle, int attribute, std::string value); + bool set_sensor_pause_policy(int handle, int pause_policy); bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency); bool set_accuracy(int handle, int accuracy); diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index c74c3a5..b62f646 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -25,8 +25,12 @@ #include #include #include +#include +#include typedef std::unordered_map event_info_map; +typedef std::map sensor_attribute_int_map; +typedef std::map sensor_attribute_str_map; class sensor_handle_info { public: @@ -59,6 +63,8 @@ public: sensor_accuracy_changed_cb_t m_accuracy_cb; void *m_accuracy_user_data; bool m_passive; + sensor_attribute_int_map attributes_int; + sensor_attribute_str_map attributes_str; private: event_info_map m_reg_event_infos; -- 2.7.4 From 8fe04eb190fda9eb38b93150f9140837d865915c Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 7 Jun 2016 14:02:41 +0900 Subject: [PATCH 03/16] sensord: set to UINT_MAX batch count when there is no batch latency for sensor - if there is no client which uses batch latency, batch count should be set the default value, not 0 but max batch count. if sensord sets the UINT_MAX as a default value, HAL will set the proper value comparing between this sensor's max batch count and UINT_MAX. Change-Id: I3aff8d24c00ca6b232d33c803b1783cb60325abb Signed-off-by: kibak.yoon --- src/server/sensor_base.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index 5ff2566..a5a40bb 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -264,10 +265,10 @@ bool sensor_base::delete_batch(int client_id) cur_max = m_sensor_info_list.get_max_batch(); if (!cur_max) { - _I("No latency for sensor[%#llx] by client[%d] deleting latency, so set to default 0 ms", + _I("No latency for sensor[%#llx] by client[%d] deleting latency, so set to default count", get_id(), client_id); - set_batch_latency(0); + set_batch_latency(UINT_MAX); } else if (cur_max != prev_max) { _I("Max latency for sensor[%#llx] is changed from %dms to %dms by client[%d] deleting latency", get_id(), prev_max, cur_max, client_id); -- 2.7.4 From 7df328c69c213aa972f0277fd9390ee332b88be6 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 20 Jun 2016 12:46:07 +0900 Subject: [PATCH 04/16] sensord: change sensor axis policy by using attribute setting via C-API - SENSORD_AXIS_DEVICE_ORIENTED - SENSORD_AXIS_DISPLAY_ORIENTED Change-Id: Iab201d26c1d957d58ee48a00d4aa1403aa034f9e Signed-off-by: kibak.yoon --- src/client/client.cpp | 1 + src/client/sensor_event_listener.cpp | 14 ++++++++++++-- src/client/sensor_event_listener.h | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index e26ba85..b900db4 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1080,6 +1080,7 @@ static int change_pause_policy(int handle, int pause) static int change_axis_orientation(int handle, int axis_orientation) { + sensor_event_listener::get_instance().set_sensor_axis(axis_orientation); return OP_SUCCESS; } diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index 80c280b..fdc622a 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -45,6 +45,7 @@ sensor_event_listener::sensor_event_listener() , m_thread_state(THREAD_STATE_TERMINATE) , m_hup_observer(NULL) , m_client_info(sensor_client_info::get_instance()) +, m_axis(SENSORD_AXIS_DEVICE_ORIENTED) , m_display_rotation(AUTO_ROTATION_DEGREE_UNKNOWN) { } @@ -204,11 +205,19 @@ bool sensor_event_listener::is_valid_callback(client_callback_info *cb_info) return m_client_info.is_event_active(cb_info->handle, cb_info->event_type, cb_info->event_id); } +void sensor_event_listener::set_sensor_axis(int axis) +{ + m_axis = axis; +} + void sensor_event_listener::align_sensor_axis(sensor_t sensor, sensor_data_t *data) { sensor_type_t type = sensor_to_sensor_info(sensor)->get_type(); - if (type != ACCELEROMETER_SENSOR && type != GYROSCOPE_SENSOR && type != GRAVITY_SENSOR) + if (m_axis != SENSORD_AXIS_DISPLAY_ORIENTED) + return; + + if (type != ACCELEROMETER_SENSOR && type != GYROSCOPE_SENSOR && type != GRAVITY_SENSOR && type != LINEAR_ACCEL_SENSOR) return; float x, y; @@ -250,7 +259,8 @@ gboolean sensor_event_listener::callback_dispatcher(gpointer data) if (cb_info->accuracy_cb) cb_info->accuracy_cb(cb_info->sensor, cb_info->timestamp, cb_info->accuracy, cb_info->accuracy_user_data); - ((sensor_cb_t) cb_info->cb)(cb_info->sensor, cb_info->event_type, (sensor_data_t *) cb_info->sensor_data.get(), cb_info->user_data); + sensor_event_listener::get_instance().align_sensor_axis(cb_info->sensor, (sensor_data_t *)cb_info->sensor_data.get()); + ((sensor_cb_t) cb_info->cb)(cb_info->sensor, cb_info->event_type, (sensor_data_t *)cb_info->sensor_data.get(), cb_info->user_data); delete cb_info; diff --git a/src/client/sensor_event_listener.h b/src/client/sensor_event_listener.h index 417d0ad..9631a63 100644 --- a/src/client/sensor_event_listener.h +++ b/src/client/sensor_event_listener.h @@ -74,6 +74,8 @@ public: void clear(void); void set_hup_observer(hup_observer_t observer); + + void set_sensor_axis(int axis); void set_display_rotation(int rt); private: @@ -97,6 +99,8 @@ private: sensor_client_info &m_client_info; /* WC1's rotation control */ + /* SENSORD_AXIS_DEVICE_ORIENTED, SENSORD_AXIS_DISPLAY_ORIENTED */ + int m_axis; int m_display_rotation; sensor_event_listener(); -- 2.7.4 From bcc7f159bdef472d1310bc55ce3b829b94456678 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 2 Jun 2016 17:48:10 +0900 Subject: [PATCH 05/16] sensord: add new internal sensor types Change-Id: I9c7bb390184877f41d379fa1bb0115dd7edecc3b Signed-off-by: kibak.yoon --- src/hal/sensor_hal_types.h | 59 +++++++++++++++++++++++++---------------- src/shared/sensor_types.h | 66 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 82 insertions(+), 43 deletions(-) diff --git a/src/hal/sensor_hal_types.h b/src/hal/sensor_hal_types.h index 91630c4..9b7ccde 100644 --- a/src/hal/sensor_hal_types.h +++ b/src/hal/sensor_hal_types.h @@ -71,12 +71,47 @@ typedef enum { SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300, SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, + SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, + SENSOR_DEVICE_HUMAN_STRESS_MONITOR, + + SENSOR_DEVICE_EXERCISE_WALKING = 0x400, + SENSOR_DEVICE_EXERCISE_RUNNING, + SENSOR_DEVICE_EXERCISE_HIKING, + SENSOR_DEVICE_EXERCISE_CYCLING, + SENSOR_DEVICE_EXERCISE_STAIR_CLIMBING, + SENSOR_DEVICE_EXERCISE_ELLIPTICAL, + SENSOR_DEVICE_EXERCISE_INDOOR_CYCLING, + SENSOR_DEVICE_EXERCISE_ROWING, + SENSOR_DEVICE_EXERCISE_STEPPER, SENSOR_DEVICE_FUSION = 0x900, SENSOR_DEVICE_AUTO_ROTATION, SENSOR_DEVICE_AUTO_BRIGHTNESS, - SENSOR_DEVICE_CONTEXT = 0x1000, + SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200, + SENSOR_DEVICE_GESTURE_WRIST_UP, + SENSOR_DEVICE_GESTURE_WRIST_DOWN, + SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, + + SENSOR_DEVICE_GPS_BATCH = 0x1A00, + SENSOR_DEVICE_ACTIVITY_TRACKER, + + SENSOR_DEVICE_HRM_CTRL = 0x1A80, + SENSOR_DEVICE_EXERCISE_COACH, + SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, + + SENSOR_DEVICE_WEAR_STATUS = 0x2000, + SENSOR_DEVICE_WEAR_ON_MONITOR, + SENSOR_DEVICE_NO_MOVE_DETECTOR, + SENSOR_DEVICE_RESTING_HR, + SENSOR_DEVICE_STEP_LEVEL_MONITOR, + SENSOR_DEVICE_EXERCISE, + SENSOR_DEVICE_EXERCISE_HR, + SENSOR_DEVICE_WORKOUT, + SENSOR_DEVICE_CYCLE_MONITOR, + SENSOR_DEVICE_STAIR_TRACKER, + + SENSOR_DEVICE_CONTEXT = 0x7000, SENSOR_DEVICE_MOTION, SENSOR_DEVICE_PIR, SENSOR_DEVICE_PIR_LONG, @@ -87,32 +122,10 @@ typedef enum { SENSOR_DEVICE_HRM_RAW, SENSOR_DEVICE_TILT, SENSOR_DEVICE_ROTATION_VECTOR_RAW, - SENSOR_DEVICE_EXERCISE, SENSOR_DEVICE_GSR, SENSOR_DEVICE_SIMSENSE, SENSOR_DEVICE_PPG, - SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200, - SENSOR_DEVICE_GESTURE_WRIST_UP, - SENSOR_DEVICE_GESTURE_WRIST_DOWN, - SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, - - SENSOR_DEVICE_WEAR_STATUS = 0x1A00, - SENSOR_DEVICE_WEAR_ON_MONITOR, - SENSOR_DEVICE_GPS_BATCH, - SENSOR_DEVICE_ACTIVITY_TRACKER, - SENSOR_DEVICE_SLEEP_DETECTOR, - SENSOR_DEVICE_NO_MOVE_DETECTOR = 0x1A80, - SENSOR_DEVICE_HRM_CTRL, - SENSOR_DEVICE_EXERCISE_COACH, - SENSOR_DEVICE_EXERCISE_HR, - SENSOR_DEVICE_RESTING_HR, - SENSOR_DEVICE_STEP_LEVEL_MONITOR, - SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, - SENSOR_DEVICE_CYCLE_MONITOR, - SENSOR_DEVICE_STRESS_MONITOR, - SENSOR_DEVICE_AUTOSESSION_EXERCISE, - SENSOR_DEVICE_STAIR_TRACKER, } sensor_device_type; /* diff --git a/src/shared/sensor_types.h b/src/shared/sensor_types.h index cb8e65e..5c890b9 100644 --- a/src/shared/sensor_types.h +++ b/src/shared/sensor_types.h @@ -54,12 +54,47 @@ extern "C" \ DEF_SENSOR_VALUE(HUMAN_PEDOMETER_SENSOR, 0x300) \ DEF_SENSOR(HUMAN_SLEEP_MONITOR_SENSOR) \ + DEF_SENSOR(HUMAN_SLEEP_DETECTOR_SENSOR) \ + DEF_SENSOR(HUMAN_STRESS_MONITOR_SENSOR) \ + \ + DEF_SENSOR_VALUE(EXERCISE_WALKING_SENSOR, 0x400) \ + DEF_SENSOR(EXERCISE_RUNNING_SENSOR) \ + DEF_SENSOR(EXERCISE_HIKING_SENSOR) \ + DEF_SENSOR(EXERCISE_CYCLING_SENSOR) \ + DEF_SENSOR(EXERCISE_STAIR_CLIMBING_SENSOR) \ + DEF_SENSOR(EXERCISE_ELLIPTICAL_SENSOR) \ + DEF_SENSOR(EXERCISE_INDOOR_CYCLING_SENSOR) \ + DEF_SENSOR(EXERCISE_ROWING_SENSOR) \ + DEF_SENSOR(EXERCISE_STEPPER_SENSOR) \ \ DEF_SENSOR_VALUE(FUSION_SENSOR, 0x900) \ DEF_SENSOR(AUTO_ROTATION_SENSOR) \ DEF_SENSOR(AUTO_BRIGHTNESS_SENSOR) \ \ - DEF_SENSOR_VALUE(CONTEXT_SENSOR, 0x1000) \ + DEF_SENSOR_VALUE(GESTURE_MOVEMENT_SENSOR, 0x1200) \ + DEF_SENSOR(GESTURE_WRIST_UP_SENSOR) \ + DEF_SENSOR(GESTURE_WRIST_DOWN_SENSOR) \ + DEF_SENSOR(GESTURE_MOVEMENT_STATE_SENSOR) \ + \ + DEF_SENSOR_VALUE(GPS_BATCH_SENSOR, 0x1A00) \ + DEF_SENSOR(ACTIVITY_TRACKER_SENSOR) \ + \ + DEF_SENSOR_VALUE(HRM_CTRL_SENSOR, 0x1A80) \ + DEF_SENSOR(EXERCISE_COACH_SENSOR) \ + DEF_SENSOR(ACTIVITY_LEVEL_MONITOR_SENSOR) \ + \ + DEF_SENSOR_VALUE(WEAR_STATUS_SENSOR, 0x2000) \ + DEF_SENSOR(WEAR_ON_MONITOR_SENSOR) \ + DEF_SENSOR(NO_MOVE_DETECTOR_SENSOR) \ + DEF_SENSOR(RESTING_HR_SENSOR) \ + DEF_SENSOR(STEP_LEVEL_MONITOR_SENSOR) \ + DEF_SENSOR(EXERCISE_SENSOR) \ + DEF_SENSOR(EXERCISE_HR_SENSOR) \ + DEF_SENSOR(WORKOUT_SENSOR) \ + DEF_SENSOR(CYCLE_MONITOR_SENSOR) \ + DEF_SENSOR(STAIR_TRACKER_SENSOR) \ + \ + DEF_SENSOR_VALUE(CONTEXT_SENSOR, 0x7000) \ DEF_SENSOR(MOTION_SENSOR) \ DEF_SENSOR(PIR_SENSOR) \ DEF_SENSOR(PIR_LONG_SENSOR) \ @@ -70,30 +105,21 @@ extern "C" DEF_SENSOR(HRM_RAW_SENSOR) \ DEF_SENSOR(TILT_SENSOR) \ DEF_SENSOR(RV_RAW_SENSOR) \ - DEF_SENSOR(EXERCISE_SENSOR) \ - \ - DEF_SENSOR_VALUE(GESTURE_MOVEMENT_SENSOR, 0x1200) \ - DEF_SENSOR(GESTURE_WRIST_UP_SENSOR) \ - DEF_SENSOR(GESTURE_WRIST_DOWN_SENSOR) \ - DEF_SENSOR(GESTURE_MOVEMENT_STATE_SENSOR) \ - \ - DEF_SENSOR_VALUE(WEAR_STATUS_SENSOR, 0x1A00) \ - DEF_SENSOR(WEAR_ON_MONITOR_SENSOR) \ - DEF_SENSOR(GPS_BATCH_SENSOR) \ - DEF_SENSOR(ACTIVITY_TRACKER_SENSOR) \ - DEF_SENSOR(SLEEP_DETECTOR_SENSOR) \ -#define BIO_HRM_SENSOR HRM_SENSOR -#define BIO_LED_GREEN_SENSOR HRM_LED_GREEN_SENSOR -#define BIO_LED_IR_SENSOR HRM_LED_IR_SENSOR -#define BIO_LED_RED_SENSOR HRM_LED_RED_SENSOR -#define BIO_SENSOR HRM_RAW_SENSOR +#define BIO_HRM_SENSOR HRM_SENSOR +#define BIO_LED_GREEN_SENSOR HRM_LED_GREEN_SENSOR +#define BIO_LED_IR_SENSOR HRM_LED_IR_SENSOR +#define BIO_LED_RED_SENSOR HRM_LED_RED_SENSOR +#define BIO_SENSOR HRM_RAW_SENSOR +#define SLEEP_DETECTOR_SENSOR HUMAN_SLEEP_DETECTOR_SENSOR +#define STRESS_MONITOR_SENSOR HUMAN_STRESS_MONITOR_SENSOR +#define AUTOSESSION_EXERCISE_SENSOR WORKOUT_SENSOR DECLARE_SENSOR_ENUM(sensor_type_t, SENSOR_TYPE) enum proxi_change_state { - PROXIMITY_STATE_NEAR = 0, - PROXIMITY_STATE_FAR = 1, + PROXIMITY_STATE_NEAR = 0, + PROXIMITY_STATE_FAR = 1, }; enum auto_rotation_state { -- 2.7.4 From 7562c18dbaad2cd013843373635055456120b487 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 21 Jun 2016 12:45:25 +0900 Subject: [PATCH 06/16] sensord: rename and reorder sensor types - EXERCISE_COACH -> EXERCISE_STANDALONE - EXERCISE -> EXERCISE_COMPANION - EXERCISE_STAIR_CLIMBING -> X Change-Id: I43290e81ad9175bc2c63b46db7d6c98dcea62046 Signed-off-by: kibak.yoon --- src/hal/sensor_hal_types.h | 8 ++++---- src/shared/sensor_types.h | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hal/sensor_hal_types.h b/src/hal/sensor_hal_types.h index 9b7ccde..ffa96f1 100644 --- a/src/hal/sensor_hal_types.h +++ b/src/hal/sensor_hal_types.h @@ -78,7 +78,6 @@ typedef enum { SENSOR_DEVICE_EXERCISE_RUNNING, SENSOR_DEVICE_EXERCISE_HIKING, SENSOR_DEVICE_EXERCISE_CYCLING, - SENSOR_DEVICE_EXERCISE_STAIR_CLIMBING, SENSOR_DEVICE_EXERCISE_ELLIPTICAL, SENSOR_DEVICE_EXERCISE_INDOOR_CYCLING, SENSOR_DEVICE_EXERCISE_ROWING, @@ -97,7 +96,6 @@ typedef enum { SENSOR_DEVICE_ACTIVITY_TRACKER, SENSOR_DEVICE_HRM_CTRL = 0x1A80, - SENSOR_DEVICE_EXERCISE_COACH, SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, SENSOR_DEVICE_WEAR_STATUS = 0x2000, @@ -105,7 +103,7 @@ typedef enum { SENSOR_DEVICE_NO_MOVE_DETECTOR, SENSOR_DEVICE_RESTING_HR, SENSOR_DEVICE_STEP_LEVEL_MONITOR, - SENSOR_DEVICE_EXERCISE, + SENSOR_DEVICE_EXERCISE_STANDALONE, SENSOR_DEVICE_EXERCISE_HR, SENSOR_DEVICE_WORKOUT, SENSOR_DEVICE_CYCLE_MONITOR, @@ -219,8 +217,10 @@ typedef struct { } diffs[SENSOR_PEDOMETER_DATA_DIFFS_SIZE]; } sensor_pedometer_data_t; +#define CONVERT_TYPE_ATTR(type, index) ((type) << 8 | 0x80 | (index)) + enum sensor_attribute { - SENSOR_ATTR_ACTIVITY = 0x100, + SENSOR_ATTR_ACTIVITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_ACTIVITY_TRACKER, 0x1), }; enum sensor_activity { diff --git a/src/shared/sensor_types.h b/src/shared/sensor_types.h index 5c890b9..0612f72 100644 --- a/src/shared/sensor_types.h +++ b/src/shared/sensor_types.h @@ -61,7 +61,6 @@ extern "C" DEF_SENSOR(EXERCISE_RUNNING_SENSOR) \ DEF_SENSOR(EXERCISE_HIKING_SENSOR) \ DEF_SENSOR(EXERCISE_CYCLING_SENSOR) \ - DEF_SENSOR(EXERCISE_STAIR_CLIMBING_SENSOR) \ DEF_SENSOR(EXERCISE_ELLIPTICAL_SENSOR) \ DEF_SENSOR(EXERCISE_INDOOR_CYCLING_SENSOR) \ DEF_SENSOR(EXERCISE_ROWING_SENSOR) \ @@ -78,9 +77,9 @@ extern "C" \ DEF_SENSOR_VALUE(GPS_BATCH_SENSOR, 0x1A00) \ DEF_SENSOR(ACTIVITY_TRACKER_SENSOR) \ + DEF_SENSOR(EXERCISE_COMPANION_SENSOR) \ \ DEF_SENSOR_VALUE(HRM_CTRL_SENSOR, 0x1A80) \ - DEF_SENSOR(EXERCISE_COACH_SENSOR) \ DEF_SENSOR(ACTIVITY_LEVEL_MONITOR_SENSOR) \ \ DEF_SENSOR_VALUE(WEAR_STATUS_SENSOR, 0x2000) \ @@ -88,7 +87,7 @@ extern "C" DEF_SENSOR(NO_MOVE_DETECTOR_SENSOR) \ DEF_SENSOR(RESTING_HR_SENSOR) \ DEF_SENSOR(STEP_LEVEL_MONITOR_SENSOR) \ - DEF_SENSOR(EXERCISE_SENSOR) \ + DEF_SENSOR(EXERCISE_STANDALONE_SENSOR) \ DEF_SENSOR(EXERCISE_HR_SENSOR) \ DEF_SENSOR(WORKOUT_SENSOR) \ DEF_SENSOR(CYCLE_MONITOR_SENSOR) \ @@ -114,6 +113,8 @@ extern "C" #define SLEEP_DETECTOR_SENSOR HUMAN_SLEEP_DETECTOR_SENSOR #define STRESS_MONITOR_SENSOR HUMAN_STRESS_MONITOR_SENSOR #define AUTOSESSION_EXERCISE_SENSOR WORKOUT_SENSOR +#define EXERCISE_COACH_SENSOR EXERCISE_STANDALONE_SENSOR +#define EXERCISE_SENSOR EXERCISE_COMPANION_SENSOR DECLARE_SENSOR_ENUM(sensor_type_t, SENSOR_TYPE) -- 2.7.4 From fda09ec118138917b72afad8ab21f12988ce33e9 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 22 Jun 2016 19:07:50 +0900 Subject: [PATCH 07/16] sensord: fix the bug which converts wrong pause policy Change-Id: I655ccde45a65637672fb9c23141e66b32d34c2c7 Signed-off-by: kibak.yoon --- src/client/client.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index b900db4..129958c 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -44,9 +44,7 @@ using std::vector; #define DEFAULT_INTERVAL POLL_10HZ_MS -#define CONVERT_OPTION_PAUSE_POLICY(option) \ - (option == SENSOR_OPTION_DEFAULT || option == SENSOR_OPTION_ALWAYS_ON) ? \ - (option ^ 0b11) : option +#define CONVERT_OPTION_PAUSE_POLICY(option) ((option) ^ 0b11) static cmutex lock; -- 2.7.4 From a0b71120db332e7ae23da7ebb3dd1f2c8db2fa91 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 27 Jun 2016 13:27:25 +0900 Subject: [PATCH 08/16] sensord: clean up switch-case statement if attribute is not global. - if it is a default attribute in switch-case statement, break and call set_attribute_int() function. Change-Id: I1bf0403ad268a8465190439acd9c1ebe320cda2c Signed-off-by: kibak.yoon --- src/client/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 129958c..171cb88 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1129,10 +1129,10 @@ API int sensord_set_attribute_int(int handle, int attribute, int value) case SENSORD_ATTRIBUTE_AXIS_ORIENTATION: return change_axis_orientation(handle, value); default: - return change_attribute_int(handle, attribute, value); + break; } - return OP_SUCCESS; + return change_attribute_int(handle, attribute, value); } API int sensord_set_attribute_str(int handle, int attribute, const char *value, int value_len) -- 2.7.4 From 0bd9a6b6dba2efc5a269279a0eefacd892b885fd Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 29 Jun 2016 11:51:58 +0900 Subject: [PATCH 09/16] sensord: remove unused sensor_config sources - device_config - virtual_sensor_config Change-Id: I91eb3abf9c062c6dd0576b846440fc199b6be89f Signed-off-by: kibak.yoon --- packaging/sensord.spec | 1 - src/sensor/virtual_sensors.xml | 271 ------------------------------ src/server/CMakeLists.txt | 2 +- src/server/device_config.cpp | 72 -------- src/server/device_config.h | 40 ----- src/server/virtual_sensor_config.cpp | 315 ----------------------------------- src/server/virtual_sensor_config.h | 83 --------- 7 files changed, 1 insertion(+), 783 deletions(-) delete mode 100644 src/sensor/virtual_sensors.xml delete mode 100644 src/server/device_config.cpp delete mode 100644 src/server/device_config.h delete mode 100644 src/server/virtual_sensor_config.cpp delete mode 100644 src/server/virtual_sensor_config.h diff --git a/packaging/sensord.spec b/packaging/sensord.spec index e743bc9..9111df8 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -12,7 +12,6 @@ Source3: sensord_event.socket BuildRequires: cmake BuildRequires: libattr-devel BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(libsystemd-daemon) diff --git a/src/sensor/virtual_sensors.xml b/src/sensor/virtual_sensors.xml deleted file mode 100644 index c0c08f5..0000000 --- a/src/sensor/virtual_sensors.xml +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 50ac418..763e904 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -1,7 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(sensord CXX) -SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon libxml-2.0 cynara-client cynara-creds-socket cynara-session") +SET(DEPENDENTS "glib-2.0 gio-2.0 dlog libsystemd-daemon cynara-client cynara-creds-socket cynara-session") INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(SERVER_PKGS REQUIRED ${DEPENDENTS}) diff --git a/src/server/device_config.cpp b/src/server/device_config.cpp deleted file mode 100644 index 082b6d6..0000000 --- a/src/server/device_config.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include - -using std::ifstream; -using std::string; -using std::istringstream; - -device_config::device_config(void) -{ -} - -device_config::~device_config(void) -{ -} - -bool device_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) - continue; - - start_pos = start_pos + START_DELIMETER.size(); - end_pos = line.find(END_DELIMETER, start_pos); - - if (end_pos == std::string::npos) - continue; - - m_device_id = line.substr(start_pos, end_pos - start_pos); - ret = true; - break; - } - - in_file.close(); - - return ret; -} diff --git a/src/server/device_config.h b/src/server/device_config.h deleted file mode 100644 index 5c73509..0000000 --- a/src/server/device_config.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2016 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 _DEVICE_CONFIG_H_ -#define _DEVICE_CONFIG_H_ - -#include -#include -#include - -class device_config { -public: - device_config(); - virtual ~device_config(); - - bool get_device_id(void); - -protected: - virtual bool load_config(const std::string& config_path) = 0; - - std::string m_device_id; -}; - -#endif /* _DEVICE_CONFIG_H_ */ diff --git a/src/server/virtual_sensor_config.cpp b/src/server/virtual_sensor_config.cpp deleted file mode 100644 index fc57bd8..0000000 --- a/src/server/virtual_sensor_config.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include "sensor_log.h" -#include -#include -#include -#include -#include - -using std::string; -using std::stringstream; - -#define ROOT_ELEMENT "VIRTUAL_SENSOR" -#define DEVICE_TYPE_ATTR "type" -#define TEXT_ELEMENT "text" -#define DEFAULT_ATTR "value" -#define DEFAULT_ATTR1 "value1" -#define DEFAULT_ATTR2 "value2" -#define DEFAULT_ATTR3 "value3" -#define DEFAULT_DEVICE "Default" - -virtual_sensor_config::virtual_sensor_config() -{ -} - -virtual_sensor_config& virtual_sensor_config::get_instance(void) -{ - static bool load_done = false; - static virtual_sensor_config inst; - - if (!load_done) { - inst.load_config(VIRTUAL_SENSOR_CONFIG_FILE_PATH); - inst.get_device_id(); - if (!inst.m_device_id.empty()) - _I("Device ID = %s", inst.m_device_id.c_str()); - else - _E("Failed to get Device ID"); - load_done = true; - } - - return inst; -} - -bool virtual_sensor_config::load_config(const string& config_path) -{ - xmlDocPtr doc; - xmlNodePtr cur; - - _D("virtual_sensor_config::load_config(\"%s\") is called!\n", config_path.c_str()); - - doc = xmlParseFile(config_path.c_str()); - - if (doc == NULL) { - _E("There is no %s\n", config_path.c_str()); - return false; - } - - cur = xmlDocGetRootElement(doc); - if (cur == NULL) { - _E("There is no root element in %s\n", config_path.c_str()); - xmlFreeDoc(doc); - return false; - } - - if (xmlStrcmp(cur->name, (const xmlChar *)ROOT_ELEMENT)) { - _E("Wrong type document: there is no [%s] root element in %s\n", ROOT_ELEMENT, config_path.c_str()); - xmlFreeDoc(doc); - return false; - } - - xmlNodePtr device_node_ptr; - xmlNodePtr virtual_sensor_node_ptr; - xmlNodePtr element_node_ptr; - xmlAttrPtr attr_ptr; - char* prop = NULL; - - device_node_ptr = cur->xmlChildrenNode; - while (device_node_ptr != NULL){ - //skip garbage element, [text] - if (!xmlStrcmp(device_node_ptr->name, (const xmlChar *)TEXT_ELEMENT)) { - device_node_ptr = device_node_ptr->next; - continue; - } - - string device_type; - prop = (char*)xmlGetProp(device_node_ptr, (const xmlChar*)DEVICE_TYPE_ATTR); - device_type = prop; - free(prop); - - //insert device to device_list - m_virtual_sensor_configs[device_type]; - _D("\n", device_type.c_str()); - - virtual_sensor_node_ptr = device_node_ptr->xmlChildrenNode; - - while (virtual_sensor_node_ptr != NULL) { - //skip garbage element, [text] - if (!xmlStrcmp(virtual_sensor_node_ptr->name, (const xmlChar *)TEXT_ELEMENT)) { - virtual_sensor_node_ptr = virtual_sensor_node_ptr->next; - continue; - } - - m_virtual_sensor_configs[device_type][(const char*)virtual_sensor_node_ptr->name]; - _D("<%s>\n", device_type.c_str(), (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_configs[device_type][(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name]; - _D("<%s><%s>\n", device_type.c_str(), (const char*)virtual_sensor_node_ptr->name, (const char*)element_node_ptr->name); - - attr_ptr = element_node_ptr->properties; - while (attr_ptr != NULL) { - string key, value; - key = (char*)attr_ptr->name; - prop = (char*)xmlGetProp(element_node_ptr, attr_ptr->name); - value = prop; - free(prop); - - //insert attribute to Element - m_virtual_sensor_configs[device_type][(const char*)virtual_sensor_node_ptr->name][(const char*)element_node_ptr->name][key] = value; - _D("<%s><%s \"%s\"=\"%s\">\n", device_type.c_str(), (const char*)virtual_sensor_node_ptr->name, (const char*)element_node_ptr->name, key.c_str(), value.c_str()); - attr_ptr = attr_ptr->next; - } - - element_node_ptr = element_node_ptr->next; - } - - _D("\n"); - virtual_sensor_node_ptr = virtual_sensor_node_ptr->next; - } - - device_node_ptr = device_node_ptr->next; - } - - xmlFreeDoc(doc); - return true; -} - -bool virtual_sensor_config::get(const string& sensor_type, const string& element, const string& attr, string& value) -{ - auto it_device_list = m_virtual_sensor_configs.find(m_device_id); - - if (it_device_list == m_virtual_sensor_configs.end()) { - _E("There is no <%s> device\n", m_device_id.c_str()); - - m_device_id = DEFAULT_DEVICE; - it_device_list = m_virtual_sensor_configs.find(m_device_id); - - if (it_device_list == m_virtual_sensor_configs.end()) { - _E("There is no Default device\n"); - return false; - } - - _I("m_device_id is set to Default\n"); - } - - auto it_virtual_sensor_list = it_device_list->second.find(sensor_type); - - if (it_virtual_sensor_list == it_device_list->second.end()) { - _E("There is no <%s> sensor\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()) { - _E("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()) { - _D("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 virtual_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 virtual_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 virtual_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 virtual_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; - } - - 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; - } - - _D("Count value not supported.\n"); - - return false; -} - -bool virtual_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; - } - - 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; - } - - _D("Count value not supported.\n"); - - return false; -} - -bool virtual_sensor_config::is_supported(const string& sensor_type) -{ - auto it_device_list = m_virtual_sensor_configs.find(m_device_id); - - if (it_device_list == m_virtual_sensor_configs.end()) - return false; - - auto it_virtual_sensor_list = it_device_list->second.find(sensor_type); - - if (it_virtual_sensor_list == it_device_list->second.end()) - return false; - - return true; -} diff --git a/src/server/virtual_sensor_config.h b/src/server/virtual_sensor_config.h deleted file mode 100644 index 949d840..0000000 --- a/src/server/virtual_sensor_config.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef _VIRTUAL_SENSOR_CONFIG_H_ -#define _VIRTUAL_SENSOR_CONFIG_H_ - -#include - -#define VIRTUAL_SENSOR_CONFIG_FILE_PATH "/usr/etc/virtual_sensors.xml" - -typedef std::unordered_map Element; -/* -* an Element is a group of attributes -* -* -*/ - -typedef std::unordered_map Virtual_sensor; -/* -* a Virtual_sensor is a group of elements to consist of one virtual sensor's configuration -* -* -* -* ... -*/ - -typedef std::unordered_map virtual_sensor_configs; -/* -* a Virtual_sensor_config represents virtual_sensors.xml -* -* -* -* -*/ - -typedef std::unordered_map virtual_sensor_device_configs; -/* -* a virtual_sensor_device_config represents virtual_sensors.xml -* -* -* -*/ - -class virtual_sensor_config : public device_config { -private: - virtual_sensor_config(); - virtual_sensor_config& operator=(virtual_sensor_config const&); - - bool load_config(const std::string& config_path); - - virtual_sensor_device_configs m_virtual_sensor_configs; - -public: - static virtual_sensor_config& get_instance(void); - - bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, std::string& value); - bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, float *value); - bool get(const std::string& sensor_type, const std::string& element, const std::string& attr, int *value); - - bool get(const std::string& sensor_type, const std::string& element, std::string& value); - bool get(const std::string& sensor_type, const std::string& element, float *value, int count = 1); - bool get(const std::string& sensor_type, const std::string& element, int *value, int count = 1); - - bool is_supported(const std::string &sensor_type); -}; - -#endif /* _VIRTUAL_SENSOR_CONFIG_H_ */ -- 2.7.4 From 54eed59e2f0dc5ba2f3d3bd11d5abf0c78f090bc Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 29 Jun 2016 17:04:20 +0900 Subject: [PATCH 10/16] sensord: fix wrong log in case of setting batch latency Change-Id: I9254577b0ac02b44645578e1680550e7672b3bef Signed-off-by: kibak.yoon --- src/server/physical_sensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/physical_sensor.cpp b/src/server/physical_sensor.cpp index 9bc53ea..96cb7f0 100644 --- a/src/server/physical_sensor.cpp +++ b/src/server/physical_sensor.cpp @@ -147,7 +147,7 @@ bool physical_sensor::set_batch_latency(unsigned long latency) if (!m_sensor_device) return false; - _I("Polling interval is set to %dms", latency); + _I("Batch latency is set to %dms", latency); return m_sensor_device->set_batch_latency(m_info->id, latency); } -- 2.7.4 From c1e1d210100f99c32e78588a71abe9e7babdd1ef Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 30 Jun 2016 11:29:22 +0900 Subject: [PATCH 11/16] sensord: version 2.0.6 Change-Id: I03bd5c537de1f3ad27d9f5cc6d5f1ce0f72b90c1 Signed-off-by: kibak.yoon --- packaging/sensord.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 9111df8..8af0b2d 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -1,6 +1,6 @@ Name: sensord Summary: Sensor daemon -Version: 2.0.5 +Version: 2.0.6 Release: 0 Group: System/Sensor Framework License: Apache-2.0 -- 2.7.4 From 1854e42b3a7a86d03267323a875c30043b470f37 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 30 Jun 2016 23:02:17 +0900 Subject: [PATCH 12/16] sensord: print errno log when proper errors are returned Change-Id: Ib89d28b1b75fc4ef563536f643633928ab0ec17e Signed-off-by: kibak.yoon --- src/shared/csocket.cpp | 53 ++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 09a7d0e..3b55107 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -241,29 +241,26 @@ ssize_t csocket::send_for_stream(const void *buffer, size_t size) const do { len = ::send(m_sock_fd, (const void *)((uint8_t *)buffer + total_sent_size), size - total_sent_size, m_send_flags); - if (len >= 0) { - total_sent_size += len; - err = 0; - } else { - _ERRNO(errno, _E, "Failed to send(%d, %#p + %d, %d - %d) = %d for %s", - m_sock_fd, buffer, total_sent_size, size, total_sent_size, - len, get_client_name()); - + if (len < 0) { /* * If socket is not available to use it temporarily, - * EAGAIN(EWOULDBLOCK) is returned by ::send(). + * EAGAIN(EWOULDBLOCK) or EINTR is returned by ::send(). * so in order to prevent that data are omitted, sleep&retry to send it */ - if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { - usleep(1000); + if ((errno == EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK)) { + usleep(10000); continue; } - if (errno != EINTR) { - err = errno; - break; - } + _ERRNO(errno, _E, "Failed to send(%d, %#p + %d, %d - %d) = %d for %s", + m_sock_fd, buffer, total_sent_size, size, total_sent_size, + len, get_client_name()); + + err = errno; + break; } + + total_sent_size += len; } while (total_sent_size < size); return err == 0 ? total_sent_size : -err; @@ -278,33 +275,33 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const do { len = ::recv(m_sock_fd, (void *)((uint8_t *)buffer + total_recv_size), size - total_recv_size, m_recv_flags); - if (len > 0) { - total_recv_size += len; - } else if (len == 0) { + if (len == 0) { _E("recv(%d, %#p + %d, %d - %d) = %d, because the peer of %s performed shutdown!", m_sock_fd, buffer, total_recv_size, size, total_recv_size, len, get_client_name()); err = 1; break; - } else { - _ERRNO(errno, _E, "Failed to recv(%d, %#p + %d, %d - %d) = %d for %s", - m_sock_fd, buffer, total_recv_size, size, total_recv_size, - len, get_client_name()); + } + if (len < 0) { /* * If socket is not available to use it temporarily, * EAGAIN(EWOULDBLOCK) is returned by ::recv(). * so in order to prevent that data are omitted, sleep&retry to receive it */ - if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { - usleep(1000); + if ((errno != EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK)) { + usleep(10000); continue; } - if (errno != EINTR) { - err = errno; - break; - } + _ERRNO(errno, _E, "Failed to recv(%d, %#p + %d, %d - %d) = %d for %s", + m_sock_fd, buffer, total_recv_size, size, total_recv_size, + len, get_client_name()); + + err = errno; + break; } + + total_recv_size += len; } while (total_recv_size < size); return err == 0 ? total_recv_size : -err; -- 2.7.4 From 61f313be33ef4017cc02f370d5c7018380528363 Mon Sep 17 00:00:00 2001 From: "hs81.go" Date: Fri, 1 Jul 2016 14:05:45 +0900 Subject: [PATCH 13/16] sensord: modify enum values for classification Change-Id: I0db7552f2c29f1805a20f13f47a7d79a73f0adec Signed-off-by: kibak.yoon --- src/hal/sensor_hal_types.h | 6 +++--- src/shared/sensor_types.h | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/hal/sensor_hal_types.h b/src/hal/sensor_hal_types.h index ffa96f1..6c30f47 100644 --- a/src/hal/sensor_hal_types.h +++ b/src/hal/sensor_hal_types.h @@ -92,11 +92,11 @@ typedef enum { SENSOR_DEVICE_GESTURE_WRIST_DOWN, SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, - SENSOR_DEVICE_GPS_BATCH = 0x1A00, - SENSOR_DEVICE_ACTIVITY_TRACKER, + SENSOR_DEVICE_ACTIVITY_TRACKER = 0x1A00, + SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, + SENSOR_DEVICE_GPS_BATCH, SENSOR_DEVICE_HRM_CTRL = 0x1A80, - SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, SENSOR_DEVICE_WEAR_STATUS = 0x2000, SENSOR_DEVICE_WEAR_ON_MONITOR, diff --git a/src/shared/sensor_types.h b/src/shared/sensor_types.h index 0612f72..277cbc4 100644 --- a/src/shared/sensor_types.h +++ b/src/shared/sensor_types.h @@ -75,12 +75,11 @@ extern "C" DEF_SENSOR(GESTURE_WRIST_DOWN_SENSOR) \ DEF_SENSOR(GESTURE_MOVEMENT_STATE_SENSOR) \ \ - DEF_SENSOR_VALUE(GPS_BATCH_SENSOR, 0x1A00) \ - DEF_SENSOR(ACTIVITY_TRACKER_SENSOR) \ - DEF_SENSOR(EXERCISE_COMPANION_SENSOR) \ + DEF_SENSOR_VALUE(ACTIVITY_TRACKER_SENSOR, 0x1A00) \ + DEF_SENSOR(ACTIVITY_LEVEL_MONITOR_SENSOR) \ + DEF_SENSOR(GPS_BATCH_SENSOR) \ \ DEF_SENSOR_VALUE(HRM_CTRL_SENSOR, 0x1A80) \ - DEF_SENSOR(ACTIVITY_LEVEL_MONITOR_SENSOR) \ \ DEF_SENSOR_VALUE(WEAR_STATUS_SENSOR, 0x2000) \ DEF_SENSOR(WEAR_ON_MONITOR_SENSOR) \ @@ -114,7 +113,6 @@ extern "C" #define STRESS_MONITOR_SENSOR HUMAN_STRESS_MONITOR_SENSOR #define AUTOSESSION_EXERCISE_SENSOR WORKOUT_SENSOR #define EXERCISE_COACH_SENSOR EXERCISE_STANDALONE_SENSOR -#define EXERCISE_SENSOR EXERCISE_COMPANION_SENSOR DECLARE_SENSOR_ENUM(sensor_type_t, SENSOR_TYPE) -- 2.7.4 From d33da5b5ef6e18713c32c371d0714246af6c337b Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Wed, 20 Jul 2016 20:28:46 +0900 Subject: [PATCH 14/16] Set SmackProcessLabel to System Change-Id: Ic6db23e47dfc46aeade072e08a8396b4505774a5 Signed-off-by: Yunjin Lee --- packaging/sensord.service | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/sensord.service b/packaging/sensord.service index 5cb2e72..031b383 100644 --- a/packaging/sensord.service +++ b/packaging/sensord.service @@ -5,6 +5,7 @@ Description=Sensor Daemon User=sensor Group=input Type=notify +SmackProcessLabel=System ExecStart=/usr/bin/sensord MemoryLimit=20M Sockets=sensord_command.socket -- 2.7.4 From 0c00a6c13a8be9ffaf27a7b2e5eba2cbe7abdd7f Mon Sep 17 00:00:00 2001 From: akhilkedia94 Date: Fri, 29 Jul 2016 15:27:17 +0900 Subject: [PATCH 15/16] Porting Sensor Fusion to Tizen 3.0 Change-Id: I8607fea652431cf277d7f9a577686c77318052bc Signed-off-by: akhilkedia94 --- .gitignore | 1 + src/sensor/CMakeLists.txt | 5 +- src/sensor/fusion/fusion_sensor.cpp | 440 --------------------- src/sensor/fusion/fusion_sensor.h | 81 ---- .../documentation}/hardware_fusion_sensor.html | 0 src/sensor/sensor_fusion/fusion.h | 37 ++ src/sensor/sensor_fusion/fusion_base.cpp | 105 +++++ src/sensor/sensor_fusion/fusion_base.h | 60 +++ src/sensor/sensor_fusion/gyro_fusion.cpp | 39 ++ src/sensor/sensor_fusion/gyro_fusion.h | 33 ++ src/sensor/sensor_fusion/gyro_magnetic_fusion.cpp | 40 ++ src/sensor/sensor_fusion/gyro_magnetic_fusion.h | 33 ++ src/sensor/sensor_fusion/magnetic_fusion.cpp | 39 ++ src/sensor/sensor_fusion/magnetic_fusion.h | 33 ++ src/sensor/sensor_fusion/orientation_filter.cpp | 4 +- src/sensor/sensor_fusion/orientation_filter.h | 2 - src/sensor/sensor_fusion/sensor_data.cpp | 9 +- src/sensor/sensor_fusion/sensor_data.h | 2 +- .../sensor_fusion/test/orientation_sensor.cpp | 2 - 19 files changed, 429 insertions(+), 536 deletions(-) delete mode 100644 src/sensor/fusion/fusion_sensor.cpp delete mode 100644 src/sensor/fusion/fusion_sensor.h rename src/sensor/{fusion => sensor_fusion/design/documentation}/hardware_fusion_sensor.html (100%) create mode 100644 src/sensor/sensor_fusion/fusion.h create mode 100644 src/sensor/sensor_fusion/fusion_base.cpp create mode 100644 src/sensor/sensor_fusion/fusion_base.h create mode 100644 src/sensor/sensor_fusion/gyro_fusion.cpp create mode 100644 src/sensor/sensor_fusion/gyro_fusion.h create mode 100644 src/sensor/sensor_fusion/gyro_magnetic_fusion.cpp create mode 100644 src/sensor/sensor_fusion/gyro_magnetic_fusion.h create mode 100644 src/sensor/sensor_fusion/magnetic_fusion.cpp create mode 100644 src/sensor/sensor_fusion/magnetic_fusion.h diff --git a/.gitignore b/.gitignore index 8b1529d..ca9cbd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .project .cproject .*.swp +nbproject diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt index 7328a1d..0547bc8 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/sensor/CMakeLists.txt @@ -14,7 +14,7 @@ ELSE() SET(RV "OFF") SET(ORIENTATION "OFF") ENDIF() -SET(FUSION "OFF") +SET(FUSION "ON") SET(MOTION "OFF") INCLUDE_DIRECTORIES( @@ -64,7 +64,8 @@ IF("${RV}" STREQUAL "ON") SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_ROTATION_VECTOR") ENDIF() IF("${FUSION}" STREQUAL "ON") -add_subdirectory(fusion) +FILE(GLOB SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/sensor_fusion/*.cpp) +SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/sensor_fusion) ENDIF() IF("${MOTION}" STREQUAL "ON") add_subdirectory(motion) diff --git a/src/sensor/fusion/fusion_sensor.cpp b/src/sensor/fusion/fusion_sensor.cpp deleted file mode 100644 index ff56ead..0000000 --- a/src/sensor/fusion/fusion_sensor.cpp +++ /dev/null @@ -1,440 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using std::string; -using std::vector; - -#define SENSOR_NAME "FUSION_SENSOR" -#define SENSOR_TYPE_FUSION "FUSION" - -#define ACCELEROMETER_ENABLED 0x01 -#define GYROSCOPE_ENABLED 0x02 -#define GEOMAGNETIC_ENABLED 0x04 -#define TILT_ENABLED 1 -#define GAMING_RV_ENABLED 3 -#define GEOMAGNETIC_RV_ENABLED 5 -#define ORIENTATION_ENABLED 7 -#define ROTATION_VECTOR_ENABLED 7 -#define GYROSCOPE_UNCAL_ENABLED 7 - -#define INITIAL_VALUE -1 - -#define MS_TO_US 1000 -#define MIN_DELIVERY_DIFF_FACTOR 0.75f - -#define PI 3.141593 -#define AZIMUTH_OFFSET_DEGREES 360 -#define AZIMUTH_OFFSET_RADIANS (2 * PI) - -#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_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" - -fusion_sensor::fusion_sensor() -: m_accel_sensor(NULL) -, m_gyro_sensor(NULL) -, m_magnetic_sensor(NULL) -, m_time(0) -{ - virtual_sensor_config &config = virtual_sensor_config::get_instance(); - m_name = string(SENSOR_NAME); - m_enable_fusion = 0; - - if (!config.get(SENSOR_TYPE_FUSION, ELEMENT_VENDOR, m_vendor)) { - _E("[VENDOR] is empty\n"); - throw ENXIO; - } - - _I("m_vendor = %s", m_vendor.c_str()); - - if (!config.get(SENSOR_TYPE_FUSION, ELEMENT_RAW_DATA_UNIT, m_raw_data_unit)) { - _E("[RAW_DATA_UNIT] is empty\n"); - throw ENXIO; - } - - _I("m_raw_data_unit = %s", m_raw_data_unit.c_str()); - - if (!config.get(SENSOR_TYPE_FUSION, ELEMENT_DEFAULT_SAMPLING_TIME, &m_default_sampling_time)) { - _E("[DEFAULT_SAMPLING_TIME] is empty\n"); - throw ENXIO; - } - - _I("m_default_sampling_time = %d", m_default_sampling_time); - - if (!config.get(SENSOR_TYPE_FUSION, ELEMENT_ACCEL_STATIC_BIAS, m_accel_static_bias, 3)) { - _E("[ACCEL_STATIC_BIAS] is empty\n"); - throw ENXIO; - } - - _I("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_FUSION, ELEMENT_GYRO_STATIC_BIAS, m_gyro_static_bias, 3)) { - _E("[GYRO_STATIC_BIAS] is empty\n"); - throw ENXIO; - } - - _I("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_FUSION, ELEMENT_GEOMAGNETIC_STATIC_BIAS, m_geomagnetic_static_bias, 3)) { - _E("[GEOMAGNETIC_STATIC_BIAS] is empty\n"); - throw ENXIO; - } - - _I("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_FUSION, ELEMENT_ACCEL_ROTATION_DIRECTION_COMPENSATION, m_accel_rotation_direction_compensation, 3)) { - _E("[ACCEL_ROTATION_DIRECTION_COMPENSATION] is empty\n"); - throw ENXIO; - } - - _I("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_FUSION, ELEMENT_GYRO_ROTATION_DIRECTION_COMPENSATION, m_gyro_rotation_direction_compensation, 3)) { - _E("[GYRO_ROTATION_DIRECTION_COMPENSATION] is empty\n"); - throw ENXIO; - } - - _I("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_FUSION, ELEMENT_GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION, m_geomagnetic_rotation_direction_compensation, 3)) { - _E("[GEOMAGNETIC_ROTATION_DIRECTION_COMPENSATION] is empty\n"); - throw ENXIO; - } - - _I("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_FUSION, ELEMENT_MAGNETIC_ALIGNMENT_FACTOR, &m_magnetic_alignment_factor)) { - _E("[MAGNETIC_ALIGNMENT_FACTOR] is empty\n"); - throw ENXIO; - } - - _I("m_magnetic_alignment_factor = %d", m_magnetic_alignment_factor); - - m_interval = m_default_sampling_time * MS_TO_US; - - m_accel_ptr = m_gyro_ptr = m_magnetic_ptr = NULL; -} - -fusion_sensor::~fusion_sensor() -{ - _I("fusion_sensor is destroyed!\n"); -} - -bool fusion_sensor::init(void) -{ - m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); - m_gyro_sensor = sensor_loader::get_instance().get_sensor(GYROSCOPE_SENSOR); - m_magnetic_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); - - if (!m_accel_sensor) { - _E("Failed to load accel sensor: %#x", m_accel_sensor); - return false; - } - - if (!m_gyro_sensor) - _I("Failed to load gyro sensor: %#x", m_gyro_sensor); - - if (!m_magnetic_sensor) - _I("Failed to load geomagnetic sensor: %#x", m_magnetic_sensor); - - _I("%s is created!", sensor_base::get_name()); - return true; -} - -void fusion_sensor::get_types(vector &types) -{ - types.push_back(FUSION_SENSOR); -} - -bool fusion_sensor::on_start(void) -{ - AUTOLOCK(m_mutex); - activate(); - return true; -} - -bool fusion_sensor::on_stop(void) -{ - AUTOLOCK(m_mutex); - deactivate(); - return true; -} - -bool fusion_sensor::add_interval(int client_id, unsigned int interval) -{ - bool retval; - - AUTOLOCK(m_mutex); - retval = sensor_base::add_interval(client_id, interval, false); - - m_interval = sensor_base::get_interval(client_id, false); - - if (m_interval != 0) - retval = true; - - return retval; -} - -bool fusion_sensor::delete_interval(int client_id) -{ - bool retval; - - AUTOLOCK(m_mutex); - retval = sensor_base::delete_interval(client_id, false); - - m_interval = sensor_base::get_interval(client_id, false); - - if (m_interval != 0) - retval = true; - - return retval; -} - -void fusion_sensor::synthesize(const sensor_event_t &event, vector &outs) -{ - unsigned long long diff_time; - euler_angles euler_orientation; - - if (event.event_type == ACCELEROMETER_RAW_DATA_EVENT) { - diff_time = event.data.timestamp - m_time; - - if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) - return; - - pre_process_data(m_accel, event.data.values, m_accel_static_bias, m_accel_rotation_direction_compensation, ACCEL_SCALE); - - m_accel.m_time_stamp = event.data.timestamp; - - m_accel_ptr = &m_accel; - - m_enable_fusion |= ACCELEROMETER_ENABLED; - } - - if (sensor_base::is_supported(FUSION_ORIENTATION_ENABLED) || - sensor_base::is_supported(FUSION_ROTATION_VECTOR_ENABLED) || - sensor_base::is_supported(FUSION_GEOMAGNETIC_ROTATION_VECTOR_ENABLED) || - sensor_base::is_supported(FUSION_GYROSCOPE_UNCAL_ENABLED)) { - if (event.event_type == GEOMAGNETIC_RAW_DATA_EVENT) { - diff_time = event.data.timestamp - m_time; - - if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) - return; - - pre_process_data(m_magnetic, event.data.values, m_geomagnetic_static_bias, m_geomagnetic_rotation_direction_compensation, GEOMAGNETIC_SCALE); - - m_magnetic.m_time_stamp = event.data.timestamp; - - m_magnetic_ptr = &m_magnetic; - - m_enable_fusion |= GEOMAGNETIC_ENABLED; - } - } - - if (sensor_base::is_supported(FUSION_ORIENTATION_ENABLED) || - sensor_base::is_supported(FUSION_ROTATION_VECTOR_ENABLED) || - sensor_base::is_supported(FUSION_GAMING_ROTATION_VECTOR_ENABLED) || - sensor_base::is_supported(FUSION_GYROSCOPE_UNCAL_ENABLED)) { - if (event.event_type == GYROSCOPE_RAW_DATA_EVENT) { - diff_time = event.data.timestamp - m_time; - - if (m_time && (diff_time < m_interval * MIN_DELIVERY_DIFF_FACTOR)) - return; - - pre_process_data(m_gyro, event.data.values, m_gyro_static_bias, m_gyro_rotation_direction_compensation, GYRO_SCALE); - - m_gyro.m_time_stamp = event.data.timestamp; - - m_gyro_ptr = &m_gyro; - - m_enable_fusion |= GYROSCOPE_ENABLED; - } - } - - if ((m_enable_fusion == TILT_ENABLED && sensor_base::is_supported(FUSION_TILT_ENABLED)) || - (m_enable_fusion == ORIENTATION_ENABLED && sensor_base::is_supported(FUSION_ORIENTATION_ENABLED)) || - (m_enable_fusion == ROTATION_VECTOR_ENABLED && sensor_base::is_supported(FUSION_ROTATION_VECTOR_ENABLED)) || - (m_enable_fusion == GAMING_RV_ENABLED && sensor_base::is_supported(FUSION_GAMING_ROTATION_VECTOR_ENABLED)) || - (m_enable_fusion == GEOMAGNETIC_RV_ENABLED && sensor_base::is_supported(FUSION_GEOMAGNETIC_ROTATION_VECTOR_ENABLED)) || - (m_enable_fusion == GYROSCOPE_UNCAL_ENABLED && sensor_base::is_supported(FUSION_GYROSCOPE_UNCAL_ENABLED))) { - sensor_event_t fusion_event; - - m_orientation_filter.m_magnetic_alignment_factor = m_magnetic_alignment_factor; - - m_orientation_filter.get_device_orientation(m_accel_ptr, m_gyro_ptr, m_magnetic_ptr); - - if (m_enable_fusion == GYROSCOPE_UNCAL_ENABLED && sensor_base::is_supported(FUSION_GYROSCOPE_UNCAL_ENABLED)) { - m_time = get_timestamp(); - fusion_event.sensor_id = get_id(); - fusion_event.data.timestamp = m_time; - fusion_event.data.accuracy = SENSOR_ACCURACY_GOOD; - fusion_event.event_type = FUSION_GYROSCOPE_UNCAL_EVENT; - fusion_event.data.value_count = 3; - fusion_event.data.values[0] = m_orientation_filter.m_gyro_bias.m_vec[0]; - fusion_event.data.values[1] = m_orientation_filter.m_gyro_bias.m_vec[1]; - fusion_event.data.values[2] = m_orientation_filter.m_gyro_bias.m_vec[2]; - - push(fusion_event); - } - - if ((m_enable_fusion == TILT_ENABLED && sensor_base::is_supported(FUSION_TILT_ENABLED)) || - (m_enable_fusion == ORIENTATION_ENABLED && sensor_base::is_supported(FUSION_ORIENTATION_ENABLED)) || - (m_enable_fusion == ROTATION_VECTOR_ENABLED && sensor_base::is_supported(FUSION_ROTATION_VECTOR_ENABLED)) || - (m_enable_fusion == GAMING_RV_ENABLED && sensor_base::is_supported(FUSION_GAMING_ROTATION_VECTOR_ENABLED)) || - (m_enable_fusion == GEOMAGNETIC_RV_ENABLED && sensor_base::is_supported(FUSION_GEOMAGNETIC_ROTATION_VECTOR_ENABLED))) { - m_time = get_timestamp(); - fusion_event.sensor_id = get_id(); - fusion_event.data.timestamp = m_time; - fusion_event.data.accuracy = SENSOR_ACCURACY_GOOD; - fusion_event.event_type = FUSION_EVENT; - fusion_event.data.value_count = 4; - fusion_event.data.values[0] = m_orientation_filter.m_quaternion.m_quat.m_vec[0]; - fusion_event.data.values[1] = m_orientation_filter.m_quaternion.m_quat.m_vec[1]; - fusion_event.data.values[2] = m_orientation_filter.m_quaternion.m_quat.m_vec[2]; - fusion_event.data.values[3] = m_orientation_filter.m_quaternion.m_quat.m_vec[3]; - - push(fusion_event); - } - - m_enable_fusion = 0; - m_accel_ptr = m_gyro_ptr = m_magnetic_ptr = NULL; - } - - return; -} - -int fusion_sensor::get_sensor_data(const unsigned int event_type, sensor_data_t &data) -{ - sensor_data accel; - sensor_data gyro; - sensor_data magnetic; - - sensor_data_t accel_data; - sensor_data_t gyro_data; - sensor_data_t magnetic_data; - - euler_angles euler_orientation; - - if (event_type != FUSION_ORIENTATION_ENABLED && - event_type != FUSION_ROTATION_VECTOR_ENABLED && - event_type != FUSION_GAMING_ROTATION_VECTOR_ENABLED && - event_type != FUSION_TILT_ENABLED && - event_type != FUSION_GEOMAGNETIC_ROTATION_VECTOR_ENABLED && - event_type != FUSION_GYROSCOPE_UNCAL_ENABLED) - return -1; - - m_accel_sensor->get_sensor_data(ACCELEROMETER_RAW_DATA_EVENT, accel_data); - pre_process_data(accel, accel_data.values, m_accel_static_bias, m_accel_rotation_direction_compensation, ACCEL_SCALE); - accel.m_time_stamp = accel_data.timestamp; - - if (event_type == FUSION_ORIENTATION_ENABLED || - event_type == FUSION_ROTATION_VECTOR_ENABLED || - event_type == FUSION_GAMING_ROTATION_VECTOR_ENABLED || - event_type == FUSION_GYROSCOPE_UNCAL_ENABLED) - { - m_gyro_sensor->get_sensor_data(GYROSCOPE_RAW_DATA_EVENT, gyro_data); - pre_process_data(gyro, gyro_data.values, m_gyro_static_bias, m_gyro_rotation_direction_compensation, GYRO_SCALE); - gyro.m_time_stamp = gyro_data.timestamp; - } - - if (event_type == FUSION_ORIENTATION_ENABLED || - event_type == FUSION_ROTATION_VECTOR_ENABLED || - event_type == FUSION_GEOMAGNETIC_ROTATION_VECTOR_ENABLED || - event_type == FUSION_GYROSCOPE_UNCAL_ENABLED) - { - m_magnetic_sensor->get_sensor_data(GEOMAGNETIC_RAW_DATA_EVENT, magnetic_data); - pre_process_data(magnetic, magnetic_data.values, m_geomagnetic_static_bias, m_geomagnetic_rotation_direction_compensation, GEOMAGNETIC_SCALE); - magnetic.m_time_stamp = magnetic_data.timestamp; - } - - m_orientation_filter_poll.m_magnetic_alignment_factor = m_magnetic_alignment_factor; - - if (event_type == FUSION_ORIENTATION_ENABLED || - event_type == FUSION_ROTATION_VECTOR_ENABLED || - event_type == FUSION_GYROSCOPE_UNCAL_ENABLED) - m_orientation_filter_poll.get_device_orientation(&accel, &gyro, &magnetic); - else if (event_type == FUSION_GAMING_ROTATION_VECTOR_ENABLED) - m_orientation_filter_poll.get_device_orientation(&accel, &gyro, NULL); - else if (event_type == FUSION_GEOMAGNETIC_ROTATION_VECTOR_ENABLED) - m_orientation_filter_poll.get_device_orientation(&accel, NULL, &magnetic); - else if (event_type == FUSION_TILT_ENABLED) - m_orientation_filter_poll.get_device_orientation(&accel, NULL, NULL); - - if (event_type == FUSION_GYROSCOPE_UNCAL_ENABLED) { - data.accuracy = SENSOR_ACCURACY_GOOD; - data.timestamp = get_timestamp(); - data.value_count = 3; - data.values[0] = m_orientation_filter_poll.m_gyro_bias.m_vec[0]; - data.values[1] = m_orientation_filter_poll.m_gyro_bias.m_vec[1]; - data.values[2] = m_orientation_filter_poll.m_gyro_bias.m_vec[2]; - } else if (event_type == FUSION_ORIENTATION_ENABLED || - event_type == FUSION_ROTATION_VECTOR_ENABLED || - event_type == FUSION_GAMING_ROTATION_VECTOR_ENABLED || - event_type == FUSION_TILT_ENABLED || - event_type == FUSION_GEOMAGNETIC_ROTATION_VECTOR_ENABLED) { - data.accuracy = SENSOR_ACCURACY_GOOD; - data.timestamp = get_timestamp(); - data.value_count = 4; - data.values[0] = m_orientation_filter_poll.m_quaternion.m_quat.m_vec[0]; - data.values[1] = m_orientation_filter_poll.m_quaternion.m_quat.m_vec[1]; - data.values[2] = m_orientation_filter_poll.m_quaternion.m_quat.m_vec[2]; - data.values[3] = m_orientation_filter_poll.m_quaternion.m_quat.m_vec[3]; - } - - return 0; -} - -bool fusion_sensor::get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) -{ - properties.min_range = 0; - properties.max_range = 0; - properties.resolution = 0; - properties.vendor = m_vendor; - properties.name = SENSOR_NAME; - properties.min_interval = 0; - properties.fifo_count = 0; - properties.max_batch_count = 0; - - return true; -} diff --git a/src/sensor/fusion/fusion_sensor.h b/src/sensor/fusion/fusion_sensor.h deleted file mode 100644 index 4985f15..0000000 --- a/src/sensor/fusion/fusion_sensor.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 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_SENSOR_H_ -#define _FUSION_SENSOR_H_ - -#include -#include -#include - -class fusion_sensor : public virtual_sensor { -public: - fusion_sensor(); - virtual ~fusion_sensor(); - - bool init(void); - - void synthesize(const sensor_event_t &event, vector &outs); - - bool add_interval(int client_id, unsigned int interval); - bool delete_interval(int client_id); - virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties); - virtual void get_types(std::vector &types); - - int get_sensor_data(const unsigned int data_id, sensor_data_t &data); - -private: - sensor_base *m_accel_sensor; - sensor_base *m_gyro_sensor; - sensor_base *m_magnetic_sensor; - - sensor_data m_accel; - sensor_data m_gyro; - sensor_data m_magnetic; - - sensor_data *m_accel_ptr; - sensor_data *m_gyro_ptr; - sensor_data *m_magnetic_ptr; - - cmutex m_value_mutex; - - orientation_filter m_orientation_filter; - orientation_filter m_orientation_filter_poll; - - unsigned int m_enable_fusion; - - unsigned long long m_time; - unsigned int m_interval; - - std::string m_vendor; - std::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]; - int m_magnetic_alignment_factor; - - bool on_start(void); - bool on_stop(void); -}; - -#endif diff --git a/src/sensor/fusion/hardware_fusion_sensor.html b/src/sensor/sensor_fusion/design/documentation/hardware_fusion_sensor.html similarity index 100% rename from src/sensor/fusion/hardware_fusion_sensor.html rename to src/sensor/sensor_fusion/design/documentation/hardware_fusion_sensor.html diff --git a/src/sensor/sensor_fusion/fusion.h b/src/sensor/sensor_fusion/fusion.h new file mode 100644 index 0000000..d53f800 --- /dev/null +++ b/src/sensor/sensor_fusion/fusion.h @@ -0,0 +1,37 @@ +/* + * sensord + * + * Copyright (c) 2016 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_H__ +#define __FUSION_H__ + +#include + +class fusion { +public: + fusion() {}; + virtual ~fusion() {} ; + + virtual void push_accel(sensor_data_t &data) = 0; + virtual void push_gyro(sensor_data_t &data) = 0; + virtual void push_mag(sensor_data_t &data) = 0; + virtual bool get_rv(unsigned long long timestamp, float &w, float &x, float &y, float &z) = 0; +}; + + + +#endif /* __FUSION_H__ */ diff --git a/src/sensor/sensor_fusion/fusion_base.cpp b/src/sensor/sensor_fusion/fusion_base.cpp new file mode 100644 index 0000000..92e02f6 --- /dev/null +++ b/src/sensor/sensor_fusion/fusion_base.cpp @@ -0,0 +1,105 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "fusion_base.h" +#include "orientation_filter.h" + +#define ACCEL_COMPENSATION -1 +#define GYRO_COMPENSATION 1 +#define MAG_COMPENSATION -1 + +fusion_base::fusion_base() +: m_enable_accel(false) +, m_enable_gyro(false) +, m_enable_magnetic(false) +{ + _I("fusion_base is created!"); +} + +fusion_base::~fusion_base() +{ + _I("fusion_sensor is destroyed!"); +} + +void fusion_base::clear(void) +{ + m_enable_accel = false; + m_enable_gyro = false; + m_enable_magnetic = false; +} + +void fusion_base::push_accel(sensor_data_t &data) +{ + //_I("[fusion_sensor] : Pushing accel"); + pre_process_data(m_accel, data.values, ACCEL_COMPENSATION, ACCEL_SCALE); + m_accel.m_time_stamp = data.timestamp; + m_enable_accel = true; + if (get_orientation()) + store_orientation(); +} + +void fusion_base::push_gyro(sensor_data_t &data) +{ + //_I("[fusion_sensor] : Pushing mag"); + pre_process_data(m_gyro, data.values, GYRO_COMPENSATION, GYRO_SCALE); + m_gyro.m_time_stamp = data.timestamp; + m_enable_gyro = true; + if (get_orientation()) + store_orientation(); +} + +void fusion_base::push_mag(sensor_data_t &data) +{ + //_I("[fusion_sensor] : Pushing gyro"); + pre_process_data(m_magnetic, data.values, MAG_COMPENSATION, GEOMAGNETIC_SCALE); + m_magnetic.m_time_stamp = data.timestamp; + m_enable_magnetic = true; + if (get_orientation()) + store_orientation(); + +} + +bool fusion_base::get_rv(unsigned long long timestamp, float &x, float &y, float &z, float &w) +{ + if (m_timestamp == 0) + return false; + timestamp = m_timestamp; + x = m_x; + y = m_y; + z = m_z; + w = m_w; + return true; +} + +void fusion_base::store_orientation(void) +{ + m_x = m_orientation_filter.m_quaternion.m_quat.m_vec[0]; + m_y = m_orientation_filter.m_quaternion.m_quat.m_vec[1]; + m_z = m_orientation_filter.m_quaternion.m_quat.m_vec[2]; + m_w = m_orientation_filter.m_quaternion.m_quat.m_vec[3]; + clear(); +} \ No newline at end of file diff --git a/src/sensor/sensor_fusion/fusion_base.h b/src/sensor/sensor_fusion/fusion_base.h new file mode 100644 index 0000000..2428712 --- /dev/null +++ b/src/sensor/sensor_fusion/fusion_base.h @@ -0,0 +1,60 @@ +/* + * sensord + * + * Copyright (c) 2016 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_BASE_H__ +#define __FUSION_BASE_H__ + +#include +#include + +class fusion_base : public virtual fusion { +public: + fusion_base(); + virtual ~fusion_base(); + + virtual void push_accel(sensor_data_t &data); + virtual void push_gyro(sensor_data_t &data); + virtual void push_mag(sensor_data_t &data); + virtual bool get_rv(unsigned long long timestamp, float &w, float &x, float &y, float &z); + +protected: + + sensor_data m_accel; + sensor_data m_gyro; + sensor_data m_magnetic; + + orientation_filter m_orientation_filter; + + bool m_enable_accel; + bool m_enable_gyro; + bool m_enable_magnetic; + + float m_x; + float m_y; + float m_z; + float m_w; + float m_timestamp; + + void clear(); + void store_orientation(void); + virtual bool get_orientation(void) = 0; +}; + + + +#endif /* __FUSION_BASE_H__ */ diff --git a/src/sensor/sensor_fusion/gyro_fusion.cpp b/src/sensor/sensor_fusion/gyro_fusion.cpp new file mode 100644 index 0000000..a668e65 --- /dev/null +++ b/src/sensor/sensor_fusion/gyro_fusion.cpp @@ -0,0 +1,39 @@ +/* + * sensord + * + * Copyright (c) 2016 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 "gyro_fusion.h" + +gyro_fusion::gyro_fusion() +{ +} + +gyro_fusion::~gyro_fusion() +{ +} + +bool gyro_fusion::get_orientation(void) +{ + //_I("[fusion_sensor] : enable values are %d %d %d", m_enable_accel, m_enable_gyro, m_enable_magnetic); + if (!m_enable_accel || !m_enable_gyro) + return false; + + m_orientation_filter.get_device_orientation(&m_accel, &m_gyro, NULL); + m_timestamp = fmax(m_accel.m_time_stamp, m_gyro.m_time_stamp); + return true; +} diff --git a/src/sensor/sensor_fusion/gyro_fusion.h b/src/sensor/sensor_fusion/gyro_fusion.h new file mode 100644 index 0000000..0089e0d --- /dev/null +++ b/src/sensor/sensor_fusion/gyro_fusion.h @@ -0,0 +1,33 @@ +/* + * sensord + * + * Copyright (c) 2016 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 __GYRO_FUSION_H__ +#define __GYRO_FUSION_H__ + +#include + +class gyro_fusion : public fusion_base { +public: + gyro_fusion(); + ~gyro_fusion(); +private: + bool get_orientation(); +}; + +#endif /* __GYRO_FUSION_H__ */ diff --git a/src/sensor/sensor_fusion/gyro_magnetic_fusion.cpp b/src/sensor/sensor_fusion/gyro_magnetic_fusion.cpp new file mode 100644 index 0000000..0d1f32d --- /dev/null +++ b/src/sensor/sensor_fusion/gyro_magnetic_fusion.cpp @@ -0,0 +1,40 @@ +/* + * sensord + * + * Copyright (c) 2016 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 "gyro_magnetic_fusion.h" + +gyro_magnetic_fusion::gyro_magnetic_fusion() +{ +} + +gyro_magnetic_fusion::~gyro_magnetic_fusion() +{ +} + +bool gyro_magnetic_fusion::get_orientation(void) +{ + //_I("[fusion_sensor] : enable values are %d %d %d", m_enable_accel, m_enable_gyro, m_enable_magnetic); + if (!m_enable_accel || !m_enable_gyro || !m_enable_magnetic) + return false; + + m_orientation_filter.get_device_orientation(&m_accel, &m_gyro, &m_magnetic); + m_timestamp = fmax(m_accel.m_time_stamp, m_gyro.m_time_stamp); + m_timestamp = fmax(m_timestamp, m_magnetic.m_time_stamp); + return true; +} diff --git a/src/sensor/sensor_fusion/gyro_magnetic_fusion.h b/src/sensor/sensor_fusion/gyro_magnetic_fusion.h new file mode 100644 index 0000000..54bf75c --- /dev/null +++ b/src/sensor/sensor_fusion/gyro_magnetic_fusion.h @@ -0,0 +1,33 @@ +/* + * sensord + * + * Copyright (c) 2016 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 __GYRO_MAGNETIC_FUSION_H__ +#define __GYRO_MAGNETIC_FUSION_H__ + +#include + +class gyro_magnetic_fusion : public fusion_base { +public: + gyro_magnetic_fusion(); + ~gyro_magnetic_fusion(); +private: + bool get_orientation(); +}; + +#endif /* __GYRO_MAGNETIC_FUSION_H__ */ diff --git a/src/sensor/sensor_fusion/magnetic_fusion.cpp b/src/sensor/sensor_fusion/magnetic_fusion.cpp new file mode 100644 index 0000000..89050e5 --- /dev/null +++ b/src/sensor/sensor_fusion/magnetic_fusion.cpp @@ -0,0 +1,39 @@ +/* + * sensord + * + * Copyright (c) 2016 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 "magnetic_fusion.h" + +magnetic_fusion::magnetic_fusion() +{ +} + +magnetic_fusion::~magnetic_fusion() +{ +} + +bool magnetic_fusion::get_orientation(void) +{ + //_I("[fusion_sensor] : enable values are %d %d %d", m_enable_accel, m_enable_magnetic, m_enable_magnetic); + if (!m_enable_accel || !m_enable_magnetic) + return false; + + m_orientation_filter.get_device_orientation(&m_accel, &m_magnetic, NULL); + m_timestamp = fmax(m_accel.m_time_stamp, m_magnetic.m_time_stamp); + return true; +} diff --git a/src/sensor/sensor_fusion/magnetic_fusion.h b/src/sensor/sensor_fusion/magnetic_fusion.h new file mode 100644 index 0000000..41758ea --- /dev/null +++ b/src/sensor/sensor_fusion/magnetic_fusion.h @@ -0,0 +1,33 @@ +/* + * sensord + * + * Copyright (c) 2016 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 __MAGNETIC_FUSION_H__ +#define __MAGNETIC_FUSION_H__ + +#include + +class magnetic_fusion: public fusion_base { +public: + magnetic_fusion(); + ~magnetic_fusion(); +private: + bool get_orientation(); +}; + +#endif /* __MAGNETIC_FUSION_H__ */ diff --git a/src/sensor/sensor_fusion/orientation_filter.cpp b/src/sensor/sensor_fusion/orientation_filter.cpp index 7e1cd8d..be41328 100644 --- a/src/sensor/sensor_fusion/orientation_filter.cpp +++ b/src/sensor/sensor_fusion/orientation_filter.cpp @@ -64,8 +64,6 @@ orientation_filter::orientation_filter() m_var_pitch = vec; m_var_azimuth = vec; - m_magnetic_alignment_factor = 1; - m_gyro.m_time_stamp = 0; } @@ -106,7 +104,7 @@ template inline void orientation_filter::orientation_triad_algorithm() { TYPE arr_acc_e[V1x3S] = {0.0, 0.0, 1.0}; - TYPE arr_mag_e[V1x3S] = {0.0, (TYPE) m_magnetic_alignment_factor, 0.0}; + TYPE arr_mag_e[V1x3S] = {0.0, 1.0, 0.0}; vect acc_e(arr_acc_e); vect mag_e(arr_mag_e); diff --git a/src/sensor/sensor_fusion/orientation_filter.h b/src/sensor/sensor_fusion/orientation_filter.h index d55b7c1..eaea224 100644 --- a/src/sensor/sensor_fusion/orientation_filter.h +++ b/src/sensor/sensor_fusion/orientation_filter.h @@ -73,8 +73,6 @@ public: euler_angles m_euler_error; TYPE m_gyro_dt; - int m_magnetic_alignment_factor; - orientation_filter(void); ~orientation_filter(void); diff --git a/src/sensor/sensor_fusion/sensor_data.cpp b/src/sensor/sensor_fusion/sensor_data.cpp index 9f730cc..abd1181 100644 --- a/src/sensor/sensor_fusion/sensor_data.cpp +++ b/src/sensor/sensor_fusion/sensor_data.cpp @@ -117,12 +117,11 @@ quaternion sensor_data2quat(const sensor_data data, const vect -void pre_process_data(sensor_data &data_out, const T *data_in, T *bias, int *sign, int scale) +void pre_process_data(sensor_data &data_out, const T *data_in, int sign, int scale) { - data_out.m_data.m_vec[0] = sign[0] * (data_in[0] - bias[0]) / scale; - data_out.m_data.m_vec[1] = sign[1] * (data_in[1] - bias[1]) / scale; - data_out.m_data.m_vec[2] = sign[2] * (data_in[2] - bias[2]) / scale; + data_out.m_data.m_vec[0] = sign * data_in[0] / scale; + data_out.m_data.m_vec[1] = sign * data_in[1] / scale; + data_out.m_data.m_vec[2] = sign * data_in[2] / scale; } #endif /* _SENSOR_DATA_H_ */ - diff --git a/src/sensor/sensor_fusion/sensor_data.h b/src/sensor/sensor_fusion/sensor_data.h index 6841369..f266760 100644 --- a/src/sensor/sensor_fusion/sensor_data.h +++ b/src/sensor/sensor_fusion/sensor_data.h @@ -50,7 +50,7 @@ public: template friend quaternion sensor_data2quat(const sensor_data data, const vect ref_vec); template friend void pre_process_data(sensor_data &data_out, - const T *data_in, T *bias, int *sign, int scale); + const T *data_in, int sign, int scale); }; #include "sensor_data.cpp" diff --git a/src/sensor/sensor_fusion/test/orientation_sensor.cpp b/src/sensor/sensor_fusion/test/orientation_sensor.cpp index a67627e..25099e2 100644 --- a/src/sensor/sensor_fusion/test/orientation_sensor.cpp +++ b/src/sensor/sensor_fusion/test/orientation_sensor.cpp @@ -45,8 +45,6 @@ void orientation_sensor::get_device_orientation(sensor_data *accel_data, if (magnetic_data != NULL) { pre_process_data(magnetic_data, magnetic_data, bias_magnetic, sign_magnetic, scale_magnetic); normalize(*magnetic_data); - - orien_filter.m_magnetic_alignment_factor = magnetic_alignment_factor; } orien_filter.get_device_orientation(accel_data, gyro_data, magnetic_data); -- 2.7.4 From 377bab9f669bbbd6646b753de155901870652485 Mon Sep 17 00:00:00 2001 From: akhilkedia94 Date: Tue, 16 Aug 2016 17:37:51 +0900 Subject: [PATCH 16/16] [Bugfix] Timestamp was not being passed by refferencce to sensor_fusion Change-Id: Ifb0ff04689880ede5fe565f85931a49f8bc16e6d Signed-off-by: akhilkedia94 --- src/sensor/sensor_fusion/fusion.h | 2 +- src/sensor/sensor_fusion/fusion_base.cpp | 4 ++-- src/sensor/sensor_fusion/fusion_base.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sensor/sensor_fusion/fusion.h b/src/sensor/sensor_fusion/fusion.h index d53f800..6c14439 100644 --- a/src/sensor/sensor_fusion/fusion.h +++ b/src/sensor/sensor_fusion/fusion.h @@ -29,7 +29,7 @@ public: virtual void push_accel(sensor_data_t &data) = 0; virtual void push_gyro(sensor_data_t &data) = 0; virtual void push_mag(sensor_data_t &data) = 0; - virtual bool get_rv(unsigned long long timestamp, float &w, float &x, float &y, float &z) = 0; + virtual bool get_rv(unsigned long long ×tamp, float &w, float &x, float &y, float &z) = 0; }; diff --git a/src/sensor/sensor_fusion/fusion_base.cpp b/src/sensor/sensor_fusion/fusion_base.cpp index 92e02f6..355a551 100644 --- a/src/sensor/sensor_fusion/fusion_base.cpp +++ b/src/sensor/sensor_fusion/fusion_base.cpp @@ -83,7 +83,7 @@ void fusion_base::push_mag(sensor_data_t &data) } -bool fusion_base::get_rv(unsigned long long timestamp, float &x, float &y, float &z, float &w) +bool fusion_base::get_rv(unsigned long long ×tamp, float &x, float &y, float &z, float &w) { if (m_timestamp == 0) return false; @@ -102,4 +102,4 @@ void fusion_base::store_orientation(void) m_z = m_orientation_filter.m_quaternion.m_quat.m_vec[2]; m_w = m_orientation_filter.m_quaternion.m_quat.m_vec[3]; clear(); -} \ No newline at end of file +} diff --git a/src/sensor/sensor_fusion/fusion_base.h b/src/sensor/sensor_fusion/fusion_base.h index 2428712..1479023 100644 --- a/src/sensor/sensor_fusion/fusion_base.h +++ b/src/sensor/sensor_fusion/fusion_base.h @@ -30,7 +30,7 @@ public: virtual void push_accel(sensor_data_t &data); virtual void push_gyro(sensor_data_t &data); virtual void push_mag(sensor_data_t &data); - virtual bool get_rv(unsigned long long timestamp, float &w, float &x, float &y, float &z); + virtual bool get_rv(unsigned long long ×tamp, float &w, float &x, float &y, float &z); protected: -- 2.7.4