Chapter 2
Environmental Monitoring
37
Sample Application Program
This section presents a sample environmental monitoring (
envmond
) application
that monitors the CPU diode temperature.
CODE EXAMPLE 2-1
Sample
envmond
Application Program
/*
* sensor_readwrite.c
*
* compile: cc sensor_readwrite.c -lthread -lpicl -o sensor_readwrite
*/
#include <stdio.h>
#include <picl.h>
#define HI_POWEROFF_THRESHOLD "HighPowerOffThreshold"
#define HI_SHUTDOWN_THRESHOLD "HighShutdownThreshold"
#define HI_WARNING_THRESHOLD "HighWarningThreshold"
#define LO_POWEROFF_THRESHOLD "LowPowerOffThreshold"
#define LO_SHUTDOWN_THRESHOLD "LowShutdownThreshold"
#define LO_WARNING_THRESHOLD "LowWarningThreshold"
#define CURRENT_TEMPERATURE "Temperature"
static int
get_child_by_name(picl_nodehdl_t nodeh, char *name, picl_nodehdl_t *resulth)
{
picl_nodehdl_t childh;
picl_nodehdl_t nexth;
char propname[PICL_PROPNAMELEN_MAX];
picl_errno_t rc;
/* look up first child node */
rc = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, &childh,
sizeof (picl_nodehdl_t));
if (rc != PICL_SUCCESS) {
return (rc);
}
/* step through child nodes looking for named node */
while (rc == PICL_SUCCESS) {
rc = picl_get_propval_by_name(childh, PICL_PROP_NAME,
propname, sizeof (propname));
if (rc != PICL_SUCCESS) {
return (rc);
}
if (name && strcmp(propname, name) == 0) {
/* yes - got it */