/*************************************************************************\
* "$RCSfile: CL_Chain.h,v $"                                              *
***************************************************************************
* Information by CVS or VSS:                                              *
*     Last check in on: $Date: 2010-08-19 13:22:44 $                      *
*     by                $Author: goebel $
*     Revision        : $Revision: 1.17 $                                 *
*                                                                         *
* CVS: $Source: /Daten/Projekte/CVS/Lib/CLChain_Lib/src/CL_Chain.h,v $
\*************************************************************************/
/*! \file CL_Chain.h
*	\brief CL Chain Library Interface
*	\author (c) 2005 - 2013 IMAGO Technologies GmbH
*
*	$Revision: 1.17 $
*	$Date: 2010-08-19 13:22:44 $
**************************************************************************/

#include "vision_box.h"

#ifndef _CL_CHAIN_H_
#define _CL_CHAIN_H_

/*************************************************************************\
* Camera Link defines                                                     *
\*************************************************************************/

//! Types
enum eCLCHTypes
{
	CL_MASTER = 1,	//!< Master
	CL_SLAVE = 0	//!< Slave
};

//! Camera Link init states
enum eCLInitStates
{
	CLSTATE_INIT_START =	1,	//!< Initialization started
	CLSTATE_INIT_SLAVES =	2,	//!< Distributing to Slaves
	CLSTATE_INIT_WAIT =		3,	//!< Slave is waiting
	CLSTATE_INIT_DONE =		4	//!< Initialization done
};

//! Camera Link errors
enum eCLCHErrors
{
	CLE_NONE = 0,				//!< No error (0)
	CLE_TIMEOUT =		 -1,	//!< A time out occurs
	CLE_BUFFER_OVERRUN = -2		//!< A function buffer is too small
};

/*************************************************************************/
/*! @brief CameraLink configuration structure

	After starting the initialization, the user can use the configuration
	structure #CLCH_CONFIG to read the configuration of the CameraLink chain.
	After successful initialization, a unique address is assigned to each
	DSP. The valid address range reaches from 1 to 250.
**************************************************************************/
typedef struct sCLCH_CONFIG
{
	unsigned char bIAmMaster;		//!< 1=Master, 0=Slave (#CL_MASTER / #CL_SLAVE)
	unsigned char nMyAddress;		//!< Own address
	unsigned char nMasterAddress;	//!< Master address
	unsigned char nSlaveAddress0;	//!< First Slave address
	unsigned char nSlaveCount;		//!< Number of Slaves
	IO_DEVICE IoDevice;				//!< I/O device
} CLCH_CONFIG;

extern far char *CLCH_LibVersion;
extern far char *CLCH_LibDate;

/*************************************************************************\
* Prototypes                                                              *
\*************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

CLCH_CONFIG *CLCH_InitStart(char nBoardId, char bMaster, VIB_FxnMessageDispatcher MessageDispatcher);
int CLCH_InitState(void);
int CLCH_GetLibVersion(int *pMajor, int *pMinor);
int CLCH_SetBlockSize(unsigned int BlockSize);
int CLCH_SendMessage(unsigned char nRemoteAddress, const void *pData, unsigned int nBytes);
int CLCH_Send(unsigned char nRemoteAddress, const void *pBuffer, unsigned int nBytes, char bWait);
int CLCH_SendWait(unsigned char nRemoteAddress, int msTimeout);
int CLCH_SendAbort(unsigned char nRemoteAddress);
int CLCH_Recv(unsigned int nRemoteAddress, void *pBuffer, unsigned int nBytes, char bWait);
int CLCH_RecvWait(unsigned char nRemoteAddress, int msTimeout);
int CLCH_RecvQuery(unsigned char nRemoteAddress);
int CLCH_RecvAbort(unsigned char nRemoteAddress);
int CLCH_GetHammingError(CLCH_CONFIG *pClConfig, int *nSingleBitError, int *nDoubleBitErrors, unsigned int msTimeout);
void CLCH_Shutdown(void);

#ifdef __cplusplus
}
#endif

#endif //_CL_CHAIN_H_

/*************************************************************************/
