From fdb3b536dc14fa2651de1793bcaf674f67526273 Mon Sep 17 00:00:00 2001 From: Asit Srivastava Date: Wed, 13 Jul 2016 16:03:16 +0530 Subject: [PATCH] [ITC][sensor][ACR-667][Add new sensor types/ sensor recorder APIs] Change-Id: I52135b6563e240e14b9ac7cd744516dfafa86adc Signed-off-by: Asit Srivastava --- src/itc/sensor/CMakeLists.txt | 1 + src/itc/sensor/ITs-sensor-common.c | 38 +- src/itc/sensor/ITs-sensor-common.h | 10 + src/itc/sensor/ITs-sensor-recorder.c | 1176 +++++++++++++++++++++++++ src/itc/sensor/ITs-sensor-util.c | 1 + src/itc/sensor/ITs-sensor.c | 28 +- src/itc/sensor/tct-sensor-native_common_iot.h | 26 + src/itc/sensor/tct-sensor-native_mobile.h | 26 + src/itc/sensor/tct-sensor-native_wearable.h | 26 + 9 files changed, 1303 insertions(+), 29 deletions(-) create mode 100755 src/itc/sensor/ITs-sensor-recorder.c diff --git a/src/itc/sensor/CMakeLists.txt b/src/itc/sensor/CMakeLists.txt index dfacfbc..8d2c527 100755 --- a/src/itc/sensor/CMakeLists.txt +++ b/src/itc/sensor/CMakeLists.txt @@ -8,6 +8,7 @@ SET(TC_SOURCES ITs-sensor-common.c ITs-sensor.c ITs-sensor-util.c + ITs-sensor-recorder.c ) PKG_CHECK_MODULES(${CAPI_LIB} REQUIRED diff --git a/src/itc/sensor/ITs-sensor-common.c b/src/itc/sensor/ITs-sensor-common.c index 59aaa1c..767690b 100755 --- a/src/itc/sensor/ITs-sensor-common.c +++ b/src/itc/sensor/ITs-sensor-common.c @@ -39,6 +39,8 @@ char* SensorsGetError(int nRet) case SENSOR_ERROR_NOT_SUPPORTED: szErrorVal = "SENSOR_ERROR_NOT_SUPPORTED"; break; case SENSOR_ERROR_OPERATION_FAILED: szErrorVal = "SENSOR_ERROR_OPERATION_FAILED"; break; case SENSOR_ERROR_PERMISSION_DENIED: szErrorVal = "SENSOR_ERROR_PERMISSION_DENIED"; break; + case SENSOR_ERROR_NO_DATA: szErrorVal = "SENSOR_ERROR_NO_DATA"; break; + case SENSOR_ERROR_NOT_AVAILABLE: szErrorVal = "SENSOR_ERROR_NOT_AVAILABLE"; break; default : szErrorVal = "Unknown error"; break; } return szErrorVal; @@ -78,7 +80,8 @@ char* SensorGetType(sensor_type_e nSensorType) case SENSOR_GEOMAGNETIC_ROTATION_VECTOR: szErrorVal = "SENSOR_GEOMAGNETIC_ROTATION_VECTOR"; break; /**< Geomagnetic-based rotation vector sensor (Since Tizen 2.4) */ case SENSOR_HUMAN_PEDOMETER: szErrorVal = "SENSOR_HUMAN_PEDOMETER"; break; case SENSOR_HUMAN_SLEEP_MONITOR : szErrorVal = "SENSOR_HUMAN_SLEEP_MONITOR"; break; - + case SENSOR_HUMAN_SLEEP_DETECTOR : szErrorVal = "SENSOR_HUMAN_SLEEP_DETECTOR"; break; + case SENSOR_HUMAN_STRESS_MONITOR : szErrorVal = "SENSOR_HUMAN_STRESS_MONITOR"; break; default : szErrorVal = "Unknown Error"; break; } return szErrorVal; @@ -95,15 +98,38 @@ char* SensorOption(sensor_option_e nSensorOption) char *szErrorVal = NULL; switch ( nSensorOption ) { - case SENSOR_OPTION_DEFAULT: szErrorVal = "SENSOR_OPTION_DEFAULT"; break; - case SENSOR_OPTION_ON_IN_SCREEN_OFF: szErrorVal = "SENSOR_OPTION_ON_IN_SCREEN_OFF"; break; - case SENSOR_OPTION_ON_IN_POWERSAVE_MODE: szErrorVal = "SENSOR_OPTION_ON_IN_POWERSAVE_MODE"; break; - case SENSOR_OPTION_ALWAYS_ON: szErrorVal = "SENSOR_OPTION_ALWAYS_ON"; break; - default : szErrorVal = "Unknown Error"; break; + case SENSOR_OPTION_DEFAULT: szErrorVal = "SENSOR_OPTION_DEFAULT"; break; + case SENSOR_OPTION_ON_IN_SCREEN_OFF: szErrorVal = "SENSOR_OPTION_ON_IN_SCREEN_OFF"; break; + case SENSOR_OPTION_ON_IN_POWERSAVE_MODE: szErrorVal = "SENSOR_OPTION_ON_IN_POWERSAVE_MODE"; break; + case SENSOR_OPTION_ALWAYS_ON: szErrorVal = "SENSOR_OPTION_ALWAYS_ON"; break; + default : szErrorVal = "Unknown Error"; break; } return szErrorVal; } +/** +* @function SensorTimeout +* @description Called if some callback is not invoked for a particular SensorTimeout +* @parameter gpointer data +* @return gboolean +*/ +gboolean SensorTimeout(gpointer data) +{ +#if DEBUG + FPRINTF("[Line : %d][%s] Callback Time-out\\n", __LINE__, API_NAMESPACE); +#endif + + GMainLoop *pMainLoop = NULL; + pMainLoop = (GMainLoop *)data; + if ( pMainLoop != NULL ) + { + g_main_loop_quit(g_pSensorMainLoop); + g_main_loop_unref(g_pSensorMainLoop); + g_pSensorMainLoop = NULL; + } + return false; +} + /** * @function SensorAttributeOption * @description Maps sensorattribute option enums diff --git a/src/itc/sensor/ITs-sensor-common.h b/src/itc/sensor/ITs-sensor-common.h index 9d1084a..65a9849 100755 --- a/src/itc/sensor/ITs-sensor-common.h +++ b/src/itc/sensor/ITs-sensor-common.h @@ -30,11 +30,15 @@ #define PATH_LEN 1024 #define TIMEOUT_CB 2000 #define MICROSECONDS_PER_SECOND 1000000 +#define TIME_1_HOUR_SEC 3600 +#define TIME_1_DAY_SEC (TIME_1_HOUR_SEC * 24) +#define TIME_1_MONTH_SEC (TIME_1_DAY_SEC * 30) bool g_bSensorsCreation; sensor_h g_pstSensorHandle; sensor_listener_h g_pstSensorListener; GMainLoop *g_pSensorMainLoop; +bool g_bSensorSkipExecutionWithFail; typedef struct Sensor { @@ -50,6 +54,11 @@ typedef enum FeatureCheck { #define START_TEST {\ FPRINTF("[Line : %d][%s] Starting test : %s\\n", __LINE__, API_NAMESPACE, __FUNCTION__);\ + if ( g_bSensorSkipExecutionWithFail == true )\ + {\ + FPRINTF("[Line : %d][%s] Sensor feature mismatch did not return TIZEN_ERROR_NOT_SUPPORTED, while feature value returned from model-config.xml is false \\n", __LINE__, API_NAMESPACE);\ + return 1;\ + }\ } #define RUN_POLLING_LOOP {\ @@ -62,6 +71,7 @@ typedef enum FeatureCheck { char* SensorOption(sensor_option_e nRet); char* SensorGetType(sensor_type_e nRet); +gboolean SensorTimeout(gpointer data); char* SensorsGetError(int nRet); feature_check_e SensorCheckFeature(sensor_type_e sensor, char* feature); char* SensorAttributeOption(sensor_attribute_e nSensorAttrOption); diff --git a/src/itc/sensor/ITs-sensor-recorder.c b/src/itc/sensor/ITs-sensor-recorder.c new file mode 100755 index 0000000..1cce92b --- /dev/null +++ b/src/itc/sensor/ITs-sensor-recorder.c @@ -0,0 +1,1176 @@ +// +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#include "ITs-sensor-common.h" + + +static bool sensor_recorder_supported[24]; +static bool g_bCallbackHit = false; +static int g_nRet; +static bool g_bStatus; +static bool g_bIsFeatureSupported = false; + + +SensorFeature Sensor[] = { + {SENSOR_ACCELEROMETER, "http://tizen.org/feature/sensor.accelerometer"}, + {SENSOR_GRAVITY, "http://tizen.org/feature/sensor.gravity"}, + {SENSOR_LINEAR_ACCELERATION, "http://tizen.org/feature/sensor.linear_acceleration"}, + {SENSOR_MAGNETIC, "http://tizen.org/feature/sensor.magnetometer"}, + {SENSOR_ROTATION_VECTOR, "http://tizen.org/feature/sensor.rotation_vector"}, + {SENSOR_ORIENTATION, "http://tizen.org/feature/sensor.tiltmeter"}, + {SENSOR_GYROSCOPE, "http://tizen.org/feature/sensor.gyroscope"}, + {SENSOR_LIGHT, "http://tizen.org/feature/sensor.photometer"}, + {SENSOR_PROXIMITY, "http://tizen.org/feature/sensor.proximity"}, + {SENSOR_PRESSURE, "http://tizen.org/feature/sensor.barometer"}, + {SENSOR_ULTRAVIOLET, "http://tizen.org/feature/sensor.ultraviolet"}, + {SENSOR_TEMPERATURE, "http://tizen.org/feature/sensor.temperature"}, + {SENSOR_HUMIDITY, "http://tizen.org/feature/sensor.humidity"}, + {SENSOR_HRM, "http://tizen.org/feature/sensor.heart_rate_monitor"}, + {SENSOR_HRM_LED_GREEN, "http://tizen.org/feature/sensor.heart_rate_monitor.led_green"}, + {SENSOR_HRM_LED_IR, "http://tizen.org/feature/sensor.heart_rate_monitor.led_ir"}, + {SENSOR_HRM_LED_RED, "http://tizen.org/feature/sensor.heart_rate_monitor.led_red"}, + {SENSOR_GYROSCOPE_UNCALIBRATED, "http://tizen.org/feature/sensor.gyroscope.uncalibrated"}, + {SENSOR_GEOMAGNETIC_UNCALIBRATED, "http://tizen.org/feature/sensor.magnetometer.uncalibrated"}, + {SENSOR_GYROSCOPE_ROTATION_VECTOR, "http://tizen.org/feature/sensor.gyroscope_rotation_vector"}, + {SENSOR_GEOMAGNETIC_ROTATION_VECTOR, "http://tizen.org/feature/sensor.geomagnetic_rotation_vector"}, + {SENSOR_HUMAN_SLEEP_MONITOR, "http://tizen.org/feature/sensor.sleep_monitor"}, + {SENSOR_HUMAN_SLEEP_DETECTOR, "http://tizen.org/feature/sensor.sleep_monitor"}, + {SENSOR_HUMAN_STRESS_MONITOR, "http://tizen.org/feature/sensor.stress_monitor"} + +}; + + +/** +* @function SensorRecorderDatacb +* @description Called during sensor recorder read. +* @parameter[IN] sensor_type_e +* @parameter[IN] sensor_recorder_data_h +* @parameter[IN] int +* @parameter[IN] sensor_error_e +* @parameter[IN] The user data passed from the callback registration function +* @return bool +*/ +static bool SensorRecorderDatacb(sensor_type_e type, sensor_recorder_data_h data, int remains, sensor_error_e error, void *user_data) +{ + g_bCallbackHit = true; + if (error != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] SensorRecorderSyncCb error = %d \\n", __LINE__, API_NAMESPACE,error); + } + + if ( g_pSensorMainLoop ) + { + g_main_loop_quit(g_pSensorMainLoop); + g_main_loop_unref(g_pSensorMainLoop); + g_pSensorMainLoop = NULL; + } + return true; +} + +/** +* @function SensorRecorderSyncCb +* @description Called during sensor recorder read sync. +* @parameter[IN] sensor_type_e +* @parameter[IN] sensor_recorder_data_h +* @parameter[IN] int +* @parameter[IN] sensor_error_e +* @parameter[IN] The user data passed from the callback registration function +* @return bool +*/ +static bool SensorRecorderSyncCb(sensor_type_e type, sensor_recorder_data_h data, int remains, sensor_error_e error, void *user_data) +{ + g_bCallbackHit = true; + + if (error != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] SensorRecorderSyncCb error = %d \\n", __LINE__, API_NAMESPACE,error); + } + if ( g_pSensorMainLoop ) + { + g_main_loop_quit(g_pSensorMainLoop); + g_main_loop_unref(g_pSensorMainLoop); + g_pSensorMainLoop = NULL; + } + + return true; +} + +/** +* @function SensorRecorderReadSyncCbGetDouble +* @description Called during sensor recorder read sync. +* @parameter[IN] sensor_type_e +* @parameter[IN] sensor_recorder_data_h +* @parameter[IN] int +* @parameter[IN] sensor_error_e +* @parameter[IN] The user data passed from the callback registration function +* @return bool +*/ +static bool SensorRecorderReadSyncCbGetDouble(sensor_type_e type, sensor_recorder_data_h data, int remains, sensor_error_e error, void *user_data) +{ + double val_double ; + int nEnumCount; + int arrSensorRecorderData[] = + { + SENSOR_RECORDER_DATA_STEPS, + SENSOR_RECORDER_DATA_WALK_STEPS, + SENSOR_RECORDER_DATA_RUN_STEPS, + SENSOR_RECORDER_DATA_DISTANCE, + SENSOR_RECORDER_DATA_CALORIE, + SENSOR_RECORDER_DATA_HEART_RATE, + SENSOR_RECORDER_DATA_SLEEP_STATE, + SENSOR_RECORDER_DATA_PRESSURE, + SENSOR_RECORDER_DATA_MAX_PRESSURE, + SENSOR_RECORDER_DATA_MIN_PRESSURE, + SENSOR_RECORDER_DATA_AVERAGE_PRESSURE, + }; + int nSensorRecorderTypeCount = sizeof(arrSensorRecorderData) / sizeof(arrSensorRecorderData[0]); + + g_bCallbackHit = true; + + if (error != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] SensorRecorderReadSyncCbGetDouble error = %d \\n", __LINE__, API_NAMESPACE,error); + } + + if (type == SENSOR_HUMAN_PEDOMETER) + { + for(nEnumCount = 0;nEnumCount < nSensorRecorderTypeCount;nEnumCount++ ) + { + val_double = -1.0; + g_nRet = sensor_recorder_data_get_double(data, arrSensorRecorderData[nEnumCount], &val_double); + if(g_nRet != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_double failed \\n", __LINE__, API_NAMESPACE); + return false; + } + if(val_double == -1.0) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_double failed as val_double is incorrect \\n", __LINE__, API_NAMESPACE); + g_bStatus = false; + return false; + } + } + } + if ( g_pSensorMainLoop ) + { + g_main_loop_quit(g_pSensorMainLoop); + g_main_loop_unref(g_pSensorMainLoop); + g_pSensorMainLoop = NULL; + } + + return true; +} + +/** +* @function SensorRecorderReadSyncCbGetTime +* @description Called during sensor recorder read sync. +* @parameter[IN] sensor_type_e +* @parameter[IN] sensor_recorder_data_h +* @parameter[IN] int +* @parameter[IN] sensor_error_e +* @parameter[IN] The user data passed from the callback registration function +* @return bool +*/ +static bool SensorRecorderReadSyncCbGetTime(sensor_type_e type, sensor_recorder_data_h data, int remains, sensor_error_e error, void *user_data) +{ + time_t start = time(NULL), end = time(NULL); + g_bCallbackHit = true; + if (error != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] SensorRecorderReadSyncCbGetTime error = %d \\n", __LINE__, API_NAMESPACE,error); + } + + if (data == NULL) + { + FPRINTF("[Line : %d][%s] SensorRecorderReadSyncCbGetTime input data is NULL = %d \\n", __LINE__, API_NAMESPACE,error); + g_bStatus = false; + return false; + } + + g_nRet = sensor_recorder_data_get_time(data, &start, &end); + if(g_nRet != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_time failed \\n", __LINE__, API_NAMESPACE); + return false; + } + if( (start == time(NULL)) || (end == time(NULL)) ) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_time failed as time is incorrect \\n", __LINE__, API_NAMESPACE); + g_bStatus = false; + return false; + } + if ( g_pSensorMainLoop ) + { + g_main_loop_quit(g_pSensorMainLoop); + g_main_loop_unref(g_pSensorMainLoop); + g_pSensorMainLoop = NULL; + } + + return true; +} + +/** +* @function SensorRecorderReadSyncCbGetInt +* @description Called during sensor recorder read sync. +* @parameter[IN] sensor_type_e +* @parameter[IN] sensor_recorder_data_h +* @parameter[IN] int +* @parameter[IN] sensor_error_e +* @parameter[IN] The user data passed from the callback registration function +* @return bool +*/ +static bool SensorRecorderReadSyncCbGetInt(sensor_type_e type, sensor_recorder_data_h data, int remains, sensor_error_e error, void *user_data) +{ + int val_int = -1; + int nEnumCount; + int arrSensorRecorderData[] = + { + SENSOR_RECORDER_DATA_STEPS, + SENSOR_RECORDER_DATA_WALK_STEPS, + SENSOR_RECORDER_DATA_RUN_STEPS, + SENSOR_RECORDER_DATA_DISTANCE, + SENSOR_RECORDER_DATA_CALORIE, + SENSOR_RECORDER_DATA_HEART_RATE, + SENSOR_RECORDER_DATA_SLEEP_STATE, + SENSOR_RECORDER_DATA_PRESSURE, + SENSOR_RECORDER_DATA_MAX_PRESSURE, + SENSOR_RECORDER_DATA_MIN_PRESSURE, + SENSOR_RECORDER_DATA_AVERAGE_PRESSURE, + }; + int nSensorRecorderTypeCount = sizeof(arrSensorRecorderData) / sizeof(arrSensorRecorderData[0]); + + g_bCallbackHit = true; + if (error != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] SensorRecorderReadSyncCbGetInt error = %d \\n", __LINE__, API_NAMESPACE,error); + } + + if (data == NULL) + { + FPRINTF("[Line : %d][%s] SensorRecorderReadSyncCbGetTime input data is NULL = %d \\n", __LINE__, API_NAMESPACE,error); + g_bStatus = false; + return false; + } + + if (type == SENSOR_HUMAN_PEDOMETER) + { + for(nEnumCount = 0;nEnumCount < nSensorRecorderTypeCount;nEnumCount++ ) + { + val_int = -1; + g_nRet = sensor_recorder_data_get_int(data, arrSensorRecorderData[nEnumCount], &val_int); + if(g_nRet != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_int failed \\n", __LINE__, API_NAMESPACE); + return false; + } + if(val_int == -1) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_double failed as val_int is incorrect \\n", __LINE__, API_NAMESPACE); + g_bStatus = false; + return false; + } + } + } + + if (type == SENSOR_HRM) + { + for(nEnumCount = 0;nEnumCount < nSensorRecorderTypeCount;nEnumCount++ ) + { + val_int = -1; + g_nRet = sensor_recorder_data_get_int(data, arrSensorRecorderData[nEnumCount], &val_int); + if(g_nRet != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_int failed \\n", __LINE__, API_NAMESPACE); + return false; + } + if(val_int == -1) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_double failed as val_int is incorrect \\n", __LINE__, API_NAMESPACE); + g_bStatus = false; + return false; + } + } + } + + if (type == SENSOR_HUMAN_SLEEP_MONITOR || type == SENSOR_HUMAN_SLEEP_DETECTOR) + { + for(nEnumCount = 0;nEnumCount < nSensorRecorderTypeCount;nEnumCount++ ) + { + val_int = -1; + g_nRet = sensor_recorder_data_get_int(data, arrSensorRecorderData[nEnumCount], &val_int); + if(g_nRet != SENSOR_ERROR_NONE) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_int failed \\n", __LINE__, API_NAMESPACE); + return false; + } + if(val_int == -1) + { + FPRINTF("[Line : %d][%s] sensor_recorder_data_get_double failed as val_int is incorrect \\n", __LINE__, API_NAMESPACE); + g_bStatus = false; + return false; + } + } + } + + if ( g_pSensorMainLoop ) + { + g_main_loop_quit(g_pSensorMainLoop); + g_main_loop_unref(g_pSensorMainLoop); + g_pSensorMainLoop = NULL; + } + + return true; +} + + +/** +* @function ITs_sensor_recorder_startup +* @description Called before each test, creates Sensors +* @parameter NA +* @return NA +*/ +void ITs_sensor_recorder_startup(void) +{ + g_bSensorSkipExecutionWithFail = false; + struct stat stBuff; + if ( stat(ERR_LOG, &stBuff) == 0 ) + { + remove(ERR_LOG); + } + + int i; + int enum_size = sizeof(Sensor) / sizeof(Sensor[0]); + + for ( i=0; i