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

📄 shr_devent_vcdlg.cpp

📁 三汇CTI示例程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				}
				break;
			case E_RCV_DSTDChannel:
				{
					switch(pEvent->dwParam)			//Judge D-Channel event
					{
					case DST_OFFHOOK:
						{
							ChannelState[ch].Dir = UP;
							ChannelState[ch].WorkState = CH_ACTIVE;
							ChannelState[ch].Lcd[0] = '\0';
							ClearCallID(pEvent);	//Clear phone number buffer
							StartRecord(ch);		//Start record
						}
						break;
					case DST_RING_ON:
						{
							ChannelState[ch].Dir = DOWN;
							ChannelState[ch].WorkState = CH_RING;
							ClearCallID(pEvent);	//Clear phone number buffer
							ChannelState[ch].Lcd[0] = '\0';
						}
						break;
					case DST_MSG_CHG:
						{
							strncpy(ChannelState[ch].Lcd, (char*)pEvent->pvBuffer, pEvent->dwDataLength);
							ChannelState[ch].LCDLen = pEvent->dwDataLength;
						}
						break;
					default:
						break;
					}
				}
				break;
			default:
				break;
			}
		}
		break;
	case CH_RING:
		{
			switch(pEvent->wEventCode)                  
			{
			case E_CHG_ChState:
				{
					if ((pEvent->dwParam & 0xffff) == S_CALL_OFFLINE) //Judge channel state 				 
					{ 
						ChannelState[ch].Dir = UNKNOWN;
						ChannelState[ch].WorkState = CH_OFFLINE;
						ChannelState[ch].Lcd[0] = '\0';
						ClearCallID(pEvent);	//Clear phone number buffer

					}
				}
				break;
			case E_RCV_DSTDChannel:
				{
					switch(pEvent->dwParam)
					{
					case DST_RING_OFF:
						{
							ChannelState[ch].Dir = UNKNOWN;
							ChannelState[ch].WorkState = CH_IDLE;
							GetCallID(pEvent);			//Get phone number
						}
						break;
					case DST_OFFHOOK:
						{
							ChannelState[ch].Dir = DOWN;
							ChannelState[ch].WorkState = CH_ACTIVE;
							StartRecord(ch);
						}
						break;
					case DST_MSG_CHG:
						{
							strncpy(ChannelState[ch].Lcd, (char *)pEvent->pvBuffer, pEvent->dwDataLength);
							ChannelState[ch].LCDLen = pEvent->dwDataLength;
						}
						break;
					default:
						break;
					}
				}
				break;
			default:
				break;
			}
		}
		break;
	case CH_ACTIVE:
		{
			switch(pEvent->wEventCode)                  
			{
			case E_CHG_ChState:
				{
					if ((pEvent->dwParam & 0xffff) == S_CALL_OFFLINE) //Judge channel state 				 
					{ 
						ChannelState[ch].Dir = UNKNOWN;
						ChannelState[ch].WorkState = CH_OFFLINE;
						ChannelState[ch].Lcd[0] = '\0';
						ClearCallID(pEvent);	//Clear phone number buffer
						if (ChannelState[ch].IsRecord)
						{
							StopRecord(ch);				//Stop record
						}
					}
				}
				break;
			case E_RCV_DSTDChannel:
				{
					switch(pEvent->dwParam)
					{
					case DST_ONHOOK:
						{
							ChannelState[ch].Dir = UNKNOWN;
							ChannelState[ch].WorkState = CH_IDLE;
							GetCallID(pEvent);
							StopRecord(ch);
						}
						break;
					case DST_MSG_CHG:
						{
							strncpy(ChannelState[ch].Lcd, (char *)pEvent->pvBuffer, pEvent->dwDataLength);
							ChannelState[ch].LCDLen = pEvent->dwDataLength;
						}
						break; 
					case DST_ABANDONED:
						{
							ChannelState[ch].WorkState = CH_WAITFOR_ONHOOK;
							GetCallID(pEvent);
							StopRecord(ch);
						}
						break;
					default:
						break;
					}
				}
				break;
			default:
				break;
			}
		}
		break;
	case CH_OFFLINE:
		{
			if ((pEvent->wEventCode==E_CHG_ChState) && ((pEvent->dwParam & 0xffff)==S_CALL_STANDBY))
			{
				ChannelState[ch].Dir = UNKNOWN;
				ChannelState[ch].Lcd[0] = '\0';
				ChannelState[ch].WorkState = CH_IDLE;
				ClearCallID(pEvent);	//Clear phone number buffer
			}
		}
		break;
	case CH_WAITFOR_ONHOOK:
		{
			switch(pEvent->wEventCode)        
			{
			case E_CHG_ChState:
				{
					if ((pEvent->dwParam & 0xffff) == S_CALL_OFFLINE) //Judge channel state 				 
					{ 
						ChannelState[ch].Dir = UNKNOWN;
						ChannelState[ch].WorkState = CH_OFFLINE;
						if (ChannelState[ch].IsRecord)
						{
							StopRecord(ch);				//Stop record
						}
					}
				}
				break;
			case E_RCV_DSTDChannel:
				{
					switch(pEvent->dwParam)
					{
					case DST_ONHOOK:
						{
							ChannelState[ch].Dir = UNKNOWN;
							ChannelState[ch].WorkState = CH_IDLE;
						}
						break;
					case DST_MSG_CHG:
						{
							strncpy(ChannelState[ch].Lcd, (char *)pEvent->pvBuffer, pEvent->dwDataLength);
							ChannelState[ch].LCDLen = pEvent->dwDataLength;
						}
						break;
					default:
						break;
					}
				}
				break;
			default:
				break;
			}
		}
		break;
	default:
		break;
	}
}//EventHandler End 

