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

📄 dtp_event.cpp

📁 三汇CTI示例程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "DTP_Event.h"
#include "shpa3api.h"
#include <stdio.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TDTP_Form *DTP_Form;
//---------------------------------------------------------------------------
__fastcall TDTP_Form::TDTP_Form(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void  __fastcall TDTP_Form::OnCreate(TObject *Sender)
{
        m_nCallFnMode = 0;
//        m_nRecFormat = 2;
	if(!InitCtiBoard())
	{
		PostQuitMessage(0);
                ShowMessage("fail to init board");
		return ;
	}
	//CHS: 设置事件驱动方式
	//ENG: Set event-driven mode
	EVENT_SET_INFO EventSet;
	EventSet.dwWorkMode = EVENT_MESSAGE;
	EventSet.lpHandlerParam = DTP_Form->Handle;//->GetSafeHwnd();
	if(SsmSetEvent(-1, -1, TRUE, &EventSet) == -1)
        {
		ShowMessage("Fail to call SsmSetEvent");
                return ;
        }
	if(SsmSetEvent(E_CHG_SpyState, -1, TRUE, &EventSet) == -1)
		ShowMessage("Fail to call SsmSetEvent when setting E_CHG_SpyState");


	InitCircuitListCtrl();		//initialize list
        return ;
}
//---------------------------------------------------------------------------
BOOL __fastcall TDTP_Form::InitCtiBoard()
{
	char szCurPath[MAX_PATH];		//CHS:当前路径
					   	//ENG:Current path
	char szShIndex[MAX_PATH];		//CHS:存放ShIndex.ini文件的路径
					    	//ENG:path to ShIndex.ini
	char szShConfig[MAX_PATH];		//CHS:存放ShConfig.ini文件的路径
					      	//ENG:path to ShConfig.ini
	char CErrMsg[500];	        		    //CHS:错误信息
        				        	//ENG:error message
	GetCurrentDirectory(MAX_PATH, szCurPath);
	strcpy(szShIndex, szCurPath);
	strcpy(szShConfig, szCurPath);
	strcat(szShIndex, "\\ShIndex.ini");
	strcat(szShConfig, "\\ShConfig.ini");

	//CHS: 将配置文件传递给驱动程序,并初始化系统
	//ENG: load configuration file and initialize system
	if(SsmStartCti(szShConfig, szShIndex) == -1)
	{
                SsmGetLastErrMsg(CErrMsg);//Get error message
		ShowMessage(CErrMsg);
                CErrMsg[0] = 0;
		return FALSE;
	}
	
	//CHS: 判断驱动已经初始化的板卡数和配置文件中配置的板卡数是否一致
	//ENG: Judge if the number of initialized boards is the same as
	//		   that of boards specified in the configuration file
	if(SsmGetMaxUsableBoard() != SsmGetMaxCfgBoard())
	{
                SsmGetLastErrMsg(CErrMsg);
		ShowMessage(CErrMsg);
		CErrMsg[0] = 0;
		return FALSE;
	}
	//CHS: 取得被监控电路的最大数
	//ENG: Get the maximum number of the monitored circuits
	nMaxCic = SpyGetMaxCic();
	if(nMaxCic == -1)
	{
		ShowMessage("Fail to call SpyGetMaxCic");
                return FALSE;
	}
        if(nMaxCic == 0)
        {
                ShowMessage("no monitored circuit");
                return FALSE;
        }

	String str[300];
	for(int i = 0; i < nMaxCic; i++)
	{
		memset(CicState[i].szCallInDtmf, 0, sizeof(char)*100);
		memset(CicState[i].szCallOutDtmf, 0, sizeof(char)*100);
		memset(CicState[i].szCallerId, 0, sizeof(char)*20);
		memset(CicState[i].szCalleeId, 0, sizeof(char)*20);
		CicState[i].nCicState = CIRCUIT_IDLE;
		CicState[i].nCallInIndex = 0;
		CicState[i].nCallOutIndex = 0;
		CicState[i].wRecDirection = MIX_RECORD;	    //mix-record
		CicState[i].nCallInCh = -1;	
		CicState[i].nCallOutCh = -1;
//                sprintf(str,"%d",i);
//		str.Format("%d", i);
                m_cmbCic->Items->Add(i);
//		m_cmbCic->InsertString(-1, str);
	}
        m_cmbCic->ItemIndex = 0;

	return TRUE;
}
//----------------------------------------------------
void __fastcall TDTP_Form::InitCircuitListCtrl()
{
        TListItem *ListItem;
        m_CicList->Color = TColor(RGB(0,0,0));
        m_CicList->Font->Color = TColor(RGB(0,255,0));
        m_CicList->RowSelect = true;
        m_CicList->GridLines = true;

	char dig[10];
	for(int i = 0; i < nMaxCic; i++)
	{
                ListItem = m_CicList->Items->Add();
                ListItem->Caption = i;
                UpdateCircuitListCtrl(i);
	}

}
//-----------------------------------------------------
void __fastcall TDTP_Form::UpdateCircuitListCtrl(int n)
{
	char szNewStat[100];
	char szOldStat[100];
        TListItem *tempItem;

//	nIndex = 0;
	{
                tempItem = m_CicList->Items->Item[n];
                tempItem->SubItems->Clear();

		//CHS:显示被监控电路的状态
		//ENG:Display the state of the monitored circuit
		switch(CicState[n].nCicState)
		{
		case CIRCUIT_IDLE:				strcpy(szNewStat, "Idle");					  break;
		case CIRCUIT_RCV_PHONUM:		strcpy(szNewStat, "Receiving Phone number");  break;
		case CIRCUIT_RINGING:			strcpy(szNewStat, "Ringing");				  break;
		case CIRCUIT_TALKING:			strcpy(szNewStat, "Talking");			   	  break;
		}
                tempItem->SubItems->Add(szNewStat);

		//CHS:显示主叫号码
		//ENG:Display calling party number
                tempItem->SubItems->Add(CicState[n].szCallerId);

		//CHS:显示被叫号码
		//ENG:Display called party number
                tempItem->SubItems->Add(CicState[n].szCalleeId);

		//CHS:显示来话通道及此通道收到的DTMF
		//ENG:Display incoming channel and received DTMFs in the channel
		sprintf(szNewStat, "%d:%s", CicState[n].nCallInCh, CicState[n].szCallInDtmf);
                tempItem->SubItems->Add(szNewStat);

		//CHS:显示去话通道及此通道收到的DTMF
		//ENG:Display outgoing channel and received DTMFs in the channel
		sprintf(szNewStat, "%d:%s", CicState[n].nCallOutCh, CicState[n].szCallOutDtmf);
                tempItem->SubItems->Add(szNewStat);
	}

}


void   __fastcall   TDTP_Form::WndProc(Messages::TMessage   &Message)
{
        UINT message;
        int wParam;
        int lParam;
	int nCic;
	int nCh;
	char cNewDtmf;
	int nEventCode;
	int nNewState;

        message = Message.Msg;
        wParam =  Message.WParam;
        lParam =  Message.LParam;


	//CHS: 采用windows消息机制,windows消息编码:事件码+0x7000(WM_USER)
	//ENG: Adopt windows message mechanism
	//	   windows message code:event code + 0x7000(WM_USER)
	if(message > WM_USER)  
	{		
		nEventCode = message - WM_USER;	

		//CHS: 被监控电路的接续状态发生改变事件
		//ENG: Event notifying the state change of the monitored circuit
		if(nEventCode == E_CHG_SpyState)	
		{
			nCic = wParam;
	 		nNewState = (int)lParam & 0xFFFF;
			if(nCic >= 0 && nCic < MAX_CIC)
			{
				switch(nNewState)
				{
				//Idle state
				case S_SPY_STANDBY:
					{
						if(CicState[nCic].nCicState == CIRCUIT_TALKING)
						{	
							//CHS:调用以电路号为参数的录音函数
							//ENG:Call the function with circuit number as its parameter
							if(m_nCallFnMode == 0)
							{
								//stop recording
								if(SpyStopRecToFile(nCic) == -1)
									ShowMessage("Fail to call SpyStopRecToFile");
							}
							//CHS:调用以通道号为参数的录音函数
							//ENG:Call the function with channel number as its parameter

⌨️ 快捷键说明

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