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,376 @@
|
|
1
|
+
#include "PeripheralLinux.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/Config.h>
|
10
|
+
#include <simpleble/Characteristic.h>
|
11
|
+
#include <simpleble/Descriptor.h>
|
12
|
+
#include <simpleble/Exceptions.h>
|
13
|
+
#include <simpleble/Service.h>
|
14
|
+
#include <simplebluez/Exceptions.h>
|
15
|
+
#include <algorithm>
|
16
|
+
#include <thread>
|
17
|
+
#include "CommonUtils.h"
|
18
|
+
#include "LoggingInternal.h"
|
19
|
+
|
20
|
+
const SimpleBLE::BluetoothUUID BATTERY_SERVICE_UUID = "0000180f-0000-1000-8000-00805f9b34fb";
|
21
|
+
const SimpleBLE::BluetoothUUID BATTERY_CHARACTERISTIC_UUID = "00002a19-0000-1000-8000-00805f9b34fb";
|
22
|
+
|
23
|
+
using namespace SimpleBLE;
|
24
|
+
using namespace std::chrono_literals;
|
25
|
+
|
26
|
+
PeripheralLinux::PeripheralLinux(std::shared_ptr<SimpleBluez::Device> device,
|
27
|
+
std::shared_ptr<SimpleBluez::Adapter> adapter)
|
28
|
+
: device_(std::move(device)), adapter_(std::move(adapter)) {}
|
29
|
+
|
30
|
+
PeripheralLinux::~PeripheralLinux() {
|
31
|
+
// Clear the callbacks to prevent any further events from being sent to the user.
|
32
|
+
this->callback_on_connected_.unload();
|
33
|
+
this->callback_on_disconnected_.unload();
|
34
|
+
|
35
|
+
device_->clear_on_disconnected();
|
36
|
+
device_->clear_on_services_resolved();
|
37
|
+
_cleanup_characteristics();
|
38
|
+
}
|
39
|
+
|
40
|
+
void* PeripheralLinux::underlying() const { return device_.get(); }
|
41
|
+
|
42
|
+
std::string PeripheralLinux::identifier() { return device_->name(); }
|
43
|
+
|
44
|
+
BluetoothAddress PeripheralLinux::address() { return device_->address(); }
|
45
|
+
|
46
|
+
BluetoothAddressType PeripheralLinux::address_type() {
|
47
|
+
std::string address_type = device_->address_type();
|
48
|
+
|
49
|
+
if (address_type == "public") {
|
50
|
+
return BluetoothAddressType::PUBLIC;
|
51
|
+
} else if (address_type == "public") {
|
52
|
+
return BluetoothAddressType::RANDOM;
|
53
|
+
} else {
|
54
|
+
return BluetoothAddressType::UNSPECIFIED;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
int16_t PeripheralLinux::rssi() { return device_->rssi(); }
|
59
|
+
|
60
|
+
int16_t PeripheralLinux::tx_power() { return device_->tx_power(); }
|
61
|
+
|
62
|
+
uint16_t PeripheralLinux::mtu() {
|
63
|
+
if (!is_connected()) return 0;
|
64
|
+
|
65
|
+
for (auto bluez_service : device_->services()) {
|
66
|
+
for (auto bluez_characteristic : bluez_service->characteristics()) {
|
67
|
+
// The value provided by Bluez includes an extra 3 bytes from the GATT header
|
68
|
+
// which needs to be removed.
|
69
|
+
return bluez_characteristic->mtu() - 3;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return 0;
|
73
|
+
}
|
74
|
+
|
75
|
+
void PeripheralLinux::connect() {
|
76
|
+
device_->clear_on_disconnected();
|
77
|
+
device_->set_on_services_resolved([this]() { this->connection_cv_.notify_all(); });
|
78
|
+
|
79
|
+
// Attempt to connect to the device.
|
80
|
+
for (size_t i = 0; i < 5; i++) {
|
81
|
+
if (_attempt_connect()) {
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
// Set the on_disconnected callback once the connection attempts are finished, thus
|
87
|
+
// preventing disconnection events that should not be seen by the user.
|
88
|
+
device_->set_on_disconnected([this]() {
|
89
|
+
this->_cleanup_characteristics();
|
90
|
+
this->disconnection_cv_.notify_all();
|
91
|
+
|
92
|
+
SAFE_CALLBACK_CALL(this->callback_on_disconnected_);
|
93
|
+
});
|
94
|
+
|
95
|
+
if (!is_connected()) {
|
96
|
+
throw Exception::OperationFailed();
|
97
|
+
}
|
98
|
+
|
99
|
+
SAFE_CALLBACK_CALL(this->callback_on_connected_);
|
100
|
+
}
|
101
|
+
|
102
|
+
void PeripheralLinux::disconnect() {
|
103
|
+
// Attempt to connect to the device.
|
104
|
+
for (size_t i = 0; i < 5; i++) {
|
105
|
+
if (_attempt_disconnect()) {
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
if (is_connected()) {
|
111
|
+
throw Exception::OperationFailed();
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
bool PeripheralLinux::is_connected() {
|
116
|
+
// NOTE: For Bluez, a device being connected means that it's both
|
117
|
+
// connected and services have been resolved.
|
118
|
+
return device_->connected() && device_->services_resolved();
|
119
|
+
}
|
120
|
+
|
121
|
+
bool PeripheralLinux::is_connectable() { return device_->name() != ""; }
|
122
|
+
|
123
|
+
bool PeripheralLinux::is_paired() { return device_->paired(); }
|
124
|
+
|
125
|
+
void PeripheralLinux::unpair() {
|
126
|
+
if (device_->paired()) {
|
127
|
+
adapter_->device_remove(device_->path());
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
SharedPtrVector<ServiceBase> PeripheralLinux::available_services() {
|
132
|
+
bool is_battery_service_available = false;
|
133
|
+
|
134
|
+
SharedPtrVector<ServiceBase> service_list;
|
135
|
+
for (auto bluez_service : device_->services()) {
|
136
|
+
// Check if the service is the battery service.
|
137
|
+
if (bluez_service->uuid() == BATTERY_SERVICE_UUID) {
|
138
|
+
is_battery_service_available = true;
|
139
|
+
}
|
140
|
+
|
141
|
+
// Build the list of characteristics for the service.
|
142
|
+
SharedPtrVector<CharacteristicBase> characteristic_list;
|
143
|
+
for (auto bluez_characteristic : bluez_service->characteristics()) {
|
144
|
+
// Build the list of descriptors for the characteristic.
|
145
|
+
SharedPtrVector<DescriptorBase> descriptor_list;
|
146
|
+
for (auto bluez_descriptor : bluez_characteristic->descriptors()) {
|
147
|
+
descriptor_list.push_back(std::make_shared<DescriptorBase>(bluez_descriptor->uuid()));
|
148
|
+
}
|
149
|
+
|
150
|
+
std::vector<std::string> flags = bluez_characteristic->flags();
|
151
|
+
|
152
|
+
bool can_read = std::find(flags.begin(), flags.end(), "read") != flags.end();
|
153
|
+
bool can_write_request = std::find(flags.begin(), flags.end(), "write") != flags.end();
|
154
|
+
bool can_write_command = std::find(flags.begin(), flags.end(), "write-without-response") != flags.end();
|
155
|
+
bool can_notify = std::find(flags.begin(), flags.end(), "notify") != flags.end();
|
156
|
+
bool can_indicate = std::find(flags.begin(), flags.end(), "indicate") != flags.end();
|
157
|
+
|
158
|
+
characteristic_list.push_back(
|
159
|
+
std::make_shared<CharacteristicBase>(bluez_characteristic->uuid(), descriptor_list, can_read,
|
160
|
+
can_write_request, can_write_command, can_notify, can_indicate));
|
161
|
+
}
|
162
|
+
|
163
|
+
service_list.push_back(std::make_shared<ServiceBase>(bluez_service->uuid(), characteristic_list));
|
164
|
+
}
|
165
|
+
|
166
|
+
// If the battery service is not available, and the device has the appropriate interface, add it.
|
167
|
+
if (!is_battery_service_available && device_->has_battery_interface()) {
|
168
|
+
// Emulate the battery service through the Battery1 interface.
|
169
|
+
SharedPtrVector<DescriptorBase> descriptor_list;
|
170
|
+
SharedPtrVector<CharacteristicBase> characteristic_list = {std::make_shared<CharacteristicBase>(
|
171
|
+
BATTERY_CHARACTERISTIC_UUID, descriptor_list, true, false, false, true, false)};
|
172
|
+
service_list.push_back(std::make_shared<ServiceBase>(BATTERY_SERVICE_UUID, characteristic_list));
|
173
|
+
}
|
174
|
+
|
175
|
+
return service_list;
|
176
|
+
}
|
177
|
+
|
178
|
+
SharedPtrVector<ServiceBase> PeripheralLinux::advertised_services() {
|
179
|
+
SharedPtrVector<ServiceBase> service_list;
|
180
|
+
for (auto& service_uuid : device_->uuids()) {
|
181
|
+
service_list.push_back(std::make_shared<ServiceBase>(service_uuid));
|
182
|
+
}
|
183
|
+
|
184
|
+
return service_list;
|
185
|
+
}
|
186
|
+
|
187
|
+
std::map<uint16_t, ByteArray> PeripheralLinux::manufacturer_data() { return device_->manufacturer_data(); }
|
188
|
+
|
189
|
+
ByteArray PeripheralLinux::read(BluetoothUUID const& service, BluetoothUUID const& characteristic) {
|
190
|
+
// Check if the user is attempting to read the battery service/characteristic and if so,
|
191
|
+
// emulate the battery service through the Battery1 interface if it's not available.
|
192
|
+
if (service == BATTERY_SERVICE_UUID && characteristic == BATTERY_CHARACTERISTIC_UUID &&
|
193
|
+
device_->has_battery_interface()) {
|
194
|
+
// If this point is reached, the battery service needs to be emulated.
|
195
|
+
uint8_t battery_percentage = device_->battery_percentage();
|
196
|
+
return ByteArray(reinterpret_cast<char*>(&battery_percentage), 1);
|
197
|
+
}
|
198
|
+
|
199
|
+
// Otherwise, attempt to read the characteristic using default mechanisms
|
200
|
+
return _get_characteristic(service, characteristic)->read();
|
201
|
+
}
|
202
|
+
|
203
|
+
void PeripheralLinux::write_request(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
204
|
+
ByteArray const& data) {
|
205
|
+
// TODO: Check if the characteristic is writable.
|
206
|
+
// TODO: SimpleBluez::Characteristic::write_request() should also take ByteArray by const reference (but that's
|
207
|
+
// another library)
|
208
|
+
_get_characteristic(service, characteristic)->write_request(data);
|
209
|
+
}
|
210
|
+
|
211
|
+
void PeripheralLinux::write_command(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
212
|
+
ByteArray const& data) {
|
213
|
+
// TODO: Check if the characteristic is writable.
|
214
|
+
// TODO: SimpleBluez::Characteristic::write_command() should also take ByteArray by const reference (but that's
|
215
|
+
// another library)
|
216
|
+
_get_characteristic(service, characteristic)->write_command(data);
|
217
|
+
}
|
218
|
+
|
219
|
+
void PeripheralLinux::notify(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
220
|
+
std::function<void(ByteArray payload)> callback) {
|
221
|
+
// Check if the user is attempting to notify the battery service/characteristic and if so,
|
222
|
+
// emulate the battery service through the Battery1 interface if it's not available.
|
223
|
+
if (service == BATTERY_SERVICE_UUID && characteristic == BATTERY_CHARACTERISTIC_UUID &&
|
224
|
+
device_->has_battery_interface()) {
|
225
|
+
// If this point is reached, the battery service needs to be emulated.
|
226
|
+
device_->set_on_battery_percentage_changed(
|
227
|
+
[callback](uint8_t new_value) { callback(ByteArray(reinterpret_cast<char*>(&new_value), 1)); });
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
|
231
|
+
// Otherwise, attempt to read the characteristic using default mechanisms
|
232
|
+
// TODO: What to do if the characteristic is already being notified?
|
233
|
+
// TODO: Check if the property can be notified.
|
234
|
+
auto characteristic_object = _get_characteristic(service, characteristic);
|
235
|
+
characteristic_object->set_on_value_changed([callback](SimpleBluez::ByteArray new_value) { callback(new_value); });
|
236
|
+
characteristic_object->start_notify();
|
237
|
+
}
|
238
|
+
|
239
|
+
void PeripheralLinux::indicate(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
240
|
+
std::function<void(ByteArray payload)> callback) {
|
241
|
+
notify(service, characteristic, callback);
|
242
|
+
}
|
243
|
+
|
244
|
+
void PeripheralLinux::unsubscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic) {
|
245
|
+
// Check if the user is attempting to read the battery service/characteristic and if so,
|
246
|
+
// emulate the battery service through the Battery1 interface if it's not available.
|
247
|
+
if (service == BATTERY_SERVICE_UUID && characteristic == BATTERY_CHARACTERISTIC_UUID &&
|
248
|
+
device_->has_battery_interface()) {
|
249
|
+
// If this point is reached, the battery service needs to be emulated.
|
250
|
+
device_->clear_on_battery_percentage_changed();
|
251
|
+
return;
|
252
|
+
}
|
253
|
+
|
254
|
+
// TODO: What to do if the characteristic is not being notified?
|
255
|
+
auto characteristic_object = _get_characteristic(service, characteristic);
|
256
|
+
characteristic_object->stop_notify();
|
257
|
+
|
258
|
+
// Wait for the characteristic to stop notifying.
|
259
|
+
// TODO: Upgrade SimpleDBus to provide a way to wait for this signal.
|
260
|
+
auto timeout = std::chrono::steady_clock::now() + 5s;
|
261
|
+
while (characteristic_object->notifying() && std::chrono::steady_clock::now() < timeout) {
|
262
|
+
std::this_thread::sleep_for(50ms);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
ByteArray PeripheralLinux::read(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
267
|
+
BluetoothUUID const& descriptor) {
|
268
|
+
return _get_descriptor(service, characteristic, descriptor)->read();
|
269
|
+
}
|
270
|
+
|
271
|
+
void PeripheralLinux::write(BluetoothUUID const& service, BluetoothUUID const& characteristic,
|
272
|
+
BluetoothUUID const& descriptor, ByteArray const& data) {
|
273
|
+
_get_descriptor(service, characteristic, descriptor)->write(data);
|
274
|
+
}
|
275
|
+
|
276
|
+
void PeripheralLinux::set_callback_on_connected(std::function<void()> on_connected) {
|
277
|
+
if (on_connected) {
|
278
|
+
callback_on_connected_.load(std::move(on_connected));
|
279
|
+
} else {
|
280
|
+
callback_on_connected_.unload();
|
281
|
+
}
|
282
|
+
}
|
283
|
+
|
284
|
+
void PeripheralLinux::set_callback_on_disconnected(std::function<void()> on_disconnected) {
|
285
|
+
if (on_disconnected) {
|
286
|
+
callback_on_disconnected_.load(std::move(on_disconnected));
|
287
|
+
} else {
|
288
|
+
callback_on_disconnected_.unload();
|
289
|
+
}
|
290
|
+
}
|
291
|
+
|
292
|
+
// Private methods
|
293
|
+
|
294
|
+
void PeripheralLinux::_cleanup_characteristics() noexcept {
|
295
|
+
// As this method can be called in multiple stages of a disconnection or object
|
296
|
+
// destruction, the entire execution of this method is wrapped in a try-catch
|
297
|
+
// block to prevent any exceptions from being thrown, as these will most certainly
|
298
|
+
// crash the user application.
|
299
|
+
try {
|
300
|
+
// Clear all callbacks first to ensure that a failure during `stop_notify`
|
301
|
+
// does not leave any dangling callbacks.
|
302
|
+
if (device_->has_battery_interface()) {
|
303
|
+
device_->clear_on_battery_percentage_changed();
|
304
|
+
}
|
305
|
+
|
306
|
+
for (auto bluez_service : device_->services()) {
|
307
|
+
for (auto bluez_characteristic : bluez_service->characteristics()) {
|
308
|
+
bluez_characteristic->clear_on_value_changed();
|
309
|
+
}
|
310
|
+
}
|
311
|
+
|
312
|
+
// Stop notifying all characteristics.
|
313
|
+
for (auto bluez_service : device_->services()) {
|
314
|
+
for (auto bluez_characteristic : bluez_service->characteristics()) {
|
315
|
+
try {
|
316
|
+
if (bluez_characteristic->notifying()) {
|
317
|
+
bluez_characteristic->stop_notify();
|
318
|
+
}
|
319
|
+
} catch (std::exception const& e) {
|
320
|
+
SIMPLEBLE_LOG_WARN(fmt::format("Exception during characteristic cleanup: {}", e.what()));
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
} catch (std::exception const& e) {
|
325
|
+
SIMPLEBLE_LOG_WARN(fmt::format("Exception during characteristic cleanup: {}", e.what()));
|
326
|
+
} catch (...) {
|
327
|
+
// It's possible during the cleanup process that the Bluez device has already
|
328
|
+
// been removed, which could cause calls to cleanup methods to throw.
|
329
|
+
SIMPLEBLE_LOG_WARN("Unknown exception during characteristic cleanup");
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
bool PeripheralLinux::_attempt_connect() {
|
334
|
+
try {
|
335
|
+
device_->connect();
|
336
|
+
} catch (SimpleDBus::Exception::SendFailed const& e) {
|
337
|
+
return false;
|
338
|
+
}
|
339
|
+
|
340
|
+
// Wait for the connection to be confirmed.
|
341
|
+
// The condition variable will return false if the connection was not established.
|
342
|
+
std::unique_lock<std::mutex> lock(connection_mutex_);
|
343
|
+
return connection_cv_.wait_for(lock, Config::SimpleBluez::connection_timeout, [this]() { return is_connected(); });
|
344
|
+
}
|
345
|
+
|
346
|
+
bool PeripheralLinux::_attempt_disconnect() {
|
347
|
+
_cleanup_characteristics();
|
348
|
+
|
349
|
+
device_->disconnect();
|
350
|
+
|
351
|
+
// Wait for the disconnection to be confirmed.
|
352
|
+
// The condition variable will return false if the connection is still active.
|
353
|
+
std::unique_lock<std::mutex> lock(disconnection_mutex_);
|
354
|
+
return disconnection_cv_.wait_for(lock, Config::SimpleBluez::disconnection_timeout, [this]() { return !is_connected(); });
|
355
|
+
}
|
356
|
+
|
357
|
+
std::shared_ptr<SimpleBluez::Characteristic> PeripheralLinux::_get_characteristic(
|
358
|
+
BluetoothUUID const& service_uuid, BluetoothUUID const& characteristic_uuid) {
|
359
|
+
try {
|
360
|
+
return device_->get_characteristic(service_uuid, characteristic_uuid);
|
361
|
+
} catch (SimpleBluez::Exception::ServiceNotFoundException& e) {
|
362
|
+
throw Exception::ServiceNotFound(service_uuid);
|
363
|
+
} catch (SimpleBluez::Exception::CharacteristicNotFoundException& e) {
|
364
|
+
throw Exception::CharacteristicNotFound(characteristic_uuid);
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
std::shared_ptr<SimpleBluez::Descriptor> PeripheralLinux::_get_descriptor(BluetoothUUID const& service_uuid,
|
369
|
+
BluetoothUUID const& characteristic_uuid,
|
370
|
+
BluetoothUUID const& descriptor_uuid) {
|
371
|
+
try {
|
372
|
+
return device_->get_characteristic(service_uuid, characteristic_uuid)->get_descriptor(descriptor_uuid);
|
373
|
+
} catch (SimpleBluez::Exception::DescriptorNotFoundException& e) {
|
374
|
+
throw Exception::DescriptorNotFound(descriptor_uuid);
|
375
|
+
}
|
376
|
+
}
|
@@ -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 <simplebluez/Adapter.h>
|
8
|
+
#include <simplebluez/Characteristic.h>
|
9
|
+
#include <simplebluez/Device.h>
|
10
|
+
|
11
|
+
#include "../common/PeripheralBase.h"
|
12
|
+
|
13
|
+
#include <kvn_safe_callback.hpp>
|
14
|
+
|
15
|
+
#include <atomic>
|
16
|
+
#include <condition_variable>
|
17
|
+
#include <memory>
|
18
|
+
|
19
|
+
namespace SimpleBLE {
|
20
|
+
|
21
|
+
class PeripheralLinux : public SimpleBLE::PeripheralBase {
|
22
|
+
public:
|
23
|
+
PeripheralLinux(std::shared_ptr<SimpleBluez::Device> device, std::shared_ptr<SimpleBluez::Adapter> adapter);
|
24
|
+
virtual ~PeripheralLinux();
|
25
|
+
|
26
|
+
virtual void* underlying() const override;
|
27
|
+
|
28
|
+
virtual std::string identifier() override;
|
29
|
+
virtual BluetoothAddress address() override;
|
30
|
+
virtual BluetoothAddressType address_type() override;
|
31
|
+
virtual int16_t rssi() override;
|
32
|
+
|
33
|
+
virtual int16_t tx_power() override;
|
34
|
+
virtual uint16_t mtu() override;
|
35
|
+
|
36
|
+
virtual void connect() override;
|
37
|
+
virtual void disconnect() override;
|
38
|
+
virtual bool is_connected() override;
|
39
|
+
virtual bool is_connectable() override;
|
40
|
+
virtual bool is_paired() override;
|
41
|
+
virtual void unpair() override;
|
42
|
+
|
43
|
+
virtual std::vector<std::shared_ptr<ServiceBase>> available_services() override;
|
44
|
+
virtual std::vector<std::shared_ptr<ServiceBase>> advertised_services() override;
|
45
|
+
|
46
|
+
virtual std::map<uint16_t, ByteArray> manufacturer_data() override;
|
47
|
+
|
48
|
+
// clang-format off
|
49
|
+
virtual ByteArray read(BluetoothUUID const& service, BluetoothUUID const& characteristic) override;
|
50
|
+
virtual void write_request(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data) override;
|
51
|
+
virtual void write_command(BluetoothUUID const& service, BluetoothUUID const& characteristic, ByteArray const& data) override;
|
52
|
+
virtual void notify(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback) override;
|
53
|
+
virtual void indicate(BluetoothUUID const& service, BluetoothUUID const& characteristic, std::function<void(ByteArray payload)> callback) override;
|
54
|
+
virtual void unsubscribe(BluetoothUUID const& service, BluetoothUUID const& characteristic) override;
|
55
|
+
|
56
|
+
virtual ByteArray read(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor) override;
|
57
|
+
virtual void write(BluetoothUUID const& service, BluetoothUUID const& characteristic, BluetoothUUID const& descriptor, ByteArray const& data) override;
|
58
|
+
// clang-format on
|
59
|
+
|
60
|
+
virtual void set_callback_on_connected(std::function<void()> on_connected) override;
|
61
|
+
virtual void set_callback_on_disconnected(std::function<void()> on_disconnected) override;
|
62
|
+
|
63
|
+
private:
|
64
|
+
std::atomic_bool battery_emulation_required_{false};
|
65
|
+
|
66
|
+
std::shared_ptr<SimpleBluez::Adapter> adapter_;
|
67
|
+
std::shared_ptr<SimpleBluez::Device> device_;
|
68
|
+
|
69
|
+
std::condition_variable connection_cv_;
|
70
|
+
std::mutex connection_mutex_;
|
71
|
+
|
72
|
+
std::condition_variable disconnection_cv_;
|
73
|
+
std::mutex disconnection_mutex_;
|
74
|
+
|
75
|
+
kvn::safe_callback<void()> callback_on_connected_;
|
76
|
+
kvn::safe_callback<void()> callback_on_disconnected_;
|
77
|
+
|
78
|
+
bool _attempt_connect();
|
79
|
+
bool _attempt_disconnect();
|
80
|
+
void _cleanup_characteristics() noexcept;
|
81
|
+
|
82
|
+
std::shared_ptr<SimpleBluez::Characteristic> _get_characteristic(BluetoothUUID const& service_uuid,
|
83
|
+
BluetoothUUID const& characteristic_uuid);
|
84
|
+
|
85
|
+
std::shared_ptr<SimpleBluez::Descriptor> _get_descriptor(BluetoothUUID const& service_uuid,
|
86
|
+
BluetoothUUID const& characteristic_uuid,
|
87
|
+
BluetoothUUID const& descriptor_uuid);
|
88
|
+
};
|
89
|
+
|
90
|
+
} // namespace SimpleBLE
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#import <CoreBluetooth/CoreBluetooth.h>
|
4
|
+
#import <Foundation/Foundation.h>
|
5
|
+
|
6
|
+
#include <functional>
|
7
|
+
#import "AdapterMac.h"
|
8
|
+
|
9
|
+
@interface AdapterBaseMacOS : NSObject<CBCentralManagerDelegate>
|
10
|
+
|
11
|
+
@property NSString* uuid;
|
12
|
+
|
13
|
+
- (bool)isBluetoothEnabled;
|
14
|
+
|
15
|
+
- (instancetype)init:(SimpleBLE::AdapterMac*)adapter;
|
16
|
+
|
17
|
+
- (void*)underlying;
|
18
|
+
|
19
|
+
- (void)powerOn;
|
20
|
+
- (void)powerOff;
|
21
|
+
- (bool)isPowered;
|
22
|
+
|
23
|
+
- (void)scanStart;
|
24
|
+
- (void)scanStop;
|
25
|
+
- (bool)scanIsActive;
|
26
|
+
|
27
|
+
- (NSString*)address;
|
28
|
+
|
29
|
+
@end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <simpleble/Exceptions.h>
|
4
|
+
#include <simpleble/Types.h>
|
5
|
+
|
6
|
+
#include "AdapterBase.h"
|
7
|
+
#include "AdapterBaseTypes.h"
|
8
|
+
|
9
|
+
#include <kvn_safe_callback.hpp>
|
10
|
+
|
11
|
+
#include <functional>
|
12
|
+
#include <map>
|
13
|
+
#include <memory>
|
14
|
+
#include <string>
|
15
|
+
#include <vector>
|
16
|
+
|
17
|
+
namespace SimpleBLE {
|
18
|
+
|
19
|
+
class Peripheral;
|
20
|
+
class PeripheralBase;
|
21
|
+
class PeripheralMac;
|
22
|
+
|
23
|
+
/**
|
24
|
+
This class definition acts as an abstraction layer between C++ and Objective-C.
|
25
|
+
If Objective-C headers are included here, everything blows up.
|
26
|
+
*/
|
27
|
+
class AdapterMac : public AdapterBase {
|
28
|
+
public:
|
29
|
+
AdapterMac();
|
30
|
+
virtual ~AdapterMac();
|
31
|
+
|
32
|
+
virtual void* underlying() const override;
|
33
|
+
|
34
|
+
virtual std::string identifier() override;
|
35
|
+
virtual BluetoothAddress address() override;
|
36
|
+
|
37
|
+
virtual void power_on() override;
|
38
|
+
virtual void power_off() override;
|
39
|
+
virtual bool is_powered() override;
|
40
|
+
|
41
|
+
virtual void scan_start() override;
|
42
|
+
virtual void scan_stop() override;
|
43
|
+
virtual void scan_for(int timeout_ms) override;
|
44
|
+
virtual bool scan_is_active() override;
|
45
|
+
virtual std::vector<std::shared_ptr<PeripheralBase>> scan_get_results() override;
|
46
|
+
|
47
|
+
virtual std::vector<std::shared_ptr<PeripheralBase>> get_paired_peripherals() override;
|
48
|
+
|
49
|
+
virtual bool bluetooth_enabled() override;
|
50
|
+
|
51
|
+
void delegate_did_discover_peripheral(void* opaque_peripheral, void* opaque_adapter,
|
52
|
+
advertising_data_t advertising_data);
|
53
|
+
void delegate_did_connect_peripheral(void* opaque_peripheral);
|
54
|
+
void delegate_did_fail_to_connect_peripheral(void* opaque_peripheral, void* opaque_error);
|
55
|
+
void delegate_did_disconnect_peripheral(void* opaque_peripheral, void* opaque_error);
|
56
|
+
|
57
|
+
protected:
|
58
|
+
/**
|
59
|
+
* Holds a pointer to the Objective-C representation of this object.
|
60
|
+
*/
|
61
|
+
void* opaque_internal_;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Holds a map of objective-c peripheral objects to their corresponding C++ objects.
|
65
|
+
*
|
66
|
+
* Whenever some sort of event happens on a peripheral, we need to find
|
67
|
+
* the corresponding PeripheralBase object. The PeripheralBase objects
|
68
|
+
* can be wrapped in disposable Peripheral objects, so there is no need
|
69
|
+
* be careful with them.
|
70
|
+
*/
|
71
|
+
std::map<void*, std::shared_ptr<PeripheralMac>> peripherals_;
|
72
|
+
std::map<void*, std::shared_ptr<PeripheralMac>> seen_peripherals_;
|
73
|
+
|
74
|
+
private:
|
75
|
+
BluetoothAddress address() const;
|
76
|
+
};
|
77
|
+
|
78
|
+
} // namespace SimpleBLE
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#import <CoreBluetooth/CoreBluetooth.h>
|
4
|
+
#import <Foundation/Foundation.h>
|
5
|
+
|
6
|
+
#include <cstdint>
|
7
|
+
#include <functional>
|
8
|
+
#include <vector>
|
9
|
+
#import "PeripheralMac.h"
|
10
|
+
|
11
|
+
@interface PeripheralBaseMacOS : NSObject<CBPeripheralDelegate>
|
12
|
+
|
13
|
+
- (instancetype)init:(CBPeripheral*)peripheral centralManager:(CBCentralManager*)centralManager;
|
14
|
+
|
15
|
+
- (void*)underlying;
|
16
|
+
|
17
|
+
- (NSString*)identifier;
|
18
|
+
- (NSString*)address;
|
19
|
+
- (uint16_t)mtu;
|
20
|
+
|
21
|
+
- (void)connect;
|
22
|
+
- (void)disconnect;
|
23
|
+
- (bool)isConnected;
|
24
|
+
- (std::vector<std::shared_ptr<SimpleBLE::ServiceBase>>)getServices;
|
25
|
+
|
26
|
+
- (SimpleBLE::ByteArray)read:(NSString*)service_uuid characteristic_uuid:(NSString*)characteristic_uuid;
|
27
|
+
- (void)writeRequest:(NSString*)service_uuid characteristic_uuid:(NSString*)characteristic_uuid payload:(NSData*)payload;
|
28
|
+
- (void)writeCommand:(NSString*)service_uuid characteristic_uuid:(NSString*)characteristic_uuid payload:(NSData*)payload;
|
29
|
+
- (void)notify:(NSString*)service_uuid
|
30
|
+
characteristic_uuid:(NSString*)characteristic_uuid
|
31
|
+
callback:(std::function<void(SimpleBLE::ByteArray)>)callback;
|
32
|
+
- (void)indicate:(NSString*)service_uuid
|
33
|
+
characteristic_uuid:(NSString*)characteristic_uuid
|
34
|
+
callback:(std::function<void(SimpleBLE::ByteArray)>)callback;
|
35
|
+
- (void)unsubscribe:(NSString*)service_uuid characteristic_uuid:(NSString*)characteristic_uuid;
|
36
|
+
|
37
|
+
- (SimpleBLE::ByteArray)read:(NSString*)service_uuid
|
38
|
+
characteristic_uuid:(NSString*)characteristic_uuid
|
39
|
+
descriptor_uuid:(NSString*)descriptor_uuid;
|
40
|
+
- (void)write:(NSString*)service_uuid
|
41
|
+
characteristic_uuid:(NSString*)characteristic_uuid
|
42
|
+
descriptor_uuid:(NSString*)descriptor_uuid
|
43
|
+
payload:(NSData*)payload;
|
44
|
+
|
45
|
+
- (void)delegateDidConnect;
|
46
|
+
- (void)delegateDidFailToConnect:(NSError*)error;
|
47
|
+
- (void)delegateDidDisconnect:(NSError*)error;
|
48
|
+
|
49
|
+
@end
|