⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tce1.cpp

📁 电话拨号演示系统(需硬件板卡支持)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**********************************************************
  this project is mainly to show how to dial out of trunk 
with TC-30E1(60E1) and TC-08A board,your can take it as a
simple switch(only export).
  Before running this demo,your should make sure that your
computer has pluged with the two board and the TC-30E1(60E1)
board is connected with another TC-30E1(60E1) board in another
computer that running an application(such as demo.exe). 

  Oriental Co.,Ltd. 
**********************************************************/

#include <windows.h>
#include <commdlg.h>
#include <commctrl.h>
#include <windowsx.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include "..\\..\\..\\..\\inc\\tce1_32.h"
#include "Tce1.h"
#include "resource.h"

//////////////////////////////////////////////////////////////////

TRUNK_STRUCT *Trunk ;   //Struct array of trunk
USER_STRUCT *User ;     //struct array of extension
DIALDATA_STRUCT DialData ;

int TotalTrunk ;		//total trunk count
int TotalUser ;			//total user count
int VocChannel[3] ;		//voice channel that play special tone 
extern HWND hGWnd;
extern HWND hPropPage[3];
int nDialType;
//////////////////////////////////////////////////////

void yzDoTrunkWork0() //电话拨号
{
	int i ;
	int tmpval ;
	
	DJSys_PushPlay() ;
	
	for( i = 0 ; i < TotalTrunk ; i++ ) 
	{
		yzDrawTrkState( i ) ;

		if ( DJTrk_GetTrunkStatus(i) == Step_Delay ) continue ;
		if( DJTrk_CheckForwardHangUp(i) == 1 ) 
		{
			if( Trunk[i].State != TRK_WAITUSERONHOOK && Trunk[i].State != TRK_ONHOOK  ) 
			{
				tmpval = Trunk[i].ConnectUser ;
				DJExg_ClearLinkTrunkAndUserByTrunk(i);
				DJExg_ClearLinkPlayVoiceFromTrunk( i );
				Trunk[i].State = TRK_ONHOOK ;
				
				if( tmpval != -1 ) 
				{
					if( DJUser_CheckHookOFF( tmpval ) ) 
					{
						DJExg_SetLinkPlayVoiceToUser( tmpval, VocChannel[VOCBUSYCH] ) ;//play busy tone
						Trunk[i].State = TRK_WAITUSERONHOOK ;
					}
				}
			}
		}

	}//end for
}
void yzDoTrunkWork1()//模拟呼叫
{
	int vocno;
	
	DJSys_PushPlay() ;
	for(int i=0;i<TotalTrunk;i++)
	{
		yzDrawTrkState(i);
		if(DJTrk_CheckForwardHangUp(i)) ResetTrunk(i);
		if(Trunk[i].State==TRK_CALLOUT)
		{
			switch( DJTrk_GetDialStatus(i) )
			{
			case DS_Dialing:
				break;
			case DS_NoDial:
				break;
			case DS_Wait:
				break;
			case DS_Connect:
				if(!yzPlayPromptFile(i,"SIGN"))
					ResetTrunk(i);
				else Trunk[i].State=TRK_PLAY;
				break;
			default:
				ResetTrunk(i);
				break;
			}
		
		}
		if(Trunk[i].State==TRK_PLAY)
		{
			if( (vocno = DJTrk_GetTrunkPlayID(i)) == -1 )
			{
				ResetTrunk(i);
				return;
			}
				
			if( DJVoc_CheckVoiceEnd(vocno) == 1 ) 
			{
				DJVoc_StopPlayFile( i ) ;
				ResetTrunk(i);
			}
		}
	}
}
void yzDoTrunkWork2()//单机自测
{
	int vocno;
	
	DJSys_PushPlay() ;
	
	for(int i=0;i<TotalTrunk;i++)
	{
		yzDrawTrkState(i);
		if(DJTrk_CheckForwardHangUp(i))
		{
			ResetTrunk(i);
		}
		if(DJTrk_CheckWait(i)&& i>=TotalTrunk/2)
		{
			if(yzPlayPromptFile(i,"SIGN")) 
				Trunk[i].State=TRK_PLAY;
		}
		if(Trunk[i].State==TRK_PLAY)
		{
			if( (vocno = DJTrk_GetTrunkPlayID(i)) == -1 )
			{
				ResetTrunk(i);
				return;
			}
				
			if( DJVoc_CheckVoiceEnd(vocno) == 1 ) 
			{
				ResetTrunk(i);
			}
		}
	}
}
////////////////////////////////////////////////////

