/**
 * \brief TCP/IPv4/ethernet/LAN communication
 * \copyright 2013-2014, IQ² Development GmbH, Neckartenzlingen. All rights reserved.
 */

#ifndef _iqi_ethernet_internal_h
#define _iqi_ethernet_internal_h

typedef int16 (*enet_ReadSerialNumberT)(uint16 uiPortNo, ulong64 * ul64pSerialNumber, char08 *cpErrMsg);

/**
 * \brief Search iqInterface in all availiable IPv4 networks
 *
 * \param[out]  pFoundConnections         buffer to return found TCP/IPv4 connections with iqInterface
 * \param[in]   ucMaxConnectionsNumber    size of foundConnections buffer
 * \param[out]  ucpFoundConnectionsNumber number of found connections returned in foundConnections buffer
 * \param[in]   readSerialNumber          pointer to function which can be used to read serial number of iqInterface
 * \param[in]   uiSendRecvTimoutMs        send/receive timeout for UDP broadcast and TCP/IPv4 connection
 * \param[out]  cpErrMsg                  an error message (minimum 256 symbols!)
 *
 * \return error or ERR_NONE, 
 *         found TCP/IPv4 connections with iqInterface in foundConnections buffer
 *         and their number in ucpFoundConnectionsNumber
 */
int16 enet_findIQInterfaces(enet_ConnectionT * pFoundConnections, 
                            uchar08 ucMaxConnectionsNumber, 
                            uchar08 * ucpFoundConnectionsNumber,
                            enet_ReadSerialNumberT readSerialNumber,
                            uint16 uiBroadcastTimoutMs, char08 * cpErrMsg);

/**
 * \brief Open TCP/IPv4 connection to iqInterface
 *
 * \param[in]   connection         TCP connection info, used only cpIqInterfaceIpAddr and uiPort
 * \param[in]   uiSendRecvTimoutMs TCP send/receive timout
 * \param[out]  cpErrMsg           an error message (minimum 256 symbols!)
 *
 * \return virtual port (TCP handle) of successfully connected iqInterface 
 *         to use in enet_Send/enet_Recv functions or error
 */
int16 enet_OpenConnection(enet_ConnectionT * connection, uint16 uiSendRecvTimoutMs, char08 * cpErrMsg);

/**
 * \brief Close TCP/IPv4 connection to iqInterface
 *
 * \param[in]   uiPortNo virtual ethernet port number of iqInterface (TCP handle)
 * \param[out]  cpErrMsg an error message (minimum 256 symbols!)
 */
int16 enet_CloseConnection(uint16 uiPortNo, char08 * cpErrMsg);

/**
 * \brief Sends byte message to iqInterface over opened TCP/IPv4 connection
 *
 * \param[in]   uiPortNo      virtual ethernet port number of iqInterface (TCP handle)
 * \param[in]   ucpBuf        pointer on data buffer with byte message to send
 * \param[in]   ulBytesCount  count of bytes to send
 * \param[out]  cpErrMsg      an error message (minimum 256 symbols!)
 */
int16 enet_Send(uint16 uiPortNo,
                 uchar08 *ucpBuf,
                 ulong32 ulBytesCount,
                 char08 *cpErrMsg);

/**
 * \brief Receives byte message from iqInterface over opened TCP/IPv4 connection
 *
 * \param[in]   uiPortNo      virtual ethernet port number of iqInterface (TCP handle)
 * \param[out]  ucpBuf        pointer on data buffer to receive byte message
 * \param[in]   ulBytesCount  count of bytes to receive
 * \param[out]  cpErrMsg      an error message (minimum 256 symbols!)
 */
int16 enet_Recv(uint16 uiPortNo,
                uchar08 *ucpBuf,
                ulong32 ulBytesCount,
                char08 *cpErrMsg);

#endif
