forked from Blendman974/faceclaw
Firmware 2.2.9 requires the sid-0x80 DEVICE_SETTINGS/AUTHENTICATION(4) exchange shortly after each GATT connection: it gates query responses on completing it over an encrypted link, and closes unauthenticated links after ~30 s. On a phone with no existing bond (no inherited stock-app pairing) the exchange is also what triggers SMP pairing. This is why the onboarding firmware check failed with "no response to the device-info query" on a fresh device: the probe connected, the prelude was acked, but the settings query was never answered and no pairing ever happened. (See ../notes/ble-connections-2.2.9.md, validated by g2flash on hardware.) - BleProtocol: buildAuthenticationRequest / isAuthenticationSuccess (strict: command 4, matching magic, empty result message), SID_SECURITY_AUTH. - Device-info probe: authenticates before the prelude with a 30 s window (the user may need to accept an OS pairing prompt; the check page says so). Soft on non-response since the probe also runs against the custom firmware — but a query timeout after unconfirmed auth now names the pairing problem. - Flash-prompt communicator: authenticates each arm before the prelude (mandatory — it only ever talks to stock firmware). - Firmware flasher: control-channel notifications are now mandatory, each lens authenticates before OTA BEGIN, and the OTA-time heartbeat is gone — official captures show no control traffic during a transfer, heartbeats demonstrably do not satisfy the 2.2.9 deadline, and a concurrent control writer interleaves with the marker/data transactions. The OTA envelope counter now resets after bring-up, mirroring the stock sequence. - Main communicator: authenticates both arms after connecting, before the prelude, with a short soft wait (logs and continues on timeout so firmware that never answers cannot stall reconnects). Hardware test pending: fresh-device onboarding against stock 2.2.9 (check, prompt, flash), and a regression pass on custom-firmware connect + probe. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
102 lines
3.0 KiB
TypeScript
102 lines
3.0 KiB
TypeScript
import { Utils } from "@nativescript/core";
|
|
|
|
declare const com: any;
|
|
|
|
export type DeviceInfo = {
|
|
leftVersion: string;
|
|
rightVersion: string;
|
|
capabilities: string;
|
|
};
|
|
|
|
export type DeviceInfoState = "connecting" | "authenticating" | "querying";
|
|
|
|
/**
|
|
* TS wrapper around the native FaceclawDeviceInfoProbe — a one-shot,
|
|
* stock-compatible connect + firmware/device-info read. `run()` resolves with
|
|
* the firmware versions and CFW capability string, or rejects on failure.
|
|
*/
|
|
export class DeviceInfoProbe {
|
|
private readonly probe: any;
|
|
private readonly listenerProxy: any;
|
|
private readonly logListeners = new Set<(line: string) => void>();
|
|
private readonly stateListeners = new Set<(state: DeviceInfoState, detail: string) => void>();
|
|
|
|
private settled = false;
|
|
private resolveFn: ((info: DeviceInfo) => void) | null = null;
|
|
private rejectFn: ((error: Error) => void) | null = null;
|
|
|
|
constructor(rightAddress: string) {
|
|
const context = Utils.android.getApplicationContext();
|
|
if (!context) throw new Error("Android application context unavailable");
|
|
|
|
this.probe = new com.faceclaw.app.FaceclawDeviceInfoProbe(context, rightAddress);
|
|
this.listenerProxy = new com.faceclaw.app.FaceclawDeviceInfoProbeListener({
|
|
onLog: (line: string) => this.emit(this.logListeners, String(line)),
|
|
onState: (state: string, detail: string) =>
|
|
this.emit(this.stateListeners, String(state) as DeviceInfoState, String(detail ?? "")),
|
|
onResult: (leftVersion: string, rightVersion: string, capabilities: string) =>
|
|
this.settle(null, {
|
|
leftVersion: String(leftVersion),
|
|
rightVersion: String(rightVersion),
|
|
capabilities: String(capabilities),
|
|
}),
|
|
onError: (message: string) => this.settle(new Error(String(message)), null),
|
|
});
|
|
this.probe.setListener(this.listenerProxy);
|
|
}
|
|
|
|
onLog(listener: (line: string) => void): () => void {
|
|
this.logListeners.add(listener);
|
|
return () => this.logListeners.delete(listener);
|
|
}
|
|
|
|
onStateChange(listener: (state: DeviceInfoState, detail: string) => void): () => void {
|
|
this.stateListeners.add(listener);
|
|
return () => this.stateListeners.delete(listener);
|
|
}
|
|
|
|
run(): Promise<DeviceInfo> {
|
|
return new Promise<DeviceInfo>((resolve, reject) => {
|
|
this.resolveFn = resolve;
|
|
this.rejectFn = reject;
|
|
this.probe.start();
|
|
});
|
|
}
|
|
|
|
cancel(): void {
|
|
try {
|
|
this.probe.cancel();
|
|
} catch {
|
|
// ignore
|
|
}
|
|
}
|
|
|
|
close(): void {
|
|
try {
|
|
this.probe.close();
|
|
} catch {
|
|
// ignore
|
|
}
|
|
}
|
|
|
|
private settle(error: Error | null, info: DeviceInfo | null): void {
|
|
if (this.settled) return;
|
|
this.settled = true;
|
|
this.close();
|
|
if (error) {
|
|
this.rejectFn?.(error);
|
|
} else if (info) {
|
|
this.resolveFn?.(info);
|
|
}
|
|
}
|
|
|
|
private emit<A extends unknown[]>(listeners: Set<(...args: A) => void>, ...args: A): void {
|
|
const snapshot = Array.from(listeners);
|
|
setTimeout(() => {
|
|
for (const listener of snapshot) {
|
|
listener(...args);
|
|
}
|
|
}, 0);
|
|
}
|
|
}
|