Alarm Management API Sample Program

A sample utility program is provided to demonstrate the use of the Alarm Management application utilities--the contents of an application program, and the steps for compiling and linking.

Below is a copy of the amaru_demo.c demonstration program:

/*

|*|                    PROPRIETARY NOTICE

|*|

|*|   THIS PROGRAM AND RELATED MATERIAL ARE THE PROPERTY OF GE FANUC

|*|   AUTOMATION NORTH AMERICA AND CONTAINS CONFIDENTIAL AND PROPRIETARY

|*|   INFORMATION. THIS PROGRAM, THE RELATED MATERIAL, AND THE

|*|   INFORMATION CONTAINED THEREIN, SHALL NOT BE DISCLOSED TO OTHERS

|*|   WITHOUT PERMISSION OF GE FANUC N.A., AND SHALL NOT BE DUPLICATED

|*|   OR USED EXCEPT IN ACCORDANCE WITH THE LIMITED CONDITIONS UNDER

|*|   WHICH IT WAS PROVIDED.

|*|

|*|         COPYRIGHT (C) 1990 GE FANUC AUTOMATION NORTH AMERICA

|*|                PROPRIETARY AND TRADE SECRET

|*|            PUBLISHED ONLY IN LIMITED COPYRIGHT SENSE

|*|-----------------------------------------------------------------------------

|*| NAME:                     AMARU_DEMO

|*|

|*| PURPOSE:    define global storage, main modules for demonstrating the

|*|             Alarm Management Utilities Package. It generates an alarm

|*|             and then resets it.

|*|

|*| MODULE:  amaru_demo.c

|*|

|*| ENGINEER/DATE:   24-May 1990 G. M. Heitker

|*|

|*| MODULE DATA:

|*|

|*| GLOBAL DATA:

|*|

|*| PROCEDURES:

|*|             main

|*|

|*| NOTES:       <revision-date> <revision-author>

*/

#include <stdio.h>

#include <inc_path/cor.h>

#include <inc_path/cor_stat.h>

#include <inc_path/sc_recs.h>

#include <inc_path/netcom.h>

#include <inc_path/am_defs.h>

#ifdef WIN32

#include <string.h>

#include <inc_path/amaru_proto.h>

#endif

int _tmain()

