--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(hal-backend-sensor-rpi CXX)
+INCLUDE(GNUInstallDirs)
+
+SET(LIBRARY_NAME "hal-backend-sensor-rpi")
+SET(HAL_LIBDIR ${CMAKE_HAL_LIBDIR_PREFIX})
+SET(HAL_LICENSEDIR ${CMAKE_HAL_LICENSEDIR_PREFIX})
+SET(DEPENDENTS "dlog hal-api-common hal-api-sensor")
+
+SET(ACCEL "ON")
+SET(PROXIMITY "ON")
+SET(SENSORHUB "OFF")
+
+# Common Options
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-section -Wl,--print-gc-section")
+MESSAGE("FLAGS: ${CMAKE_CXX_FLAGS}")
+MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
+
+# Internal Debugging Options
+#ADD_DEFINITIONS(-Wall -g -D_DEBUG)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(HAL_PKGS REQUIRED dlog)
+
+FOREACH(flag ${HAL_PKGS_CFLAGS})
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
+FILE(GLOB SRCS src/*.cpp)
+
+IF("${ACCEL}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/accel/*.cpp)
+ADD_DEFINITIONS(-DENABLE_ACCEL)
+ENDIF()
+
+IF("${PROXIMITY}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/proxi/*.cpp)
+ADD_DEFINITIONS(-DENABLE_PROXIMITY)
+ENDIF()
+
+IF("${SENSORHUB}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/sensorhub/*.cpp)
+ADD_DEFINITIONS(-DENABLE_SENSORHUB)
+ENDIF()
+
+MESSAGE("Sources: ${SRCS}")
+ADD_LIBRARY(${LIBRARY_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${HAL_PKGS_LDFLAGS})
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.APLv2 DESTINATION ${HAL_LICENSEDIR}/${PROJECT_NAME})
+INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${HAL_LIBDIR} COMPONENT RuntimeLibraries)
+
+ADD_SUBDIRECTORY(testcase)
--- /dev/null
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
+\r
--- /dev/null
+SUBSYSTEM!="input", GOTO="sensor_rules_end"
+ATTRS{enable}!="", ENV{ID_INPUT_KEY}=""
+ATTRS{enable}!="", ENV{ID_INPUT_KEYPAD}=""
+ATTRS{enable}!="", ENV{ID_INPUT_KEYBOARD}=""
+ATTRS{enable}!="", ENV{ID_INPUT_TOUCHPAD}=""
+ATTRS{enable}!="", ENV{ID_INPUT_TOUCHSCREEN}=""
+ATTRS{enable}!="", ENV{ID_INPUT_MOUSE}=""
+ATTRS{enable}!="", ENV{ID_INPUT_JOYSTICK}=""
+
+ATTRS{enable}!="", ACTION=="add", RUN+="/bin/chown sensor:input %S/%p/enable %S/%p/poll_delay"
+ATTRS{eanble}!="", ACTION=="add", RUN+="/bin/chsmack -a * %S/%p/enable %S/%p/poll_delay"
+
+LABEL="sensor_rules_end"
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+Name: hal-backend-sensor-rpi
+Summary: Sensor HAL for RPI targets
+Version: 1.0.4
+Release: 0
+Group: Service Framework / Sensor
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Source1: 99-sensor.rules
+
+ExcludeArch: aarch64 %ix86 x86_64
+
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(hal-api-common)
+BuildRequires: pkgconfig(hal-api-sensor)
+
+%description
+Sensor HAL for RPI targets
+
+%package haltests
+Summary: Device HAL(Hardware Abstraction Layer) Test Cases
+Requires: %{name} = %{version}-%{release}
+
+%description haltests
+Sensor Device HAL(Hardware Abstraction Layer) Test Cases
+
+%prep
+%setup -q
+
+%build
+%cmake . -DCMAKE_HAL_LIBDIR_PREFIX=%{_hal_libdir} -DCMAKE_HAL_LICENSEDIR_PREFIX=%{_hal_licensedir}
+make %{?_smp_mflags}
+
+%install
+%make_install
+
+mkdir -p %{buildroot}%{_libdir}/udev/rules.d
+
+install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/udev/rules.d
+
+%post
+/sbin/ldconfig
+
+%postun
+/sbin/ldconfig
+
+%files
+%manifest packaging/%{name}.manifest
+%{_libdir}/udev/rules.d/99-sensor.rules
+%{_hal_libdir}/*.so*
+%{_hal_licensedir}/%{name}/LICENSE.Apache-2.0
+
+%files haltests
+%manifest packaging/%{name}.manifest
+%{_bindir}/*haltest
--- /dev/null
+/*
+ * 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 <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <linux/input.h>
+#include <sys/ioctl.h>
+#include <poll.h>
+
+#include <util.h>
+#include <sensor_common.h>
+#include <sensor_log.h>
+
+#include "accel_device.h"
+
+#define MODEL_NAME "K2HH"
+#define VENDOR "ST Microelectronics"
+#define RESOLUTION 16
+#define RAW_DATA_UNIT 0.122
+#define MIN_INTERVAL 10
+#define MAX_BATCH_COUNT 0
+
+#define SENSOR_NAME "SENSOR_ACCELEROMETER"
+#define SENSOR_TYPE_ACCEL "ACCEL"
+
+#define INPUT_NAME "accelerometer_sensor"
+#define ACCEL_SENSORHUB_POLL_NODE_NAME "accel_poll_delay"
+
+#define GRAVITY 9.80665
+#define G_TO_MG 1000
+#define RAW_DATA_TO_G_UNIT(X) (((float)(X))/((float)G_TO_MG))
+#define RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(X) (GRAVITY * (RAW_DATA_TO_G_UNIT(X)))
+
+#define MIN_RANGE(RES) (-((1 << (RES))/2))
+#define MAX_RANGE(RES) (((1 << (RES))/2)-1)
+
+#define MAX_ID 0x3
+
+static sensor_info_t sensor_info = {
+ id: 0x1,
+ name: SENSOR_NAME,
+ type: SENSOR_DEVICE_ACCELEROMETER,
+ event_type: (SENSOR_DEVICE_ACCELEROMETER << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
+ model_name: MODEL_NAME,
+ vendor: VENDOR,
+ min_range: MIN_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
+ max_range: MAX_RANGE(RESOLUTION) * RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
+ resolution: RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(RAW_DATA_UNIT),
+ min_interval: MIN_INTERVAL,
+ max_batch_count: MAX_BATCH_COUNT,
+ wakeup_supported: false
+};
+
+accel_device::accel_device()
+: m_node_handle(-1)
+, m_x(-1)
+, m_y(-1)
+, m_z(-1)
+, m_polling_interval(1000)
+, m_fired_time(0)
+, m_sensorhub_controlled(false)
+{
+ const std::string sensorhub_interval_node_name = ACCEL_SENSORHUB_POLL_NODE_NAME;
+
+ node_info_query query;
+ node_info info;
+
+ query.sensorhub_controlled = m_sensorhub_controlled = util::is_sensorhub_controlled(sensorhub_interval_node_name);
+ query.sensor_type = SENSOR_TYPE_ACCEL;
+ query.key = INPUT_NAME;
+ query.iio_enable_node_name = "accel_enable";
+ query.sensorhub_interval_node_name = sensorhub_interval_node_name;
+
+ if (!util::get_node_info(query, info)) {
+ _E("Failed to get node info");
+ throw ENXIO;
+ }
+
+ util::show_node_info(info);
+
+ m_method = info.method;
+ m_data_node = info.data_node_path;
+ m_enable_node = info.enable_node_path;
+ m_interval_node = info.interval_node_path;
+
+ m_node_handle = open(m_data_node.c_str(), O_RDONLY);
+
+ if (m_node_handle < 0) {
+ _ERRNO(errno, _E, "accel handle open fail for accel processor");
+ throw ENXIO;
+ }
+
+ if (m_method == INPUT_EVENT_METHOD) {
+ if (!util::set_monotonic_clock(m_node_handle))
+ throw ENXIO;
+
+ update_value = [=]() {
+ return this->update_value_input_event();
+ };
+ } else {
+ if (!info.buffer_length_node_path.empty())
+ util::set_node_value(info.buffer_length_node_path, 480);
+
+ if (!info.buffer_enable_node_path.empty())
+ util::set_node_value(info.buffer_enable_node_path, 1);
+
+ update_value = [=]() {
+ return this->update_value_iio();
+ };
+ }
+
+ _I("accel_device is created!");
+}
+
+accel_device::~accel_device()
+{
+ close(m_node_handle);
+ m_node_handle = -1;
+
+ _I("accel_device is destroyed!");
+}
+
+int accel_device::get_poll_fd(void)
+{
+ return m_node_handle;
+}
+
+int accel_device::get_sensors(const sensor_info_t **sensors)
+{
+ retvm_if(sensors == NULL || sensors == nullptr, SENSOR_ERROR_INVALID_PARAMETER, "%s:NULL interface", SENSOR_NAME);
+ *sensors = &sensor_info;
+
+ return 1;
+}
+
+bool accel_device::enable(uint32_t id)
+{
+ retvm_if(id == 0 || id > MAX_ID, false, "%s:Invalid ID Received", SENSOR_NAME);
+
+ util::set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
+ set_interval(id, m_polling_interval);
+
+ m_fired_time = 0;
+ _I("Enable accelerometer sensor");
+ return true;
+}
+
+bool accel_device::disable(uint32_t id)
+{
+ retvm_if(id == 0 || id > MAX_ID, false, "%s:Invalid ID Received", SENSOR_NAME);
+
+ util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
+
+ _I("Disable accelerometer sensor");
+ return true;
+}
+
+bool accel_device::set_interval(uint32_t id, unsigned long val)
+{
+ unsigned long long polling_interval_ns;
+ retvm_if(id == 0 || id > MAX_ID, false, "%s:Invalid ID Received", SENSOR_NAME);
+
+ polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);
+
+ if (!util::set_node_value(m_interval_node, polling_interval_ns)) {
+ _E("Failed to set polling resource: %s", m_interval_node.c_str());
+ return false;
+ }
+
+ _I("Interval is changed from %lu ms to %lu ms", m_polling_interval, val);
+ m_polling_interval = val;
+ return true;
+}
+
+bool accel_device::update_value_input_event(void)
+{
+ int accel_raw[3] = {0, };
+ bool x, y, z;
+ int read_input_cnt = 0;
+ const int INPUT_MAX_BEFORE_SYN = 10;
+ unsigned long long fired_time = 0;
+ bool syn = false;
+
+ x = y = z = false;
+
+ struct input_event accel_input;
+ _D("accel sensor event detection");
+
+ while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+ int len = read(m_node_handle, &accel_input, sizeof(accel_input));
+ if (len != sizeof(accel_input)) {
+ _E("accel_file read fail, read_len = %d", len);
+ return false;
+ }
+
+ ++read_input_cnt;
+
+ if (accel_input.type == EV_REL) {
+ switch (accel_input.code) {
+ case REL_X:
+ accel_raw[0] = (int)accel_input.value;
+ x = true;
+ break;
+ case REL_Y:
+ accel_raw[1] = (int)accel_input.value;
+ y = true;
+ break;
+ case REL_Z:
+ accel_raw[2] = (int)accel_input.value;
+ z = true;
+ break;
+ default:
+ _E("accel_input event[type = %d, code = %d] is unknown.", accel_input.type, accel_input.code);
+ return false;
+ break;
+ }
+ } else if (accel_input.type == EV_SYN) {
+ syn = true;
+ fired_time = util::get_timestamp(&accel_input.time);
+ } else {
+ _E("accel_input event[type = %d, code = %d] is unknown.", accel_input.type, accel_input.code);
+ return false;
+ }
+ }
+
+ if (syn == false) {
+ _E("EV_SYN didn't come until %d inputs had come", read_input_cnt);
+ return false;
+ }
+
+ if (x)
+ m_x = accel_raw[0];
+ if (y)
+ m_y = accel_raw[1];
+ if (z)
+ m_z = accel_raw[2];
+
+ m_fired_time = fired_time;
+
+ _D("m_x = %d, m_y = %d, m_z = %d, time = %lluus", m_x, m_y, m_z, m_fired_time);
+
+ return true;
+}
+
+bool accel_device::update_value_iio(void)
+{
+ struct {
+ int16_t x;
+ int16_t y;
+ int16_t z;
+ int64_t timestamp;
+ } __attribute__((packed)) data;
+
+ struct pollfd pfd;
+
+ pfd.fd = m_node_handle;
+ pfd.events = POLLIN | POLLERR;
+ pfd.revents = 0;
+
+ int ret = poll(&pfd, 1, -1);
+
+ if (ret == -1) {
+ _ERRNO(errno, _E, "Failed to poll from m_node_handle:%d", m_node_handle);
+ return false;
+ } else if (!ret) {
+ _E("poll timeout m_node_handle:%d", m_node_handle);
+ return false;
+ }
+
+ if (pfd.revents & POLLERR) {
+ _E("poll exception occurred! m_node_handle:%d", m_node_handle);
+ return false;
+ }
+
+ if (!(pfd.revents & POLLIN)) {
+ _E("poll nothing to read! m_node_handle:%d, pfd.revents = %d", m_node_handle, pfd.revents);
+ return false;
+ }
+
+ int len = read(m_node_handle, &data, sizeof(data));
+
+ if (len != sizeof(data)) {
+ _E("Failed to read data, m_node_handle:%d read_len:%d", m_node_handle, len);
+ return false;
+ }
+
+ m_x = data.x;
+ m_y = data.y;
+ m_z = data.z;
+ m_fired_time = data.timestamp;
+
+ _D("m_x = %d, m_y = %d, m_z = %d, time = %lluus", m_x, m_y, m_z, m_fired_time);
+
+ return true;
+}
+
+int accel_device::read_fd(uint32_t **ids)
+{
+ retvm_if(ids == NULL || ids == nullptr, SENSOR_ERROR_INVALID_PARAMETER, "%s:NULL interface", SENSOR_NAME);
+
+ if (!update_value()) {
+ _D("Failed to update value");
+ return false;
+ }
+
+ event_ids.clear();
+ event_ids.push_back(sensor_info.id);
+
+ *ids = &event_ids[0];
+
+ return event_ids.size();
+}
+
+int accel_device::get_data(uint32_t id, sensor_data_t **data, int *length)
+{
+ sensor_data_t *sensor_data;
+ retvm_if(data == NULL || data == nullptr, SENSOR_ERROR_INVALID_PARAMETER, "%s:NULL data interface", SENSOR_NAME);
+ retvm_if(length == NULL || length == nullptr, SENSOR_ERROR_INVALID_PARAMETER, "%s:NULL length interface", SENSOR_NAME);
+ retvm_if(id == 0 || id > MAX_ID, SENSOR_ERROR_INVALID_PARAMETER, "%s:Invalid ID Received", SENSOR_NAME);
+
+ sensor_data = new (std::nothrow) sensor_data_t;
+ retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
+
+ sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
+ sensor_data->timestamp = m_fired_time;
+ sensor_data->value_count = 3;
+ sensor_data->values[0] = m_x;
+ sensor_data->values[1] = m_y;
+ sensor_data->values[2] = m_z;
+
+ raw_to_base(sensor_data);
+
+ *data = sensor_data;
+ *length = sizeof(sensor_data_t);
+
+ return 0;
+}
+
+void accel_device::raw_to_base(sensor_data_t *data)
+{
+ data->values[0] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[0] * RAW_DATA_UNIT);
+ data->values[1] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[1] * RAW_DATA_UNIT);
+ data->values[2] = RAW_DATA_TO_METRE_PER_SECOND_SQUARED_UNIT(data->values[2] * RAW_DATA_UNIT);
+}
--- /dev/null
+/*
+ * 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 _ACCEL_DEVICE_H_
+#define _ACCEL_DEVICE_H_
+
+#include <hal/hal-sensor-types.h>
+#include <string>
+#include <vector>
+#include <functional>
+
+class accel_device : public sensor_device {
+public:
+ accel_device();
+ virtual ~accel_device();
+
+ int get_poll_fd(void);
+ int get_sensors(const sensor_info_t **sensors);
+
+ bool enable(uint32_t id);
+ bool disable(uint32_t id);
+
+ bool set_interval(uint32_t id, unsigned long val);
+
+ int read_fd(uint32_t **ids);
+ int get_data(uint32_t id, sensor_data_t **data, int *length);
+
+private:
+ int m_node_handle;
+ int m_x;
+ int m_y;
+ int m_z;
+ unsigned long m_polling_interval;
+ unsigned long long m_fired_time;
+ bool m_sensorhub_controlled;
+
+ int m_method;
+ std::string m_data_node;
+ std::string m_enable_node;
+ std::string m_interval_node;
+
+ std::function<bool(void)> update_value;
+
+ std::vector<uint32_t> event_ids;
+
+ bool update_value_input_event(void);
+ bool update_value_iio(void);
+
+ void raw_to_base(sensor_data_t *data);
+};
+#endif /* _ACCEL_DEVICE_H_ */
--- /dev/null
+/*
+ * Copyright (c) 2021 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 <errno.h>
+#include <hal/hal-sensor-interface.h>
+#include <sensor_log.h>
+#include <stdlib.h>
+
+#include <vector>
+
+#include "accel/accel_device.h"
+#include "proxi/proxi_device.h"
+#include "sensorhub/sensorhub.h"
+
+static std::vector<sensor_device_t> devs;
+
+template <typename _sensor>
+void create_sensor(const char *name) {
+ sensor_device *instance = NULL;
+ try {
+ instance = new _sensor;
+ } catch (std::exception &e) {
+ ERR("Failed to create %s sensor device, exception: %s", name, e.what());
+ return;
+ } catch (int err) {
+ _ERRNO(err, _E, "Failed to create %s sensor device", name);
+ return;
+ }
+
+ devs.push_back(instance);
+}
+
+static int sensor_tm1_create(sensor_device_t **devices) {
+ if (devs.empty()) {
+#ifdef ENABLE_ACCEL
+ create_sensor<accel_device>("Accelerometer");
+#endif
+#ifdef ENABLE_PROXIMITY
+ create_sensor<proxi_device>("Proximity");
+#endif
+#ifdef ENABLE_SENSORHUB
+ create_sensor<sensorhub_device>("Sensorhub");
+#endif
+ }
+
+ *devices = &devs[0];
+ return devs.size();
+}
+
+static int sensor_tm1_init(void **data) {
+ _I("init hal backend sensor");
+ hal_backend_sensor_funcs *funcs;
+
+ funcs =
+ (hal_backend_sensor_funcs *)calloc(1, sizeof(hal_backend_sensor_funcs));
+ if (!funcs) return -ENOMEM;
+
+ funcs->create = sensor_tm1_create;
+
+ *data = (void *)funcs;
+
+ return 0;
+}
+
+static int sensor_tm1_exit(void *data) {
+ if (!data) return -EINVAL;
+ free(data);
+
+ return 0;
+}
+
+extern "C" hal_backend hal_backend_sensor_data = {
+ .name = "sensor-tm1",
+ .vendor = "Tizen",
+ .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
+ .init = sensor_tm1_init,
+ .exit = sensor_tm1_exit,
+};
--- /dev/null
+/*
+ * 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 __MACRO_H__
+#define __MACRO_H__
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+
+#endif /* __MACRO_H__ */
--- /dev/null
+/*
+ * 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 _SENSOR_COMMON_H_
+#define _SENSOR_COMMON_H_
+
+#define SENSOR_EVENT_SHIFT 16
+#define RAW_DATA_EVENT 0x0001
+
+#define UNKNOWN_NAME "UNKNOWN"
+
+
+enum sensorhub_enable_bit {
+ SENSORHUB_ACCELEROMETER_ENABLE_BIT = 0,
+ SENSORHUB_GYROSCOPE_ENABLE_BIT,
+ SENSORHUB_GEOMAGNETIC_UNCALIB_ENABLE_BIT,
+ SENSORHUB_GEOMAGNETIC_RAW_ENABLE_BIT,
+ SENSORHUB_GEOMAGNETIC_ENABLE_BIT,
+ SENSORHUB_PRESSURE_ENABLE_BIT,
+ SENSORHUB_GESTURE_ENABLE_BIT,
+ SENSORHUB_PROXIMITY_ENABLE_BIT,
+ SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT,
+ SENSORHUB_LIGHT_ENABLE_BIT,
+ SENSORHUB_PROXIMITY_RAW_ENABLE_BIT,
+ SENSORHUB_ORIENTATION_ENABLE_BIT,
+ SENSORHUB_STEP_DETECTOR_ENABLE_BIT = 12,
+ SENSORHUB_SIG_MOTION_ENABLE_BIT,
+ SENSORHUB_GYRO_UNCALIB_ENABLE_BIT,
+ SENSORHUB_GAME_ROTATION_VECTOR_ENABLE_BIT = 15,
+ SENSORHUB_ROTATION_VECTOR_ENABLE_BIT,
+ SENSORHUB_STEP_COUNTER_ENABLE_BIT,
+ SENSORHUB_HRM_RAW_ENABLE_BIT,
+ SENSORHUB_HRM_RAW_FAC_ENABLE_BIT,
+ SENSORHUB_HRM_LIB_ENABLE_BIT,
+ SENSORHUB_TILT_MOTION,
+ SENSORHUB_UV_SENSOR,
+ SENSORHUB_PIR_ENABLE_BIT,
+ SENSORHUB_PIR_RAW_ENABLE_BIT,
+ SENSORHUB_GSR_ENABLE_BIT = 25,
+ SENSORHUB_ENABLE_BIT_MAX,
+};
+
+#endif /* __SENSOR_COMMON_H__ */
--- /dev/null
+/*
+ * 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 _SENSOR_LOG_H_
+#define _SENSOR_LOG_H_
+
+#include <dlog.h>
+
+#ifndef NAME_MAX
+#define NAME_MAX 256
+#endif
+
+#ifdef LOG_TAG
+ #undef LOG_TAG
+#endif
+#define LOG_TAG "SENSOR"
+
+#define LOG_DUMP(fp, fmt, arg...) do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0)
+
+#ifdef _DEBUG
+#define DBG SLOGD
+#else
+#define DBG(...) do { } while (0)
+#endif
+
+#define ERR SLOGE
+#define WARN SLOGW
+#define INFO SLOGI
+#define _E ERR
+#define _W WARN
+#define _I INFO
+#define _D DBG
+
+#define _ERRNO(errno, tag, fmt, arg...) do { \
+ char buf[1024]; \
+ char *error = strerror_r(errno, buf, 1024); \
+ if (!error) { \
+ _E("Failed to strerror_r()"); \
+ break; \
+ } \
+ tag(fmt" (%s[%d])", ##arg, error, errno); \
+ } while (0)
+
+#ifdef _DEBUG
+#define warn_if(expr, fmt, arg...) do { \
+ if(expr) { \
+ _D("(%s) -> " fmt, #expr, ##arg); \
+ } \
+ } while (0)
+#define ret_if(expr) do { \
+ if(expr) { \
+ _D("(%s) -> %s() return", #expr, __FUNCTION__); \
+ return; \
+ } \
+ } while (0)
+#define retv_if(expr, val) do { \
+ if(expr) { \
+ _D("(%s) -> %s() return", #expr, __FUNCTION__); \
+ return (val); \
+ } \
+ } while (0)
+#define retm_if(expr, fmt, arg...) do { \
+ if(expr) { \
+ _E(fmt, ##arg); \
+ _D("(%s) -> %s() return", #expr, __FUNCTION__); \
+ return; \
+ } \
+ } while (0)
+#define retvm_if(expr, val, fmt, arg...) do { \
+ if(expr) { \
+ _E(fmt, ##arg); \
+ _D("(%s) -> %s() return", #expr, __FUNCTION__); \
+ return (val); \
+ } \
+ } while (0)
+
+#else
+#define warn_if(expr, fmt, arg...) do { \
+ if(expr) { \
+ _E(fmt, ##arg); \
+ } \
+ } while (0)
+#define ret_if(expr) do { \
+ if(expr) { \
+ return; \
+ } \
+ } while (0)
+#define retv_if(expr, val) do { \
+ if(expr) { \
+ return (val); \
+ } \
+ } while (0)
+#define retm_if(expr, fmt, arg...) do { \
+ if(expr) { \
+ _E(fmt, ##arg); \
+ return; \
+ } \
+ } while (0)
+#define retvm_if(expr, val, fmt, arg...) do { \
+ if(expr) { \
+ _E(fmt, ##arg); \
+ return (val); \
+ } \
+ } while (0)
+
+#endif
+
+#endif /* _SENSOR_LOG_H_ */
--- /dev/null
+/*
+ * 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 <util.h>
+
+#include <unistd.h>
+#include <dirent.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <linux/input.h>
+#include <fstream>
+
+#include "sensor_log.h"
+
+using std::ifstream;
+using std::ofstream;
+using std::fstream;
+using std::string;
+
+#define PREFIX_EVENT "event"
+
+static bool get_event_num(const string &input_path, string &event_num)
+{
+ const string event_prefix = PREFIX_EVENT;
+ DIR *dir = NULL;
+ struct dirent *entry;
+ std::string node_name;
+ bool find = false;
+
+ dir = opendir(input_path.c_str());
+ retvm_if(!dir, false, "Failed to open directory[%s]", input_path.c_str());
+
+ int prefix_size = event_prefix.size();
+
+ while (true) {
+ entry = readdir(dir);
+ if (!entry) break;
+
+ node_name = std::string(entry->d_name);
+
+ if (node_name.compare(0, prefix_size, event_prefix) != 0)
+ continue;
+
+ event_num = node_name.substr(prefix_size, node_name.size() - prefix_size);
+ find = true;
+ break;
+ }
+
+ closedir(dir);
+
+ return find;
+}
+
+static bool get_iio_node_info(const string& enable_node_name, const string& device_num, node_info &info)
+{
+ const string base_dir = string("/sys/bus/iio/devices/iio:device") + device_num + string("/");
+
+ info.data_node_path = string("/dev/iio:device") + device_num;
+ info.enable_node_path = base_dir + enable_node_name;
+ info.interval_node_path = base_dir + string("sampling_frequency");
+ info.buffer_enable_node_path = base_dir + string("buffer/enable");
+ info.buffer_length_node_path = base_dir + string("buffer/length");
+ info.trigger_node_path = base_dir + string("trigger/current_trigger");
+
+ return true;
+}
+
+static bool get_sensorhub_iio_node_info(const string &interval_node_name, const string& device_num, node_info &info)
+{
+ const string base_dir = string("/sys/bus/iio/devices/iio:device") + device_num + string("/");
+ const string hub_dir = "/sys/class/sensors/ssp_sensor/";
+
+ info.data_node_path = string("/dev/iio:device") + device_num;
+ info.enable_node_path = hub_dir + string("enable");
+ info.interval_node_path = hub_dir + interval_node_name;
+ info.buffer_enable_node_path = base_dir + string("buffer/enable");
+ info.buffer_length_node_path = base_dir + string("buffer/length");
+ return true;
+}
+
+static bool get_input_event_node_info(const string& device_num, node_info &info)
+{
+ string base_dir;
+ string event_num;
+
+ base_dir = string("/sys/class/input/input") + device_num + string("/");
+
+ if (!get_event_num(base_dir, event_num))
+ return false;
+
+ info.data_node_path = string("/dev/input/event") + event_num;
+
+ info.enable_node_path = base_dir + string("enable");
+ info.interval_node_path = base_dir + string("poll_delay");
+ return true;
+}
+
+static bool get_sensorhub_input_event_node_info(const string &interval_node_name, const string& device_num, node_info &info)
+{
+ const string base_dir = "/sys/class/sensors/ssp_sensor/";
+ string event_num;
+
+ string input_dir = string("/sys/class/input/input") + device_num + string("/");
+
+ if (!get_event_num(input_dir, event_num))
+ return false;
+
+ info.data_node_path = string("/dev/input/event") + event_num;
+ info.enable_node_path = base_dir + string("enable");
+ info.interval_node_path = base_dir + interval_node_name;
+ return true;
+}
+
+static bool get_node_value(const string &node_path, int &value)
+{
+ ifstream node(node_path, ifstream::binary);
+
+ if (!node)
+ return false;
+
+ node >> value;
+
+ return true;
+}
+
+static bool get_input_method(const string &key, int &method, string &device_num)
+{
+ input_method_info input_info[2] = {
+ {INPUT_EVENT_METHOD, "/sys/class/input/", "input"},
+ {IIO_METHOD, "/sys/bus/iio/devices/", "iio:device"}
+ };
+
+ const int input_info_len = sizeof(input_info)/sizeof(input_info[0]);
+ size_t prefix_size;
+ std::string name_node, name;
+ std::string d_name;
+ DIR *dir = NULL;
+ struct dirent *entry;
+ bool find = false;
+
+ for (int i = 0; i < input_info_len; ++i) {
+ prefix_size = input_info[i].prefix.size();
+
+ dir = opendir(input_info[i].dir_path.c_str());
+ retvm_if(!dir, false, "Failed to open directory[%s]", input_info[i].dir_path.c_str());
+
+ find = false;
+
+ while (true) {
+ entry = readdir(dir);
+ if (!entry) break;
+
+ d_name = std::string(entry->d_name);
+
+ if (d_name.compare(0, prefix_size, input_info[i].prefix) != 0)
+ continue;
+
+ name_node = input_info[i].dir_path + d_name + string("/name");
+
+ ifstream infile(name_node.c_str());
+ if (!infile)
+ continue;
+
+ infile >> name;
+
+ if (name != key)
+ continue;
+
+ device_num = d_name.substr(prefix_size, d_name.size() - prefix_size);
+ find = true;
+ method = input_info[i].method;
+ break;
+ }
+
+ closedir(dir);
+
+ if (find)
+ break;
+ }
+
+ return find;
+}
+
+bool util::set_monotonic_clock(int fd)
+{
+#ifdef EVIOCSCLOCKID
+ int clockId = CLOCK_MONOTONIC;
+ if (ioctl(fd, EVIOCSCLOCKID, &clockId) != 0) {
+ _E("Fail to set monotonic timestamp for fd[%d]", fd);
+ return false;
+ }
+#endif
+ return true;
+}
+
+bool util::set_enable_node(const string &node_path, bool sensorhub_controlled, bool enable, int enable_bit)
+{
+ int prev_status, status;
+
+ if (!get_node_value(node_path, prev_status)) {
+ ERR("Failed to get node: %s", node_path.c_str());
+ return false;
+ }
+
+ int _enable_bit = sensorhub_controlled ? enable_bit : 0;
+
+ if (enable)
+ status = prev_status | (1 << _enable_bit);
+ else
+ status = prev_status & (~(1 << _enable_bit));
+
+ if (!set_node_value(node_path, status)) {
+ ERR("Failed to set node: %s", node_path.c_str());
+ return false;
+ }
+
+ return true;
+}
+
+unsigned long long util::get_timestamp(void)
+{
+ struct timespec t;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
+}
+
+unsigned long long util::get_timestamp(timeval *t)
+{
+ if (!t) {
+ ERR("t is NULL");
+ return 0;
+ }
+
+ return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec);
+}
+
+bool util::is_sensorhub_controlled(const string &key)
+{
+ string key_node = string("/sys/class/sensors/ssp_sensor/") + key;
+
+ if (access(key_node.c_str(), F_OK) == 0)
+ return true;
+
+ return false;
+}
+
+bool util::get_node_info(const node_info_query &query, node_info &info)
+{
+ int method;
+ string device_num;
+
+ if (!get_input_method(query.key, method, device_num)) {
+ ERR("Failed to get input method for %s", query.key.c_str());
+ return false;
+ }
+
+ info.method = method;
+
+ if (method == IIO_METHOD) {
+ if (query.sensorhub_controlled)
+ return get_sensorhub_iio_node_info(query.sensorhub_interval_node_name, device_num, info);
+ else
+ return get_iio_node_info(query.iio_enable_node_name, device_num, info);
+ } else {
+ if (query.sensorhub_controlled)
+ return get_sensorhub_input_event_node_info(query.sensorhub_interval_node_name, device_num, info);
+ else
+ return get_input_event_node_info(device_num, info);
+ }
+}
+
+void util::show_node_info(node_info &info)
+{
+ if (info.data_node_path.size())
+ INFO("Data node: %s", info.data_node_path.c_str());
+ if (info.enable_node_path.size())
+ INFO("Enable node: %s", info.enable_node_path.c_str());
+ if (info.interval_node_path.size())
+ INFO("Interval node: %s", info.interval_node_path.c_str());
+ if (info.buffer_enable_node_path.size())
+ INFO("Buffer enable node: %s", info.buffer_enable_node_path.c_str());
+ if (info.buffer_length_node_path.size())
+ INFO("Buffer length node: %s", info.buffer_length_node_path.c_str());
+ if (info.trigger_node_path.size())
+ INFO("Trigger node: %s", info.trigger_node_path.c_str());
+}
+
+bool util::set_node_value(const string &node_path, int value)
+{
+ ofstream node(node_path, ofstream::binary);
+
+ if (!node)
+ return false;
+
+ node << value;
+
+ return true;
+}
+
+bool util::set_node_value(const string &node_path, unsigned long long value)
+{
+ ofstream node(node_path, ofstream::binary);
+
+ if (!node)
+ return false;
+
+ node << value;
+
+ return true;
+}
--- /dev/null
+/*
+ * 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 __SENSOR_UTIL_H__
+#define __SENSOR_UTIL_H__
+
+#include <sys/time.h>
+#include <string>
+
+typedef struct {
+ int method;
+ std::string data_node_path;
+ std::string enable_node_path;
+ std::string interval_node_path;
+ std::string buffer_enable_node_path;
+ std::string buffer_length_node_path;
+ std::string trigger_node_path;
+} node_info;
+
+typedef struct {
+ bool sensorhub_controlled;
+ std::string sensor_type;
+ std::string key;
+ std::string iio_enable_node_name;
+ std::string sensorhub_interval_node_name;
+} node_info_query;
+
+enum input_method {
+ IIO_METHOD = 0,
+ INPUT_EVENT_METHOD = 1,
+};
+
+typedef struct {
+ int method;
+ std::string dir_path;
+ std::string prefix;
+} input_method_info;
+
+namespace util {
+ bool set_monotonic_clock(int fd);
+
+ bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0);
+
+ unsigned long long get_timestamp(void);
+ unsigned long long get_timestamp(timeval *t);
+
+ bool is_sensorhub_controlled(const std::string &key);
+ bool get_node_info(const node_info_query &query, node_info &info);
+ void show_node_info(node_info &info);
+ bool set_node_value(const std::string &node_path, int value);
+ bool set_node_value(const std::string &node_path, unsigned long long value);
+}
+
+#endif /* __SENSOR_UTIL_H__ */
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(sensor-haltest C CXX)
+SET(GTEST_TEST "sensor-haltest")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+ glib-2.0
+ gio-2.0
+ gmock
+ dlog )
+INCLUDE(FindPkgConfig)
+pkg_check_modules(gtest_pkgs REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${gtest_pkgs_CFLAGS})
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE -fPIC")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+ GET_FILENAME_COMPONENT (src_name ${src} NAME_WE)
+ MESSAGE("${src_name}")
+ ADD_EXECUTABLE(${src_name} ${SRCS} ${src})
+ TARGET_LINK_LIBRARIES(${src_name} ${gtest_LDFLAGS} ${gtest_pkgs_LDFLAGS} -ldl)
+ INSTALL(TARGETS ${src_name} DESTINATION /usr/bin)
+ENDFOREACH()
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2018 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 <glib.h>
+#include <string.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+#include <iostream>
+
+
+#include <accel/accel_device.h>
+#include <proxi/proxi_device.h>
+#include <sensorhub/sensorhub.h>
+#include "sensor_common.h"
+
+using namespace std;
+
+//#define SENSOR_NAME "SENSOR_ACCELEROMETER"
+//#define SENSOR_TYPE_ACCEL "ACCEL"
+
+//#define INPUT_NAME "accelerometer_sensor"
+
+
+#define SENSOR_SUPPORT_CHECK(name) \
+ do {\
+ if (!sensor_supported) {\
+ cout << #name <<" SENSOR NOT SUPPORTED" << endl;\
+ EXPECT_EQ(ret, SENSOR_ERROR_NOT_SUPPORTED);\
+ return;\
+ }\
+ } while (0)
+
+
+
+/*
+ * accel device test class
+ */
+class AccelSensorHalTest : public testing::Test
+{
+public:
+ int ret;
+ bool sensor_supported;
+ sensor_device *sensor_handle = NULL;
+
+public:
+ virtual void SetUp()
+ {
+ sensor_supported = false;
+ sensor_handle = new accel_device;
+ if (sensor_handle == NULL) {
+ cout << "accel sensor init failed " << endl;
+ return;
+ }
+ sensor_supported = true;
+ }
+ virtual void TearDown()
+ {
+ if(sensor_handle) {
+ delete sensor_handle;
+ sensor_handle = NULL;
+ }
+ sensor_supported = false;
+ }
+ /*int GetSupportedFormat(int index)
+ {
+ return 0;
+ }*/
+};
+
+/*
+ * proxi device test class
+ */
+class ProxiSensorHalTest : public testing::Test
+{
+public:
+ int ret;
+ bool sensor_supported;
+ sensor_device *sensor_handle = NULL;
+
+public:
+ virtual void SetUp()
+ {
+ sensor_supported = false;
+ sensor_handle = new proxi_device;
+ if (sensor_handle == NULL) {
+ cout << "proximity sensor init failed " << endl;
+ return;
+ }
+ sensor_supported = true;
+ }
+ virtual void TearDown()
+ {
+ if(sensor_handle) {
+ delete sensor_handle;
+ sensor_handle = NULL;
+ }
+ sensor_supported = false;
+ }
+ /*int GetSupportedFormat(int index)
+ {
+ return 0;
+ }*/
+};
+
+
+
+#ifdef SENSORHUB
+
+/*
+ * sensorhub device test class
+ */
+class SensorHubHalTest : public testing::Test
+{
+public:
+ int ret;
+ bool sensor_supported;
+ sensor_device *sensor_handle = NULL;
+
+public:
+ virtual void SetUp()
+ {
+ sensor_supported = false;
+ sensor_handle = new sensorhub_device;
+ if (sensor_handle == NULL) {
+ cout << "Sensorhub sensor init failed " << endl;
+ return;
+ }
+ sensor_supported = true;
+ }
+ virtual void TearDown()
+ {
+ if(sensor_handle) {
+ delete sensor_handle;
+ sensor_handle = NULL;
+ }
+ sensor_supported = false;
+ }
+ /*int GetSupportedFormat(int index)
+ {
+ return 0;
+ }*/
+};
+
+#endif
+
+/**
+ * @testcase get_poll_fdP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, get fd of sensor device
+ * @apicovered get_poll_fd
+ * @passcase Returns valid node handle value
+ * @failcase Returns invalid node handle value
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, get_poll_fdP)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ int node_handle = 0;
+ node_handle = sensor_handle->get_poll_fd();
+ EXPECT_NE(node_handle, 0);
+}
+
+/**
+ * @testcase get_sensorsP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Get sensor data
+ * @apicovered get_sensors
+ * @passcase get valid sensor info
+ * @failcase get invalid sensor info
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, get_sensorsP)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ const sensor_info_t *sensor_info_tc = nullptr;
+ ret = sensor_handle->get_sensors(&sensor_info_tc);
+ EXPECT_NE(sensor_info_tc, nullptr);
+ EXPECT_EQ(ret, 1);
+}
+
+/**
+ * @testcase get_sensorsN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Get sensor data
+ * @apicovered get_sensors
+ * @passcase when invalid parameter passed, returns invalid parameter error
+ * @failcase when invalid parameter passed, doesn't return invalid paramter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, get_sensorsN)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ ret = sensor_handle->get_sensors(nullptr);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+
+}
+
+/**
+ * @testcase enableP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Enable Sensor
+ * @apicovered enable
+ * @passcase when valid id passed, returns 1
+ * @failcase when valid id passed, doesn't returns 1
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, enableP)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ bool res = false;
+ uint32_t id = 1;
+ res = sensor_handle->enable(id);
+ EXPECT_EQ(res, true);
+}
+
+/**
+ * @testcase enableN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Enable Sensor
+ * @apicovered enable
+ * @passcase when invalid id passed, returns invalid parameter error
+ * @failcase when invalid id passed, doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, enableN)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ bool res = true;
+ uint32_t id = 0;
+ res = sensor_handle->enable(id);
+ EXPECT_EQ(res, false);
+ res = true;
+ id = 10;
+ res = sensor_handle->enable(id);
+ EXPECT_EQ(res, false);
+
+}
+
+/**
+ * @testcase disableP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Disable Sensor
+ * @apicovered disable
+ * @passcase when valid id passed, returns true
+ * @failcase when valid id passed, doesn't returns true
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, disableP)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ bool res = false;
+ uint32_t id = 1;
+ res = sensor_handle->disable(id);
+ EXPECT_EQ(res, true);
+
+}
+
+/**
+ * @testcase disableN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Disable Sensor
+ * @apicovered disable
+ * @passcase when invalid id passed, returns invalid parameter error
+ * @failcase when invalid id passed, doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, disableN)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ bool res = true;
+ uint32_t id = 0;
+ res = sensor_handle->disable(id);
+ EXPECT_EQ(res, false);
+ res = true;
+ id = 10;
+ res = sensor_handle->disable(id);
+ EXPECT_EQ(res, false);
+}
+
+/**
+ * @testcase read_fdP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Reads sensosr device id
+ * @apicovered read_fd
+ * @passcase get valid id and returns other than zero
+ * @failcase get invalid id and returns other zero
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, read_fdP)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ uint32_t *id = nullptr;
+ bool res = false;
+ res = sensor_handle->enable(1);
+ EXPECT_EQ(res, true);
+ ret = sensor_handle->read_fd(&id);
+ EXPECT_NE(id, nullptr);
+ EXPECT_NE(ret, 0);
+}
+
+/**
+ * @testcase read_fdN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Reads sensosr device id
+ * @apicovered read_fd
+ * @passcase when invalid id passed, returns invalid parameter error
+ * @failcase when invalid id passed, doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, read_fdN)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ ret = sensor_handle->read_fd(nullptr);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase get_dataP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Gets Sensor data and data size
+ * @apicovered get_data
+ * @passcase Gets valid data and length and returns 0
+ * @failcase Doesn't get valid or length or doesn't return 0
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, get_dataP)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ uint32_t id = 1;
+ sensor_data_t *data = NULL;
+ int length = 0;
+ ret = sensor_handle->get_data(id, &data, &length);
+ EXPECT_EQ(ret, 0);
+ EXPECT_NE(data, nullptr);
+ EXPECT_NE(length, 0);
+}
+
+/**
+ * @testcase get_dataN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type.... auto
+ * @description Negative, Gets Sensor data and data size
+ * @apicovered get_data
+ * @passcase Returns invalid parameter error
+ * @failcase Doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, get_dataN)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ uint32_t id = 1;
+ sensor_data_t *data = nullptr;
+ int length = 0;
+ ret = sensor_handle->get_data(id, nullptr, &length);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+ data = nullptr;
+ ret = sensor_handle->get_data(id, &data, nullptr);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+ id = 0;
+ data = nullptr;
+ length = 0;
+ ret = sensor_handle->get_data(id, &data, &length);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+}
+
+
+/**
+ * @testcase set_intervalP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Set Interval for sensor response
+ * @apicovered set_interval
+ * @passcase when innterval is set, it returns true
+ * @failcase Returns false
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, set_intervalP)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ uint32_t id = 1;
+ unsigned long val = 10;
+ bool res = false;
+ res = sensor_handle->set_interval(id, val);
+ EXPECT_EQ(res, true);
+
+}
+
+/**
+ * @testcase set_intervalN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Set Interval for sensor response
+ * @apicovered set_interval
+ * @passcase Returns Invalid paramter error
+ * @failcase Doesn't returns Invalid paramter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(AccelSensorHalTest, set_intervalN)
+{
+ SENSOR_SUPPORT_CHECK(ACCEL);
+ uint32_t id = 0;
+ unsigned long val = 1;
+ bool res = true;
+ res = sensor_handle->set_interval(id, val);
+ EXPECT_EQ(res, false);
+ id = 10;
+ res = true;
+ res = sensor_handle->set_interval(id, val);
+ EXPECT_EQ(res, false);
+
+}
+
+
+/**** PROXI Device TESTS **************/
+
+
+/**
+ * @testcase get_poll_fdP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, get fd of sensor device
+ * @apicovered get_poll_fd
+ * @passcase Returns valid node handle value
+ * @failcase Returns invalid node handle value
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, get_poll_fdP)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ int node_handle = 0;
+ node_handle = sensor_handle->get_poll_fd();
+ EXPECT_NE(node_handle, 0);
+}
+
+/**
+ * @testcase get_sensorsP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Get sensor data
+ * @apicovered get_sensors
+ * @passcase get valid sensor info
+ * @failcase get invalid sensor info
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, get_sensorsP)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ const sensor_info_t *sensor_info_tc = nullptr;
+ ret = sensor_handle->get_sensors(&sensor_info_tc);
+ EXPECT_NE(sensor_info_tc, nullptr);
+ EXPECT_EQ(ret, 1);
+}
+
+/**
+ * @testcase get_sensorsN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Get sensor data
+ * @apicovered get_sensors
+ * @passcase when invalid parameter passed, returns invalid parameter error
+ * @failcase when invalid parameter passed, doesn't return invalid paramter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, get_sensorsN)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ ret = sensor_handle->get_sensors(nullptr);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+
+}
+
+/**
+ * @testcase enableP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Enable Sensor
+ * @apicovered enable
+ * @passcase when valid id passed, returns 1
+ * @failcase when valid id passed, doesn't returns 1
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, enableP)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ bool res = false;
+ uint32_t id = 1;
+ res = sensor_handle->enable(id);
+ EXPECT_EQ(res, true);
+}
+
+/**
+ * @testcase enableN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Enable Sensor
+ * @apicovered enable
+ * @passcase when invalid id passed, returns invalid parameter error
+ * @failcase when invalid id passed, doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, enableN)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ bool res = true;
+ uint32_t id = 0;
+ res = sensor_handle->enable(id);
+ EXPECT_EQ(res, false);
+ res = true;
+ id = 10;
+ res = sensor_handle->enable(id);
+ EXPECT_EQ(res, false);
+
+}
+
+/**
+ * @testcase disableP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Disable Sensor
+ * @apicovered disable
+ * @passcase when valid id passed, returns true
+ * @failcase when valid id passed, doesn't returns true
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, disableP)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ bool res = false;
+ uint32_t id = 1;
+ res = sensor_handle->disable(id);
+ EXPECT_EQ(res, true);
+
+}
+
+/**
+ * @testcase disableN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Disable Sensor
+ * @apicovered disable
+ * @passcase when invalid id passed, returns invalid parameter error
+ * @failcase when invalid id passed, doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, disableN)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ bool res = true;
+ uint32_t id = 0;
+ res = sensor_handle->disable(id);
+ EXPECT_EQ(res, false);
+ res = true;
+ id = 10;
+ res = sensor_handle->disable(id);
+ EXPECT_EQ(res, false);
+}
+
+
+/**
+ * @testcase get_dataP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Gets Sensor data and data size
+ * @apicovered get_data
+ * @passcase Gets valid data and length and returns 0
+ * @failcase Doesn't get valid or length or doesn't return 0
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, get_dataP)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ uint32_t id = 1;
+ sensor_data_t *data = NULL;
+ int length = 0;
+ ret = sensor_handle->get_data(id, &data, &length);
+ EXPECT_EQ(ret, 0);
+ EXPECT_NE(data, nullptr);
+ EXPECT_NE(length, 0);
+}
+
+/**
+ * @testcase get_dataN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type.... auto
+ * @description Negative, Gets Sensor data and data size
+ * @apicovered get_data
+ * @passcase Returns invalid parameter error
+ * @failcase Doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, get_dataN)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ uint32_t id = 1;
+ sensor_data_t *data = nullptr;
+ int length = 0;
+ ret = sensor_handle->get_data(id, nullptr, &length);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+ data = nullptr;
+ ret = sensor_handle->get_data(id, &data, nullptr);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+ id = 0;
+ data = nullptr;
+ length = 0;
+ ret = sensor_handle->get_data(id, &data, &length);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+}
+
+#ifdef MANUAL_TEST
+
+/**
+ * @testcase read_fdP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Reads sensosr device id
+ * @apicovered read_fd
+ * @passcase get valid id and returns other than zero
+ * @failcase get invalid id and returns other zero
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, read_fdP)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ uint32_t *id = nullptr;
+ bool res = false;
+ res = sensor_handle->enable(1);
+ EXPECT_EQ(res, true);
+ ret = sensor_handle->read_fd(&id);
+ EXPECT_NE(id, nullptr);
+ EXPECT_NE(ret, 0);
+}
+
+/**
+ * @testcase read_fdN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Reads sensosr device id
+ * @apicovered read_fd
+ * @passcase when invalid id passed, returns invalid parameter error
+ * @failcase when invalid id passed, doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(ProxiSensorHalTest, read_fdN)
+{
+ SENSOR_SUPPORT_CHECK(PROXIMITY);
+ ret = sensor_handle->read_fd(nullptr);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+}
+#endif //MANUAL_TEST
+
+
+#ifdef SENSORHUB
+ /**** SENSORHUB Device TESTS **************/
+
+/**
+ * @testcase get_poll_fdP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, get fd of sensor device
+ * @apicovered get_poll_fd
+ * @passcase Returns valid node handle value
+ * @failcase Returns invalid node handle value
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, get_poll_fdP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ int node_handle = 0;
+ node_handle = sensor_handle->get_poll_fd();
+ EXPECT_NE(node_handle, 0);
+}
+
+/**
+ * @testcase get_sensorsP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Get sensor data
+ * @apicovered get_sensors
+ * @passcase get valid sensor info
+ * @failcase get invalid sensor info
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, get_sensorsP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ const sensor_info_t *sensor_info_tc = nullptr;
+ ret = sensor_handle->get_sensors(&sensor_info_tc);
+ EXPECT_NE(sensor_info_tc, nullptr);
+ EXPECT_EQ(ret, 1);
+}
+
+/**
+ * @testcase get_sensorsN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Get sensor data
+ * @apicovered get_sensors
+ * @passcase when invalid parameter passed, returns invalid parameter error
+ * @failcase when invalid parameter passed, doesn't return invalid paramter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, get_sensorsN)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ ret = sensor_handle->get_sensors(nullptr);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+
+}
+
+/**
+ * @testcase enableP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Enable Sensor
+ * @apicovered enable
+ * @passcase when valid id passed, returns 1
+ * @failcase when valid id passed, doesn't returns 1
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, enableP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ bool res = false;
+ uint32_t id = 1;
+ res = sensor_handle->enable(id);
+ EXPECT_EQ(res, true);
+}
+
+/**
+ * @testcase enableN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Enable Sensor
+ * @apicovered enable
+ * @passcase when invalid id passed, returns invalid parameter error
+ * @failcase when invalid id passed, doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, enableN)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ bool res = true;
+ uint32_t id = 0;
+ res = sensor_handle->enable(id);
+ EXPECT_EQ(res, false);
+ res = true;
+ id = 10;
+ res = sensor_handle->enable(id);
+ EXPECT_EQ(res, false);
+
+}
+
+/**
+ * @testcase disableP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Disable Sensor
+ * @apicovered disable
+ * @passcase when valid id passed, returns true
+ * @failcase when valid id passed, doesn't returns true
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, disableP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ bool res = false;
+ uint32_t id = 1;
+ res = sensor_handle->disable(id);
+ EXPECT_EQ(res, true);
+
+}
+
+/**
+ * @testcase disableN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Disable Sensor
+ * @apicovered disable
+ * @passcase when invalid id passed, returns invalid parameter error
+ * @failcase when invalid id passed, doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, disableN)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ bool res = true;
+ uint32_t id = 0;
+ res = sensor_handle->disable(id);
+ EXPECT_EQ(res, false);
+ res = true;
+ id = 10;
+ res = sensor_handle->disable(id);
+ EXPECT_EQ(res, false);
+}
+
+/**
+ * @testcase read_fdP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Reads sensosr device id
+ * @apicovered read_fd
+ * @passcase get valid id and returns other than zero
+ * @failcase get invalid id and returns other zero
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, read_fdP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t *id = nullptr;
+ bool res = false;
+ res = sensor_handle->enable(1);
+ EXPECT_EQ(res, true);
+ ret = sensor_handle->read_fd(&id);
+ EXPECT_NE(id, nullptr);
+ EXPECT_NE(ret, 0);
+}
+
+/**
+ * @testcase read_fdN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Reads sensosr device id
+ * @apicovered read_fd
+ * @passcase when invalid id passed, returns invalid parameter error
+ * @failcase when invalid id passed, doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, read_fdN)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ ret = sensor_handle->read_fd(nullptr);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase get_dataP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Gets Sensor data and data size
+ * @apicovered get_data
+ * @passcase Gets valid data and length and returns 0
+ * @failcase Doesn't get valid or length or doesn't return 0
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, get_dataP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = 1;
+ sensor_data_t *data = NULL;
+ int length = 0;
+ ret = sensor_handle->get_data(id, &data, &length);
+ EXPECT_EQ(ret, 0);
+ EXPECT_NE(data, nullptr);
+ EXPECT_NE(length, 0);
+}
+
+/**
+ * @testcase get_dataN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type.... auto
+ * @description Negative, Gets Sensor data and data size
+ * @apicovered get_data
+ * @passcase Returns invalid parameter error
+ * @failcase Doesn't returns invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, get_dataN)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = 1;
+ sensor_data_t *data = nullptr;
+ int length = 0;
+ ret = sensor_handle->get_data(id, nullptr, &length);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+ data = nullptr;
+ ret = sensor_handle->get_data(id, &data, nullptr);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+ id = 0;
+ data = nullptr;
+ length = 0;
+ ret = sensor_handle->get_data(id, &data, &length);
+ EXPECT_EQ(ret, SENSOR_ERROR_INVALID_PARAMETER);
+}
+
+
+/**
+ * @testcase set_intervalP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Set Interval for sensor response
+ * @apicovered set_interval
+ * @passcase when innterval is set, it returns true
+ * @failcase Returns false
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, set_intervalP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = 1;
+ unsigned long val = 10;
+ bool res = false;
+ res = sensor_handle->set_interval(id, val);
+ EXPECT_EQ(res, true);
+
+}
+
+/**
+ * @testcase set_intervalN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Set Interval for sensor response
+ * @apicovered set_interval
+ * @passcase Returns Invalid paramter error
+ * @failcase Doesn't returns Invalid paramter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, set_intervalN)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = 0;
+ unsigned long val = 1;
+ bool res = true;
+ res = sensor_handle->set_interval(id, val);
+ EXPECT_EQ(res, false);
+ id = 10;
+ res = true;
+ res = sensor_handle->set_interval(id, val);
+ EXPECT_EQ(res, false);
+
+}
+
+/**
+ * @testcase set_batch_latencyP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, sets batch latency to sensor
+ * @apicovered set_batch_latency
+ * @passcase upon latency setting it return SENSOR_ERROR_NONE
+ * @failcase upon latency setting it does not return SENSOR_ERROR_NONE
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, set_batch_latencyP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = 0;
+ unsigned long val = 1;
+ bool res = false;
+ res = sensor_handle->set_batch_latency(id, val);
+ EXPECT_EQ(res, true);
+}
+
+/**
+ * @testcase set_batch_latencyN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, sets batch latency to sensor
+ * @apicovered set_batch_latency
+ * @passcase upon latency setting it return Invalid parameter error
+ * @failcase upon latency setting it doesnot return Invalid parameter error
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, set_batch_latencyN)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = -1;
+ unsigned long val = 1;
+ bool res = true;
+ res = sensor_handle->set_batch_latency(id, val);
+ EXPECT_EQ(res, false);
+ res = true;
+ val = -1;
+ res = sensor_handle->set_batch_latency(id, val);
+ EXPECT_EQ(res, false);
+
+}
+
+/**
+ * @testcase set_attribute_intP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Set Integer attribute
+ * @apicovered set_attribute_int
+ * @passcase upon attribute setting it reurns true
+ * @failcase upon attribute setting it reurns false
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, set_attribute_intP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = 1;
+ int32_t attribute = 1, val = 1;
+ bool res = false;
+ res = sensor_handle->set_attribute_int(id, attribute, val);
+ EXPECT_EQ(res, true);
+
+}
+
+/**
+ * @testcase set_attribute_intN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Set Integer attribute
+ * @apicovered set_attribute_int
+ * @passcase upon wrong attribute setting it reurns false
+ * @failcase upon wrong attribute setting it reurns true
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, set_attribute_intN)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = -1;
+ int32_t attribute = 1, val = 1;
+ bool res = true;
+ res = sensor_handle->set_attribute_int(id, attribute, val);
+ EXPECT_EQ(res, false);
+ res = true;
+ attribute = -1;
+ id = 1;
+ res = sensor_handle->set_attribute_int(id, attribute, val);
+ EXPECT_EQ(res, false);
+ res = true;
+ attribute = 1;
+ id = 1;
+ val = -1;
+ res = sensor_handle->set_attribute_int(id, attribute, val);
+ EXPECT_EQ(res, false);
+
+}
+
+/**
+ * @testcase set_attribute_strP
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Positive, Set String attribute
+ * @apicovered set_attribute_str
+ * @passcase upon attribute setting it reurns true
+ * @failcase upon attribute setting it reurns false
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, set_attribute_strP)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = 1;
+ int32_t attribute = 1, len = 0;
+ char value[10] = "1";
+ len = 2;
+ bool res = false;
+ res = sensor_handle->set_attribute_str(id, attribute, value, len);
+ EXPECT_EQ(res, true);
+
+}
+
+/**
+ * @testcase set_attribute_strN
+ * @since_tizen 4.0
+ * @author SRID(srinivasa.m)
+ * @reviewer SRID(randeep.s)
+ * @type auto
+ * @description Negative, Set String attribute
+ * @apicovered set_attribute_str
+ * @passcase upon wrong attribute setting it reurns false
+ * @failcase upon wrong attribute setting it reurns true
+ * @precondition None
+ * @postcondition None
+ */
+TEST_F(SensorHubHalTest, set_attribute_strN)
+{
+ SENSOR_SUPPORT_CHECK(SENSORHUB);
+ uint32_t id = 1;
+ int32_t attribute = 1, len = 0;
+ char value[10] = "1";
+ len = 3;
+ bool res = true;
+ res = sensor_handle->set_attribute_str(id, attribute, value, len);
+ EXPECT_EQ(res, false);
+ attribute = -1;
+ res = true;
+ res = sensor_handle->set_attribute_str(id, attribute, NULL, len);
+ EXPECT_EQ(res, false);
+}
+#endif
+
+
+int main(int argc, char **argv)
+{
+ testing::InitGoogleTest(&argc, argv);
+
+ return RUN_ALL_TESTS();
+}
+