void CSHR_DEvent_VCDlg::GetCallID(PSSM_EVENT pEvent)
{
	WORD ch;
	int IDPos;
	int LCDPos;
	int NumStarPos = 0;
	int NumStopPos = 0;
	ch = pEvent->nReference;
	if (ChannelState[ch].LCDLen < 2)
	{
		return;
	}
	LCDPos = ChannelState[ch].LCDLen - 1;
	IDPos = 0;

	//find the number's start position and end position in the LCD information;
	while (LCDPos > 0)
	{
		if (NumStopPos == 0)
		{
			if ((int)ChannelState[ch].Lcd[LCDPos]<0x39 && (int)ChannelState[ch].Lcd[LCDPos]>0x30)
			{
				NumStopPos = LCDPos ;
			}
		}
		else
		{
			if ((int)ChannelState[ch].Lcd[LCDPos]>0x39 || (int)ChannelState[ch].Lcd[LCDPos]<0x30)
			{
				NumStarPos = LCDPos + 1;
				break ;
			}
		}
		LCDPos --;
	}
	if ((NumStarPos==0) && (NumStopPos==0) && (ChannelState[ch].Lcd[0]>0x39||ChannelState[ch].Lcd[0]<0x30))
	{
		return;			//not found any number;
	}
	ChannelState[ch].CallIdLen = NumStopPos - NumStarPos + 1;
	for(IDPos=0; IDPos<ChannelState[ch].CallIdLen; IDPos++)
	{
		ChannelState[ch].pCallId[IDPos] = ChannelState[ch].Lcd[NumStarPos];
		NumStarPos ++;
	}
	ChannelState[ch].pCallId[IDPos] = '\0';
	return;
}

void CSHR_DEvent_VCDlg::ClearCallID(PSSM_EVENT pEvent)
{
	WORD ch;
	ch = pEvent->nReference;
	memset(ChannelState[ch].pCallId, 0, MAX_CALLID_LEN);
	return;
}

void CSHR_DEvent_VCDlg::StartRecord(int ch)
{
	char recFile[256];
	_snprintf(recFile, 256, "Test%d.wav", ch);
	recFile[255] = '\0';

	//Start the file sound recording task on the designates channel. -1:error
	if(SsmRecToFile(ch, recFile, nRecFormat, 0L, 0xffffffff, 0, 0) == -1)  
	{																	
		SsmGetLastErrMsg(ChannelState[ch].pErrMsg);
		WriteLog(ChannelState[ch].pErrMsg);
	}
	ChannelState[ch].IsRecord = RECORD;
	return;
}

