#if !defined(AFX_EDSOCKSERVERCTL_H__1FA54A89_2A76_4CA9_B42B_9584C7B73245__INCLUDED_)
#define AFX_EDSOCKSERVERCTL_H__1FA54A89_2A76_4CA9_B42B_9584C7B73245__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "stdAfx.h"

#define EDDATAERROR      1000 //資料錯誤
#define EDBUFOVERFLOW	  1001 //模組緩衝區溢位
#define EDRECVBUFOVERFLOW	1002 //電腦接收緩衝區溢位,用於阻塞接收呼叫

typedef void (CALLBACK* LPONACCEPT)(long ConnectID);
typedef void (CALLBACK* LPONCONNECTCLOSE)(long ConnectID);
typedef void (CALLBACK* LPONERROR)(long SocketID,long ErrorCode);
typedef void (CALLBACK* LPONRECECONFIGDATA)(long ConnectID,LPBYTE pDataBuf,long DataLength);
typedef void (CALLBACK* LPONRECEFROMCOM)(long ConnectID,long COMNum,LPBYTE pDataBuf,long DataLength);
typedef void (CALLBACK* LPONSWITCHCHANGE)(long ConnectID,long PortNum,long Value);


#ifdef EDSOCKSERVER_EXPORTS

#define EDSOCKSERVER_API extern "C" __declspec(dllexport)

#else

#ifdef __cplusplus
#define EDSOCKSERVER_API extern "C" __declspec(dllimport)
#else
#define EDSOCKSERVER_API __declspec(dllimport)
#endif

#endif


EDSOCKSERVER_API int WINAPI mac_ntoa(BYTE *mac,int maclen,BYTE *strmac,int strlen);
EDSOCKSERVER_API int WINAPI net_ntoa(u_long ipAddr,BYTE *str,int strlen);

EDSOCKSERVER_API u_long WINAPI GetLocalIP(long ConnectID);
EDSOCKSERVER_API long WINAPI GetLocalPort(long ConnectID);
EDSOCKSERVER_API BOOL WINAPI StartListen(LPCTSTR LocalIP,long LocalPort); 
EDSOCKSERVER_API BOOL WINAPI StopListen();
EDSOCKSERVER_API BOOL WINAPI CloseConnect(long ConnectID);
EDSOCKSERVER_API long WINAPI GetError(long SocketID);
EDSOCKSERVER_API u_long WINAPI GetPeerIP(long ConnectID);
EDSOCKSERVER_API long WINAPI GetPeerPort(long ConnectID);
EDSOCKSERVER_API BOOL WINAPI OpenConnect(LPCTSTR PeerIP, long PeerPort,LPCTSTR LocalIP,long LocalPort);
EDSOCKSERVER_API int WINAPI GetMAC(long ConnectID,LPBYTE lpMac,int maclen);
EDSOCKSERVER_API long WINAPI GetSwitchDirection(long ConnectID, long PortNum);
EDSOCKSERVER_API BOOL WINAPI SendToCOM(long ConnectID, long COMNum, LPBYTE pDataBuf, long DataLength);
EDSOCKSERVER_API BOOL WINAPI SetSwitchValue(long ConnectID, long PortNum, long Value);
EDSOCKSERVER_API BOOL WINAPI RequestConfigData(long ConnectID);
EDSOCKSERVER_API BOOL WINAPI SetConfigData(long ConnectID, LPBYTE pDataBuf, long DataLength);
EDSOCKSERVER_API long WINAPI GetSwitchValue(long ConnectID, long PortNum);
EDSOCKSERVER_API long WINAPI ResetBoard(long ConnectID);
EDSOCKSERVER_API short WINAPI GetModel(long ConnectID);
EDSOCKSERVER_API BOOL WINAPI SetCOMPara(long ConnectID, long COMNum, LPBYTE pDataBuf,long DataLength);
EDSOCKSERVER_API BOOL WINAPI IsSocket();
EDSOCKSERVER_API BOOL WINAPI IsNoDelay();
EDSOCKSERVER_API BOOL WINAPI SetSocket(BOOL IsSocketValue);
EDSOCKSERVER_API BOOL WINAPI SetNoDelay(BOOL IsNoDelayValue);
EDSOCKSERVER_API BOOL WINAPI SetCallback(LPONACCEPT lpOnAccept,LPONCONNECTCLOSE lpOnConnectClose,LPONERROR lpOnError,LPONRECECONFIGDATA lpOnReceConfigData,LPONRECEFROMCOM lpOnReceFromCom,LPONSWITCHCHANGE lpOnSwitchChange);
EDSOCKSERVER_API BOOL WINAPI CloseAllConnect();
EDSOCKSERVER_API BOOL WINAPI SetConnectOpt(long ConnectID,int level,int optname,const char FAR *optval,int optlen);
EDSOCKSERVER_API int WINAPI GetCOM(long ConnectID);
EDSOCKSERVER_API long WINAPI ReceiveData(long ConnectID,LPBYTE pDataBuf,long BufLen,DWORD dwWait);



