/* 
 * Thomas Pantzer: t_msgtype.h, v0.1b  8.6.99 16:49 
 * 
 * 
 * Copyright 1999 by Thomas Pantzer
 * 
 * Permission to use, copy, modify, and distribute this software for noncommercial 
 * use and without fee is hereby granted, provided that the above copyright notice 
 * appear in all copies and that both that copyright notice and this permission 
 * notice appear in supporting documentation, and that the name of the Author not be 
 * used in advertising or publicity pertaining to distribution of the software 
 * without specific, written prior permission. The Author makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is" 
 * without expressed or implied warranty. 
 * 
 * 
 * pantec@isys2.informatik.uni-leipzig.de   (Thomas Pantzer) 
 * 
 */





#ifndef _T_MSGTYPE_H
#define _T_MSGTYPE_H


// typedefs


//******** Basics
#define _m_GET_COORDS		 (1 <<  0)	
#define _m_GET_PROXIMITY_LED	 (1 <<  1)
#define _m_GET_AMBIENT_LED	 (1 <<  2)
#define _m_GET_WHEEL_COUNTER	 (1 <<  3)
#define	_m_GET_MOTOR_SPEED	 (1 <<  4)
#define _m_GET_STATUS		 (1 <<  5)
//********
#define _m_SET_WHEEL_COUNTER	 (1 <<  6)
#define _m_SET_WHEEL_POSITION	 (1 <<  7)
#define	_m_SET_MOTOR_SPEED	 (1 <<  8)
#define _m_SET_LED0		 (1 <<  9)
#define _m_SET_LED1		 (1 << 10)


//********* Gripper
#define _m_GET_GRIP_WIDTH	 (1 << 11) 
#define _m_GET_GRIP_OHM		 (1 << 12)	
#define _m_GET_ARM_POSITION	 (1 << 13)
#define _m_GET_OBJECT_DETECT	 (1 << 14)
//*********
#define _m_SET_GRIP_WIDTH	 (1 << 15)
#define _m_SET_ARM_POSITION	 (1 << 16)


//********* Vision
#define _m_GET_CAMERA_IMAGE	 (1 << 17)
#define _m_GET_CAMERA_INTENSITY  (1 << 18)
#define _m_GET_CAMERA_MAXLIGHT	 (1 << 19)
#define _m_GET_CAMERA_MINLIGHT	 (1 << 20)	
#define _m_GET_CAMERA_SUBSCAN2	 (1 << 21)	
#define _m_GET_CAMERA_SUBSCAN4	 (1 << 22)	
#define _m_GET_CAMERA_LOWRES	 (1 << 23)	
#define _m_GET_CAMERA_PARTIAL8	 (1 << 24)	
#define _m_GET_CAMERA_PARTIAL16	 (1 << 25)	
#define _m_SET_CAMERA_PERIOD	 (1 << 26)	

#define _m_VISION_MASK (_m_GET_CAMERA_IMAGE	|\
			_m_GET_CAMERA_INTENSITY	|\
			_m_GET_CAMERA_MAXLIGHT	|\
			_m_GET_CAMERA_MINLIGHT	|\
			_m_GET_CAMERA_SUBSCAN2	|\
			_m_GET_CAMERA_SUBSCAN4	|\
			_m_GET_CAMERA_LOWRES	|\
			_m_GET_CAMERA_PARTIAL8	|\
			_m_GET_CAMERA_PARTIAL16		 )


#define _m_SET_MASK ( _m_SET_WHEEL_COUNTER + \
			_m_SET_WHEEL_POSITION + \
			_m_SET_MOTOR_SPEED + \
			_m_SET_LED0 + \
			_m_SET_LED1 + \
			_m_SET_GRIP_WIDTH + \
			_m_SET_ARM_POSITION	)

