www.pudn.com > RecDemo.rar > D.cpp
#include "stdafx.h"
#include "D.h"
#include "..\\..\\..\\..\\inc\\tc08a32.h"
#include "resource.h"
#include "..\\..\\..\\..\\inc\\NewSig.h"
#include "mydefines.h"
extern int TotalLine;
extern HWND hGWnd;
extern LINESTRUCT *Lines;
char VoicePath[100];
void WINAPI new_yzDrawState( int trkno )
{
char state[100]; ;
char tmpstr[20] ;
CString stringtmp;
switch( Lines[trkno].State )
{
case CH_FREE:
stringtmp.LoadString(IDS_STATE_FREE) ;
strcpy(state,stringtmp);
break ;
case CH_RECEIVEID:
stringtmp.LoadString(IDS_RECEIVE_CALLERID) ;
strcpy(state,stringtmp);
break;
case CH_WAITSECONDRING:
stringtmp.LoadString(IDS_WAITING_SECOND_RINGING) ;
strcpy(state,stringtmp);
break;
case CH_WELCOME:
stringtmp.LoadString(IDS_ORIENTAL_BANK_DEMO) ;
strcpy(state,stringtmp);
break ;
case CH_ACCOUNT:
case CH_ACCOUNT1:
stringtmp.LoadString(IDS_INPUT_EIGHT_ACCOUNTS) ;
strcpy(state,stringtmp);
break ;
case CH_PASSWORD:
case CH_PASSWORD1:
stringtmp.LoadString(IDS_INPUT_SIX_PASSWORD) ;
strcpy(state,stringtmp);
break;
case CH_SELECT:
case CH_SELECT1:
stringtmp.LoadString(IDS_SELECT_OPTION) ;
strcpy(state,stringtmp);
break;
case CH_RECORDFILE:
stringtmp.LoadString(IDS_LEAVE_WORDS) ;
strcpy(state,stringtmp);
break;
case CH_PLAYRESULT:
stringtmp.LoadString(IDS_PLAY_RESULT) ;
strcpy(state,stringtmp);
break;
case CH_PLAYRECORD:
stringtmp.LoadString(IDS_PLAY_RECORD) ;
strcpy(state,stringtmp);
break;
case CH_OFFHOOK:
stringtmp.LoadString(IDS_STATE_OFFHOOK) ;
strcpy(state,stringtmp);
break;
case CH_WAITUSERONHOOK:
stringtmp.LoadString(IDS_WAITING_HANGUP) ;
strcpy(state,stringtmp);
break;
}
ListView_GetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 2, tmpstr, 19 ) ;
if ( strcmp(state,tmpstr )!=0)
ListView_SetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 2, state );
strcpy(state, Lines[trkno].CallerID) ;
ListView_GetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 3, tmpstr, 19 ) ;
if ( strcmp(state,tmpstr )!=0)
ListView_SetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 3, state );
strcpy(state,Lines[trkno].Dtmf);
ListView_GetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 4, tmpstr, 19 ) ;
if ( strcmp(state,tmpstr )!=0)
ListView_SetItemText(GetDlgItem(hGWnd,IDC_LIST1), trkno, 4, state );
}
void yzResetChannel(int channelID)
{
if(Lines[channelID].nType==CHTYPE_TRUNK)
{
Sig_ResetCheck(channelID);
StartSigCheck(channelID);
HangUp(channelID);
}
Lines[channelID].Dtmf[0]=0;
Lines[channelID].CallerID[0]=0;
Lines[channelID].State = CH_FREE;
}
char yzConvertDtmf(int ch)
{
char c;
switch(ch)
{
case 10:
c = '0';
break;
case 11:
c = '*';
break;
case 12:
c = '#';
break;
case 13:
case 14:
case 15:
c=ch-13+'a';
break;
case 0:
c='d';
break;
default:
c = ch + '0';//conversion ASCII
}
return c;
}
#define USER_DEFINE_TIMER 5
void WINAPI yzDoWork(int i)
{
char FileName[200];
short int code;
int len;
CString stringtmp;
// for(int i=0;i 5000 ) // no ring for 5 second
{
Lines[i].State = CH_FREE;
}
}
// deal with offhook
if ( DRec_OffHookDetect(i) == 1 )
{ // user OffHook
Lines[i].State = CH_OFFHOOK;
int a=GetCallerIDStr (i,Lines[i].CallerID);
if(a==4)
{
stringtmp.LoadString(IDS_CALLERID_ERR) ;
strcpy(Lines[i].CallerID,stringtmp);
}
}
}
break;
case CH_OFFHOOK: // start record
wsprintf ( FileName, "TmpRec.%d.pcm", i );
StartRecordFile ( i, FileName, 8000L*60 );
Lines[i].State = CH_WAITUSERONHOOK;
break;
case CH_WAITUSERONHOOK:
if ( DRec_OffHookDetect(i) == 0 )
{ // user OffHook
StopRecordFile ( i );
Lines[i].State = CH_FREE;
}
break;
} // end of switch
// continue;
return ;
}
// end of record module
switch(Lines[i].State)
{
case CH_FREE:
if(RingDetect(i))
{
if(Lines[i].nType==CHTYPE_USER)
{
Lines[i].State=CH_OFFHOOK;
}
else
{
Lines[i].State=CH_RECEIVEID;
ResetCallerIDBuffer(i);
Lines[i].nTimeElapse=0;
}
}
break;
case CH_RECEIVEID:
{
bool bOffHook=false;
if(Lines[i].nTimeElapse>2000 && RingDetect(i)) bOffHook=true;
if(Lines[i].nTimeElapse>7000) bOffHook=true;
int a=GetCallerIDStr (i,Lines[i].CallerID);
if(a==3)
{
bOffHook=true;
}
else if(a==4)
{
stringtmp.LoadString(IDS_CALLERID_ERR) ;
strcpy(Lines[i].CallerID,stringtmp);
bOffHook=true;
}
if(bOffHook)
{
OffHook(i);
StartSigCheck(i);
Lines[i].State=CH_OFFHOOK;
}
Lines[i].nTimeElapse+=50;
}
break;
case CH_WAITSECONDRING:
if(RingDetect(i))
{
OffHook(i);
StartSigCheck(i);
Lines[i].State=CH_OFFHOOK;
}
break;
case CH_OFFHOOK:
strcpy(FileName,VoicePath);
strcat(FileName,"bank.001");
InitDtmfBuf(i);
StartPlayFile(i,FileName,0L);
Lines[i].State = CH_WELCOME;
break;
case CH_WELCOME:
code=GetDtmfCode(i);
if(code!=-1)
{
StopPlayFile(i);
Lines[i].Dtmf[0]=yzConvertDtmf(code);
Lines[i].Dtmf[1]=0;
Lines[i].State=CH_ACCOUNT1;
break;
}
if(CheckPlayEnd(i))
{
StopPlayFile(i);
strcpy(FileName,VoicePath);
strcat(FileName,"bank.002");
StartPlayFile(i,FileName,0L);
Lines[i].State=CH_ACCOUNT;
}
break;
case CH_ACCOUNT:
code=GetDtmfCode(i);
if(code!=-1)
{
StopPlayFile(i);
Lines[i].Dtmf[0]=yzConvertDtmf(code);
Lines[i].Dtmf[1]=0;
Lines[i].State=CH_ACCOUNT1;
break;
}
if(CheckPlayEnd(i))
{
StopPlayFile(i);
Lines[i].State=CH_ACCOUNT1;
}
break;
case CH_ACCOUNT1:
len=strlen(Lines[i].Dtmf);
while((code=GetDtmfCode(i))!=-1)
{
Lines[i].Dtmf[len++]=yzConvertDtmf(code);
}
Lines[i].Dtmf[len]=0;
if(len>=8)
{
// code=GetDtmfCode(i);
Lines[i].Dtmf[0]=0;
strcpy(FileName,VoicePath);
strcat ( FileName,"bank.003" );
StartPlayFile(i,FileName,0L);
Lines[i].State = CH_PASSWORD;
}
break;
case CH_PASSWORD:
code=GetDtmfCode(i);
if(code!=-1)
{
StopPlayFile(i);
Lines[i].Dtmf[0]=yzConvertDtmf(code);
Lines[i].Dtmf[1]=0;
Lines[i].State=CH_PASSWORD1;
break;
}
if(CheckPlayEnd(i))
{
StopPlayFile(i);
Lines[i].State=CH_PASSWORD1;
}
break;
case CH_PASSWORD1:
len=strlen(Lines[i].Dtmf);
while((code=GetDtmfCode(i))!=-1)
{
Lines[i].Dtmf[len++]=yzConvertDtmf(code);
}
Lines[i].Dtmf[len]=0;
if(len>=6)
{
Lines[i].Dtmf[0]=0;
strcpy(FileName,VoicePath);
strcat ( FileName,"bank.004");
StartPlayFile(i,FileName,0L);
Lines[i].State = CH_SELECT;
}
break;
case CH_SELECT:
code=GetDtmfCode(i);
if(code!=-1)
{
Lines[i].Dtmf[0]=yzConvertDtmf(code);
Lines[i].Dtmf[1]=0;
switch(Lines[i].Dtmf[0])
{
case '1':
StopPlayFile(i);
RsetIndexPlayFile(i);
strcpy(FileName,VoicePath);
strcat ( FileName, "bank.005");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d5");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d12");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d8");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d11");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d9");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d10");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d6");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d15");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d8");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"bank.008");
AddIndexPlayFile(i,FileName);
StartIndexPlayFile(i);
Lines[i].State = CH_PLAYRESULT;
break;
case '2':
StopPlayFile(i);
RsetIndexPlayFile(i);
strcpy(FileName,VoicePath);
strcat(FileName,"bank.006");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d0");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d15");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d4");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d8");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"bank.008");
AddIndexPlayFile(i,FileName);
StartIndexPlayFile(i);
Lines[i].State = CH_PLAYRESULT;
break;
case '3':
StopPlayFile(i);
RsetIndexPlayFile(i);
strcpy(FileName,VoicePath);
strcat(FileName,"bank.007");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d3");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d13");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d7");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"d12");
AddIndexPlayFile(i,FileName);
strcpy(FileName,VoicePath);
strcat(FileName,"bank.008");
AddIndexPlayFile(i,FileName);
StartIndexPlayFile(i);
Lines[i].State = CH_PLAYRESULT;
break;
default:
break;
}
}
break;
case CH_PLAYRESULT:
if(CheckIndexPlayFile(i))
{
StopIndexPlayFile(i);
if(Lines[i].nType==CHTYPE_TRUNK)
{
yzResetChannel(i);
}
else
{
StartPlaySignal(i,SIG_BUSY1);
Lines[i].State=CH_WAITUSERONHOOK;
}
}
break;
case CH_WAITUSERONHOOK:
if(!RingDetect(i))
{
StartPlaySignal(i,SIG_STOP);
yzResetChannel(i);
}
break;
}//end switch
if(Lines[i].nType==CHTYPE_TRUNK && Lines[i].State!=CH_FREE)
{
//WORD wSigCheckResult=ReadCheckResult(i,PLAY_CHECK);
//if(wSigCheckResult==R_BUSY)
if (Sig_CheckBusy(i))
{
switch(Lines[i].State)
{
case CH_WELCOME:
case CH_ACCOUNT:
case CH_PASSWORD:
case CH_SELECT:
StopPlayFile(i);
break;
case CH_PLAYRESULT:
StopIndexPlayFile(i);
break;
}
yzResetChannel(i);
}
}
else if(Lines[i].nType==CHTYPE_USER && Lines[i].State!=CH_FREE)
{
if(!RingDetect(i))
{
switch(Lines[i].State)
{
case CH_WELCOME:
case CH_ACCOUNT:
case CH_PASSWORD:
case CH_SELECT:
StopPlayFile(i);
break;
case CH_PLAYRESULT:
StopIndexPlayFile(i);
break;
}
yzResetChannel(i);
}
}
}//end for
}
void GetVoicePath()
{
char FileName[100];
GetWindowsDirectory(FileName,100);
strcat(FileName,"\\tc08a-v.ini");
GetPrivateProfileString("SYSTEM","InstallDir",NULL,VoicePath,100,FileName);
strcat(VoicePath,"voc\\");
}