o Add a -a flag for changing/getting the ALTPIN setting for a digi port.

o For the -i switch, only show the device if more than one is given on
  the command line.
This commit is contained in:
Brian Somers 2001-06-20 14:52:20 +00:00
parent 4b65cac846
commit d4140ab80c
2 changed files with 99 additions and 19 deletions

View File

@ -1,5 +1,5 @@
.\" $FreeBSD$
.Dd May 1, 2001
.Dd June 20, 2001
.Dt DIGICTL 8
.Os
.Sh NAME
@ -9,27 +9,55 @@
devices
.Sh SYNOPSIS
.Nm
.Fl a
disable|enable|query
.Ar device ...
.Nm
.Op Fl d Ar debug
.Op Fl ir
.Ar device ...
.Ar ctrl-device ...
.Sh DESCRIPTION
The
.Nm
program provides control of the
.Tn Digiboard
installed with the given control
.Ar device
name.
A digiboard control
installed with the given
.Ar ctrl-device
name and provides control of individual digiboard
.Ar device Ns No s.
A digiboard
.Ar ctrl-device
is usually of the form
.Pa /dev/digi Ns Sy N Ns Pa .ctl
where
.Sy N
is the card number and starts at
.Dq 0
for the first attached card.
A digiboard
.Ar device
is usually of the form
.Pa /dev/digi Ns Ar N Ns Pa .ctl
.Pa /dev/cua Ns Oo Pa \&il Oc Ns Pa D Ns Sy N Ns . Ns Sy D
or
.Pa /dev/tty Ns Oo Pa \&il Oc Ns Pa D Ns Sy N Ns . Ns Sy D
where
.Ar N
is the card number and starts at 0 for the first attached card.
.Sy N
is the card number and
.Sy D
is the port number.
.Pp
The following flags are recognized:
.Bl -tag -xwidth ".Fl d Ar debug"
.Bl -tag
.It Fl a No disable|enable|query
Disable, enable or query the
.Em ALTPIN
settings for the given port(s).
.Pp
When ALTPIN is enabled, the CD and DSR lines are logically reversed.
This is useful when wiring serial ports to an 8 way RJ45 cable (full
10 way RJ45 cables are quite rare).
.Pp
A single ALTPIN setting applies to both of the callout and callin devices.
.It Fl d Ar debug
If the driver has been compiled with
.Dv DEBUG

View File

@ -36,10 +36,13 @@
#include <sys/ioctl.h>
#include <unistd.h>
enum aflag { NO_AFLAG, ALTPIN_DISABLE, ALTPIN_ENABLE, ALTPIN_QUERY };
static int
usage(const char *prog)
{
fprintf(stderr, "Usage: %s [-d debug] [-ir] device...\n", prog);
fprintf(stderr, "Usage: %s -a disable|enable|query device\n", prog);
fprintf(stderr, " %s [-d debug] [-ir] ctrl-device...\n", prog);
return (EX_USAGE);
}
@ -49,35 +52,56 @@ main(int argc, char **argv)
char namedata[256], *name = namedata;
const char *prog;
enum digi_model model;
int ch, debug, fd, i, res;
int altpin, ch, debug, fd, i, res;
int dflag, iflag, rflag;
enum aflag aflag;
if ((prog = strrchr(argv[0], '/')) == NULL)
prog = argv[0];
else
prog++;
aflag = NO_AFLAG;
dflag = iflag = rflag = 0;
while ((ch = getopt(argc, argv, "d:ir")) != -1)
while ((ch = getopt(argc, argv, "a:d:ir")) != -1)
switch (ch) {
case 'a':
if (strcasecmp(optarg, "disable") == 0)
aflag = ALTPIN_DISABLE;
else if (strcasecmp(optarg, "enable") == 0)
aflag = ALTPIN_ENABLE;
else if (strcasecmp(optarg, "query") == 0)
aflag = ALTPIN_QUERY;
else
return (usage(prog));
break;
case 'd':
dflag = 1;
debug = atoi(optarg);
break;
case 'i':
iflag = 1;
break;
case 'r':
rflag = 1;
break;
default:
return usage(prog);
return (usage(prog));
}
if (argc < optind)
return usage(prog);
if ((dflag || iflag || rflag) && aflag != NO_AFLAG)
return (usage(prog));
if (argc <= optind)
return (usage(prog));
altpin = (aflag == ALTPIN_ENABLE);
res = 0;
for (i = optind; i < argc; i++) {
if ((fd = open(argv[i], O_RDONLY)) == -1) {
fprintf(stderr, "%s: %s: open: %s\n", prog, argv[i],
@ -86,6 +110,32 @@ main(int argc, char **argv)
continue;
}
switch (aflag) {
case NO_AFLAG:
break;
case ALTPIN_ENABLE:
case ALTPIN_DISABLE:
if (ioctl(fd, DIGIIO_SETALTPIN, &altpin) != 0) {
fprintf(stderr, "%s: %s: set altpin: %s\n",
prog, argv[i], strerror(errno));
res++;
}
break;
case ALTPIN_QUERY:
if (ioctl(fd, DIGIIO_GETALTPIN, &altpin) != 0) {
fprintf(stderr, "%s: %s: get altpin: %s\n",
prog, argv[i], strerror(errno));
res++;
} else {
if (argc > optind + 1)
printf("%s: ", argv[i]);
puts(altpin ? "enabled" : "disabled");
}
break;
}
if (dflag && ioctl(fd, DIGIIO_DEBUG, &debug) != 0) {
fprintf(stderr, "%s: %s: debug: %s\n",
prog, argv[i], strerror(errno));
@ -101,9 +151,11 @@ main(int argc, char **argv)
fprintf(stderr, "%s: %s: ident: %s\n",
prog, argv[i], strerror(errno));
res++;
} else
printf("%s: %s (type %d)\n",
argv[i], name, (int)model);
} else {
if (argc > optind + 1)
printf("%s: ", argv[i]);
printf("%s (type %d)\n", name, (int)model);
}
}
if (rflag && ioctl(fd, DIGIIO_REINIT) != 0) {