sensor-hal: re-organize build procedure
[platform/adaptation/tm1/sensor-hal-tm1.git] / src / sensor_common.h
1 /*
2  * libsensord-share
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef __SENSOR_COMMON_H__
21 #define __SENSOR_COMMON_H__
22
23 #include <unistd.h>
24 #include <sensor_logs.h>
25 #include <string>
26 #include <vector>
27
28 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
29
30 #ifndef DEPRECATED
31 #define DEPRECATED __attribute__((deprecated))
32 #endif
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
39 /**
40  * @defgroup SENSOR_FRAMEWORK SensorFW
41  * To support the unified API for the various sensors
42  */
43
44 /**
45  * @defgroup SENSOR_FRAMEWORK_COMMON Sensor Framework Common API
46  * @ingroup SENSOR_FRAMEWORK
47  *
48  * These APIs are used to control the sensors.
49  * @{
50  */
51
52 typedef enum {
53         ALL_SENSOR = -1,
54         UNKNOWN_SENSOR = 0,
55         ACCELEROMETER_SENSOR,
56         GEOMAGNETIC_SENSOR,
57         LIGHT_SENSOR,
58         PROXIMITY_SENSOR,
59         THERMOMETER_SENSOR,
60         GYROSCOPE_SENSOR,
61         PRESSURE_SENSOR,
62         MOTION_SENSOR,
63         FUSION_SENSOR,
64         PEDOMETER_SENSOR,
65         CONTEXT_SENSOR,
66         FLAT_SENSOR,
67         BIO_SENSOR,
68         BIO_HRM_SENSOR,
69         AUTO_ROTATION_SENSOR,
70         GRAVITY_SENSOR,
71         LINEAR_ACCEL_SENSOR,
72         ROTATION_VECTOR_SENSOR,
73         GEOMAGNETIC_RV_SENSOR,
74         GAMING_RV_SENSOR,
75         ORIENTATION_SENSOR,
76         TILT_SENSOR,
77         PIR_SENSOR,
78         PIR_LONG_SENSOR,
79         TEMPERATURE_SENSOR,
80         HUMIDITY_SENSOR,
81         ULTRAVIOLET_SENSOR,
82         DUST_SENSOR,
83         BIO_LED_GREEN_SENSOR,
84         BIO_LED_IR_SENSOR,
85         BIO_LED_RED_SENSOR,
86         RV_RAW_SENSOR,
87         UNCAL_GYROSCOPE_SENSOR,
88         UNCAL_GEOMAGNETIC_SENSOR
89 } sensor_type_t;
90
91 typedef unsigned int sensor_id_t;
92
93 typedef void *sensor_t;
94
95 typedef enum {
96         SENSOR_PRIVILEGE_PUBLIC,
97         SENSOR_PRIVILEGE_INTERNAL,
98 } sensor_privilege_t;
99
100 #define SENSOR_DATA_VALUE_SIZE 16
101
102 /*
103  *      When modifying it, check copy_sensor_data()
104  */
105 typedef struct sensor_data_t {
106 /*
107  *      Use "accuracy" instead of "data_accuracy"
108  *      which is going to be removed soon
109  */
110         union {
111                 int accuracy;
112                 int data_accuracy; //deprecated
113         };
114
115         union {
116                 unsigned long long timestamp;
117                 unsigned long long time_stamp; //deprecated
118         };
119
120 /*
121  *      Use "value_count" instead of "values_num"
122  *      which is going to be removed soon
123  */
124         union {
125                 int value_count;
126                 int values_num; //deprecated
127         };
128
129         float values[SENSOR_DATA_VALUE_SIZE];
130
131 /*
132  *      If extra_data_size > 0,
133  *      then use extra_data.
134  */
135         int extra_data_size;
136         void *extra_data;
137 } sensor_data_t;
138
139 #define SENSOR_HUB_DATA_SIZE    4096
140
141 typedef struct sensorhub_data_t {
142     int version;
143     int sensorhub;
144     int type;
145     int hub_data_size;
146     unsigned long long timestamp;
147     char hub_data[SENSOR_HUB_DATA_SIZE];
148     float data[16];
149 } sensorhub_data_t;
150
151 enum sensor_accuracy_t {
152         SENSOR_ACCURACY_UNDEFINED = -1,
153         SENSOR_ACCURACY_BAD = 0,
154         SENSOR_ACCURACY_NORMAL =1,
155         SENSOR_ACCURACY_GOOD = 2,
156         SENSOR_ACCURACY_VERYGOOD = 3
157 };
158
159 /*
160  *      To prevent naming confliction as using same enums as sensor CAPI use
161  */
162 #ifndef __SENSOR_H__
163 enum sensor_option_t {
164         SENSOR_OPTION_DEFAULT = 0,
165         SENSOR_OPTION_ON_IN_SCREEN_OFF = 1,
166         SENSOR_OPTION_ON_IN_POWERSAVE_MODE = 2,
167         SENSOR_OPTION_ALWAYS_ON = SENSOR_OPTION_ON_IN_SCREEN_OFF | SENSOR_OPTION_ON_IN_POWERSAVE_MODE,
168         SENSOR_OPTION_END
169 };
170
171 typedef enum sensor_option_t sensor_option_e;
172 #endif
173
174 /*
175  *      To prevent naming confliction as using same enums as sensor CAPI use
176  */
177 #ifndef __SENSOR_H__
178 enum sensor_wakeup_t {
179         SENSOR_WAKEUP_UNKNOWN = -1,
180         SENSOR_WAKEUP_OFF = 0,
181         SENSOR_WAKEUP_ON = 1,
182 };
183
184 typedef enum sensor_wakeup_t sensor_wakeup_e;
185 #endif
186
187 enum sensor_interval_t {
188         SENSOR_INTERVAL_FASTEST = 0,
189         SENSOR_INTERVAL_NORMAL = 200,
190 };
191
192 typedef enum {
193         CONDITION_NO_OP,
194         CONDITION_EQUAL,
195         CONDITION_GREAT_THAN,
196         CONDITION_LESS_THAN,
197 } condition_op_t;
198
199 #define COMMAND_CHANNEL_PATH                    "/tmp/sensord_command_socket"
200 #define EVENT_CHANNEL_PATH                              "/tmp/sensord_event_socket"
201
202 #define MAX_HANDLE                      256
203 #define MAX_HANDLE_REACHED      -2
204
205 #define CLIENT_ID_INVALID   -1
206
207 #define SENSOR_TYPE_MASK  0xFFFF
208
209 enum packet_type_t {
210         CMD_NONE = 0,
211         CMD_GET_ID,
212         CMD_GET_SENSOR_LIST,
213         CMD_HELLO,
214         CMD_BYEBYE,
215         CMD_DONE,
216         CMD_START,
217         CMD_STOP,
218         CMD_REG,
219         CMD_UNREG,
220         CMD_SET_OPTION,
221         CMD_SET_WAKEUP,
222         CMD_SET_BATCH,
223         CMD_UNSET_BATCH,
224         CMD_SET_COMMAND,
225         CMD_GET_DATA,
226         CMD_SEND_SENSORHUB_DATA,
227         CMD_CNT,
228 };
229
230 enum sensor_state_t {
231         SENSOR_STATE_UNKNOWN = -1,
232         SENSOR_STATE_STOPPED = 0,
233         SENSOR_STATE_STARTED = 1,
234         SENSOR_STATE_PAUSED = 2
235 };
236
237 enum poll_interval_t {
238         POLL_100HZ_MS   = 10,
239         POLL_50HZ_MS    = 20,
240         POLL_25HZ_MS    = 40,
241         POLL_20HZ_MS    = 50,
242         POLL_10HZ_MS    = 100,
243         POLL_5HZ_MS             = 200,
244         POLL_1HZ_MS             = 1000,
245         POLL_MAX_HZ_MS  = POLL_1HZ_MS,
246 };
247
248 typedef struct {
249         char name[NAME_MAX];
250 } cmd_get_id_t;
251
252 typedef struct {
253 } cmd_get_sensor_list_t;
254
255 typedef struct {
256         int client_id;
257         int sensor;
258 } cmd_hello_t;
259
260 typedef struct {
261 } cmd_byebye_t;
262
263
264 typedef struct {
265         unsigned int type;
266 } cmd_get_data_t;
267
268 typedef struct {
269         long value;
270 } cmd_done_t;
271
272
273 typedef struct {
274         int client_id;
275 } cmd_get_id_done_t;
276
277 typedef struct {
278         int sensor_cnt;
279         char data[0];
280 } cmd_get_sensor_list_done_t;
281
282 typedef struct {
283         int state;
284         sensor_data_t base_data;
285 } cmd_get_data_done_t;
286
287 typedef struct {
288 } cmd_start_t;
289
290 typedef struct {
291 } cmd_stop_t;
292
293 typedef struct {
294         unsigned int event_type;
295 } cmd_reg_t;
296
297 typedef struct {
298         unsigned int event_type;
299 } cmd_unreg_t;
300
301 typedef struct {
302         unsigned int interval;
303         unsigned int latency;
304 } cmd_set_batch_t;
305
306 typedef struct {
307 } cmd_unset_batch_t;
308
309 typedef struct {
310         int option;
311 } cmd_set_option_t;
312
313 typedef struct {
314         int wakeup;
315 } cmd_set_wakeup_t;
316
317 typedef struct  {
318         unsigned int cmd;
319         long value;
320 } cmd_set_command_t;
321
322 typedef struct  {
323         int data_len;
324         char data[0];
325 } cmd_send_sensorhub_data_t;
326
327 #define EVENT_CHANNEL_MAGIC 0xCAFECAFE
328
329 typedef struct {
330         unsigned int magic;
331         int client_id;
332 } event_channel_ready_t;
333
334 typedef struct {
335         std::string name;
336         std::string vendor;
337         float min_range;
338         float max_range;
339         float resolution;
340         int min_interval;
341         int fifo_count;
342         int max_batch_count;
343         bool wakeup_supported;
344 } sensor_properties_s;
345
346 /*
347  * When modifying it, check copy_sensor*_data()
348  */
349 typedef struct sensor_event_t {
350         unsigned int event_type;
351         sensor_id_t sensor_id;
352         sensor_data_t data;
353 } sensor_event_t;
354
355 typedef struct sensorhub_event_t {
356         unsigned int event_type;
357         sensor_id_t sensor_id;
358         sensorhub_data_t data;
359 } sensorhub_event_t;
360
361 typedef struct {
362         std::vector<void*> devices;
363 } sensor_devices;
364
365 typedef sensor_devices* (*create_t)(void);
366
367 typedef void *(*cmd_func_t)(void *data, void *cb_data);
368
369 typedef std::vector<unsigned int> event_type_vector;
370
371 enum sensorhub_enable_bit {
372         SENSORHUB_ACCELEROMETER_ENABLE_BIT = 0,
373         SENSORHUB_GYROSCOPE_ENABLE_BIT,
374         SENSORHUB_GEOMAGNETIC_UNCALIB_ENABLE_BIT,
375         SENSORHUB_GEOMAGNETIC_RAW_ENABLE_BIT,
376         SENSORHUB_GEOMAGNETIC_ENABLE_BIT,
377         SENSORHUB_PRESSURE_ENABLE_BIT,
378         SENSORHUB_GESTURE_ENABLE_BIT,
379         SENSORHUB_PROXIMITY_ENABLE_BIT,
380         SENSORHUB_TEMPERATURE_HUMIDITY_ENABLE_BIT,
381         SENSORHUB_LIGHT_ENABLE_BIT,
382         SENSORHUB_PROXIMITY_RAW_ENABLE_BIT,
383         SENSORHUB_ORIENTATION_ENABLE_BIT,
384         SENSORHUB_STEP_DETECTOR_ENABLE_BIT = 12,
385         SENSORHUB_SIG_MOTION_ENABLE_BIT,
386         SENSORHUB_GYRO_UNCALIB_ENABLE_BIT,
387         SENSORHUB_GAME_ROTATION_VECTOR_ENABLE_BIT = 15,
388         SENSORHUB_ROTATION_VECTOR_ENABLE_BIT,
389         SENSORHUB_STEP_COUNTER_ENABLE_BIT,
390         SENSORHUB_BIO_HRM_RAW_ENABLE_BIT,
391         SENSORHUB_BIO_HRM_RAW_FAC_ENABLE_BIT,
392         SENSORHUB_BIO_HRM_LIB_ENABLE_BIT,
393         SENSORHUB_TILT_MOTION,
394         SENSORHUB_UV_SENSOR,
395         SENSORHUB_PIR_ENABLE_BIT,
396         SENSORHUB_ENABLE_BIT_MAX,
397 };
398
399 enum sensor_permission_t {
400         SENSOR_PERMISSION_NONE  = 0,
401         SENSOR_PERMISSION_STANDARD = (1 << 0),
402         SENSOR_PERMISSION_BIO   =  (1 << 1),
403 };
404
405 #define BIO_SENSOR_PRIVELEGE_NAME "sensord::bio"
406 #define BIO_SENSOR_ACCESS_RIGHT "rw"
407
408 #ifdef __cplusplus
409 }
410 #endif
411
412 #endif
413 //! End of a file