Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit fc9f7fc

Browse files
committed
[22129] Serial I/O: Expand the baudrates on Linux and Mac
1 parent a3f717e commit fc9f7fc

File tree

3 files changed

+33
-52
lines changed

3 files changed

+33
-52
lines changed

docs/notes/bugfix-22129.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Serial I/O: Expand the baudrates on Linux and Mac

engine/src/dsklnx.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,29 +110,38 @@ static void parseSerialControlStr(char *setting, struct termios *theTermios)
110110
if (MCU_strncasecmp(type, "baud", strlen(type)) == 0)
111111
{
112112
long baudrate = strtol(value, NULL, 10);
113-
if (baudrate == 57600)
114-
baud = B57600;
115-
else if (baudrate == 38400)
116-
baud = B38400;
117-
else if (baudrate == 19200)
118-
baud = B19200;
119-
else if (baudrate == 9600)
113+
114+
switch(baudrate)
115+
{
116+
case 4000000: baud = B4000000; break;
117+
case 3500000: baud = B3500000; break;
118+
case 3000000: baud = B3000000; break;
119+
case 2500000: baud = B2500000; break;
120+
case 2000000: baud = B2000000; break;
121+
case 1500000: baud = B1500000; break;
122+
case 1152000: baud = B1152000; break;
123+
case 1000000: baud = B1000000; break;
124+
case 921600: baud = B921600; break;
125+
case 576000: baud = B576000; break;
126+
case 500000: baud = B500000; break;
127+
case 460800: baud = B460800; break;
128+
case 230400: baud = B230400; break;
129+
case 115200: baud = B115200; break;
130+
case 57600: baud = B57600; break;
131+
case 38400: baud = B38400; break;
132+
case 19200: baud = B19200; break;
133+
case 9600: baud = B9600; break;
134+
case 4800: baud = B4800; break;
135+
case 2400: baud = B2400; break;
136+
case 1800: baud = B1800; break;
137+
case 1200: baud = B1200; break;
138+
case 600: baud = B600; break;
139+
case 300: baud = B300; break;
140+
default:
120141
baud = B9600;
121-
122-
else if (baudrate == 4800)
123-
baud = B4800;
124-
else if (baudrate == 3600)
125-
baud = B4800;
126-
else if (baudrate == 2400)
127-
baud = B2400;
128-
else if (baudrate == 1800)
129-
baud = B1800;
130-
else if (baudrate == 1200)
131-
baud = B1200;
132-
else if (baudrate == 600)
133-
baud = B600;
134-
else if (baudrate == 300)
135-
baud = B300;
142+
break;
143+
}
144+
136145
cfsetispeed(theTermios, baud);
137146
cfsetospeed(theTermios, baud);
138147
}

engine/src/dskmac.cpp

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -567,36 +567,7 @@ static void parseSerialControlStr(MCStringRef setting, struct termios *theTermio
567567
{
568568
integer_t baudrate;
569569
/* UNCHECKED */ MCStringToInteger(*t_value, baudrate);
570-
if (baudrate == 57600)
571-
baud = B57600;
572-
else if (baudrate == 38400)
573-
baud = B38400;
574-
else if (baudrate == 28800)
575-
baud = B28800;
576-
else if (baudrate == 19200)
577-
baud = B19200;
578-
else if (baudrate == 16600)
579-
baud = B16600;
580-
else if (baudrate == 14400)
581-
baud = B14400;
582-
else if (baudrate == 9600)
583-
baud = B9600;
584-
else if (baudrate == 7200)
585-
baud = B7200;
586-
else if (baudrate == 4800)
587-
baud = B4800;
588-
else if (baudrate == 3600)
589-
baud = B4800;
590-
else if (baudrate == 2400)
591-
baud = B2400;
592-
else if (baudrate == 1800)
593-
baud = B1800;
594-
else if (baudrate == 1200)
595-
baud = B1200;
596-
else if (baudrate == 600)
597-
baud = B600;
598-
else if (baudrate == 300)
599-
baud = B300;
570+
baud = baudrate;
600571
cfsetispeed(theTermios, baud);
601572
cfsetospeed(theTermios, baud);
602573

0 commit comments

Comments
 (0)