simpleble 0.0.1
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +88 -0
- data/LICENSE.txt +21 -0
- data/README.md +350 -0
- data/ext/simpleble/extconf.rb +57 -0
- data/ext/simpleble/simpleble_ruby.c +682 -0
- data/lib/simpleble/adapter.rb +10 -0
- data/lib/simpleble/characteristic.rb +36 -0
- data/lib/simpleble/descriptor.rb +8 -0
- data/lib/simpleble/exceptions.rb +25 -0
- data/lib/simpleble/peripheral.rb +64 -0
- data/lib/simpleble/service.rb +16 -0
- data/lib/simpleble/version.rb +3 -0
- data/lib/simpleble.rb +40 -0
- data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/CMakeCXXCompilerId.cpp +920 -0
- data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/apple-sdk.cpp +1 -0
- data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/CMakeCXXCompilerId.cpp +949 -0
- data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/apple-sdk.cpp +1 -0
- data/vendor/simpleble/build_simplecble/export/simplecble/export.h +43 -0
- data/vendor/simpleble/build_simplecble/simpleble/export/simpleble/export.h +43 -0
- data/vendor/simpleble/dependencies/external/kvn/kvn_bytearray.h +222 -0
- data/vendor/simpleble/dependencies/external/kvn/kvn_safe_callback.hpp +66 -0
- data/vendor/simpleble/dependencies/external/kvn/logfwd.hpp +35 -0
- data/vendor/simpleble/dependencies/internal/fmt/args.h +220 -0
- data/vendor/simpleble/dependencies/internal/fmt/base.h +2962 -0
- data/vendor/simpleble/dependencies/internal/fmt/chrono.h +2338 -0
- data/vendor/simpleble/dependencies/internal/fmt/color.h +610 -0
- data/vendor/simpleble/dependencies/internal/fmt/compile.h +539 -0
- data/vendor/simpleble/dependencies/internal/fmt/core.h +5 -0
- data/vendor/simpleble/dependencies/internal/fmt/format-inl.h +1949 -0
- data/vendor/simpleble/dependencies/internal/fmt/format.h +4244 -0
- data/vendor/simpleble/dependencies/internal/fmt/os.h +427 -0
- data/vendor/simpleble/dependencies/internal/fmt/ostream.h +166 -0
- data/vendor/simpleble/dependencies/internal/fmt/printf.h +633 -0
- data/vendor/simpleble/dependencies/internal/fmt/ranges.h +850 -0
- data/vendor/simpleble/dependencies/internal/fmt/std.h +726 -0
- data/vendor/simpleble/dependencies/internal/fmt/xchar.h +373 -0
- data/vendor/simpleble/dependencies/internal/simplejni/Common.hpp +579 -0
- data/vendor/simpleble/dependencies/internal/simplejni/References.hpp +151 -0
- data/vendor/simpleble/dependencies/internal/simplejni/Registry.hpp +183 -0
- data/vendor/simpleble/dependencies/internal/simplejni/VM.hpp +88 -0
- data/vendor/simpleble/examples/simpleble/src/connect.cpp +67 -0
- data/vendor/simpleble/examples/simpleble/src/connect_safe.cpp +91 -0
- data/vendor/simpleble/examples/simpleble/src/list_adapters.cpp +22 -0
- data/vendor/simpleble/examples/simpleble/src/list_adapters_safe.cpp +33 -0
- data/vendor/simpleble/examples/simpleble/src/list_paired.cpp +27 -0
- data/vendor/simpleble/examples/simpleble/src/multiconnect.cpp +60 -0
- data/vendor/simpleble/examples/simpleble/src/notify.cpp +85 -0
- data/vendor/simpleble/examples/simpleble/src/notify_multi.cpp +101 -0
- data/vendor/simpleble/examples/simpleble/src/power_cycle.cpp +43 -0
- data/vendor/simpleble/examples/simpleble/src/read.cpp +82 -0
- data/vendor/simpleble/examples/simpleble/src/scan.cpp +62 -0
- data/vendor/simpleble/examples/simpleble/src/utils.cpp +59 -0
- data/vendor/simpleble/examples/simpleble/src/utils.hpp +27 -0
- data/vendor/simpleble/examples/simpleble/src/write.cpp +81 -0
- data/vendor/simpleble/examples/simplebluez/ble_nus/ble_nus.cpp +138 -0
- data/vendor/simpleble/examples/simplebluez/connect/connect.cpp +119 -0
- data/vendor/simpleble/examples/simplebluez/list_adapters/list_adapters.cpp +44 -0
- data/vendor/simpleble/examples/simplebluez/list_paired/list_paired.cpp +48 -0
- data/vendor/simpleble/examples/simplebluez/notify/notify.cpp +145 -0
- data/vendor/simpleble/examples/simplebluez/pair/pair.cpp +181 -0
- data/vendor/simpleble/examples/simplebluez/read/read.cpp +141 -0
- data/vendor/simpleble/examples/simplebluez/scan/scan.cpp +85 -0
- data/vendor/simpleble/examples/simplecble/c/connect.c +163 -0
- data/vendor/simpleble/examples/simplecble/c/notify.c +217 -0
- data/vendor/simpleble/examples/simplecble/c/scan.c +164 -0
- data/vendor/simpleble/examples/simpledbus/notification.cpp +24 -0
- data/vendor/simpleble/hitl/src/test_sanity.cpp +48 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Adapter.h +102 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/AdapterSafe.h +58 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Advanced.h +50 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Characteristic.h +39 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Config.h +55 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Descriptor.h +30 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Exceptions.h +72 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Logging.h +73 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Peripheral.h +82 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/PeripheralSafe.h +64 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Service.h +34 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/SimpleBLE.h +8 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Types.h +49 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/Utils.h +13 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/export.h +43 -0
- data/vendor/simpleble/install_simplecble/include/simpleble/kvn/kvn_bytearray.h +222 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/adapter.h +188 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/logging.h +37 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/peripheral.h +304 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/simpleble.h +21 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/types.h +73 -0
- data/vendor/simpleble/install_simplecble/include/simplecble/utils.h +27 -0
- data/vendor/simpleble/simpleble/include/simpleble/Adapter.h +102 -0
- data/vendor/simpleble/simpleble/include/simpleble/AdapterSafe.h +58 -0
- data/vendor/simpleble/simpleble/include/simpleble/Characteristic.h +39 -0
- data/vendor/simpleble/simpleble/include/simpleble/Config.h +55 -0
- data/vendor/simpleble/simpleble/include/simpleble/Descriptor.h +30 -0
- data/vendor/simpleble/simpleble/include/simpleble/Exceptions.h +72 -0
- data/vendor/simpleble/simpleble/include/simpleble/Logging.h +73 -0
- data/vendor/simpleble/simpleble/include/simpleble/Peripheral.h +82 -0
- data/vendor/simpleble/simpleble/include/simpleble/PeripheralSafe.h +64 -0
- data/vendor/simpleble/simpleble/include/simpleble/Service.h +34 -0
- data/vendor/simpleble/simpleble/include/simpleble/SimpleBLE.h +8 -0
- data/vendor/simpleble/simpleble/include/simpleble/Types.h +49 -0
- data/vendor/simpleble/simpleble/include/simpleble/Utils.h +13 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/adapter.h +188 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/logging.h +37 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/peripheral.h +304 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/simpleble.h +21 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/types.h +73 -0
- data/vendor/simpleble/simpleble/include/simpleble_c/utils.h +27 -0
- data/vendor/simpleble/simpleble/src/CommonUtils.h +63 -0
- data/vendor/simpleble/simpleble/src/Exceptions.cpp +31 -0
- data/vendor/simpleble/simpleble/src/Logging.cpp +136 -0
- data/vendor/simpleble/simpleble/src/LoggingInternal.h +85 -0
- data/vendor/simpleble/simpleble/src/Utils.cpp +24 -0
- data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.cpp +101 -0
- data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.h +70 -0
- data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.cpp +40 -0
- data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.h +20 -0
- data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.cpp +365 -0
- data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.h +90 -0
- data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.cpp +432 -0
- data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.h +102 -0
- data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.cpp +142 -0
- data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.h +55 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.cpp +107 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.h +55 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.cpp +68 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.h +54 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.cpp +115 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.h +75 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.cpp +142 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.h +66 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.cpp +67 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.h +46 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.cpp +106 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.h +47 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.cpp +47 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.h +37 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.cpp +69 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.h +41 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.cpp +63 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.h +42 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.cpp +32 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.h +30 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.cpp +54 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.h +37 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.cpp +36 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.h +28 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.cpp +29 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.h +27 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.cpp +33 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.h +28 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.cpp +26 -0
- data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.h +29 -0
- data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.cpp +53 -0
- data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.h +81 -0
- data/vendor/simpleble/simpleble/src/backends/common/AdapterBaseTypes.h +22 -0
- data/vendor/simpleble/simpleble/src/backends/common/BackendBase.h +20 -0
- data/vendor/simpleble/simpleble/src/backends/common/BackendUtils.h +33 -0
- data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.cpp +28 -0
- data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.h +38 -0
- data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.cpp +7 -0
- data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.h +19 -0
- data/vendor/simpleble/simpleble/src/backends/common/PeripheralBase.h +82 -0
- data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.cpp +18 -0
- data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.h +28 -0
- data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.cpp +102 -0
- data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.h +55 -0
- data/vendor/simpleble/simpleble/src/backends/linux/BackendBluez.cpp +87 -0
- data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.cpp +376 -0
- data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.h +90 -0
- data/vendor/simpleble/simpleble/src/backends/macos/AdapterBaseMacOS.h +29 -0
- data/vendor/simpleble/simpleble/src/backends/macos/AdapterMac.h +78 -0
- data/vendor/simpleble/simpleble/src/backends/macos/PeripheralBaseMacOS.h +49 -0
- data/vendor/simpleble/simpleble/src/backends/macos/PeripheralMac.h +81 -0
- data/vendor/simpleble/simpleble/src/backends/macos/Utils.h +9 -0
- data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.cpp +65 -0
- data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.h +49 -0
- data/vendor/simpleble/simpleble/src/backends/plain/BackendPlain.cpp +30 -0
- data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.cpp +159 -0
- data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.h +72 -0
- data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.cpp +330 -0
- data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.h +89 -0
- data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.cpp +67 -0
- data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.h +18 -0
- data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.cpp +49 -0
- data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.h +90 -0
- data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.cpp +487 -0
- data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.h +129 -0
- data/vendor/simpleble/simpleble/src/backends/windows/Utils.cpp +146 -0
- data/vendor/simpleble/simpleble/src/backends/windows/Utils.h +47 -0
- data/vendor/simpleble/simpleble/src/builders/BuildVec.h +32 -0
- data/vendor/simpleble/simpleble/src/builders/BuilderBase.h +87 -0
- data/vendor/simpleble/simpleble/src/external/TaskRunner.hpp +99 -0
- data/vendor/simpleble/simpleble/src/external/ThreadRunner.h +52 -0
- data/vendor/simpleble/simpleble/src/external/kvn_safe_callback.hpp +66 -0
- data/vendor/simpleble/simpleble/src/external/kvn_safe_map.hpp +94 -0
- data/vendor/simpleble/simpleble/src/external/kvn_threadrunner.hpp +70 -0
- data/vendor/simpleble/simpleble/src/external/logfwd.hpp +35 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Adapter.cpp +111 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Backend.cpp +83 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Backend.h +76 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Characteristic.cpp +56 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Descriptor.cpp +21 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Peripheral.cpp +113 -0
- data/vendor/simpleble/simpleble/src/frontends/base/Service.cpp +26 -0
- data/vendor/simpleble/simpleble/src/frontends/safe/AdapterSafe.cpp +158 -0
- data/vendor/simpleble/simpleble/src/frontends/safe/PeripheralSafe.cpp +219 -0
- data/vendor/simpleble/simpleble/src_c/adapter.cpp +204 -0
- data/vendor/simpleble/simpleble/src_c/logging.cpp +19 -0
- data/vendor/simpleble/simpleble/src_c/peripheral.cpp +444 -0
- data/vendor/simpleble/simpleble/src_c/simpleble.cpp +5 -0
- data/vendor/simpleble/simpleble/src_c/utils.cpp +15 -0
- data/vendor/simpleble/simpleble/test/src/main.cpp +8 -0
- data/vendor/simpleble/simpleble/test/src/test_bytearray.cpp +246 -0
- data/vendor/simpleble/simpleble/test/src/test_utils.cpp +24 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Adapter.h +46 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Agent.h +52 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Bluez.h +37 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrg.h +22 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrgBluez.h +26 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/BluezRoot.h +32 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Characteristic.h +46 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Descriptor.h +33 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Device.h +64 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Exceptions.h +43 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Service.h +27 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/Types.h +9 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Adapter1.h +49 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Agent1.h +100 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/AgentManager1.h +24 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Battery1.h +32 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Device1.h +62 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattCharacteristic1.h +48 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattDescriptor1.h +41 -0
- data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattService1.h +28 -0
- data/vendor/simpleble/simplebluez/src/Adapter.cpp +78 -0
- data/vendor/simpleble/simplebluez/src/Agent.cpp +72 -0
- data/vendor/simpleble/simplebluez/src/Bluez.cpp +45 -0
- data/vendor/simpleble/simplebluez/src/BluezOrg.cpp +20 -0
- data/vendor/simpleble/simplebluez/src/BluezOrgBluez.cpp +23 -0
- data/vendor/simpleble/simplebluez/src/BluezRoot.cpp +44 -0
- data/vendor/simpleble/simplebluez/src/Characteristic.cpp +64 -0
- data/vendor/simpleble/simplebluez/src/Descriptor.cpp +27 -0
- data/vendor/simpleble/simplebluez/src/Device.cpp +104 -0
- data/vendor/simpleble/simplebluez/src/Exceptions.cpp +29 -0
- data/vendor/simpleble/simplebluez/src/Logging.cpp +52 -0
- data/vendor/simpleble/simplebluez/src/Logging.h +57 -0
- data/vendor/simpleble/simplebluez/src/Service.cpp +33 -0
- data/vendor/simpleble/simplebluez/src/interfaces/Adapter1.cpp +123 -0
- data/vendor/simpleble/simplebluez/src/interfaces/Agent1.cpp +143 -0
- data/vendor/simpleble/simplebluez/src/interfaces/AgentManager1.cpp +34 -0
- data/vendor/simpleble/simplebluez/src/interfaces/Battery1.cpp +30 -0
- data/vendor/simpleble/simplebluez/src/interfaces/Device1.cpp +170 -0
- data/vendor/simpleble/simplebluez/src/interfaces/GattCharacteristic1.cpp +118 -0
- data/vendor/simpleble/simplebluez/src/interfaces/GattDescriptor1.cpp +78 -0
- data/vendor/simpleble/simplebluez/src/interfaces/GattService1.cpp +28 -0
- data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.cpp +53 -0
- data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.h +24 -0
- data/vendor/simpleble/simplebluez/test/src/main.cpp +16 -0
- data/vendor/simpleble/simplecble/include/simplecble/adapter.h +188 -0
- data/vendor/simpleble/simplecble/include/simplecble/logging.h +37 -0
- data/vendor/simpleble/simplecble/include/simplecble/peripheral.h +304 -0
- data/vendor/simpleble/simplecble/include/simplecble/simpleble.h +21 -0
- data/vendor/simpleble/simplecble/include/simplecble/types.h +73 -0
- data/vendor/simpleble/simplecble/include/simplecble/utils.h +27 -0
- data/vendor/simpleble/simplecble/src/adapter.cpp +204 -0
- data/vendor/simpleble/simplecble/src/logging.cpp +19 -0
- data/vendor/simpleble/simplecble/src/peripheral.cpp +444 -0
- data/vendor/simpleble/simplecble/src/simpleble.cpp +5 -0
- data/vendor/simpleble/simplecble/src/utils.cpp +15 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Interface.h +67 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/advanced/InterfaceRegistry.h +64 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Proxy.h +117 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Connection.h +50 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Exceptions.h +56 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Holder.h +147 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Logging.h +57 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Message.h +89 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/base/Path.h +24 -0
- data/vendor/simpleble/simpledbus/include/simpledbus/interfaces/ObjectManager.h +26 -0
- data/vendor/simpleble/simpledbus/src/advanced/Interface.cpp +155 -0
- data/vendor/simpleble/simpledbus/src/advanced/Proxy.cpp +375 -0
- data/vendor/simpleble/simpledbus/src/base/Connection.cpp +222 -0
- data/vendor/simpleble/simpledbus/src/base/Exceptions.cpp +39 -0
- data/vendor/simpleble/simpledbus/src/base/Holder.cpp +739 -0
- data/vendor/simpleble/simpledbus/src/base/Logging.cpp +52 -0
- data/vendor/simpleble/simpledbus/src/base/Message.cpp +622 -0
- data/vendor/simpleble/simpledbus/src/base/Path.cpp +129 -0
- data/vendor/simpleble/simpledbus/src/interfaces/ObjectManager.cpp +58 -0
- data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.cpp +53 -0
- data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.h +24 -0
- data/vendor/simpleble/simpledbus/test/src/main.cpp +16 -0
- data/vendor/simpleble/simpledbus/test/src/test_holder.cpp +184 -0
- data/vendor/simpleble/simpledbus/test/src/test_message.cpp +397 -0
- data/vendor/simpleble/simpledbus/test/src/test_path.cpp +76 -0
- data/vendor/simpleble/simpledbus/test/src/test_proxy_children.cpp +109 -0
- data/vendor/simpleble/simpledbus/test/src/test_proxy_interfaces.cpp +102 -0
- data/vendor/simpleble/simpledbus/test/src/test_proxy_lifetime.cpp +18 -0
- data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/ThreadRunner.h +89 -0
- data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.cpp +55 -0
- data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.h +18 -0
- data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/simpleble_android.cpp +813 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.cpp +37 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.h +23 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/Cache.cpp +58 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/Cache.h +34 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.cpp +17 -0
- data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.h +19 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.cpp +257 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.h +78 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.cpp +96 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.h +54 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.cpp +93 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.h +49 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.cpp +85 -0
- data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.h +48 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.cpp +91 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.h +90 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.cpp +35 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.h +60 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.cpp +33 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.h +45 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.cpp +30 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.h +49 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.cpp +41 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.h +51 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.cpp +33 -0
- data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.h +54 -0
- data/vendor/simpleble/simplejavable/cpp/src/simplejavable.cpp +361 -0
- data/vendor/simpleble/simplepyble/src/main.cpp +55 -0
- data/vendor/simpleble/simplepyble/src/wrap_adapter.cpp +106 -0
- data/vendor/simpleble/simplepyble/src/wrap_characteristic.cpp +56 -0
- data/vendor/simpleble/simplepyble/src/wrap_config.cpp +136 -0
- data/vendor/simpleble/simplepyble/src/wrap_descriptor.cpp +21 -0
- data/vendor/simpleble/simplepyble/src/wrap_peripheral.cpp +217 -0
- data/vendor/simpleble/simplepyble/src/wrap_service.cpp +32 -0
- data/vendor/simpleble/simplepyble/src/wrap_types.cpp +21 -0
- data/vendor/simpleble/simplersble/src/bindings/Bindings.cpp +338 -0
- data/vendor/simpleble/simplersble/src/bindings/Bindings.hpp +178 -0
- metadata +430 -0
@@ -0,0 +1,365 @@
|
|
1
|
+
#include "PeripheralAndroid.h"
|
2
|
+
|
3
|
+
#include "BuildVec.h"
|
4
|
+
#include "BuilderBase.h"
|
5
|
+
#include "CharacteristicBase.h"
|
6
|
+
#include "DescriptorBase.h"
|
7
|
+
#include "ServiceBase.h"
|
8
|
+
|
9
|
+
#include <simpleble/Exceptions.h>
|
10
|
+
#include <simpleble/Config.h>
|
11
|
+
#include <algorithm>
|
12
|
+
#include "CommonUtils.h"
|
13
|
+
#include "LoggingInternal.h"
|
14
|
+
#include "simpleble/Descriptor.h"
|
15
|
+
|
16
|
+
using namespace SimpleBLE;
|
17
|
+
using namespace std::chrono_literals;
|
18
|
+
|
19
|
+
PeripheralAndroid::PeripheralAndroid(Android::BluetoothDevice device) : _device(device) {
|
20
|
+
_btGattCallback.set_callback_onConnectionStateChange([this](bool connected) {
|
21
|
+
if (connected) {
|
22
|
+
if (Config::Android::connection_priority_request != Config::Android::ConnectionPriorityRequest::DISABLED) {
|
23
|
+
_gatt.requestConnectionPriority(static_cast<int>(Config::Android::connection_priority_request));
|
24
|
+
}
|
25
|
+
|
26
|
+
// If a connection has been established, request service discovery.
|
27
|
+
_gatt.discoverServices();
|
28
|
+
} else {
|
29
|
+
// If a connection has been lost, close the GATT object.
|
30
|
+
_gatt.close();
|
31
|
+
SAFE_CALLBACK_CALL(callback_on_disconnected_);
|
32
|
+
_disconnection_cv.notify_all();
|
33
|
+
}
|
34
|
+
});
|
35
|
+
|
36
|
+
_btGattCallback.set_callback_onServicesDiscovered([this]() {
|
37
|
+
// Once services have been discovered, store them and notify the user.
|
38
|
+
_services = _gatt.getServices();
|
39
|
+
SAFE_CALLBACK_CALL(callback_on_connected_);
|
40
|
+
_connection_cv.notify_all();
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
PeripheralAndroid::~PeripheralAndroid() {}
|
45
|
+
|
46
|
+
void PeripheralAndroid::update_advertising_data(Android::ScanResult scan_result) {
|
47
|
+
rssi_ = scan_result.getRssi();
|
48
|
+
tx_power_ = scan_result.getTxPower();
|
49
|
+
connectable_ = scan_result.isConnectable();
|
50
|
+
|
51
|
+
auto scan_record = scan_result.getScanRecord();
|
52
|
+
auto service_uuids = scan_record.getServiceUuids();
|
53
|
+
for (auto& service_uuid : service_uuids) {
|
54
|
+
if (std::find(advertised_services_.begin(), advertised_services_.end(), service_uuid) ==
|
55
|
+
advertised_services_.end()) {
|
56
|
+
advertised_services_.push_back(service_uuid);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
manufacturer_data_ = scan_record.getManufacturerData();
|
61
|
+
}
|
62
|
+
|
63
|
+
void* PeripheralAndroid::underlying() const { return nullptr; }
|
64
|
+
|
65
|
+
std::string PeripheralAndroid::identifier() { return _device.getName(); }
|
66
|
+
|
67
|
+
BluetoothAddress PeripheralAndroid::address() { return BluetoothAddress(_device.getAddress()); }
|
68
|
+
|
69
|
+
BluetoothAddressType PeripheralAndroid::address_type() {
|
70
|
+
// TODO: This is only available on API level 35 and above, so we're forced to return UNSPECIFIED
|
71
|
+
return BluetoothAddressType::UNSPECIFIED;
|
72
|
+
// switch (_device.getAddressType()) {
|
73
|
+
// case Android::BluetoothDevice::ADDRESS_TYPE_PUBLIC:
|
74
|
+
// return BluetoothAddressType::PUBLIC;
|
75
|
+
// case Android::BluetoothDevice::ADDRESS_TYPE_RANDOM:
|
76
|
+
// return BluetoothAddressType::RANDOM;
|
77
|
+
// default:
|
78
|
+
// return BluetoothAddressType::UNSPECIFIED;
|
79
|
+
// }
|
80
|
+
}
|
81
|
+
|
82
|
+
int16_t PeripheralAndroid::rssi() { return rssi_; }
|
83
|
+
|
84
|
+
int16_t PeripheralAndroid::tx_power() { return tx_power_; }
|
85
|
+
|
86
|
+
uint16_t PeripheralAndroid::mtu() { return _btGattCallback.mtu; }
|
87
|
+
|
88
|
+
void PeripheralAndroid::connect() {
|
89
|
+
_gatt = _device.connectGatt(false, _btGattCallback);
|
90
|
+
|
91
|
+
// Wait for the connection to be confirmed.
|
92
|
+
// The condition variable will return false if the connection was not established.
|
93
|
+
std::unique_lock<std::mutex> lock(_connection_mutex);
|
94
|
+
bool connected = _connection_cv.wait_for(lock, 8s, [this]() { return is_connected(); });
|
95
|
+
if (!connected) {
|
96
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to connect to device");
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
void PeripheralAndroid::disconnect() {
|
101
|
+
_gatt.disconnect();
|
102
|
+
|
103
|
+
// Wait for the disconnection to be confirmed.
|
104
|
+
std::unique_lock<std::mutex> lock(_disconnection_mutex);
|
105
|
+
bool disconnected = _disconnection_cv.wait_for(lock, 8s, [this]() { return !is_connected(); });
|
106
|
+
if (!disconnected) {
|
107
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to disconnect from device");
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
bool PeripheralAndroid::is_connected() { return _btGattCallback.connected && _btGattCallback.services_discovered; }
|
112
|
+
|
113
|
+
bool PeripheralAndroid::is_connectable() { return connectable_; }
|
114
|
+
|
115
|
+
bool PeripheralAndroid::is_paired() { return _device.getBondState() == Android::BluetoothDevice::BOND_BONDED; }
|
116
|
+
|
117
|
+
void PeripheralAndroid::unpair() {
|
118
|
+
// IMPORTANT: This is a non-public API call, which might be blacklisted by the Android OS in the future.
|
119
|
+
// NOTE: Doesn't seem to work, needs further investigation.
|
120
|
+
//_device.removeBond();
|
121
|
+
}
|
122
|
+
|
123
|
+
SharedPtrVector<ServiceBase> PeripheralAndroid::available_services() {
|
124
|
+
SharedPtrVector<ServiceBase> service_list;
|
125
|
+
for (auto service : _services) {
|
126
|
+
// Build the list of characteristics for the service.
|
127
|
+
SharedPtrVector<CharacteristicBase> characteristic_list;
|
128
|
+
for (auto characteristic : service.getCharacteristics()) {
|
129
|
+
// Build the list of descriptors for the characteristic.
|
130
|
+
SharedPtrVector<DescriptorBase> descriptor_list;
|
131
|
+
for (auto descriptor : characteristic.getDescriptors()) {
|
132
|
+
descriptor_list.push_back(std::make_shared<DescriptorBase>(descriptor.getUuid()));
|
133
|
+
}
|
134
|
+
|
135
|
+
int flags = characteristic.getProperties();
|
136
|
+
|
137
|
+
bool can_read = flags & Android::BluetoothGattCharacteristic::PROPERTY_READ;
|
138
|
+
bool can_write_request = flags & Android::BluetoothGattCharacteristic::PROPERTY_WRITE;
|
139
|
+
bool can_write_command = flags & Android::BluetoothGattCharacteristic::PROPERTY_WRITE_NO_RESPONSE;
|
140
|
+
bool can_notify = flags & Android::BluetoothGattCharacteristic::PROPERTY_NOTIFY;
|
141
|
+
bool can_indicate = flags & Android::BluetoothGattCharacteristic::PROPERTY_INDICATE;
|
142
|
+
|
143
|
+
characteristic_list.push_back(
|
144
|
+
std::make_shared<CharacteristicBase>(characteristic.getUuid(), descriptor_list, can_read,
|
145
|
+
can_write_request, can_write_command, can_notify, can_indicate));
|
146
|
+
}
|
147
|
+
|
148
|
+
service_list.push_back(std::make_shared<ServiceBase>(service.getUuid(), characteristic_list));
|
149
|
+
}
|
150
|
+
|
151
|
+
return service_list;
|
152
|
+
}
|
153
|
+
|
154
|
+
SharedPtrVector<ServiceBase> PeripheralAndroid::advertised_services() {
|
155
|
+
SharedPtrVector<ServiceBase> service_list;
|
156
|
+
for (auto& service_uuid : advertised_services_) {
|
157
|
+
service_list.push_back(std::make_shared<ServiceBase>(service_uuid));
|
158
|
+
}
|
159
|
+
return service_list;
|
160
|
+
}
|
161
|
+
|
162
|
+
std::map<uint16_t, ByteArray> PeripheralAndroid::manufacturer_data() { return manufacturer_data_; }
|
163
|
+
|
164
|
+
ByteArray PeripheralAndroid::read(BluetoothUUID const& service, BluetoothUUID const& characteristic) {
|
165
|
+
SIMPLEBLE_LOG_INFO("Reading characteristic " + characteristic);
|
166
|
+
|
167
|
+
auto characteristic_obj = _fetch_characteristic(service, characteristic);
|
168
|
+
|
169
|
+
_btGattCallback.set_flag_characteristicReadPending(characteristic_obj.getObject());
|
170
|
+
if (!_gatt.readCharacteristic(characteristic_obj)) {
|
171
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to read characteristic " + characteristic);
|
172
|
+
}
|
173
|
+
|
174
|
+
auto value = _btGattCallback.wait_flag_characteristicReadPending(characteristic_obj.getObject());
|
175
|
+
return ByteArray(value);
|
176
|
+
}
|
177
|
+
|
178
|
+
void PeripheralAndroid::write_request(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
179
|
+
ByteArray const& data) {
|
180
|
+
SIMPLEBLE_LOG_INFO("Writing request to characteristic " + characteristic);
|
181
|
+
|
182
|
+
auto characteristic_obj = _fetch_characteristic(service, characteristic);
|
183
|
+
|
184
|
+
characteristic_obj.setWriteType(Android::BluetoothGattCharacteristic::WRITE_TYPE_DEFAULT);
|
185
|
+
characteristic_obj.setValue(std::vector<uint8_t>(data.begin(), data.end()));
|
186
|
+
|
187
|
+
_btGattCallback.set_flag_characteristicWritePending(characteristic_obj.getObject());
|
188
|
+
if (!_gatt.writeCharacteristic(characteristic_obj)) {
|
189
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to write characteristic " + characteristic);
|
190
|
+
}
|
191
|
+
_btGattCallback.wait_flag_characteristicWritePending(characteristic_obj.getObject());
|
192
|
+
}
|
193
|
+
|
194
|
+
void PeripheralAndroid::write_command(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
195
|
+
ByteArray const& data) {
|
196
|
+
SIMPLEBLE_LOG_INFO("Writing command to characteristic " + characteristic);
|
197
|
+
|
198
|
+
auto characteristic_obj = _fetch_characteristic(service, characteristic);
|
199
|
+
|
200
|
+
characteristic_obj.setWriteType(Android::BluetoothGattCharacteristic::WRITE_TYPE_NO_RESPONSE);
|
201
|
+
characteristic_obj.setValue(std::vector<uint8_t>(data.begin(), data.end()));
|
202
|
+
|
203
|
+
_btGattCallback.set_flag_characteristicWritePending(characteristic_obj.getObject());
|
204
|
+
if (!_gatt.writeCharacteristic(characteristic_obj)) {
|
205
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to write characteristic " + characteristic);
|
206
|
+
}
|
207
|
+
_btGattCallback.wait_flag_characteristicWritePending(characteristic_obj.getObject());
|
208
|
+
}
|
209
|
+
|
210
|
+
void PeripheralAndroid::notify(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
211
|
+
std::function<void(ByteArray payload)> callback) {
|
212
|
+
SIMPLEBLE_LOG_INFO("Subscribing to characteristic " + characteristic);
|
213
|
+
|
214
|
+
auto characteristic_obj = _fetch_characteristic(service, characteristic);
|
215
|
+
auto descriptor_obj = _fetch_descriptor(service, characteristic,
|
216
|
+
Android::BluetoothGattDescriptor::CLIENT_CHARACTERISTIC_CONFIG);
|
217
|
+
|
218
|
+
_btGattCallback.set_callback_onCharacteristicChanged(characteristic_obj.getObject(),
|
219
|
+
[callback](std::vector<uint8_t> data) {
|
220
|
+
ByteArray payload(data);
|
221
|
+
callback(payload);
|
222
|
+
});
|
223
|
+
bool success = _gatt.setCharacteristicNotification(characteristic_obj, true);
|
224
|
+
if (!success) {
|
225
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to subscribe to characteristic " + characteristic);
|
226
|
+
}
|
227
|
+
|
228
|
+
_btGattCallback.set_flag_descriptorWritePending(descriptor_obj.getObject());
|
229
|
+
descriptor_obj.setValue(Android::BluetoothGattDescriptor::ENABLE_NOTIFICATION_VALUE);
|
230
|
+
if (!_gatt.writeDescriptor(descriptor_obj)) {
|
231
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to write descriptor for characteristic " + characteristic);
|
232
|
+
}
|
233
|
+
_btGattCallback.wait_flag_descriptorWritePending(descriptor_obj.getObject());
|
234
|
+
}
|
235
|
+
|
236
|
+
void PeripheralAndroid::indicate(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
237
|
+
std::function<void(ByteArray payload)> callback) {
|
238
|
+
SIMPLEBLE_LOG_INFO("Subscribing to characteristic " + characteristic);
|
239
|
+
|
240
|
+
auto characteristic_obj = _fetch_characteristic(service, characteristic);
|
241
|
+
auto descriptor_obj = _fetch_descriptor(service, characteristic,
|
242
|
+
Android::BluetoothGattDescriptor::CLIENT_CHARACTERISTIC_CONFIG);
|
243
|
+
|
244
|
+
_btGattCallback.set_callback_onCharacteristicChanged(characteristic_obj.getObject(),
|
245
|
+
[callback](std::vector<uint8_t> data) {
|
246
|
+
ByteArray payload(data);
|
247
|
+
callback(payload);
|
248
|
+
});
|
249
|
+
bool success = _gatt.setCharacteristicNotification(characteristic_obj, true);
|
250
|
+
if (!success) {
|
251
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to subscribe to characteristic " + characteristic);
|
252
|
+
}
|
253
|
+
|
254
|
+
_btGattCallback.set_flag_descriptorWritePending(descriptor_obj.getObject());
|
255
|
+
descriptor_obj.setValue(Android::BluetoothGattDescriptor::ENABLE_INDICATION_VALUE);
|
256
|
+
if (!_gatt.writeDescriptor(descriptor_obj)) {
|
257
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to write descriptor for characteristic " + characteristic);
|
258
|
+
}
|
259
|
+
_btGattCallback.wait_flag_descriptorWritePending(descriptor_obj.getObject());
|
260
|
+
}
|
261
|
+
|
262
|
+
void PeripheralAndroid::unsubscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic) {
|
263
|
+
SIMPLEBLE_LOG_INFO("Unsubscribing from characteristic " + characteristic);
|
264
|
+
|
265
|
+
auto characteristic_obj = _fetch_characteristic(service, characteristic);
|
266
|
+
auto descriptor_obj = _fetch_descriptor(service, characteristic,
|
267
|
+
Android::BluetoothGattDescriptor::CLIENT_CHARACTERISTIC_CONFIG);
|
268
|
+
|
269
|
+
_btGattCallback.set_flag_descriptorWritePending(descriptor_obj.getObject());
|
270
|
+
descriptor_obj.setValue(Android::BluetoothGattDescriptor::DISABLE_NOTIFICATION_VALUE);
|
271
|
+
if (!_gatt.writeDescriptor(descriptor_obj)) {
|
272
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to write descriptor for characteristic " + characteristic);
|
273
|
+
}
|
274
|
+
_btGattCallback.wait_flag_descriptorWritePending(descriptor_obj.getObject());
|
275
|
+
|
276
|
+
_btGattCallback.clear_callback_onCharacteristicChanged(characteristic_obj.getObject());
|
277
|
+
bool success = _gatt.setCharacteristicNotification(characteristic_obj, false);
|
278
|
+
if (!success) {
|
279
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to unsubscribe from characteristic " + characteristic);
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
ByteArray PeripheralAndroid::read(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
284
|
+
BluetoothUUID const& descriptor) {
|
285
|
+
SIMPLEBLE_LOG_INFO("Reading descriptor " + descriptor);
|
286
|
+
|
287
|
+
auto descriptor_obj = _fetch_descriptor(service, characteristic, descriptor);
|
288
|
+
|
289
|
+
_btGattCallback.set_flag_descriptorReadPending(descriptor_obj.getObject());
|
290
|
+
if (!_gatt.readDescriptor(descriptor_obj)) {
|
291
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to read descriptor " + descriptor);
|
292
|
+
}
|
293
|
+
|
294
|
+
auto value = _btGattCallback.wait_flag_descriptorReadPending(descriptor_obj.getObject());
|
295
|
+
return ByteArray(value);
|
296
|
+
}
|
297
|
+
|
298
|
+
void PeripheralAndroid::write(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
299
|
+
BluetoothUUID const& descriptor, ByteArray const& data) {
|
300
|
+
SIMPLEBLE_LOG_INFO("Writing descriptor " + descriptor);
|
301
|
+
|
302
|
+
auto descriptor_obj = _fetch_descriptor(service, characteristic, descriptor);
|
303
|
+
|
304
|
+
_btGattCallback.set_flag_descriptorWritePending(descriptor_obj.getObject());
|
305
|
+
descriptor_obj.setValue(std::vector<uint8_t>(data.begin(), data.end()));
|
306
|
+
if (!_gatt.writeDescriptor(descriptor_obj)) {
|
307
|
+
throw SimpleBLE::Exception::OperationFailed("Failed to write descriptor " + descriptor);
|
308
|
+
}
|
309
|
+
_btGattCallback.wait_flag_descriptorWritePending(descriptor_obj.getObject());
|
310
|
+
}
|
311
|
+
|
312
|
+
void PeripheralAndroid::set_callback_on_connected(std::function<void()> on_connected) {
|
313
|
+
if (on_connected) {
|
314
|
+
callback_on_connected_.load(std::move(on_connected));
|
315
|
+
} else {
|
316
|
+
callback_on_connected_.unload();
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
void PeripheralAndroid::set_callback_on_disconnected(std::function<void()> on_disconnected) {
|
321
|
+
if (on_disconnected) {
|
322
|
+
callback_on_disconnected_.load(std::move(on_disconnected));
|
323
|
+
} else {
|
324
|
+
callback_on_disconnected_.unload();
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
// NOTE: This approach to retrieve the characteristic and descriptor objects is not ideal, as it involves
|
329
|
+
// iterating on Java objects and returning a copy of the desired object. This will be improved in the future
|
330
|
+
// if performance becomes a bottleneck.
|
331
|
+
Android::BluetoothGattCharacteristic PeripheralAndroid::_fetch_characteristic(
|
332
|
+
const BluetoothUUID& service_uuid, const BluetoothUUID& characteristic_uuid) {
|
333
|
+
for (auto& service : _services) {
|
334
|
+
if (service.getUuid() == service_uuid) {
|
335
|
+
for (auto& characteristic : service.getCharacteristics()) {
|
336
|
+
if (characteristic.getUuid() == characteristic_uuid) {
|
337
|
+
return characteristic;
|
338
|
+
}
|
339
|
+
}
|
340
|
+
throw SimpleBLE::Exception::CharacteristicNotFound(characteristic_uuid);
|
341
|
+
}
|
342
|
+
}
|
343
|
+
throw SimpleBLE::Exception::ServiceNotFound(service_uuid);
|
344
|
+
}
|
345
|
+
|
346
|
+
Android::BluetoothGattDescriptor PeripheralAndroid::_fetch_descriptor(const BluetoothUUID& service_uuid,
|
347
|
+
const BluetoothUUID& characteristic_uuid,
|
348
|
+
const BluetoothUUID& descriptor_uuid) {
|
349
|
+
for (auto& service : _services) {
|
350
|
+
if (service.getUuid() == service_uuid) {
|
351
|
+
for (auto& characteristic : service.getCharacteristics()) {
|
352
|
+
if (characteristic.getUuid() == characteristic_uuid) {
|
353
|
+
for (auto& descriptor : characteristic.getDescriptors()) {
|
354
|
+
if (descriptor.getUuid() == descriptor_uuid) {
|
355
|
+
return descriptor;
|
356
|
+
}
|
357
|
+
}
|
358
|
+
throw SimpleBLE::Exception::DescriptorNotFound(descriptor_uuid);
|
359
|
+
}
|
360
|
+
}
|
361
|
+
throw SimpleBLE::Exception::CharacteristicNotFound(characteristic_uuid);
|
362
|
+
}
|
363
|
+
}
|
364
|
+
throw SimpleBLE::Exception::ServiceNotFound(service_uuid);
|
365
|
+
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <simpleble/Exceptions.h>
|
4
|
+
#include <simpleble/Service.h>
|
5
|
+
#include <simpleble/Types.h>
|
6
|
+
|
7
|
+
#include <kvn_safe_callback.hpp>
|
8
|
+
#include "../common/PeripheralBase.h"
|
9
|
+
|
10
|
+
#include <types/android/bluetooth/le/ScanResult.h>
|
11
|
+
#include <bridge/BluetoothGattCallback.h>
|
12
|
+
|
13
|
+
#include <condition_variable>
|
14
|
+
#include <map>
|
15
|
+
#include <mutex>
|
16
|
+
|
17
|
+
namespace SimpleBLE {
|
18
|
+
|
19
|
+
class PeripheralAndroid : public PeripheralBase {
|
20
|
+
public:
|
21
|
+
PeripheralAndroid(Android::BluetoothDevice device);
|
22
|
+
virtual ~PeripheralAndroid();
|
23
|
+
|
24
|
+
virtual void* underlying() const override;
|
25
|
+
|
26
|
+
virtual std::string identifier() override;
|
27
|
+
virtual BluetoothAddress address() override;
|
28
|
+
virtual BluetoothAddressType address_type() override;
|
29
|
+
virtual int16_t rssi() override;
|
30
|
+
virtual int16_t tx_power() override;
|
31
|
+
virtual uint16_t mtu() override;
|
32
|
+
|
33
|
+
virtual void connect() override;
|
34
|
+
virtual void disconnect() override;
|
35
|
+
virtual bool is_connected() override;
|
36
|
+
virtual bool is_connectable() override;
|
37
|
+
virtual bool is_paired() override;
|
38
|
+
virtual void unpair() override;
|
39
|
+
|
40
|
+
virtual std::vector<std::shared_ptr<ServiceBase>> available_services() override;
|
41
|
+
virtual std::vector<std::shared_ptr<ServiceBase>> advertised_services() override;
|
42
|
+
virtual std::map<uint16_t, ByteArray> manufacturer_data() override;
|
43
|
+
|
44
|
+
// clang-format off
|
45
|
+
virtual ByteArray read(BluetoothUUID const& service, BluetoothUUID const& characteristic) override;
|
46
|
+
virtual void write_request(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data) override;
|
47
|
+
virtual void write_command(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data) override;
|
48
|
+
virtual void notify(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback) override;
|
49
|
+
virtual void indicate(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback) override;
|
50
|
+
virtual void unsubscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic) override;
|
51
|
+
|
52
|
+
virtual ByteArray read(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor) override;
|
53
|
+
virtual void write(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor, ByteArray const& data) override;
|
54
|
+
// clang-format on
|
55
|
+
|
56
|
+
virtual void set_callback_on_connected(std::function<void()> on_connected) override;
|
57
|
+
virtual void set_callback_on_disconnected(std::function<void()> on_disconnected) override;
|
58
|
+
|
59
|
+
void update_advertising_data(Android::ScanResult scan_result);
|
60
|
+
|
61
|
+
private:
|
62
|
+
Android::Bridge::BluetoothGattCallback _btGattCallback;
|
63
|
+
Android::BluetoothDevice _device;
|
64
|
+
Android::BluetoothGatt _gatt;
|
65
|
+
std::vector<Android::BluetoothGattService> _services;
|
66
|
+
|
67
|
+
int16_t rssi_ = INT16_MIN;
|
68
|
+
int16_t tx_power_ = INT16_MIN;
|
69
|
+
uint16_t mtu_;
|
70
|
+
bool connectable_;
|
71
|
+
|
72
|
+
std::vector<std::string> advertised_services_;
|
73
|
+
std::map<uint16_t, kvn::bytearray> manufacturer_data_;
|
74
|
+
|
75
|
+
std::mutex _connection_mutex;
|
76
|
+
std::mutex _disconnection_mutex;
|
77
|
+
std::condition_variable _connection_cv;
|
78
|
+
std::condition_variable _disconnection_cv;
|
79
|
+
|
80
|
+
kvn::safe_callback<void()> callback_on_connected_;
|
81
|
+
kvn::safe_callback<void()> callback_on_disconnected_;
|
82
|
+
|
83
|
+
Android::BluetoothGattCharacteristic _fetch_characteristic(const BluetoothUUID& service_uuid,
|
84
|
+
const BluetoothUUID& characteristic_uuid);
|
85
|
+
Android::BluetoothGattDescriptor _fetch_descriptor(const BluetoothUUID& service_uuid,
|
86
|
+
const BluetoothUUID& characteristic_uuid,
|
87
|
+
const BluetoothUUID& descriptor_uuid);
|
88
|
+
};
|
89
|
+
|
90
|
+
} // namespace SimpleBLE
|