1
0
mirror of https://github.com/UzixLS/picocom.git synced 2025-07-19 07:21:18 +03:00

Added support for setting custom baud rates.

If the requested baudrate is not a custom one (i.e. does not match one
of the Bxxx macros), then the cfsetospeed_custom() and
cfsetispeed_custom() are called to configure the "nexttermios" structure
with the requested non-standard baudrate. Same thing for reading the
baudrate: If cfgetospeed() and / or cfgetispeed() return a value that is
not among the Bxxx macros, cfgetospeed_custom() and cfgetispeed_custom()
are called, to read (and decode) the non-standard baudrate from the
"nexttermios" structure.

Currently the cf[set|get][i|o]speed_custom functions are only
implemented for Linux, and work only with non-ancient kernels (>2.6). So
in effect, custom baud-rate support is currently only supported for
Linux.
This commit is contained in:
Nick Patavalis
2015-08-20 12:40:28 +03:00
parent 30a06fd05f
commit fd306077d6
3 changed files with 48 additions and 16 deletions

View File

@ -33,6 +33,12 @@ CPPFLAGS += -DHISTFILE=\"$(HISTFILE)\" \
picocom : linenoise-1.0/linenoise.o
linenoise-1.0/linenoise.o : linenoise-1.0/linenoise.c linenoise-1.0/linenoise.h
## Comment these IN to enable custom baudrate support.
## Currently works *only* with Linux (kernels > 2.6).
CPPFLAGS += -DUSE_CUSTOM_BAUD
picocom : termios2.o
termios2.o : termios2.c termios2.h termbits2.h
## Comment this IN to remove help strings (saves ~ 4-6 Kb).
#CPPFLAGS += -DNO_HELP
@ -62,6 +68,7 @@ picocom.8.ps : picocom.8
clean:
rm -f picocom.o term.o fdio.o split.o linenoise-1.0/linenoise.o
rm -f termios2.o
rm -f *~
rm -f \#*\#

View File

@ -1159,6 +1159,9 @@ show_usage(char *name)
printf(" LINENOISE is enabled\n");
printf(" HISTFILE is: %s\n", HISTFILE);
#endif
#ifdef USE_CUSTOM_BAUD
printf(" USE_CUSTOM_BAUD is enabled\n");
#endif
printf("\nUsage is: %s [options] <tty device>\n", s);
printf("Options are:\n");

54
term.c
View File

@ -38,6 +38,11 @@
#include <sys/ioctl.h>
#endif
#ifdef USE_CUSTOM_BAUD
/* only works for linux, recent kernels */
#include "termios2.h"
#endif
#include "term.h"
/***************************************************************************/
@ -721,24 +726,28 @@ term_set_baudrate (int fd, int baudrate)
tio = term.nexttermios[i];
spd = Bcode(baudrate);
if ( spd == BNONE ) {
if ( spd != BNONE ) {
r = cfsetospeed(&tio, spd);
if ( r < 0 ) {
term_errno = TERM_ESETOSPEED;
rval = -1;
break;
}
cfsetispeed(&tio, B0);
} else {
#ifdef USE_CUSTOM_BAUD
r = cfsetospeed_custom(&tio, baudrate);
if ( r < 0 ) {
term_errno = TERM_ESETOSPEED;
rval = -1;
break;
}
cfsetispeed(&tio, B0);
#else /* ! defined USE_CUSTOM_BAUD */
term_errno = TERM_EBAUD;
rval = -1;
break;
}
r = cfsetospeed(&tio, spd);
if ( r < 0 ) {
term_errno = TERM_ESETOSPEED;
rval = -1;
break;
}
r = cfsetispeed(&tio, spd);
if ( r < 0 ) {
term_errno = TERM_ESETISPEED;
rval = -1;
break;
#endif /* of USE_CUSTOM_BAUD */
}
term.nexttermios[i] = tio;
@ -765,11 +774,24 @@ term_get_baudrate (int fd, int *ispeed)
if ( ispeed ) {
code = cfgetispeed(&term.currtermios[i]);
*ispeed = Bspeed(code);
#ifdef USE_CUSTOM_BAUD
if ( *ispeed < 0 ) {
*ispeed = cfgetispeed_custom(&term.currtermios[i]);
}
#endif
}
code = cfgetospeed(&term.currtermios[i]);
ospeed = Bspeed(code);
if ( ospeed < 0 )
if ( ospeed < 0 ) {
#ifdef USE_CUSTOM_BAUD
ospeed = cfgetospeed_custom(&term.currtermios[i]);
if ( ospeed < 0 ) {
term_errno = TERM_EGETSPEED;
}
#else
term_errno = TERM_EGETSPEED;
#endif
}
} while (0);