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

📄 fax_event_vcdlg.cpp

📁 VC6.0
💻 CPP
📖 第 1 页 / 共 5 页
字号:


void CFax_Event_VCDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here

	// unload speech data loaded in the memory
	SsmFreeIndexData(1);	
	SsmFreeIndexData(2);
	//close board drivers
	if(SsmCloseCti() == -1)	
		WriteLog("Failed to call SsmCloseCti");
}


LRESULT CFax_Event_VCDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class

	int		nEventCode; //event ID
	int		nCh;		//channel ID
	int		nCheck;

	if(message > WM_USER)
	{
		nEventCode = message - WM_USER;
		if(nEventCode == E_SYS_TIMEOUT)
		{
			// identify the channel number according to the flag 'timer'
			for(int i = 0; i < m_nTotalCh; i++)
			{
				if(wParam == (WPARAM)(m_TrkCh[i].nTimer))
				{
					nCh = i;
					break;
				}
			}
		}
		else
			nCh = wParam;
		nCheck = SsmGetChType(nCh);
		if(nCheck == -1)
		{
			WriteLog("Fail to call SsmGetChType");
		}
		else if(nCheck == FAX_CH || nCheck == SOFTFAX_CH)
		{
			FaxProc(nEventCode, nCh, lParam);
		}
		else
		{
			if(m_TrkCh[nCh].bEnCalled == TRUE)
			{
				TrunkProc(nEventCode, nCh, lParam);
			}
		}
	}

	return CDialog::WindowProc(message, wParam, lParam);
}


