From 4242016a0151b906a1e7e45f105feb9ddac9d8fa Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Tue, 26 Jan 2021 18:27:04 +0900 Subject: [PATCH 01/16] Fix minor things * Remove redundant defines * Remove meaningless slash Change-Id: I51426f32d532e4cdb038c0ebeec9ba346831fdc1 Signed-off-by: Boram Bae --- CMakeLists.txt | 4 ---- packaging/hal-api-sensor.spec | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abbe3dc..3501524 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(hal-api-sensor CXX) -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) -SET(EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}/bin") -SET(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include") -SET(LIBDIR ${CMAKE_LIBDIR_PREFIX}) SET(VERSION_MAJOR 0) SET(VERSION "${VERSION_MAJOR}.1.0") diff --git a/packaging/hal-api-sensor.spec b/packaging/hal-api-sensor.spec index 96fcc94..a06a530 100644 --- a/packaging/hal-api-sensor.spec +++ b/packaging/hal-api-sensor.spec @@ -42,7 +42,7 @@ Requires: %{name} = %{version}-%{release} %build cp %{SOURCE1} . cp %{SOURCE2} . -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir}/ +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir} make %{?jobs:-j%jobs} %install -- 2.7.4 From 259dbbed3f03a086dc3342fd33739978d5654717 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Tue, 2 Feb 2021 14:00:05 +0900 Subject: [PATCH 02/16] Add hal-sensor-types.h * Move sensor data types and a base class to hal-sensor-types.h * This change required by plan of Next HAL Change-Id: Icca31d1a62b9ba141763880829eb5427f983dcce Signed-off-by: Boram Bae --- include/hal-sensor-interface.h | 547 +-------------------------------------- include/hal-sensor-types.h | 572 +++++++++++++++++++++++++++++++++++++++++ include/hal-sensor.h | 4 +- src/hal-api-sensor.cpp | 2 +- 4 files changed, 578 insertions(+), 547 deletions(-) create mode 100644 include/hal-sensor-types.h diff --git a/include/hal-sensor-interface.h b/include/hal-sensor-interface.h index 7e0324a..6a6b807 100644 --- a/include/hal-sensor-interface.h +++ b/include/hal-sensor-interface.h @@ -20,560 +20,17 @@ #define __HAL_SENSOR_INTERFACE__ #include -#include -#include -#include - -#define SENSOR_HAL_VERSION(maj, min) ((((maj)&0xFFFF) << 24) | ((min)&0xFFFF)) +#include "hal-sensor-types.h" #ifdef __cplusplus extern "C" { #endif typedef struct _hal_backend_sensor_funcs { - int (*create)(void ***devices); + int (*create)(sensor_device_t **devices); } hal_backend_sensor_funcs; -/* - * Sensor Types - * These types are used to controll the sensors - * - * - base unit - * acceleration values : meter per second^2 (m/s^2) - * magnetic values : micro-Tesla (uT) - * orientation values : degrees - * gyroscope values : degree/s - * temperature values : degrees centigrade - * proximity valeus : distance - * light values : lux - * pressure values : hectopascal (hPa) - * humidity : relative humidity (%) - */ -typedef enum { - SENSOR_DEVICE_UNKNOWN = -2, - SENSOR_DEVICE_ALL = -1, - SENSOR_DEVICE_ACCELEROMETER, - SENSOR_DEVICE_GRAVITY, - SENSOR_DEVICE_LINEAR_ACCELERATION, - SENSOR_DEVICE_GEOMAGNETIC, - SENSOR_DEVICE_ROTATION_VECTOR, - SENSOR_DEVICE_ORIENTATION, - SENSOR_DEVICE_GYROSCOPE, - SENSOR_DEVICE_LIGHT, - SENSOR_DEVICE_PROXIMITY, - SENSOR_DEVICE_PRESSURE, - SENSOR_DEVICE_ULTRAVIOLET, - SENSOR_DEVICE_TEMPERATURE, - SENSOR_DEVICE_HUMIDITY, - SENSOR_DEVICE_HRM, - SENSOR_DEVICE_HRM_LED_GREEN, - SENSOR_DEVICE_HRM_LED_IR, - SENSOR_DEVICE_HRM_LED_RED, - SENSOR_DEVICE_GYROSCOPE_UNCAL, - SENSOR_DEVICE_GEOMAGNETIC_UNCAL, - SENSOR_DEVICE_GYROSCOPE_RV, - SENSOR_DEVICE_GEOMAGNETIC_RV, - - SENSOR_DEVICE_SIGNIFICANT_MOTION = 0x100, - - SENSOR_DEVICE_HRM_BATCH = 0x200, - SENSOR_DEVICE_HRM_LED_GREEN_BATCH, - - SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300, - SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, - SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, - SENSOR_DEVICE_HUMAN_STRESS_MONITOR, - - SENSOR_DEVICE_EXERCISE_WALKING = 0x400, - SENSOR_DEVICE_EXERCISE_RUNNING, - SENSOR_DEVICE_EXERCISE_HIKING, - SENSOR_DEVICE_EXERCISE_CYCLING, - SENSOR_DEVICE_EXERCISE_ELLIPTICAL, - SENSOR_DEVICE_EXERCISE_INDOOR_CYCLING, - SENSOR_DEVICE_EXERCISE_ROWING, - SENSOR_DEVICE_EXERCISE_STEPPER, - - SENSOR_DEVICE_DATA_JOURNAL = 0x500, - - SENSOR_DEVICE_FUSION = 0x900, - SENSOR_DEVICE_AUTO_ROTATION, - SENSOR_DEVICE_AUTO_BRIGHTNESS, - SENSOR_DEVICE_MYOTEST, - - SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200, - SENSOR_DEVICE_GESTURE_WRIST_UP, - SENSOR_DEVICE_GESTURE_WRIST_DOWN, - SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, - SENSOR_DEVICE_GESTURE_PICK_UP, - SENSOR_DEVICE_GESTURE_FACE_DOWN, - - SENSOR_DEVICE_ACTIVITY_TRACKER = 0x1A00, - SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, - SENSOR_DEVICE_GPS_BATCH, - SENSOR_DEVICE_PPG_BATCH, - SENSOR_DEVICE_GPS_TIMESYNC, - - SENSOR_DEVICE_HRM_CTRL = 0x1A80, - SENSOR_DEVICE_REG_CTRL, - SENSOR_DEVICE_GPS_CTRL, - - SENSOR_DEVICE_WEAR_STATUS = 0x2000, - SENSOR_DEVICE_WEAR_ON_MONITOR, - SENSOR_DEVICE_NO_MOVE_DETECTOR, - SENSOR_DEVICE_RESTING_HR, - SENSOR_DEVICE_STEP_LEVEL_MONITOR, - SENSOR_DEVICE_EXERCISE_STANDALONE, - SENSOR_DEVICE_EXERCISE_HR, - SENSOR_DEVICE_WORKOUT, - SENSOR_DEVICE_CYCLE_MONITOR, - SENSOR_DEVICE_STAIR_TRACKER, - SENSOR_DEVICE_PRESSURE_INDICATOR, - SENSOR_DEVICE_PRESSURE_ALERT, - SENSOR_DEVICE_HR_CALORIE, - SENSOR_DEVICE_SWIMMING_TRACKER, - SENSOR_DEVICE_STRESS_TRACKER, - SENSOR_DEVICE_FAKE_MOTION, - SENSOR_DEVICE_GEOFENCE, - SENSOR_DEVICE_SWIMMING_OUTDOOR, - SENSOR_DEVICE_AUTO_SWIMMING, - SENSOR_DEVICE_INACTIVITY_DETECTOR, - SENSOR_DEVICE_HRM_BP, - SENSOR_DEVICE_ECG, - SENSOR_DEVICE_FALL_DETECTION, - - SENSOR_DEVICE_CONTEXT = 0x7000, - SENSOR_DEVICE_MOTION, - SENSOR_DEVICE_PIR, - SENSOR_DEVICE_PIR_LONG, - SENSOR_DEVICE_DUST, - SENSOR_DEVICE_THERMOMETER, - SENSOR_DEVICE_PEDOMETER, - SENSOR_DEVICE_FLAT, - SENSOR_DEVICE_HRM_RAW, - SENSOR_DEVICE_TILT, - SENSOR_DEVICE_ROTATION_VECTOR_RAW, - SENSOR_DEVICE_GSR, - SENSOR_DEVICE_SIMSENSE, - SENSOR_DEVICE_PPG, -} sensor_device_type; - -/* - * A platform sensor handler is generated based on this handle - * This id can be assigned from HAL developer. so it has to be unique in 1 - * sensor_device. - */ -typedef struct sensor_info_t { - uint32_t id; - const char *name; - sensor_device_type type; - unsigned int event_type; // for Internal API - const char *model_name; - const char *vendor; - float min_range; - float max_range; - float resolution; - int min_interval; - int max_batch_count; - bool wakeup_supported; -} sensor_info_t; - -enum sensor_accuracy_t { - SENSOR_ACCURACY_UNDEFINED = -1, - SENSOR_ACCURACY_BAD = 0, - SENSOR_ACCURACY_NORMAL = 1, - SENSOR_ACCURACY_GOOD = 2, - SENSOR_ACCURACY_VERYGOOD = 3 -}; - -#define SENSOR_DATA_VALUE_SIZE 16 - -/* sensor_data_t */ -typedef struct sensor_data_t { - int accuracy; - unsigned long long timestamp; - int value_count; - float values[SENSOR_DATA_VALUE_SIZE]; -} sensor_data_t; - -#define SENSORHUB_DATA_VALUE_SIZE 4096 - -/* sensorhub_data_t */ -typedef struct sensorhub_data_t { - int accuracy; - unsigned long long timestamp; - - /* - * Use "value_count" instead of "hub_data_size" - * which is going to be removed soon - */ - union { - int value_count; - int hub_data_size; /* deprecated */ - }; - - /* - * Use "values" instead of "hub_data" - * which is going to be removed soon - */ - union { - char values[SENSORHUB_DATA_VALUE_SIZE]; - char hub_data[SENSORHUB_DATA_VALUE_SIZE]; /* deprecated */ - }; -} sensorhub_data_t; - -#define SENSOR_PEDOMETER_DATA_DIFFS_SIZE 20 - -typedef struct { - int accuracy; - unsigned long long timestamp; - int value_count; /* value_count == 8 */ - float values[SENSOR_DATA_VALUE_SIZE]; - /* values = {step count, walk step count, run step count, - moving distance, calorie burned, last speed, - last stepping frequency (steps per sec), - last step status (walking, running, ...)} */ - /* Additional data attributes (not in sensor_data_t)*/ - int diffs_count; - struct differences { - int timestamp; - int steps; - int walk_steps; - int run_steps; - int walk_up_steps; - int walk_down_steps; - int run_up_steps; - int run_down_steps; - float distance; - float calories; - float speed; - } diffs[SENSOR_PEDOMETER_DATA_DIFFS_SIZE]; -} sensor_pedometer_data_t; - -#define CONVERT_TYPE_ATTR(type, index) ((type) << 8 | 0x80 | (index)) - -enum sensor_attribute { - SENSOR_ATTR_ACCELEROMETER_INJECTION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_ACCELEROMETER, 0xFF), - SENSOR_ATTR_ACTIVITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_ACTIVITY_TRACKER, 0x1), - - SENSOR_ATTR_HRM_BATCH_OPR_MODE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x1), - SENSOR_ATTR_HRM_BATCH_ACTIVITY_TYPE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x2), - SENSOR_ATTR_HRM_BATCH_BATCH_DUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x3), - SENSOR_ATTR_HRM_BATCH_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x4), - SENSOR_ATTR_HRM_BATCH_ELEVATED_DUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x5), - SENSOR_ATTR_HRM_BATCH_ELEVATED_THR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x6), - SENSOR_ATTR_HRM_BATCH_BPM_RAW = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x7), - SENSOR_ATTR_HRM_BATCH_LOW_ALERT_DUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x8), - SENSOR_ATTR_HRM_BATCH_LOW_ALERT_THR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x9), - - SENSOR_ATTR_HRM_LED_GREEN_BATCH_POLLING_INTERVAL = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_LED_GREEN_BATCH, 0x1), - SENSOR_ATTR_HRM_LED_GREEN_BATCH_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_LED_GREEN_BATCH, 0x2), - SENSOR_ATTR_HRM_LED_GREEN_BATCH_BATCH_PERIOD = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_LED_GREEN_BATCH, 0x3), - - SENSOR_ATTR_PEDOMETER_HEIGHT = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x1), - SENSOR_ATTR_PEDOMETER_WEIGHT = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2), - SENSOR_ATTR_PEDOMETER_GENDER = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x3), - SENSOR_ATTR_PEDOMETER_AGE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x4), - SENSOR_ATTR_PEDOMETER_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2F), - - SENSOR_ATTR_STRESS_MONITOR_AGE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1), - - SENSOR_ATTR_EXERCISE_TYPE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x1), - SENSOR_ATTR_EXERCISE_GPS = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x2), - SENSOR_ATTR_EXERCISE_BATCH_INTERVAL = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x3), - SENSOR_ATTR_EXERCISE_PSERVICE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x4), - - SENSOR_ATTR_CYCLE_DURATION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x1), - SENSOR_ATTR_CYCLE_HOLDING_POSITION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x2), - SENSOR_ATTR_CYCLE_VELOCITY = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x3), - SENSOR_ATTR_CYCLE_GET_DATA_TYPE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x4), - SENSOR_ATTR_CYCLE_DATA_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x5), - SENSOR_ATTR_CYCLE_GPS_AGREEMENT = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x6), - - SENSOR_ATTR_WORKOUT_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x1), - SENSOR_ATTR_WORKOUT_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x2), - - SENSOR_ATTR_RESTING_HR_OPR_MODE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x1), - SENSOR_ATTR_RESTING_HR_MAX_RHR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x2), - SENSOR_ATTR_RESTING_HR_MIN_RHR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x3), - SENSOR_ATTR_RESTING_HR_AVG_RHR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x4), - SENSOR_ATTR_RESTING_HR_HOUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x5), - SENSOR_ATTR_RESTING_HR_MIN = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x6), - SENSOR_ATTR_RESTING_HR_SEC = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x7), - SENSOR_ATTR_RESTING_HR_PROPERTY_TYPE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x10), - SENSOR_ATTR_RESTING_HR_PROPERTY_HR_TYPE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x11), - SENSOR_ATTR_RESTING_HR_PROPERTY_HR_VALUE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x12), - SENSOR_ATTR_RESTING_HR_PROPERTY_DURATION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x13), - SENSOR_ATTR_RESTING_HR_PROPERTY_ACT_TYPE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x14), - SENSOR_ATTR_RESTING_HR_PROPERTY_ACT_DUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x15), - SENSOR_ATTR_RESTING_HR_PROPERTY_CONT_DUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x16), - SENSOR_ATTR_RESTING_HR_DATA_TYPE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x20), - SENSOR_ATTR_RESTING_HR_DATA_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x21), - - SENSOR_ATTR_STEP_LEVEL_MONITOR_DW_DURATION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_STEP_LEVEL_MONITOR, 0x1), - - SENSOR_ATTR_EXERCISE_HR_OPR_MODE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x1), - SENSOR_ATTR_EXERCISE_HR_ACTIVITY_TYPE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x2), - SENSOR_ATTR_EXERCISE_HR_BATCH_DUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x3), - SENSOR_ATTR_EXERCISE_HR_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x4), - SENSOR_ATTR_EXERCISE_HR_ELEVATED_DUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x5), - SENSOR_ATTR_EXERCISE_HR_ELEVATED_THR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x6), - SENSOR_ATTR_EXERCISE_HR_BPM_RAW = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x7), - SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_DUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x8), - SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_THR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x9), - - SENSOR_ATTR_PRESSURE_INDICATOR_START = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x1), - SENSOR_ATTR_PRESSURE_INDICATOR_STOP = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x2), - SENSOR_ATTR_PRESSURE_INDICATOR_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x3), - SENSOR_ATTR_PRESSURE_INDICATOR_RESTORE_TIME = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x4), - SENSOR_ATTR_PRESSURE_INDICATOR_RESTORE_VALUE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x5), - SENSOR_ATTR_PRESSURE_INDICATOR_CURRENT_TIME = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x6), - - SENSOR_ATTR_PRESSURE_ALERT_START = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_ALERT, 0x1), - SENSOR_ATTR_PRESSURE_ALERT_STOP = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_ALERT, 0x2), - - SENSOR_ATTR_HR_CALORIE_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x1), - SENSOR_ATTR_HR_CALORIE_HEIGHT = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x2), - SENSOR_ATTR_HR_CALORIE_WEIGHT = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x3), - SENSOR_ATTR_HR_CALORIE_GENDER = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x4), - SENSOR_ATTR_HR_CALORIE_INST = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x10), - SENSOR_ATTR_HR_CALORIE_EXERCISE_TYPE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x11), - SENSOR_ATTR_HR_CALORIE_TARGET_CAL = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x12), - SENSOR_ATTR_HR_CALORIE_MAX_HEARTRATE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x13), - SENSOR_ATTR_HR_CALORIE_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x20), - - SENSOR_ATTR_SWIMMING_TRACKER_PLACE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x1), - SENSOR_ATTR_SWIMMING_TRACKER_DISTANCE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x2), - SENSOR_ATTR_SWIMMING_TRACKER_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x3), - SENSOR_ATTR_SWIMMING_TRACKER_BATCH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x4), - SENSOR_ATTR_SWIMMING_TRACKER_GOAL_CALORIES = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x5), - SENSOR_ATTR_SWIMMING_TRACKER_GOAL_LAPS = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x6), - SENSOR_ATTR_SWIMMING_TRACKER_TIME_REST = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x7), - SENSOR_ATTR_SWIMMING_TRACKER_TIME_TURN = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x8), - - SENSOR_ATTR_SWIMMING_OUTDOOR_SET_BATCH_LAP_COUNT = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x1), - SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_LENGTH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x2), - SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_TIME = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x3), - SENSOR_ATTR_SWIMMING_OUTDOOR_SET_GPS_PERMISSION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x4), - SENSOR_ATTR_SWIMMING_OUTDOOR_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x6), - - SENSOR_ATTR_AUTO_SWIMMING_DURATION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_AUTO_SWIMMING, 0x1), - - SENSOR_ATTR_INACTIVITY_DETECTOR_LEVEL = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x1), - SENSOR_ATTR_INACTIVITY_DETECTOR_DURATION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x2), - - SENSOR_ATTR_STRESS_TRACKER_DUR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x1), - SENSOR_ATTR_STRESS_TRACKER_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x2), - - SENSOR_ATTR_STRESS_MONITOR_BASE_HR = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1), - SENSOR_ATTR_STRESS_MONITOR_HISTO_INDEX = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x2), - SENSOR_ATTR_STRESS_MONITOR_HISTO_VALUE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x3), - SENSOR_ATTR_STRESS_MONITOR_TUNE_INDEX = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x4), - SENSOR_ATTR_STRESS_MONITOR_TUNE_VALUE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x5), - SENSOR_ATTR_STRESS_MONITOR_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x6), - SENSOR_ATTR_STRESS_MONITOR_OPERATION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x7), - - SENSOR_ATTR_SLEEP_MONITOR_STOP = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x1), - SENSOR_ATTR_SLEEP_MONITOR_FLUSH = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x2), - - SENSOR_ATTR_SLEEP_DETECTOR_STOP = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x1), - SENSOR_ATTR_SLEEP_DETECTOR_SETTING = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x2), - - SENSOR_ATTR_DATA_JOURNAL_START = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x1), - SENSOR_ATTR_DATA_JOURNAL_STOP = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x2), - - SENSOR_ATTR_GPS_BATCH_OPR_MODE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_BATCH, 0x1), - - SENSOR_ATTR_PPG_BATCH_POLLING_INTERVAL = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x1), - SENSOR_ATTR_PPG_BATCH_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x2), - - SENSOR_ATTR_REG_CTRL_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x1), - SENSOR_ATTR_REG_CTRL_ADDRESS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x2), - SENSOR_ATTR_REG_CTRL_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x3), - SENSOR_ATTR_REG_CTRL_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x4), - - SENSOR_ATTR_GPS_CTRL_SETTING = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_CTRL, 0x1), - - SENSOR_ATTR_FAKE_MOTION_EVENT_INTERVAL = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x1), - SENSOR_ATTR_FAKE_MOTION_EVENT_COUNT = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x2), - SENSOR_ATTR_FAKE_MOTION_PAUSE_INTERVAL = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x3), - - SENSOR_ATTR_GEOFENCE_ID = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x1), - SENSOR_ATTR_GEOFENCE_LAT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x2), - SENSOR_ATTR_GEOFENCE_LON = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x3), - SENSOR_ATTR_GEOFENCE_RADIUS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x4), - SENSOR_ATTR_GEOFENCE_PROVIDER = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x5), - SENSOR_ATTR_GEOFENCE_ACCURACY = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x6), - SENSOR_ATTR_GEOFENCE_TIMESTAMP = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x7), - SENSOR_ATTR_GEOFENCE_CONNECT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x8), - SENSOR_ATTR_GEOFENCE_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x10), - SENSOR_ATTR_GEOFENCE_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x11), - SENSOR_ATTR_GEOFENCE_SET_LOCATION = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x12), - SENSOR_ATTR_GEOFENCE_BT_CONNECT = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x13), - - SENSOR_ATTR_FALL_DETECTION_OPR_MODE = - CONVERT_TYPE_ATTR(SENSOR_DEVICE_FALL_DETECTION, 0x1), -}; - -enum sensor_activity { - SENSOR_ACTIVITY_UNKNOWN = 1, - SENSOR_ACTIVITY_STILL = 2, - SENSOR_ACTIVITY_WALKING = 4, - SENSOR_ACTIVITY_RUNNING = 8, - SENSOR_ACTIVITY_IN_VEHICLE = 16, - SENSOR_ACTIVITY_ON_BICYCLE = 32, -}; - #ifdef __cplusplus } - -/* - * Create devices - */ -typedef void *sensor_device_t; -typedef int (*create_t)(sensor_device_t **devices); - -/* - * Sensor device interface - * 1 device must be abstracted from 1 device event node - */ -class sensor_device { - public: - virtual ~sensor_device() {} - - uint32_t get_hal_version(void) { return SENSOR_HAL_VERSION(1, 0); } - - virtual int get_poll_fd(void) = 0; - virtual int get_sensors(const sensor_info_t **sensors) = 0; - - virtual bool enable(uint32_t id) = 0; - virtual bool disable(uint32_t id) = 0; - - virtual int read_fd(uint32_t **ids) = 0; - virtual int get_data(uint32_t id, sensor_data_t **data, int *length) = 0; - - virtual bool set_interval(uint32_t id, unsigned long val) { return true; } - virtual bool set_batch_latency(uint32_t id, unsigned long val) { - return true; - } - virtual bool set_attribute_int(uint32_t id, int32_t attribute, - int32_t value) { - return true; - } - virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, - int len) { - return true; - } - virtual bool flush(uint32_t id) { return true; } -}; - #endif #endif /* __HAL_SENSOR_INTERFACE__ */ diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h new file mode 100644 index 0000000..653714a --- /dev/null +++ b/include/hal-sensor-types.h @@ -0,0 +1,572 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __HAL_SENSOR_TYPES__ +#define __HAL_SENSOR_TYPES__ + +#include +#include +#include + +#define SENSOR_HAL_VERSION(maj, min) ((((maj)&0xFFFF) << 24) | ((min)&0xFFFF)) + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Sensor Types + * These types are used to controll the sensors + * + * - base unit + * acceleration values : meter per second^2 (m/s^2) + * magnetic values : micro-Tesla (uT) + * orientation values : degrees + * gyroscope values : degree/s + * temperature values : degrees centigrade + * proximity valeus : distance + * light values : lux + * pressure values : hectopascal (hPa) + * humidity : relative humidity (%) + */ +typedef enum { + SENSOR_DEVICE_UNKNOWN = -2, + SENSOR_DEVICE_ALL = -1, + SENSOR_DEVICE_ACCELEROMETER, + SENSOR_DEVICE_GRAVITY, + SENSOR_DEVICE_LINEAR_ACCELERATION, + SENSOR_DEVICE_GEOMAGNETIC, + SENSOR_DEVICE_ROTATION_VECTOR, + SENSOR_DEVICE_ORIENTATION, + SENSOR_DEVICE_GYROSCOPE, + SENSOR_DEVICE_LIGHT, + SENSOR_DEVICE_PROXIMITY, + SENSOR_DEVICE_PRESSURE, + SENSOR_DEVICE_ULTRAVIOLET, + SENSOR_DEVICE_TEMPERATURE, + SENSOR_DEVICE_HUMIDITY, + SENSOR_DEVICE_HRM, + SENSOR_DEVICE_HRM_LED_GREEN, + SENSOR_DEVICE_HRM_LED_IR, + SENSOR_DEVICE_HRM_LED_RED, + SENSOR_DEVICE_GYROSCOPE_UNCAL, + SENSOR_DEVICE_GEOMAGNETIC_UNCAL, + SENSOR_DEVICE_GYROSCOPE_RV, + SENSOR_DEVICE_GEOMAGNETIC_RV, + + SENSOR_DEVICE_SIGNIFICANT_MOTION = 0x100, + + SENSOR_DEVICE_HRM_BATCH = 0x200, + SENSOR_DEVICE_HRM_LED_GREEN_BATCH, + + SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300, + SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, + SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, + SENSOR_DEVICE_HUMAN_STRESS_MONITOR, + + SENSOR_DEVICE_EXERCISE_WALKING = 0x400, + SENSOR_DEVICE_EXERCISE_RUNNING, + SENSOR_DEVICE_EXERCISE_HIKING, + SENSOR_DEVICE_EXERCISE_CYCLING, + SENSOR_DEVICE_EXERCISE_ELLIPTICAL, + SENSOR_DEVICE_EXERCISE_INDOOR_CYCLING, + SENSOR_DEVICE_EXERCISE_ROWING, + SENSOR_DEVICE_EXERCISE_STEPPER, + + SENSOR_DEVICE_DATA_JOURNAL = 0x500, + + SENSOR_DEVICE_FUSION = 0x900, + SENSOR_DEVICE_AUTO_ROTATION, + SENSOR_DEVICE_AUTO_BRIGHTNESS, + SENSOR_DEVICE_MYOTEST, + + SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200, + SENSOR_DEVICE_GESTURE_WRIST_UP, + SENSOR_DEVICE_GESTURE_WRIST_DOWN, + SENSOR_DEVICE_GESTURE_MOVEMENT_STATE, + SENSOR_DEVICE_GESTURE_PICK_UP, + SENSOR_DEVICE_GESTURE_FACE_DOWN, + + SENSOR_DEVICE_ACTIVITY_TRACKER = 0x1A00, + SENSOR_DEVICE_ACTIVITY_LEVEL_MONITOR, + SENSOR_DEVICE_GPS_BATCH, + SENSOR_DEVICE_PPG_BATCH, + SENSOR_DEVICE_GPS_TIMESYNC, + + SENSOR_DEVICE_HRM_CTRL = 0x1A80, + SENSOR_DEVICE_REG_CTRL, + SENSOR_DEVICE_GPS_CTRL, + + SENSOR_DEVICE_WEAR_STATUS = 0x2000, + SENSOR_DEVICE_WEAR_ON_MONITOR, + SENSOR_DEVICE_NO_MOVE_DETECTOR, + SENSOR_DEVICE_RESTING_HR, + SENSOR_DEVICE_STEP_LEVEL_MONITOR, + SENSOR_DEVICE_EXERCISE_STANDALONE, + SENSOR_DEVICE_EXERCISE_HR, + SENSOR_DEVICE_WORKOUT, + SENSOR_DEVICE_CYCLE_MONITOR, + SENSOR_DEVICE_STAIR_TRACKER, + SENSOR_DEVICE_PRESSURE_INDICATOR, + SENSOR_DEVICE_PRESSURE_ALERT, + SENSOR_DEVICE_HR_CALORIE, + SENSOR_DEVICE_SWIMMING_TRACKER, + SENSOR_DEVICE_STRESS_TRACKER, + SENSOR_DEVICE_FAKE_MOTION, + SENSOR_DEVICE_GEOFENCE, + SENSOR_DEVICE_SWIMMING_OUTDOOR, + SENSOR_DEVICE_AUTO_SWIMMING, + SENSOR_DEVICE_INACTIVITY_DETECTOR, + SENSOR_DEVICE_HRM_BP, + SENSOR_DEVICE_ECG, + SENSOR_DEVICE_FALL_DETECTION, + + SENSOR_DEVICE_CONTEXT = 0x7000, + SENSOR_DEVICE_MOTION, + SENSOR_DEVICE_PIR, + SENSOR_DEVICE_PIR_LONG, + SENSOR_DEVICE_DUST, + SENSOR_DEVICE_THERMOMETER, + SENSOR_DEVICE_PEDOMETER, + SENSOR_DEVICE_FLAT, + SENSOR_DEVICE_HRM_RAW, + SENSOR_DEVICE_TILT, + SENSOR_DEVICE_ROTATION_VECTOR_RAW, + SENSOR_DEVICE_GSR, + SENSOR_DEVICE_SIMSENSE, + SENSOR_DEVICE_PPG, +} sensor_device_type; + +/* + * A platform sensor handler is generated based on this handle + * This id can be assigned from HAL developer. so it has to be unique in 1 + * sensor_device. + */ +typedef struct sensor_info_t { + uint32_t id; + const char *name; + sensor_device_type type; + unsigned int event_type; // for Internal API + const char *model_name; + const char *vendor; + float min_range; + float max_range; + float resolution; + int min_interval; + int max_batch_count; + bool wakeup_supported; +} sensor_info_t; + +enum sensor_accuracy_t { + SENSOR_ACCURACY_UNDEFINED = -1, + SENSOR_ACCURACY_BAD = 0, + SENSOR_ACCURACY_NORMAL = 1, + SENSOR_ACCURACY_GOOD = 2, + SENSOR_ACCURACY_VERYGOOD = 3 +}; + +#define SENSOR_DATA_VALUE_SIZE 16 + +/* sensor_data_t */ +typedef struct sensor_data_t { + int accuracy; + unsigned long long timestamp; + int value_count; + float values[SENSOR_DATA_VALUE_SIZE]; +} sensor_data_t; + +#define SENSORHUB_DATA_VALUE_SIZE 4096 + +/* sensorhub_data_t */ +typedef struct sensorhub_data_t { + int accuracy; + unsigned long long timestamp; + + /* + * Use "value_count" instead of "hub_data_size" + * which is going to be removed soon + */ + union { + int value_count; + int hub_data_size; /* deprecated */ + }; + + /* + * Use "values" instead of "hub_data" + * which is going to be removed soon + */ + union { + char values[SENSORHUB_DATA_VALUE_SIZE]; + char hub_data[SENSORHUB_DATA_VALUE_SIZE]; /* deprecated */ + }; +} sensorhub_data_t; + +#define SENSOR_PEDOMETER_DATA_DIFFS_SIZE 20 + +typedef struct { + int accuracy; + unsigned long long timestamp; + int value_count; /* value_count == 8 */ + float values[SENSOR_DATA_VALUE_SIZE]; + /* values = {step count, walk step count, run step count, + moving distance, calorie burned, last speed, + last stepping frequency (steps per sec), + last step status (walking, running, ...)} */ + /* Additional data attributes (not in sensor_data_t)*/ + int diffs_count; + struct differences { + int timestamp; + int steps; + int walk_steps; + int run_steps; + int walk_up_steps; + int walk_down_steps; + int run_up_steps; + int run_down_steps; + float distance; + float calories; + float speed; + } diffs[SENSOR_PEDOMETER_DATA_DIFFS_SIZE]; +} sensor_pedometer_data_t; + +#define CONVERT_TYPE_ATTR(type, index) ((type) << 8 | 0x80 | (index)) + +enum sensor_attribute { + SENSOR_ATTR_ACCELEROMETER_INJECTION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_ACCELEROMETER, 0xFF), + SENSOR_ATTR_ACTIVITY = CONVERT_TYPE_ATTR(SENSOR_DEVICE_ACTIVITY_TRACKER, 0x1), + + SENSOR_ATTR_HRM_BATCH_OPR_MODE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x1), + SENSOR_ATTR_HRM_BATCH_ACTIVITY_TYPE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x2), + SENSOR_ATTR_HRM_BATCH_BATCH_DUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x3), + SENSOR_ATTR_HRM_BATCH_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x4), + SENSOR_ATTR_HRM_BATCH_ELEVATED_DUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x5), + SENSOR_ATTR_HRM_BATCH_ELEVATED_THR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x6), + SENSOR_ATTR_HRM_BATCH_BPM_RAW = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x7), + SENSOR_ATTR_HRM_BATCH_LOW_ALERT_DUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x8), + SENSOR_ATTR_HRM_BATCH_LOW_ALERT_THR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_BATCH, 0x9), + + SENSOR_ATTR_HRM_LED_GREEN_BATCH_POLLING_INTERVAL = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_LED_GREEN_BATCH, 0x1), + SENSOR_ATTR_HRM_LED_GREEN_BATCH_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_LED_GREEN_BATCH, 0x2), + SENSOR_ATTR_HRM_LED_GREEN_BATCH_BATCH_PERIOD = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HRM_LED_GREEN_BATCH, 0x3), + + SENSOR_ATTR_PEDOMETER_HEIGHT = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x1), + SENSOR_ATTR_PEDOMETER_WEIGHT = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2), + SENSOR_ATTR_PEDOMETER_GENDER = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x3), + SENSOR_ATTR_PEDOMETER_AGE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x4), + SENSOR_ATTR_PEDOMETER_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_PEDOMETER, 0x2F), + + SENSOR_ATTR_STRESS_MONITOR_AGE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1), + + SENSOR_ATTR_EXERCISE_TYPE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x1), + SENSOR_ATTR_EXERCISE_GPS = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x2), + SENSOR_ATTR_EXERCISE_BATCH_INTERVAL = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x3), + SENSOR_ATTR_EXERCISE_PSERVICE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_STANDALONE, 0x4), + + SENSOR_ATTR_CYCLE_DURATION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x1), + SENSOR_ATTR_CYCLE_HOLDING_POSITION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x2), + SENSOR_ATTR_CYCLE_VELOCITY = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x3), + SENSOR_ATTR_CYCLE_GET_DATA_TYPE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x4), + SENSOR_ATTR_CYCLE_DATA_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x5), + SENSOR_ATTR_CYCLE_GPS_AGREEMENT = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_CYCLE_MONITOR, 0x6), + + SENSOR_ATTR_WORKOUT_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x1), + SENSOR_ATTR_WORKOUT_DURATION = CONVERT_TYPE_ATTR(SENSOR_DEVICE_WORKOUT, 0x2), + + SENSOR_ATTR_RESTING_HR_OPR_MODE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x1), + SENSOR_ATTR_RESTING_HR_MAX_RHR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x2), + SENSOR_ATTR_RESTING_HR_MIN_RHR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x3), + SENSOR_ATTR_RESTING_HR_AVG_RHR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x4), + SENSOR_ATTR_RESTING_HR_HOUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x5), + SENSOR_ATTR_RESTING_HR_MIN = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x6), + SENSOR_ATTR_RESTING_HR_SEC = CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x7), + SENSOR_ATTR_RESTING_HR_PROPERTY_TYPE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x10), + SENSOR_ATTR_RESTING_HR_PROPERTY_HR_TYPE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x11), + SENSOR_ATTR_RESTING_HR_PROPERTY_HR_VALUE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x12), + SENSOR_ATTR_RESTING_HR_PROPERTY_DURATION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x13), + SENSOR_ATTR_RESTING_HR_PROPERTY_ACT_TYPE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x14), + SENSOR_ATTR_RESTING_HR_PROPERTY_ACT_DUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x15), + SENSOR_ATTR_RESTING_HR_PROPERTY_CONT_DUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x16), + SENSOR_ATTR_RESTING_HR_DATA_TYPE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x20), + SENSOR_ATTR_RESTING_HR_DATA_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_RESTING_HR, 0x21), + + SENSOR_ATTR_STEP_LEVEL_MONITOR_DW_DURATION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_STEP_LEVEL_MONITOR, 0x1), + + SENSOR_ATTR_EXERCISE_HR_OPR_MODE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x1), + SENSOR_ATTR_EXERCISE_HR_ACTIVITY_TYPE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x2), + SENSOR_ATTR_EXERCISE_HR_BATCH_DUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x3), + SENSOR_ATTR_EXERCISE_HR_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x4), + SENSOR_ATTR_EXERCISE_HR_ELEVATED_DUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x5), + SENSOR_ATTR_EXERCISE_HR_ELEVATED_THR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x6), + SENSOR_ATTR_EXERCISE_HR_BPM_RAW = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x7), + SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_DUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x8), + SENSOR_ATTR_EXERCISE_HR_LOW_ALERT_THR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_EXERCISE_HR, 0x9), + + SENSOR_ATTR_PRESSURE_INDICATOR_START = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x1), + SENSOR_ATTR_PRESSURE_INDICATOR_STOP = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x2), + SENSOR_ATTR_PRESSURE_INDICATOR_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x3), + SENSOR_ATTR_PRESSURE_INDICATOR_RESTORE_TIME = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x4), + SENSOR_ATTR_PRESSURE_INDICATOR_RESTORE_VALUE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x5), + SENSOR_ATTR_PRESSURE_INDICATOR_CURRENT_TIME = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_INDICATOR, 0x6), + + SENSOR_ATTR_PRESSURE_ALERT_START = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_ALERT, 0x1), + SENSOR_ATTR_PRESSURE_ALERT_STOP = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_PRESSURE_ALERT, 0x2), + + SENSOR_ATTR_HR_CALORIE_AGE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x1), + SENSOR_ATTR_HR_CALORIE_HEIGHT = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x2), + SENSOR_ATTR_HR_CALORIE_WEIGHT = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x3), + SENSOR_ATTR_HR_CALORIE_GENDER = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x4), + SENSOR_ATTR_HR_CALORIE_INST = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x10), + SENSOR_ATTR_HR_CALORIE_EXERCISE_TYPE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x11), + SENSOR_ATTR_HR_CALORIE_TARGET_CAL = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x12), + SENSOR_ATTR_HR_CALORIE_MAX_HEARTRATE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x13), + SENSOR_ATTR_HR_CALORIE_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HR_CALORIE, 0x20), + + SENSOR_ATTR_SWIMMING_TRACKER_PLACE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x1), + SENSOR_ATTR_SWIMMING_TRACKER_DISTANCE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x2), + SENSOR_ATTR_SWIMMING_TRACKER_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x3), + SENSOR_ATTR_SWIMMING_TRACKER_BATCH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x4), + SENSOR_ATTR_SWIMMING_TRACKER_GOAL_CALORIES = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x5), + SENSOR_ATTR_SWIMMING_TRACKER_GOAL_LAPS = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x6), + SENSOR_ATTR_SWIMMING_TRACKER_TIME_REST = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x7), + SENSOR_ATTR_SWIMMING_TRACKER_TIME_TURN = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_TRACKER, 0x8), + + SENSOR_ATTR_SWIMMING_OUTDOOR_SET_BATCH_LAP_COUNT = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x1), + SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_LENGTH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x2), + SENSOR_ATTR_SWIMMING_OUTDOOR_SETGOAL_TIME = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x3), + SENSOR_ATTR_SWIMMING_OUTDOOR_SET_GPS_PERMISSION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x4), + SENSOR_ATTR_SWIMMING_OUTDOOR_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_SWIMMING_OUTDOOR, 0x6), + + SENSOR_ATTR_AUTO_SWIMMING_DURATION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_AUTO_SWIMMING, 0x1), + + SENSOR_ATTR_INACTIVITY_DETECTOR_LEVEL = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x1), + SENSOR_ATTR_INACTIVITY_DETECTOR_DURATION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_INACTIVITY_DETECTOR, 0x2), + + SENSOR_ATTR_STRESS_TRACKER_DUR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x1), + SENSOR_ATTR_STRESS_TRACKER_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_STRESS_TRACKER, 0x2), + + SENSOR_ATTR_STRESS_MONITOR_BASE_HR = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x1), + SENSOR_ATTR_STRESS_MONITOR_HISTO_INDEX = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x2), + SENSOR_ATTR_STRESS_MONITOR_HISTO_VALUE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x3), + SENSOR_ATTR_STRESS_MONITOR_TUNE_INDEX = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x4), + SENSOR_ATTR_STRESS_MONITOR_TUNE_VALUE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x5), + SENSOR_ATTR_STRESS_MONITOR_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x6), + SENSOR_ATTR_STRESS_MONITOR_OPERATION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_STRESS_MONITOR, 0x7), + + SENSOR_ATTR_SLEEP_MONITOR_STOP = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x1), + SENSOR_ATTR_SLEEP_MONITOR_FLUSH = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_MONITOR, 0x2), + + SENSOR_ATTR_SLEEP_DETECTOR_STOP = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x1), + SENSOR_ATTR_SLEEP_DETECTOR_SETTING = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_HUMAN_SLEEP_DETECTOR, 0x2), + + SENSOR_ATTR_DATA_JOURNAL_START = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x1), + SENSOR_ATTR_DATA_JOURNAL_STOP = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_DATA_JOURNAL, 0x2), + + SENSOR_ATTR_GPS_BATCH_OPR_MODE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_BATCH, 0x1), + + SENSOR_ATTR_PPG_BATCH_POLLING_INTERVAL = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x1), + SENSOR_ATTR_PPG_BATCH_FLUSH = CONVERT_TYPE_ATTR(SENSOR_DEVICE_PPG_BATCH, 0x2), + + SENSOR_ATTR_REG_CTRL_TYPE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x1), + SENSOR_ATTR_REG_CTRL_ADDRESS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x2), + SENSOR_ATTR_REG_CTRL_VALUE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x3), + SENSOR_ATTR_REG_CTRL_MODE = CONVERT_TYPE_ATTR(SENSOR_DEVICE_REG_CTRL, 0x4), + + SENSOR_ATTR_GPS_CTRL_SETTING = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GPS_CTRL, 0x1), + + SENSOR_ATTR_FAKE_MOTION_EVENT_INTERVAL = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x1), + SENSOR_ATTR_FAKE_MOTION_EVENT_COUNT = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x2), + SENSOR_ATTR_FAKE_MOTION_PAUSE_INTERVAL = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_FAKE_MOTION, 0x3), + + SENSOR_ATTR_GEOFENCE_ID = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x1), + SENSOR_ATTR_GEOFENCE_LAT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x2), + SENSOR_ATTR_GEOFENCE_LON = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x3), + SENSOR_ATTR_GEOFENCE_RADIUS = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x4), + SENSOR_ATTR_GEOFENCE_PROVIDER = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x5), + SENSOR_ATTR_GEOFENCE_ACCURACY = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x6), + SENSOR_ATTR_GEOFENCE_TIMESTAMP = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x7), + SENSOR_ATTR_GEOFENCE_CONNECT = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x8), + SENSOR_ATTR_GEOFENCE_START = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x10), + SENSOR_ATTR_GEOFENCE_STOP = CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x11), + SENSOR_ATTR_GEOFENCE_SET_LOCATION = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x12), + SENSOR_ATTR_GEOFENCE_BT_CONNECT = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_GEOFENCE, 0x13), + + SENSOR_ATTR_FALL_DETECTION_OPR_MODE = + CONVERT_TYPE_ATTR(SENSOR_DEVICE_FALL_DETECTION, 0x1), +}; + +enum sensor_activity { + SENSOR_ACTIVITY_UNKNOWN = 1, + SENSOR_ACTIVITY_STILL = 2, + SENSOR_ACTIVITY_WALKING = 4, + SENSOR_ACTIVITY_RUNNING = 8, + SENSOR_ACTIVITY_IN_VEHICLE = 16, + SENSOR_ACTIVITY_ON_BICYCLE = 32, +}; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/* + * Create devices + */ +typedef void *sensor_device_t; +typedef int (*create_t)(sensor_device_t **devices); + +/* + * Sensor device interface + * 1 device must be abstracted from 1 device event node + */ +class sensor_device { + public: + virtual ~sensor_device() {} + + uint32_t get_hal_version(void) { return SENSOR_HAL_VERSION(1, 0); } + + virtual int get_poll_fd(void) = 0; + virtual int get_sensors(const sensor_info_t **sensors) = 0; + + virtual bool enable(uint32_t id) = 0; + virtual bool disable(uint32_t id) = 0; + + virtual int read_fd(uint32_t **ids) = 0; + virtual int get_data(uint32_t id, sensor_data_t **data, int *length) = 0; + + virtual bool set_interval(uint32_t id, unsigned long val) { return true; } + virtual bool set_batch_latency(uint32_t id, unsigned long val) { + return true; + } + virtual bool set_attribute_int(uint32_t id, int32_t attribute, + int32_t value) { + return true; + } + virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, + int len) { + return true; + } + virtual bool flush(uint32_t id) { return true; } +}; + +#endif /* __HAL_SENSOR_TYPES__ */ diff --git a/include/hal-sensor.h b/include/hal-sensor.h index 7b6c0ca..6743422 100644 --- a/include/hal-sensor.h +++ b/include/hal-sensor.h @@ -19,6 +19,8 @@ #ifndef __HAL_SENSOR__ #define __HAL_SENSOR__ +#include "hal-sensor-types.h" + #ifdef __cplusplus extern "C" { #endif @@ -26,7 +28,7 @@ extern "C" { int hal_sensor_get_backend(void); int hal_sensor_put_backend(void); -int hal_sensor_create(void ***devices); +int hal_sensor_create(sensor_device_t **devices); #ifdef __cplusplus } diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index 31f5bac..e4b535a 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -59,7 +59,7 @@ int hal_sensor_put_backend(void) { } EXPORT -int hal_sensor_create(void ***devices) { +int hal_sensor_create(sensor_device_t **devices) { if (!g_sensor_funcs) { return -ENOTSUP; } -- 2.7.4 From 1d6e19a847fb178a263de4a0ef4955afa13e13c5 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Thu, 4 Feb 2021 10:40:20 +0900 Subject: [PATCH 03/16] Fix a wrong conditional compilation Change-Id: I4bc14399318aa645398ea8fd7a55669e8f21a0db Signed-off-by: Boram Bae --- include/hal-sensor-types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index 653714a..c805fc5 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -527,7 +527,6 @@ enum sensor_activity { #ifdef __cplusplus } -#endif /* __cplusplus */ /* * Create devices @@ -569,4 +568,5 @@ class sensor_device { virtual bool flush(uint32_t id) { return true; } }; +#endif /* __cplusplus */ #endif /* __HAL_SENSOR_TYPES__ */ -- 2.7.4 From 508300ebcd3dc462a42af5ac43671f8f0b56fe3b Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Wed, 17 Feb 2021 15:55:54 +0900 Subject: [PATCH 04/16] Add more sensor types * Change type from sensor_device_type to int Change-Id: I941b0d97ee96b80dede3dede362cf829fca957b6 Signed-off-by: Boram Bae --- include/hal-sensor-types.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index c805fc5..fcba0cd 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -87,6 +87,11 @@ typedef enum { SENSOR_DEVICE_EXERCISE_STEPPER, SENSOR_DEVICE_DATA_JOURNAL = 0x500, + SENSOR_DEVICE_MOTION_SENSOR, + SENSOR_DEVICE_FAKE, + SENSOR_DEVICE_TAP_SENSOR, + SENSOR_DEVICE_COLOR_SENSOR, + SENSOR_DEVICE_WIFI_MOTION_DETECTOR, SENSOR_DEVICE_FUSION = 0x900, SENSOR_DEVICE_AUTO_ROTATION, @@ -158,7 +163,7 @@ typedef enum { typedef struct sensor_info_t { uint32_t id; const char *name; - sensor_device_type type; + int type; // sensor_device_type unsigned int event_type; // for Internal API const char *model_name; const char *vendor; -- 2.7.4 From 31562d6e5c6d66d21002c45d0e3eac9b88f6796f Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Mon, 22 Mar 2021 12:05:37 +0900 Subject: [PATCH 05/16] Add build flags Change-Id: I20fee1c80f11d9b84edfa10b7a7fa4d610bdcf28 Signed-off-by: Boram Bae --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3501524..697f63e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIE") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIE -fPIC") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-pie") -- 2.7.4 From 4b985b6a8a86ec9289f38d07e95d784dde4b82c5 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 5 Apr 2021 20:10:04 +0900 Subject: [PATCH 06/16] Load HAL module before running API Change-Id: Ibe74a9b72c30ea96f61efb7110a8c897eeffd5c7 Signed-off-by: Yunmi Ha --- src/hal-api-sensor.cpp | 67 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index e4b535a..01683b7 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -25,43 +25,58 @@ #define EXPORT __attribute__((visibility("default"))) #endif -static hal_backend_sensor_funcs *g_sensor_funcs = NULL; +static hal_backend_sensor_funcs *hal_sensor_funcs = NULL; +/* +-1 : failed to initialize +0 : not initialized +1 : succeeded to initialize +*/ +static int hal_initialized = 0; EXPORT -int hal_sensor_get_backend(void) { - int ret; +int hal_sensor_get_backend(void) +{ + int ret; - if (g_sensor_funcs) return 0; + if (hal_sensor_funcs) + return 0; - ret = hal_common_get_backend(HAL_MODULE_SENSOR, (void **)&g_sensor_funcs); - if (ret < 0) { - _E("Failed to get backend\n"); - return -EINVAL; - } + ret = hal_common_get_backend(HAL_MODULE_SENSOR, (void **)&hal_sensor_funcs); + if (ret < 0) { + _E("Failed to get backend"); + hal_initialized = -1; + return -ENODEV; + } - return 0; + hal_initialized = 1; + return 0; } EXPORT -int hal_sensor_put_backend(void) { - int ret; - - if (!g_sensor_funcs) return -EINVAL; +int hal_sensor_put_backend(void) +{ + if (!hal_sensor_funcs) + return -ENODEV; - ret = hal_common_put_backend(HAL_MODULE_SENSOR, (void *)g_sensor_funcs); - if (ret < 0) { - _E("Failed to put backend\n"); - return -EINVAL; - } - g_sensor_funcs = NULL; + hal_common_put_backend(HAL_MODULE_SENSOR, (void *)hal_sensor_funcs); + hal_sensor_funcs = NULL; + hal_initialized = 0; - return 0; + return 0; } EXPORT -int hal_sensor_create(sensor_device_t **devices) { - if (!g_sensor_funcs) { - return -ENOTSUP; - } - return g_sensor_funcs->create(devices); +int hal_sensor_create(sensor_device_t **devices) +{ + int ret; + + if (!hal_sensor_funcs && !hal_initialized) { + if ((ret = hal_sensor_get_backend()) < 0) + return ret; + } + + if (!hal_sensor_funcs || !hal_sensor_funcs->create) + return -ENODEV; + + return hal_sensor_funcs->create(devices); } -- 2.7.4 From 49335ba517dd035fd3438834f46094583a4c8099 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 13 Apr 2021 15:34:55 +0900 Subject: [PATCH 07/16] Add haltest Change-Id: I71919c82656d07c14990795a2b6f099cb4104150 Signed-off-by: Yunmi Ha --- CMakeLists.txt | 4 + haltest/CMakeLists.txt | 46 +++++++++++ haltest/main.cpp | 60 +++++++++++++++ haltest/sensor-device.cpp | 173 ++++++++++++++++++++++++++++++++++++++++++ haltest/sensor-haltest.h | 80 +++++++++++++++++++ include/hal-sensor-types.h | 20 +++++ packaging/hal-api-sensor.spec | 19 ++++- 7 files changed, 400 insertions(+), 2 deletions(-) create mode 100644 haltest/CMakeLists.txt create mode 100644 haltest/main.cpp create mode 100644 haltest/sensor-device.cpp create mode 100644 haltest/sensor-haltest.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 697f63e..1b3e104 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,3 +56,7 @@ INSTALL( FILES_MATCHING PATTERN "*.h" ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIBDIR}/pkgconfig) + +IF(HALTEST STREQUAL on) + ADD_SUBDIRECTORY(haltest) +ENDIF() diff --git a/haltest/CMakeLists.txt b/haltest/CMakeLists.txt new file mode 100644 index 0000000..97c237c --- /dev/null +++ b/haltest/CMakeLists.txt @@ -0,0 +1,46 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(sensor-haltests CXX) + +SET(HALAPI_LIBRARY "hal-api-sensor") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/${INC_DIR}) + +SET(REQUIRES_LIST ${REQUIRES_LIST} + hal-api-common + glib-2.0 + gio-2.0 + gmock + dlog +) + +FIND_LIBRARY( + HALAPI_LIBRARY + NAMES libhal-api-sensor.so + HINTS /usr/lib/hal /usr/lib64/hal + REQUIRED) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(gtest_pkgs REQUIRED ${REQUIRES_LIST}) + +SET(GTEST_VERSION ${gtest_pkgs_gmock_VERSION}) +STRING(REPLACE "." ";" GTEST_VERSION ${GTEST_VERSION}) +LIST(GET GTEST_VERSION 0 GTEST_VERSION_MAJOR) +LIST(GET GTEST_VERSION 1 GTEST_VERSION_MINOR) +ADD_DEFINITIONS("-DGTEST_VERSION_MAJOR=${GTEST_VERSION_MAJOR}") +ADD_DEFINITIONS("-DGTEST_VERSION_MINOR=${GTEST_VERSION_MINOR}") + +FOREACH(flag ${gtest_pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=gnu++0x") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--gc-sections -pie") + +FILE(GLOB HALTESTS "*.cpp") + +SET(SRCS ${CMAKE_SOURCE_DIR}/haltest/main.cpp ${HALTESTS}) +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${gtest_LDFLAGS} ${gtest_pkgs_LDFLAGS} -ldl ${HALAPI_LIBRARY}) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/hal) diff --git a/haltest/main.cpp b/haltest/main.cpp new file mode 100644 index 0000000..287c9f4 --- /dev/null +++ b/haltest/main.cpp @@ -0,0 +1,60 @@ +#include "sensor-haltest.h" +#include "hal-sensor.h" + +#define CHECK_NODEV(ret_val) \ + if (ret_val == -ENODEV) { \ + SKIP_MESSAGE("Not supported HAL."); \ + return ; \ + } + +class SENSOR_API : public testing::Test { +protected: + static void SetUpHalTestSuite() { + } + + void SetUp() override {} + void TearDown() override {} +}; + +TEST_F(SENSOR_API, GetBackendP) +{ + int ret_val; + + ret_val = hal_sensor_get_backend(); + EXPECT_EQ(ret_val, 0) << strerr("Failed to get sensor device", ret_val); +} + +TEST_F(SENSOR_API, CreateP) +{ + int ret_val; + + void **devices; + ret_val = hal_sensor_create(&devices); + if (ret_val == -ENODEV) { + SKIP_MESSAGE("Not supported HAL"); + return ; + } + ASSERT_GT(ret_val, 0) << strerr("Failed to call create", ret_val); + ASSERT_NE(devices[0], nullptr) << "Opened devices are invalid."; +} + +int main(int argc, char **argv) +{ + int ret = -1; + + try { + testing::InitGoogleTest(&argc, argv); + } catch(...) { + std::cout << "Exception occurred." << std::endl; + } + + try { + ret = RUN_ALL_TESTS(); + } catch (const ::testing::internal::GoogleTestFailureException& e) { + ret = -1; + std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl; + } + + return ret; +} + diff --git a/haltest/sensor-device.cpp b/haltest/sensor-device.cpp new file mode 100644 index 0000000..93089e4 --- /dev/null +++ b/haltest/sensor-device.cpp @@ -0,0 +1,173 @@ +#include + +#include "sensor-haltest.h" +#include "hal-sensor.h" +#include "hal-sensor-types.h" + +typedef std::vector> device_registry_t; + +class SENSOR_DEV : public testing::Test { +public: + static int device_count; + static device_registry_t devices; + + static void SetUpHalTestSuite() { + void **sensors = nullptr; + + device_count = hal_sensor_create(&sensors); + ASSERT_GT(device_count, 0) << "Failed to get sensor devices"; + + DEBUG_MESSAGE("Setup test suite : Create %d sensor devices", device_count); + for (int i = 0; i < device_count; i++) { + devices.emplace_back(static_cast(sensors[i])); + } + } + + void SetUp() override{} + void TearDown() override{} +}; + +int SENSOR_DEV::device_count = 0; +device_registry_t SENSOR_DEV::devices; + +#define SKIP_NO_DEV() \ + if (device_count <= 0) { \ + SKIP_MESSAGE("There is no sensor devices."); \ + return; \ + } + +TEST_F(SENSOR_DEV, get_poll_fdP) +{ + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_NE((*it)->get_poll_fd(), 0); + } +} + +TEST_F(SENSOR_DEV, get_sensorsP) +{ + const sensor_info_t *sensors = nullptr; + int ret_func; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + ret_func = (*it)->get_sensors(&sensors); + EXPECT_GE(ret_func, 1); + EXPECT_NE(sensors, nullptr); + } +} + +TEST_F(SENSOR_DEV, get_sensorsN) +{ + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->get_sensors(nullptr), SENSOR_ERROR_INVALID_PARAMETER); + } +} +/* +TEST_F(SENSOR_DEV, enableP) +{ + const sensor_info_t *sensors = nullptr; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_GE((*it)->get_sensors(&sensors), 1); + (*it)->disable(sensors[0].id); + EXPECT_EQ((*it)->enable(sensors[0].id), true); + } +} + +TEST_F(SENSOR_DEV, enableN) +{ + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->enable(0), false); + EXPECT_EQ((*it)->enable(10), false); + } +} + +TEST_F(SENSOR_DEV, disableP) +{ + const sensor_info_t *sensors = nullptr; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_GE((*it)->get_sensors(&sensors), 1); + EXPECT_EQ((*it)->disable(sensors[0].id), true); + } + +} + +TEST_F(SENSOR_DEV, disableN) +{ + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->disable(0), false); + EXPECT_EQ((*it)->disable(10), false); + } +} +*/ +/* +TEST_F(SENSOR_DEV, read_fdP) +{ + uint32_t *id = nullptr; + int ret_func = 0; + + SKIP_NO_DEV(); + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->enable(1), true); + + ret_func = (*it)->read_fd(&id); + EXPECT_NE(id, nullptr); + EXPECT_NE(ret_func, 0); + } +} + +TEST_F(SENSOR_DEV, read_fdN) +{ + + SKIP_NO_DEV(); + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->read_fd(nullptr), SENSOR_ERROR_INVALID_PARAMETER); + } +} +*/ +TEST_F(SENSOR_DEV, get_dataP) +{ + int length = 0; + int ret_func = 0; + sensor_data_t *data = NULL; + const sensor_info_t *sensors = nullptr; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_GE((*it)->get_sensors(&sensors), 1); + + ret_func = (*it)->get_data(sensors[0].id, &data, &length); + EXPECT_EQ(ret_func, 0); + } +} + +TEST_F(SENSOR_DEV, get_dataN) +{ + int length = 0; + sensor_data_t *data = NULL; + + SKIP_NO_DEV() + + for (auto it = devices.begin(); it != devices.end(); ++it) { + EXPECT_EQ((*it)->get_data(0, &data, &length), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->get_data(1, nullptr, &length), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->get_data(1, &data, nullptr), SENSOR_ERROR_INVALID_PARAMETER); + } +} diff --git a/haltest/sensor-haltest.h b/haltest/sensor-haltest.h new file mode 100644 index 0000000..033fb75 --- /dev/null +++ b/haltest/sensor-haltest.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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_HALTEST_H__ +#define __SENSOR_HALTEST_H__ + +#include +#include + +// hack gtest internal for print message +namespace testing +{ + namespace internal + { + enum GTestColor { + COLOR_DEFAULT, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW + }; + + extern void ColoredPrintf(GTestColor color, const char* fmt, ...); + } +} + +#define SKIP_MESSAGE(fmt, args...) \ +do { \ + testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, "[ SKIPPED ] "); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, fmt, ##args); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_YELLOW, "\n"); \ +} while (0) + +#define DEBUG_MESSAGE(fmt, args...) \ +do { \ + testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "[ DEBUG ] "); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_DEFAULT, fmt, ##args); \ + testing::internal::ColoredPrintf(testing::internal::COLOR_DEFAULT, "\n"); \ +} while (0) + +// SetUp/TearDown function for a testsuite differ by gtest version +#if (GTEST_VERSION_MAJOR >= 2 || (GTEST_VERSION_MAJOR == 1 && GTEST_VERSION_MINOR >= 10)) +#define SetUpHalTestSuite SetUpTestSuite +#define TearDownHalTestSuite TearDownTestSuite +#else +#define SetUpHalTestSuite SetUpTestCase +#define TearDownHalTestSuite TearDownTestCase +#endif + +#define BUFMAX 256 +static char errbuf1[BUFMAX]; + +static inline const char* strerr(const char* message, int eno) +{ + if (eno == 0) + return message; + + if (eno < 0) + eno = -eno; + + if (message) + snprintf(errbuf1, BUFMAX, "%s (%s)", message, strerror(eno)); + else + snprintf(errbuf1, BUFMAX, "%s", strerror(eno)); + + return errbuf1; +} + +#endif /* __SENSOR_HALTEST_H__ */ diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index fcba0cd..d373f6f 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -20,6 +20,7 @@ #include #include #include +#include #define SENSOR_HAL_VERSION(maj, min) ((((maj)&0xFFFF) << 24) | ((min)&0xFFFF)) @@ -155,6 +156,25 @@ typedef enum { SENSOR_DEVICE_PPG, } sensor_device_type; +/** + * @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; + /* * A platform sensor handler is generated based on this handle * This id can be assigned from HAL developer. so it has to be unique in 1 diff --git a/packaging/hal-api-sensor.spec b/packaging/hal-api-sensor.spec index a06a530..c86626f 100644 --- a/packaging/hal-api-sensor.spec +++ b/packaging/hal-api-sensor.spec @@ -7,7 +7,7 @@ Name: %{name} Summary: %{name} interface Version: 0.0.1 Release: 1 -Group: Development/Libraries +Group: System/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1: %{name}.manifest @@ -34,6 +34,14 @@ Requires: %{name} = %{version}-%{release} %description -n %{devel_name} %{name} Interface for product vendor developer +### hal test package ######## +%package -n sensor-haltests +Summary: Sensor HAL(Hardware Abstraction Layer) Test Cases +Requires: %{name} = %{version}-%{release} + +%description -n sensor-haltests +Sensor HAL(Hardware Abstraction Layer) Test Cases + ### build and install ######### %prep %setup -q @@ -42,7 +50,9 @@ Requires: %{name} = %{version}-%{release} %build cp %{SOURCE1} . cp %{SOURCE2} . -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir} +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + -DCMAKE_LIBDIR_PREFIX=%{_libdir} \ + -DHALTEST=on make %{?jobs:-j%jobs} %install @@ -71,3 +81,8 @@ rm -rf %{buildroot} %license LICENSE %{_includedir}/hal/*.h %{_libdir}/pkgconfig/%{name}.pc + +%files -n sensor-haltests +%manifest %{name}.manifest +%license LICENSE +%{_bindir}/hal/sensor-haltests -- 2.7.4 From 94c68e97f9ac6d0b5357c5e41e9b522fa17c0b78 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 20 Apr 2021 14:12:58 +0900 Subject: [PATCH 08/16] Use system error instaed of sensor_error_e Change-Id: Ibea2e23204e1186533ee997bbf2509eae319b19b Signed-off-by: Yunmi Ha --- haltest/sensor-device.cpp | 10 +++++----- include/hal-sensor-types.h | 20 -------------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/haltest/sensor-device.cpp b/haltest/sensor-device.cpp index 93089e4..58bd034 100644 --- a/haltest/sensor-device.cpp +++ b/haltest/sensor-device.cpp @@ -64,7 +64,7 @@ TEST_F(SENSOR_DEV, get_sensorsN) SKIP_NO_DEV() for (auto it = devices.begin(); it != devices.end(); ++it) { - EXPECT_EQ((*it)->get_sensors(nullptr), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->get_sensors(nullptr), -EINVAL); } } /* @@ -137,7 +137,7 @@ TEST_F(SENSOR_DEV, read_fdN) SKIP_NO_DEV(); for (auto it = devices.begin(); it != devices.end(); ++it) { - EXPECT_EQ((*it)->read_fd(nullptr), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->read_fd(nullptr), -EINVAL); } } */ @@ -166,8 +166,8 @@ TEST_F(SENSOR_DEV, get_dataN) SKIP_NO_DEV() for (auto it = devices.begin(); it != devices.end(); ++it) { - EXPECT_EQ((*it)->get_data(0, &data, &length), SENSOR_ERROR_INVALID_PARAMETER); - EXPECT_EQ((*it)->get_data(1, nullptr, &length), SENSOR_ERROR_INVALID_PARAMETER); - EXPECT_EQ((*it)->get_data(1, &data, nullptr), SENSOR_ERROR_INVALID_PARAMETER); + EXPECT_EQ((*it)->get_data(0, &data, &length), -EINVAL); + EXPECT_EQ((*it)->get_data(1, nullptr, &length), -EINVAL); + EXPECT_EQ((*it)->get_data(1, &data, nullptr), -EINVAL); } } diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index d373f6f..fcba0cd 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -20,7 +20,6 @@ #include #include #include -#include #define SENSOR_HAL_VERSION(maj, min) ((((maj)&0xFFFF) << 24) | ((min)&0xFFFF)) @@ -156,25 +155,6 @@ typedef enum { SENSOR_DEVICE_PPG, } sensor_device_type; -/** - * @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; - /* * A platform sensor handler is generated based on this handle * This id can be assigned from HAL developer. so it has to be unique in 1 -- 2.7.4 From 6f0d90cea3cef30da5de4dcb1c58280a881fdc15 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 22 Apr 2021 14:50:16 +0900 Subject: [PATCH 09/16] Remove unneeded fPIE gcc option The fPIE option is for the executable binary. It is not proper for shared library files. So that remove unneeded fPIE gcc option. Change-Id: I800016e2bb30b8a02d2170b9c87df4cd334dfa02 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b3e104..8e2f855 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIE -fPIC") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-pie") -- 2.7.4 From 0813c0b54e38beb0f84d1b5d1f0a455bdb12474f Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 26 Apr 2021 17:19:16 +0900 Subject: [PATCH 10/16] Add get_attribute interface Change-Id: I588887f1fdc17dbd079d97d646b1b88b932a940a Signed-off-by: Yunmi Ha --- include/hal-sensor-types.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index fcba0cd..d7b78d1 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -570,6 +570,15 @@ class sensor_device { int len) { return true; } + virtual bool get_attribute_int(uint32_t id, int32_t attribute, + int32_t *value) { + return true; + } + virtual bool set_attribute_str(uint32_t id, int32_t attribute, char **value, + int *len) { + return true; + } + virtual bool flush(uint32_t id) { return true; } }; -- 2.7.4 From 452278d1f20aebc46f4dc7a78a190d6e0baaf618 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Tue, 11 May 2021 16:04:32 +0900 Subject: [PATCH 11/16] Add conditional compile directive to avoid build error Change-Id: I4e6d3bda7bcea0af59793344b0787b9aa89114b0 Signed-off-by: taemin.yeom --- haltest/sensor-haltest.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/haltest/sensor-haltest.h b/haltest/sensor-haltest.h index 033fb75..3e030f1 100644 --- a/haltest/sensor-haltest.h +++ b/haltest/sensor-haltest.h @@ -19,6 +19,7 @@ #include #include +#if (GTEST_VERSION_MAJOR < 1 || (GTEST_VERSION_MAJOR == 1 && GTEST_VERSION_MINOR < 10)) // hack gtest internal for print message namespace testing { @@ -34,6 +35,7 @@ namespace testing extern void ColoredPrintf(GTestColor color, const char* fmt, ...); } } +#endif #define SKIP_MESSAGE(fmt, args...) \ do { \ -- 2.7.4 From d8f8d0c6004ec5cf821c891a19b5d8fb690aaa17 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 21 Jun 2021 20:51:21 +0900 Subject: [PATCH 12/16] Fix get_attribute interface Change-Id: I22e5145fbb8a11f32a0eba96d9dfbf335cf2e0ba Signed-off-by: Hyotaek Shim --- include/hal-sensor-types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index d7b78d1..07d89d3 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -574,7 +574,7 @@ class sensor_device { int32_t *value) { return true; } - virtual bool set_attribute_str(uint32_t id, int32_t attribute, char **value, + virtual bool get_attribute_str(uint32_t id, int32_t attribute, char **value, int *len) { return true; } -- 2.7.4 From ed1d69136415abe6c2f74eaac3eed67485108679 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 21 Jun 2021 20:58:12 +0900 Subject: [PATCH 13/16] Add file cases to .gitignore Change-Id: I2bb317443cd46fbff28c369c92081dafe3422f26 Signed-off-by: Hyotaek Shim --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 623211c..43c5f5b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,7 @@ build.ninja rules.ninja #ETC -.vscode/ \ No newline at end of file +.vscode/ +cscope.files +cscope.out +tags -- 2.7.4 From a1f3041dd445b01942e5b7bad512398a60798df3 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Tue, 22 Jun 2021 10:51:05 +0900 Subject: [PATCH 14/16] Add const keyword to char* argument Change-Id: I84d417a5c4e17c1eeeb03c6c66654a8ef78b35b2 Signed-off-by: taemin.yeom --- include/hal-sensor-types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/hal-sensor-types.h b/include/hal-sensor-types.h index 07d89d3..d4ee3fe 100644 --- a/include/hal-sensor-types.h +++ b/include/hal-sensor-types.h @@ -566,7 +566,7 @@ class sensor_device { int32_t value) { return true; } - virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, + virtual bool set_attribute_str(uint32_t id, int32_t attribute, const char *value, int len) { return true; } -- 2.7.4 From e06b5066452e0967f04d278cce00ebc4e5ba635f Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Fri, 9 Jul 2021 15:23:21 +0900 Subject: [PATCH 15/16] Divide HAL so file by each sensor Change-Id: I13af2315223a2730876983b587153bd4d75de346 Signed-off-by: Yunmi Ha --- src/hal-api-sensor.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 12 deletions(-) diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index 01683b7..7dbbd99 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -13,19 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include +#include #include #include #include "hal-api-sensor-log.h" #include "hal-sensor-interface.h" +#include "hal-sensor-types.h" #include "hal-sensor.h" #ifndef EXPORT #define EXPORT __attribute__((visibility("default"))) #endif -static hal_backend_sensor_funcs *hal_sensor_funcs = NULL; +static hal_backend_sensor_funcs **hal_sensor_funcs = NULL; +static char **hal_sensor_names = NULL; +static int hal_sensor_count = 0; /* -1 : failed to initialize 0 : not initialized @@ -33,33 +37,100 @@ static hal_backend_sensor_funcs *hal_sensor_funcs = NULL; */ static int hal_initialized = 0; +static std::vector hal_backend_devs; + +#define FREE(x) \ + do { if (x) { free(x); x = NULL; } } while(0) + EXPORT int hal_sensor_get_backend(void) { - int ret; + int ret_getnames, ret_getbackend; + int i; + int loaded_backend = 0; if (hal_sensor_funcs) return 0; - ret = hal_common_get_backend(HAL_MODULE_SENSOR, (void **)&hal_sensor_funcs); - if (ret < 0) { - _E("Failed to get backend"); - hal_initialized = -1; + hal_sensor_count = hal_common_get_backend_count(HAL_MODULE_SENSOR); + if (hal_sensor_count < 0) { + _E("Failed to get backend count."); + return -ENODEV; + } else if (hal_sensor_count == 0) { + _E("There is no hal-backend-sensor library."); + return -ENODEV; + } + + hal_sensor_names = (char **)malloc(sizeof(char *) * hal_sensor_count); + if (!hal_sensor_names) { + _E("Failed to allocate memory."); + hal_sensor_count = 0; return -ENODEV; } + for (i = 0; i < hal_sensor_count; i++) { + hal_sensor_names[i] = (char *)malloc(sizeof(char) * 256); + if (!hal_sensor_names[i]) { + _E("Failed to allocate memory."); + goto FREE_MEMORY; + } + } + + ret_getnames = hal_common_get_backend_library_names(HAL_MODULE_SENSOR, hal_sensor_names, hal_sensor_count); + if (ret_getnames < 0) { + _E("Failed to get backend library names."); + goto FREE_MEMORY; + } + + hal_sensor_funcs = (hal_backend_sensor_funcs **)malloc(sizeof(hal_backend_sensor_funcs *) * hal_sensor_count); + if (!hal_sensor_funcs) { + _E("Failed to allocate memory."); + goto FREE_MEMORY; + } + + for(i = 0; i < hal_sensor_count; i++) { + ret_getbackend = hal_common_get_backend_with_library_name(HAL_MODULE_SENSOR, (void **)&hal_sensor_funcs[i], hal_sensor_names[i]); + if (ret_getbackend < 0) { + _E("Failed to get backend (%s)", hal_sensor_names[i]); + } else + loaded_backend++; + } + + if (loaded_backend == 0) { + FREE(hal_sensor_funcs); + goto FREE_MEMORY; + } + hal_initialized = 1; return 0; + +FREE_MEMORY: + for(i = 0; i < hal_sensor_count; i++) + FREE(hal_sensor_names[i]); + + FREE(hal_sensor_names); + + hal_sensor_count = 0; + hal_initialized = -1; + return -ENODEV; } EXPORT int hal_sensor_put_backend(void) { + int i = 0; if (!hal_sensor_funcs) return -ENODEV; - hal_common_put_backend(HAL_MODULE_SENSOR, (void *)hal_sensor_funcs); - hal_sensor_funcs = NULL; + for (i = 0; i < hal_sensor_count; i++) { + if (hal_sensor_funcs[i]) { + hal_common_put_backend_with_library_name(HAL_MODULE_SENSOR, (void *)hal_sensor_funcs[i], hal_sensor_names[i]); + } + FREE(hal_sensor_names[i]); + } + FREE(hal_sensor_names); + FREE(hal_sensor_funcs); + hal_initialized = 0; return 0; @@ -68,15 +139,31 @@ int hal_sensor_put_backend(void) EXPORT int hal_sensor_create(sensor_device_t **devices) { - int ret; + int ret, ret_create; + int i, j; + sensor_device_t *device; if (!hal_sensor_funcs && !hal_initialized) { if ((ret = hal_sensor_get_backend()) < 0) return ret; } - if (!hal_sensor_funcs || !hal_sensor_funcs->create) + if (!hal_sensor_funcs || (hal_sensor_count == 0)) return -ENODEV; - return hal_sensor_funcs->create(devices); + if (hal_backend_devs.empty()) { + for (i = 0; i < hal_sensor_count; i++) { + if (!hal_sensor_funcs[i] || !hal_sensor_funcs[i]->create) + continue; + + ret_create = hal_sensor_funcs[i]->create(&device); + for (j = 0; j < ret_create; j++) + { + hal_backend_devs.push_back(device[j]); + } + } + } + + *devices = &hal_backend_devs[0]; + return hal_backend_devs.size(); } -- 2.7.4 From f0f58a0bff4126e122af6676e6ada40f60e2781a Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 13 Jul 2021 11:35:15 +0900 Subject: [PATCH 16/16] Change hal_common_get_backend_library_names API parameter. Change-Id: I1bca6851b6a8b2704622ebf44fbf4bfa6b413ce5 Signed-off-by: Yunmi Ha --- src/hal-api-sensor.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hal-api-sensor.cpp b/src/hal-api-sensor.cpp index 7dbbd99..02a88b5 100644 --- a/src/hal-api-sensor.cpp +++ b/src/hal-api-sensor.cpp @@ -42,6 +42,8 @@ static std::vector hal_backend_devs; #define FREE(x) \ do { if (x) { free(x); x = NULL; } } while(0) +#define MAX_LIB_NAME 256 + EXPORT int hal_sensor_get_backend(void) { @@ -69,14 +71,14 @@ int hal_sensor_get_backend(void) } for (i = 0; i < hal_sensor_count; i++) { - hal_sensor_names[i] = (char *)malloc(sizeof(char) * 256); + hal_sensor_names[i] = (char *)malloc(sizeof(char) * MAX_LIB_NAME); if (!hal_sensor_names[i]) { _E("Failed to allocate memory."); goto FREE_MEMORY; } } - ret_getnames = hal_common_get_backend_library_names(HAL_MODULE_SENSOR, hal_sensor_names, hal_sensor_count); + ret_getnames = hal_common_get_backend_library_names(HAL_MODULE_SENSOR, hal_sensor_names, hal_sensor_count, MAX_LIB_NAME); if (ret_getnames < 0) { _E("Failed to get backend library names."); goto FREE_MEMORY; -- 2.7.4