simplejsble 0.0.4 → 0.0.6

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 (273) hide show
  1. package/VERSION +1 -0
  2. package/android/CMakeLists.txt +62 -20
  3. package/cmake/epilogue.cmake +81 -0
  4. package/cmake/find/FindDBus1.cmake +20 -0
  5. package/cmake/find/Findfmt.cmake +41 -0
  6. package/cmake/find/Findgoogletest.cmake +18 -0
  7. package/cmake/parse_version.cmake +45 -0
  8. package/cmake/prelude.cmake +8 -0
  9. package/dependencies/README +4 -0
  10. package/dependencies/external/kvn/kvn_bytearray.h +297 -0
  11. package/dependencies/external/kvn/kvn_safe_callback.hpp +66 -0
  12. package/dependencies/external/kvn/logfwd.hpp +35 -0
  13. package/dependencies/internal/include/fmt/LICENSE +27 -0
  14. package/dependencies/internal/include/fmt/args.h +220 -0
  15. package/dependencies/internal/include/fmt/base.h +2962 -0
  16. package/dependencies/internal/include/fmt/chrono.h +2338 -0
  17. package/dependencies/internal/include/fmt/color.h +610 -0
  18. package/dependencies/internal/include/fmt/compile.h +539 -0
  19. package/dependencies/internal/include/fmt/core.h +5 -0
  20. package/dependencies/internal/include/fmt/format-inl.h +1949 -0
  21. package/dependencies/internal/include/fmt/format.h +4244 -0
  22. package/dependencies/internal/include/fmt/os.h +427 -0
  23. package/dependencies/internal/include/fmt/ostream.h +166 -0
  24. package/dependencies/internal/include/fmt/printf.h +633 -0
  25. package/dependencies/internal/include/fmt/ranges.h +850 -0
  26. package/dependencies/internal/include/fmt/std.h +726 -0
  27. package/dependencies/internal/include/fmt/xchar.h +373 -0
  28. package/dependencies/internal/include/nanopb/pb.h +948 -0
  29. package/dependencies/internal/include/nanopb/pb_common.h +49 -0
  30. package/dependencies/internal/include/nanopb/pb_decode.h +204 -0
  31. package/dependencies/internal/include/nanopb/pb_encode.h +195 -0
  32. package/dependencies/internal/include/simplejni/Common.hpp +598 -0
  33. package/dependencies/internal/include/simplejni/References.hpp +151 -0
  34. package/dependencies/internal/include/simplejni/Registry.hpp +249 -0
  35. package/dependencies/internal/include/simplejni/VM.hpp +93 -0
  36. package/dependencies/internal/src/nanopb/pb_common.c +388 -0
  37. package/dependencies/internal/src/nanopb/pb_decode.c +1763 -0
  38. package/dependencies/internal/src/nanopb/pb_encode.c +1009 -0
  39. package/dependencies/internal/src/simplejni/Common.cpp +4 -0
  40. package/package.json +5 -1
  41. package/simpleble/CMakeLists.txt +519 -0
  42. package/simpleble/cmake/simpleble.pc.in +11 -0
  43. package/simpleble/include/simpleble/Adapter.h +102 -0
  44. package/simpleble/include/simpleble/AdapterSafe.h +58 -0
  45. package/simpleble/include/simpleble/Advanced.h +50 -0
  46. package/simpleble/include/simpleble/Characteristic.h +39 -0
  47. package/simpleble/include/simpleble/Config.h +64 -0
  48. package/simpleble/include/simpleble/Descriptor.h +30 -0
  49. package/simpleble/include/simpleble/Exceptions.h +72 -0
  50. package/simpleble/include/simpleble/Logging.h +73 -0
  51. package/simpleble/include/simpleble/Peripheral.h +82 -0
  52. package/simpleble/include/simpleble/PeripheralSafe.h +64 -0
  53. package/simpleble/include/simpleble/Service.h +34 -0
  54. package/simpleble/include/simpleble/SimpleBLE.h +8 -0
  55. package/simpleble/include/simpleble/Types.h +49 -0
  56. package/simpleble/include/simpleble/Utils.h +13 -0
  57. package/simpleble/include/simpleble_c/DEPRECATED +2 -0
  58. package/simpleble/include/simpleble_c/adapter.h +188 -0
  59. package/simpleble/include/simpleble_c/logging.h +37 -0
  60. package/simpleble/include/simpleble_c/peripheral.h +304 -0
  61. package/simpleble/include/simpleble_c/simpleble.h +21 -0
  62. package/simpleble/include/simpleble_c/types.h +73 -0
  63. package/simpleble/include/simpleble_c/utils.h +27 -0
  64. package/simpleble/src/CommonUtils.h +63 -0
  65. package/simpleble/src/Config.cpp +25 -0
  66. package/simpleble/src/Exceptions.cpp +31 -0
  67. package/simpleble/src/Logging.cpp +136 -0
  68. package/simpleble/src/LoggingInternal.h +85 -0
  69. package/simpleble/src/Utils.cpp +24 -0
  70. package/simpleble/src/backends/android/AdapterAndroid.cpp +101 -0
  71. package/simpleble/src/backends/android/AdapterAndroid.h +67 -0
  72. package/simpleble/src/backends/android/BackendAndroid.cpp +41 -0
  73. package/simpleble/src/backends/android/BackendAndroid.h +26 -0
  74. package/simpleble/src/backends/android/PeripheralAndroid.cpp +365 -0
  75. package/simpleble/src/backends/android/PeripheralAndroid.h +90 -0
  76. package/simpleble/src/backends/android/bridge/BluetoothGattCallback.cpp +432 -0
  77. package/simpleble/src/backends/android/bridge/BluetoothGattCallback.h +102 -0
  78. package/simpleble/src/backends/android/bridge/ScanCallback.cpp +142 -0
  79. package/simpleble/src/backends/android/bridge/ScanCallback.h +55 -0
  80. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.cpp +107 -0
  81. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothAdapter.h +55 -0
  82. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.cpp +68 -0
  83. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothDevice.h +54 -0
  84. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.cpp +115 -0
  85. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGatt.h +75 -0
  86. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.cpp +142 -0
  87. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattCharacteristic.h +66 -0
  88. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.cpp +67 -0
  89. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattDescriptor.h +46 -0
  90. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.cpp +106 -0
  91. package/simpleble/src/backends/android/types/android/bluetooth/BluetoothGattService.h +47 -0
  92. package/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.cpp +47 -0
  93. package/simpleble/src/backends/android/types/android/bluetooth/le/BluetoothScanner.h +37 -0
  94. package/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.cpp +69 -0
  95. package/simpleble/src/backends/android/types/android/bluetooth/le/ScanRecord.h +41 -0
  96. package/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.cpp +63 -0
  97. package/simpleble/src/backends/android/types/android/bluetooth/le/ScanResult.h +42 -0
  98. package/simpleble/src/backends/android/types/android/os/ParcelUUID.cpp +32 -0
  99. package/simpleble/src/backends/android/types/android/os/ParcelUUID.h +30 -0
  100. package/simpleble/src/backends/android/types/android/util/SparseArray.cpp +54 -0
  101. package/simpleble/src/backends/android/types/android/util/SparseArray.h +37 -0
  102. package/simpleble/src/backends/android/types/java/util/Iterator.cpp +36 -0
  103. package/simpleble/src/backends/android/types/java/util/Iterator.h +28 -0
  104. package/simpleble/src/backends/android/types/java/util/List.cpp +29 -0
  105. package/simpleble/src/backends/android/types/java/util/List.h +27 -0
  106. package/simpleble/src/backends/android/types/java/util/Set.cpp +33 -0
  107. package/simpleble/src/backends/android/types/java/util/Set.h +28 -0
  108. package/simpleble/src/backends/android/types/java/util/UUID.cpp +26 -0
  109. package/simpleble/src/backends/android/types/java/util/UUID.h +29 -0
  110. package/simpleble/src/backends/common/AdapterBase.cpp +53 -0
  111. package/simpleble/src/backends/common/AdapterBase.h +81 -0
  112. package/simpleble/src/backends/common/AdapterBaseTypes.h +22 -0
  113. package/simpleble/src/backends/common/BackendBase.h +20 -0
  114. package/simpleble/src/backends/common/BackendUtils.h +33 -0
  115. package/simpleble/src/backends/common/CharacteristicBase.cpp +28 -0
  116. package/simpleble/src/backends/common/CharacteristicBase.h +38 -0
  117. package/simpleble/src/backends/common/DescriptorBase.cpp +7 -0
  118. package/simpleble/src/backends/common/DescriptorBase.h +19 -0
  119. package/simpleble/src/backends/common/PeripheralBase.h +82 -0
  120. package/simpleble/src/backends/common/ServiceBase.cpp +18 -0
  121. package/simpleble/src/backends/common/ServiceBase.h +28 -0
  122. package/simpleble/src/backends/dongl/AdapterBaseTypes.h +22 -0
  123. package/simpleble/src/backends/dongl/AdapterDongl.cpp +369 -0
  124. package/simpleble/src/backends/dongl/AdapterDongl.h +60 -0
  125. package/simpleble/src/backends/dongl/BackendDongl.cpp +35 -0
  126. package/simpleble/src/backends/dongl/PeripheralDongl.cpp +562 -0
  127. package/simpleble/src/backends/dongl/PeripheralDongl.h +136 -0
  128. package/simpleble/src/backends/dongl/protocol/basic.pb.c +33 -0
  129. package/simpleble/src/backends/dongl/protocol/basic.pb.h +172 -0
  130. package/simpleble/src/backends/dongl/protocol/d2h.pb.c +18 -0
  131. package/simpleble/src/backends/dongl/protocol/d2h.pb.h +118 -0
  132. package/simpleble/src/backends/dongl/protocol/h2d.pb.c +12 -0
  133. package/simpleble/src/backends/dongl/protocol/h2d.pb.h +69 -0
  134. package/simpleble/src/backends/dongl/protocol/simpleble.pb.c +123 -0
  135. package/simpleble/src/backends/dongl/protocol/simpleble.pb.h +908 -0
  136. package/simpleble/src/backends/dongl/protocol/softdevice.pb.c +18 -0
  137. package/simpleble/src/backends/dongl/protocol/softdevice.pb.h +815 -0
  138. package/simpleble/src/backends/dongl/protocol/softdevice_gap.pb.c +339 -0
  139. package/simpleble/src/backends/dongl/protocol/softdevice_gap.pb.h +2086 -0
  140. package/simpleble/src/backends/dongl/protocol/softdevice_gattc.pb.c +114 -0
  141. package/simpleble/src/backends/dongl/protocol/softdevice_gattc.pb.h +772 -0
  142. package/simpleble/src/backends/dongl/protocol/softdevice_gatts.pb.c +117 -0
  143. package/simpleble/src/backends/dongl/protocol/softdevice_gatts.pb.h +766 -0
  144. package/simpleble/src/backends/dongl/protocol/softdevice_types.pb.c +207 -0
  145. package/simpleble/src/backends/dongl/protocol/softdevice_types.pb.h +1686 -0
  146. package/simpleble/src/backends/dongl/serial/Protocol.cpp +887 -0
  147. package/simpleble/src/backends/dongl/serial/Protocol.h +117 -0
  148. package/simpleble/src/backends/dongl/serial/ProtocolBase.cpp +95 -0
  149. package/simpleble/src/backends/dongl/serial/ProtocolBase.h +54 -0
  150. package/simpleble/src/backends/dongl/serial/Wire.cpp +133 -0
  151. package/simpleble/src/backends/dongl/serial/Wire.h +116 -0
  152. package/simpleble/src/backends/dongl/usb/UsbHelper.cpp +53 -0
  153. package/simpleble/src/backends/dongl/usb/UsbHelper.h +32 -0
  154. package/simpleble/src/backends/dongl/usb/UsbHelperApple.cpp +266 -0
  155. package/simpleble/src/backends/dongl/usb/UsbHelperApple.h +34 -0
  156. package/simpleble/src/backends/dongl/usb/UsbHelperImpl.h +29 -0
  157. package/simpleble/src/backends/dongl/usb/UsbHelperLinux.cpp +21 -0
  158. package/simpleble/src/backends/dongl/usb/UsbHelperLinux.h +22 -0
  159. package/simpleble/src/backends/dongl/usb/UsbHelperNull.cpp +21 -0
  160. package/simpleble/src/backends/dongl/usb/UsbHelperNull.h +22 -0
  161. package/simpleble/src/backends/dongl/usb/UsbHelperWindows.cpp +21 -0
  162. package/simpleble/src/backends/dongl/usb/UsbHelperWindows.h +22 -0
  163. package/simpleble/src/backends/linux/AdapterLinux.cpp +102 -0
  164. package/simpleble/src/backends/linux/AdapterLinux.h +55 -0
  165. package/simpleble/src/backends/linux/BackendBluez.cpp +90 -0
  166. package/simpleble/src/backends/linux/PeripheralLinux.cpp +394 -0
  167. package/simpleble/src/backends/linux/PeripheralLinux.h +90 -0
  168. package/simpleble/src/backends/linux_legacy/AdapterLinuxLegacy.cpp +102 -0
  169. package/simpleble/src/backends/linux_legacy/AdapterLinuxLegacy.h +55 -0
  170. package/simpleble/src/backends/linux_legacy/BackendBluezLegacy.cpp +87 -0
  171. package/simpleble/src/backends/linux_legacy/PeripheralLinuxLegacy.cpp +376 -0
  172. package/simpleble/src/backends/linux_legacy/PeripheralLinuxLegacy.h +90 -0
  173. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Adapter.h +46 -0
  174. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Agent.h +52 -0
  175. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Bluez.h +37 -0
  176. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/BluezOrg.h +22 -0
  177. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/BluezOrgBluez.h +26 -0
  178. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/BluezRoot.h +32 -0
  179. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Characteristic.h +47 -0
  180. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Descriptor.h +33 -0
  181. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Device.h +64 -0
  182. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Exceptions.h +43 -0
  183. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Service.h +27 -0
  184. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/Types.h +9 -0
  185. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/Adapter1.h +49 -0
  186. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/Agent1.h +100 -0
  187. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/AgentManager1.h +24 -0
  188. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/Battery1.h +32 -0
  189. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/Device1.h +62 -0
  190. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/GattCharacteristic1.h +48 -0
  191. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/GattDescriptor1.h +41 -0
  192. package/simpleble/src/backends/linux_legacy/include/simplebluezlegacy/interfaces/GattService1.h +28 -0
  193. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/advanced/Interface.h +67 -0
  194. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/advanced/InterfaceRegistry.h +62 -0
  195. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/advanced/Proxy.h +117 -0
  196. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Connection.h +50 -0
  197. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Exceptions.h +56 -0
  198. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Holder.h +147 -0
  199. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Logging.h +57 -0
  200. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Message.h +89 -0
  201. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/base/Path.h +24 -0
  202. package/simpleble/src/backends/linux_legacy/include/simpledbuslegacy/interfaces/ObjectManager.h +26 -0
  203. package/simpleble/src/backends/linux_legacy/src/Adapter.cpp +78 -0
  204. package/simpleble/src/backends/linux_legacy/src/Agent.cpp +72 -0
  205. package/simpleble/src/backends/linux_legacy/src/Bluez.cpp +45 -0
  206. package/simpleble/src/backends/linux_legacy/src/BluezOrg.cpp +20 -0
  207. package/simpleble/src/backends/linux_legacy/src/BluezOrgBluez.cpp +23 -0
  208. package/simpleble/src/backends/linux_legacy/src/BluezRoot.cpp +44 -0
  209. package/simpleble/src/backends/linux_legacy/src/Characteristic.cpp +64 -0
  210. package/simpleble/src/backends/linux_legacy/src/Descriptor.cpp +27 -0
  211. package/simpleble/src/backends/linux_legacy/src/Device.cpp +104 -0
  212. package/simpleble/src/backends/linux_legacy/src/Exceptions.cpp +29 -0
  213. package/simpleble/src/backends/linux_legacy/src/Service.cpp +33 -0
  214. package/simpleble/src/backends/linux_legacy/src/advanced/Interface.cpp +155 -0
  215. package/simpleble/src/backends/linux_legacy/src/advanced/Proxy.cpp +374 -0
  216. package/simpleble/src/backends/linux_legacy/src/base/Connection.cpp +219 -0
  217. package/simpleble/src/backends/linux_legacy/src/base/Exceptions.cpp +39 -0
  218. package/simpleble/src/backends/linux_legacy/src/base/Holder.cpp +739 -0
  219. package/simpleble/src/backends/linux_legacy/src/base/Message.cpp +622 -0
  220. package/simpleble/src/backends/linux_legacy/src/base/Path.cpp +129 -0
  221. package/simpleble/src/backends/linux_legacy/src/interfaces/Adapter1.cpp +123 -0
  222. package/simpleble/src/backends/linux_legacy/src/interfaces/Agent1.cpp +143 -0
  223. package/simpleble/src/backends/linux_legacy/src/interfaces/AgentManager1.cpp +34 -0
  224. package/simpleble/src/backends/linux_legacy/src/interfaces/Battery1.cpp +30 -0
  225. package/simpleble/src/backends/linux_legacy/src/interfaces/Device1.cpp +170 -0
  226. package/simpleble/src/backends/linux_legacy/src/interfaces/GattCharacteristic1.cpp +118 -0
  227. package/simpleble/src/backends/linux_legacy/src/interfaces/GattDescriptor1.cpp +78 -0
  228. package/simpleble/src/backends/linux_legacy/src/interfaces/GattService1.cpp +28 -0
  229. package/simpleble/src/backends/linux_legacy/src/interfaces/ObjectManager.cpp +58 -0
  230. package/simpleble/src/backends/macos/AdapterBaseMacOS.h +29 -0
  231. package/simpleble/src/backends/macos/AdapterBaseMacOS.mm +235 -0
  232. package/simpleble/src/backends/macos/AdapterMac.h +78 -0
  233. package/simpleble/src/backends/macos/AdapterMac.mm +156 -0
  234. package/simpleble/src/backends/macos/BackendCoreBluetooth.mm +45 -0
  235. package/simpleble/src/backends/macos/PeripheralBaseMacOS.h +49 -0
  236. package/simpleble/src/backends/macos/PeripheralBaseMacOS.mm +714 -0
  237. package/simpleble/src/backends/macos/PeripheralMac.h +81 -0
  238. package/simpleble/src/backends/macos/PeripheralMac.mm +229 -0
  239. package/simpleble/src/backends/macos/Utils.h +9 -0
  240. package/simpleble/src/backends/macos/Utils.mm +23 -0
  241. package/simpleble/src/backends/plain/AdapterPlain.cpp +65 -0
  242. package/simpleble/src/backends/plain/AdapterPlain.h +49 -0
  243. package/simpleble/src/backends/plain/BackendPlain.cpp +30 -0
  244. package/simpleble/src/backends/plain/PeripheralPlain.cpp +159 -0
  245. package/simpleble/src/backends/plain/PeripheralPlain.h +72 -0
  246. package/simpleble/src/backends/windows/AdapterWindows.cpp +338 -0
  247. package/simpleble/src/backends/windows/AdapterWindows.h +89 -0
  248. package/simpleble/src/backends/windows/BackendWinRT.cpp +67 -0
  249. package/simpleble/src/backends/windows/BackendWinRT.h +18 -0
  250. package/simpleble/src/backends/windows/MtaManager.cpp +49 -0
  251. package/simpleble/src/backends/windows/MtaManager.h +90 -0
  252. package/simpleble/src/backends/windows/PeripheralWindows.cpp +487 -0
  253. package/simpleble/src/backends/windows/PeripheralWindows.h +129 -0
  254. package/simpleble/src/backends/windows/Utils.cpp +146 -0
  255. package/simpleble/src/backends/windows/Utils.h +47 -0
  256. package/simpleble/src/builders/BuildVec.h +32 -0
  257. package/simpleble/src/builders/BuilderBase.h +87 -0
  258. package/simpleble/src/external/TaskRunner.hpp +99 -0
  259. package/simpleble/src/external/ThreadRunner.h +52 -0
  260. package/simpleble/src/external/kvn_safe_callback.hpp +66 -0
  261. package/simpleble/src/external/kvn_safe_map.hpp +94 -0
  262. package/simpleble/src/external/kvn_threadrunner.hpp +70 -0
  263. package/simpleble/src/external/logfwd.hpp +35 -0
  264. package/simpleble/src/frontends/base/Adapter.cpp +111 -0
  265. package/simpleble/src/frontends/base/Advanced.cpp +34 -0
  266. package/simpleble/src/frontends/base/Backend.cpp +95 -0
  267. package/simpleble/src/frontends/base/Backend.h +76 -0
  268. package/simpleble/src/frontends/base/Characteristic.cpp +56 -0
  269. package/simpleble/src/frontends/base/Descriptor.cpp +21 -0
  270. package/simpleble/src/frontends/base/Peripheral.cpp +113 -0
  271. package/simpleble/src/frontends/base/Service.cpp +26 -0
  272. package/simpleble/src/frontends/safe/AdapterSafe.cpp +158 -0
  273. package/simpleble/src/frontends/safe/PeripheralSafe.cpp +219 -0