//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_EDSOCKSERVERCTL_H__1FA54A89_2A76_4CA9_B42B_9584C7B73245__INCLUDED)
package net.rxwy.serialserver.sdk;

import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.win32.StdCallLibrary;

public interface C2000SDK extends StdCallLibrary{
	
	C2000SDK INSTANCE = (C2000SDK) Native.loadLibrary("EdSockServer",C2000SDK.class);

	boolean CloseAllConnect();

	boolean CloseConnect(NativeLong ConnectID);

	short GetCOM(NativeLong ConnectID);

	short GetError(NativeLong SocketID);

	NativeLong GetLocalIP(NativeLong ConnectID);

	NativeLong GetLocalPort(NativeLong ConnectID);

	int GetMAC(NativeLong ConnectID,byte[] lpMac,int maclen);

	short GetModel(NativeLong ConnectID);

	NativeLong GetPeerIP(NativeLong ConnectID);

	NativeLong GetPeerPort(NativeLong ConnectID);

	NativeLong GetSwitchDirection(NativeLong ConnectID,NativeLong PortNum);

	NativeLong GetSwitchValue(NativeLong ConnectID,NativeLong PortNum);

	boolean IsNoDelay();

	boolean IsSocket();

	NativeLong ReceiveData(NativeLong ConnectID,byte[] pDataBuf,NativeLong BufLen,int dwWait);

	boolean OpenConnect(String PeerIP,NativeLong PeerPort,String LocalIP,NativeLong LocalPort);

	boolean RequestConfigData(NativeLong ConnectID);

	NativeLong ResetBoard(NativeLong ConnectID);

	boolean SendToCOM(NativeLong ConnectID,NativeLong COMNum,byte[] pDataBuf,NativeLong DataLength);

	boolean SetCallback(OnAccept lpOnAccept,OnConnectClose lpOnConnectClose,OnError lpOnError,OnReceConfigData lpOnReceConfigData,OnReceFromCOM lpOnReceFromCOM,OnSwitchChange lpOnSwitchChange);

	boolean SetCOMPara(NativeLong ConnectID,NativeLong COMNum,byte[] pDataBuf,NativeLong DataLength);

	boolean SetConfigData(NativeLong ConnectID,byte[] pDataBuf,NativeLong DataLength);

	boolean SetNoDelay(boolean IsNoDelayValue);

	boolean SetSocket(boolean IsSocketValue); 

	boolean SetSwitchValue(NativeLong ConnectID,NativeLong PortNum,NativeLong Value);

	boolean StartListen(String LocalIP,NativeLong LocalPort);

	boolean StopListen();

	public static interface OnAccept extends StdCallCallback{
		public void invoke(NativeLong ConnectID);
	}

	public static interface OnConnectClose extends StdCallCallback{
		public void invoke(NativeLong ConnectID);
	}

	public static interface OnError extends StdCallCallback{
		public void invoke(NativeLong SocketID,NativeLong ErrorCode);
	}

	public static interface OnReceConfigData extends StdCallCallback{
		public void invoke(NativeLong ConnectID,ByteByReference pDataBuf,NativeLong DataLength);
	}

	public static interface OnReceFromCOM extends StdCallCallback{	
		public void invoke(NativeLong ConnectID,NativeLong COMNum,ByteByReference pDataBuf,NativeLong DataLength);
	}

	public static interface OnSwitchChange extends StdCallCallback{
		public void invoke(NativeLong ConnectID,NativeLong PortNum,NativeLong Value);
	}
}