/*-=-=-=-=-=-=-=-=-=-=-=- 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.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#ifndef _MONITOR_H_
#define _MONITOR_H_

#include "../h/cdefs.h"
#include "../h/rciConfig.h"
#include "../robots/robotData.h"
#include "../h/robotComfxns.h"
#include "../h/rciTask.h"
#include "../h/robot_jls.h"
#include "../h/robot_kynvar.h"
#include "../h/IOdevice.h"

/* sizes of the buffers associated with monitor communication */

#define MON_MSGBUF_SIZE		512	/* per-monitor command */
#define MON_READBUF_SIZE       4096	/* global shared data area */

/* termination code passed to the wrapup functions: */

#define MON_COMSIG		2 	/* monitor communication signal */

/* command codes sent to the monitors through the variable moncomCmd[] */

#define MON_INITIALIZE		1
#define MON_SETUP_TASK		2
#define MON_TASK_INIT		3
#define MON_SETUP_CLOCK		4
#define MON_START_TASKS		5
#define MON_SETUP_ROBOT		6
#define MON_ATTACH_ROBOT	7
#define MON_DETACH_ROBOT	8

#define MON_START_CLOCK		9
#define MON_IMPORT_CLOCK	10
#define MON_EXPORT_CLOCK	11
#define MON_MSGMEM_ASSIGN	12

#define MON_USERLEVEL		0x80	/* command executed at user level */

/* message structures associated with different monitor commands */

struct setupTaskMsg {
  	int id;
  	int taskCpu;
  	void *shareMem;
  	void *localMem;
	char name[TASK_NAME_SIZE+1];
	int flags;
#define TASK_HOST	0x01
  };

struct setupClockMsg {
	int clockCpu;
	float resolution;
  	int export[MAX_CPUS];
  };


struct clockControlMsg {
	int reInitClock;
	int hostCpu;
	int targetCpu;
	int exportCode;
	float resolution;
	float oldResolution;
};

struct startTasksMsg {
	int activate[MAX_CPUS];
  };

struct setupRobotMsg {
	int id;
	int class;
	void *shareMem;
	void *localMem;
	JLS *jls;
	GEN_KYN *kynGen;
	void *kynPar;
	int kynSize;
	int varSize;

	ROBOT_COMFXNS comfxns;
	char *name;
	int nameLength;
  };

struct attachRobotMsg {
	int taskId;
	int num;
	void *localMem;
  	void *shareMem;
	IO_DEVICE dev;
	int flags;
#define ROBOT_HOST	0x01	
	int idev;
  };

struct detachRobotMsg {
	int taskId;
	int num;
  };  	

struct msgMemoryMsg {
	int cpu;
  	void *addr;
};

extern char moncomMsgBuf[MAX_CPUS][MON_MSGBUF_SIZE];
extern char moncomReadBuf[MON_READBUF_SIZE];

#define PUT_MSG(msg,type,cpu)	*(struct type*)&moncomMsgBuf[cpu][0] = (msg);

/* per task commands, specfied for each task by the planner in the 
   tcb field 'cmodeReq' */

#define SET_IDLE		1
#define SET_ACTIVE_GO		2
#define SET_ACTIVE_WAIT		3
#define SET_ACTIVE_SYNC		4	

#endif
