@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,344 @@
|
|
|
1
|
+
package com.glassly.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertNotNull
|
|
5
|
+
import org.junit.Assert.assertNull
|
|
6
|
+
import org.junit.Assert.assertTrue
|
|
7
|
+
import org.junit.Test
|
|
8
|
+
import org.junit.runner.RunWith
|
|
9
|
+
import org.robolectric.RobolectricTestRunner
|
|
10
|
+
import org.robolectric.annotation.Config
|
|
11
|
+
import org.robolectric.annotation.GraphicsMode
|
|
12
|
+
|
|
13
|
+
@RunWith(RobolectricTestRunner::class)
|
|
14
|
+
@Config(sdk = [33])
|
|
15
|
+
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
|
16
|
+
class G2CfwRendererTest {
|
|
17
|
+
@Test
|
|
18
|
+
fun placementMatchesStockWindowTablesAndClamps() {
|
|
19
|
+
val defaults = boxes(height = 4, depth = 2)
|
|
20
|
+
assertEquals(G2CfwRenderer.LensBoxes(24, 128, 40, 128, 576, 288), defaults)
|
|
21
|
+
|
|
22
|
+
assertEquals(32, boxes(height = 6, depth = 1).leftX)
|
|
23
|
+
assertEquals(32, boxes(height = 6, depth = 1).rightX)
|
|
24
|
+
assertEquals(40, boxes(height = 6, depth = 0).leftX)
|
|
25
|
+
assertEquals(24, boxes(height = 6, depth = 0).rightX)
|
|
26
|
+
assertEquals(192, boxes(height = 0, depth = 1).leftY)
|
|
27
|
+
assertEquals(0, boxes(height = 99, depth = 7).leftY)
|
|
28
|
+
|
|
29
|
+
val oversized = G2CfwRenderer.lensBoxes(900, 700, 4, 2)
|
|
30
|
+
assertEquals(G2CfwRenderer.LensBoxes(0, 0, 0, 0, 640, 480), oversized)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Test
|
|
34
|
+
fun canvasIsRasterizedOneToOne() {
|
|
35
|
+
val pixels = G2CfwRenderer.rasterize(frame(rect(border = 4)), 576, 288)
|
|
36
|
+
assertNotNull(pixels)
|
|
37
|
+
pixels!!
|
|
38
|
+
assertEquals(576 * 288, pixels.size)
|
|
39
|
+
fun pixel(x: Int, y: Int) = pixels[y * 576 + x].toInt() and 0xFF
|
|
40
|
+
assertTrue(pixel(100, 1) > 200)
|
|
41
|
+
assertTrue(pixel(1, 100) > 200)
|
|
42
|
+
assertTrue(pixel(574, 100) > 200)
|
|
43
|
+
assertTrue(pixel(100, 286) > 200)
|
|
44
|
+
assertEquals(0, pixel(288, 144))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Test
|
|
48
|
+
fun wireHeaderCarriesBothLensBoxesAndFrameId() {
|
|
49
|
+
val payload = G2CfwRenderer.stereoFrame(ByteArray(576 * 288), boxes(4, 2), 0x1234)
|
|
50
|
+
assertNotNull(payload)
|
|
51
|
+
assertEquals(
|
|
52
|
+
listOf(0x83, 6, 64, 144, 144, 10, 64, 144, 144, 0x34, 0x12),
|
|
53
|
+
payload!!.take(11).map { it.toInt() and 0xFF },
|
|
54
|
+
)
|
|
55
|
+
assertEquals(0x78, payload[11].toInt() and 0xFF)
|
|
56
|
+
assertNull(G2CfwRenderer.stereoFrame(ByteArray(10), boxes(4, 2), 1))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Test
|
|
60
|
+
fun bundleAndRleMatchFirmwareDecoder() {
|
|
61
|
+
val first = byteArrayOf(0x83.toByte(), 1, 2, 3)
|
|
62
|
+
val second = ByteArray(300) { 6 }
|
|
63
|
+
val bundle = G2CfwRenderer.bundle(listOf(first, second))
|
|
64
|
+
assertNotNull(bundle)
|
|
65
|
+
assertEquals(listOf(8, 2, 4, 0), bundle!!.take(4).map { it.toInt() and 0xFF })
|
|
66
|
+
assertEquals(listOf(0x2C, 0x01), bundle.copyOfRange(8, 10).map { it.toInt() and 0xFF })
|
|
67
|
+
assertEquals(310, bundle.size)
|
|
68
|
+
assertNull(G2CfwRenderer.bundle(emptyList()))
|
|
69
|
+
|
|
70
|
+
// Round-to-nearest quantization (reference GRAY_TO_NIBBLE): [8,15]
|
|
71
|
+
// promotes to level 1, 7 stays 0, and 0 is pinned for the transparent
|
|
72
|
+
// color key.
|
|
73
|
+
assertEquals(0, G2CfwRenderer.grayNibble(0))
|
|
74
|
+
assertEquals(0, G2CfwRenderer.grayNibble(7))
|
|
75
|
+
assertEquals(1, G2CfwRenderer.grayNibble(8))
|
|
76
|
+
assertEquals(9, G2CfwRenderer.grayNibble(0x88))
|
|
77
|
+
assertEquals(15, G2CfwRenderer.grayNibble(234))
|
|
78
|
+
assertEquals(15, G2CfwRenderer.grayNibble(255))
|
|
79
|
+
|
|
80
|
+
val pixels = ByteArray(22) { if (it < 20) 0xFF.toByte() else 0 }
|
|
81
|
+
assertEquals(
|
|
82
|
+
listOf(0x0F, 20, 0x20),
|
|
83
|
+
G2CfwRenderer.rleEncode(G2CfwRenderer.pack4Bpp(pixels)).map { it.toInt() and 0xFF },
|
|
84
|
+
)
|
|
85
|
+
assertEquals(
|
|
86
|
+
listOf(0x0F, 0, 0x2C, 0x01),
|
|
87
|
+
G2CfwRenderer.rleEncode(G2CfwRenderer.pack4Bpp(ByteArray(300) { 0xFF.toByte() }))
|
|
88
|
+
.map { it.toInt() and 0xFF },
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Test
|
|
93
|
+
fun blackKeyframeUsesModeSixZlibEnvelope() {
|
|
94
|
+
val payload = G2CfwRenderer.blackPayload()
|
|
95
|
+
assertNotNull(payload)
|
|
96
|
+
assertEquals(6, payload!![0].toInt() and 0xFF)
|
|
97
|
+
assertEquals(0x78, payload[1].toInt() and 0xFF)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@Test
|
|
101
|
+
fun seededFramePayloadCompositesContentAtLensEqualWindow() {
|
|
102
|
+
val lensEqual = boxes(height = 4, depth = 1) // depth 1: both lenses share an x offset
|
|
103
|
+
val pixels = ByteArray(lensEqual.width * lensEqual.height) { 0xFF.toByte() }
|
|
104
|
+
val payload = G2CfwRenderer.seededFramePayload(pixels, lensEqual)
|
|
105
|
+
assertNotNull(payload)
|
|
106
|
+
assertEquals(6, payload!![0].toInt() and 0xFF)
|
|
107
|
+
|
|
108
|
+
// Byte-identical to a mode-6 encode of the hand-composed panel.
|
|
109
|
+
val expected = ByteArray(G2CfwRenderer.FRAME_WIDTH * G2CfwRenderer.FRAME_HEIGHT)
|
|
110
|
+
for (row in 0 until lensEqual.height) {
|
|
111
|
+
val base = (lensEqual.leftY + row) * G2CfwRenderer.FRAME_WIDTH + lensEqual.leftX
|
|
112
|
+
expected.fill(0xFF.toByte(), base, base + lensEqual.width)
|
|
113
|
+
}
|
|
114
|
+
assertTrue(payload.contentEquals(G2CfwRenderer.encodePixels(expected)))
|
|
115
|
+
|
|
116
|
+
// Mode 6 has no per-lens variant: differing windows and mismatched
|
|
117
|
+
// pixel counts must refuse rather than mis-place one lens.
|
|
118
|
+
assertNull(G2CfwRenderer.seededFramePayload(pixels, boxes(height = 4, depth = 2)))
|
|
119
|
+
assertNull(G2CfwRenderer.seededFramePayload(ByteArray(10), lensEqual))
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ── Dirty-rect planning ──────────────────────────────────────────────
|
|
123
|
+
|
|
124
|
+
private fun raster(width: Int, height: Int, paint: (ByteArray) -> Unit = {}): ByteArray =
|
|
125
|
+
ByteArray(width * height).also(paint)
|
|
126
|
+
|
|
127
|
+
@Test
|
|
128
|
+
fun identicalRastersPlanNothing() {
|
|
129
|
+
val base = raster(64, 32)
|
|
130
|
+
val plan = G2CfwRenderer.diffPlan(base, base, 64, 32, emptyList(), allowCopy = true)
|
|
131
|
+
assertTrue(plan.isNoop)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Test
|
|
135
|
+
fun smallChangeBecomesOneAlignedRect() {
|
|
136
|
+
val width = 64
|
|
137
|
+
val prev = raster(width, 32)
|
|
138
|
+
val next = raster(width, 32) {
|
|
139
|
+
it[9 * width + 13] = 0xFF.toByte()
|
|
140
|
+
it[10 * width + 17] = 0xFF.toByte()
|
|
141
|
+
}
|
|
142
|
+
val plan = G2CfwRenderer.diffPlan(prev, next, width, 32, emptyList(), allowCopy = true)
|
|
143
|
+
assertTrue(!plan.full)
|
|
144
|
+
assertNull(plan.copy)
|
|
145
|
+
assertEquals(listOf(G2CfwRenderer.CanvasRect(12, 8, 8, 4)), plan.rects)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@Test
|
|
149
|
+
fun distantChangesBecomeSeparateRectsAndLargeChangesGoFull() {
|
|
150
|
+
val width = 64
|
|
151
|
+
val prev = raster(width, 64)
|
|
152
|
+
val next = raster(width, 64) {
|
|
153
|
+
it[2 * width + 4] = 0xFF.toByte()
|
|
154
|
+
it[60 * width + 40] = 0xFF.toByte()
|
|
155
|
+
}
|
|
156
|
+
assertEquals(2, G2CfwRenderer.diffPlan(prev, next, width, 64, emptyList(), true).rects.size)
|
|
157
|
+
|
|
158
|
+
val noisy = raster(width, 32) {
|
|
159
|
+
for (i in it.indices step 2) it[i] = 0xFF.toByte()
|
|
160
|
+
}
|
|
161
|
+
assertTrue(G2CfwRenderer.diffPlan(raster(width, 32), noisy, width, 32, emptyList(), true).full)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@Test
|
|
165
|
+
fun forcedRectsDirtyUnchangedPixels() {
|
|
166
|
+
val base = raster(64, 32)
|
|
167
|
+
val plan =
|
|
168
|
+
G2CfwRenderer.diffPlan(
|
|
169
|
+
base, base, 64, 32,
|
|
170
|
+
listOf(G2CfwRenderer.CanvasRect(5, 3, 10, 6)), allowCopy = true,
|
|
171
|
+
)
|
|
172
|
+
assertTrue(!plan.full)
|
|
173
|
+
assertEquals(listOf(G2CfwRenderer.CanvasRect(4, 2, 12, 8)), plan.rects)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@Test
|
|
177
|
+
fun verticalScrollBecomesRectCopyPlusResidue() {
|
|
178
|
+
val width = 64
|
|
179
|
+
val height = 96
|
|
180
|
+
fun content(row: Int) = ((row * 7) % 251).toByte()
|
|
181
|
+
val prev = raster(width, height) {
|
|
182
|
+
for (y in 0 until height) for (x in 0 until width) {
|
|
183
|
+
it[y * width + x] = (content(y) + (x % 3)).toByte()
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
val next = raster(width, height) {
|
|
187
|
+
for (y in 0 until height) for (x in 0 until width) {
|
|
188
|
+
val source = y + 8
|
|
189
|
+
it[y * width + x] =
|
|
190
|
+
if (source < height) (content(source) + (x % 3)).toByte() else 0xEE.toByte()
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
val plan = G2CfwRenderer.diffPlan(prev, next, width, height, emptyList(), allowCopy = true)
|
|
194
|
+
assertTrue(!plan.full)
|
|
195
|
+
assertEquals(G2CfwRenderer.RowCopy(srcY = 8, dstY = 0, height = 88), plan.copy)
|
|
196
|
+
assertEquals(1, plan.rects.size)
|
|
197
|
+
assertEquals(88, plan.rects[0].y)
|
|
198
|
+
assertEquals(8, plan.rects[0].h)
|
|
199
|
+
|
|
200
|
+
assertNull(G2CfwRenderer.diffPlan(prev, next, width, height, emptyList(), allowCopy = false).copy)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ── Delta / copy / builtin-text wire formats ─────────────────────────
|
|
204
|
+
|
|
205
|
+
@Test
|
|
206
|
+
fun boxDeltaFrameOffsetsBothLensWindows() {
|
|
207
|
+
val b = boxes(height = 4, depth = 2) // left (24,128), right (40,128)
|
|
208
|
+
val rect = G2CfwRenderer.CanvasRect(100, 50, 32, 16)
|
|
209
|
+
val payload = G2CfwRenderer.boxDeltaFrame(raster(576, 288), 576, rect, b, 5)
|
|
210
|
+
assertNotNull(payload)
|
|
211
|
+
assertEquals(
|
|
212
|
+
listOf(0x83, (24 + 100) / 4, (128 + 50) / 2, 8, 8, (40 + 100) / 4, (128 + 50) / 2, 8, 8, 5, 0),
|
|
213
|
+
payload!!.take(11).map { it.toInt() and 0xFF },
|
|
214
|
+
)
|
|
215
|
+
assertEquals(0x78, payload[11].toInt() and 0xFF)
|
|
216
|
+
assertNull(
|
|
217
|
+
G2CfwRenderer.boxDeltaFrame(raster(576, 288), 576, G2CfwRenderer.CanvasRect(3, 0, 32, 16), b, 1)
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
@Test
|
|
222
|
+
fun rectCopyPayloadCarriesPerLensRectSets() {
|
|
223
|
+
val b = boxes(height = 4, depth = 2) // left (24,128), right (40,128)
|
|
224
|
+
val payload = G2CfwRenderer.rectCopyPayload(G2CfwRenderer.RowCopy(20, 8, 100), 576, b)
|
|
225
|
+
assertEquals(33, payload.size)
|
|
226
|
+
assertEquals(0x89, payload[0].toInt() and 0xFF)
|
|
227
|
+
fun u16(offset: Int) = (payload[offset].toInt() and 0xFF) or ((payload[offset + 1].toInt() and 0xFF) shl 8)
|
|
228
|
+
assertEquals(listOf(24, 148, 576, 100), listOf(u16(1), u16(3), u16(5), u16(7)))
|
|
229
|
+
assertEquals(listOf(24, 136, 576, 100), listOf(u16(9), u16(11), u16(13), u16(15)))
|
|
230
|
+
assertEquals(listOf(40, 148, 576, 100), listOf(u16(17), u16(19), u16(21), u16(23)))
|
|
231
|
+
assertEquals(listOf(40, 136, 576, 100), listOf(u16(25), u16(27), u16(29), u16(31)))
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@Test
|
|
235
|
+
fun builtinStringPayloadMatchesMode15Wire() {
|
|
236
|
+
val payload = G2CfwRenderer.builtinStringPayload(300, 130, 0x1F, "Hi ✓")
|
|
237
|
+
assertNotNull(payload)
|
|
238
|
+
val bytes = "Hi ✓".toByteArray(Charsets.UTF_8)
|
|
239
|
+
assertEquals(
|
|
240
|
+
listOf(15, 0x2C, 0x01, 130, 0, 0x1F, bytes.size),
|
|
241
|
+
payload!!.take(7).map { it.toInt() and 0xFF },
|
|
242
|
+
)
|
|
243
|
+
assertEquals(bytes.toList(), payload.drop(7))
|
|
244
|
+
|
|
245
|
+
// Bytes 1–31 are firmware x-adjust controls; raw control chars must not leak.
|
|
246
|
+
val cleaned = G2CfwRenderer.builtinStringPayload(0, 0, 0, "a\tbc")
|
|
247
|
+
assertEquals("abc".toByteArray(Charsets.UTF_8).toList(), cleaned!!.drop(7))
|
|
248
|
+
val truncated = G2CfwRenderer.builtinStringPayload(0, 0, 0, "é".repeat(200))
|
|
249
|
+
assertEquals(254, truncated!![6].toInt() and 0xFF) // no split codepoint
|
|
250
|
+
assertNull(G2CfwRenderer.builtinStringPayload(0, 0, 0, ""))
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
@Test
|
|
254
|
+
fun builtinTextDrawsSplitLinesAtTheLineHeight() {
|
|
255
|
+
val b = boxes(height = 4, depth = 1) // equal lens x = 32
|
|
256
|
+
val element =
|
|
257
|
+
SceneElement(
|
|
258
|
+
id = "t",
|
|
259
|
+
type = "text",
|
|
260
|
+
x = 10,
|
|
261
|
+
y = 20,
|
|
262
|
+
w = 200,
|
|
263
|
+
h = 80,
|
|
264
|
+
text = "one\ntwo",
|
|
265
|
+
data = null,
|
|
266
|
+
border = 0,
|
|
267
|
+
radius = 0,
|
|
268
|
+
change = "created",
|
|
269
|
+
contentHash = "",
|
|
270
|
+
font = "builtin",
|
|
271
|
+
)
|
|
272
|
+
val draws = G2CfwRenderer.builtinTextDraws(frame(element), b)
|
|
273
|
+
assertEquals(
|
|
274
|
+
listOf(
|
|
275
|
+
G2CfwRenderer.TextDraw(32 + 10 + 2, 128 + 20 + 2, "one"),
|
|
276
|
+
G2CfwRenderer.TextDraw(32 + 10 + 2, 128 + 20 + 2 + 27, "two"),
|
|
277
|
+
),
|
|
278
|
+
draws,
|
|
279
|
+
)
|
|
280
|
+
val bounds = G2CfwRenderer.builtinTextBounds(draws, b, 576, 288)
|
|
281
|
+
assertEquals(2, bounds.size)
|
|
282
|
+
assertEquals(8, bounds[0].x)
|
|
283
|
+
assertEquals(20, bounds[0].y)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
@Test
|
|
287
|
+
fun omittedBuiltinTextStillRasterizesItsBorder() {
|
|
288
|
+
val element =
|
|
289
|
+
SceneElement(
|
|
290
|
+
id = "apps-button",
|
|
291
|
+
type = "text",
|
|
292
|
+
x = 16,
|
|
293
|
+
y = 100,
|
|
294
|
+
w = 200,
|
|
295
|
+
h = 34,
|
|
296
|
+
text = "Apps",
|
|
297
|
+
data = null,
|
|
298
|
+
border = 2,
|
|
299
|
+
radius = 8,
|
|
300
|
+
change = "created",
|
|
301
|
+
contentHash = "",
|
|
302
|
+
font = "builtin",
|
|
303
|
+
)
|
|
304
|
+
val pixels = G2CfwRenderer.rasterize(frame(element), 576, 288, omitBuiltinText = true)
|
|
305
|
+
assertNotNull(pixels)
|
|
306
|
+
pixels!!
|
|
307
|
+
fun pixel(x: Int, y: Int) = pixels[y * 576 + x].toInt() and 0xFF
|
|
308
|
+
// Border edges (past the corner radius) are stroked white.
|
|
309
|
+
assertTrue(pixel(116, 101) > 100) // top edge
|
|
310
|
+
assertTrue(pixel(116, 132) > 100) // bottom edge
|
|
311
|
+
assertTrue(pixel(17, 117) > 100) // left edge
|
|
312
|
+
assertTrue(pixel(214, 117) > 100) // right edge
|
|
313
|
+
// Interior stays black: the glyphs are firmware-drawn (mode 15).
|
|
314
|
+
assertEquals(0, pixel(116, 117))
|
|
315
|
+
// A border-less builtin element is skipped entirely.
|
|
316
|
+
val plain = G2CfwRenderer.rasterize(
|
|
317
|
+
frame(element.copy(border = 0)), 576, 288, omitBuiltinText = true
|
|
318
|
+
)
|
|
319
|
+
assertNotNull(plain)
|
|
320
|
+
assertTrue(plain!!.all { it.toInt() == 0 })
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private fun boxes(height: Int, depth: Int) =
|
|
324
|
+
G2CfwRenderer.lensBoxes(576, 288, height, depth)
|
|
325
|
+
|
|
326
|
+
private fun rect(border: Int) =
|
|
327
|
+
SceneElement(
|
|
328
|
+
id = "r",
|
|
329
|
+
type = "rect",
|
|
330
|
+
x = 0,
|
|
331
|
+
y = 0,
|
|
332
|
+
w = 576,
|
|
333
|
+
h = 288,
|
|
334
|
+
text = null,
|
|
335
|
+
data = null,
|
|
336
|
+
border = border,
|
|
337
|
+
radius = 0,
|
|
338
|
+
change = "created",
|
|
339
|
+
contentHash = "",
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
private fun frame(element: SceneElement) =
|
|
343
|
+
SceneFrame(appId = "test", epoch = 1, replay = false, elements = listOf(element), removed = emptyList())
|
|
344
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
package com.glassly.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertArrayEquals
|
|
4
|
+
import org.junit.Assert.assertEquals
|
|
5
|
+
import org.junit.Assert.assertFalse
|
|
6
|
+
import org.junit.Assert.assertNotNull
|
|
7
|
+
import org.junit.Assert.assertNull
|
|
8
|
+
import org.junit.Assert.assertTrue
|
|
9
|
+
import org.junit.Test
|
|
10
|
+
import org.junit.runner.RunWith
|
|
11
|
+
import org.robolectric.RobolectricTestRunner
|
|
12
|
+
import org.robolectric.annotation.Config
|
|
13
|
+
import org.robolectric.annotation.GraphicsMode
|
|
14
|
+
|
|
15
|
+
@RunWith(RobolectricTestRunner::class)
|
|
16
|
+
@Config(sdk = [33])
|
|
17
|
+
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
|
18
|
+
class G2CfwTextureCacheTest {
|
|
19
|
+
// ── Flat RLE (cached-image contract: exact pixel count, no row pad) ─────
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
fun rleEncodePixelsCoversExactPixelCount() {
|
|
23
|
+
// 3 white pixels — the odd count must NOT gain a pad nibble.
|
|
24
|
+
assertArrayEquals(
|
|
25
|
+
byteArrayOf(0x3F),
|
|
26
|
+
G2CfwTextureCache.rleEncodePixels(byteArrayOf(0xFF.toByte(), 0xFF.toByte(), 0xF0.toByte())),
|
|
27
|
+
)
|
|
28
|
+
assertArrayEquals(
|
|
29
|
+
byteArrayOf(0x0F, 0, 0x2C, 0x01),
|
|
30
|
+
G2CfwTextureCache.rleEncodePixels(ByteArray(300) { 0xFF.toByte() }),
|
|
31
|
+
)
|
|
32
|
+
assertArrayEquals(
|
|
33
|
+
byteArrayOf(0x10, 0x1F),
|
|
34
|
+
G2CfwTextureCache.rleEncodePixels(byteArrayOf(0x00, 0xFF.toByte())),
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ── Cache model ─────────────────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
@Test
|
|
41
|
+
fun allocationsSkipTheZeroGuardAndPatchTheFontTable() {
|
|
42
|
+
val cache = G2CfwTextureCache()
|
|
43
|
+
cache.reset(1)
|
|
44
|
+
val font = cache.font(fontSize = 12, cellWidth = 4, lineHeight = 2)
|
|
45
|
+
assertNotNull(font)
|
|
46
|
+
font!!
|
|
47
|
+
// Bytes 0..1 stay zero (invalid-image guard); the table lands at 2.
|
|
48
|
+
assertEquals(2, font.tableOffset)
|
|
49
|
+
|
|
50
|
+
val raster = ByteArray(8) { 0xFF.toByte() } // 4×2 white cell
|
|
51
|
+
assertTrue(cache.ensureGlyph(font, 'A'.code) { raster })
|
|
52
|
+
// Second ensure is a no-op (no duplicate uploads).
|
|
53
|
+
assertTrue(cache.ensureGlyph(font, 'A'.code) { raster })
|
|
54
|
+
|
|
55
|
+
val payloads = cache.takeUploadPayloads()
|
|
56
|
+
assertEquals(1, payloads.size)
|
|
57
|
+
// [12] + glyph entry: image right after the 192-byte table (offset
|
|
58
|
+
// 194), [offset16][len16][w=4][h=2][RLE 8 white pixels = 0x8F] —
|
|
59
|
+
// + table-patch entry for slot ('A' - 32) pointing at that offset.
|
|
60
|
+
val glyphOffset = 2 + 96 * 2 // 194
|
|
61
|
+
val patchOffset = 2 + ('A'.code - 32) * 2
|
|
62
|
+
assertArrayEquals(
|
|
63
|
+
byteArrayOf(
|
|
64
|
+
12,
|
|
65
|
+
(glyphOffset and 0xFF).toByte(), (glyphOffset ushr 8).toByte(), 3, 0, 4, 2, 0x8F.toByte(),
|
|
66
|
+
(patchOffset and 0xFF).toByte(), (patchOffset ushr 8).toByte(), 2, 0,
|
|
67
|
+
(glyphOffset and 0xFF).toByte(), (glyphOffset ushr 8).toByte(),
|
|
68
|
+
),
|
|
69
|
+
payloads[0],
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
assertTrue(cache.takeUploadPayloads().isEmpty())
|
|
73
|
+
cache.reset(2)
|
|
74
|
+
// After a reset the same glyph re-uploads.
|
|
75
|
+
val font2 = cache.font(fontSize = 12, cellWidth = 4, lineHeight = 2)
|
|
76
|
+
assertNotNull(font2)
|
|
77
|
+
assertTrue(cache.ensureGlyph(font2!!, 'A'.code) { raster })
|
|
78
|
+
assertEquals(1, cache.takeUploadPayloads().size)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Test
|
|
82
|
+
fun imagePromotionRequiresASecondSighting() {
|
|
83
|
+
val cache = G2CfwTextureCache()
|
|
84
|
+
cache.reset(1)
|
|
85
|
+
assertFalse(cache.noteImageSighting("icon@10x10"))
|
|
86
|
+
assertTrue(cache.noteImageSighting("icon@10x10"))
|
|
87
|
+
val gray = ByteArray(100) { 0x80.toByte() }
|
|
88
|
+
val offset = cache.ensureImage("icon@10x10", gray, width = 10, height = 10)
|
|
89
|
+
assertNotNull(offset)
|
|
90
|
+
assertEquals(offset, cache.ensureImage("icon@10x10", gray, width = 10, height = 10))
|
|
91
|
+
assertNull(cache.ensureImage("big", ByteArray(300 * 10), width = 300, height = 10))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ── Draw payload wire formats ───────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
@Test
|
|
97
|
+
fun imageDrawPayloadMatchesMode13Wire() {
|
|
98
|
+
val payload = G2CfwTextureCache.imageDrawPayload(offset = 0x1234, x = 300, y = 130, options = 0x0F)
|
|
99
|
+
assertNotNull(payload)
|
|
100
|
+
assertArrayEquals(
|
|
101
|
+
byteArrayOf(13, 0x34, 0x12, 0x2C, 0x01, 130.toByte(), 0, 0x0F),
|
|
102
|
+
payload,
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Test
|
|
107
|
+
fun stringRunPayloadMatchesMode14Wire() {
|
|
108
|
+
val chars = "Hi".toByteArray(Charsets.US_ASCII)
|
|
109
|
+
val payload =
|
|
110
|
+
G2CfwTextureCache.stringRunPayload(fontTableOffset = 2, x = 40, y = 150, options = 0x0F, chars = chars)
|
|
111
|
+
assertNotNull(payload)
|
|
112
|
+
assertArrayEquals(
|
|
113
|
+
byteArrayOf(14, 2, 0, 40, 0, 150.toByte(), 0, 0x0F, 2) + chars,
|
|
114
|
+
payload,
|
|
115
|
+
)
|
|
116
|
+
// Control/non-ASCII bytes are x-adjust commands on the wire — rejected.
|
|
117
|
+
assertNull(G2CfwTextureCache.stringRunPayload(2, 0, 0, 0, byteArrayOf(10)))
|
|
118
|
+
assertNull(G2CfwTextureCache.stringRunPayload(2, 0, 0, 0, byteArrayOf(200.toByte())))
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ── End-to-end mono fast path ───────────────────────────────────────────
|
|
122
|
+
|
|
123
|
+
private fun monoFrame(text: String): SceneFrame =
|
|
124
|
+
SceneFrame(
|
|
125
|
+
appId = "t",
|
|
126
|
+
epoch = 1,
|
|
127
|
+
replay = false,
|
|
128
|
+
elements =
|
|
129
|
+
listOf(
|
|
130
|
+
SceneElement(
|
|
131
|
+
id = "screen", type = "text", x = 0, y = 0, w = 576, h = 288,
|
|
132
|
+
text = text, data = null, border = 0, radius = 0,
|
|
133
|
+
change = "updated", contentHash = "", font = "mono", fontSize = 12,
|
|
134
|
+
)
|
|
135
|
+
),
|
|
136
|
+
removed = emptyList(),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
@Test
|
|
140
|
+
fun monoTextChangeBecomesCachedGlyphRunsNotBitmapDeltas() {
|
|
141
|
+
// Depth level 1 = lens-equal window, the texture-path requirement.
|
|
142
|
+
val boxes = G2CfwRenderer.lensBoxes(576, 288, heightLevel = 4, depthLevel = 1)
|
|
143
|
+
val fids = List(G2CfwRenderer.REQUIRED_FID_COUNT) { it + 1 }
|
|
144
|
+
|
|
145
|
+
val first =
|
|
146
|
+
G2CfwRenderer.encodeUpdate(
|
|
147
|
+
monoFrame("hello world\nrow two"), boxes, previousRaster = null,
|
|
148
|
+
forcedRects = emptyList(), fids = fids, textDraws = emptyList(),
|
|
149
|
+
allowRectCopy = true, blankBoxes = null, omitBuiltinText = false,
|
|
150
|
+
textureGlyphsEnabled = true, textureImagesEnabled = true, cacheGeneration = 7,
|
|
151
|
+
)
|
|
152
|
+
assertNotNull(first)
|
|
153
|
+
assertTrue(first!!.usedFullFrame)
|
|
154
|
+
|
|
155
|
+
val second =
|
|
156
|
+
G2CfwRenderer.encodeUpdate(
|
|
157
|
+
monoFrame("hello there\nrow two"), boxes, previousRaster = first.raster,
|
|
158
|
+
forcedRects = emptyList(), fids = fids, textDraws = emptyList(),
|
|
159
|
+
allowRectCopy = true, blankBoxes = null, omitBuiltinText = false,
|
|
160
|
+
textureGlyphsEnabled = true, textureImagesEnabled = true, cacheGeneration = 7,
|
|
161
|
+
)
|
|
162
|
+
assertNotNull(second)
|
|
163
|
+
second!!
|
|
164
|
+
assertFalse(second.usedFullFrame)
|
|
165
|
+
// The changed cells travel as mode-12 uploads + mode-14 runs; no
|
|
166
|
+
// bitmap delta (0x83) should remain for a pure-ASCII grid change.
|
|
167
|
+
assertTrue(second.uploads.isNotEmpty())
|
|
168
|
+
assertTrue(second.uploads.all { it.first() == 12.toByte() })
|
|
169
|
+
val payload = second.payload
|
|
170
|
+
assertNotNull(payload)
|
|
171
|
+
payload!!
|
|
172
|
+
if (payload.first() == 8.toByte()) {
|
|
173
|
+
val segments = mutableListOf<Byte>()
|
|
174
|
+
var pos = 2
|
|
175
|
+
while (pos + 2 <= payload.size) {
|
|
176
|
+
val len = (payload[pos].toInt() and 0xFF) or ((payload[pos + 1].toInt() and 0xFF) shl 8)
|
|
177
|
+
pos += 2
|
|
178
|
+
if (pos < payload.size) segments.add(payload[pos])
|
|
179
|
+
pos += len
|
|
180
|
+
}
|
|
181
|
+
assertTrue(segments.contains(14.toByte()))
|
|
182
|
+
assertFalse(segments.contains(0x83.toByte()))
|
|
183
|
+
} else {
|
|
184
|
+
assertEquals(14.toByte(), payload.first())
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A lens-unequal window must fall back to plain bitmap deltas.
|
|
188
|
+
val stereo = G2CfwRenderer.lensBoxes(576, 288, heightLevel = 4, depthLevel = 2)
|
|
189
|
+
val plain =
|
|
190
|
+
G2CfwRenderer.encodeUpdate(
|
|
191
|
+
monoFrame("hello"), stereo, previousRaster = null,
|
|
192
|
+
forcedRects = emptyList(), fids = fids, textDraws = emptyList(),
|
|
193
|
+
allowRectCopy = true, blankBoxes = null, omitBuiltinText = false,
|
|
194
|
+
textureGlyphsEnabled = true, textureImagesEnabled = true, cacheGeneration = 7,
|
|
195
|
+
)
|
|
196
|
+
assertNotNull(plain)
|
|
197
|
+
assertTrue(plain!!.uploads.isEmpty())
|
|
198
|
+
assertEquals(0x83.toByte(), plain.payload?.first())
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
package com.glassly.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import androidx.test.core.app.ApplicationProvider
|
|
4
|
+
import java.io.FileNotFoundException
|
|
5
|
+
import org.junit.Assert.assertArrayEquals
|
|
6
|
+
import org.junit.Assert.assertEquals
|
|
7
|
+
import org.junit.Assert.assertNotNull
|
|
8
|
+
import org.junit.Assert.assertNull
|
|
9
|
+
import org.junit.Assert.assertTrue
|
|
10
|
+
import org.junit.Assume.assumeTrue
|
|
11
|
+
import org.junit.Test
|
|
12
|
+
import org.robolectric.RobolectricTestRunner
|
|
13
|
+
import org.junit.runner.RunWith
|
|
14
|
+
import org.robolectric.annotation.Config
|
|
15
|
+
|
|
16
|
+
@RunWith(RobolectricTestRunner::class)
|
|
17
|
+
@Config(sdk = [33])
|
|
18
|
+
class G2FlashProtocolTest {
|
|
19
|
+
@Test
|
|
20
|
+
fun crcGoldenVectorsMatchFirmwareTools() {
|
|
21
|
+
assertArrayEquals(byteArrayOf(0xB1.toByte(), 0x29), G2FlashProtocol.crc16("123456789".toByteArray()))
|
|
22
|
+
assertEquals(0xC052_A8C8L, G2FlashProtocol.crc32c("123456789".toByteArray()))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Test
|
|
26
|
+
fun framesCarrySharedSequenceAndCrc() {
|
|
27
|
+
val payload = byteArrayOf(1, 2, 3)
|
|
28
|
+
val frames = G2FlashProtocol.frames(sid = 0xC1, pb = payload, seq = 0x44)
|
|
29
|
+
assertEquals(1, frames.size)
|
|
30
|
+
assertEquals(listOf(0xAA, 0x21, 0x44, 5, 1, 1, 0xC1, 0), frames[0].take(8).unsigned())
|
|
31
|
+
assertArrayEquals(payload, frames[0].copyOfRange(8, 11))
|
|
32
|
+
assertArrayEquals(G2FlashProtocol.crc16(payload), frames[0].takeLast(2).toByteArray())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Test
|
|
36
|
+
fun replyParserMatchesOpcodeWithoutSequenceOrSidEcho() {
|
|
37
|
+
assertNull(G2FlashProtocol.parseRx(bytes(0xAA, 0x21, 0, 0, 0, 0, 0, 0, 0, 0)))
|
|
38
|
+
val parsed = G2FlashProtocol.parseRx(bytes(0xAA, 0x12, 7, 4, 1, 1, 0xC0, 0, 3, 8))
|
|
39
|
+
assertNotNull(parsed)
|
|
40
|
+
assertEquals(7, parsed?.sequence)
|
|
41
|
+
assertEquals(0xC0, parsed?.sid)
|
|
42
|
+
assertArrayEquals(byteArrayOf(3, 8), parsed?.pb)
|
|
43
|
+
|
|
44
|
+
val unrelated = bytes(0xAA, 0x12, 3, 4, 1, 1, 0xC0, 0, 1, 0)
|
|
45
|
+
val blockAck = bytes(0xAA, 0x12, 99, 4, 1, 1, 0xC1, 0, 2, 0)
|
|
46
|
+
assertEquals(0, G2FlashProtocol.otaAckStatus(listOf(unrelated, blockAck), opcode = 0x02))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Test
|
|
50
|
+
fun preflightAcceptsConsistentImageAndRejectsPayloadCorruption() {
|
|
51
|
+
val image = makeFirmware()
|
|
52
|
+
val validated = G2Flasher.preflight(image)
|
|
53
|
+
assertEquals(5, validated.segments.size)
|
|
54
|
+
assertTrue(validated.guardResult.pass)
|
|
55
|
+
|
|
56
|
+
val first = G2FlashProtocol.parseSegments(image).first()
|
|
57
|
+
val corrupt = image.copyOf()
|
|
58
|
+
corrupt[first.off.toInt() + 128] = (corrupt[first.off.toInt() + 128].toInt() xor 1).toByte()
|
|
59
|
+
val error = runCatching { G2Flasher.preflight(corrupt) }.exceptionOrNull()
|
|
60
|
+
assertTrue(error?.message.orEmpty().contains("CRC32C mismatch"))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test
|
|
64
|
+
fun preflightRejectsStaleSubheaderCrc() {
|
|
65
|
+
val image = makeFirmware()
|
|
66
|
+
val first = G2FlashProtocol.parseSegments(image).first()
|
|
67
|
+
image[first.off.toInt() + 12] = (image[first.off.toInt() + 12].toInt() xor 1).toByte()
|
|
68
|
+
val error = runCatching { G2Flasher.preflight(image) }.exceptionOrNull()
|
|
69
|
+
assertTrue(error?.message.orEmpty().contains("CRC32C mismatch"))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Test
|
|
73
|
+
fun locallyBundledFirmwarePassesFullValidationWhenAvailable() {
|
|
74
|
+
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
|
|
75
|
+
val available =
|
|
76
|
+
try {
|
|
77
|
+
context.assets.list("G2Firmware").orEmpty().filter { it.endsWith(".bin") }.toSet()
|
|
78
|
+
} catch (_: FileNotFoundException) {
|
|
79
|
+
emptySet()
|
|
80
|
+
}
|
|
81
|
+
assumeTrue("Firmware binaries are intentionally absent from fresh clones", available.isNotEmpty())
|
|
82
|
+
assertEquals(G2FirmwareCatalog.artifacts.map { it.fileName }.toSet(), available)
|
|
83
|
+
for (artifact in G2FirmwareCatalog.artifacts) {
|
|
84
|
+
G2Flasher.preflight(G2FirmwareCatalog.load(context, artifact))
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private fun makeFirmware(): ByteArray {
|
|
89
|
+
val names =
|
|
90
|
+
listOf(
|
|
91
|
+
"firmware/codec.bin",
|
|
92
|
+
"firmware/ble.bin",
|
|
93
|
+
"firmware/touch.bin",
|
|
94
|
+
"ota/s200_bootloader.bin",
|
|
95
|
+
G2FlashProtocol.REQUIRED_SEGMENT,
|
|
96
|
+
)
|
|
97
|
+
var image = ByteArray(0x100)
|
|
98
|
+
writeU32(names.size.toLong(), 8, image)
|
|
99
|
+
var offset = 0x100
|
|
100
|
+
for ((index, name) in names.withIndex()) {
|
|
101
|
+
val payload = ByteArray(32) { (index + 1).toByte() }
|
|
102
|
+
if (name == G2FlashProtocol.REQUIRED_SEGMENT) {
|
|
103
|
+
writeU32(payload.size.toLong(), 0, payload)
|
|
104
|
+
writeU32(G2FlashProtocol.APP_LOAD_ADDR, 0x14, payload)
|
|
105
|
+
}
|
|
106
|
+
val crc = G2FlashProtocol.crc32c(payload)
|
|
107
|
+
val end = offset + 128 + payload.size
|
|
108
|
+
if (image.size < end) image = image.copyOf(end)
|
|
109
|
+
|
|
110
|
+
val toc = 0x40 + index * 16
|
|
111
|
+
writeU32((index + 1).toLong(), toc, image)
|
|
112
|
+
writeU32(offset.toLong(), toc + 4, image)
|
|
113
|
+
writeU32((payload.size + 128).toLong(), toc + 8, image)
|
|
114
|
+
writeU32(crc, toc + 12, image)
|
|
115
|
+
writeU32(payload.size.toLong(), offset + 8, image)
|
|
116
|
+
writeU32(crc, offset + 12, image)
|
|
117
|
+
name.toByteArray(Charsets.ISO_8859_1).copyInto(image, offset + 48)
|
|
118
|
+
payload.copyInto(image, offset + 128)
|
|
119
|
+
offset = end
|
|
120
|
+
}
|
|
121
|
+
return image
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private fun writeU32(value: Long, offset: Int, bytes: ByteArray) {
|
|
125
|
+
repeat(4) { index -> bytes[offset + index] = ((value ushr (index * 8)) and 0xFF).toByte() }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private fun bytes(vararg values: Int): ByteArray = ByteArray(values.size) { values[it].toByte() }
|
|
129
|
+
|
|
130
|
+
private fun List<Byte>.unsigned(): List<Int> = map { it.toInt() and 0xFF }
|
|
131
|
+
}
|