[Asterisk-cvs] zaptel Makefile,1.62,1.63 fxotune.c,1.4,1.5

mattf at lists.digium.com mattf at lists.digium.com
Mon Jan 10 20:28:55 CST 2005


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

Modified Files:
	Makefile fxotune.c 
Log Message:
Working out bugs


Index: Makefile
===================================================================
RCS file: /usr/cvsroot/zaptel/Makefile,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- Makefile	9 Jan 2005 01:17:38 -0000	1.62
+++ Makefile	11 Jan 2005 02:33:08 -0000	1.63
@@ -368,4 +368,5 @@
 	rm -f gendigits tones.h
 	rm -f libtonezone*
 	rm -f tor2ee
+	rm -f fxotune
 	rm -f core

Index: fxotune.c
===================================================================
RCS file: /usr/cvsroot/zaptel/fxotune.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- fxotune.c	11 Jan 2005 00:20:49 -0000	1.4
+++ fxotune.c	11 Jan 2005 02:33:08 -0000	1.5
@@ -26,7 +26,8 @@
 #include "zaptel.h"
 
 
-static int testduration = 100;  /* Test the line for x milliseconds */
+//static int testduration = 100;  /* Test the line for x milliseconds */
+#define TESTDURATION 100  /* Test the line for x milliseconds */
 static int readduration = 100 * 2;
 
 static char *zappath = "/dev/zap";
@@ -39,6 +40,9 @@
 
 #define OUT_OF_BOUNDS(x) ((x) < 0 || (x) > 255)
 
+static short *outbuf = NULL;
+static short obufsize = TESTDURATION * 8 * 2;
+
 int process_readbuf(short *ibuf, int isize, short *obuf, int osize)
 {
 	int i = 0;
@@ -52,21 +56,13 @@
 	return minsample;
 }
 
-/* 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)
+int fill_outputdata(void)
 {
-	short bestval = 32355;
-	int bestindex = -1;
-	int i = 0;
-	int res = 0;
-	int total = sizeof(echo_trys) / sizeof(struct wctdm_echo_coefs);
 	int randdev;
-	short *outbuf = NULL, *inbuf = NULL;
-	int obufsize = testduration * 8 * 2; /* In one milisecond there are 8 samples of 2 byte length */
-	int ibufsize = readduration * 8 * 2;
-
+	int cursize = 0;
+	int res;
 
+	fprintf(stdout, "Getting random impulse data\n");
 	randdev = open("/dev/random", O_RDONLY);
 	if (randdev < 0) {
 		fprintf(stdout, "Unable to open /dev/random: %s\n", strerror(errno));
@@ -78,21 +74,36 @@
 		exit(-1);
 	}
 	
-	res = read(randdev, outbuf, obufsize);
-	if (res <= 0) {
-		fprintf(stdout, "WARNING: could not read from /dev/random: %s\n", strerror(errno));
-		return -1;
+	while (cursize < obufsize) {
+		res = read(randdev, &outbuf[cursize], obufsize - cursize);
+		if (res <= 0) {
+			fprintf(stdout, "WARNING: could not read from /dev/random: %s\n", strerror(errno));
+			return -1;
+		}
+		cursize += res;
 	}
+	
+	fprintf(stdout, "Cool, we filled the random data buffer\n");
+	close(randdev);
 
-	if (res != obufsize) {
-		fprintf(stdout, "Could not read request %d bytes from /dev/random.  Using only %d\n", obufsize, res);
-		ibufsize = res;
-	}
+	return 0;
+}
 
-	close(randdev);
 
-	outbuf = malloc(readduration);
-	if (!outbuf) {
+/* 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)
+{
+	short bestval = 32355;
+	int bestindex = -1;
+	int i = 0;
+	int res = 0;
+	int total = sizeof(echo_trys) / sizeof(struct wctdm_echo_coefs);
+	short *inbuf = NULL;
+	int ibufsize = readduration * 8 * 2;
+
+	inbuf = malloc(readduration);
+	if (!inbuf) {
 		fprintf(stdout, "Malloc failed on readbuf.  Bad, bad, bad....\n");
 		exit(-1);
 	}
@@ -235,6 +246,11 @@
 			return -1;
 		}
 
+		if (fill_outputdata()) {
+			fprintf(stdout, "Error in generating outputdata... dieing\n");
+			return -1;
+		}
+
 		for (i = 0; i < 252; i++) {
 			snprintf(zapdev, sizeof(zapdev), "%s/%d", zappath, i+1);
 
@@ -245,6 +261,8 @@
 			}
 
 			res = echo_tune(fd);
+
+			close(fd);
 			if (res > -1) {
 			/* Do output to file */
 				int len = 0;
@@ -262,6 +280,8 @@
 				}
 			}
 		}
+
+		close(configfd);
 	}
 
 	return 0;




More information about the svn-commits mailing list