#include "../h/rci.h"
#include <sys/time.h>			/* to get 'struct timeval' */

extern int simRobotsReady();

startupFxn (td)
RCI_DESC *td;
{
	RCI_RBT *rbt = TASKROBOT(td, 0);

	if (td->tcb->scheduleDisp == ON_SIGNAL)
	 { rciWakeupOn (td, simRobotsReady, (int)td);
	   simSetTimer (td->tcb->interval, (struct timeval*)NULL);
	 }
	(*rbt->startup)(td, rbt);
}

controlFxn (td)
RCI_DESC *td;
{
	RCI_RBT *rbt = TASKROBOT(td, 0);
	struct timeval cycleStartTime;

	getSystemTime(&cycleStartTime);

        (*rbt->input)(td, rbt);
        (*rbt->output)(td, rbt);

	/* ... presumably some time may elapse here ... */

        printf ("doing robot control\n");

        if (td->tcb->scheduleDisp == ON_SIGNAL)
         { simSetTimer (td->tcb->interval, &cycleStartTime);
         }
}

releaseFxn (td, arg, code)
RCI_DESC *td;
int arg, code;
{
	RCI_RBT *rbt = TASKROBOT(td, 0);

	(*rbt->release)(td, rbt, code == RELEASE_REQ ? RBT_NORMAL : 
						       RBT_HARDERROR );
}
