/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
/*---------------------------------------------------------------------------
 *		
 * MODULE NAME:	getManip.c
 *
 * DESCRIPTION:	Routines to access the MANIP structure for a particular
 *		manipulator.
 * 
 * AUTHOR/DATE:	John Lloyd, September, 1988
 *
 *-------------------------------------------------------------------------*/

#include "../h/rcclDefs.h"
#include "../rccl/setpoint.h"

extern MANIP_RECORD *rcclManipTable;
extern int rcclTaskInitDone;
extern MANIP *rcclManipPool[MAX_CPUS];
extern int rciCpu;

MANIP *getManipByAddr (mnp)
MANIP *mnp;
{
	/* finds the pointer to MANIP given the address used by the
	   planning task as a key */

	RCCL_GMEM *gmem;

	char *fxnName = "getManipByAddr()";
	int offset;

	if (rcclTaskInitDone != rciCpu)
	 { return (NULL);
	 }
	if ((gmem = globalMemoryCheck (fxnName)) == NULL)
	 { return (NULL);
	 }
	offset = (int)mnp - (int)gmem->manipPool[ARBITER_CPU];
	if (offset >= 0 && (offset%sizeof(MANIP) == 0) && 
	    offset/sizeof(MANIP) < MAX_MANIPS)
	 { return (&rcclManipPool[rciCpu][offset/sizeof(MANIP)]);
	 }	
}

MANIP *getManipByName (name)
const char *name;
{
	/* finds the pointer to MANIP using the name of the manipulator
	   as a key */

	int k;

	if (rcclTaskInitDone != rciCpu)
	 { return (NULL);
	 }
	for (k=0; k<MAX_MANIPS; k++)
	 { if (rcclManipTable[k].allocated &&
	       (strcmp (name, rcclManipTable[k].mnp->name) == 0))
	    { return (rcclManipTable[k].mnp);
	    }
	 }
	return (NULL);
}
