Make BLE benchmark work on iOS

This commit is contained in:
James Babcock committed 2026-10-26 11:12:55 -07:00
1 parent 50c608c26b
commit 8e50c004a6
4 files changed
+74 -3

No files matched your search

+7 -3
View File
@@ -14,6 +14,9 @@ import {
const MESSAGE_SIZES = [250, 500, 1000, 2000, 3800];
const WINDOW_SIZES = [1, 2, 3, 4, 6];
const LINK_MODES = ["Current", "Request HIGH", "Request 2M", "HIGH + 2M"];
// CoreBluetooth has no connection-priority or PHY request API (iOS's
// prepareBenchmarkLink is a no-op), so iOS always runs on the current link.
const LINK_REQUESTS_SUPPORTED = !global.isIOS;
const DURATION_MS = 15_000;
// After painting the "running" screen, wait for that frame to reach the
// glasses before the benchmark blocks normal image sends — otherwise the
@@ -40,7 +43,7 @@ type ConfigRow = "size" | "window" | "link" | "start";
export class BandwidthBenchmarkLayer implements Layer {
private phase: Phase = "config";
private readonly menu = new Menu<ConfigRow>({
items: ["size", "window", "link", "start"],
items: LINK_REQUESTS_SUPPORTED ? ["size", "window", "link", "start"] : ["size", "window", "start"],
wrap: false,
rowGap: 1,
highlight: { radius: 4 },
@@ -134,7 +137,8 @@ export class BandwidthBenchmarkLayer implements Layer {
font,
LIST_X,
HEADER_HEIGHT + 30,
`${MESSAGE_SIZES[this.sizeIndex]} B, window ${WINDOW_SIZES[this.windowIndex]}, ${LINK_MODES[this.linkModeIndex]}`,
`${MESSAGE_SIZES[this.sizeIndex]} B, window ${WINDOW_SIZES[this.windowIndex]}`
+ (LINK_REQUESTS_SUPPORTED ? `, ${LINK_MODES[this.linkModeIndex]}` : ""),
150,
);
image.drawText(font, LIST_X, HEADER_HEIGHT + 52, "Display updates pause until the run finishes.", 110);
@@ -161,8 +165,8 @@ export class BandwidthBenchmarkLayer implements Layer {
`Throughput: ${(payloadRate / 1024).toFixed(2)} KB/s payload (${(wireRate / 1024).toFixed(2)} KB/s wire)`,
`Messages: ${r.messagesAcked}/${r.messagesSent} acked, ${r.timeouts} timeouts`,
`Elapsed: ${seconds.toFixed(1)} s` + (r.aborted ? " (aborted early)" : ""),
`Link request: ${LINK_MODES[r.linkMode] ?? "Current"}`,
];
if (LINK_REQUESTS_SUPPORTED) lines.push(`Link request: ${LINK_MODES[r.linkMode] ?? "Current"}`);
for (const line of lines) {
image.drawText(font, LIST_X, y, line, 190);
y += 20;
+3
View File
@@ -14,6 +14,7 @@ import { registerNavigateTools } from '../assistant/navigate-tools'
import { registerRoamTools } from '../assistant/roam-tools'
import { IosNavigationSensors } from '../native/ios-navigation-sensors'
import { bindCompassSession, receiveCompassEvent } from '../native/compass.ios'
import { bindBandwidthBenchmarkSession } from '../native/bandwidth-benchmark.ios'
import { Dialogs, File, knownFolders, path, Utils, type ImageSource } from '@nativescript/core'
import { iosVoiceInput } from '../native/ios-voice-input'
import { voiceActivity } from '../ui/shell/voice-activity'
@@ -832,6 +833,7 @@ export class IosPreviewController {
this.notifications = notifications
bindIosNotifications(notifications)
bindCompassSession(communicator)
bindBandwidthBenchmarkSession(communicator)
communicator.setRequiresAncs(true)
this.sessionOffs.push(
communicator.onStateChange(state => this.handleSessionState(communicator, state)),
@@ -974,6 +976,7 @@ export class IosPreviewController {
for (const off of this.sessionOffs.splice(0)) off()
this.notifications = null
this.communicator = null
bindBandwidthBenchmarkSession(null)
// Releases an EvenHub app's mic before the session closes.
this.syncRawMicSession()
this.glance.reset()
+49
View File
@@ -0,0 +1,49 @@
import type { BandwidthBenchmarkStatus } from './bandwidth-benchmark'
export type { BandwidthBenchmarkStatus } from './bandwidth-benchmark'
// The iOS twin of the Android benchmark bridge. iOS has no static active
// communicator, so the preview controller binds its session here on connect
// and unbinds it on close; the run itself is the same shared-Kotlin
// GlassesSessionCore stream as on Android.
type BenchmarkSession = {
startBandwidthBenchmark(messageSize: number, windowSize: number, durationMs: number, linkMode: number): boolean
cancelBandwidthBenchmark(): void
getBandwidthBenchmarkStatus(): string
}
let session: BenchmarkSession | null = null
export function bindBandwidthBenchmarkSession(next: BenchmarkSession | null): void {
session = next
}
/** Start a run. False if not connected or a run is already active. */
export function startBandwidthBenchmark(messageSize: number, windowSize: number, durationMs: number, linkMode = 0): boolean {
if (!session) return false
try {
return session.startBandwidthBenchmark(
Math.round(messageSize), Math.round(windowSize), Math.round(durationMs), Math.round(linkMode))
} catch (error) {
console.warn(`startBandwidthBenchmark failed: ${error}`)
return false
}
}
/** Cancel an in-progress run. Safe to call when idle. */
export function cancelBandwidthBenchmark(): void {
try {
session?.cancelBandwidthBenchmark()
} catch (error) {
console.warn(`cancelBandwidthBenchmark failed: ${error}`)
}
}
/** Status of the current or most recent run; null when not connected. */
export function getBandwidthBenchmarkStatus(): BandwidthBenchmarkStatus | null {
if (!session) return null
try {
return JSON.parse(session.getBandwidthBenchmarkStatus()) as BandwidthBenchmarkStatus
} catch (error) {
console.warn(`getBandwidthBenchmarkStatus failed: ${error}`)
return null
}
}
+15
View File
@@ -663,6 +663,21 @@ export class FaceclawCommunicatorBridge {
return () => { this.communicator.removeCompassListenerListener(proxy); };
}
/** Developer > Debug tests > BLE bandwidth; see app/native/bandwidth-benchmark.ios.ts. */
startBandwidthBenchmark(messageSize: number, windowSize: number, durationMs: number, linkMode: number): boolean {
return Boolean(this.communicator.startBandwidthBenchmarkWithLinkModeMessageSizeWindowSizeDurationMsLinkMode(
messageSize, windowSize, durationMs, linkMode));
}
cancelBandwidthBenchmark(): void {
this.communicator.cancelBandwidthBenchmark();
}
/** Status/results of the current or most recent run, as JSON. */
getBandwidthBenchmarkStatus(): string {
return String(this.communicator.getBandwidthBenchmarkStatus());
}
/**
* Serialized glasses microphone enable/disable (the voice bridge's
* IosMicrophoneSession contract). A release while an enable awaits its ACK