📄 calldlg.cpp
字号:
// CallDlg.cpp : implementation file
//
#include "stdafx.h"
#include <stdlib.h>
#include <io.h>
#include "Call.h"
#include "CallDlg.h"
#include "../../../../../api/vc6.0/inc/shpa3api.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCallDlg dialog
CCallDlg::CCallDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCallDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCallDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCallDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCallDlg)
DDX_Control(pDX, IDC_LIST_TRK, m_TrkChList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCallDlg, CDialog)
//{{AFX_MSG_MAP(CCallDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCallDlg message handlers
BOOL CCallDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
if(InitCtiSystem() == false)
{
PostQuitMessage(0);
return false;
}
InitATrunkCh();
InitDTrunkListCtrl();
SetTimer( 1000, 50, NULL );
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCallDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CCallDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCallDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
UpDateATrunkChListCtrl();
ScanATrunkCh();
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
void CCallDlg::ScanATrunkCh()
{
CFileFind cf;
int UserCh;
for( int i=0; i< nTotCh; i++ )
{
if( !ATrkCh[i].EnCalled ) continue;
ATrkCh[i].lineState = SsmGetChState(i);
if( ATrkCh[i].lineState == S_CALL_PENDING ) //check if remote user hangup
{
switch( ATrkCh[i].Step )
{
case TRK_CHECK_PLAY_WELCOM:
SsmStopPlayFileList(i);
break;
case TRK_CHECK_PLAY_PASSWORD:
case TRK_CHECK_REC_START:
case TRK_CHECK_PLAY_SELECT:
case TRK_CHECK_PLAY_BYEBYE:
SsmStopPlayIndex(i);
break;
case TRK_CHECK_REC_END:
SsmStopRecToFile(i);
break;
case TRK_CHECK_PLAY_RECORD:
SsmStopPlayFile(i);
break;
case TRK_WAIT_USER_PICKUP:
SsmStopRing(ATrkCh[i].UserCh);
ATrkCh[i].UserCh = -1;
break;
case TRK_WAIT_USER_HANGUP:
SsmStopTalkWith(ATrkCh[i].UserCh,i);
ATrkCh[i].UserCh = -1;
break;
}
if(ATrkCh[i].Step != TRK_IDLE ) SsmHangup(i);
ATrkCh[i].Step = TRK_IDLE;
}
switch( ATrkCh[i].Step )
{
case TRK_IDLE:
if( ATrkCh[i].lineState == S_CALL_RINGING ) //ring detected
{
SsmPickup(i);
SsmGetCallerId(i, ATrkCh[i].pCallerId.GetBuffer(50));
ATrkCh[i].dwTimeOutCounter = 0;
ATrkCh[i].Step = TRK_WAIT_CONNECT;
}
else
{
ATrkCh[i].pCallerId = "";
}
break;
case TRK_WAIT_CONNECT:
if( ATrkCh[i].lineState == S_CALL_TALKING )
ATrkCh[i].Step = TRK_PLAY_WELCOM;
break;
case TRK_PLAY_WELCOM:
SsmClearFileList(i);
if (SsmAddToFileList(i,"..\\..\\..\\..\\..\\DemoVoc\\Welcom1.voc",6,0,-1)==-1 ||
SsmAddToFileList(i,"..\\..\\..\\..\\..\\DemoVoc\\Welcom2.voc",6,0,-1)==-1)
AppErrorHandler(i);
else
if(SsmPlayFileList(i) == -1)
AppErrorHandler(i);
else
ATrkCh[i].Step = TRK_CHECK_PLAY_WELCOM;
case TRK_CHECK_PLAY_WELCOM:
if( SsmCheckPlay(i) > 0) //end of playing "welcom"
ATrkCh[i].Step = TRK_PLAY_SELECT;
break;
case TRK_PLAY_SELECT:
SsmSetDtmfStopPlay(i,1); //enable DTMF-Stop-Play function
if(SsmPlayIndexString(i,"Select") == -1)
AppErrorHandler(i);
else
{
SsmClearRxDtmfBuf(i);
ATrkCh[i].dwTimeOutCounter = 0;
ATrkCh[i].Step = TRK_CHECK_PLAY_SELECT;
}
break;
case TRK_CHECK_PLAY_SELECT:
if(SsmGetRxDtmfLen(i) >= 1 && (SsmCheckPlay(i) == 2 || SsmCheckPlay(i) == 1))
{
char tmp;
SsmGet1stDtmf(i,&tmp);
SsmClearRxDtmfBuf(i);
switch(tmp)
{
case '1': //DTMF=1: record to file "test.voc"
if(SsmPlayIndexString(i,"RecPrompt") == -1) //play "press any key to start, and any key again to stop".
AppErrorHandler(i);
else
{
ATrkCh[i].dwTimeOutCounter = 0;
ATrkCh[i].Step = TRK_CHECK_REC_START;
}
break;
case '2': //DTMF=2: play recorded file "test.voc"
if(cf.FindFile("test.voc", 0) != 0)
if(SsmPlayFile(i,"test.voc",6,0,0xFFFFFFFF) == -1)
AppErrorHandler(i);
else
ATrkCh[i].Step = TRK_CHECK_PLAY_RECORD;
else
if(SsmPlayIndexString(i,"FileNotFound") == -1) //play "file not found" message
AppErrorHandler(i);
else
ATrkCh[i].Step = TRK_CHECK_PLAY_RECORD;
break ;
case '3': //DTMF=3: play user's password,some sample digital
SsmSetDtmfStopPlay(i,0); //disable DTMF-Stop-Play function while playing password
if(SsmPlayIndexString(i,"YourPasswordIs,1,2,3,4") == -1) //play "your password is 1234".
AppErrorHandler(i);
else
ATrkCh[i].Step = TRK_CHECK_PLAY_PASSWORD;
break;
case '4': //DTMF=4: connect to an idle user channel
UserCh = SearchIdleUserCh();
if(UserCh < 0)
ATrkCh[i].Step = TRK_PLAY_SELECT;
else
{
SsmStartRing(UserCh);
ATrkCh[i].UserCh = UserCh;
ATrkCh[i].Step = TRK_WAIT_USER_PICKUP;
}
break;
case '0': //DTMF=0: end of service,play "Byebye"
if ( SsmPlayIndexString(i, "Byebye" )== -1 )
AppErrorHandler(i);
else
ATrkCh[i].Step = TRK_CHECK_PLAY_BYEBYE;
break;
default:
break;
}
}
else if( SsmCheckPlay(i) > 0) // end of playing "Select"
{
if(++ATrkCh[i].dwTimeOutCounter > 100) // wait DTMF key for maximum 10 seconds
{
if ( SsmPlayIndexString( i, "Byebye" )== -1 )
AppErrorHandler(i);
else
ATrkCh[i].Step = TRK_CHECK_PLAY_BYEBYE;
}
}
break;
case TRK_CHECK_PLAY_PASSWORD:
if(SsmCheckPlay(i) > 0) //this channel is not playing index now
ATrkCh[i].Step = TRK_PLAY_SELECT;
break ;
case TRK_CHECK_REC_START:
if(SsmGetRxDtmfLen(i) >= 1)
{
SsmClearRxDtmfBuf(i);
if( SsmRecToFile(i,"test.voc",6,0L,10L*8000L,0,0) == -1) //start from 16000L,maxmium 10 seconds
AppErrorHandler(i);
else
ATrkCh[i].Step = TRK_CHECK_REC_END;
}
else if(++ATrkCh[i].dwTimeOutCounter > 300) //wait 15 seconds for DTMF-key
{
if ( SsmPlayIndexString( i, "Byebye" )== -1 )
AppErrorHandler(i);
else
ATrkCh[i].Step = TRK_CHECK_PLAY_BYEBYE;
}
break ;
case TRK_CHECK_REC_END:
if(SsmGetRxDtmfLen(i)>=1 || SsmChkRecToFile(i)==0)
{
SsmStopRecToFile(i);
ATrkCh[i].Step = TRK_PLAY_SELECT;
}
break ;
case TRK_CHECK_PLAY_RECORD:
if(SsmCheckPlay(i) > 0)
ATrkCh[i].Step = TRK_PLAY_SELECT;
break;
case TRK_WAIT_USER_PICKUP:
UserCh = ATrkCh[i].UserCh;
if( SsmGetHookState(UserCh) ) //user is in pickup state now
{
SsmStopRing(UserCh);
SsmTalkWith(i,UserCh);
ATrkCh[i].Step = TRK_WAIT_USER_HANGUP;
}
break;
case TRK_WAIT_USER_HANGUP:
UserCh = ATrkCh[i].UserCh;
if( !SsmGetHookState(UserCh) ) //user hang up
{
SsmStopTalkWith(i,UserCh);
ATrkCh[i].UserCh = -1;
ATrkCh[i].Step = TRK_PLAY_SELECT;
}
break;
case TRK_CHECK_PLAY_BYEBYE:
if(SsmCheckPlay(i) > 0)
{
SsmHangup(i);
ATrkCh[i].Step = TRK_IDLE;
}
break ;
} //end of switch(ATrkCh[i].Step)
}//end of for(int i=0; i<nTotCh; i++ )
}
int CCallDlg::SearchIdleUserCh()
{
int i;
for(i=0;i<nTotCh;i++)
{
if( SsmGetChType(i) == 2 // User Channel
&& SsmGetHookState(i) == 0) break;
}
if (i == nTotCh) return -1;
return i;
}
void CCallDlg::AppErrorHandler(int ch)
{
SsmHangup( ch );
SsmGetLastErrMsg(ATrkCh[ch].pErrMsg.GetBuffer(200));
ATrkCh[ch].Step = TRK_IDLE;
}
void CCallDlg::OnDestroy()
{
CDialog::OnDestroy();
SsmCloseCti();
}
bool CCallDlg::InitCtiSystem()
{
char fnIni[220],fnIndex[220];
GetCurrentDirectory(200,CurPath);
strcpy(fnIni,CurPath);
strcat(fnIni,"\\ShConfig.ini");
strcpy(fnIndex,CurPath);
strcat(fnIndex,"\\ShIndex.ini");
if( SsmStartCti( fnIni, fnIndex ) != 0 )
{
CString ErrMsg;
SsmGetLastErrMsg(ErrMsg.GetBuffer(200)); //To tretrieve error information at initialization phrase
AfxMessageBox(ErrMsg, MB_OK ) ;
return false;
}
return true;
}
void CCallDlg::InitATrunkCh()
{
nTotCh = SsmGetMaxCh();
for(int i=0; i<nTotCh; i++)
{
ATrkCh[i].EnCalled = false;
int nDirection;
if( SsmGetAutoCallDirection(i,&nDirection) == 1 ) //auto connection is allowed
{
if( nDirection == 0 || nDirection == 2 ) //enable call in
{
ATrkCh[i].Step = TRK_IDLE;
ATrkCh[i].EnCalled = true;
}
}
}
}
void CCallDlg::InitDTrunkListCtrl()
{
static int ColumnWidth[5] = {36, 85, 70, 70, 200};
LV_COLUMN lvc;
lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.iSubItem = 0;
lvc.pszText = "Channel" ;
lvc.cx = ColumnWidth[0];
m_TrkChList.InsertColumn(0,&lvc);
lvc.iSubItem = 1;
lvc.pszText = "ChannelState";
lvc.cx = ColumnWidth[1];
m_TrkChList.InsertColumn(1,&lvc);
lvc.iSubItem = 2;
lvc.pszText = "CallerId";
lvc.cx = ColumnWidth[2];
m_TrkChList.InsertColumn(2,&lvc);
lvc.iSubItem = 3;
lvc.pszText = "DTMF";
lvc.cx = ColumnWidth[3];
m_TrkChList.InsertColumn(3,&lvc);
lvc.iSubItem = 4;
lvc.pszText = "ErrorMsg";
lvc.cx = ColumnWidth[4];
m_TrkChList.InsertColumn(4,&lvc);
char dig[3];
for(int i = 0; i < nTotCh; i++)
if ( ATrkCh[i].EnCalled ) m_TrkChList.InsertItem(i,_itoa(i,dig,10));
}
void CCallDlg::UpDateATrunkChListCtrl()
{
CString state;
char tmpstr[30];
int nIndex;
nIndex = 0;
for(int i=0; i< nTotCh; i++)
{
if( ATrkCh[i].EnCalled )
{
switch( ATrkCh[i].Step )
{
case TRK_IDLE: state = "Idle"; break ;
case TRK_WAIT_CONNECT: state = "WaitForConn"; break ;
case TRK_CHECK_PLAY_WELCOM: state = "PlaySalutatory"; break ;
case TRK_CHECK_PLAY_SELECT: state = "WaitForPlaySelect"; break ;
case TRK_CHECK_REC_START: state = "WatiForRecordStart"; break ;
case TRK_CHECK_REC_END: state = "RecordSpeech"; break ;
case TRK_CHECK_PLAY_RECORD: state = "PlaySpeech"; break ;
case TRK_CHECK_PLAY_BYEBYE: state = "PlayBye"; break ;
case TRK_CHECK_PLAY_PASSWORD: state = "PlayPassword"; break ;
case TRK_WAIT_USER_PICKUP: state = "WaitForStationPickup"; break ;
case TRK_WAIT_USER_HANGUP: state = "WaitForStationHangup"; break ;
default: state = "Undefined"; break;
}
m_TrkChList.GetItemText( nIndex, 1, tmpstr, 29 ) ;
if ( state != tmpstr )
m_TrkChList.SetItemText( nIndex, 1, state.GetBuffer(30) );
m_TrkChList.GetItemText( nIndex, 2, tmpstr, 29 ) ; //display caller ID
if ( tmpstr != ATrkCh[i].pCallerId )
m_TrkChList.SetItemText( nIndex, 2, ATrkCh[i].pCallerId );
if( ATrkCh[i].Step == TRK_IDLE )
{
state = "";
if ( state != tmpstr )
m_TrkChList.SetItemText( nIndex, 3, state.GetBuffer(30) );
}
else
{
state.Empty();
if (SsmGetDtmfStr(i, state.GetBuffer(30))>0) //receive and display DTMF keys
{
m_TrkChList.GetItemText( nIndex, 3, tmpstr, 29 );
if ( state != tmpstr )
m_TrkChList.SetItemText( nIndex, 3, state.GetBuffer(30) );
}
}
m_TrkChList.GetItemText( nIndex, 4, tmpstr, 29 ); //display error messages occured
if ( ATrkCh[i].pErrMsg != tmpstr )
m_TrkChList.SetItemText( nIndex, 4, ATrkCh[i].pErrMsg );
nIndex=nIndex+1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -