/*-=-=-=-=-=-=-=-=-=-=-=- 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:	getMisc
 *
 * DESCRIPTION:	Routines to read back parameter settings for miscellaneous
 *		RCCL 'set' primitives.
 *
 * AUTHOR/DATE:	John Lloyd, Fall 1988
 *
 * MODIFICATION HISTORY:
 *
 *--------------------------------------------------------------------------*/

#include "../h/cdefs.h"
#include "../h/robotMath.h"
#include "../h/rcclDefs.h"
#include "../h/errorCodes.h"
#include "../h/robot_kynvar.h"

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

getMod(mnp)
MANIP *mnp;
{
	/* RCCL primitive to read back the interpolation
	   mode setting */

	char *fxnName = "getMod()";
	MOTION_CONTROL_BLOCK *mcb = (MOTION_CONTROL_BLOCK*)mnp->mcb;

	switch (mcb->setInterMode)
	 { case JOINT:
	    { return ('j');
	      break;
	    }
	   case CARTESIAN:
	    { return ('c');
	      break;
	    }
	   default:
	    { rciAbort (EInternal, "%s -- bogus mode value %d\n",
				   fxnName, mcb->setInterMode);
	      return (-1);
	    }
	 }
}

getActiveMod(mnp)
MANIP *mnp;
{
	/* RCCL primitive to read back the interpolation
	   mode setting */

	char *fxnName = "getActiveMod()";
	MOTION_CONTROL_BLOCK *mcb = (MOTION_CONTROL_BLOCK*)mnp->mcb;

	switch (mcb->activeInterMode[mcb->pathsegIndex&1])
	 { case JOINT:
	    { return ('j');
	      break;
	    }
	   case CARTESIAN:
	    { return ('c');
	      break;
	    }
	   default:
	    { rciAbort (EInternal, "%s -- bogus mode value\n", fxnName);
	      return (-1);
	    }
	 }
}

getActiveConf (mnp, string)
MANIP *mnp;
char *string;
{
	/* RCCL primitive to read back the manipulator configuration. */

	char *fxnName = "getActiveConf()";

	int conf;

	if (mnp->objectFlag)
	 { return (0);
	 }
	conf = mnp->conf;
	if (string)
	 { configToStr (string, conf, mnp->kyn);
	 }
	return (conf);
}

getActiveMotionCounts (mnp, tau, sigma)
MANIP *mnp;
int *tau, *sigma;
{
	/* RCCL primtive to return the transition and path segment
	   counts associated with the current motion */

	char *fxnName = "getActiveMotionCounts()";

	MOTION_CONTROL_BLOCK *mcb = (MOTION_CONTROL_BLOCK*)mnp->mcb;
	register int index;
	int tauval, retval;

	do
	 { index = mcb->countIndex;
	   tauval = mcb->activeTau[index&1];
	   if (tauval)
	    { retval = mcb->activeCount[index&1] - (tauval+1);
	    }
	   else
	    { retval = mcb->activeCount[index&1];
	    }
	   if (tau)
	    { *tau = tauval;
	    }
	   if (sigma)
	    { *sigma = mcb->activeSigma[index&1];
	    }
	 }
	while ((index&~1) != (mcb->countIndex&~1));
	return (retval);
}

getActiveCount (mnp)
MANIP *mnp;
{
	/* Returns the count associated with the current motion */
	 
	char *fxnName = "getActiveCount()";

	MOTION_CONTROL_BLOCK *mcb = (MOTION_CONTROL_BLOCK*)mnp->mcb;

	return (mcb->activeCount[mcb->countIndex&1]);
}