@@ -0,0 +1,266 @@
1
+ #include "UsbHelperApple.h"
2
+
3
+ #include <CoreFoundation/CoreFoundation.h>
4
+ #include <IOKit/IOKitLib.h>
5
+ #include <IOKit/IOReturn.h>
6
+ #include <IOKit/serial/IOSerialKeys.h>
7
+ #include <IOKit/usb/IOUSBLib.h>
8
+ #include <IOKit/serial/ioss.h>
9
+
10
+ #include <fcntl.h>
11
+ #include <sys/ioctl.h>
12
+ #include <sys/select.h>
13
+ #include <termios.h>
14
+ #include <unistd.h>
15
+ #include <cerrno>
16
+ #include <cstring>
17
+ #include <iostream>
18
+ #include <memory>
19
+ #include <string>
20
+ #include <vector>
21
+
22
+ #include <fmt/core.h>
23
+
24
+ namespace SimpleBLE {
25
+ namespace Dongl {
26
+ namespace USB {
27
+
28
+ template <typename T, typename Deleter>
29
+ class ScopedResource {
30
+ public:
31
+ ScopedResource(T resource = nullptr) : resource_(resource) {}
32
+ ~ScopedResource() {
33
+ if (resource_) deleter_(resource_);
34
+ }
35
+
36
+ T get() const { return resource_; }
37
+ T operator->() const { return resource_; }
38
+ operator bool() const { return resource_ != nullptr; }
39
+
40
+ private:
41
+ T resource_;
42
+ Deleter deleter_;
43
+ };
44
+
45
+ struct CFReleaser {
46
+ void operator()(CFTypeRef obj) const { CFRelease(obj); }
47
+ };
48
+
49
+ struct IOReleaser {
50
+ void operator()(io_object_t obj) const { IOObjectRelease(obj); }
51
+ };
52
+
53
+ using ScopedCFRef = ScopedResource<CFTypeRef, CFReleaser>;
54
+ using ScopedIOObject = ScopedResource<io_object_t, IOReleaser>;
55
+
56
+ UsbHelperApple::UsbHelperApple(const std::string& device_path) : UsbHelperImpl(device_path) {
57
+ // Open and configure the serial port
58
+ if (!_open_serial_port()) {
59
+ throw std::runtime_error("Failed to open serial port: " + _device_path);
60
+ }
61
+
62
+ _running = true;
63
+ _thread = std::thread(&UsbHelperApple::_run, this);
64
+ }
65
+
66
+ UsbHelperApple::~UsbHelperApple() {
67
+ _running = false;
68
+ if (_thread.joinable()) {
69
+ _thread.join();
70
+ }
71
+ _close_serial_port();
72
+ }
73
+
74
+ void UsbHelperApple::tx(const kvn::bytearray& data) {
75
+ const ssize_t written = write(_serial_fd, data.data(), data.size());
76
+ if (written != data.size()) {
77
+ throw std::runtime_error("Failed to write to serial port: " + std::string(strerror(errno)));
78
+ }
79
+ }
80
+
81
+ void UsbHelperApple::set_rx_callback(std::function<void(const kvn::bytearray&)> callback) {
82
+ _rx_callback.load(callback);
83
+ }
84
+
85
+ std::vector<std::string> UsbHelperApple::get_dongl_devices() {
86
+ std::vector<std::string> dongle_devices;
87
+
88
+ io_iterator_t raw_iterator = 0;
89
+ if (IOServiceGetMatchingServices(kIOMainPortDefault, IOServiceMatching(kIOSerialBSDServiceValue), &raw_iterator) !=
90
+ kIOReturnSuccess) {
91
+ return {};
92
+ }
93
+ ScopedIOObject iterator(raw_iterator);
94
+
95
+ io_service_t raw_service;
96
+ while ((raw_service = IOIteratorNext(iterator.get()))) {
97
+ ScopedIOObject service_guard(raw_service);
98
+
99
+ // Get the callout device raw_path (/dev/cu.*)
100
+ char raw_path[PATH_MAX];
101
+ ScopedCFRef pathCF((CFStringRef)IORegistryEntryCreateCFProperty(raw_service, CFSTR(kIOCalloutDeviceKey),
102
+ kCFAllocatorDefault, 0));
103
+ if (!pathCF) {
104
+ continue;
105
+ }
106
+
107
+ if (!CFStringGetCString((CFStringRef)pathCF.get(), raw_path, sizeof(raw_path), kCFStringEncodingUTF8)) {
108
+ continue;
109
+ }
110
+
111
+ std::string path(raw_path);
112
+
113
+ //fmt::print("Checking device path: {}\n", path);
114
+
115
+ // Search up parents for idVendor and idProduct
116
+ ScopedCFRef vidCF((CFNumberRef)IORegistryEntrySearchCFProperty(
117
+ raw_service, kIOServicePlane, CFSTR(kUSBVendorID), kCFAllocatorDefault,
118
+ kIORegistryIterateParents | kIORegistryIterateRecursively));
119
+ ScopedCFRef pidCF((CFNumberRef)IORegistryEntrySearchCFProperty(
120
+ raw_service, kIOServicePlane, CFSTR(kUSBProductID), kCFAllocatorDefault,
121
+ kIORegistryIterateParents | kIORegistryIterateRecursively));
122
+
123
+ if (!vidCF || !pidCF) {
124
+ continue;
125
+ }
126
+
127
+ uint16_t vid, pid;
128
+ CFNumberGetValue((CFNumberRef)vidCF.get(), kCFNumberSInt16Type, &vid);
129
+ CFNumberGetValue((CFNumberRef)pidCF.get(), kCFNumberSInt16Type, &pid);
130
+
131
+ //fmt::print("VID/PID: 0x{:x}/0x{:x}\n", vid, pid);
132
+
133
+ if (vid == UsbHelperImpl::DONGL_VENDOR_ID && pid == UsbHelperImpl::DONGL_PRODUCT_ID) {
134
+ dongle_devices.push_back(path);
135
+ }
136
+ }
137
+ return dongle_devices;
138
+ }
139
+
140
+ bool UsbHelperApple::_open_serial_port() {
141
+ // Open the serial port in non-blocking mode
142
+ _serial_fd = open(_device_path.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
143
+ if (_serial_fd < 0) {
144
+ std::cerr << "Failed to open serial port " << _device_path << ": " << strerror(errno) << std::endl;
145
+ return false;
146
+ }
147
+
148
+ // Configure the serial port
149
+ _configure_serial_port();
150
+
151
+ //std::cout << "Successfully opened serial port: " << _device_path << std::endl;
152
+ return true;
153
+ }
154
+
155
+ void UsbHelperApple::_configure_serial_port() {
156
+ struct termios tty;
157
+
158
+ // Get current serial port settings
159
+ if (tcgetattr(_serial_fd, &tty) != 0) {
160
+ throw std::runtime_error("Failed to get serial port attributes: " + std::string(strerror(errno)));
161
+ }
162
+
163
+ // Configure serial port settings
164
+ tty.c_cflag &= ~PARENB; // No parity bit
165
+ tty.c_cflag &= ~CSTOPB; // One stop bit
166
+ tty.c_cflag &= ~CSIZE; // Clear data size bits
167
+ tty.c_cflag |= CS8; // 8 data bits
168
+ tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
169
+ tty.c_cflag |= CREAD | CLOCAL; // Enable receiver, ignore modem control lines
170
+
171
+ tty.c_lflag &= ~ICANON; // Disable canonical mode
172
+ tty.c_lflag &= ~ECHO; // Disable echo
173
+ tty.c_lflag &= ~ECHOE; // Disable erasure echo
174
+ tty.c_lflag &= ~ECHONL; // Disable new-line echo
175
+ tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
176
+
177
+ tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Disable software flow control
178
+ tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL); // Disable special handling
179
+
180
+ tty.c_oflag &= ~OPOST; // Disable output processing
181
+ tty.c_oflag &= ~ONLCR; // Disable conversion of newline to carriage return/line feed
182
+
183
+ // Set minimum characters to read and timeout
184
+ tty.c_cc[VMIN] = 0; // Read doesn't block
185
+ tty.c_cc[VTIME] = 0; // 0.0 seconds read timeout
186
+
187
+ // Apply the settings
188
+ if (tcsetattr(_serial_fd, TCSANOW, &tty) != 0) {
189
+ throw std::runtime_error("Failed to set serial port attributes: " + std::string(strerror(errno)));
190
+ }
191
+
192
+ speed_t speed = 1000000; // Set 1 Mbps
193
+ if (ioctl(_serial_fd, IOSSIOSPEED, &speed) == -1) {
194
+ throw std::runtime_error("Failed to set serial port speed: " + std::string(strerror(errno)));
195
+ }
196
+
197
+ // Flush any existing data
198
+ tcflush(_serial_fd, TCIOFLUSH);
199
+ }
200
+
201
+ void UsbHelperApple::_close_serial_port() {
202
+ if (_serial_fd >= 0) {
203
+ close(_serial_fd);
204
+ _serial_fd = -1;
205
+ //std::cout << "Closed serial port: " << _device_path << std::endl;
206
+ }
207
+ }
208
+
209
+ void UsbHelperApple::_run() {
210
+ const size_t BUFFER_SIZE = 256;
211
+ char buffer[BUFFER_SIZE];
212
+
213
+ fd_set read_fds;
214
+ struct timeval timeout;
215
+
216
+ //std::cout << "UsbHelperApple: _run() started with non-blocking reads" << std::endl;
217
+
218
+ while (_running) {
219
+ // Clear the file descriptor set
220
+ FD_ZERO(&read_fds);
221
+ FD_SET(_serial_fd, &read_fds);
222
+
223
+ // Set timeout for select (100ms)
224
+ timeout.tv_sec = 0;
225
+ timeout.tv_usec = 100000; // 100ms
226
+
227
+ // Wait for data to be available (non-blocking)
228
+ int ready = select(_serial_fd + 1, &read_fds, nullptr, nullptr, &timeout);
229
+
230
+ if (ready > 0) {
231
+ // Data is available to read
232
+ if (FD_ISSET(_serial_fd, &read_fds)) {
233
+ ssize_t bytes_read = read(_serial_fd, buffer, BUFFER_SIZE - 1);
234
+
235
+ if (bytes_read > 0) {
236
+ kvn::bytearray data(buffer, bytes_read);
237
+ _rx_callback(data);
238
+ } else if (bytes_read == 0) {
239
+ // End of file (device disconnected)
240
+ std::cerr << "Serial port disconnected" << std::endl;
241
+ break;
242
+ } else {
243
+ // Error reading from serial port
244
+ if (errno != EAGAIN && errno != EWOULDBLOCK) {
245
+ std::cerr << "Error reading from serial port: " << strerror(errno) << std::endl;
246
+ break;
247
+ }
248
+ }
249
+ }
250
+ } else if (ready == 0) {
251
+ // Timeout - no data available, continue loop
252
+ continue;
253
+ } else {
254
+ // Error in select
255
+ if (errno != EINTR) {
256
+ std::cerr << "Error in select: " << strerror(errno) << std::endl;
257
+ break;
258
+ }
259
+ }
260
+ }
261
+ }
262
+
263
+
264
+ } // namespace USB
265
+ } // namespace Dongl
266
+ } // namespace SimpleBLE
@@ -0,0 +1,34 @@
1
+ #pragma once
2
+
3
+ #include "UsbHelperImpl.h"
4
+ #include <thread>
5
+ #include <atomic>
6
+
7
+ namespace SimpleBLE {
8
+ namespace Dongl {
9
+ namespace USB {
10
+
11
+ class UsbHelperApple : public UsbHelperImpl {
12
+ public:
13
+ UsbHelperApple(const std::string& device_path);
14
+ ~UsbHelperApple();
15
+
16
+ void tx(const kvn::bytearray& data);
17
+ void set_rx_callback(std::function<void(const kvn::bytearray&)> callback);
18
+
19
+ static std::vector<std::string> get_dongl_devices();
20
+
21
+ private:
22
+ void _run();
23
+ std::atomic_bool _running;
24
+ std::thread _thread;
25
+
26
+ int _serial_fd;
27
+ bool _open_serial_port();
28
+ void _close_serial_port();
29
+ void _configure_serial_port();
30
+ };
31
+
32
+ } // namespace USB
33
+ } // namespace Dongl
34
+ } // namespace SimpleBLE
@@ -0,0 +1,29 @@
1
+ #pragma once
2
+
3
+ #include <kvn/kvn_bytearray.h>
4
+ #include <kvn/kvn_safe_callback.hpp>
5
+ #include <string>
6
+
7
+ namespace SimpleBLE {
8
+ namespace Dongl {
9
+ namespace USB {
10
+
11
+ class UsbHelperImpl {
12
+ public:
13
+ UsbHelperImpl(const std::string& device_path) : _device_path(device_path) {}
14
+ virtual ~UsbHelperImpl() = default;
15
+
16
+ virtual void tx(const kvn::bytearray& data) = 0;
17
+ virtual void set_rx_callback(std::function<void(const kvn::bytearray&)> callback) = 0;
18
+
19
+ static const uint16_t DONGL_VENDOR_ID = 0x9999; // 0x0403 for legacy dongles
20
+ static const uint16_t DONGL_PRODUCT_ID = 0x0001; // 0x6001 for legacy dongles
21
+
22
+ protected:
23
+ std::string _device_path;
24
+ kvn::safe_callback<void(const kvn::bytearray&)> _rx_callback;
25
+ };
26
+
27
+ } // namespace USB
28
+ } // namespace Dongl
29
+ } // namespace SimpleBLE
@@ -0,0 +1,21 @@
1
+ #include "UsbHelperLinux.h"
2
+
3
+ namespace SimpleBLE {
4
+ namespace Dongl {
5
+ namespace USB {
6
+
7
+ UsbHelperLinux::UsbHelperLinux(const std::string& device_path) : UsbHelperImpl(device_path) {}
8
+
9
+ UsbHelperLinux::~UsbHelperLinux() = default;
10
+
11
+ void UsbHelperLinux::tx(const kvn::bytearray& data) {}
12
+
13
+ void UsbHelperLinux::set_rx_callback(std::function<void(const kvn::bytearray&)> callback) {
14
+ _rx_callback.load(callback);
15
+ }
16
+
17
+ std::vector<std::string> UsbHelperLinux::get_dongl_devices() { return {}; }
18
+
19
+ } // namespace USB
20
+ } // namespace Dongl
21
+ } // namespace SimpleBLE
@@ -0,0 +1,22 @@
1
+ #pragma once
2
+
3
+ #include "UsbHelperImpl.h"
4
+
5
+ namespace SimpleBLE {
6
+ namespace Dongl {
7
+ namespace USB {
8
+
9
+ class UsbHelperLinux : public UsbHelperImpl {
10
+ public:
11
+ UsbHelperLinux(const std::string& device_path);
12
+ ~UsbHelperLinux();
13
+
14
+ void tx(const kvn::bytearray& data);
15
+ void set_rx_callback(std::function<void(const kvn::bytearray&)> callback);
16
+
17
+ static std::vector<std::string> get_dongl_devices();
18
+ };
19
+
20
+ } // namespace USB
21
+ } // namespace Dongl
22
+ } // namespace SimpleBLE
@@ -0,0 +1,21 @@
1
+ #include "UsbHelperNull.h"
2
+
3
+ namespace SimpleBLE {
4
+ namespace Dongl {
5
+ namespace USB {
6
+
7
+ UsbHelperNull::UsbHelperNull(const std::string& device_path) : UsbHelperImpl(device_path) {}
8
+
9
+ UsbHelperNull::~UsbHelperNull() = default;
10
+
11
+ void UsbHelperNull::tx(const kvn::bytearray& data) {}
12
+
13
+ void UsbHelperNull::set_rx_callback(std::function<void(const kvn::bytearray&)> callback) {
14
+ _rx_callback.load(callback);
15
+ }
16
+
17
+ std::vector<std::string> UsbHelperNull::get_dongl_devices() { return {}; }
18
+
19
+ } // namespace USB
20
+ } // namespace Dongl
21
+ } // namespace SimpleBLE
@@ -0,0 +1,22 @@
1
+ #pragma once
2
+
3
+ #include "UsbHelperImpl.h"
4
+
5
+ namespace SimpleBLE {
6
+ namespace Dongl {
7
+ namespace USB {
8
+
9
+ class UsbHelperNull : public UsbHelperImpl {
10
+ public:
11
+ UsbHelperNull(const std::string& device_path);
12
+ ~UsbHelperNull();
13
+
14
+ void tx(const kvn::bytearray& data);
15
+ void set_rx_callback(std::function<void(const kvn::bytearray&)> callback);
16
+
17
+ static std::vector<std::string> get_dongl_devices();
18
+ };
19
+
20
+ } // namespace USB
21
+ } // namespace Dongl
22
+ } // namespace SimpleBLE
@@ -0,0 +1,21 @@
1
+ #include "UsbHelperWindows.h"
2
+
3
+ namespace SimpleBLE {
4
+ namespace Dongl {
5
+ namespace USB {
6
+
7
+ UsbHelperWindows::UsbHelperWindows(const std::string& device_path) : UsbHelperImpl(device_path) {}
8
+
9
+ UsbHelperWindows::~UsbHelperWindows() = default;
10
+
11
+ void UsbHelperWindows::tx(const kvn::bytearray& data) {}
12
+
13
+ void UsbHelperWindows::set_rx_callback(std::function<void(const kvn::bytearray&)> callback) {
14
+ _rx_callback.load(callback);
15
+ }
16
+
17
+ std::vector<std::string> UsbHelperWindows::get_dongl_devices() { return {}; }
18
+
19
+ } // namespace USB
20
+ } // namespace Dongl
21
+ } // namespace SimpleBLE
@@ -0,0 +1,22 @@
1
+ #pragma once
2
+
3
+ #include "UsbHelperImpl.h"
4
+
5
+ namespace SimpleBLE {
6
+ namespace Dongl {
7
+ namespace USB {
8
+
9
+ class UsbHelperWindows : public UsbHelperImpl {
10
+ public:
11
+ UsbHelperWindows(const std::string& device_path);
12
+ ~UsbHelperWindows();
13
+
14
+ void tx(const kvn::bytearray& data);
15
+ void set_rx_callback(std::function<void(const kvn::bytearray&)> callback);
16
+
17
+ static std::vector<std::string> get_dongl_devices();
18
+ };
19
+
20
+ } // namespace USB
21
+ } // namespace Dongl
22
+ } // namespace SimpleBLE
@@ -0,0 +1,102 @@
1
+ #include <thread>
2
+
3
+ #include <simpleble/Peripheral.h>
4
+
5
+ #include "AdapterLinux.h"
6
+ #include "BuildVec.h"
7
+ #include "BuilderBase.h"
8
+ #include "CommonUtils.h"
9
+ #include "PeripheralLinux.h"
10
+
11
+ using namespace SimpleBLE;
12
+
13
+ bool AdapterLinux::bluetooth_enabled() { return adapter_->powered(); }
14
+
15
+ AdapterLinux::AdapterLinux(std::shared_ptr<SimpleBluez::Adapter> adapter) : adapter_(adapter) {}
16
+
17
+ AdapterLinux::~AdapterLinux() { adapter_->clear_on_device_updated(); }
18
+
19
+ void* AdapterLinux::underlying() const { return adapter_.get(); }
20
+
21
+ std::string AdapterLinux::identifier() { return adapter_->identifier(); }
22
+
23
+ BluetoothAddress AdapterLinux::address() { return adapter_->address(); }
24
+
25
+ void AdapterLinux::power_on() {
26
+ // TODO: This will be implemented after SimpleDBus and SimpleBluez are updated to the new architecture.
27
+ }
28
+
29
+ void AdapterLinux::power_off() {
30
+ // TODO: This will be implemented after SimpleDBus and SimpleBluez are updated to the new architecture.
31
+ }
32
+
33
+ bool AdapterLinux::is_powered() {
34
+ return adapter_->powered();
35
+ }
36
+
37
+ void AdapterLinux::scan_start() {
38
+ seen_peripherals_.clear();
39
+
40
+ adapter_->set_on_device_updated([this](std::shared_ptr<SimpleBluez::Device> device) {
41
+ if (!this->is_scanning_) {
42
+ return;
43
+ }
44
+
45
+ if (this->peripherals_.count(device->address()) == 0) {
46
+ // If the incoming peripheral has never been seen before, create and save a reference to it.
47
+ auto base_peripheral = std::make_shared<PeripheralLinux>(device, this->adapter_);
48
+ this->peripherals_.insert(std::make_pair(device->address(), base_peripheral));
49
+ }
50
+
51
+ // Update the received advertising data.
52
+ auto peripheral = this->peripherals_.at(device->address());
53
+
54
+ // Check if the device has been seen before, to forward the correct call to the user.
55
+ if (this->seen_peripherals_.count(device->address()) == 0) {
56
+ // Store it in our table of seen peripherals
57
+ this->seen_peripherals_.insert(std::make_pair(device->address(), peripheral));
58
+ SAFE_CALLBACK_CALL(this->_callback_on_scan_found, Factory::build(peripheral));
59
+ } else {
60
+ SAFE_CALLBACK_CALL(this->_callback_on_scan_updated, Factory::build(peripheral));
61
+ }
62
+ });
63
+
64
+ // Start scanning and notify the user.
65
+ adapter_->discovery_start();
66
+
67
+ // TODO: Does a discovery filter need to be set?
68
+
69
+ SAFE_CALLBACK_CALL(this->_callback_on_scan_start);
70
+ is_scanning_ = true;
71
+ }
72
+
73
+ void AdapterLinux::scan_stop() {
74
+ adapter_->discovery_stop();
75
+ is_scanning_ = false;
76
+ SAFE_CALLBACK_CALL(this->_callback_on_scan_stop);
77
+
78
+ // Important: Bluez might continue scanning if another process is also requesting
79
+ // scanning from the adapter. The use of the is_scanning_ flag is to prevent
80
+ // any scan updates to reach the user when not expected.
81
+ }
82
+
83
+ void AdapterLinux::scan_for(int timeout_ms) {
84
+ scan_start();
85
+ std::this_thread::sleep_for(std::chrono::milliseconds(timeout_ms));
86
+ scan_stop();
87
+ }
88
+
89
+ bool AdapterLinux::scan_is_active() { return is_scanning_ && adapter_->discovering(); }
90
+
91
+ SharedPtrVector<PeripheralBase> AdapterLinux::scan_get_results() { return Util::values(seen_peripherals_); }
92
+
93
+ SharedPtrVector<PeripheralBase> AdapterLinux::get_paired_peripherals() {
94
+ SharedPtrVector<PeripheralBase> peripherals;
95
+
96
+ auto paired_list = adapter_->device_paired_get();
97
+ for (auto& device : paired_list) {
98
+ peripherals.push_back(std::make_shared<PeripheralLinux>(device, this->adapter_));
99
+ }
100
+
101
+ return peripherals;
102
+ }
@@ -0,0 +1,55 @@
1
+ #pragma once
2
+
3
+ #include <simpleble/Exceptions.h>
4
+ #include <simpleble/Types.h>
5
+
6
+ #include "../common/AdapterBase.h"
7
+
8
+ #include <kvn_safe_callback.hpp>
9
+
10
+ #include <simplebluez/Adapter.h>
11
+
12
+ #include <atomic>
13
+ #include <functional>
14
+ #include <memory>
15
+ #include <string>
16
+ #include <vector>
17
+
18
+ namespace SimpleBLE {
19
+
20
+ class PeripheralLinux;
21
+
22
+ class AdapterLinux : public SimpleBLE::AdapterBase {
23
+ public:
24
+ AdapterLinux(std::shared_ptr<SimpleBluez::Adapter> adapter);
25
+ virtual ~AdapterLinux();
26
+
27
+ void* underlying() const override;
28
+
29
+ virtual std::string identifier() override;
30
+ virtual BluetoothAddress address() override;
31
+
32
+ virtual void power_on() override;
33
+ virtual void power_off() override;
34
+ virtual bool is_powered() override;
35
+
36
+ virtual void scan_start() override;
37
+ virtual void scan_stop() override;
38
+ virtual void scan_for(int timeout_ms) override;
39
+ virtual bool scan_is_active() override;
40
+ virtual std::vector<std::shared_ptr<PeripheralBase>> scan_get_results() override;
41
+
42
+ virtual std::vector<std::shared_ptr<PeripheralBase>> get_paired_peripherals() override;
43
+
44
+ virtual bool bluetooth_enabled() override;
45
+
46
+ private:
47
+ std::shared_ptr<SimpleBluez::Adapter> adapter_;
48
+
49
+ std::atomic_bool is_scanning_;
50
+
51
+ std::map<BluetoothAddress, std::shared_ptr<PeripheralLinux>> peripherals_;
52
+ std::map<BluetoothAddress, std::shared_ptr<PeripheralLinux>> seen_peripherals_;
53
+ };
54
+
55
+ } // namespace SimpleBLE