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.
Files changed (341) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +88 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +350 -0
  5. data/ext/simpleble/extconf.rb +57 -0
  6. data/ext/simpleble/simpleble_ruby.c +682 -0
  7. data/lib/simpleble/adapter.rb +10 -0
  8. data/lib/simpleble/characteristic.rb +36 -0
  9. data/lib/simpleble/descriptor.rb +8 -0
  10. data/lib/simpleble/exceptions.rb +25 -0
  11. data/lib/simpleble/peripheral.rb +64 -0
  12. data/lib/simpleble/service.rb +16 -0
  13. data/lib/simpleble/version.rb +3 -0
  14. data/lib/simpleble.rb +40 -0
  15. data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/CMakeCXXCompilerId.cpp +920 -0
  16. data/vendor/simpleble/build_simplecble/CMakeFiles/4.0.3/CompilerIdCXX/apple-sdk.cpp +1 -0
  17. data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/CMakeCXXCompilerId.cpp +949 -0
  18. data/vendor/simpleble/build_simplecble/CMakeFiles/4.1.0/CompilerIdCXX/apple-sdk.cpp +1 -0
  19. data/vendor/simpleble/build_simplecble/export/simplecble/export.h +43 -0
  20. data/vendor/simpleble/build_simplecble/simpleble/export/simpleble/export.h +43 -0
  21. data/vendor/simpleble/dependencies/external/kvn/kvn_bytearray.h +222 -0
  22. data/vendor/simpleble/dependencies/external/kvn/kvn_safe_callback.hpp +66 -0
  23. data/vendor/simpleble/dependencies/external/kvn/logfwd.hpp +35 -0
  24. data/vendor/simpleble/dependencies/internal/fmt/args.h +220 -0
  25. data/vendor/simpleble/dependencies/internal/fmt/base.h +2962 -0
  26. data/vendor/simpleble/dependencies/internal/fmt/chrono.h +2338 -0
  27. data/vendor/simpleble/dependencies/internal/fmt/color.h +610 -0
  28. data/vendor/simpleble/dependencies/internal/fmt/compile.h +539 -0
  29. data/vendor/simpleble/dependencies/internal/fmt/core.h +5 -0
  30. data/vendor/simpleble/dependencies/internal/fmt/format-inl.h +1949 -0
  31. data/vendor/simpleble/dependencies/internal/fmt/format.h +4244 -0
  32. data/vendor/simpleble/dependencies/internal/fmt/os.h +427 -0
  33. data/vendor/simpleble/dependencies/internal/fmt/ostream.h +166 -0
  34. data/vendor/simpleble/dependencies/internal/fmt/printf.h +633 -0
  35. data/vendor/simpleble/dependencies/internal/fmt/ranges.h +850 -0
  36. data/vendor/simpleble/dependencies/internal/fmt/std.h +726 -0
  37. data/vendor/simpleble/dependencies/internal/fmt/xchar.h +373 -0
  38. data/vendor/simpleble/dependencies/internal/simplejni/Common.hpp +579 -0
  39. data/vendor/simpleble/dependencies/internal/simplejni/References.hpp +151 -0
  40. data/vendor/simpleble/dependencies/internal/simplejni/Registry.hpp +183 -0
  41. data/vendor/simpleble/dependencies/internal/simplejni/VM.hpp +88 -0
  42. data/vendor/simpleble/examples/simpleble/src/connect.cpp +67 -0
  43. data/vendor/simpleble/examples/simpleble/src/connect_safe.cpp +91 -0
  44. data/vendor/simpleble/examples/simpleble/src/list_adapters.cpp +22 -0
  45. data/vendor/simpleble/examples/simpleble/src/list_adapters_safe.cpp +33 -0
  46. data/vendor/simpleble/examples/simpleble/src/list_paired.cpp +27 -0
  47. data/vendor/simpleble/examples/simpleble/src/multiconnect.cpp +60 -0
  48. data/vendor/simpleble/examples/simpleble/src/notify.cpp +85 -0
  49. data/vendor/simpleble/examples/simpleble/src/notify_multi.cpp +101 -0
  50. data/vendor/simpleble/examples/simpleble/src/power_cycle.cpp +43 -0
  51. data/vendor/simpleble/examples/simpleble/src/read.cpp +82 -0
  52. data/vendor/simpleble/examples/simpleble/src/scan.cpp +62 -0
  53. data/vendor/simpleble/examples/simpleble/src/utils.cpp +59 -0
  54. data/vendor/simpleble/examples/simpleble/src/utils.hpp +27 -0
  55. data/vendor/simpleble/examples/simpleble/src/write.cpp +81 -0
  56. data/vendor/simpleble/examples/simplebluez/ble_nus/ble_nus.cpp +138 -0
  57. data/vendor/simpleble/examples/simplebluez/connect/connect.cpp +119 -0
  58. data/vendor/simpleble/examples/simplebluez/list_adapters/list_adapters.cpp +44 -0
  59. data/vendor/simpleble/examples/simplebluez/list_paired/list_paired.cpp +48 -0
  60. data/vendor/simpleble/examples/simplebluez/notify/notify.cpp +145 -0
  61. data/vendor/simpleble/examples/simplebluez/pair/pair.cpp +181 -0
  62. data/vendor/simpleble/examples/simplebluez/read/read.cpp +141 -0
  63. data/vendor/simpleble/examples/simplebluez/scan/scan.cpp +85 -0
  64. data/vendor/simpleble/examples/simplecble/c/connect.c +163 -0
  65. data/vendor/simpleble/examples/simplecble/c/notify.c +217 -0
  66. data/vendor/simpleble/examples/simplecble/c/scan.c +164 -0
  67. data/vendor/simpleble/examples/simpledbus/notification.cpp +24 -0
  68. data/vendor/simpleble/hitl/src/test_sanity.cpp +48 -0
  69. data/vendor/simpleble/install_simplecble/include/simpleble/Adapter.h +102 -0
  70. data/vendor/simpleble/install_simplecble/include/simpleble/AdapterSafe.h +58 -0
  71. data/vendor/simpleble/install_simplecble/include/simpleble/Advanced.h +50 -0
  72. data/vendor/simpleble/install_simplecble/include/simpleble/Characteristic.h +39 -0
  73. data/vendor/simpleble/install_simplecble/include/simpleble/Config.h +55 -0
  74. data/vendor/simpleble/install_simplecble/include/simpleble/Descriptor.h +30 -0
  75. data/vendor/simpleble/install_simplecble/include/simpleble/Exceptions.h +72 -0
  76. data/vendor/simpleble/install_simplecble/include/simpleble/Logging.h +73 -0
  77. data/vendor/simpleble/install_simplecble/include/simpleble/Peripheral.h +82 -0
  78. data/vendor/simpleble/install_simplecble/include/simpleble/PeripheralSafe.h +64 -0
  79. data/vendor/simpleble/install_simplecble/include/simpleble/Service.h +34 -0
  80. data/vendor/simpleble/install_simplecble/include/simpleble/SimpleBLE.h +8 -0
  81. data/vendor/simpleble/install_simplecble/include/simpleble/Types.h +49 -0
  82. data/vendor/simpleble/install_simplecble/include/simpleble/Utils.h +13 -0
  83. data/vendor/simpleble/install_simplecble/include/simpleble/export.h +43 -0
  84. data/vendor/simpleble/install_simplecble/include/simpleble/kvn/kvn_bytearray.h +222 -0
  85. data/vendor/simpleble/install_simplecble/include/simplecble/adapter.h +188 -0
  86. data/vendor/simpleble/install_simplecble/include/simplecble/logging.h +37 -0
  87. data/vendor/simpleble/install_simplecble/include/simplecble/peripheral.h +304 -0
  88. data/vendor/simpleble/install_simplecble/include/simplecble/simpleble.h +21 -0
  89. data/vendor/simpleble/install_simplecble/include/simplecble/types.h +73 -0
  90. data/vendor/simpleble/install_simplecble/include/simplecble/utils.h +27 -0
  91. data/vendor/simpleble/simpleble/include/simpleble/Adapter.h +102 -0
  92. data/vendor/simpleble/simpleble/include/simpleble/AdapterSafe.h +58 -0
  93. data/vendor/simpleble/simpleble/include/simpleble/Characteristic.h +39 -0
  94. data/vendor/simpleble/simpleble/include/simpleble/Config.h +55 -0
  95. data/vendor/simpleble/simpleble/include/simpleble/Descriptor.h +30 -0
  96. data/vendor/simpleble/simpleble/include/simpleble/Exceptions.h +72 -0
  97. data/vendor/simpleble/simpleble/include/simpleble/Logging.h +73 -0
  98. data/vendor/simpleble/simpleble/include/simpleble/Peripheral.h +82 -0
  99. data/vendor/simpleble/simpleble/include/simpleble/PeripheralSafe.h +64 -0
  100. data/vendor/simpleble/simpleble/include/simpleble/Service.h +34 -0
  101. data/vendor/simpleble/simpleble/include/simpleble/SimpleBLE.h +8 -0
  102. data/vendor/simpleble/simpleble/include/simpleble/Types.h +49 -0
  103. data/vendor/simpleble/simpleble/include/simpleble/Utils.h +13 -0
  104. data/vendor/simpleble/simpleble/include/simpleble_c/adapter.h +188 -0
  105. data/vendor/simpleble/simpleble/include/simpleble_c/logging.h +37 -0
  106. data/vendor/simpleble/simpleble/include/simpleble_c/peripheral.h +304 -0
  107. data/vendor/simpleble/simpleble/include/simpleble_c/simpleble.h +21 -0
  108. data/vendor/simpleble/simpleble/include/simpleble_c/types.h +73 -0
  109. data/vendor/simpleble/simpleble/include/simpleble_c/utils.h +27 -0
  110. data/vendor/simpleble/simpleble/src/CommonUtils.h +63 -0
  111. data/vendor/simpleble/simpleble/src/Exceptions.cpp +31 -0
  112. data/vendor/simpleble/simpleble/src/Logging.cpp +136 -0
  113. data/vendor/simpleble/simpleble/src/LoggingInternal.h +85 -0
  114. data/vendor/simpleble/simpleble/src/Utils.cpp +24 -0
  115. data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.cpp +101 -0
  116. data/vendor/simpleble/simpleble/src/backends/android/AdapterAndroid.h +70 -0
  117. data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.cpp +40 -0
  118. data/vendor/simpleble/simpleble/src/backends/android/BackendAndroid.h +20 -0
  119. data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.cpp +365 -0
  120. data/vendor/simpleble/simpleble/src/backends/android/PeripheralAndroid.h +90 -0
  121. data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.cpp +432 -0
  122. data/vendor/simpleble/simpleble/src/backends/android/bridge/BluetoothGattCallback.h +102 -0
  123. data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.cpp +142 -0
  124. data/vendor/simpleble/simpleble/src/backends/android/bridge/ScanCallback.h +55 -0
  125. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.cpp +107 -0
  126. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.h +55 -0
  127. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.cpp +68 -0
  128. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.h +54 -0
  129. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.cpp +115 -0
  130. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.h +75 -0
  131. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.cpp +142 -0
  132. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.h +66 -0
  133. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.cpp +67 -0
  134. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.h +46 -0
  135. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.cpp +106 -0
  136. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.h +47 -0
  137. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.cpp +47 -0
  138. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.h +37 -0
  139. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.cpp +69 -0
  140. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.h +41 -0
  141. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.cpp +63 -0
  142. data/vendor/simpleble/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.h +42 -0
  143. data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.cpp +32 -0
  144. data/vendor/simpleble/simpleble/src/backends/android/types/android/os/ParcelUUID.h +30 -0
  145. data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.cpp +54 -0
  146. data/vendor/simpleble/simpleble/src/backends/android/types/android/util/SparseArray.h +37 -0
  147. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.cpp +36 -0
  148. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Iterator.h +28 -0
  149. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.cpp +29 -0
  150. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/List.h +27 -0
  151. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.cpp +33 -0
  152. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/Set.h +28 -0
  153. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.cpp +26 -0
  154. data/vendor/simpleble/simpleble/src/backends/android/types/java/util/UUID.h +29 -0
  155. data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.cpp +53 -0
  156. data/vendor/simpleble/simpleble/src/backends/common/AdapterBase.h +81 -0
  157. data/vendor/simpleble/simpleble/src/backends/common/AdapterBaseTypes.h +22 -0
  158. data/vendor/simpleble/simpleble/src/backends/common/BackendBase.h +20 -0
  159. data/vendor/simpleble/simpleble/src/backends/common/BackendUtils.h +33 -0
  160. data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.cpp +28 -0
  161. data/vendor/simpleble/simpleble/src/backends/common/CharacteristicBase.h +38 -0
  162. data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.cpp +7 -0
  163. data/vendor/simpleble/simpleble/src/backends/common/DescriptorBase.h +19 -0
  164. data/vendor/simpleble/simpleble/src/backends/common/PeripheralBase.h +82 -0
  165. data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.cpp +18 -0
  166. data/vendor/simpleble/simpleble/src/backends/common/ServiceBase.h +28 -0
  167. data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.cpp +102 -0
  168. data/vendor/simpleble/simpleble/src/backends/linux/AdapterLinux.h +55 -0
  169. data/vendor/simpleble/simpleble/src/backends/linux/BackendBluez.cpp +87 -0
  170. data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.cpp +376 -0
  171. data/vendor/simpleble/simpleble/src/backends/linux/PeripheralLinux.h +90 -0
  172. data/vendor/simpleble/simpleble/src/backends/macos/AdapterBaseMacOS.h +29 -0
  173. data/vendor/simpleble/simpleble/src/backends/macos/AdapterMac.h +78 -0
  174. data/vendor/simpleble/simpleble/src/backends/macos/PeripheralBaseMacOS.h +49 -0
  175. data/vendor/simpleble/simpleble/src/backends/macos/PeripheralMac.h +81 -0
  176. data/vendor/simpleble/simpleble/src/backends/macos/Utils.h +9 -0
  177. data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.cpp +65 -0
  178. data/vendor/simpleble/simpleble/src/backends/plain/AdapterPlain.h +49 -0
  179. data/vendor/simpleble/simpleble/src/backends/plain/BackendPlain.cpp +30 -0
  180. data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.cpp +159 -0
  181. data/vendor/simpleble/simpleble/src/backends/plain/PeripheralPlain.h +72 -0
  182. data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.cpp +330 -0
  183. data/vendor/simpleble/simpleble/src/backends/windows/AdapterWindows.h +89 -0
  184. data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.cpp +67 -0
  185. data/vendor/simpleble/simpleble/src/backends/windows/BackendWinRT.h +18 -0
  186. data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.cpp +49 -0
  187. data/vendor/simpleble/simpleble/src/backends/windows/MtaManager.h +90 -0
  188. data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.cpp +487 -0
  189. data/vendor/simpleble/simpleble/src/backends/windows/PeripheralWindows.h +129 -0
  190. data/vendor/simpleble/simpleble/src/backends/windows/Utils.cpp +146 -0
  191. data/vendor/simpleble/simpleble/src/backends/windows/Utils.h +47 -0
  192. data/vendor/simpleble/simpleble/src/builders/BuildVec.h +32 -0
  193. data/vendor/simpleble/simpleble/src/builders/BuilderBase.h +87 -0
  194. data/vendor/simpleble/simpleble/src/external/TaskRunner.hpp +99 -0
  195. data/vendor/simpleble/simpleble/src/external/ThreadRunner.h +52 -0
  196. data/vendor/simpleble/simpleble/src/external/kvn_safe_callback.hpp +66 -0
  197. data/vendor/simpleble/simpleble/src/external/kvn_safe_map.hpp +94 -0
  198. data/vendor/simpleble/simpleble/src/external/kvn_threadrunner.hpp +70 -0
  199. data/vendor/simpleble/simpleble/src/external/logfwd.hpp +35 -0
  200. data/vendor/simpleble/simpleble/src/frontends/base/Adapter.cpp +111 -0
  201. data/vendor/simpleble/simpleble/src/frontends/base/Backend.cpp +83 -0
  202. data/vendor/simpleble/simpleble/src/frontends/base/Backend.h +76 -0
  203. data/vendor/simpleble/simpleble/src/frontends/base/Characteristic.cpp +56 -0
  204. data/vendor/simpleble/simpleble/src/frontends/base/Descriptor.cpp +21 -0
  205. data/vendor/simpleble/simpleble/src/frontends/base/Peripheral.cpp +113 -0
  206. data/vendor/simpleble/simpleble/src/frontends/base/Service.cpp +26 -0
  207. data/vendor/simpleble/simpleble/src/frontends/safe/AdapterSafe.cpp +158 -0
  208. data/vendor/simpleble/simpleble/src/frontends/safe/PeripheralSafe.cpp +219 -0
  209. data/vendor/simpleble/simpleble/src_c/adapter.cpp +204 -0
  210. data/vendor/simpleble/simpleble/src_c/logging.cpp +19 -0
  211. data/vendor/simpleble/simpleble/src_c/peripheral.cpp +444 -0
  212. data/vendor/simpleble/simpleble/src_c/simpleble.cpp +5 -0
  213. data/vendor/simpleble/simpleble/src_c/utils.cpp +15 -0
  214. data/vendor/simpleble/simpleble/test/src/main.cpp +8 -0
  215. data/vendor/simpleble/simpleble/test/src/test_bytearray.cpp +246 -0
  216. data/vendor/simpleble/simpleble/test/src/test_utils.cpp +24 -0
  217. data/vendor/simpleble/simplebluez/include/simplebluez/Adapter.h +46 -0
  218. data/vendor/simpleble/simplebluez/include/simplebluez/Agent.h +52 -0
  219. data/vendor/simpleble/simplebluez/include/simplebluez/Bluez.h +37 -0
  220. data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrg.h +22 -0
  221. data/vendor/simpleble/simplebluez/include/simplebluez/BluezOrgBluez.h +26 -0
  222. data/vendor/simpleble/simplebluez/include/simplebluez/BluezRoot.h +32 -0
  223. data/vendor/simpleble/simplebluez/include/simplebluez/Characteristic.h +46 -0
  224. data/vendor/simpleble/simplebluez/include/simplebluez/Descriptor.h +33 -0
  225. data/vendor/simpleble/simplebluez/include/simplebluez/Device.h +64 -0
  226. data/vendor/simpleble/simplebluez/include/simplebluez/Exceptions.h +43 -0
  227. data/vendor/simpleble/simplebluez/include/simplebluez/Service.h +27 -0
  228. data/vendor/simpleble/simplebluez/include/simplebluez/Types.h +9 -0
  229. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Adapter1.h +49 -0
  230. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Agent1.h +100 -0
  231. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/AgentManager1.h +24 -0
  232. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Battery1.h +32 -0
  233. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/Device1.h +62 -0
  234. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattCharacteristic1.h +48 -0
  235. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattDescriptor1.h +41 -0
  236. data/vendor/simpleble/simplebluez/include/simplebluez/interfaces/GattService1.h +28 -0
  237. data/vendor/simpleble/simplebluez/src/Adapter.cpp +78 -0
  238. data/vendor/simpleble/simplebluez/src/Agent.cpp +72 -0
  239. data/vendor/simpleble/simplebluez/src/Bluez.cpp +45 -0
  240. data/vendor/simpleble/simplebluez/src/BluezOrg.cpp +20 -0
  241. data/vendor/simpleble/simplebluez/src/BluezOrgBluez.cpp +23 -0
  242. data/vendor/simpleble/simplebluez/src/BluezRoot.cpp +44 -0
  243. data/vendor/simpleble/simplebluez/src/Characteristic.cpp +64 -0
  244. data/vendor/simpleble/simplebluez/src/Descriptor.cpp +27 -0
  245. data/vendor/simpleble/simplebluez/src/Device.cpp +104 -0
  246. data/vendor/simpleble/simplebluez/src/Exceptions.cpp +29 -0
  247. data/vendor/simpleble/simplebluez/src/Logging.cpp +52 -0
  248. data/vendor/simpleble/simplebluez/src/Logging.h +57 -0
  249. data/vendor/simpleble/simplebluez/src/Service.cpp +33 -0
  250. data/vendor/simpleble/simplebluez/src/interfaces/Adapter1.cpp +123 -0
  251. data/vendor/simpleble/simplebluez/src/interfaces/Agent1.cpp +143 -0
  252. data/vendor/simpleble/simplebluez/src/interfaces/AgentManager1.cpp +34 -0
  253. data/vendor/simpleble/simplebluez/src/interfaces/Battery1.cpp +30 -0
  254. data/vendor/simpleble/simplebluez/src/interfaces/Device1.cpp +170 -0
  255. data/vendor/simpleble/simplebluez/src/interfaces/GattCharacteristic1.cpp +118 -0
  256. data/vendor/simpleble/simplebluez/src/interfaces/GattDescriptor1.cpp +78 -0
  257. data/vendor/simpleble/simplebluez/src/interfaces/GattService1.cpp +28 -0
  258. data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.cpp +53 -0
  259. data/vendor/simpleble/simplebluez/test/src/helpers/PythonRunner.h +24 -0
  260. data/vendor/simpleble/simplebluez/test/src/main.cpp +16 -0
  261. data/vendor/simpleble/simplecble/include/simplecble/adapter.h +188 -0
  262. data/vendor/simpleble/simplecble/include/simplecble/logging.h +37 -0
  263. data/vendor/simpleble/simplecble/include/simplecble/peripheral.h +304 -0
  264. data/vendor/simpleble/simplecble/include/simplecble/simpleble.h +21 -0
  265. data/vendor/simpleble/simplecble/include/simplecble/types.h +73 -0
  266. data/vendor/simpleble/simplecble/include/simplecble/utils.h +27 -0
  267. data/vendor/simpleble/simplecble/src/adapter.cpp +204 -0
  268. data/vendor/simpleble/simplecble/src/logging.cpp +19 -0
  269. data/vendor/simpleble/simplecble/src/peripheral.cpp +444 -0
  270. data/vendor/simpleble/simplecble/src/simpleble.cpp +5 -0
  271. data/vendor/simpleble/simplecble/src/utils.cpp +15 -0
  272. data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Interface.h +67 -0
  273. data/vendor/simpleble/simpledbus/include/simpledbus/advanced/InterfaceRegistry.h +64 -0
  274. data/vendor/simpleble/simpledbus/include/simpledbus/advanced/Proxy.h +117 -0
  275. data/vendor/simpleble/simpledbus/include/simpledbus/base/Connection.h +50 -0
  276. data/vendor/simpleble/simpledbus/include/simpledbus/base/Exceptions.h +56 -0
  277. data/vendor/simpleble/simpledbus/include/simpledbus/base/Holder.h +147 -0
  278. data/vendor/simpleble/simpledbus/include/simpledbus/base/Logging.h +57 -0
  279. data/vendor/simpleble/simpledbus/include/simpledbus/base/Message.h +89 -0
  280. data/vendor/simpleble/simpledbus/include/simpledbus/base/Path.h +24 -0
  281. data/vendor/simpleble/simpledbus/include/simpledbus/interfaces/ObjectManager.h +26 -0
  282. data/vendor/simpleble/simpledbus/src/advanced/Interface.cpp +155 -0
  283. data/vendor/simpleble/simpledbus/src/advanced/Proxy.cpp +375 -0
  284. data/vendor/simpleble/simpledbus/src/base/Connection.cpp +222 -0
  285. data/vendor/simpleble/simpledbus/src/base/Exceptions.cpp +39 -0
  286. data/vendor/simpleble/simpledbus/src/base/Holder.cpp +739 -0
  287. data/vendor/simpleble/simpledbus/src/base/Logging.cpp +52 -0
  288. data/vendor/simpleble/simpledbus/src/base/Message.cpp +622 -0
  289. data/vendor/simpleble/simpledbus/src/base/Path.cpp +129 -0
  290. data/vendor/simpleble/simpledbus/src/interfaces/ObjectManager.cpp +58 -0
  291. data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.cpp +53 -0
  292. data/vendor/simpleble/simpledbus/test/src/helpers/PythonRunner.h +24 -0
  293. data/vendor/simpleble/simpledbus/test/src/main.cpp +16 -0
  294. data/vendor/simpleble/simpledbus/test/src/test_holder.cpp +184 -0
  295. data/vendor/simpleble/simpledbus/test/src/test_message.cpp +397 -0
  296. data/vendor/simpleble/simpledbus/test/src/test_path.cpp +76 -0
  297. data/vendor/simpleble/simpledbus/test/src/test_proxy_children.cpp +109 -0
  298. data/vendor/simpleble/simpledbus/test/src/test_proxy_interfaces.cpp +102 -0
  299. data/vendor/simpleble/simpledbus/test/src/test_proxy_lifetime.cpp +18 -0
  300. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/ThreadRunner.h +89 -0
  301. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.cpp +55 -0
  302. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/android_utils.h +18 -0
  303. data/vendor/simpleble/simpledroidble/simpledroidble/src/main/cpp/simpleble_android.cpp +813 -0
  304. data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.cpp +37 -0
  305. data/vendor/simpleble/simplejavable/cpp/src/core/AdapterWrapper.h +23 -0
  306. data/vendor/simpleble/simplejavable/cpp/src/core/Cache.cpp +58 -0
  307. data/vendor/simpleble/simplejavable/cpp/src/core/Cache.h +34 -0
  308. data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.cpp +17 -0
  309. data/vendor/simpleble/simplejavable/cpp/src/core/PeripheralWrapper.h +19 -0
  310. data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.cpp +257 -0
  311. data/vendor/simpleble/simplejavable/cpp/src/java/lang/ArrayList.h +78 -0
  312. data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.cpp +96 -0
  313. data/vendor/simpleble/simplejavable/cpp/src/java/lang/HashMap.h +54 -0
  314. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.cpp +93 -0
  315. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Integer.h +49 -0
  316. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.cpp +85 -0
  317. data/vendor/simpleble/simplejavable/cpp/src/java/lang/Iterator.h +48 -0
  318. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.cpp +91 -0
  319. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/AdapterCallback.h +90 -0
  320. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.cpp +35 -0
  321. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Characteristic.h +60 -0
  322. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.cpp +33 -0
  323. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/DataCallback.h +45 -0
  324. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.cpp +30 -0
  325. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Descriptor.h +49 -0
  326. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.cpp +41 -0
  327. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/PeripheralCallback.h +51 -0
  328. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.cpp +33 -0
  329. data/vendor/simpleble/simplejavable/cpp/src/org/simplejavable/Service.h +54 -0
  330. data/vendor/simpleble/simplejavable/cpp/src/simplejavable.cpp +361 -0
  331. data/vendor/simpleble/simplepyble/src/main.cpp +55 -0
  332. data/vendor/simpleble/simplepyble/src/wrap_adapter.cpp +106 -0
  333. data/vendor/simpleble/simplepyble/src/wrap_characteristic.cpp +56 -0
  334. data/vendor/simpleble/simplepyble/src/wrap_config.cpp +136 -0
  335. data/vendor/simpleble/simplepyble/src/wrap_descriptor.cpp +21 -0
  336. data/vendor/simpleble/simplepyble/src/wrap_peripheral.cpp +217 -0
  337. data/vendor/simpleble/simplepyble/src/wrap_service.cpp +32 -0
  338. data/vendor/simpleble/simplepyble/src/wrap_types.cpp +21 -0
  339. data/vendor/simpleble/simplersble/src/bindings/Bindings.cpp +338 -0
  340. data/vendor/simpleble/simplersble/src/bindings/Bindings.hpp +178 -0
  341. metadata +430 -0
