Sample setup

The following code sample opens the service for TX board boardNum and then registers for events from that boards. In this sample, after opening these services, a loop watching for events prints out the data from the events as they are received.

/* Service name/manager pair for ctaInitialize */
CTA_SERVICE_NAME    HmiServiceNames[] = { { "HMI", "HMIMGR" } };

/* Service list for ctaOpenServices */
CTA_SERVICE_DESC    HmiOpenSvcLst[] =
{
    {{"HMI", "HMIMGR"}, {0}, {0}, {0}}
};

hmiInitparms.size = sizeof( CTA_INIT_PARMS );
hmiInitparms.parmflags = CTA_PARM_MGMT_SHARED;
hmiInitparms.ctacompatlevel = CTA_COMPATLEVEL;
ret = ctaInitialize( HmiServiceNames, 1, &hmiInitparms );

/* create a CT Access queue used to pass all events to the application */
ret = ctaCreateQueue( NULL, 0, &AppCtlQueue );

/* create a CT Access context for HMI async events
 * and open the HMI async events service on that context
 */
ret = ctaCreateContext( AppCtlQueue, 0, "APPCTL", &AppCtlAsyncHd );

HmiOpenSvcLst[0].svcargs.args[0] = hmiCtlChan;
HmiOpenSvcLst[0].svcargs.args[1] = boardNum;
HmiOpenSvcLst[0].svcargs.args[2] = HMI_RCV_EVENTS;
ret = ctaOpenServices( &AppCtlAsyncHd, &HmiOpenSvcLst[0], 1 );

/* Wait for service open to complete. */
do
{
    ctaWaitEvent( AppCtlQueue, &event, CTA_WAIT_FOREVER );
} while (event.id != CTAEVN_OPEN_SERVICES_DONE);

if (event.value != CTA_REASON_FINISHED)
{
    ctaGetText( event.ctahd, event.value, emsg, sizeof( emsg ) );
    printf( "ERROR opening HMI service [%ld]: %s\n", hmiCtlChan, emsg );
    exit( 1 );
}

/* create a CT Access context for HMI commands
 * and open the HMI commands service on that context
 */
ret = ctaCreateContext( AppCtlQueue, 0, "APPCMD", &AppCtlCmdHd );

HmiOpenSvcLst[0].svcargs.args[0] = hmiCmdChan;
HmiOpenSvcLst[0].svcargs.args[1] = boardNum;
HmiOpenSvcLst[0].svcargs.args[2] = HMI_RCV_EVENTS;
ret = ctaOpenServices( &AppCtlCmdHd, &HmiOpenSvcLst[0], 1 );

/* Wait for service open to complete. */
do
{
    ctaWaitEvent( AppCtlQueue, &event, CTA_WAIT_FOREVER );
} while (event.id != CTAEVN_OPEN_SERVICES_DONE);

if (event.value != CTA_REASON_FINISHED)
{
    ctaGetText( event.ctahd, event.value, emsg, sizeof( emsg ) );
    printf( "ERROR opening HMI service [%ld]: %s\n", hmiCmdChan, emsg );
    exit( 1 );
}

while (!stop)
{
    ret = ctaWaitEvent( AppCtlQueue, &event, CTA_WAIT_FOREVER );
    if (ret == SUCCESS)
    {
        printf( "Received event %x from board %d\n", event.id, event.value );
        if (event.id == HMI_EVN_SERVICE_DOWN)
            stop = TRUE;
    }
    else
    {
        ctaGetText( NULL_CTAHD, ret, emsg, sizeof( emsg ) );
        printf( "ERROR waiting on CTA event: %s\n", emsg );
        stop = TRUE;
    }
}

The application opens the number of HMI service interfaces needed to monitor and control health management. The following illustration shows the arrangement between the Natural Access queues and contexts when three opens were performed:

In a single node system, an application can control both boards by opening HMI services to each board. This application can take appropriate actions to recover from board failures (for example, by making backup boards primary, reloading dead boards). In a dual node system, the applications are responsible for choreographing failovers and switchovers. Consider these situations when designing the user part application. Refer to ISUP demonstration program overview for an application that can be run in dual node or single node environments.