.

     

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) {
      meiPlatformConsole("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,
                 MEISynqNet        *synqNet,
                 long               synqNetNumber,
             MEISqNode        *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 =
        meiSynqNetCreate(*control,
        synqNetNumber);
    msgCHECK(meiSynqNetValidate(*synqNet));

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

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

      *nodeCount = netInfo.nodeCount;

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

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

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


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

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

    *synqNet = MPIHandleVOID;

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

    *control = MPIHandleVOID;
}

void displayNetworkStringInfo(MEISynqNet synqNet,
                       MEISqNode  *sqNode,
                       long       nodeCount,
                       FILE       *logFile)
{
   MEINetworkObjectInfo info;
   MPI_BOOL terminated;
   long port;
   long returnValue;
   long count;

   for (port=MEINetworkPortFIRST; port<MEINetworkPortLAST; port++) {

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

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

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

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

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

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

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

   meiPlatformConsole("\n");
}

/* Log version information */
long logVersion(MPIControl control,
            MEISynqNet synqNet,
            MEISqNode  *node,
            long     nodeCount,
            FILE *logFile)
{
   MEISynqNetInfo          netInfo;
   MEISqNodeInfo           info;
   MEIControlInfo          controlInfo;

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

   returnValue =
      meiControlInfo(control,
                  &controlInfo);

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

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

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

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

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

      meiPlatformConsole("%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 =
      meiSynqNetInfo(synqNet,&netInfo);
   msgCHECK(returnValue);

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

      switch(netInfo.networkType) {
         case MEINetworkTypeSTRING: {
            type = "String";
            break;
         }
         case MEINetworkTypeRING: {
            type = "Ring";
            break;
         }
         case MEINetworkTypeSTRING_DUAL: {
            type = "Dual-String";
            break;
         }
         default: {
            type = "Unknown";
         }
      }

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

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

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

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

         if (!quiet) {
            meiPlatformConsole("\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,
                          MEISynqNet synqNet,
                    FILE *logFile)
{
   MEISqNode         sqNode[MEISynqNetMaxNODE_COUNT];
   MEISynqNetInfo    netInfo;
   MEISynqNetStatus  netStatus;
   MEISynqNetStatus  initNetStatus;
   MEISqNodeStatus      nodeStatus[MEISynqNetMaxNODE_COUNT];
   MEISqNodeStatus      initNodeStatus[MEISynqNetMaxNODE_COUNT];

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


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

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

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

    /* Read initial SynqNet and Node Status */
    returnValue =
        meiSynqNetStatus(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] =
                meiSqNodeCreate(control, index);
            msgCHECK(meiSqNodeValidate(sqNode[index]));

         returnValue =
            meiSqNodeStatus(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");
    }

   meiPlatformConsole("\nPress any key to exit...\n\n");
   meiPlatformSleep(logPeriod);

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

      returnValue =
         meiSynqNetStatus(synqNet, &netStatus);

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

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

         if (returnValue != MPIMessageOK) {
            if (!quiet) {
               meiPlatformConsole("Node: %ld meiSqNodeStatus(...) returns 0x%x: %s\n",
                  index,
                  returnValue,
                  mpiMessage(returnValue, NULL));
            }
            fprintf(logFile,
                  "Node: %ld meiSqNodeStatus(...) 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[MEINetworkPortIN0] !=
            netStatus.crcError.port[MEINetworkPortIN0]) ||
         (initNetStatus.crcError.port[MEINetworkPortOUT0] !=
            netStatus.crcError.port[MEINetworkPortOUT0])) {
         statusChanged = TRUE;
         /* store for next pass */
         initNetStatus.crcError.port[MEINetworkPortIN0] =
            netStatus.crcError.port[MEINetworkPortIN0];
         initNetStatus.crcError.port[MEINetworkPortOUT0] =
            netStatus.crcError.port[MEINetworkPortOUT0];
      }

      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[MEINetworkPortIN0] !=
               nodeStatus[index].crcError.port[MEINetworkPortIN0]) ||
            (initNodeStatus[index].crcError.port[MEINetworkPortOUT0] !=
               nodeStatus[index].crcError.port[MEINetworkPortOUT0])) {
            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[MEINetworkPortIN0] =
               nodeStatus[index].crcError.port[MEINetworkPortIN0];
            initNodeStatus[index].crcError.port[MEINetworkPortOUT0] =
               nodeStatus[index].crcError.port[MEINetworkPortOUT0];
         }
      }

      /* Log data if any value changed */
      if (statusChanged) {
         logCounter++;
         if (!quiet) {
            meiPlatformConsole("\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[MEINetworkPortIN0],
                           netStatus.crcError.port[MEINetworkPortOUT0],
                           netStatus.failedNodeMask[0],
                           mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_DEAD),
                            mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_RX_FAILURE),
                            mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_TX_FAILURE),
                            mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_NODE_FAILURE),
                            mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_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[MEINetworkPortIN0],
               netStatus.crcError.port[MEINetworkPortOUT0],
               netStatus.failedNodeMask[0],
               mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_DEAD),
               mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_RX_FAILURE),
               mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_TX_FAILURE),
               mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_NODE_FAILURE),
               mpiEventMaskBitGET(netStatus.eventMask, MEIEventTypeSYNQNET_RECOVERY));

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

            if (!quiet) {
               meiPlatformConsole("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[MEINetworkPortIN0],
                     nodeStatus[index].crcError.port[MEINetworkPortOUT0],
                     mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_IO_ABORT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_NODE_DISABLE),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_NODE_ALARM),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_ANALOG_POWER_FAULT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_USER_FAULT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_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[MEINetworkPortIN0],
                     nodeStatus[index].crcError.port[MEINetworkPortOUT0],
                     mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_IO_ABORT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_NODE_DISABLE),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_NODE_ALARM),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_ANALOG_POWER_FAULT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_USER_FAULT),
                      mpiEventMaskBitGET(nodeStatus[index].eventMask, MEIEventTypeSQNODE_NODE_FAILURE));
         }
      }

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

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

   if (!quiet) {
      meiPlatformConsole("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 =
            meiSqNodeDelete(sqNode[index]);
        msgCHECK(returnValue);
    }
}


int main(int    argc,
         char   *argv[])
{
    MPIControl          control;
    MPIControlType      controlType;
    MPIControlAddress   controlAddress;
   MEISqNode         sqNode[MEISynqNetMaxNODE_COUNT];
   long           nodeCount;
    MEISynqNet          synqNet;
   MEISynqNetStatus  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 =
      meiSynqNetStatus(synqNet, &synqNetStatus);
   msgCHECK(returnValue);

   if (synqNetStatus.state != MEISynqNetStateSYNQ &&
      synqNetStatus.state != MEISynqNetStateSYNQ_RECOVERING) {
      meiPlatformConsole("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) {
      meiPlatformConsole("\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