A P P E N D I X  B

Alarm Library libtsalarm

The libtsalarm library program allows you to get or set the status of the alarms with the tsalarm_get and tsalarm_set functions. For more details on the alarm indicators, see Alarm Status Indicators.

The following is an example of an application using the libtsalarm library.


EXAMPLE B-1 Application Using the libtsalarm Library

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <tsalarm.h>
 
void help(char *name) {
       printf("Syntax:  %s [get <type> | set <type> <state>]\n\n", name);
       printf("         type  = { critical, major, minor, user }\n");
       printf("         state = { on, off }\n\n");
 
       exit(0);
}
 
int main(int argc, char **argv) {
 
       uint32_t alarm_type, alarm_state;
 
       if (argc < 3)
               help(argv[0]);
 
       if (strncmp(argv[2], "critical", 1) == 0)
               alarm_type = TSALARM_CRITICAL;
       else if (strncmp(argv[2], "major", 2) == 0)
               alarm_type = TSALARM_MAJOR;
       else if (strncmp(argv[2], "minor", 2) == 0)
               alarm_type = TSALARM_MINOR;
       else if (strncmp(argv[2], "user", 1) == 0)
               alarm_type = TSALARM_USER;
       else
               help(argv[0]);
 
       if (strncmp(argv[1], "get", 1) == 0) {
               tsalarm_get(alarm_type, &alarm_state);
               printf("alarm = %d\tstate = %d\n", alarm_type, alarm_state);
       }
       else if (strncmp(argv[1], "set", 1) == 0) {
               if (strncmp(argv[3], "on", 2) == 0)
                       alarm_state = TSALARM_STATE_ON;
               else if (strncmp(argv[3], "off", 2) == 0)
                       alarm_state = TSALARM_STATE_OFF;
               else
                       help(argv[0]);
 
               tsalarm_set(alarm_type, alarm_state);
       }
       else {
               help(argv[0]);
       }
 
       return 0;
}