[svn-commits] tzafrir: tools/trunk r7658 - in /tools/trunk: ./ doc/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Dec 2 13:45:49 CST 2009


Author: tzafrir
Date: Wed Dec  2 13:45:45 2009
New Revision: 7658

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=7658
Log:
patgen and pattest: channel by number

Allow pattest and patgen to get the DAHDI channel by number rather than
with an explicit device file.

Modified:
    tools/trunk/doc/patgen.8
    tools/trunk/doc/pattest.8
    tools/trunk/patgen.c
    tools/trunk/pattest.c

Modified: tools/trunk/doc/patgen.8
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/doc/patgen.8?view=diff&rev=7658&r1=7657&r2=7658
==============================================================================
--- tools/trunk/doc/patgen.8 (original)
+++ tools/trunk/doc/patgen.8 Wed Dec  2 13:45:45 2009
@@ -1,4 +1,4 @@
-.TH patgen 8 "2008-01-08" 
+.TH patgen 8 "2 Dec 2009" 
 .SH NAME 
 patgen \(em Generates a Pattern for a DAHDI Clear Channel Test
 .SH SYNOPSIS 
@@ -18,15 +18,17 @@
 .SH OPTIONS
 .I dahdi-device
 .RS
-A DAHDI device file.
+A DAHDI device. Can be either a device number or an explicit device file
+name
 .RE
 
 .SH EXAMPLE
   patgen /dev/dahdi/5
 
+  patgen 305
+
 .SH BUGS
-Will not work with channels whose number > 249 as they don't have device
-files. For a simple workaround, see dahdi_diag.c .
+Waiting for you to report them at <http://issues.asterisk.org> .
 
 .SH SEE ALSO 
 pattest(8), dahdi_cfg(8), asterisk(8). 

Modified: tools/trunk/doc/pattest.8
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/doc/pattest.8?view=diff&rev=7658&r1=7657&r2=7658
==============================================================================
--- tools/trunk/doc/pattest.8 (original)
+++ tools/trunk/doc/pattest.8 Wed Dec  2 13:45:45 2009
@@ -1,4 +1,4 @@
-.TH pattest 8 "2008-01-08" 
+.TH pattest 8 "2 Dec 2009" 
 .SH NAME 
 pattest \(em Tests a Pattern for a DAHDI Clear Channel Test
 .SH SYNOPSIS 
@@ -22,16 +22,17 @@
 .SH OPTIONS
 .I dahdi-device
 .RS
-A DAHDI device file.
+A DAHDI device. Can be either a device number or an explicit device file
+name
 .RE
 
 .SH EXAMPLE
   pattest /dev/dahdi/5
 
+  pattest 305
+.RE
+
 .SH BUGS
-Will not work with channels whose number > 249 as they don't have device
-files. For a simple workaround, see dahdi_diag.c .
-
 Gives way too many errors when does not get any input.
 
 .SH SEE ALSO 

Modified: tools/trunk/patgen.c
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/patgen.c?view=diff&rev=7658&r1=7657&r2=7658
==============================================================================
--- tools/trunk/patgen.c (original)
+++ tools/trunk/patgen.c Wed Dec  2 13:45:45 2009
@@ -42,6 +42,19 @@
 
 /* #define BLOCK_SIZE 2048 */
 #define BLOCK_SIZE 2041
+#define DEVICE	  "/dev/dahdi/channel"
+
+static const char	rcsid[] = "$Id$";
+char			*prog_name;
+
+static void usage(void)
+{
+	fprintf(stderr, "Usage: %s <dahdi_chan>\n", prog_name);
+	fprintf(stderr, "   e.g.: %s /dev/dahdi/55\n", prog_name);
+	fprintf(stderr, "         %s 455\n", prog_name);
+	fprintf(stderr, "%s version %s\n", prog_name, rcsid);
+	exit(1);
+}
 
 void print_packet(unsigned char *buf, int len)
 {
@@ -52,31 +65,60 @@
 	printf("}\n");
 }
 
+int channel_open(char *name, int *bs)
+{
+	int 			channo;
+	int			fd;
+	struct 			dahdi_params tp;
+	char 			*dev;
+
+	channo = atoi(name);
+	/* channo==0: The user passed a file name to be opened. */
+	dev = channo ? DEVICE : name;
+
+	fd = open(dev, O_RDWR, 0600);
+
+	if (fd < 0) {
+		perror(DEVICE);
+		return -1;
+	}
+
+	/* If we got a channel number, get it from /dev/dahdi/channel: */
+	if(channo && ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
+		perror("SPECIFY");
+		return -1;
+	}
+	if(ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
+		perror("SET_BLOCKSIZE");
+		return -1;
+	}
+
+	if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
+		fprintf(stderr, "Unable to get channel parameters\n");
+		return -1;
+	}
+
+	return fd;
+}
+
 int main(int argc, char *argv[])
 {
 	int fd;
 	int res, res1, x;
-	struct dahdi_params tp;
 	int bs = BLOCK_SIZE;
 	unsigned char c=0;
 	unsigned char outbuf[BLOCK_SIZE];
+
+	prog_name = argv[0];
+
 	if (argc < 2) {
-		fprintf(stderr, "Usage: %s <DAHDI device>\n", argv[0]);
+		usage();
+	}
+
+	fd = channel_open(argv[1], &bs);
+	if (fd < 0)
 		exit(1);
-	}
-	fd = open(argv[1], O_RDWR, 0600);
-	if (fd < 0) {
-		fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
-		exit(1);
-	}
-	if (ioctl(fd, DAHDI_SET_BLOCKSIZE, &bs)) {
-		fprintf(stderr, "Unable to set block size to %d: %s\n", bs, strerror(errno));
-		exit(1);
-	}
-	if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
-		fprintf(stderr, "Unable to get channel parameters\n");
-		exit(1);
-	}
+
 	ioctl(fd, DAHDI_GETEVENT);
 #if 0
 	print_packet(outbuf, res);

