Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: tools/battor_agent/battor_agent.cc

Issue 2618693003: Fix logic for retrying BattOr initialization after a timeout (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #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"
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 538
539 void BattOrAgent::OnActionTimeout() { 539 void BattOrAgent::OnActionTimeout() {
540 switch (last_action_) { 540 switch (last_action_) {
541 case Action::READ_INIT_ACK: 541 case Action::READ_INIT_ACK:
542 if (num_init_attempts_++ < kMaxInitAttempts) { 542 if (num_init_attempts_++ < kMaxInitAttempts) {
543 // OnMessageRead() will fail and retry SEND_INIT. 543 // OnMessageRead() will fail and retry SEND_INIT.
544 connection_->CancelReadMessage(); 544 connection_->CancelReadMessage();
545 } else { 545 } else {
546 CompleteCommand(BATTOR_ERROR_TOO_MANY_INIT_RETRIES); 546 CompleteCommand(BATTOR_ERROR_TOO_MANY_INIT_RETRIES);
547 } 547 }
548
549 return; 548 return;
550 549
551 // TODO(crbug.com/672631): There's currently a BattOr firmware bug that's 550 // TODO(crbug.com/672631): There's currently a BattOr firmware bug that's
552 // causing the BattOr to reset when it's sent the START_TRACING command. 551 // causing the BattOr to reset when it's sent the START_TRACING command.
553 // When the BattOr resets, it emits 0x00 to the serial connection. This 0x00 552 // When the BattOr resets, it emits 0x00 to the serial connection. This 0x00
554 // isn't long enough for the connection to consider it a full ack of the 553 // isn't long enough for the connection to consider it a full ack of the
555 // START_TRACING command, so it continues to wait for more data. We handle 554 // START_TRACING command, so it continues to wait for more data. We handle
556 // this case here by assuming any timeouts while waiting for the 555 // this case here by assuming any timeouts while waiting for the
557 // StartTracing ack are related to this bug and retrying the full 556 // StartTracing ack are related to this bug and retrying the full
558 // initialization sequence. 557 // initialization sequence.
559 case Action::READ_START_TRACING_ACK: 558 case Action::READ_START_TRACING_ACK:
560 if (num_start_tracing_attempts_ < kMaxStartTracingAttempts) { 559 if (num_start_tracing_attempts_ < kMaxStartTracingAttempts) {
561 // OnMessageRead() will fail and retry StartTracing. 560 // OnMessageRead() will fail and retry StartTracing.
562 connection_->CancelReadMessage(); 561 connection_->CancelReadMessage();
563 } else { 562 } else {
564 CompleteCommand(BATTOR_ERROR_TOO_MANY_START_TRACING_RETRIES); 563 CompleteCommand(BATTOR_ERROR_TOO_MANY_START_TRACING_RETRIES);
565 } 564 }
565 return;
566 566
567 default: 567 default:
568 CompleteCommand(BATTOR_ERROR_TIMEOUT); 568 CompleteCommand(BATTOR_ERROR_TIMEOUT);
569 timeout_callback_.Cancel();
569 } 570 }
570
571 timeout_callback_.Cancel();
572 } 571 }
573 572
574 void BattOrAgent::SendControlMessage(BattOrControlMessageType type, 573 void BattOrAgent::SendControlMessage(BattOrControlMessageType type,
575 uint16_t param1, 574 uint16_t param1,
576 uint16_t param2) { 575 uint16_t param2) {
577 DCHECK(thread_checker_.CalledOnValidThread()); 576 DCHECK(thread_checker_.CalledOnValidThread());
578 577
579 BattOrControlMessage msg{type, param1, param2}; 578 BattOrControlMessage msg{type, param1, param2};
580 connection_->SendBytes(BATTOR_MESSAGE_TYPE_CONTROL, &msg, sizeof(msg)); 579 connection_->SendBytes(BATTOR_MESSAGE_TYPE_CONTROL, &msg, sizeof(msg));
581 } 580 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 if (clock_sync_marker != clock_sync_markers_.end()) 650 if (clock_sync_marker != clock_sync_markers_.end())
652 trace_stream << " <" << clock_sync_marker->second << ">"; 651 trace_stream << " <" << clock_sync_marker->second << ">";
653 652
654 trace_stream << std::endl; 653 trace_stream << std::endl;
655 } 654 }
656 655
657 return trace_stream.str(); 656 return trace_stream.str();
658 } 657 }
659 658
660 } // namespace battor 659 } // namespace battor
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698