.

     

MPI Application Template
template.c
 

SQLogger.c -- Log SynqNet network status, packet errors, and CRCs to a file.
/* SQLogger.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.
 */

/*

:Log SynqNet network status, packet errors, and CRCs to a file.

This program demonstrates how to log SynqNet network status information
 to a file.  It is useful for monitoring network operation and/or
 debugging network problems.
 
By default, this program will check status information from the controller,
 network, and nodes every 200 milliseconds.  If there is a change in status,
 the data will be displayed and logged to a file (SQlog.txt).  The program
 will execute until a key is pressed.

The display information is in an easy to read format to fit within the screen.
 The log data is tab delimited for import into MS Excel.

Command line parameters allow the user to change the log file name (-file),
 disable the display update (-quiet), and adjust the update period (-period).

The following information is logged:
   Versions
   Network Topology
   Network Event Status
   Node Event Status
   Failed Node Mask
   Packet Error Counters
   CRCs

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"

/* Command line arguments and defaults */
char  *fileName   = "SQLog.txt";
long  quiet    = 0;
long  logPeriod   = 200;

Arg   argList[] = {
   {  "-file", ArgTypeTEXT,   &fileName,     },
   {  "-quiet",   ArgTypeNONE,   &quiet,        },
   {  "-period",  ArgTypeLONG,   &logPeriod,    },

   {  NULL,    ArgTypeINVALID,   NULL,       }
};


/* Parse the command line */
long parseCommandLine(int                 argc,
                      char               *argv[],
                      long               *synqNetNumber,
                      MPIControlType     *controlType,
                      MPIControlAddress  *controlAddress)
{
    long    argIndex;


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

    /* Parse command line for application-specific arguments */
    while (argIndex < argc) {
        long    argIndexNew;

        argIndexNew = argSet(argList, argIndex, argc, argv);

        if (argIndexNew <= argIndex) {
            argIndex = argIndexNew;
            break;
        }
        else {
            argIndex = argIndexNew;
        }
    }

   /* Check for unknown/invalid command line arguments */
   if (argIndex < argc) {
      mpiPlatformConsole("usage: crcLogger %s\n"
                     "\t\t[-file name (%s)] - specifies file name to log CRC counts\n"
                     "\t\t[-quiet (%d)]     - if set disables logging to screen\n"
                     "\t\t[-period (%d)]    - number of mSec to delay between samples\n",
                     ArgUSAGE,
                     fileName,
                     quiet,
                     logPeriod);

      exit(MPIMessageARG_INVALID);
   }

    return 0;
}


/* Create and initialize MPI objects */
void programInit(MPIControl        *control,
                 MPIControlType     controlType,
                 MPIControlAddress *controlAddress,
                 MPISynqNet        *synqNet,
                 long               synqNetNumber,
             MPISqNode        *sqNode,
             long          *nodeCount)
{
    long returnValue;

    /* Create motion controller object */
    *control =
        mpiControlCreate(controlType,
        controlAddress);
    msgCHECK(mpiControlValidate(*control));

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

    /* Create SynqNet object */
    *synqNet =
        mpiSynqNetCreate(*control,
        synqNetNumber);
    msgCHECK(mpiSynqNetValidate(*synqNet));

   if (*synqNet != NULL) {
      MPISynqNetInfo netInfo;
      long nodeIndex;

      returnValue =
         mpiSynqNetInfo(*synqNet,&netInfo);
      msgCHECK(returnValue);

      *nodeCount = netInfo.nodeCount;

      for(nodeIndex = netInfo.nodeOffset;
         nodeIndex < (netInfo.nodeOffset + netInfo.nodeCount);
         nodeIndex++) {

         sqNode[nodeIndex] =
            mpiSqNodeCreate(*control, nodeIndex);

         returnValue = mpiSqNodeValidate(sqNode[nodeIndex]);
         msgCHECK(returnValue);
      }
   }
}


