#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; } |