[Asterisk-cvs] zaptel fxotune.c,1.7,1.8

mattf at lists.digium.com mattf at lists.digium.com
Thu Jan 13 16:21:08 CST 2005


Update of /usr/cvsroot/zaptel
In directory mongoose.digium.com:/tmp/cvs-serv22474

Modified Files:
	fxotune.c 
Log Message:
Mark's magic touches


Index: fxotune.c
===================================================================
RCS file: /usr/cvsroot/zaptel/fxotune.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- fxotune.c	13 Jan 2005 02:45:10 -0000	1.7
+++ fxotune.c	13 Jan 2005 22:25:01 -0000	1.8
@@ -35,8 +35,8 @@
 
 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 @@
 
 /* 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 res = 0;
 	int configfd;
 
-	if (argc != 2) {
+	if ((argc < 2) || (argc > 3)) {
 		/* Show usage */
 		fputs(usage, stdout);
 		return -1;
@@ -239,6 +266,11 @@
 	}
 	
 	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 @@
 				return -1;
 			}
 
-			res = echo_tune(fd);
+			res = echo_tune(fd, argv[2]);
 
 			close(fd);
 			if (res > -1) {




More information about the svn-commits mailing list