recorderinuse.c -- Shows Recorders taking resources and active recorders. Can kill inactive recorders.
/* recorderinuse.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.
*/
/*
: Shows Recorders taking resources and active recorders. Can kill inactive recorders.
This program kills inactive recorders. Uses the MPI interface for identifying and
freeing reorders to determine the inactive recorder(s).
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 <conio.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)
{
long returnValue;
/* Create motion controller object */
*control =
mpiControlCreate(controlType, controlAddress);
msgCHECK(mpiControlValidate(*control));
/* Initialize motion controller */
returnValue =
mpiControlInit(*control);
msgCHECK(returnValue);
}
/* Perform certain cleanup actions and delete MPI objects */
void programCleanup(MPIControl *control)
{
long returnValue;
/* Delete motion controller object */
returnValue =
mpiControlDelete(*control);
msgCHECK(returnValue);
*control = MPIHandleVOID;
}
/*
This function:
1) Looks to see what reserved recorders are currently disabled. This is a
big hint about whether a recorder got abandoned. An abandoned
recorder will be disabled, but will show up as a reserved recorder.
Make sure you have no reason to think a recorder is being
used before kicking it off with meiControlRecorderCancel().
2) Assumes that a well written recorder object would never let the
recorder buffer go without collecting the recorded data so long
that the buffer get completely full. This sort of behavior is what
happens when a program crashes that has a recorder operating. All full
recorders that are running are represented in the stalledMask
3) Stores a bit mask of the recorders running, but is very different from
the number of recorders enabled in firmware. The runningMask tells you
which recorders think they are currently recording.
*/
long recordersStatusMasks(MPIControl control,
long *disabledMask,
long *stalledMask,
long *runningMask)
{
MPIControlConfig config;
long returnValue = MPIMessageOK;
long recorderIndex;
*disabledMask = *stalledMask = *runningMask = 0x0;
returnValue = mpiControlConfigGet(control, &config, NULL);
if(returnValue == MPIMessageOK)
{
if(config.recorderCount < 0)
{
returnValue = MPIRecorderMessageNO_RECORDERS_AVAIL;
}
else {
for(recorderIndex = 0; recorderIndex < config.recorderCount; recorderIndex++)
{
MPIRecorderStatus status;
returnValue =
meiControlRecorderStatus(control, recorderIndex, &status);
if(returnValue == MPIMessageOK)
{
if((status.reserved == TRUE) &&
(status.enabled == FALSE))
{
*disabledMask |= 1<<recorderIndex;
}
if(status.enabled == TRUE)
{
if (status.full == TRUE)
{
*stalledMask |= 1<<recorderIndex;
}
else {
*runningMask |= 1<<recorderIndex;
}
}
}
}
}
}
return (returnValue);
}
/*
clears the reservation for all non-running recorders
*/
long recordersCancel(MPIControl control,
long disabledMask,
long stalledMask)
{
long returnValue = MPIMessageOK;
long recorderIndex;
for(recorderIndex = 0; recorderIndex < sizeof(long); recorderIndex++)
{
if ((disabledMask & (1<<recorderIndex)) ||
(stalledMask & (1<<recorderIndex)))
{
returnValue =
meiControlRecorderCancel(control, recorderIndex);
if (returnValue != MPIMessageOK) {
break;
}
}
}
return (returnValue);
}
int main(int argc,
char *argv[])
{
MPIControl control;
MPIControlType controlType;
MPIControlAddress controlAddress;
MPI_BOOL done = FALSE;
long returnValue;
char key;
long disabledMask;
long stalledMask;
long runningMask;
/* Perform basic command line parsing. (-control -server -port -trace) */
basicParsing(argc,
argv,
&controlType,
&controlAddress);
/* Create and initialize MPI objects */
programInit(&control,
controlType,
&controlAddress);
printf("\nPress 'k' to kill all non active recorders. \nAny other key to exit.\n\n");
/* Display in use status and shutdown recorders if requested */
while (!done)
{
key = (char) meiPlatformKey(MPIWaitMSEC*100);
if (key >= 0) /* k >= indicates a key has been pressed */
{
if(key != 'k') done = TRUE;
else
{
returnValue =
recordersCancel(control, disabledMask, stalledMask);
}
}
returnValue =
recordersStatusMasks(control,
&disabledMask,
&stalledMask,
&runningMask);
msgCHECK(returnValue);
printf("RecorderMasks: Disabled 0x%x\t Stalled 0x%x\t Active 0x%x\t\t\r",
disabledMask, stalledMask, runningMask);
}
printf("\n\n");
/* Perform certain cleanup actions and delete MPI objects */
programCleanup(&control);
return MPIMessageOK;
}
|