Debian Codegraph @

src/osmo-bts-lc15/misc/lc15bts_temp.c

raw symbols SCIP
1 /* Copyright (C) 2015 by Yves Godin <[email protected]>
2 *
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20 #include <stdint.h>
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <limits.h>
27
28 #include <osmocom/core/utils.h>
29
30 #include "lc15bts_temp.h"
31
32 static const char *temp_devs[_NUM_TEMP_SENSORS] = {
33 [LC15BTS_TEMP_SUPPLY] = "/var/lc15/temp/main-supply/temp",
34 [LC15BTS_TEMP_SOC] = "/var/lc15/temp/cpu/temp",
35 [LC15BTS_TEMP_FPGA] = "/var/lc15/temp/fpga/temp",
36 [LC15BTS_TEMP_RMSDET] = "/var/lc15/temp/rmsdet/temp",
37 [LC15BTS_TEMP_OCXO] = "/var/lc15/temp/ocxo/temp",
38 [LC15BTS_TEMP_TX0] = "/var/lc15/temp/tx0/temp",
39 [LC15BTS_TEMP_TX1] = "/var/lc15/temp/tx1/temp",
40 [LC15BTS_TEMP_PA0] = "/var/lc15/temp/pa0/temp",
41 [LC15BTS_TEMP_PA1] = "/var/lc15/temp/pa1/temp",
42 };
43
44 int lc15bts_temp_get(enum lc15bts_temp_sensor sensor, int *temp)
45 {
46 char buf[PATH_MAX];
47 char tempstr[8];
48 int fd, rc;
49
50 if (sensor < 0 || sensor >= _NUM_TEMP_SENSORS)
51 return -EINVAL;
52
53 snprintf(buf, sizeof(buf)-1, "%s", temp_devs[sensor]);
54 buf[sizeof(buf)-1] = '\0';
55
56 fd = open(buf, O_RDONLY);
57 if (fd < 0)
58 return fd;
59
60 rc = read(fd, tempstr, sizeof(tempstr));
61 tempstr[sizeof(tempstr)-1] = '\0';
62 if (rc < 0) {
63 close(fd);
64 return rc;
65 }
66 if (rc == 0) {
67 close(fd);
68 return -EIO;
69 }
70 close(fd);
71 *temp = atoi(tempstr);
72 return 0;
73 }
74