#define _m_GET_MASK  (	_m_GET_PROXIMITY_LED	|\
			_m_GET_AMBIENT_LED	|\
			_m_GET_WHEEL_COUNTER	|\
			_m_GET_MOTOR_SPEED	|\
			_m_GET_STATUS		|\
			_m_GET_GRIP_WIDTH	|\
			_m_GET_GRIP_OHM		|\
			_m_GET_ARM_POSITION	|\
			_m_GET_OBJECT_DETECT  	|\
			_m_GET_CAMERA_IMAGE	|\
			_m_GET_CAMERA_INTENSITY	|\
			_m_GET_CAMERA_MAXLIGHT	|\
			_m_GET_COORDS		|\
			_m_GET_CAMERA_SUBSCAN2  |\
                        _m_GET_CAMERA_SUBSCAN4	|\
                        _m_GET_CAMERA_LOWRES	|\
                        _m_GET_CAMERA_PARTIAL8	|\
                        _m_GET_CAMERA_PARTIAL16 |\
			_m_GET_CAMERA_MINLIGHT		)


#define _m_MUCHDATA_MASK	(		\
		_m_GET_PROXIMITY_LED		|\
		_m_GET_AMBIENT_LED		|\
		_m_GET_CAMERA_IMAGE		|\
		_m_GET_CAMERA_SUBSCAN2		|\
		_m_GET_CAMERA_SUBSCAN4		|\
		_m_GET_CAMERA_LOWRES		|\
		_m_GET_CAMERA_PARTIAL8		|\
		_m_GET_CAMERA_PARTIAL16			)

#define _m_LESSDATA_MASK	(		\
		_m_GET_WHEEL_COUNTER		|\
		_m_GET_MOTOR_SPEED		|\
		_m_GET_STATUS			|\
		_m_GET_GRIP_WIDTH		|\
		_m_GET_GRIP_OHM			|\
		_m_GET_ARM_POSITION		|\
		_m_GET_OBJECT_DETECT		|\
		_m_GET_CAMERA_INTENSITY		|\
		_m_GET_CAMERA_MAXLIGHT		|\
		_m_GET_CAMERA_MINLIGHT			)

#define _m_NODATA_MASK	_m_SET_MASK


#define MSG_QUEUE_SIZE	16384


// #include "khepera.h"


class t_khepera_msgs {
public:
	void Init(char *r);
	void Done(void);

	int receive_packet(void);		// call this once to flush 
	int transfer_packet(void);		// call this every time 
						// after flush

	void send_wheelposition(long l, long r);
	void send_positioninfo(long l, long r);
	void send_motorspeed(int l, int r);
	void send_led(int num, int action);
	void send_gripopen(void);
	void send_gripclose(void);
	void send_armpos(int n);

	void request_proximity(void);
	void request_ambient(void);
	void request_wheelposition(void);
	void request_motorspeed(void);
	void request_status(void);
	void request_gripwidth(void);

	void request_coords(void);

	void request_armpos(void);
	void request_resistor(void);
	void request_contact(void);
	void request_image(void);
	void request_subscan2(void);
	void request_brightness(void);
	void request_maxlight(void);
	void request_minlight(void);
	void request_subscan4(void);
	void request_lowres_scan(void);

	void request_partial_scan8(int start);
	void request_partial_scan16(int start);

private:
//	RobotContext *R;
	char *Rptr;
	unsigned long int query_mask, last_query_mask, got_mask, vision_timestamp;
	int readstart,partial8_start,partial16_start;

	long Parse(void);
	void Delete_First(char C, char *st);
//	void reflect_values(char *);

	char DataPacket[MSG_QUEUE_SIZE + 128];	// make this dynamic
	char ReceiveBuf[MSG_QUEUE_SIZE + 128];
	char tmp_buf[MSG_QUEUE_SIZE+128];
	char buf[MSG_QUEUE_SIZE+128];

};



#ifdef _T_MSGTYPE_G
#define m_extern
#else 
#define m_extern extern
#endif

// extern accessible vars


#undef m_extern

#endif







/**/
/**/
/**/
/**/
/**/
/**/
/**/
/**/
/*****  End Of File  ****************************/