/* Perform certain cleanup actions and delete MPI objects */
void programCleanup(MPIControl   *control,
                    MPISynqNet   *synqNet,
               MPISqNode   *sqNode,
               long     nodeCount)
{
   long returnValue;
   long i;

   for (i=0; i<nodeCount; i++) {
      /* Delete node handle */
      returnValue =
         mpiSqNodeDelete(sqNode[i]);
      msgCHECK(returnValue);
   }
    returnValue =
        mpiSynqNetDelete(*synqNet);
    msgCHECK(returnValue);

    *synqNet = MPIHandleVOID;

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

    *control = MPIHandleVOID;
}

void displayNetworkStringInfo(MPISynqNet synqNet,
                       MPISqNode  *sqNode,
                       long       nodeCount,
                       FILE       *logFile)
{
   MPINetworkObjectInfo info;
   MPI_BOOL terminated;
   long port;
   long returnValue;
   long count;

   for (port=MPINetworkPortFIRST; port<MPINetworkPortLAST; port++) {

      count = 0;  /* init node count on this port */
      terminated = FALSE;

      returnValue =
         mpiSynqNetNetworkObjectNext(synqNet, port, &info);
      msgCHECK(returnValue);

      while (info.type == MPINetworkObjectTypeSQNODE) {
         count++;
         returnValue =
            mpiSqNodeNetworkObjectNext(sqNode[info.number], port, &info);
         msgCHECK(returnValue);
      }

      if (info.type == MPINetworkObjectTypeTERMINATOR) {
         terminated = TRUE;
      }

      if (!quiet) {
         mpiPlatformConsole("\n  %s : %d nodes %s",
                        (port == MPINetworkPortOUT0) ? "Out port" : "In port ",
                        count,
                        (terminated) ? "[terminated]" : "");
      }

      fprintf(logFile, "\n  %s : %d nodes %s",
                     (port == MPINetworkPortOUT0) ? "Out port" : "In port ",
                     count,
                     (terminated) ? "[terminated]" : "");

      if (info.type == MPINetworkObjectTypeSYNQNET) {
         break;      /* reached the synqnet controller, quit. */
      }
   }

   mpiPlatformConsole("\n");
}