void CFax_Event_VCDlg::TrunkProc(UINT event, WPARAM wParam, LPARAM lParam)
{
	int nCh, nFaxCh;
	int nChannel;
	char szRecFile[250];
	DWORD dwDtmf;
	DWORD dwToneAnalyze;
	int i;
	char temp[1];
	int nNewState;

	nCh = wParam;
	nFaxCh = wParam;
	switch(event)
	{
	case E_CHG_ChState:
		{
			nNewState = (int)(lParam & 0xFFFF);	//new state
			if(nNewState == S_CALL_RINGING)		//ring detected
			{
				if(m_TrkCh[nCh].nStep == TRK_IDLE)
				{
					m_TrkCh[nCh].bInUse = TRUE;
					if(SsmPickup(nCh) == -1)	//pick up
						WriteLog("Fail to call SsmPickup");
					m_TrkCh[nCh].nCallFlag = 0;
	
					sprintf(szRecFile,"channel%d.pcm", nCh);
					if(m_TrkCh[nCh].bRecord)	
					{
						if(SsmRecToFile(nCh, szRecFile, -1, 0, -1, -1, 0) == -1)	//record
							WriteLog("Fail to call SsmRecToFile");

						// turn on record mixer
						if(SsmSetRecMixer(nCh, 1, 0) == -1)		
							WriteLog("Fail to call SsmSetRecMixer");
					}
			

					if(SsmGetCallerId(nCh, m_TrkCh[nCh].szCallerId) == -1)
						WriteLog("Fail to call SsmGetCallerId");
					CString str;
					m_SecondDlg.m_cmbFaxCh.GetWindowText(str);
					if(str == "None")
						nChannel = -1;
					else
						nChannel = atoi(str);
					if(nChannel != -1)
					{
						if(m_FaxCh[nChannel].nStep != FAX_IDLE || m_FaxCh[nChannel].bInUse == TRUE)
						{
							if((nChannel = FindAnIdleFaxCh()) == -1)
							{
								// idle fax channel is unavailable
								Hangup(nCh);
								break;
							}	
						}
					}
					else			
					{	
						if((nChannel = FindAnIdleFaxCh()) == -1)
						{
							// idle fax channel is unavailable
							Hangup(nCh);
							break;
						}
					}


					// idle fax channel is available						
					m_FaxCh[nChannel].bInUse = TRUE;

					// manual
					if(m_TrkCh[nCh].nAutoOrNot)
					{
						m_TrkCh[nCh].nStep = TRK_PLAY_VOC1;	
						m_TrkCh[nCh].nToFaxCh = nChannel;
						//m_TrkCh[nCh].bLinked = TRUE;
						m_FaxCh[nChannel].nTrunkCh = nCh;
						// turn on 'DTMF_stop_play' switch
						if(SsmSetDtmfStopPlay(nCh, 1) == -1)			
							WriteLog("Fail to call SsmSetDtmfStopPlay");
						if(SsmPlayIndexString(nCh, "1") == -1)			//play voice 1
							WriteLog("Fail to call SsmPlayIndexString");
						if(SsmClearRxDtmfBuf(nCh) == -1)				//Clear buffer
							WriteLog("Fail to call SsmClearRxDtmfBuf");
						// turn on timer
						if((m_TrkCh[nCh].nTimer = SsmStartTimer(15000, 1)) == -1)
							WriteLog("Fail to call SsmStartTimer");
					}
					// automatic
					else						
					{
						m_TrkCh[nCh].nToFaxCh = nChannel;
						//m_TrkCh[nCh].bLinked = TRUE;
						m_FaxCh[nChannel].nDirection = C_RECEIVE_FAX;	//receive
						m_FaxCh[nChannel].nTrunkCh = nCh;
						m_TrkCh[nCh].nStep = TRK_FAXING;

						// set up bus connection between fax and trunk channel
						if(SsmTalkWith(nCh, nChannel) == -1)			
							WriteLog("Fail to call SsmTalkWith");
						SendMessage(WM_USER+E_MSG_RCV_FAX, nChannel, nCh);
					}
				}
			}

			// remote hungup
			else if(nNewState == S_CALL_PENDING)	
			{
				if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1)
				{	
					// turn off timer
					if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
						WriteLog("Fail to call SsmStopTimer");
					m_TrkCh[nCh].nTimer = -1;
					if(SsmStopPlayIndex(nCh) == -1)
						WriteLog("Fail to call SsmStopPlayIndex");
				}

				else if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC2)
				{
					if(SsmStopPlayIndex(nCh) == -1)
						WriteLog("Fail to call SsmStopPlayIndex");
				}
				else if(m_TrkCh[nCh].nStep == TRK_FAXING)
				{
					// tear down bus connection between fax and trunk channel
					if(SsmStopTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)
						WriteLog("Fail to call SsmStopTalkWith");
					SendMessage(WM_USER+E_MSG_OFFLINE, m_TrkCh[nCh].nToFaxCh, NULL);
				}
				Hangup(nCh);
			}
		}
		break;

	// event generated by the driver when DTMF is received
	case E_CHG_RcvDTMF:	
		{
			dwDtmf = lParam & 0xFFFF;	//the latest DTMF received
			*temp = (char)dwDtmf;
			m_TrkCh[nCh].szDtmf[m_TrkCh[nCh].nIndex++] = *temp;
			if(m_TrkCh[nCh].nIndex >= 99)
			{
				m_TrkCh[nCh].nIndex = 0;
			}
			m_TrkCh[nCh].szDtmf[m_TrkCh[nCh].nIndex] = 0;

			if((*temp) ==  '1' || (*temp) == '2')
			{
				if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1)
				{
					m_TrkCh[nCh].szDtmfChose = *temp;
					if (SsmCheckPlay(nCh)==0) SsmStopPlayIndex(nCh);
					if(SsmPlayIndexString(nCh, "2") == -1)	//play voice 2
						WriteLog("Fail to call SsmPlayIndexString");
					if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
						WriteLog("Fail to call SsmStopTimer");
					m_TrkCh[nCh].nTimer = -1;
					m_TrkCh[nCh].nStep = TRK_PLAY_VOC2;
				}
			}
		}
		break;

	// event generated by the driver when the timer is overtime
	case E_SYS_TIMEOUT:
		{
			if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
				WriteLog("Fail to call SsmStopTimer");
			m_TrkCh[nCh].nTimer = -1;
			Hangup(nCh);
		}

	// event generated by the driver when the result of tone analysis changes
	case E_CHG_ToneAnalyze:	
		{
			dwToneAnalyze = lParam & 0xFFFF;	//the result of tone analysis
			i = dwToneAnalyze;
			if(i == 7)	//F1 tone 
			{
				if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1
					|| m_TrkCh[nCh].nStep == TRK_PLAY_VOC2)
				{
					if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1)
					{
						if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
							WriteLog("Fail to call SsmStopTimer");
						m_TrkCh[nCh].nTimer = -1;
					}

					m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_RECEIVE_FAX;	//receive
					if(SsmStopPlayIndex(nCh) == -1)	//stop playing
						WriteLog("Fail to call SsmStopPlayIndex");
					if(SsmTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)
						WriteLog("Fail to call SsmTalkWith");

					m_TrkCh[nCh].nStep = TRK_FAXING;	
					SendMessage(WM_USER+E_MSG_RCV_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
				}
			}
			else if(i == 8)	//F2 tone
			{
				if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1
					|| m_TrkCh[nCh].nStep == TRK_PLAY_VOC2)
				{
					if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC1)
					{
						if(SsmStopTimer(m_TrkCh[nCh].nTimer) == -1)
							WriteLog("Fail to call SsmStopTimer");
						m_TrkCh[nCh].nTimer = -1;
					}

					m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_SEND_FAX;	//send
					if(SsmStopPlayIndex(nCh) == -1)	//stop playing
						WriteLog("Fail to call SsmStopPlayIndex");
					if(SsmTalkWith(m_TrkCh[nCh].nToFaxCh, nCh) == -1)	
						WriteLog("Fail to call SsmTalkWith");
				
					m_TrkCh[nCh].nStep = TRK_FAXING;
					SendMessage(WM_USER+E_MSG_SEND_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
				}
			}
		}
		break;

	// event generated by the driver when the playing stops 
	case E_PROC_PlayEnd:	
		{
			if(m_TrkCh[nCh].nStep == TRK_PLAY_VOC2)
		
			{
				if(SsmTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)
					WriteLog("Fail to call SsmTalkWith");
				if(m_TrkCh[nCh].szDtmfChose == '1')	
				{
					m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_SEND_FAX;	//send
					SendMessage(WM_USER+E_MSG_SEND_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
				}
				else
				{
					m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_RECEIVE_FAX;//receive
					SendMessage(WM_USER+E_MSG_RCV_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
				}
								
				m_TrkCh[nCh].nStep = TRK_FAXING;
			}
		}
		break;

	// event generated by the driver when the fax channel state turns to be idle
	case E_MSG_FAX_IDLE:
		{
			if(SsmStopTalkWith(nCh, nFaxCh) == -1)
				WriteLog("Fail to call SsmStopTalkWith");
			Hangup(nCh);
		}
		break;

	// event generated by the driver when the task of auto-dialing progresses
	case E_PROC_AutoDial:
		{
			i = lParam;
			if(m_TrkCh[nCh].nStep == TRK_DIALING)
			{
				switch(i)
				{
				case DIAL_NO_DIALTONE:
					if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
						strcpy(m_TrkCh[nCh].szChErrMsg, "无拨号音");
					else 
						strcpy(m_TrkCh[nCh].szChErrMsg, "No dial tone");

					WriteLog(m_TrkCh[nCh].szChErrMsg);
					Hangup(nCh);
					break;
				case DIAL_BUSYTONE:
					if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
						strcpy(m_TrkCh[nCh].szChErrMsg, "忙音");
					else 
						strcpy(m_TrkCh[nCh].szChErrMsg, "Busy tone");
					WriteLog(m_TrkCh[nCh].szChErrMsg);
					Hangup(nCh);
					break;
				case DIAL_ECHO_NOVOICE:
					if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
						strcpy(m_TrkCh[nCh].szChErrMsg, "回铃后无声");
					else 
						strcpy(m_TrkCh[nCh].szChErrMsg, "Silent after ringback tone");
					WriteLog(m_TrkCh[nCh].szChErrMsg);
					Hangup(nCh);
					break;
				case DIAL_NOVOICE:
					if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
						strcpy(m_TrkCh[nCh].szChErrMsg, "拨号后无声");
					else 
						strcpy(m_TrkCh[nCh].szChErrMsg, "Silent after dial tone");
					WriteLog(m_TrkCh[nCh].szChErrMsg);
					Hangup(nCh);
					break;
				case DIAL_VOICEF1:
					if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
						strcpy(m_TrkCh[nCh].szChErrMsg, "对端传真机摘机,并处于发送状态");
					else 
						strcpy(m_TrkCh[nCh].szChErrMsg, "The receiver's fax machine answers and it is in transmitting process");
					WriteLog(m_TrkCh[nCh].szChErrMsg);
					Hangup(nCh);
					break;
				case DIAL_NOANSWER:
					if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
						strcpy(m_TrkCh[nCh].szChErrMsg, "没人接听");
					else 
						strcpy(m_TrkCh[nCh].szChErrMsg, "Nobody answers");
					WriteLog(m_TrkCh[nCh].szChErrMsg);
					Hangup(nCh);
					break;			
	
				// called party picked up (voice detected)
				case DIAL_VOICE:	
					if(!m_TrkCh[nCh].nAutoOrNot)	//send automatically
					{
						if(SsmTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)	
							WriteLog("Fail to call SsmTalkWith");						
						m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_SEND_FAX;		//send
						m_TrkCh[nCh].nStep = TRK_FAXING;
						SendMessage(WM_USER+E_MSG_SEND_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
					}
					else	//manual
					{
						// turn on 'DTMF_stop_play' switch
						if(SsmSetDtmfStopPlay(nCh, 1) == -1)				
							WriteLog("Fail to call SsmSetDtmfStopPlay");	
						if(SsmPlayIndexString(nCh, "1") == -1)			//play voice 1
							WriteLog("Fail to call SsmPlayIndexString");
						if(SsmClearRxDtmfBuf(nCh) == -1)				//clear DTMF buffer
							WriteLog("Fail to call SsmClearRxDtmfBuf");
						if((m_TrkCh[nCh].nTimer = SsmStartTimer(15000, 1)) == -1)
							WriteLog("Fail to call SsmStartTimer");
						m_TrkCh[nCh].nStep = TRK_PLAY_VOC1;
					}
					break;
				//F2 tone detected
				case DIAL_VOICEF2:					
					if(SsmTalkWith(nCh, m_TrkCh[nCh].nToFaxCh) == -1)	
						WriteLog("Fail to call SsmTalkWith");
					m_FaxCh[m_TrkCh[nCh].nToFaxCh].nDirection = C_SEND_FAX;		//send
					m_TrkCh[i].nStep = TRK_FAXING;
					SendMessage(WM_USER+E_MSG_SEND_FAX, m_TrkCh[nCh].nToFaxCh, nCh);
					break;
				case DIAL_INVALID_PHONUM:
					if(g_dwLanguageConversion == g_dwCHINESE_SIMPLIFIED)
						strcpy(m_TrkCh[nCh].szChErrMsg, "空号");
					else 
						strcpy(m_TrkCh[nCh].szChErrMsg, "empty phone number");
					WriteLog(m_TrkCh[nCh].szChErrMsg);
					Hangup(nCh);
					break;	
				default :
					break;
				}//end of switch
			}//end of if

⌨️ 快捷键说明

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