Amit Arora | 39f2954 | 2010-09-14 12:03:22 +0530 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 17 | #include "powerdebug.h" |
| 18 | #include "sensor.h" |
| 19 | |
| 20 | char *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 | |
| 35 | void 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 Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 81 | filep = fopen(filename, "r"); |
| 82 | |
| 83 | if(!filep) |
| 84 | goto exit; |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 85 | ret = fscanf(filep, "%s", result); |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 86 | fclose(filep); |
Amit Arora | 97006e5 | 2010-10-28 11:56:08 +0530 | [diff] [blame] | 87 | |
Amit Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 88 | 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 Arora | e9e16b0 | 2010-08-03 10:15:20 +0530 | [diff] [blame] | 98 | exit: |
| 99 | free(num); |
| 100 | return; |
| 101 | } |