@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,566 @@
|
|
|
1
|
+
package com.glassly.bluetoothsdk.sgcs.ar99.ota;
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothGatt;
|
|
4
|
+
import android.os.Handler;
|
|
5
|
+
import android.os.Looper;
|
|
6
|
+
import android.util.Log;
|
|
7
|
+
import java.io.ByteArrayOutputStream;
|
|
8
|
+
import java.io.File;
|
|
9
|
+
import java.io.FileInputStream;
|
|
10
|
+
import java.io.IOException;
|
|
11
|
+
import java.util.Arrays;
|
|
12
|
+
|
|
13
|
+
public class Ar99OtaManager {
|
|
14
|
+
private static final String TAG = "Ar99OtaManager";
|
|
15
|
+
private static final int DEFAULT_BLOCK_SIZE = 200;
|
|
16
|
+
private static final int TIMEOUT_MS = 5000;
|
|
17
|
+
private static final int RECONNECT_TIMEOUT_MS = 90000;
|
|
18
|
+
|
|
19
|
+
private static volatile Ar99OtaManager instance;
|
|
20
|
+
|
|
21
|
+
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
22
|
+
private OtaGattTransport transport;
|
|
23
|
+
private OTACallback callback;
|
|
24
|
+
private Runnable timeoutRunnable;
|
|
25
|
+
private Runnable reconnectTimeoutRunnable;
|
|
26
|
+
|
|
27
|
+
private int state = OtaCommandConstants.OTA.State.IDLE;
|
|
28
|
+
private byte[] firmwareData;
|
|
29
|
+
private int firmwareSize;
|
|
30
|
+
private long firmwareCrc32;
|
|
31
|
+
private int blockSize = DEFAULT_BLOCK_SIZE;
|
|
32
|
+
private int currentOffset = 0;
|
|
33
|
+
private boolean otaNotifyEnabled = false;
|
|
34
|
+
|
|
35
|
+
private Ar99OtaManager() {}
|
|
36
|
+
|
|
37
|
+
public static Ar99OtaManager getInstance() {
|
|
38
|
+
if (instance == null) {
|
|
39
|
+
synchronized (Ar99OtaManager.class) {
|
|
40
|
+
if (instance == null) instance = new Ar99OtaManager();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return instance;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public synchronized void setTransport(OtaGattTransport transport) {
|
|
47
|
+
this.transport = transport;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public synchronized void setCallback(OTACallback callback) {
|
|
51
|
+
this.callback = callback;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public synchronized int getState() {
|
|
55
|
+
return state;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public synchronized boolean isOTAInProgress() {
|
|
59
|
+
return state != OtaCommandConstants.OTA.State.IDLE
|
|
60
|
+
&& state != OtaCommandConstants.OTA.State.COMPLETED
|
|
61
|
+
&& state != OtaCommandConstants.OTA.State.FAILED;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public synchronized boolean isPausedWaitingReconnect() {
|
|
65
|
+
return state == OtaCommandConstants.OTA.State.PAUSED_DISCONNECTED;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public synchronized int getProgress() {
|
|
69
|
+
if (firmwareSize <= 0) return 0;
|
|
70
|
+
return (int) ((currentOffset * 100L) / firmwareSize);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public boolean startOTA(File firmwareFile) {
|
|
74
|
+
if (firmwareFile == null || !firmwareFile.exists()) {
|
|
75
|
+
notifyError(OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "Firmware file does not exist");
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
return startOTA(readFile(firmwareFile));
|
|
80
|
+
} catch (IOException e) {
|
|
81
|
+
notifyError(OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "Failed to read firmware file");
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public synchronized boolean startOTA(byte[] data) {
|
|
87
|
+
if (isOTAInProgress()) {
|
|
88
|
+
Log.w(TAG, "OTA is already in progress");
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (data == null || data.length == 0) {
|
|
92
|
+
notifyError(OtaCommandConstants.OTA.ErrorCode.PACKAGE_SIZE_ERROR, "Firmware data is empty");
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
state = OtaCommandConstants.OTA.State.IDLE;
|
|
97
|
+
otaNotifyEnabled = false;
|
|
98
|
+
cancelTimeout();
|
|
99
|
+
cancelReconnectTimeout();
|
|
100
|
+
firmwareData = data;
|
|
101
|
+
firmwareSize = data.length;
|
|
102
|
+
firmwareCrc32 = OtaCrc32Util.calculate(data);
|
|
103
|
+
blockSize = DEFAULT_BLOCK_SIZE;
|
|
104
|
+
currentOffset = 0;
|
|
105
|
+
|
|
106
|
+
OtaGattTransport t = transport;
|
|
107
|
+
if (t == null) {
|
|
108
|
+
notifyError(OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "OTA transport is not initialized");
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (!t.enableOtaNotification()) {
|
|
112
|
+
notifyError(OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "OTA service was not found");
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public void cancelOTA() {
|
|
119
|
+
synchronized (this) {
|
|
120
|
+
state = OtaCommandConstants.OTA.State.IDLE;
|
|
121
|
+
otaNotifyEnabled = false;
|
|
122
|
+
firmwareData = null;
|
|
123
|
+
firmwareSize = 0;
|
|
124
|
+
currentOffset = 0;
|
|
125
|
+
cancelTimeout();
|
|
126
|
+
cancelReconnectTimeout();
|
|
127
|
+
}
|
|
128
|
+
OTACallback cb = callback;
|
|
129
|
+
if (cb != null) mainHandler.post(cb::onCancelled);
|
|
130
|
+
cleanupFirmware();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public void onBleDisconnected() {
|
|
134
|
+
boolean shouldNotify = false;
|
|
135
|
+
synchronized (this) {
|
|
136
|
+
if (!isOTAInProgress() || firmwareData == null || firmwareSize <= 0) return;
|
|
137
|
+
if (state == OtaCommandConstants.OTA.State.PAUSED_DISCONNECTED) return;
|
|
138
|
+
state = OtaCommandConstants.OTA.State.PAUSED_DISCONNECTED;
|
|
139
|
+
otaNotifyEnabled = false;
|
|
140
|
+
cancelTimeout();
|
|
141
|
+
startReconnectTimeout();
|
|
142
|
+
shouldNotify = true;
|
|
143
|
+
}
|
|
144
|
+
if (shouldNotify) notifyPausedWaitingReconnect();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public void tryResumeOtaAfterGattReady() {
|
|
148
|
+
boolean resume;
|
|
149
|
+
synchronized (this) {
|
|
150
|
+
resume =
|
|
151
|
+
state == OtaCommandConstants.OTA.State.PAUSED_DISCONNECTED
|
|
152
|
+
&& firmwareData != null
|
|
153
|
+
&& firmwareSize > 0;
|
|
154
|
+
}
|
|
155
|
+
if (resume) {
|
|
156
|
+
OtaGattTransport t = transport;
|
|
157
|
+
if (t != null) t.enableOtaNotification();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public void onOtaNotifyEnabled() {
|
|
162
|
+
synchronized (this) {
|
|
163
|
+
otaNotifyEnabled = true;
|
|
164
|
+
if (firmwareData == null || firmwareSize <= 0) return;
|
|
165
|
+
if (state != OtaCommandConstants.OTA.State.IDLE
|
|
166
|
+
&& state != OtaCommandConstants.OTA.State.PAUSED_DISCONNECTED) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
mainHandler.postDelayed(
|
|
171
|
+
() -> {
|
|
172
|
+
synchronized (Ar99OtaManager.this) {
|
|
173
|
+
if (state != OtaCommandConstants.OTA.State.IDLE
|
|
174
|
+
&& state != OtaCommandConstants.OTA.State.PAUSED_DISCONNECTED) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
sendUpgradeRequest();
|
|
179
|
+
},
|
|
180
|
+
1000);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public boolean handleGattMtuChangedForOta(int status) {
|
|
184
|
+
synchronized (this) {
|
|
185
|
+
if (state != OtaCommandConstants.OTA.State.REQUESTING) return false;
|
|
186
|
+
}
|
|
187
|
+
if (status != BluetoothGatt.GATT_SUCCESS) {
|
|
188
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "MTU negotiation failed");
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
onMtuNegotiated();
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public void handleOTAResponse(byte[] data) {
|
|
196
|
+
if (data == null || data.length < 5) return;
|
|
197
|
+
OtaProtocol.FrameHeader header = OtaProtocol.parseFrameHeader(data);
|
|
198
|
+
if (header == null || header.svcId != OtaCommandConstants.OTA.SVC_ID) return;
|
|
199
|
+
cancelTimeout();
|
|
200
|
+
|
|
201
|
+
byte[] payload = null;
|
|
202
|
+
if (header.paramLen > 0 && data.length >= header.payloadOffset + header.paramLen) {
|
|
203
|
+
payload = Arrays.copyOfRange(data, header.payloadOffset, header.payloadOffset + header.paramLen);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
switch (header.cmd) {
|
|
207
|
+
case OtaCommandConstants.OTA.REQUEST_UPGRADE:
|
|
208
|
+
handleUpgradeRequestResponse(payload);
|
|
209
|
+
break;
|
|
210
|
+
case OtaCommandConstants.OTA.CONNECT_NEGOTIATION:
|
|
211
|
+
handleNegotiationResponse(payload);
|
|
212
|
+
break;
|
|
213
|
+
case OtaCommandConstants.OTA.NEGOTIATION_RESULT:
|
|
214
|
+
handleNegotiationResultResponse();
|
|
215
|
+
break;
|
|
216
|
+
case OtaCommandConstants.OTA.REQUIRE_IMAGE_DATA:
|
|
217
|
+
handleRequireImageData(payload);
|
|
218
|
+
break;
|
|
219
|
+
case OtaCommandConstants.OTA.SEND_IMAGE_DATA:
|
|
220
|
+
handleImageDataResponse(payload);
|
|
221
|
+
break;
|
|
222
|
+
case OtaCommandConstants.OTA.VALIDATE_IMAGE:
|
|
223
|
+
handleValidateImageResponse(payload);
|
|
224
|
+
break;
|
|
225
|
+
default:
|
|
226
|
+
startTimeout();
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private boolean sendUpgradeRequest() {
|
|
232
|
+
if (!isBluetoothConnected()) {
|
|
233
|
+
notifyError(OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "Bluetooth is not connected");
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
synchronized (this) {
|
|
237
|
+
if (firmwareData == null || firmwareSize <= 0) {
|
|
238
|
+
state = OtaCommandConstants.OTA.State.IDLE;
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
cancelReconnectTimeout();
|
|
242
|
+
state = OtaCommandConstants.OTA.State.REQUESTING;
|
|
243
|
+
}
|
|
244
|
+
OtaGattTransport t = transport;
|
|
245
|
+
if (t == null) {
|
|
246
|
+
notifyError(OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "OTA transport is not initialized");
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
t.requestMtu(247);
|
|
250
|
+
startTimeout();
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private void onMtuNegotiated() {
|
|
255
|
+
mainHandler.postDelayed(
|
|
256
|
+
() -> {
|
|
257
|
+
synchronized (Ar99OtaManager.this) {
|
|
258
|
+
if (state != OtaCommandConstants.OTA.State.REQUESTING) return;
|
|
259
|
+
}
|
|
260
|
+
sendOtaData(OtaProtocol.buildRequestUpgrade(firmwareSize, blockSize, firmwareCrc32));
|
|
261
|
+
},
|
|
262
|
+
500);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private void handleUpgradeRequestResponse(byte[] payload) {
|
|
266
|
+
if (payload == null || payload.length < 3) {
|
|
267
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Invalid upgrade response");
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
int offset = 0;
|
|
272
|
+
boolean success = false;
|
|
273
|
+
while (offset + 3 <= payload.length) {
|
|
274
|
+
int type = payload[offset++] & 0xFF;
|
|
275
|
+
int len = OtaByteUtils.readShortLE(payload, offset);
|
|
276
|
+
offset += 2;
|
|
277
|
+
if (offset + len > payload.length) {
|
|
278
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Invalid upgrade TLV");
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (type == 0x7F && len >= 4) {
|
|
282
|
+
int errorCode = OtaByteUtils.readIntLE(payload, offset);
|
|
283
|
+
if (errorCode == 100000) {
|
|
284
|
+
success = true;
|
|
285
|
+
} else {
|
|
286
|
+
handleOTAFailure(
|
|
287
|
+
OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Upgrade request failed: " + errorCode);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
offset += len;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!success) {
|
|
295
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Upgrade request was rejected");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
synchronized (this) {
|
|
299
|
+
state = OtaCommandConstants.OTA.State.NEGOTIATING;
|
|
300
|
+
}
|
|
301
|
+
sendOtaData(OtaProtocol.buildConnectNegotiation(blockSize));
|
|
302
|
+
startTimeout();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private void handleNegotiationResponse(byte[] payload) {
|
|
306
|
+
if (payload == null || payload.length < 3) {
|
|
307
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Invalid negotiation response");
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
int offset = 0;
|
|
311
|
+
while (offset + 3 <= payload.length) {
|
|
312
|
+
int type = payload[offset++] & 0xFF;
|
|
313
|
+
int len = OtaByteUtils.readShortLE(payload, offset);
|
|
314
|
+
offset += 2;
|
|
315
|
+
if (offset + len > payload.length) {
|
|
316
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Invalid negotiation TLV");
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (type == 0x03 && len >= 2) {
|
|
320
|
+
int suggestedBlockSize = OtaByteUtils.readShortLE(payload, offset);
|
|
321
|
+
if (suggestedBlockSize > 0) blockSize = suggestedBlockSize;
|
|
322
|
+
}
|
|
323
|
+
offset += len;
|
|
324
|
+
}
|
|
325
|
+
synchronized (this) {
|
|
326
|
+
state = OtaCommandConstants.OTA.State.WAITING_READY;
|
|
327
|
+
}
|
|
328
|
+
sendOtaData(OtaProtocol.buildNegotiationResult());
|
|
329
|
+
startTimeout();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
private void handleNegotiationResultResponse() {
|
|
333
|
+
synchronized (this) {
|
|
334
|
+
state = OtaCommandConstants.OTA.State.TRANSFERRING;
|
|
335
|
+
}
|
|
336
|
+
startTimeout();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private void handleRequireImageData(byte[] payload) {
|
|
340
|
+
if (payload == null || payload.length < 3) {
|
|
341
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Invalid image data request");
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
int offset = 0;
|
|
346
|
+
int fileOffset = 0;
|
|
347
|
+
int fileLength = 0;
|
|
348
|
+
while (offset + 3 <= payload.length) {
|
|
349
|
+
int type = payload[offset++] & 0xFF;
|
|
350
|
+
int len = OtaByteUtils.readShortLE(payload, offset);
|
|
351
|
+
offset += 2;
|
|
352
|
+
if (offset + len > payload.length) {
|
|
353
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Invalid image data TLV");
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (type == 0x01 && len >= 4) {
|
|
357
|
+
fileOffset = OtaByteUtils.readIntLE(payload, offset);
|
|
358
|
+
} else if (type == 0x02 && len >= 4) {
|
|
359
|
+
fileLength = OtaByteUtils.readIntLE(payload, offset);
|
|
360
|
+
}
|
|
361
|
+
offset += len;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
byte[] image;
|
|
365
|
+
int imageSize;
|
|
366
|
+
synchronized (this) {
|
|
367
|
+
image = firmwareData;
|
|
368
|
+
imageSize = firmwareSize;
|
|
369
|
+
}
|
|
370
|
+
if (image == null || imageSize <= 0 || fileOffset < 0 || fileOffset > imageSize) {
|
|
371
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Invalid firmware offset");
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (fileOffset >= imageSize) {
|
|
375
|
+
startTimeout();
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
int remaining = imageSize - fileOffset;
|
|
380
|
+
int totalSendLength = fileLength > 0 ? Math.min(remaining, fileLength) : remaining;
|
|
381
|
+
int sentLength = 0;
|
|
382
|
+
int psn = 0;
|
|
383
|
+
while (sentLength < totalSendLength) {
|
|
384
|
+
int size = Math.min(totalSendLength - sentLength, blockSize);
|
|
385
|
+
int current = fileOffset + sentLength;
|
|
386
|
+
byte[] block = Arrays.copyOfRange(image, current, current + size);
|
|
387
|
+
sendOtaData(OtaProtocol.buildSendImageData(psn, block));
|
|
388
|
+
sentLength += size;
|
|
389
|
+
psn++;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
synchronized (this) {
|
|
393
|
+
currentOffset = fileOffset + sentLength;
|
|
394
|
+
}
|
|
395
|
+
notifyProgress(currentOffset, getProgress());
|
|
396
|
+
startTimeout();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
private void handleValidateImageResponse(byte[] payload) {
|
|
400
|
+
Integer validFlag = null;
|
|
401
|
+
if (payload != null && payload.length >= 4) {
|
|
402
|
+
int offset = 0;
|
|
403
|
+
while (offset + 3 <= payload.length) {
|
|
404
|
+
int type = payload[offset++] & 0xFF;
|
|
405
|
+
int len = OtaByteUtils.readShortLE(payload, offset);
|
|
406
|
+
offset += 2;
|
|
407
|
+
if (offset + len > payload.length) break;
|
|
408
|
+
if (type == 0x01 && len >= 1) {
|
|
409
|
+
validFlag = payload[offset] & 0xFF;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
offset += len;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (validFlag == null && payload != null && payload.length > 0) {
|
|
416
|
+
validFlag = payload[0] & 0xFF;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (validFlag != null && validFlag == 1) {
|
|
420
|
+
handleOTASuccess();
|
|
421
|
+
} else {
|
|
422
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.FIRMWARE_VALIDATION_FAILED, "Firmware validation failed");
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
private void handleImageDataResponse(byte[] payload) {
|
|
427
|
+
if (payload == null || payload.length < 5) {
|
|
428
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.PROTOCOL_ERROR, "Invalid image data response");
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
int receivedOffset = OtaByteUtils.readIntLE(payload, 0);
|
|
432
|
+
int status = payload[4] & 0xFF;
|
|
433
|
+
if (status != 0) {
|
|
434
|
+
handleOTAFailure(status, "Firmware data write failed");
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
synchronized (this) {
|
|
438
|
+
if (receivedOffset != currentOffset) currentOffset = receivedOffset;
|
|
439
|
+
}
|
|
440
|
+
startTimeout();
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
private void sendOtaData(byte[] frame) {
|
|
444
|
+
OtaGattTransport t = transport;
|
|
445
|
+
if (t == null) {
|
|
446
|
+
handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "OTA transport is not initialized");
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
t.sendOtaData(frame);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private boolean isBluetoothConnected() {
|
|
453
|
+
OtaGattTransport t = transport;
|
|
454
|
+
return t != null && t.isBleConnected() && otaNotifyEnabled;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
private void handleOTASuccess() {
|
|
458
|
+
synchronized (this) {
|
|
459
|
+
state = OtaCommandConstants.OTA.State.COMPLETED;
|
|
460
|
+
currentOffset = firmwareSize;
|
|
461
|
+
cancelTimeout();
|
|
462
|
+
cancelReconnectTimeout();
|
|
463
|
+
}
|
|
464
|
+
notifyProgress(firmwareSize, 100);
|
|
465
|
+
OTACallback cb = callback;
|
|
466
|
+
if (cb != null) mainHandler.post(() -> cb.onCompleted(false));
|
|
467
|
+
cleanupFirmware();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
private void handleOTAFailure(int code, String message) {
|
|
471
|
+
synchronized (this) {
|
|
472
|
+
state = OtaCommandConstants.OTA.State.FAILED;
|
|
473
|
+
cancelTimeout();
|
|
474
|
+
cancelReconnectTimeout();
|
|
475
|
+
}
|
|
476
|
+
notifyError(code, message);
|
|
477
|
+
cleanupFirmware();
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
private synchronized void startTimeout() {
|
|
481
|
+
cancelTimeout();
|
|
482
|
+
timeoutRunnable =
|
|
483
|
+
() -> handleOTAFailure(OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "OTA timed out");
|
|
484
|
+
mainHandler.postDelayed(timeoutRunnable, TIMEOUT_MS);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
private synchronized void cancelTimeout() {
|
|
488
|
+
if (timeoutRunnable != null) {
|
|
489
|
+
mainHandler.removeCallbacks(timeoutRunnable);
|
|
490
|
+
timeoutRunnable = null;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
private synchronized void startReconnectTimeout() {
|
|
495
|
+
cancelReconnectTimeout();
|
|
496
|
+
reconnectTimeoutRunnable =
|
|
497
|
+
() -> {
|
|
498
|
+
synchronized (Ar99OtaManager.this) {
|
|
499
|
+
if (state != OtaCommandConstants.OTA.State.PAUSED_DISCONNECTED) return;
|
|
500
|
+
}
|
|
501
|
+
handleOTAFailure(
|
|
502
|
+
OtaCommandConstants.OTA.ErrorCode.UNKNOWN_ERROR, "OTA reconnect timed out");
|
|
503
|
+
};
|
|
504
|
+
mainHandler.postDelayed(reconnectTimeoutRunnable, RECONNECT_TIMEOUT_MS);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
private synchronized void cancelReconnectTimeout() {
|
|
508
|
+
if (reconnectTimeoutRunnable != null) {
|
|
509
|
+
mainHandler.removeCallbacks(reconnectTimeoutRunnable);
|
|
510
|
+
reconnectTimeoutRunnable = null;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
private void notifyProgress(int offset, int progress) {
|
|
515
|
+
OTACallback cb = callback;
|
|
516
|
+
int total;
|
|
517
|
+
synchronized (this) {
|
|
518
|
+
total = firmwareSize;
|
|
519
|
+
}
|
|
520
|
+
if (cb != null) mainHandler.post(() -> cb.onProgress(offset, total, progress));
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
private void notifyError(int errorCode, String message) {
|
|
524
|
+
OTACallback cb = callback;
|
|
525
|
+
if (cb != null) mainHandler.post(() -> cb.onError(errorCode, message));
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
private void notifyPausedWaitingReconnect() {
|
|
529
|
+
OTACallback cb = callback;
|
|
530
|
+
if (cb != null) mainHandler.post(cb::onPausedWaitingReconnect);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
private static byte[] readFile(File file) throws IOException {
|
|
534
|
+
try (FileInputStream input = new FileInputStream(file);
|
|
535
|
+
ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
|
536
|
+
byte[] buffer = new byte[8192];
|
|
537
|
+
int read;
|
|
538
|
+
while ((read = input.read(buffer)) != -1) {
|
|
539
|
+
output.write(buffer, 0, read);
|
|
540
|
+
}
|
|
541
|
+
return output.toByteArray();
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
private synchronized void cleanupFirmware() {
|
|
546
|
+
firmwareData = null;
|
|
547
|
+
firmwareSize = 0;
|
|
548
|
+
firmwareCrc32 = 0;
|
|
549
|
+
currentOffset = 0;
|
|
550
|
+
blockSize = DEFAULT_BLOCK_SIZE;
|
|
551
|
+
otaNotifyEnabled = false;
|
|
552
|
+
cancelTimeout();
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
public interface OTACallback {
|
|
556
|
+
void onProgress(int offset, int total, int progress);
|
|
557
|
+
|
|
558
|
+
void onCompleted(boolean needReboot);
|
|
559
|
+
|
|
560
|
+
void onError(int errorCode, String message);
|
|
561
|
+
|
|
562
|
+
void onCancelled();
|
|
563
|
+
|
|
564
|
+
default void onPausedWaitingReconnect() {}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.glassly.bluetoothsdk.sgcs.ar99.ota;
|
|
2
|
+
|
|
3
|
+
public final class OtaByteUtils {
|
|
4
|
+
private OtaByteUtils() {}
|
|
5
|
+
|
|
6
|
+
public static int readShortLE(byte[] data, int offset) {
|
|
7
|
+
if (data == null || offset < 0 || offset + 1 >= data.length) return 0;
|
|
8
|
+
return (data[offset] & 0xFF) | ((data[offset + 1] & 0xFF) << 8);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public static int readIntLE(byte[] data, int offset) {
|
|
12
|
+
if (data == null || offset < 0 || offset + 3 >= data.length) return 0;
|
|
13
|
+
return (data[offset] & 0xFF)
|
|
14
|
+
| ((data[offset + 1] & 0xFF) << 8)
|
|
15
|
+
| ((data[offset + 2] & 0xFF) << 16)
|
|
16
|
+
| ((data[offset + 3] & 0xFF) << 24);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package com.glassly.bluetoothsdk.sgcs.ar99.ota;
|
|
2
|
+
|
|
3
|
+
public final class OtaCommandConstants {
|
|
4
|
+
private OtaCommandConstants() {}
|
|
5
|
+
|
|
6
|
+
public static final class OTA {
|
|
7
|
+
public static final byte SVC_ID = 0x09;
|
|
8
|
+
|
|
9
|
+
public static final byte REQUEST_UPGRADE = 0x01;
|
|
10
|
+
public static final byte CONNECT_NEGOTIATION = 0x02;
|
|
11
|
+
public static final byte REQUIRE_IMAGE_DATA = 0x03;
|
|
12
|
+
public static final byte VALIDATE_IMAGE = 0x06;
|
|
13
|
+
public static final byte NEGOTIATION_RESULT = 0x09;
|
|
14
|
+
public static final byte SEND_IMAGE_DATA = 0x0B;
|
|
15
|
+
|
|
16
|
+
public static final class ErrorCode {
|
|
17
|
+
public static final int PROTOCOL_ERROR = 0x04;
|
|
18
|
+
public static final int PACKAGE_SIZE_ERROR = 0x06;
|
|
19
|
+
public static final int FIRMWARE_VALIDATION_FAILED = 0x0A;
|
|
20
|
+
public static final int UNKNOWN_ERROR = 0xFF;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static final class State {
|
|
24
|
+
public static final int IDLE = 0;
|
|
25
|
+
public static final int REQUESTING = 1;
|
|
26
|
+
public static final int NEGOTIATING = 2;
|
|
27
|
+
public static final int WAITING_READY = 3;
|
|
28
|
+
public static final int TRANSFERRING = 4;
|
|
29
|
+
public static final int VALIDATING = 5;
|
|
30
|
+
public static final int COMPLETED = 6;
|
|
31
|
+
public static final int FAILED = 7;
|
|
32
|
+
public static final int PAUSED_DISCONNECTED = 8;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package com.glassly.bluetoothsdk.sgcs.ar99.ota;
|
|
2
|
+
|
|
3
|
+
import java.util.zip.CRC32;
|
|
4
|
+
|
|
5
|
+
public final class OtaCrc32Util {
|
|
6
|
+
private OtaCrc32Util() {}
|
|
7
|
+
|
|
8
|
+
public static long calculate(byte[] data) {
|
|
9
|
+
CRC32 crc32 = new CRC32();
|
|
10
|
+
if (data != null) crc32.update(data);
|
|
11
|
+
return crc32.getValue();
|
|
12
|
+
}
|
|
13
|
+
}
|