Chromium Code Reviews| 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 | |
| 5 #include "tools/battor_agent/battor_agent.h" | 4 #include "tools/battor_agent/battor_agent.h" |
| 6 | 5 |
| 7 #include <iomanip> | 6 #include <iomanip> |
| 8 | 7 |
| 9 #include "base/bind.h" | 8 #include "base/bind.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "tools/battor_agent/battor_connection_impl.h" | 10 #include "tools/battor_agent/battor_connection_impl.h" |
| 12 #include "tools/battor_agent/battor_sample_converter.h" | 11 #include "tools/battor_agent/battor_sample_converter.h" |
| 13 | 12 |
| 14 using std::vector; | 13 using std::vector; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 } | 151 } |
| 153 | 152 |
| 154 void BattOrAgent::RecordClockSyncMarker(const std::string& marker) { | 153 void BattOrAgent::RecordClockSyncMarker(const std::string& marker) { |
| 155 DCHECK(thread_checker_.CalledOnValidThread()); | 154 DCHECK(thread_checker_.CalledOnValidThread()); |
| 156 | 155 |
| 157 command_ = Command::RECORD_CLOCK_SYNC_MARKER; | 156 command_ = Command::RECORD_CLOCK_SYNC_MARKER; |
| 158 pending_clock_sync_marker_ = marker; | 157 pending_clock_sync_marker_ = marker; |
| 159 PerformAction(Action::REQUEST_CONNECTION); | 158 PerformAction(Action::REQUEST_CONNECTION); |
| 160 } | 159 } |
| 161 | 160 |
| 161 void BattOrAgent::GetVersion() { | |
| 162 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 163 | |
| 164 command_ = Command::GET_VERSION; | |
| 165 PerformAction(Action::REQUEST_CONNECTION); | |
| 166 } | |
| 167 | |
| 162 void BattOrAgent::BeginConnect() { | 168 void BattOrAgent::BeginConnect() { |
| 163 DCHECK(thread_checker_.CalledOnValidThread()); | 169 DCHECK(thread_checker_.CalledOnValidThread()); |
| 164 | 170 |
| 165 connection_->Open(); | 171 connection_->Open(); |
| 166 } | 172 } |
| 167 | 173 |
| 168 void BattOrAgent::OnConnectionOpened(bool success) { | 174 void BattOrAgent::OnConnectionOpened(bool success) { |
| 169 // Return immediately if opening the connection already timed out. | 175 // Return immediately if opening the connection already timed out. |
| 170 if (timeout_callback_.IsCancelled()) | 176 if (timeout_callback_.IsCancelled()) |
| 171 return; | 177 return; |
| 172 timeout_callback_.Cancel(); | 178 timeout_callback_.Cancel(); |
| 173 | 179 |
| 174 if (!success) { | 180 if (!success) { |
| 175 CompleteCommand(BATTOR_ERROR_CONNECTION_FAILED); | 181 CompleteCommand(BATTOR_ERROR_CONNECTION_FAILED); |
| 176 return; | 182 return; |
| 177 } | 183 } |
| 178 | 184 |
| 179 switch (command_) { | 185 switch (command_) { |
| 180 case Command::START_TRACING: | 186 case Command::START_TRACING: |
| 181 num_init_attempts_ = 1; | 187 num_init_attempts_ = 1; |
| 182 PerformAction(Action::SEND_INIT); | 188 PerformAction(Action::SEND_INIT); |
| 183 return; | 189 return; |
| 184 case Command::STOP_TRACING: | 190 case Command::STOP_TRACING: |
| 185 PerformAction(Action::SEND_EEPROM_REQUEST); | 191 PerformAction(Action::SEND_EEPROM_REQUEST); |
| 186 return; | 192 return; |
| 187 case Command::RECORD_CLOCK_SYNC_MARKER: | 193 case Command::RECORD_CLOCK_SYNC_MARKER: |
| 188 PerformAction(Action::SEND_CURRENT_SAMPLE_REQUEST); | 194 PerformAction(Action::SEND_CURRENT_SAMPLE_REQUEST); |
| 189 return; | 195 return; |
| 196 case Command::GET_VERSION: | |
| 197 PerformAction(Action::SEND_EEPROM_REQUEST); | |
| 198 return; | |
| 190 case Command::INVALID: | 199 case Command::INVALID: |
| 191 NOTREACHED(); | 200 NOTREACHED(); |
| 192 } | 201 } |
| 193 } | 202 } |
| 194 | 203 |
| 195 void BattOrAgent::OnBytesSent(bool success) { | 204 void BattOrAgent::OnBytesSent(bool success) { |
| 196 DCHECK(thread_checker_.CalledOnValidThread()); | 205 DCHECK(thread_checker_.CalledOnValidThread()); |
| 197 | 206 |
| 198 // Return immediately if whatever action we were trying to perform already | 207 // Return immediately if whatever action we were trying to perform already |
| 199 // timed out. | 208 // timed out. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 std::unique_ptr<vector<char>> bytes) { | 247 std::unique_ptr<vector<char>> bytes) { |
| 239 // Return immediately if whatever action we were trying to perform already | 248 // Return immediately if whatever action we were trying to perform already |
| 240 // timed out. | 249 // timed out. |
| 241 if (timeout_callback_.IsCancelled()) | 250 if (timeout_callback_.IsCancelled()) |
| 242 return; | 251 return; |
| 243 timeout_callback_.Cancel(); | 252 timeout_callback_.Cancel(); |
| 244 | 253 |
| 245 if (!success) { | 254 if (!success) { |
| 246 switch (last_action_) { | 255 switch (last_action_) { |
| 247 case Action::READ_EEPROM: | 256 case Action::READ_EEPROM: |
| 257 if (command_ == Command::GET_VERSION) { | |
| 258 CompleteCommand(BATTOR_ERROR_NONE); | |
|
charliea (OOO until 10-5)
2016/10/05 15:19:28
This should be the error case, not the happy case.
| |
| 259 } | |
| 248 case Action::READ_CALIBRATION_FRAME: | 260 case Action::READ_CALIBRATION_FRAME: |
| 249 case Action::READ_DATA_FRAME: | 261 case Action::READ_DATA_FRAME: |
| 250 case Action::READ_CURRENT_SAMPLE: | 262 case Action::READ_CURRENT_SAMPLE: |
| 251 if (num_read_attempts_++ > kMaxReadAttempts) { | 263 if (num_read_attempts_++ > kMaxReadAttempts) { |
| 252 CompleteCommand(BATTOR_ERROR_RECEIVE_ERROR); | 264 CompleteCommand(BATTOR_ERROR_RECEIVE_ERROR); |
| 253 return; | 265 return; |
| 254 } | 266 } |
| 255 | 267 |
| 256 PerformDelayedAction(last_action_, base::TimeDelta::FromMilliseconds( | 268 PerformDelayedAction(last_action_, base::TimeDelta::FromMilliseconds( |
| 257 kReadRetryDelayMilliseconds)); | 269 kReadRetryDelayMilliseconds)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); | 320 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); |
| 309 return; | 321 return; |
| 310 } | 322 } |
| 311 | 323 |
| 312 CompleteCommand(BATTOR_ERROR_NONE); | 324 CompleteCommand(BATTOR_ERROR_NONE); |
| 313 return; | 325 return; |
| 314 | 326 |
| 315 case Action::READ_EEPROM: { | 327 case Action::READ_EEPROM: { |
| 316 battor_eeprom_ = ParseEEPROM(type, *bytes); | 328 battor_eeprom_ = ParseEEPROM(type, *bytes); |
| 317 if (!battor_eeprom_) { | 329 if (!battor_eeprom_) { |
| 330 // Here is where the error is being thrown.............................. ........ | |
| 318 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); | 331 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); |
| 319 return; | 332 return; |
| 320 } | 333 } |
| 321 | 334 |
| 322 // Make sure that we don't request samples until a safe amount of time has | 335 // Make sure that we don't request samples until a safe amount of time has |
| 323 // elapsed since recording the last clock sync marker: we need to ensure | 336 // elapsed since recording the last clock sync marker: we need to ensure |
| 324 // that the sample we synced to doesn't get thrown out. | 337 // that the sample we synced to doesn't get thrown out. |
| 325 base::TimeTicks min_request_samples_time = | 338 base::TimeTicks min_request_samples_time = |
| 326 last_clock_sync_time_ + base::TimeDelta::FromMilliseconds( | 339 last_clock_sync_time_ + base::TimeDelta::FromMilliseconds( |
| 327 kStopTracingClockSyncDelayMilliseconds); | 340 kStopTracingClockSyncDelayMilliseconds); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 base::ThreadTaskRunnerHandle::Get()->PostTask( | 536 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 524 FROM_HERE, | 537 FROM_HERE, |
| 525 base::Bind(&Listener::OnStopTracingComplete, | 538 base::Bind(&Listener::OnStopTracingComplete, |
| 526 base::Unretained(listener_), SamplesToString(), error)); | 539 base::Unretained(listener_), SamplesToString(), error)); |
| 527 break; | 540 break; |
| 528 case Command::RECORD_CLOCK_SYNC_MARKER: | 541 case Command::RECORD_CLOCK_SYNC_MARKER: |
| 529 base::ThreadTaskRunnerHandle::Get()->PostTask( | 542 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 530 FROM_HERE, base::Bind(&Listener::OnRecordClockSyncMarkerComplete, | 543 FROM_HERE, base::Bind(&Listener::OnRecordClockSyncMarkerComplete, |
| 531 base::Unretained(listener_), error)); | 544 base::Unretained(listener_), error)); |
| 532 break; | 545 break; |
| 546 // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | |
| 547 // Need to get proper version number. | |
| 548 case Command::GET_VERSION: | |
| 549 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 550 FROM_HERE, base::Bind(&Listener::OnGetVersionComplete, | |
| 551 base::Unretained(listener_), 1, error)); | |
| 552 break; | |
| 533 case Command::INVALID: | 553 case Command::INVALID: |
| 534 NOTREACHED(); | 554 NOTREACHED(); |
| 535 } | 555 } |
| 536 | 556 |
| 537 last_action_ = Action::INVALID; | 557 last_action_ = Action::INVALID; |
| 538 command_ = Command::INVALID; | 558 command_ = Command::INVALID; |
| 539 pending_clock_sync_marker_.clear(); | 559 pending_clock_sync_marker_.clear(); |
| 540 battor_eeprom_.reset(); | 560 battor_eeprom_.reset(); |
| 541 calibration_frame_.clear(); | 561 calibration_frame_.clear(); |
| 542 samples_.clear(); | 562 samples_.clear(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 if (clock_sync_marker != clock_sync_markers_.end()) | 597 if (clock_sync_marker != clock_sync_markers_.end()) |
| 578 trace_stream << " <" << clock_sync_marker->second << ">"; | 598 trace_stream << " <" << clock_sync_marker->second << ">"; |
| 579 | 599 |
| 580 trace_stream << std::endl; | 600 trace_stream << std::endl; |
| 581 } | 601 } |
| 582 | 602 |
| 583 return trace_stream.str(); | 603 return trace_stream.str(); |
| 584 } | 604 } |
| 585 | 605 |
| 586 } // namespace battor | 606 } // namespace battor |
| OLD | NEW |