Skip to content

Commit

Permalink
Fixing serial baut/bit rate definition on PostOpen for Linux. By "STA…
Browse files Browse the repository at this point in the history
…NDARD" POSIX defines that B9600, B38400 defined types should be used. Linux define it on /usr/include/rpcsvc/rex.h and it uses numeric sequence increment to enumeration, Mac OS X define it as the same number for example #define B38400 38400. So If you're trying to connect on Linux using a bautrate 38400 for example, the cfsetispeed was called using the 38400 int value, that works for MAC but not for Linux. Code was changed to met the STANDART Bxxxxxx.

Mac OS definition: http://developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man3/cfsetispeed.3.html

Contributed by matheusbrat@gmail.com
BUG found by cTn / Shadow6363 @ freenode - Thanks!

BUG=176439,176711
TEST=Try to open a connection with different bitrates on Linux and see that is working. More information about how to reproduce it on Bug report.

Review URL: https://chromiumcodereview.appspot.com/12294009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183543 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
matheusbrat@gmail.com committed Feb 20, 2013
1 parent 3323801 commit 0d2efd6
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,4 @@ Sungmann Cho <sungmann.cho@gmail.com>
方觉 (Fang Jue) <fangjue23303@gmail.com>
Evan Peterson <evan.peterson.ep@gmail.com>
J. Ryan Stinnett <jryans@chromium.org>
Matheus Bratfisch <matheusbrat@gmail.com>
84 changes: 82 additions & 2 deletions chrome/browser/extensions/api/serial/serial_connection_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,88 @@ bool SerialConnection::PostOpen() {

// Bitrate (sometimes erroneously referred to as baud rate).
if (bitrate_ >= 0) {
cfsetispeed(&options, bitrate_);
cfsetospeed(&options, bitrate_);
int bitrate_opt_;
switch (bitrate_) {
case 0:
bitrate_opt_ = B0;
break;
case 50:
bitrate_opt_ = B50;
break;
case 75:
bitrate_opt_ = B75;
break;
case 110:
bitrate_opt_ = B110;
break;
case 134:
bitrate_opt_ = B134;
break;
case 150:
bitrate_opt_ = B150;
break;
case 200:
bitrate_opt_ = B200;
break;
case 300:
bitrate_opt_ = B300;
break;
case 600:
bitrate_opt_ = B600;
break;
case 1200:
bitrate_opt_ = B1200;
break;
case 1800:
bitrate_opt_ = B1800;
break;
case 2400:
bitrate_opt_ = B2400;
break;
case 4800:
bitrate_opt_ = B4800;
break;
case 9600:
bitrate_opt_ = B9600;
break;
case 19200:
bitrate_opt_ = B19200;
break;
case 38400:
bitrate_opt_ = B38400;
break;
#if defined(OS_POSIX) && !defined(OS_MACOSX)
case 57600:
bitrate_opt_ = B57600;
break;
case 115200:
bitrate_opt_ = B115200;
break;
case 230400:
bitrate_opt_ = B230400;
break;
case 460800:
bitrate_opt_ = B460800;
break;
case 576000:
bitrate_opt_ = B576000;
break;
case 921600:
bitrate_opt_ = B921600;
break;
default:
bitrate_opt_ = B9600;
#else
// MACOSX doesn't define constants bigger than 38400.
// So if it is MACOSX and the value doesn't fit any of the defined constants
// It will setup the bitrate with 'bitrate_' (just forwarding the value)
default:
bitrate_opt_ = bitrate_;
#endif
}

cfsetispeed(&options, bitrate_opt_);
cfsetospeed(&options, bitrate_opt_);
}

// 8N1
Expand Down

0 comments on commit 0d2efd6

Please sign in to comment.