@glassly/bluetooth-sdk 0.1.0-dev.26
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 +563 -0
- package/android/build.gradle +450 -0
- package/android/gradle.properties.example +9 -0
- package/android/lc3Lib/CMakeLists.txt +6 -0
- package/android/lc3Lib/build.gradle +212 -0
- package/android/lc3Lib/proguard-rules.pro +33 -0
- package/android/lc3Lib/src/main/AndroidManifest.xml +2 -0
- package/android/lc3Lib/src/main/cpp/CMakeLists.txt +8 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/CMakeLists.txt +30 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/CMakeLists.txt +7 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.cc +96 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.h +53 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/Makefile.am +6 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h.in +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/ogg.h +209 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/os_types.h +158 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus.h +981 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_custom.h +342 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_defines.h +799 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_multistream.h +660 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_projection.h +568 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_types.h +166 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.cc +268 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.h +115 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/opus_tools/opus_header.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/CMakeLists.txt +38 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3.h +309 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3_private.h +162 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/rnnoise.h +114 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/CMakeLists.txt +19 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.c +92 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.h +44 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.c +375 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.h +315 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.c +129 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/common.h +148 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.c +70 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.h +43 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/fastmath.h +158 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/lc3.c +702 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.c +893 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.h +111 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_arm.h +506 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_neon.h +281 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/makefile.mk +35 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.c +452 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct_neon.h +296 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/meson.build +46 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.c +61 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.c +880 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.h +103 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.c +904 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.h +119 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.c +3457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.h +94 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.c +457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.h +99 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3.cpp +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/_kiss_fft_guts.h +182 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/arch.h +261 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.c +279 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/common.h +48 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/compile.sh +3 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/denoise.c +646 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.c +601 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.h +203 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/opus_types.h +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.c +526 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.h +149 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.c +178 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.c +11051 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.h +34 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_reader.c +168 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_train.py +66 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/tansig_table.h +45 -0
- package/android/lc3Lib/src/main/java/com/glassly/lc3Lib/Lc3Cpp.java +38 -0
- package/android/lc3Lib/third_party/CMakeLists.txt +23 -0
- package/android/lc3Lib/third_party/CMakeLists_libogg.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_libopus.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_opus-tools.txt +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/AUTHORS +5 -0
- package/android/lc3Lib/third_party/opus_tools/src/CMakeLists.txt +4 -0
- package/android/lc3Lib/third_party/opus_tools/src/COPYING +371 -0
- package/android/lc3Lib/third_party/opus_tools/src/ChangeLog +3 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.am +42 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.unix +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/NEWS +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/README +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/autogen.sh +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/configure.ac +293 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/arch.h +239 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/audio-in.c +1046 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.c +245 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.h +28 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.c +320 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.c +157 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.h +27 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.c +286 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.h +59 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusdec.c +884 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.c +1021 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.h +101 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.c +639 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/os_support.h +167 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/resample.c +1137 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/speex_resampler.h +344 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/stack_alloc.h +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.c +125 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.h +62 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.c +223 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.h +60 -0
- package/android/settings.gradle +4 -0
- package/android/silero/LICENSE.md +17 -0
- package/android/silero/build.gradle +50 -0
- package/android/silero/proguard-rules.pro +24 -0
- package/android/silero/src/androidTest/assets/hello.wav +0 -0
- package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +79 -0
- package/android/silero/src/main/assets/LICENSE +21 -0
- package/android/silero/src/main/assets/silero_vad.onnx +0 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +160 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +449 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +15 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +14 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +12 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +47 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +41 -0
- package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +44 -0
- package/android/src/main/AndroidManifest.xml +42 -0
- package/android/src/main/assets/G2Firmware/README.md +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdk.kt +2325 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkAnalytics.kt +216 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDebug.kt +14 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDefaults.kt +7 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkModule.kt +1088 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/Bridge.kt +953 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/DeviceManager.kt +2528 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/DeviceStore.kt +360 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedChangelogCatalog.kt +8 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedReleaseMetadata.kt +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/LocalNetworkModule.kt +414 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ObservableStore.kt +88 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/OtaManifest.kt +191 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ReleaseChangelog.kt +61 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ScopedNetworkReadiness.kt +17 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/audio/AudioModels.kt +144 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/camera/CameraModels.kt +486 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/connection/ConnectionModels.kt +78 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/controllers/ControllerManager.kt +158 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/controllers/R1.kt +937 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/debug/BleTraceLogger.kt +165 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/events/BluetoothEvents.kt +178 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/internal/MapParsing.kt +140 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/net/LocalIpv4.kt +57 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServer.kt +304 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/OtaServerModule.kt +120 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistry.java +108 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoUploadServer.kt +622 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/PhotoReceiverModule.kt +156 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/requests/DisplayRequests.kt +56 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/services/Foreground.kt +272 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/services/PhoneMic.kt +1195 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Ar99.java +2653 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuard.kt +49 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapper.kt +27 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1.kt +3878 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizer.kt +38 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2.kt +6428 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassification.kt +49 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwRenderer.kt +1241 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCache.kt +270 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocol.kt +291 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2Flasher.kt +411 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/GlasslyBle.java +43189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Mach1.kt +1280 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLive.kt +10817 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLiveL2capChannel.kt +274 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +54 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraNex.kt +2011 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Nimo.kt +2532 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/SGCManager.kt +470 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Simulated.kt +228 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/Ar99OtaManager.java +566 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaByteUtils.java +18 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCommandConstants.java +35 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCrc32Util.java +13 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaGattTransport.java +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaProtocol.java +92 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/speakerid/SpeakerIdEngine.kt +525 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/DeviceStatus.kt +669 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/RuntimeState.kt +201 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/WifiHotspotStatus.kt +189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/streaming/StreamModels.kt +518 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/STTTools.kt +391 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +518 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/VadGateSpeechPolicy.kt +229 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/tts/TTSTools.kt +248 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/types/DeviceModels.kt +96 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AES.java +106 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AvifExifStripper.java +573 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleJsonCompact.java +496 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadService.java +677 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleWireProtocol.java +108 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/Constants.kt +46 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/G1Text.kt +436 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/HeifExifTagReader.java +199 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleUploadService.java +77 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900LengthCodec.java +115 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtils.java +827 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunkReassembler.java +228 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunker.java +325 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/NexSGCUtils.kt +698 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitor.kt +348 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Ar99OpusPcmDecoder.java +398 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +328 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/BluetoothSdkExceptionTest.kt +18 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/OtaManifestDowngradeTest.kt +86 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/OtaStartResponsePolicyTest.kt +30 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/ReleaseChangelogTest.kt +13 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/ScopedNetworkReadinessTest.kt +39 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/StreamStatusEventTest.kt +29 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/camera/PhotoRequestTest.kt +141 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServerTest.kt +82 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistryTest.java +75 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/services/ForegroundServiceTypeTest.kt +69 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/Ar99AdvertisementMatcherTest.java +22 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuardTest.kt +73 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapperTest.kt +67 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/EvenRleTest.kt +63 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizerTest.kt +31 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassificationTest.kt +89 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwRendererTest.kt +344 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCacheTest.kt +200 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocolTest.kt +131 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLiveGattCharacteristicsTest.kt +39 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +133 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/NimoProtocolTest.kt +333 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/AvifExifStripperTest.java +46 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BinaryMessageChunkerTest.java +84 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BleJsonCompactTest.java +319 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadServiceTest.java +107 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsEndiannessTest.java +172 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsTest.java +24 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitorTest.kt +45 -0
- package/android/src/test/resources/avif_with_exif.avif +0 -0
- package/app.plugin.js +3 -0
- package/build/BluetoothSdk.types.d.ts +1354 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -0
- package/build/BluetoothSdk.types.js +41 -0
- package/build/BluetoothSdk.types.js.map +1 -0
- package/build/_internal.d.ts +17 -0
- package/build/_internal.d.ts.map +1 -0
- package/build/_internal.js +16 -0
- package/build/_internal.js.map +1 -0
- package/build/_private/BluetoothSdkModule.d.ts +172 -0
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -0
- package/build/_private/BluetoothSdkModule.js +300 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -0
- package/build/_private/LocalNetworkModule.d.ts +38 -0
- package/build/_private/LocalNetworkModule.d.ts.map +1 -0
- package/build/_private/LocalNetworkModule.js +3 -0
- package/build/_private/LocalNetworkModule.js.map +1 -0
- package/build/_private/cameraRequestPayload.d.ts +4 -0
- package/build/_private/cameraRequestPayload.d.ts.map +1 -0
- package/build/_private/cameraRequestPayload.js +32 -0
- package/build/_private/cameraRequestPayload.js.map +1 -0
- package/build/_private/photoRequestPayload.d.ts +6 -0
- package/build/_private/photoRequestPayload.d.ts.map +1 -0
- package/build/_private/photoRequestPayload.js +86 -0
- package/build/_private/photoRequestPayload.js.map +1 -0
- package/build/_private/sdkOtaManifest.d.ts +11 -0
- package/build/_private/sdkOtaManifest.d.ts.map +1 -0
- package/build/_private/sdkOtaManifest.js +15 -0
- package/build/_private/sdkOtaManifest.js.map +1 -0
- package/build/changelogs.d.ts +7 -0
- package/build/changelogs.d.ts.map +1 -0
- package/build/changelogs.js +46 -0
- package/build/changelogs.js.map +1 -0
- package/build/debug.d.ts +3 -0
- package/build/debug.d.ts.map +1 -0
- package/build/debug.js +8 -0
- package/build/debug.js.map +1 -0
- package/build/generated/changelogCatalog.d.ts +9 -0
- package/build/generated/changelogCatalog.d.ts.map +1 -0
- package/build/generated/changelogCatalog.js +12 -0
- package/build/generated/changelogCatalog.js.map +1 -0
- package/build/generated/releaseMetadata.d.ts +12 -0
- package/build/generated/releaseMetadata.d.ts.map +1 -0
- package/build/generated/releaseMetadata.js +10 -0
- package/build/generated/releaseMetadata.js.map +1 -0
- package/build/index.d.ts +6 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +171 -0
- package/build/index.js.map +1 -0
- package/build/ota-server/OtaServer.types.d.ts +14 -0
- package/build/ota-server/OtaServer.types.d.ts.map +1 -0
- package/build/ota-server/OtaServer.types.js +2 -0
- package/build/ota-server/OtaServer.types.js.map +1 -0
- package/build/ota-server/OtaServerModule.d.ts +21 -0
- package/build/ota-server/OtaServerModule.d.ts.map +1 -0
- package/build/ota-server/OtaServerModule.js +3 -0
- package/build/ota-server/OtaServerModule.js.map +1 -0
- package/build/ota-server/OtaServerModule.web.d.ts +10 -0
- package/build/ota-server/OtaServerModule.web.d.ts.map +1 -0
- package/build/ota-server/OtaServerModule.web.js +12 -0
- package/build/ota-server/OtaServerModule.web.js.map +1 -0
- package/build/ota-server/index.d.ts +3 -0
- package/build/ota-server/index.d.ts.map +1 -0
- package/build/ota-server/index.js +3 -0
- package/build/ota-server/index.js.map +1 -0
- package/build/ota-transport/index.d.ts +67 -0
- package/build/ota-transport/index.d.ts.map +1 -0
- package/build/ota-transport/index.js +58 -0
- package/build/ota-transport/index.js.map +1 -0
- package/build/photo-receiver/PhotoReceiver.types.d.ts +18 -0
- package/build/photo-receiver/PhotoReceiver.types.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiver.types.js +2 -0
- package/build/photo-receiver/PhotoReceiver.types.js.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.d.ts +10 -0
- package/build/photo-receiver/PhotoReceiverModule.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.js +3 -0
- package/build/photo-receiver/PhotoReceiverModule.js.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.web.d.ts +10 -0
- package/build/photo-receiver/PhotoReceiverModule.web.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.web.js +12 -0
- package/build/photo-receiver/PhotoReceiverModule.web.js.map +1 -0
- package/build/photo-receiver/index.d.ts +3 -0
- package/build/photo-receiver/index.d.ts.map +1 -0
- package/build/photo-receiver/index.js +3 -0
- package/build/photo-receiver/index.js.map +1 -0
- package/build/react/index.d.ts +5 -0
- package/build/react/index.d.ts.map +1 -0
- package/build/react/index.js +4 -0
- package/build/react/index.js.map +1 -0
- package/build/react/useBluetooth.d.ts +100 -0
- package/build/react/useBluetooth.d.ts.map +1 -0
- package/build/react/useBluetooth.js +167 -0
- package/build/react/useBluetooth.js.map +1 -0
- package/build/react/useBluetoothEvent.d.ts +6 -0
- package/build/react/useBluetoothEvent.d.ts.map +1 -0
- package/build/react/useBluetoothEvent.js +21 -0
- package/build/react/useBluetoothEvent.js.map +1 -0
- package/build/react/useBluetoothScan.d.ts +22 -0
- package/build/react/useBluetoothScan.d.ts.map +1 -0
- package/build/react/useBluetoothScan.js +135 -0
- package/build/react/useBluetoothScan.js.map +1 -0
- package/build/react/useBluetoothStatus.d.ts +16 -0
- package/build/react/useBluetoothStatus.d.ts.map +1 -0
- package/build/react/useBluetoothStatus.js +137 -0
- package/build/react/useBluetoothStatus.js.map +1 -0
- package/build/react/useGlassesConnection.d.ts +29 -0
- package/build/react/useGlassesConnection.d.ts.map +1 -0
- package/build/react/useGlassesConnection.js +153 -0
- package/build/react/useGlassesConnection.js.map +1 -0
- package/build/types/index.d.ts +3 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +2 -0
- package/build/types/index.js.map +1 -0
- package/expo-module.config.json +14 -0
- package/ios/BackgroundOtaArtifactDownloader.swift +125 -0
- package/ios/BluetoothSdkModule.swift +1034 -0
- package/ios/GlasslyBluetoothSDK.podspec +106 -0
- package/ios/LocalIPv4.swift +150 -0
- package/ios/LocalOtaServer.swift +309 -0
- package/ios/LocalPhotoUploadServer.swift +754 -0
- package/ios/OtaServerModule.swift +147 -0
- package/ios/Packages/CoreObjC/CoreObjC.xcodeproj/project.pbxproj +213 -0
- package/ios/Packages/CoreObjC/PcmConverter.h +22 -0
- package/ios/Packages/CoreObjC/PcmConverter.m +266 -0
- package/ios/Packages/CoreObjC/attdet.c +92 -0
- package/ios/Packages/CoreObjC/attdet.h +44 -0
- package/ios/Packages/CoreObjC/bits.c +375 -0
- package/ios/Packages/CoreObjC/bits.h +315 -0
- package/ios/Packages/CoreObjC/bwdet.c +129 -0
- package/ios/Packages/CoreObjC/bwdet.h +69 -0
- package/ios/Packages/CoreObjC/common.h +151 -0
- package/ios/Packages/CoreObjC/energy.c +70 -0
- package/ios/Packages/CoreObjC/energy.h +43 -0
- package/ios/Packages/CoreObjC/fastmath.h +158 -0
- package/ios/Packages/CoreObjC/include/PcmConverter.h +22 -0
- package/ios/Packages/CoreObjC/lc3.c +704 -0
- package/ios/Packages/CoreObjC/lc3.h +313 -0
- package/ios/Packages/CoreObjC/lc3_cpp.h +283 -0
- package/ios/Packages/CoreObjC/lc3_private.h +163 -0
- package/ios/Packages/CoreObjC/ltpf.c +905 -0
- package/ios/Packages/CoreObjC/ltpf.h +111 -0
- package/ios/Packages/CoreObjC/ltpf_arm.h +506 -0
- package/ios/Packages/CoreObjC/ltpf_neon.h +281 -0
- package/ios/Packages/CoreObjC/makefile.mk +35 -0
- package/ios/Packages/CoreObjC/mdct.c +469 -0
- package/ios/Packages/CoreObjC/mdct.h +57 -0
- package/ios/Packages/CoreObjC/mdct_neon.h +296 -0
- package/ios/Packages/CoreObjC/meson.build +61 -0
- package/ios/Packages/CoreObjC/plc.c +61 -0
- package/ios/Packages/CoreObjC/plc.h +57 -0
- package/ios/Packages/CoreObjC/rnnoise.h +114 -0
- package/ios/Packages/CoreObjC/sns.c +880 -0
- package/ios/Packages/CoreObjC/sns.h +103 -0
- package/ios/Packages/CoreObjC/spec.c +907 -0
- package/ios/Packages/CoreObjC/spec.h +119 -0
- package/ios/Packages/CoreObjC/tables.c +3457 -0
- package/ios/Packages/CoreObjC/tables.h +94 -0
- package/ios/Packages/CoreObjC/tns.c +457 -0
- package/ios/Packages/CoreObjC/tns.h +99 -0
- package/ios/Packages/SherpaOnnx/Model/joiner.onnx +0 -0
- package/ios/Packages/SherpaOnnx/Model/tokens.txt +502 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +2383 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +48 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
- package/ios/Packages/libbz2/module.modulemap +5 -0
- package/ios/Packages/libbz2/shim.h +1 -0
- package/ios/PhotoReceiverModule.swift +129 -0
- package/ios/Source/BluetoothSDK.swift +2303 -0
- package/ios/Source/BluetoothSDKDebug.swift +12 -0
- package/ios/Source/BluetoothSdkDefaults.swift +29 -0
- package/ios/Source/Bridge.swift +708 -0
- package/ios/Source/Bridging-Header.h +16 -0
- package/ios/Source/DeviceManager.swift +2109 -0
- package/ios/Source/DeviceStore.swift +336 -0
- package/ios/Source/GeneratedChangelogCatalog.swift +7 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +11 -0
- package/ios/Source/ObservableStore.swift +118 -0
- package/ios/Source/OtaManifest.swift +211 -0
- package/ios/Source/PrivacyInfo.xcprivacy +23 -0
- package/ios/Source/ReleaseChangelog.swift +65 -0
- package/ios/Source/Resources/G2Firmware/README.md +10 -0
- package/ios/Source/audio/AudioModels.swift +178 -0
- package/ios/Source/audio/PcmStreamPlayer.swift +410 -0
- package/ios/Source/camera/CameraModels.swift +866 -0
- package/ios/Source/connection/ScanSession.swift +27 -0
- package/ios/Source/controllers/ControllerManager.swift +184 -0
- package/ios/Source/controllers/R1.swift +829 -0
- package/ios/Source/errors/BluetoothSdkError.swift +19 -0
- package/ios/Source/events/BluetoothEvents.swift +342 -0
- package/ios/Source/internal/BleTraceLogger.swift +192 -0
- package/ios/Source/internal/BluetoothAvailability.swift +78 -0
- package/ios/Source/internal/BluetoothSdkAnalytics.swift +199 -0
- package/ios/Source/internal/ValueParsing.swift +99 -0
- package/ios/Source/requests/DisplayRequests.swift +82 -0
- package/ios/Source/services/PhoneMic.swift +662 -0
- package/ios/Source/sgcs/Ar99.swift +2451 -0
- package/ios/Source/sgcs/Frame.swift +649 -0
- package/ios/Source/sgcs/G1.swift +2554 -0
- package/ios/Source/sgcs/G2.swift +6887 -0
- package/ios/Source/sgcs/G2CfwClassification.swift +43 -0
- package/ios/Source/sgcs/G2CfwRenderer.swift +1279 -0
- package/ios/Source/sgcs/G2CfwTextureCache.swift +233 -0
- package/ios/Source/sgcs/G2FlashProtocol.swift +312 -0
- package/ios/Source/sgcs/G2Flasher.swift +773 -0
- package/ios/Source/sgcs/Mach1.swift +541 -0
- package/ios/Source/sgcs/MentraLive.swift +7011 -0
- package/ios/Source/sgcs/MentraLiveL2capChannel.swift +183 -0
- package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +64 -0
- package/ios/Source/sgcs/MentraNex.swift +3221 -0
- package/ios/Source/sgcs/Nimo.swift +1886 -0
- package/ios/Source/sgcs/SGCManager.swift +608 -0
- package/ios/Source/sgcs/Simulated.swift +274 -0
- package/ios/Source/sgcs/ar99/ota/Ar99OtaManager.swift +637 -0
- package/ios/Source/sgcs/glassly_ble.pb.swift +4354 -0
- package/ios/Source/speakerid/SpeakerIdEngine.swift +573 -0
- package/ios/Source/status/DeviceStatus.swift +981 -0
- package/ios/Source/status/RuntimeState.swift +359 -0
- package/ios/Source/status/WifiHotspotStatus.swift +345 -0
- package/ios/Source/streaming/StreamModels.swift +693 -0
- package/ios/Source/stt/STTTools.swift +191 -0
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +466 -0
- package/ios/Source/tts/TTSTools.swift +171 -0
- package/ios/Source/types/DeviceModels.swift +177 -0
- package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
- package/ios/Source/utils/BinaryCodec.swift +61 -0
- package/ios/Source/utils/BleJsonCompact.swift +405 -0
- package/ios/Source/utils/BleWireProtocol.swift +92 -0
- package/ios/Source/utils/Constants.swift +78 -0
- package/ios/Source/utils/Enums.swift +95 -0
- package/ios/Source/utils/G1Text.swift +2096 -0
- package/ios/Source/utils/JSCExperiment.swift +241 -0
- package/ios/Source/utils/MemoryMonitor.swift +44 -0
- package/ios/Source/utils/MessageChunkReassembler.swift +190 -0
- package/ios/Source/utils/MessageChunker.swift +294 -0
- package/ios/Source/utils/Models.swift +135 -0
- package/ios/Source/utils/PhoneAudioMonitor.swift +230 -0
- package/ios/Source/utils/TarBz2Extractor.swift +257 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwClassificationTests.swift +78 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwRendererTests.swift +372 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwTextureCacheTests.swift +162 -0
- package/ios/Tests/BluetoothSDKTests/G2FlashProtocolTests.swift +182 -0
- package/ios/Tests/MentraLivePairingAdvertisementTests.swift +160 -0
- package/ios/Tests/ReleaseChangelogTests.swift +13 -0
- package/package.json +129 -0
- package/plugin/build/index.d.ts +10 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/withAndroid.d.ts +3 -0
- package/plugin/build/withAndroid.js +190 -0
- package/plugin/build/withIos.d.ts +5 -0
- package/plugin/build/withIos.js +108 -0
- package/scripts/inject-ios-sdk-version.mjs +65 -0
- package/scripts/public-ota-api.test.mjs +37 -0
- package/scripts/verify-release-package.mjs +45 -0
- package/scripts/write-release-metadata.mjs +152 -0
- package/scripts/write-release-metadata.test.mjs +37 -0
- package/src/BluetoothSdk.types.ts +1623 -0
- package/src/_internal.ts +16 -0
- package/src/_private/BluetoothSdkModule.ts +684 -0
- package/src/_private/LocalNetworkModule.ts +50 -0
- package/src/_private/cameraRequestPayload.ts +34 -0
- package/src/_private/photoRequestPayload.ts +90 -0
- package/src/_private/sdkOtaManifest.ts +18 -0
- package/src/changelogs.ts +46 -0
- package/src/debug.ts +9 -0
- package/src/generated/changelogCatalog.ts +13 -0
- package/src/generated/releaseMetadata.ts +20 -0
- package/src/index.ts +321 -0
- package/src/ota-server/OtaServer.types.ts +10 -0
- package/src/ota-server/OtaServerModule.ts +23 -0
- package/src/ota-server/OtaServerModule.web.ts +17 -0
- package/src/ota-server/index.ts +2 -0
- package/src/ota-transport/index.ts +116 -0
- package/src/photo-receiver/PhotoReceiver.types.ts +20 -0
- package/src/photo-receiver/PhotoReceiverModule.ts +11 -0
- package/src/photo-receiver/PhotoReceiverModule.web.ts +17 -0
- package/src/photo-receiver/index.ts +2 -0
- package/src/react/index.ts +21 -0
- package/src/react/useBluetooth.ts +309 -0
- package/src/react/useBluetoothEvent.ts +35 -0
- package/src/react/useBluetoothScan.ts +173 -0
- package/src/react/useBluetoothStatus.ts +180 -0
- package/src/react/useGlassesConnection.ts +202 -0
- package/src/types/index.ts +12 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
public struct BluetoothSdkError: Error, LocalizedError, CustomStringConvertible {
|
|
4
|
+
public let code: String
|
|
5
|
+
public let message: String
|
|
6
|
+
|
|
7
|
+
public init(code: String, message: String) {
|
|
8
|
+
self.code = code
|
|
9
|
+
self.message = message
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public var errorDescription: String? {
|
|
13
|
+
message
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public var description: String {
|
|
17
|
+
"\(code): \(message)"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
public struct ButtonPressEvent: CustomStringConvertible {
|
|
4
|
+
public let buttonId: String
|
|
5
|
+
public let pressType: String
|
|
6
|
+
public let timestamp: Int?
|
|
7
|
+
|
|
8
|
+
public init(buttonId: String, pressType: String, timestamp: Int? = nil) {
|
|
9
|
+
self.buttonId = buttonId
|
|
10
|
+
self.pressType = pressType
|
|
11
|
+
self.timestamp = timestamp
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public var description: String {
|
|
15
|
+
"ButtonPressEvent(buttonId: \(buttonId), pressType: \(pressType))"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public struct TouchEvent: CustomStringConvertible {
|
|
20
|
+
public let values: [String: Any]
|
|
21
|
+
|
|
22
|
+
public init(values: [String: Any]) {
|
|
23
|
+
self.values = values
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public var deviceModel: String? {
|
|
27
|
+
stringValue(values, "deviceModel")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public var gestureName: String? {
|
|
31
|
+
stringValue(values, "gestureName")
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public var timestamp: Int? {
|
|
35
|
+
intValue(values["timestamp"])
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public var isSwipe: Bool {
|
|
39
|
+
gestureName?.localizedCaseInsensitiveContains("swipe") == true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public var description: String {
|
|
43
|
+
"TouchEvent(gestureName: \(gestureName ?? "unknown"))"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public struct VoiceActivityDetectionStatusEvent: CustomStringConvertible {
|
|
48
|
+
public let voiceActivityDetectionEnabled: Bool
|
|
49
|
+
public let values: [String: Any]
|
|
50
|
+
|
|
51
|
+
public init(values: [String: Any]) {
|
|
52
|
+
voiceActivityDetectionEnabled =
|
|
53
|
+
boolValue(values, "voiceActivityDetectionEnabled") ?? BluetoothSdkDefaults.voiceActivityDetectionEnabled
|
|
54
|
+
self.values = values
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public var description: String {
|
|
58
|
+
"VoiceActivityDetectionStatusEvent(voiceActivityDetectionEnabled: \(voiceActivityDetectionEnabled))"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public struct SpeakingStatusEvent: CustomStringConvertible {
|
|
63
|
+
public let speaking: Bool
|
|
64
|
+
public let values: [String: Any]
|
|
65
|
+
|
|
66
|
+
public init(values: [String: Any]) {
|
|
67
|
+
speaking = boolValue(values, "speaking") ?? false
|
|
68
|
+
self.values = values
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public var description: String {
|
|
72
|
+
"SpeakingStatusEvent(speaking: \(speaking))"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public struct MicHealthEvent: CustomStringConvertible {
|
|
77
|
+
public let reason: String
|
|
78
|
+
public let sequenceGapEvents: Int
|
|
79
|
+
public let decodeFailures: Int
|
|
80
|
+
public let lastLc3ReceivedAt: Int?
|
|
81
|
+
public let lastPcmProducedAt: Int?
|
|
82
|
+
public let timestamp: Int
|
|
83
|
+
public let values: [String: Any]
|
|
84
|
+
|
|
85
|
+
public init(values: [String: Any]) {
|
|
86
|
+
reason = stringValue(values, "reason") ?? ""
|
|
87
|
+
sequenceGapEvents = intValue(values["sequenceGapEvents"]) ?? 0
|
|
88
|
+
decodeFailures = intValue(values["decodeFailures"]) ?? 0
|
|
89
|
+
lastLc3ReceivedAt = intValue(values["lastLc3ReceivedAt"])
|
|
90
|
+
lastPcmProducedAt = intValue(values["lastPcmProducedAt"])
|
|
91
|
+
timestamp = intValue(values["timestamp"]) ?? Int(Date().timeIntervalSince1970 * 1000)
|
|
92
|
+
self.values = values
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public var description: String {
|
|
96
|
+
"MicHealthEvent(reason: \(reason), sequenceGapEvents: \(sequenceGapEvents), decodeFailures: \(decodeFailures))"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public struct OtaStartAckEvent: CustomStringConvertible {
|
|
101
|
+
public let timestamp: Int?
|
|
102
|
+
public let values: [String: Any]
|
|
103
|
+
|
|
104
|
+
public init(values: [String: Any]) {
|
|
105
|
+
timestamp = intValue(values["timestamp"])
|
|
106
|
+
self.values = values
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public var description: String {
|
|
110
|
+
"OtaStartAckEvent(timestamp: \(timestamp.map(String.init) ?? "unknown"))"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public struct OtaStatusEvent: CustomStringConvertible {
|
|
115
|
+
public let sessionId: String
|
|
116
|
+
public let totalSteps: Int
|
|
117
|
+
public let currentStep: Int
|
|
118
|
+
public let stepType: String
|
|
119
|
+
public let phase: String
|
|
120
|
+
public let stepPercent: Int
|
|
121
|
+
public let overallPercent: Int
|
|
122
|
+
public let status: String
|
|
123
|
+
public let errorMessage: String?
|
|
124
|
+
public let glassesTimeMs: Int?
|
|
125
|
+
public let values: [String: Any]
|
|
126
|
+
|
|
127
|
+
public init(values: [String: Any]) {
|
|
128
|
+
sessionId = stringValue(values, "session_id") ?? ""
|
|
129
|
+
totalSteps = intValue(values["total_steps"]) ?? 0
|
|
130
|
+
currentStep = intValue(values["current_step"]) ?? 0
|
|
131
|
+
stepType = stringValue(values, "step_type") ?? ""
|
|
132
|
+
phase = stringValue(values, "phase") ?? ""
|
|
133
|
+
stepPercent = intValue(values["step_percent"]) ?? 0
|
|
134
|
+
overallPercent = intValue(values["overall_percent"]) ?? 0
|
|
135
|
+
status = stringValue(values, "status") ?? ""
|
|
136
|
+
errorMessage = stringValue(values, "error_message")
|
|
137
|
+
glassesTimeMs = intValue(values["glasses_time_ms"])
|
|
138
|
+
self.values = values
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public var description: String {
|
|
142
|
+
"OtaStatusEvent(status: \(status), overallPercent: \(overallPercent))"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public struct OtaQueryResult: CustomStringConvertible {
|
|
147
|
+
public let values: [String: Any]
|
|
148
|
+
|
|
149
|
+
public init(values: [String: Any]) {
|
|
150
|
+
self.values = values
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public var type: String {
|
|
154
|
+
stringValue(values, "type") ?? ""
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public var status: String? {
|
|
158
|
+
stringValue(values, "status")
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public var description: String {
|
|
162
|
+
"OtaQueryResult(type: \(type), status: \(status ?? "unknown"))"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public struct SettingsAckEvent: CustomStringConvertible {
|
|
167
|
+
public let values: [String: Any]
|
|
168
|
+
|
|
169
|
+
public init(values: [String: Any]) {
|
|
170
|
+
self.values = values
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public var requestId: String {
|
|
174
|
+
stringValue(values, "requestId") ?? ""
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public var setting: String {
|
|
178
|
+
stringValue(values, "setting") ?? ""
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
public var status: String {
|
|
182
|
+
stringValue(values, "status") ?? "applied"
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
public var timestamp: Int {
|
|
186
|
+
intValue(values["timestamp"]) ?? Int(Date().timeIntervalSince1970 * 1000)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
public var fov: Int? {
|
|
190
|
+
intValue(values["fov"])
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public var roiPosition: Int? {
|
|
194
|
+
intValue(values["roiPosition"]) ?? intValue(values["roi_position"])
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public var hardwareApplied: Bool {
|
|
198
|
+
boolValue(values, "hardwareApplied") ?? boolValue(values, "hardware_applied") ?? false
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public var errorCode: String? {
|
|
202
|
+
stringValue(values, "errorCode")
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
public var errorMessage: String? {
|
|
206
|
+
stringValue(values, "errorMessage")
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public var description: String {
|
|
210
|
+
"SettingsAckEvent(setting: \(setting), status: \(status))"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public struct RgbLedControlResponseEvent: CustomStringConvertible {
|
|
215
|
+
public let values: [String: Any]
|
|
216
|
+
|
|
217
|
+
public init(values: [String: Any]) {
|
|
218
|
+
self.values = values
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public var requestId: String {
|
|
222
|
+
stringValue(values, "requestId") ?? ""
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public var state: String {
|
|
226
|
+
stringValue(values, "state") ?? "error"
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
public var errorCode: String? {
|
|
230
|
+
stringValue(values, "errorCode")
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
public var description: String {
|
|
234
|
+
"RgbLedControlResponseEvent(requestId: \(requestId), state: \(state))"
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
public enum BluetoothEvent: CustomStringConvertible {
|
|
239
|
+
case buttonPress(ButtonPressEvent)
|
|
240
|
+
case touch(TouchEvent)
|
|
241
|
+
case voiceActivityDetectionStatus(VoiceActivityDetectionStatusEvent)
|
|
242
|
+
case speakingStatus(SpeakingStatusEvent)
|
|
243
|
+
case micHealth(MicHealthEvent)
|
|
244
|
+
case wifiStatus(WifiStatusEvent)
|
|
245
|
+
case hotspotStatus(HotspotStatusEvent)
|
|
246
|
+
case hotspotError(HotspotErrorEvent)
|
|
247
|
+
case photoResponse(PhotoResponseEvent)
|
|
248
|
+
case photoStatus(PhotoStatusEvent)
|
|
249
|
+
case cameraStatus(CameraStatusEvent)
|
|
250
|
+
case videoRecordingStatus(VideoRecordingStatusEvent)
|
|
251
|
+
case mediaUpload(MediaUploadEvent)
|
|
252
|
+
case rgbLedControlResponse(RgbLedControlResponseEvent)
|
|
253
|
+
case streamStatus(StreamStatusEvent)
|
|
254
|
+
case keepAliveAck(KeepAliveAckEvent)
|
|
255
|
+
case otaStartAck(OtaStartAckEvent)
|
|
256
|
+
case otaStatus(OtaStatusEvent)
|
|
257
|
+
case settingsAck(SettingsAckEvent)
|
|
258
|
+
case versionInfo(VersionInfoResult)
|
|
259
|
+
case localTranscription(LocalTranscriptionEvent)
|
|
260
|
+
case raw(name: String, values: [String: Any])
|
|
261
|
+
|
|
262
|
+
public var description: String {
|
|
263
|
+
switch self {
|
|
264
|
+
case let .buttonPress(event):
|
|
265
|
+
event.description
|
|
266
|
+
case let .touch(event):
|
|
267
|
+
event.description
|
|
268
|
+
case let .voiceActivityDetectionStatus(event):
|
|
269
|
+
event.description
|
|
270
|
+
case let .speakingStatus(event):
|
|
271
|
+
event.description
|
|
272
|
+
case let .micHealth(event):
|
|
273
|
+
event.description
|
|
274
|
+
case let .wifiStatus(event):
|
|
275
|
+
event.description
|
|
276
|
+
case let .hotspotStatus(event):
|
|
277
|
+
event.description
|
|
278
|
+
case let .hotspotError(event):
|
|
279
|
+
event.description
|
|
280
|
+
case let .photoResponse(event):
|
|
281
|
+
event.description
|
|
282
|
+
case let .photoStatus(event):
|
|
283
|
+
event.description
|
|
284
|
+
case let .cameraStatus(event):
|
|
285
|
+
event.description
|
|
286
|
+
case let .videoRecordingStatus(event):
|
|
287
|
+
event.description
|
|
288
|
+
case let .mediaUpload(event):
|
|
289
|
+
event.description
|
|
290
|
+
case let .rgbLedControlResponse(event):
|
|
291
|
+
event.description
|
|
292
|
+
case let .streamStatus(event):
|
|
293
|
+
event.description
|
|
294
|
+
case let .keepAliveAck(event):
|
|
295
|
+
event.description
|
|
296
|
+
case let .otaStartAck(event):
|
|
297
|
+
event.description
|
|
298
|
+
case let .otaStatus(event):
|
|
299
|
+
event.description
|
|
300
|
+
case let .settingsAck(event):
|
|
301
|
+
event.description
|
|
302
|
+
case let .versionInfo(event):
|
|
303
|
+
event.description
|
|
304
|
+
case let .localTranscription(event):
|
|
305
|
+
event.description
|
|
306
|
+
case let .raw(name, values):
|
|
307
|
+
"\(name): \(values)"
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
@MainActor
|
|
313
|
+
public protocol BluetoothSDKDelegate: AnyObject {
|
|
314
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didUpdate state: BluetoothState)
|
|
315
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didUpdateGlasses glasses: GlassesRuntimeState)
|
|
316
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didUpdateSdkState sdkState: PhoneSdkRuntimeState)
|
|
317
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didUpdateScan scan: BluetoothScanState)
|
|
318
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didDiscover device: Device)
|
|
319
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didStopScan reason: ScanStopReason)
|
|
320
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didReceive event: BluetoothEvent)
|
|
321
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didReceiveMicPcm event: MicPcmEvent)
|
|
322
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didReceiveMicLc3 event: MicLc3Event)
|
|
323
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didChangeDefaultDevice device: Device?)
|
|
324
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didLog message: String)
|
|
325
|
+
func bluetoothSDK(_ sdk: BluetoothSDK, didFail error: BluetoothSdkError)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
@MainActor
|
|
329
|
+
public extension BluetoothSDKDelegate {
|
|
330
|
+
func bluetoothSDK(_: BluetoothSDK, didUpdate _: BluetoothState) {}
|
|
331
|
+
func bluetoothSDK(_: BluetoothSDK, didUpdateGlasses _: GlassesRuntimeState) {}
|
|
332
|
+
func bluetoothSDK(_: BluetoothSDK, didUpdateSdkState _: PhoneSdkRuntimeState) {}
|
|
333
|
+
func bluetoothSDK(_: BluetoothSDK, didUpdateScan _: BluetoothScanState) {}
|
|
334
|
+
func bluetoothSDK(_: BluetoothSDK, didDiscover _: Device) {}
|
|
335
|
+
func bluetoothSDK(_: BluetoothSDK, didStopScan _: ScanStopReason) {}
|
|
336
|
+
func bluetoothSDK(_: BluetoothSDK, didReceive _: BluetoothEvent) {}
|
|
337
|
+
func bluetoothSDK(_: BluetoothSDK, didReceiveMicPcm _: MicPcmEvent) {}
|
|
338
|
+
func bluetoothSDK(_: BluetoothSDK, didReceiveMicLc3 _: MicLc3Event) {}
|
|
339
|
+
func bluetoothSDK(_: BluetoothSDK, didChangeDefaultDevice _: Device?) {}
|
|
340
|
+
func bluetoothSDK(_: BluetoothSDK, didLog _: String) {}
|
|
341
|
+
func bluetoothSDK(_: BluetoothSDK, didFail _: BluetoothSdkError) {}
|
|
342
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import os.log
|
|
3
|
+
import UIKit
|
|
4
|
+
|
|
5
|
+
enum BleTraceLogger {
|
|
6
|
+
private static let log = OSLog(subsystem: "com.glassly.bluetoothsdk", category: "GlasslyBleTrace")
|
|
7
|
+
private static let maxPayloadChars = 3000
|
|
8
|
+
private static let k900Type = "k900"
|
|
9
|
+
private static let sensitiveKeyParts = ["password", "pass", "token", "secret", "authorization", "auth", "email", "serial"]
|
|
10
|
+
|
|
11
|
+
static func logJson(
|
|
12
|
+
direction: String,
|
|
13
|
+
layer: String,
|
|
14
|
+
payload: [String: Any]?,
|
|
15
|
+
bytes: Int? = nil,
|
|
16
|
+
sourceFile: String = #fileID,
|
|
17
|
+
sourceFunction: String = #function,
|
|
18
|
+
sourceLine: Int = #line
|
|
19
|
+
) {
|
|
20
|
+
guard let payload else {
|
|
21
|
+
emit(format(
|
|
22
|
+
direction: direction,
|
|
23
|
+
layer: layer,
|
|
24
|
+
source: source(file: sourceFile, function: sourceFunction, line: sourceLine),
|
|
25
|
+
type: "null",
|
|
26
|
+
bytes: bytes,
|
|
27
|
+
payload: "null"
|
|
28
|
+
))
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let sanitized = sanitizeDictionary(payload)
|
|
33
|
+
emit(format(
|
|
34
|
+
direction: direction,
|
|
35
|
+
layer: layer,
|
|
36
|
+
source: source(file: sourceFile, function: sourceFunction, line: sourceLine),
|
|
37
|
+
type: extractType(from: payload),
|
|
38
|
+
bytes: bytes,
|
|
39
|
+
payload: jsonString(sanitized)
|
|
40
|
+
))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static func logMap(
|
|
44
|
+
direction: String,
|
|
45
|
+
layer: String,
|
|
46
|
+
type: String?,
|
|
47
|
+
payload: [String: Any],
|
|
48
|
+
bytes: Int? = nil,
|
|
49
|
+
sourceFile: String = #fileID,
|
|
50
|
+
sourceFunction: String = #function,
|
|
51
|
+
sourceLine: Int = #line
|
|
52
|
+
) {
|
|
53
|
+
let sanitized = sanitizeDictionary(payload)
|
|
54
|
+
emit(format(
|
|
55
|
+
direction: direction,
|
|
56
|
+
layer: layer,
|
|
57
|
+
source: source(file: sourceFile, function: sourceFunction, line: sourceLine),
|
|
58
|
+
type: type ?? extractType(from: sanitized),
|
|
59
|
+
bytes: bytes,
|
|
60
|
+
payload: jsonString(sanitized)
|
|
61
|
+
))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static func logLifecycle(component: String, event: String, extra: [String: Any] = [:]) {
|
|
65
|
+
var payload: [String: Any] = [
|
|
66
|
+
"event": event,
|
|
67
|
+
"component": component,
|
|
68
|
+
"pid": ProcessInfo.processInfo.processIdentifier,
|
|
69
|
+
"model": UIDevice.current.model,
|
|
70
|
+
"systemVersion": UIDevice.current.systemVersion,
|
|
71
|
+
]
|
|
72
|
+
for (key, value) in extra {
|
|
73
|
+
payload[key] = value
|
|
74
|
+
}
|
|
75
|
+
logMap(direction: "phone_app", layer: "app_lifecycle", type: event, payload: payload)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private static func emit(_ line: String) {
|
|
79
|
+
os_log("%{public}@", log: log, type: .info, line)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private static func format(
|
|
83
|
+
direction: String,
|
|
84
|
+
layer: String,
|
|
85
|
+
source: String,
|
|
86
|
+
type: String,
|
|
87
|
+
bytes: Int?,
|
|
88
|
+
payload: String
|
|
89
|
+
) -> String {
|
|
90
|
+
let bytesText = bytes.map { " bytes=\($0)" } ?? ""
|
|
91
|
+
return "BLE_TRACE direction=\(direction) layer=\(layer) source=\(source) type=\(type)\(bytesText) payload=\(truncate(payload))"
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private static func extractType(from payload: [String: Any]) -> String {
|
|
95
|
+
if let type = payload["type"] as? String, !type.isEmpty {
|
|
96
|
+
return type
|
|
97
|
+
}
|
|
98
|
+
if let cValue = payload["C"] as? String, !cValue.isEmpty {
|
|
99
|
+
if let data = cValue.data(using: .utf8),
|
|
100
|
+
let inner = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
|
|
101
|
+
let type = inner["type"] as? String,
|
|
102
|
+
!type.isEmpty
|
|
103
|
+
{
|
|
104
|
+
return type
|
|
105
|
+
}
|
|
106
|
+
return extractK900Type(cValue)
|
|
107
|
+
}
|
|
108
|
+
return "unknown"
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private static func extractK900Type(_ value: String) -> String {
|
|
112
|
+
value == "sr_log" ? "\(k900Type):sr_log" : k900Type
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private static func sanitizeDictionary(_ value: [String: Any]) -> [String: Any] {
|
|
116
|
+
var output: [String: Any] = [:]
|
|
117
|
+
for (key, child) in value {
|
|
118
|
+
output[key] = sanitizeValue(key: key, value: child)
|
|
119
|
+
}
|
|
120
|
+
return output
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private static func sanitizeArray(_ value: [Any]) -> [Any] {
|
|
124
|
+
value.map { sanitizeValue(key: nil, value: $0) }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private static func sanitizeValue(key: String?, value: Any) -> Any {
|
|
128
|
+
if let key, sensitiveKeyParts.contains(where: { key.localizedCaseInsensitiveContains($0) }) {
|
|
129
|
+
return "<redacted>"
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if key == "C", let stringValue = value as? String {
|
|
133
|
+
if let data = stringValue.data(using: .utf8),
|
|
134
|
+
let parsed = try? JSONSerialization.jsonObject(with: data)
|
|
135
|
+
{
|
|
136
|
+
return jsonString(sanitizeJsonValue(parsed))
|
|
137
|
+
}
|
|
138
|
+
return sanitizeK900Command(stringValue)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return sanitizeJsonValue(value)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private static func sanitizeJsonValue(_ value: Any) -> Any {
|
|
145
|
+
switch value {
|
|
146
|
+
case let dictionary as [String: Any]:
|
|
147
|
+
return sanitizeDictionary(dictionary)
|
|
148
|
+
case let array as [Any]:
|
|
149
|
+
return sanitizeArray(array)
|
|
150
|
+
case let data as Data:
|
|
151
|
+
return "<data \(data.count) bytes>"
|
|
152
|
+
case let url as URL:
|
|
153
|
+
return url.absoluteString
|
|
154
|
+
case let bool as Bool:
|
|
155
|
+
return bool
|
|
156
|
+
case let number as NSNumber:
|
|
157
|
+
return number
|
|
158
|
+
case let string as String:
|
|
159
|
+
return string
|
|
160
|
+
case _ as NSNull:
|
|
161
|
+
return NSNull()
|
|
162
|
+
default:
|
|
163
|
+
return String(describing: value)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private static func sanitizeK900Command(_ value: String) -> String {
|
|
168
|
+
value == "sr_log" ? value : "<non-json C payload>"
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private static func jsonString(_ value: Any) -> String {
|
|
172
|
+
guard JSONSerialization.isValidJSONObject(value),
|
|
173
|
+
let data = try? JSONSerialization.data(withJSONObject: value),
|
|
174
|
+
let string = String(data: data, encoding: .utf8)
|
|
175
|
+
else {
|
|
176
|
+
return String(describing: value)
|
|
177
|
+
}
|
|
178
|
+
return string
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private static func source(file: String, function: String, line: Int) -> String {
|
|
182
|
+
"\(function)(\(file):\(line))"
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private static func truncate(_ value: String) -> String {
|
|
186
|
+
guard value.count > maxPayloadChars else {
|
|
187
|
+
return value
|
|
188
|
+
}
|
|
189
|
+
let endIndex = value.index(value.startIndex, offsetBy: maxPayloadChars)
|
|
190
|
+
return "\(value[..<endIndex])...(truncated \(value.count - maxPayloadChars) chars)"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import CoreBluetooth
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
final class BluetoothAvailability: NSObject, CBCentralManagerDelegate {
|
|
5
|
+
static let shared = BluetoothAvailability()
|
|
6
|
+
|
|
7
|
+
private var centralManager: CBCentralManager?
|
|
8
|
+
private var state: CBManagerState = .unknown
|
|
9
|
+
private var listeners: [UUID: (CBManagerState) -> Void] = [:]
|
|
10
|
+
|
|
11
|
+
override private init() {
|
|
12
|
+
super.init()
|
|
13
|
+
centralManager = CBCentralManager(
|
|
14
|
+
delegate: self,
|
|
15
|
+
queue: .main,
|
|
16
|
+
options: [CBCentralManagerOptionShowPowerAlertKey: false]
|
|
17
|
+
)
|
|
18
|
+
state = centralManager?.state ?? .unknown
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func centralManagerDidUpdateState(_ central: CBCentralManager) {
|
|
22
|
+
state = central.state
|
|
23
|
+
for listener in Array(listeners.values) {
|
|
24
|
+
listener(state)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@discardableResult
|
|
29
|
+
func addStateListener(_ listener: @escaping (CBManagerState) -> Void) -> UUID {
|
|
30
|
+
// `listeners` is unsynchronized; it is only safe because the central
|
|
31
|
+
// manager queue is `.main` and all callers are main-thread bound.
|
|
32
|
+
dispatchPrecondition(condition: .onQueue(.main))
|
|
33
|
+
let id = UUID()
|
|
34
|
+
listeners[id] = listener
|
|
35
|
+
listener(state)
|
|
36
|
+
return id
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
func removeStateListener(_ id: UUID) {
|
|
40
|
+
dispatchPrecondition(condition: .onQueue(.main))
|
|
41
|
+
listeners[id] = nil
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func requirePoweredOn(operation: String) throws {
|
|
45
|
+
if let current = centralManager?.state {
|
|
46
|
+
state = current
|
|
47
|
+
}
|
|
48
|
+
switch state {
|
|
49
|
+
case .poweredOn:
|
|
50
|
+
return
|
|
51
|
+
case .poweredOff:
|
|
52
|
+
throw BluetoothSdkError(
|
|
53
|
+
code: "bluetooth_powered_off",
|
|
54
|
+
message: "Turn on phone Bluetooth to \(operation)."
|
|
55
|
+
)
|
|
56
|
+
case .unauthorized:
|
|
57
|
+
throw BluetoothSdkError(
|
|
58
|
+
code: "bluetooth_unauthorized",
|
|
59
|
+
message: "Allow Bluetooth access to \(operation)."
|
|
60
|
+
)
|
|
61
|
+
case .unsupported:
|
|
62
|
+
throw BluetoothSdkError(
|
|
63
|
+
code: "bluetooth_unsupported",
|
|
64
|
+
message: "This phone does not support Bluetooth."
|
|
65
|
+
)
|
|
66
|
+
case .resetting, .unknown:
|
|
67
|
+
throw BluetoothSdkError(
|
|
68
|
+
code: "bluetooth_not_ready",
|
|
69
|
+
message: "Bluetooth is not ready yet. Try again."
|
|
70
|
+
)
|
|
71
|
+
@unknown default:
|
|
72
|
+
throw BluetoothSdkError(
|
|
73
|
+
code: "bluetooth_unavailable",
|
|
74
|
+
message: "Bluetooth is unavailable. Try again."
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|