sensord: add sensorctl instead of original sensor-test
[platform/core/system/sensord.git] / src / sensorctl / info_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 <stdio.h>
21 #include <stdlib.h>
22 #include <glib.h>
23 #include <sensor_internal.h>
24 #include <sensorctl_log.h>
25 #include "info_manager.h"
26
27 bool info_manager::process(int argc, char *argv[])
28 {
29         sensor_type_t type;
30
31         if (argc == 2) {
32                 usage();
33                 return false;
34         }
35
36         type = get_sensor_type(argv[2]);
37         if (type == UNKNOWN_SENSOR)
38                 return false;
39
40         sensor_t *sensors;
41         int count;
42
43         sensord_get_sensor_list(type, &sensors, &count);
44         sensor_info(sensors, count);
45
46         free(sensors);
47         return true;
48 }
49
50 void info_manager::sensor_info(sensor_t *sensors, int count)
51 {
52         sensor_t sensor;
53         char *vendor;
54         char *name;
55         float min_range;
56         float max_range;
57         float resolution;
58         int min_interval;
59         int fifo_count;
60         int max_batch_count;
61
62         for (int i = 0; i < count; ++i) {
63                 sensor = sensors[i];
64
65                 name = const_cast<char *>(sensord_get_name(sensor));
66                 vendor = const_cast<char *>(sensord_get_vendor(sensor));
67                 sensord_get_max_range(sensor, &max_range);
68                 sensord_get_min_range(sensor, &min_range);
69                 sensord_get_resolution(sensor, &resolution);
70                 sensord_get_min_interval(sensor, &min_interval);
71                 sensord_get_fifo_count(sensor, &fifo_count);
72                 sensord_get_max_batch_count(sensor, &max_batch_count);
73
74                 PRINT("-------sensor[%d] information-------\n", i);
75                 PRINT("vendor : %s\n", vendor);
76                 PRINT("name : %s\n", name);
77                 PRINT("min_range : %f\n", min_range);
78                 PRINT("max_range : %f\n", max_range);
79                 PRINT("resolution : %f\n", resolution);
80                 PRINT("min_interval : %d\n", min_interval);
81                 PRINT("fifo_count : %d\n", fifo_count);
82                 PRINT("max_batch_count : %d\n", max_batch_count);
83                 PRINT("--------------------------------\n");
84         }
85 }
86
87 void info_manager::usage(void)
88 {
89         PRINT("usage: sensorctl info <sensor_type>\n");
90         PRINT("\n");
91
92         usage_sensors();
93 }
94