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

Unified Diff: tools/battor_agent/battor_agent.cc

Issue 2390893002: [BattOr] Make BattOr able to return firmware version. (Closed)
Patch Set: First functional version Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: tools/battor_agent/battor_agent.cc
diff --git a/tools/battor_agent/battor_agent.cc b/tools/battor_agent/battor_agent.cc
index 6fc6ea17983b09ed662e617b9906fc6c3dbc2f94..370f1d4ccad493dff62eddddbaf439b16c62b283 100644
--- a/tools/battor_agent/battor_agent.cc
+++ b/tools/battor_agent/battor_agent.cc
@@ -1,7 +1,6 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-
#include "tools/battor_agent/battor_agent.h"
#include <iomanip>
@@ -108,6 +107,14 @@ bool ParseSampleFrame(BattOrMessageType type,
return true;
}
+bool ParseGitHashFrame(BattOrMessageType type,
charliea (OOO until 10-5) 2016/10/18 23:46:29 I think it's probably okay to do this inline in On
charliea (OOO until 10-5) 2016/10/18 23:46:29 I think that, if you use an std::string, this enti
rnephew (Reviews Here) 2016/10/19 18:23:47 Done.
+ const vector<char>& msg,
+ char* git_hash){
+ if (type != BATTOR_MESSAGE_TYPE_CONTROL_ACK)
+ return false;
+ memcpy(git_hash, msg.data(), msg.size());
+ return true;
+}
} // namespace
BattOrAgent::BattOrAgent(
@@ -159,6 +166,13 @@ void BattOrAgent::RecordClockSyncMarker(const std::string& marker) {
PerformAction(Action::REQUEST_CONNECTION);
}
+void BattOrAgent::GetVersion() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ command_ = Command::GET_VERSION;
+ PerformAction(Action::REQUEST_CONNECTION);
+}
+
void BattOrAgent::BeginConnect() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -187,6 +201,9 @@ void BattOrAgent::OnConnectionOpened(bool success) {
case Command::RECORD_CLOCK_SYNC_MARKER:
PerformAction(Action::SEND_CURRENT_SAMPLE_REQUEST);
return;
+ case Command::GET_VERSION:
+ PerformAction(Action::SEND_GIT_HASH_REQUEST);
+ return;
case Command::INVALID:
NOTREACHED();
}
@@ -228,6 +245,10 @@ void BattOrAgent::OnBytesSent(bool success) {
num_read_attempts_ = 1;
PerformAction(Action::READ_CURRENT_SAMPLE);
return;
+ case Action::SEND_GIT_HASH_REQUEST:
+ num_read_attempts_ = 1;
+ PerformAction(Action::READ_GIT_HASH);
+ return;
default:
CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE);
}
@@ -244,6 +265,7 @@ void BattOrAgent::OnMessageRead(bool success,
if (!success) {
switch (last_action_) {
+ case Action::READ_GIT_HASH:
case Action::READ_EEPROM:
case Action::READ_CALIBRATION_FRAME:
case Action::READ_DATA_FRAME:
@@ -387,6 +409,21 @@ void BattOrAgent::OnMessageRead(bool success,
CompleteCommand(BATTOR_ERROR_NONE);
return;
+ case Action::READ_GIT_HASH:
+ // Get size to allocate space for git_hash_.
+ if (bytes->size() <= 0 ){
charliea (OOO until 10-5) 2016/10/18 23:46:29 Also don't think this should be necessary once we
rnephew (Reviews Here) 2016/10/19 18:23:47 Done.
+ CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE);
+ return;
+ }
+ git_hash_ = (char*) malloc(bytes->size());
+
+ if(!ParseGitHashFrame(type, *bytes, git_hash_)) {
+ CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE);
+ return;
+ }
+ CompleteCommand(BATTOR_ERROR_NONE);
+ return;
+
default:
CompleteCommand(BATTOR_ERROR_UNEXPECTED_MESSAGE);
}
@@ -473,6 +510,14 @@ void BattOrAgent::PerformAction(Action action) {
connection_->ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL_ACK);
return;
+ case Action::SEND_GIT_HASH_REQUEST:
+ SendControlMessage(BATTOR_CONTROL_MESSAGE_TYPE_GET_GIT_HASH, 0, 0);
+ return;
+
+ case Action::READ_GIT_HASH:
+ connection_->ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL_ACK);
+ return;
+
case Action::INVALID:
NOTREACHED();
}
@@ -530,6 +575,12 @@ void BattOrAgent::CompleteCommand(BattOrError error) {
FROM_HERE, base::Bind(&Listener::OnRecordClockSyncMarkerComplete,
base::Unretained(listener_), error));
break;
+ case Command::GET_VERSION:
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&Listener::OnGetVersionComplete,
+ base::Unretained(listener_),
+ git_hash_, error));
+ break;
case Command::INVALID:
NOTREACHED();
}

Powered by Google App Engine
This is Rietveld 408576698