dtmfascii.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);
- signal(SIGIO, &getdata);
- fcntl(ixj1, F_SETOWN, getpid());
- oflags1 = fcntl(ixj1, F_GETFL);
- fcntl(ixj1, F_SETFL, oflags1 | FASYNC);
- getchar();
- }
- void closeall(void)
- {
- ioctl(ixj1, IXJCTL_DSP_IDLE);
- close(ixj1);
- }
- void getdata(int x)
- {
- fd_set rfds,wfds,efds;
- struct timeval tv;
- IXJ_EXCEPTION ixje;
- 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))
- {
- ixje.bytes = ioctl(ixj1, IXJCTL_EXCEPTION);
- if(ixje.bits.dtmf_ready)
- {
- // Deal with DTMF
- ioctl(ixj1, IXJCTL_CPT_STOP);
- printf("DTMF from card 0 = %cn",ioctl(ixj1, IXJCTL_GET_DTMF_ASCII));
- }
- if(ixje.bits.hookstate)
- {
- if(ioctl(ixj1, IXJCTL_HOOKSTATE))
- {
- ioctl(ixj1, IXJCTL_DIALTONE);
- printf("Off Hookn");
- }
- else
- printf("On Hookn");
- }
- fflush(stdout);
- }
- }