blob: abc99d4fd25a3737e2b738ca26236e3de7ca31dd [file] [log] [blame]
Amit Arora39f29542010-09-14 12:03:22 +05301/*******************************************************************************
2 * Copyright (C) 2010, Linaro
3 * Copyright (C) 2010, IBM Corporation
4 *
5 * This file is part of PowerDebug.
6 *
7 * All rights reserved. This program and the accompanying materials
8 * are made available under the terms of the Eclipse Public License v1.0
9 * which accompanies this distribution, and is available at
10 * http://www.eclipse.org/legal/epl-v10.html
11 *
12 * Contributors:
13 * Amit Arora <amit.arora@linaro.org> (IBM Corporation)
14 * - initial API and implementation
15 *******************************************************************************/
16
Amit Arorae9e16b02010-08-03 10:15:20 +053017#include "powerdebug.h"
18#include "sensor.h"
19
20char *get_num(char *fname, char *sensor)
21{
22 char tmpstr[NAME_MAX];
23 char *str;
24
25 strcpy(tmpstr, (fname+strlen(sensor)));
26
27 str = strrchr(tmpstr, '_');
28 str[0] = '\0';
29
30 str = strdup(tmpstr);
31 return str;
32}
33
34
35void get_sensor_info(char *path, char *fname, char *sensor, int verbose)
36{
37 FILE *filep;
38 char filename[PATH_MAX];
39 char **items = NULL, **suffix = NULL;
40 char *item, result[NAME_MAX], *num;
41 int ret, count = 0;
42
43 (void)verbose; // get rid of warning
44
45 sprintf(filename, "%s/%s", path, fname);
46
47 if(!strcmp(sensor, "in")) {
48 items = (char **)items_in;
49 suffix = (char **)suffix_in;
50 }
51
52 if(!strcmp(sensor, "temp")) {
53 items = (char **)items_temp;
54 suffix = (char **)suffix_temp;
55 }
56
57 if(!strcmp(sensor, "fan")) {
58 items = (char **)items_fan;
59 suffix = (char **)suffix_fan;
60 }
61 if(!strcmp(sensor, "pwm")) {
62 items = (char **)items_pwm;
63 suffix = (char **)suffix_pwm;
64 }
65
66
67 if (!items || !suffix)
68 return;
69
70 item = strrchr(fname, '_');
71 if(!item)
72 return;
73
74 if(item)
75 item++;
76
77 if(item > (fname + strlen(fname)))
78 return;
79
80 num = get_num(fname, sensor);
Amit Arorae9e16b02010-08-03 10:15:20 +053081 filep = fopen(filename, "r");
82
83 if(!filep)
84 goto exit;
Amit Arorae9e16b02010-08-03 10:15:20 +053085 ret = fscanf(filep, "%s", result);
Amit Arorae9e16b02010-08-03 10:15:20 +053086 fclose(filep);
Amit Arora97006e52010-10-28 11:56:08 +053087
Amit Arorae9e16b02010-08-03 10:15:20 +053088 if(ret != 1)
89 goto exit;
90
91 while(strcmp(items[count], "")) {
92 if(!strcmp(items[count], item))
93 printf("\'temp\' %s sensor %s\t\t%d%s\n",
94 num, items[count], atoi(result)/1000,
95 suffix[count]);
96 count++;
97 }
Amit Arorae9e16b02010-08-03 10:15:20 +053098exit:
99 free(num);
100 return;
101}