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

Unified Diff: tools/battor_agent/battor_finder.cc

Issue 1631313002: tools/battor_agent: Adds a tool to find connected BattOrs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/battor_agent/battor_finder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/battor_agent/battor_finder.cc
diff --git a/tools/battor_agent/battor_finder.cc b/tools/battor_agent/battor_finder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b0e32db1ee9b0f27dec6f912befd1d157f0ec583
--- /dev/null
+++ b/tools/battor_agent/battor_finder.cc
@@ -0,0 +1,39 @@
+// Copyright 2016 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_finder.h"
+
+#include "device/serial/serial.mojom.h"
+#include "device/serial/serial_device_enumerator.h"
+#include "mojo/public/cpp/bindings/array.h"
+
+namespace battor {
+
+namespace {
+
+// The USB display name prefix that all BattOrs have.
+const char kBattOrDisplayNamePrefix[] = "BattOr";
+
+} // namespace
+
+// Returns the path of the first BattOr that we find.
+std::string BattOrFinder::FindBattOr() {
+ scoped_ptr<device::SerialDeviceEnumerator> serial_device_enumerator =
+ device::SerialDeviceEnumerator::Create();
+
+ mojo::Array<device::serial::DeviceInfoPtr> devices =
+ serial_device_enumerator->GetDevices();
+
+ for (size_t i = 0; i < devices.size(); i++) {
+ std::string display_name = devices[i]->display_name.get();
+
+ if (display_name.find(kBattOrDisplayNamePrefix) != std::string::npos) {
+ return devices[i]->path;
+ }
+ }
+
+ return std::string();
+}
+
+} // namespace battor
« no previous file with comments | « tools/battor_agent/battor_finder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698