Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
|
charliea (OOO until 10-5)
2017/01/12 17:05:50
nit in description: s/geting/getting
rnephew (Reviews Here)
2017/01/12 17:53:21
Done.
| |
| 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 #include "tools/battor_agent/battor_agent.h" | 4 #include "tools/battor_agent/battor_agent.h" |
| 5 | 5 |
| 6 #include <iomanip> | 6 #include <iomanip> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "tools/battor_agent/battor_connection_impl.h" | 10 #include "tools/battor_agent/battor_connection_impl.h" |
| 11 #include "tools/battor_agent/battor_sample_converter.h" | 11 #include "tools/battor_agent/battor_sample_converter.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 num_init_attempts_ = 1; | 191 num_init_attempts_ = 1; |
| 192 PerformAction(Action::SEND_INIT); | 192 PerformAction(Action::SEND_INIT); |
| 193 return; | 193 return; |
| 194 case Command::STOP_TRACING: | 194 case Command::STOP_TRACING: |
| 195 PerformAction(Action::SEND_EEPROM_REQUEST); | 195 PerformAction(Action::SEND_EEPROM_REQUEST); |
| 196 return; | 196 return; |
| 197 case Command::RECORD_CLOCK_SYNC_MARKER: | 197 case Command::RECORD_CLOCK_SYNC_MARKER: |
| 198 PerformAction(Action::SEND_CURRENT_SAMPLE_REQUEST); | 198 PerformAction(Action::SEND_CURRENT_SAMPLE_REQUEST); |
| 199 return; | 199 return; |
| 200 case Command::GET_FIRMWARE_GIT_HASH: | 200 case Command::GET_FIRMWARE_GIT_HASH: |
| 201 PerformAction(Action::SEND_GIT_HASH_REQUEST); | 201 PerformAction(Action::SEND_INIT); |
|
charliea (OOO until 10-5)
2017/01/12 17:05:49
I think that, before this line, you want num_init_
rnephew (Reviews Here)
2017/01/12 17:53:21
Done.
| |
| 202 return; | 202 return; |
| 203 case Command::INVALID: | 203 case Command::INVALID: |
| 204 NOTREACHED(); | 204 NOTREACHED(); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 void BattOrAgent::OnBytesSent(bool success) { | 208 void BattOrAgent::OnBytesSent(bool success) { |
| 209 DCHECK(thread_checker_.CalledOnValidThread()); | 209 DCHECK(thread_checker_.CalledOnValidThread()); |
| 210 | 210 |
| 211 // Return immediately if whatever action we were trying to perform already | 211 // Return immediately if whatever action we were trying to perform already |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 return; | 298 return; |
| 299 | 299 |
| 300 default: | 300 default: |
| 301 CompleteCommand(BATTOR_ERROR_RECEIVE_ERROR); | 301 CompleteCommand(BATTOR_ERROR_RECEIVE_ERROR); |
| 302 return; | 302 return; |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 switch (last_action_) { | 306 switch (last_action_) { |
| 307 case Action::READ_INIT_ACK: | 307 case Action::READ_INIT_ACK: |
| 308 if (command_ == Command::GET_FIRMWARE_GIT_HASH) { | |
|
charliea (OOO until 10-5)
2017/01/12 17:05:50
note that the current location of this circumvents
rnephew (Reviews Here)
2017/01/12 17:53:21
Done.
| |
| 309 PerformAction(Action::SEND_GIT_HASH_REQUEST); | |
| 310 return; | |
| 311 } | |
| 308 if (!IsAckOfControlCommand(type, BATTOR_CONTROL_MESSAGE_TYPE_INIT, | 312 if (!IsAckOfControlCommand(type, BATTOR_CONTROL_MESSAGE_TYPE_INIT, |
| 309 *bytes)) { | 313 *bytes)) { |
| 310 if (num_init_attempts_++ < kMaxInitAttempts) { | 314 if (num_init_attempts_++ < kMaxInitAttempts) { |
| 311 PerformDelayedAction(Action::SEND_INIT, | 315 PerformDelayedAction(Action::SEND_INIT, |
| 312 base::TimeDelta::FromMilliseconds(kInitRetryDelayMilliseconds)); | 316 base::TimeDelta::FromMilliseconds(kInitRetryDelayMilliseconds)); |
| 313 } else { | 317 } else { |
| 314 CompleteCommand(BATTOR_ERROR_TOO_MANY_INIT_RETRIES); | 318 CompleteCommand(BATTOR_ERROR_TOO_MANY_INIT_RETRIES); |
| 315 } | 319 } |
| 316 | 320 |
| 317 return; | 321 return; |
| 318 } | 322 } |
| 319 | 323 |
| 320 PerformAction(Action::SEND_SET_GAIN); | 324 PerformAction(Action::SEND_SET_GAIN); |
|
charliea (OOO until 10-5)
2017/01/12 17:05:49
Rather than adding an if statement, how about addi
rnephew (Reviews Here)
2017/01/12 17:53:21
Done.
| |
| 321 return; | 325 return; |
| 322 | 326 |
| 323 case Action::READ_SET_GAIN_ACK: | 327 case Action::READ_SET_GAIN_ACK: |
| 324 if (!IsAckOfControlCommand(type, BATTOR_CONTROL_MESSAGE_TYPE_SET_GAIN, | 328 if (!IsAckOfControlCommand(type, BATTOR_CONTROL_MESSAGE_TYPE_SET_GAIN, |
| 325 *bytes)) { | 329 *bytes)) { |
| 326 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); | 330 CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE); |
| 327 return; | 331 return; |
| 328 } | 332 } |
| 329 | 333 |
| 330 PerformAction(Action::SEND_START_TRACING); | 334 PerformAction(Action::SEND_START_TRACING); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 if (clock_sync_marker != clock_sync_markers_.end()) | 655 if (clock_sync_marker != clock_sync_markers_.end()) |
| 652 trace_stream << " <" << clock_sync_marker->second << ">"; | 656 trace_stream << " <" << clock_sync_marker->second << ">"; |
| 653 | 657 |
| 654 trace_stream << std::endl; | 658 trace_stream << std::endl; |
| 655 } | 659 } |
| 656 | 660 |
| 657 return trace_stream.str(); | 661 return trace_stream.str(); |
| 658 } | 662 } |
| 659 | 663 |
| 660 } // namespace battor | 664 } // namespace battor |
| OLD | NEW |