sensorctl test
[platform/core/system/sensord.git] / src / sensorctl / sensor_manager.cpp
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2015 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 #include <string.h>
21 #include <stdlib.h>
22 #include <macro.h>
23 #include <sensorctl_log.h>
24 #include "sensor_manager.h"
25
26 #define NAME_MAX_TEST 32
27
28 struct sensor_info {
29         sensor_type_t type;
30         char name[NAME_MAX_TEST];
31         /* if manual is true, the way of injecting fake event will be created */
32         bool manual;
33 };
34
35 static struct sensor_info sensor_infos[] = {
36         {ALL_SENSOR,                            "all",                          false},
37
38         // General Sensors
39         {ACCELEROMETER_SENSOR,          "accelerometer",        false},
40         {GRAVITY_SENSOR,                        "gravity",                      false},
41         {LINEAR_ACCEL_SENSOR,           "linear_accel",         false},
42         {GEOMAGNETIC_SENSOR,            "magnetic",                     false},
43         {ROTATION_VECTOR_SENSOR,        "rotation_vector",      false},
44         {ORIENTATION_SENSOR,            "orientation",          false},
45         {GYROSCOPE_SENSOR,                      "gyroscope",            false},
46         {LIGHT_SENSOR,                          "light",                        false},
47         {PROXIMITY_SENSOR,                      "proximity",            true},
48         {PRESSURE_SENSOR,                       "pressure",                     false},
49         {ULTRAVIOLET_SENSOR,            "ultraviolet",          false},
50         {TEMPERATURE_SENSOR,            "temperature",          false},
51         {HUMIDITY_SENSOR,                       "humidity",                     false},
52         {HRM_RAW_SENSOR,                        "hrm_raw",                      false},
53         {HRM_SENSOR,                            "hrm",                          false},
54         {HRM_LED_GREEN_SENSOR,          "hrm_led_green",        false},
55         {HRM_LED_IR_SENSOR,                     "hrm_led_ir",           false},
56         {HRM_LED_RED_SENSOR,            "hrm_led_red",          false},
57         {GYROSCOPE_UNCAL_SENSOR,        "gyro_uncal",           false},
58         {GEOMAGNETIC_UNCAL_SENSOR,      "mag_uncal",            false},
59         {GYROSCOPE_RV_SENSOR,           "gyro_rv",                      false},
60         {GEOMAGNETIC_RV_SENSOR,         "mag_rv",                       false},
61
62         {HUMAN_PEDOMETER_SENSOR,        "pedo",                         true},
63         {HUMAN_SLEEP_MONITOR_SENSOR,"sleep_monitor",    true},
64
65         /*
66         {AUTO_ROTATION_SENSOR,          "auto_rotation",        true},
67         {AUTO_BRIGHTNESS_SENSOR,        "auto_brightness",      true},
68         {MOTION_SENSOR,                         "motion",                       true},
69         {PIR_SENSOR,                            "pir",                          true},
70         {PIR_LONG_SENSOR,                       "pir_long",                     true},
71         {DUST_SENSOR,                           "dust",                         false},
72         {THERMOMETER_SENSOR,            "thermometer",          false},
73         {FLAT_SENSOR,                           "flat",                         true},
74         {TILT_SENSOR,                           "tilt",                         false},
75         {RV_RAW_SENSOR,                         "rv_raw",                       false},
76         {EXERCISE_SENSOR,                       "exercise",                     false},
77         {GSR_SENSOR,                            "gsr",                          false},
78         {SIMSENSE_SENSOR,                       "simsense",                     false},
79         {PPG_SENSOR,                            "ppg",                          false},
80
81         {GESTURE_MOVEMENT_SENSOR,       "movement",                     true},
82         {GESTURE_WRIST_UP_SENSOR,       "wristup",                      true},
83         {GESTURE_WRIST_DOWN_SENSOR,     "wristdown",            true},
84         {GESTURE_MOVEMENT_STATE_SENSOR, "movement_state",true},
85
86         {WEAR_STATUS_SENSOR,            "wear_status",          true},
87         {WEAR_ON_MONITOR_SENSOR,        "wear_on",                      true},
88         {GPS_BATCH_SENSOR,                      "gps_batch",            true},
89         {ACTIVITY_TRACKER_SENSOR,       "activity_tracker",     true},
90         {SLEEP_DETECTOR_SENSOR,         "sleep_detector",       true},
91         {NO_MOVE_DETECTOR_SENSOR,       "no_move",                      true},
92         {HRM_CTRL_SENSOR,                       "hrm_ctrl",                     true},
93         {EXERCISE_COACH_SENSOR,         "ex_coach",                     true},
94         {EXERCISE_HR_SENSOR,            "ex_hr",                        true},
95         {RESTING_HR_SENSOR,                     "resting_hr",           true},
96         {STEP_LEVEL_MONITOR_SENSOR,     "step_level",           true},
97         {ACTIVITY_LEVEL_MONITOR_SENSOR, "activity",             true},
98         {CYCLE_MONITOR_SENSOR,          "cycle",                        true},
99         {STRESS_MONITOR_SENSOR,         "stress",                       true},
100         {AUTOSESSION_EXERCISE_SENSOR,"autosesstion",    true},
101         {STAIR_TRACKER_SENSOR,          "stair_tracker",        true}
102         */
103
104 };
105
106 bool sensor_manager::process(int argc, char *argv[])
107 {
108         return false;
109 }
110
111 void sensor_manager::usage_sensors(void)
112 {
113         PRINT("The sensor types are:\n");
114         int sensor_count = ARRAY_SIZE(sensor_infos);
115
116         for (int i = 0; i < sensor_count; ++i)
117                 PRINT("  %d: %s(%d)\n", i, sensor_infos[i].name, sensor_infos[i].type);
118         PRINT("\n");
119 }
120
121 sensor_type_t sensor_manager::get_sensor_type(char *name)
122 {
123         int index;
124         int sensor_count = ARRAY_SIZE(sensor_infos);
125
126         if (is_number(name))
127                 return (sensor_type_t) (atoi(name));
128
129         for (index = 0; index < sensor_count; ++index) {
130                 if (!strcmp(sensor_infos[index].name, name))
131                         break;
132         }
133
134         if (index == sensor_count) {
135                 _E("ERROR: sensor name is wrong\n");
136                 usage_sensors();
137                 return UNKNOWN_SENSOR;
138         }
139         return sensor_infos[index].type;
140 }
141
142 const char *sensor_manager::get_sensor_name(sensor_type_t type)
143 {
144         int index;
145         int sensor_count = ARRAY_SIZE(sensor_infos);
146
147         for (index = 0; index < sensor_count; ++index) {
148                 if (sensor_infos[index].type == type)
149                         break;
150         }
151
152         if (index == sensor_count) {
153                 _E("ERROR: sensor name is wrong\n");
154                 usage_sensors();
155                 return "UNKNOWN SENSOR";
156         }
157         return sensor_infos[index].name;
158 }
159
160 bool sensor_manager::is_number(char *value)
161 {
162         if (value == NULL || *value == 0)
163                 return false;
164
165         while (*value) {
166                 if (*value < '0' || *value > '9')
167                         return false;
168                 value++;
169         }
170
171         return true;
172 }