| Index: device/serial/serial_io_handler.cc
|
| diff --git a/device/serial/serial_io_handler.cc b/device/serial/serial_io_handler.cc
|
| index a9cb52f85dc918ae4809110bd9e14a615093004c..288e7618c42d6c729f889eb0f8da53e0c6a01c76 100644
|
| --- a/device/serial/serial_io_handler.cc
|
| +++ b/device/serial/serial_io_handler.cc
|
| @@ -16,6 +16,12 @@ SerialIoHandler::SerialIoHandler(
|
| scoped_refptr<base::MessageLoopProxy> ui_thread_message_loop)
|
| : file_thread_message_loop_(file_thread_message_loop),
|
| ui_thread_message_loop_(ui_thread_message_loop) {
|
| + options_.bitrate = 9600;
|
| + options_.data_bits = serial::DATA_BITS_EIGHT;
|
| + options_.parity_bit = serial::PARITY_BIT_NO;
|
| + options_.stop_bits = serial::STOP_BITS_ONE;
|
| + options_.cts_flow_control = false;
|
| + options_.has_cts_flow_control = true;
|
| }
|
|
|
| SerialIoHandler::~SerialIoHandler() {
|
| @@ -24,12 +30,14 @@ SerialIoHandler::~SerialIoHandler() {
|
| }
|
|
|
| void SerialIoHandler::Open(const std::string& port,
|
| + const serial::ConnectionOptions& options,
|
| const OpenCompleteCallback& callback) {
|
| DCHECK(CalledOnValidThread());
|
| DCHECK(open_complete_.is_null());
|
| open_complete_ = callback;
|
| DCHECK(file_thread_message_loop_.get());
|
| DCHECK(ui_thread_message_loop_.get());
|
| + MergeConnectionOptions(options);
|
| RequestAccess(port, file_thread_message_loop_, ui_thread_message_loop_);
|
| }
|
|
|
| @@ -61,6 +69,26 @@ void SerialIoHandler::OnRequestAccessComplete(const std::string& port,
|
| }
|
| }
|
|
|
| +void SerialIoHandler::MergeConnectionOptions(
|
| + const serial::ConnectionOptions& options) {
|
| + if (options.bitrate) {
|
| + options_.bitrate = options.bitrate;
|
| + }
|
| + if (options.data_bits != serial::DATA_BITS_NONE) {
|
| + options_.data_bits = options.data_bits;
|
| + }
|
| + if (options.parity_bit != serial::PARITY_BIT_NONE) {
|
| + options_.parity_bit = options.parity_bit;
|
| + }
|
| + if (options.stop_bits != serial::STOP_BITS_NONE) {
|
| + options_.stop_bits = options.stop_bits;
|
| + }
|
| + if (options.has_cts_flow_control) {
|
| + DCHECK(options_.has_cts_flow_control);
|
| + options_.cts_flow_control = options.cts_flow_control;
|
| + }
|
| +}
|
| +
|
| void SerialIoHandler::StartOpen(
|
| const std::string& port,
|
| scoped_refptr<base::MessageLoopProxy> io_message_loop) {
|
| @@ -89,15 +117,19 @@ void SerialIoHandler::FinishOpen(base::File file) {
|
| open_complete_.Reset();
|
|
|
| if (!file.IsValid()) {
|
| + LOG(ERROR) << "Failed to open serial port: "
|
| + << base::File::ErrorToString(file.error_details());
|
| callback.Run(false);
|
| return;
|
| }
|
|
|
| file_ = file.Pass();
|
|
|
| - bool success = PostOpen();
|
| - if (!success)
|
| + bool success = PostOpen() && ConfigurePortImpl();
|
| + if (!success) {
|
| Close();
|
| + }
|
| +
|
| callback.Run(success);
|
| }
|
|
|
| @@ -191,6 +223,11 @@ void SerialIoHandler::CancelWrite(serial::SendError reason) {
|
| }
|
| }
|
|
|
| +bool SerialIoHandler::ConfigurePort(const serial::ConnectionOptions& options) {
|
| + MergeConnectionOptions(options);
|
| + return ConfigurePortImpl();
|
| +}
|
| +
|
| void SerialIoHandler::QueueReadCompleted(int bytes_read,
|
| serial::ReceiveError error) {
|
| base::MessageLoop::current()->PostTask(
|
|
|