コード例 #1
0
/*
 * Retrieve the information structure for the given thermal OID.
 *
 * If the OID is invalid, return ONLP_E_STATUS_INVALID.
 * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
 * Otherwise, return ONLP_STATUS_OK with the OID's information.
 *
 * Note -- it is expected that you fill out the information
 * structure even if the sensor described by the OID is not present.
 */
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};
    VALIDATE(id);
	
    local_id = ONLP_OID_ID_GET(id);
	
    /* Set the onlp_oid_hdr_t and capabilities */		
    *info = linfo[local_id];

    if(local_id == THERMAL_CPU_CORE) {
        int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
        return rv;
    }	
	
    /* get fullpath */
    sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]);

    OPEN_READ_FILE(fd, fullpath, r_data, nbytes, len);
    info->mcelsius = atoi(r_data) / temp_base;	
    DEBUG_PRINT("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius);

    return ONLP_STATUS_OK;								
}
コード例 #2
0
ファイル: thermali.c プロジェクト: carlroth/OpenNetworkLinux
/*
 * Retrieve the information structure for the given thermal OID.
 *
 * If the OID is invalid, return ONLP_E_STATUS_INVALID.
 * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
 * Otherwise, return ONLP_STATUS_OK with the OID's information.
 *
 * Note -- it is expected that you fill out the information
 * structure even if the sensor described by the OID is not present.
 */
int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
{
    uint8_t local_id    = 0;
    UINT4 multiplier    = 1000;
    UINT4 u4Data        = 0;
    char device_buf[20] = {0};
    int rv;

    VALIDATE(id);
    local_id    = ONLP_OID_ID_GET(id);
    *info       = linfo[ONLP_OID_ID_GET(id)]; 
    if(local_id == THERMAL_CPU_CORE) {
        rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
        return rv;
    }
    switch(local_id)
    {
        case THERMAL_1_ON_CPU_BOARD:
        case THERMAL_2_ON_FAN_BOARD:
        case THERMAL_3_ON_MAIN_BOARD:
        case THERMAL_4_ON_MAIN_BOARD:
        case THERMAL_5_ON_MAIN_BOARD:
            sprintf(device_buf, "Sensor_Temp_%d", local_id-1);
            rv = dni_get_bmc_data(device_buf, &u4Data, multiplier);
            break;
        case THERMAL_6_ON_PSU1:
            sprintf(device_buf, "PSU1_Temp_1");
            rv = dni_get_bmc_data(device_buf, &u4Data, multiplier);
            break;
        case THERMAL_7_ON_PSU2:
            sprintf(device_buf, "PSU2_Temp_1");
            rv = dni_get_bmc_data(device_buf, &u4Data, multiplier);
            break;
        default:
            AIM_LOG_ERROR("Invalid Thermal ID!!\n");
            return ONLP_STATUS_E_PARAM;
    }

    if (u4Data == 0 || rv == ONLP_STATUS_E_GENERIC){
        return ONLP_STATUS_E_INTERNAL;
    }
    else{
        info->mcelsius = u4Data;
        return 0;
    }
}
コード例 #3
0
ファイル: thermali.c プロジェクト: carlroth/OpenNetworkLinux
/*
 * Retrieve the information structure for the given thermal OID.
 *
 * If the OID is invalid, return ONLP_E_STATUS_INVALID.
 * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
 * Otherwise, return ONLP_STATUS_OK with the OID's information.
 *
 * Note -- it is expected that you fill out the information
 * structure even if the sensor described by the OID is not present.
 */
int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
{
    int   tid;
    VALIDATE(id);
	
    tid = ONLP_OID_ID_GET(id);
	
    /* Set the onlp_oid_hdr_t and capabilities */		
    *info = linfo[tid];

    if(tid == THERMAL_CPU_CORE) {
        int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
        return rv;
    }

    return onlp_file_read_int(&info->mcelsius, devfiles__[tid]);
}
コード例 #4
0
ファイル: thermali.c プロジェクト: carlroth/OpenNetworkLinux
/*
 * Retrieve the information structure for the given thermal OID.
 *
 * If the OID is invalid, return ONLP_E_STATUS_INVALID.
 * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
 * Otherwise, return ONLP_STATUS_OK with the OID's information.
 *
 * Note -- it is expected that you fill out the information
 * structure even if the sensor described by the OID is not present.
 */
