| 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_agent.h" | 5 #include "tools/battor_agent/battor_agent.h" |
| 6 | 6 |
| 7 #include <iomanip> | 7 #include <iomanip> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 reinterpret_cast<const BattOrControlMessageAck*>(msg.data()); | 48 reinterpret_cast<const BattOrControlMessageAck*>(msg.data()); |
| 49 | 49 |
| 50 if (ack->type != control_message_type) | 50 if (ack->type != control_message_type) |
| 51 return false; | 51 return false; |
| 52 | 52 |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Attempts to decode the specified vector of bytes decodes to a valid EEPROM. | 56 // Attempts to decode the specified vector of bytes decodes to a valid EEPROM. |
| 57 // Returns the new EEPROM, or nullptr if unsuccessful. | 57 // Returns the new EEPROM, or nullptr if unsuccessful. |
| 58 scoped_ptr<BattOrEEPROM> ParseEEPROM(BattOrMessageType message_type, | 58 std::unique_ptr<BattOrEEPROM> ParseEEPROM(BattOrMessageType message_type, |
| 59 const vector<char>& msg) { | 59 const vector<char>& msg) { |
| 60 if (message_type != BATTOR_MESSAGE_TYPE_CONTROL_ACK) | 60 if (message_type != BATTOR_MESSAGE_TYPE_CONTROL_ACK) |
| 61 return nullptr; | 61 return nullptr; |
| 62 | 62 |
| 63 if (msg.size() != sizeof(BattOrEEPROM)) | 63 if (msg.size() != sizeof(BattOrEEPROM)) |
| 64 return nullptr; | 64 return nullptr; |
| 65 | 65 |
| 66 scoped_ptr<BattOrEEPROM> eeprom(new BattOrEEPROM()); | 66 std::unique_ptr<BattOrEEPROM> eeprom(new BattOrEEPROM()); |
| 67 memcpy(eeprom.get(), msg.data(), sizeof(BattOrEEPROM)); | 67 memcpy(eeprom.get(), msg.data(), sizeof(BattOrEEPROM)); |
| 68 return eeprom; | 68 return eeprom; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Returns true if the specified vector of bytes decodes to a valid BattOr | 71 // Returns true if the specified vector of bytes decodes to a valid BattOr |
| 72 // samples frame. The frame header and samples are returned via the frame_header | 72 // samples frame. The frame header and samples are returned via the frame_header |
| 73 // and samples paramaters. | 73 // and samples paramaters. |
| 74 bool ParseSampleFrame(BattOrMessageType type, | 74 bool ParseSampleFrame(BattOrMessageType type, |
| 75 const vector<char>& msg, | 75 const vector<char>& msg, |
| 76 uint32_t expected_sequence_number, | 76 uint32_t expected_sequence_number, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 num_read_attempts_ = 1; | 237 num_read_attempts_ = 1; |
| 238 PerformAction(Action::READ_CURRENT_SAMPLE); | 238 PerformAction(Action::READ_CURRENT_SAMPLE); |
| 239 return; | 239 return; |
| 240 default: | 240 default: |
| 241 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); | 241 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 void BattOrAgent::OnMessageRead(bool success, | 245 void BattOrAgent::OnMessageRead(bool success, |
| 246 BattOrMessageType type, | 246 BattOrMessageType type, |
| 247 scoped_ptr<vector<char>> bytes) { | 247 std::unique_ptr<vector<char>> bytes) { |
| 248 // Return immediately if whatever action we were trying to perform already | 248 // Return immediately if whatever action we were trying to perform already |
| 249 // timed out. | 249 // timed out. |
| 250 if (timeout_callback_.IsCancelled()) | 250 if (timeout_callback_.IsCancelled()) |
| 251 return; | 251 return; |
| 252 timeout_callback_.Cancel(); | 252 timeout_callback_.Cancel(); |
| 253 | 253 |
| 254 if (!success) { | 254 if (!success) { |
| 255 switch (last_action_) { | 255 switch (last_action_) { |
| 256 case Action::READ_EEPROM: | 256 case Action::READ_EEPROM: |
| 257 case Action::READ_CALIBRATION_FRAME: | 257 case Action::READ_CALIBRATION_FRAME: |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 if (clock_sync_marker != clock_sync_markers_.end()) | 561 if (clock_sync_marker != clock_sync_markers_.end()) |
| 562 trace_stream << " <" << clock_sync_marker->second << ">"; | 562 trace_stream << " <" << clock_sync_marker->second << ">"; |
| 563 | 563 |
| 564 trace_stream << std::endl; | 564 trace_stream << std::endl; |
| 565 } | 565 } |
| 566 | 566 |
| 567 return trace_stream.str(); | 567 return trace_stream.str(); |
| 568 } | 568 } |
| 569 | 569 |
| 570 } // namespace battor | 570 } // namespace battor |
| OLD | NEW |