Exemplo n.º 1
0
int
onlp_file_vread_int(int* value, const char* fmt, va_list vargs)
{
    int rv;
    uint8_t data[32];
    int len;
    rv = onlp_file_vread(data, sizeof(data), &len, fmt, vargs);
    if(rv < 0) {
        return rv;
    }
    *value = ONLPLIB_ATOI((char*)data);
    return 0;

}
Exemplo n.º 2
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   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;
}