From: kibak.yoon Date: Tue, 2 Feb 2016 02:27:17 +0000 (+0900) Subject: sensord: [1/4] add the refactored HAL interface X-Git-Tag: accepted/tizen/mobile/20160216.102843~1^2~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1eb9c45606154ad2a07c47897067e9fc8b3a180e;p=platform%2Fcore%2Fsystem%2Fsensord.git sensord: [1/4] add the refactored HAL interface * WARNING: if this patch is applied only, it cannot be built. please apply the series of the patches Change-Id: I3095e9c7b387a0e00cddf5b4086fb18331584231 Signed-off-by: kibak.yoon --- diff --git a/packaging/sensord.spec b/packaging/sensord.spec index cd22230..ab768f0 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -21,7 +21,7 @@ BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) Requires: libsensord = %{version}-%{release} -%define auto_rotation_state ON +%define auto_rotation_state OFF %define orientation_state OFF %define gravity_state OFF %define linear_accel_state OFF @@ -30,7 +30,7 @@ Requires: libsensord = %{version}-%{release} %define gaming_rv_state OFF %define tilt_state OFF %define gyroscope_uncal_state OFF -%define build_test_suite ON +%define build_test_suite OFF %description Sensor daemon diff --git a/src/shared/sensor_common.h b/src/shared/sensor_common.h index 53c7e26..ac3450f 100644 --- a/src/shared/sensor_common.h +++ b/src/shared/sensor_common.h @@ -20,6 +20,10 @@ #ifndef __SENSOR_COMMON_H__ #define __SENSOR_COMMON_H__ +#include +#include +#include + #ifndef DEPRECATED #define DEPRECATED __attribute__((deprecated)) #endif @@ -29,20 +33,17 @@ extern "C" { #endif -/** - * @defgroup SENSOR_FRAMEWORK SensorFW - * To support the unified API for the various sensors - */ - -/** - * @defgroup SENSOR_FRAMEWORK_COMMON Sensor Framework Common API - * @ingroup SENSOR_FRAMEWORK - * - * These APIs are used to control the sensors. - * @{ - */ - -typedef unsigned int sensor_id_t; +/* +typedef union { + struct { + sensor_type_t type; + int16_t sensor_id; + int16_t device_id; + } __attribute__((packed)); + int64_t id; +} sensor_id_t; +*/ +typedef int64_t sensor_id_t; typedef void *sensor_t; @@ -51,39 +52,6 @@ typedef enum { SENSOR_PRIVILEGE_INTERNAL, } sensor_privilege_t; - -#define SENSOR_DATA_VALUE_SIZE 16 - -/* - * When modifying it, check copy_sensor_data() - */ -typedef struct sensor_data_t { -/* - * Use "accuracy" instead of "data_accuracy" - * which is going to be removed soon - */ - union { - int accuracy; - int data_accuracy; //deprecated - }; - - union { - unsigned long long timestamp; - unsigned long long time_stamp; //deprecated - }; - -/* - * Use "value_count" instead of "values_num" - * which is going to be removed soon - */ - union { - int value_count; - int values_num; //deprecated - }; - - float values[SENSOR_DATA_VALUE_SIZE]; -} sensor_data_t; - #define SENSOR_HUB_DATA_SIZE 4096 typedef struct sensorhub_data_t { @@ -96,14 +64,6 @@ typedef struct sensorhub_data_t { float data[16]; } sensorhub_data_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 -}; - /* * To prevent naming confliction as using same enums as sensor CAPI use */ @@ -137,7 +97,6 @@ enum sensor_interval_t { SENSOR_INTERVAL_NORMAL = 200, }; - typedef enum { CONDITION_NO_OP, CONDITION_EQUAL, diff --git a/src/shared/sensor_hal.h b/src/shared/sensor_hal.h index b9f38c6..46fd840 100644 --- a/src/shared/sensor_hal.h +++ b/src/shared/sensor_hal.h @@ -21,14 +21,20 @@ #define _SENSOR_HAL_H_ #include + +#ifdef __cplusplus #include #include -#include -#include +#endif /* __cplusplus */ #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 @@ -98,21 +104,61 @@ typedef enum { SENSOR_DEVICE_ROTATION_VECTOR_RAW, } sensor_device_type; +typedef struct sensor_info_t { + 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; + /* * A platform sensor handler is generated based on this handle * ID can be assigned from HAL developer. so it has to be unique in HAL. */ typedef struct sensor_handle_t { - uint32_t id; - std::string name; + uint16_t id; + const char *name; sensor_device_type type; unsigned int event_type; // for Internal API - sensor_properties_s properties; + sensor_info_t info; } sensor_handle_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; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#ifdef __cplusplus +typedef struct { + std::vector devices; +} sensor_devices; + +typedef sensor_devices* (*create_t)(void); + /* * Sensor device interface - * 1 HAL must be abstracted from 1 device event node + * 1 device must be abstracted from 1 device event node */ class sensor_device { @@ -127,23 +173,18 @@ public: virtual int get_poll_fd(void) = 0; virtual bool get_sensors(std::vector &sensors) = 0; - /* enable/disable sensor device */ - virtual bool enable(uint32_t id) = 0; - virtual bool disable(uint32_t id) = 0; - - /* set_command or set_option? */ - virtual bool set_command(uint32_t id, std::string command, std::string value) = 0; + virtual bool enable(uint16_t id) = 0; + virtual bool disable(uint16_t id) = 0; - /* the belows can be merged to one */ - virtual bool set_interval(uint32_t id, unsigned long val) = 0; - virtual bool set_batch_latency(uint32_t id, unsigned long val) = 0; + virtual bool set_interval(uint16_t id, unsigned long val) = 0; + virtual bool set_batch_latency(uint16_t id, unsigned long val) = 0; + virtual bool set_attribute(uint16_t id, int32_t attribute, int32_t value) = 0; - /* sensor fw read the data when is_data_ready() is true */ - virtual bool is_data_ready() = 0; - virtual bool get_sensor_data(uint32_t id, sensor_data_t &data) = 0; - virtual int get_sensor_event(uint32_t id, sensor_event_t **event) = 0; + virtual bool read_fd(std::vector &ids) = 0; + virtual int get_data(uint16_t id, sensor_data_t **data) = 0; - /* TODO: use get_sensors() instead of get_properties() */ - virtual bool get_properties(uint32_t id, sensor_properties_s &properties) = 0; + virtual bool flush(uint16_t id) = 0; }; +#endif /* __cplusplus */ + #endif /* _SENSOR_HAL_H_ */ diff --git a/src/shared/sf_common.h b/src/shared/sf_common.h index 2781348..7bcc35f 100644 --- a/src/shared/sf_common.h +++ b/src/shared/sf_common.h @@ -34,8 +34,6 @@ #define CLIENT_ID_INVALID -1 -#define SENSOR_TYPE_MASK 0xFFFF - enum packet_type_t { CMD_NONE = 0, CMD_GET_ID, @@ -84,7 +82,7 @@ typedef struct { typedef struct { int client_id; - int sensor; + sensor_id_t sensor; } cmd_hello_t; typedef struct { @@ -151,7 +149,7 @@ typedef struct { typedef struct { int data_len; - char data[0]; + int data; } cmd_send_sensorhub_data_t; #define EVENT_CHANNEL_MAGIC 0xCAFECAFE @@ -161,74 +159,24 @@ typedef struct { int client_id; } event_channel_ready_t; - -typedef struct { - std::string name; - std::string vendor; - float min_range; - float max_range; - float resolution; - int min_interval; - int fifo_count; - int max_batch_count; - bool wakeup_supported; -} sensor_properties_s; - - -/* - * When modifying it, check copy_sensor*_data() - */ typedef struct sensor_event_t { unsigned int event_type; sensor_id_t sensor_id; - sensor_data_t data; + unsigned int data_length; + sensor_data_t *data; } sensor_event_t; - typedef struct sensorhub_event_t { unsigned int event_type; sensor_id_t sensor_id; + unsigned int data_length; sensorhub_data_t data; } sensorhub_event_t; -typedef struct sensor_devices { - std::vector devices; -} sensor_devices; - -typedef sensor_devices* (*create_t)(void); - typedef void *(*cmd_func_t)(void *data, void *cb_data); typedef std::vector event_type_vector; -enum sensorhub_enable_bit { - SENSORHUB_ACCELEROMETER_ENABLE_BIT = 0, - SENSORHUB_GYROSCOPE_ENABLE_BIT, - SENSORHUB_GEOMAGNETIC_UNCALIB_ENABLE_BIT, - SENSORHUB_GEOMAGNETIC_RAW_ENABLE_BIT, - SENSORHUB_GEOMAGNETIC_ENABLE_BIT, - SENSORHUB_PRESSURE_ENABLE_BIT, - SENSORHUB_GESTURE_ENABLE_BIT, - SENSORHUB_PROXIMITY_ENABLE_BIT, - SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT, - SENSORHUB_LIGHT_ENABLE_BIT, - SENSORHUB_PROXIMITY_RAW_ENABLE_BIT, - SENSORHUB_ORIENTATION_ENABLE_BIT, - SENSORHUB_STEP_DETECTOR_ENABLE_BIT = 12, - SENSORHUB_SIG_MOTION_ENABLE_BIT, - SENSORHUB_GYRO_UNCALIB_ENABLE_BIT, - SENSORHUB_GAME_ROTATION_VECTOR_ENABLE_BIT = 15, - SENSORHUB_ROTATION_VECTOR_ENABLE_BIT, - SENSORHUB_STEP_COUNTER_ENABLE_BIT, - SENSORHUB_BIO_HRM_RAW_ENABLE_BIT, - SENSORHUB_BIO_HRM_RAW_FAC_ENABLE_BIT, - SENSORHUB_BIO_HRM_LIB_ENABLE_BIT, - SENSORHUB_TILT_MOTION, - SENSORHUB_UV_SENSOR, - SENSORHUB_PIR_ENABLE_BIT, - SENSORHUB_ENABLE_BIT_MAX, -}; - enum sensor_permission_t { SENSOR_PERMISSION_NONE = 0, SENSOR_PERMISSION_STANDARD = (1 << 0),