본문 바로가기

UNIX_LINUX_C_C++

dialogic programming example - async mode

dialogic programming example - async mode

번호: 59 / 작성자: jinyedge / 등록일: 2002-05-08 17:49:52 / 조회: 222
#include <stdio.h>
#include <windows.h>
#include "e:\  documents\lib\dialogic\srllib.h"
#include "e:\  documents\lib\dialogic\dxxxlib.h"

int DO_NEXT = 1;

int sethook_handler(evtdev);
int process(int evtdev, int event);

//------------------------
int main(){
int chdev, evtdev, evttype;
char *chname = "dxxxB1C1";

if((chdev = dx_open(chname, 0)) == -1){
puts("An error occured while dx_open!!");
exit(-1);
}

if(dx_sethook(chdev, DX_ONHOOK, EV_ASYNC) == -1)
{puts("An error occured while dx_sethook - DX_ONHOOK!!");}

while(DO_NEXT){
//Wait for events
sr_waitevt(-1);
evtdev = sr_getevtdev();
evttype = sr_getevttype();
if(process(evtdev, evttype) != 0){break;}
}

if(dx_close(chdev) == -1){
puts("An error occured while dx_close!!");
exit(-1);
}

return 0;
}

//------------------------
int process(int evtdev, int event){
//Switch according to the event received.
switch(event){
case TDX_SETHOOK:
sethook_handler(evtdev);
break;
case TDX_DIAL:
//Next go onhook
puts("Received TDX_DIAL event");
Sleep(3000);
DO_NEXT = 0;
}
return 0;
}

//------------------------
int sethook_handler(int evtdev){
DX_CST *cstp;
cstp = (DX_CST *)sr_getevtdatap();

switch(cstp->cst_event){
case DX_ONHOOK:
//Go offhook next
printf("Received onhook event\n");
if(dx_sethook(evtdev, DX_OFFHOOK, EV_ASYNC) == -1){
puts("An error occured while dx_sethook - DX_OFFHOOK!!");
return(-1);
}

break;
case DX_OFFHOOK:
//dial next
puts("Received offhook event");
if(dx_dial(evtdev, "0193937040", NULL, EV_ASYNC) == -1){
puts("An error occured while dx_dial!!");
return(-1);
}
break;
}
return 0;
}

dialogic programming example - sync mode
번호: 58 / 작성자: jinyedge / 등록일: 2002-05-08 12:14:10 / 조회: 219
#include <stdio.h>
#include <windows.h>
#include "e:\  documents\lib\dialogic\srllib.h"
#include "e:\  documents\lib\dialogic\dxxxlib.h"

//----------------------
void print_conntype(int chdev){
switch(ATDX_CONNTYPE(chdev )){
case CON_CAD:
printf( "Cadence Break\n" );
break;
case CON_LPC:
printf( "Loop Current Drop\n" );
break;
case CON_PVD:
printf( "Positive Voice Detection\n" );
break;
case CON_PAMD:
printf( "Positive Answering Machine Detection\n" );
break;
default:
printf( "Unknown connection type\n" );
break;
}
}

//----------------------
void phone_getdgt(int chdev){
int i, numdigs;
DV_TPT tpt[3];
DV_DIGIT digp;

/* Set up the DV_TPT and get the digits */
dx_clrtpt(tpt, 3);
tpt[0].tp_type = IO_CONT;
tpt[0].tp_termno = DX_MAXDTMF; /* Maximum number of digits */
tpt[0].tp_length = 4; /* terminate on 4 digits */
tpt[0].tp_flags = TF_MAXDTMF; /* terminate if already in buf. */

tpt[1].tp_type = IO_CONT;
tpt[1].tp_termno = DX_LCOFF; /* LC off termination */
tpt[1].tp_length = 3; /* Use 30 ms (10 ms resolution * timer) */
tpt[1].tp_flags = TF_LCOFF|TF_10MS; /* level triggered, clear history, * 10 ms resolution */

tpt[2].tp_type = IO_EOT;
tpt[2].tp_termno = DX_MAXTIME; /* Function Time */
tpt[2].tp_length = 100; /* 10 seconds (100 ms resolution * timer) */
tpt[2].tp_flags = TF_MAXTIME; /* Edge-triggered */

/* clear previously entered digits */
if(dx_clrdigbuf(chdev) == -1){
puts("dx_clrdigbuf error!!");
}
if((numdigs = dx_getdig(chdev,tpt, &digp, EV_SYNC)) == -1){
puts("dx_getdig error!!");
}
for(i = 0; i < 3; i++){
printf("\nDigit received = %c, digit type = %d", digp.dg_value[i], digp.dg_type[i]);
}
}

//----------------------
void phone_getonedgt(int chdev){
DV_TPT tptdig;
DV_DIGIT digp;

tptdig.tp_type = IO_EOT;
tptdig.tp_termno = DX_MAXDTMF; /* Maximum number of digits */
tptdig.tp_length = 1;
tptdig.tp_flags = TF_MAXDTMF; /* terminate if already in buf. */

dx_clrdigbuf(chdev);
if(dx_getdig(chdev, &tptdig, &digp, EV_SYNC) == -1){puts("dx_getdig error!!");}
printf("\nDigit received = %c, digit type = %d", digp.dg_value[0], digp.dg_type[0]);
}

