dtmfread.c
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:2k
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
- #include <sys/ioctl.h>
- #include <sys/types.h>
- #include <sys/time.h>
- #include <signal.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <asm/errno.h>
- #include "ixjuser.h"
- void closeall(void);
- void getdata(int);
- int ixj1, size1, len, cmd;
- unsigned long write1;
- char buff1[480];
- int main(int argc, char *argv[])
- {
- char pname1[80], buff1[480];
- int cnt, oflags1, oflags2;
- sprintf(pname1, "/dev/ixj%s", argv[1]);
- ixj1 = open(pname1, O_RDWR);
- atexit(closeall);
- printf("Sync Mode %dn", ioctl(ixj1, IXJCTL_GET_DTMFSYNCMODE));
- signal(SIGIO, &getdata);
- fcntl(ixj1, F_SETOWN, getpid());
- oflags1 = fcntl(ixj1, F_GETFL);
- fcntl(ixj1, F_SETFL, oflags1 | FASYNC);
- while(!ioctl(ixj1, IXJCTL_HOOKSTATE))
- {
- printf("On Hookr");
- }
- printf("n");
- cnt = -1;
- while(ioctl(ixj1, IXJCTL_HOOKSTATE))
- {
- cmd = ioctl(ixj1, IXJCTL_DTMF_READY);
- if(cmd)
- {
- printf("nDTMF READY = %x", cmd);
- fflush(stdout);
- }
- usleep(40);
- }
- printf("n");
- printf("On Hookn");
- fflush(stdout);
- // getchar();
- }
- void closeall(void)
- {
- ioctl(ixj1, IXJCTL_AEC_STOP);
- close(ixj1);
- }
- void getdata(int x)
- {
- fd_set rfds,wfds,efds;
- struct timeval tv;
- int nmax, size;
- char buf[480];
- signal(SIGIO, &getdata);
- // nmax = (ixj1 > 0 ? ixj1+1 : 1);
- nmax = ixj1+1;
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- FD_ZERO(&efds);
- FD_SET(ixj1, &rfds);
- FD_SET(ixj1, &wfds);
- FD_SET(ixj1, &efds);
- tv.tv_sec = 0;
- tv.tv_usec = 300;
- select(nmax,&rfds, &wfds, &efds, &tv);
- if(FD_ISSET(ixj1,&rfds))
- {
-
- }
- if(FD_ISSET(ixj1,&wfds))
- {
- }
- if(FD_ISSET(ixj1,&efds))
- {
- // Deal with DTMF
- printf("nDTMF from card 0 = %x",ioctl(ixj1, IXJCTL_GET_DTMF));
- fflush(stdout);
- }
- }