Move Quest access ownership to Muninn
This commit is contained in:
parent
09d0d3ad2e
commit
c1178512c4
9 changed files with 36 additions and 276 deletions
|
|
@ -127,13 +127,6 @@ if (args.Any(arg => string.Equals(arg, "--move-calibration-protocol-smoke", Stri
|
|||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (args.Any(arg => string.Equals(arg, "--quest-usb-preflight-smoke", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return await RunQuestUsbPreflightSmokeAsync(
|
||||
ParseStringOption(args, "--output", "artifacts/move-calibration/quest-usb-preflight.cc"))
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (args.Any(arg => string.Equals(arg, "--import-obs-program-scene", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return await ImportObsProgramSceneAsync(
|
||||
|
|
@ -1918,172 +1911,6 @@ static async Task<int> RunMoveCalibrationProtocolSmokeAsync(string outputPath)
|
|||
: 1;
|
||||
}
|
||||
|
||||
static async Task<int> RunQuestUsbPreflightSmokeAsync(string outputPath)
|
||||
{
|
||||
var devices = await RunProcessCaptureAsync("adb", ["devices", "-l"]).ConfigureAwait(false);
|
||||
if (devices.ExitCode != 0)
|
||||
{
|
||||
Console.Error.WriteLine($"quest-usb-preflight-smoke failed: adb devices exited {devices.ExitCode}: {devices.Stderr.Trim()}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
var quest = FindAuthorizedQuestDevice(devices.Stdout);
|
||||
if (quest is null)
|
||||
{
|
||||
Console.Error.WriteLine("quest-usb-preflight-smoke failed: no authorized Quest device found in adb devices -l");
|
||||
Console.Error.WriteLine(devices.Stdout.Trim());
|
||||
return 1;
|
||||
}
|
||||
|
||||
var serial = quest.Value.Serial;
|
||||
var fields = quest.Value.Fields;
|
||||
var product = fields.GetValueOrDefault("product", "");
|
||||
var model = fields.GetValueOrDefault("model", "");
|
||||
var device = fields.GetValueOrDefault("device", "");
|
||||
var transportId = fields.GetValueOrDefault("transport_id", "");
|
||||
var androidRelease = await GetAdbPropertyAsync(serial, "ro.build.version.release").ConfigureAwait(false);
|
||||
var androidSdk = await GetAdbPropertyAsync(serial, "ro.build.version.sdk").ConfigureAwait(false);
|
||||
var buildFingerprint = await GetAdbPropertyAsync(serial, "ro.build.fingerprint").ConfigureAwait(false);
|
||||
var batterySummary = await GetAdbBatterySummaryAsync(serial).ConfigureAwait(false);
|
||||
var document = MimirQuestUsbPreflight.Create(
|
||||
serial,
|
||||
"device",
|
||||
product,
|
||||
model,
|
||||
device,
|
||||
transportId,
|
||||
androidRelease,
|
||||
androidSdk,
|
||||
buildFingerprint,
|
||||
batterySummary);
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(outputPath)) ?? ".");
|
||||
using var cache = await CultCacheMessagePack.OpenAsync(outputPath, new CultCacheOpenOptions
|
||||
{
|
||||
PullOnOpen = File.Exists(outputPath)
|
||||
}).ConfigureAwait(false);
|
||||
await cache.UpsertAsync(
|
||||
document,
|
||||
new CultRecordHandle<MimirQuestUsbPreflightDocument>(new CultRecordKey($"mimir-quest-usb-preflight:{document.Serial}")))
|
||||
.ConfigureAwait(false);
|
||||
await cache.FlushAsync().ConfigureAwait(false);
|
||||
|
||||
Console.WriteLine(
|
||||
$"quest-usb-preflight-smoke path={outputPath} serial={document.Serial} model={document.Model} product={document.Product} android={document.AndroidRelease} sdk={document.AndroidSdk} pose={document.PoseCaptureStatus}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static (string Serial, Dictionary<string, string> Fields)? FindAuthorizedQuestDevice(string adbDevicesOutput)
|
||||
{
|
||||
foreach (var rawLine in adbDevicesOutput.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var tokens = rawLine.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (tokens.Length < 2 || tokens[0] == "List" || !string.Equals(tokens[1], "device", StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var fields = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var token in tokens.Skip(2))
|
||||
{
|
||||
var split = token.IndexOf(':');
|
||||
if (split > 0 && split < token.Length - 1)
|
||||
{
|
||||
fields[token[..split]] = token[(split + 1)..];
|
||||
}
|
||||
}
|
||||
|
||||
var model = fields.GetValueOrDefault("model", "");
|
||||
var product = fields.GetValueOrDefault("product", "");
|
||||
if (model.Contains("Quest", StringComparison.OrdinalIgnoreCase) ||
|
||||
product.Contains("hollywood", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return (tokens[0], fields);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static async Task<string> GetAdbPropertyAsync(string serial, string property)
|
||||
{
|
||||
var result = await RunProcessCaptureAsync("adb", ["-s", serial, "shell", "getprop", property], 5_000).ConfigureAwait(false);
|
||||
return result.ExitCode == 0 ? result.Stdout.Trim() : "";
|
||||
}
|
||||
|
||||
static async Task<string> GetAdbBatterySummaryAsync(string serial)
|
||||
{
|
||||
var result = await RunProcessCaptureAsync("adb", ["-s", serial, "shell", "dumpsys", "battery"], 5_000).ConfigureAwait(false);
|
||||
if (result.ExitCode != 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
var usefulLines = result.Stdout.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(line => line.Trim())
|
||||
.Where(line =>
|
||||
line.StartsWith("AC powered:", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.StartsWith("USB powered:", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.StartsWith("Wireless powered:", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.StartsWith("status:", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.StartsWith("level:", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.StartsWith("scale:", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.StartsWith("voltage:", StringComparison.OrdinalIgnoreCase) ||
|
||||
line.StartsWith("temperature:", StringComparison.OrdinalIgnoreCase))
|
||||
.Take(12);
|
||||
return string.Join(" | ", usefulLines);
|
||||
}
|
||||
|
||||
static async Task<(int ExitCode, string Stdout, string Stderr)> RunProcessCaptureAsync(
|
||||
string fileName,
|
||||
IReadOnlyList<string> arguments,
|
||||
int timeoutMilliseconds = 10_000)
|
||||
{
|
||||
using var process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo(fileName)
|
||||
{
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
|
||||
foreach (var argument in arguments)
|
||||
{
|
||||
process.StartInfo.ArgumentList.Add(argument);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!process.Start())
|
||||
{
|
||||
return (-1, "", $"could not start {fileName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is InvalidOperationException or System.ComponentModel.Win32Exception)
|
||||
{
|
||||
return (-1, "", $"could not start {fileName}: {ex.Message}");
|
||||
}
|
||||
|
||||
var stdoutTask = process.StandardOutput.ReadToEndAsync();
|
||||
var stderrTask = process.StandardError.ReadToEndAsync();
|
||||
var waitTask = process.WaitForExitAsync();
|
||||
var completed = await Task.WhenAny(waitTask, Task.Delay(timeoutMilliseconds)).ConfigureAwait(false);
|
||||
if (completed != waitTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
process.Kill(entireProcessTree: true);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
}
|
||||
|
||||
return (-1, await stdoutTask.ConfigureAwait(false), $"timed out after {timeoutMilliseconds} ms");
|
||||
}
|
||||
|
||||
return (process.ExitCode, await stdoutTask.ConfigureAwait(false), await stderrTask.ConfigureAwait(false));
|
||||
}
|
||||
|
||||
static MoveTrackingSmokeContext BuildMoveTrackingSmokeHub()
|
||||
{
|
||||
var starfireDescriptor = new MimirStreamDescriptor(
|
||||
|
|
|
|||
Loading…
Reference in a new issue