sensor hal for tw3
authorSusnata Sovalin <s.sovalin@samsung.com>
Mon, 25 Mar 2019 10:54:20 +0000 (16:24 +0530)
committerSusnata Sovalin <s.sovalin@samsung.com>
Mon, 25 Mar 2019 10:54:20 +0000 (16:24 +0530)
Change-Id: I8a6668ee3e3dd91066e03fba4d50436ac57b711f
Signed-off-by: Susnata Sovalin <s.sovalin@samsung.com>
26 files changed:
CMakeLists.txt [new file with mode: 0755]
LICENSE.APLv2 [new file with mode: 0644]
packaging/99-sensor.rules [new file with mode: 0644]
packaging/99-sensorhub.rules [new file with mode: 0644]
packaging/sensor-hal-tw3.manifest [new file with mode: 0644]
packaging/sensor-hal-tw3.spec [new file with mode: 0755]
src/accel/accel_device.cpp [new file with mode: 0755]
src/accel/accel_device.h [new file with mode: 0755]
src/create.cpp [new file with mode: 0644]
src/gyro/gyro_device.cpp [new file with mode: 0755]
src/gyro/gyro_device.h [new file with mode: 0644]
src/hrm/hrm_device.cpp [new file with mode: 0755]
src/hrm/hrm_device.h [new file with mode: 0644]
src/hrm_raw/hrm_raw_device.cpp [new file with mode: 0755]
src/hrm_raw/hrm_raw_device.h [new file with mode: 0755]
src/light/light_device.cpp [new file with mode: 0755]
src/light/light_device.h [new file with mode: 0644]
src/macro.h [new file with mode: 0644]
src/pressure/pressure_device.cpp [new file with mode: 0755]
src/pressure/pressure_device.h [new file with mode: 0644]
src/sensor_common.h [new file with mode: 0755]
src/sensor_log.h [new file with mode: 0644]
src/util.cpp [new file with mode: 0644]
src/util.h [new file with mode: 0644]
testcase/CMakeLists.txt [new file with mode: 0755]
testcase/sensor_device_haltest.cpp [new file with mode: 0755]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..d2b420a
--- /dev/null
@@ -0,0 +1,141 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(sensor-hal-tw3 CXX)
+INCLUDE(GNUInstallDirs)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(BINDIR "${PREFIX}/bin")
+SET(DEPENDENTS "dlog")
+
+SET(ACCEL "ON")
+SET(GYRO "ON")
+SET(GYRO_UNCAL "OFF")
+SET(PROXIMITY "OFF")
+SET(LIGHT "ON")
+SET(GEOMAG "OFF")
+SET(GEOMAG_UNCAL "OFF")
+SET(HRM_RAW "ON")
+SET(HRM "ON")
+SET(RV "OFF")
+SET(PRESSURE "ON")
+SET(TEMPERATURE "OFF")
+SET(HUMIDITY "OFF")
+SET(TEMP_HUMIDITY "OFF")
+SET(ULTRAVIOLET "OFF")
+SET(DUST "OFF")
+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_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-section -Wl,--print-gc-section")
+SET(CMAKE_VERBOSE_MAKEFILE OFF)
+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 ${DEPENDENTS})
+
+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("${GYRO}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/gyro/*.cpp)
+ADD_DEFINITIONS(-DENABLE_GYRO)
+ENDIF()
+
+IF("${GYRO_UNCAL}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/gyro_uncal/*.cpp)
+ADD_DEFINITIONS(-DENABLE_GYRO_UNCAL)
+ENDIF()
+
+IF("${PROXIMITY}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/proxi/*.cpp)
+ADD_DEFINITIONS(-DENABLE_PROXIMITY)
+ENDIF()
+
+IF("${LIGHT}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/light/*.cpp)
+ADD_DEFINITIONS(-DENABLE_LIGHT)
+ENDIF()
+
+IF("${GEOMAG}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/geomag/*.cpp)
+ADD_DEFINITIONS(-DENABLE_GEOMAG)
+ENDIF()
+
+IF("${GEOMAG_UNCAL}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/geo_uncal/*.cpp)
+ADD_DEFINITIONS(-DENABLE_GEOMAG_UNCAL)
+ENDIF()
+
+IF("${HRM_RAW}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/hrm_raw/*.cpp)
+ADD_DEFINITIONS(-DENABLE_HRM_RAW)
+ENDIF()
+
+IF("${HRM}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/hrm/*.cpp)
+ADD_DEFINITIONS(-DENABLE_HRM)
+ENDIF()
+
+IF("${RV}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/rv/*.cpp)
+ADD_DEFINITIONS(-DENABLE_RV)
+ENDIF()
+
+IF("${PRESSURE}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/pressure/*.cpp)
+ADD_DEFINITIONS(-DENABLE_PRESSURE)
+ENDIF()
+
+IF("${TEMPERATURE}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/temperature/*.cpp)
+ADD_DEFINITIONS(-DENABLE_TEMPERATURE)
+ENDIF()
+
+IF("${HUMIDITY}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/humidity/*.cpp)
+ADD_DEFINITIONS(-DENABLE_HUMIDITY)
+ENDIF()
+
+IF("${TEMP_HUMIDITY}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/temp_humidity/*.cpp)
+ADD_DEFINITIONS(-DENABLE_TEMP_HUMIDITY)
+ENDIF()
+
+IF("${ULTRAVIOLET}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/ultraviolet/*.cpp)
+ADD_DEFINITIONS(-DENABLE_ULTRAVIOLET)
+ENDIF()
+
+IF("${DUST}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/dust/*.cpp)
+ADD_DEFINITIONS(-DENABLE_DUST)
+ENDIF()
+
+IF("${SENSORHUB}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/sensorhub/*.cpp)
+ADD_DEFINITIONS(-DENABLE_SENSORHUB)
+ENDIF()
+
+MESSAGE("Sources: ${SRCS}")
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${HAL_PKGS_LDFLAGS})
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}/sensor)
+
+ADD_SUBDIRECTORY(testcase)
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100644 (file)
index 0000000..bbb021e
--- /dev/null
@@ -0,0 +1,203 @@
+Copyright (c) 2015 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 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.
diff --git a/packaging/99-sensor.rules b/packaging/99-sensor.rules
new file mode 100644 (file)
index 0000000..3799e36
--- /dev/null
@@ -0,0 +1,13 @@
+SUBSYSTEM!="input", GOTO="sensor_rules_end"
+ATTRS{poll_delay}!="", ENV{ID_INPUT_KEY}=""
+ATTRS{poll_delay}!="", ENV{ID_INPUT_KEYPAD}=""
+ATTRS{poll_delay}!="", ENV{ID_INPUT_KEYBOARD}=""
+ATTRS{poll_delay}!="", ENV{ID_INPUT_TOUCHPAD}=""
+ATTRS{poll_delay}!="", ENV{ID_INPUT_TOUCHSCREEN}=""
+ATTRS{poll_delay}!="", ENV{ID_INPUT_MOUSE}=""
+ATTRS{poll_delay}!="", ENV{ID_INPUT_JOYSTICK}=""
+
+ATTRS{poll_delay}!="", ACTION=="add", RUN+="/bin/chown sensor:input %S/%p/enable %S/%p/poll_delay"
+ATTRS{poll_delay}!="", ACTION=="add", RUN+="/bin/chsmack -a * %S/%p/enable %S/%p/poll_delay"
+
+LABEL="sensor_rules_end"
diff --git a/packaging/99-sensorhub.rules b/packaging/99-sensorhub.rules
new file mode 100644 (file)
index 0000000..d34f721
--- /dev/null
@@ -0,0 +1,11 @@
+SUBSYSTEMS=="sensors", DEVPATH=="*ssp_sensor*", \
+RUN+="/bin/sh -c '/bin/chown :input %S/%p/enable %S/%p/set_cal_data %S/%p/*_poll_delay'"
+
+SUBSYSTEMS=="sensors", DEVPATH=="*ssp_sensor*", \
+RUN+="/bin/sh -c '/bin/chsmack -a \* %S/%p/enable %S/%p/set_cal_data %S/%p/*_poll_delay'"
+
+SUBSYSTEMS=="misc", DEVPATH=="/devices/virtual/misc/ssp_sensorhub", \
+ENV{DEVNAME}=="/dev/ssp_sensorhub", GROUP="input", SECLABEL{smack}="*"
+
+KERNEL == "ssp_sensorhub", GROUP="sensor", MODE="0660" RUN+="/bin/chown -R sensor:sensor /sys/class/sensors/ssp_sensor/"
+KERNEL == "batch_io", GROUP="sensor", MODE="0660"
diff --git a/packaging/sensor-hal-tw3.manifest b/packaging/sensor-hal-tw3.manifest
new file mode 100644 (file)
index 0000000..75b0fa5
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+    <request>
+        <domain name="_"/>
+    </request>
+</manifest>
diff --git a/packaging/sensor-hal-tw3.spec b/packaging/sensor-hal-tw3.spec
new file mode 100755 (executable)
index 0000000..e7c2905
--- /dev/null
@@ -0,0 +1,62 @@
+Name:       sensor-hal-tw3
+Summary:    TW3 Sensor HAL
+Version:    1.0.0
+Release:    0
+Group:      Service Framework / Sensor
+License:    Apache-2.0
+Source0:    %{name}-%{version}.tar.gz
+Source1:    99-sensor.rules
+Source2:    99-sensorhub.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:  sensor-hal-devel
+
+
+%description
+TW3 Sensor HAL
+
+%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 .
+make %{?_smp_mflags}
+
+%install
+%make_install
+
+mkdir -p %{buildroot}%{_libdir}/udev/rules.d
+
+install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/udev/rules.d
+install -m 0644 %SOURCE2 %{buildroot}%{_libdir}/udev/rules.d
+
+%post
+/sbin/ldconfig
+
+%postun
+/sbin/ldconfig
+
+%files
+%manifest packaging/%{name}.manifest
+%{_libdir}/udev/rules.d/99-sensor.rules
+%{_libdir}/udev/rules.d/99-sensorhub.rules
+%{_libdir}/sensor/*.so
+%license LICENSE.APLv2
+
+%files haltests
+%manifest packaging/%{name}.manifest
+%{_bindir}/*haltest
diff --git a/src/accel/accel_device.cpp b/src/accel/accel_device.cpp
new file mode 100755 (executable)
index 0000000..964d443
--- /dev/null
@@ -0,0 +1,296 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "accel_device.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/input.h>
+
+#include "util.h"
+#include "sensor_common.h"
+#include "sensor_log.h"
+
+#define MODEL_NAME "BMI168"
+#define VENDOR "Bosch"
+#define RESOLUTION 16
+#define RAW_DATA_UNIT 0.244
+#define MIN_INTERVAL 1
+#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_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 (!util::set_monotonic_clock(m_node_handle))
+               throw ENXIO;
+
+       _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;
+
+       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;
+                       case REL_Z+1:
+                               fired_time |= SHORT_TO_UINT64(accel_input.value, 48);
+                               break;
+                       case REL_Z+2:
+                               fired_time |= SHORT_TO_UINT64(accel_input.value, 32);
+                               break;
+                       case REL_Z+3:
+                               fired_time |= SHORT_TO_UINT64(accel_input.value, 16);
+                               break;
+                       case REL_Z+4:
+                               fired_time |= SHORT_TO_UINT64(accel_input.value, 0);
+                               break;
+                       default:
+                               _E("accel_input event[type = %d, code = %d] is unknown.", accel_input.type, accel_input.code);
+                               return false;
+                       }
+               } else if (accel_input.type == EV_SYN) {
+                       syn = true;
+               } 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 / 1000;       /* ns to us */
+
+       //_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_input_event()) {
+               _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 = (sensor_data_t *)malloc(sizeof(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);
+}
diff --git a/src/accel/accel_device.h b/src/accel/accel_device.h
new file mode 100755 (executable)
index 0000000..34770be
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __ACCEL_DEVICE_H__
+#define __ACCEL_DEVICE_H__
+
+#include <sensor/sensor_hal.h>
+#include <string>
+#include <vector>
+
+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;
+
+       std::string m_data_node;
+       std::string m_enable_node;
+       std::string m_interval_node;
+
+       std::vector<uint32_t> event_ids;
+
+       bool update_value_input_event(void);
+       void raw_to_base(sensor_data_t *data);
+};
+
+#endif /* __ACCEL_DEVICE_H__ */
diff --git a/src/create.cpp b/src/create.cpp
new file mode 100644 (file)
index 0000000..263a2b8
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <sensor/sensor_hal.h>
+#include <sensor_log.h>
+#include <vector>
+
+#include "accel/accel_device.h"
+#include "gyro/gyro_device.h"
+#include "pressure/pressure_device.h"
+#include "light/light_device.h"
+#include "hrm_raw/hrm_raw_device.h"
+#include "hrm/hrm_device.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);
+}
+
+extern "C" int create(sensor_device_t **devices)
+{
+       create_sensor<accel_device>("Accelerometer");
+       create_sensor<gyro_device>("Gyroscope");
+       create_sensor<pressure_device>("Pressure");
+       create_sensor<light_device>("Light");
+       create_sensor<hrm_raw_device>("HRM Raw");
+       create_sensor<hrm_device>("HRM");
+
+       *devices = &devs[0];
+       return devs.size();
+}
diff --git a/src/gyro/gyro_device.cpp b/src/gyro/gyro_device.cpp
new file mode 100755 (executable)
index 0000000..d82b141
--- /dev/null
@@ -0,0 +1,295 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "gyro_device.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/input.h>
+
+#include "util.h"
+#include "sensor_common.h"
+#include "sensor_log.h"
+
+#define MODEL_NAME "BMI168"
+#define VENDOR "Boach"
+#define RESOLUTION 16
+#define RAW_DATA_UNIT 61.04
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
+
+#define SENSOR_NAME "SENSOR_GYROSCOPE"
+#define SENSOR_TYPE_GYRO "GYRO"
+
+#define INPUT_NAME "gyro_sensor"
+#define GYRO_SENSORHUB_POLL_NODE_NAME "gyro_poll_delay"
+
+#define DPS_TO_MDPS 1000
+#define RAW_DATA_TO_DPS_UNIT(X) ((float)(X)/((float)DPS_TO_MDPS))
+#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_GYROSCOPE,
+       event_type: (SENSOR_DEVICE_GYROSCOPE << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
+       model_name: MODEL_NAME,
+       vendor: VENDOR,
+       min_range: MIN_RANGE(RESOLUTION) * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT),
+       max_range: MAX_RANGE(RESOLUTION) * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT),
+       resolution: RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT),
+       min_interval: MIN_INTERVAL,
+       max_batch_count: MAX_BATCH_COUNT,
+       wakeup_supported: false
+};
+
+gyro_device::gyro_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 = GYRO_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_GYRO;
+       query.key = INPUT_NAME;
+       query.iio_enable_node_name = "gyro_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_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, "Failed to open gyro handle");
+               throw ENXIO;
+       }
+
+       if (!util::set_monotonic_clock(m_node_handle))
+               throw ENXIO;
+
+       _I("gyro_device is created");
+}
+
+gyro_device::~gyro_device()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       _I("gyro_device is destroyed");
+}
+
+int gyro_device::get_poll_fd(void)
+{
+       return m_node_handle;
+}
+
+int gyro_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 gyro_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_GYROSCOPE_ENABLE_BIT);
+       set_interval(id, m_polling_interval);
+
+       m_fired_time = 0;
+       _I("Enable gyroscope sensor");
+       return true;
+}
+
+bool gyro_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_GYROSCOPE_ENABLE_BIT);
+
+       _I("Disable gyroscope sensor");
+       return true;
+}
+
+bool gyro_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 gyro_device::update_value_input_event(void)
+{
+       int gyro_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 gyro_input;
+       _D("gyro event detection");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &gyro_input, sizeof(gyro_input));
+               if (len != sizeof(gyro_input)) {
+                       _E("gyro_file read fail, read_len = %d", len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (gyro_input.type == EV_REL) {
+                       switch (gyro_input.code) {
+                       case REL_RX:
+                               gyro_raw[0] = (int)gyro_input.value;
+                               x = true;
+                               break;
+                       case REL_RY:
+                               gyro_raw[1] = (int)gyro_input.value;
+                               y = true;
+                               break;
+                       case REL_RZ:
+                               gyro_raw[2] = (int)gyro_input.value;
+                               z = true;
+                               break;
+                       case REL_RZ+1:
+                               fired_time |= SHORT_TO_UINT64(gyro_input.value, 48);
+                               break;
+                       case REL_RZ+2:
+                               fired_time |= SHORT_TO_UINT64(gyro_input.value, 32);
+                               break;
+                       case REL_RZ+3:
+                               fired_time |= SHORT_TO_UINT64(gyro_input.value, 16);
+                               break;
+                       case REL_RZ+4:
+                               fired_time |= SHORT_TO_UINT64(gyro_input.value, 0);
+                               break;
+                       default:
+                               _E("gyro_input event[type = %d, code = %d] is unknown.", gyro_input.type, gyro_input.code);
+                               return false;
+                               break;
+                       }
+               } else if (gyro_input.type == EV_SYN) {
+                       syn = true;
+               } else {
+                       _E("gyro_input event[type = %d, code = %d] is unknown.", gyro_input.type, gyro_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 =  gyro_raw[0];
+       if (y)
+               m_y =  gyro_raw[1];
+       if (z)
+               m_z =  gyro_raw[2];
+
+       m_fired_time = NS_TO_US(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;
+}
+
+int gyro_device::read_fd(uint32_t **ids)
+{
+       retvm_if(ids == NULL || ids == nullptr, SENSOR_ERROR_INVALID_PARAMETER, "%s:NULL interface", SENSOR_NAME);
+
+       if (!update_value_input_event()) {
+               _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 gyro_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 = (sensor_data_t *)malloc(sizeof(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 gyro_device::raw_to_base(sensor_data_t *data)
+{
+       data->values[0] = data->values[0] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+       data->values[1] = data->values[1] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+       data->values[2] = data->values[2] * RAW_DATA_TO_DPS_UNIT(RAW_DATA_UNIT);
+}
diff --git a/src/gyro/gyro_device.h b/src/gyro/gyro_device.h
new file mode 100644 (file)
index 0000000..9c86499
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __GYRO_DEVICE_H__
+#define __GYRO_DEVICE_H__
+
+#include <sensor/sensor_hal.h>
+#include <string>
+#include <vector>
+
+class gyro_device : public sensor_device {
+public:
+       gyro_device();
+       virtual ~gyro_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;
+
+       std::string m_data_node;
+       std::string m_enable_node;
+       std::string m_interval_node;
+
+       std::vector<uint32_t> event_ids;
+
+       bool update_value_input_event(void);
+       void raw_to_base(sensor_data_t *data);
+};
+
+#endif /* __GYRO_DEVICE_H__ */
diff --git a/src/hrm/hrm_device.cpp b/src/hrm/hrm_device.cpp
new file mode 100755 (executable)
index 0000000..c96615a
--- /dev/null
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "hrm_device.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/input.h>
+
+#include "util.h"
+#include "sensor_common.h"
+#include "sensor_log.h"
+
+#define MODEL_NAME "AD45251"
+#define VENDOR "ANALOG DEVICES"
+#define MIN_RANGE 0
+#define MAX_RANGE 1000
+#define RESOLUTION 1
+#define RAW_DATA_UNIT 1
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
+
+#define SENSOR_NAME "SENSOR_HRM"
+#define SENSOR_TYPE_HRM "HRM"
+
+#define INPUT_NAME "hrm_lib_sensor"
+#define HRM_SENSORHUB_POLL_NODE_NAME "hrm_lib_poll_delay"
+
+#define MAX_ID 0x3
+
+
+static sensor_info_t sensor_info = {
+       id: 0x1,
+       name: SENSOR_NAME,
+       type: SENSOR_DEVICE_HRM,
+       event_type: (SENSOR_DEVICE_HRM << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
+       model_name: MODEL_NAME,
+       vendor: VENDOR,
+       min_range: MIN_RANGE,
+       max_range: MAX_RANGE,
+       resolution: RAW_DATA_UNIT,
+       min_interval: MIN_INTERVAL,
+       max_batch_count: MAX_BATCH_COUNT,
+       wakeup_supported: false
+};
+
+hrm_device::hrm_device()
+: m_node_handle(-1)
+, m_hr(0)
+, m_spo2(0)
+, m_peek_to_peek(0)
+, m_snr(0.0f)
+, m_polling_interval(1000)
+, m_fired_time(0)
+, m_interval_supported(false)
+, m_sensorhub_controlled(false)
+{
+       const std::string sensorhub_interval_node_name = HRM_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_HRM;
+       query.key = INPUT_NAME;
+       query.iio_enable_node_name = "hrm_lib_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_data_node = info.data_node_path;
+       m_enable_node = info.enable_node_path;
+       m_interval_node = info.interval_node_path;
+
+       if (access(m_interval_node.c_str(), F_OK) == 0)
+               m_interval_supported = true;
+
+       m_node_handle = open(m_data_node.c_str(), O_RDONLY);
+
+       if (m_node_handle < 0) {
+               _ERRNO(errno, _E, "Failed to open HRM handle");
+               throw ENXIO;
+       }
+
+       if (!util::set_monotonic_clock(m_node_handle))
+               throw ENXIO;
+
+       _I("hrm_device is created");
+}
+
+hrm_device::~hrm_device()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       _I("hrm_device is destroyed");
+}
+
+int hrm_device::get_poll_fd(void)
+{
+       return m_node_handle;
+}
+
+int hrm_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 hrm_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_HRM_LIB_ENABLE_BIT);
+       if (m_interval_supported)
+               set_interval(id, m_polling_interval);
+
+       m_fired_time = 0;
+       _I("Enable HRM sensor");
+       return true;
+}
+
+bool hrm_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_HRM_LIB_ENABLE_BIT);
+
+       _I("Disable HRM sensor");
+       return true;
+}
+
+bool hrm_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);
+
+       if (!m_interval_supported)
+               return true;
+
+       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 hrm_device::update_value_input_event(void)
+{
+       const float SNR_SIG_FIGS = 10000.0f;
+       const int HR_MAX = 300;
+       int hrm_raw[4] = {0, };
+       unsigned long long fired_time = 0;
+       int read_input_cnt = 0;
+       const int INPUT_MAX_BEFORE_SYN = 10;
+       bool syn = false;
+
+       struct input_event hrm_input;
+       _D("hrm event detection");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &hrm_input, sizeof(hrm_input));
+               if (len != sizeof(hrm_input)) {
+                       _E("hrm_file read fail, read_len = %d", len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (hrm_input.type == EV_REL) {
+                       switch (hrm_input.code) {
+                       case REL_X:
+                               hrm_raw[0] = (int)hrm_input.value - 1;
+                               break;
+                       case REL_Y:
+                               hrm_raw[1] = (int)hrm_input.value - 1;
+                               break;
+                       case REL_Z:
+                               hrm_raw[2] = (int)hrm_input.value - 1;
+                               break;
+                       default:
+                               _E("hrm_input event[type = %d, code = %d] is unknown.", hrm_input.type, hrm_input.code);
+                               return false;
+                               break;
+                       }
+               } else if (hrm_input.type == EV_SYN) {
+                       syn = true;
+                       fired_time = util::get_timestamp(&hrm_input.time);
+               } else {
+                       _E("hrm_input event[type = %d, code = %d] is unknown.", hrm_input.type, hrm_input.code);
+                       return false;
+               }
+       }
+
+       if (hrm_raw[0] * RAW_DATA_UNIT > HR_MAX) {
+               _E("Drop abnormal HR: %d", hrm_raw[0]);
+               return false;
+       }
+
+       m_hr = hrm_raw[0];
+       m_peek_to_peek = hrm_raw[1];
+       m_snr = ((float)hrm_raw[2] / SNR_SIG_FIGS);
+       m_spo2 = 0;
+       m_fired_time = fired_time;
+
+       return true;
+}
+
+int hrm_device::read_fd(uint32_t **ids)
+{
+       retvm_if(ids == NULL || ids == nullptr, SENSOR_ERROR_INVALID_PARAMETER, "%s:NULL interface", SENSOR_NAME);
+
+       if (!update_value_input_event()) {
+               _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 hrm_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 = (sensor_data_t *)malloc(sizeof(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 = 4;
+       sensor_data->values[0] = m_hr;
+       sensor_data->values[1] = m_spo2;
+       sensor_data->values[2] = m_peek_to_peek;
+       sensor_data->values[3] = m_snr;
+
+       raw_to_base(sensor_data);
+
+       *data = sensor_data;
+       *length = sizeof(sensor_data_t);
+
+       return 0;
+}
+
+void hrm_device::raw_to_base(sensor_data_t *data)
+{
+       data->values[0] = data->values[0] * RAW_DATA_UNIT;
+}
diff --git a/src/hrm/hrm_device.h b/src/hrm/hrm_device.h
new file mode 100644 (file)
index 0000000..d3067f1
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __HRM_DEVICE_H__
+#define __HRM_DEVICE_H__
+
+#include <sensor/sensor_hal.h>
+#include <string>
+#include <vector>
+
+class hrm_device : public sensor_device {
+public:
+       hrm_device();
+       virtual ~hrm_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_hr;
+       int m_spo2;
+       int m_peek_to_peek;
+       float m_snr;
+       unsigned long m_polling_interval;
+       unsigned long long m_fired_time;
+       bool m_interval_supported;
+       bool m_sensorhub_controlled;
+
+       std::string m_data_node;
+       std::string m_enable_node;
+       std::string m_interval_node;
+
+       std::vector<uint32_t> event_ids;
+
+       bool update_value_input_event(void);
+       void raw_to_base(sensor_data_t *data);
+};
+
+#endif /* __HRM_DEVICE_H__ */
diff --git a/src/hrm_raw/hrm_raw_device.cpp b/src/hrm_raw/hrm_raw_device.cpp
new file mode 100755 (executable)
index 0000000..a0a00d4
--- /dev/null
@@ -0,0 +1,313 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "hrm_raw_device.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/input.h>
+
+#include "macro.h"
+#include "util.h"
+#include "sensor_common.h"
+#include "sensor_log.h"
+
+#define MODEL_NAME "AD45251"
+#define VENDOR "ANALOG DEVICES"
+#define MIN_RANGE 0
+#define MAX_RANGE 1000
+#define RESOLUTION 1
+#define RAW_DATA_UNIT 1
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
+
+#define SENSOR_NAME "SENSOR_HRM_RAW"
+#define SENSOR_TYPE_HRM_RAW "HRM_RAW"
+
+#define INPUT_NAME "hrm_raw_sensor"
+#define HRM_SENSORHUB_POLL_NODE_NAME "hrm_poll_delay"
+
+#define INDEX_HRM_RAW 0x1
+#define INDEX_HRM_LED_GREEN 0x2
+
+#define POLL_1HZ_MS 1000
+
+#define INPUT_MAX_BEFORE_SYN 20
+#define INPUT_EVENT_BIAS 1
+#define INPUT_VALUE_COUNT 10
+#define MAX_ID 0x3
+
+
+static sensor_info_t sensor_info[] = {
+       {
+               id: INDEX_HRM_RAW,
+               name: SENSOR_NAME,
+               type: SENSOR_DEVICE_HRM_RAW,
+               event_type: (SENSOR_DEVICE_HRM_RAW << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
+               model_name: MODEL_NAME,
+               vendor: VENDOR,
+               min_range: MIN_RANGE,
+               max_range: MAX_RANGE,
+               resolution: RAW_DATA_UNIT,
+               min_interval: MIN_INTERVAL,
+               max_batch_count: MAX_BATCH_COUNT,
+               wakeup_supported: false
+       },
+       {
+               id: INDEX_HRM_LED_GREEN,
+               name: "HRM LED GREEN SENSOR",
+               type: SENSOR_DEVICE_HRM_LED_GREEN,
+               event_type: (SENSOR_DEVICE_HRM_LED_GREEN << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
+               model_name: MODEL_NAME,
+               vendor: VENDOR,
+               min_range: MIN_RANGE,
+               max_range: MAX_RANGE,
+               resolution: RAW_DATA_UNIT,
+               min_interval: MIN_INTERVAL,
+               max_batch_count: MAX_BATCH_COUNT,
+               wakeup_supported: false
+       }
+};
+
+hrm_raw_device::hrm_raw_device()
+: m_node_handle(-1)
+, m_data()
+, m_polling_interval(POLL_1HZ_MS)
+, m_raw_interval(POLL_1HZ_MS)
+, m_led_green_interval(POLL_1HZ_MS)
+, m_interval_supported(false)
+, m_sensorhub_controlled(false)
+, m_enable(0)
+{
+       const std::string sensorhub_interval_node_name = HRM_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_HRM_RAW;
+       query.key = INPUT_NAME;
+       query.iio_enable_node_name = "hrm_raw_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_data_node = info.data_node_path;
+       m_enable_node = info.enable_node_path;
+       m_interval_node = info.interval_node_path;
+
+       if (access(m_interval_node.c_str(), F_OK) == 0)
+               m_interval_supported = true;
+
+       m_node_handle = open(m_data_node.c_str(), O_RDONLY);
+
+       if (m_node_handle < 0) {
+               _ERRNO(errno, _E, "Failed to open node[%s]", m_data_node.c_str());
+               throw ENXIO;
+       }
+
+       if (!util::set_monotonic_clock(m_node_handle))
+               throw ENXIO;
+
+       _I("hrm_raw_device is created");
+}
+
+hrm_raw_device::~hrm_raw_device()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       _I("hrm_raw_device is destroyed");
+}
+
+int hrm_raw_device::get_poll_fd(void)
+{
+       return m_node_handle;
+}
+
+int hrm_raw_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 2;
+}
+
+bool hrm_raw_device::enable(uint32_t id)
+{
+       retvm_if(id == 0 || id > MAX_ID, false, "%s:Invalid ID Received", SENSOR_NAME);
+
+       ++m_enable;
+
+       if (m_enable > 1)
+               return true;
+
+       util::set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_HRM_RAW_ENABLE_BIT);
+       if (m_interval_supported)
+               set_interval(id, m_polling_interval);
+
+       m_data.timestamp = 0;
+       _I("Enable HRM Raw sensor");
+       return true;
+}
+
+bool hrm_raw_device::disable(uint32_t id)
+{
+       retvm_if(id == 0 || id > MAX_ID, false, "%s:Invalid ID Received", SENSOR_NAME);
+
+       --m_enable;
+
+       if (m_enable > 0)
+               return true;
+
+       util::set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_HRM_RAW_ENABLE_BIT);
+
+       m_enable = 0;
+       _I("Disable HRM Raw sensor");
+       return true;
+}
+
+bool hrm_raw_device::set_interval(uint32_t id, unsigned long val)
+{
+       unsigned long interval = 100;
+       unsigned long long polling_interval_ns;
+       retvm_if(id == 0 || id > MAX_ID, false, "%s:Invalid ID Received", SENSOR_NAME);
+
+       if (!m_interval_supported)
+               return true;
+
+       if (id == INDEX_HRM_LED_GREEN)
+               interval = (val > m_raw_interval)?m_raw_interval:val;
+       else
+               interval = (val > m_led_green_interval)?m_led_green_interval:val;
+
+       polling_interval_ns = ((unsigned long long)(interval) * 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, interval);
+       m_polling_interval = interval;
+
+       if (id == INDEX_HRM_LED_GREEN)
+               m_led_green_interval = val;
+       else
+               m_raw_interval = val;
+
+       return true;
+}
+
+bool hrm_raw_device::update_value_input_event(void)
+{
+       bool syn = false;
+       int read_input_cnt = 0;
+       int index = 0;
+       struct input_event hrm_raw_input;
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &hrm_raw_input, sizeof(hrm_raw_input));
+               if (len != sizeof(hrm_raw_input)) {
+                       _E("hrm_raw_file read fail, read_len = %d", len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (hrm_raw_input.type == EV_REL) {
+                       index = hrm_raw_input.code - REL_X;
+
+                       /* Check an avaiable value REL_X(0x00) ~ REL_MISC(0x09) */
+                       if (index >= INPUT_VALUE_COUNT) {
+                               _E("hrm_raw_input event[type = %d, code = %d] is unknown.", hrm_raw_input.type, index);
+                               return false;
+                       }
+                       m_data.values[index] = (unsigned int)hrm_raw_input.value - INPUT_EVENT_BIAS;
+                       _I("SRINIEVENT: EV_REL input had come, val:%d, index[%d]", hrm_raw_input.value, index);
+               } else if (hrm_raw_input.type == EV_SYN) {
+                       syn = true;
+                       m_data.timestamp = util::get_timestamp(&hrm_raw_input.time);
+                       m_data.value_count = INPUT_VALUE_COUNT;
+
+                       _I("SRINIEVENT: EV_SYN input had come, val:%d, index[%d]", hrm_raw_input.value, index);
+               } else {
+                       _E("hrm_raw_input event[type = %d, code = %d] is unknown.", hrm_raw_input.type, hrm_raw_input.code);
+                       return false;
+               }
+       }
+
+       if (!syn) {
+               _E("EV_SYN didn't come until %d inputs had come", read_input_cnt);
+               return false;
+       }
+       return true;
+}
+
+int hrm_raw_device::read_fd(uint32_t **ids)
+{
+       retvm_if(ids == NULL || ids == nullptr, SENSOR_ERROR_INVALID_PARAMETER, "%s:NULL interface", SENSOR_NAME);
+
+       if (!update_value_input_event()) {
+               _D("Failed to update value");
+               return false;
+       }
+
+       event_ids.clear();
+
+       int size = ARRAY_SIZE(sensor_info);
+
+       for (int i = 0; i < size; ++i)
+               event_ids.push_back(sensor_info[i].id);
+
+       *ids = &event_ids[0];
+
+       return event_ids.size();
+}
+
+int hrm_raw_device::get_data(uint32_t id, sensor_data_t **data, int *length)
+{
+       int remains = 1;
+       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 = (sensor_data_t *)malloc(sizeof(sensor_data_t));
+       retvm_if(!sensor_data, -ENOMEM, "Memory allocation failed");
+
+       sensor_data->accuracy = SENSOR_ACCURACY_GOOD;
+       sensor_data->timestamp = m_data.timestamp;
+
+       if (id == INDEX_HRM_LED_GREEN) {
+               sensor_data->value_count = 1;
+               sensor_data->values[0] = m_data.values[5];
+       } else {
+               sensor_data->value_count = m_data.value_count;
+               memcpy(sensor_data->values, m_data.values, m_data.value_count * sizeof(m_data.values[0]));
+       }
+       _I("SRINIHAL: Sensor Data:%.2f, id: %d", sensor_data->values[0], id);
+       *data = sensor_data;
+       *length = sizeof(sensor_data_t);
+
+       return --remains;
+}
diff --git a/src/hrm_raw/hrm_raw_device.h b/src/hrm_raw/hrm_raw_device.h
new file mode 100755 (executable)
index 0000000..bb10530
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __HRM_RAW_DEVICE_H__
+#define __HRM_RAW_DEVICE_H__
+
+#include <sensor/sensor_hal.h>
+#include <string>
+#include <vector>
+
+class hrm_raw_device : public sensor_device {
+public:
+       hrm_raw_device();
+       virtual ~hrm_raw_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;
+       sensor_data_t m_data;
+       unsigned long m_polling_interval;
+       unsigned long m_raw_interval;
+       unsigned long m_led_green_interval;
+
+       bool m_interval_supported;
+       bool m_sensorhub_controlled;
+       int m_enable;
+
+       std::string m_data_node;
+       std::string m_enable_node;
+       std::string m_interval_node;
+
+       std::vector<uint32_t> event_ids;
+
+       bool update_value_input_event(void);
+};
+
+#endif /* __HRM_RAW_DEVICE_H__ */
diff --git a/src/light/light_device.cpp b/src/light/light_device.cpp
new file mode 100755 (executable)
index 0000000..d40e8e6
--- /dev/null
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "light_device.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/input.h>
+
+#include "macro.h"
+#include "util.h"
+#include "sensor_common.h"
+#include "sensor_log.h"
+
+#define MODEL_NAME "TSL2584"
+#define VENDOR "AMS"
+#define MIN_RANGE 0
+#define MAX_RANGE 65536
+#define RESOLUTION 1
+#define RAW_DATA_UNIT 1
+#define MIN_INTERVAL 1
+#define MAX_BATCH_COUNT 0
+
+#define SENSOR_NAME "SENSOR_LIGHT"
+#define SENSOR_TYPE_LIGHT "LIGHT"
+
+#define INPUT_NAME "light_sensor"
+#define LIGHT_SENSORHUB_POLL_NODE_NAME "light_poll_delay"
+
+#define BIAS 1
+#define MAX_ID 0x3
+
+static sensor_info_t sensor_info = {
+       id: 0x1,
+       name: SENSOR_NAME,
+       type: SENSOR_DEVICE_LIGHT,
+       event_type: (SENSOR_DEVICE_LIGHT << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
+       model_name: MODEL_NAME,
+       vendor: VENDOR,
+       min_range: MIN_RANGE,
+       max_range: MAX_RANGE,
+       resolution: RAW_DATA_UNIT,
+       min_interval: MIN_INTERVAL,
+       max_batch_count: MAX_BATCH_COUNT,
+       wakeup_supported: false
+};
+
+light_device::light_device()
+: m_node_handle(-1)
+, m_lux(-1)
+, m_polling_interval(1000)
+, m_fired_time(0)
+, m_sensorhub_controlled(false)
+{
+       const std::string sensorhub_interval_node_name = LIGHT_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_LIGHT;
+       query.key = INPUT_NAME;
+       query.iio_enable_node_name = "light_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_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, "light handle open fail for light device");
+               throw ENXIO;
+       }
+
+       if (!util::set_monotonic_clock(m_node_handle))
+               throw ENXIO;
+
+       _I("light_device is created");
+}
+
+light_device::~light_device()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       _I("light_device is destroyed");
+}
+
+int light_device::get_poll_fd()
+{
+       return m_node_handle;
+}
+
+int light_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 light_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_LIGHT_ENABLE_BIT);
+       set_interval(id, m_polling_interval);
+
+       m_fired_time = 0;
+       _I("Enable light sensor");
+       return true;
+}
+
+bool light_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_LIGHT_ENABLE_BIT);
+
+       _I("Disable light sensor");
+       return true;
+}
+
+bool light_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 light_device::update_value_lux(void)
+{
+       int lux = -1;
+       struct input_event light_event;
+       _D("Light event detection");
+
+       int len = read(m_node_handle, &light_event, sizeof(light_event));
+       if (len == -1) {
+               _ERRNO(errno, _E, "Failed to read from m_node_handle");
+               return false;
+       }
+
+       if (light_event.type == EV_ABS && light_event.code == ABS_MISC) {
+               lux = light_event.value;
+       } else if (light_event.type == EV_REL && light_event.code == REL_RX) {
+               lux = light_event.value - BIAS;
+       } else {
+               _D("light input event[type = %d, code = %d] is unknown.", light_event.type, light_event.code);
+               return false;
+       }
+
+       _D("read event, len : %d, type : %x, code : %x, value : %x",
+               len, light_event.type, light_event.code, light_event.value);
+
+       _D("lux : %d", lux);
+
+       m_lux = lux;
+       m_fired_time = util::get_timestamp(&light_event.time);
+
+       return true;
+}
+
+int light_device::read_fd(uint32_t **ids)
+{
+       retvm_if(ids == NULL || ids == nullptr, SENSOR_ERROR_INVALID_PARAMETER, "%s:NULL interface", SENSOR_NAME);
+
+       if (!update_value_lux()) {
+               _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 light_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 = (sensor_data_t *)malloc(sizeof(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 = 1;
+       sensor_data->values[0] = (float)m_lux;
+
+       *data = sensor_data;
+       *length = sizeof(sensor_data_t);
+
+       return 0;
+}
diff --git a/src/light/light_device.h b/src/light/light_device.h
new file mode 100644 (file)
index 0000000..2a29dd7
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __LIGHT_DEVICE_H__
+#define __LIGHT_DEVICE_H__
+
+#include <sensor/sensor_hal.h>
+#include <string>
+#include <vector>
+
+class light_device : public sensor_device {
+public:
+       light_device();
+       virtual ~light_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_lux;
+       unsigned long m_polling_interval;
+       unsigned long long m_fired_time;
+       bool m_sensorhub_controlled;
+
+       std::string m_enable_node;
+       std::string m_data_node;
+       std::string m_interval_node;
+
+       std::vector<uint32_t> event_ids;
+
+       bool update_value_lux(void);
+};
+
+#endif /* __LIGHT_DEVICE_H__ */
diff --git a/src/macro.h b/src/macro.h
new file mode 100644 (file)
index 0000000..c2c1557
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __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__ */
diff --git a/src/pressure/pressure_device.cpp b/src/pressure/pressure_device.cpp
new file mode 100755 (executable)
index 0000000..757ea9f
--- /dev/null
@@ -0,0 +1,310 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "pressure_device.h"
+
+#include <math.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <linux/input.h>
+
+#include "util.h"
+#include "sensor_common.h"
+#include "sensor_log.h"
+
+#define SEA_LEVEL_RESOLUTION 0.01
+#define SEA_LEVEL_PRESSURE 101325.0
+#define SEA_LEVEL_EPSILON 0.00001
+
+#define MODEL_NAME "LPS25H"
+#define VENDOR "ST Microelectronics"
+#define RESOLUTION 1
+#define RAW_DATA_UNIT 0.000244
+#define MIN_INTERVAL 1
+#define MIN_RANGE 260
+#define MAX_RANGE 1260
+#define TEMPERATURE_RESOLUTION 0.002083
+#define TEMPERATURE_OFFSET 42.5
+#define MAX_BATCH_COUNT 0
+
+#define SENSOR_NAME "SENSOR_PRESSURE"
+#define SENSOR_TYPE_PRESSURE "PRESSURE"
+
+#define INPUT_NAME "pressure_sensor"
+#define PRESSURE_SENSORHUB_POLL_NODE_NAME "pressure_poll_delay"
+#define MAX_ID 0x3
+
+
+static sensor_info_t sensor_info = {
+       id: 0x1,
+       name: SENSOR_NAME,
+       type: SENSOR_DEVICE_PRESSURE,
+       event_type: (SENSOR_DEVICE_PRESSURE << SENSOR_EVENT_SHIFT) | RAW_DATA_EVENT,
+       model_name: MODEL_NAME,
+       vendor: VENDOR,
+       min_range: MIN_RANGE,
+       max_range: MAX_RANGE,
+       resolution: RAW_DATA_UNIT,
+       min_interval: MIN_INTERVAL,
+       max_batch_count: MAX_BATCH_COUNT,
+       wakeup_supported: false
+};
+
+pressure_device::pressure_device()
+: m_node_handle(-1)
+, m_pressure(0)
+, m_temperature(0)
+, m_sea_level_pressure(SEA_LEVEL_PRESSURE)
+, m_polling_interval(1000)
+, m_fired_time(0)
+, m_sensorhub_controlled(false)
+{
+       const std::string sensorhub_interval_node_name = PRESSURE_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_PRESSURE;
+       query.key = INPUT_NAME;
+       query.iio_enable_node_name = "pressure_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_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, "pressure handle open fail for pressure sensor");
+               throw ENXIO;
+       }
+
+       if (!util::set_monotonic_clock(m_node_handle))
+               throw ENXIO;
+
+       _I("pressure_device is created");
+}
+
+pressure_device::~pressure_device()
+{
+       close(m_node_handle);
+       m_node_handle = -1;
+
+       _I("pressure_device is destroyed");
+}
+
+int pressure_device::get_poll_fd(void)
+{
+       return m_node_handle;
+}
+
+int pressure_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 pressure_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_PRESSURE_ENABLE_BIT);
+       set_interval(id, m_polling_interval);
+
+       m_fired_time = 0;
+       _I("Enable pressure sensor");
+       return true;
+}
+
+bool pressure_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_PRESSURE_ENABLE_BIT);
+
+       _I("Disable pressure sensor");
+       return true;
+}
+
+bool pressure_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 pressure_device::update_value_input_event(void)
+{
+       int pressure_raw[3] = {0, };
+       bool pressure = false;
+       bool sea_level = false;
+       bool temperature = false;
+       int read_input_cnt = 0;
+       const int INPUT_MAX_BEFORE_SYN = 10;
+       unsigned long long fired_time = 0;
+       bool syn = false;
+
+       struct input_event pressure_event;
+       _D("pressure event detection");
+
+       while ((syn == false) && (read_input_cnt < INPUT_MAX_BEFORE_SYN)) {
+               int len = read(m_node_handle, &pressure_event, sizeof(pressure_event));
+               if (len != sizeof(pressure_event)) {
+                       _E("pressure_file read fail, read_len = %d\n", len);
+                       return false;
+               }
+
+               ++read_input_cnt;
+
+               if (pressure_event.type == EV_REL) {
+                       switch (pressure_event.code) {
+                               case REL_HWHEEL:
+                                       pressure_raw[0] = (int)pressure_event.value;
+                                       pressure = true;
+                                       break;
+                               case REL_DIAL:
+                                       pressure_raw[1] = (int)pressure_event.value;
+                                       sea_level = true;
+                                       break;
+                               case REL_WHEEL:
+                                       pressure_raw[2] = (int)pressure_event.value;
+                                       temperature = true;
+                                       break;
+                               case REL_WHEEL+1:
+                                       fired_time |= SHORT_TO_UINT64(pressure_event.value, 48);
+                                       break;
+                               case REL_WHEEL+2:
+                                       fired_time |= SHORT_TO_UINT64(pressure_event.value, 32);
+                                       break;
+                               case REL_WHEEL+3:
+                                       fired_time |= SHORT_TO_UINT64(pressure_event.value, 16);
+                                       break;
+                               case REL_WHEEL+4:
+                                       fired_time |= SHORT_TO_UINT64(pressure_event.value, 0);
+                                       break;
+                               default:
+                                       _E("pressure_event event[type = %d, code = %d] is unknown.", pressure_event.type, pressure_event.code);
+                                       break;
+                       }
+               } else if (pressure_event.type == EV_SYN) {
+                       syn = true;
+                       fired_time = util::get_timestamp(&pressure_event.time);
+               } else {
+                       _E("pressure_event event[type = %d, code = %d] is unknown.", pressure_event.type, pressure_event.code);
+                       return false;
+               }
+       }
+
+       if (syn == false) {
+               _E("EV_SYN didn't come until %d inputs had come", read_input_cnt);
+               return false;
+       }
+
+       if (pressure)
+               m_pressure = pressure_raw[0];
+       if (sea_level)
+               m_sea_level_pressure = pressure_raw[1];
+       if (temperature)
+               m_temperature = pressure_raw[2];
+
+       m_fired_time = fired_time;
+
+       _D("m_pressure = %d, sea_level = %f, temperature = %d, time = %lluus", m_pressure, m_sea_level_pressure, m_temperature, m_fired_time);
+
+       return true;
+}
+
+int pressure_device::read_fd(uint32_t **ids)
+{
+       retvm_if(ids == NULL || ids == nullptr, SENSOR_ERROR_INVALID_PARAMETER, "%s:NULL interface", SENSOR_NAME);
+
+       if (!update_value_input_event()) {
+               _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 pressure_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 = (sensor_data_t *)malloc(sizeof(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_pressure;
+       sensor_data->values[1] = (float)m_sea_level_pressure;
+       sensor_data->values[2] = m_temperature;
+
+       raw_to_base(sensor_data);
+
+       *data = sensor_data;
+       *length = sizeof(sensor_data_t);
+
+       return 0;
+}
+
+void pressure_device::raw_to_base(sensor_data_t *data)
+{
+       data->values[0] = data->values[0] * RAW_DATA_UNIT;
+       m_sea_level_pressure = data->values[1] * SEA_LEVEL_RESOLUTION;
+       data->values[1] = pressure_to_altitude(data->values[0]);
+       data->values[2] = data->values[2] * TEMPERATURE_RESOLUTION + TEMPERATURE_OFFSET;
+}
+
+float pressure_device::pressure_to_altitude(float pressure)
+{
+       float sea_level_pressure = m_sea_level_pressure;
+
+       if (sea_level_pressure < SEA_LEVEL_EPSILON && sea_level_pressure > -SEA_LEVEL_EPSILON)
+               sea_level_pressure = SEA_LEVEL_PRESSURE * SEA_LEVEL_RESOLUTION;
+
+       return 44330.0f * (1.0f - pow(pressure/sea_level_pressure, 1.0f/5.255f));
+}
diff --git a/src/pressure/pressure_device.h b/src/pressure/pressure_device.h
new file mode 100644 (file)
index 0000000..4a014df
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __PRESSURE_DEVICE_H__
+#define __PRESSURE_DEVICE_H__
+
+#include <sensor/sensor_hal.h>
+#include <string>
+#include <vector>
+
+class pressure_device : public sensor_device {
+public:
+       pressure_device();
+       virtual ~pressure_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_pressure;
+       int m_temperature;
+       float m_sea_level_pressure;
+       unsigned long m_polling_interval;
+       unsigned long long m_fired_time;
+
+       bool m_sensorhub_controlled;
+       std::string m_data_node;
+       std::string m_enable_node;
+       std::string m_interval_node;
+
+       std::vector<uint32_t> event_ids;
+
+       bool update_value_input_event(void);
+       void raw_to_base(sensor_data_t *data);
+       float pressure_to_altitude(float pressure);
+};
+
+#endif /* __PRESSURE_DEVICE_H__*/
diff --git a/src/sensor_common.h b/src/sensor_common.h
new file mode 100755 (executable)
index 0000000..5072936
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SENSOR_COMMON_H__
+#define __SENSOR_COMMON_H__
+
+#define SENSOR_EVENT_SHIFT 16
+#define RAW_DATA_EVENT 0x0001
+
+#define SHORT_TO_UINT64(value, shift) (((unsigned long long)(value & 0xFFFF)) << shift)
+#define NS_TO_US(x) ((x) / 1000)
+
+#define UNKNOWN_NAME "UNKNOWN"
+#include <tizen.h>
+
+
+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,
+};
+
+
+/**
+ * @brief   Enumeration for errors.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ */
+typedef enum {
+       SENSOR_ERROR_NONE                  = TIZEN_ERROR_NONE,                 /**< Successful */
+       SENSOR_ERROR_IO_ERROR              = TIZEN_ERROR_IO_ERROR,             /**< I/O error */
+       SENSOR_ERROR_INVALID_PARAMETER     = TIZEN_ERROR_INVALID_PARAMETER,    /**< Invalid parameter */
+       SENSOR_ERROR_NOT_SUPPORTED         = TIZEN_ERROR_NOT_SUPPORTED,        /**< Not supported */
+       SENSOR_ERROR_PERMISSION_DENIED     = TIZEN_ERROR_PERMISSION_DENIED,    /**< Permission denied */
+       SENSOR_ERROR_OUT_OF_MEMORY         = TIZEN_ERROR_OUT_OF_MEMORY,        /**< Out of memory */
+       SENSOR_ERROR_NO_DATA               = TIZEN_ERROR_NO_DATA,              /**< No data available
+                                                                                @if MOBILE (Since 3.0) @elseif WEARABLE (Since 2.3.2) @endif */
+       SENSOR_ERROR_NOT_NEED_CALIBRATION  = TIZEN_ERROR_SENSOR | 0x03,        /**< Sensor doesn't need calibration */
+       SENSOR_ERROR_OPERATION_FAILED      = TIZEN_ERROR_SENSOR | 0x06,        /**< Operation failed */
+       SENSOR_ERROR_NOT_AVAILABLE         = TIZEN_ERROR_SENSOR | 0x07,        /**< The sensor is supported, but currently not available
+                                                                                @if MOBILE (Since 3.0) @elseif WEARABLE (Since 2.3.2) @endif */
+} sensor_error_e;
+
+
+#endif /* __SENSOR_COMMON_H__ */
diff --git a/src/sensor_log.h b/src/sensor_log.h
new file mode 100644 (file)
index 0000000..8ac5abb
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __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__ */
diff --git a/src/util.cpp b/src/util.cpp
new file mode 100644 (file)
index 0000000..1692d44
--- /dev/null
@@ -0,0 +1,324 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <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;
+}
diff --git a/src/util.h b/src/util.h
new file mode 100644 (file)
index 0000000..2358119
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __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__ */
diff --git a/testcase/CMakeLists.txt b/testcase/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..2b72941
--- /dev/null
@@ -0,0 +1,30 @@
+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
diff --git a/testcase/sensor_device_haltest.cpp b/testcase/sensor_device_haltest.cpp
new file mode 100755 (executable)
index 0000000..f9da72b
--- /dev/null
@@ -0,0 +1,2163 @@
+/*
+ * 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 <gyro/gyro_device.h>
+#include <hrm/hrm_device.h>
+#include <hrm_raw/hrm_raw_device.h>
+#include <light/light_device.h>
+#include <pressure/pressure_device.h>
+
+#include "sensor_common.h"
+using namespace std;
+
+#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;
+       }*/
+};
+
+/*
+ * Gyro device test class
+ */
+class GyroSensorHalTest : public testing::Test
+{
+public:
+       int ret;
+       bool sensor_supported;
+       sensor_device *sensor_handle = NULL;
+public:
+       virtual void SetUp()
+       {
+               sensor_supported = false;
+               sensor_handle = new gyro_device;
+               if (sensor_handle == NULL) {
+                       cout << "gyro 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;
+       }*/
+};
+
+/*
+ * HRM device test class
+ */
+class HRMSensorHalTest : public testing::Test
+{
+public:
+       int ret;
+       bool sensor_supported;
+       sensor_device *sensor_handle = NULL;
+public:
+       virtual void SetUp()
+       {
+               sensor_supported = false;
+               sensor_handle = new hrm_device;
+               if (sensor_handle == NULL) {
+                       cout << "hrm 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;
+       }*/
+};
+
+
+/*
+ * HRM Raw device test class
+ */
+class HRMRawSensorHalTest : public testing::Test
+{
+public:
+       int ret;
+       bool sensor_supported;
+       sensor_device *sensor_handle = NULL;
+public:
+       virtual void SetUp()
+       {
+               sensor_supported = false;
+               sensor_handle = new hrm_raw_device;
+               if (sensor_handle == NULL) {
+                       cout << "hrm raw 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;
+       }*/
+};
+
+/*
+ * Light device test class
+ */
+class LightSensorHalTest : public testing::Test
+{
+public:
+       int ret;
+       bool sensor_supported;
+       sensor_device *sensor_handle = NULL;
+public:
+       virtual void SetUp()
+       {
+               sensor_supported = false;
+               sensor_handle = new light_device;
+               if (sensor_handle == NULL) {
+                       cout << "Light 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;
+       }*/
+};
+
+/*
+ * Pressure device test class
+ */
+class PressureSensorHalTest : public testing::Test
+{
+public:
+       int ret;
+       bool sensor_supported;
+       sensor_device *sensor_handle = NULL;
+public:
+       virtual void SetUp()
+       {
+               sensor_supported = false;
+               sensor_handle = new pressure_device;
+               if (sensor_handle == NULL) {
+                       cout << "pressure 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;
+       }*/
+};
+
+
+
+/**
+ * @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);
+}
+
+/*********** GYRO 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(GyroSensorHalTest, get_poll_fdP)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, get_sensorsP)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, get_sensorsN)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, enableP)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, enableN)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, disableP)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, disableN)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, read_fdP)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, read_fdN)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, get_dataP)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, get_dataN)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, set_intervalP)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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(GyroSensorHalTest, set_intervalN)
+{
+       SENSOR_SUPPORT_CHECK(GYRO);
+       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);
+
+}
+
+/*********** HRM 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(HRMSensorHalTest, get_poll_fdP)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, get_sensorsP)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, get_sensorsN)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, enableP)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, enableN)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, disableP)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, disableN)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, read_fdP)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, read_fdN)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, get_dataP)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, get_dataN)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, set_intervalP)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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(HRMSensorHalTest, set_intervalN)
+{
+       SENSOR_SUPPORT_CHECK(HRM);
+       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);
+}
+
+
+/*********** HRM RAW 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(HRMRawSensorHalTest, get_poll_fdP)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, get_sensorsP)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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, 2);
+}
+
+/**
+ * @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(HRMRawSensorHalTest, get_sensorsN)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, enableP)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, enableN)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, disableP)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, disableN)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, read_fdP)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, read_fdN)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, get_dataP)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, get_dataN)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, set_intervalP)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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(HRMRawSensorHalTest, set_intervalN)
+{
+       SENSOR_SUPPORT_CHECK(HRMRAW);
+       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);
+}
+
+
+/*********** Light 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(LightSensorHalTest, get_poll_fdP)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, get_sensorsP)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, get_sensorsN)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, enableP)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, enableN)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, disableP)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, disableN)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, read_fdP)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, read_fdN)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, get_dataP)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, get_dataN)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, set_intervalP)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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(LightSensorHalTest, set_intervalN)
+{
+       SENSOR_SUPPORT_CHECK(LIGHT);
+       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);
+}
+
+
+/*********** Pressure 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(PressureSensorHalTest, get_poll_fdP)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, get_sensorsP)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, get_sensorsN)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, enableP)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, enableN)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, disableP)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, disableN)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, read_fdP)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, read_fdN)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, get_dataP)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, get_dataN)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, set_intervalP)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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(PressureSensorHalTest, set_intervalN)
+{
+       SENSOR_SUPPORT_CHECK(PRESSURE);
+       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);
+
+}
+
+
+int main(int argc, char **argv)
+{
+       testing::InitGoogleTest(&argc, argv);
+
+       return RUN_ALL_TESTS();
+}
+