Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: chrome/browser/extensions/api/serial/serial_connection_posix.cc

Issue 12294009: Serial bitrate fix for linux (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/serial/serial_connection.h" 5 #include "chrome/browser/extensions/api/serial/serial_connection.h"
6 6
7 #include <sys/ioctl.h> 7 #include <sys/ioctl.h>
8 #include <termios.h> 8 #include <termios.h>
9 9
10 namespace extensions { 10 namespace extensions {
11 11
12 bool SerialConnection::PostOpen() { 12 bool SerialConnection::PostOpen() {
13 struct termios options; 13 struct termios options;
14 14
15 // Start with existing options and modify. 15 // Start with existing options and modify.
16 tcgetattr(file_, &options); 16 tcgetattr(file_, &options);
17 17
18 // Bitrate (sometimes erroneously referred to as baud rate). 18 // Bitrate (sometimes erroneously referred to as baud rate).
19 if (bitrate_ >= 0) { 19 if (bitrate_ >= 0) {
20 cfsetispeed(&options, bitrate_); 20 int bitrate_opt_;
21 cfsetospeed(&options, bitrate_); 21 switch (bitrate_) {
22 case 0:
23 bitrate_opt_ = B0;
24 break;
25 case 50:
26 bitrate_opt_ = B50;
27 break;
28 case 75:
29 bitrate_opt_ = B75;
30 break;
31 case 110:
32 bitrate_opt_ = B110;
33 break;
34 case 134:
35 bitrate_opt_ = B134;
36 break;
37 case 150:
38 bitrate_opt_ = B150;
39 break;
40 case 200:
41 bitrate_opt_ = B200;
42 break;
43 case 300:
44 bitrate_opt_ = B300;
45 break;
46 case 600:
47 bitrate_opt_ = B600;
48 break;
49 case 1200:
50 bitrate_opt_ = B1200;
51 break;
52 case 1800:
53 bitrate_opt_ = B1800;
54 break;
55 case 2400:
56 bitrate_opt_ = B2400;
57 break;
58 case 4800:
59 bitrate_opt_ = B4800;
60 break;
61 case 9600:
62 bitrate_opt_ = B9600;
63 break;
64 case 19200:
65 bitrate_opt_ = B19200;
66 break;
67 case 38400:
68 bitrate_opt_ = B38400;
69 break;
70 #if defined(OS_POSIX) && !defined(OS_MACOSX)
71 case 57600:
72 bitrate_opt_ = B57600;
73 break;
74 case 115200:
75 bitrate_opt_ = B115200;
76 break;
77 case 230400:
78 bitrate_opt_ = B230400;
79 break;
80 case 460800:
81 bitrate_opt_ = B460800;
82 break;
83 case 576000:
84 bitrate_opt_ = B576000;
85 break;
86 case 921600:
87 bitrate_opt_ = B921600;
88 break;
89 default:
90 bitrate_opt_ = B9600;
91 #else
92 // MACOSX doesn't define constants bigger than 38400.
93 // So if it is MACOSX and the value doesn't fit any of the defined constants
94 // It will setup the bitrate with 'bitrate_' (just forwarding the value)
95 default:
96 bitrate_opt_ = bitrate_;
97 #endif
98 }
99
100 cfsetispeed(&options, bitrate_opt_);
101 cfsetospeed(&options, bitrate_opt_);
22 } 102 }
23 103
24 // 8N1 104 // 8N1
25 options.c_cflag &= ~PARENB; 105 options.c_cflag &= ~PARENB;
26 options.c_cflag &= ~CSTOPB; 106 options.c_cflag &= ~CSTOPB;
27 options.c_cflag &= ~CSIZE; 107 options.c_cflag &= ~CSIZE;
28 options.c_cflag |= CS8; 108 options.c_cflag |= CS8;
29 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); 109 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
30 110
31 // Enable receiver and set local mode 111 // Enable receiver and set local mode
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 150
71 return ioctl(file_, TIOCMSET, &status) == 0; 151 return ioctl(file_, TIOCMSET, &status) == 0;
72 } 152 }
73 153
74 std::string SerialConnection::MaybeFixUpPortName( 154 std::string SerialConnection::MaybeFixUpPortName(
75 const std::string &port_name) { 155 const std::string &port_name) {
76 return port_name; 156 return port_name;
77 } 157 }
78 158
79 } // namespace extensions 159 } // namespace extensions
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698