playtone.c
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:1k
- #include <sys/types.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
- #include <sys/ioctl.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include "ixjuser.h"
- int main(int argc, char *argv[])
- {
- int ixj1, hook, m_hook, digit, state, cnt;
- char pname1[80], pname2[80];
- sprintf(pname1, "/dev/ixj%s", argv[1]);
- ixj1 = open(pname1, O_RDWR);
- if(ixj1 <= 0)
- {
- printf("Open failed %sn", pname1);
- exit(0);
- }
- hook = m_hook = ioctl(ixj1, IXJCTL_HOOKSTATE);
- printf("hook state %dn", hook);
- // if(!ioctl(ixj1, IXJCTL_RING))
- // exit(0);
- hook = ioctl(ixj1, IXJCTL_HOOKSTATE);
- while(!hook)
- {
- hook = ioctl(ixj1, IXJCTL_HOOKSTATE);
- }
- printf("hook state %dn", hook);
- ioctl(ixj1, IXJCTL_SET_TONE_ON_TIME, 0x0168);
- ioctl(ixj1, IXJCTL_SET_TONE_OFF_TIME, 0x0168);
- printf("Tone on period = %4.4xn", ioctl(ixj1, IXJCTL_GET_TONE_ON_TIME));
- printf("Tone off period = %4.4xn", ioctl(ixj1, IXJCTL_GET_TONE_OFF_TIME));
- fflush(stdout);
- ioctl(ixj1, IXJCTL_AEC_STOP);
- for(digit = 1;digit < 13;digit++)
- {
- ioctl(ixj1, IXJCTL_PLAY_TONE, digit);
- state = ioctl(ixj1, IXJCTL_GET_TONE_STATE);
- printf("state = %dt", state);
- fflush(stdout);
- cnt = 0;
- while(state)
- {
- cnt++;
- usleep(40);
- state = ioctl(ixj1, IXJCTL_GET_TONE_STATE);
- }
- printf("cnt = %dn", cnt);
- fflush(stdout);
- }
- // ioctl(ixj1, IXJCTL_PLAY_TONE, digit);
- getchar();
- close(ixj1);
- }