//----------------------
void phone_getonedgt2(int chdev, int time_limit){
DV_TPT tptdig;
DV_DIGIT digp;

tptdig.tp_type = IO_EOT;
tptdig.tp_termno = DX_MAXTIME;
tptdig.tp_length = time_limit;
tptdig.tp_flags = TF_MAXTIME;

dx_clrdigbuf(chdev);
if(dx_getdig(chdev, &tptdig, &digp, EV_SYNC) == -1){puts("dx_getdig error!!");}
printf("\nDigit received = %c, digit type = %d", digp.dg_value[0], digp.dg_type[0]);
}

//----------------------
void play_wave(int chdev){
DV_TPT tpt;/* termination parameter table */

/* Set to terminate play on 1 digit */
tpt.tp_type = IO_EOT;
tpt.tp_termno = DX_MAXDTMF;
tpt.tp_length = 1;
tpt.tp_flags = TF_MAXDTMF;

/* Start playback */
puts("play wave file..");
if (dx_playwav(chdev, "d:\\imsi\\sample8k.wav", &tpt, EV_SYNC) == -1){
printf("Error playing file - %s\n", ATDV_ERRMSGP(chdev));
}
puts("wave file done.");
}

//----------------------
void phone_rec(int chdev){
DV_TPT tpt; /* termination parameter table */

tpt.tp_type = IO_EOT;
tpt.tp_termno = DX_MAXDTMF;
tpt.tp_length = 1;
tpt.tp_flags = TF_MAXDTMF;
dx_clrdigbuf(chdev);

/* Start 11KHz PCM recording */
if(dx_recwav(chdev, "d:\\imsi\\message.wav", &tpt, (DX_XPB *)NULL, PM_TONE|EV_SYNC) == -1){
printf("Error recording file - %s\n", ATDV_ERRMSGP(chdev));
}
}

//----------------------
void phone_rec2(int chdev, int time_limit){
DV_TPT tpt; /* termination parameter table */

tpt.tp_type = IO_EOT;
tpt.tp_termno = DX_MAXTIME;
tpt.tp_length = time_limit;
tpt.tp_flags = TF_MAXTIME;
dx_clrdigbuf(chdev);

/* Start 11KHz PCM recording */
if(dx_recwav(chdev, "d:\\imsi\\message.wav", &tpt, (DX_XPB *)NULL, PM_TONE|EV_SYNC) == -1){
printf("Error recording file - %s\n", ATDV_ERRMSGP(chdev));
}
}

//----------------------
int main(){
DX_CAP cap;
int chdev, i;
long hookst;
long bdtype;

if((chdev = dx_open("dxxxB1C1", 0)) == -1){
printf("dx_open failed!!\n");
}

//board type
if((bdtype = ATDX_BDTYPE(chdev)) == AT_FAILURE){puts("bdtype error!!!");}
else{printf("boardtype = %d\n", bdtype);}

//hook state
if((hookst = ATDX_HOOKST(chdev)) == AT_FAILURE)
{puts("an error occured while checking hook state!!");}

if(hookst == DX_OFFHOOK){//if current state is off hook
puts("channel is off hook. attempt to make on hook");
dx_sethook(chdev, DX_ONHOOK, EV_SYNC);//made it on hook state
puts("and now it is on hook..");
}

Sleep(3000);
dx_sethook(chdev, DX_OFFHOOK, EV_SYNC);
puts("channel is off hook");

//pick up the receiver

//dialing
dx_clrcap(&cap);
cap.ca_hedge = 1;
cap.ca_nbrdna = 30;//limit of ringing
cap.ca_noanswer = (unsigned short)30 * 100;
cap.ca_intflg = DX_PVDOPTNOCON;
cap.ca_pamd_spdval = PAMD_QUICK;

//set tones
if(dx_chgfreq(TID_BUSY2, 475, 40, 615, 40) < 0 ){puts("dx_chgfreq error!!");}
if(dx_chgdur(TID_BUSY2, 45, 40, 45, 40) < 0 ){puts("dx_chgdur error!!");}
if(dx_chgrepcnt(TID_BUSY2, 2) < 0){puts("dx_chgrepcnt error!!");}

//before use perfect call you must delete all tones.
//unless analysys mode set to basic.
if(dx_deltones(chdev) < 0){puts("dx_deltones error!!");}
if(dx_initcallp(chdev) == -1){puts("initcallp error!!");}

puts("dialing...");
printf("%d\n", dx_dial(chdev, "01939370xx", &cap, DX_CALLP|EV_SYNC));

//connection type
printf("connection type = %d\n", ATDX_CPTERM(chdev));

print_conntype(chdev);

puts("press return to play wave file.");
getchar();

play_wave(chdev);

puts("press return to get digit.");
getchar();

for(i = 0; i < 100; i++){//get digit for 10 sec
phone_getonedgt2(chdev, 1);
}

puts("press return to record wave file.");
getchar();

phone_rec2(chdev, 100);//record for 10 sec

//hang up the receiver
printf("%d\n", dx_sethook(chdev, DX_ONHOOK, EV_SYNC));

dx_close(chdev);

return 0;
}

'UNIX_LINUX_C_C++' 카테고리의 다른 글

jinie_lib_winwock2  (0) 2011.10.16
[공유메모리] 데이터 넣는 방법  (0) 2011.10.16
select 함수를 이용한 채팅 서버  (1) 2011.10.16
날짜,pthread,도메인  (0) 2011.10.16
[펌] C 에서의 문자열  (0) 2011.10.16