Modified: tools/trunk/pattest.c
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/pattest.c?view=diff&rev=7658&r1=7657&r2=7658
==============================================================================
--- tools/trunk/pattest.c (original)
+++ tools/trunk/pattest.c Wed Dec  2 13:45:45 2009
@@ -41,6 +41,19 @@
 #include "dahdi_tools_version.h"
 
 #define BLOCK_SIZE 2039
+#define DEVICE	  "/dev/dahdi/channel"
+
+static const char	rcsid[] = "$Id$";
+char			*prog_name;
+
+static void usage(void)
+{
+	fprintf(stderr, "Usage: %s <dahdi_chan>\n", prog_name);
+	fprintf(stderr, "   e.g.: %s /dev/dahdi/55\n", prog_name);
+	fprintf(stderr, "         %s 455\n", prog_name);
+	fprintf(stderr, "%s version %s\n", prog_name, rcsid);
+	exit(1);
+}
 
 void print_packet(unsigned char *buf, int len)
 {
@@ -51,34 +64,63 @@
 	printf("}\n");
 }
 
+int channel_open(char *name, int *bs)
+{
+	int 			channo;
+	int			fd;
+	struct 			dahdi_params tp;
+	char 			*dev;
+
+	channo = atoi(name);
+	/* channo==0: The user passed a file name to be opened. */
+	dev = channo ? DEVICE : name;
+
+	fd = open(dev, O_RDWR, 0600);
+
+	if (fd < 0) {
+		perror(DEVICE);
+		return -1;
+	}
+
+	/* If we got a channel number, get it from /dev/dahdi/channel: */
+	if(channo && ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
+		perror("SPECIFY");
+		return -1;
+	}
+	if(ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
+		perror("SET_BLOCKSIZE");
+		return -1;
+	}
+
+	if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
+		fprintf(stderr, "Unable to get channel parameters\n");
+		return -1;
+	}
+
+	return fd;
+}
+
 int main(int argc, char *argv[])
 {
 	int fd;
 	int res, x;
-	struct dahdi_params tp;
 	int bs = BLOCK_SIZE;
 	unsigned char c=0;
 	unsigned char outbuf[BLOCK_SIZE];
 	int setup=0;
 	int errors=0;
 	int bytes=0;
+
+	prog_name = argv[0];
+
 	if (argc < 2) {
-		fprintf(stderr, "Usage: %s <DAHDI device>\n", argv[0]);
+		usage();
+	}
+
+	fd = channel_open(argv[1], &bs);
+	if (fd < 0)
 		exit(1);
-	}
-	fd = open(argv[1], O_RDWR, 0600);
-	if (fd < 0) {
-		fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
-		exit(1);
-	}
-	if (ioctl(fd, DAHDI_SET_BLOCKSIZE, &bs)) {
-		fprintf(stderr, "Unable to set block size to %d: %s\n", bs, strerror(errno));
-		exit(1);
-	}
-	if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
-		fprintf(stderr, "Unable to get channel parameters\n");
-		exit(1);
-	}
+
 	ioctl(fd, DAHDI_GETEVENT);
 	for(;;) {
 		res = bs;




More information about the svn-commits mailing list