📄 lmsensors.c
字号:
*/#ifdef solaris2/* ******* picld sensor procedures * */#ifdef HAVE_PICL_Hstatic intprocess_individual_fan(picl_nodehdl_t childh, char propname[PICL_PROPNAMELEN_MAX]){ picl_nodehdl_t sensorh; picl_propinfo_t sensor_info; int speed; int typ = 1; /*fan*/ picl_errno_t error_code,ec2; if (sensor_array[typ].n >= MAX_SENSORS){ DEBUGMSG(("ucd-snmp/lmSensors", "There are too many sensors of type %d\n",typ)); } else{ error_code = (picl_get_propinfo_by_name(childh, "AtoDSensorValue",&sensor_info,&sensorh)); if (error_code == PICL_SUCCESS) { ec2 = picl_get_propval(sensorh,&speed,sizeof(speed)); if (ec2 == PICL_SUCCESS){ sensor_array[typ].sensor[sensor_array[typ].n].value = speed; snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name, (PICL_PROPNAMELEN_MAX - 1),"%s",propname); sensor_array[typ].sensor[sensor_array[typ].n]. name[PICL_PROPNAMELEN_MAX - 1] = '\0'; sensor_array[typ].n++; } /*end if ec2*/ else DEBUGMSG(("ucd-snmp/lmSensors", "sensor value read error code->%d\n",ec2)); } /* end if */ else DEBUGMSG(("ucd-snmp/lmSensors", "sensor lookup failed error code->%d\n",error_code)); }} /*process individual fan*/static intprocess_temperature_sensor(picl_nodehdl_t childh, char propname[PICL_PROPNAMELEN_MAX]){ picl_nodehdl_t sensorh; picl_propinfo_t sensor_info; int temp; int typ = 0; /*temperature*/ picl_errno_t error_code,ec2; if (sensor_array[typ].n >= MAX_SENSORS){ DEBUGMSG(("ucd-snmp/lmSensors", "There are too many sensors of type %d\n",typ)); } else{ error_code = (picl_get_propinfo_by_name(childh, "Temperature",&sensor_info,&sensorh)); if (error_code == PICL_SUCCESS) { ec2 = picl_get_propval(sensorh,&temp,sizeof(temp)); if (ec2 == PICL_SUCCESS){ sensor_array[typ].sensor[sensor_array[typ].n].value = temp; snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name, (PICL_PROPNAMELEN_MAX - 1),"%s",propname); sensor_array[typ].sensor[sensor_array[typ].n]. name[PICL_PROPNAMELEN_MAX - 1] = '\0'; sensor_array[typ].n++; } /*end if ec2*/ else DEBUGMSG(("ucd-snmp/lmSensors", "sensor value read error code->%d\n",ec2)); } /* end if */ else DEBUGMSG(("ucd-snmp/lmSensors", "sensor lookup failed error code->%d\n",error_code)); }} /* process temperature sensor */static intprocess_digital_sensor(picl_nodehdl_t childh, char propname[PICL_PROPNAMELEN_MAX]){ picl_nodehdl_t sensorh; picl_propinfo_t sensor_info; int temp; /*volts?*/ int typ = 2; /*volts*/ picl_errno_t error_code,ec2; if (sensor_array[typ].n >= MAX_SENSORS){ DEBUGMSG(("ucd-snmp/lmSensors", "There are too many sensors of type %d\n",typ)); } else{ error_code = (picl_get_propinfo_by_name(childh, "AtoDSensorValue",&sensor_info,&sensorh)); if (error_code == PICL_SUCCESS) { ec2 = picl_get_propval(sensorh,&temp,sizeof(temp)); if (ec2 == PICL_SUCCESS){ sensor_array[typ].sensor[sensor_array[typ].n].value = temp; snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name, (PICL_PROPNAMELEN_MAX - 1),"%s",propname); sensor_array[typ].sensor[sensor_array[typ].n]. name[PICL_PROPNAMELEN_MAX - 1] = '\0'; sensor_array[typ].n++; } else DEBUGMSG(("ucd-snmp/lmSensors", "sensor value read error code->%d\n",ec2)); } /* end if */ else DEBUGMSG(("ucd-snmp/lmSensors", "sensor lookup failed error code->%d\n",error_code)); }} /* process digital sensor */static intprocess_switch(picl_nodehdl_t childh, char propname[PICL_PROPNAMELEN_MAX]){ picl_nodehdl_t sensorh; picl_propinfo_t sensor_info; char state[32]; int st_cnt; char *switch_settings[]={"OFF","ON","NORMAL","LOCKED","UNKNOWN", "DIAG","SECURE"}; u_int value; u_int found = 0; int max_key_posns = 7; int typ = 3; /*other*/ if (sensor_array[typ].n >= MAX_SENSORS){ DEBUGMSG(("ucd-snmp/lmSensors", "There are too many sensors of type %d\n",typ)); } else{ picl_errno_t error_code,ec2; error_code = (picl_get_propinfo_by_name(childh, "State",&sensor_info,&sensorh)); if (error_code == PICL_SUCCESS) { ec2 = picl_get_propval(sensorh,&state,sensor_info.size); if (ec2 == PICL_SUCCESS){ for (st_cnt=0;st_cnt < max_key_posns;st_cnt++){ if (strncmp(state,switch_settings[st_cnt], strlen(switch_settings[st_cnt])) == 0){ value = st_cnt; found = 1; break; } /* end if */ } /* end for */ if (found==0) value = 99; sensor_array[typ].sensor[sensor_array[typ].n].value = value; snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name, (PICL_PROPNAMELEN_MAX - 1),"%s",propname); sensor_array[typ].sensor[sensor_array[typ].n]. name[PICL_PROPNAMELEN_MAX - 1] = '\0'; sensor_array[typ].n++; } /*end if ec2*/ else DEBUGMSG(("ucd-snmp/lmSensors", "sensor value read error code->%d\n",ec2)); } /* end if */ else DEBUGMSG(("ucd-snmp/lmSensors", "sensor lookup failed error code->%d\n",error_code)); }} /*process switch*/static intprocess_led(picl_nodehdl_t childh, char propname[PICL_PROPNAMELEN_MAX]){ picl_nodehdl_t sensorh; picl_propinfo_t sensor_info; char state[32]; int st_cnt; char *led_settings[]={"OFF","ON","BLINK"}; u_int value; u_int found = 0; int max_led_posns = 3; int typ = 3; picl_errno_t error_code,ec2; if (sensor_array[typ].n >= MAX_SENSORS){ DEBUGMSG(("ucd-snmp/lmSensors", "There are too many sensors of type %d\n",typ)); } else{ error_code = (picl_get_propinfo_by_name(childh, "State",&sensor_info,&sensorh)); if (error_code == PICL_SUCCESS) { ec2 = picl_get_propval(sensorh,&state,sensor_info.size); if (ec2 == PICL_SUCCESS){ for (st_cnt=0; st_cnt < max_led_posns; st_cnt++){ if (strncmp(state,led_settings[st_cnt], strlen(led_settings[st_cnt])) == 0){ value=st_cnt; found = 1; break; } } if (found==0) value = 99; sensor_array[typ].sensor[sensor_array[typ].n].value = value; snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name, (PICL_PROPNAMELEN_MAX - 1),"%s",propname); sensor_array[typ].sensor[sensor_array[typ].n]. name[PICL_PROPNAMELEN_MAX - 1] = '\0'; sensor_array[typ].n++; } else DEBUGMSG(("ucd-snmp/lmSensors", "sensor value read error code->%d\n",ec2)); } else DEBUGMSG(("ucd-snmp/lmSensors", "sensor lookup failed error code->%d\n",error_code)); }} static intprocess_i2c(picl_nodehdl_t childh, char propname[PICL_PROPNAMELEN_MAX]){ picl_nodehdl_t sensorh; picl_propinfo_t sensor_info; char state[32]; int st_cnt; char *i2c_settings[]={"OK"}; u_int value; u_int found = 0; int max_i2c_posns = 1; int typ = 3; picl_errno_t error_code,ec2; if (sensor_array[typ].n >= MAX_SENSORS){ DEBUGMSG(("ucd-snmp/lmSensors", "There are too many sensors of type %d\n",typ)); } else{ error_code = (picl_get_propinfo_by_name(childh, "State",&sensor_info,&sensorh)); if (error_code == PICL_SUCCESS) { ec2 = picl_get_propval(sensorh,&state,sensor_info.size); if (ec2 == PICL_SUCCESS){ for (st_cnt=0;st_cnt < max_i2c_posns;st_cnt++){ if (strncmp(state,i2c_settings[st_cnt], strlen(i2c_settings[st_cnt])) == 0){ value=st_cnt; found = 1; break; } } if (found==0) value = 99; sensor_array[typ].sensor[sensor_array[typ].n].value = value; snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name, (PICL_PROPNAMELEN_MAX - 1),"%s",propname); sensor_array[typ].sensor[sensor_array[typ].n]. name[PICL_PROPNAMELEN_MAX - 1] = '\0'; sensor_array[typ].n++; } else DEBUGMSG(("ucd-snmp/lmSensors", "sensor value read error code->%d\n",ec2)); } else DEBUGMSG(("ucd-snmp/lmSensors", "sensor lookup failed error code->%d\n",error_code)); }}static intprocess_sensors(picl_nodehdl_t nodeh){ picl_nodehdl_t childh; picl_nodehdl_t nexth; char propname[PICL_PROPNAMELEN_MAX]; char propclass[PICL_CLASSNAMELEN_MAX]; picl_errno_t error_code; /* look up first child node */ error_code = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, &childh, sizeof (picl_nodehdl_t)); if (error_code != PICL_SUCCESS) { return (error_code); } /* step through child nodes, get the name first */ while (error_code == PICL_SUCCESS) { error_code = picl_get_propval_by_name(childh, PICL_PROP_NAME, propname, (PICL_PROPNAMELEN_MAX - 1)); if (error_code != PICL_SUCCESS) { /*we found a node with no name. Impossible.! */ return (error_code); } if (strcmp(propname,PICL_NODE_PLATFORM)==0){ /*end of the chain*/ return (255); } error_code = picl_get_propval_by_name(childh, PICL_PROP_CLASSNAME, propclass, sizeof (propclass)); if (error_code != PICL_SUCCESS) { /*we found a node with no class. Impossible.! */ return (error_code); }/* DEBUGMSGTL(("ucd-snmp/lmSensors","found %s of class %s\n",propname,propclass)); */ if (strstr(propclass,"fan-tachometer")) process_individual_fan(childh,propname); if (strstr(propclass,"temperature-sensor")) process_temperature_sensor(childh,propname); if (strstr(propclass,"digital-sensor")) process_digital_sensor(childh,propname); if (strstr(propclass,"switch")) process_switch(childh,propname); if (strstr(propclass,"led")) process_led(childh,propname); if (strstr(propclass,"i2c")) process_i2c(childh,propname);/* if (strstr(propclass,"gpio")) process_gpio(childh,propname); */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -