/*************************************************************************\
* "$RCSfile: GBit.h,v $"                                                  *
***************************************************************************
* Information by CVS or VSS:                                              *
*     Last check in on: $Date: 2013-06-07 09:06:35 $                      *
*     by                $Author: goebel $
*     Revision        : $Revision: 1.21 $                                 *
*                                                                         *
* CVS: $Source: /Daten/Projekte/CVS/Lib/GBIT_Lib/include/GBit.h,v $
**************************************************************************/
/*! \file GBIT.h
*	\brief GBit Library Interface
*	\author (c) 2004 - 2013 IMAGO Technologies GmbH
*
*	$Revision: 1.21 $
*	$Date: 2013-06-07 09:06:35 $
***************************************************************************/

#define _GBIT_LIB_HID {"GBit.h", __DATE__, __TIME__, _REVISION($Revision: 1.21 $)}

#ifndef _GBIT_H_
#define _GBIT_H_

#include "vision_box.h"
#include "socket.h"

//! PHY information
enum ePHY_BITS
{
	PHY_LINKUP =	 0x01,	//!< Link established
	PHY_FULLDUPLEX = 0x02,	//!< Full duplex operation
	PHY_10MBPS =	 0x04,	//!< 10 MBit/s
	PHY_100MBPS =	 0x08,	//!< 100 MBit/s
	PHY_1000MBPS =	 0x10	//!< 1000 MBit/s
};

//! GBit initialization structure
typedef struct sGBIT_INITDATA
{
	char *IpAddress;	//!< IP host address printed into a character string
	char *IpSubnetMask;	//!< IP subnet mask printed into a character string
	char *IpDefaultGw;	//!< IP default gateway printed into a character string
	char *IpDNSServer;	//!< IP DNS server printed into a character string
	char *HostName;		//!< Host name printed into a character string
	char *DomainName;	//!< Domain name printed into a character string
} GBIT_INITDATA;

extern far char *GBIT_LibVersion;
extern far char *GBIT_LibDate;
extern far unsigned int GBIT_Version;
extern far int GBIT_InitTimeout;

#ifdef __cplusplus

/**
 * \brief Each network interface is represented by an instance of this class.
 *
 * Some functions are implemented as "C" version and as methods of this class.
 * Using the member function can be useful, if more than one network interface is used.
 * For example, if the user wants to create a socket on a specific interface,
 * instead of ::socket() he can use the method GBIT::socket() with the corresponding instance.
 * The created socket handle can then be used with the normal socket API.\n
 * The default instance for the "C" functions can be specified with GBIT::SetDefault().
 */
class GBIT
{
public:
	GBIT();
	~GBIT();
	int Init(int BoardId, GBIT_INITDATA *InitData, int InitTimeout=10000);
	int GetInitStatus();
	int Close(int Shutdown=1);
	int OfferDevice(IO_DEVICE *pIoDevice, int RemoteAddress);
	int GetDevice(IO_DEVICE *pIoDevice, int RemoteAddress);
	void SetDefault();
	static GBIT *GetDefault();
	int GetBoardId();
	int GetPhyInfo(unsigned char *MacAddress, int *LinkStatus, unsigned int Port = 0);
	int AddWebFile(const char *pFileName, const unsigned char *pBuffer, unsigned int Size);
	void RemoveWebFile(const char *pFileName);
	int InitDisplay(int Width, int Height, int TcpPort, VIB_DISPLAYDEVICE *pDevice);
	int AddTcpDisplayJar();
	int RemoveTcpDisplayJar();
	SOCKET socket(int Addrfamily, int Type, int Protocol);
	int gethostname(char *pNameBuf, int Size);
	int gethostbyname(char *pName, void *pScrapBuf, int Size);
	unsigned int MacReadRegister(unsigned int Address);
	int MacWriteRegister(unsigned int Address, unsigned int Value);
	unsigned short PhyReadRegister(unsigned char Address);
	int PhyWriteRegister(unsigned char Address, unsigned short Value);
	HANDLE CfgGetDefault();
	int CfgAddEntry(HANDLE hCfg, uint Tag, uint Item, uint Mode, int Size, UINT8 *pData, HANDLE *phCfgEntry);
	int CfgRemoveEntry(HANDLE hCfg, HANDLE hCfgEntry);

	class GBIT_IO *GBitIO;
	unsigned int Version;
	unsigned int LoaderVersion;

private:
	bool tcpDispAppValid;
};

extern "C" {
#endif

int  GBIT_Init(int BoardId, GBIT_INITDATA *pInitData);
int  GBIT_GetLibVersion(int *pMajor, int *pMinor);
int  GBIT_OfferDevice(IO_DEVICE *pIoDevice, int RemoteAddress);
int  GBIT_GetDevice(IO_DEVICE *pIoDevice, int RemoteAddress);
int  GBIT_GetPhyInfo(unsigned char *pMacAddress, int *pLinkStatus);
int  GBIT_FlashWriteFile(const char *pFilename, const unsigned char *pFileBuffer, unsigned int FileSize);
int  GBIT_AddWebFile(const char *pFileName, const unsigned char *pBuffer, unsigned int Size);
void GBIT_RemoveWebFile(const char *pFileName);
int  GBIT_InitDisplay(int Width, int Height, int TcpPort, VIB_DISPLAYDEVICE *pDevice);
int  GBIT_CloseDisplay(VIB_DISPLAYDEVICE *pDevice);
void GBIT_SetModeRaw(void);
int  GBIT_DisplayStatus(VIB_DISPLAYDEVICE *pDisplayDevice);
int  GBIT_GetKoord(int *pX, int *pY);

#ifdef __cplusplus
}
#endif

#endif

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