/* Log version information */
long logVersion(MPIControl control,
            MPISynqNet synqNet,
            MPISqNode  *node,
            long     nodeCount,
            FILE *logFile)
{
   MPISynqNetInfo          netInfo;
   MPISqNodeInfo           info;
   MPIControlInfo          controlInfo;

   long  returnValue;   /* return value from library */
   long  nodeIndex;

   returnValue =
      mpiControlInfo(control,
                  &controlInfo);

   if (!quiet) {
      mpiPlatformConsole("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);

      if (controlInfo.firmware.zmp.boot0Version) {
         mpiPlatformConsole("\n\nBoot0 Version %d.%3.3d\n",
                        controlInfo.firmware.zmp.boot0Version,
                        controlInfo.firmware.zmp.boot0Revision);
      }

      if (controlInfo.firmware.zmp.zbootVersion) {
         mpiPlatformConsole("ZBoot Version %d.%3.3d\n",
                        controlInfo.firmware.zmp.zbootVersion,
                        controlInfo.firmware.zmp.zbootRevision);
      }

      mpiPlatformConsole("\nPLD   : version %s option %s\n",
                     controlInfo.pld.version,
                     controlInfo.pld.option);

      mpiPlatformConsole("Rincon: version %s package %s\n",
                     controlInfo.rincon.version,
                     controlInfo.rincon.package);

      mpiPlatformConsole("%s   : %s  Serial Number %s\n",
                     controlInfo.hardware.type,
                     controlInfo.hardware.modelNumber,
                     controlInfo.hardware.serialNumber);
   }


   fprintf(logFile,
         "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);

   if (controlInfo.firmware.zmp.boot0Version) {
      fprintf(logFile,
            "\n\nBoot0 Version %d.%3.3d\n",
            controlInfo.firmware.zmp.boot0Version,
            controlInfo.firmware.zmp.boot0Revision);
   }

   if (controlInfo.firmware.zmp.zbootVersion) {
      fprintf(logFile,
            "ZBoot Version %d.%3.3d\n",
            controlInfo.firmware.zmp.zbootVersion,
            controlInfo.firmware.zmp.zbootRevision);
   }

   fprintf(logFile,
         "\nPLD   : version %s option %s\n",
         controlInfo.pld.version,
         controlInfo.pld.option);

   fprintf(logFile,
         "Rincon: version %s package %s\n",
         controlInfo.rincon.version,
         controlInfo.rincon.package);

   fprintf(logFile,
         "%s   : %s  Serial Number %s\n",
         controlInfo.hardware.type,
         controlInfo.hardware.modelNumber,
         controlInfo.hardware.serialNumber);

   returnValue =
      mpiSynqNetInfo(synqNet,&netInfo);
   msgCHECK(returnValue);

   if(netInfo.nodeCount > 0) {
      char *type;

      switch(netInfo.networkType) {
         case MPINetworkTypeSTRING: {
            type = "String";
            break;
         }
         case MPINetworkTypeRING: {
            type = "Ring";
            break;
         }
         case MPINetworkTypeSTRING_DUAL: {
            type = "Dual-String";
            break;
         }
         default: {
            type = "Unknown";
         }
      }

      if (!quiet) {
         mpiPlatformConsole("\nSynqnet: %2ld Nodes, %s", netInfo.nodeCount, type);
      }
      fprintf(logFile, "\nSynqnet: %2ld Nodes, %s", netInfo.nodeCount, type);

      if (netInfo.networkType != MPINetworkTypeRING) {
         displayNetworkStringInfo(synqNet, node, nodeCount, logFile);
      }

      for(nodeIndex = netInfo.nodeOffset;
         nodeIndex < (netInfo.nodeOffset + netInfo.nodeCount);
         nodeIndex++) {

         returnValue =
            mpiSqNodeInfo(node[nodeIndex], &info);
         msgCHECK(returnValue);

         if (!quiet) {
            mpiPlatformConsole("\nNode[%d] - %s\n"
                        "  Node Type : 0x%8.8X"
                        "\tFPGA ID     : 0x%8.8X\n"
                        "  Option #  : 0x%8.8X"
                        "\tFPGA Ver    : 0x%8.8lX\n",
                        (nodeIndex - netInfo.nodeOffset),
                        info.id.nodeName,
                        info.id.nodeType,
                        info.fpga.vendorDevice,
                        info.id.option,
                        info.fpga.version);
         }
         fprintf(logFile,
               "\nNode[%d] - %s\n"
               "  Node Type : 0x%8.8X"
               "\tFPGA ID     : 0x%8.8X\n"
               "  Option #  : 0x%8.8X"
               "\tFPGA Ver    : 0x%8.8lX\n",
               (nodeIndex - netInfo.nodeOffset),
               info.id.nodeName,
               info.id.nodeType,
               info.fpga.vendorDevice,
               info.id.option,
               info.fpga.version);
      }
   }

   return (returnValue);
}


/* Monitor SynqNet status */
void monitorSynqNetStatus(MPIControl control,
                          MPISynqNet synqNet,
                    FILE *logFile)
{
   MPISqNode         sqNode[MPISynqNetMaxNODE_COUNT];
   MPISynqNetInfo    netInfo;
   MPISynqNetStatus  netStatus;
   MPISynqNetStatus  initNetStatus;
   MPISqNodeStatus      nodeStatus[MPISynqNetMaxNODE_COUNT];
   MPISqNodeStatus      initNodeStatus[MPISynqNetMaxNODE_COUNT];

   long     returnValue;
   long     index;
   long     sampleCounter;
   long     logCounter = 0;
   MPI_BOOL statusChanged;
   long     networkNotSynq = 0;
   double   sampleRate;


   /* Read Controller Sample Rate Info */
   returnValue =
      mpiControlSampleRate(control,
                      &sampleRate);
   msgCHECK(returnValue);

   if (!quiet) {
      mpiPlatformConsole("\nSample Rate: %.2lf\n", sampleRate);
   }
   fprintf(logFile,"\nSample Rate: %.2lf\n", sampleRate);

    /* Read SynqNet Info */
    returnValue =
        mpiSynqNetInfo(synqNet, &netInfo);
    msgCHECK(returnValue);

    /* Read initial SynqNet and Node Status */
    returnValue =
        mpiSynqNetStatus(synqNet,
                         &initNetStatus);
    msgCHECK(returnValue);

   /* Log headings */
   fprintf(logFile, "\nNote: Log data is tab delimited for import into MS Excel.\n");
   fprintf(logFile,
      "\nEntry\t"
      "Sample\t"
      "SqState\t"
      "InPortCRC\t"
      "OutPortCRC\t"
      "FailNodeMask\t"
      "NetworkDead\t"
      "RxFail\t"
      "TxFail\t"
      "NodeFail\t"
      "Recovery\t");

    if (netInfo.nodeCount) {
        for (index = netInfo.nodeOffset;
             index < (netInfo.nodeOffset + netInfo.nodeCount);
             index++) {

            sqNode[index] =
                mpiSqNodeCreate(control, index);
            msgCHECK(mpiSqNodeValidate(sqNode[index]));

         returnValue =
            mpiSqNodeStatus(sqNode[index], &initNodeStatus[index]);
         msgCHECK(returnValue);

         /* Log headings */
         fprintf(logFile,
            "Node\t"
            "UpstreamError\t"
            "DownstreamError\t"
            "InPortCRC\t"
            "OutPortCRC\t"
            "IoAbort\t"
            "NodeDisable\t"
            "NodeAlarm\t"
            "PowerFail\t"
            "UserFault\t"
            "NodeFail\t");
        }
    }
    else {
        printf("No SynqNet Nodes found.\n");
    }

   mpiPlatformConsole("\nPress any key to exit...\n\n");
   mpiPlatformSleep(logPeriod);

   /* Force initial values to be logged */
   statusChanged = TRUE;
   while (mpiPlatformKey(MPIWaitPOLL) <= 0) {
      returnValue =
         mpiControlSampleCounter(control,
                           &sampleCounter);
      msgCHECK(returnValue);

      returnValue =
         mpiSynqNetStatus(synqNet, &netStatus);

      if (returnValue != MPIMessageOK) {
         if (!quiet) {
            mpiPlatformConsole("mpiSynqNetStatus(...) returns 0x%x: %s\n",
                    returnValue,
                    mpiMessage(returnValue, NULL));
         }
         fprintf(logFile,
               "mpiSynqNetStatus(...) returns 0x%x: %s\n",
                    returnValue,
                    mpiMessage(returnValue, NULL));
      }

        for (index = netInfo.nodeOffset;
             index < (netInfo.nodeOffset + netInfo.nodeCount);
             index++) {
         returnValue =
            mpiSqNodeStatus(sqNode[index], &nodeStatus[index]);

         if (returnValue != MPIMessageOK) {
            if (!quiet) {
               mpiPlatformConsole("Node: %ld mpiSqNodeStatus(...) returns 0x%x: %s\n",
                  index,
                  returnValue,
                  mpiMessage(returnValue, NULL));
            }
            fprintf(logFile,
                  "Node: %ld mpiSqNodeStatus(...) returns 0x%x: %s\n",
                  index,
                  returnValue,
                  mpiMessage(returnValue, NULL));        }
        }

      /* Check for a status value change */
      if (initNetStatus.state != netStatus.state) {
         statusChanged = TRUE;
         /* store for next pass */
         initNetStatus.state = netStatus.state;
      }

      if (initNetStatus.failedNodeMask[0] != netStatus.failedNodeMask[0]) {
         statusChanged = TRUE;
         /* store for next pass */
         initNetStatus.failedNodeMask[0] = netStatus.failedNodeMask[0];
      }

      if ((initNetStatus.eventMask[0] != netStatus.eventMask[0]) ||
         (initNetStatus.eventMask[1] != netStatus.eventMask[1])) {
         statusChanged = TRUE;
         /* store for next pass */
         initNetStatus.eventMask[0] = netStatus.eventMask[0];
         initNetStatus.eventMask[1] = netStatus.eventMask[1];
      }

      if ((initNetStatus.crcError.port[MPINetworkPortIN0] !=
            netStatus.crcError.port[MPINetworkPortIN0]) ||
         (initNetStatus.crcError.port[MPINetworkPortOUT0] !=
            netStatus.crcError.port[MPINetworkPortOUT0])) {
         statusChanged = TRUE;
         /* store for next pass */
         initNetStatus.crcError.port[MPINetworkPortIN0] =
            netStatus.crcError.port[MPINetworkPortIN0];
         initNetStatus.crcError.port[MPINetworkPortOUT0] =
            netStatus.crcError.port[MPINetworkPortOUT0];
      }

      for (index = netInfo.nodeOffset;
          index < (netInfo.nodeOffset + netInfo.nodeCount);
          index++) {
         if ((initNodeStatus[index].upStreamError.count !=
               nodeStatus[index].upStreamError.count) ||
            (initNodeStatus[index].downStreamError.count !=
               nodeStatus[index].downStreamError.count) ||
            (initNodeStatus[index].crcError.port[MPINetworkPortIN0] !=
               nodeStatus[index].crcError.port[MPINetworkPortIN0]) ||
            (initNodeStatus[index].crcError.port[MPINetworkPortOUT0] !=
               nodeStatus[index].crcError.port[MPINetworkPortOUT0])) {
            statusChanged = TRUE;
            /* store for next pass */
            initNodeStatus[index].upStreamError.count =
               nodeStatus[index].upStreamError.count;
            initNodeStatus[index].downStreamError.count =
               nodeStatus[index].downStreamError.count;
            initNodeStatus[index].crcError.port[MPINetworkPortIN0] =
               nodeStatus[index].crcError.port[MPINetworkPortIN0];
            initNodeStatus[index].crcError.port[MPINetworkPortOUT0] =
               nodeStatus[index].crcError.port[MPINetworkPortOUT0];
         }
      }

      /* Log data if any value changed */
      if (statusChanged) {
         logCounter++;
         if (!quiet) {
            mpiPlatformConsole("\n***** Log Entry #%ld *****\n"
                           "Controller\n"
                           " Sample Counter      : %ld\n"
                           " Network State       : %ld\n"
                           " In Port CRC Errors  : %ld\n"
                           " Out Port CRC Errors : %ld\n"
                           " Failed Node Mask    : 0x%X\n"
                              " Network Dead Event  : %d\n"
                           " Rx Failure Event    : %d\n"
                           " Tx Failure Event    : %d\n"
                           " Node Failure Event  : %d\n"
                           " Recovery Event      : %d\n\n",
                           logCounter,
                           sampleCounter,
                           netStatus.state,
                           netStatus.crcError.port[MPINetworkPortIN0],
                           netStatus.crcError.port[MPINetworkPortOUT0],
                           netStatus.failedNodeMask[0],
                           mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_DEAD),
                            mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_RX_FAILURE),
                            mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_TX_FAILURE),
                            mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_NODE_FAILURE),
                            mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_RECOVERY));
         }
         fprintf(logFile,
               "\n%ld\t"
                "%ld\t"
                "%ld\t"
                "%ld\t"
                "%ld\t"
                "0x%X\t"
                "%d\t"
                "%d\t"
                "%d\t"
                "%d\t"
                "%d\t",
               logCounter,
               sampleCounter,
               netStatus.state,
               netStatus.crcError.port[MPINetworkPortIN0],
               netStatus.crcError.port[MPINetworkPortOUT0],
               netStatus.failedNodeMask[0],
               mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_DEAD),
               mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_RX_FAILURE),
               mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_TX_FAILURE),
               mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_NODE_FAILURE),
               mpiEventMaskBitGET(netStatus.eventMask, MPIEventTypeSYNQNET_RECOVERY));

         for (index = netInfo.nodeOffset;
             index < (netInfo.nodeOffset + netInfo.nodeCount);
             index++) {

            if (!quiet) {
               mpiPlatformConsole("Node %ld\n"
                     " Upstream Error Count  : %ld\n"
                     " Downstream Error Count: %ld\n"
                     " In Port CRC Errors    : %ld\n"
                     " Out Port CRC Errors   : %ld\n"
                     " IoAbort Event         : %d\n"
                     " Node Disable Event    : %d\n"
                     " Node Alarm Event      : %d\n"
                     " Power Failure Event   : %d\n"
                     " User Fault Event      : %d\n"
                     " Node Failure Event    : %d\n\n",
                     index,
                     nodeStatus[index].upStreamError.count,
                     nodeStatus[index].downStreamError.count,
                     nodeStatus[index].crcError.port[MPINetworkPortIN0],
                     nodeStatus[index].crcError.port[MPINetworkPortOUT0],
                     mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_IO_ABORT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_NODE_DISABLE),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_NODE_ALARM),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_ANALOG_POWER_FAULT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_USER_FAULT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_NODE_FAILURE));
            }
            fprintf(logFile,
                     "%ld\t"
                     "%ld\t"
                     "%ld\t"
                     "%ld\t"
                     "%ld\t"
                     "%d\t"
                     "%d\t"
                     "%d\t"
                     "%d\t"
                     "%d\t"
                     "%d\t",
                     index,
                     nodeStatus[index].upStreamError.count,
                     nodeStatus[index].downStreamError.count,
                     nodeStatus[index].crcError.port[MPINetworkPortIN0],
                     nodeStatus[index].crcError.port[MPINetworkPortOUT0],
                     mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_IO_ABORT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_NODE_DISABLE),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_NODE_ALARM),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_ANALOG_POWER_FAULT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_USER_FAULT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MPIEventTypeSQNODE_NODE_FAILURE));
         }
      }

      /* re-arm status display flag */
      statusChanged = FALSE;
      mpiPlatformSleep(logPeriod);
   }

   returnValue =
      mpiControlSampleCounter(control,
                        &sampleCounter);
   msgCHECK(returnValue);

   if (!quiet) {
      mpiPlatformConsole("Exit at sample: %ld\n", sampleCounter);
   }
   fprintf(logFile, "\nExit\t%ld", sampleCounter);

   /* Clean-up */
    for (index = netInfo.nodeOffset;
         index < (netInfo.nodeOffset + netInfo.nodeCount);
         index++) {

        returnValue =
            mpiSqNodeDelete(sqNode[index]);
        msgCHECK(returnValue);
    }
}


