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

📄 pbxdlg.cpp

📁 三汇CTI示例程序源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				if(SsmClearRxDtmfBuf(m_StationCh[nIndex].nChId) == -1)
				{
					AppErrorHandler(m_StationCh[nIndex].nChId);
				}

				// 对通道各个参数进行附初值
				m_StationCh[nIndex].nStatus = STATION_IDLE;
				m_StationCh[nIndex].bPressFlag = FALSE;
				m_StationCh[nIndex].bSubmiteChHookFlag = FALSE;
				m_StationCh[nIndex].nSaveSubmiteCh = -1;
				m_StationCh[nIndex].nTimer = -1;
				m_StationCh[nIndex].nLinkToChId = -1;
				memset(m_StationCh[nIndex].szCallerId, '\0', MAX_TELNUM_LEN);		// 清空主叫号码
				memset(m_StationCh[nIndex].szCalleeId, '\0', MAX_TELNUM_LEN);		// 清空被叫号码	
			}
			else if(nHook == 1)	// 座席摘机
			{
				cString.LoadString(IDS_PBX30);
				LogToList(LOGTYPE_INFORMATION, m_StationCh[nIndex].nChId, (LPTSTR)(LPCTSTR)cString, m_StationCh[nIndex].szStationNum);
				
				switch(m_StationCh[nIndex].nStatus)
				{
				case STATION_IDLE:
					{
						memset(m_StationCh[nIndex].szPhoneNumBuf, '\0', sizeof(char)*MAX_TELNUM_LEN);
						m_StationCh[nIndex].nStatus = STATION_GET_1STDTMF;

						// 清空通道DTMF缓冲区
						if(SsmClearRxDtmfBuf(m_StationCh[nIndex].nChId) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}

						// 启动T1: 25秒
						if( (m_StationCh[nIndex].nTimer = SsmStartTimer(25000, 1)) == -1)	
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
						
						//播放放欢迎提示音乐
						if(SsmPlayFile(m_StationCh[nIndex].nChId, "DemoVoc\\Welcome2.wav", -1, 0, 0xffffffff) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}

						// 设置抢拨开关即如果有DTMF按下就停音乐
						if(SsmSetDtmfStopPlay(m_StationCh[nIndex].nChId, 1) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}

						break;
					}
				case STATION_LOCAL_RING:
					{
						// 停止震铃
						if(SsmStopRing(m_StationCh[nIndex].nChId) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
						m_StationCh[nIndex].nStatus = STATION_TALKING;
						// 发送E_US_PICKUP
						SendMessage(WM_USER+E_US_PICKUP, m_StationCh[nIndex].nLinkToChId, m_StationCh[nIndex].nChId);
						break;
					}
				default:
					break;
				}			
			}
			break;
		}// end case E_CHG_HookState
	case E_CHG_RcvDTMF:		//座席收到DTMF事件
		{
			dwDtmfLen = lParam >> 16;
			dwDtmfNum = lParam & 0xFFFF;
		
			switch(m_StationCh[nIndex].nStatus)
			{
			case STATION_GET_1STDTMF:
				{
					// 关闭T1
					if(SsmStopTimer(m_StationCh[nIndex].nTimer) == -1)	
					{
						AppErrorHandler(m_StationCh[nIndex].nChId);
					}

					m_StationCh[nIndex].nTimer = -1;

					// 得到第一个DTMF
					m_StationCh[nIndex].szPhoneNumBuf[dwDtmfLen-1] = dwDtmfNum;

					switch(dwDtmfNum)
					{
						case '0':
							{
								cString.LoadString(IDS_PBX31);
								LogToList(LOGTYPE_INFORMATION, -1, (LPTSTR)(LPCTSTR)cString, m_StationCh[nIndex].szStationNum);
	
								memset(m_StationCh[nIndex].szPhoneNumBuf, '\0', sizeof(char)*MAX_TELNUM_LEN);
								// 搜索空闲的模拟通道
								m_StationCh[nIndex].nLinkToChId = SsmSearchIdleCallOutCh(1, 0);

								if((m_StationCh[nIndex].nLinkToChId >= 0) && (SsmGetChType(m_StationCh[nIndex].nLinkToChId) == 0))
								{					
									if(SsmClearRxDtmfBuf(m_StationCh[nIndex].nChId) == -1)
									{
										AppErrorHandler(m_StationCh[nIndex].nChId);
									}
									m_StationCh[nIndex].nStatus = STATION_REQ_ANALOG;
									// 发送E_US_SEIZURE_TK
									SendMessage(WM_USER+E_US_SEIZURE_TK, m_StationCh[nIndex].nLinkToChId, m_StationCh[nIndex].nChId);
								}
								else
								{
									// 说明:调用SsmSearchIdleCallOutCh时如果返回值是-1有可能是调用函数失败也有可能没有找到空闲的通道
									if(m_StationCh[nIndex].nLinkToChId == -1)
									{
										AppErrorHandler(m_StationCh[nIndex].nChId);
									}
	
									if(SsmSendTone(m_StationCh[nIndex].nChId, 1) == -1)
									{
										AppErrorHandler(m_StationCh[nIndex].nChId);
									}
									m_StationCh[nIndex].nStatus = STATION_WAIT_HANGUP;
								}
								break;
							}
						case '2':
							{
								cString.LoadString(IDS_PBX32);
								LogToList(LOGTYPE_INFORMATION, -1, (LPTSTR)(LPCTSTR)cString, m_StationCh[nIndex].szStationNum);

								m_StationCh[nIndex].nStatus = STATION_GET_DTMF;
								// 启动T2:8秒
								if( (m_StationCh[nIndex].nTimer = SsmStartTimer(8000, 1)) == -1)
								{
									AppErrorHandler(m_StationCh[nIndex].nChId);
								}
								break;
							}
						case '#':
							{
								cString.LoadString(IDS_PBX33);
								LogToList(LOGTYPE_INFORMATION, -1, (LPTSTR)(LPCTSTR)cString, m_StationCh[nIndex].szStationNum);

								memset(m_StationCh[nIndex].szPhoneNumBuf, '\0', sizeof(char)*MAX_TELNUM_LEN);
								// 搜索空闲的IP通道
								if(m_nIPProtocol == PROTOCOL_H323)
								{
									m_StationCh[nIndex].nLinkToChId = SsmSearchIdleCallOutCh(0x1 << 9, 0);
								}
								else
								{
									m_StationCh[nIndex].nLinkToChId = SsmSearchIdleCallOutCh(0x1 << 8, 0);
								}
								if((m_StationCh[nIndex].nLinkToChId >= 0) && (SsmGetChType(m_StationCh[nIndex].nLinkToChId) == m_nIPProtocol))
								{					
									if(SsmClearRxDtmfBuf(m_StationCh[nIndex].nChId) == -1)
									{
										AppErrorHandler(m_StationCh[nIndex].nChId);
									}
								
									m_StationCh[nIndex].nStatus = STATION_REQ_IP;
									// 发送E_US_SEIZURE_IP
									SendMessage(WM_USER+E_US_SEIZURE_IP, m_StationCh[nIndex].nLinkToChId, m_StationCh[nIndex].nChId);
								}
								else
								{
									// 说明:调用SsmSearchIdleCallOutCh时如果返回值是-1有可能是调用函数失败也有可能没有找到空闲的通道
									if(m_StationCh[nIndex].nLinkToChId == -1)
									{
										AppErrorHandler(m_StationCh[nIndex].nChId);
									}
					
									if(SsmSendTone(m_StationCh[nIndex].nChId, 1) == -1)
									{
										AppErrorHandler(m_StationCh[nIndex].nChId);
									}
									m_StationCh[nIndex].nStatus = STATION_WAIT_HANGUP;
								}
								break;
							}
						default:
							{
								// 向座席发送忙音
								if(SsmSendTone(m_StationCh[nIndex].nChId, 1) == -1)
								{
									AppErrorHandler(m_StationCh[nIndex].nChId);
								}
								m_StationCh[nIndex].nStatus = STATION_WAIT_HANGUP;
								break;
							}
					}
					break;
				}
			case STATION_GET_DTMF:
				{
					if(dwDtmfLen == MAX_STATION_DTMFLEN)
					{
						m_StationCh[nIndex].szPhoneNumBuf[dwDtmfLen-1] = dwDtmfNum;
						// 关闭T2
						if(SsmStopTimer(m_StationCh[nIndex].nTimer) == -1)	
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
			
						m_StationCh[nIndex].szPhoneNumBuf[MAX_STATION_DTMFLEN] = '\0';
						for(int i = 0; i < m_nTotalStationCh ; i++)
						{
							// 由分机号码查出通道Ch-k
							if ( (strcmp(m_StationCh[nIndex].szPhoneNumBuf, m_StationCh[i].szStationNum) == 0 ) && i != nIndex)
							{
								m_StationCh[nIndex].nLinkToChId = m_StationCh[i].nChId;
								m_StationCh[nIndex].nStatus = STATION_REQ_STATION;
								// 发送E_US_SEIZURE
								SendMessage(WM_USER+E_US_SEIZURE, m_StationCh[nIndex].nLinkToChId, m_StationCh[nIndex].nChId);	//向被叫发送占用请求	
							}
						}
				
						if(m_StationCh[nIndex].nLinkToChId == -1)
						{
							// 向座席发送忙音
							if(SsmSendTone(m_StationCh[nIndex].nChId, 1) == -1)
							{
								AppErrorHandler(m_StationCh[nIndex].nChId);
							}
							m_StationCh[nIndex].nStatus = STATION_WAIT_HANGUP;
						}
					}//end of first if
					else
					{
						m_StationCh[nIndex].szPhoneNumBuf[dwDtmfLen-1] = dwDtmfNum;

						// 通过关闭定时器T2,和启动T2来实现T2清零
						if(SsmStopTimer(m_StationCh[nIndex].nTimer) == -1)	
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
						if( (m_StationCh[nIndex].nTimer = SsmStartTimer(8000, 1)) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
					}
					break;
				}
			case STATION_DIALOUT_WITH_ANALOG:
				{
					// 通过关闭定时器T3,和启动T3来实现T3清零
					if(SsmStopTimer(m_StationCh[nIndex].nTimer) == -1)	
					{
						AppErrorHandler(m_StationCh[nIndex].nChId);
					}
					if( (m_StationCh[nIndex].nTimer = SsmStartTimer(9000, 1)) == -1)
					{
						AppErrorHandler(m_StationCh[nIndex].nChId);
					}
			
					// 发送E_US_DTMF2TK
					SendMessage(WM_USER+E_US_DTMF2TK, m_StationCh[nIndex].nLinkToChId, lParam);		// 向外线模拟通道发送DTMF码事件
					break;
				}
			case STATION_DIALOUT_WITH_IP:
				{
					// 通过关闭定时器T3,和启动T3来实现T3清零
					if(SsmStopTimer(m_StationCh[nIndex].nTimer) == -1)	
					{
						AppErrorHandler(m_StationCh[nIndex].nChId);
					}
					if( (m_StationCh[nIndex].nTimer = SsmStartTimer(9000, 1)) == -1)
					{
						AppErrorHandler(m_StationCh[nIndex].nChId);
					}
					// 发送E_US_DTMF2IP
					SendMessage(WM_USER+E_US_DTMF2IP, m_StationCh[nIndex].nLinkToChId, lParam);		//向IP通道发送DTMF码事件
					break;
				}		
			case STATION_F_GET_DTMF:
				{
					if(dwDtmfLen == MAX_STATION_DTMFLEN)
					{
						m_StationCh[nIndex].szPhoneNumBuf[dwDtmfLen-1] = dwDtmfNum;
						// 关闭T4
						if(SsmStopTimer(m_StationCh[nIndex].nTimer) == -1)	
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}

						m_StationCh[nIndex].szPhoneNumBuf[MAX_STATION_DTMFLEN] = '\0';

						for(int i=0; i<m_nTotalStationCh; i++)
						{
							// 内线规则判断?
							if( (strcmp(m_StationCh[nIndex].szPhoneNumBuf, m_StationCh[i].szStationNum) ==0) && i != nIndex )
							{
								m_StationCh[nIndex].nLinkToChId = i;
								m_StationCh[nIndex].nStatus = STATION_F_REQ_STATION;
								// F_US_ SEIZURE→ch2
								SendMessage(WM_USER+F_US_SEIZURE, m_StationCh[nIndex].nLinkToChId, m_StationCh[nIndex].nChId);	//向座席发送占用事件	
							}
						}
						
						if(m_StationCh[nIndex].nLinkToChId == -1)
						{
							// 向座席发送忙音
							if(SsmSendTone(m_StationCh[nIndex].nChId, 1) == -1)
							{
								AppErrorHandler(m_StationCh[nIndex].nChId);
							}

							m_StationCh[nIndex].nStatus = STATION_F_OPERATE;
						}
					}// end of first if
					else
					{
						m_StationCh[nIndex].szPhoneNumBuf[dwDtmfLen-1] = dwDtmfNum;
						// 通过关闭定时器T4,和启动T4来实现T4清零
						if(SsmStopTimer(m_StationCh[nIndex].nTimer) == -1)	
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
						if( (m_StationCh[nIndex].nTimer = SsmStartTimer(8000, 1)) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
					}
					break;
				}
			case STATION_REQ_STATION:
				break;
			case STATION_RING_BACK:
				break;
			case STATION_TALKING:
				break;
			case STATION_WAIT_HANGUP:
				break;
			case STATION_LOCAL_RING:
				break;
			case STATION_REQ_ANALOG:
				break;
			case STATION_WAIT_REMOTE_ANALOG_PICKUP:
				break;
			case STATION_REQ_IP:
				break;
			case STATION_WAIT_REMOTE_IP_PICKUP:
				break;
			case STATION_F_REQ_STATION:
				break;
			case STATION_F_RING_BACK:
				break;
			case STATION_F_TALKING:
				break;
			case STATION_F_OPERATE:
				break;
			default:
				break;
			}
			break;//end of switch for E_CHG_RcvDTMF
		}
	case E_CHG_FlashCount:
		{
			switch(m_StationCh[nIndex].nStatus)
			{
			case STATION_TALKING:
				{
					if(!m_StationCh[nIndex].bPressFlag)	// 闪断Flag==0?
					{
						// 断开总线(ch0,ch1)
						if(SsmStopTalkWith(m_StationCh[nIndex].nChId, m_StationCh[nIndex].nLinkToChId) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
						// E_MSG _FLASH→ch0
						SendMessage(WM_USER+E_MSG_FLASH, m_StationCh[nIndex].nLinkToChId, m_StationCh[nIndex].nChId);
						// 闪断Flag=1
						m_StationCh[nIndex].bPressFlag = TRUE;
						// 清空DTMF缓冲
						if(SsmClearRxDtmfBuf(m_StationCh[nIndex].nChId) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
						// 送拨号音
						if(SsmSendTone(m_StationCh[nIndex].nChId, 0) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}

						m_StationCh[nIndex].nSaveSubmiteCh = m_StationCh[nIndex].nLinkToChId;			
						m_StationCh[nIndex].nStatus =STATION_F_GET_DTMF;
						m_StationCh[nIndex].nLinkToChId = -1;

						// 启动T4:8秒
						if( (m_StationCh[nIndex].nTimer = SsmStartTimer(8000, 1)) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
					}
					break;
				}
			case STATION_F_GET_DTMF:
				{
					// 关闭T4
					if(SsmStopTimer(m_StationCh[nIndex].nTimer) == -1)	
					{
						AppErrorHandler(m_StationCh[nIndex].nChId);
					}
					// 停拨号音
					nToneType = -2;
					nToneChResult = SsmChkSendTone(m_StationCh[nIndex].nChId, &nToneType);
					if(nToneChResult == -1)
					{
						AppErrorHandler(m_StationCh[nIndex].nChId);
					}
					else
					{
						if(nToneChResult == 1)
						{
							if(SsmStopSendTone(m_StationCh[nIndex].nChId) == -1)
							{
								AppErrorHandler(m_StationCh[nIndex].nChId);
							}
						}
					}
			
					// Ch0挂机Flag==0?
					if(m_StationCh[nIndex].bSubmiteChHookFlag)
					{
						if(SsmSendTone(m_StationCh[nIndex].nChId, 3) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
						m_StationCh[nIndex].nStatus = STATION_WAIT_HANGUP;
					}
					else								
					{
						m_StationCh[nIndex].nStatus = STATION_TALKING;	
						m_StationCh[nIndex].nLinkToChId = m_StationCh[nIndex].nSaveSubmiteCh;
						// E_MSG_CONNECT→ch0
						SendMessage(WM_USER+E_MSG_CONNECT, m_StationCh[nIndex].nLinkToChId, m_StationCh[nIndex].nChId);	
						// 闪断Flag=0
						m_StationCh[nIndex].bPressFlag = FALSE;
						m_StationCh[nIndex].nSaveSubmiteCh = -1;
				
						// 连接总线
						if(SsmTalkWith(m_StationCh[nIndex].nChId, m_StationCh[nIndex].nLinkToChId) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
						// 清空通道DTMF缓冲区
						if(SsmClearRxDtmfBuf(m_StationCh[nIndex].nChId) == -1)
						{
							AppErrorHandler(m_StationCh[nIndex].nChId);
						}
					}
					break;
				}
			case STATION_F_REQ_STATION:
				{

⌨️ 快捷键说明

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