.

     

MPI Application Template
template.c
 

XmpStats1.c -- XMP controller firmware foreground/background execution timing
/* XmpStats1.c */

/* Copyright(c) 1991-2006 by Motion Engineering, Inc.  All rights reserved.
 *
 * This software  contains proprietary and  confidential information  of
 * Motion Engineering Inc., and its suppliers.  Except as may be set forth
 * in the license agreement under which  this software is supplied, use,
 * disclosure, or  reproduction is prohibited without the prior express
 * written consent of Motion Engineering, Inc.
 */

/*

:XMP controller firmware foreground/background execution timing.

This program demonstrates how to monitor the controller's timer values
 to determine the performance.  The maximum foreground cycle time,
 average background cycle time, and delta are displayed.

Warning!  This is a sample program to assist in the integration of an
 MEI motion controller with your application.  It may not contain all
 of the logic and safety features that your application requires.

The msgCHECK(...) macros used in the following sample code are intended
 to convey our strong belief that ALL error return codes should be checked.
 Actual application code should use specific error handling techniques (other
 than msgCHECKs) best suited to your internal error recovery methods.

*/

#include <stdlib.h>
#include <stdio.h>

#include "stdmpi.h"
#include "stdmei.h"
#include "apputil.h"

/* Perform basic command line parsing. (-control -server -port -trace) */
Static void
   basicParsing(int                    argc,
                 char                  *argv[],
                 MPIControlType        *controlType,
                 MPIControlAddress     *controlAddress)
{
    long argIndex;

    /* Parse command line for Control type and address */
    argIndex = argControl(argc, argv, controlType, controlAddress);

    /* Check for unknown/invalid command line arguments */
    if (argIndex < argc) {
        fprintf(stderr,"usage: %s %s\n", argv[0], ArgUSAGE);
        exit(MPIMessageARG_INVALID);
    }
}


/* Create and initialize MPI objects */
Static void
   programInit(MPIControl         *control,
                MPIControlType     controlType,
                MPIControlAddress  *controlAddress)
{
    long    returnValue;

    /* Obtain a control handle */
    *control =
        mpiControlCreate(controlType, controlAddress);
    msgCHECK(mpiControlValidate(*control));

    /* Initialize the controller */
    returnValue =
        mpiControlInit(*control);
    msgCHECK(returnValue);
}


/* Perform certain cleanup actions and delete MPI objects */
Static void
   programCleanup(MPIControl *control)
{
    long    returnValue;

    /* Delete control handle */
    returnValue =
        mpiControlDelete(*control);
    msgCHECK(returnValue);

    *control = MPIHandleVOID;
}

Static void
   displayControllerVersion(MPIControl *control)
{
   MEIControlInfo controlInfo;

   long returnValue;

   returnValue =
      meiControlInfo(*control,
                  &controlInfo);

   meiPlatformConsole("MPI: version %s\n"
         "MPI firmware: version %d option %d\n"
         "%s firmware: version %d revision %c sub-revision %d\n"
         "\t\toption %d branchId %d\n\n"
         "Driver: version %s",
         controlInfo.mpi.version,
         controlInfo.mpi.fwVersion,
         controlInfo.mpi.fwOption,
         controlInfo.hardware.type,
         controlInfo.firmware.version,
         controlInfo.firmware.revision,
         controlInfo.firmware.subRevision,
         controlInfo.firmware.option,
         controlInfo.firmware.branchId,
         controlInfo.driver.version);
}

int main(int     argc,
         char   *argv[])
{
    MPIControl          control;
    MPIControlType         controlType;
    MPIControlAddress      controlAddress;
   MPIControlConfig     controlConfig;
   MEIControlStatistics statistics;

   long  returnValue;

    /* Perform basic command line parsing. (-control -server -port -trace) */
    basicParsing(argc,
                 argv,
                 &controlType,
                 &controlAddress);

    /* Create and initialize MPI objects */
    programInit(&control,
                controlType,
                &controlAddress);

   displayControllerVersion(&control);

   returnValue =
      mpiControlConfigGet(control,
                     &controlConfig,
                     NULL);
   msgCHECK(returnValue);

   meiPlatformConsole("\nSample rate: %ld\nMotors: %ld\nFilters: %ld\nAxes: %ld\nMS's: %ld\n\n",
         controlConfig.sampleRate,
         controlConfig.motorCount,
         controlConfig.filterCount,
         controlConfig.axisCount,
         controlConfig.motionCount);

    meiPlatformConsole("Performance Statistics (Press any key to quit)\n\n");
   meiPlatformConsole("    MaxFg          MaxBg       MaxDelta AvBgRate AvgBgTime        BgTime\n");

    while (meiPlatformKey(MPIWaitPOLL) <= 0) {

      /* Initial foreground/background timers */
      returnValue =
         meiControlStatisticsReset(control);
      msgCHECK(returnValue);

      meiPlatformSleep(200);  /* let the controller run for awhile */

      returnValue =
         meiControlStatistics(control,
                         &statistics);
      msgCHECK(returnValue);

      /* Calculate statistics */
      meiPlatformConsole("\r %8.1lf(usec) %8.1lf(usec) %8.1lf %8.0lf %8.1lf(usec) %8.1lf(usec)",
         statistics.maxForegroundTime,
         statistics.maxBackgroundTime,
         statistics.maxDelta,
         statistics.avgBackgroundRate,
         statistics.avgBackgroundTime,
         statistics.backgroundTime);
   }

    /* Perform certain cleanup actions and delete MPI objects */
    programCleanup(&control);

    return MPIMessageOK;
}


 
      
       Legal Notice  |  Tech Email  |  Feedback
      
Copyright ©
2001-2009 Motion Engineering