summaryrefslogtreecommitdiff
path: root/fxotune.c
diff options
context:
space:
mode:
authormattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2005-01-13 22:25:01 +0000
committermattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2005-01-13 22:25:01 +0000
commit82da973eeee00bf906cffe01c7483e77cbb39536 (patch)
tree25237cd665fc05a8f58f6a1ea2117836e9792118 /fxotune.c
parentda09e007bbcb0c7df93f3b7ba3cff09121f1aa36 (diff)
Mark's magic touches
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@550 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'fxotune.c')
-rwxr-xr-xfxotune.c80
1 files changed, 56 insertions, 24 deletions
diff --git a/fxotune.c b/fxotune.c
index da36961..029375c 100755
--- a/fxotune.c
+++ b/fxotune.c
@@ -35,8 +35,8 @@ static char *configfile = "/etc/fxotune.conf";
static char *usage =
"Usage: fxotest\n"
-" -i : Tests for FXO modules and sets echo coefficients\n"
-" -s : Sets the FXO modules echo coefficients on your system to the best settings\n";
+" -i <number> : Tests for FXO modules and sets echo coefficients, dialing <number> to clear dialtone\n"
+" -s : Sets the FXO modules echo coefficients on your system to the best settings\n";
#define OUT_OF_BOUNDS(x) ((x) < 0 || (x) > 255)
@@ -92,43 +92,70 @@ int fill_outputdata(void)
/* Returns index in echocan table with the lowest power pulse readback
* -1 means the device is not an FXO module or fails */
-int echo_tune(int whichzap)
+static int echo_tune(int whichzap, const char *dialstr)
{
short bestval = 32355;
int bestindex = -1;
int i = 0;
+ int x;
int res = 0;
int total = sizeof(echo_trys) / sizeof(struct wctdm_echo_coefs);
- short *inbuf = NULL;
+ short inbuf[8192];
+ struct zt_bufferinfo bi;
+ struct zt_dialoperation dop;
int ibufsize = readduration * 8 * 2;
- inbuf = malloc(readduration);
- if (!inbuf) {
- fprintf(stdout, "Malloc failed on readbuf. Bad, bad, bad....\n");
- exit(-1);
+ x = 1;
+ if (ioctl(whichzap, ZT_SETLINEAR, &x)) {
+ fprintf(stderr, "Unable to set channel to signed linear mode.\n");
+ return -1;
}
-
- for (i = 0; i < total; i++) {
- int x;
- /* Set echo settings */
- if (ioctl(whichzap, WCTDM_SET_ECHOTUNE, &echo_trys[i])) {
- fprintf(stdout, "Unable to set echo params: %s\n", strerror(errno));
- return -1;
- }
-
- x = 1;
- if (ioctl(whichzap, ZT_SETLINEAR, &x)) {
- fprintf(stdout, "Unable to set channel to signed linear mode.\n");
- return -1;
- }
+ memset(&bi, 0, sizeof(bi));
+ if (ioctl(whichzap, ZT_GET_BUFINFO, &bi)) {
+ fprintf(stderr, "Unable to get buffer information!\n");
+ return -1;
+ }
+ bi.numbufs = 2;
+ bi.bufsize = 128;
+ bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
+ bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
+ if (ioctl(whichzap, ZT_SET_BUFINFO, &bi)) {
+ fprintf(stderr, "Unable to set buffer information!\n");
+ return -1;
+ }
+ /* XXX May need to put in a loop XXX */
+ {
+ printf("Going off hook!\n");
/* Take off hook */
x = ZT_OFFHOOK;
if(ioctl(whichzap, ZT_HOOK, &x)) {
fprintf(stdout, "Unable to set hook state.\n");
return -1;
}
+ printf("Off hook!\n");
+ memset(&dop, 0, sizeof(dop));
+ dop.op = ZT_DIAL_OP_REPLACE;
+ dop.dialstr[0] = 'T';
+ strncpy(dop.dialstr + 1, dialstr, sizeof(dop.dialstr) - 1);
+ printf("Dialing...\n");
+ if (ioctl(whichzap, ZT_DIAL, &dop)) {
+ fprintf(stderr, "Unable to dial!\n");
+ return -1;
+ }
+ printf("Finished Dialing...\n");
+ sleep(5);
+ return 0;
+ }
+
+ for (i = 0; i < total; i++) {
+ /* Set echo settings */
+ if (ioctl(whichzap, WCTDM_SET_ECHOTUNE, &echo_trys[i])) {
+ fprintf(stdout, "Unable to set echo params: %s\n", strerror(errno));
+ return -1;
+ }
+
/* write samples */
res = write(whichzap, outbuf, obufsize);
@@ -178,7 +205,7 @@ int main (int argc , char **argv)
int res = 0;
int configfd;
- if (argc != 2) {
+ if ((argc < 2) || (argc > 3)) {
/* Show usage */
fputs(usage, stdout);
return -1;
@@ -239,6 +266,11 @@ int main (int argc , char **argv)
}
if (!strcasecmp(argv[1], "-i")) {
+ if (argc != 3) {
+ /* Show usage */
+ fputs(usage, stdout);
+ return -1;
+ }
configfd = open(configfile, O_CREAT|O_TRUNC|O_WRONLY);
if (configfd < 0) {
@@ -260,7 +292,7 @@ int main (int argc , char **argv)
return -1;
}
- res = echo_tune(fd);
+ res = echo_tune(fd, argv[2]);
close(fd);
if (res > -1) {