@mentra/bluetooth-sdk 3.4.0-dev.998 → 3.5.0-dev.1238
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -11
- package/android/build.gradle +60 -51
- package/android/gradle.properties +3 -0
- package/android/settings.gradle +47 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +76 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +27 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +98 -120
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +2 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +24 -9
- package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +170 -23
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +13 -316
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +0 -35
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +2 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +141 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveRgbLedResponseTest.kt +76 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
- package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
- package/build/BluetoothSdk.types.d.ts +98 -1
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +42 -7
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +1 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/generated/changelogCatalog.d.ts +4 -1
- package/build/generated/changelogCatalog.d.ts.map +1 -1
- package/build/generated/changelogCatalog.js +5 -1
- package/build/generated/changelogCatalog.js.map +1 -1
- package/build/generated/releaseMetadata.js +6 -6
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +66 -14
- package/ios/MentraBluetoothSDK.podspec +4 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
- package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
- package/ios/Source/BesCrashReportWaiters.swift +64 -0
- package/ios/Source/BluetoothSdkDefaults.swift +2 -2
- package/ios/Source/DeviceManager.swift +43 -22
- package/ios/Source/GeneratedChangelogCatalog.swift +2 -1
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +27 -15
- package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
- package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
- package/ios/Source/audio/SpeechActivity.swift +277 -0
- package/ios/Source/events/BluetoothEvents.swift +41 -0
- package/ios/Source/internal/BluetoothAvailability.swift +15 -5
- package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +5 -0
- package/ios/Source/sgcs/MentraLive.swift +173 -42
- package/ios/Source/sgcs/Nimo.swift +39 -272
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +9 -38
- package/ios/Source/sgcs/NimoCanvasSession.swift +0 -1
- package/ios/Source/sgcs/SGCManager.swift +6 -0
- package/ios/Source/stt/STTTools.swift +13 -31
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
- package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
- package/ios/Source/stt/WakeWordDetector.swift +145 -0
- package/ios/Source/utils/BoundedWait.swift +44 -0
- package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
- package/ios/Source/utils/SttModelTraits.swift +62 -0
- package/ios/Tests/BesCrashReportTests.swift +142 -0
- package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
- package/ios/Tests/DeviceManagerReconnectTests.swift +0 -71
- package/ios/Tests/GlassesAudioSetupPolicyTests.swift +9 -3
- package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
- package/ios/Tests/MentraLiveAudioSetupTests.swift +6 -12
- package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +179 -10
- package/ios/Tests/NimoCanvasTransportTests.swift +0 -89
- package/ios/Tests/PcmStreamTests.swift +299 -0
- package/ios/Tests/SpeechActivityTests.swift +238 -0
- package/ios/Tests/SttModelTraitsTests.swift +62 -0
- package/package.json +2 -2
- package/plugin/build/withAndroid.js +9 -11
- package/plugin/build/withKotlinVersion.d.ts +2 -0
- package/plugin/build/withKotlinVersion.js +46 -0
- package/src/BluetoothSdk.types.ts +102 -1
- package/src/_private/BluetoothSdkModule.ts +45 -7
- package/src/generated/changelogCatalog.ts +5 -1
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +12 -0
- package/android/silero/LICENSE.md +0 -17
- package/android/silero/build.gradle +0 -50
- package/android/silero/proguard-rules.pro +0 -24
- package/android/silero/src/androidTest/assets/hello.wav +0 -0
- package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
- package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
- package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
- package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -274
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -16
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -851
- package/ios/Source/sgcs/NimoMacResourceTransport.swift +0 -217
- package/ios/Source/sgcs/NimoResourceFixture.swift +0 -384
- package/ios/Source/sgcs/NimoResourceSession.swift +0 -406
- package/ios/Tests/NimoResourceSessionTests.swift +0 -476
- /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
- /package/android/{silero/src/main/assets → src/main/assets/vad}/silero_vad.onnx +0 -0
|
@@ -696,25 +696,28 @@ private struct BlePhotoTransfer {
|
|
|
696
696
|
}
|
|
697
697
|
}
|
|
698
698
|
|
|
699
|
-
|
|
699
|
+
enum BleIncidentLogRelayKind {
|
|
700
700
|
case firmware
|
|
701
701
|
case logcat
|
|
702
702
|
}
|
|
703
703
|
|
|
704
|
-
|
|
704
|
+
final class BleIncidentLogRelayEntry {
|
|
705
705
|
let fileBaseKey: String
|
|
706
706
|
let incidentId: String
|
|
707
707
|
let apiBaseUrl: String
|
|
708
708
|
let kind: BleIncidentLogRelayKind
|
|
709
|
+
let reservedAt: TimeInterval
|
|
709
710
|
var session: MentraLiveFileTransferSession?
|
|
710
711
|
|
|
711
712
|
init(
|
|
712
|
-
fileBaseKey: String, incidentId: String, apiBaseUrl: String, kind: BleIncidentLogRelayKind
|
|
713
|
+
fileBaseKey: String, incidentId: String, apiBaseUrl: String, kind: BleIncidentLogRelayKind,
|
|
714
|
+
reservedAt: TimeInterval
|
|
713
715
|
) {
|
|
714
716
|
self.fileBaseKey = fileBaseKey
|
|
715
717
|
self.incidentId = incidentId
|
|
716
718
|
self.apiBaseUrl = apiBaseUrl
|
|
717
719
|
self.kind = kind
|
|
720
|
+
self.reservedAt = reservedAt
|
|
718
721
|
}
|
|
719
722
|
}
|
|
720
723
|
|
|
@@ -1504,6 +1507,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1504
1507
|
if state == ConnTypes.DISCONNECTED {
|
|
1505
1508
|
resetPendingAckState(reason: "BLE session ended")
|
|
1506
1509
|
resetWireNegotiationState()
|
|
1510
|
+
resetReadinessExchange()
|
|
1507
1511
|
resetAncsRelayState()
|
|
1508
1512
|
// Queued writes are session-bound: transmitting them into the NEXT session
|
|
1509
1513
|
// (e.g. a stale handshake whose reply activates v2 before the new session
|
|
@@ -1546,13 +1550,16 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1546
1550
|
func dbg1() {}
|
|
1547
1551
|
func dbg2() {}
|
|
1548
1552
|
|
|
1553
|
+
/// Clear the saved device name so the pairing filter is not bypassed on rescan.
|
|
1554
|
+
static func clearSavedPeripheral() {
|
|
1555
|
+
secureTrailerMemory.clear()
|
|
1556
|
+
UserDefaults.standard.removeObject(forKey: prefsDeviceName)
|
|
1557
|
+
UserDefaults.standard.removeObject(forKey: prefsPeripheralIds)
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1549
1560
|
func forget() {
|
|
1550
1561
|
Bridge.log("LIVE: Forgetting Mentra Live glasses")
|
|
1551
|
-
Self.
|
|
1552
|
-
|
|
1553
|
-
// Clear saved device name so the pairing filter is not bypassed on rescan
|
|
1554
|
-
UserDefaults.standard.removeObject(forKey: PREFS_DEVICE_NAME)
|
|
1555
|
-
UserDefaults.standard.removeObject(forKey: PREFS_PERIPHERAL_IDS)
|
|
1562
|
+
Self.clearSavedPeripheral()
|
|
1556
1563
|
pairFlow("forget", "cleared_saved_peripheral")
|
|
1557
1564
|
|
|
1558
1565
|
// Stop scanning first
|
|
@@ -1642,7 +1649,11 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1642
1649
|
private var fileWriteCharacteristic: CBCharacteristic?
|
|
1643
1650
|
private var activeFileTransfers = [String: MentraLiveFileTransferSession]()
|
|
1644
1651
|
private var blePhotoTransfers = [String: BlePhotoTransfer]()
|
|
1645
|
-
private var bleIncidentLogRelays = [String: BleIncidentLogRelayEntry]()
|
|
1652
|
+
private(set) var bleIncidentLogRelays = [String: BleIncidentLogRelayEntry]()
|
|
1653
|
+
// Longer than the glasses' bounded relay of one report (BES logs, two file transfers, the
|
|
1654
|
+
// phone POST), so an unreleased name cannot be reused while its report is in flight.
|
|
1655
|
+
static let incidentRelayOwnershipSeconds: TimeInterval = 600
|
|
1656
|
+
var incidentRelayClock: () -> TimeInterval = { ProcessInfo.processInfo.systemUptime }
|
|
1646
1657
|
private var l2capFileChannel: MentraLiveL2capChannel?
|
|
1647
1658
|
private var l2capFileChannelId: UUID?
|
|
1648
1659
|
private var l2capFileChannelOpening = false
|
|
@@ -1685,8 +1696,10 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1685
1696
|
private let SIGNIFICANT_BLE_TRACE_QUEUE_SIZE = 5
|
|
1686
1697
|
|
|
1687
1698
|
/// Device Settings Keys
|
|
1688
|
-
private let
|
|
1689
|
-
private let
|
|
1699
|
+
private static let prefsDeviceName = "MentraLiveLastConnectedDeviceName"
|
|
1700
|
+
private static let prefsPeripheralIds = "MentraLivePeripheralIds"
|
|
1701
|
+
private let PREFS_DEVICE_NAME = MentraLive.prefsDeviceName
|
|
1702
|
+
private let PREFS_PERIPHERAL_IDS = MentraLive.prefsPeripheralIds
|
|
1690
1703
|
|
|
1691
1704
|
// MARK: - Properties
|
|
1692
1705
|
|
|
@@ -1811,6 +1824,13 @@ class MentraLive: NSObject, SGCManager {
|
|
|
1811
1824
|
// the physical connection — so a first-seen sid after an upgrade OTA cannot be
|
|
1812
1825
|
// mistaken for a fresh pairing just because a not-ready heartbeat slipped in first.
|
|
1813
1826
|
private var readinessCompletedThisBleSession = false
|
|
1827
|
+
/// Readiness exchange the phone is waiting on. Every phone_ready carries it until the
|
|
1828
|
+
/// matching glasses_ready arrives, so retries and the copies the BES buffers while the
|
|
1829
|
+
/// glasses boot are one exchange: the glasses reset their transport once for it and answer
|
|
1830
|
+
/// later copies without resetting. Both exchange fields are scoped to the BLE session.
|
|
1831
|
+
private var pendingReadyId: String?
|
|
1832
|
+
/// `sid` of the glasses process whose glasses_ready this BLE session last handled.
|
|
1833
|
+
private var readyGlassesSessionId: String?
|
|
1814
1834
|
private var globalMessageId = 0
|
|
1815
1835
|
private var lastReceivedMessageId = 0
|
|
1816
1836
|
private var bleWriteTraceSequence = 0
|
|
@@ -2756,6 +2776,18 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2756
2776
|
}
|
|
2757
2777
|
|
|
2758
2778
|
var count: Int { commands.count }
|
|
2779
|
+
|
|
2780
|
+
/// Discards the run of writes from earlier wire-session generations at the head of
|
|
2781
|
+
/// the queue in one pass and dequeues the first current one. Stale writes are never
|
|
2782
|
+
/// sent, so they must not each cost a drain tick: a burst of epoch resets would
|
|
2783
|
+
/// otherwise park every current write behind seconds of dead entries.
|
|
2784
|
+
func dequeue(currentGeneration: Int) -> (command: PendingMessage?, staleIds: [String]) {
|
|
2785
|
+
let firstCurrent = commands.firstIndex { $0.generation == currentGeneration } ?? commands.endIndex
|
|
2786
|
+
let staleIds = commands[..<firstCurrent].map(\.id)
|
|
2787
|
+
commands.removeSubrange(..<firstCurrent)
|
|
2788
|
+
return (commands.isEmpty ? nil : commands.removeFirst(), staleIds)
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2759
2791
|
func removeAll() {
|
|
2760
2792
|
commands.removeAll()
|
|
2761
2793
|
}
|
|
@@ -2768,21 +2800,25 @@ class MentraLive: NSObject, SGCManager {
|
|
|
2768
2800
|
guard let self else { return }
|
|
2769
2801
|
while true {
|
|
2770
2802
|
let pendingIsNil = await MainActor.run { self.pending == nil }
|
|
2771
|
-
if pendingIsNil {
|
|
2772
|
-
|
|
2773
|
-
let currentGeneration = await MainActor.run { self.wireSessionGeneration }
|
|
2774
|
-
if command.generation != currentGeneration {
|
|
2775
|
-
Bridge.log("LIVE: Dropping stale queued write from a previous session epoch (id: \(command.id))")
|
|
2776
|
-
} else {
|
|
2777
|
-
await self.processSendQueue(command)
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2803
|
+
if pendingIsNil, let command = await self.dequeueCurrentGenerationWrite() {
|
|
2804
|
+
await self.processSendQueue(command)
|
|
2780
2805
|
}
|
|
2781
2806
|
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
|
|
2782
2807
|
}
|
|
2783
2808
|
}
|
|
2784
2809
|
}
|
|
2785
2810
|
|
|
2811
|
+
private func dequeueCurrentGenerationWrite() -> PendingMessage? {
|
|
2812
|
+
let next = commandQueue.dequeue(currentGeneration: wireSessionGeneration)
|
|
2813
|
+
if !next.staleIds.isEmpty {
|
|
2814
|
+
Bridge.log(
|
|
2815
|
+
"LIVE: Dropping \(next.staleIds.count) stale queued write(s) from a previous session epoch " +
|
|
2816
|
+
"(ids: \(next.staleIds.joined(separator: ", ")))"
|
|
2817
|
+
)
|
|
2818
|
+
}
|
|
2819
|
+
return next.command
|
|
2820
|
+
}
|
|
2821
|
+
|
|
2786
2822
|
private func processSendQueue(_ message: PendingMessage) async {
|
|
2787
2823
|
guard let peripheral = connectedPeripheral,
|
|
2788
2824
|
let txChar = txCharacteristic
|
|
@@ -3383,6 +3419,16 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3383
3419
|
Bridge.log("LIVE: Ignoring stale glasses_ready during pairing pause")
|
|
3384
3420
|
return
|
|
3385
3421
|
}
|
|
3422
|
+
let sid = (json["sid"] as? String).flatMap { $0.isEmpty ? nil : $0 }
|
|
3423
|
+
let readyId = (json["readyId"] as? String).flatMap { $0.isEmpty ? nil : $0 }
|
|
3424
|
+
if let readyId, isRepeatedGlassesReady(readyId: readyId, sid: sid) {
|
|
3425
|
+
Bridge.log("LIVE: Ignoring repeated glasses_ready for readiness exchange \(readyId) - the glasses did not reset for it")
|
|
3426
|
+
return
|
|
3427
|
+
}
|
|
3428
|
+
if readyId != nil, readyId == pendingReadyId {
|
|
3429
|
+
pendingReadyId = nil
|
|
3430
|
+
}
|
|
3431
|
+
readyGlassesSessionId = sid
|
|
3386
3432
|
// glasses_ready is a REMOTE wire-session reset: the glasses ran
|
|
3387
3433
|
// onTransportReset() before sending it, so their side is back on legacy
|
|
3388
3434
|
// framing regardless of what this side negotiated earlier. Start a fresh
|
|
@@ -3394,7 +3440,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3394
3440
|
// Record the session id BEFORE marking ready: an unsolicited glasses_ready
|
|
3395
3441
|
// already runs this full remote-reset flow, so recording (not re-triggering)
|
|
3396
3442
|
// is correct here; version_info detection covers the restart case.
|
|
3397
|
-
glassesSessionId =
|
|
3443
|
+
glassesSessionId = sid
|
|
3398
3444
|
streamControlVersion = json["streamControlVersion"] as? Int ?? 0
|
|
3399
3445
|
Bridge.sendTypedMessage(
|
|
3400
3446
|
"wifi_protocol_session_ready",
|
|
@@ -3730,6 +3776,11 @@ class MentraLive: NSObject, SGCManager {
|
|
|
3730
3776
|
Bridge.log("LIVE: 📱 Received ota_start_ack from glasses")
|
|
3731
3777
|
Bridge.sendOtaStartAck()
|
|
3732
3778
|
|
|
3779
|
+
case "bes_crash_detected", "bes_crash_reported_ack":
|
|
3780
|
+
let ok = json["ok"].map { "\($0)" } ?? "-"
|
|
3781
|
+
Bridge.log("LIVE: \(type) incidentKey=\(json["incidentKey"] as? String ?? "") state=\(json["state"] as? String ?? "-") ok=\(ok)")
|
|
3782
|
+
Bridge.sendTypedMessage(type, body: json)
|
|
3783
|
+
|
|
3733
3784
|
case "ota_status":
|
|
3734
3785
|
// Short keys (sid/ts/cs/st/sq/sp/op/err) are used by new firmware to keep BLE payload small.
|
|
3735
3786
|
// Verbose keys (session_id/total_steps/…) are the fallback for older firmware.
|
|
@@ -4054,12 +4105,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
4054
4105
|
// This prevents re-initialization on every heartbeat after initial connection
|
|
4055
4106
|
// The ready flag is reset on disconnect/reconnect, so this won't prevent proper reconnection
|
|
4056
4107
|
if !fullyBooted {
|
|
4057
|
-
|
|
4058
|
-
"type": "phone_ready",
|
|
4059
|
-
"timestamp": Int64(Date().timeIntervalSince1970 * 1000),
|
|
4060
|
-
]
|
|
4061
|
-
// Send it through our data channel
|
|
4062
|
-
sendJson(readyMsg, wakeUp: true)
|
|
4108
|
+
sendPhoneReady(reason: "SOC ready")
|
|
4063
4109
|
}
|
|
4064
4110
|
}
|
|
4065
4111
|
}
|
|
@@ -4476,12 +4522,14 @@ class MentraLive: NSObject, SGCManager {
|
|
|
4476
4522
|
}
|
|
4477
4523
|
let bKey = MentraLive.incidentBleFileBase(incidentId: incidentId, prefix: "B")
|
|
4478
4524
|
let lKey = MentraLive.incidentBleFileBase(incidentId: incidentId, prefix: "L")
|
|
4479
|
-
|
|
4480
|
-
|
|
4525
|
+
let now = incidentRelayClock()
|
|
4526
|
+
let bRelay = BleIncidentLogRelayEntry(
|
|
4527
|
+
fileBaseKey: bKey, incidentId: incidentId, apiBaseUrl: base, kind: .firmware, reservedAt: now
|
|
4481
4528
|
)
|
|
4482
|
-
|
|
4483
|
-
fileBaseKey: lKey, incidentId: incidentId, apiBaseUrl: base, kind: .logcat
|
|
4529
|
+
let lRelay = BleIncidentLogRelayEntry(
|
|
4530
|
+
fileBaseKey: lKey, incidentId: incidentId, apiBaseUrl: base, kind: .logcat, reservedAt: now
|
|
4484
4531
|
)
|
|
4532
|
+
try reserveIncidentRelays([bRelay, lRelay], now: now)
|
|
4485
4533
|
|
|
4486
4534
|
let auth: [String: Any] = [
|
|
4487
4535
|
"type": "auth_token", "coreToken": coreToken,
|
|
@@ -4492,13 +4540,56 @@ class MentraLive: NSObject, SGCManager {
|
|
|
4492
4540
|
sendJson(["type": "upload_incident_logs", "incidentId": incidentId, "apiBaseUrl": base],
|
|
4493
4541
|
wakeUp: true, requireAck: true, bridgeLogging: true)
|
|
4494
4542
|
else {
|
|
4495
|
-
|
|
4496
|
-
|
|
4543
|
+
releaseIncidentRelay(bRelay)
|
|
4544
|
+
releaseIncidentRelay(lRelay)
|
|
4497
4545
|
throw BluetoothSdkError(code: "incident_dispatch_failed", message: "Could not queue the glasses incident-log request.")
|
|
4498
4546
|
}
|
|
4499
4547
|
Bridge.log("LIVE: Queued incidentId to glasses for log upload: \(incidentId) (BLE relay \(bKey), \(lKey))")
|
|
4500
4548
|
}
|
|
4501
4549
|
|
|
4550
|
+
/// The 16-character relay file names keep only 15 characters of the report id, so two reports
|
|
4551
|
+
/// can share them. A received file goes to the report registered under its name; refuse a
|
|
4552
|
+
/// second report until the owner's Cloud POST is confirmed or its ownership expires.
|
|
4553
|
+
private func reserveIncidentRelays(_ relays: [BleIncidentLogRelayEntry], now: TimeInterval) throws {
|
|
4554
|
+
for relay in relays {
|
|
4555
|
+
if let owner = bleIncidentLogRelays[relay.fileBaseKey],
|
|
4556
|
+
owner.incidentId != relay.incidentId,
|
|
4557
|
+
now - owner.reservedAt < MentraLive.incidentRelayOwnershipSeconds
|
|
4558
|
+
{
|
|
4559
|
+
throw BluetoothSdkError(
|
|
4560
|
+
code: "incident_relay_busy",
|
|
4561
|
+
message: "BLE relay \(relay.fileBaseKey) is still owned by report \(owner.incidentId)."
|
|
4562
|
+
)
|
|
4563
|
+
}
|
|
4564
|
+
}
|
|
4565
|
+
for relay in relays {
|
|
4566
|
+
bleIncidentLogRelays[relay.fileBaseKey] = relay
|
|
4567
|
+
}
|
|
4568
|
+
}
|
|
4569
|
+
|
|
4570
|
+
private func releaseIncidentRelay(_ relay: BleIncidentLogRelayEntry) {
|
|
4571
|
+
if bleIncidentLogRelays[relay.fileBaseKey] === relay {
|
|
4572
|
+
bleIncidentLogRelays.removeValue(forKey: relay.fileBaseKey)
|
|
4573
|
+
}
|
|
4574
|
+
}
|
|
4575
|
+
|
|
4576
|
+
func sendBesCrashReported(incidentKey: String, reportId: String) throws {
|
|
4577
|
+
guard incidentLogTransportReady else {
|
|
4578
|
+
throw BluetoothSdkError(code: "glasses_not_connected", message: "Cannot report the BES crash because the glasses BLE link is not ready.")
|
|
4579
|
+
}
|
|
4580
|
+
guard sendJson(["type": "bes_crash_reported", "incidentKey": incidentKey, "reportId": reportId],
|
|
4581
|
+
wakeUp: true, requireAck: true, bridgeLogging: true)
|
|
4582
|
+
else {
|
|
4583
|
+
throw BluetoothSdkError(code: "bes_crash_dispatch_failed", message: "Could not queue bes_crash_reported to the glasses.")
|
|
4584
|
+
}
|
|
4585
|
+
Bridge.log("LIVE: Queued bes_crash_reported incidentKey=\(incidentKey) reportId=\(reportId)")
|
|
4586
|
+
}
|
|
4587
|
+
|
|
4588
|
+
static func isIncidentRelayFileName(_ fileName: String) -> Bool {
|
|
4589
|
+
guard fileName.count == 16, let first = fileName.first, first == "B" || first == "L" else { return false }
|
|
4590
|
+
return fileName.dropFirst().allSatisfy { ("a" ... "z").contains($0) || ("0" ... "9").contains($0) || $0 == "_" }
|
|
4591
|
+
}
|
|
4592
|
+
|
|
4502
4593
|
private static func incidentBleFileBase(incidentId: String, prefix: Character) -> String {
|
|
4503
4594
|
var compact = incidentId.replacingOccurrences(of: "-", with: "").lowercased()
|
|
4504
4595
|
if compact.count < 15 {
|
|
@@ -4670,6 +4761,20 @@ class MentraLive: NSObject, SGCManager {
|
|
|
4670
4761
|
|
|
4671
4762
|
// MARK: - Message Handlers
|
|
4672
4763
|
|
|
4764
|
+
/// A glasses_ready that echoes a readyId answers a phone_ready exchange. The answer to the
|
|
4765
|
+
/// exchange the phone is waiting on, and any answer from a glasses process other than the
|
|
4766
|
+
/// one this link last handled (an asg restart resets for every exchange it first sees),
|
|
4767
|
+
/// followed a transport reset. Any other answer repeats an exchange that process already
|
|
4768
|
+
/// reset for, or one superseded by the pending exchange, whose answer is still to come.
|
|
4769
|
+
private func isRepeatedGlassesReady(readyId: String, sid: String?) -> Bool {
|
|
4770
|
+
readyId != pendingReadyId && sid == readyGlassesSessionId
|
|
4771
|
+
}
|
|
4772
|
+
|
|
4773
|
+
private func resetReadinessExchange() {
|
|
4774
|
+
pendingReadyId = nil
|
|
4775
|
+
readyGlassesSessionId = nil
|
|
4776
|
+
}
|
|
4777
|
+
|
|
4673
4778
|
private func handleGlassesReady() {
|
|
4674
4779
|
pairFlow(
|
|
4675
4780
|
"glasses_ready",
|
|
@@ -5312,6 +5417,15 @@ class MentraLive: NSObject, SGCManager {
|
|
|
5312
5417
|
if sess.isComplete {
|
|
5313
5418
|
Bridge.log("LIVE: 📦 File transfer complete: \(packetInfo.fileName)")
|
|
5314
5419
|
|
|
5420
|
+
if Self.isIncidentRelayFileName(packetInfo.fileName) {
|
|
5421
|
+
// No relay registered (e.g. the app restarted mid-relay): nothing reached
|
|
5422
|
+
// Cloud, so success would make the glasses mark the incident uploaded.
|
|
5423
|
+
Bridge.log("LIVE: Incident log relay without a registered report: \(packetInfo.fileName)")
|
|
5424
|
+
sendTransferCompleteConfirmation(fileName: packetInfo.fileName, success: false)
|
|
5425
|
+
activeFileTransfers.removeValue(forKey: packetInfo.fileName)
|
|
5426
|
+
return
|
|
5427
|
+
}
|
|
5428
|
+
|
|
5315
5429
|
if let fileData = sess.assembleFile() {
|
|
5316
5430
|
saveReceivedFile(
|
|
5317
5431
|
fileName: packetInfo.fileName, fileData: fileData,
|
|
@@ -5413,7 +5527,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
5413
5527
|
]
|
|
5414
5528
|
}
|
|
5415
5529
|
|
|
5416
|
-
|
|
5530
|
+
func uploadBleIncidentLogRelay(
|
|
5417
5531
|
relay: BleIncidentLogRelayEntry, fileName: String, data: Data
|
|
5418
5532
|
) {
|
|
5419
5533
|
let token = DeviceStore.shared.get("bluetooth", "core_token") as? String ?? ""
|
|
@@ -5464,14 +5578,24 @@ class MentraLive: NSObject, SGCManager {
|
|
|
5464
5578
|
statusCode = nil
|
|
5465
5579
|
}
|
|
5466
5580
|
DispatchQueue.main.async {
|
|
5581
|
+
// A different report now owns this name (it was admitted after our owner finished),
|
|
5582
|
+
// so a completion here would mark ITS file done. Drop the stale callback.
|
|
5583
|
+
if let owner = self.bleIncidentLogRelays[relay.fileBaseKey], owner.incidentId != relay.incidentId {
|
|
5584
|
+
Bridge.log("LIVE: Dropping stale incident relay callback for \(relay.fileBaseKey)")
|
|
5585
|
+
return
|
|
5586
|
+
}
|
|
5467
5587
|
if ok {
|
|
5468
5588
|
Bridge.log("LIVE: ✅ Incident log BLE relay uploaded (\(relay.kind))")
|
|
5469
|
-
self.bleIncidentLogRelays.removeValue(forKey: relay.fileBaseKey)
|
|
5470
5589
|
} else if let existing = self.bleIncidentLogRelays[relay.fileBaseKey] {
|
|
5471
5590
|
// Keep relay entry for glasses retry after transfer_complete:false.
|
|
5472
5591
|
existing.session = nil
|
|
5473
5592
|
}
|
|
5474
5593
|
self.sendTransferCompleteConfirmation(fileName: fileName, success: ok)
|
|
5594
|
+
// Release only after the glasses' confirmation is queued, so a report that reuses
|
|
5595
|
+
// this name is ordered behind the owner's completion.
|
|
5596
|
+
if ok {
|
|
5597
|
+
self.releaseIncidentRelay(relay)
|
|
5598
|
+
}
|
|
5475
5599
|
}
|
|
5476
5600
|
}.resume()
|
|
5477
5601
|
}
|
|
@@ -6674,12 +6798,13 @@ class MentraLive: NSObject, SGCManager {
|
|
|
6674
6798
|
)
|
|
6675
6799
|
// requestReadyK900()
|
|
6676
6800
|
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
]
|
|
6681
|
-
|
|
6682
|
-
|
|
6801
|
+
// The timer fires on bluetoothQueue; the pending readiness exchange is main-actor state.
|
|
6802
|
+
// A tick queued just before glasses_ready stopped the loop must not start a new exchange.
|
|
6803
|
+
let check = self.readinessCheckCounter
|
|
6804
|
+
DispatchQueue.main.async { [weak self] in
|
|
6805
|
+
guard let self, self.readinessCheckDispatchTimer != nil else { return }
|
|
6806
|
+
self.sendPhoneReady(reason: "readiness check #\(check)")
|
|
6807
|
+
}
|
|
6683
6808
|
}
|
|
6684
6809
|
|
|
6685
6810
|
readinessCheckDispatchTimer!.resume()
|
|
@@ -6959,6 +7084,7 @@ class MentraLive: NSObject, SGCManager {
|
|
|
6959
7084
|
// Stop all timers
|
|
6960
7085
|
stopAllTimers()
|
|
6961
7086
|
resetWireNegotiationState()
|
|
7087
|
+
resetReadinessExchange()
|
|
6962
7088
|
commandQueue.removeAll() // stale writes die with the session
|
|
6963
7089
|
closeL2capFileChannel()
|
|
6964
7090
|
|
|
@@ -7174,11 +7300,16 @@ extension MentraLive {
|
|
|
7174
7300
|
|
|
7175
7301
|
/// Sends phone_ready to (re)start the glasses-driven readiness flow.
|
|
7176
7302
|
private func sendPhoneReady(reason: String) {
|
|
7303
|
+
let readyId = pendingReadyId ?? UUID().uuidString
|
|
7304
|
+
pendingReadyId = readyId
|
|
7177
7305
|
pairFlow("phone_ready", "reason=\(reason) gatt=\(txCharacteristic != nil) id=\(connectedPeripheral?.identifier.uuidString ?? "-")")
|
|
7178
|
-
Bridge.log(
|
|
7306
|
+
Bridge.log(
|
|
7307
|
+
"LIVE: 📱 Sending phone_ready to glasses (\(reason), exchange \(readyId)) - waiting for glasses_ready response"
|
|
7308
|
+
)
|
|
7179
7309
|
let readyMsg: [String: Any] = [
|
|
7180
7310
|
"type": "phone_ready",
|
|
7181
7311
|
"timestamp": Int64(Date().timeIntervalSince1970 * 1000),
|
|
7312
|
+
"readyId": readyId,
|
|
7182
7313
|
]
|
|
7183
7314
|
sendJson(readyMsg, wakeUp: true)
|
|
7184
7315
|
}
|