int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
{
    int   tid;
    int size;
    char     cmd[THERMAL_MAX_LENGTH/2] = {0};
    char     temp[4];
    uint8_t  data[THERMAL_MAX_LENGTH] = {0};
    //char  *ipmi_cmd;
    char  * tag, *p;
    struct  timeval    new_tv;
    long    last_time;
    int     get_data_by_ipmi=0;
       
    VALIDATE(id);
	
    tid = ONLP_OID_ID_GET(id);
	
    if(tid > THERMAL_1_ON_PSU2 || tid <= THERMAL_RESERVED)
        return ONLP_STATUS_E_INTERNAL;
    /* Set the onlp_oid_hdr_t and capabilities */
    *info = linfo[tid];
    
    if(tid == THERMAL_CPU_CORE) {    	 
        return onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
    }
    if(thermali_time_exist())
    {
        if(onlp_file_read(data, THERMAL_MAX_LENGTH, &size, THERMAL_CHECK_TIME)!=ONLP_STATUS_OK)
        {
            last_time=0; 
        }
        else
           last_time = atol((char*)data);
    }
    else
        last_time=0;

    gettimeofday(&new_tv,NULL);    

    if(last_time==0) /* first time */
    {
        get_data_by_ipmi=1;
    }
    else
    {
         if(new_tv.tv_sec > last_time)
         {
             if((new_tv.tv_sec - last_time) > THERMAL_CAN_SET_IPMI_TIME)
             {
                get_data_by_ipmi=1;
             }
             else
                get_data_by_ipmi=0;
         }
         else if(new_tv.tv_sec == last_time)
            get_data_by_ipmi=0;
         else
            get_data_by_ipmi=1;
            
    }
    memset(data ,0x0, THERMAL_MAX_LENGTH);
    snprintf((char*)data, THERMAL_MAX_LENGTH-1, "%ld", new_tv.tv_sec);
    if(onlp_file_write_str((char*)data, THERMAL_CHECK_TIME)!=ONLP_STATUS_OK)
    {
        return ONLP_STATUS_E_INTERNAL;
    }
    if(get_data_by_ipmi || !thermali_sdr_file_exist()) /* Set ipmitool cmd to get all data and save to file*/
    {
        /* set ipmi cmd */
        snprintf(cmd, (THERMAL_MAX_LENGTH/2) -1, "%s > %s ", THERMAL_IPMI_SDR_CMD, THERMAL_IPMI_SDR_FILE);
        system(cmd);
        fflush(stdout);
    }    
    tag= thermal_sensor_table[tid].tag;
    
    if(tag==NULL)
        return ONLP_STATUS_E_INTERNAL; 
    
    snprintf(cmd, (THERMAL_MAX_LENGTH/2) -1, "cat %s|grep %s > %s ", THERMAL_IPMI_SDR_FILE, tag, THERMAL_IPMI_TMP_FILE);
    system(cmd);
    
    if(onlp_file_read(data, THERMAL_MAX_LENGTH, &size, THERMAL_IPMI_TMP_FILE)!=ONLP_STATUS_OK)
    {
        return ONLP_STATUS_E_INTERNAL;
    }
    p=strstr((char*)data, THERMAL_IPMI_TMP_FILE_FIND);
    if(p==NULL)
    {
        return ONLP_STATUS_E_INTERNAL;
    }
    if(((uint8_t*)p-data) < sizeof(temp)/sizeof(char))
    {
       return ONLP_STATUS_E_INTERNAL;
    }
    
    temp[0]=data[(uint8_t*)p-data-4];
    temp[1]=data[(uint8_t*)p-data-3];
    temp[2]=data[(uint8_t*)p-data-2];
    info->mcelsius=ONLPLIB_ATOI(temp) * 1000;
       
    return ONLP_STATUS_OK;
}