| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "tools/battor_agent/battor_connection_impl.h" | 5 #include "tools/battor_agent/battor_connection_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 221 } |
| 222 | 222 |
| 223 if (bytes_read == 0) { | 223 if (bytes_read == 0) { |
| 224 // If we didn't have a message before, and we weren't able to read any | 224 // If we didn't have a message before, and we weren't able to read any |
| 225 // additional bytes, then there's no valid message available. | 225 // additional bytes, then there's no valid message available. |
| 226 LogSerial("Read failed due to no bytes being read."); | 226 LogSerial("Read failed due to no bytes being read."); |
| 227 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); | 227 EndReadBytes(false, BATTOR_MESSAGE_TYPE_CONTROL, nullptr); |
| 228 return; | 228 return; |
| 229 } | 229 } |
| 230 | 230 |
| 231 LogSerial(StringPrintf( | 231 if (pending_read_message_type_ == BATTOR_MESSAGE_TYPE_SAMPLES) { |
| 232 "%d more bytes read: %s.", bytes_read, | 232 // If we're reading samples, don't log every byte that we receive. This |
| 233 CharArrayToString(pending_read_buffer_->data(), bytes_read).c_str())); | 233 // exacerbates a problem on Mac wherein we can't process sample frames |
| 234 // quickly enough to prevent the serial buffer from overflowing, causing us |
| 235 // to drop frames. |
| 236 LogSerial(StringPrintf("%d more bytes read.", bytes_read)); |
| 237 } else { |
| 238 LogSerial(StringPrintf( |
| 239 "%d more bytes read: %s.", bytes_read, |
| 240 CharArrayToString(pending_read_buffer_->data(), bytes_read).c_str())); |
| 241 } |
| 234 | 242 |
| 235 already_read_buffer_.insert(already_read_buffer_.end(), | 243 already_read_buffer_.insert(already_read_buffer_.end(), |
| 236 pending_read_buffer_->data(), | 244 pending_read_buffer_->data(), |
| 237 pending_read_buffer_->data() + bytes_read); | 245 pending_read_buffer_->data() + bytes_read); |
| 238 | 246 |
| 239 BattOrMessageType type; | 247 BattOrMessageType type; |
| 240 size_t message_max_bytes = | 248 size_t message_max_bytes = |
| 241 GetMaxBytesForMessageType(pending_read_message_type_); | 249 GetMaxBytesForMessageType(pending_read_message_type_); |
| 242 std::unique_ptr<vector<char>> bytes(new vector<char>()); | 250 std::unique_ptr<vector<char>> bytes(new vector<char>()); |
| 243 bytes->reserve(message_max_bytes); | 251 bytes->reserve(message_max_bytes); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 base::ThreadTaskRunnerHandle::Get()->PostTask( | 352 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 345 FROM_HERE, | 353 FROM_HERE, |
| 346 base::Bind(&Listener::OnBytesSent, base::Unretained(listener_), success)); | 354 base::Bind(&Listener::OnBytesSent, base::Unretained(listener_), success)); |
| 347 } | 355 } |
| 348 | 356 |
| 349 void BattOrConnectionImpl::LogSerial(const std::string& str) { | 357 void BattOrConnectionImpl::LogSerial(const std::string& str) { |
| 350 serial_log_ << str << std::endl << std::endl; | 358 serial_log_ << str << std::endl << std::endl; |
| 351 } | 359 } |
| 352 | 360 |
| 353 } // namespace battor | 361 } // namespace battor |
| OLD | NEW |