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

📄 calldlg.cpp

📁 三汇CTI示例程序源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			case E_STATE_ANALOG_CHECK_REC_START:
				{
					if(SsmGetRxDtmfLen(m_AnalogCh[i].iChId) >= 1) 
					{
						SsmClearRxDtmfBuf(m_AnalogCh[i].iChId);
						if( SsmRecToFile(m_AnalogCh[i].iChId,"test.voc",6,0L,10L*8000L,0,0) == -1) //start from 16000L,maxmium 10 seconds
						{
							AppErrorHandler(m_AnalogCh[i].iChId);
						}
						else
						{
							m_AnalogCh[i].Step = E_STATE_ANALOG_CHECK_REC_END;
						}
					}
					else 
					{
						if(++m_AnalogCh[i].ulTimeOutCounter > 300) //wait 15 seconds for DTMF-key
						{
							if ( SsmPlayIndexString(m_AnalogCh[i].iChId, "Byebye" )== -1 ) 
							{
								AppErrorHandler(m_AnalogCh[i].iChId);
							}
							else
							{
								m_AnalogCh[i].Step = E_STATE_ANALOG_CHECK_PLAY_BYEBYE;
							}
						}
					}
					break ;
				}

			case E_STATE_ANALOG_CHECK_REC_END:
				{
					if(SsmGetRxDtmfLen(m_AnalogCh[i].iChId)>=1 || SsmChkRecToFile(m_AnalogCh[i].iChId)==0)
					{
						SsmStopRecToFile(m_AnalogCh[i].iChId);
						m_AnalogCh[i].Step = E_STATE_ANALOG_PLAY_SELECT;
					}
					break ;
				}
		
			case E_STATE_ANALOG_CHECK_PLAY_RECORD:
				{
					if(SsmCheckPlay(m_AnalogCh[i].iChId) > 0)
					{
						m_AnalogCh[i].Step = E_STATE_ANALOG_PLAY_SELECT;
					}
					break;
				}	
	
			case E_STATE_ANALOG_WAIT_STATION_PICKUP:
				{
					if( SsmGetHookState(m_AnalogCh[i].nStationCh) ) //station is in pickup state now
					{
						SsmStopRing(m_AnalogCh[i].nStationCh);
						SsmTalkWith(m_AnalogCh[i].iChId,m_AnalogCh[i].nStationCh);	
						SetStationChState(m_AnalogCh[i].nStationCh, E_STATE_STATION_TALKING);
						m_AnalogCh[i].Step = E_STATE_ANALOG_WAIT_STATION_HANGUP;
					}
					break;
				}

			case E_STATE_ANALOG_WAIT_STATION_HANGUP:
				{
					if( !SsmGetHookState(m_AnalogCh[i].nStationCh) )   //station hang up
					{
						SsmStopTalkWith(m_AnalogCh[i].iChId,m_AnalogCh[i].nStationCh);
						SetStationChState( m_AnalogCh[i].nStationCh, E_STATE_STATION_IDLE);
						SetStationChTalkWith( m_AnalogCh[i].nStationCh, -1);
						m_AnalogCh[i].nStationCh = -1;
						m_AnalogCh[i].Step = E_STATE_ANALOG_PLAY_SELECT;				
					}
					break;
				}

			case E_STATE_ANALOG_CHECK_PLAY_BYEBYE:
				{
					if(SsmCheckPlay(m_AnalogCh[i].iChId) > 0) 
					{
						SsmHangup(m_AnalogCh[i].iChId);
						m_AnalogCh[i].Step = E_STATE_ANALOG_IDLE;
					}
					break ;
				}
			} 
		}
}
///////////////////////////////////////////////////////////////////////////////////////////////
void CCallDlg::ScanIpCh()
{
	for(int i = 0; i < m_nTotalIpCh; i++) 
	{
		m_IpCh[i].iLineState = SsmGetChState(m_IpCh[i].iChId);
		if( m_IpCh[i].iLineState == S_CALL_STANDBY || m_IpCh[i].iLineState == S_CALL_PENDING)
		{	
			switch( m_IpCh[i].Step )
			{
				case  E_STATE_IP_CHECK_PLAY_WELCOME:
					{
						SsmStopPlayFileList(m_IpCh[i].iChId);
						break;
					}
				case E_STATE_IP_CHECK_REC_START:
				case E_STATE_IP_CHECK_PLAY_SELECT:
					{
						SsmStopPlayIndex(m_IpCh[i].iChId);
						break;
					}
					
				case E_STATE_IP_CHECK_REC_END:
					{
						SsmStopRecToFile(m_IpCh[i].iChId);
						break;
					}
			
				case E_STATE_IP_WAIT_STATION_PICKUP:
					{
						SsmStopRing(m_IpCh[i].nStationCh);	
						SetStationChState(m_IpCh[i].nStationCh, E_STATE_STATION_IDLE);
						SetStationChTalkWith(m_IpCh[i].nStationCh, -1);
						m_IpCh[i].nStationCh = -1;
						break;	
					}
			
				case E_STATE_IP_WAIT_STATION_HANGUP:
					{
						SsmStopTalkWith(m_IpCh[i].nStationCh, m_IpCh[i].iChId);
						SetStationChState(m_IpCh[i].nStationCh, E_STATE_STATION_IDLE);
						SetStationChTalkWith(m_IpCh[i].nStationCh, -1);
						m_IpCh[i].nStationCh = -1;
						break;
					}
			}//?end switch(m_IpCh[i].Step)
			
			SsmHangup(m_IpCh[i].iChId);
			memset(m_IpCh[i].szCallerTelNumber, 0, 64);
			m_IpCh[i].Step = E_STATE_IP_IDLE;
		}//?end if( m_IpCh[i].iLineState == S_CALL_IDLE )

		switch( m_IpCh[i].Step )
		{
			case E_STATE_IP_IDLE:
				{
					if( m_IpCh[i].iLineState == S_CALL_RINGING )  //ring detected
					{
						SsmPickup( m_IpCh[i].iChId );
						SsmGetCallerId( m_IpCh[i].iChId, m_IpCh[i].szCallerTelNumber );
						m_IpCh[i].Step = E_STATE_IP_WAIT_CONNECT;
					}
					break;
				}

			case E_STATE_IP_WAIT_CONNECT:
				{
					if( m_IpCh[i].iLineState == S_CALL_TALKING )
					{
						m_IpCh[i].Step = E_STATE_IP_PLAY_WELCOME;
					}
					break;
				}
				
			case E_STATE_IP_PLAY_WELCOME:
				{
					SsmClearFileList(m_IpCh[i].iChId);
					if (SsmAddToFileList(i,".\\DemoVoc\\cchi.voc",6,0,-1) == -1 || 
						SsmAddToFileList(i,".\\DemoVoc\\cchi2.voc",6,0,-1) == -1 ) 
					{
						AppErrorHandler(m_IpCh[i].iChId);
					}
					else 
					{
						if(SsmPlayFileList(m_IpCh[i].iChId) == -1) 
						{
							AppErrorHandler(m_IpCh[i].iChId);
						}
						else 
						{
							m_IpCh[i].Step = E_STATE_IP_CHECK_PLAY_WELCOME;
						}
					}
				}
				
			case E_STATE_IP_CHECK_PLAY_WELCOME:
				{
					if(SsmCheckPlay(m_IpCh[i].iChId) > 0) // end of playing "welcome"
					{
						int iRet = SsmCheckPlay(m_IpCh[i].iChId);
						m_IpCh[i].Step = E_STATE_IP_PLAY_SELECT;
					}
					break;
				}
				
			case E_STATE_IP_PLAY_SELECT:
				{
					if(SsmPlayIndexString(m_IpCh[i].iChId,"Select") == -1)
					{
						AppErrorHandler(m_IpCh[i].iChId);
					}
					else
					{
						SsmSetDtmfStopPlay(m_IpCh[i].iChId,1);	// enable DTMF-Stop-Play function
						SsmClearRxDtmfBuf(m_IpCh[i].iChId);
						m_IpCh[i].ulTimeOutCounter = 0;
						m_IpCh[i].Step = E_STATE_IP_CHECK_PLAY_SELECT;
					}
					break;
				}
		
			case E_STATE_IP_CHECK_PLAY_SELECT:
				{
					if(SsmGetRxDtmfLen(m_IpCh[i].iChId) >= 1 && (SsmCheckPlay(m_IpCh[i].iChId) == 2 || SsmCheckPlay(m_IpCh[i].iChId) == 1)) 
					//if((SsmCheckPlay(m_IpCh[i].iChId) == 2 || SsmCheckPlay(m_IpCh[i].iChId) == 1)) 
					{
						char ch;
						SsmGet1stDtmf(m_IpCh[i].iChId,&ch);
						SsmClearRxDtmfBuf(m_IpCh[i].iChId);
						
					//	ch = '4';
						switch(ch)
						{
							case '1':			//DTMF=1: record to file "test.voc"
								{
									if(SsmPlayIndexString(m_IpCh[i].iChId,"RecPrompt") == -1)	//play "press any key to start, and any key again to stop".
									{
										AppErrorHandler(m_IpCh[i].iChId);
									}
									else 
									{
										m_IpCh[i].ulTimeOutCounter = 0;
										m_IpCh[i].Step = E_STATE_IP_CHECK_REC_START;
									}
									break;
								}
				
							case '4':			//DTMF=4:  connect to an idle station channel
								{
									int nStationCh = SearchIdleStationCh();
									if(nStationCh >= 0)
									{
										SsmStartRing(nStationCh);
										SetStationChState(nStationCh, E_STATE_STATION_RINGING );
										SetStationChTalkWith(nStationCh, m_IpCh[i].iChId );
										m_IpCh[i].nStationCh = nStationCh;
										m_IpCh[i].Step = E_STATE_IP_WAIT_STATION_PICKUP;
									}
									else
									{
										m_IpCh[i].Step = E_STATE_IP_PLAY_SELECT;
									}

									break;
								}
				
							default:	
								break;
							}
					}
					else 
					{
						if(SsmCheckPlay(m_IpCh[i].iChId) > 0) // end of playing "Select"
						{
							if(++m_IpCh[i].ulTimeOutCounter > 100) // wait DTMF key for maximum 10 seconds 
							{
								SsmHangup(m_IpCh[i].iChId);
							}
						} 
					}
					break;
				}

			case E_STATE_IP_CHECK_REC_START:
				{
					if(SsmGetRxDtmfLen(m_IpCh[i].iChId) >= 1) 
					{
						SsmClearRxDtmfBuf(m_IpCh[i].iChId);
						if( SsmRecToFile(m_IpCh[i].iChId,"test.voc",6,0L,10L*8000L,0,0) == -1) //start from 16000L,maxmium 10 seconds
						{
							AppErrorHandler(m_IpCh[i].iChId);
						}
						else
						{
							m_IpCh[i].Step = E_STATE_IP_CHECK_REC_END;
						}
					}
					else 
					{
						if(++m_IpCh[i].ulTimeOutCounter > 300) //wait 15 seconds for DTMF-key
						{
							SsmHangup(m_IpCh[i].iChId);
						}
					}
					break ;
				}
				
			case E_STATE_IP_CHECK_REC_END:
				{
					if(SsmGetRxDtmfLen(m_IpCh[i].iChId)>=1 || SsmChkRecToFile(m_IpCh[i].iChId) == 0)
					{
						SsmStopRecToFile(m_IpCh[i].iChId);
						m_IpCh[i].Step = E_STATE_IP_PLAY_SELECT;
					}
					break ;
				}

			case E_STATE_IP_WAIT_STATION_PICKUP:
				{
					if( SsmGetHookState(m_IpCh[i].nStationCh) ) //station is in pickup state now
					{
						SsmStopRing(m_IpCh[i].nStationCh);
						SsmTalkWith(m_IpCh[i].iChId, m_IpCh[i].nStationCh);	
						SetStationChState( m_IpCh[i].nStationCh, E_STATE_STATION_TALKING);
						m_IpCh[i].Step = E_STATE_IP_WAIT_STATION_HANGUP;
					}
					break;
				}

			case E_STATE_IP_WAIT_STATION_HANGUP:
				{
					if(!SsmGetHookState(m_IpCh[i].nStationCh) )   //station hang up
					{
						SsmStopTalkWith( m_IpCh[i].iChId, m_IpCh[i].nStationCh);
						SetStationChState( m_IpCh[i].nStationCh, E_STATE_STATION_IDLE);
						SetStationChTalkWith( m_IpCh[i].nStationCh, -1);
						m_IpCh[i].nStationCh = -1;
						m_IpCh[i].Step = E_STATE_IP_PLAY_SELECT;				
					}
					break;
				}
			} //?end switch( m_IpCh[i].Step )
		}
}
///////////////////////////////////////////////////////////////////////////////////////////////
int CCallDlg::SearchIdleStationCh()
{
	for( int i = 0; i < m_nTotalStationCh; i++ )
	{
		if( m_StationCh[i].Step == E_STATE_STATION_IDLE)
		{
			return m_StationCh[i].iChId;
		}
	}
	return -1;
}
///////////////////////////////////////////////////////////////////////////////////////////////
void CCallDlg::SetStationChState(int iChId, STATIONCH_STATE state)
{
	for( int i = 0; i< m_nTotalStationCh; i++ )
	{
		if( m_StationCh[i].iChId == iChId)
		{
			m_StationCh[i].Step = state;
			return;
		}
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////
void CCallDlg::SetStationChTalkWith(int iChId, int iTalkWithChId)
{
	for( int i = 0; i< m_nTotalStationCh; i++ )
	{
		if( m_StationCh[i].iChId == iChId)
		{
			m_StationCh[i].iTalkWithChId = iTalkWithChId;
			return;
		}
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////
void CCallDlg::AppErrorHandler(int ch)
{
	char szErrMsg[124];
	SsmGetLastErrMsg(szErrMsg);
	m_strErrMsg = szErrMsg;
	UpdateData(FALSE);
}
///////////////////////////////////////////////////////////////////////////////////////////////
void CCallDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	for(int i = 0; i < m_nTotalAnalogCh; i++)
	{
		if(m_AnalogCh[i].Step != E_STATE_ANALOG_IDLE)
		{
			SsmHangup(m_AnalogCh[i].iChId);
		}
	}

	for(int n = 0; n < m_nTotalIpCh; n++)
	{
		if(m_IpCh[n].Step != E_STATE_IP_IDLE)
		{
			SsmHangup(m_IpCh[n].iChId);
		}
	}

	for(int m = 0; m < m_nTotalStationCh; m++)
	{
		if(m_StationCh[m].Step != E_STATE_STATION_IDLE)
		{
			if(m_StationCh[n].Step == E_STATE_STATION_RINGING)
			SsmStopRing(m_StationCh[n].iChId);
		}
	}
	
	if(m_bInited)
	{
		SsmCloseCti();
	}
	
	_CrtDumpMemoryLeaks();		
}
///////////////////////////////////////////////////////////////////////////////////////////////
BOOL CCallDlg::InitCtiSystem()
{
	if(SsmStartCti("ShConfig.ini", "ShIndex.ini")) 
	{
		char szErrMsg[300];
		SsmGetLastErrMsg(szErrMsg);				
		AfxMessageBox(szErrMsg, MB_OK) ;
		return FALSE;
    }
	else
	{
		m_bInited = TRUE;
	}

	if(SsmGetMaxCfgBoard() != SsmGetMaxUsableBoard())
	{
		char szErrMsg[124];
		SsmGetLastErrMsg(szErrMsg);					
		AfxMessageBox(szErrMsg, MB_OK) ;

⌨️ 快捷键说明

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