diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2015-04-14 15:36:21 +0200 |
---|---|---|
committer | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2016-01-03 21:06:21 +0100 |
commit | eaeadc0a8ff2c5ecbc31110bb6e3fe4c5d017e4a (patch) | |
tree | 301973c89cd6bbd075ad78412517ac5d682e4435 | |
parent | ff56995bceffcadad01e5b4fad02a44745d1f5e8 (diff) | |
download | microcom-eaeadc0a8ff2c5ecbc31110bb6e3fe4c5d017e4a.tar.gz microcom-eaeadc0a8ff2c5ecbc31110bb6e3fe4c5d017e4a.tar.xz |
make speed argument to .set_speed the actual rate
Up to now the desired speed had to be passed by using one of the speed_t
constants (like B19200). Make this an unsigned long instead to allow
supporting baud rates that don't have a matching constant.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
-rw-r--r-- | can.c | 2 | ||||
-rw-r--r-- | commands.c | 15 | ||||
-rw-r--r-- | microcom.c | 11 | ||||
-rw-r--r-- | microcom.h | 4 | ||||
-rw-r--r-- | serial.c | 13 | ||||
-rw-r--r-- | telnet.c | 5 |
6 files changed, 26 insertions, 24 deletions
@@ -49,7 +49,7 @@ struct can_data { static struct can_data data; static pthread_t can_thread; -static int can_set_speed(struct ios_ops *ios, speed_t speed) +static int can_set_speed(struct ios_ops *ios, unsigned long speed) { return 0; } @@ -11,24 +11,23 @@ static int cmd_speed(int argc, char *argv[]) { - int speed, ret; - speed_t flag; + unsigned long speed; + int ret; if (argc < 2) { - printf("current speed: %d\n", current_speed); + printf("current speed: %lu\n", current_speed); return 0; } speed = strtoul(argv[1], NULL, 0); - ret = baudrate_to_flag(speed, &flag); + + ret = ios->set_speed(ios, speed); if (ret) { - printf("invalid speed %d\n", speed); - return 1; + fprintf(stderr, "invalid speed %lu\n", speed); + return ret; } current_speed = speed; - ios->set_speed(ios, flag); - return 0; } @@ -196,7 +196,7 @@ void main_usage(int exitcode, char *str, char *dev) } int opt_force = 0; -int current_speed = DEFAULT_BAUDRATE; +unsigned long current_speed = DEFAULT_BAUDRATE; int current_flow = FLOW_NONE; int listenonly = 0; @@ -209,7 +209,6 @@ int main(int argc, char *argv[]) char *interfaceid = NULL; char *device = DEFAULT_DEVICE; char *logfile = NULL; - speed_t flag; struct option long_options[] = { { "help", no_argument, 0, 'h' }, @@ -303,12 +302,10 @@ int main(int argc, char *argv[]) exit(1); } - ret = baudrate_to_flag(current_speed, &flag); - if (ret) - exit(1); - current_flow = FLOW_NONE; - ios->set_speed(ios, flag); + if (ios->set_speed(ios, current_speed)) + exit(EXIT_FAILURE); + ios->set_flow(ios, current_flow); if (!listenonly) { @@ -38,7 +38,7 @@ #define DEFAULT_CAN_ID (0x200) struct ios_ops { - int (*set_speed)(struct ios_ops *, speed_t speed); + int (*set_speed)(struct ios_ops *, unsigned long speed); #define FLOW_NONE 0 #define FLOW_SOFT 1 #define FLOW_HARD 2 @@ -110,7 +110,7 @@ void commands_fsl_imx_init(void); (void) (&_max1 == &_max2); \ _max1 > _max2 ? _max1 : _max2; }) -extern int current_speed; +extern unsigned long current_speed; extern int current_flow; int do_commandline(void); int do_script(char *script); @@ -47,13 +47,20 @@ static void init_comm(struct termios *pts) pts->c_iflag &= ~ICRNL; } -static int serial_set_speed(struct ios_ops *ios, speed_t speed) +static int serial_set_speed(struct ios_ops *ios, unsigned long speed) { struct termios pts; /* termios settings on port */ + speed_t flag; + int ret; tcgetattr(ios->fd, &pts); - cfsetospeed(&pts, speed); - cfsetispeed(&pts, speed); + + ret = baudrate_to_flag(speed, &flag); + if (ret) + return ret; + + cfsetospeed(&pts, flag); + cfsetispeed(&pts, flag); tcsetattr(ios->fd, TCSANOW, &pts); return 0; @@ -26,15 +26,14 @@ #include "microcom.h" -static int telnet_set_speed(struct ios_ops *ios, speed_t speed) +static int telnet_set_speed(struct ios_ops *ios, unsigned long speed) { // unsigned char buf1[] = {IAC, WILL , COM_PORT_OPTION}; unsigned char buf2[] = {IAC, SB, COM_PORT_OPTION, SET_BAUDRATE_CS, 0, 0, 0, 0, IAC, SE}; int *speedp = (int *)&buf2[4]; -// write(fd, buf1, 3); - *speedp = htonl(flag_to_baudrate(speed)); + *speedp = htonl(speed); write(ios->fd, buf2, 10); return 0; |