.

     

MPI Application Template
template.c
 

sqTiming1.c -- Display SynqNet Timing values
/* sqTiming1.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.
 */

/*

:Display SynqNet Timing values

This sample application retrieves the SynqNetwork timing values from the 
MPI and displays them to the console.

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) */
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 */
void programInit(MPIControl         *control,
                 MPIControlType      controlType,
                 MPIControlAddress  *controlAddress,
             MEISynqNet         *synqNet)
{
    long    returnValue;


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

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

   /* Obtain a synqNet handle */
    *synqNet =
        meiSynqNetCreate(*control, 0);
    msgCHECK(meiSynqNetValidate(*synqNet));

}


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

    /* Delete synqNet handle */
    returnValue =
        meiSynqNetDelete(*synqNet);
    msgCHECK(returnValue);

   *synqNet = MPIHandleVOID;

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

   *control = MPIHandleVOID;
}


/* Display SynqNet timing information */
void displaySynqNetTiming(MPIControl   control,
                    MEISynqNet   synqNet)
{
   MEISynqNetTiming  timingValues;
   MEISynqNetInfo    netInfo;
   MEISqNode         sqNode;
   long           index;
   long           nodeNumber;
   long           returnValue;

    /* Get SynqNet info */
    returnValue =
      meiSynqNetInfo(synqNet, &netInfo);
   msgCHECK(returnValue);

    /* Get SynqNet timing values */
    returnValue =
      meiSynqNetTiming(synqNet, &timingValues);
   msgCHECK(returnValue);

   /* Display SynqNet timing values */
    if (returnValue == MPIMessageOK) {
      printf("SynqNet Timing Values\n"
                     "=====================\n\n");

      printf("Controller Frequency  : %3.3lf kHz\n"
            "Controller Period     : %3.3lf uS\n"
            "TxTime                : %d percent\n"
            "Calculation Limit     : %3.3lf uS\n"
            "Calculation Time      : %3.3lf uS\n"
            "Calculation Slack     : %3.3lf uS\n"
            "SynqNet Bandwidth Used: %d percent \n\n",
            timingValues.controllerFreq,
            timingValues.controllerPeriod,
            timingValues.txTime,
            timingValues.calculationLimit,
            timingValues.calculationTime,
            timingValues.calculationSlack,
            timingValues.bandwidthUsage);

      printf("Synq Packets    : %3.3lf uS\n"
            "Demand Packets  : %3.3lf uS\n"
            "Control Packets : %3.3lf uS\n"
            "================================\n"
            "Total Downstream: %3.3lf uS\n\n",
            timingValues.downstream.synq,
            timingValues.downstream.demand,
            timingValues.downstream.control,
            timingValues.downstream.total);

      printf("Feedback Packets : %3.3lf uS\n"
            "Status Packets   : %3.3lf uS\n"
            "================================\n"
            "Total Upstream   : %3.3lf uS\n\n",
            timingValues.upstream.feedback,
            timingValues.upstream.status,
            timingValues.upstream.total);
   }

   /* Display Node Timing Values */
   for (index = netInfo.nodeOffset;
       index < (netInfo.nodeOffset + netInfo.nodeCount);
       index++) {

      sqNode =
         meiSqNodeCreate(control, index);
      msgCHECK(meiSqNodeValidate(sqNode));

      returnValue =
         meiSqNodeNumber(sqNode, &nodeNumber);
      msgCHECK(returnValue);

      returnValue =
         meiSqNodeDelete(sqNode);
      msgCHECK(returnValue);

      printf("Node[%ld]\n"
            "Drive Update Frequency: %3.3lf kHz\n"
            "Drive Update Period   : %3.3lf uS\n"
            "Node Demand Latency   : %3.3lf uS\n"
            "Node Feedback Latency : %3.3lf uS\n"
            "Node Latency Overhead : %3.3lf uS\n"
            "Node Control Latency  : %3.3lf uS\n"
            "Node Latency Tolerance: %3.3lf uS\n"
            "================================\n\n",
            nodeNumber,
            timingValues.node[index].updateFreq,
            timingValues.node[index].updatePeriod,
            timingValues.node[index].demandLatency,
            timingValues.node[index].feedbackLatency,
            timingValues.node[index].latencyOverhead,
            timingValues.node[index].controlLatency,
            timingValues.node[index].discoveryLatencyTolerance);
   }
}


int main(int     argc,
         char   *argv[])
{
    MPIControl          control;
    MPIControlType      controlType;
    MPIControlAddress   controlAddress;
   MEISynqNet        synqNet;

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

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

   /* Display SynqNet timing information */
   displaySynqNetTiming(control, synqNet);

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

    return MPIMessageOK;
}


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