{

   int          dg_port_index;

   int          max_link = 1;

   TCHAR        object_name[OBJECT_NAME_LEN+1];

   IPCDG        *alarm_write_buffer;

   TCHAR        *alarm_write_body;

   Int          alarm_write_len;

   IPCDG        *alarm_read_buffer;

   TCHAR        *alarm_read_body;

   Int          alarm_read_len;

   Int          i;

   Int          n;

   COR_STATUS   ret_stat;

   AM_MSG_FIELD msg_field[AM_MAX_FIELDS];

TCHAR         alarm_mgr_id[ALARM_MGR_ID_LEN+1];

   /* get the current process name */

   coprcnam (object_name);

   /* register this process with IPC router */

   ret_stat.status = ipc_register(&ret_stat,

                                 &dg_port_index,

                                 object_name,

                                 max_link,

                                 MAXMSGSIZ);

   if (ret_stat.status != COR_SUCCESS)

   {

     _tprintf(_T("%s\n"),ret_stat.err_msg);

     goto end_of_program;

   }

   /* make two IPC datagram buffers */

   amaru_alloc_buffer( &alarm_write_buffer, &alarm_write_len,

                      &alarm_write_body);

amaru_alloc_buffer( &alarm_read_buffer, &alarm_read_len,

                      &alarm_read_body);

   /* initialize the AMARU system - reads and validates SC_PATH:ALARM_MGR.DAT */

   amaru_init(&ret_stat);

   if (ret_stat.status != COR_SUCCESS)

   {

     _tprintf(_T("%s\n"),ret_stat.err_msg);

     goto end_of_program_am;

   }

   /* make up the message */

   /* the chosen alarm is "$RTR_LINK_DOWN" */

   /* in the SC_PATH:ALARM_DEF.DAT file, the alarm_type is "$RTR_LINK_DOWN" */

   /* in the SC_PATH:ALARM_TYPE.DAT file,the type "$RTR_LINK_DOWN" is defined */

   /* in the SC_PATH:ALARM_FIELD.DAT file, there are three parameters */

   /* each parameter is a character string of length 10 */

   i = 0;

memset(msg_field, 0, sizeof(msg_field));

   /* we assume that the message field is configured as a character */

   /* string in this example */

   /* we assume also a message field length of 10 */

   msg_field[i].ftype = AM_STR;

   _tcscpy(msg_field[i].field.str, object_name);

   i++;

   msg_field[i].ftype = AM_STR;

   _tcscpy(msg_field[i].field.str, _T("IGNORE"));

i++;

   msg_field[i].ftype = AM_STR;

   _tcscpy(msg_field[i].field.str, _T("TESTED"));

   i++;

   

   /* set up to generate the alarm */

   /* the alarm is fixed as shown */

   amaru_add_gen(alarm_write_body, /* data pointer of write buffer */

                 alarm_write_len - IPC_HEAD_LEN, /* data length avail */

                 TRUE,             /* TRUE if first message in buffer */

                                   /* FALSE if not first message */

                 _T("$RTR_LINK_DOWN"),   /* ID of alarm */

                  _T("$SYSTEM"),         /* ID of resource */

                 object_name,       /* an identifier of who sent the alarm */

                 NULL,             /* reference ID or NULL goes here */

                 AM_CAPTURED_RESP, /* AMRP sends response immediately */

                 0,                /* key */

                 msg_field,        /* the message struct array */

                 i,                /* the number of fields in the message */

                 FALSE,            /* reset follows - TRUE if an */

                                   /* update message for this alarm follows */

                                   /* as the NEXT message in the buffer */

                 &ret_stat );

   if (ret_stat.status != COR_SUCCESS)

   {

     _tprintf(_T("%s\n"),ret_stat.err_msg);

     goto end_of_program_am;

   }

   /* find out the alarm manager */

   _tprintf (_T("\nEnter the service name of the alarm manager resident process: "));

   _tscanf(_T("%s"),alarm_mgr_id);

   /* you can add more GEN or UPDATE messages */

   /* when done, send the buffer to ALARM MANAGER */

   amaru_send_msg(dg_port_index,

                  alarm_write_buffer,

                  alarm_read_buffer,

                  alarm_read_len,

                  alarm_mgr_id,       /* this ID is configured when the */

                                      /* resource is configured; this is */

                                      /* the alarm manager to talk with */

                  &ret_stat);

   if (ret_stat.status != COR_SUCCESS)

   {

     _tprintf(_T("%s\n"),ret_stat.err_msg);

     goto end_of_program_am;

   }

   /* now analyze the response from alarm manager */

   n = amaru_num_messages(alarm_read_body, &ret_stat);

   if (ret_stat.status != COR_SUCCESS)

   {

     _tprintf(_T("%s\n"),ret_stat.err_msg);

     goto end_of_program_am;

   }

   for( i = 0; i < n; i++ )

   {

     amaru_get_resp(alarm_read_body, i, &ret_stat);

     if(ret_stat.status != COR_SUCCESS)

     {

        _tprintf(_T("%d:%s\n"),i,ret_stat.err_msg);

     }

   }

   /* now lets have some more fun - let's reset the alarm we just set */

   amaru_add_update(alarm_write_body, /* write buffer data pointer */

                    alarm_write_len-IPC_HEAD_LEN, /* size of data area */

                    TRUE,            /* set first_seg to TRUE as we are */

                                    /* re-using the write buffer */

                                    /* if we wanted to send more than */

                                    /* one request, this parameter must */

                                    /* be FALSE for all others */

                   _T("$RTR_LINK_DOWN"),  /* alarm ID that was gen'd */

                   _T("$SYSTEM"),        /* resource ID that was used in gen */

                   object_name,      /* user ID that was used in gen */

                   NULL,             /* reference ID that was used in gen */

                   AM_CLEARED,       /* NEW state for alarm */

                   0,                 /* sequence number */

                   AM_CAPTURED_RESP,  /* AMRP sends response immediately */

                   0,                /* same key value as used in gen */

                   &ret_stat);        /* status of operation */

   if (ret_stat.status != COR_SUCCESS)

   {

     _tprintf(_T("%s\n"),ret_stat.err_msg);

     goto end_of_program_am;

   }

   /* you can add more GEN or UPDATE messages */

   /* when done, send the buffer to ALARM MANAGER */

   amaru_send_msg(dg_port_index,

                  alarm_write_buffer,

                  alarm_read_buffer,

                  alarm_read_len,

                  alarm_mgr_id,      /* this ID is configured when the */

                                      /* resource is configured; this is */

                                      /* the alarm manager to talk with */

                  &ret_stat);

   if (ret_stat.status != COR_SUCCESS)

   {

     _tprintf(_T("%s\n"),ret_stat.err_msg);

     goto end_of_program_am;

   }

end_of_program_am:

   amaru_free_buffer(alarm_write_buffer);

   amaru_free_buffer(alarm_read_buffer);

   amaru_terminate();

end_of_program:

   ipc_deactivate( &ret_stat, dg_port_index );

   return(0);

}

More information

Alarm Management API getting started.