PERFORCE change 97037 for review
Marcel Moolenaar
marcel at FreeBSD.org
Fri May 12 23:30:21 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=97037
Change 97037 by marcel at marcel_nfs on 2006/05/12 23:29:24
Allow setting the line speed on the command line and
bail out if tcsetattr() fails.
Affected files ...
.. //depot/projects/uart/dev/uart/uarttest.c#6 edit
Differences ...
==== //depot/projects/uart/dev/uart/uarttest.c#6 (text+ko) ====
@@ -155,9 +155,11 @@
{
char buf[PATH_MAX];
struct termios t0, t1;
+ speed_t sp;
int ch;
- while ((ch = getopt(argc, argv, "clt")) != -1) {
+ sp = 9600; /* Any speed that we expect to work for all UARTs */
+ while ((ch = getopt(argc, argv, "cls:t")) != -1) {
switch (ch) {
case 'c': /* DCE mode */
sethow(AS_DCE);
@@ -165,6 +167,9 @@
case 'l': /* Loopback mode */
sethow(AS_LOOP);
break;
+ case 's': /* Line speed */
+ sp = atoi(optarg);
+ break;
case 't': /* DTE mode */
sethow(AS_DTE);
break;
@@ -198,7 +203,7 @@
tcgetattr(fd, &t0);
t1 = t0;
cfmakeraw(&t1);
- cfsetspeed(&t1, B115200);
+ cfsetspeed(&t1, sp);
switch (how) {
case AS_DCE:
t1.c_cflag |= CRTS_IFLOW;
@@ -210,7 +215,10 @@
t1.c_cflag |= CCTS_OFLOW | CRTS_IFLOW;
break;
}
- tcsetattr(fd, TCSAFLUSH|TCSANOW, &t1);
+ if (tcsetattr(fd, TCSAFLUSH|TCSANOW, &t1) == -1)
+ err(EX_IOERR, "cannot set line attributes");
+
+ printf("Line speed is %u baud\n", sp);
switch (how) {
case AS_DCE:
More information about the p4-projects
mailing list