void CSHR_DEvent_VCDlg::StopRecord(int ch)
{
	int nreChkRecToFile;
	ChannelState[ch].IsRecord = UNRECORD;

	//Obtains the situation of the file sound recording task. -1:error
	nreChkRecToFile = SsmChkRecToFile(ch);						  
	if(nreChkRecToFile == -1)
	{
		SsmGetLastErrMsg(ChannelState[ch].pErrMsg);
		WriteLog(ChannelState[ch].pErrMsg);
	}
	if(nreChkRecToFile == 1)									//1:Recording
	{
		//Stop the file sound recording task. -1:error
		if(SsmStopRecToFile(ch) == -1)							 
		{
			SsmGetLastErrMsg(ChannelState[ch].pErrMsg);
			WriteLog(ChannelState[ch].pErrMsg);
		}
	}
	return;
}

void CSHR_DEvent_VCDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	UpdateData(TRUE);
	UpdateChannelState();
	UpdateData(FALSE);
	CDialog::OnTimer(nIDEvent);
}

void CSHR_DEvent_VCDlg::OnDestroy() 
{
	//Close the CTI driver -1:error
	if(SsmCloseCti() == -1)									 
	{
		SsmGetLastErrMsg(szErrMsg);
		WriteLog(szErrMsg);
	}
	CDialog::OnDestroy();
}

void CSHR_DEvent_VCDlg::OnRadioDefault() 
{
	// TODO: Add your control notification handler code here
	nRecFormat = -1;
}

void CSHR_DEvent_VCDlg::OnRadioA() 
{
	// TODO: Add your control notification handler code here
	nRecFormat = 6;
}

void CSHR_DEvent_VCDlg::OnRadioMiu() 
{
	// TODO: Add your control notification handler code here
	nRecFormat = 7;
}

void CSHR_DEvent_VCDlg::OnRadioIma() 
{
	// TODO: Add your control notification handler code here
	nRecFormat = 17;
}

void CSHR_DEvent_VCDlg::OnRadioGc8() 
{
	// TODO: Add your control notification handler code here
	nRecFormat = 131;
}

void CSHR_DEvent_VCDlg::OnRadioG729a() 
{
	// TODO: Add your control notification handler code here
	nRecFormat = 0xff83;
}

void CSHR_DEvent_VCDlg::OnButtonStartlisten() 
{
	// TODO: Add your control notification handler code here
	int Cur_Line ;
	Cur_Line = m_CurLine.GetCurSel();
	if (ListenChannel != Cur_Line )
	{
		if(ListenChannel < MaxLine)
		{
			if (SsmStopListenTo(ListenChannel,0) == -1)		//Stop listen
			{
				SsmGetLastErrMsg(szErrMsg);					//Get wrong message
				AfxMessageBox(szErrMsg, MB_OK, 0);
				WriteLog(szErrMsg);
				return;
			}
			ChannelState[ListenChannel].IsListen = UNLISTEN;
		}
		if (SsmListenTo(Cur_Line,0) == -1)					//Listen
		{
			SsmGetLastErrMsg(szErrMsg);						//Get wrong message
			AfxMessageBox(szErrMsg, MB_OK, 0);
			WriteLog(szErrMsg);
			return;
		}
		ChannelState[Cur_Line].IsListen = LISTEN;
		ListenChannel = Cur_Line;
		UpdateData(FALSE);
	}
	return;
}

void CSHR_DEvent_VCDlg::OnButtonStoplisten() 
{
	// TODO: Add your control notification handler code here
	if(ListenChannel < MaxLine)
	{
		ChannelState[ListenChannel].IsListen = UNLISTEN;
		if (SsmStopListenTo(ListenChannel,0) == -1)		// Stop listen
		{
			SsmGetLastErrMsg(szErrMsg);				   // Get wrong message
			AfxMessageBox(szErrMsg, MB_OK, 0);
			WriteLog(szErrMsg);
		}
		else
		{
			UpdateData(FALSE);
		}
		ListenChannel = MaxLine;
	}
	return;
}

void CSHR_DEvent_VCDlg::OnClickListTrk(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
	int nCurSel;
	int nItemSel;
	nCurSel = m_CurLine.GetCurSel();
	nItemSel = phdn->iItem;
	if (nCurSel != nItemSel)
	{
		m_CurLine.SetCurSel(nItemSel);
		UpdateData(FALSE);
	}
	*pResult = 0;
}

⌨️ 快捷键说明

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