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