From a3178338a7857eb929280ef05f526c215cd482b2 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 17 Nov 2016 00:04:29 +0900 Subject: [PATCH 01/16] sensord: add select before sending the event because check client fd is writable or not, select() is added. Change-Id: I3189b314ec574fa8201dc79e33b91ad2e7f82deb Signed-off-by: kibak.yoon --- src/shared/csocket.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index c500def..4a97a3c 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -306,9 +306,35 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const ssize_t csocket::send(const void *buffer, size_t size) const { + const int TIMEOUT = 5; + fd_set write_fds; + struct timeval tv; + if (!is_valid()) return -EINVAL; + FD_ZERO(&write_fds); + FD_SET(m_sock_fd, &write_fds); + tv.tv_sec = TIMEOUT; + tv.tv_usec = 0; + + int ret; + + ret = select(m_sock_fd + 1, NULL, &write_fds, NULL, &tv); + + if (ret == -1) { + _ERRNO(errno, _E, "select error: sock_fd: %d\n for %s", m_sock_fd, get_client_name()); + return false; + } else if (!ret) { + _ERRNO(errno, _E, "select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name()); + return false; + } + + if (!FD_ISSET(m_sock_fd, &write_fds)) { + _ERRNO(errno, _E, "select failed for %s, nothing to write, m_sock_fd : %d", get_client_name(), m_sock_fd); + return false; + } + if (m_sock_type == SOCK_STREAM) return send_for_stream(buffer, size); -- 2.7.4 From d482ea6afbf0c2ed942a5636e99b5ba468e251d7 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 21:00:14 +0900 Subject: [PATCH 02/16] sensord: change variable name of attribute-related functions - change name from value_len to len - change name from attribute to attr Change-Id: I7a2513f207c34fd564100b6bdd1d4f2798845ca8 Signed-off-by: kibak.yoon --- src/client/client.cpp | 12 ++++++------ src/client/sensor_client_info.cpp | 10 +++++----- src/client/sensor_client_info.h | 2 +- src/client/sensor_handle_info.cpp | 12 +++++++----- src/client/sensor_handle_info.h | 2 +- src/server/external_sensor_worker.cpp | 1 - 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 7d22d9f..7fd43f5 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1135,7 +1135,7 @@ API int sensord_set_attribute_int(int handle, int attribute, int value) return change_attribute_int(handle, attribute, value); } -API int sensord_set_attribute_str(int handle, int attribute, const char *value, int value_len) +API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len) { sensor_id_t sensor_id; command_channel *cmd_channel; @@ -1154,22 +1154,22 @@ API int sensord_set_attribute_str(int handle, int attribute, const char *value, return -EPERM; } - retvm_if((value_len < 0) || (value == NULL), -EINVAL, + retvm_if((len < 0) || (value == NULL), -EINVAL, "Invalid value_len: %d, value: %#x, handle: %d, %s, %s", - value_len, value, handle, get_sensor_name(sensor_id), get_client_name()); + len, value, handle, get_sensor_name(sensor_id), get_client_name()); client_id = sensor_client_info::get_instance().get_client_id(); retvm_if((client_id < 0), -EPERM, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name()); - if (!cmd_channel->cmd_set_attribute_str(attribute, value, value_len)) { + if (!cmd_channel->cmd_set_attribute_str(attribute, value, len)) { _E("Sending cmd_set_attribute_str(%d, %d, %#x) failed for %s", - client_id, value_len, value, get_client_name()); + client_id, len, value, get_client_name()); return -EPERM; } - sensor_client_info::get_instance().set_attribute(handle, attribute, value, value_len); + sensor_client_info::get_instance().set_attribute(handle, attribute, value, len); return OP_SUCCESS; } diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp index 743cd29..2a755aa 100644 --- a/src/client/sensor_client_info.cpp +++ b/src/client/sensor_client_info.cpp @@ -682,7 +682,7 @@ bool sensor_client_info::set_attribute(int handle, int attribute, int value) return true; } -bool sensor_client_info::set_attribute(int handle, int attribute, const char *value, int value_len) +bool sensor_client_info::set_attribute(int handle, int attribute, const char *value, int len) { AUTOLOCK(m_handle_info_lock); @@ -693,17 +693,17 @@ bool sensor_client_info::set_attribute(int handle, int attribute, const char *va return false; } - auto it_attribute = it_handle->second.attributes_str.find(attribute); + auto it_attr = it_handle->second.attributes_str.find(attribute); - if (it_attribute != it_handle->second.attributes_str.end()) { - it_attribute->second->set(value, value_len); + if (it_attr != it_handle->second.attributes_str.end()) { + it_attr->second->set(value, len); return true; } attribute_info *info = new(std::nothrow) attribute_info(); retvm_if(!info, false, "Failed to allocate memory"); - info->set(value, value_len); + info->set(value, len); it_handle->second.attributes_str[attribute] = info; return true; diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h index 905d682..15f2677 100644 --- a/src/client/sensor_client_info.h +++ b/src/client/sensor_client_info.h @@ -66,7 +66,7 @@ public: bool set_passive_mode(int handle, bool passive); bool set_attribute(int handle, int attribute, int value); - bool set_attribute(int handle, int attribute, const char *value, int value_len); + bool set_attribute(int handle, int attribute, const char *value, int len); bool set_sensor_pause_policy(int handle, int pause_policy); bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency); diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp index 9f2d562..5f10930 100644 --- a/src/client/sensor_handle_info.cpp +++ b/src/client/sensor_handle_info.cpp @@ -40,15 +40,17 @@ attribute_info::~attribute_info() m_len = 0; } -bool attribute_info::set(const char *value, unsigned int len) +bool attribute_info::set(const char *value, int len) { + retvm_if(len < 0, false, "Invalid length"); + if (m_attr) delete m_attr; m_attr = new(std::nothrow) char[len]; retvm_if(!m_attr, false, "Failed to allocate memory"); - memcpy(m_attr, value, len); + memcpy(m_attr, value, (unsigned int)len); m_len = len; return true; @@ -142,10 +144,10 @@ bool sensor_handle_info::delete_reg_event_info(unsigned int event_type) void sensor_handle_info::clear(void) { - sensor_attribute_str_map::iterator it_attribute; + sensor_attribute_str_map::iterator it_attr; - for (it_attribute = attributes_str.begin(); it_attribute != attributes_str.end(); ++it_attribute) - delete it_attribute->second; + for (it_attr = attributes_str.begin(); it_attr != attributes_str.end(); ++it_attr) + delete it_attr->second; attributes_int.clear(); attributes_str.clear(); diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h index 70cf5c9..6ede304 100644 --- a/src/client/sensor_handle_info.h +++ b/src/client/sensor_handle_info.h @@ -34,7 +34,7 @@ public: ~attribute_info(); char *get(void); - bool set(const char *value, unsigned int len); + bool set(const char *value, int len); unsigned int size(void); diff --git a/src/server/external_sensor_worker.cpp b/src/server/external_sensor_worker.cpp index 67bb4d7..f62dc28 100644 --- a/src/server/external_sensor_worker.cpp +++ b/src/server/external_sensor_worker.cpp @@ -95,7 +95,6 @@ bool external_sensor_worker::working(void *ctx) ret = inst->dispatch_command(header.cmd, payload); delete[] payload; - return ret; } -- 2.7.4 From 6539d695b404d2ed28ef98de06bbce13039e0f26 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 21:03:25 +0900 Subject: [PATCH 03/16] sensord: add sensorctl instead of original sensor-test - this sensorctl is an initial version for the sync, it will be updated to the latest version as soon as possible. Change-Id: Ie532efaecf73fc742810c9b6ce53085ac8e75817 Signed-off-by: kibak.yoon --- CMakeLists.txt | 2 +- packaging/sensord.spec | 6 +- src/sensorctl/CMakeLists.txt | 28 +++ src/sensorctl/dbus_util.cpp | 107 ++++++++ src/sensorctl/dbus_util.h | 30 +++ src/sensorctl/info_manager.cpp | 94 +++++++ src/sensorctl/info_manager.h | 34 +++ src/sensorctl/injector.h | 32 +++ src/sensorctl/injector_context_orientation.cpp | 58 +++++ src/sensorctl/injector_context_orientation.h | 32 +++ src/sensorctl/injector_manager.cpp | 130 ++++++++++ src/sensorctl/injector_manager.h | 58 +++++ src/sensorctl/injector_wrist_up_algo.cpp | 77 ++++++ src/sensorctl/injector_wrist_up_algo.h | 33 +++ src/sensorctl/injector_wrist_up_conf.cpp | 59 +++++ src/sensorctl/injector_wrist_up_conf.h | 34 +++ src/sensorctl/loopback_manager.cpp | 99 ++++++++ src/sensorctl/loopback_manager.h | 33 +++ src/sensorctl/sensor_manager.cpp | 115 +++++++++ src/sensorctl/sensor_manager.h | 32 +++ src/sensorctl/sensorctl.cpp | 100 ++++++++ src/sensorctl/sensorctl_log.h | 49 ++++ src/sensorctl/tester.h | 28 +++ src/sensorctl/tester_manager.cpp | 79 ++++++ src/sensorctl/tester_manager.h | 32 +++ src/sensorctl/tester_sensor.cpp | 151 +++++++++++ src/sensorctl/tester_sensor.h | 34 +++ src/test/CMakeLists.txt | 49 ---- src/test/src/api-test.c | 271 -------------------- src/test/src/check-sensor.c | 333 ------------------------- src/test/src/check-sensor.h | 38 --- src/test/src/fusion-data-collection.c | 129 ---------- src/test/src/multi-process-performance-test.c | 117 --------- src/test/src/multi-thread-performance-test.c | 114 --------- src/test/src/sensor-test.c | 230 ----------------- 35 files changed, 1560 insertions(+), 1287 deletions(-) create mode 100644 src/sensorctl/CMakeLists.txt create mode 100644 src/sensorctl/dbus_util.cpp create mode 100644 src/sensorctl/dbus_util.h create mode 100644 src/sensorctl/info_manager.cpp create mode 100644 src/sensorctl/info_manager.h create mode 100644 src/sensorctl/injector.h create mode 100644 src/sensorctl/injector_context_orientation.cpp create mode 100644 src/sensorctl/injector_context_orientation.h create mode 100644 src/sensorctl/injector_manager.cpp create mode 100644 src/sensorctl/injector_manager.h create mode 100644 src/sensorctl/injector_wrist_up_algo.cpp create mode 100644 src/sensorctl/injector_wrist_up_algo.h create mode 100644 src/sensorctl/injector_wrist_up_conf.cpp create mode 100644 src/sensorctl/injector_wrist_up_conf.h create mode 100644 src/sensorctl/loopback_manager.cpp create mode 100644 src/sensorctl/loopback_manager.h create mode 100644 src/sensorctl/sensor_manager.cpp create mode 100644 src/sensorctl/sensor_manager.h create mode 100644 src/sensorctl/sensorctl.cpp create mode 100644 src/sensorctl/sensorctl_log.h create mode 100644 src/sensorctl/tester.h create mode 100644 src/sensorctl/tester_manager.cpp create mode 100644 src/sensorctl/tester_manager.h create mode 100644 src/sensorctl/tester_sensor.cpp create mode 100644 src/sensorctl/tester_sensor.h delete mode 100644 src/test/CMakeLists.txt delete mode 100644 src/test/src/api-test.c delete mode 100644 src/test/src/check-sensor.c delete mode 100644 src/test/src/check-sensor.h delete mode 100644 src/test/src/fusion-data-collection.c delete mode 100644 src/test/src/multi-process-performance-test.c delete mode 100644 src/test/src/multi-thread-performance-test.c delete mode 100644 src/test/src/sensor-test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 591edb4..bf31fa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,4 +17,4 @@ ADD_SUBDIRECTORY(src/server) ADD_SUBDIRECTORY(src/client) ADD_SUBDIRECTORY(src/shared) ADD_SUBDIRECTORY(src/hal) -ADD_SUBDIRECTORY(src/test) +ADD_SUBDIRECTORY(src/sensorctl) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index b1439b8..bb1cd3f 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -123,9 +123,5 @@ ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 %files -n sensor-test %defattr(-,root,root,-) -%{_bindir}/api-test -%{_bindir}/sensor-test -%{_bindir}/multi-thread-performance-test -%{_bindir}/multi-process-performance-test -%{_bindir}/fusion-data-collection +%{_bindir}/sensorctl %license LICENSE.APLv2 diff --git a/src/sensorctl/CMakeLists.txt b/src/sensorctl/CMakeLists.txt new file mode 100644 index 0000000..1accf2a --- /dev/null +++ b/src/sensorctl/CMakeLists.txt @@ -0,0 +1,28 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sensorctl CXX) +INCLUDE(GNUInstallDirs) + +SET(DEPS glib-2.0 gio-2.0) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED ${DEPS}) + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/src/hal/ + ${CMAKE_SOURCE_DIR}/src/client/ + ${CMAKE_SOURCE_DIR}/src/shared/ +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") + +# Installing files +FILE(GLOB_RECURSE SRCS *.cpp) +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} sensor) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/) diff --git a/src/sensorctl/dbus_util.cpp b/src/sensorctl/dbus_util.cpp new file mode 100644 index 0000000..886872e --- /dev/null +++ b/src/sensorctl/dbus_util.cpp @@ -0,0 +1,107 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include + +static GDBusConnection *connection; + +bool dbus_init(void) +{ + GError *error = NULL; + gchar *gaddr; + + if (connection) + return true; + +#ifndef GLIB_VERSION_2_36 + g_type_init(); +#endif + + gaddr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + + if (!gaddr) { + PRINT("ERROR: Failed to get dbus address : %s", error->message); + g_error_free(error); + error = NULL; + return false; + } + + connection = g_dbus_connection_new_for_address_sync(gaddr, + (GDBusConnectionFlags)(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT + | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION), + NULL, NULL, &error); + g_free(gaddr); + + if (!connection) { + PRINT("ERROR: Failed to get dbus connection : %s", error->message); + g_error_free(error); + error = NULL; + return false; + } + + PRINT("G-DBUS connected[%s]\n", + g_dbus_connection_get_unique_name(connection)); + return true; +} + +bool dbus_fini(void) +{ + if (!connection) + return true; + + g_dbus_connection_close_sync(connection, NULL, NULL); + g_object_unref(connection); + connection = NULL; + + return true; +} + +bool dbus_emit_signal(gchar *dest_bus_name, gchar *object_path, + gchar *interface_name, gchar *signal_name, + GVariant *variant, GError **error) +{ + g_dbus_connection_emit_signal(connection, + dest_bus_name, + object_path, + interface_name, + signal_name, + variant, + error); + return true; +} + +GVariant *make_variant_int(int count, char *options[]) +{ + switch (count) { + case 1: + return g_variant_new("(i)", atoi(options[0])); + case 2: + return g_variant_new("(ii)", atoi(options[0]), atoi(options[1])); + case 3: + return g_variant_new("(iii)", atoi(options[0]), atoi(options[1]), atoi(options[2])); + default: + break; + } + + return NULL; +} + diff --git a/src/sensorctl/dbus_util.h b/src/sensorctl/dbus_util.h new file mode 100644 index 0000000..a51d903 --- /dev/null +++ b/src/sensorctl/dbus_util.h @@ -0,0 +1,30 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _DBUS_UTIL_H_ + +#include +#include + +bool dbus_init(void); +bool dbus_fini(void); +bool dbus_emit_signal(gchar *dest_bus_name, gchar *object_path, + gchar *interface_name, gchar *signal_name, + GVariant *variant, GError **error); +GVariant *make_variant_int(int count, char *options[]); diff --git a/src/sensorctl/info_manager.cpp b/src/sensorctl/info_manager.cpp new file mode 100644 index 0000000..676bc40 --- /dev/null +++ b/src/sensorctl/info_manager.cpp @@ -0,0 +1,94 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include "info_manager.h" + +bool info_manager::process(int argc, char *argv[]) +{ + sensor_type_t type; + + if (argc == 2) { + usage(); + return false; + } + + type = get_sensor_type(argv[2]); + if (type == UNKNOWN_SENSOR) + return false; + + sensor_t *sensors; + int count; + + sensord_get_sensor_list(type, &sensors, &count); + sensor_info(sensors, count); + + free(sensors); + return true; +} + +void info_manager::sensor_info(sensor_t *sensors, int count) +{ + sensor_t sensor; + char *vendor; + char *name; + float min_range; + float max_range; + float resolution; + int min_interval; + int fifo_count; + int max_batch_count; + + for (int i = 0; i < count; ++i) { + sensor = sensors[i]; + + name = const_cast(sensord_get_name(sensor)); + vendor = const_cast(sensord_get_vendor(sensor)); + sensord_get_max_range(sensor, &max_range); + sensord_get_min_range(sensor, &min_range); + sensord_get_resolution(sensor, &resolution); + sensord_get_min_interval(sensor, &min_interval); + sensord_get_fifo_count(sensor, &fifo_count); + sensord_get_max_batch_count(sensor, &max_batch_count); + + PRINT("-------sensor[%d] information-------\n", i); + PRINT("vendor : %s\n", vendor); + PRINT("name : %s\n", name); + PRINT("min_range : %f\n", min_range); + PRINT("max_range : %f\n", max_range); + PRINT("resolution : %f\n", resolution); + PRINT("min_interval : %d\n", min_interval); + PRINT("fifo_count : %d\n", fifo_count); + PRINT("max_batch_count : %d\n", max_batch_count); + PRINT("--------------------------------\n"); + } +} + +void info_manager::usage(void) +{ + PRINT("usage: sensorctl info \n"); + PRINT("\n"); + + usage_sensors(); +} + diff --git a/src/sensorctl/info_manager.h b/src/sensorctl/info_manager.h new file mode 100644 index 0000000..b71dfc0 --- /dev/null +++ b/src/sensorctl/info_manager.h @@ -0,0 +1,34 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _INFO_MANAGER_H_ + +#include +#include "sensor_manager.h" + +class info_manager : public sensor_manager { +public: + info_manager() {} + virtual ~info_manager() {} + + bool process(int argc, char *argv[]); +private: + void sensor_info(sensor_t *sensors, int count); + void usage(void); +}; diff --git a/src/sensorctl/injector.h b/src/sensorctl/injector.h new file mode 100644 index 0000000..f9e8b40 --- /dev/null +++ b/src/sensorctl/injector.h @@ -0,0 +1,32 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _INJECTOR_H_ + +#include + +#define SENSORD_BUS_NAME "org.tizen.system.sensord" +#define SENSORD_OBJ_PATH "/Org/Tizen/System/SensorD" +#define SENSORD_INTERFACE_NAME "org.tizen.system.sensord" + +class injector_interface { +public: + virtual bool init(void) { return true; } + virtual bool inject(int option_count, char *options[]) = 0; +}; diff --git a/src/sensorctl/injector_context_orientation.cpp b/src/sensorctl/injector_context_orientation.cpp new file mode 100644 index 0000000..863b901 --- /dev/null +++ b/src/sensorctl/injector_context_orientation.cpp @@ -0,0 +1,58 @@ +/* + * sensorctl + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include "dbus_util.h" +#include "injector_manager.h" +#include "injector_context_orientation.h" + +#define CONTEXT_ORIENTATION_SIGNAL "orientation" + +bool injector_context_orientation::inject(int option_count, char *options[]) +{ + GVariant *variant; + + if (option_count == 0) { + _E("ERROR: invalid argument\n"); + return false; + } + + variant = make_variant_int(option_count, options); + + if (variant == NULL) + return false; + + dbus_emit_signal(NULL, + (gchar *)SENSORD_OBJ_PATH, + (gchar *)SENSORD_INTERFACE_NAME, + (gchar *)CONTEXT_ORIENTATION_SIGNAL, + variant, + NULL); + + PRINT("set options to context: \n"); + for (int i = 0; i < option_count; ++i) + PRINT("option %d: %s\n", i, options[i]); + + return true; +} + +REGISTER_INJECTOR(CONTEXT_SENSOR, CONTEXT_ORIENTATION_SIGNAL, injector_context_orientation) diff --git a/src/sensorctl/injector_context_orientation.h b/src/sensorctl/injector_context_orientation.h new file mode 100644 index 0000000..01d2d18 --- /dev/null +++ b/src/sensorctl/injector_context_orientation.h @@ -0,0 +1,32 @@ +/* + * sensorctl + * + * 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. + * + */ + +#pragma once // _CONTEXT_INJECTOR_H_ + +#include +#include +#include "injector.h" + +class injector_context_orientation: public injector_interface { +public: + injector_context_orientation() {} + virtual ~injector_context_orientation() {} + + bool inject(int option_count, char *options[]); +}; diff --git a/src/sensorctl/injector_manager.cpp b/src/sensorctl/injector_manager.cpp new file mode 100644 index 0000000..4f6b722 --- /dev/null +++ b/src/sensorctl/injector_manager.cpp @@ -0,0 +1,130 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include "dbus_util.h" +#include "injector.h" +#include "injector_manager.h" + +#define NAME_MAX_TEST 32 +#define ARGC_BASE 4 /* e.g. {sensorctl, inject, wristup, conf} */ + +static std::vector injector_infos; + +injector_manager::injector_manager() +{ + if (!dbus_init()) { + _E("Failed to init dbus"); + throw; + } +} + +injector_manager::~injector_manager() +{ + dbus_fini(); +} + +bool injector_manager::register_injector(injector_info info) +{ + injector_infos.push_back(info); + return true; +} + +injector_interface *injector_manager::get_injector(sensor_type_t type, const char *name) +{ + int injector_count; + injector_count = injector_infos.size(); + + for (int i = 0; i < injector_count; ++i) { + if (type == injector_infos[i].type && + !strcmp(injector_infos[i].name, name)) + return injector_infos[i].injector; + } + return NULL; +} + +bool injector_manager::process(int argc, char *argv[]) +{ + int option_count; + char *options[8]; + bool result; + sensor_type_t type; + char *event_name; + int i; + + if (argc < 4) { + usage(); + return false; + } + + /* 1. get sensor type */ + type = get_sensor_type(argv[2]); + if (type == UNKNOWN_SENSOR) { + _E("ERROR : failed to process injector\n"); + return false; + } + + /* 2. set up injector */ + event_name = argv[3]; + + injector_interface *injector = get_injector(type, event_name); + if (injector == NULL) { + _E("ERROR: cannot find matched injector\n"); + return false; + } + + /* 3. init injector */ + result = injector->init(); + if (!result) { + _E("ERROR: failed to init injector\n"); + return false; + } + + /* 4. inject event with options */ + option_count = argc - ARGC_BASE; + for (i = 0; i < option_count; ++i) { + options[i] = new char[NAME_MAX_TEST]; + strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + } + + result = injector->inject(option_count, options); + if (!result) { + _E("ERROR : failed to process injector\n"); + for (i = 0; i < option_count; ++i) + delete [] options[i]; + + return false; + } + + for (i = 0; i < option_count; ++i) + delete [] options[i]; + + return true; +} + +void injector_manager::usage(void) +{ + PRINT("usage: sensorctl inject [] []\n\n"); + + usage_sensors(); +} + diff --git a/src/sensorctl/injector_manager.h b/src/sensorctl/injector_manager.h new file mode 100644 index 0000000..380c486 --- /dev/null +++ b/src/sensorctl/injector_manager.h @@ -0,0 +1,58 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _INJECT_MANAGER_H_ + +#include +#include +#include "injector.h" +#include "sensor_manager.h" + +#define REGISTER_INJECTOR(sensor_type, sensor_name, injector_type) \ +static void __attribute__((constructor)) reg_injector(void) \ +{ \ + struct injector_info info; \ + info.type = (sensor_type); \ + info.name = (sensor_name); \ + info.injector = new(std::nothrow) (injector_type)(); \ + if (!info.injector) { \ + _E("ERROR: Failed to allocate memory(%s)", #injector_type); \ + return; \ + } \ + injector_manager::register_injector(info); \ +} + +struct injector_info { + sensor_type_t type; + const char *name; + injector_interface *injector; +}; + +class injector_manager : public sensor_manager { +public: + injector_manager(); + virtual ~injector_manager(); + + bool process(int argc, char *argv[]); + + static bool register_injector(injector_info info); +private: + injector_interface *get_injector(sensor_type_t type, const char *name); + void usage(void); +}; diff --git a/src/sensorctl/injector_wrist_up_algo.cpp b/src/sensorctl/injector_wrist_up_algo.cpp new file mode 100644 index 0000000..766e6ec --- /dev/null +++ b/src/sensorctl/injector_wrist_up_algo.cpp @@ -0,0 +1,77 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "dbus_util.h" +#include "injector_manager.h" +#include "injector_wrist_up_algo.h" + +#define WRIST_UP_ALGO_SIGNAL "algo" +#define OPTION_INDEX 0 + +typedef std::map option_map_t; +static option_map_t option_map; + +bool injector_wrist_up_algo::init(void) +{ + option_map.insert(option_map_t::value_type("auto", 0)); + option_map.insert(option_map_t::value_type("green", 1)); + option_map.insert(option_map_t::value_type("purple", 2)); + option_map.insert(option_map_t::value_type("red", 3)); + + return true; +} + +bool injector_wrist_up_algo::inject(int option_count, char *options[]) +{ + int option; + + if (option_count == 0) { + _E("ERROR: invalid argument\n"); + return false; + } + + option_map_t::iterator it; + it = option_map.find(options[OPTION_INDEX]); + + if (it == option_map.end()) { + _E("ERROR: no matched-option: %s\n", options[OPTION_INDEX]); + return false; + } + + option = it->second; + + dbus_emit_signal(NULL, + (gchar *)SENSORD_OBJ_PATH, + (gchar *)SENSORD_INTERFACE_NAME, + (gchar *)WRIST_UP_ALGO_SIGNAL, + g_variant_new("(i)", option), + NULL); + + _I("set [%s] mode to wristup (%d)", options[OPTION_INDEX], option); + return true; +} + +REGISTER_INJECTOR(MOTION_SENSOR, "algo", injector_wrist_up_algo) diff --git a/src/sensorctl/injector_wrist_up_algo.h b/src/sensorctl/injector_wrist_up_algo.h new file mode 100644 index 0000000..a5bd6fe --- /dev/null +++ b/src/sensorctl/injector_wrist_up_algo.h @@ -0,0 +1,33 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _WRISTUP_INJECTOR_H_ + +#include +#include +#include "injector.h" + +class injector_wrist_up_algo: public injector_interface { +public: + injector_wrist_up_algo() {} + virtual ~injector_wrist_up_algo() {} + + bool init(void); + bool inject(int option_count, char *options[]); +}; diff --git a/src/sensorctl/injector_wrist_up_conf.cpp b/src/sensorctl/injector_wrist_up_conf.cpp new file mode 100644 index 0000000..11e7a2f --- /dev/null +++ b/src/sensorctl/injector_wrist_up_conf.cpp @@ -0,0 +1,59 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include "dbus_util.h" +#include "injector_manager.h" +#include "injector_wrist_up_conf.h" + +#define WRIST_UP_CONF_SIGNAL "conf" + +bool injector_wrist_up_conf::inject(int option_count, char *options[]) +{ + GVariant *variant; + + if (option_count == 0) { + _E("ERROR: invalid argument\n"); + return false; + } + + variant = make_variant_int(option_count, options); + + if (variant == NULL) + return false; + + dbus_emit_signal(NULL, + (gchar *)SENSORD_OBJ_PATH, + (gchar *)SENSORD_INTERFACE_NAME, + (gchar *)WRIST_UP_CONF_SIGNAL, + variant, + NULL); + + PRINT("set options to wristup: \n"); + for (int i = 0; i < option_count; ++i) + PRINT("option %d: %s\n", i, options[i]); + + return true; +} + +REGISTER_INJECTOR(MOTION_SENSOR, "conf", injector_wrist_up_conf) + diff --git a/src/sensorctl/injector_wrist_up_conf.h b/src/sensorctl/injector_wrist_up_conf.h new file mode 100644 index 0000000..93b75f4 --- /dev/null +++ b/src/sensorctl/injector_wrist_up_conf.h @@ -0,0 +1,34 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _WRISTUP_INJECTOR_H_ + +#include +#include +#include "injector.h" + +#define NAME_MAX_TEST 32 + +class injector_wrist_up_conf: public injector_interface { +public: + injector_wrist_up_conf() {} + virtual ~injector_wrist_up_conf() {} + + bool inject(int option_count, char *options[]); +}; diff --git a/src/sensorctl/loopback_manager.cpp b/src/sensorctl/loopback_manager.cpp new file mode 100644 index 0000000..4b78007 --- /dev/null +++ b/src/sensorctl/loopback_manager.cpp @@ -0,0 +1,99 @@ +/* + * sensorctl + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include "loopback_manager.h" + +#define SHUB_INST_LIB_ADD ((char)-79) +#define SHUB_INST_LIB_REMOVE ((char)-78) +#define SHUB_LOOP_BACK_LIB 12 +#define DEFAULT_COMMAND_SIZE 3 +#define MAX_COMMAND_SIZE 82 +#define MAX_DATA_SIZE 84 /* -79, 12, 4byte Delaytime + 78 bytes data */ + +static void int_to_bytes(int32_t value, int length, char cmd[]) +{ + /* Convert to Big-endian */ + for (int i = length - 1; i >= 0; i--) { + cmd[i] = (value & 0xff); + value = value >> 8; + } +} + +bool loopback_manager::process(int argc, char *argv[]) +{ + sensor_type_t type; + + if (argc < DEFAULT_COMMAND_SIZE || argc > MAX_COMMAND_SIZE) { + usage(); + return false; + } + + if (!strcmp(argv[2], "start")) { + int handle; + sensor_t sensor; + sensor = sensord_get_sensor(CONTEXT_SENSOR); + handle = sensord_connect(sensor); + + /* + * sensorhub (bytes) command [0~1] delaytime [2~5] data[6~83] + * shell (argv) command [0~2] delaytime [3] data[4~81] + */ + char test_data[MAX_DATA_SIZE] = {SHUB_INST_LIB_ADD, SHUB_LOOP_BACK_LIB,}; + int_to_bytes(atoi(argv[3]), sizeof(int), &(test_data[2])); + + for (int i = 4; i < argc; i++) + test_data[i+2] = atoi(argv[i]); + + sensord_set_attribute_str(handle, 0, test_data, sizeof(test_data)); + sensord_disconnect(handle); + return true; + } + + if (!strcmp(argv[2], "stop")) { + int handle; + sensor_t sensor; + sensor = sensord_get_sensor(CONTEXT_SENSOR); + handle = sensord_connect(sensor); + + char test_data[4] = {SHUB_INST_LIB_REMOVE, SHUB_LOOP_BACK_LIB,}; + + sensord_set_attribute_str(handle, 0, test_data, sizeof(test_data)); + sensord_disconnect(handle); + return true; + } + + usage(); + + return false; +} + +void loopback_manager::usage(void) +{ + PRINT("usage: sensorctl loopback [start/stop] [14byte sensor char data]\n"); + PRINT("ex: sensorctl loopback start 15000 1 1 19 1 (after 15000ms, wrist up event)\n"); + PRINT("ex: sensorctl loopback stop\n"); + PRINT(" * if not enought 14byte, remain bytes are filled with 0\n"); + PRINT("\n"); +} + diff --git a/src/sensorctl/loopback_manager.h b/src/sensorctl/loopback_manager.h new file mode 100644 index 0000000..2aa3297 --- /dev/null +++ b/src/sensorctl/loopback_manager.h @@ -0,0 +1,33 @@ +/* + * sensorctl + * + * 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. + * + */ + +#pragma once // _LOOPBACK_MANAGER_H_ + +#include +#include "sensor_manager.h" + +class loopback_manager : public sensor_manager { +public: + loopback_manager() {} + virtual ~loopback_manager() {} + + bool process(int argc, char *argv[]); +private: + void usage(void); +}; diff --git a/src/sensorctl/sensor_manager.cpp b/src/sensorctl/sensor_manager.cpp new file mode 100644 index 0000000..ce2e4ef --- /dev/null +++ b/src/sensorctl/sensor_manager.cpp @@ -0,0 +1,115 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include "sensor_manager.h" + +#define NAME_MAX_TEST 32 + +struct sensor_info { + sensor_type_t type; + char name[NAME_MAX_TEST]; +}; + +static struct sensor_info sensor_infos[] = { + {ALL_SENSOR, "all"}, + + // General Sensors + {ACCELEROMETER_SENSOR, "accelerometer"}, + {GEOMAGNETIC_SENSOR, "magnetic"}, + {LIGHT_SENSOR, "light"}, + {PROXIMITY_SENSOR, "proximity"}, + {GYROSCOPE_SENSOR, "gyroscope"}, + {PRESSURE_SENSOR, "pressure"}, + {BIO_SENSOR, "bio"}, + {BIO_HRM_SENSOR, "hrm"}, + {AUTO_ROTATION_SENSOR, "auto_rotation"}, + {GRAVITY_SENSOR, "gravity"}, + {LINEAR_ACCEL_SENSOR, "linear_accel"}, + {ROTATION_VECTOR_SENSOR, "rotation_vector"}, + {ORIENTATION_SENSOR, "orientation"}, + {TEMPERATURE_SENSOR, "temperature"}, + {HUMIDITY_SENSOR, "humidity"}, + {ULTRAVIOLET_SENSOR, "ultraviolet"}, + {BIO_LED_GREEN_SENSOR, "hrm_led_green"}, + {BIO_LED_IR_SENSOR, "hrm_led_ir"}, + {BIO_LED_RED_SENSOR, "hrm_led_red"}, + {GYROSCOPE_UNCAL_SENSOR, "gyro_uncal"}, + {GEOMAGNETIC_UNCAL_SENSOR, "mag_uncal"}, + {GYROSCOPE_RV_SENSOR, "gyro_rv"}, + {GEOMAGNETIC_RV_SENSOR, "mag_rv"}, + /* If WRIST_UP_SENSOR is created, it has to be changed to WRIST_UP_SENSOR */ + {MOTION_SENSOR, "motion"}, + {CONTEXT_SENSOR, "context"}, + {EXERCISE_SENSOR, "exercise"}, + {GESTURE_WRIST_UP_SENSOR, "wristup"}, +}; + +bool sensor_manager::process(int argc, char *argv[]) +{ + return false; +} + +void sensor_manager::usage_sensors(void) +{ + PRINT("The sensor types are:\n"); + int sensor_count = ARRAY_SIZE(sensor_infos); + + for (int i = 0; i < sensor_count; ++i) + PRINT(" %d: %s(%d)\n", i, sensor_infos[i].name, sensor_infos[i].type); + PRINT("\n"); +} + +sensor_type_t sensor_manager::get_sensor_type(char *name) +{ + int index; + int sensor_count = ARRAY_SIZE(sensor_infos); + + for (index = 0; index < sensor_count; ++index) { + if (!strcmp(sensor_infos[index].name, name)) + break; + } + + if (index == sensor_count) { + _E("ERROR: sensor name is wrong\n"); + usage_sensors(); + return UNKNOWN_SENSOR; + } + return sensor_infos[index].type; +} + +const char *sensor_manager::get_sensor_name(sensor_type_t type) +{ + int index; + int sensor_count = ARRAY_SIZE(sensor_infos); + + for (index = 0; index < sensor_count; ++index) { + if (sensor_infos[index].type == type) + break; + } + + if (index == sensor_count) { + _E("ERROR: sensor name is wrong\n"); + usage_sensors(); + return "UNKNOWN SENSOR"; + } + return sensor_infos[index].name; +} diff --git a/src/sensorctl/sensor_manager.h b/src/sensorctl/sensor_manager.h new file mode 100644 index 0000000..9fd3476 --- /dev/null +++ b/src/sensorctl/sensor_manager.h @@ -0,0 +1,32 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _SENSOR_MANAGER_H_ + +#include + +class sensor_manager { +public: + virtual bool process(int argc, char *argv[]); +protected: + void usage_sensors(void); + + sensor_type_t get_sensor_type(char *name); + const char * get_sensor_name(sensor_type_t type); +}; diff --git a/src/sensorctl/sensorctl.cpp b/src/sensorctl/sensorctl.cpp new file mode 100644 index 0000000..aa4543e --- /dev/null +++ b/src/sensorctl/sensorctl.cpp @@ -0,0 +1,100 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include + +#include +#include "sensor_manager.h" +#include "tester_manager.h" +#include "injector_manager.h" +#include "info_manager.h" +#include "loopback_manager.h" + +static void good_bye(void) +{ +} + +static void signal_handler(int signo) +{ + _E("\nReceived SIGNAL(%d)\n", signo); + exit(EXIT_SUCCESS); + + return; +} + +void usage(void) +{ + PRINT("usage: sensorctl []\n"); + + PRINT("The sensorctl commands are:\n"); + PRINT(" test: test sensor(s)\n"); + PRINT(" inject: inject the event to sensor\n"); + PRINT(" info: show sensor infos\n"); + PRINT(" loopback: sensor loopback test\n"); +} + +sensor_manager *create_manager(int argc, char *argv[2]) +{ + sensor_manager *manager = NULL; + + if (!strcmp(argv[1], "test")) + manager = new(std::nothrow) tester_manager; + if (!strcmp(argv[1], "inject")) + manager = new(std::nothrow) injector_manager; + if (!strcmp(argv[1], "info")) + manager = new(std::nothrow) info_manager; + if (!strcmp(argv[1], "loopback")) + manager = new(std::nothrow) loopback_manager; + + if (!manager) { + _E("failed to allocate memory for manager"); + return NULL; + } + + return manager; +} + +int main(int argc, char *argv[]) +{ + atexit(good_bye); + + signal(SIGINT, signal_handler); + signal(SIGHUP, signal_handler); + signal(SIGTERM, signal_handler); + signal(SIGQUIT, signal_handler); + signal(SIGABRT, signal_handler); + + if (argc < 2) { + usage(); + return 0; + } + + sensor_manager *manager = create_manager(argc, argv); + if (!manager) { + usage(); + return 0; + } + + manager->process(argc, argv); + + return 0; +} diff --git a/src/sensorctl/sensorctl_log.h b/src/sensorctl/sensorctl_log.h new file mode 100644 index 0000000..f5f8f25 --- /dev/null +++ b/src/sensorctl/sensorctl_log.h @@ -0,0 +1,49 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _SENSORCTL_LOG_H_ + +#include +#include + +#define KNRM "\x1B[0m" +#define KRED "\x1B[31m" +#define KGRN "\x1B[32m" +#define KYEL "\x1B[33m" +#define KBLU "\x1B[34m" +#define KMAG "\x1B[35m" +#define KCYN "\x1B[36m" +#define KWHT "\x1B[37m" +#define RESET "\033[0m" + +#define PRINT(fmt, args...) \ + do { \ + g_print(fmt, ##args); \ + } while (0) + +#define _E(fmt, args...) \ + do { \ + g_print("\x1B[31m" fmt "\033[0m", ##args); \ + } while (0) + +#define _I(fmt, args...) \ + do { \ + g_print("\x1B[32m" fmt "\033[0m", ##args); \ + } while (0) + diff --git a/src/sensorctl/tester.h b/src/sensorctl/tester.h new file mode 100644 index 0000000..2d912c9 --- /dev/null +++ b/src/sensorctl/tester.h @@ -0,0 +1,28 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _TESTER_H_ + +#include + +class tester_interface { +public: + virtual bool init(void) = 0; + virtual bool test(sensor_type_t type, int option_count, char *options[]) = 0; +}; diff --git a/src/sensorctl/tester_manager.cpp b/src/sensorctl/tester_manager.cpp new file mode 100644 index 0000000..ffd9e57 --- /dev/null +++ b/src/sensorctl/tester_manager.cpp @@ -0,0 +1,79 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include "tester.h" +#include "tester_manager.h" +#include "tester_sensor.h" + +#define NAME_MAX_TEST 32 +#define ARGC_BASE 3 /* e.g. {sensorctl, test, accelerometer} */ + +bool tester_manager::process(int argc, char *argv[]) +{ + int option_count; + char *options[8]; + sensor_type_t type; + int i; + + if (argc == 2) { + usage(); + return false; + } + + /* 1. get sensor type */ + type = get_sensor_type(argv[2]); + if (type == UNKNOWN_SENSOR) { + _E("ERROR : failed to process injector\n"); + return false; + } + + /* 2. set up injector */ + tester_interface *tester = new tester_sensor(); + tester->init(); + + /* 3. test sensor with options */ + option_count = argc - ARGC_BASE; + for (i = 0; i < option_count; ++i) { + options[i] = new char[NAME_MAX_TEST]; + strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + } + + tester->test(type, option_count, options); + + return true; +} + +void tester_manager::usage(void) +{ + PRINT("usage: sensorctl test [interval] [event_count] [test_count]\n\n"); + + usage_sensors(); + + PRINT("interval_ms:\n"); + PRINT(" interval. default value is 100ms.\n"); + PRINT("event count(n):\n"); + PRINT(" test sensor until it gets n event. default is 999999(infinitly).\n"); + PRINT("test count(n):\n"); + PRINT(" test sensor in n times repetitively, default is 1.\n\n"); +} + diff --git a/src/sensorctl/tester_manager.h b/src/sensorctl/tester_manager.h new file mode 100644 index 0000000..16f4b16 --- /dev/null +++ b/src/sensorctl/tester_manager.h @@ -0,0 +1,32 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _TEST_MANAGER_H_ + +#include "sensor_manager.h" + +class tester_manager : public sensor_manager { +public: + tester_manager() {} + virtual ~tester_manager() {} + + bool process(int argc, char *argv[]); +private: + void usage(void); +}; diff --git a/src/sensorctl/tester_sensor.cpp b/src/sensorctl/tester_sensor.cpp new file mode 100644 index 0000000..5a75da6 --- /dev/null +++ b/src/sensorctl/tester_sensor.cpp @@ -0,0 +1,151 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include "tester_sensor.h" + +#define DEFAULT_INTERVAL 100 +#define DEFAULT_LATENCY 0 +#define DEFAULT_TEST_COUNT 1 +#define DEFAULT_EVENT_COUNT 9999 + +#define SENSOR_SHIFT_TYPE 16 + +static GMainLoop *mainloop; +static int check_loop; + +static const char *result_str(bool result) { + if (result) return KGRN"[PASS]"RESET; + else return KRED"[FAIL]"RESET; +} + +bool tester_sensor::init(void) +{ + return true; +} + +void tester_sensor::test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + sensor_type_t type; + int *cnt_event; + + sensord_get_type(sensor, &type); + + cnt_event = (int *)user_data; + + if (check_loop++ >= *cnt_event) { + if (!mainloop) + return; + + g_main_loop_quit(mainloop); + g_main_loop_unref(mainloop); + mainloop = NULL; + return; + } + + PRINT("[%llu] %s:", data->timestamp, sensord_get_name(sensor)); + + if (type == GESTURE_WRIST_UP_SENSOR) { + PRINT("[%d]\n", ((sensorhub_data_t *)data)->hub_data[0]); + return; + } + + for (int i = 0; i < data->value_count; ++i) + PRINT(" [%f]", data->values[i]); + PRINT("\n"); +} + +void tester_sensor::test_sensor(sensor_type_t type, int interval, int latency, int cnt_test, int cnt_event) +{ + bool result; + sensor_t sensor; + unsigned int event_id; + sensor_data_t data; + int handle; + int count = 0; + + event_id = type << SENSOR_SHIFT_TYPE | 0x1; + + while (count++ < cnt_test) { + mainloop = g_main_loop_new(NULL, FALSE); + check_loop = 0; + + PRINT("=======================================\n"); + PRINT("TEST(%d/%d)\n", count, cnt_test); + PRINT("=======================================\n"); + + sensor = sensord_get_sensor(type); + PRINT("%s sensord_get_sensor: sensor(%p)\n", result_str((sensor == NULL)? 0 : 1), sensor); + + handle = sensord_connect(sensor); + PRINT("%s sensord_connect: handle(%d)\n", result_str((handle >= 0)), handle); + + result = sensord_register_event(handle, event_id, interval, latency, test_cb, (void *)&cnt_event); + PRINT("%s sensord_register_event\n", result_str(result)); + + result = sensord_start(handle, 3); + PRINT("%s sensord_start\n", result_str(result)); + + result = sensord_get_data(handle, event_id, &data); + PRINT("%s sensord_get_data\n", result_str(result)); + + result = sensord_flush(handle); + PRINT("%s sensord_flush\n", result_str(result)); + + if (result) { + for (int i = 0; i < data.value_count; ++i) + PRINT("[%f] ", data.values[i]); + PRINT("\n"); + } + + g_main_loop_run(mainloop); + + result = sensord_unregister_event(handle, event_id); + PRINT("%s sensord_unregister_event: handle(%d)\n", result_str(result), handle); + result = sensord_stop(handle); + PRINT("%s sensord_stop: handle(%d)\n", result_str(result), handle); + result = sensord_disconnect(handle); + PRINT("%s sensord_disconnect: handle(%d)\n", result_str(result), handle); + } +} + +bool tester_sensor::test(sensor_type_t type, int option_count, char *options[]) +{ + int interval = DEFAULT_INTERVAL; + int latency = DEFAULT_LATENCY; + int cnt_test = DEFAULT_TEST_COUNT; + int cnt_event = DEFAULT_EVENT_COUNT; + + sensor_type_t sensor_type = type; + + if (option_count >= 1) + interval = atoi(options[0]); + if (option_count >= 2) + cnt_event = atoi(options[1]); + if (option_count >= 3) + cnt_test = atoi(options[2]); + + test_sensor(sensor_type, interval, latency, cnt_test, cnt_event); + return true; +} diff --git a/src/sensorctl/tester_sensor.h b/src/sensorctl/tester_sensor.h new file mode 100644 index 0000000..68b76b4 --- /dev/null +++ b/src/sensorctl/tester_sensor.h @@ -0,0 +1,34 @@ +/* + * sensorctl + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#pragma once // _SENSOR_TESTER_H_ + +#include "tester.h" + +class tester_sensor : public tester_interface { +public: + tester_sensor() {} + virtual ~tester_sensor() {} + + virtual bool init(void); + virtual bool test(sensor_type_t type, int option_count, char *options[]); +private: + void test_sensor(sensor_type_t type, int interval, int latency, int cnt_test, int cnt_event); + static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data); +}; diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt deleted file mode 100644 index d9e3ec9..0000000 --- a/src/test/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -project(sensor-tc C) - -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "\${prefix}") -SET(VERSION 1.0) - -INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0) - -add_definitions(${rpkgs_CFLAGS}) -add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}") - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_SOURCE_DIR}/src/client) -include_directories(${CMAKE_SOURCE_DIR}/src/shared) -include_directories(${CMAKE_SOURCE_DIR}/src/hal) - -FOREACH(flag ${pkgs_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") - -link_directories(${CMAKE_SOURCE_DIR}/src/client/) - -add_executable(api-test src/api-test.c) -add_executable(sensor-test src/sensor-test.c src/check-sensor.c) -add_executable(multi-process-performance-test src/multi-process-performance-test.c src/check-sensor.c) -add_executable(fusion-data-collection src/fusion-data-collection.c) -add_executable(multi-thread-performance-test src/multi-thread-performance-test.c src/check-sensor.c) - -SET_TARGET_PROPERTIES(api-test PROPERTIES LINKER_LANGUAGE C) -SET_TARGET_PROPERTIES(sensor-test PROPERTIES LINKER_LANGUAGE C) -SET_TARGET_PROPERTIES(multi-process-performance-test PROPERTIES LINKER_LANGUAGE C) -SET_TARGET_PROPERTIES(fusion-data-collection PROPERTIES LINKER_LANGUAGE C) -SET_TARGET_PROPERTIES(multi-thread-performance-test PROPERTIES LINKER_LANGUAGE C) - -target_link_libraries(api-test glib-2.0 dlog sensor) -target_link_libraries(sensor-test glib-2.0 dlog sensor) -target_link_libraries(multi-process-performance-test glib-2.0 dlog sensor pthread) -target_link_libraries(fusion-data-collection glib-2.0 dlog sensor) -target_link_libraries(multi-thread-performance-test glib-2.0 dlog sensor pthread) - -INSTALL(TARGETS api-test DESTINATION /usr/bin/) -INSTALL(TARGETS sensor-test DESTINATION /usr/bin/) -INSTALL(TARGETS multi-process-performance-test DESTINATION /usr/bin/) -INSTALL(TARGETS fusion-data-collection DESTINATION /usr/bin/) -INSTALL(TARGETS multi-thread-performance-test DESTINATION /usr/bin/) diff --git a/src/test/src/api-test.c b/src/test/src/api-test.c deleted file mode 100644 index 2a1ff11..0000000 --- a/src/test/src/api-test.c +++ /dev/null @@ -1,271 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DEFAULT_EVENT_INTERVAL 100 - -static GMainLoop *mainloop; -FILE *fp; - -void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - g_main_loop_quit(mainloop); -} - -bool check_sensor_api(unsigned int event_type, int cond_value) -{ - int handle; - - mainloop = g_main_loop_new(NULL, FALSE); - - sensor_type_t sensor_type = event_type >> 16; - sensor_t sensor = sensord_get_sensor(sensor_type); - - handle = sensord_connect(sensor); - - if (handle < 0) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_connect\n", sensor_type, event_type); - return false; - } - - bool is_supported; - bool result_boolean = sensord_is_supported_event_type(sensor, event_type, &is_supported); - if (!result_boolean && !is_supported) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_is_supported_event\n", sensor_type, event_type); - return false; - } - - int output; - result_boolean = sensord_get_min_interval(sensor, &output); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_min_interval\n", sensor_type, event_type); - return false; - } - - float output3; - result_boolean = sensord_get_resolution(sensor, &output3); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_resolution\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_get_max_range(sensor, &output3); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_max_range\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_get_min_range(sensor, &output3); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_min_range\n", sensor_type, event_type); - return false; - } - - sensor_privilege_t output4; - result_boolean = sensord_get_privilege(sensor, &output4); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_privilege\n", sensor_type, event_type); - return false; - } - - const char* result_char = sensord_get_vendor(sensor); - if (!result_char) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_vendor\n", sensor_type, event_type); - return false; - } - - result_char = sensord_get_name(sensor); - if (!result_char) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_name\n", sensor_type, event_type); - return false; - } - - sensor_type_t output_type; - result_boolean = sensord_get_type(sensor, &output_type); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_type\n", sensor_type, event_type); - return false; - } - - unsigned int *output2; - result_boolean = sensord_get_supported_event_types(sensor, &output2, &output); - if (!result_boolean) { - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_supported_event_types\n", sensor_type, event_type); - return false; - } - - sensor_t *output_list; - result_boolean = sensord_get_sensor_list(sensor_type, &output_list, &output); - if (!result_boolean) { - free(output2); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_sensor_list\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_register_event(handle, event_type, cond_value, 0, callback, NULL); - if (!result_boolean) { - free(output2); - free(output_list); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_register_event\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_start(handle, 1); - if (!result_boolean) { - sensord_unregister_event(handle, event_type); - sensord_disconnect(handle); - free(output2); - free(output_list); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_start\n", sensor_type, event_type); - return false; - } - - sensor_data_t data; - result_boolean = sensord_get_data(handle, event_type, &data); - if (!result_boolean) { - sensord_unregister_event(handle, event_type); - sensord_disconnect(handle); - free(output2); - free(output_list); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_get_data\n", sensor_type, event_type); - return false; - } - - g_main_loop_run(mainloop); - g_main_loop_unref(mainloop); - - result_boolean = sensord_change_event_interval(handle, event_type, 101); - if (!result_boolean) { - free(output2); - free(output_list); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_event_interval\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_set_option(handle, SENSOR_OPTION_ON_IN_SCREEN_OFF); - if (!result_boolean){ - free(output2); - free(output_list); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_change_sensor_option\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_unregister_event(handle, event_type); - if (!result_boolean) { - free(output2); - free(output_list); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_unregister_event\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_stop(handle); - if (!result_boolean) { - free(output2); - free(output_list); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_stop\n", sensor_type, event_type); - return false; - } - - result_boolean = sensord_disconnect(handle); - if (!result_boolean) { - free(output2); - free(output_list); - fprintf(fp, "Sensor - %d, event - %d, failed at sensord_disconnect\n", sensor_type, event_type); - return false; - } - - free(output2); - free(output_list); - - return true; -} - -int main(int argc, char **argv) -{ - bool result; - - int interval = DEFAULT_EVENT_INTERVAL; - if (argc == 2) - interval = atof(argv[1]); - - fp = fopen("auto_test.output", "w+"); - - result = check_sensor_api(ACCELEROMETER_RAW_DATA_EVENT, interval); - fprintf(fp, "Accelerometer - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GEOMAGNETIC_RAW_DATA_EVENT, interval); - fprintf(fp, "Geomagnetic - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GRAVITY_RAW_DATA_EVENT, interval); - fprintf(fp, "Gravity - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GYROSCOPE_RAW_DATA_EVENT, interval); - fprintf(fp, "Gyroscope - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(LIGHT_LUX_DATA_EVENT, interval); - fprintf(fp, "Light - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(LINEAR_ACCEL_RAW_DATA_EVENT, interval); - fprintf(fp, "Linear Accel - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(ORIENTATION_RAW_DATA_EVENT, interval); - fprintf(fp, "Orientation - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(TILT_RAW_DATA_EVENT, interval); - fprintf(fp, "Tilt - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(PRESSURE_RAW_DATA_EVENT, interval); - fprintf(fp, "Pressure - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(ROTATION_VECTOR_RAW_DATA_EVENT, interval); - fprintf(fp, "Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GEOMAGNETIC_RV_RAW_DATA_EVENT, interval); - fprintf(fp, "Geomagnetic Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GAMING_RV_RAW_DATA_EVENT, interval); - fprintf(fp, "Gaming Rotation Vector - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(GYROSCOPE_UNCAL_SENSOR, interval); - fprintf(fp, "Gyroscope Uncal Sensor - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(TEMPERATURE_RAW_DATA_EVENT, interval); - fprintf(fp, "Temperature - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(ULTRAVIOLET_RAW_DATA_EVENT, interval); - fprintf(fp, "ULTRAVIOLET - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(BIO_LED_RED_RAW_DATA_EVENT, interval); - fprintf(fp, "BIO_LED_RED - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - result = check_sensor_api(FACE_DOWN_RAW_DATA_EVENT, interval); - fprintf(fp, "Face Down - RAW_DATA_REPORT_ON_TIME - %d\n", result); - - printf("Logs printed in ./auto_test.output\n"); - fclose(fp); - return 0; -} diff --git a/src/test/src/check-sensor.c b/src/test/src/check-sensor.c deleted file mode 100644 index 04ea726..0000000 --- a/src/test/src/check-sensor.c +++ /dev/null @@ -1,333 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014-15 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 "check-sensor.h" - -void printpollinglogs(sensor_type_t type,sensor_data_t data) -{ - switch(type) { - case(ACCELEROMETER_SENSOR): - printf("Accelerometer [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(AUTO_ROTATION_SENSOR): - printf("Auto Rotation [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - case(GYROSCOPE_SENSOR): - printf("Gyroscope [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(PRESSURE_SENSOR): - printf("Pressure [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(GEOMAGNETIC_SENSOR): - printf("Geomagnetic [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(LIGHT_SENSOR): - printf("Light [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - case(TEMPERATURE_SENSOR): - printf("Temperature [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - case(PROXIMITY_SENSOR): - printf("Proximity [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - case(ULTRAVIOLET_SENSOR): - printf("Ultraviolet [%lld] [%6.6f]\n", data.timestamp, data.values[0]); - break; - case(BIO_LED_RED_SENSOR): - printf("Bio_LED_Red [%lld] [%6.6f]\n", data.timestamp, data.values[0]); - break; - case(ORIENTATION_SENSOR): - printf("Orientation [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(TILT_SENSOR): - printf("Tilt [%lld] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1]); - break; - case(GRAVITY_SENSOR): - printf("Gravity [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(LINEAR_ACCEL_SENSOR): - printf("Linear Acceleration [%lld] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2]); - break; - case(ROTATION_VECTOR_SENSOR): - printf("Rotation Vector [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]); - break; - case(GEOMAGNETIC_RV_SENSOR): - printf("Geomagnetic Rv [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]); - break; - case(GYROSCOPE_RV_SENSOR): - printf("Gaming Rv [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]); - break; - case(GYROSCOPE_UNCAL_SENSOR): - printf("Gyroscope Uncal [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3], data.values[4], data.values[5]); - break; - case(GESTURE_FACE_DOWN_SENSOR): - printf("Face Down [%lld] [%6.6f]\n\n", data.timestamp, data.values[0]); - break; - default: - return; - } -} - -int get_event(sensor_type_t sensor_type, char str[]) -{ - switch (sensor_type) { - case ACCELEROMETER_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return ACCELEROMETER_RAW_DATA_EVENT; - break; - case AUTO_ROTATION_SENSOR: - if (strcmp(str, "CHANGE_STATE_EVENT") == 0) - return AUTO_ROTATION_CHANGE_STATE_EVENT; - break; - case GYROSCOPE_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GYROSCOPE_RAW_DATA_EVENT; - break; - case PRESSURE_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return PRESSURE_RAW_DATA_EVENT; - break; - case GEOMAGNETIC_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GEOMAGNETIC_RAW_DATA_EVENT; - break; - case LIGHT_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return LIGHT_LUX_DATA_EVENT; - break; - case TEMPERATURE_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return TEMPERATURE_RAW_DATA_EVENT; - break; - case PROXIMITY_SENSOR: - if (strcmp(str, "CHANGE_STATE_EVENT") == 0) - return PROXIMITY_CHANGE_STATE_EVENT; - break; - case ULTRAVIOLET_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return ULTRAVIOLET_RAW_DATA_EVENT; - break; - case BIO_LED_RED_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return BIO_LED_RED_RAW_DATA_EVENT; - break; - case ORIENTATION_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return ORIENTATION_RAW_DATA_EVENT; - break; - case TILT_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return TILT_RAW_DATA_EVENT; - break; - case GRAVITY_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GRAVITY_RAW_DATA_EVENT; - break; - case LINEAR_ACCEL_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return LINEAR_ACCEL_RAW_DATA_EVENT; - break; - case ROTATION_VECTOR_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return ROTATION_VECTOR_RAW_DATA_EVENT; - break; - case GEOMAGNETIC_RV_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GEOMAGNETIC_RV_RAW_DATA_EVENT; - break; - case GYROSCOPE_RV_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GAMING_RV_RAW_DATA_EVENT; - break; - case GYROSCOPE_UNCAL_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return GYROSCOPE_UNCAL_RAW_DATA_EVENT; - break; - case GESTURE_FACE_DOWN_SENSOR: - if (strcmp(str, "RAW_DATA_EVENT") == 0) - return FACE_DOWN_RAW_DATA_EVENT; - break; - - default: - return -1; - } - return -1; -} - -void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - sensor_type_t sensor_type = event_type >> 16; - - switch (sensor_type) { - case ACCELEROMETER_SENSOR: - printf("Accelerometer [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case AUTO_ROTATION_SENSOR: - printf("Auto Rotation [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case GYROSCOPE_SENSOR: - printf("Gyroscope [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case PRESSURE_SENSOR: - printf("Pressure [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case GEOMAGNETIC_SENSOR: - printf("Geomagnetic [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case LIGHT_SENSOR: - printf("Light [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case TEMPERATURE_SENSOR : - printf("Temperature [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case PROXIMITY_SENSOR: - printf("Proximity [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case ULTRAVIOLET_SENSOR: - printf("Ultraviolet [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case BIO_LED_RED_SENSOR: - printf("Bio_LED_Red [%lld] [%6.6f]\n", data->timestamp, data->values[0]); - break; - case ORIENTATION_SENSOR : - printf("Orientation [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case TILT_SENSOR : - printf("Tilt [%lld] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1]); - break; - case GRAVITY_SENSOR: - printf("Gravity [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case LINEAR_ACCEL_SENSOR: - printf("Linear acceleration [%lld] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2]); - break; - case ROTATION_VECTOR_SENSOR: - printf("Rotation vector [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]); - break; - case GEOMAGNETIC_RV_SENSOR: - printf("Geomagnetic RV [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]); - break; - case GYROSCOPE_RV_SENSOR: - printf("Gaming RV [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]); - break; - case GYROSCOPE_UNCAL_SENSOR: - printf("Gyroscope Uncal [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3], data->values[4], data->values[5]); - break; - case GESTURE_FACE_DOWN_SENSOR: - printf("Face Down [%lld] [%6.6f] \n", data->timestamp, data->values[0]); - break; - - default: - return; - } -} - -void *check_sensor(void *arg) -{ - struct pthread_arguments * argu = (struct pthread_arguments *) arg; - - GMainLoop *mainloop; - int handle; - bool result, start_handle, stop_handle; - - mainloop = g_main_loop_new(NULL, FALSE); - - sensor_t sensor = sensord_get_sensor(argu -> sensor_type); - handle = sensord_connect(sensor); - - result = sensord_register_event(handle, argu->event, argu->interval, 0, callback, NULL); - - if (!result) { - printf("Can't register sensor\n"); - return NULL; - } - - start_handle = sensord_start(handle, 0); - - if (!start_handle) { - printf("Error\n\n\n\n"); - sensord_unregister_event(handle, argu->event); - sensord_disconnect(handle); - return NULL; - } - - g_main_loop_run(mainloop); - g_main_loop_unref(mainloop); - - result = sensord_unregister_event(handle, argu->event); - - if (!result) { - printf("Error\n\n"); - return NULL; - } - - stop_handle = sensord_stop(handle); - - if (!stop_handle) { - printf("Error\n\n"); - return NULL; - } - - sensord_disconnect(handle); - return NULL; -} - -int polling_sensor(sensor_type_t sensor_type, unsigned int event) -{ - bool result; - int handle; - - printf("Polling based\n"); - sensor_t sensor; - sensor = sensord_get_sensor(sensor_type); - handle = sensord_connect(sensor); - result = sensord_start(handle, 1); - - if (!result) { - printf("Can't start the sensor\n"); - printf("Error\n\n\n\n"); - return -1; - } - - sensor_data_t data; - - while (1) { - result = sensord_get_data(handle, event, &data); - printpollinglogs(sensor_type, data); - usleep(100000); - } - - result = sensord_disconnect(handle); - - if (!result) { - printf("Can't disconnect sensor\n"); - printf("Error\n\n\n\n"); - return -1; - } - - return 0; -} diff --git a/src/test/src/check-sensor.h b/src/test/src/check-sensor.h deleted file mode 100644 index 042dc87..0000000 --- a/src/test/src/check-sensor.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014-15 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 CHECK_SENSOR_H -#define CHECK_SENSOR_H - -#include - -#define DEFAULT_EVENT_INTERVAL 100 - -int get_event(sensor_type_t sensor_type, char str[]); -void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data); -void *check_sensor(void *arg); -void printpollinglogs(sensor_type_t type, sensor_data_t data); -int polling_sensor(sensor_type_t sensor_type, unsigned int event); - -struct pthread_arguments -{ - sensor_type_t sensor_type; - unsigned int event; - int interval; -}; -#endif diff --git a/src/test/src/fusion-data-collection.c b/src/test/src/fusion-data-collection.c deleted file mode 100644 index 6abd6f5..0000000 --- a/src/test/src/fusion-data-collection.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014-15 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 - -#define MAXSIZE 4 - -static GMainLoop *mainloop; -FILE* file_output[MAXSIZE]; - -void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - sensor_type_t sensor_type = event_type >> 16; - - switch (sensor_type) { - case ACCELEROMETER_SENSOR: - fprintf(file_output[0], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp); - fflush(file_output[0]); - break; - case GEOMAGNETIC_SENSOR: - fprintf(file_output[1], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp); - fflush(file_output[1]); - break; - case GYROSCOPE_SENSOR: - fprintf(file_output[2], "%6.6f %6.6f %6.6f %lld\n", data->values[0], data->values[1], data->values[2], data->timestamp); - fflush(file_output[2]); - break; - case PROXIMITY_SENSOR: - fprintf(file_output[MAXSIZE-1], "%6.6f %lld\n", data->values[0], data->timestamp); - fflush(file_output[MAXSIZE-1]); - break; - default: - return; - } -} - -void usage() -{ - printf("Usage : ./fusion-data-collection \n\n"); - - printf("interval:\n"); - printf("The sampling interval in ms.\n"); - exit(-1); -} - -int main(int argc, char **argv) -{ - int interval; - - if (argc == 2) { - interval = atoi(argv[1]); - if (interval <= 0) - usage(); - } - else - usage(); - - int i; - - int handle[MAXSIZE]; - bool result[MAXSIZE], start_handle[MAXSIZE]; - unsigned int event[MAXSIZE]; - int sensors[MAXSIZE]; - - sensors[0] = ACCELEROMETER_SENSOR; - sensors[1] = GEOMAGNETIC_SENSOR; - sensors[2] = GYROSCOPE_SENSOR; - sensors[MAXSIZE-1] = PROXIMITY_SENSOR; - - mainloop = g_main_loop_new(NULL, FALSE); - - char file_name[50]; - - for (i = 0; i < MAXSIZE; i++) { - snprintf(file_name, sizeof(file_name), "output_%d", sensors[i]); - file_output[i] = fopen(file_name, "w+"); - sensor_t sensor = sensord_get_sensor(sensors[i]); - handle[i] = sensord_connect(sensor); - event[i] = (sensors[i] << 16) | 0x0001; - result[i] = sensord_register_event(handle[i], event[i], interval, 0, callback, NULL); - - if (!result[i]) { - printf("error: unable to register sensor\n"); - return -1; - } - start_handle[i] = sensord_start(handle[i], 1); - - if (!start_handle[i]) { - printf("error: unable to start handle\n"); - sensord_unregister_event(handle[i], event[i]); - sensord_disconnect(handle[i]); - return -1; - } - } - - g_main_loop_run(mainloop); - g_main_loop_unref(mainloop); - - for (i = 0; i < MAXSIZE; i++) { - sensord_unregister_event(handle[i], event[i]); - sensord_stop(handle[i]); - sensord_disconnect(handle[i]); - } - - return 0; -} diff --git a/src/test/src/multi-process-performance-test.c b/src/test/src/multi-process-performance-test.c deleted file mode 100644 index c9b02ec..0000000 --- a/src/test/src/multi-process-performance-test.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include -#include -#include -#include - -#include "check-sensor.h" - -void usage() -{ - printf("Usage : ./performance-test (optional)\n\n"); - - printf("TIMEOUT:\n"); - printf("time for which the parallel sensor test cases should run\n"); - - printf("interval:\n"); - printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.\n"); - printf("If no value for sensor is entered default value by the driver will be used.\n"); -} - -int main(int argc, char** argv) -{ - pid_t b = 1; - - int i = 0; - int interval = DEFAULT_EVENT_INTERVAL; - int TIMEOUT = 10; //in seconds for which all the sensor tests should run - - if(argc < 2) { - usage(); - return -1; - } - else if(argc == 2){ - TIMEOUT = atoi(argv[1]); - if (TIMEOUT == 0) { - usage(); - return -1; - } - } - else { - TIMEOUT = atoi(argv[1]); - interval = atoi(argv[2]); - if (TIMEOUT == 0 || interval == 0) { - usage(); - return -1; - } - } - - //make an array of size MAX and fill it with all the sensors needed to run - int MAX = 6; - pid_t pids[MAX]; - sensor_type_t sensor[MAX]; - - //Update the value of MAX and add more sensors here to test more sensors in parallel - sensor[0] = ACCELEROMETER_SENSOR; - sensor[1] = GYROSCOPE_SENSOR; - sensor[2] = GEOMAGNETIC_SENSOR; - sensor[3] = PRESSURE_SENSOR; - sensor[4] = PROXIMITY_SENSOR; - sensor[MAX-1] = LIGHT_SENSOR; - - while (i < MAX) { - if (b > 0) { - b = fork(); - if (b == -1) perror("Fork failed\n"); - else if (b == 0) { - break; - } - pids[i] = b; - i++; - } - } - - if (i < MAX) { - // call the sensord test tc-common for a sensor. - int event = (sensor[i] << 16) | 0x0001; - struct pthread_arguments arg; - arg.sensor_type = sensor[i]; - arg.event = event; - arg.interval = interval; - - check_sensor((void*)&arg); - } - else { - // Main Parent Child. Waits for TIMEOUT and then kills all child processes. - sleep (TIMEOUT); - int j = 0; - - for (j = 0; j < MAX; j++) { - char command[100]; - snprintf(command, sizeof(command), "kill %d", pids[j]); - if (system(command) == -1) - return -1; - } - } - - return 0; -} diff --git a/src/test/src/multi-thread-performance-test.c b/src/test/src/multi-thread-performance-test.c deleted file mode 100644 index 588c0e7..0000000 --- a/src/test/src/multi-thread-performance-test.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "check-sensor.h" - -void usage() -{ - printf("Usage : ./multi-sensor (optional)\n\n"); - printf("TIMEOUT:\n"); - printf("time for which the parallel sensor test cases should run\n"); - - printf("interval:\n"); - printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.\n"); - printf("If no value for sensor is entered default value by the driver will be used.\n"); - printf("arg[i].sensor_type: "); - printf("[accelerometer] "); - printf("[auto_rotation]\n"); - printf("[gyroscope] "); - printf("[pressure] "); - printf("[temperature] "); - printf("[geomagnetic] "); - printf("[orientation] "); - printf("[tilt] "); - printf("[gravity] "); - printf("[linear_accel] "); - printf("[rotation_vector] "); - printf("[geomagnetic_rv] "); - printf("[gaming_rv] "); - printf("[ultraviolet] "); - printf("[light]\n"); - printf("[gyro_uncal]"); - printf("[face_down]"); - -} - -int main(int argc, char **argv) -{ - - int i = 0; - int interval = DEFAULT_EVENT_INTERVAL; - int TIMEOUT = 10; //in seconds for which all the sensor tests should run - - if(argc < 2) { - usage(); - return -1; - } - else if(argc == 2){ - TIMEOUT = atoi(argv[1]); - if (TIMEOUT == 0) { - usage(); - return -1; - } - } - else { - TIMEOUT = atoi(argv[1]); - interval = atoi(argv[2]); - if (TIMEOUT == 0 || interval == 0) { - usage(); - return -1; - } - } - - int MAX = 6, j = 0, k = 0; - struct pthread_arguments arg[MAX]; - int t = 0; - - arg[0].sensor_type = ACCELEROMETER_SENSOR; - arg[0].event = ACCELEROMETER_RAW_DATA_EVENT; - arg[1].sensor_type = GYROSCOPE_SENSOR; - arg[1].event = GYROSCOPE_RAW_DATA_EVENT; - arg[2].sensor_type = GEOMAGNETIC_RV_SENSOR; - arg[2].event = GEOMAGNETIC_RV_RAW_DATA_EVENT; - arg[3].sensor_type = PRESSURE_SENSOR; - arg[3].event = PRESSURE_RAW_DATA_EVENT; - arg[4].sensor_type = PROXIMITY_SENSOR; - arg[4].event = PROXIMITY_CHANGE_STATE_EVENT; - arg[5].sensor_type = LIGHT_SENSOR; - arg[5].event = LIGHT_LUX_DATA_EVENT; - - for (t = 0; t < MAX; t++) - arg[t].interval = interval; - - pthread_t thread_id[MAX]; - - for (j = 0; j < MAX; j++) - pthread_create(&thread_id[j], NULL, check_sensor, (void*)&arg[j]); - - sleep(TIMEOUT); - return 0; -} diff --git a/src/test/src/sensor-test.c b/src/test/src/sensor-test.c deleted file mode 100644 index ff2b005..0000000 --- a/src/test/src/sensor-test.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2014-15 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 "check-sensor.h" - -void usage() -{ - printf("Usage : ./sensor-test -p(optional) (optional) (optional)\n\n"); - - printf("Sensor_type: "); - printf("[accelerometer] "); - printf("[auto_rotation]\n"); - printf("[gyroscope] "); - printf("[pressure] "); - printf("[temperature] "); - printf("[geomagnetic] "); - printf("[orientation] "); - printf("[tilt] "); - printf("[gravity] "); - printf("[linear_accel] "); - printf("[rotation_vector] "); - printf("[geomagnetic_rv] "); - printf("[gaming_rv] "); - printf("[ultraviolet] "); - printf("[bio_led_red] "); - printf("[light]\n"); - printf("[gyroscope_uncal]"); - printf("[face_down]"); - printf("event:"); - printf("[RAW_DATA_EVENT]\n"); - printf("-p: [polling]\n"); - printf("Sensor_type: "); - printf("[proximity]\n"); - printf("event:"); - printf("[CHANGE_STATE_EVENT]\n"); - printf("-p: [polling]\n"); - printf("interval:\n"); - printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.If no value for sensor is entered default value by the driver will be used.\n"); -} - -int main(int argc, char **argv) -{ - int interval; - unsigned int event; - sensor_type_t sensor_type; - bool is_polling; - - char *end1; - - if (argc < 2 || argc > 5) { - printf("Wrong number of arguments\n"); - usage(); - return -1; - } - - if (strcmp(argv[1], "accelerometer") == 0) { - sensor_type = ACCELEROMETER_SENSOR; - event = ACCELEROMETER_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "auto_rotation") == 0) { - sensor_type = AUTO_ROTATION_SENSOR; - event = AUTO_ROTATION_CHANGE_STATE_EVENT; - } - else if (strcmp(argv[1], "gyroscope") == 0) { - sensor_type = GYROSCOPE_SENSOR; - event = GYROSCOPE_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "pressure") == 0) { - sensor_type = PRESSURE_SENSOR; - event = PRESSURE_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "temperature") == 0) { - sensor_type = TEMPERATURE_SENSOR; - event = TEMPERATURE_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "geomagnetic") == 0) { - sensor_type = GEOMAGNETIC_SENSOR; - event = GEOMAGNETIC_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "orientation") == 0) { - sensor_type = ORIENTATION_SENSOR; - event = ORIENTATION_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "tilt") == 0) { - sensor_type = TILT_SENSOR; - event = TILT_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "gravity") == 0) { - sensor_type = GRAVITY_SENSOR; - event = GRAVITY_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "linear_accel") == 0) { - sensor_type = LINEAR_ACCEL_SENSOR; - event = LINEAR_ACCEL_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "rotation_vector") == 0) { - sensor_type = ROTATION_VECTOR_SENSOR; - event = ROTATION_VECTOR_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "geomagnetic_rv") == 0) { - sensor_type = GEOMAGNETIC_RV_SENSOR; - event = GEOMAGNETIC_RV_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "gaming_rv") == 0) { - sensor_type = GYROSCOPE_RV_SENSOR; - event = GAMING_RV_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "light") == 0) { - sensor_type = LIGHT_SENSOR; - event = LIGHT_LUX_DATA_EVENT; - } - else if (strcmp(argv[1], "proximity") == 0) { - sensor_type = PROXIMITY_SENSOR; - event = PROXIMITY_CHANGE_STATE_EVENT; - } - else if (strcmp(argv[1], "ultraviolet") == 0) { - sensor_type = ULTRAVIOLET_SENSOR; - event = ULTRAVIOLET_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "gyroscope_uncal") == 0) { - sensor_type = GYROSCOPE_UNCAL_SENSOR; - event = GYROSCOPE_UNCAL_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "bio_led_red") == 0) { - sensor_type = BIO_LED_RED_SENSOR; - event = BIO_LED_RED_RAW_DATA_EVENT; - } - else if (strcmp(argv[1], "face_down") == 0) { - sensor_type = GESTURE_FACE_DOWN_SENSOR; - event = FACE_DOWN_RAW_DATA_EVENT; - } - else { - usage(); - return -1; - } - - interval = DEFAULT_EVENT_INTERVAL; - - is_polling = FALSE; - - if(argc >= 3 && strcmp(argv[2], "-p") == 0) { - is_polling = TRUE; - } - - if (is_polling) { - if (argc == 4) { - int temp_event = get_event(sensor_type, argv[3]); - if (temp_event == -1) { - interval = atoi(argv[3]); - if (interval == 0){ - usage(); - return -1; - } - } - else { - event = temp_event; - } - } - else if (argc == 5) { - event = get_event(sensor_type, argv[3]); - interval = strtol(argv[4], &end1, 10); - - if (*end1) { - printf("Conversion error, non-convertible part: %s\n", end1); - return -1; - } - } - return polling_sensor(sensor_type, event); - } - else { - if (argc == 3) { - int temp_event = get_event(sensor_type, argv[2]); - - if (temp_event == -1) { - interval = atoi(argv[2]); - if (interval == 0){ - usage(); - return -1; - } - } - else { - event = temp_event; - } - } - else if (argc == 4) { - event = get_event(sensor_type, argv[2]); - interval = strtol(argv[3], &end1, 10); - - if (*end1) { - printf("Conversion error, non-convertible part: %s\n", end1); - return -1; - } - } - struct pthread_arguments arg; - arg.sensor_type = sensor_type; - arg.event = event; - arg.interval = interval; - - void *result = check_sensor((void*)&arg); - - if (!result) - return -1; - - return 0; - } -} -- 2.7.4 From 44ddaba7e2869edbe46bb37f6b7e648ba0773253 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 21:07:39 +0900 Subject: [PATCH 04/16] sensord: add internal sensor types Change-Id: Ieacf15fdceb421dbc8e7912d137fcae52462a948 Signed-off-by: kibak.yoon --- src/client/client_common.cpp | 1 + src/shared/sensor_types.h | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp index a0a7345..96ce4ff 100644 --- a/src/client/client_common.cpp +++ b/src/client/client_common.cpp @@ -72,6 +72,7 @@ unsigned int get_log_per_count(sensor_id_t id) case GESTURE_WRIST_DOWN_SENSOR: case GESTURE_MOVEMENT_SENSOR: case WEAR_STATUS_SENSOR: + case PRESSURE_SENSOR: return LOG_PER_COUNT_EVERY_EVENT; default: break; diff --git a/src/shared/sensor_types.h b/src/shared/sensor_types.h index 18e40f4..dab36bc 100644 --- a/src/shared/sensor_types.h +++ b/src/shared/sensor_types.h @@ -66,6 +66,8 @@ extern "C" DEF_SENSOR(EXERCISE_ROWING_SENSOR) \ DEF_SENSOR(EXERCISE_STEPPER_SENSOR) \ \ + DEF_SENSOR_VALUE(EXTERNAL_EXERCISE_SENSOR, 0x800) \ + \ DEF_SENSOR_VALUE(FUSION_SENSOR, 0x900) \ DEF_SENSOR(AUTO_ROTATION_SENSOR) \ DEF_SENSOR(AUTO_BRIGHTNESS_SENSOR) \ @@ -92,6 +94,9 @@ extern "C" DEF_SENSOR(WORKOUT_SENSOR) \ DEF_SENSOR(CYCLE_MONITOR_SENSOR) \ DEF_SENSOR(STAIR_TRACKER_SENSOR) \ + DEF_SENSOR(PRESSURE_INDICATOR_SENSOR) \ + DEF_SENSOR(PRESSURE_ALERT_SENSOR) \ + DEF_SENSOR(HR_CALORIE_SENSOR) \ \ DEF_SENSOR_VALUE(CONTEXT_SENSOR, 0x7000) \ DEF_SENSOR(MOTION_SENSOR) \ @@ -104,6 +109,9 @@ extern "C" DEF_SENSOR(HRM_RAW_SENSOR) \ DEF_SENSOR(TILT_SENSOR) \ DEF_SENSOR(RV_RAW_SENSOR) \ + DEF_SENSOR(GSR_SENSOR) \ + DEF_SENSOR(SIMSENSE_SENSOR) \ + DEF_SENSOR(PPG_SENSOR) \ #define BIO_HRM_SENSOR HRM_SENSOR #define BIO_LED_GREEN_SENSOR HRM_LED_GREEN_SENSOR @@ -114,6 +122,7 @@ extern "C" #define STRESS_MONITOR_SENSOR HUMAN_STRESS_MONITOR_SENSOR #define AUTOSESSION_EXERCISE_SENSOR WORKOUT_SENSOR #define EXERCISE_COACH_SENSOR EXERCISE_STANDALONE_SENSOR +#define EXERCISE_SENSOR EXTERNAL_EXERCISE_SENSOR DECLARE_SENSOR_ENUM(sensor_type_t, SENSOR_TYPE) -- 2.7.4 From e358d052833d6af22ce1c1acf835a0b4443fa226 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 24 Nov 2016 18:13:36 +0900 Subject: [PATCH 05/16] sensord: change file permission to remove execute permission Change-Id: I5cce417208269fdbae3899f643089ff1fbd990e5 Signed-off-by: kibak.yoon --- src/client/dbus_listener.cpp | 0 src/server/dbus_util.cpp | 0 src/server/server.cpp | 0 src/shared/macro.h | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/client/dbus_listener.cpp mode change 100755 => 100644 src/server/dbus_util.cpp mode change 100755 => 100644 src/server/server.cpp mode change 100755 => 100644 src/shared/macro.h diff --git a/src/client/dbus_listener.cpp b/src/client/dbus_listener.cpp old mode 100755 new mode 100644 diff --git a/src/server/dbus_util.cpp b/src/server/dbus_util.cpp old mode 100755 new mode 100644 diff --git a/src/server/server.cpp b/src/server/server.cpp old mode 100755 new mode 100644 diff --git a/src/shared/macro.h b/src/shared/macro.h old mode 100755 new mode 100644 -- 2.7.4 From 530996c4a54010f2217862ac891207cb796ffd7f Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 30 Nov 2016 22:16:08 +0900 Subject: [PATCH 06/16] [BugFix] Reset Sensor Fusion Backend if it returns NaN because of inconsitent input and high error Change-Id: I29fe84898d32f710cb914748d3111edfb2da38b7 Signed-off-by: Akhil --- src/sensor/rotation_vector/fusion_base.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sensor/rotation_vector/fusion_base.cpp b/src/sensor/rotation_vector/fusion_base.cpp index 51e45d3..89b5a44 100644 --- a/src/sensor/rotation_vector/fusion_base.cpp +++ b/src/sensor/rotation_vector/fusion_base.cpp @@ -100,5 +100,10 @@ void fusion_base::store_orientation(void) m_y = m_orientation_filter.m_quaternion.m_quat.m_vec[1]; m_z = m_orientation_filter.m_quaternion.m_quat.m_vec[2]; m_w = m_orientation_filter.m_quaternion.m_quat.m_vec[3]; + + if (std::isnan(m_x) || std::isnan(m_y) || std::isnan(m_z) || std::isnan(m_w)) { + m_timestamp = 0; + m_orientation_filter = orientation_filter(); + } clear(); } -- 2.7.4 From 98584eab2e8e7270af197d064ca5aba166c676ea Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 2 Dec 2016 18:44:25 +0900 Subject: [PATCH 07/16] sensord: fix compiler warnings Change-Id: I6c702882e120c470ac69d6b0d510021d49ceb15c Signed-off-by: kibak.yoon --- src/sensorctl/injector_manager.cpp | 2 +- src/sensorctl/loopback_manager.cpp | 2 -- src/sensorctl/tester_manager.cpp | 2 +- src/sensorctl/tester_sensor.cpp | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/sensorctl/injector_manager.cpp b/src/sensorctl/injector_manager.cpp index 4f6b722..8aeebb0 100644 --- a/src/sensorctl/injector_manager.cpp +++ b/src/sensorctl/injector_manager.cpp @@ -103,7 +103,7 @@ bool injector_manager::process(int argc, char *argv[]) option_count = argc - ARGC_BASE; for (i = 0; i < option_count; ++i) { options[i] = new char[NAME_MAX_TEST]; - strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + strncpy(options[i], argv[ARGC_BASE + i], strlen(argv[ARGC_BASE + i])); } result = injector->inject(option_count, options); diff --git a/src/sensorctl/loopback_manager.cpp b/src/sensorctl/loopback_manager.cpp index 4b78007..b7908b6 100644 --- a/src/sensorctl/loopback_manager.cpp +++ b/src/sensorctl/loopback_manager.cpp @@ -42,8 +42,6 @@ static void int_to_bytes(int32_t value, int length, char cmd[]) bool loopback_manager::process(int argc, char *argv[]) { - sensor_type_t type; - if (argc < DEFAULT_COMMAND_SIZE || argc > MAX_COMMAND_SIZE) { usage(); return false; diff --git a/src/sensorctl/tester_manager.cpp b/src/sensorctl/tester_manager.cpp index ffd9e57..c16140f 100644 --- a/src/sensorctl/tester_manager.cpp +++ b/src/sensorctl/tester_manager.cpp @@ -55,7 +55,7 @@ bool tester_manager::process(int argc, char *argv[]) option_count = argc - ARGC_BASE; for (i = 0; i < option_count; ++i) { options[i] = new char[NAME_MAX_TEST]; - strncpy(options[i], argv[ARGC_BASE+i], sizeof(argv[ARGC_BASE+i])); + strncpy(options[i], argv[ARGC_BASE + i], strlen(argv[ARGC_BASE + i])); } tester->test(type, option_count, options); diff --git a/src/sensorctl/tester_sensor.cpp b/src/sensorctl/tester_sensor.cpp index 5a75da6..7f324f6 100644 --- a/src/sensorctl/tester_sensor.cpp +++ b/src/sensorctl/tester_sensor.cpp @@ -36,8 +36,8 @@ static GMainLoop *mainloop; static int check_loop; static const char *result_str(bool result) { - if (result) return KGRN"[PASS]"RESET; - else return KRED"[FAIL]"RESET; + if (result) return KGRN "[PASS]" RESET; + else return KRED "[FAIL]" RESET; } bool tester_sensor::init(void) -- 2.7.4 From 0c9da3394ec379bd829a8d5e4712bcfb3198cb9a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 6 Dec 2016 10:43:02 +0900 Subject: [PATCH 08/16] sensord: install required header files instead of all header files Change-Id: Ib826fe1e3464a560f58e5868c64fd4e2cf9a8136 Signed-off-by: kibak.yoon --- src/client/CMakeLists.txt | 12 ++++++++---- src/client/sensor_internal.h | 2 +- src/client/sensor_internal_deprecated.h | 2 +- src/shared/CMakeLists.txt | 15 +++++++++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 2f32b9c..f14b841 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -22,6 +22,11 @@ ENDFOREACH(flag) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -g -fPIC") +SET (INSTALL_HEADERS + sensor_internal.h + sensor_internal_deprecated.h +) + INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/hal ${CMAKE_SOURCE_DIR}/src/shared @@ -37,9 +42,8 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER}) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) -INSTALL( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor - FILES_MATCHING PATTERN "*.h" - ) +FOREACH(HEADER IN ITEMS ${INSTALL_HEADERS}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) +ENDFOREACH() INSTALL(FILES ${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/src/client/sensor_internal.h b/src/client/sensor_internal.h index 47452d4..b7e9469 100644 --- a/src/client/sensor_internal.h +++ b/src/client/sensor_internal.h @@ -24,7 +24,7 @@ #define API __attribute__((visibility("default"))) #endif -#include "stdbool.h" +#include #include /*header for common sensor type*/ diff --git a/src/client/sensor_internal_deprecated.h b/src/client/sensor_internal_deprecated.h index a2b5b30..851ccbc 100644 --- a/src/client/sensor_internal_deprecated.h +++ b/src/client/sensor_internal_deprecated.h @@ -24,7 +24,7 @@ #define DEPRECATED __attribute__((deprecated)) #endif -#include "stdbool.h" +#include #include diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index 8b8416e..5d094ec 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -11,6 +11,13 @@ FOREACH(flag ${SHARED_PKGS_CFLAGS}) ENDFOREACH(flag) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") +SET (INSTALL_HEADERS + sensor_types.h + sensor_common.h + sensor_deprecated.h + enum_factory.h +) + INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/hal ${CMAKE_CURRENT_SOURCE_DIR} @@ -22,7 +29,7 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SHARED_PKGS_LDFLAGS}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) -INSTALL( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor - FILES_MATCHING PATTERN "*.h" -) + +FOREACH(HEADER IN ITEMS ${INSTALL_HEADERS}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sensor) +ENDFOREACH() -- 2.7.4 From 77be7fb50f78d4858acd5c2aad3f32342cea0121 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Sat, 10 Dec 2016 14:57:24 +0900 Subject: [PATCH 09/16] sensord: add pre_start() that should be executed before starting regardless of clients Change-Id: I1cd8a70cdfcb5f838c94a1da7fced99835fbf872 Signed-off-by: kibak.yoon --- src/sensor/auto_rotation/auto_rotation_sensor.cpp | 6 ++++++ src/sensor/auto_rotation/auto_rotation_sensor.h | 1 + src/server/sensor_base.cpp | 8 ++++++++ src/server/sensor_base.h | 1 + 4 files changed, 16 insertions(+) diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index c3bd18e..71d10b4 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -194,6 +194,12 @@ bool auto_rotation_sensor::set_wakeup(int wakeup) return false; } +bool auto_rotation_sensor::pre_start(void) +{ + m_rotation = AUTO_ROTATION_DEGREE_UNKNOWN; + return true; +} + bool auto_rotation_sensor::on_start(void) { int length; diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.h b/src/sensor/auto_rotation/auto_rotation_sensor.h index ddd4e3c..d50f728 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.h +++ b/src/sensor/auto_rotation/auto_rotation_sensor.h @@ -56,6 +56,7 @@ private: 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); diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp index a5a40bb..24e16a7 100644 --- a/src/server/sensor_base.cpp +++ b/src/server/sensor_base.cpp @@ -121,6 +121,9 @@ bool sensor_base::start(void) { AUTOLOCK(m_client_mutex); + if (!pre_start()) + return false; + ++m_client; if (m_client == 1) { @@ -348,6 +351,11 @@ bool sensor_base::set_batch_latency(unsigned long latency) return true; } +bool sensor_base::pre_start(void) +{ + return true; +} + bool sensor_base::on_start(void) { return true; diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h index 04883d8..89b88ed 100644 --- a/src/server/sensor_base.h +++ b/src/server/sensor_base.h @@ -103,6 +103,7 @@ private: virtual bool set_interval(unsigned long interval); virtual bool set_batch_latency(unsigned long latency); + virtual bool pre_start(void); virtual bool on_start(void); virtual bool on_stop(void); -- 2.7.4 From ef5f8297e1557197bab236094a4882c08b46e1c9 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 13 Dec 2016 16:47:53 +0900 Subject: [PATCH 10/16] sensor: fix return value from false to 0 Change-Id: Icb84d1ec8f8e20b29f02dc86807a4fe535c79455 Signed-off-by: kibak.yoon --- src/shared/csocket.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 4a97a3c..ca9ec4f 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -324,15 +324,15 @@ ssize_t csocket::send(const void *buffer, size_t size) const if (ret == -1) { _ERRNO(errno, _E, "select error: sock_fd: %d\n for %s", m_sock_fd, get_client_name()); - return false; + return 0; } else if (!ret) { _ERRNO(errno, _E, "select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name()); - return false; + return 0; } if (!FD_ISSET(m_sock_fd, &write_fds)) { _ERRNO(errno, _E, "select failed for %s, nothing to write, m_sock_fd : %d", get_client_name(), m_sock_fd); - return false; + return 0; } if (m_sock_type == SOCK_STREAM) -- 2.7.4 From 32032e4e333ebb3cfa5ee53320d0db858fd6f44e Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 13 Dec 2016 18:35:45 +0900 Subject: [PATCH 11/16] sensor: enable pedometer sensor - pedometer sensor needs healthinfo privilege Change-Id: I9ac4e2079fd0a6e640c92b63ce13f3c3f1c81ed0 Signed-off-by: kibak.yoon --- src/sensor/CMakeLists.txt | 6 ++++++ src/sensor/sensorhub/pedometer_sensor.cpp | 34 +++++++++++++++++++++++++++++++ src/sensor/sensorhub/pedometer_sensor.h | 32 +++++++++++++++++++++++++++++ src/server/sensor_loader.cpp | 6 ++++++ 4 files changed, 78 insertions(+) create mode 100644 src/sensor/sensorhub/pedometer_sensor.cpp create mode 100644 src/sensor/sensorhub/pedometer_sensor.h diff --git a/src/sensor/CMakeLists.txt b/src/sensor/CMakeLists.txt index 3ec60fd..272b547 100644 --- a/src/sensor/CMakeLists.txt +++ b/src/sensor/CMakeLists.txt @@ -10,6 +10,7 @@ SET(LINEAR_ACCEL "ON") SET(RV "ON") SET(ORIENTATION "ON") SET(FACE_DOWN "ON") +SET(SENSORHUB "ON") INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/shared @@ -63,6 +64,11 @@ IF("${FACE_DOWN}" STREQUAL "ON") 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") +ENDIF() MESSAGE("${SENSOR_SRCS}") SET(SENSOR_SRCS ${SENSOR_SRCS} PARENT_SCOPE) diff --git a/src/sensor/sensorhub/pedometer_sensor.cpp b/src/sensor/sensorhub/pedometer_sensor.cpp new file mode 100644 index 0000000..b9d5c23 --- /dev/null +++ b/src/sensor/sensorhub/pedometer_sensor.cpp @@ -0,0 +1,34 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include "pedometer_sensor.h" + +pedometer_sensor::pedometer_sensor() +{ + set_permission(SENSOR_PERMISSION_BIO); + + _I("pedometer_sensor is created : %#x", this); +} + +pedometer_sensor::~pedometer_sensor() +{ + _I("pedometer_sensor is destroyed : %#x", this); +} diff --git a/src/sensor/sensorhub/pedometer_sensor.h b/src/sensor/sensorhub/pedometer_sensor.h new file mode 100644 index 0000000..5ae94c2 --- /dev/null +++ b/src/sensor/sensorhub/pedometer_sensor.h @@ -0,0 +1,32 @@ +/* + * sensord + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _PEDOMETER_SENSOR_H_ +#define _PEDOMETER_SENSOR_H_ + +#include + +class pedometer_sensor : public physical_sensor { +public: + pedometer_sensor(); + virtual ~pedometer_sensor(); +}; + +#endif /* _PEDOMETER_SENSOR_H_ */ + diff --git a/src/server/sensor_loader.cpp b/src/server/sensor_loader.cpp index c25d07a..614e057 100644 --- a/src/server/sensor_loader.cpp +++ b/src/server/sensor_loader.cpp @@ -53,6 +53,9 @@ #ifdef ENABLE_FACE_DOWN #include #endif +#ifdef ENABLE_SENSORHUB +#include +#endif using std::vector; using std::string; @@ -169,6 +172,9 @@ void sensor_loader::create_sensors(void) create_physical_sensors(HRM_LED_GREEN_SENSOR); create_physical_sensors(HRM_LED_IR_SENSOR); create_physical_sensors(HRM_LED_RED_SENSOR); +#ifdef ENABLE_SENSORHUB + create_physical_sensors(HUMAN_PEDOMETER_SENSOR); +#endif create_physical_sensors(UNKNOWN_SENSOR); -- 2.7.4 From 5abd1da78db60bc3a8674b75db3b38b7e8c2f78a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 13 Dec 2016 19:50:03 +0900 Subject: [PATCH 12/16] sensord: fix incorrect return type - int to size_t Change-Id: Ia1d5b0308e2a9a546c1980d0bb1896a1e4a88204 Signed-off-by: kibak.yoon --- src/server/command_worker.cpp | 2 +- src/server/command_worker.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp index 8d57968..2436ab8 100644 --- a/src/server/command_worker.cpp +++ b/src/server/command_worker.cpp @@ -91,7 +91,7 @@ void command_worker::init_cmd_handlers(void) m_cmd_handlers[CMD_FLUSH] = &command_worker::cmd_flush; } -int command_worker::create_sensor_raw_list(int client_perms, std::vector &raw_list) +size_t command_worker::create_sensor_raw_list(int client_perms, std::vector &raw_list) { size_t total_raw_data_size = 0; vector sensors; diff --git a/src/server/command_worker.h b/src/server/command_worker.h index 3e1b62c..e6dff1d 100644 --- a/src/server/command_worker.h +++ b/src/server/command_worker.h @@ -45,7 +45,7 @@ private: static sensor_raw_data_map m_sensor_raw_data_map; static void init_cmd_handlers(void); - static int create_sensor_raw_list(int client_perms, std::vector &raw_list); + static size_t create_sensor_raw_list(int client_perms, std::vector &raw_list); static void get_sensor_list(int permissions, cpacket &sensor_list); static bool working(void *ctx); -- 2.7.4 From 4217c2abce8ac882f8f3384c1dca8d97f37d5baf Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 13 Dec 2016 20:04:01 +0900 Subject: [PATCH 13/16] sensord: version up 2.0.9 Change-Id: I4d12ec6c0c12890c58407657dca42621cc128819 Signed-off-by: kibak.yoon --- packaging/sensord.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index bb1cd3f..957ebcb 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -1,6 +1,6 @@ Name: sensord Summary: Sensor daemon -Version: 2.0.8 +Version: 2.0.9 Release: 0 Group: System/Sensor Framework License: Apache-2.0 -- 2.7.4 From e02c195ed699ebf0f0cf4869624a6734029dd762 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 28 Dec 2016 15:38:07 +0900 Subject: [PATCH 14/16] sensord: accumulate pedometer data - accumulated pedometer data should be provided to client Change-Id: Ib9a4bb5325867e1e55f1e8c9b9a32609915dbd08 Signed-off-by: kibak.yoon --- src/sensor/sensorhub/pedometer_sensor.cpp | 60 ++++++++++++++++++++++++++++++- src/sensor/sensorhub/pedometer_sensor.h | 15 ++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/sensor/sensorhub/pedometer_sensor.cpp b/src/sensor/sensorhub/pedometer_sensor.cpp index b9d5c23..c825e41 100644 --- a/src/sensor/sensorhub/pedometer_sensor.cpp +++ b/src/sensor/sensorhub/pedometer_sensor.cpp @@ -21,7 +21,32 @@ #include #include "pedometer_sensor.h" +enum value_index { + IDX_STEPS = 0, + IDX_WALK_STEPS, + IDX_RUN_STEPS, + IDX_DISTANCE, + IDX_CALORIES, + IDX_SPEED, + IDX_FREQUENCY, + IDX_STATE, + IDX_WALK_UP, + IDX_WALK_DOWN, + IDX_RUN_UP, + IDX_RUN_DOWN, + IDX_STATE_EX, +}; + pedometer_sensor::pedometer_sensor() +: m_steps(0) +, m_walk_steps(0) +, m_run_steps(0) +, m_walk_up_steps(0) +, m_walk_down_steps(0) +, m_run_up_steps(0) +, m_run_down_steps(0) +, m_distance(0) +, m_calories(0) { set_permission(SENSOR_PERMISSION_BIO); @@ -30,5 +55,38 @@ pedometer_sensor::pedometer_sensor() pedometer_sensor::~pedometer_sensor() { - _I("pedometer_sensor is destroyed : %#x", this); +} + +bool pedometer_sensor::on_event(const sensor_data_t *data, int data_len, int remains) +{ + if (data_len == sizeof(sensorhub_data_t)) + return false; + + accumulate((sensor_pedometer_data_t*)data); + return true; +} + +void pedometer_sensor::accumulate(sensor_pedometer_data_t *data) +{ + m_steps += data->values[IDX_STEPS]; + m_walk_steps += data->values[IDX_WALK_STEPS]; + m_run_steps += data->values[IDX_RUN_STEPS]; + m_distance += data->values[IDX_DISTANCE]; + m_calories += data->values[IDX_CALORIES]; + + m_walk_up_steps += data->values[IDX_WALK_UP]; + m_walk_down_steps += data->values[IDX_WALK_DOWN]; + m_run_up_steps += data->values[IDX_RUN_UP]; + m_run_down_steps += data->values[IDX_RUN_DOWN]; + + data->values[IDX_STEPS] = m_steps; + data->values[IDX_WALK_STEPS] = m_walk_steps; + data->values[IDX_RUN_STEPS] = m_run_steps; + data->values[IDX_DISTANCE] = m_distance; + data->values[IDX_CALORIES] = m_calories; + + data->values[IDX_WALK_UP] = m_walk_up_steps; + data->values[IDX_WALK_DOWN] = m_walk_down_steps; + data->values[IDX_RUN_UP] = m_run_up_steps; + data->values[IDX_RUN_DOWN] = m_run_down_steps; } diff --git a/src/sensor/sensorhub/pedometer_sensor.h b/src/sensor/sensorhub/pedometer_sensor.h index 5ae94c2..16f1ac7 100644 --- a/src/sensor/sensorhub/pedometer_sensor.h +++ b/src/sensor/sensorhub/pedometer_sensor.h @@ -26,6 +26,21 @@ class pedometer_sensor : public physical_sensor { public: pedometer_sensor(); virtual ~pedometer_sensor(); + + bool on_event(const sensor_data_t *data, int data_len, int remains); + +private: + unsigned long long m_steps; + unsigned long long m_walk_steps; + unsigned long long m_run_steps; + unsigned long long m_walk_up_steps; + unsigned long long m_walk_down_steps; + unsigned long long m_run_up_steps; + unsigned long long m_run_down_steps; + double m_distance; + double m_calories; + + void accumulate(sensor_pedometer_data_t *data); }; #endif /* _PEDOMETER_SENSOR_H_ */ -- 2.7.4 From e970cca5105790b1c3c70194a23c4c5176bd06a1 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 2 Jan 2017 14:39:03 +0900 Subject: [PATCH 15/16] sensord: add dummy api library for tv profile Change-Id: I610a6a2e43e475b20e96432d47b68aebe7785655 Signed-off-by: kibak.yoon --- packaging/sensord.spec | 12 ++- src/client/CMakeLists.txt | 11 ++ src/client/client_dummy.cpp | 204 +++++++++++++++++++++++++++++++++++ src/client/external_client_dummy.cpp | 39 +++++++ 4 files changed, 263 insertions(+), 3 deletions(-) create mode 100644 src/client/client_dummy.cpp create mode 100644 src/client/external_client_dummy.cpp diff --git a/packaging/sensord.spec b/packaging/sensord.spec index 957ebcb..cfd30af 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -20,6 +20,8 @@ BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) Requires: libsensord = %{version}-%{release} +%define BUILD_PROFILE %{?profile}%{!?profile:%{?tizen_profile_name}} + %description Sensor daemon @@ -56,9 +58,8 @@ Sensor functional testing %prep %setup -q MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` - cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir} \ - -DMAJORVER=${MAJORVER} -DFULLVER=%{version} + -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{BUILD_PROFILE} %build make %{?jobs:-j%jobs} @@ -69,6 +70,7 @@ rm -rf %{buildroot} mkdir -p %{buildroot}%{_unitdir} +%if "%{?BUILD_PROFILE}" != "tv" install -m 0644 %SOURCE1 %{buildroot}%{_unitdir} install -m 0644 %SOURCE2 %{buildroot}%{_unitdir} install -m 0644 %SOURCE3 %{buildroot}%{_unitdir} @@ -76,6 +78,7 @@ install -m 0644 %SOURCE3 %{buildroot}%{_unitdir} %install_service multi-user.target.wants sensord.service %install_service sockets.target.wants sensord_event.socket %install_service sockets.target.wants sensord_command.socket +%endif %post systemctl daemon-reload @@ -93,13 +96,16 @@ ln -sf %{_libdir}/libsensor.so.%{version} %{_libdir}/libsensor.so.1 %files %manifest packaging/sensord.manifest %{_bindir}/sensord +%license LICENSE.APLv2 + +%if "%{?BUILD_PROFILE}" != "tv" %{_unitdir}/sensord.service %{_unitdir}/sensord_command.socket %{_unitdir}/sensord_event.socket %{_unitdir}/multi-user.target.wants/sensord.service %{_unitdir}/sockets.target.wants/sensord_command.socket %{_unitdir}/sockets.target.wants/sensord_event.socket -%license LICENSE.APLv2 +%endif %files -n libsensord %defattr(-,root,root,-) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index f14b841..33ed7fa 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -34,6 +34,17 @@ INCLUDE_DIRECTORIES( ) FILE(GLOB_RECURSE SRCS *.cpp) + +IF("${PROFILE}" STREQUAL "tv") + LIST(REMOVE_ITEM SRCS + "${CMAKE_CURRENT_SOURCE_DIR}/client.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/external_client.cpp") +ELSE() + LIST(REMOVE_ITEM SRCS + "${CMAKE_CURRENT_SOURCE_DIR}/client_dummy.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/external_client_dummy.cpp") +ENDIF() + ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} "sensord-shared") diff --git a/src/client/client_dummy.cpp b/src/client/client_dummy.cpp new file mode 100644 index 0000000..c7732a6 --- /dev/null +++ b/src/client/client_dummy.cpp @@ -0,0 +1,204 @@ +/* + * sensord + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "sensor_internal.h" +#include "sensor_internal_deprecated.h" + +API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count) +{ + return -ENODATA; +} + +API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor) +{ + return -ENODATA; +} + +API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count) +{ + return false; +} + +API sensor_t sensord_get_sensor(sensor_type_t type) +{ + return NULL; +} + +API bool sensord_get_type(sensor_t sensor, sensor_type_t *type) +{ + return false; +} + +API const char* sensord_get_name(sensor_t sensor) +{ + return NULL; +} + +API const char* sensord_get_vendor(sensor_t sensor) +{ + return NULL; +} + +API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege) +{ + return false; +} + +API bool sensord_get_min_range(sensor_t sensor, float *min_range) +{ + return false; +} + +API bool sensord_get_max_range(sensor_t sensor, float *max_range) +{ + return false; +} + +API bool sensord_get_resolution(sensor_t sensor, float *resolution) +{ + return false; +} + +API bool sensord_get_min_interval(sensor_t sensor, int *min_interval) +{ + return false; +} + +API bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count) +{ + return false; +} + +API bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count) +{ + return false; +} + +API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count) +{ + return false; +} + +API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported) +{ + return false; +} + +API bool sensord_is_wakeup_supported(sensor_t sensor) +{ + return false; +} + +API int sensord_connect(sensor_t sensor) +{ + return OP_ERROR; +} + +API bool sensord_disconnect(int handle) +{ + return false; +} + +API bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data) +{ + return false; +} + +API bool sensord_unregister_event(int handle, unsigned int event_type) +{ + return false; +} + +API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data) +{ + return false; +} + +API bool sensord_unregister_accuracy_cb(int handle) +{ + return false; +} + +API bool sensord_start(int handle, int option) +{ + return false; +} + +API bool sensord_stop(int handle) +{ + return false; +} + +API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval) +{ + return false; +} + +API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency) +{ + return false; +} + +API bool sensord_set_option(int handle, int option) +{ + return false; +} + +API int sensord_set_attribute_int(int handle, int attribute, int value) +{ + return OP_ERROR; +} + +API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len) +{ + return OP_ERROR; +} + +API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len) +{ + return false; +} + +API bool sensord_send_command(int handle, const char *command, int command_len) +{ + return false; +} + +API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data) +{ + return false; +} + +API bool sensord_flush(int handle) +{ + return false; +} + +API bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data) +{ + return false; +} + +API bool sensord_set_passive_mode(int handle, bool passive) +{ + return false; +} diff --git a/src/client/external_client_dummy.cpp b/src/client/external_client_dummy.cpp new file mode 100644 index 0000000..8f359d0 --- /dev/null +++ b/src/client/external_client_dummy.cpp @@ -0,0 +1,39 @@ +/* + * sensord + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include + +#include "sensor_internal.h" +#include "sensor_internal_deprecated.h" + +API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data) +{ + return OP_ERROR; +} + +API bool sensord_external_disconnect(int handle) +{ + return false; +} + +API bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt) +{ + return false; +} -- 2.7.4 From 3f5a4094622aee6a80f16c2f29331eff15ecff38 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 8 Feb 2017 16:07:43 +0900 Subject: [PATCH 16/16] sensord: initialize class member variables in constructors Change-Id: I52f2e2a84f29c5f0b99f3eecb8986113aaf43b2d Signed-off-by: kibak.yoon --- src/client/sensor_callback_deliverer.cpp | 1 + src/client/sensor_event_listener.cpp | 1 + src/sensor/auto_rotation/auto_rotation_sensor.cpp | 6 ++++-- src/sensor/gesture/face_down_sensor.cpp | 2 ++ src/sensor/gravity/gravity_sensor.cpp | 5 ++++- src/sensor/linear_accel/linear_accel_sensor.cpp | 3 ++- src/sensor/orientation/orientation_sensor.cpp | 3 ++- src/sensor/rotation_vector/fusion_base.cpp | 5 +++++ src/sensor/rotation_vector/gyro_rv_sensor.cpp | 3 ++- src/sensor/rotation_vector/gyro_rv_sensor.h | 2 +- src/sensor/rotation_vector/magnetic_rv_sensor.cpp | 3 ++- src/sensor/rotation_vector/magnetic_rv_sensor.h | 2 +- src/sensor/rotation_vector/rv_sensor.cpp | 3 ++- src/sensor/rotation_vector/rv_sensor.h | 2 +- src/sensor/tilt/tilt_sensor.cpp | 1 + src/server/physical_sensor.cpp | 3 ++- src/server/physical_sensor.h | 1 - src/shared/poller.cpp | 1 + 18 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/client/sensor_callback_deliverer.cpp b/src/client/sensor_callback_deliverer.cpp index 9af3790..e27b944 100644 --- a/src/client/sensor_callback_deliverer.cpp +++ b/src/client/sensor_callback_deliverer.cpp @@ -24,6 +24,7 @@ sensor_callback_deliverer::sensor_callback_deliverer() : m_running(false) , m_callbacks(NULL) +, m_deliverer(NULL) { } diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp index fd11d4f..21d611f 100644 --- a/src/client/sensor_event_listener.cpp +++ b/src/client/sensor_event_listener.cpp @@ -45,6 +45,7 @@ sensor_event_listener::sensor_event_listener() , m_thread_state(THREAD_STATE_TERMINATE) , m_hup_observer(NULL) , m_client_info(sensor_client_info::get_instance()) +, m_cb_deliverer(NULL) , m_axis(SENSORD_AXIS_DISPLAY_ORIENTED) , m_display_rotation(AUTO_ROTATION_DEGREE_UNKNOWN) { diff --git a/src/sensor/auto_rotation/auto_rotation_sensor.cpp b/src/sensor/auto_rotation/auto_rotation_sensor.cpp index 71d10b4..107566b 100644 --- a/src/sensor/auto_rotation/auto_rotation_sensor.cpp +++ b/src/sensor/auto_rotation/auto_rotation_sensor.cpp @@ -37,13 +37,15 @@ #include #define SENSOR_NAME "SENSOR_AUTO_ROTATION" +#define AUTO_ROTATION_LIB "/usr/lib/sensord/libauto-rotation.so" +#define POLLING_INTERVAL 60 auto_rotation_sensor::auto_rotation_sensor() : m_accel_sensor(NULL) , m_alg(NULL) , m_rotation(0) -, m_interval(100) -, m_rotation_time(0) +, m_interval(POLLING_INTERVAL) +, m_rotation_time(1) /* rotation state is valid from initial state, so set rotation time to non-zero value */ { } diff --git a/src/sensor/gesture/face_down_sensor.cpp b/src/sensor/gesture/face_down_sensor.cpp index 03ddf7c..6bb53af 100644 --- a/src/sensor/gesture/face_down_sensor.cpp +++ b/src/sensor/gesture/face_down_sensor.cpp @@ -42,8 +42,10 @@ face_down_sensor::face_down_sensor() : m_gravity_sensor(NULL) +, m_alg(NULL) , m_time(0) , m_state(false) +, m_interval(SENSOR_INTERVAL_NORMAL) { } diff --git a/src/sensor/gravity/gravity_sensor.cpp b/src/sensor/gravity/gravity_sensor.cpp index d4c74ce..8ad7e00 100644 --- a/src/sensor/gravity/gravity_sensor.cpp +++ b/src/sensor/gravity/gravity_sensor.cpp @@ -61,8 +61,11 @@ gravity_sensor::gravity_sensor() , m_x(-1) , m_y(-1) , m_z(-1) -, m_accuracy(-1) +, m_accuracy(SENSOR_ACCURACY_UNDEFINED) , m_time(0) +, m_interval(SENSOR_INTERVAL_NORMAL) +, m_accel_mag(0) +, m_time_new(0) { } diff --git a/src/sensor/linear_accel/linear_accel_sensor.cpp b/src/sensor/linear_accel/linear_accel_sensor.cpp index 56af7b6..b881706 100644 --- a/src/sensor/linear_accel/linear_accel_sensor.cpp +++ b/src/sensor/linear_accel/linear_accel_sensor.cpp @@ -48,8 +48,9 @@ linear_accel_sensor::linear_accel_sensor() , m_gx(0) , m_gy(0) , m_gz(0) -, m_accuracy(0) +, m_accuracy(SENSOR_ACCURACY_UNDEFINED) , m_time(0) +, m_interval(SENSOR_INTERVAL_NORMAL) { } diff --git a/src/sensor/orientation/orientation_sensor.cpp b/src/sensor/orientation/orientation_sensor.cpp index c9cad8b..8d09b96 100644 --- a/src/sensor/orientation/orientation_sensor.cpp +++ b/src/sensor/orientation/orientation_sensor.cpp @@ -42,8 +42,9 @@ orientation_sensor::orientation_sensor() , m_azimuth(-1) , m_pitch(-1) , m_roll(-1) -, m_accuracy(-1) +, m_accuracy(SENSOR_ACCURACY_UNDEFINED) , m_time(0) +, m_interval(SENSOR_INTERVAL_NORMAL) { } diff --git a/src/sensor/rotation_vector/fusion_base.cpp b/src/sensor/rotation_vector/fusion_base.cpp index 89b5a44..f17e704 100644 --- a/src/sensor/rotation_vector/fusion_base.cpp +++ b/src/sensor/rotation_vector/fusion_base.cpp @@ -35,6 +35,11 @@ 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!"); } diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.cpp b/src/sensor/rotation_vector/gyro_rv_sensor.cpp index 7c7c9b3..8c5fd23 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.cpp +++ b/src/sensor/rotation_vector/gyro_rv_sensor.cpp @@ -44,8 +44,9 @@ gyro_rv_sensor::gyro_rv_sensor() , m_y(-1) , m_z(-1) , m_w(-1) -, m_time(0) , m_accuracy(SENSOR_ACCURACY_UNDEFINED) +, m_time(0) +, m_interval(SENSOR_INTERVAL_NORMAL) { } diff --git a/src/sensor/rotation_vector/gyro_rv_sensor.h b/src/sensor/rotation_vector/gyro_rv_sensor.h index 052f0e3..b28db23 100644 --- a/src/sensor/rotation_vector/gyro_rv_sensor.h +++ b/src/sensor/rotation_vector/gyro_rv_sensor.h @@ -56,9 +56,9 @@ private: float m_y; float m_z; float m_w; + int m_accuracy; 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); diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp index 61001c1..6f28e6b 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.cpp +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.cpp @@ -44,8 +44,9 @@ magnetic_rv_sensor::magnetic_rv_sensor() , m_y(-1) , m_z(-1) , m_w(-1) -, m_time(0) , m_accuracy(SENSOR_ACCURACY_UNDEFINED) +, m_time(0) +, m_interval(SENSOR_INTERVAL_NORMAL) { } diff --git a/src/sensor/rotation_vector/magnetic_rv_sensor.h b/src/sensor/rotation_vector/magnetic_rv_sensor.h index 34b5d49..f1093eb 100644 --- a/src/sensor/rotation_vector/magnetic_rv_sensor.h +++ b/src/sensor/rotation_vector/magnetic_rv_sensor.h @@ -56,9 +56,9 @@ private: float m_y; float m_z; float m_w; + int m_accuracy; 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); diff --git a/src/sensor/rotation_vector/rv_sensor.cpp b/src/sensor/rotation_vector/rv_sensor.cpp index 9fb42c7..75c7e16 100644 --- a/src/sensor/rotation_vector/rv_sensor.cpp +++ b/src/sensor/rotation_vector/rv_sensor.cpp @@ -46,8 +46,9 @@ rv_sensor::rv_sensor() , m_y(-1) , m_z(-1) , m_w(-1) -, m_time(0) , m_accuracy(SENSOR_ACCURACY_UNDEFINED) +, m_time(0) +, m_interval(SENSOR_INTERVAL_NORMAL) { } diff --git a/src/sensor/rotation_vector/rv_sensor.h b/src/sensor/rotation_vector/rv_sensor.h index db23d01..54d7985 100644 --- a/src/sensor/rotation_vector/rv_sensor.h +++ b/src/sensor/rotation_vector/rv_sensor.h @@ -57,9 +57,9 @@ private: float m_y; float m_z; float m_w; + int m_accuracy; 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); diff --git a/src/sensor/tilt/tilt_sensor.cpp b/src/sensor/tilt/tilt_sensor.cpp index 6691978..7d83b49 100644 --- a/src/sensor/tilt/tilt_sensor.cpp +++ b/src/sensor/tilt/tilt_sensor.cpp @@ -54,6 +54,7 @@ tilt_sensor::tilt_sensor() : m_accel_sensor(NULL) , m_fusion_sensor(NULL) , m_time(0) +, m_interval(SENSOR_INTERVAL_NORMAL) { virtual_sensor_config &config = virtual_sensor_config::get_instance(); diff --git a/src/server/physical_sensor.cpp b/src/server/physical_sensor.cpp index 65ab74e..9207e08 100644 --- a/src/server/physical_sensor.cpp +++ b/src/server/physical_sensor.cpp @@ -26,7 +26,8 @@ cmutex physical_sensor::m_mutex; physical_sensor::physical_sensor() -: m_sensor_device(NULL) +: m_info(NULL) +, m_sensor_device(NULL) { } diff --git a/src/server/physical_sensor.h b/src/server/physical_sensor.h index 1264931..36667c0 100644 --- a/src/server/physical_sensor.h +++ b/src/server/physical_sensor.h @@ -50,7 +50,6 @@ public: protected: const sensor_info_t *m_info; sensor_device *m_sensor_device; - uint32_t hal_id; virtual bool on_start(void); virtual bool on_stop(void); diff --git a/src/shared/poller.cpp b/src/shared/poller.cpp index 8e05af8..cc3ba14 100644 --- a/src/shared/poller.cpp +++ b/src/shared/poller.cpp @@ -32,6 +32,7 @@ poller::poller() poller::poller(int fd) : m_epfd(-1) +, sfd(-1) { init_poll_fd(); add_fd(fd); -- 2.7.4