@@ -0,0 +1,682 @@
1
+ // Ruby integration
2
+ #include <ruby.h>
3
+ #include <stdlib.h>
4
+ #include <string.h>
5
+
6
+ // SimpleBLE C API - extconf.rb dynamically configures the correct include paths
7
+ #include <adapter.h>
8
+ #include <peripheral.h>
9
+ #include <types.h>
10
+
11
+ // Module and class definitions
12
+ static VALUE mSimpleBLE;
13
+ static VALUE cAdapter;
14
+ static VALUE cPeripheral;
15
+
16
+ // Exception classes
17
+ static VALUE eSimpleBLEError;
18
+ static VALUE eScanError;
19
+ static VALUE eConnectionError;
20
+ static VALUE eCharacteristicError; // placeholder for future use
21
+
22
+ // Error handling macro (SimpleBLE currently only has SUCCESS/FAILURE)
23
+ #define SIMPLEBLE_RAISE_IF_FAILURE(err, exc, msg) do { \
24
+ if ((err) != SIMPLEBLE_SUCCESS) { \
25
+ rb_raise((exc), "%s", (msg)); \
26
+ } \
27
+ } while(0)
28
+
29
+ // Ruby object data structures - using SimpleBLE C API types
30
+ typedef struct {
31
+ simpleble_adapter_t adapter_handle;
32
+ } adapter_data_t;
33
+
34
+ typedef struct {
35
+ simpleble_peripheral_t peripheral_handle;
36
+ } peripheral_data_t;
37
+
38
+ // Memory management functions
39
+ static void adapter_free(void* ptr) {
40
+ adapter_data_t* data = (adapter_data_t*)ptr;
41
+ if (data->adapter_handle) {
42
+ simpleble_adapter_release_handle(data->adapter_handle);
43
+ }
44
+ xfree(data);
45
+ }
46
+
47
+ static const rb_data_type_t adapter_type = {
48
+ "SimpleBLE::Adapter",
49
+ {0, adapter_free, 0, 0},
50
+ 0, 0,
51
+ RUBY_TYPED_FREE_IMMEDIATELY,
52
+ };
53
+
54
+ static void peripheral_free(void* ptr) {
55
+ peripheral_data_t* data = (peripheral_data_t*)ptr;
56
+ if (data->peripheral_handle) {
57
+ simpleble_peripheral_release_handle(data->peripheral_handle);
58
+ }
59
+ xfree(data);
60
+ }
61
+
62
+ static const rb_data_type_t peripheral_type = {
63
+ "SimpleBLE::Peripheral",
64
+ {0, peripheral_free, 0, 0},
65
+ 0, 0,
66
+ RUBY_TYPED_FREE_IMMEDIATELY,
67
+ };
68
+
69
+ // Helper functions
70
+ static void check_adapter_data(adapter_data_t* data) {
71
+ if (!data || !data->adapter_handle) {
72
+ rb_raise(eSimpleBLEError, "Adapter not initialized");
73
+ }
74
+ }
75
+
76
+ static void check_peripheral_data(peripheral_data_t* data) {
77
+ if (!data || !data->peripheral_handle) {
78
+ rb_raise(eSimpleBLEError, "Peripheral not initialized");
79
+ }
80
+ }
81
+
82
+ /*
83
+ * call-seq:
84
+ * SimpleBLE::Adapter.bluetooth_enabled? -> Boolean
85
+ *
86
+ * Check if Bluetooth is enabled on the system.
87
+ */
88
+ static VALUE
89
+ rb_adapter_bluetooth_enabled(VALUE self)
90
+ {
91
+ return simpleble_adapter_is_bluetooth_enabled() ? Qtrue : Qfalse;
92
+ }
93
+
94
+ /*
95
+ * call-seq:
96
+ * SimpleBLE::Adapter.get_adapters -> Array
97
+ *
98
+ * Get all available Bluetooth adapters.
99
+ */
100
+ static VALUE
101
+ rb_adapter_get_adapters(VALUE self)
102
+ {
103
+ size_t count = simpleble_adapter_get_count();
104
+ VALUE adapters = rb_ary_new_capa(count);
105
+
106
+ for (size_t i = 0; i < count; i++) {
107
+ simpleble_adapter_t adapter_handle = simpleble_adapter_get_handle(i);
108
+ if (adapter_handle) {
109
+ adapter_data_t* data = ALLOC(adapter_data_t);
110
+ data->adapter_handle = adapter_handle;
111
+
112
+ VALUE adapter = TypedData_Wrap_Struct(cAdapter, &adapter_type, data);
113
+ rb_ary_push(adapters, adapter);
114
+ }
115
+ }
116
+
117
+ return adapters;
118
+ }
119
+
120
+ /*
121
+ * call-seq:
122
+ * adapter.scan_start -> self
123
+ *
124
+ * Start scanning (continuous until scan_stop is called).
125
+ */
126
+ static VALUE
127
+ rb_adapter_scan_start(VALUE self)
128
+ {
129
+ adapter_data_t* data;
130
+ TypedData_Get_Struct(self, adapter_data_t, &adapter_type, data);
131
+ check_adapter_data(data);
132
+ simpleble_err_t err = simpleble_adapter_scan_start(data->adapter_handle);
133
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eScanError, "Failed to start scan");
134
+ return self;
135
+ }
136
+
137
+ /*
138
+ * call-seq:
139
+ * adapter.scan_stop -> self
140
+ *
141
+ * Stop scanning.
142
+ */
143
+ static VALUE
144
+ rb_adapter_scan_stop(VALUE self)
145
+ {
146
+ adapter_data_t* data;
147
+ TypedData_Get_Struct(self, adapter_data_t, &adapter_type, data);
148
+ check_adapter_data(data);
149
+ simpleble_err_t err = simpleble_adapter_scan_stop(data->adapter_handle);
150
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eScanError, "Failed to stop scan");
151
+ return self;
152
+ }
153
+
154
+ /*
155
+ * call-seq:
156
+ * adapter.scan_for(timeout_ms) -> self
157
+ *
158
+ * Perform a blocking scan for timeout_ms milliseconds.
159
+ */
160
+ static VALUE
161
+ rb_adapter_scan_for(VALUE self, VALUE timeout_ms_val)
162
+ {
163
+ adapter_data_t* data;
164
+ TypedData_Get_Struct(self, adapter_data_t, &adapter_type, data);
165
+ check_adapter_data(data);
166
+ int timeout_ms = NUM2INT(timeout_ms_val);
167
+ simpleble_err_t err = simpleble_adapter_scan_for(data->adapter_handle, timeout_ms);
168
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eScanError, "Failed to perform timed scan");
169
+ return self;
170
+ }
171
+
172
+ /*
173
+ * call-seq:
174
+ * adapter.scan_active? -> Boolean
175
+ */
176
+ static VALUE
177
+ rb_adapter_scan_active(VALUE self)
178
+ {
179
+ adapter_data_t* data;
180
+ TypedData_Get_Struct(self, adapter_data_t, &adapter_type, data);
181
+ check_adapter_data(data);
182
+ bool active = false;
183
+ simpleble_err_t err = simpleble_adapter_scan_is_active(data->adapter_handle, &active);
184
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eScanError, "Failed to query scan state");
185
+ return active ? Qtrue : Qfalse;
186
+ }
187
+
188
+ /*
189
+ * call-seq:
190
+ * adapter.scan_results -> [Peripheral, ...]
191
+ *
192
+ * Return peripherals discovered in last/ongoing scan.
193
+ */
194
+ static VALUE
195
+ rb_adapter_scan_results(VALUE self)
196
+ {
197
+ adapter_data_t* data;
198
+ TypedData_Get_Struct(self, adapter_data_t, &adapter_type, data);
199
+ check_adapter_data(data);
200
+ size_t count = simpleble_adapter_scan_get_results_count(data->adapter_handle);
201
+ VALUE ary = rb_ary_new_capa(count);
202
+ for (size_t i = 0; i < count; i++) {
203
+ simpleble_peripheral_t ph = simpleble_adapter_scan_get_results_handle(data->adapter_handle, i);
204
+ if (ph) {
205
+ peripheral_data_t* pdata = ALLOC(peripheral_data_t);
206
+ pdata->peripheral_handle = ph;
207
+ VALUE periph = TypedData_Wrap_Struct(cPeripheral, &peripheral_type, pdata);
208
+ rb_ary_push(ary, periph);
209
+ }
210
+ }
211
+ return ary;
212
+ }
213
+
214
+ /*
215
+ * call-seq:
216
+ * adapter.identifier -> String
217
+ *
218
+ * Get the adapter identifier.
219
+ */
220
+ static VALUE
221
+ rb_adapter_identifier(VALUE self)
222
+ {
223
+ adapter_data_t* data;
224
+ TypedData_Get_Struct(self, adapter_data_t, &adapter_type, data);
225
+ check_adapter_data(data);
226
+
227
+ char* identifier = simpleble_adapter_identifier(data->adapter_handle);
228
+ if (!identifier) {
229
+ return Qnil;
230
+ }
231
+
232
+ VALUE result = rb_str_new_cstr(identifier);
233
+ free(identifier);
234
+ return result;
235
+ }
236
+
237
+ /*
238
+ * call-seq:
239
+ * adapter.address -> String
240
+ *
241
+ * Get the adapter MAC address.
242
+ */
243
+ static VALUE
244
+ rb_adapter_address(VALUE self)
245
+ {
246
+ adapter_data_t* data;
247
+ TypedData_Get_Struct(self, adapter_data_t, &adapter_type, data);
248
+ check_adapter_data(data);
249
+
250
+ char* address = simpleble_adapter_address(data->adapter_handle);
251
+ if (!address) {
252
+ return Qnil;
253
+ }
254
+
255
+ VALUE result = rb_str_new_cstr(address);
256
+ free(address);
257
+ return result;
258
+ }
259
+
260
+ /*
261
+ * call-seq:
262
+ * adapter.paired_peripherals -> [Peripheral, ...]
263
+ *
264
+ * Return previously paired peripherals.
265
+ */
266
+ static VALUE
267
+ rb_adapter_paired_peripherals(VALUE self)
268
+ {
269
+ adapter_data_t* data;
270
+ TypedData_Get_Struct(self, adapter_data_t, &adapter_type, data);
271
+ check_adapter_data(data);
272
+ size_t count = simpleble_adapter_get_paired_peripherals_count(data->adapter_handle);
273
+ VALUE ary = rb_ary_new_capa(count);
274
+ for (size_t i = 0; i < count; i++) {
275
+ simpleble_peripheral_t ph = simpleble_adapter_get_paired_peripherals_handle(data->adapter_handle, i);
276
+ if (ph) {
277
+ peripheral_data_t* pdata = ALLOC(peripheral_data_t);
278
+ pdata->peripheral_handle = ph;
279
+ VALUE periph = TypedData_Wrap_Struct(cPeripheral, &peripheral_type, pdata);
280
+ rb_ary_push(ary, periph);
281
+ }
282
+ }
283
+ return ary;
284
+ }
285
+
286
+ /* Peripheral Methods */
287
+
288
+ /* identifier */
289
+ static VALUE rb_peripheral_identifier(VALUE self) {
290
+ peripheral_data_t* data;
291
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
292
+ check_peripheral_data(data);
293
+ char* ident = simpleble_peripheral_identifier(data->peripheral_handle);
294
+ if (!ident) return Qnil;
295
+ VALUE str = rb_str_new_cstr(ident);
296
+ free(ident);
297
+ return str;
298
+ }
299
+
300
+ /* address */
301
+ static VALUE rb_peripheral_address(VALUE self) {
302
+ peripheral_data_t* data;
303
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
304
+ check_peripheral_data(data);
305
+ char* addr = simpleble_peripheral_address(data->peripheral_handle);
306
+ if (!addr) return Qnil;
307
+ VALUE str = rb_str_new_cstr(addr);
308
+ free(addr);
309
+ return str;
310
+ }
311
+
312
+ /* rssi */
313
+ static VALUE rb_peripheral_rssi(VALUE self) {
314
+ peripheral_data_t* data;
315
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
316
+ check_peripheral_data(data);
317
+ int16_t rssi = simpleble_peripheral_rssi(data->peripheral_handle);
318
+ return INT2NUM(rssi);
319
+ }
320
+
321
+ /* address_type */
322
+ static VALUE rb_peripheral_address_type(VALUE self) {
323
+ peripheral_data_t* data;
324
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
325
+ check_peripheral_data(data);
326
+ simpleble_address_type_t at = simpleble_peripheral_address_type(data->peripheral_handle);
327
+ return INT2NUM((int)at);
328
+ }
329
+
330
+ /* connectable? */
331
+ static VALUE rb_peripheral_connectable(VALUE self) {
332
+ peripheral_data_t* data;
333
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
334
+ check_peripheral_data(data);
335
+ bool connectable = false;
336
+ simpleble_err_t err = simpleble_peripheral_is_connectable(data->peripheral_handle, &connectable);
337
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eConnectionError, "Failed to query connectable state");
338
+ return connectable ? Qtrue : Qfalse;
339
+ }
340
+
341
+ /* connected? */
342
+ static VALUE rb_peripheral_connected(VALUE self) {
343
+ peripheral_data_t* data;
344
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
345
+ check_peripheral_data(data);
346
+ bool connected = false;
347
+ simpleble_err_t err = simpleble_peripheral_is_connected(data->peripheral_handle, &connected);
348
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eConnectionError, "Failed to query connection state");
349
+ return connected ? Qtrue : Qfalse;
350
+ }
351
+
352
+ /* paired? */
353
+ static VALUE rb_peripheral_paired(VALUE self) {
354
+ peripheral_data_t* data;
355
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
356
+ check_peripheral_data(data);
357
+ bool paired = false;
358
+ simpleble_err_t err = simpleble_peripheral_is_paired(data->peripheral_handle, &paired);
359
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eConnectionError, "Failed to query paired state");
360
+ return paired ? Qtrue : Qfalse;
361
+ }
362
+
363
+ /* connect */
364
+ static VALUE rb_peripheral_connect(VALUE self) {
365
+ peripheral_data_t* data;
366
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
367
+ check_peripheral_data(data);
368
+ simpleble_err_t err = simpleble_peripheral_connect(data->peripheral_handle);
369
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eConnectionError, "Failed to connect to peripheral");
370
+ return self;
371
+ }
372
+
373
+ /* disconnect */
374
+ static VALUE rb_peripheral_disconnect(VALUE self) {
375
+ peripheral_data_t* data;
376
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
377
+ check_peripheral_data(data);
378
+ simpleble_err_t err = simpleble_peripheral_disconnect(data->peripheral_handle);
379
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eConnectionError, "Failed to disconnect peripheral");
380
+ return self;
381
+ }
382
+
383
+ /* unpair */
384
+ static VALUE rb_peripheral_unpair(VALUE self) {
385
+ peripheral_data_t* data;
386
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
387
+ check_peripheral_data(data);
388
+ simpleble_err_t err = simpleble_peripheral_unpair(data->peripheral_handle);
389
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eConnectionError, "Failed to unpair peripheral");
390
+ return self;
391
+ }
392
+
393
+ /* tx_power */
394
+ static VALUE rb_peripheral_tx_power(VALUE self) {
395
+ peripheral_data_t* data;
396
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
397
+ check_peripheral_data(data);
398
+ int16_t tx_power = simpleble_peripheral_tx_power(data->peripheral_handle);
399
+ return INT2NUM(tx_power);
400
+ }
401
+
402
+ /* mtu */
403
+ static VALUE rb_peripheral_mtu(VALUE self) {
404
+ peripheral_data_t* data;
405
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
406
+ check_peripheral_data(data);
407
+ uint16_t mtu = simpleble_peripheral_mtu(data->peripheral_handle);
408
+ return UINT2NUM(mtu);
409
+ }
410
+
411
+ /* services */
412
+ static VALUE rb_peripheral_services(VALUE self) {
413
+ peripheral_data_t* data;
414
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
415
+ check_peripheral_data(data);
416
+
417
+ size_t count = simpleble_peripheral_services_count(data->peripheral_handle);
418
+ VALUE services = rb_ary_new_capa(count);
419
+
420
+ for (size_t i = 0; i < count; i++) {
421
+ simpleble_service_t service;
422
+ simpleble_err_t err = simpleble_peripheral_services_get(data->peripheral_handle, i, &service);
423
+ if (err == SIMPLEBLE_SUCCESS) {
424
+ VALUE service_hash = rb_hash_new();
425
+ rb_hash_aset(service_hash, rb_str_new_cstr("uuid"), rb_str_new_cstr(service.uuid.value));
426
+
427
+ // Add characteristics array
428
+ VALUE characteristics = rb_ary_new_capa(service.characteristic_count);
429
+ for (size_t j = 0; j < service.characteristic_count; j++) {
430
+ simpleble_characteristic_t* char_ptr = &service.characteristics[j];
431
+ VALUE char_hash = rb_hash_new();
432
+ rb_hash_aset(char_hash, rb_str_new_cstr("uuid"), rb_str_new_cstr(char_ptr->uuid.value));
433
+ rb_hash_aset(char_hash, rb_str_new_cstr("can_read"), char_ptr->can_read ? Qtrue : Qfalse);
434
+ rb_hash_aset(char_hash, rb_str_new_cstr("can_write_request"), char_ptr->can_write_request ? Qtrue : Qfalse);
435
+ rb_hash_aset(char_hash, rb_str_new_cstr("can_write_command"), char_ptr->can_write_command ? Qtrue : Qfalse);
436
+ rb_hash_aset(char_hash, rb_str_new_cstr("can_notify"), char_ptr->can_notify ? Qtrue : Qfalse);
437
+ rb_hash_aset(char_hash, rb_str_new_cstr("can_indicate"), char_ptr->can_indicate ? Qtrue : Qfalse);
438
+
439
+ // Add descriptors array
440
+ VALUE descriptors = rb_ary_new_capa(char_ptr->descriptor_count);
441
+ for (size_t k = 0; k < char_ptr->descriptor_count; k++) {
442
+ VALUE desc_hash = rb_hash_new();
443
+ rb_hash_aset(desc_hash, rb_str_new_cstr("uuid"), rb_str_new_cstr(char_ptr->descriptors[k].uuid.value));
444
+ rb_ary_push(descriptors, desc_hash);
445
+ }
446
+ rb_hash_aset(char_hash, rb_str_new_cstr("descriptors"), descriptors);
447
+ rb_ary_push(characteristics, char_hash);
448
+ }
449
+ rb_hash_aset(service_hash, rb_str_new_cstr("characteristics"), characteristics);
450
+ rb_ary_push(services, service_hash);
451
+ }
452
+ }
453
+
454
+ return services;
455
+ }
456
+
457
+ /* manufacturer_data */
458
+ static VALUE rb_peripheral_manufacturer_data(VALUE self) {
459
+ peripheral_data_t* data;
460
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
461
+ check_peripheral_data(data);
462
+
463
+ size_t count = simpleble_peripheral_manufacturer_data_count(data->peripheral_handle);
464
+ VALUE manufacturer_data = rb_ary_new_capa(count);
465
+
466
+ for (size_t i = 0; i < count; i++) {
467
+ simpleble_manufacturer_data_t mfd;
468
+ simpleble_err_t err = simpleble_peripheral_manufacturer_data_get(data->peripheral_handle, i, &mfd);
469
+ if (err == SIMPLEBLE_SUCCESS) {
470
+ VALUE mfd_hash = rb_hash_new();
471
+ rb_hash_aset(mfd_hash, rb_str_new_cstr("manufacturer_id"), UINT2NUM(mfd.manufacturer_id));
472
+ rb_hash_aset(mfd_hash, rb_str_new_cstr("data"), rb_str_new((char*)mfd.data, mfd.data_length));
473
+ rb_ary_push(manufacturer_data, mfd_hash);
474
+ }
475
+ }
476
+
477
+ return manufacturer_data;
478
+ }
479
+
480
+ /* Helper function to parse UUID from Ruby string or symbol */
481
+ static simpleble_uuid_t parse_uuid(VALUE uuid_val) {
482
+ simpleble_uuid_t uuid;
483
+ memset(&uuid, 0, sizeof(uuid));
484
+
485
+ if (TYPE(uuid_val) == T_SYMBOL) {
486
+ uuid_val = rb_sym_to_s(uuid_val);
487
+ }
488
+
489
+ if (TYPE(uuid_val) == T_STRING) {
490
+ const char* uuid_str = StringValueCStr(uuid_val);
491
+ size_t len = strlen(uuid_str);
492
+ if (len < SIMPLEBLE_UUID_STR_LEN) {
493
+ strcpy(uuid.value, uuid_str);
494
+ } else {
495
+ rb_raise(rb_eArgError, "UUID string too long (max %d characters)", SIMPLEBLE_UUID_STR_LEN - 1);
496
+ }
497
+ } else {
498
+ rb_raise(rb_eTypeError, "UUID must be a string or symbol");
499
+ }
500
+
501
+ return uuid;
502
+ }
503
+
504
+ /* read_characteristic */
505
+ static VALUE rb_peripheral_read_characteristic(VALUE self, VALUE service_uuid, VALUE char_uuid) {
506
+ peripheral_data_t* data;
507
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
508
+ check_peripheral_data(data);
509
+
510
+ simpleble_uuid_t service = parse_uuid(service_uuid);
511
+ simpleble_uuid_t characteristic = parse_uuid(char_uuid);
512
+
513
+ uint8_t* read_data = NULL;
514
+ size_t data_length = 0;
515
+
516
+ simpleble_err_t err = simpleble_peripheral_read(data->peripheral_handle, service, characteristic, &read_data, &data_length);
517
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eCharacteristicError, "Failed to read characteristic");
518
+
519
+ if (!read_data) {
520
+ return Qnil;
521
+ }
522
+
523
+ VALUE result = rb_str_new((char*)read_data, data_length);
524
+ free(read_data);
525
+ return result;
526
+ }
527
+
528
+ /* write_characteristic_request */
529
+ static VALUE rb_peripheral_write_characteristic_request(VALUE self, VALUE service_uuid, VALUE char_uuid, VALUE data_val) {
530
+ peripheral_data_t* data;
531
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
532
+ check_peripheral_data(data);
533
+
534
+ simpleble_uuid_t service = parse_uuid(service_uuid);
535
+ simpleble_uuid_t characteristic = parse_uuid(char_uuid);
536
+
537
+ Check_Type(data_val, T_STRING);
538
+ const uint8_t* write_data = (const uint8_t*)RSTRING_PTR(data_val);
539
+ size_t data_length = RSTRING_LEN(data_val);
540
+
541
+ simpleble_err_t err = simpleble_peripheral_write_request(data->peripheral_handle, service, characteristic, write_data, data_length);
542
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eCharacteristicError, "Failed to write characteristic (request)");
543
+
544
+ return self;
545
+ }
546
+
547
+ /* write_characteristic_command */
548
+ static VALUE rb_peripheral_write_characteristic_command(VALUE self, VALUE service_uuid, VALUE char_uuid, VALUE data_val) {
549
+ peripheral_data_t* data;
550
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
551
+ check_peripheral_data(data);
552
+
553
+ simpleble_uuid_t service = parse_uuid(service_uuid);
554
+ simpleble_uuid_t characteristic = parse_uuid(char_uuid);
555
+
556
+ Check_Type(data_val, T_STRING);
557
+ const uint8_t* write_data = (const uint8_t*)RSTRING_PTR(data_val);
558
+ size_t data_length = RSTRING_LEN(data_val);
559
+
560
+ simpleble_err_t err = simpleble_peripheral_write_command(data->peripheral_handle, service, characteristic, write_data, data_length);
561
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eCharacteristicError, "Failed to write characteristic (command)");
562
+
563
+ return self;
564
+ }
565
+
566
+ /* read_descriptor */
567
+ static VALUE rb_peripheral_read_descriptor(VALUE self, VALUE service_uuid, VALUE char_uuid, VALUE desc_uuid) {
568
+ peripheral_data_t* data;
569
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
570
+ check_peripheral_data(data);
571
+
572
+ simpleble_uuid_t service = parse_uuid(service_uuid);
573
+ simpleble_uuid_t characteristic = parse_uuid(char_uuid);
574
+ simpleble_uuid_t descriptor = parse_uuid(desc_uuid);
575
+
576
+ uint8_t* read_data = NULL;
577
+ size_t data_length = 0;
578
+
579
+ simpleble_err_t err = simpleble_peripheral_read_descriptor(data->peripheral_handle, service, characteristic, descriptor, &read_data, &data_length);
580
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eCharacteristicError, "Failed to read descriptor");
581
+
582
+ if (!read_data) {
583
+ return Qnil;
584
+ }
585
+
586
+ VALUE result = rb_str_new((char*)read_data, data_length);
587
+ free(read_data);
588
+ return result;
589
+ }
590
+
591
+ /* write_descriptor */
592
+ static VALUE rb_peripheral_write_descriptor(VALUE self, VALUE service_uuid, VALUE char_uuid, VALUE desc_uuid, VALUE data_val) {
593
+ peripheral_data_t* data;
594
+ TypedData_Get_Struct(self, peripheral_data_t, &peripheral_type, data);
595
+ check_peripheral_data(data);
596
+
597
+ simpleble_uuid_t service = parse_uuid(service_uuid);
598
+ simpleble_uuid_t characteristic = parse_uuid(char_uuid);
599
+ simpleble_uuid_t descriptor = parse_uuid(desc_uuid);
600
+
601
+ Check_Type(data_val, T_STRING);
602
+ const uint8_t* write_data = (const uint8_t*)RSTRING_PTR(data_val);
603
+ size_t data_length = RSTRING_LEN(data_val);
604
+
605
+ simpleble_err_t err = simpleble_peripheral_write_descriptor(data->peripheral_handle, service, characteristic, descriptor, write_data, data_length);
606
+ SIMPLEBLE_RAISE_IF_FAILURE(err, eCharacteristicError, "Failed to write descriptor");
607
+
608
+ return self;
609
+ }
610
+
611
+ // Module initialization - SimpleBLE C API direct integration working locally
612
+ void Init_simpleble(void)
613
+ {
614
+ // Define main module
615
+ mSimpleBLE = rb_define_module("SimpleBLE");
616
+
617
+ // Define classes
618
+ cAdapter = rb_define_class_under(mSimpleBLE, "Adapter", rb_cObject);
619
+ cPeripheral = rb_define_class_under(mSimpleBLE, "Peripheral", rb_cObject);
620
+
621
+ // Define (or fetch existing) exception classes
622
+ eSimpleBLEError = rb_define_class_under(mSimpleBLE, "Error", rb_eStandardError);
623
+ // Fetch subclasses defined in Ruby layer if present
624
+ if (rb_const_defined(mSimpleBLE, rb_intern("ScanError"))) {
625
+ eScanError = rb_const_get(mSimpleBLE, rb_intern("ScanError"));
626
+ } else {
627
+ eScanError = rb_define_class_under(mSimpleBLE, "ScanError", eSimpleBLEError);
628
+ }
629
+ if (rb_const_defined(mSimpleBLE, rb_intern("ConnectionError"))) {
630
+ eConnectionError = rb_const_get(mSimpleBLE, rb_intern("ConnectionError"));
631
+ } else {
632
+ eConnectionError = rb_define_class_under(mSimpleBLE, "ConnectionError", eSimpleBLEError);
633
+ }
634
+ if (rb_const_defined(mSimpleBLE, rb_intern("CharacteristicError"))) {
635
+ eCharacteristicError = rb_const_get(mSimpleBLE, rb_intern("CharacteristicError"));
636
+ } else {
637
+ eCharacteristicError = rb_define_class_under(mSimpleBLE, "CharacteristicError", eSimpleBLEError);
638
+ }
639
+
640
+ // Adapter class methods
641
+ rb_define_singleton_method(cAdapter, "bluetooth_enabled?", rb_adapter_bluetooth_enabled, 0);
642
+ rb_define_singleton_method(cAdapter, "get_adapters", rb_adapter_get_adapters, 0);
643
+
644
+ // Adapter instance methods
645
+ rb_define_method(cAdapter, "identifier", rb_adapter_identifier, 0);
646
+ rb_define_method(cAdapter, "address", rb_adapter_address, 0);
647
+ rb_define_method(cAdapter, "scan_start", rb_adapter_scan_start, 0);
648
+ rb_define_method(cAdapter, "scan_stop", rb_adapter_scan_stop, 0);
649
+ rb_define_method(cAdapter, "scan_for", rb_adapter_scan_for, 1);
650
+ rb_define_method(cAdapter, "scan_active?", rb_adapter_scan_active, 0);
651
+ rb_define_method(cAdapter, "scan_results", rb_adapter_scan_results, 0);
652
+ rb_define_method(cAdapter, "paired_peripherals", rb_adapter_paired_peripherals, 0);
653
+
654
+ // Peripheral instance methods - basic info
655
+ rb_define_method(cPeripheral, "identifier", rb_peripheral_identifier, 0);
656
+ rb_define_method(cPeripheral, "address", rb_peripheral_address, 0);
657
+ rb_define_method(cPeripheral, "rssi", rb_peripheral_rssi, 0);
658
+ rb_define_method(cPeripheral, "tx_power", rb_peripheral_tx_power, 0);
659
+ rb_define_method(cPeripheral, "mtu", rb_peripheral_mtu, 0);
660
+ rb_define_method(cPeripheral, "address_type", rb_peripheral_address_type, 0);
661
+
662
+ // Peripheral instance methods - connection management
663
+ rb_define_method(cPeripheral, "connectable?", rb_peripheral_connectable, 0);
664
+ rb_define_method(cPeripheral, "connected?", rb_peripheral_connected, 0);
665
+ rb_define_method(cPeripheral, "paired?", rb_peripheral_paired, 0);
666
+ rb_define_method(cPeripheral, "connect", rb_peripheral_connect, 0);
667
+ rb_define_method(cPeripheral, "disconnect", rb_peripheral_disconnect, 0);
668
+ rb_define_method(cPeripheral, "unpair", rb_peripheral_unpair, 0);
669
+
670
+ // Peripheral instance methods - service discovery and data access
671
+ rb_define_method(cPeripheral, "services", rb_peripheral_services, 0);
672
+ rb_define_method(cPeripheral, "manufacturer_data", rb_peripheral_manufacturer_data, 0);
673
+
674
+ // Peripheral instance methods - characteristic operations
675
+ rb_define_method(cPeripheral, "read_characteristic", rb_peripheral_read_characteristic, 2);
676
+ rb_define_method(cPeripheral, "write_characteristic_request", rb_peripheral_write_characteristic_request, 3);
677
+ rb_define_method(cPeripheral, "write_characteristic_command", rb_peripheral_write_characteristic_command, 3);
678
+
679
+ // Peripheral instance methods - descriptor operations
680
+ rb_define_method(cPeripheral, "read_descriptor", rb_peripheral_read_descriptor, 3);
681
+ rb_define_method(cPeripheral, "write_descriptor", rb_peripheral_write_descriptor, 4);
682
+ }
@@ -0,0 +1,10 @@
1
+ module SimpleBLE
2
+ class Adapter
3
+ # All core methods (get_adapters, bluetooth_enabled?, identifier, address,
4
+ # scan_start, scan_stop, scan_for, scan_active?, scan_results) are
5
+ # implemented in the C extension.
6
+ #
7
+ # This Ruby file provides the namespace and any additional Ruby-level
8
+ # helper methods or functionality.
9
+ end
10
+ end