summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2015-04-14 15:36:21 +0200
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>2016-01-03 21:06:21 +0100
commiteaeadc0a8ff2c5ecbc31110bb6e3fe4c5d017e4a (patch)
tree301973c89cd6bbd075ad78412517ac5d682e4435
parentff56995bceffcadad01e5b4fad02a44745d1f5e8 (diff)
downloadmicrocom-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.c2
-rw-r--r--commands.c15
-rw-r--r--microcom.c11
-rw-r--r--microcom.h4
-rw-r--r--serial.c13
-rw-r--r--telnet.c5
6 files changed, 26 insertions, 24 deletions
diff --git a/can.c b/can.c
index 42a9b6a..1de2a12 100644
--- a/can.c
+++ b/can.c
@@ -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;
}
diff --git a/commands.c b/commands.c
index eb54062..41605e7 100644
--- a/commands.c
+++ b/commands.c
@@ -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;
}
diff --git a/microcom.c b/microcom.c
index c32e372..b70e6a9 100644
--- a/microcom.c
+++ b/microcom.c
@@ -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) {
diff --git a/microcom.h b/microcom.h
index e411ffe..b1f7d82 100644
--- a/microcom.h
+++ b/microcom.h
@@ -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);
diff --git a/serial.c b/serial.c
index 740e2dd..f0b3af3 100644
--- a/serial.c
+++ b/serial.c
@@ -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;
diff --git a/telnet.c b/telnet.c
index 6214601..89b6057 100644
--- a/telnet.c
+++ b/telnet.c
@@ -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;