From fc87b7c292bb3ab6d9f735c2b52b059a40d17fa9 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 12 Apr 2017 11:00:27 +0900 Subject: [PATCH 01/16] sensord: check privilege everytime for every request - check privilege for get_sensor/get_sensor_list - check privilege for all controls Change-Id: I7148c7d506bb1eaa01046e60b1b81a0ce5ec899a Signed-off-by: kibak.yoon --- src/client/sensor_manager.cpp | 64 +++++++++++++++++++++++++++++------ src/client/sensor_manager.h | 1 + src/server/sensor_listener_proxy.cpp | 6 ++++ src/server/sensor_listener_proxy.h | 1 + src/server/server_channel_handler.cpp | 61 +++++++++++++++++++++++++++++++++ src/server/server_channel_handler.h | 5 +++ src/shared/command_types.h | 6 ++++ 7 files changed, 134 insertions(+), 10 deletions(-) diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index 5602312..c50cdae 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -27,6 +27,8 @@ #include #include +#define SIZE_STR_SENSOR_ALL 27 + using namespace sensor; class manager_handler : public ipc::channel_handler @@ -81,20 +83,22 @@ int sensor_manager::get_sensors(sensor_type_t type, sensor_t **list, int *count) int sensor_manager::get_sensor(const char *uri, sensor_t *sensor) { - sensor_info *info; - - info = get_info(uri); - if (!info) { + if (!is_supported(uri)) { *sensor = NULL; return -ENODATA; } + sensor_info *info = get_info(uri); + retv_if(!info, -EACCES); + *sensor = (sensor_t)info; return OP_SUCCESS; } int sensor_manager::get_sensors(const char *uri, sensor_t **list, int *count) { + retv_if(!is_supported(uri), -ENODATA); + std::vector infos; int size; @@ -130,8 +134,13 @@ bool sensor_manager::is_supported(sensor_t sensor) bool sensor_manager::is_supported(const char *uri) { + if (strncmp(uri, utils::get_uri(ALL_SENSOR), SIZE_STR_SENSOR_ALL) == 0) + return true; + for (auto it = m_infos.begin(); it != m_infos.end(); ++it) { - if ((*it).get_uri() == uri) + std::size_t found = (*it).get_uri().rfind(uri); + + if (found != std::string::npos) return true; } @@ -260,9 +269,34 @@ bool sensor_manager::get_sensors_internal(void) return true; } +bool sensor_manager::has_privilege(std::string &uri) +{ + retvm_if(!is_connected(), false, "Failed to get sensors"); + + bool ret; + ipc::message msg; + ipc::message reply; + cmd_has_privilege_t buf = {0, }; + + msg.set_type(CMD_HAS_PRIVILEGE); + memcpy(buf.sensor, uri.c_str(), uri.size()); + msg.enclose((const char *)&buf, sizeof(buf)); + + ret = m_channel->send_sync(&msg); + retvm_if(!ret, false, "Failed to send message"); + + ret = m_channel->read_sync(reply); + retvm_if(!ret, false, "Failed to receive message"); + + if (reply.header()->err == OP_SUCCESS) + return true; + + return false; +} + sensor_info *sensor_manager::get_info(const char *uri) { - if (strncmp(uri, utils::get_uri(ALL_SENSOR), 27) == 0) + if (strncmp(uri, utils::get_uri(ALL_SENSOR), SIZE_STR_SENSOR_ALL) == 0) return &m_infos[0]; for (auto it = m_infos.begin(); it != m_infos.end(); ++it) { @@ -271,7 +305,11 @@ sensor_info *sensor_manager::get_info(const char *uri) if (found == std::string::npos) continue; - return &*it; + if ((*it).get_privilege().empty()) + return &*it; + + if (has_privilege((*it).get_uri())) + return &*it; } return NULL; @@ -282,16 +320,22 @@ std::vector sensor_manager::get_infos(const char *uri) std::vector infos; bool all = false; - if (strncmp(uri, utils::get_uri(ALL_SENSOR), 27) == 0) + if (strncmp(uri, utils::get_uri(ALL_SENSOR), SIZE_STR_SENSOR_ALL) == 0) all = true; - for (auto it = m_infos.begin(); it != m_infos.end(); ++it) { +for (auto it = m_infos.begin(); it != m_infos.end(); ++it) { std::size_t found = (*it).get_uri().rfind(uri); if (!all && found == std::string::npos) continue; - infos.push_back(&*it); + if ((*it).get_privilege().empty()) { + infos.push_back(&*it); + continue; + } + + if (has_privilege((*it).get_uri())) + infos.push_back(&*it); } return infos; diff --git a/src/client/sensor_manager.h b/src/client/sensor_manager.h index 35ae863..5cb7d40 100644 --- a/src/client/sensor_manager.h +++ b/src/client/sensor_manager.h @@ -65,6 +65,7 @@ private: void decode_sensors(const char *buf, std::vector &infos); bool get_sensors_internal(void); + bool has_privilege(std::string &uri); sensor_info *get_info(const char *uri); std::vector get_infos(const char *uri); diff --git a/src/server/sensor_listener_proxy.cpp b/src/server/sensor_listener_proxy.cpp index 29608b0..b542af8 100644 --- a/src/server/sensor_listener_proxy.cpp +++ b/src/server/sensor_listener_proxy.cpp @@ -127,3 +127,9 @@ int sensor_listener_proxy::get_data(sensor_data_t **data, int *len) /* TODO : caching the last data & retry logic if there is no data */ return m_sensor->get_data(data, len); } + +std::string sensor_listener_proxy::get_required_privileges(void) +{ + sensor_info info = m_sensor->get_sensor_info(); + return info.get_privilege(); +} diff --git a/src/server/sensor_listener_proxy.h b/src/server/sensor_listener_proxy.h index 709f057..583cf36 100644 --- a/src/server/sensor_listener_proxy.h +++ b/src/server/sensor_listener_proxy.h @@ -48,6 +48,7 @@ public: int set_attribute(int attribute, const char *value, int len); int flush(void); int get_data(sensor_data_t **data, int *len); + std::string get_required_privileges(void); private: uint32_t m_id; diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index a34f58f..1c18d1d 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -22,8 +22,13 @@ #include #include #include +#include #include +#include "permission_checker.h" + +#define PRIV_DELIMINATOR ";" + using namespace sensor; using namespace ipc; @@ -78,6 +83,8 @@ void server_channel_handler::read(channel *ch, message &msg) err = provider_disconnect(ch, msg); break; case CMD_PROVIDER_POST: err = provider_post(ch, msg); break; + case CMD_HAS_PRIVILEGE: + err = has_privileges(ch, msg); break; default: break; } @@ -118,6 +125,8 @@ int server_channel_handler::listener_connect(channel *ch, message &msg) sensor_listener_proxy *listener = new(std::nothrow) sensor_listener_proxy(listener_id, sensor, ch); retvm_if(!listener, OP_ERROR, "Failed to allocate memory"); + retvm_if(!has_privileges(ch->get_fd(), listener->get_required_privileges()), + -EACCES, "Permission denied"); buf.listener_id = listener_id; @@ -142,6 +151,9 @@ int server_channel_handler::listener_disconnect(channel *ch, message &msg) uint32_t id = m_listeners[ch]->get_id(); + retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + -EACCES, "Permission denied"); + delete m_listeners[ch]; m_listeners.erase(ch); @@ -154,6 +166,8 @@ int server_channel_handler::listener_start(channel *ch, message &msg) { auto it = m_listeners.find(ch); retv_if(it == m_listeners.end(), -EINVAL); + retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + -EACCES, "Permission denied"); int ret = m_listeners[ch]->start(); retv_if(ret < 0, ret); @@ -165,6 +179,8 @@ int server_channel_handler::listener_stop(channel *ch, message &msg) { auto it = m_listeners.find(ch); retv_if(it == m_listeners.end(), -EINVAL); + retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + -EACCES, "Permission denied"); int ret = m_listeners[ch]->stop(); retv_if(ret < 0, ret); @@ -178,6 +194,8 @@ int server_channel_handler::listener_attr_int(channel *ch, message &msg) auto it = m_listeners.find(ch); retv_if(it == m_listeners.end(), -EINVAL); + retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + -EACCES, "Permission denied"); cmd_listener_attr_int_t buf; msg.disclose((char *)&buf); @@ -203,6 +221,8 @@ int server_channel_handler::listener_attr_str(channel *ch, message &msg) { auto it = m_listeners.find(ch); retv_if(it == m_listeners.end(), -EINVAL); + retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + -EACCES, "Permission denied"); cmd_listener_attr_str_t buf; msg.disclose((char *)&buf); @@ -215,6 +235,11 @@ int server_channel_handler::listener_attr_str(channel *ch, message &msg) int server_channel_handler::listener_get_data(channel *ch, message &msg) { + auto it = m_listeners.find(ch); + retv_if(it == m_listeners.end(), -EINVAL); + retvm_if(!has_privileges(ch->get_fd(), m_listeners[ch]->get_required_privileges()), + -EACCES, "Permission denied"); + return send_reply(ch, OP_ERROR); } @@ -233,9 +258,45 @@ int server_channel_handler::provider_post(channel *ch, message &msg) return send_reply(ch, OP_ERROR); } +int server_channel_handler::has_privileges(channel *ch, message &msg) +{ + sensor_handler *sensor; + cmd_has_privilege_t buf; + msg.disclose((char *)&buf); + + sensor = m_manager->get_sensor(buf.sensor); + retv_if(!sensor, OP_ERROR); + + sensor_info info = sensor->get_sensor_info(); + + if (!has_privileges(ch->get_fd(), info.get_privilege())) + return OP_ERROR; + + return send_reply(ch, OP_SUCCESS); +} + int server_channel_handler::send_reply(channel *ch, int error) { message reply(error); retvm_if(!ch->send_sync(&reply), OP_ERROR, "Failed to send reply"); return OP_SUCCESS; } + +bool server_channel_handler::has_privilege(int fd, std::string &priv) +{ + static permission_checker checker; + return checker.has_permission(fd, priv); +} + +bool server_channel_handler::has_privileges(int fd, std::string priv) +{ + std::vector privileges; + privileges = utils::tokenize(priv, PRIV_DELIMINATOR); + + for (auto it = privileges.begin(); it != privileges.end(); ++it) { + if (!has_privilege(fd, *it)) + return false; + } + + return true; +} diff --git a/src/server/server_channel_handler.h b/src/server/server_channel_handler.h index d48ff7e..1ccc998 100644 --- a/src/server/server_channel_handler.h +++ b/src/server/server_channel_handler.h @@ -58,6 +58,11 @@ private: int provider_disconnect(ipc::channel *ch, ipc::message &msg); int provider_post(ipc::channel *ch, ipc::message &msg); + int has_privileges(ipc::channel *ch, ipc::message &msg); + + bool has_privilege(int fd, std::string &priv); + bool has_privileges(int fd, std::string priv); + int send_reply(ipc::channel *ch, int error); sensor_manager *m_manager; diff --git a/src/shared/command_types.h b/src/shared/command_types.h index 81d4a21..6b5e0c6 100644 --- a/src/shared/command_types.h +++ b/src/shared/command_types.h @@ -51,6 +51,8 @@ enum cmd_type_e { CMD_PROVIDER_DISCONNECT, CMD_PROVIDER_POST, + CMD_HAS_PRIVILEGE, + CMD_CNT, }; @@ -113,4 +115,8 @@ typedef struct { sensorhub_data_t base_data; } cmd_provider_post_t; +typedef struct { + char sensor[NAME_MAX]; +} cmd_has_privilege_t ; + #endif /* __COMMAND_TYPES_H__ */ -- 2.7.4 From 90758547f668fe9d8932f0099aee552e47d9a2a9 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 12 Apr 2017 11:24:49 +0900 Subject: [PATCH 02/16] sensord: fix to return approprivate error Change-Id: I4d1ca524b4041232ed7c8e350f3261b264112ceb Signed-off-by: kibak.yoon --- src/client/sensor_internal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/sensor_internal.cpp b/src/client/sensor_internal.cpp index 364eb92..a0b683f 100644 --- a/src/client/sensor_internal.cpp +++ b/src/client/sensor_internal.cpp @@ -117,7 +117,7 @@ API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor) { int ret = OP_ERROR; - retvm_if(!sensor, -EPERM, "Invalid parameter[%#x]", sensor); + retvm_if(!sensor, -EINVAL, "Invalid parameter[%#x]", sensor); retvm_if(!manager.connect(), -EIO, "Failed to connect"); ret = manager.get_sensor(type, sensor); @@ -548,7 +548,7 @@ API int sensord_external_connect(const char *key, sensor_external_command_cb_t c * 3. first connection(client) * 4. cmd_connect for external sensor with key */ - retvm_if(!key, -EPERM, "Invalid key"); + retvm_if(!key, -EINVAL, "Invalid key"); return 0; } -- 2.7.4 From 135fdeb7dbdccf1d255ba692772bbf87c28ca1f7 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 12 Apr 2017 03:06:21 +0900 Subject: [PATCH 03/16] sensord: support original path to load HAL library Change-Id: Id32a8e5d2f008766542ee9a46e5757a284667630 Signed-off-by: kibak.yoon --- src/server/sensor_loader.cpp | 14 +++++++++++++- src/server/sensor_manager.cpp | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index d46a5cf..4d1d20e 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -19,6 +19,9 @@ #include "sensor_loader.h" +#include +#include +#include #include #include #include @@ -112,6 +115,7 @@ bool sensor_loader::get_module_paths(const std::string &dir_path, std::vector Date: Wed, 12 Apr 2017 12:28:15 +0900 Subject: [PATCH 04/16] sensord: rename information list/map properly Change-Id: I1e56466e0ef00c428196cb5df1340839236c9ab5 Signed-off-by: kibak.yoon --- src/client/sensor_manager.cpp | 12 ++++++------ src/client/sensor_manager.h | 4 ++-- src/shared/event_loop.cpp | 14 +++++++------- src/shared/event_loop.h | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index c50cdae..4be1065 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -124,7 +124,7 @@ bool sensor_manager::is_supported(sensor_t sensor) { retvm_if(!sensor, false, "Invalid parameter[%#x]", sensor); - for (auto it = m_infos.begin(); it != m_infos.end(); ++it) { + for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) { if (&*it == sensor) return true; } @@ -137,7 +137,7 @@ bool sensor_manager::is_supported(const char *uri) if (strncmp(uri, utils::get_uri(ALL_SENSOR), SIZE_STR_SENSOR_ALL) == 0) return true; - for (auto it = m_infos.begin(); it != m_infos.end(); ++it) { + for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) { std::size_t found = (*it).get_uri().rfind(uri); if (found != std::string::npos) @@ -264,7 +264,7 @@ bool sensor_manager::get_sensors_internal(void) reply.disclose(buf); - decode_sensors(buf, m_infos); + decode_sensors(buf, m_sensors); return true; } @@ -297,9 +297,9 @@ bool sensor_manager::has_privilege(std::string &uri) sensor_info *sensor_manager::get_info(const char *uri) { if (strncmp(uri, utils::get_uri(ALL_SENSOR), SIZE_STR_SENSOR_ALL) == 0) - return &m_infos[0]; + return &m_sensors[0]; - for (auto it = m_infos.begin(); it != m_infos.end(); ++it) { + for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) { std::size_t found = (*it).get_uri().rfind(uri); if (found == std::string::npos) @@ -323,7 +323,7 @@ std::vector sensor_manager::get_infos(const char *uri) if (strncmp(uri, utils::get_uri(ALL_SENSOR), SIZE_STR_SENSOR_ALL) == 0) all = true; -for (auto it = m_infos.begin(); it != m_infos.end(); ++it) { + for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) { std::size_t found = (*it).get_uri().rfind(uri); if (!all && found == std::string::npos) diff --git a/src/client/sensor_manager.h b/src/client/sensor_manager.h index 5cb7d40..8839943 100644 --- a/src/client/sensor_manager.h +++ b/src/client/sensor_manager.h @@ -54,7 +54,7 @@ public: /* int unregister_sensor(const char *uri) */ private: - typedef std::vector sensor_infos_t; + typedef std::vector sensor_list_t; bool init(void); void deinit(void); @@ -75,7 +75,7 @@ private: ipc::event_loop m_loop; std::atomic m_connected; - sensor_infos_t m_infos; + sensor_list_t m_sensors; }; } diff --git a/src/shared/event_loop.cpp b/src/shared/event_loop.cpp index 73854b5..1b569a1 100644 --- a/src/shared/event_loop.cpp +++ b/src/shared/event_loop.cpp @@ -127,7 +127,7 @@ uint64_t event_loop::add_event(const int fd, const event_condition cond, event_h g_source_set_callback(src, (GSourceFunc) g_io_handler, info, NULL); g_source_attach(src, g_main_loop_get_context(m_mainloop)); - m_infos[id] = info; + m_handlers[id] = info; /* _D("Added[%llu](fd:%d)", id, fd); */ return id; @@ -151,14 +151,14 @@ uint64_t event_loop::add_idle_event(unsigned int priority, idle_handler *handler bool event_loop::remove_event(uint64_t id, bool close_channel) { - auto it = m_infos.find(id); - retv_if(it == m_infos.end(), false); + auto it = m_handlers.find(id); + retv_if(it == m_handlers.end(), false); if (close_channel) g_io_channel_shutdown(it->second->g_ch, TRUE, NULL); release_info(it->second); - m_infos.erase(it); + m_handlers.erase(it); /* _D("Removed[%llu]", id); */ return true; @@ -166,10 +166,10 @@ bool event_loop::remove_event(uint64_t id, bool close_channel) void event_loop::remove_all_events(void) { - auto it = m_infos.begin(); - while (it != m_infos.end()) { + auto it = m_handlers.begin(); + while (it != m_handlers.end()) { release_info(it->second); - it = m_infos.erase(it); + it = m_handlers.erase(it); } } diff --git a/src/shared/event_loop.h b/src/shared/event_loop.h index 934a8b4..870e6a3 100644 --- a/src/shared/event_loop.h +++ b/src/shared/event_loop.h @@ -92,7 +92,7 @@ private: std::atomic m_running; std::atomic m_terminating; std::atomic m_sequence; - std::map m_infos; + std::map m_handlers; int m_term_fd; }; -- 2.7.4 From d6fec29ca61fe6634f9c3dc19cd4b2ea84e021fc Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 12 Apr 2017 12:39:16 +0900 Subject: [PATCH 05/16] sensord: fix warnings detected from static analysis - fix member variable initialziation ordered warnings - add missing breaks in switch-case statement - check the range of index Change-Id: Iaf75452578b69b9a7952321d25db75e53be7ca81 Signed-off-by: kibak.yoon --- src/client/sensor_listener.cpp | 2 ++ src/sensorctl/sensor_adapter.cpp | 2 ++ src/sensorctl/test_bench.cpp | 1 + src/server/external_sensor_handler.cpp | 2 +- src/server/fusion_sensor_handler.cpp | 5 ++--- src/server/fusion_sensor_handler.h | 1 - src/shared/ipc_server.cpp | 3 +++ src/shared/socket.cpp | 5 ++--- 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp index da9dbe8..a5c4af2 100644 --- a/src/client/sensor_listener.cpp +++ b/src/client/sensor_listener.cpp @@ -47,9 +47,11 @@ public: case CMD_LISTENER_EVENT: if (m_listener->get_event_handler()) m_listener->get_event_handler()->read(ch, msg); + break; case CMD_LISTENER_ACC_EVENT: if (m_listener->get_accuracy_handler()) m_listener->get_accuracy_handler()->read(ch, msg); + break; } } diff --git a/src/sensorctl/sensor_adapter.cpp b/src/sensorctl/sensor_adapter.cpp index 9ed2b24..82a54a2 100644 --- a/src/sensorctl/sensor_adapter.cpp +++ b/src/sensorctl/sensor_adapter.cpp @@ -73,6 +73,8 @@ bool sensor_adapter::start(sensor_info info, int &handle) err = sensord_get_sensors(info.type, &sensors, &count); ASSERT_EQ(err, 0); + ASSERT_LT(info.index, count); + ASSERT_GE(info.index, 0); handle = sensord_connect(sensors[info.index]); ASSERT_GE(handle, 0); diff --git a/src/sensorctl/test_bench.cpp b/src/sensorctl/test_bench.cpp index 191fb0d..201a7f5 100644 --- a/src/sensorctl/test_bench.cpp +++ b/src/sensorctl/test_bench.cpp @@ -51,6 +51,7 @@ void test_option::set_options(int argc, char *argv[]) test_case::test_case(const std::string &group, const std::string &name) : m_group(group) , m_name(name) +, m_func(NULL) { test_bench::register_testcase(group, this); } diff --git a/src/server/external_sensor_handler.cpp b/src/server/external_sensor_handler.cpp index 110e15b..7ace9a5 100644 --- a/src/server/external_sensor_handler.cpp +++ b/src/server/external_sensor_handler.cpp @@ -60,8 +60,8 @@ int external_sensor_notifier::notify(void) external_sensor_handler::external_sensor_handler(const sensor_info &info, external_sensor *sensor) : m_info(info) -, m_sensor(sensor) , m_notifier(NULL) +, m_policy(OP_DEFAULT) { init(); } diff --git a/src/server/fusion_sensor_handler.cpp b/src/server/fusion_sensor_handler.cpp index 44c794a..ace60b8 100644 --- a/src/server/fusion_sensor_handler.cpp +++ b/src/server/fusion_sensor_handler.cpp @@ -29,7 +29,6 @@ fusion_sensor_handler::fusion_sensor_handler(const sensor_info &info, fusion_sensor *sensor) : m_info(info) , m_sensor(sensor) -, m_policy(OP_DEFAULT) { } @@ -187,7 +186,7 @@ int fusion_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, int3 policy = m_sensor->set_attribute(ob, attr, value); retv_if(policy <= OP_ERROR, policy); - if (m_policy == OP_DEFAULT) { + if (policy == OP_DEFAULT) { /* default logic */ } @@ -203,7 +202,7 @@ int fusion_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, cons policy = m_sensor->set_attribute(ob, attr, value, len); retv_if(policy <= OP_ERROR, policy); - if (m_policy == OP_DEFAULT) { + if (policy == OP_DEFAULT) { /* default logic */ } diff --git a/src/server/fusion_sensor_handler.h b/src/server/fusion_sensor_handler.h index d16278f..151bb16 100644 --- a/src/server/fusion_sensor_handler.h +++ b/src/server/fusion_sensor_handler.h @@ -71,7 +71,6 @@ private: std::unordered_map m_interval_map; std::unordered_map m_batch_latency_map; - int m_policy; }; } diff --git a/src/shared/ipc_server.cpp b/src/shared/ipc_server.cpp index 9723a98..dba54f0 100644 --- a/src/shared/ipc_server.cpp +++ b/src/shared/ipc_server.cpp @@ -30,6 +30,9 @@ using namespace ipc; #define MAX_CONNECTIONS 1000 ipc_server::ipc_server(const std::string &path) +: m_event_loop(NULL) +, m_handler(NULL) +, m_accept_handler(NULL) { m_accept_sock.create(path); } diff --git a/src/shared/socket.cpp b/src/shared/socket.cpp index 239e554..b29ba96 100644 --- a/src/shared/socket.cpp +++ b/src/shared/socket.cpp @@ -375,12 +375,11 @@ bool socket::set_recv_timeout(int sec) bool socket::set_sock_type(int type) { socklen_t opt_len; - int sock_type; - opt_len = sizeof(sock_type); + opt_len = sizeof(type); retvm_if(m_sock_fd < 0, false, "Invalid socket[%d]", m_sock_fd); - if (setsockopt(m_sock_fd, SOL_SOCKET, SO_TYPE, &sock_type, opt_len) < 0) { + if (setsockopt(m_sock_fd, SOL_SOCKET, SO_TYPE, &type, opt_len) < 0) { _ERRNO(errno, _E, "Failed to setsockopt[%d]", m_sock_fd); return false; } -- 2.7.4 From 4a99e65c8d000f7dd4b90c94f3c8f0fbcc8e4fc5 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Wed, 12 Apr 2017 21:30:47 +0900 Subject: [PATCH 06/16] Rename packages in a more conventional way: sensord & sensord-dummy Change-Id: I5a86ca6256fc0781cccea5e6806520c4d3b9822b Signed-off-by: Mu-Woong Lee --- packaging/sensord.spec | 78 ++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index cb86503..e4dfaf3 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -1,6 +1,6 @@ Name: sensord Summary: Sensor daemon -Version: 2.0.10 +Version: 2.0.11 Release: 1 Group: System/Sensor Framework License: Apache-2.0 @@ -18,34 +18,38 @@ BuildRequires: pkgconfig(cynara-creds-socket) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) -Provides: %{name}-profile_tv = %{version}-%{release} -# For backward compatibility - -%description -Sensor daemon - -%package genuine -Summary: Genuine Sensor Framework service daemon and shared library -Requires: %{name} = %{version}-%{release} +Requires: %{name}-dummy = %{version}-%{release} Provides: %{name}-profile_mobile = %{version}-%{release} Provides: %{name}-profile_wearable = %{version}-%{release} Provides: %{name}-profile_ivi = %{version}-%{release} Provides: %{name}-profile_common = %{version}-%{release} +%global __provides_exclude ^.*-genuine\\.so.*$ + +%description +This package provides the fully functional internal API library and the service daemon +of the Sensor Framework. The library replaces the dummy library installed by %{name}-dummy. + + +%package dummy +Summary: Sensor Framework 'dummy' library +Provides: libsensord +Provides: %{name}-profile_tv = %{version}-%{release} + +%description dummy +This package provides the dummy library of the sensor internal API. +Installing %{name} replaces this dummy library with the actually functional library. -%description genuine -Binary replacement for sensord. -This genuine sensord package contains actually working shared library -of the sensor internal APIs and the sensor service daemon. -If you want to keep using %{name} after uninstalling this, you need to reinstall %{name}. %package devel Summary: Internal Sensor API (Development) Group: System/Development -Requires: %{name} = %{version}-%{release} +Requires: %{name}-dummy = %{version}-%{release} +Provides: libsensord-devel %description devel Internal Sensor API (Development) + %package -n sensor-hal-devel Summary: Sensord HAL interface Group: System/Development @@ -53,6 +57,7 @@ Group: System/Development %description -n sensor-hal-devel Sensord HAL interface + %package -n sensor-test Summary: Sensord library Group: System/Testing @@ -60,14 +65,15 @@ Group: System/Testing %description -n sensor-test Sensor functional testing + # These dummy packages will be removed later. %package -n libsensord Summary: Dummy package for backward compatibility Requires: sensord %description -n libsensord -Without this dummy package, obs may reports several 'unresolvable' issues. -This is a temporal solution to handle such cases. +A yaml requires libsensord explicitly. This is a temporal solution to prevent image creation failures. + %package -n libsensord-devel Summary: Dummy package for backward compatibility @@ -77,6 +83,7 @@ Requires: sensord-devel Some packages require libsensord-devel directly, and it causes local gbs build failures with the old build snapshots. This is a temporal solution to handle such cases. + %prep %setup -q @@ -100,35 +107,35 @@ install -m 0644 %SOURCE2 %{buildroot}%{_unitdir} ln -s libsensor.so.2 %{buildroot}%{_libdir}/libsensor.so.1 %post -/sbin/ldconfig - -%postun -/sbin/ldconfig - -%files -%manifest packaging/sensord.manifest -%{_libdir}/libsensor.so.* -%license LICENSE.APLv2 - -%post genuine pushd %{_libdir} ln -sf libsensor-genuine.so.%{version} libsensor.so.%{version} chsmack -a "_" libsensor.so.%{version} popd /sbin/ldconfig -%preun genuine -echo "You need to reinstall %{name}, if you need to keep using the APIs after uinstalling this." +%preun +echo "You need to reinstall %{name}-dummy to keep using the APIs after uninstalling this." -%files genuine +%files %manifest packaging/sensord.manifest -%{_libdir}/libsensord-shared.so %{_libdir}/libsensor-genuine.so.* +%{_libdir}/libsensord-shared.so %{_bindir}/sensord %{_unitdir}/sensord.service %{_unitdir}/sensord.socket %{_unitdir}/multi-user.target.wants/sensord.service %{_unitdir}/sockets.target.wants/sensord.socket +%license LICENSE.APLv2 + + +%post dummy +/sbin/ldconfig + +%files dummy +%manifest packaging/sensord.manifest +%{_libdir}/libsensor.so.* +%license LICENSE.APLv2 + %files devel %manifest packaging/sensord.manifest @@ -137,15 +144,16 @@ echo "You need to reinstall %{name}, if you need to keep using the APIs after ui %{_libdir}/libsensor.so %{_libdir}/pkgconfig/sensor.pc + %files -n sensor-hal-devel %manifest packaging/sensord.manifest %{_includedir}/sensor/sensor_hal*.h + %files -n sensor-test %{_bindir}/sensorctl + %files -n libsensord -%license LICENSE.APLv2 %files -n libsensord-devel -%license LICENSE.APLv2 -- 2.7.4 From d5a83bb3924e79727fce9891c10e0df0bb510ae4 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 12 Apr 2017 18:54:08 +0900 Subject: [PATCH 07/16] sensord: modify sensor plugin interface - rename from get_sensors to get_sensor_info() - change the parameter of update() from id to URI * [TBD] the name of sensor_notifier Change-Id: Ie50afe75a3517847d17e259a6bf317095a827cc7 Signed-off-by: kibak.yoon --- include/external_sensor.h | 4 +-- include/fusion_sensor.h | 11 +++++-- src/server/external_sensor_handler.cpp | 3 +- src/server/fusion_sensor_handler.cpp | 51 ++++++++++++++++--------------- src/server/fusion_sensor_handler.h | 15 +++++++-- src/server/sensor_event_handler.cpp | 2 +- src/server/sensor_manager.cpp | 56 +++++++++++++++------------------- 7 files changed, 77 insertions(+), 65 deletions(-) diff --git a/include/external_sensor.h b/include/external_sensor.h index d34cf96..d029419 100644 --- a/include/external_sensor.h +++ b/include/external_sensor.h @@ -68,8 +68,8 @@ public: inline uint32_t get_version(void) { return EXTERNAL_SENSOR_VERSION(1, 0); } - virtual int get_sensors(const sensor_info2_t **sensors) = 0; - virtual void set_notifier(sensor_notifier *notifier) = 0; + virtual int get_sensor_info(const sensor_info2_t **info) = 0; + virtual int set_notifier(sensor_notifier *notifier) = 0; virtual int get_data(sensor_data_t **data, int *len) = 0; virtual int start(observer_h ob) diff --git a/include/fusion_sensor.h b/include/fusion_sensor.h index 6fa6d09..f772e3d 100644 --- a/include/fusion_sensor.h +++ b/include/fusion_sensor.h @@ -49,6 +49,11 @@ typedef int (*create_fusion_t)(fusion_sensor_t **sensors); typedef void *observer_h; +typedef struct required_sensor_s { + uint32_t id; + const char *uri; +} required_sensor_s; + /* * Sensor interface */ @@ -58,11 +63,11 @@ public: inline uint32_t get_version(void) { return FUSION_SENSOR_VERSION(1, 0); } - virtual int get_sensors(const sensor_info2_t **sensors) = 0; - virtual void get_required_sensors(std::vector &sensors) = 0; + virtual int get_sensor_info(const sensor_info2_t **info) = 0; + virtual int get_required_sensors(const required_sensor_s **info) = 0; /* if update() returns positive value, then get_data() is called */ - virtual int update(const char *uri, sensor_data_t *data, int len) = 0; + virtual int update(uint32_t id, sensor_data_t *data, int len) = 0; virtual int get_data(sensor_data_t **data, int *len) = 0; virtual int start(observer_h ob) diff --git a/src/server/external_sensor_handler.cpp b/src/server/external_sensor_handler.cpp index 7ace9a5..15b8bae 100644 --- a/src/server/external_sensor_handler.cpp +++ b/src/server/external_sensor_handler.cpp @@ -52,9 +52,8 @@ int external_sensor_notifier::notify(void) /* TODO: pointer would be better */ sensor_info info = m_sensor->get_sensor_info(); - std::string uri = info.get_type_uri(); - return m_sensor->notify(uri.c_str(), data, len); + return m_sensor->notify(info.get_uri().c_str(), data, len); } external_sensor_handler::external_sensor_handler(const sensor_info &info, diff --git a/src/server/fusion_sensor_handler.cpp b/src/server/fusion_sensor_handler.cpp index ace60b8..05ab314 100644 --- a/src/server/fusion_sensor_handler.cpp +++ b/src/server/fusion_sensor_handler.cpp @@ -34,18 +34,23 @@ fusion_sensor_handler::fusion_sensor_handler(const sensor_info &info, fusion_sensor_handler::~fusion_sensor_handler() { + m_required_sensors.clear(); } -void fusion_sensor_handler::add_required_sensor(sensor_handler *sensor) +void fusion_sensor_handler::add_required_sensor(uint32_t id, sensor_handler *sensor) { - m_required_sensors.push_back(sensor); + sensor_info info = sensor->get_sensor_info(); + m_required_sensors.emplace(info.get_uri(), required_sensor(id, sensor)); } int fusion_sensor_handler::update(const char *uri, ipc::message *msg) { retv_if(!m_sensor, -EINVAL); - if (m_sensor->update(uri, (sensor_data_t *)msg->body(), msg->size()) < 0) + auto it = m_required_sensors.find(uri); + retv_if(it == m_required_sensors.end(), OP_SUCCESS); + + if (m_sensor->update(it->second.id, (sensor_data_t *)msg->body(), msg->size()) < 0) return OP_SUCCESS; sensor_data_t *data; @@ -54,9 +59,7 @@ int fusion_sensor_handler::update(const char *uri, ipc::message *msg) if (m_sensor->get_data(&data, &len) < 0) return OP_ERROR; - std::string fsensor_uri = m_info.get_type_uri(); - - return notify(fsensor_uri.c_str(), data, len); + return notify(m_info.get_uri().c_str(), data, len); } const sensor_info &fusion_sensor_handler::get_sensor_info(void) @@ -226,9 +229,9 @@ int fusion_sensor_handler::flush(sensor_observer *ob) int fusion_sensor_handler::start_internal(void) { - int size = m_required_sensors.size(); - for (int i = 0; i < size; ++i) { - if (m_required_sensors[i]->start(this) < 0) + auto it = m_required_sensors.begin(); + for (; it != m_required_sensors.end(); ++it) { + if (it->second.sensor->start(this) < 0) return OP_ERROR; } @@ -237,9 +240,9 @@ int fusion_sensor_handler::start_internal(void) int fusion_sensor_handler::stop_internal(void) { - int size = m_required_sensors.size(); - for (int i = 0; i < size; ++i) { - if (m_required_sensors[i]->stop(this) < 0) + auto it = m_required_sensors.begin(); + for (; it != m_required_sensors.end(); ++it) { + if (it->second.sensor->stop(this) < 0) return OP_ERROR; } @@ -248,9 +251,9 @@ int fusion_sensor_handler::stop_internal(void) int fusion_sensor_handler::set_interval_internal(int32_t interval) { - int size = m_required_sensors.size(); - for (int i = 0; i < size; ++i) { - if (m_required_sensors[i]->set_interval(this, interval) < 0) + auto it = m_required_sensors.begin(); + for (; it != m_required_sensors.end(); ++it) { + if (it->second.sensor->set_interval(this, interval) < 0) return OP_ERROR; } @@ -259,9 +262,9 @@ int fusion_sensor_handler::set_interval_internal(int32_t interval) int fusion_sensor_handler::set_batch_latency_internal(int32_t latency) { - int size = m_required_sensors.size(); - for (int i = 0; i < size; ++i) { - if (m_required_sensors[i]->set_batch_latency(this, latency) < 0) + auto it = m_required_sensors.begin(); + for (; it != m_required_sensors.end(); ++it) { + if (it->second.sensor->set_batch_latency(this, latency) < 0) return OP_ERROR; } @@ -270,9 +273,9 @@ int fusion_sensor_handler::set_batch_latency_internal(int32_t latency) int fusion_sensor_handler::set_attribute_internal(int32_t attr, int32_t value) { - int size = m_required_sensors.size(); - for (int i = 0; i < size; ++i) { - if (m_required_sensors[i]->set_attribute(this, attr, value) < 0) + auto it = m_required_sensors.begin(); + for (; it != m_required_sensors.end(); ++it) { + if (it->second.sensor->set_attribute(this, attr, value) < 0) return OP_ERROR; } @@ -281,9 +284,9 @@ int fusion_sensor_handler::set_attribute_internal(int32_t attr, int32_t value) int fusion_sensor_handler::set_attribute_internal(int32_t attr, const char *value, int len) { - int size = m_required_sensors.size(); - for (int i = 0; i < size; ++i) { - if (m_required_sensors[i]->set_attribute(this, attr, value, len) < 0) + auto it = m_required_sensors.begin(); + for (; it != m_required_sensors.end(); ++it) { + if (it->second.sensor->set_attribute(this, attr, value, len) < 0) return OP_ERROR; } diff --git a/src/server/fusion_sensor_handler.h b/src/server/fusion_sensor_handler.h index 151bb16..0bd1fa6 100644 --- a/src/server/fusion_sensor_handler.h +++ b/src/server/fusion_sensor_handler.h @@ -30,13 +30,24 @@ namespace sensor { +class required_sensor { +public: + required_sensor(uint32_t _id, sensor_handler *_sensor) + : id(_id) + , sensor(_sensor) + {} + + uint32_t id; + sensor_handler *sensor; +}; + class fusion_sensor_handler : public sensor_handler, public sensor_observer { public: fusion_sensor_handler(const sensor_info &info, fusion_sensor *sensor); ~fusion_sensor_handler(); - void add_required_sensor(sensor_handler *sensor); + void add_required_sensor(uint32_t id, sensor_handler *sensor); /* subscriber */ int update(const char *uri, ipc::message *msg); @@ -67,7 +78,7 @@ private: sensor_info m_info; fusion_sensor *m_sensor; - std::vector m_required_sensors; + std::unordered_map m_required_sensors; std::unordered_map m_interval_map; std::unordered_map m_batch_latency_map; diff --git a/src/server/sensor_event_handler.cpp b/src/server/sensor_event_handler.cpp index de13006..4fac18d 100644 --- a/src/server/sensor_event_handler.cpp +++ b/src/server/sensor_event_handler.cpp @@ -62,7 +62,7 @@ bool sensor_event_handler::handle(int fd, ipc::event_condition condition) info = m_sensor->get_sensor_info(); //_I("[Data] allocate %p", data); - if (m_sensor->notify(info.get_type_uri().c_str(), data, length) < 0) { + if (m_sensor->notify(info.get_uri().c_str(), data, length) < 0) { free(data); } info.clear(); diff --git a/src/server/sensor_manager.cpp b/src/server/sensor_manager.cpp index 7aa04fe..9a06489 100644 --- a/src/server/sensor_manager.cpp +++ b/src/server/sensor_manager.cpp @@ -187,41 +187,37 @@ void sensor_manager::create_physical_sensors(device_sensor_registry_t &devices, void sensor_manager::create_fusion_sensors(fusion_sensor_registry_t &fsensors) { const sensor_info2_t *info; + const required_sensor_s *required_sensors; fusion_sensor_handler *fsensor; - std::vector req_names; + sensor_handler *sensor = NULL; for (auto it = fsensors.begin(); it != fsensors.end(); ++it) { - int count = (*it)->get_sensors(&info); - - for (int i = 0; i < count; ++i) { - bool support = true; - req_names.clear(); + bool support = true; - fsensor = new(std::nothrow) fusion_sensor_handler(info[i], it->get()); - retm_if(!fsensor, "Failed to allocate memory"); + (*it)->get_sensor_info(&info); - (*it)->get_required_sensors(req_names); - for (unsigned int j = 0; j < req_names.size(); ++j) { - sensor_handler *sensor; - sensor = get_sensor_by_type(req_names[j]); + fsensor = new(std::nothrow) fusion_sensor_handler(info[0], it->get()); + retm_if(!fsensor, "Failed to allocate memory"); - if (sensor == NULL) { - support = false; - break; - } + int count = (*it)->get_required_sensors(&required_sensors); + for (int i = 0; i < count; ++i) { + sensor = get_sensor_by_type(required_sensors[i].uri); - fsensor->add_required_sensor(sensor); + if (sensor == NULL) { + support = false; + break; } - if (!support) { - delete fsensor; - /* TODO: remove plugin */ - continue; - } + fsensor->add_required_sensor(required_sensors[i].id, sensor); + } - sensor_info sinfo = fsensor->get_sensor_info(); - m_sensors[sinfo.get_uri()] = fsensor; + if (!support) { + delete fsensor; + continue; } + + sensor_info sinfo = fsensor->get_sensor_info(); + m_sensors[sinfo.get_uri()] = fsensor; } } @@ -231,15 +227,13 @@ void sensor_manager::create_external_sensors(external_sensor_registry_t &esensor external_sensor_handler *esensor; for (auto it = esensors.begin(); it != esensors.end(); ++it) { - int count = (*it)->get_sensors(&info); + (*it)->get_sensor_info(&info); - for (int i = 0; i < count; ++i) { - esensor = new(std::nothrow) external_sensor_handler(info[i], it->get()); - retm_if(!esensor, "Failed to allocate memory"); + esensor = new(std::nothrow) external_sensor_handler(info[0], it->get()); + retm_if(!esensor, "Failed to allocate memory"); - sensor_info sinfo = esensor->get_sensor_info(); - m_sensors[sinfo.get_uri()] = esensor; - } + sensor_info sinfo = esensor->get_sensor_info(); + m_sensors[sinfo.get_uri()] = esensor; } } -- 2.7.4 From 3bbc00562a898ecbab323355207e5a9fc4d65fc7 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 12 Apr 2017 18:57:17 +0900 Subject: [PATCH 08/16] sensord: enable auto_rotation sensor Signed-off-by: kibak.yoon Change-Id: I16b057a84c9606297a5a7d8b481bae633a95b69c --- CMakeLists.txt | 1 + packaging/sensord.spec | 1 + src/sensor/CMakeLists.txt | 92 ++++----- src/sensor/auto_rotation/auto_rotation_alg.cpp | 3 +- src/sensor/auto_rotation/auto_rotation_alg.h | 6 +- .../auto_rotation/auto_rotation_alg_emul.cpp | 9 +- src/sensor/auto_rotation/auto_rotation_alg_emul.h | 11 +- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 209 +++++++-------------- src/sensor/auto_rotation/auto_rotation_sensor.h | 50 ++--- src/sensor/create.cpp | 69 +++++++ 10 files changed, 207 insertions(+), 244 deletions(-) create mode 100644 src/sensor/create.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e91c388..0f30d92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ ADD_SUBDIRECTORY(src/server) ADD_SUBDIRECTORY(src/client) ADD_SUBDIRECTORY(src/client-dummy) ADD_SUBDIRECTORY(src/sensorctl) +ADD_SUBDIRECTORY(src/sensor) INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ diff --git a/packaging/sensord.spec b/packaging/sensord.spec index e4dfaf3..f340404 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -120,6 +120,7 @@ echo "You need to reinstall %{name}-dummy to keep using the APIs after uninstall %manifest packaging/sensord.manifest %{_libdir}/libsensor-genuine.so.* %{_libdir}/libsensord-shared.so +%{_libdir}/sensor/fusion/libsensor-fusion.so %{_bindir}/sensord %{_unitdir}/sensord.service %{_unitdir}/sensord.socket diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt index 0339c23..dc6f04b 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/sensor/CMakeLists.txt @@ -1,79 +1,53 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(sensors CXX) +PROJECT(sensor-fusion CXX) INCLUDE(GNUInstallDirs) -SET(ACC "OFF") -SET(HRM "OFF") -SET(HRM_VIRT "OFF") -SET(AUTO_ROTATION "OFF") +SET(AUTO_ROTATION "ON") SET(GRAVITY "OFF") SET(LINEAR_ACCEL "OFF") -SET(RV "OFF") -SET(ORIENTATION "OFF") -SET(FACE_DOWN "OFF") -SET(SENSORHUB "OFF") INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/shared - ${CMAKE_SOURCE_DIR}/src/server ${CMAKE_CURRENT_SOURCE_DIR} ) -FILE(GLOB SENSOR_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}) +# Common Options +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--print-gc-sections") +MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}") +MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") -IF("${ACC}" STREQUAL "ON") -FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/accel/*.cpp) -SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/accel) -SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_ACCEL") -ENDIF() +# Internal Debugging Options +#ADD_DEFINITIONS(-Wall -g -D_DEBUG) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(PLUGINS_PKGS REQUIRED dlog) + +FOREACH(flag ${PLUGINS_PKGS_CFLAGS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + +FILE(GLOB SRCS *.cpp) -IF("${HRM}" STREQUAL "ON") - FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/hrm/*.cpp) - SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/hrm) - SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_HRM") -ENDIF() -IF("${HRM_VIRT}" STREQUAL "ON") -add_subdirectory(hrm_virt) -ENDIF() IF("${AUTO_ROTATION}" STREQUAL "ON") - FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/auto_rotation/*.cpp) - SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/auto_rotation) - SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_AUTO_ROTATION") +FILE(GLOB_RECURSE SRCS ${SRCS} auto_rotation/*.cpp) +ADD_DEFINITIONS(-DENABLE_AUTO_ROTATION) ENDIF() + IF("${GRAVITY}" STREQUAL "ON") - FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/gravity/*.cpp) - SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/gravity) - SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_GRAVITY") +FILE(GLOB_RECURSE SRCS ${SRCS} gravity/*.cpp) +ADD_DEFINITIONS(-DENABLE_GRAVITY) ENDIF() + IF("${LINEAR_ACCEL}" STREQUAL "ON") - FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/linear_accel/*.cpp) - SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/linear_accel) - SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_LINEAR_ACCEL") -ENDIF() -IF("${ORIENTATION}" STREQUAL "ON") - FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/orientation/*.cpp) - SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/orientation) - SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_ORIENTATION") -ENDIF() -IF("${RV}" STREQUAL "ON") - FILE(GLOB SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/rotation_vector/*.cpp) - SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/rotation_vector) - SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_ROTATION_VECTOR") - FILE(GLOB SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/rotation_vector/fusion_utils/*.cpp) -ENDIF() -IF("${FACE_DOWN}" STREQUAL "ON") - FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/gesture/*.cpp) - SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/gesture) - SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_FACE_DOWN") -ENDIF() -IF("${SENSORHUB}" STREQUAL "ON") - FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/sensorhub/*.cpp) - SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/sensorhub) - SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_SENSORHUB") +FILE(GLOB_RECURSE SRCS ${SRCS} linear_accel/*.cpp) +ADD_DEFINITIONS(-DENABLE_LINEAR_ACCEL) ENDIF() -MESSAGE("${SENSOR_SRCS}") -SET(SENSOR_SRCS ${SENSOR_SRCS} PARENT_SCOPE) -SET(SENSOR_HEADERS ${SENSOR_HEADERS} PARENT_SCOPE) -SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} PARENT_SCOPE) +MESSAGE("Sources: ${SRCS}") +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS}) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor/fusion) diff --git a/src/sensor/auto_rotation/auto_rotation_alg.cpp b/src/sensor/auto_rotation/auto_rotation_alg.cpp index 14f61ae..d01bac4 100644 --- a/src/sensor/auto_rotation/auto_rotation_alg.cpp +++ b/src/sensor/auto_rotation/auto_rotation_alg.cpp @@ -17,8 +17,7 @@ * */ -#include -#include +#include "auto_rotation_alg.h" auto_rotation_alg::auto_rotation_alg() { diff --git a/src/sensor/auto_rotation/auto_rotation_alg.h b/src/sensor/auto_rotation/auto_rotation_alg.h index cfcc72d..301330c 100644 --- a/src/sensor/auto_rotation/auto_rotation_alg.h +++ b/src/sensor/auto_rotation/auto_rotation_alg.h @@ -17,8 +17,8 @@ * */ -#ifndef _AUTO_ROTATION_ALG_H_ -#define _AUTO_ROTATION_ALG_H_ +#ifndef __AUTO_ROTATION_ALG_H__ +#define __AUTO_ROTATION_ALG_H__ class auto_rotation_alg { public: @@ -32,4 +32,4 @@ public: virtual bool get_rotation(float acc[3], unsigned long long timestamp, int prev_rotation, int &rotation) = 0; }; -#endif /* _AUTO_ROTATION_ALG_H_ */ +#endif /* __AUTO_ROTATION_ALG_H__ */ diff --git a/src/sensor/auto_rotation/auto_rotation_alg_emul.cpp b/src/sensor/auto_rotation/auto_rotation_alg_emul.cpp index e3200dd..0448e6b 100644 --- a/src/sensor/auto_rotation/auto_rotation_alg_emul.cpp +++ b/src/sensor/auto_rotation/auto_rotation_alg_emul.cpp @@ -17,12 +17,11 @@ * */ -#include -#include -#include -#include -#include +#include "auto_rotation_alg_emul.h" + #include +#include +#include #define ROTATION_RULE_CNT 4 diff --git a/src/sensor/auto_rotation/auto_rotation_alg_emul.h b/src/sensor/auto_rotation/auto_rotation_alg_emul.h index 1c9357c..bf148a0 100644 --- a/src/sensor/auto_rotation/auto_rotation_alg_emul.h +++ b/src/sensor/auto_rotation/auto_rotation_alg_emul.h @@ -17,20 +17,21 @@ * */ -#ifndef _AUTO_ROTATION_ALG_EMUL_H_ -#define _AUTO_ROTATION_ALG_EMUL_H_ +#ifndef __AUTO_ROTATION_ALG_EMUL_H__ +#define __AUTO_ROTATION_ALG_EMUL_H__ -#include +#include "auto_rotation_alg.h" class auto_rotation_alg_emul : public auto_rotation_alg { public: auto_rotation_alg_emul(); virtual ~auto_rotation_alg_emul(); - virtual bool get_rotation(float acc[3], unsigned long long timestamp, int prev_rotation, int &cur_rotation); + bool get_rotation(float acc[3], unsigned long long timestamp, + int prev_rotation, int &cur_rotation); private: int convert_rotation(int prev_rotation, float acc_pitch, float acc_theta); }; -#endif /* _AUTO_ROTATION_ALG_EMUL_H_ */ +#endif /* __AUTO_ROTATION_ALG_EMUL_H__ */ diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 71d10b4..2a6aa98 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -1,7 +1,7 @@ /* * sensord * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,151 +17,98 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include +#include "auto_rotation_sensor.h" #include #include -#include -#include -#include -#include -#include -#include +#include "auto_rotation_alg_emul.h" -#define SENSOR_NAME "SENSOR_AUTO_ROTATION" +#define NAME_SENSOR "http://tizen.org/sensor/auto_rotation/AUTO_ROTATION" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: AUTO_ROTATION_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: AUTO_ROTATION_DEGREE_UNKNOWN, + max_range: AUTO_ROTATION_DEGREE_270, + resolution: 1, + min_interval: 60, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC} +}; auto_rotation_sensor::auto_rotation_sensor() -: m_accel_sensor(NULL) -, m_alg(NULL) -, m_rotation(0) -, m_interval(100) +: m_rotation(0) , m_rotation_time(0) +, m_alg(NULL) { + if (!init()) + throw OP_ERROR; } auto_rotation_sensor::~auto_rotation_sensor() { - delete m_alg; - - _I("auto_rotation_sensor is destroyed!\n"); + deinit(); } bool auto_rotation_sensor::init(void) { - m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); - - if (!m_accel_sensor) { - _W("cannot load accel sensor_hal from %s", get_name()); - return false; - } - m_alg = get_alg(); - - if (!m_alg) { - _E("Not supported AUTO ROTATION sensor"); - return false; - } - - if (!m_alg->open()) - return false; - - _I("%s is created!\n", get_name()); - + retvm_if(!m_alg, false, "Not supported"); + retvm_if(!m_alg->open(), false, "Cannot open auto rotation algorithm"); return true; } -sensor_type_t auto_rotation_sensor::get_type(void) +void auto_rotation_sensor::deinit(void) { - return AUTO_ROTATION_SENSOR; + delete m_alg; } -unsigned int auto_rotation_sensor::get_event_type(void) +int auto_rotation_sensor::get_sensor_info(const sensor_info2_t **info) { - return AUTO_ROTATION_EVENT_CHANGE_STATE; + *info = &sensor_info; + return OP_SUCCESS; } -const char* auto_rotation_sensor::get_name(void) +int auto_rotation_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 1; } -bool auto_rotation_sensor::get_sensor_info(sensor_info &info) +int auto_rotation_sensor::update(uint32_t id, sensor_data_t *data, int len) { - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); // FIXME - info.set_name("Auto Rotation Sensor"); - info.set_vendor("Samsung Electronics"); - info.set_min_range(AUTO_ROTATION_DEGREE_UNKNOWN); - info.set_max_range(AUTO_ROTATION_DEGREE_270); - info.set_resolution(1); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void auto_rotation_sensor::synthesize(const sensor_event_t& event) -{ - if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) - return; - int rotation; float acc[3]; - acc[0] = event.data->values[0]; - acc[1] = event.data->values[1]; - acc[2] = event.data->values[2]; - - if (!m_alg->get_rotation(acc, event.data->timestamp, m_rotation, rotation)) - return; - - m_rotation = rotation; - m_rotation_time = event.data->timestamp; + acc[0] = data->values[0]; + acc[1] = data->values[1]; + acc[2] = data->values[2]; - sensor_event_t *rotation_event; - sensor_data_t *rotation_data; - int data_length; - int remains; + if (!m_alg->get_rotation(acc, data->timestamp, m_rotation, rotation)) + return OP_ERROR; - rotation_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!rotation_event) { - _E("Failed to allocate memory"); - return; - } + _D("Rotation: %d, ACC[0]: %f, ACC[1]: %f, ACC[2]: %f", + rotation, data->values[0], data->values[1], data->values[2]); - remains = get_data(&rotation_data, &data_length); - - if (remains < 0) { - free(rotation_event); - return; - } - - rotation_event->sensor_id = get_id(); - rotation_event->event_type = AUTO_ROTATION_EVENT_CHANGE_STATE; - rotation_event->data_length = data_length; - rotation_event->data = rotation_data; - - push(rotation_event); + m_rotation = rotation; + m_rotation_time = data->timestamp; - _D("Rotation: %d, ACC[0]: %f, ACC[1]: %f, ACC[2]: %f", rotation, event.data->values[0], event.data->values[1], event.data->values[2]); + return OP_SUCCESS; } int auto_rotation_sensor::get_data(sensor_data_t **data, int *length) { - /* if It is batch sensor, remains can be 2+ */ - int remains = 1; - sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); @@ -173,54 +120,36 @@ int auto_rotation_sensor::get_data(sensor_data_t **data, int *length) *data = sensor_data; *length = sizeof(sensor_data_t); - return --remains; + return 1; } -bool auto_rotation_sensor::set_interval(unsigned long interval) +int auto_rotation_sensor::start(observer_h ob) { - m_accel_sensor->add_interval((intptr_t)this , interval, true); - - m_interval = interval; - return false; -} + m_rotation = AUTO_ROTATION_DEGREE_UNKNOWN; -bool auto_rotation_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} + /* TODO: cache */ -bool auto_rotation_sensor::set_wakeup(int wakeup) -{ - return false; -} + m_alg->start(); -bool auto_rotation_sensor::pre_start(void) -{ - m_rotation = AUTO_ROTATION_DEGREE_UNKNOWN; - return true; + /* if OP_DEFAULT is returned, + * this function is not called anymore before stop() is called */ + return OP_DEFAULT; } -bool auto_rotation_sensor::on_start(void) +int auto_rotation_sensor::stop(observer_h ob) { - int length; - m_rotation = AUTO_ROTATION_DEGREE_UNKNOWN; + m_alg->stop(); - get_data(&m_last_data, &length); - - m_alg->start(); - - m_accel_sensor->add_interval((intptr_t)this , m_interval, true); - m_accel_sensor->start(); - - return activate(); + /* if OP_DEFAULT is returned, + * this function is not called anymore before start() is called */ + return OP_DEFAULT; } -bool auto_rotation_sensor::on_stop(void) +int auto_rotation_sensor::set_interval(observer_h ob, int32_t &interval) { - m_accel_sensor->delete_interval((intptr_t)this , true); - m_accel_sensor->stop(); - - return deactivate(); + /* Fix internal */ + interval = 60; + return OP_SUCCESS; } auto_rotation_alg *auto_rotation_sensor::get_alg(void) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.h b/src/sensor/auto_rotation/auto_rotation_sensor.h index d50f728..c573203 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.h +++ b/src/sensor/auto_rotation/auto_rotation_sensor.h @@ -1,7 +1,7 @@ /* * sensord * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,50 +17,40 @@ * */ -#ifndef _AUTO_ROTATION_SENSOR_H_ -#define _AUTO_ROTATION_SENSOR_H_ +#ifndef __AUTO_ROTATION_SENSOR_H__ +#define __AUTO_ROTATION_SENSOR_H__ -#include +#include #include -#include -class auto_rotation_sensor : public virtual_sensor { +#include "auto_rotation_alg.h" + +class auto_rotation_sensor : public fusion_sensor { public: auto_rotation_sensor(); virtual ~auto_rotation_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); + int start(observer_h ob); + int stop(observer_h ob); - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); + int set_interval(observer_h ob, int32_t &interval); - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_accel_sensor; - auto_rotation_alg *m_alg; + bool init(void); + void deinit(void); + + auto_rotation_alg *get_alg(void); int m_rotation; - unsigned int m_interval; unsigned long long m_rotation_time; - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - virtual bool set_wakeup(int wakeup); - - virtual bool pre_start(void); - virtual bool on_start(void); - virtual bool on_stop(void); - - auto_rotation_alg *get_alg(void); + auto_rotation_alg *m_alg; }; -#endif /* _AUTO_ROTATION_SENSOR_H_ */ +#endif /* __AUTO_ROTATION_SENSOR_H__ */ diff --git a/src/sensor/create.cpp b/src/sensor/create.cpp new file mode 100644 index 0000000..10dd21f --- /dev/null +++ b/src/sensor/create.cpp @@ -0,0 +1,69 @@ +/* + * 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 + +#ifdef ENABLE_AUTO_ROTATION +#include "auto_rotation/auto_rotation_sensor.h" +#endif +#ifdef ENABLE_GRAVITY +#include "gravity/gravity_lowpass_sensor.h" +#include "gravity/gravity_comp_sensor.h" +#endif +#ifdef ENABLE_LINEAR_ACCEL +#include "linear_accel/linear_accel_sensor.h" +#endif + +static std::vector sensors; + +template +void create_sensor(const char *name) +{ + fusion_sensor *instance = NULL; + try { + instance = new _sensor; + } catch (std::exception &e) { + _E("Failed to create %s sensor, exception: %s", name, e.what()); + return; + } catch (int err) { + _ERRNO(err, _E, "Failed to create %s sensor device", name); + return; + } + + sensors.push_back(instance); +} + +extern "C" int create(fusion_sensor_t **fsensors) +{ +#ifdef ENABLE_AUTO_ROTATION + create_sensor("Accelerometer"); +#endif + +#ifdef ENABLE_GRAVITY + create_sensor("Gravity(Lowpass)"); + create_sensor("Gravity(Complementary)"); +#endif + +#ifdef ENABLE_LINEAR_ACCEL + create_sensor("Linear Acceleration Sensor"); +#endif + + *fsensors = &sensors[0]; + return sensors.size(); +} -- 2.7.4 From b34fe61cf4032618a61f7b6510492f2121d6ca9b Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 12 Apr 2017 19:54:18 +0900 Subject: [PATCH 09/16] sensord: enable gravity sensors (lowpass and complementary) Change-Id: I7324bb6b806befc188145ed26281db9a8a65d36e Signed-off-by: kibak.yoon --- src/sensor/CMakeLists.txt | 2 +- src/sensor/gravity/gravity_comp_sensor.cpp | 244 ++++++++++++ src/sensor/gravity/gravity_comp_sensor.h | 60 +++ src/sensor/gravity/gravity_lowpass_sensor.cpp | 131 +++++++ src/sensor/gravity/gravity_lowpass_sensor.h | 45 +++ src/sensor/gravity/gravity_sensor.cpp | 532 -------------------------- src/sensor/gravity/gravity_sensor.h | 90 ----- 7 files changed, 481 insertions(+), 623 deletions(-) create mode 100644 src/sensor/gravity/gravity_comp_sensor.cpp create mode 100644 src/sensor/gravity/gravity_comp_sensor.h create mode 100644 src/sensor/gravity/gravity_lowpass_sensor.cpp create mode 100644 src/sensor/gravity/gravity_lowpass_sensor.h delete mode 100644 src/sensor/gravity/gravity_sensor.cpp delete mode 100644 src/sensor/gravity/gravity_sensor.h diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt index dc6f04b..edd1357 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/sensor/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sensor-fusion CXX) INCLUDE(GNUInstallDirs) SET(AUTO_ROTATION "ON") -SET(GRAVITY "OFF") +SET(GRAVITY "ON") SET(LINEAR_ACCEL "OFF") INCLUDE_DIRECTORIES( diff --git a/src/sensor/gravity/gravity_comp_sensor.cpp b/src/sensor/gravity/gravity_comp_sensor.cpp new file mode 100644 index 0000000..2a09115 --- /dev/null +++ b/src/sensor/gravity/gravity_comp_sensor.cpp @@ -0,0 +1,244 @@ +/* + * sensord + * + * Copyright (c) 2017 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 "gravity_comp_sensor.h" + +#include +#include +#include +#include + +#define NAME_SENSOR "http://tizen.org/sensor/gravity/complementary" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +#define SRC_ID_GYRO 0x2 +#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope" + +#define GRAVITY 9.80665 + +#define PHASE_ACCEL_READY 0x01 +#define PHASE_GYRO_READY 0x02 +#define PHASE_FUSION_READY 0x03 +#define US_PER_SEC 1000000 +#define MS_PER_SEC 1000 +#define INV_ANGLE -1000 +#define TAU_LOW 0.4 +#define TAU_MID 0.75 +#define TAU_HIGH 0.99 + +#define DEG2RAD(x) ((x) * M_PI / 180.0) +#define NORM(x, y, z) sqrt((x)*(x) + (y)*(y) + (z)*(z)) +#define ARCTAN(x, y) ((x) == 0 ? 0 : (y) != 0 ? atan2((x), (y)) : (x) > 0 ? M_PI/2.0 : -M_PI/2.0) + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GRAVITY_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: -19.6, + max_range: 19.6, + resolution: 0.01, + min_interval: 5, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC}, + {SRC_ID_GYRO, SRC_STR_GYRO}, +}; + +gravity_comp_sensor::gravity_comp_sensor() +: m_fusion_phase(0) +, m_x(-1) +, m_y(-1) +, m_z(-1) +, m_accuracy(-1) +, m_time(0) +, m_accel_mag(0) +, m_time_new(0) +{ +} + +gravity_comp_sensor::~gravity_comp_sensor() +{ +} + +int gravity_comp_sensor::get_sensor_info(const sensor_info2_t **info) +{ + *info = &sensor_info; + return OP_SUCCESS; +} + +int gravity_comp_sensor::get_required_sensors(const required_sensor_s **sensors) +{ + *sensors = required_sensors; + return 2; +} + +int gravity_comp_sensor::update(uint32_t id, sensor_data_t *data, int len) +{ + if (id == SRC_ID_ACC) { + fusion_set_accel(data); + m_fusion_phase |= PHASE_ACCEL_READY; + } else if (id == SRC_ID_GYRO) { + fusion_set_gyro(data); + m_fusion_phase |= PHASE_GYRO_READY; + } + + if (m_fusion_phase != PHASE_FUSION_READY) + return OP_ERROR; + + m_fusion_phase = 0; + + fusion_update_angle(); + fusion_get_gravity(); + + return OP_SUCCESS; +} + +void gravity_comp_sensor::fusion_set_accel(sensor_data_t *data) +{ + double x = data->values[0]; + double y = data->values[1]; + double z = data->values[2]; + + m_accel_mag = NORM(x, y, z); + + m_angle_n[0] = ARCTAN(z, y); + m_angle_n[1] = ARCTAN(x, z); + m_angle_n[2] = ARCTAN(y, x); + + m_accuracy = data->accuracy; + m_time_new = data->timestamp; + + _D("AccIn: (%f, %f, %f)", x/m_accel_mag, y/m_accel_mag, z/m_accel_mag); +} + +void gravity_comp_sensor::fusion_set_gyro(sensor_data_t *data) +{ + m_velocity[0] = -DEG2RAD(data->values[0]); + m_velocity[1] = -DEG2RAD(data->values[1]); + m_velocity[2] = -DEG2RAD(data->values[2]); + + m_time_new = data->timestamp; +} + +void gravity_comp_sensor::fusion_update_angle(void) +{ + _D("AngleIn: (%f, %f, %f)", m_angle_n[0], m_angle_n[1], m_angle_n[2]); + _D("AngAccl: (%f, %f, %f)", m_velocity[0], m_velocity[1], m_velocity[2]); + _D("Angle : (%f, %f, %f)", m_angle[0], m_angle[1], m_angle[2]); + + if (m_angle[0] == INV_ANGLE) { + /* 1st iteration */ + m_angle[0] = m_angle_n[0]; + m_angle[1] = m_angle_n[1]; + m_angle[2] = m_angle_n[2]; + } else { + complementary(m_time_new - m_time); + } + + _D("Angle' : (%f, %f, %f)", m_angle[0], m_angle[1], m_angle[2]); +} + +void gravity_comp_sensor::fusion_get_gravity(void) +{ + double x = 0, y = 0, z = 0; + double norm; + double vec[3][3]; + + /* Rotating along y-axis then z-axis */ + vec[0][2] = cos(m_angle[1]); + vec[0][0] = sin(m_angle[1]); + vec[0][1] = vec[0][0] * tan(m_angle[2]); + + /* Rotating along z-axis then x-axis */ + vec[1][0] = cos(m_angle[2]); + vec[1][1] = sin(m_angle[2]); + vec[1][2] = vec[1][1] * tan(m_angle[0]); + + /* Rotating along x-axis then y-axis */ + vec[2][1] = cos(m_angle[0]); + vec[2][2] = sin(m_angle[0]); + vec[2][0] = vec[2][2] * tan(m_angle[1]); + + /* Normalize */ + for (int i = 0; i < 3; ++i) { + norm = NORM(vec[i][0], vec[i][1], vec[i][2]); + vec[i][0] /= norm; + vec[i][1] /= norm; + vec[i][2] /= norm; + x += vec[i][0]; + y += vec[i][1]; + z += vec[i][2]; + } + + norm = NORM(x, y, z); + + m_x = x / norm * GRAVITY; + m_y = y / norm * GRAVITY; + m_z = z / norm * GRAVITY; + m_time = m_time_new; +} + +void gravity_comp_sensor::complementary(unsigned long long time_diff) +{ + double err = fabs(m_accel_mag - GRAVITY) / GRAVITY; + double tau = (err < 0.1 ? TAU_LOW : err > 0.9 ? TAU_HIGH : TAU_MID); + double delta_t = (double)time_diff/ US_PER_SEC; + double alpha = tau / (tau + delta_t); + + _D("mag, err, tau, dt, alpha = %f, %f, %f, %f, %f", m_accel_mag, err, tau, delta_t, alpha); + + m_angle[0] = complementary(m_angle[0], m_angle_n[0], m_velocity[0], delta_t, alpha); + m_angle[1] = complementary(m_angle[1], m_angle_n[1], m_velocity[1], delta_t, alpha); + m_angle[2] = complementary(m_angle[2], m_angle_n[2], m_velocity[2], delta_t, alpha); +} + +double gravity_comp_sensor::complementary(double angle, double angle_in, double vel, double delta_t, double alpha) +{ + double s, c; + angle = angle + vel * delta_t; + s = alpha * sin(angle) + (1 - alpha) * sin(angle_in); + c = alpha * cos(angle) + (1 - alpha) * cos(angle_in); + return ARCTAN(s, c); +} + +int gravity_comp_sensor::get_data(sensor_data_t **data, int *len) +{ + sensor_data_t *sensor_data; + sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + + sensor_data->accuracy = m_accuracy; + sensor_data->timestamp = m_time; + sensor_data->value_count = 3; + sensor_data->values[0] = m_x; + sensor_data->values[1] = m_y; + sensor_data->values[2] = m_z; + + *data = sensor_data; + *len = sizeof(sensor_data_t); + + return 0; +} diff --git a/src/sensor/gravity/gravity_comp_sensor.h b/src/sensor/gravity/gravity_comp_sensor.h new file mode 100644 index 0000000..d3e4d60 --- /dev/null +++ b/src/sensor/gravity/gravity_comp_sensor.h @@ -0,0 +1,60 @@ +/* + * sensord + * + * Copyright (c) 2017 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 __GRAVITY_COMP_SENSOR_H__ +#define __GRAVITY_COMP_SENSOR_H__ + +#include +#include + +class gravity_comp_sensor : public fusion_sensor { +public: + gravity_comp_sensor(); + virtual ~gravity_comp_sensor(); + + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); + + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); + +private: + int m_fusion_phase; + + float m_x; + float m_y; + float m_z; + int m_accuracy; + unsigned long long m_time; + + double m_angle[3]; + double m_angle_n[3]; + double m_accel_mag; + double m_velocity[3]; + unsigned long long m_time_new; + + void fusion_set_accel(sensor_data_t *data); + void fusion_set_gyro(sensor_data_t *data); + void fusion_update_angle(void); + void fusion_get_gravity(void); + double complementary(double angle, double angle_in, double vel, double delta_t, double alpha); + void complementary(unsigned long long time_diff); +}; + +#endif /* _GRAVITY_COMP_SENSOR_H_ */ diff --git a/src/sensor/gravity/gravity_lowpass_sensor.cpp b/src/sensor/gravity/gravity_lowpass_sensor.cpp new file mode 100644 index 0000000..f3e7d7b --- /dev/null +++ b/src/sensor/gravity/gravity_lowpass_sensor.cpp @@ -0,0 +1,131 @@ +/* + * sensord + * + * Copyright (c) 2017 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 "gravity_lowpass_sensor.h" + +#include +#include +#include +#include + +#define NAME_SENSOR "http://tizen.org/sensor/gravity/lowpass" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +#define GRAVITY 9.80665 +#define US_PER_SEC 1000000 +#define TAU_LOW 0.4 +#define TAU_MID 0.75 +#define TAU_HIGH 0.99 +#define NORM(x, y, z) sqrt((x)*(x) + (y)*(y) + (z)*(z)) + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GRAVITY_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: -19.6, + max_range: 19.6, + resolution: 0.01, + min_interval: 5, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC} +}; + +gravity_lowpass_sensor::gravity_lowpass_sensor() +: m_x(-1) +, m_y(-1) +, m_z(-1) +, m_accuracy(-1) +, m_time(0) +{ + _I("Gravity Sensor is created!"); +} + +gravity_lowpass_sensor::~gravity_lowpass_sensor() +{ +} + +int gravity_lowpass_sensor::get_sensor_info(const sensor_info2_t **info) +{ + *info = &sensor_info; + return OP_SUCCESS; +} + +int gravity_lowpass_sensor::get_required_sensors(const required_sensor_s **sensors) +{ + *sensors = required_sensors; + return 1; +} + +int gravity_lowpass_sensor::update(uint32_t id, sensor_data_t *data, int len) +{ + float x, y, z, norm, alpha, tau, err; + + norm = NORM(data->values[0], data->values[1], data->values[2]); + x = data->values[0] / norm * GRAVITY; + y = data->values[1] / norm * GRAVITY; + z = data->values[2] / norm * GRAVITY; + + if (m_time > 0) { + err = fabs(norm - GRAVITY) / GRAVITY; + tau = (err < 0.1 ? TAU_LOW : err > 0.9 ? TAU_HIGH : TAU_MID); + alpha = tau / (tau + (float)(data->timestamp - m_time) / US_PER_SEC); + x = alpha * m_x + (1 - alpha) * x; + y = alpha * m_y + (1 - alpha) * y; + z = alpha * m_z + (1 - alpha) * z; + norm = NORM(x, y, z); + x = x / norm * GRAVITY; + y = y / norm * GRAVITY; + z = z / norm * GRAVITY; + } + + m_time = data->timestamp; + m_accuracy = data->accuracy; + m_x = x; + m_y = y; + m_z = z; + + return OP_SUCCESS; +} + +int gravity_lowpass_sensor::get_data(sensor_data_t **data, int *len) +{ + sensor_data_t *sensor_data; + sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + + sensor_data->accuracy = m_accuracy; + sensor_data->timestamp = m_time; + sensor_data->value_count = 3; + sensor_data->values[0] = m_x; + sensor_data->values[1] = m_y; + sensor_data->values[2] = m_z; + + *data = sensor_data; + *len = sizeof(sensor_data_t); + + return 0; +} diff --git a/src/sensor/gravity/gravity_lowpass_sensor.h b/src/sensor/gravity/gravity_lowpass_sensor.h new file mode 100644 index 0000000..44897b7 --- /dev/null +++ b/src/sensor/gravity/gravity_lowpass_sensor.h @@ -0,0 +1,45 @@ +/* + * sensord + * + * Copyright (c) 2017 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 __GRAVITY_LOWPASS_SENSOR_H__ +#define __GRAVITY_LOWPASS_SENSOR_H__ + +#include +#include + +class gravity_lowpass_sensor : public fusion_sensor { +public: + gravity_lowpass_sensor(); + virtual ~gravity_lowpass_sensor(); + + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); + + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); + +private: + float m_x; + float m_y; + float m_z; + int m_accuracy; + unsigned long long m_time; +}; + +#endif /* __GRAVITY_LOWPASS_SENSOR_H__ */ diff --git a/src/sensor/gravity/gravity_sensor.cpp b/src/sensor/gravity/gravity_sensor.cpp deleted file mode 100644 index d4c74ce..0000000 --- a/src/sensor/gravity/gravity_sensor.cpp +++ /dev/null @@ -1,532 +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 -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#define SENSOR_NAME "SENSOR_GRAVITY" - -#define GRAVITY 9.80665 - -#define PHASE_ACCEL_READY 0x01 -#define PHASE_GYRO_READY 0x02 -#define PHASE_FUSION_READY 0x03 -#define US_PER_SEC 1000000 -#define MS_PER_SEC 1000 -#define INV_ANGLE -1000 -#define TAU_LOW 0.4 -#define TAU_MID 0.75 -#define TAU_HIGH 0.99 - -#define DEG2RAD(x) ((x) * M_PI / 180.0) -#define NORM(x, y, z) sqrt((x)*(x) + (y)*(y) + (z)*(z)) -#define ARCTAN(x, y) ((x) == 0 ? 0 : (y) != 0 ? atan2((x), (y)) : (x) > 0 ? M_PI/2.0 : -M_PI/2.0) - -gravity_sensor::gravity_sensor() -: m_fusion(NULL) -, m_accel_sensor(NULL) -, m_gyro_sensor(NULL) -, m_fusion_phase(0) -, m_x(-1) -, m_y(-1) -, m_z(-1) -, m_accuracy(-1) -, m_time(0) -{ -} - -gravity_sensor::~gravity_sensor() -{ - _I("gravity_sensor is destroyed!\n"); -} - -bool gravity_sensor::init(void) -{ - /* Acc (+ Gyro) fusion */ - m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); - - if (!m_accel_sensor) { - _W("cannot load accelerometer sensor_hal[%s]", get_name()); - return false; - } - - m_gyro_sensor = sensor_loader::get_instance().get_sensor(GYROSCOPE_SENSOR); - - _I("%s (%s) is created!\n", get_name(), m_gyro_sensor ? "Acc+Gyro Fusion" : "LowPass Acc"); - return true; -} - -sensor_type_t gravity_sensor::get_type(void) -{ - return GRAVITY_SENSOR; -} - -unsigned int gravity_sensor::get_event_type(void) -{ - return GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME; -} - -const char* gravity_sensor::get_name(void) -{ - return SENSOR_NAME; -} - -bool gravity_sensor::get_sensor_info(sensor_info &info) -{ - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); // FIXME - info.set_name("Gravity Sensor"); - info.set_vendor("Samsung Electronics"); - info.set_min_range(-19.6); - info.set_max_range(19.6); - info.set_resolution(0.01); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void gravity_sensor::synthesize(const sensor_event_t& event) -{ - /* If the rotation vector sensor is available */ - if (m_fusion) { - synthesize_rv(event); - return; - } - - /* If both Acc & Gyro are available */ - if (m_gyro_sensor) { - synthesize_fusion(event); - return; - } - - /* If only Acc is available */ - synthesize_lowpass(event); -} - -void gravity_sensor::synthesize_rv(const sensor_event_t& event) -{ - if (!m_fusion->is_data_ready()) - return; - - sensor_event_t *gravity_event; - float gravity[3]; - float x, y, z, w, heading_accuracy; - int accuracy; - - if (!m_fusion->get_rotation_vector(x, y, z, w, heading_accuracy, accuracy)) { - _W("Failed to get rotation vector"); - return; - } - - unsigned long long timestamp = m_fusion->get_data_timestamp(); - - if (!check_sampling_time(timestamp)) - return; - - float rotation[4] = {x, y, z, w}; - - if (!rotation_to_gravity(rotation, gravity)) { - _D("Invalid rotation_vector: [%10f] [%10f] [%10f] [%10f]", x, y, z, w); - return; - } - - gravity_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!gravity_event) { - _E("Failed to allocate memory"); - return; - } - gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!gravity_event->data) { - _E("Failed to allocate memory"); - free(gravity_event); - return; - } - - gravity_event->sensor_id = get_id(); - gravity_event->event_type = GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME; - gravity_event->data_length = sizeof(sensor_data_t); - gravity_event->data->accuracy = accuracy; - gravity_event->data->timestamp = m_fusion->get_data_timestamp(); - gravity_event->data->value_count = 3; - gravity_event->data->values[0] = gravity[0]; - gravity_event->data->values[1] = gravity[1]; - gravity_event->data->values[2] = gravity[2]; - push(gravity_event); - - m_time = event.data->timestamp; - m_x = gravity[0]; - m_y = gravity[1]; - m_z = gravity[2]; - m_accuracy = accuracy; -} - -void gravity_sensor::synthesize_lowpass(const sensor_event_t& event) -{ - if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) - return; - - sensor_event_t *gravity_event; - float x, y, z, norm, alpha, tau, err; - - norm = NORM(event.data->values[0], event.data->values[1], event.data->values[2]); - x = event.data->values[0] / norm * GRAVITY; - y = event.data->values[1] / norm * GRAVITY; - z = event.data->values[2] / norm * GRAVITY; - - if (m_time > 0) { - err = fabs(norm - GRAVITY) / GRAVITY; - tau = (err < 0.1 ? TAU_LOW : err > 0.9 ? TAU_HIGH : TAU_MID); - alpha = tau / (tau + (float)(event.data->timestamp - m_time) / US_PER_SEC); - x = alpha * m_x + (1 - alpha) * x; - y = alpha * m_y + (1 - alpha) * y; - z = alpha * m_z + (1 - alpha) * z; - norm = NORM(x, y, z); - x = x / norm * GRAVITY; - y = y / norm * GRAVITY; - z = z / norm * GRAVITY; - } - - gravity_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!gravity_event) { - _E("Failed to allocate memory"); - return; - } - gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!gravity_event->data) { - _E("Failed to allocate memory"); - free(gravity_event); - return; - } - - gravity_event->sensor_id = get_id(); - gravity_event->event_type = GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME; - gravity_event->data_length = sizeof(sensor_data_t); - gravity_event->data->accuracy = event.data->accuracy; - gravity_event->data->timestamp = event.data->timestamp; - gravity_event->data->value_count = 3; - gravity_event->data->values[0] = x; - gravity_event->data->values[1] = y; - gravity_event->data->values[2] = z; - push(gravity_event); - - m_time = event.data->timestamp; - m_x = x; - m_y = y; - m_z = z; - m_accuracy = event.data->accuracy; -} - -void gravity_sensor::synthesize_fusion(const sensor_event_t& event) -{ - sensor_event_t *gravity_event; - - if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) { - fusion_set_accel(event); - m_fusion_phase |= PHASE_ACCEL_READY; - } else if (event.event_type == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) { - fusion_set_gyro(event); - m_fusion_phase |= PHASE_GYRO_READY; - } - - if (m_fusion_phase != PHASE_FUSION_READY) - return; - - m_fusion_phase = 0; - - fusion_update_angle(); - fusion_get_gravity(); - - gravity_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!gravity_event) { - _E("Failed to allocate memory"); - return; - } - gravity_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!gravity_event->data) { - _E("Failed to allocate memory"); - free(gravity_event); - return; - } - - gravity_event->sensor_id = get_id(); - gravity_event->event_type = GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME; - gravity_event->data_length = sizeof(sensor_data_t); - gravity_event->data->accuracy = m_accuracy; - gravity_event->data->timestamp = m_time; - gravity_event->data->value_count = 3; - gravity_event->data->values[0] = m_x; - gravity_event->data->values[1] = m_y; - gravity_event->data->values[2] = m_z; - push(gravity_event); -} - -void gravity_sensor::fusion_set_accel(const sensor_event_t& event) -{ - double x = event.data->values[0]; - double y = event.data->values[1]; - double z = event.data->values[2]; - - m_accel_mag = NORM(x, y, z); - - m_angle_n[0] = ARCTAN(z, y); - m_angle_n[1] = ARCTAN(x, z); - m_angle_n[2] = ARCTAN(y, x); - - m_accuracy = event.data->accuracy; - m_time_new = event.data->timestamp; - - _D("AccIn: (%f, %f, %f)", x/m_accel_mag, y/m_accel_mag, z/m_accel_mag); -} - -void gravity_sensor::fusion_set_gyro(const sensor_event_t& event) -{ - m_velocity[0] = -DEG2RAD(event.data->values[0]); - m_velocity[1] = -DEG2RAD(event.data->values[1]); - m_velocity[2] = -DEG2RAD(event.data->values[2]); - - m_time_new = event.data->timestamp; -} - -void gravity_sensor::fusion_update_angle(void) -{ - _D("AngleIn: (%f, %f, %f)", m_angle_n[0], m_angle_n[1], m_angle_n[2]); - _D("AngAccl: (%f, %f, %f)", m_velocity[0], m_velocity[1], m_velocity[2]); - _D("Angle : (%f, %f, %f)", m_angle[0], m_angle[1], m_angle[2]); - - if (m_angle[0] == INV_ANGLE) { - /* 1st iteration */ - m_angle[0] = m_angle_n[0]; - m_angle[1] = m_angle_n[1]; - m_angle[2] = m_angle_n[2]; - } else { - complementary(m_time_new - m_time); - } - - _D("Angle' : (%f, %f, %f)", m_angle[0], m_angle[1], m_angle[2]); -} - -void gravity_sensor::fusion_get_gravity(void) -{ - double x = 0, y = 0, z = 0; - double norm; - double vec[3][3]; - - /* Rotating along y-axis then z-axis */ - vec[0][2] = cos(m_angle[1]); - vec[0][0] = sin(m_angle[1]); - vec[0][1] = vec[0][0] * tan(m_angle[2]); - - /* Rotating along z-axis then x-axis */ - vec[1][0] = cos(m_angle[2]); - vec[1][1] = sin(m_angle[2]); - vec[1][2] = vec[1][1] * tan(m_angle[0]); - - /* Rotating along x-axis then y-axis */ - vec[2][1] = cos(m_angle[0]); - vec[2][2] = sin(m_angle[0]); - vec[2][0] = vec[2][2] * tan(m_angle[1]); - - /* Normalize */ - for (int i = 0; i < 3; ++i) { - norm = NORM(vec[i][0], vec[i][1], vec[i][2]); - vec[i][0] /= norm; - vec[i][1] /= norm; - vec[i][2] /= norm; - x += vec[i][0]; - y += vec[i][1]; - z += vec[i][2]; - } - - norm = NORM(x, y, z); - - m_x = x / norm * GRAVITY; - m_y = y / norm * GRAVITY; - m_z = z / norm * GRAVITY; - m_time = m_time_new; -} - -void gravity_sensor::complementary(unsigned long long time_diff) -{ - double err = fabs(m_accel_mag - GRAVITY) / GRAVITY; - double tau = (err < 0.1 ? TAU_LOW : err > 0.9 ? TAU_HIGH : TAU_MID); - double delta_t = (double)time_diff/ US_PER_SEC; - double alpha = tau / (tau + delta_t); - - _D("mag, err, tau, dt, alpha = %f, %f, %f, %f, %f", m_accel_mag, err, tau, delta_t, alpha); - - m_angle[0] = complementary(m_angle[0], m_angle_n[0], m_velocity[0], delta_t, alpha); - m_angle[1] = complementary(m_angle[1], m_angle_n[1], m_velocity[1], delta_t, alpha); - m_angle[2] = complementary(m_angle[2], m_angle_n[2], m_velocity[2], delta_t, alpha); -} - -double gravity_sensor::complementary(double angle, double angle_in, double vel, double delta_t, double alpha) -{ - double s, c; - angle = angle + vel * delta_t; - s = alpha * sin(angle) + (1 - alpha) * sin(angle_in); - c = alpha * cos(angle) + (1 - alpha) * cos(angle_in); - return ARCTAN(s, c); -} - -int gravity_sensor::get_data(sensor_data_t **data, int *length) -{ - /* if It is batch sensor, remains can be 2+ */ - int remains = 1; - - sensor_data_t *sensor_data; - sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - - sensor_data->accuracy = m_accuracy; - sensor_data->timestamp = m_time; - sensor_data->value_count = 3; - sensor_data->values[0] = m_x; - sensor_data->values[1] = m_y; - sensor_data->values[2] = m_z; - - *data = sensor_data; - *length = sizeof(sensor_data_t); - - return --remains; -} - -bool gravity_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool gravity_sensor::set_wakeup(int wakeup) -{ - return false; -} - -bool gravity_sensor::on_start(void) -{ - if (m_fusion) - m_fusion->start(); - - if (m_accel_sensor) - m_accel_sensor->start(); - - if (m_gyro_sensor) - m_gyro_sensor->start(); - - m_time = 0; - m_fusion_phase = 0; - m_angle[0] = INV_ANGLE; - - return activate(); -} - -bool gravity_sensor::on_stop(void) -{ - if (m_fusion) - m_fusion->stop(); - - if (m_accel_sensor) - m_accel_sensor->stop(); - - if (m_gyro_sensor) - m_gyro_sensor->stop(); - - m_time = 0; - - return deactivate(); -} - -bool gravity_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - if (m_fusion) - m_fusion->set_interval(FUSION_EVENT_AGM, client_id, interval); - - if (m_accel_sensor) - m_accel_sensor->add_interval(client_id, interval, true); - - if (m_gyro_sensor) - m_gyro_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool gravity_sensor::delete_interval(int client_id, bool is_processor) -{ - if (m_fusion) - m_fusion->unset_interval(FUSION_EVENT_AGM, client_id); - - if (m_accel_sensor) - m_accel_sensor->delete_interval(client_id, true); - - if (m_gyro_sensor) - m_gyro_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); -} - -bool gravity_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool gravity_sensor::rotation_to_gravity(const float *rotation, float *gravity) -{ - float R[9]; - - if (quat_to_matrix(rotation, R) < 0) - return false; - - gravity[0] = R[6] * GRAVITY; - gravity[1] = R[7] * GRAVITY; - gravity[2] = R[8] * GRAVITY; - - return true; -} - -bool gravity_sensor::check_sampling_time(unsigned long long timestamp) -{ - const float MIN_DELIVERY_DIFF_FACTOR = 0.75f; - const int MS_TO_US = 1000; - long long diff_time; - - diff_time = timestamp - m_time; - - if (m_time && (diff_time < m_interval * MS_TO_US * MIN_DELIVERY_DIFF_FACTOR)) - return false; - - return true; -} diff --git a/src/sensor/gravity/gravity_sensor.h b/src/sensor/gravity/gravity_sensor.h deleted file mode 100644 index 093465c..0000000 --- a/src/sensor/gravity/gravity_sensor.h +++ /dev/null @@ -1,90 +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 _GRAVITY_SENSOR_H_ -#define _GRAVITY_SENSOR_H_ - -#include -#include -#include - -class gravity_sensor : public virtual_sensor { -public: - gravity_sensor(); - virtual ~gravity_sensor(); - - /* initialize sensor */ - bool init(void); - - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); - - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); -private: - sensor_fusion *m_fusion; - sensor_base *m_accel_sensor; - sensor_base *m_gyro_sensor; - - int m_fusion_phase; - float m_x; - float m_y; - float m_z; - int m_accuracy; - unsigned long long m_time; - unsigned long m_interval; - - double m_angle[3]; - double m_angle_n[3]; - double m_accel_mag; - double m_velocity[3]; - unsigned long long m_time_new; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - virtual bool set_wakeup(int wakeup); - - virtual bool on_start(void); - virtual bool on_stop(void); - - bool rotation_to_gravity(const float *rotation, float *gravity); - bool check_sampling_time(unsigned long long timestamp); - - void synthesize_rv(const sensor_event_t& event); - void synthesize_lowpass(const sensor_event_t& event); - void synthesize_fusion(const sensor_event_t& event); - - void fusion_set_accel(const sensor_event_t& event); - void fusion_set_gyro(const sensor_event_t& event); - void fusion_update_angle(void); - void fusion_get_gravity(void); - double complementary(double angle, double angle_in, double vel, double delta_t, double alpha); - void complementary(unsigned long long time_diff); -}; - -#endif /* _GRAVITY_SENSOR_H_ */ -- 2.7.4 From 3caddf17643beced5c54a6991eb5a8e071943d38 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:22:10 +0900 Subject: [PATCH 10/16] sensord: enable linear acceleration sensor Change-Id: I6cd5d9ae2606e5544f2fdde2830ee33392d5e81a Signed-off-by: kibak.yoon --- src/sensor/CMakeLists.txt | 2 +- src/sensor/linear_accel/linear_accel_sensor.cpp | 220 ++++++------------------ src/sensor/linear_accel/linear_accel_sensor.h | 42 ++--- 3 files changed, 61 insertions(+), 203 deletions(-) diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt index edd1357..227698b 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/sensor/CMakeLists.txt @@ -4,7 +4,7 @@ INCLUDE(GNUInstallDirs) SET(AUTO_ROTATION "ON") SET(GRAVITY "ON") -SET(LINEAR_ACCEL "OFF") +SET(LINEAR_ACCEL "ON") INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/shared diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index 56af7b6..e46f74a 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -1,7 +1,7 @@ /* * sensord * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,32 +17,44 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include +#include "linear_accel_sensor.h" #include #include - -#include -#include -#include -#include #include -#define SENSOR_NAME "SENSOR_LINEAR_ACCELERATION" +#define NAME_SENSOR "http://tizen.org/sensor/linear_accel/linear_accel" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +#define SRC_ID_GRAVITY 0x2 +#define SRC_STR_GRAVITY "http://tizen.org/sensor/gravity" #define GRAVITY 9.80665 +static sensor_info2_t sensor_info = { + id: 0x1, + type: LINEAR_ACCEL_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: -19.6, + max_range: 19.6, + resolution: 0.01, + min_interval: 5, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC}, + {SRC_ID_GRAVITY, SRC_STR_GRAVITY}, +}; + linear_accel_sensor::linear_accel_sensor() -: m_accel_sensor(NULL) -, m_gravity_sensor(NULL) -, m_x(0) +: m_x(0) , m_y(0) , m_z(0) , m_gx(0) @@ -55,111 +67,41 @@ linear_accel_sensor::linear_accel_sensor() linear_accel_sensor::~linear_accel_sensor() { - _I("linear_accel_sensor is destroyed!\n"); -} - -bool linear_accel_sensor::init(void) -{ - m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); - - if (!m_accel_sensor) { - _W("cannot load accelerometer sensor_hal[%s]", get_name()); - return false; - } - - m_gravity_sensor = sensor_loader::get_instance().get_sensor(GRAVITY_SENSOR); - - if (!m_gravity_sensor) { - _W("cannot load gravity sensor_hal[%s]", get_name()); - return false; - } - - _I("%s is created!\n", get_name()); - - return true; -} - -sensor_type_t linear_accel_sensor::get_type(void) -{ - return LINEAR_ACCEL_SENSOR; } -unsigned int linear_accel_sensor::get_event_type(void) +int linear_accel_sensor::get_sensor_info(const sensor_info2_t **info) { - return LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME; + *info = &sensor_info; + return OP_SUCCESS; } -const char* linear_accel_sensor::get_name(void) +int linear_accel_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 2; } -bool linear_accel_sensor::get_sensor_info(sensor_info &info) +int linear_accel_sensor::update(uint32_t id, sensor_data_t *data, int len) { - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); // FIXME - info.set_name("Linear Accelerometer Sensor"); - info.set_vendor("Samsung Electronics"); - info.set_min_range(-19.6); - info.set_max_range(19.6); - info.set_resolution(0.01); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} + if (id == SRC_ID_GRAVITY) { + m_gx = data->values[0]; + m_gy = data->values[1]; + m_gz = data->values[2]; + } else if (id == SRC_ID_ACC) { + m_accuracy = data->accuracy; + m_time = data->timestamp; + m_x = data->values[0] - m_gx; + m_y = data->values[1] - m_gy; + m_z = data->values[2] - m_gz; -void linear_accel_sensor::synthesize(const sensor_event_t& event) -{ - if (event.event_type == GRAVITY_EVENT_RAW_DATA_REPORT_ON_TIME) { - m_gx = event.data->values[0]; - m_gy = event.data->values[1]; - m_gz = event.data->values[2]; - return; + return OP_SUCCESS; } - if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) { - m_time = event.data->timestamp; - m_x = event.data->values[0] - m_gx; - m_y = event.data->values[1] - m_gy; - m_z = event.data->values[2] - m_gz; - - sensor_event_t *linear_accel_event; - sensor_data_t *linear_accel_data; - int data_length; - int remains; - - linear_accel_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!linear_accel_event) { - _E("Failed to allocate memory"); - return; - } - - remains = get_data(&linear_accel_data, &data_length); - - if (remains < 0) { - free(linear_accel_event); - return; - } - - linear_accel_event->sensor_id = get_id(); - linear_accel_event->event_type = LINEAR_ACCEL_EVENT_RAW_DATA_REPORT_ON_TIME; - linear_accel_event->data_length = data_length; - linear_accel_event->data = linear_accel_data; - - push(linear_accel_event); - } + return OP_ERROR; /* skip */ } int linear_accel_sensor::get_data(sensor_data_t **data, int *length) { - /* if It is batch sensor, remains can be 2+ */ - int remains = 1; - sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); @@ -173,67 +115,5 @@ int linear_accel_sensor::get_data(sensor_data_t **data, int *length) *data = sensor_data; *length = sizeof(sensor_data_t); - return --remains; -} - -bool linear_accel_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - if (m_accel_sensor) - m_accel_sensor->add_interval(client_id, interval, true); - - if (m_gravity_sensor) - m_gravity_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool linear_accel_sensor::delete_interval(int client_id, bool is_processor) -{ - if (m_accel_sensor) - m_accel_sensor->delete_interval(client_id, true); - - if (m_gravity_sensor) - m_gravity_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); -} - -bool linear_accel_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool linear_accel_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool linear_accel_sensor::set_wakeup(int wakeup) -{ - return false; -} - -bool linear_accel_sensor::on_start(void) -{ - if (m_accel_sensor) - m_accel_sensor->start(); - - if (m_gravity_sensor) - m_gravity_sensor->start(); - - m_time = 0; - return activate(); -} - -bool linear_accel_sensor::on_stop(void) -{ - if (m_accel_sensor) - m_accel_sensor->stop(); - - if (m_gravity_sensor) - m_gravity_sensor->stop(); - - m_time = 0; - return deactivate(); + return 0; } diff --git a/src/sensor/linear_accel/linear_accel_sensor.h b/src/sensor/linear_accel/linear_accel_sensor.h index 1c2be40..1411907 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.h +++ b/src/sensor/linear_accel/linear_accel_sensor.h @@ -1,7 +1,7 @@ /* * sensord * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,38 +17,24 @@ * */ -#ifndef _LINEAR_ACCEL_SENSOR_H_ -#define _LINEAR_ACCEL_SENSOR_H_ +#ifndef __LINEAR_ACCEL_SENSOR_H__ +#define __LINEAR_ACCEL_SENSOR_H__ -#include +#include #include -class linear_accel_sensor : public virtual_sensor { +class linear_accel_sensor : public fusion_sensor { public: linear_accel_sensor(); virtual ~linear_accel_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_accel_sensor; - sensor_base *m_gravity_sensor; - float m_x; float m_y; float m_z; @@ -57,14 +43,6 @@ private: float m_gz; int m_accuracy; unsigned long long m_time; - unsigned long m_interval; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - virtual bool set_wakeup(int wakeup); - - virtual bool on_start(void); - virtual bool on_stop(void); }; -#endif +#endif /* __LINEAR_ACCEL_SENSOR_H__ */ -- 2.7.4 From bc2cc24c19467155c0d73ac6e4e0051e85898304 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:24:49 +0900 Subject: [PATCH 11/16] sensord: remove unnecessary testcases for fusion library Change-Id: Iaf95f379ccf05cfa2c8f001d1976804d50ad7b10 Signed-off-by: kibak.yoon --- src/sensor/rotation_vector/test/gravity_sensor.cpp | 40 ----- src/sensor/rotation_vector/test/gravity_sensor.h | 36 ---- .../test/linear_acceleration_sensor.cpp | 39 ---- .../test/linear_acceleration_sensor.h | 36 ---- .../rotation_vector/test/orientation_sensor.cpp | 53 ------ .../rotation_vector/test/orientation_sensor.h | 36 ---- .../euler_angles_test/euler_angles_main.cpp | 78 -------- .../gravity_sensor_test/gravity_sensor_main.cpp | 91 ---------- .../linear_acceleration_sensor_main.cpp | 91 ---------- .../test/test_projects/matrix_test/matrix_main.cpp | 154 ---------------- .../orientation_sensor_main.cpp | 121 ------------- .../quaternion_test/quaternion_main.cpp | 77 -------- .../rotation_matrix_test/rotation_matrix_main.cpp | 62 ------- .../sensor_data_test/sensor_data_main.cpp | 69 -------- .../test/test_projects/vector_test/vector_main.cpp | 196 --------------------- 15 files changed, 1179 deletions(-) delete mode 100644 src/sensor/rotation_vector/test/gravity_sensor.cpp delete mode 100644 src/sensor/rotation_vector/test/gravity_sensor.h delete mode 100644 src/sensor/rotation_vector/test/linear_acceleration_sensor.cpp delete mode 100644 src/sensor/rotation_vector/test/linear_acceleration_sensor.h delete mode 100644 src/sensor/rotation_vector/test/orientation_sensor.cpp delete mode 100644 src/sensor/rotation_vector/test/orientation_sensor.h delete mode 100644 src/sensor/rotation_vector/test/test_projects/euler_angles_test/euler_angles_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/gravity_sensor_test/gravity_sensor_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/linear_acceleration_sensor_test/linear_acceleration_sensor_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/matrix_test/matrix_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/orientation_sensor_test/orientation_sensor_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/quaternion_test/quaternion_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/rotation_matrix_test/rotation_matrix_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/sensor_data_test/sensor_data_main.cpp delete mode 100644 src/sensor/rotation_vector/test/test_projects/vector_test/vector_main.cpp diff --git a/src/sensor/rotation_vector/test/gravity_sensor.cpp b/src/sensor/rotation_vector/test/gravity_sensor.cpp deleted file mode 100644 index 94a82e7..0000000 --- a/src/sensor/rotation_vector/test/gravity_sensor.cpp +++ /dev/null @@ -1,40 +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. - * - */ - -#ifdef _GRAVITY_SENSOR_H_ - -#define GRAVITY 9.80665 - -sensor_data gravity_sensor::get_gravity(const sensor_data accel, - const sensor_data gyro, const sensor_data magnetic) -{ - euler_angles orientation; - sensor_data gravity; - - orientation = orien_sensor.get_orientation(accel, gyro, magnetic); - - gravity.m_data.m_vec[0] = GRAVITY * sin(orientation.m_ang.m_vec[0]); - gravity.m_data.m_vec[1] = GRAVITY * sin(orientation.m_ang.m_vec[1]); - gravity.m_data.m_vec[2] = GRAVITY * cos(orientation.m_ang.m_vec[0]) * - cos(orientation.m_ang.m_vec[1]); - - return gravity; -} - -#endif diff --git a/src/sensor/rotation_vector/test/gravity_sensor.h b/src/sensor/rotation_vector/test/gravity_sensor.h deleted file mode 100644 index 7d3fa6c..0000000 --- a/src/sensor/rotation_vector/test/gravity_sensor.h +++ /dev/null @@ -1,36 +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 _GRAVITY_SENSOR_H_ -#define _GRAVITY_SENSOR_H_ - -#include "orientation_sensor.h" - -class gravity_sensor -{ -public: - orientation_sensor orien_sensor; - - sensor_data get_gravity(const sensor_data accel, - const sensor_data gyro, const sensor_data magnetic); -}; - -#include "gravity_sensor.cpp" - -#endif /* _GRAVITY_SENSOR_H_ */ diff --git a/src/sensor/rotation_vector/test/linear_acceleration_sensor.cpp b/src/sensor/rotation_vector/test/linear_acceleration_sensor.cpp deleted file mode 100644 index b38a2d1..0000000 --- a/src/sensor/rotation_vector/test/linear_acceleration_sensor.cpp +++ /dev/null @@ -1,39 +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. - * - */ - -#ifdef _LINEAR_ACCELERATION_SENSOR_H_ - -sensor_data linear_acceleration_sensor::get_linear_acceleration(const sensor_data accel, - const sensor_data gyro, const sensor_data magnetic) -{ - sensor_data gravity_data; - float la_x, la_y, la_z; - - gravity_data = grav_sensor.get_gravity(accel, gyro, magnetic); - - la_x = accel.m_data.m_vec[0] - gravity_data.m_data.m_vec[1]; - la_y = accel.m_data.m_vec[1] - gravity_data.m_data.m_vec[0]; - la_z = accel.m_data.m_vec[2] - gravity_data.m_data.m_vec[2]; - - sensor_data lin_accel_data(la_x, la_y, la_z); - - return lin_accel_data; -} - -#endif diff --git a/src/sensor/rotation_vector/test/linear_acceleration_sensor.h b/src/sensor/rotation_vector/test/linear_acceleration_sensor.h deleted file mode 100644 index 1942f3b..0000000 --- a/src/sensor/rotation_vector/test/linear_acceleration_sensor.h +++ /dev/null @@ -1,36 +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 _LINEAR_ACCELERATION_SENSOR_H_ -#define _LINEAR_ACCELERATION_SENSOR_H_ - -#include "gravity_sensor.h" - -class linear_acceleration_sensor -{ -public: - gravity_sensor grav_sensor; - - sensor_data get_linear_acceleration(const sensor_data accel, - const sensor_data gyro, const sensor_data magnetic); -}; - -#include "linear_acceleration_sensor.cpp" - -#endif /* _LINEAR_ACCELERATION_SENSOR_H_ */ diff --git a/src/sensor/rotation_vector/test/orientation_sensor.cpp b/src/sensor/rotation_vector/test/orientation_sensor.cpp deleted file mode 100644 index 25099e2..0000000 --- a/src/sensor/rotation_vector/test/orientation_sensor.cpp +++ /dev/null @@ -1,53 +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. - * - */ - -#ifdef _ORIENTATION_SENSOR_H_ - -float bias_accel[] = {0.098586, 0.18385, (10.084 - GRAVITY)}; -float bias_gyro[] = {-5.3539, 0.24325, 2.3391}; -float bias_magnetic[] = {0, 0, 0}; -int sign_accel[] = {+1, +1, +1}; -int sign_gyro[] = {+1, +1, +1}; -int sign_magnetic[] = {+1, +1, +1}; -float scale_accel = 1; -float scale_gyro = 1150; -float scale_magnetic = 1; -int magnetic_alignment_factor = -1; - -void orientation_sensor::get_device_orientation(sensor_data *accel_data, - sensor_data *gyro_data, sensor_data *magnetic_data) -{ - vect vec_bias_gyro(bias_gyro); - - pre_process_data(accel_data, accel_data, bias_accel, sign_accel, scale_accel); - normalize(*accel_data); - - if (gyro_data != NULL) { - pre_process_data(gyro_data, gyro_data, bias_gyro, sign_gyro, scale_gyro); - } - - if (magnetic_data != NULL) { - pre_process_data(magnetic_data, magnetic_data, bias_magnetic, sign_magnetic, scale_magnetic); - normalize(*magnetic_data); - } - - orien_filter.get_device_orientation(accel_data, gyro_data, magnetic_data); -} - -#endif /* _ORIENTATION_SENSOR_H_ */ diff --git a/src/sensor/rotation_vector/test/orientation_sensor.h b/src/sensor/rotation_vector/test/orientation_sensor.h deleted file mode 100644 index c7aff2f..0000000 --- a/src/sensor/rotation_vector/test/orientation_sensor.h +++ /dev/null @@ -1,36 +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 _ORIENTATION_SENSOR_H_ -#define _ORIENTATION_SENSOR_H_ - -#include "../orientation_filter.h" - -class orientation_sensor -{ -public: - orientation_filter orien_filter; - - void get_device_orientation(sensor_data *accel, - sensor_data *gyro, sensor_data *magnetic); -}; - -#include "orientation_sensor.cpp" - -#endif /* _ORIENTATION_SENSOR_H_ */ diff --git a/src/sensor/rotation_vector/test/test_projects/euler_angles_test/euler_angles_main.cpp b/src/sensor/rotation_vector/test/test_projects/euler_angles_test/euler_angles_main.cpp deleted file mode 100644 index fc69bd5..0000000 --- a/src/sensor/rotation_vector/test/test_projects/euler_angles_test/euler_angles_main.cpp +++ /dev/null @@ -1,78 +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 "../../../euler_angles.h" - -int main() -{ - float arr0[3] = {234.98, 345.24, -56.12}; - float arr1[3] = {56, -34, 76}; - float arr2[4] = {0.6, 0.6, -.18, -.44}; - float arr3[4] = {-0.5, -0.36, .43, .03}; - - vect v0(arr0); - vect v1(arr1); - vect v2(arr2); - vect v3(arr3); - - quaternion q1(v2); - quaternion q2(v3); - - euler_angles e0(v0); - euler_angles e1(v1); - euler_angles e2((float)234.98, (float)345.24, (float)-56.12); - euler_angles e3(e1); - euler_angles e4; - - cout << "Constructor tests\n"; - cout << "input\t" << v0 << "\n"; - cout << "output\t" << e0.m_ang << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << e1.m_ang << "\n\n"; - cout << "input\t" << v0 << "\n"; - cout << "output\t" << e2.m_ang << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << e3.m_ang << "\n\n"; - cout << "default constructor\n"; - cout << "output\t" << e4.m_ang << "\n\n"; - - cout << "Quaternion to Euler\n"; - euler_angles e5 = quat2euler(q1); - cout << "input\t" << q1.m_quat << "\n"; - cout << "output\t" << e5.m_ang << "\n\n"; - euler_angles e8 = quat2euler(q2); - cout << "input\t" << q2.m_quat << "\n"; - cout << "output\t" << e8.m_ang << "\n\n"; - - cout << "Euler to Quaternion\n"; - quaternion q3 = euler2quat(e8); - cout << "input\t" << e8.m_ang << "\n"; - cout << "output\t" << q3.m_quat << "\n\n"; - - cout << "Radians to Degrees\n"; - euler_angles e6 = deg2rad(e0); - cout << "input\t" << e0.m_ang << "\n"; - cout << "output\t" << e6.m_ang << "\n\n"; - - cout << "Degrees to Radians\n"; - euler_angles e7 = rad2deg(e6); - cout << "input\t" << e6.m_ang << "\n"; - cout << "output\t" << e7.m_ang << "\n\n"; -} - diff --git a/src/sensor/rotation_vector/test/test_projects/gravity_sensor_test/gravity_sensor_main.cpp b/src/sensor/rotation_vector/test/test_projects/gravity_sensor_test/gravity_sensor_main.cpp deleted file mode 100644 index 3525c32..0000000 --- a/src/sensor/rotation_vector/test/test_projects/gravity_sensor_test/gravity_sensor_main.cpp +++ /dev/null @@ -1,91 +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 "../../gravity_sensor.h" -#include -#include -#include -#include -using namespace std; - -#define GRAVITY_DATA_PATH "../../../design/data/100ms/gravity/throw/" -#define GRAVITY_DATA_SIZE 135 - -int main() -{ - int data_available = GRAVITY_DATA_SIZE; - ifstream accel_in, gyro_in, mag_in; - ofstream gravity_file; - string line_accel, line_gyro, line_magnetic; - float sdata[3]; - unsigned long long time_stamp; - sensor_data gravity; - gravity_sensor grav_sensor; - - accel_in.open(((string)GRAVITY_DATA_PATH + (string)"accel.txt").c_str()); - gyro_in.open(((string)GRAVITY_DATA_PATH + (string)"gyro.txt").c_str()); - mag_in.open(((string)GRAVITY_DATA_PATH + (string)"magnetic.txt").c_str()); - - gravity_file.open(((string)"gravity.txt").c_str()); - - char *token = NULL; - - while (data_available-- > 0) - { - getline(accel_in, line_accel); - sdata[0] = strtof(line_accel.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data accel_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n"; - - getline(gyro_in, line_gyro); - sdata[0] = strtof(line_gyro.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data gyro_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n"; - - getline(mag_in, line_magnetic); - sdata[0] = strtof(line_magnetic.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n"; - - gravity = grav_sensor.get_gravity(accel_data, gyro_data, magnetic_data); - - gravity_file << gravity.m_data; - - cout << "Gravity Data\t" << gravity.m_data << "\n\n"; - } - - accel_in.close(); - gyro_in.close(); - mag_in.close(); - gravity_file.close(); - - return 0; -} diff --git a/src/sensor/rotation_vector/test/test_projects/linear_acceleration_sensor_test/linear_acceleration_sensor_main.cpp b/src/sensor/rotation_vector/test/test_projects/linear_acceleration_sensor_test/linear_acceleration_sensor_main.cpp deleted file mode 100644 index 958559a..0000000 --- a/src/sensor/rotation_vector/test/test_projects/linear_acceleration_sensor_test/linear_acceleration_sensor_main.cpp +++ /dev/null @@ -1,91 +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 "../../linear_acceleration_sensor.h" -#include -#include -#include -#include -using namespace std; - -#define LA_DATA_PATH "../../../design/data/100ms/linear_acceleration/move_x_y_z/" -#define LA_DATA_SIZE 170 - -int main() -{ - int data_available = LA_DATA_SIZE; - ifstream accel_in, gyro_in, mag_in; - ofstream la_file; - string line_accel, line_gyro, line_magnetic; - float sdata[3]; - unsigned long long time_stamp; - sensor_data lin_accel; - linear_acceleration_sensor la_sensor; - - accel_in.open(((string)LA_DATA_PATH + (string)"accel.txt").c_str()); - gyro_in.open(((string)LA_DATA_PATH + (string)"gyro.txt").c_str()); - mag_in.open(((string)LA_DATA_PATH + (string)"magnetic.txt").c_str()); - - la_file.open(((string)"linear_acceleration.txt").c_str()); - - char *token = NULL; - - while (data_available-- > 0) - { - getline(accel_in, line_accel); - sdata[0] = strtof(line_accel.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data accel_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n"; - - getline(gyro_in, line_gyro); - sdata[0] = strtof(line_gyro.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data gyro_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n"; - - getline(mag_in, line_magnetic); - sdata[0] = strtof(line_magnetic.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n"; - - lin_accel = la_sensor.get_linear_acceleration(accel_data, gyro_data, magnetic_data); - - la_file << lin_accel.m_data; - - cout << "Linear Acceleration Data\t" << lin_accel.m_data << "\n\n"; - } - - accel_in.close(); - gyro_in.close(); - mag_in.close(); - la_file.close(); - - return 0; -} diff --git a/src/sensor/rotation_vector/test/test_projects/matrix_test/matrix_main.cpp b/src/sensor/rotation_vector/test/test_projects/matrix_test/matrix_main.cpp deleted file mode 100644 index 05b1743..0000000 --- a/src/sensor/rotation_vector/test/test_projects/matrix_test/matrix_main.cpp +++ /dev/null @@ -1,154 +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 "../../../matrix.h" - -int main() -{ - float arr0[2][2] = {{-2.243, 2.57}, {3.56, -3.02}}; - float arr1[2][2] = {{2.2, 2.5}, {3.5, 3.0}}; - float arr5[3][2] = {{0.22, 4.56}, {3.652, 5.86}, {1.430, 0.45}}; - float arr11[1][3] = {{2.0, 3.0, 4.0}}; - float arr12[3][1] = {{2.0}, {1.0}, {3.0}}; - float arr15[2][3] = {{20.0, -40.0, 10.0}, {36.0, 52.0, -55.0}}; - float arr3[3][3] = {{20.2, 40.5, 10.0}, {3.6, 52.0, 5.5}, {1.0, 45.5, 66.6}}; - float arr4[3][3] = {{2.24, 0.5, 0.023}, {3.675, 5.32, 0.556}, {1.023, 45.75, 621.6}}; - float arr8[3][3] = {{4.75, 0.65, 0.123}, {0.075, 5.302, 0.56}, {1.113, 0.475, 2.362}}; - float arr9[3][3] = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}}; - - matrix m1(arr0); - matrix m2(arr1); - matrix m3; - matrix m10(arr3); - matrix m11(arr5); - matrix m6; - matrix m13; - matrix m12(arr4); - matrix m15(arr8); - matrix m20(arr11); - matrix m21(arr12); - matrix m22(arr15); - matrix m9(arr9); - - cout << "Constructor Test\n"; - cout << "\n" << m6; - - cout << "\n\nAddition\n"; - m6 = m10 + m15; - m13 = m11 + m11; - cout << "\n" << m10 << "\n" << m15; - cout << "\nSum:\n" << m6 << endl; - cout << "\n" << m11 << "\n" << m11; - cout << "\nSum:\n" << m13 << endl; - - cout << "\n\n\nSubtraction\n"; - m6 = m10 - m12; - cout << "\n" << m10 << "\n" << m12; - cout << "\nDifference:\n" << m6 << endl; - - cout << "\n\n\nMultiplication\n"; - m6 = m10 * m12; - m3 = m1 * m2; - matrix m7; - m7 = m20 * m21; - cout << "\n" << m10 << "\n" << m12; - cout << "\nProduct:\n" << m6 << endl; - cout << "\n" << m1 << "\n" << m2; - cout << "\nProduct:\n" << m3 << endl; - cout << "\n" << m20 << "\n" << m21; - cout << "\nProduct:\n" << m7 << endl; - cout << "\n" << m9 << "\n" << m21; - m21 = m9 * m21; - cout << "\nProduct:\n" << m21 << endl; - - cout << "\n\n\nDivision\n"; - m3 = m1 / (float)2.5; - cout << "\n" << m1 << "\n" << "2.5"; - cout << "\nResult:\n" << m3 << endl; - m6 = m12 / (float)0.125; - cout << "\n" << m12 << "\n" << ".125"; - cout << "\nResult:\n" << m6 << endl; - - float num = 5.5650; - float num1 = -2.32; - cout << "\n\n\nScalar addition\n"; - m3 = m2 + num; - m6 = m10 + num1; - cout << "\nNumber added:" << num; - cout << "\n\n" << m2; - cout << "\nResult:\n\n" << m3; - cout << "\nNumber added:" << num1; - cout << "\n\n" << m10; - cout << "\nResult:\n\n" << m6; - - float x = 4.0; - float x1 = -2.5; - cout << "\n\n\nScalar subtraction\n"; - m13 = m11 - x; - m6 = m10 - x1; - cout << "\nNumber Subtracted:" << x; - cout << "\n\n" << m11; - cout << "\nResult:\n\n" << m13; - cout << "\nNumber Subtracted:" << x1; - cout << "\n\n" << m10; - cout << "\nResult:\n\n" << m6; - - float z = 3.50; - float z1 = -5.567; - cout << "\n\n\nScalar multiplication\n"; - m3 = m1 * z; - m6 = m12 * z1; - cout << "\nNumber Multiplied:" << z; - cout << "\n\n" << m1; - cout << "\nResult:\n\n" << m3; - cout << "\nNumber Multiplied:" << z1; - cout << "\n\n" << m12; - cout << "\nResult:\n\n" << m6; - - m6 = tran(m15); - cout << "\n\n\nTranspose:"; - cout << "\n\n" << m15; - cout << "\nResult:\n\n" << m6; - - cout << "\n\nm1:\n\n" << m1; - cout << "\n\nm2:\n\n" << m2; - cout << "\n\n\nm1 == m2 :"; - cout << (m1 == m2); - - cout << "\n\nm2:\n\n" << m2; - cout << "\n\nm2:\n\n" << m2; - cout << "\n\n\nm2 == m2 :"; - cout << (m2 == m2); - - cout << "\n\nm6:\n\n" << m6; - cout << "\n\nm6:\n\n" << m6; - cout << "\n\n\nm6 != m6 :"; - cout << (m6 != m6); - - cout << "\n\nm6:\n\n" << m6; - cout << "\n\nm1:\n\n" << m1; - cout << "\n\n\nm6 != m1 :"; - cout << (m6 != m1); - - - cout << "\n\nAssignment\n"; - matrix m30 = m12; - cout << "Input \n" << m12; - cout << "\nOutput:\n" << m30 << endl; -} diff --git a/src/sensor/rotation_vector/test/test_projects/orientation_sensor_test/orientation_sensor_main.cpp b/src/sensor/rotation_vector/test/test_projects/orientation_sensor_test/orientation_sensor_main.cpp deleted file mode 100644 index d0a41fd..0000000 --- a/src/sensor/rotation_vector/test/test_projects/orientation_sensor_test/orientation_sensor_main.cpp +++ /dev/null @@ -1,121 +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 "../../orientation_sensor.h" -#include -#include -#include -#include -using namespace std; - -#define ORIENTATION_DATA_PATH "../../../design/data/100ms/orientation/roll_pitch_yaw/" -#define ORIENTATION_DATA_SIZE 1095 -int pitch_phase_compensation = -1; -int roll_phase_compensation = -1; -int azimuth_phase_compensation = -1; - -int main() -{ - int data_available = ORIENTATION_DATA_SIZE; - ifstream accel_in, gyro_in, mag_in; - ofstream orien_file; - string line_accel, line_gyro, line_magnetic; - float sdata[3]; - unsigned long long time_stamp; - euler_angles orientation; - rotation_matrix orientation_mat; - quaternion orientation_9axis_quat; - quaternion orientation_geomagnetic_quat; - quaternion orientation_gaming_quat; - orientation_sensor orien_sensor; - - accel_in.open(((string)ORIENTATION_DATA_PATH + (string)"accel.txt").c_str()); - gyro_in.open(((string)ORIENTATION_DATA_PATH + (string)"gyro.txt").c_str()); - mag_in.open(((string)ORIENTATION_DATA_PATH + (string)"magnetic.txt").c_str()); - - orien_file.open(((string)"orientation.txt").c_str()); - - char *token = NULL; - - while (data_available-- > 0) - { - getline(accel_in, line_accel); - sdata[0] = strtof(line_accel.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data accel_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Accel Data\t" << accel_data.m_data << "\t Time Stamp\t" << accel_data.m_time_stamp << "\n\n"; - - getline(gyro_in, line_gyro); - sdata[0] = strtof(line_gyro.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data gyro_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Gyro Data\t" << gyro_data.m_data << "\t Time Stamp\t" << gyro_data.m_time_stamp << "\n\n"; - - getline(mag_in, line_magnetic); - sdata[0] = strtof(line_magnetic.c_str(), &token); - sdata[1] = strtof(token, &token); - sdata[2] = strtof(token, &token); - time_stamp = strtoull(token, NULL, 10); - sensor_data magnetic_data(sdata[0], sdata[1], sdata[2], time_stamp); - - cout << "Magnetic Data\t" << magnetic_data.m_data << "\t Time Stamp\t" << magnetic_data.m_time_stamp << "\n\n"; - - orien_sensor.get_device_orientation(&accel_data, &gyro_data, &magnetic_data); - - orientation = orien_sensor.orien_filter.m_orientation; - - cout << "Gyro Bias in radians\t" << orien_sensor.orien_filter.m_gyro_bias; - - orientation = rad2deg(orientation); - - orientation.m_ang.m_vec[0] *= pitch_phase_compensation; - orientation.m_ang.m_vec[1] *= roll_phase_compensation; - orientation.m_ang.m_vec[2] *= azimuth_phase_compensation; - - if (orientation.m_ang.m_vec[2] < 0) - orientation.m_ang.m_vec[2] += 360; - - orien_file << orientation.m_ang; - - orientation = orien_sensor.orien_filter.m_orientation; - - cout << "Orientation angles\t" << orientation.m_ang << "\n\n"; - - cout << "Orientation matrix\t" << orien_sensor.orien_filter.m_rot_matrix.m_rot_mat << "\n\n"; - - cout << "Orientation 9-axis quaternion\t" << orien_sensor.orien_filter.m_quat_9axis.m_quat << "\n\n"; - - cout << "Orientation geomagnetic quaternion\t" << orien_sensor.orien_filter.m_quat_aid.m_quat << "\n\n"; - - cout << "Orientation gaming quaternion\t" << orien_sensor.orien_filter.m_quat_gaming_rv.m_quat << "\n\n"; - } - - accel_in.close(); - gyro_in.close(); - mag_in.close(); - orien_file.close(); - - return 0; -} diff --git a/src/sensor/rotation_vector/test/test_projects/quaternion_test/quaternion_main.cpp b/src/sensor/rotation_vector/test/test_projects/quaternion_test/quaternion_main.cpp deleted file mode 100644 index f437d6c..0000000 --- a/src/sensor/rotation_vector/test/test_projects/quaternion_test/quaternion_main.cpp +++ /dev/null @@ -1,77 +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 "../../../quaternion.h" - -int main() -{ - float arr0[4] = {2344.98, 345.24, 456.12, 98.33}; - float arr1[4] = {0.056, 0.34, -0.0076, 0.001}; - float axis1[3] = {6.5, 7.5, 8.3}; - float ang1 = 8.4; - - vect v0(arr0); - vect v1(arr1); - vect v2(axis1); - - quaternion q0(v0); - quaternion q1(v1); - quaternion q2((float)2344.98, (float)345.24, (float)456.12, (float)98.33); - quaternion q3(q1); - quaternion q4; - - cout << "Constructor tests\n"; - cout << "input\t" << v0 << "\n"; - cout << "output\t" << q0.m_quat << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << q1.m_quat << "\n\n"; - cout << "input\t" << v0 << "\n"; - cout << "output\t" << q2.m_quat << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << q3.m_quat << "\n\n"; - cout << "default constructor\n"; - cout << "output\t" << q4.m_quat << "\n\n"; - - cout << "Multiplication\n"; - float val = 0.1; - quaternion q5 = q0 * val; - cout << "input\t" << q0.m_quat << "\n" << 0.1 << "\n"; - cout << "output\t" << q5.m_quat << "\n\n"; - quaternion q6 = q0 * q1; - cout << "input\t" << q0.m_quat << "\n" << q1.m_quat << "\n"; - cout << "output\t" << q6.m_quat << "\n\n"; - - cout << "Addition\n"; - quaternion q7 = q0 + q1; - cout << "input\t" << q0.m_quat << "\n" << q1.m_quat << "\n"; - cout << "output\t" << q7.m_quat << "\n\n"; - - cout << "Quaternion Normalization\n"; - cout << "input\t" << q1.m_quat << "\n"; - q1.quat_normalize(); - cout << "output\t" << q1.m_quat << "\n\n"; - - cout << "Axis2quat\n"; - cout << "input\t" << " " << v2 << endl; - cout << endl; - quaternion q11 = axis2quat(v2, ang1); - cout << "output\t" << q11.m_quat << "\n\n"; - cout << endl; -} - diff --git a/src/sensor/rotation_vector/test/test_projects/rotation_matrix_test/rotation_matrix_main.cpp b/src/sensor/rotation_vector/test/test_projects/rotation_matrix_test/rotation_matrix_main.cpp deleted file mode 100644 index 9ab8c35..0000000 --- a/src/sensor/rotation_vector/test/test_projects/rotation_matrix_test/rotation_matrix_main.cpp +++ /dev/null @@ -1,62 +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 "../../../rotation_matrix.h" - -int main() -{ - float arr1[3][3] = {{20.2, 40.5, 10.0}, {3.6, 52.0, 5.5}, {1.0, 45.5, 66.6}}; - float arr2[3][3] = {{2.24, 0.5, 0.023}, {3.675, 5.32, 0.556}, {1.023, 45.75, 621.6}}; - float arr3[3][3] = {{4.75, 0.65, 0.123}, {0.075, 5.302, 0.56}, {1.113, 0.475, 2.362}}; - - matrix m1(arr1); - matrix m2(arr2); - matrix m3(arr3); - - rotation_matrix rm0, rm5; - rotation_matrix rm1(m1); - rotation_matrix rm2(m2); - rotation_matrix rm3(m3); - rotation_matrix rm4(arr1); - - quaternion q0(-0.612372, 0.456436, 0.456436, 0.456436); - quaternion q1; - - cout << "Constructor tests\n"; - cout << "input\n" << m1 << "\n"; - cout << "output\n" << rm1.m_rot_mat << "\n\n"; - cout << "input\n" << m2 << "\n"; - cout << "output\n" << rm2.m_rot_mat << "\n\n"; - cout << "input\n" << m3 << "\n"; - cout << "output\n" << rm3.m_rot_mat << "\n\n"; - cout << "input\n" << m1 << "\n"; - cout << "output\n" << rm4.m_rot_mat << "\n\n"; - cout << "default constructor\n"; - cout << "output\n" << rm0.m_rot_mat << "\n\n"; - - cout << "Quaternion to Rotation Matrix\n"; - cout << "input\n" << q0.m_quat << "\n"; - rm0 = quat2rot_mat(q0); - cout << "output\n" << rm0.m_rot_mat << "\n\n"; - - cout << "Rotation Matrix to Quaternion\n"; - cout << "input\n" << rm0.m_rot_mat << "\n"; - q1 = rot_mat2quat(rm0); - cout << "output\n" << q1.m_quat << "\n\n"; -} diff --git a/src/sensor/rotation_vector/test/test_projects/sensor_data_test/sensor_data_main.cpp b/src/sensor/rotation_vector/test/test_projects/sensor_data_test/sensor_data_main.cpp deleted file mode 100644 index 526bda4..0000000 --- a/src/sensor/rotation_vector/test/test_projects/sensor_data_test/sensor_data_main.cpp +++ /dev/null @@ -1,69 +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 "../../../sensor_data.h" - -int main() -{ - float arr1[3] = {1.04, -4.678, -2.34}; - float arr2[3] = {0, 0, 1}; - vect v1(arr1); - vect v2(arr2); - - sensor_data sd1(2.0, 3.0, 4.0, 140737488355328); - sensor_data sd2(1.04, -4.678, -2.34, 0); - sensor_data sd3(0.054, 1.097, 4.456, 140737488355328); - - sensor_data sd10(v1, 140737488355328); - sensor_data sd11(0.2, 0.1, 0.3, 140737488355328); - - cout << "Constructor tests\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << sd10.m_data << "\t" << sd10.m_time_stamp << "\n\n"; - cout << "input\t" << v1 << "\n"; - cout << "output\t" << sd2.m_data << "\t" << sd2.m_time_stamp << "\n\n"; - - cout << "Addition:\n"; - sensor_data sd4 = sd1 + sd2; - cout << "\n" << sd1.m_data << "\n" << sd2.m_data; - cout << "\nSum:\n" << sd4.m_data << endl; - sensor_data sd9 = sd1 + sd10; - cout << "\n" << sd1.m_data << "\n" << sd10.m_data; - cout << "\nSum:\n" << sd9.m_data << endl; - - cout << "\n\n\nNormalization:\n"; - cout << "\n" << sd3.m_data; - normalize(sd3); - cout << "\nResult:\n" << sd3.m_data << endl; - cout << "\n" << sd2.m_data; - normalize(sd2); - cout << "\nResult:\n" << sd2.m_data << endl; - - float xx = 2.5; - cout << "\n\n\nScale data:\n"; - sensor_data sd8 = scale_data(sd2, xx); - cout << "\n" << sd2.m_data << "\n" << xx; - cout << "\nResult:\n" << sd8.m_data << endl; - - cout << "\n\n\nConvert Sensor Data to Quaternion:\n"; - quaternion q = sensor_data2quat(sd11, v2); - cout << "\n" << sd11.m_data << "\n" << v2; - cout << "\nResult:\n" << q.m_quat << endl; -} - diff --git a/src/sensor/rotation_vector/test/test_projects/vector_test/vector_main.cpp b/src/sensor/rotation_vector/test/test_projects/vector_test/vector_main.cpp deleted file mode 100644 index 2a81f83..0000000 --- a/src/sensor/rotation_vector/test/test_projects/vector_test/vector_main.cpp +++ /dev/null @@ -1,196 +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 "../../../vector.h" - -int main() -{ - float arr2[3] = {0.056, 2.34, -65.76}; - float arr15[3] = {1.04, -4.678, -2.34}; - float arr3[4] = {1.03, 2.345, 6.78, 5.55}; - float arr4[4] = {-6.78, -45.213, -7.89, -3.456}; - float arr8[5] = {0.0123, 5.678, 2.345, 0.345, 8.956}; - float arr0[5] = {2344.98, 345.24, 456.12, 98.33, 144.67}; - float arr1[6] = {1.234, 4.5, 6.8987, 3.33, 5.66, 77.695}; - float arr43[6] = {2.3454, -0.0384, -8.90, 3.455, 6.785, 21.345}; - float arr5[5] = {0.2, -0.4, 0.6, -0.8, 1.0}; - - vect v1(arr0); - vect v2(arr8); - vect v10(arr3); - vect v12(arr4); - vect v15(arr1); - vect v20(arr43); - vect v21(arr2); - vect v22(arr15); - vect v31(arr0); - vect v3; - vect vn; - vect v61(arr4); - vect v6; - vect vm; - vect v13; - vect v95; - vect v35(arr5); - vect vl; - vect vp; - vect vr(arr4); - vect vf; - - float arr57[3][3] = {{2.24, 0.5, 0.023}, {3.675, 5.32, 0.556}, {1.023, 45.75, 621.6}}; - matrix m12(arr57); - float arr67[3][1] = {{2.0}, {3.0}, {4.0}}; - matrix m32(arr67); - - cout << "Constructor Test\n"; - cout << "\n" << v3; - - cout << "\n\nAddition\n"; - v3 = v21 + v22; - v95 = v15 + v20; - cout << "\n\nNumbers added\n"; - cout << "\n" << v21 << "\n" << v22; - cout << "\nSum:\n" << v3 << endl; - cout << "\n\nNumbers added\n"; - cout << "\n" << v15 << "\n" << v20; - cout << "\nSum:\n" << v95 << endl; - - float num = 5.5650; - float num1 = -2.32; - cout << "\n\n\nScalar addition\n"; - vl = v2 + num; - vm = v10 + num1; - cout << "\nNumber added:" << num; - cout << "\n\n" << v2; - cout << "\nResult:\n\n" << vl; - cout << "\nNumber added:" << num1; - cout << "\n\n" << v10; - cout << "\nResult:\n\n" << vm; - - cout << "\n\n\nSubtraction\n"; - vp = v10 - v12; - cout << "\n" << v10 << "\n" << v12; - cout << "\nDifference:\n" << vp << endl; - - float x = 4.0; - float x1 = -2.5; - cout << "\n\n\nScalar subtraction\n"; - v13 = v1 - x; - vp = v10 - x1; - cout << "\nNumber Subtracted:" << x; - cout << "\n\n" << v1; - cout << "\nResult:\n\n" << v13; - cout << "\nNumber Subtracted:" << x1; - cout << "\n\n" << v10; - cout << "\nResult:\n\n" << vp; - - float xx = 7.2; - cout << "\n\n\nMultiplication\n"; - v13 = v2 * xx; - cout << "\n" << v2 << "\n" << xx; - cout << "\nProduct:\n" << v13 << endl; - - cout << "\n\n\nMultiplication matrix x vector:\n"; - matrix m102 = m32 * v22; - cout << "\n" << m32 << "\n" << v22; - cout << "\nProduct:\n" << m102 << endl; - - cout << "\n\n\nVector x Multiplication matrix:\n"; - vect v102 = (v22 * m12); - cout << "\n" << v22 << "\n" << m12; - cout << "\nProduct:\n" << v102 << endl; - - float z = 3.50; - float z1 = -5.567; - cout << "\n\n\nScalar multiplication\n"; - v13 = v1 * z; - v61 = v12 * z1; - cout << "\nNumber Multiplied:" << z; - cout << "\n\n" << v1; - cout << "\nResult:\n\n" << v13; - cout << "\nNumber Multiplied:" << z1; - cout << "\n\n" << v12; - cout << "\nResult:\n\n" << v6; - - float num2 = 5.5; - cout << "\n\n\nDivision\n"; - v31 = v1 / num2; - cout << "\n" << v1 << "\n" << num2; - cout << "\nResult:\n" << v3 << endl; - - cout << "\n\n\nTranspose:"; - cout << "\n\n" << v20; - cout << "\nResult:\n\n"; - matrix m101 = transpose(v20); - cout << m101; - cout << "\n\n" << m101; - cout << "\nResult:\n\n"; - v20 = transpose(m101); - cout << v20; - - cout << "\n\nv1:\n\n" << v1; - cout << "\n\nv2:\n\n" << v2; - cout << "\n\n\nv1 == v2 :"; - cout << (v1 == v2); - - cout << "\n\nv10:\n\n" << v10; - cout << "\n\nv10:\n\n" << v10; - cout << "\n\n\nv10 == v10 :"; - cout << (v10 == v10); - - cout << "\n\nv12:\n\n" << v12; - cout << "\n\nv15:\n\n" << vr; - cout << "\n\n\nv12 != v15 :"; - cout << (v12 != vr); - - cout << "\n\nv15:\n\n" << v15; - cout << "\n\nv15:\n\n" << v15; - cout << "\n\n\nv15 != v15 :"; - cout << (v15 != v15); - - cout << "\n\nAssignment\n"; - v3 = vf; - cout << "Input \n" << v1; - cout << "\nOutput:\n" << v3 << endl; - - vect v111 = cross(v21, v22); - cout << "\n\n\nCross Product:"; - cout << "\n\n" << v21 << "\n\n" << v22; - cout << "\nResult:\n\n" << v111; - - float val = dot(v21, v22); - cout << "\n\n\nDot Product:"; - cout << "\n\n" << v21 << "\n\n" << v22; - cout << "\nResult:\n\n" << val; - - cout << "\n\n\nQueue insert function:"; - cout << "\nInput:\n\n" << v111; - insert_end(v111, (float) 0.9191919); - cout << "\nResult:\n\n" << v111; - - cout << "\n\n\nVariance:"; - cout << "\nInput:\n\n" << v35; - val = var(v35); - cout << "\nResult:\n\n" << val; - - cout << "\n\n\nIs Initialized:"; - cout << "\nInput:\n\n" << v35; - cout << "\nResult:\n\n" << is_initialized(v35) << endl; -} - -- 2.7.4 From 00782e26f24f88a8895ee54587bf718fc2ae0bab Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:30:02 +0900 Subject: [PATCH 12/16] sensord: enable rotation vector/orientation sensors Change-Id: I60368ad616e34f17107565c6014135a4aeb4aacb Signed-off-by: kibak.yoon --- src/sensor/CMakeLists.txt | 12 ++ src/sensor/create.cpp | 18 ++ src/sensor/orientation/orientation_sensor.cpp | 180 ++++-------------- src/sensor/orientation/orientation_sensor.h | 41 +--- src/sensor/rotation_vector/fusion_base.cpp | 9 +- src/sensor/rotation_vector/fusion_base.h | 2 +- src/sensor/rotation_vector/gyro_fusion.h | 2 +- src/sensor/rotation_vector/gyro_magnetic_fusion.h | 2 +- src/sensor/rotation_vector/gyro_rv_sensor.cpp | 204 ++++++-------------- src/sensor/rotation_vector/gyro_rv_sensor.h | 34 +--- src/sensor/rotation_vector/magnetic_fusion.h | 2 +- src/sensor/rotation_vector/magnetic_rv_sensor.cpp | 204 ++++++-------------- src/sensor/rotation_vector/magnetic_rv_sensor.h | 34 +--- src/sensor/rotation_vector/rv_sensor.cpp | 220 ++++++---------------- src/sensor/rotation_vector/rv_sensor.h | 41 +--- 15 files changed, 277 insertions(+), 728 deletions(-) diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt index 227698b..9735d8d 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/sensor/CMakeLists.txt @@ -5,6 +5,8 @@ INCLUDE(GNUInstallDirs) SET(AUTO_ROTATION "ON") SET(GRAVITY "ON") SET(LINEAR_ACCEL "ON") +SET(RV "ON") +SET(ORIENTATION "ON") INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/shared @@ -47,6 +49,16 @@ FILE(GLOB_RECURSE SRCS ${SRCS} linear_accel/*.cpp) ADD_DEFINITIONS(-DENABLE_LINEAR_ACCEL) ENDIF() +IF("${RV}" STREQUAL "ON") +FILE(GLOB_RECURSE SRCS ${SRCS} rotation_vector/*.cpp) +ADD_DEFINITIONS(-DENABLE_ROTATION_VECTOR) +ENDIF() + +IF("${ORIENTATION}" STREQUAL "ON") +FILE(GLOB_RECURSE SRCS ${SRCS} orientation/*.cpp) +ADD_DEFINITIONS(-DENABLE_ORIENTATION) +ENDIF() + MESSAGE("Sources: ${SRCS}") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PLUGINS_PKGS_LDFLAGS}) diff --git a/src/sensor/create.cpp b/src/sensor/create.cpp index 10dd21f..0dd39b5 100644 --- a/src/sensor/create.cpp +++ b/src/sensor/create.cpp @@ -29,6 +29,14 @@ #ifdef ENABLE_LINEAR_ACCEL #include "linear_accel/linear_accel_sensor.h" #endif +#ifdef ENABLE_ROTATION_VECTOR +#include "rotation_vector/rv_sensor.h" +#include "rotation_vector/magnetic_rv_sensor.h" +#include "rotation_vector/gyro_rv_sensor.h" +#endif +#ifdef ENABLE_ORIENTATION +#include "orientation/orientation_sensor.h" +#endif static std::vector sensors; @@ -64,6 +72,16 @@ extern "C" int create(fusion_sensor_t **fsensors) create_sensor("Linear Acceleration Sensor"); #endif +#ifdef ENABLE_ROTATION_VECTOR + create_sensor("Rotation Vector Sensor"); + create_sensor("Magnetic Rotation Vector Sensor"); + create_sensor("Gyroscope Rotation Vector Sensor"); +#endif + +#ifdef ENABLE_ORIENTATION + create_sensor("Orientation Sensor"); +#endif + *fsensors = &sensors[0]; return sensors.size(); } diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/sensor/orientation/orientation_sensor.cpp index c9cad8b..393ec9a 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/sensor/orientation/orientation_sensor.cpp @@ -17,136 +17,83 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include +#include "orientation_sensor.h" #include #include - -#include -#include -#include -#include #include -#define SENSOR_NAME "SENSOR_ORIENTATION" +#define NAME_SENSOR "http://tizen.org/sensor/orientation/orientation" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_RV 0x1 +#define SRC_STR_RV "http://tizen.org/sensor/rotation_vector" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: ORIENTATION_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: -180, + max_range: 360, + resolution: 0.01, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_RV, SRC_STR_RV}, +}; + orientation_sensor::orientation_sensor() -: m_rotation_vector_sensor(NULL) -, m_azimuth(-1) +: m_azimuth(-1) , m_pitch(-1) , m_roll(-1) , m_accuracy(-1) , m_time(0) +, m_interval(0) { } orientation_sensor::~orientation_sensor() { - _I("%s is destroyed!", SENSOR_NAME); -} - -bool orientation_sensor::init(void) -{ - m_rotation_vector_sensor = sensor_loader::get_instance().get_sensor(ROTATION_VECTOR_SENSOR); - - if (!m_rotation_vector_sensor) { - _W("cannot load sensor[%s]", SENSOR_NAME); - return false; - } - _I("%s is created!", SENSOR_NAME); - return true; -} - -sensor_type_t orientation_sensor::get_type(void) -{ - return ORIENTATION_SENSOR; } -unsigned int orientation_sensor::get_event_type(void) +int orientation_sensor::get_sensor_info(const sensor_info2_t **info) { - return ORIENTATION_EVENT_RAW_DATA_REPORT_ON_TIME; + *info = &sensor_info; + return OP_SUCCESS; } -const char* orientation_sensor::get_name(void) +int orientation_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 1; } -bool orientation_sensor::get_sensor_info(sensor_info &info) -{ - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); - info.set_name(get_name()); - info.set_vendor("Samsung Electronics"); - info.set_min_range(-180); - info.set_max_range(360); - info.set_resolution(0.01); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void orientation_sensor::synthesize(const sensor_event_t& event) +int orientation_sensor::update(uint32_t id, sensor_data_t *data, int len) { int error; - sensor_event_t *orientation_event; float azimuth, pitch, roll; - if (CONVERT_ID_TYPE(event.sensor_id) != ROTATION_VECTOR_SENSOR) - return; - - error = quat_to_orientation(event.data->values, azimuth, pitch, roll); - ret_if(error); - - orientation_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!orientation_event) { - _E("Failed to allocate memory"); - return; - } - orientation_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!orientation_event->data) { - _E("Failed to allocate memory"); - free(orientation_event); - return; - } - - orientation_event->sensor_id = get_id(); - orientation_event->event_type = CONVERT_TYPE_EVENT(ORIENTATION_SENSOR); - orientation_event->data_length = sizeof(sensor_data_t); - orientation_event->data->accuracy = event.data->accuracy; - orientation_event->data->timestamp = event.data->timestamp; - orientation_event->data->value_count = 3; - orientation_event->data->values[0] = azimuth; - orientation_event->data->values[1] = pitch; - orientation_event->data->values[2] = roll; - push(orientation_event); + error = quat_to_orientation(data->values, azimuth, pitch, roll); + retv_if(error, OP_ERROR); m_azimuth = azimuth; m_pitch = pitch; m_roll = roll; - m_time = event.data->timestamp; - m_accuracy = event.data->accuracy; + m_time = data->timestamp; + m_accuracy = data->accuracy; _D("[orientation] : [%10f] [%10f] [%10f]", m_azimuth, m_pitch, m_roll); + return OP_SUCCESS; } int orientation_sensor::get_data(sensor_data_t **data, int *length) { - /* if It is batch sensor, remains can be 2+ */ - int remains = 1; - sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); @@ -160,52 +107,5 @@ int orientation_sensor::get_data(sensor_data_t **data, int *length) *data = sensor_data; *length = sizeof(sensor_data_t); - return --remains; -} - -bool orientation_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool orientation_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool orientation_sensor::on_start(void) -{ - if (m_rotation_vector_sensor) - m_rotation_vector_sensor->start(); - - m_time = 0; - - return activate(); -} - -bool orientation_sensor::on_stop(void) -{ - if (m_rotation_vector_sensor) - m_rotation_vector_sensor->stop(); - - m_time = 0; - - return deactivate(); -} - -bool orientation_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - if (m_rotation_vector_sensor) - m_rotation_vector_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool orientation_sensor::delete_interval(int client_id, bool is_processor) -{ - if (m_rotation_vector_sensor) - m_rotation_vector_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); + return 1; } diff --git a/src/sensor/orientation/orientation_sensor.h b/src/sensor/orientation/orientation_sensor.h index 4e5f4c3..03de5b0 100644 --- a/src/sensor/orientation/orientation_sensor.h +++ b/src/sensor/orientation/orientation_sensor.h @@ -17,53 +17,30 @@ * */ -#ifndef _ORIENTATION_SENSOR_H_ -#define _ORIENTATION_SENSOR_H_ +#ifndef __ORIENTATION_SENSOR_H__ +#define __ORIENTATION_SENSOR_H__ -#include +#include #include -#include -class orientation_sensor : public virtual_sensor { +class orientation_sensor : public fusion_sensor { public: orientation_sensor(); virtual ~orientation_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_rotation_vector_sensor; - float m_azimuth; float m_pitch; float m_roll; int m_accuracy; unsigned long long m_time; unsigned long m_interval; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - - virtual bool on_start(void); - virtual bool on_stop(void); - - int rotation_to_orientation(const float *rotation, float &azimuth, float &pitch, float &roll); }; -#endif /* _ORIENTATION_SENSOR_H_ */ +#endif /* __ORIENTATION_SENSOR_H__ */ diff --git a/src/sensor/rotation_vector/fusion_base.cpp b/src/sensor/rotation_vector/fusion_base.cpp index 89b5a44..ad92d2a 100644 --- a/src/sensor/rotation_vector/fusion_base.cpp +++ b/src/sensor/rotation_vector/fusion_base.cpp @@ -22,8 +22,6 @@ #include #include #include -#include -#include #include #include "fusion_base.h" @@ -35,13 +33,16 @@ fusion_base::fusion_base() : m_enable_accel(false) , m_enable_gyro(false) , m_enable_magnetic(false) +, m_x(0) +, m_y(0) +, m_z(0) +, m_w(0) +, m_timestamp(0) { - _I("fusion_base is created!"); } fusion_base::~fusion_base() { - _I("fusion_sensor is destroyed!"); } void fusion_base::clear(void) diff --git a/src/sensor/rotation_vector/fusion_base.h b/src/sensor/rotation_vector/fusion_base.h index 3af7c91..96a3301 100644 --- a/src/sensor/rotation_vector/fusion_base.h +++ b/src/sensor/rotation_vector/fusion_base.h @@ -19,7 +19,7 @@ #ifndef __FUSION_BASE_H__ #define __FUSION_BASE_H__ -#include +#include "fusion.h" #include "fusion_utils/orientation_filter.h" class fusion_base : public virtual fusion { diff --git a/src/sensor/rotation_vector/gyro_fusion.h b/src/sensor/rotation_vector/gyro_fusion.h index 0089e0d..9139e0d 100644 --- a/src/sensor/rotation_vector/gyro_fusion.h +++ b/src/sensor/rotation_vector/gyro_fusion.h @@ -20,7 +20,7 @@ #ifndef __GYRO_FUSION_H__ #define __GYRO_FUSION_H__ -#include +#include "fusion_base.h" class gyro_fusion : public fusion_base { public: diff --git a/src/sensor/rotation_vector/gyro_magnetic_fusion.h b/src/sensor/rotation_vector/gyro_magnetic_fusion.h index 54bf75c..b95aafd 100644 --- a/src/sensor/rotation_vector/gyro_magnetic_fusion.h +++ b/src/sensor/rotation_vector/gyro_magnetic_fusion.h @@ -20,7 +20,7 @@ #ifndef __GYRO_MAGNETIC_FUSION_H__ #define __GYRO_MAGNETIC_FUSION_H__ -#include +#include "fusion_base.h" class gyro_magnetic_fusion : public fusion_base { public: diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/sensor/rotation_vector/gyro_rv_sensor.cpp index 7c7c9b3..3a738d0 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gyro_rv_sensor.cpp @@ -17,143 +17,89 @@ * */ -#include -#include -#include -#include -#include -#include -#include +#include "gyro_rv_sensor.h" #include #include - -#include -#include -#include -#include #include -#define SENSOR_NAME "SENSOR_GYROSCOPE_ROTATION_VECTOR" - +#define NAME_SENSOR "http://tizen.org/sensor/gyro_rotation_vector/gyro_rv" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +#define SRC_ID_GYRO 0x2 +#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GYROSCOPE_RV_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: 0, + max_range: 1, + resolution: 1, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC}, + {SRC_ID_GYRO, SRC_STR_GYRO}, +}; gyro_rv_sensor::gyro_rv_sensor() -: m_accel_sensor(NULL) -, m_gyro_sensor(NULL) -, m_x(-1) +: m_x(-1) , m_y(-1) , m_z(-1) , m_w(-1) , m_time(0) +, m_interval(100) , m_accuracy(SENSOR_ACCURACY_UNDEFINED) { } gyro_rv_sensor::~gyro_rv_sensor() { - _I("%s is destroyed!", SENSOR_NAME); -} - -bool gyro_rv_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); - - if (!m_accel_sensor || !m_gyro_sensor) { - _W("cannot load sensors[%s]", SENSOR_NAME); - return false; - } - - _I("%s is created!", SENSOR_NAME); - return true; -} - -sensor_type_t gyro_rv_sensor::get_type(void) -{ - return GYROSCOPE_RV_SENSOR; } -unsigned int gyro_rv_sensor::get_event_type(void) +int gyro_rv_sensor::get_sensor_info(const sensor_info2_t **info) { - return CONVERT_TYPE_EVENT(GYROSCOPE_RV_SENSOR); + *info = &sensor_info; + return OP_SUCCESS; } -const char* gyro_rv_sensor::get_name(void) +int gyro_rv_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 2; } -bool gyro_rv_sensor::get_sensor_info(sensor_info &info) +int gyro_rv_sensor::update(uint32_t id, sensor_data_t *data, int len) { - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); - info.set_name(get_name()); - info.set_vendor("Samsung Electronics"); - info.set_min_range(0); - info.set_max_range(1); - info.set_resolution(1); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void gyro_rv_sensor::synthesize(const sensor_event_t& event) -{ - sensor_event_t *rotation_vector_event; - - if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME && - event.event_type != GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) - return; + unsigned long long timestamp; - if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_accel(*(event.data)); - else if (event.event_type == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_gyro(*(event.data)); + if (id == SRC_ID_ACC) + m_fusion.push_accel(*data); + else if (id == SRC_ID_GYRO) + m_fusion.push_gyro(*data); - if (m_accuracy == SENSOR_ACCURACY_UNDEFINED) - m_accuracy = event.data->accuracy; - else if (m_accuracy > event.data->accuracy) - m_accuracy = event.data->accuracy; + if (m_accuracy > data->accuracy) + m_accuracy = data->accuracy; - unsigned long long timestamp; if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z)) - return; + return OP_ERROR; if(timestamp == m_time) - return; - m_time = timestamp; + return OP_ERROR; - rotation_vector_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!rotation_vector_event) { - _E("Failed to allocate memory"); - return; - } - rotation_vector_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!rotation_vector_event->data) { - _E("Failed to allocate memory"); - free(rotation_vector_event); - return; - } - - rotation_vector_event->sensor_id = get_id(); - rotation_vector_event->event_type = CONVERT_TYPE_EVENT(GYROSCOPE_RV_SENSOR); - rotation_vector_event->data_length = sizeof(sensor_data_t); - rotation_vector_event->data->accuracy = m_accuracy; - rotation_vector_event->data->timestamp = m_time; - rotation_vector_event->data->value_count = 4; - rotation_vector_event->data->values[0] = m_w; - rotation_vector_event->data->values[1] = m_x; - rotation_vector_event->data->values[2] = m_y; - rotation_vector_event->data->values[3] = m_z; - push(rotation_vector_event); - m_accuracy = SENSOR_ACCURACY_UNDEFINED; + m_time = timestamp; _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w); + return OP_SUCCESS; } int gyro_rv_sensor::get_data(sensor_data_t **data, int *length) @@ -163,58 +109,14 @@ int gyro_rv_sensor::get_data(sensor_data_t **data, int *length) sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; - sensor_data->value_count = 3; - sensor_data->values[0] = m_x; - sensor_data->values[1] = m_y; - sensor_data->values[2] = m_z; + sensor_data->value_count = 4; + sensor_data->values[0] = m_w; + sensor_data->values[1] = m_x; + sensor_data->values[2] = m_y; + sensor_data->values[3] = m_z; *data = sensor_data; *length = sizeof(sensor_data_t); return 0; } - -bool gyro_rv_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool gyro_rv_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool gyro_rv_sensor::on_start(void) -{ - m_accel_sensor->start(); - m_gyro_sensor->start(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return activate(); -} - -bool gyro_rv_sensor::on_stop(void) -{ - m_accel_sensor->stop(); - m_gyro_sensor->stop(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return deactivate(); -} - -bool gyro_rv_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - m_accel_sensor->add_interval(client_id, interval, true); - m_gyro_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool gyro_rv_sensor::delete_interval(int client_id, bool is_processor) -{ - m_accel_sensor->delete_interval(client_id, true); - m_gyro_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); -} diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.h b/src/sensor/rotation_vector/gyro_rv_sensor.h index 052f0e3..c6c16b1 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.h +++ b/src/sensor/rotation_vector/gyro_rv_sensor.h @@ -20,36 +20,22 @@ #ifndef __GYRO_RV_SENSOR_H__ #define __GYRO_RV_SENSOR_H__ -#include +#include #include -#include +#include "gyro_fusion.h" -class gyro_rv_sensor : public virtual_sensor { +class gyro_rv_sensor : public fusion_sensor { public: gyro_rv_sensor(); virtual ~gyro_rv_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_accel_sensor; - sensor_base *m_gyro_sensor; gyro_fusion m_fusion; float m_x; @@ -59,12 +45,6 @@ private: unsigned long long m_time; unsigned long m_interval; int m_accuracy; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - - virtual bool on_start(void); - virtual bool on_stop(void); }; #endif /* __GYRO_SENSOR_H__ */ diff --git a/src/sensor/rotation_vector/magnetic_fusion.h b/src/sensor/rotation_vector/magnetic_fusion.h index 41758ea..e5aca7e 100644 --- a/src/sensor/rotation_vector/magnetic_fusion.h +++ b/src/sensor/rotation_vector/magnetic_fusion.h @@ -20,7 +20,7 @@ #ifndef __MAGNETIC_FUSION_H__ #define __MAGNETIC_FUSION_H__ -#include +#include "fusion_base.h" class magnetic_fusion: public fusion_base { public: diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp index 61001c1..66c8808 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp @@ -17,143 +17,89 @@ * */ -#include -#include -#include -#include -#include -#include -#include +#include "magnetic_rv_sensor.h" #include #include - -#include -#include -#include -#include #include -#define SENSOR_NAME "SENSOR_MAGNETIC_ROTATION_VECTOR" - +#define NAME_SENSOR "http://tizen.org/sensor/mag_rotation_vector/mag_rv" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +#define SRC_ID_MAG 0x3 +#define SRC_STR_MAG "http://tizen.org/sensor/geomagnetic" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: GEOMAGNETIC_RV_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: 0, + max_range: 1, + resolution: 1, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC}, + {SRC_ID_MAG, SRC_STR_MAG}, +}; magnetic_rv_sensor::magnetic_rv_sensor() -: m_accel_sensor(NULL) -, m_mag_sensor(NULL) -, m_x(-1) +: m_x(-1) , m_y(-1) , m_z(-1) , m_w(-1) , m_time(0) +, m_interval(100) , m_accuracy(SENSOR_ACCURACY_UNDEFINED) { } magnetic_rv_sensor::~magnetic_rv_sensor() { - _I("%s is destroyed!", SENSOR_NAME); -} - -bool magnetic_rv_sensor::init(void) -{ - m_accel_sensor = sensor_loader::get_instance().get_sensor(ACCELEROMETER_SENSOR); - m_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); - - if (!m_accel_sensor || !m_mag_sensor) { - _W("cannot load sensors[%s]", SENSOR_NAME); - return false; - } - - _I("%s is created!", SENSOR_NAME); - return true; -} - -sensor_type_t magnetic_rv_sensor::get_type(void) -{ - return GEOMAGNETIC_RV_SENSOR; } -unsigned int magnetic_rv_sensor::get_event_type(void) +int magnetic_rv_sensor::get_sensor_info(const sensor_info2_t **info) { - return CONVERT_TYPE_EVENT(GEOMAGNETIC_RV_SENSOR); + *info = &sensor_info; + return OP_SUCCESS; } -const char* magnetic_rv_sensor::get_name(void) +int magnetic_rv_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 2; } -bool magnetic_rv_sensor::get_sensor_info(sensor_info &info) +int magnetic_rv_sensor::update(uint32_t id, sensor_data_t *data, int len) { - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); - info.set_name(get_name()); - info.set_vendor("Samsung Electronics"); - info.set_min_range(0); - info.set_max_range(1); - info.set_resolution(1); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void magnetic_rv_sensor::synthesize(const sensor_event_t& event) -{ - sensor_event_t *rotation_vector_event; - - if (event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME && - event.event_type != GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME) - return; + unsigned long long timestamp; - if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_accel(*(event.data)); - else if (event.event_type == GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_mag(*(event.data)); + if (id == SRC_ID_ACC) + m_fusion.push_accel(*data); + else if (id == SRC_ID_MAG) + m_fusion.push_mag(*data); - if (m_accuracy == SENSOR_ACCURACY_UNDEFINED) - m_accuracy = event.data->accuracy; - else if (m_accuracy > event.data->accuracy) - m_accuracy = event.data->accuracy; + if (m_accuracy > data->accuracy) + m_accuracy = data->accuracy; - unsigned long long timestamp; if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z)) - return; + return OP_ERROR; if (timestamp == m_time) - return; - m_time = timestamp; + return OP_ERROR; - rotation_vector_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!rotation_vector_event) { - _E("Failed to allocate memory"); - return; - } - rotation_vector_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!rotation_vector_event->data) { - _E("Failed to allocate memory"); - free(rotation_vector_event); - return; - } - - rotation_vector_event->sensor_id = get_id(); - rotation_vector_event->event_type = CONVERT_TYPE_EVENT(GEOMAGNETIC_RV_SENSOR); - rotation_vector_event->data_length = sizeof(sensor_data_t); - rotation_vector_event->data->accuracy = m_accuracy; - rotation_vector_event->data->timestamp = m_time; - rotation_vector_event->data->value_count = 4; - rotation_vector_event->data->values[0] = m_w; - rotation_vector_event->data->values[1] = m_x; - rotation_vector_event->data->values[2] = m_y; - rotation_vector_event->data->values[3] = m_z; - push(rotation_vector_event); - m_accuracy = SENSOR_ACCURACY_UNDEFINED; + m_time = timestamp; _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w); + return OP_SUCCESS; } int magnetic_rv_sensor::get_data(sensor_data_t **data, int *length) @@ -163,58 +109,14 @@ int magnetic_rv_sensor::get_data(sensor_data_t **data, int *length) sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; - sensor_data->value_count = 3; - sensor_data->values[0] = m_x; - sensor_data->values[1] = m_y; - sensor_data->values[2] = m_z; + sensor_data->value_count = 4; + sensor_data->values[0] = m_w; + sensor_data->values[1] = m_x; + sensor_data->values[2] = m_y; + sensor_data->values[3] = m_z; *data = sensor_data; *length = sizeof(sensor_data_t); return 0; } - -bool magnetic_rv_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool magnetic_rv_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool magnetic_rv_sensor::on_start(void) -{ - m_accel_sensor->start(); - m_mag_sensor->start(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return activate(); -} - -bool magnetic_rv_sensor::on_stop(void) -{ - m_accel_sensor->stop(); - m_mag_sensor->stop(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return deactivate(); -} - -bool magnetic_rv_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - m_accel_sensor->add_interval(client_id, interval, true); - m_mag_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool magnetic_rv_sensor::delete_interval(int client_id, bool is_processor) -{ - m_accel_sensor->delete_interval(client_id, true); - m_mag_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); -} diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.h b/src/sensor/rotation_vector/magnetic_rv_sensor.h index 34b5d49..cc6ee79 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.h +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.h @@ -20,36 +20,22 @@ #ifndef __MAGNETIC_RV_SENSOR_H__ #define __MAGNETIC_RV_SENSOR_H__ -#include +#include #include -#include +#include "magnetic_fusion.h" -class magnetic_rv_sensor : public virtual_sensor { +class magnetic_rv_sensor : public fusion_sensor { public: magnetic_rv_sensor(); virtual ~magnetic_rv_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_accel_sensor; - sensor_base *m_mag_sensor; magnetic_fusion m_fusion; float m_x; @@ -59,12 +45,6 @@ private: unsigned long long m_time; unsigned long m_interval; int m_accuracy; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - - virtual bool on_start(void); - virtual bool on_stop(void); }; #endif /* __MAGNETIC_SENSOR_H__ */ diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/sensor/rotation_vector/rv_sensor.cpp index 9fb42c7..6d69cda 100644 --- a/src/sensor/rotation_vector/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv_sensor.cpp @@ -17,149 +17,95 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include +#include "rv_sensor.h" #include #include - -#include -#include -#include -#include #include -#define SENSOR_NAME "SENSOR_ROTATION_VECTOR" - +#define NAME_SENSOR "http://tizen.org/sensor/rotation_vector/rotation_vector" +#define NAME_VENDOR "Samsung" + +#define SRC_ID_ACC 0x1 +#define SRC_STR_ACC "http://tizen.org/sensor/accelerometer" + +#define SRC_ID_GYRO 0x2 +#define SRC_STR_GYRO "http://tizen.org/sensor/gyroscope" + +#define SRC_ID_MAG 0x3 +#define SRC_STR_MAG "http://tizen.org/sensor/geomagnetic" + +static sensor_info2_t sensor_info = { + id: 0x1, + type: ROTATION_VECTOR_SENSOR, + uri: NAME_SENSOR, + vendor: NAME_VENDOR, + min_range: 0, + max_range: 1, + resolution: 1, + min_interval: 10, + max_batch_count: 0, + wakeup_supported: false, + privilege:"", +}; + +static required_sensor_s required_sensors[] = { + {SRC_ID_ACC, SRC_STR_ACC}, + {SRC_ID_GYRO, SRC_STR_GYRO}, + {SRC_ID_MAG, SRC_STR_MAG}, +}; rv_sensor::rv_sensor() -: m_accel_sensor(NULL) -, m_gyro_sensor(NULL) -, m_mag_sensor(NULL) -, m_x(-1) +: m_x(-1) , m_y(-1) , m_z(-1) , m_w(-1) , m_time(0) +, m_interval(100) , m_accuracy(SENSOR_ACCURACY_UNDEFINED) { } rv_sensor::~rv_sensor() { - _I("%s is destroyed!", SENSOR_NAME); -} - -bool rv_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_mag_sensor = sensor_loader::get_instance().get_sensor(GEOMAGNETIC_SENSOR); - - if (!m_accel_sensor || !m_gyro_sensor|| !m_mag_sensor) { - _W("cannot load sensors[%s]", SENSOR_NAME); - return false; - } - - _I("%s is created!", SENSOR_NAME); - return true; -} - -sensor_type_t rv_sensor::get_type(void) -{ - return ROTATION_VECTOR_SENSOR; } -unsigned int rv_sensor::get_event_type(void) +int rv_sensor::get_sensor_info(const sensor_info2_t **info) { - return CONVERT_TYPE_EVENT(ROTATION_VECTOR_SENSOR); + *info = &sensor_info; + return OP_SUCCESS; } -const char* rv_sensor::get_name(void) +int rv_sensor::get_required_sensors(const required_sensor_s **sensors) { - return SENSOR_NAME; + *sensors = required_sensors; + return 3; } -bool rv_sensor::get_sensor_info(sensor_info &info) +int rv_sensor::update(uint32_t id, sensor_data_t *data, int len) { - info.set_type(get_type()); - info.set_id(get_id()); - info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); - info.set_name(get_name()); - info.set_vendor("Samsung Electronics"); - info.set_min_range(0); - info.set_max_range(1); - info.set_resolution(1); - info.set_min_interval(1); - info.set_fifo_count(0); - info.set_max_batch_count(0); - info.set_supported_event(get_event_type()); - info.set_wakeup_supported(false); - - return true; -} - -void rv_sensor::synthesize(const sensor_event_t& event) -{ - sensor_event_t *rotation_vector_event; - - if (event.event_type != GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME && - event.event_type != ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME && - event.event_type != GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) - return; + unsigned long long timestamp; - if (event.event_type == ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_accel(*(event.data)); - else if (event.event_type == GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_mag(*(event.data)); - else if (event.event_type == GYROSCOPE_EVENT_RAW_DATA_REPORT_ON_TIME) - m_fusion.push_gyro(*(event.data)); + if (id == SRC_ID_ACC) + m_fusion.push_accel(*data); + else if (id == SRC_ID_MAG) + m_fusion.push_mag(*data); + else if (id == SRC_ID_GYRO) + m_fusion.push_gyro(*data); - if (m_accuracy == SENSOR_ACCURACY_UNDEFINED) - m_accuracy = event.data->accuracy; - else if (m_accuracy > event.data->accuracy) - m_accuracy = event.data->accuracy; + if (m_accuracy > data->accuracy) + m_accuracy = data->accuracy; - unsigned long long timestamp; if (!m_fusion.get_rv(timestamp, m_w, m_x, m_y, m_z)) - return; + return OP_ERROR; if (timestamp == m_time) - return; - m_time = timestamp; + return OP_ERROR; - rotation_vector_event = (sensor_event_t *)malloc(sizeof(sensor_event_t)); - if (!rotation_vector_event) { - _E("Failed to allocate memory"); - return; - } - rotation_vector_event->data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); - if (!rotation_vector_event->data) { - _E("Failed to allocate memory"); - free(rotation_vector_event); - return; - } - - rotation_vector_event->sensor_id = get_id(); - rotation_vector_event->event_type = CONVERT_TYPE_EVENT(ROTATION_VECTOR_SENSOR); - rotation_vector_event->data_length = sizeof(sensor_data_t); - rotation_vector_event->data->accuracy = m_accuracy; - rotation_vector_event->data->timestamp = m_time; - rotation_vector_event->data->value_count = 4; - rotation_vector_event->data->values[0] = m_w; - rotation_vector_event->data->values[1] = m_x; - rotation_vector_event->data->values[2] = m_y; - rotation_vector_event->data->values[3] = m_z; - push(rotation_vector_event); - m_accuracy = SENSOR_ACCURACY_UNDEFINED; + m_time = timestamp; _D("[rotation_vector] : [%10f] [%10f] [%10f] [%10f]", m_x, m_y, m_z, m_w); + return OP_SUCCESS; } int rv_sensor::get_data(sensor_data_t **data, int *length) @@ -169,62 +115,14 @@ int rv_sensor::get_data(sensor_data_t **data, int *length) sensor_data->accuracy = m_accuracy; sensor_data->timestamp = m_time; - sensor_data->value_count = 3; - sensor_data->values[0] = m_x; - sensor_data->values[1] = m_y; - sensor_data->values[2] = m_z; + sensor_data->value_count = 4; + sensor_data->values[0] = m_w; + sensor_data->values[1] = m_x; + sensor_data->values[2] = m_y; + sensor_data->values[3] = m_z; *data = sensor_data; *length = sizeof(sensor_data_t); return 0; } - -bool rv_sensor::set_interval(unsigned long interval) -{ - m_interval = interval; - return true; -} - -bool rv_sensor::set_batch_latency(unsigned long latency) -{ - return false; -} - -bool rv_sensor::on_start(void) -{ - m_accel_sensor->start(); - m_gyro_sensor->start(); - m_mag_sensor->start(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return activate(); -} - -bool rv_sensor::on_stop(void) -{ - m_accel_sensor->stop(); - m_gyro_sensor->stop(); - m_mag_sensor->stop(); - m_time = 0; - m_accuracy = SENSOR_ACCURACY_UNDEFINED; - return deactivate(); -} - -bool rv_sensor::add_interval(int client_id, unsigned int interval, bool is_processor) -{ - m_accel_sensor->add_interval(client_id, interval, true); - m_gyro_sensor->add_interval(client_id, interval, true); - m_mag_sensor->add_interval(client_id, interval, true); - - return sensor_base::add_interval(client_id, interval, is_processor); -} - -bool rv_sensor::delete_interval(int client_id, bool is_processor) -{ - m_accel_sensor->delete_interval(client_id, true); - m_gyro_sensor->delete_interval(client_id, true); - m_mag_sensor->delete_interval(client_id, true); - - return sensor_base::delete_interval(client_id, is_processor); -} diff --git a/src/sensor/rotation_vector/rv_sensor.h b/src/sensor/rotation_vector/rv_sensor.h index db23d01..0e06370 100644 --- a/src/sensor/rotation_vector/rv_sensor.h +++ b/src/sensor/rotation_vector/rv_sensor.h @@ -17,40 +17,25 @@ * */ -#ifndef _ROTATION_VECTOR_SENSOR_H_ -#define _ROTATION_VECTOR_SENSOR_H_ +#ifndef __ROTATION_VECTOR_SENSOR_H__ +#define __ROTATION_VECTOR_SENSOR_H__ -#include +#include #include -#include +#include "gyro_magnetic_fusion.h" -class rv_sensor : public virtual_sensor { +class rv_sensor : public fusion_sensor { public: rv_sensor(); virtual ~rv_sensor(); - /* initialize sensor */ - bool init(void); + int get_sensor_info(const sensor_info2_t **info); + int get_required_sensors(const required_sensor_s **sensors); - /* sensor info */ - virtual sensor_type_t get_type(void); - virtual unsigned int get_event_type(void); - virtual const char* get_name(void); + int update(uint32_t id, sensor_data_t *data, int len); + int get_data(sensor_data_t **data, int *len); - virtual bool get_sensor_info(sensor_info &info); - - /* synthesize event */ - virtual void synthesize(const sensor_event_t& event); - - bool add_interval(int client_id, unsigned int interval, bool is_processor); - bool delete_interval(int client_id, bool is_processor); - - /* get data */ - virtual int get_data(sensor_data_t **data, int *length); private: - sensor_base *m_accel_sensor; - sensor_base *m_gyro_sensor; - sensor_base *m_mag_sensor; gyro_magnetic_fusion m_fusion; float m_x; @@ -60,12 +45,6 @@ private: unsigned long long m_time; unsigned long m_interval; int m_accuracy; - - virtual bool set_interval(unsigned long interval); - virtual bool set_batch_latency(unsigned long latency); - - virtual bool on_start(void); - virtual bool on_stop(void); }; -#endif /* _ROTATION_VECTOR_SENSOR_H_ */ +#endif /* __ROTATION_VECTOR_SENSOR_H__ */ -- 2.7.4 From 4a604f34e0801e1ce2c414305b806cec65386fe5 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:30:48 +0900 Subject: [PATCH 13/16] sensord: use emplace_back instead of push_back Change-Id: I812a34b162a982dfa1ba7033bcb35e758d8d71dd Signed-off-by: kibak.yoon --- src/sensorctl/test_bench.cpp | 4 +--- src/server/sensor_loader.cpp | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/sensorctl/test_bench.cpp b/src/sensorctl/test_bench.cpp index 201a7f5..3b9cd51 100644 --- a/src/sensorctl/test_bench.cpp +++ b/src/sensorctl/test_bench.cpp @@ -133,9 +133,7 @@ void test_bench::add_testcase(const std::string &group, test_case *testcase) void test_bench::add_failure(const std::string &function, long line, const std::string &msg) { - test_result fail(function, line, msg); - - results.push_back(fail); + results.emplace_back(function, line, msg); m_failure_count++; } diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index 4d1d20e..9ea7e7f 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -73,7 +73,6 @@ bool sensor_loader::load(const std::string &dir_path, std::vector module_paths; void **results; - T *sensor; ret = get_module_paths(dir_path, module_paths); retv_if(!ret, false); @@ -97,11 +96,8 @@ bool sensor_loader::load(const std::string &dir_path, std::vector(results[i]); - std::shared_ptr sensor_ptr(sensor); - sensors.push_back(sensor_ptr); - } + for (int i = 0; i < size; ++i) + sensors.emplace_back(static_cast(results[i])); m_modules[path.c_str()] = handle; } -- 2.7.4 From 83e771e00fbd3ffd2cd36e7f4966103da1ce338b Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:31:56 +0900 Subject: [PATCH 14/16] sensord: use underscore(_) instead of dot(.) for URI string - [TBD] discuss what is the better Change-Id: I6c41cc4eca22062159734ebfae422f9da0ce7c04 Signed-off-by: kibak.yoon --- src/shared/sensor_utils.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/shared/sensor_utils.cpp b/src/shared/sensor_utils.cpp index 6ef0504..817eb31 100644 --- a/src/shared/sensor_utils.cpp +++ b/src/shared/sensor_utils.cpp @@ -52,13 +52,13 @@ static std::map types = { {TEMPERATURE_SENSOR, "http://tizen.org/sensor/temperature"}, {HUMIDITY_SENSOR, "http://tizen.org/sensor/humidity"}, {HRM_SENSOR, "http://tizen.org/sensor/heart_rate_monitor"}, - {HRM_LED_GREEN_SENSOR, "http://tizen.org/sensor/hrm.led_green"}, - {HRM_LED_IR_SENSOR, "http://tizen.org/sensor/hrm.led_ir"}, - {HRM_LED_RED_SENSOR, "http://tizen.org/sensor/hrm.led_red"}, - {GYROSCOPE_UNCAL_SENSOR, "http://tizen.org/sensor/gyroscope.uncalibrated"}, - {GEOMAGNETIC_UNCAL_SENSOR, "http://tizen.org/sensor/geomagnetic.uncalibrated"}, - {GYROSCOPE_RV_SENSOR, "http://tizen.org/sensor/rotation_vector.gyroscope"}, - {GEOMAGNETIC_RV_SENSOR, "http://tizen.org/sensor/rotation_vector.geomagnetic"}, + {HRM_LED_GREEN_SENSOR, "http://tizen.org/sensor/hrm_led_green"}, + {HRM_LED_IR_SENSOR, "http://tizen.org/sensor/hrm_led_ir"}, + {HRM_LED_RED_SENSOR, "http://tizen.org/sensor/hrm_led_red"}, + {GYROSCOPE_UNCAL_SENSOR, "http://tizen.org/sensor/gyro_uncalibrated"}, + {GEOMAGNETIC_UNCAL_SENSOR, "http://tizen.org/sensor/mag_uncalibrated"}, + {GYROSCOPE_RV_SENSOR, "http://tizen.org/sensor/gyro_rotation_vector"}, + {GEOMAGNETIC_RV_SENSOR, "http://tizen.org/sensor/mag_rotation_vector"}, {HUMAN_PEDOMETER_SENSOR, "http://tizen.org/sensor/human_pedometer"}, {HUMAN_SLEEP_MONITOR_SENSOR, "http://tizen.org/sensor/human_sleep_monitor"}, -- 2.7.4 From 877af40d645dc7aa3b07f1db55a14f82ba08a095 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:42:10 +0900 Subject: [PATCH 15/16] sensord: return the appropriate error Change-Id: I953af6979592f003b7967898f2389b782b562f63 Signed-off-by: kibak.yoon --- src/client/sensor_manager.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index 4be1065..7d5197f 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -104,11 +104,7 @@ int sensor_manager::get_sensors(const char *uri, sensor_t **list, int *count) infos = get_infos(uri); size = infos.size(); - - if (size == 0) { - *count = 0; - return -ENODATA; - } + retv_if(size == 0, -EACCES); *list = (sensor_t *)malloc(sizeof(sensor_info *) * size); retvm_if(!*list, -ENOMEM, "Failed to allocate memory"); -- 2.7.4 From eff2a8e3c95b2a8c68703724d842034070c9887c Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 14 Apr 2017 00:51:14 +0900 Subject: [PATCH 16/16] sensord: use int32_t instead size_t - compatibility with 64bit platform Change-Id: I16299dfe15418492506063ce6572e7cdf9502127 Signed-off-by: kibak.yoon --- src/client/sensor_manager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index 7d5197f..2d14a4d 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -220,22 +220,22 @@ void sensor_manager::decode_sensors(const char *buf, std::vector &i { int count = 0; sensor_info info; - const size_t *size; + const int32_t *size; const char *data; cmd_manager_sensor_list_t *raw; raw = (cmd_manager_sensor_list_t *)buf; count = raw->sensor_cnt; - size = (const size_t *)raw->data; - data = (const char *)raw->data + sizeof(size_t); + size = (const int32_t *)raw->data; + data = (const char *)raw->data + sizeof(int32_t); for (int i = 0; i < count; ++i) { info.clear(); info.deserialize(data, size[0]); infos.push_back(info); - size = (const size_t *)((const char *)data + size[0]); - data = (const char *)size + sizeof(size_t); + size = (const int32_t *)((const char *)data + size[0]); + data = (const char *)size + sizeof(int32_t); } _D("Sensor count : %d", count); -- 2.7.4