forked from Blendman974/faceclaw
Merge branch 'main' of https://github.com/jimrandomh/faceclaw into android-wear-integration
# Conflicts: # app/phone-ui/main-page.xml # app/phone-ui/main-view-model.ts
This commit is contained in:
commit
646335cb64
63 files changed
+1296
-621
No files matched your search
+20
-49
@@ -13,8 +13,11 @@
|
||||
*
|
||||
* `txPower` is the expected signal at one metre and `n` the path loss
|
||||
* exponent — 2.0 in free space, higher indoors where walls and bodies absorb.
|
||||
* A device that advertises its own TX power gets used as measured; everything
|
||||
* else falls back to a per-product calibration.
|
||||
* The reference power always comes from the per-product calibration table. An
|
||||
* advertised BLE "TX Power Level" is deliberately NOT used: that field is the
|
||||
* radiated power at the antenna (typically 0…+4 dBm), not an iBeacon-style
|
||||
* measured power at one metre, and reading it as the latter inflates every
|
||||
* distance by orders of magnitude.
|
||||
*
|
||||
* ## What this is for, and what it is not
|
||||
*
|
||||
@@ -25,14 +28,15 @@
|
||||
* absolute numbers metres out.
|
||||
*
|
||||
* It is **not** a measurement. A hand over the temple, a pocket, or a body
|
||||
* between phone and glasses moves the estimate by metres. Every user-facing
|
||||
* number is therefore rounded hard, prefixed with "~" when confidence is low,
|
||||
* and paired with a coarse zone rather than being presented as a distance the
|
||||
* wearer could act on precisely.
|
||||
* between phone and glasses moves the estimate by metres. The wearer therefore
|
||||
* only ever sees a coarse zone (glyph + label), never a number in metres they
|
||||
* might over-trust; the metres value exists purely to rank and bucket.
|
||||
*
|
||||
* This module is pure (no NativeScript imports) so it can run under node tests.
|
||||
*/
|
||||
|
||||
import { clamp } from "../util/numeric-util";
|
||||
|
||||
/** Expected RSSI at one metre, and the path loss exponent, per product. */
|
||||
export type ProximityCalibration = {
|
||||
readonly txPowerAtOneMeter: number;
|
||||
@@ -66,8 +70,6 @@ export const MAXIMUM_METERS = 100;
|
||||
*/
|
||||
export type ProximityZone = "immediate" | "near" | "far" | "distant";
|
||||
|
||||
const ZONE_ORDER: Record<ProximityZone, number> = { immediate: 0, near: 1, far: 2, distant: 3 };
|
||||
|
||||
export function zoneFromMeters(meters: number): ProximityZone {
|
||||
if (meters < 0.5) return "immediate";
|
||||
if (meters < 3) return "near";
|
||||
@@ -75,10 +77,6 @@ export function zoneFromMeters(meters: number): ProximityZone {
|
||||
return "distant";
|
||||
}
|
||||
|
||||
export function zoneRank(zone: ProximityZone): number {
|
||||
return ZONE_ORDER[zone];
|
||||
}
|
||||
|
||||
export function zoneLabel(zone: ProximityZone): string {
|
||||
switch (zone) {
|
||||
case "immediate":
|
||||
@@ -109,64 +107,37 @@ export function zoneGlyph(zone: ProximityZone): string {
|
||||
/** A distance estimate and how much to trust it. */
|
||||
export type ProximityEstimate = {
|
||||
readonly meters: number;
|
||||
/** 0…1. Drops with weak signal and with having to guess the TX power. */
|
||||
/** 0…1. Drops with weak signal. */
|
||||
readonly confidence: number;
|
||||
readonly zone: ProximityZone;
|
||||
};
|
||||
|
||||
/** "0.4 m", "~3 m". The tilde marks an estimate the reader should not lean on. */
|
||||
export function formatDistance(estimate: ProximityEstimate): string {
|
||||
const prefix = estimate.confidence < 0.6 ? "~" : "";
|
||||
const meters = estimate.meters;
|
||||
if (meters < 1) {
|
||||
return `${prefix}${Math.round(meters * 100)} cm`;
|
||||
}
|
||||
if (meters < 10) {
|
||||
return `${prefix}${meters.toFixed(1)} m`;
|
||||
}
|
||||
if (meters < MAXIMUM_METERS) {
|
||||
return `${prefix}${Math.round(meters)} m`;
|
||||
}
|
||||
return `${prefix}>${MAXIMUM_METERS} m`;
|
||||
}
|
||||
|
||||
/** "In your hand · 0.3 m" — zone first, because the zone is the trustworthy half. */
|
||||
export function proximitySummary(estimate: ProximityEstimate): string {
|
||||
return `${zoneLabel(estimate.zone)} · ${formatDistance(estimate)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate distance from a signal sample. Null when there is no RSSI to work
|
||||
* from, so callers can say "signal unknown" rather than render a fabricated
|
||||
* distance. 127 is the Bluetooth "RSSI unavailable" sentinel.
|
||||
*/
|
||||
export function estimateProximity(
|
||||
rssi: number | null | undefined,
|
||||
txPower: number | null | undefined,
|
||||
calibration: ProximityCalibration,
|
||||
): ProximityEstimate | null {
|
||||
export function estimateProximity(rssi: number | null | undefined, calibration: ProximityCalibration): ProximityEstimate | null {
|
||||
if (rssi == null || !Number.isFinite(rssi) || rssi === 127) return null;
|
||||
const hasTxPower = txPower != null && Number.isFinite(txPower);
|
||||
const referencePower = hasTxPower ? txPower! : calibration.txPowerAtOneMeter;
|
||||
const ratio = (referencePower - rssi) / (10 * calibration.pathLossExponent);
|
||||
const meters = Math.min(Math.max(Math.pow(10, ratio), MINIMUM_METERS), MAXIMUM_METERS);
|
||||
const ratio = (calibration.txPowerAtOneMeter - rssi) / (10 * calibration.pathLossExponent);
|
||||
const meters = clamp(Math.pow(10, ratio), MINIMUM_METERS, MAXIMUM_METERS);
|
||||
return {
|
||||
meters,
|
||||
confidence: proximityConfidence(rssi, hasTxPower),
|
||||
confidence: proximityConfidence(rssi),
|
||||
zone: zoneFromMeters(meters),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Confidence falls with signal strength, because a weak sample is a noisy one,
|
||||
* and with having to assume the TX power instead of being told it.
|
||||
* Confidence falls with signal strength, because a weak sample is a noisy one.
|
||||
* The 0.85 ceiling reflects that the TX power is always an assumption from the
|
||||
* calibration table, never a measurement.
|
||||
*/
|
||||
export function proximityConfidence(rssi: number, hasAdvertisedTxPower: boolean): number {
|
||||
let confidence = 1.0;
|
||||
export function proximityConfidence(rssi: number): number {
|
||||
let confidence = 0.85;
|
||||
if (rssi < -85) confidence *= 0.4;
|
||||
else if (rssi < -75) confidence *= 0.7;
|
||||
else if (rssi < -65) confidence *= 0.85;
|
||||
confidence *= hasAdvertisedTxPower ? 1.0 : 0.85;
|
||||
return confidence;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging"
|
||||
export type DashboardSnapshot = {
|
||||
phase: ConnectionPhase;
|
||||
status: string;
|
||||
log: string;
|
||||
displayPreview: ImageSource | null;
|
||||
/**
|
||||
* When non-empty, the phone UI shows this instead of the display preview:
|
||||
@@ -181,7 +180,6 @@ function sourceName(eventSource: number): string {
|
||||
class DashboardController {
|
||||
private phase: ConnectionPhase = "disconnected";
|
||||
private status = "Disconnected.";
|
||||
private log = "";
|
||||
private activeTextSettings: ConfigSettingString[] = [];
|
||||
private activeTextEditorTitle = "";
|
||||
private activeTextEditorOnFinish: (() => void) | null = null;
|
||||
@@ -257,6 +255,7 @@ class DashboardController {
|
||||
// underneath it, so it waits for this to clear.
|
||||
private connectRunning = false;
|
||||
private incompatibleDisconnectPending = false;
|
||||
private unpairedDisconnectPending = false;
|
||||
|
||||
constructor() {
|
||||
const sharedActions = {
|
||||
@@ -822,7 +821,6 @@ class DashboardController {
|
||||
return {
|
||||
phase: this.phase,
|
||||
status: this.status,
|
||||
log: this.log,
|
||||
displayPreview: this.displayPreview,
|
||||
displayPreviewMessage: this.displayPreviewMessage(),
|
||||
activeTextSettingId: primaryTextSetting?.id ?? null,
|
||||
@@ -941,7 +939,6 @@ class DashboardController {
|
||||
this.appendLog(`error: ${message}`);
|
||||
throw new Error(message);
|
||||
}
|
||||
this.log = "";
|
||||
this.lastInput = "waiting...";
|
||||
this.lastSys = "none yet";
|
||||
this.welcomeSoundArmed = isWelcomeSoundPending();
|
||||
@@ -977,6 +974,14 @@ class DashboardController {
|
||||
this.appendLog(line);
|
||||
});
|
||||
this.offState = communicator.onStateChange((state) => {
|
||||
if (state.phase === "unpaired") {
|
||||
// Java parked its retry loop: an arm's Android bond is gone, so
|
||||
// every redial would fail the same way until the user re-pairs.
|
||||
// Tear down into the manual-disconnected state and keep the
|
||||
// re-pair instruction as the visible status.
|
||||
this.scheduleUnpairedDisconnect(state.status);
|
||||
return;
|
||||
}
|
||||
const mappedPhase =
|
||||
state.phase === "connected"
|
||||
? "connected"
|
||||
@@ -1243,6 +1248,40 @@ class DashboardController {
|
||||
setTimeout(attempt, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* A connect attempt found an arm whose Android bond is missing, so the Java
|
||||
* worker stopped retrying. Drop into the manual-disconnected state (no
|
||||
* auto-reconnect: it would just fail again) and leave the re-pair
|
||||
* instruction from Java as the status the user sees.
|
||||
*/
|
||||
private scheduleUnpairedDisconnect(message: string): void {
|
||||
if (this.unpairedDisconnectPending) return;
|
||||
this.unpairedDisconnectPending = true;
|
||||
const attempt = () => {
|
||||
// The unpaired report can arrive while connect() is still mid-flight;
|
||||
// let it finish so the teardown doesn't race its surface setup.
|
||||
if (this.connectRunning) {
|
||||
setTimeout(attempt, 200);
|
||||
return;
|
||||
}
|
||||
this.unpairedDisconnectPending = false;
|
||||
if (this.phase === "disconnected" || this.phase === "disconnecting") {
|
||||
// The session ended some other way; still stop auto-reconnect from
|
||||
// re-dialing glasses that are no longer paired.
|
||||
suppressAutoReconnect();
|
||||
this.setStatus(message);
|
||||
return;
|
||||
}
|
||||
this.appendLog(`Disconnecting: ${message} Auto-reconnect is disabled until you connect manually.`);
|
||||
void this.disconnect({ skipFirmwareCleanup: true })
|
||||
.then(() => this.setStatus(message))
|
||||
.catch((error) => {
|
||||
this.appendLog(`unpaired disconnect failed: ${this.formatError(error)}`);
|
||||
});
|
||||
};
|
||||
setTimeout(attempt, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down the connection and enter the manual-disconnected state: every
|
||||
* caller is deliberate (the phone/glasses Disconnect actions, entering the
|
||||
@@ -1254,6 +1293,14 @@ class DashboardController {
|
||||
*/
|
||||
async disconnect(options?: { skipFirmwareCleanup?: boolean }): Promise<void> {
|
||||
suppressAutoReconnect();
|
||||
// The phone menu offers Disconnect during the connecting phase (it is the
|
||||
// only way out of a reconnection-attempt loop), so a call can land while
|
||||
// connect() is still mid-flight; let it finish so the teardown doesn't
|
||||
// race its surface setup. connect() returns once the Java worker thread
|
||||
// owns the retry loop, so this wait is short.
|
||||
while (this.connectRunning) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
}
|
||||
if (this.phase === "disconnected" || this.phase === "disconnecting") return;
|
||||
|
||||
this.setPhase("disconnecting");
|
||||
@@ -2078,10 +2125,7 @@ class DashboardController {
|
||||
}
|
||||
|
||||
private appendLog(line: string): void {
|
||||
const stamped = `[${formatTimestamp(new Date())}] ${line}`;
|
||||
//this.log = this.log ? `${this.log}\n${stamped}` : stamped;
|
||||
console.log(stamped);
|
||||
//this.emit();
|
||||
console.log(`[${formatTimestamp(new Date())}] ${line}`);
|
||||
}
|
||||
|
||||
private setDisplayPreview(preview: ImageSource | null): void {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { ApplicationSettings } from "@nativescript/core";
|
||||
|
||||
import { normalizeMacAddress } from "./even-advertisement";
|
||||
|
||||
export { normalizeMacAddress };
|
||||
|
||||
export type DeviceAddresses = {
|
||||
right: string;
|
||||
left: string;
|
||||
@@ -32,17 +36,6 @@ export function saveDeviceAddresses(addresses: DeviceAddresses): void {
|
||||
ApplicationSettings.setString(ADDRESS_KEYS.ring, normalizeMacAddress(addresses.ring));
|
||||
}
|
||||
|
||||
export function normalizeMacAddress(value: string | null | undefined): string {
|
||||
const compact = (value ?? "")
|
||||
.trim()
|
||||
.replace(/[^0-9a-fA-F]/g, "")
|
||||
.toUpperCase();
|
||||
if (compact.length !== 12) {
|
||||
return (value ?? "").trim().toUpperCase();
|
||||
}
|
||||
return compact.match(/.{1,2}/g)?.join(":") ?? compact;
|
||||
}
|
||||
|
||||
export function isValidMacAddress(value: string, allowEmpty = false): boolean {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) {
|
||||
|
||||
@@ -27,28 +27,15 @@
|
||||
* This module is pure (no NativeScript imports) so it can run under node tests.
|
||||
*/
|
||||
|
||||
import { bytesToHex, hexToBytes } from "../util/hex-util";
|
||||
|
||||
export { bytesToHex, hexToBytes };
|
||||
|
||||
/** Even Realities' manufacturer-data company identifier (`"ER"` read little-endian). */
|
||||
export const EVEN_COMPANY_IDENTIFIER = 0x5245;
|
||||
|
||||
export type EvenDeviceRole = "left" | "right" | "ring";
|
||||
|
||||
export function hexToBytes(hex: string | null | undefined): Uint8Array {
|
||||
const clean = (hex ?? "").replace(/[^0-9a-fA-F]/g, "");
|
||||
const out = new Uint8Array(Math.floor(clean.length / 2));
|
||||
for (let i = 0; i < out.length; i++) {
|
||||
out[i] = parseInt(clean.substr(i * 2, 2), 16);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function bytesToHex(bytes: ArrayLike<number>): string {
|
||||
let out = "";
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
out += (bytes[i]! & 0xff).toString(16).padStart(2, "0").toUpperCase();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** True when the manufacturer data opens with Even's `"ER"` marker. */
|
||||
export function hasEvenManufacturerSignature(mfg: Uint8Array): boolean {
|
||||
return mfg.length >= 2 && mfg[0] === 0x45 && mfg[1] === 0x52;
|
||||
@@ -136,7 +123,7 @@ export function ringNameAddressOctets(name: string | null | undefined): number[]
|
||||
const marker = name.indexOf("R1_");
|
||||
const suffix = (marker >= 0 ? name.slice(marker + 3) : name).trim();
|
||||
if (suffix.length !== 6 || !/^[0-9a-fA-F]{6}$/.test(suffix)) return null;
|
||||
return [0, 2, 4].map((i) => parseInt(suffix.substr(i, 2), 16));
|
||||
return [0, 2, 4].map((i) => parseInt(suffix.slice(i, i + 2), 16));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,20 +220,25 @@ export type EvenAdvertisement = {
|
||||
* Classify a raw advertisement. Returns null for anything that is not an Even
|
||||
* Realities G2 temple or R1 ring. Admission mirrors the SDK: stock names
|
||||
* contain "G2"/"R1", but renamed firmware may not, so the "ER" manufacturer
|
||||
* signature is an equally strong admission path.
|
||||
* signature is an equally strong admission path. The ring check is anchored to
|
||||
* the stock "EVEN R1…" prefix — a bare `R1` substring also matches unrelated
|
||||
* hardware ("Oppo Enco R1"), and every ring row is selectable, so a loose
|
||||
* match here saves a stranger's earbuds as the ring. Keep this in sync with
|
||||
* the Java pre-filter (FaceclawDeviceDiscovery.isAdmissible), which must stay
|
||||
* a superset of it.
|
||||
*/
|
||||
export function classifyAdvertisement(raw: RawAdvertisement): EvenAdvertisement | null {
|
||||
const mfg = hexToBytes(raw.manufacturerData);
|
||||
const name = raw.name ?? "";
|
||||
const upper = name.toUpperCase();
|
||||
const hasSignature = hasEvenManufacturerSignature(mfg);
|
||||
const looksLikeRing = /\bR1\b|EVEN R1|R1_/.test(upper);
|
||||
const looksLikeRing = /^EVEN R1([_ ]|$)/.test(upper);
|
||||
const looksLikeG2 = upper.includes("G2");
|
||||
|
||||
if (!looksLikeRing && !looksLikeG2 && !hasSignature) return null;
|
||||
|
||||
const base = {
|
||||
address: normalizeAddress(raw.address),
|
||||
address: normalizeMacAddress(raw.address),
|
||||
name,
|
||||
rssi: raw.rssi,
|
||||
txPower: raw.txPower,
|
||||
@@ -295,8 +287,19 @@ export function classifyAdvertisement(raw: RawAdvertisement): EvenAdvertisement
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeAddress(value: string | null | undefined): string {
|
||||
const compact = (value ?? "").replace(/[^0-9a-fA-F]/g, "").toUpperCase();
|
||||
/**
|
||||
* Canonical MAC form: uppercase, colon-separated. Anything that does not
|
||||
* contain exactly 12 hex digits is passed through trimmed and uppercased so
|
||||
* an obviously-wrong value stays visible instead of being silently mangled.
|
||||
* The single normalizer for every address comparison in the app — the stored
|
||||
* side (device-addresses.ts re-exports this) and the scanned side must agree
|
||||
* byte for byte or "is this the previously-paired device" checks break.
|
||||
*/
|
||||
export function normalizeMacAddress(value: string | null | undefined): string {
|
||||
const compact = (value ?? "")
|
||||
.trim()
|
||||
.replace(/[^0-9a-fA-F]/g, "")
|
||||
.toUpperCase();
|
||||
if (compact.length !== 12) return (value ?? "").trim().toUpperCase();
|
||||
return compact.match(/.{2}/g)!.join(":");
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
isEvenHubFontAsset,
|
||||
} from "./firmware-fonts";
|
||||
import { fetchWithUserAgent } from "../util/http";
|
||||
import { bytesToHex, hexToBytes as hexToBytesLenient } from "../util/hex-util";
|
||||
|
||||
declare const com: any;
|
||||
|
||||
@@ -237,23 +238,12 @@ function applyPatches(
|
||||
return buf;
|
||||
}
|
||||
|
||||
/** Patch-op hex is data, not user input: reject malformed strings instead of the shared decoder's silent stripping. */
|
||||
function hexToBytes(hex: string): Uint8Array {
|
||||
if (hex.length % 2 !== 0) {
|
||||
throw new FirmwareBuildError(`odd-length hex string: ${hex}`);
|
||||
if (hex.length % 2 !== 0 || /[^0-9a-fA-F]/.test(hex)) {
|
||||
throw new FirmwareBuildError(`invalid hex string: ${hex}`);
|
||||
}
|
||||
const out = new Uint8Array(hex.length / 2);
|
||||
for (let i = 0; i < out.length; i++) {
|
||||
out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function bytesToHex(bytes: Uint8Array): string {
|
||||
let hex = "";
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
hex += bytes[i].toString(16).padStart(2, "0");
|
||||
}
|
||||
return hex;
|
||||
return hexToBytesLenient(hex);
|
||||
}
|
||||
|
||||
function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {
|
||||
|
||||
@@ -19,7 +19,7 @@ export type FirmwarePatchSet = {
|
||||
export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
"base": "g2_2.2.6.10.bin",
|
||||
"baseSha256": "f4dfb0b49ad3de3c2daf17f8a27a157c3dc98411d6a0d3ab2cfd0918f41b9afa",
|
||||
"outputSha256": "82726bbe4d1d82f06a3d345ba3e5a4a39161077e5d26dcd7af24c4677df87fd1",
|
||||
"outputSha256": "e37c8d7b5876abd68cb58dd19a91cbb515b35fe91c0032648c7d20bb02601884",
|
||||
"patches": [
|
||||
{
|
||||
"offset": 1089903,
|
||||
@@ -96,8 +96,8 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
{
|
||||
"offset": 823369,
|
||||
"old": "1cf09bfb",
|
||||
"new": "55f3dbfd",
|
||||
"desc": "bl ring_release (forward ring release-long-press)"
|
||||
"new": "55f3d9fd",
|
||||
"desc": "bl ring_release (forward source-qualified release-long-press)"
|
||||
},
|
||||
{
|
||||
"offset": 1474137,
|
||||
@@ -138,43 +138,43 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
{
|
||||
"offset": 4301227,
|
||||
"old": "",
|
||||
"new": "02fb01f000e000bfb0b546f27424c2f22a040146206846f23f52c5f28802b2eb500f40f2543044f281124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f2543044f29f22c2f20000c0f24802104770b500284ed001684ef66762ccf2ff02914218bf70bd90f8081190f8095142f6c52c8d42c0f2500c2ad205eb8501014491f80d2191f80e4191f80ae191f80b3191f80c1142ea0424012c4ff0010298bf14466e1c054680f80961b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f80811bde870406047e047d5f8040138b149f29942c0f244022146bde87040104770bd00bf70b54ff6fd03c0f2450314460d46984746f27021c2f22a010e6831466ff39601b1f1005f0ad131684ef66762ccf2ff02914218bf0026412d03d070bd0026412dfbd1002cf9d04af26951c0f2450105468847002e01462846efd00129edd196f807120029e9d02168002948bf70bd47f25d02c0f2580208469047284670bd00bf2de9f04f9db046f2702ac2f22a0adaf800b058466ff39600b0f1005f40f07d81dbf800004ef66767ccf2ff07b84240f074819bf82802002800f05d81dbf82442002c00f0588140f2b870c2f20000d0f8008004a802f08effb8f1000f00f0dd81032045f24075cff68070a4f1600108f160026ff0bf03c0f2020500bf0e6ed41826664e6ec03366668e6eab42a666ce6ee6660e6f26674e6f66678e6fa667ce6fe667d1f88060c4f88060d1f88460c4f88460d1f88860c4f88860d1f88c60c4f88c60d1f89060c4f89060d1f89460c4f89460d1f89860c4f89860d1f89c60c4f89c60d1f8a060c4f8a060d1f8a460c4f8a460d1f8a860c4f8a860d1f8ac60c4f8ac60d1f8b060c4f8b060d1f8b460c4f8b460d1f8b860c4f8b860d1f8bc60c4f8bc6051f8c06fc4f8c0604e68c4f8c4608e68c4f8c860ce68c4f8cc600e69c4f8d0604e69c4f8d4608e69c4f8d860ce69c4f8dc600e6ac4f8e0604e6ac4f8e4608e6ac4f8e860ce6ac4f8ec600e6bc4f8f0604e6bc4f8f4608e6bc4f8f860ce6bc4f8fc600e6cc4f800614e6cc4f804618e6cc4f80861ce6cc4f80c610e6dc4f810614e6dc4f814618e6dc4f81861ce6dc4f81c617ff462afdaf800603040b0f1005f40f0b2803068b84240f0ae8096f8ce00002840f0348196f8dc10002000298df8140000f0ac8105a90a5c002a00f07f810a185378002b00f03d819378002b00f03b81d378002b00f039811379002b00f037815379002b00f035819379002b00f03381d379002b00f03181137a002b00f02f81537a002b00f02d81937a002b00f02b81d37a002b00f02981137b002b00f02781537b002b00f02581937b002b00f02381d37b002b00f02181137c002b00f01f81537c002b00f01d81937c002b00f01b81d37c002b00f01981137d002b00f01781537d002b00f01581937d002b00f01381d37d002b00f01181137e002b00f00f81537e002b00f00d81937e002b00f00b81d37e002b00f00981137f002b00f00781537f002b00f00581937f002b00f00381d27f002a00f00181203060287ff47baf20e19bf82a0270b1dbf82c0240b144f63421c2f207010968401a002800f3ae8000208bf82a024cf61520c0f246001db0bde8f04f004704f005fb002800f0838000216ff017020023c518c1542f338618b3f50d7f02f12f026970a970e97029716971a971e97129726972a972e97229736973a973e97329746974a974e97429756975a97586f82f1086f830106976a976e97629776977a977e97785f8201085f8211085f8221085f8231085f8241085f8251085f8261085f8271085f8281085f8291085f82a1085f82b1085f82c1085f82d1085f82e10b7d1012180f8ce104ff0ff310760a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe1010e000208bf82802cbf824028bf82a0201208bf829024cf61520c0f24600804715e00020caf8000000208bf82802cbf824024ff4163045f20f11069005a8c0f24701cdf81480884701208bf82a0204a802f06efecbf8d4001db0bde8f08f01303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f2821d84ff052020a541dd0014445225e284a7018d04f225d288a7014d052225c28ca7010d044225b280a710cd045225a284a7108d0522259288a7104d020225828ca7142f0168500208df87300012096f8dd10002900f0c280002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf54e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2915d84ff05303535411d00a444b235e2953700cd049235d29937008d050235c29d37004d020235b29137140f0c28200218df87310013096f8de10002900f0be80002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00Line truncated
|
||||
"new": "02fb01f000e000bfb0b546f27424c2f22a040146206846f23f52c5f28802b2eb500f40f2543044f281124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f2543044f29f22c2f20000c0f24802104770b500284ed001684ef66762ccf2ff02914218bf70bd90f8081190f8095142f6c52c8d42c0f2500c2ad205eb8501014491f80d2191f80e4191f80ae191f80b3191f80c1142ea0424012c4ff0010298bf14466e1c054680f80961b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f80811bde870406047e047d5f8040138b149f29942c0f244022146bde87040104770bd00bf70b54ff6fd03c0f2450314460d46984746f27021c2f22a010e6831466ff39601b1f1005f0ad131684ef66762ccf2ff02914218bf0026412d03d070bd0026412dfbd1002cf9d04af26951c0f2450105468847002e01462846efd00129edd196f807120029e9d02168002948bf70bd47f25d02c0f2580208469047284670bd00bf2de9f04f9db046f2702ac2f22a0adaf800b058466ff39600b0f1005f40f07d81dbf800004ef66767ccf2ff07b84240f074819bf82802002800f05d81dbf82442002c00f0588140f2b870c2f20000d0f8008004a802f08effb8f1000f00f0dd81032045f24075cff68070a4f1600108f160026ff0bf03c0f2020500bf0e6ed41826664e6ec03366668e6eab42a666ce6ee6660e6f26674e6f66678e6fa667ce6fe667d1f88060c4f88060d1f88460c4f88460d1f88860c4f88860d1f88c60c4f88c60d1f89060c4f89060d1f89460c4f89460d1f89860c4f89860d1f89c60c4f89c60d1f8a060c4f8a060d1f8a460c4f8a460d1f8a860c4f8a860d1f8ac60c4f8ac60d1f8b060c4f8b060d1f8b460c4f8b460d1f8b860c4f8b860d1f8bc60c4f8bc6051f8c06fc4f8c0604e68c4f8c4608e68c4f8c860ce68c4f8cc600e69c4f8d0604e69c4f8d4608e69c4f8d860ce69c4f8dc600e6ac4f8e0604e6ac4f8e4608e6ac4f8e860ce6ac4f8ec600e6bc4f8f0604e6bc4f8f4608e6bc4f8f860ce6bc4f8fc600e6cc4f800614e6cc4f804618e6cc4f80861ce6cc4f80c610e6dc4f810614e6dc4f814618e6dc4f81861ce6dc4f81c617ff462afdaf800603040b0f1005f40f0b2803068b84240f0ae8096f8ce00002840f0348196f8dc10002000298df8140000f0ac8105a90a5c002a00f07f810a185378002b00f03d819378002b00f03b81d378002b00f039811379002b00f037815379002b00f035819379002b00f03381d379002b00f03181137a002b00f02f81537a002b00f02d81937a002b00f02b81d37a002b00f02981137b002b00f02781537b002b00f02581937b002b00f02381d37b002b00f02181137c002b00f01f81537c002b00f01d81937c002b00f01b81d37c002b00f01981137d002b00f01781537d002b00f01581937d002b00f01381d37d002b00f01181137e002b00f00f81537e002b00f00d81937e002b00f00b81d37e002b00f00981137f002b00f00781537f002b00f00581937f002b00f00381d27f002a00f00181203060287ff47baf20e19bf82a0270b1dbf82c0240b144f63421c2f207010968401a002800f3ae8000208bf82a024cf61520c0f246001db0bde8f04f004704f001fb002800f0838000216ff017020023c518c1542f338618b3f50d7f02f12f026970a970e97029716971a971e97129726972a972e97229736973a973e97329746974a974e97429756975a97586f82f1086f830106976a976e97629776977a977e97785f8201085f8211085f8221085f8231085f8241085f8251085f8261085f8271085f8281085f8291085f82a1085f82b1085f82c1085f82d1085f82e10b7d1012180f8ce104ff0ff310760a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe1010e000208bf82802cbf824028bf82a0201208bf829024cf61520c0f24600804715e00020caf8000000208bf82802cbf824024ff4163045f20f11069005a8c0f24701cdf81480884701208bf82a0204a802f06efecbf8d4001db0bde8f08f01303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f2821d84ff052020a541dd0014445225e284a7018d04f225d288a7014d052225c28ca7010d044225b280a710cd045225a284a7108d0522259288a7104d020225828ca7142f0168500208df87300012096f8dd10002900f0c280002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf54e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2915d84ff05303535411d00a444b235e2953700cd049235d29937008d050235c29d37004d020235b29137140f0c28200218df87310013096f8de10002900f0be80002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00Line truncated
|
||||
"desc": "append injected blobs to main-app payload"
|
||||
},
|
||||
{
|
||||
"offset": 777711,
|
||||
"old": "44c33500",
|
||||
"new": "604b3600",
|
||||
"new": "584b3600",
|
||||
"desc": "main-app subheader payload size (ps)"
|
||||
},
|
||||
{
|
||||
"offset": 152,
|
||||
"old": "c4c33500",
|
||||
"new": "e04b3600",
|
||||
"new": "d84b3600",
|
||||
"desc": "main-app TOC entry size (ps + 128)"
|
||||
},
|
||||
{
|
||||
"offset": 777831,
|
||||
"old": "44c33504",
|
||||
"new": "604b3604",
|
||||
"new": "584b3604",
|
||||
"desc": "main-app preamble length (low 24 bits)"
|
||||
},
|
||||
{
|
||||
"offset": 777835,
|
||||
"old": "df8110c9",
|
||||
"new": "562ec508",
|
||||
"new": "0c327522",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
|
||||
},
|
||||
{
|
||||
"offset": 156,
|
||||
"old": "c1be0fb1",
|
||||
"new": "ef84d21c",
|
||||
"new": "e3712717",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
|
||||
},
|
||||
{
|
||||
"offset": 777715,
|
||||
"old": "c1be0fb1",
|
||||
"new": "ef84d21c",
|
||||
"new": "e3712717",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -280,16 +280,32 @@ export type GlassesPairSerialVerdict =
|
||||
| { kind: "unknown" }
|
||||
| { kind: "mismatched"; left: string; right: string };
|
||||
|
||||
/**
|
||||
* Canonical comparison key for a serial-ish string: the decoded serial when it
|
||||
* decodes (so an `_L_1` arm suffix or casing difference is not read as
|
||||
* different hardware), else the trimmed uppercase raw value. Null when empty.
|
||||
* The single definition of serial equality — pair grouping, the pair check,
|
||||
* and the "Yours" badge must all agree on it.
|
||||
*/
|
||||
export function serialKey(value: string | null | undefined): string | null {
|
||||
const trimmed = nonEmpty(value);
|
||||
if (!trimmed) return null;
|
||||
return GlassesHardwareIdentity.decode(trimmed)?.serial ?? trimmed.toUpperCase();
|
||||
}
|
||||
|
||||
/** True when both values carry a serial and the serials name the same hardware. */
|
||||
export function serialsMatch(a: string | null | undefined, b: string | null | undefined): boolean {
|
||||
const keyA = serialKey(a);
|
||||
const keyB = serialKey(b);
|
||||
return !!keyA && !!keyB && keyA === keyB;
|
||||
}
|
||||
|
||||
export function evaluatePairSerials(left: string | null | undefined, right: string | null | undefined): GlassesPairSerialVerdict {
|
||||
const l = nonEmpty(left);
|
||||
const r = nonEmpty(right);
|
||||
if (!l || !r) return { kind: "unknown" };
|
||||
// Compare on the decoded serial when both decode, so an arm suffix or casing
|
||||
// difference in the reported string is not read as different hardware.
|
||||
const leftKey = GlassesHardwareIdentity.decode(l)?.serial ?? l.toUpperCase();
|
||||
const rightKey = GlassesHardwareIdentity.decode(r)?.serial ?? r.toUpperCase();
|
||||
if (leftKey !== rightKey) return { kind: "mismatched", left: l, right: r };
|
||||
return { kind: "matched", serial: leftKey };
|
||||
if (!serialsMatch(l, r)) return { kind: "mismatched", left: l, right: r };
|
||||
return { kind: "matched", serial: serialKey(l)! };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+104
-64
@@ -14,14 +14,14 @@
|
||||
import {
|
||||
estimateProximity,
|
||||
GLASSES_CALIBRATION,
|
||||
proximitySummary,
|
||||
RING_CALIBRATION,
|
||||
sortedByProximity,
|
||||
zoneGlyph,
|
||||
zoneLabel,
|
||||
type ProximityEstimate,
|
||||
type ProximityZone,
|
||||
} from "./ble-proximity";
|
||||
import { classifyAdvertisement, type EvenAdvertisement, type RawAdvertisement } from "./even-advertisement";
|
||||
import { classifyAdvertisement, normalizeMacAddress, type EvenAdvertisement, type RawAdvertisement } from "./even-advertisement";
|
||||
import { glassesImagePath, R1_IMAGE_PATH } from "./glasses-artwork";
|
||||
import {
|
||||
colorwayDisplayName,
|
||||
@@ -29,6 +29,8 @@ import {
|
||||
evaluatePairSerials,
|
||||
GlassesHardwareIdentity,
|
||||
pairSerialWarning,
|
||||
serialKey,
|
||||
serialsMatch,
|
||||
type GlassesColorway,
|
||||
} from "./glasses-hardware-identity";
|
||||
|
||||
@@ -45,9 +47,14 @@ export type GlassesPairCandidate = {
|
||||
completeness: PairCompleteness;
|
||||
/** Strongest smoothed signal across the arms that have one. */
|
||||
rssi: number | null;
|
||||
txPower: number | null;
|
||||
proximity: ProximityEstimate | null;
|
||||
lastSeenMs: number;
|
||||
/**
|
||||
* Set when this lone arm and a lone arm of the other side carry different
|
||||
* serials — the mixed-pair situation the serial check exists to name.
|
||||
* Grouping is by serial, so the mismatch can only show up across groups.
|
||||
*/
|
||||
mismatchWarning: string | null;
|
||||
};
|
||||
|
||||
export type RingCandidate = {
|
||||
@@ -84,10 +91,24 @@ export class DiscoveryAggregator {
|
||||
|
||||
/** Feed one raw advertisement. Returns the classified record, or null when ignored. */
|
||||
ingest(raw: RawAdvertisement): EvenAdvertisement | null {
|
||||
const classified = classifyAdvertisement(raw);
|
||||
let classified = classifyAdvertisement(raw);
|
||||
if (!classified) {
|
||||
if (raw.name) this.rejectedNames.add(raw.name);
|
||||
return null;
|
||||
// Android sometimes splits an advertisement across reports — an ADV
|
||||
// report without the scan response's name, or the reverse. If earlier
|
||||
// traffic from this address already supplied the missing half, retry
|
||||
// with it filled in rather than dropping the arm.
|
||||
const remembered = this.byAddress.get(normalizeMacAddress(raw.address));
|
||||
if (remembered) {
|
||||
classified = classifyAdvertisement({
|
||||
...raw,
|
||||
name: raw.name || remembered.name,
|
||||
manufacturerData: raw.manufacturerData || remembered.manufacturerData,
|
||||
});
|
||||
}
|
||||
if (!classified) {
|
||||
if (raw.name) this.rejectedNames.add(raw.name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const previous = this.byAddress.get(classified.address);
|
||||
let smoothedRssi: number | null = classified.rssi;
|
||||
@@ -109,6 +130,19 @@ export class DiscoveryAggregator {
|
||||
seenAtMs: Math.max(classified.seenAtMs, previous?.seenAtMs ?? 0),
|
||||
smoothedRssi,
|
||||
};
|
||||
if (previous && !classified.manufacturerData && previous.manufacturerData) {
|
||||
// A record without manufacturer data (a bonded listing, or a split
|
||||
// report) parses to "serial unknown" notes and a possibly stale cached
|
||||
// name; those must not overwrite what a fuller advertisement already
|
||||
// established, or the row shows a serial and claims it is unknown.
|
||||
merged.note = previous.note;
|
||||
merged.flag = previous.flag;
|
||||
merged.embeddedMacMismatch = previous.embeddedMacMismatch;
|
||||
merged.ringSerialSuffix = previous.ringSerialSuffix;
|
||||
if (previous.name && (!classified.name || classified.source === "paired")) {
|
||||
merged.name = previous.name;
|
||||
}
|
||||
}
|
||||
this.byAddress.set(merged.address, merged);
|
||||
return merged;
|
||||
}
|
||||
@@ -144,7 +178,8 @@ export class DiscoveryAggregator {
|
||||
const groups = new Map<string, { left: (EvenAdvertisement & { smoothedRssi: number | null }) | null; right: (EvenAdvertisement & { smoothedRssi: number | null }) | null }>();
|
||||
for (const record of this.byAddress.values()) {
|
||||
if (record.role === "ring") continue;
|
||||
const key = record.serial ? `serial:${record.serial}` : `arm:${record.address}`;
|
||||
const canonical = serialKey(record.serial);
|
||||
const key = canonical ? `serial:${canonical}` : `arm:${record.address}`;
|
||||
const group = groups.get(key) ?? { left: null, right: null };
|
||||
const slot = record.role === "left" ? "left" : "right";
|
||||
const incumbent = group[slot];
|
||||
@@ -162,20 +197,31 @@ export class DiscoveryAggregator {
|
||||
const samples = [left, right].filter((arm): arm is NonNullable<typeof arm> => !!arm && arm.smoothedRssi != null);
|
||||
const strongest = samples.length ? samples.reduce((a, b) => (a.smoothedRssi! >= b.smoothedRssi! ? a : b)) : null;
|
||||
const rssi = strongest ? Math.round(strongest.smoothedRssi!) : null;
|
||||
const txPower = strongest?.txPower ?? left?.txPower ?? right?.txPower ?? null;
|
||||
pairs.push({
|
||||
id: serial ?? `arm:${any.address}`,
|
||||
id: serialKey(serial) ?? `arm:${any.address}`,
|
||||
serial,
|
||||
identity: GlassesHardwareIdentity.decode(serial),
|
||||
left: left ? stripSmoothing(left) : null,
|
||||
right: right ? stripSmoothing(right) : null,
|
||||
completeness: left && right ? "complete" : left ? "left-only" : "right-only",
|
||||
rssi,
|
||||
txPower,
|
||||
proximity: estimateProximity(rssi, txPower, GLASSES_CALIBRATION),
|
||||
proximity: estimateProximity(rssi, GLASSES_CALIBRATION),
|
||||
lastSeenMs: Math.max(left?.seenAtMs ?? 0, right?.seenAtMs ?? 0),
|
||||
mismatchWarning: null,
|
||||
});
|
||||
}
|
||||
// Grouping on the serial means a group can never hold two different
|
||||
// serials, so a mixed pair (left temple from A, right from B) surfaces as
|
||||
// two lone arms, not as one mismatched row. With exactly one lone arm per
|
||||
// side visible that IS the mixed-arms situation — name it on both rows so
|
||||
// the wearer isn't left staring at two "waiting for the other" rows.
|
||||
const loneLeft = pairs.filter((pair) => pair.completeness === "left-only" && pair.serial);
|
||||
const loneRight = pairs.filter((pair) => pair.completeness === "right-only" && pair.serial);
|
||||
if (loneLeft.length === 1 && loneRight.length === 1) {
|
||||
const warning = pairSerialWarning(evaluatePairSerials(loneLeft[0]!.left!.serial, loneRight[0]!.right!.serial));
|
||||
loneLeft[0]!.mismatchWarning = warning;
|
||||
loneRight[0]!.mismatchWarning = warning;
|
||||
}
|
||||
return sortedByProximity(pairs, (pair) => pair.proximity, (pair) => pair.id);
|
||||
}
|
||||
|
||||
@@ -189,7 +235,7 @@ export class DiscoveryAggregator {
|
||||
id: record.address,
|
||||
advertisement: stripSmoothing(record),
|
||||
rssi,
|
||||
proximity: estimateProximity(rssi, record.txPower, RING_CALIBRATION),
|
||||
proximity: estimateProximity(rssi, RING_CALIBRATION),
|
||||
lastSeenMs: record.seenAtMs,
|
||||
});
|
||||
}
|
||||
@@ -205,9 +251,11 @@ function stripSmoothing(record: EvenAdvertisement & { smoothedRssi: number | nul
|
||||
/**
|
||||
* The candidate whose signal is strong enough to call "the one you are
|
||||
* holding". `null` when nothing leads clearly, which is the honest answer for
|
||||
* two pairs sitting on the same table.
|
||||
* two pairs sitting on the same table — and when the list has a single entry,
|
||||
* where "closest" has nothing to be closer than.
|
||||
*/
|
||||
export function nearestCandidateId(candidates: ReadonlyArray<{ id: string; rssi: number | null }>): string | null {
|
||||
if (candidates.length < 2) return null;
|
||||
const ranked = candidates
|
||||
.filter((candidate): candidate is { id: string; rssi: number } => candidate.rssi != null)
|
||||
.slice()
|
||||
@@ -221,19 +269,11 @@ export function nearestCandidateId(candidates: ReadonlyArray<{ id: string; rssi:
|
||||
|
||||
/**
|
||||
* The saved pair identity is stored as the serial, but historical values may
|
||||
* carry the `_L_1` arm suffix, so compare on the decoded serial when both
|
||||
* sides decode and fall back to a containment check when they do not.
|
||||
* carry the `_L_1` arm suffix; `serialsMatch` compares on the decoded serial
|
||||
* so the suffix or casing is not read as different hardware.
|
||||
*/
|
||||
export function isPreviouslyPaired(name: string | null | undefined, pairedSerial: string | null | undefined): boolean {
|
||||
if (!name || !pairedSerial) return false;
|
||||
const saved = pairedSerial.trim();
|
||||
if (!saved) return false;
|
||||
const left = GlassesHardwareIdentity.decode(name);
|
||||
const right = GlassesHardwareIdentity.decode(saved);
|
||||
if (left && right) return left.serial === right.serial;
|
||||
const a = name.toLowerCase();
|
||||
const b = saved.toLowerCase();
|
||||
return a.includes(b) || b.includes(a);
|
||||
return serialsMatch(name, pairedSerial);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -263,15 +303,12 @@ export type PairingRowPresentation = {
|
||||
proximitySummary: string;
|
||||
proximityGlyph: string;
|
||||
zone: ProximityZone | null;
|
||||
/** "Left + right arms found", "Only the left arm has been seen", … */
|
||||
/** "Left + right arms found", "Only the left arm has been seen", …; "" when there is nothing worth a line (an unbonded ring). */
|
||||
armsSummary: string;
|
||||
/** A problem the wearer should read before tapping, or "" when none. */
|
||||
warning: string;
|
||||
/** Both arms present (or a ring), so tapping can save addresses. */
|
||||
canSelect: boolean;
|
||||
leftAddress: string;
|
||||
rightAddress: string;
|
||||
ringAddress: string;
|
||||
};
|
||||
|
||||
export type RowContext = {
|
||||
@@ -283,6 +320,29 @@ export type RowContext = {
|
||||
pairedRingAddress?: string | null;
|
||||
};
|
||||
|
||||
/** The presentation fields glasses and ring rows share, so badge and fallback rules cannot drift apart. */
|
||||
function presentationBase(
|
||||
proximity: ProximityEstimate | null,
|
||||
isNearest: boolean,
|
||||
isPaired: boolean,
|
||||
warnings: readonly string[],
|
||||
): Pick<PairingRowPresentation, "isNearest" | "isPreviouslyPaired" | "badge" | "proximitySummary" | "proximityGlyph" | "zone" | "warning"> {
|
||||
return {
|
||||
isNearest,
|
||||
isPreviouslyPaired: isPaired,
|
||||
badge: isPaired ? "Yours" : isNearest ? "Closest" : "",
|
||||
proximitySummary: proximity ? zoneLabel(proximity.zone) : "Signal unknown",
|
||||
proximityGlyph: proximity ? zoneGlyph(proximity.zone) : "○○○○",
|
||||
zone: proximity?.zone ?? null,
|
||||
warning: warnings.join(" "),
|
||||
};
|
||||
}
|
||||
|
||||
function embeddedMacMismatchWarning(subject: string, ad: EvenAdvertisement | null): string | null {
|
||||
if (!ad?.embeddedMacMismatch) return null;
|
||||
return `${subject} advertised address ${ad.embeddedMac} differs from its radio address ${ad.address}.`;
|
||||
}
|
||||
|
||||
export function glassesRow(pair: GlassesPairCandidate, context: RowContext = {}): PairingRowPresentation {
|
||||
const identity = pair.identity;
|
||||
const imagePath = glassesImagePath(identity);
|
||||
@@ -294,20 +354,17 @@ export function glassesRow(pair: GlassesPairCandidate, context: RowContext = {})
|
||||
const rightNote = pair.right?.note;
|
||||
if (leftNote) warnings.push(`Left arm: ${leftNote}.`);
|
||||
if (rightNote) warnings.push(`Right arm: ${rightNote}.`);
|
||||
if (pair.left?.embeddedMacMismatch) {
|
||||
warnings.push(`Left arm's advertised address ${pair.left.embeddedMac} differs from its radio address ${pair.left.address}.`);
|
||||
}
|
||||
if (pair.right?.embeddedMacMismatch) {
|
||||
warnings.push(`Right arm's advertised address ${pair.right.embeddedMac} differs from its radio address ${pair.right.address}.`);
|
||||
}
|
||||
const verdict = evaluatePairSerials(pair.left?.serial, pair.right?.serial);
|
||||
const mismatch = pairSerialWarning(verdict);
|
||||
if (mismatch) warnings.push(mismatch);
|
||||
const leftMacWarning = embeddedMacMismatchWarning("Left arm's", pair.left);
|
||||
if (leftMacWarning) warnings.push(leftMacWarning);
|
||||
const rightMacWarning = embeddedMacMismatchWarning("Right arm's", pair.right);
|
||||
if (rightMacWarning) warnings.push(rightMacWarning);
|
||||
if (pair.mismatchWarning) warnings.push(pair.mismatchWarning);
|
||||
|
||||
let armsSummary: string;
|
||||
switch (pair.completeness) {
|
||||
case "complete":
|
||||
armsSummary = verdict.kind === "matched" ? "Left + right arms found · serials match" : "Left + right arms found";
|
||||
// Arms are grouped by serial, so a complete pair's serials match by construction.
|
||||
armsSummary = "Left + right arms found · serials match";
|
||||
break;
|
||||
case "left-only":
|
||||
armsSummary = "Only the left arm has been seen — waiting for the right";
|
||||
@@ -328,30 +385,20 @@ export function glassesRow(pair: GlassesPairCandidate, context: RowContext = {})
|
||||
swatchHex: identity?.colorway ? colorwaySwatchHex(identity.colorway) : null,
|
||||
imagePath,
|
||||
hasVariantImage: !!identity?.imageAssetName,
|
||||
isNearest,
|
||||
isPreviouslyPaired: isPreviouslyPairedRow,
|
||||
badge: isPreviouslyPairedRow ? "Yours" : isNearest ? "Closest" : "",
|
||||
proximitySummary: pair.proximity ? proximitySummary(pair.proximity) : "Signal unknown",
|
||||
proximityGlyph: pair.proximity ? zoneGlyph(pair.proximity.zone) : "○○○○",
|
||||
zone: pair.proximity?.zone ?? null,
|
||||
...presentationBase(pair.proximity, isNearest, isPreviouslyPairedRow, warnings),
|
||||
armsSummary,
|
||||
warning: warnings.join(" "),
|
||||
canSelect: pair.completeness === "complete" && verdict.kind !== "mismatched",
|
||||
leftAddress: pair.left?.address ?? "",
|
||||
rightAddress: pair.right?.address ?? "",
|
||||
ringAddress: "",
|
||||
canSelect: pair.completeness === "complete",
|
||||
};
|
||||
}
|
||||
|
||||
export function ringRow(ring: RingCandidate, context: RowContext = {}): PairingRowPresentation {
|
||||
const ad = ring.advertisement;
|
||||
const isPaired = !!context.pairedRingAddress && context.pairedRingAddress.toUpperCase() === ad.address;
|
||||
const isPaired = !!context.pairedRingAddress && normalizeMacAddress(context.pairedRingAddress) === ad.address;
|
||||
const isNearest = !!context.nearestId && context.nearestId === ring.id;
|
||||
const warnings: string[] = [];
|
||||
if (ad.note) warnings.push(`${ad.note}.`);
|
||||
if (ad.embeddedMacMismatch) {
|
||||
warnings.push(`The ring's advertised address ${ad.embeddedMac} differs from its radio address ${ad.address}.`);
|
||||
}
|
||||
const macWarning = embeddedMacMismatchWarning("The ring's", ad);
|
||||
if (macWarning) warnings.push(macWarning);
|
||||
return {
|
||||
id: ring.id,
|
||||
kind: "ring",
|
||||
@@ -362,18 +409,11 @@ export function ringRow(ring: RingCandidate, context: RowContext = {}): PairingR
|
||||
swatchHex: null,
|
||||
imagePath: R1_IMAGE_PATH,
|
||||
hasVariantImage: true,
|
||||
isNearest,
|
||||
isPreviouslyPaired: isPaired,
|
||||
badge: isPaired ? "Yours" : isNearest ? "Closest" : "",
|
||||
proximitySummary: ring.proximity ? proximitySummary(ring.proximity) : "Signal unknown",
|
||||
proximityGlyph: ring.proximity ? zoneGlyph(ring.proximity.zone) : "○○○○",
|
||||
zone: ring.proximity?.zone ?? null,
|
||||
armsSummary: ad.bonded ? "Paired with this phone" : "Advertising",
|
||||
warning: warnings.join(" "),
|
||||
...presentationBase(ring.proximity, isNearest, isPaired, warnings),
|
||||
// "Advertising" told the wearer nothing (a listed ring is advertising by
|
||||
// definition); only the bonded state is worth a line.
|
||||
armsSummary: ad.bonded ? "Paired with this phone" : "",
|
||||
canSelect: true,
|
||||
leftAddress: "",
|
||||
rightAddress: "",
|
||||
ringAddress: ad.address,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user