#ifndef _VCOM3_

#define _VCOM3_	3230

#ifdef __cplusplus
extern "C" {
#endif

void UserInit(void);
/*
  User must support the function : UserInit();
*/

void UserEnd(void);
/*
  User must support the function : UserEnd();
*/

void UserLoopFun(void);
/*
  User must support the function : UserLoopFun();
*/
int UserCmd(unsigned char *Cmd,unsigned char *Response);
/*
  When user want use COMMAND "19",
  User must support the function : UserCmd();
  COMMAND "19" will pass the user command to function UserCmd();
  If the function will return something back, must put the data on
  the output buffer "Response", and return value must >0 .
*/

/*
void AddUserTimerFunction(void (*fun)(void),unsigned timems);

In vlib3230.lib or later remove this function, please use the new function:
InstallUserTimerFunction_ms(unsigned timems,void (*fun)(void)); 
*/

#define AddUserTimerFunction(fun,ms) InstallUserTimerFunction_ms(ms,fun)
/*
   The vxcomm.LIB support AddUserTimerFunction();
   when user want to install a function, and for a period time
   the system will call the function, just call this function to
   install it.

   for example:

    unsigned cnt;
    void UserCount(void)
    {
       cnt++;
    }

    void UserInit(void)
    {
      AddUserTimerFunction(UserCount,10); // every 10 ms will call UserCnt
    }
*/

int EnableCom(int port);
/*
    The function can force the eXserver to re-work with the com port
*/
int DisableCom(int port);
/*
    The function can force the eXserver to skip the com port
*/

#if _VCOM3_ >= 3230
int EnableCom8K(int slot,int port);
/*
    The function can force the eXserver to re-work with the com port
    slot: 0~3 (for I-84xx/I-88xx), 0~1 (for I-82xx), 0 (for I-81xx)
    port: 0~3 
*/
int DisableCom8K(int slot,int port);
/*
    The function can force the eXserver to skip the com port
    slot: 0~3 (for I-84xx/I-88xx), 0~1 (for I-82xx), 0 (for I-81xx)
    port: 0~3 
*/

#endif

extern int SocketConnected;
/*
  SocketConnected : total connect socket number
*/

extern int EchoMode;
/*
  EchoMode:
   0, default mode.
   1, will add the command number to the echo message.
      for example:
      input: 10
      output:107188E2
*/

#ifndef  _TCPREADDATA_
#define  _TCPREADDATA_

typedef struct t_TcpReadData{
	int Comport;
	int Socket;
	int Length;
	char* ReadUartChar;
}TCPREADDATA;

#endif

/*
int VcomSendSocket(int skt,char *data,int cnt);
*/
#define VcomSendSocket	XS_WriteSocket

extern unsigned Port9999,Port502,Port10000,PortUser;
/*
  By default Port10000=10000,Port9999=9999, Port502=502, PortUser=0
  user's function(UserInit()) can change them to others port value.
*/

void VcomSaveComData(int port);

/* #define MAX_COMPORT 20 // defined in module1.h */

#ifndef _COM_DATA_
#define _COM_DATA_

typedef struct COM_DATA {
  unsigned long baud;
  char databit;
  char parity;
  char stopbit;
  unsigned char sum;
} *pCOM_DATA,COM_DATA;

#endif

extern COM_DATA ComData[MAX_COMPORT];
/*
  The COM port setting value will be save in EEPROM and VCOMnnnn will read it from EEPROM.
  And it will be display on the 5DigitLed.
  If user's function want change the setting value, just set the variable ComData[port],
and can call VcomSaveComData(int port) to save the new value to EEPROM.
*/

int TcpPrint(int skt,int mode,char *fmt,...);
/*
 [09/09/2002] Add. VCOM3009 or later
 Use TcpPrint like printf, add the message will be send out by TCP/IP.

 skt: socket
 mode: 0: send to internal buffer first,if the buffered size > 1360
          the buffered msg will be send out.
       1: send out immediately.
*/

#ifndef _TCPIP_H_

struct in_addr {                /* Internet address */
    unsigned long   s_addr;
};

struct sockaddr_in {            /* Internet socket address */
    short           sin_family; /* should be unsigned but this is BSD */
    unsigned short  sin_port;   /* network order !!! */
    struct in_addr  sin_addr;
    char            sin_zero[8];
};
#endif

typedef struct socket_state {
  int                active;  /* socket is active */
  struct sockaddr_in sin;     /* client address */
} socket_state;


/* Global Variable */
extern socket_state sst[];    /* sockets state table */

/* After establish connection to Port9999/Port520/PortUser, system will call these function. 
   user program must support these three functions.
   It can send welcome message to client side, or the message to ask user id/password, or ...
*/
void Port9999Start(int skt);
void Port502Start(int skt);
void PortUserStart(int skt);

extern unsigned char xBoardName[16]; /* [2006/02/15]: 10 --> 16 */
extern int bVcomWebReadOnly; /*[2007/05/03]: */

#if _VCOM3_ >= 3230

extern COMPORT LocalCom[MAX_COMPORT+1];
extern TCP_SERVER VcomServer[MAX_COMPORT];
extern char *UserProgramName;
extern char *UserProgramVersion;

#endif

#ifdef __cplusplus
}
#endif

#endif
