CODE EXAMPLE B-1Example Program for get/set Status of the Alarms (Continued)

#include <sys/types.h>

if ((ald.alarm_state != ALARM_OFF) && (ald.alarm_state != ALARM_ON)) {

printf("Invalid value returned: %d\n", ald.alarm_state); exit(1);

}

printf("ALARM.%s = %s\n", alarm, get_alarmval(ald.alarm_state));

}

static int

set_alarm(const char *alarm, const char *alarmstate)

{

ts_aldata_t ald;

int alarmval = ALARM_OFF, altype = parse_alarm(alarm);

if (altype == ALARM_INVALID) { usage();

exit (1);

}

if (strcmp(alarmstate, "on") == 0) alarmval = ALARM_ON;

else

if (strcmp(alarmstate, "off") == 0) alarmval = ALARM_OFF;

else {

usage(); exit (1);

}

ald.alarm_no = altype; ald.alarm_state = alarmval;

if (lom_ioctl(LOMIOCALCTL, (char *)&ald) != 0) {

printf("Setting ALARM.%s to %s failed\n", alarm, alarmstate); return (1);

} else {

printf("Setting ALARM.%s successfully set to %s\n", alarm,

alarmstate);

return (1);

}

}

static int

parse_alarm(const char *alarm)

Appendix B Alarm Relay Output Application Programming Interface 73

Page 87
Image 87
Sun Microsystems 440 manual