OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "device/serial/serial_io_handler_posix.h" | 5 #include "device/serial/serial_io_handler_posix.h" |
6 | 6 |
7 #include <sys/ioctl.h> | 7 #include <sys/ioctl.h> |
8 #include <termios.h> | 8 #include <termios.h> |
9 | 9 |
10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 if (ioctl(file().GetPlatformFile(), TIOCMGET, &status) == -1) { | 391 if (ioctl(file().GetPlatformFile(), TIOCMGET, &status) == -1) { |
392 VPLOG(1) << "Failed to get port control signals"; | 392 VPLOG(1) << "Failed to get port control signals"; |
393 return serial::DeviceControlSignalsPtr(); | 393 return serial::DeviceControlSignalsPtr(); |
394 } | 394 } |
395 | 395 |
396 serial::DeviceControlSignalsPtr signals(serial::DeviceControlSignals::New()); | 396 serial::DeviceControlSignalsPtr signals(serial::DeviceControlSignals::New()); |
397 signals->dcd = (status & TIOCM_CAR) != 0; | 397 signals->dcd = (status & TIOCM_CAR) != 0; |
398 signals->cts = (status & TIOCM_CTS) != 0; | 398 signals->cts = (status & TIOCM_CTS) != 0; |
399 signals->dsr = (status & TIOCM_DSR) != 0; | 399 signals->dsr = (status & TIOCM_DSR) != 0; |
400 signals->ri = (status & TIOCM_RI) != 0; | 400 signals->ri = (status & TIOCM_RI) != 0; |
401 return signals.Pass(); | 401 return signals; |
402 } | 402 } |
403 | 403 |
404 bool SerialIoHandlerPosix::SetControlSignals( | 404 bool SerialIoHandlerPosix::SetControlSignals( |
405 const serial::HostControlSignals& signals) { | 405 const serial::HostControlSignals& signals) { |
406 int status; | 406 int status; |
407 | 407 |
408 if (ioctl(file().GetPlatformFile(), TIOCMGET, &status) == -1) { | 408 if (ioctl(file().GetPlatformFile(), TIOCMGET, &status) == -1) { |
409 VPLOG(1) << "Failed to get port control signals"; | 409 VPLOG(1) << "Failed to get port control signals"; |
410 return false; | 410 return false; |
411 } | 411 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 } | 471 } |
472 if (config.c_cflag & PARENB) { | 472 if (config.c_cflag & PARENB) { |
473 info->parity_bit = (config.c_cflag & PARODD) ? serial::PARITY_BIT_ODD | 473 info->parity_bit = (config.c_cflag & PARODD) ? serial::PARITY_BIT_ODD |
474 : serial::PARITY_BIT_EVEN; | 474 : serial::PARITY_BIT_EVEN; |
475 } else { | 475 } else { |
476 info->parity_bit = serial::PARITY_BIT_NO; | 476 info->parity_bit = serial::PARITY_BIT_NO; |
477 } | 477 } |
478 info->stop_bits = | 478 info->stop_bits = |
479 (config.c_cflag & CSTOPB) ? serial::STOP_BITS_TWO : serial::STOP_BITS_ONE; | 479 (config.c_cflag & CSTOPB) ? serial::STOP_BITS_TWO : serial::STOP_BITS_ONE; |
480 info->cts_flow_control = (config.c_cflag & CRTSCTS) != 0; | 480 info->cts_flow_control = (config.c_cflag & CRTSCTS) != 0; |
481 return info.Pass(); | 481 return info; |
482 } | 482 } |
483 | 483 |
484 bool SerialIoHandlerPosix::SetBreak() { | 484 bool SerialIoHandlerPosix::SetBreak() { |
485 if (ioctl(file().GetPlatformFile(), TIOCSBRK, 0) != 0) { | 485 if (ioctl(file().GetPlatformFile(), TIOCSBRK, 0) != 0) { |
486 VPLOG(1) << "Failed to set break"; | 486 VPLOG(1) << "Failed to set break"; |
487 return false; | 487 return false; |
488 } | 488 } |
489 | 489 |
490 return true; | 490 return true; |
491 } | 491 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 memcpy(buffer, chars_stashed_, std::min(new_bytes_read, 2)); | 612 memcpy(buffer, chars_stashed_, std::min(new_bytes_read, 2)); |
613 memcpy(chars_stashed_, tmp, num_chars_stashed_); | 613 memcpy(chars_stashed_, tmp, num_chars_stashed_); |
614 return new_bytes_read; | 614 return new_bytes_read; |
615 } | 615 } |
616 | 616 |
617 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { | 617 std::string SerialIoHandler::MaybeFixUpPortName(const std::string& port_name) { |
618 return port_name; | 618 return port_name; |
619 } | 619 } |
620 | 620 |
621 } // namespace device | 621 } // namespace device |
OLD | NEW |