diff options
author | Uwe Kleine-König <ukleinek@debian.org> | 2022-09-07 12:24:58 +0200 |
---|---|---|
committer | Uwe Kleine-König <ukleinek@debian.org> | 2022-09-07 12:24:58 +0200 |
commit | bd94799a4ad5a1af20ad35d36e2bec2b5760659c (patch) | |
tree | 6ee17cea8b425cf6fb1280d662044b9a6a94efc9 | |
parent | 927bda7d68dd73ce8437e548a9eea7ceb7fa12aa (diff) | |
parent | 50e868981dbe58a472bb79638f849262f0f432ef (diff) | |
download | microcom-bd94799a4ad5a1af20ad35d36e2bec2b5760659c.tar.gz microcom-bd94799a4ad5a1af20ad35d36e2bec2b5760659c.tar.xz |
Merge branch 'master' of https://github.com/ukleinek/microcom
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | microcom.c | 86 | ||||
-rw-r--r-- | microcom.h | 3 | ||||
-rw-r--r-- | serial.c | 74 |
4 files changed, 75 insertions, 90 deletions
diff --git a/configure.ac b/configure.ac index 3af0b36..5aa1607 100644 --- a/configure.ac +++ b/configure.ac @@ -12,7 +12,7 @@ AC_PROG_CC AC_SYS_LARGEFILE # Checks for libraries. -AC_CHECK_LIB([readline], [readline]) +AC_SEARCH_LIBS([readline], [readline],,[AC_MSG_ERROR([Please install readline development files (libreadline-dev)])]) # Checks for header files. AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/file.h sys/ioctl.h sys/socket.h sys/time.h termios.h unistd.h]) @@ -61,92 +61,6 @@ void restore_terminal(void) tcsetattr(STDIN_FILENO, TCSANOW, &sots); } -static const struct { - int speed; - speed_t flag; -} bd_to_flg[] = { - { 50, B50 }, - { 75, B75 }, - { 110, B110 }, - { 134, B134 }, - { 150, B150 }, - { 200, B200 }, - { 300, B300 }, - { 600, B600 }, - { 1200, B1200}, - { 1800, B1800}, - { 2400, B2400}, - { 4800, B4800}, - { 9600, B9600}, - { 19200, B19200}, - { 38400, B38400}, - { 57600, B57600}, - { 115200, B115200}, - { 230400, B230400}, -#ifdef B460800 - { 460800, B460800}, -#endif -#ifdef B500000 - { 500000, B500000}, -#endif -#ifdef B576000 - { 576000, B576000}, -#endif -#ifdef B921600 - { 921600, B921600}, -#endif -#ifdef B1000000 - { 1000000, B1000000}, -#endif -#ifdef B1152000 - { 1152000, B1152000}, -#endif -#ifdef B1500000 - { 1500000, B1500000}, -#endif -#ifdef B2000000 - { 2000000, B2000000}, -#endif -#ifdef B2500000 - { 2500000, B2500000}, -#endif -#ifdef B3000000 - { 3000000, B3000000}, -#endif -#ifdef B3500000 - { 3500000, B3500000}, -#endif -#ifdef B4000000 - { 4000000, B4000000}, -#endif -}; - -int baudrate_to_flag(int speed, speed_t *flag) -{ - size_t i; - - /* possible optimisation: binary search for speed */ - for (i = 0; i < ARRAY_SIZE(bd_to_flg); ++i) - if (bd_to_flg[i].speed == speed) { - *flag = bd_to_flg[i].flag; - return 0; - } - - printf("unknown speed: %d\n", speed); - return -1; -} - -int flag_to_baudrate(speed_t speed) -{ - size_t i; - - for (i = 0; i < ARRAY_SIZE(bd_to_flg); ++i) - if (bd_to_flg[i].flag == speed) - return bd_to_flg[i].speed; - - printf("unknown speed flag: 0x%x\n", (unsigned)speed); - return -1; -} void microcom_exit(int signal) { @@ -69,9 +69,6 @@ void microcom_cmd_usage(char *str); void main_usage(int exitcode, char *str, char *dev); -int flag_to_baudrate(speed_t speed); -int baudrate_to_flag(int speed, speed_t *flag); - extern struct ios_ops *ios; extern int debug; extern int opt_force; @@ -80,6 +80,80 @@ static int serial_set_handshake_line(struct ios_ops *ios, int pin, int enable) return ret; } +static const struct { + int speed; + speed_t flag; +} bd_to_flg[] = { + { 50, B50 }, + { 75, B75 }, + { 110, B110 }, + { 134, B134 }, + { 150, B150 }, + { 200, B200 }, + { 300, B300 }, + { 600, B600 }, + { 1200, B1200}, + { 1800, B1800}, + { 2400, B2400}, + { 4800, B4800}, + { 9600, B9600}, + { 19200, B19200}, + { 38400, B38400}, + { 57600, B57600}, + { 115200, B115200}, + { 230400, B230400}, +#ifdef B460800 + { 460800, B460800}, +#endif +#ifdef B500000 + { 500000, B500000}, +#endif +#ifdef B576000 + { 576000, B576000}, +#endif +#ifdef B921600 + { 921600, B921600}, +#endif +#ifdef B1000000 + { 1000000, B1000000}, +#endif +#ifdef B1152000 + { 1152000, B1152000}, +#endif +#ifdef B1500000 + { 1500000, B1500000}, +#endif +#ifdef B2000000 + { 2000000, B2000000}, +#endif +#ifdef B2500000 + { 2500000, B2500000}, +#endif +#ifdef B3000000 + { 3000000, B3000000}, +#endif +#ifdef B3500000 + { 3500000, B3500000}, +#endif +#ifdef B4000000 + { 4000000, B4000000}, +#endif +}; + +static int baudrate_to_flag(int speed, speed_t *flag) +{ + size_t i; + + /* possible optimisation: binary search for speed */ + for (i = 0; i < ARRAY_SIZE(bd_to_flg); ++i) + if (bd_to_flg[i].speed == speed) { + *flag = bd_to_flg[i].flag; + return 0; + } + + return -1; +} + static int serial_set_speed(struct ios_ops *ios, unsigned long speed) { struct termios pts; /* termios settings on port */ |