mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
Use search specification.
This commit is contained in:
@@ -29,10 +29,6 @@
|
||||
#include <onlp/platformi/thermali.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define prefix_path "/sys/bus/i2c/devices/"
|
||||
#define filename "temp1_input"
|
||||
#define LOCAL_DEBUG 0
|
||||
|
||||
#define VALIDATE(_id) \
|
||||
do { \
|
||||
if(!ONLP_OID_IS_THERMAL(_id)) { \
|
||||
@@ -41,20 +37,6 @@
|
||||
} while(0)
|
||||
|
||||
|
||||
#define OPEN_READ_FILE(fd,fullpath,data,nbytes,len) \
|
||||
if (LOCAL_DEBUG) \
|
||||
printf("[Debug][%s][%d][openfile: %s]\n", __FUNCTION__, __LINE__, fullpath); \
|
||||
if ((fd = open(fullpath, O_RDONLY)) == -1) \
|
||||
return ONLP_STATUS_E_INTERNAL; \
|
||||
if ((len = read(fd, r_data, nbytes)) <= 0){ \
|
||||
close(fd); \
|
||||
return ONLP_STATUS_E_INTERNAL;} \
|
||||
if (LOCAL_DEBUG) \
|
||||
printf("[Debug][%s][%d][read data: %s]\n", __FUNCTION__, __LINE__, r_data); \
|
||||
if (close(fd) == -1) \
|
||||
return ONLP_STATUS_E_INTERNAL
|
||||
|
||||
|
||||
enum onlp_thermal_id
|
||||
{
|
||||
THERMAL_RESERVED = 0,
|
||||
@@ -66,23 +48,23 @@ enum onlp_thermal_id
|
||||
THERMAL_1_ON_PSU2,
|
||||
};
|
||||
|
||||
static char* last_path[] = /* must map with onlp_thermal_id */
|
||||
static char* devfiles__[] = /* must map with onlp_thermal_id */
|
||||
{
|
||||
"reserved",
|
||||
NULL, /* CPU_CORE files */
|
||||
"63-0048/",
|
||||
"64-0049/",
|
||||
"65-004a/",
|
||||
"59-003c/psu_",
|
||||
"60-003f/psu_",
|
||||
"/sys/bus/i2c/devices/63-0048*temp1_input",
|
||||
"/sys/bus/i2c/devices/64-0049*temp1_input",
|
||||
"/sys/bus/i2c/devices/65-004a*temp1_input",
|
||||
"/sys/bus/i2c/devices/59-003c*psu_temp1_input",
|
||||
"/sys/bus/i2c/devices/60-003f*psu_temp1_input",
|
||||
};
|
||||
|
||||
static char* cpu_coretemp_files[] =
|
||||
{
|
||||
"/sys/devices/platform/coretemp.0/temp2_input",
|
||||
"/sys/devices/platform/coretemp.0/temp3_input",
|
||||
"/sys/devices/platform/coretemp.0/temp4_input",
|
||||
"/sys/devices/platform/coretemp.0/temp5_input",
|
||||
"/sys/devices/platform/coretemp.0*temp2_input",
|
||||
"/sys/devices/platform/coretemp.0*temp3_input",
|
||||
"/sys/devices/platform/coretemp.0*temp4_input",
|
||||
"/sys/devices/platform/coretemp.0*temp5_input",
|
||||
NULL,
|
||||
};
|
||||
|
||||
@@ -141,16 +123,11 @@ onlp_thermali_init(void)
|
||||
int
|
||||
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
|
||||
{
|
||||
int fd, len, nbytes = 10, temp_base=1, local_id;
|
||||
char r_data[10] = {0};
|
||||
char fullpath[50] = {0};
|
||||
int local_id;
|
||||
VALIDATE(id);
|
||||
|
||||
local_id = ONLP_OID_ID_GET(id);
|
||||
|
||||
if (LOCAL_DEBUG)
|
||||
printf("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id);
|
||||
|
||||
/* Set the onlp_oid_hdr_t and capabilities */
|
||||
*info = linfo[local_id];
|
||||
|
||||
@@ -158,18 +135,5 @@ onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
|
||||
int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* get fullpath */
|
||||
sprintf(fullpath, "%s%s%s", prefix_path, last_path[local_id], filename);
|
||||
|
||||
OPEN_READ_FILE(fd,fullpath,r_data,nbytes,len);
|
||||
|
||||
info->mcelsius = atoi(r_data)/temp_base;
|
||||
|
||||
if (LOCAL_DEBUG)
|
||||
printf("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius);
|
||||
|
||||
return ONLP_STATUS_OK;
|
||||
return onlp_file_read_int(&info->mcelsius, devfiles__[local_id]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user