int main(int    argc,
         char   *argv[])
{
    MPIControl          control;
    MPIControlType      controlType;
    MPIControlAddress   controlAddress;
   MPISqNode         sqNode[MPISynqNetMaxNODE_COUNT];
   long           nodeCount;
    MPISynqNet          synqNet;
   MPISynqNetStatus  synqNetStatus;
    long                synqNetNumber = 0;
    long                returnValue;

   FILE  *logFile;

    /* Parse command line */
    returnValue =
        parseCommandLine(argc,
                         argv,
                         &synqNetNumber,
                         &controlType,
                         &controlAddress);
    msgCHECK(returnValue);

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

   returnValue =
      mpiSynqNetStatus(synqNet, &synqNetStatus);
   msgCHECK(returnValue);

   if (synqNetStatus.state != MPISynqNetStateSYNQ &&
      synqNetStatus.state != MPISynqNetStateSYNQ_RECOVERING) {
      mpiPlatformConsole("ERROR: Network must be in SYNQ mode to log status\n\n");
      exit(-2);
   }

   /* open log file for writing */
   logFile = fopen(fileName, "w");

   if (logFile == NULL) {
      mpiPlatformConsole("\nCannot open %s for writing.\n",
                     fileName);
      exit(-1);
   }

   /* log version info */
   logVersion(control, synqNet, sqNode, nodeCount, logFile);

   /* log network and node status */
   monitorSynqNetStatus(control, synqNet, logFile);

   fclose(logFile);

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

    return ((int)returnValue);
}


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