#ifndef _8ECP__H
#define _8ECP__H

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <time.h>
#include "../../../public/src/include/includes.h"
#include "../../../public/src/include/public.h"
#include "../../../iptrans/src/include/iptrans.h"
#include "../../../snmp/src/include/snmp.h"
#include "../../../debug/src/include/debug.h"

#include "./8ecp_debug.h"

extern BYTE s_msg[128];

#ifndef _8ECP_MAX_USER_NAME_LEN
#define _8ECP_MAX_USER_NAME_LEN		100
#endif

#ifndef _8KE1_NUM
#define _8KE1_NUM					32
#endif

#ifndef MAX_DELAY
#define MAX_DELAY					1          //the max delay time of heartbeat message
#endif 


#ifndef PORT
#define PORT						4950
#endif

#ifndef OID_Prefix
#define OID_Prefix					8
#endif

#ifndef InUSE
#define InUse						1
#endif

#ifndef NotInUse
#define NotInUse					0
#endif

#ifndef TrkStartIndex
#define TrkStartIndex				8    //the first index of trkno in the heartbeat msg
#endif

#ifndef E1NumOnCSU
#define E1NumOnCSU					16
#endif

#ifndef _T_BYTE
#define _T_BYTE
typedef unsigned char BYTE;
#endif

#ifndef _T_WORD
#define _T_WORD
typedef unsigned short WORD;
#endif

#ifndef _T_DWORD
#define _T_DWORD
typedef unsigned int DWORD;
#endif


typedef struct _8ECP_SAP
{
char name[_8ECP_MAX_USER_NAME_LEN];

//8ECP module will use these callback functions to update 8E1 MG and trunk status
//Return 0 if success, return -1 if failure
int (*update_mg_status)(BYTE mgNo, BYTE status);
int (*update_trk_status)(BYTE mgNo, BYTE trkNo, BYTE status);

}_8ECP_SAP;


typedef struct _8ECP_PDU           //the message send to IPTRANS
{
	BYTE reserved;
	BYTE lenInd;
	BYTE CPC_IFA_Inf;                  //fixed value 0x87
	BYTE dstRef[2];
	BYTE reserved1;
	BYTE sourceRef[2];
	BYTE reserved2;
	BYTE type;                              //00=connect time slot with echo
							    //01=connect ack
	                                              //02=connect tone
	                                              //03=connect DTMF
	                                              //04=connect group
	                                              //05=disconnect group
	                                              //06=connect time slot without echo
	BYTE sourceTimeSlotNo;
	BYTE dstModuleID;
	BYTE dstTimeSlotNo;
	BYTE Value;                          /*when type=02,
								0=tone#0, 1=tone#1, 2=tone#2, 3=tone#3, 
								4=tone#4, 5=tone#5/,6=tone#6, 7=tone#7
								
							     when type=03
							     0=DTMF1, 1=DTMF2, 2=DTMF3, 3=DTMF4,
							     4=DTMF5, 5=DTMF6, 6=DTMF7, 7=DTMF8,
							     8=DTMF9, 9=DTMF0, 10=DTMF*, 11=DTMF#

							     */

	BYTE duration;
	

}_8ECP_PDU;


// the struct of SAP in 8ecp
typedef struct _SAP_In_8ECP
{
	BYTE inUse;
	_8ECP_SAP _8ecp_sap;
}SAP_In_8ECP;

// the struct of MG in 8ecp
typedef struct Card_Struct
{
//	WORD mgNo;
	DWORD ip;
	BYTE mgNo;
}Card_Struct;



//8ecp interface
int _8ecp_bind(_8ECP_SAP *sap);
int _8ecp_unbind(BYTE sapIndex);

int _8ecp_createMG(WORD mgNo, DWORD ip, BYTE cardNo);        //create or update MG
int _8ecp_deleteMG(WORD mgNo, DWORD ip, BYTE cardNo);        //delete MG

void _8ecp_connect_chnl(WORD orgChnl, WORD dstChnl, BYTE ecDisable); //ecDisable:0/1=enable/disable echo canceller
void _8ecp_connect_dtmf(WORD orgChnl, WORD dstChnl, BYTE dtmfNo);
void _8ecp_connect_tone(WORD orgChnl, WORD dstChnl, BYTE toneNo, WORD duration);
void _8ecp_init(); //called in the main program during initialization stage
void _8ecp_timer(); //called every 10ms in the main program
#endif
