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

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

Issue 107363002: Support custom serial bitrates on OS X (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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
« no previous file with comments | « no previous file | 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 #if defined(OS_LINUX) 10 #if defined(OS_LINUX)
11 #include <linux/serial.h> 11 #include <linux/serial.h>
12 #endif 12 #endif
13 13
14 #if defined(OS_MACOSX)
15 #include <IOKit/serial/ioss.h>
16 #endif
17
14 namespace extensions { 18 namespace extensions {
15 19
16 namespace { 20 namespace {
17 21
18 // Convert an integral bit rate to a nominal one. Returns |true| 22 // Convert an integral bit rate to a nominal one. Returns |true|
19 // if the conversion was successful and |false| otherwise. 23 // if the conversion was successful and |false| otherwise.
20 bool BitrateToSpeedConstant(int bitrate, speed_t* speed) { 24 bool BitrateToSpeedConstant(int bitrate, speed_t* speed) {
21 #define BITRATE_TO_SPEED_CASE(x) case x: *speed = B ## x; return true; 25 #define BITRATE_TO_SPEED_CASE(x) case x: *speed = B ## x; return true;
22 switch (bitrate) { 26 switch (bitrate) {
23 BITRATE_TO_SPEED_CASE(0) 27 BITRATE_TO_SPEED_CASE(0)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return false; 98 return false;
95 } 99 }
96 serial.flags = (serial.flags & ~ASYNC_SPD_MASK) | ASYNC_SPD_CUST; 100 serial.flags = (serial.flags & ~ASYNC_SPD_MASK) | ASYNC_SPD_CUST;
97 serial.custom_divisor = serial.baud_base / bitrate; 101 serial.custom_divisor = serial.baud_base / bitrate;
98 if (serial.custom_divisor < 1) { 102 if (serial.custom_divisor < 1) {
99 serial.custom_divisor = 1; 103 serial.custom_divisor = 1;
100 } 104 }
101 cfsetispeed(config, B38400); 105 cfsetispeed(config, B38400);
102 cfsetospeed(config, B38400); 106 cfsetospeed(config, B38400);
103 return ioctl(file, TIOCSSERIAL, &serial) >= 0; 107 return ioctl(file, TIOCSSERIAL, &serial) >= 0;
108 #elif defined(OS_MACOSX)
109 speed_t speed = static_cast<speed_t>(bitrate);
110 return ioctl(file, IOSSIOSPEED, &speed) != -1;
104 #else 111 #else
105 return false; 112 return false;
106 #endif 113 #endif
107 } 114 }
108 115
109 } // namespace 116 } // namespace
110 117
111 bool SerialConnection::ConfigurePort( 118 bool SerialConnection::ConfigurePort(
112 const api::serial::ConnectionOptions& options) { 119 const api::serial::ConnectionOptions& options) {
113 struct termios config; 120 struct termios config;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 info->cts_flow_control.reset(new bool((config.c_cflag & CRTSCTS) != 0)); 274 info->cts_flow_control.reset(new bool((config.c_cflag & CRTSCTS) != 0));
268 return true; 275 return true;
269 } 276 }
270 277
271 std::string SerialConnection::MaybeFixUpPortName( 278 std::string SerialConnection::MaybeFixUpPortName(
272 const std::string &port_name) { 279 const std::string &port_name) {
273 return port_name; 280 return port_name;
274 } 281 }
275 282
276 } // namespace extensions 283 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698