void yzDoUserWork() 
{
	char *dialcode ;
	int tmpval ;
	int i;
	for( i = 0; i < TotalUser; i++ )
	{
		yzDrawUserState( i ) ;
		if ( !DJUser_CheckHookOFF(i) && User[i].State != USR_ONHOOK ) 
		{	//user offhook
			tmpval = User[i].ConnectTrk ;
			ResetTrunk( tmpval ) ;			
			ResetUser(i);
			
			continue;
		}
		switch( User[i].State ) 
		{
		case USR_ONHOOK:
			if ( DJUser_CheckHookOFF(i) && User[i].ConnectTrk == -1 ) 
			{
				//DJExg_SetLinkPlayVoiceToUser( i, VocChannel[VOCTONECH] ) ;//you can unmask this line
				User[i].State = USR_OFFHOOK ;
			}
			break ;

		case USR_OFFHOOK:
			if( DJUser_GetDialNum(i) >= 1 )
			{	//press at lest 1 key,wait to get another key
				DJExg_ClearLinkPlayVoiceFromUser( i ) ;//stop play tone
				User[i].State = USR_WAITDIAL ;
			}
			break;

		case USR_WAITDIAL:
			if( DJUser_GetDialNum(i) >= DialData.DialLen ) 
			{
				dialcode = DJUser_GetDialCode(i);	//get the user dial
				tmpval = GetDialTrunkId() ;			//get a free trunk for callout
				if( tmpval == -1 ) 
				{//cannot find free trunk channel
					User[i].State = USR_ENDSESSION;
				}
				else 
				{
					DJTrk_StartDial( tmpval, dialcode, DialData.CallerNum ) ;
					User[i].ConnectTrk = tmpval ; 
					User[i].State = USR_DIAL;
					Trunk[tmpval].ConnectUser = i ;
					Trunk[tmpval].State = TRK_CALLOUT ;
				}
			}	
			break ;

		case USR_DIAL:
			switch( DJTrk_GetDialStatus( User[i].ConnectTrk ) ){
			case DS_Dialing:
				break;
			case DS_NoDial:
				break;
			case DS_Wait:
				if( DJUser_GetPlayChannel(i) == -1 ) {//play ring tone or not
					DJExg_ClearLinkPlayVoiceFromUser( i ) ;
					DJExg_SetLinkPlayVoiceToUser( i, VocChannel[VOCRINGCH] ) ;
				}
				break ;
			case DS_Connect:
				DJExg_ClearLinkPlayVoiceFromUser( i ) ;//stop ring tone
				DJExg_SetLinkTrunkAndUser( User[i].ConnectTrk, i );//link trunk and user,then the connection is 2-direction
				User[i].State = USR_CONNECT;
				DJUser_InitDialBuf(i);//ready for getting dtmf
				break;
			default:
				User[i].State	= USR_ENDSESSION ;
				break;
			}
			break ;

		case USR_ENDSESSION:
			DJExg_ClearLinkTrunkAndUserByUser(i) ;
			DJExg_ClearLinkPlayVoiceFromUser(i) ;
			DJExg_SetLinkPlayVoiceToUser( i, VocChannel[VOCBUSYCH] ) ;
			User[i].State = USR_WAITONHOOK ;
			break;
		}//end switch
	}//end for
}

////////////////////////////////////////////////////////////

int	GetDialTrunkId()
{
	static int CurrentTrunkNo = 0 ;
	int i ;
	for( i = CurrentTrunkNo ; i < TotalTrunk ; i++ ) {
		if( DJTrk_CheckTrunkFree( i ) && !DJTrk_CheckTrunkIn( i ) ) {
			CurrentTrunkNo = i+1 ;
			return i ;
		}
	}
	
	for( i = 0 ; i < CurrentTrunkNo ; i++ ) {
		if( DJTrk_CheckTrunkFree( i ) && !DJTrk_CheckTrunkIn( i ) ) {
			CurrentTrunkNo = i+1 ;
			return i ;
		}
	}

	return -1 ;
}

////////////////////////////////////////////////////////////

bool yzInitSystem()
{
	int i = DJSys_EnableCard( "", "PROMPT.INI" ) ;
	if ( i != 0 ) {
		MessageBox(NULL,"Load Drive Faile!","Error", MB_OK ) ;
		return false;
	}

	TotalTrunk = DJTrk_GetTotalTrunkNum();
	TotalUser = DJUser_GetTotalUserNum();
	
	Trunk = new TRUNK_STRUCT[TotalTrunk] ;
	User = new USER_STRUCT[TotalUser] ;
	if( !Trunk || !User )
	{
		DJSys_DisableCard();
		MessageBox(NULL,"Memory alloc error!","Error", MB_OK ) ;
		return false;
	}

	for(i = 0; i < TotalTrunk; i++)	{
		DJTrk_SetTrunkType( i, Type_Export );
		Trunk[i].ConnectUser = -1 ;
		Trunk[i].ConnectTrk = -1 ;
		Trunk[i].State = TRK_FREE ;
	}
	
	for(i = 0; i < TotalUser; i++)	{
		DJUser_SetPowerON(i) ;
		if ( ! DJUser_EnableDialSound(i) ) {
			DJSys_DisableCard();
			MessageBox(NULL,"Init UserBoard Error!","Error", MB_OK ) ;
			exit( 2 );
		}
		User[i].ConnectTrk = -1 ;
		User[i].ConnectUser = -1 ;
		User[i].State = USR_ONHOOK ;
	}

	//VocChannel[VOCBUSYCH] = DJVoc_SearchFreeVoiceChannelForPlay() ;
	VocChannel[VOCBUSYCH] = DJVoc_SFVC_ForPlay_New(0, false);
	DJVoc_LoopPlayPromptFile( VocChannel[VOCBUSYCH], "BUSY" ) ;
		
	//VocChannel[VOCRINGCH] = DJVoc_SearchFreeVoiceChannelForPlay() ;
	VocChannel[VOCRINGCH] = DJVoc_SFVC_ForPlay_New(0, false);
	DJVoc_LoopPlayPromptFile( VocChannel[VOCRINGCH], "RING" ) ;
	
	//VocChannel[VOCTONECH] = DJVoc_SearchFreeVoiceChannelForPlay() ;
	VocChannel[VOCTONECH] = DJVoc_SFVC_ForPlay_New(0, false);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -