@stoprocent/bleno 0.8.5 → 0.9.0

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 (39) hide show
  1. package/README.md +197 -30
  2. package/examples/echo/async.js +47 -0
  3. package/examples/echo/characteristic.js +15 -17
  4. package/examples/echo/main.js +19 -1
  5. package/examples/uart/main.js +3 -2
  6. package/examples/with-bindings/main.js +35 -0
  7. package/index.d.ts +166 -121
  8. package/index.js +5 -1
  9. package/lib/bleno.js +108 -17
  10. package/lib/characteristic.js +27 -10
  11. package/lib/hci-socket/acl-stream.js +3 -3
  12. package/lib/hci-socket/bindings.js +36 -29
  13. package/lib/hci-socket/gatt.js +177 -105
  14. package/lib/hci-socket/hci.js +5 -3
  15. package/lib/hci-socket/mgmt.js +1 -1
  16. package/lib/hci-socket/smp.js +5 -4
  17. package/lib/mac/src/ble_peripheral_manager.h +3 -7
  18. package/lib/mac/src/ble_peripheral_manager.mm +117 -162
  19. package/lib/mac/src/bleno_mac.h +0 -1
  20. package/lib/mac/src/bleno_mac.mm +21 -33
  21. package/lib/mac/src/callbacks.h +12 -48
  22. package/lib/mac/src/callbacks.mm +34 -45
  23. package/lib/mac/src/napi_objc.mm +9 -30
  24. package/lib/mac/src/objc_cpp.h +2 -2
  25. package/lib/mac/src/objc_cpp.mm +3 -37
  26. package/lib/resolve-bindings.js +27 -6
  27. package/package.json +7 -9
  28. package/prebuilds/darwin-x64+arm64/@stoprocent+bleno.node +0 -0
  29. package/prebuilds/win32-ia32/@stoprocent+bleno.node +0 -0
  30. package/prebuilds/win32-x64/@stoprocent+bleno.node +0 -0
  31. package/test/characteristic.test.js +158 -11
  32. package/examples/battery-service/README.md +0 -14
  33. package/examples/blink1/README.md +0 -44
  34. package/examples/pizza/README.md +0 -16
  35. package/lib/mac/src/noble_mac.h +0 -34
  36. package/lib/mac/src/noble_mac.mm +0 -267
  37. package/lib/mac/src/peripheral.h +0 -23
  38. package/with-bindings.js +0 -5
  39. package/with-custom-binding.js +0 -6
@@ -1,44 +0,0 @@
1
- bleno - [blink(1)](http://thingm.com/products/blink-1/) example
2
- ===============================================
3
- This example allows you to control a [ThingM](http://thingm.com/) [blink(1)](http://thingm.com/products/blink-1/) via BLE.
4
-
5
- It uses bleno and [node-blink1](https://github.com/sandeepmistry/node-blink1) and requires a blink(1) to be connected via USB.
6
-
7
- See [main file](https://github.com/sandeepmistry/bleno/blob/master/examples/blink1/main.js) for entry point.
8
-
9
- [Device Information service](https://github.com/sandeepmistry/bleno/blob/master/examples/blink1/device-information-service.js)
10
- -----------------------------------
11
-
12
- UUID: [0x180A](https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.device_information.xml)
13
-
14
- __Characteristics:__
15
-
16
- * [Serial Number](https://github.com/sandeepmistry/bleno/blob/master/examples/blink1/serial-number-characteristic.js)
17
- * UUID: [0x2a25](https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.serial_number_string.xml)
18
- * Properties: read
19
- * Description: read the blink(1)'s serial number
20
-
21
- * [Hardware Revision](https://github.com/sandeepmistry/bleno/blob/master/examples/blink1/hardware-revision-characteristic.js)
22
- * UUID: [0x2a27](https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.hardware_revision_string.xml)
23
- * Properties: read
24
- * Description: read the blink(1)'s version
25
-
26
- blink(1) service
27
- --------------------
28
- UUID: 0x01010101010101010101010101010101
29
-
30
- __Characteristics:__
31
-
32
- * [RGB](https://github.com/sandeepmistry/bleno/blob/master/examples/blink1/blink1-rgb-characteristic.js)
33
- * UUID: 01010101010101010101010101524742
34
- * Properties: write, write without response
35
- * Description: Set the blink(1)'s color
36
- * Data format is: RRGGBB (3 bytes) - single byte for each color
37
-
38
- * [Fade RGB](https://github.com/sandeepmistry/bleno/blob/master/examples/blink1/blink1-fade-rgb-characteristic.js)
39
- * UUID: 01010101010101010166616465524742
40
- * Properties: write, write without response, notify
41
- * Description: Fade the blink(1)'s color and notication when fade is complete
42
- * Data format is: TTTTRRGGBB (5 bytes)
43
- * TTTT - fade time in milliseconds (Little Endian)
44
- * RRGGBB (3 bytes) - single byte for each color
@@ -1,16 +0,0 @@
1
- # BLE Pizza Service
2
-
3
- This is an example program demonstrating BLE connectivity between a peripheral running bleno, and a central running noble.
4
-
5
- The service represents a robotic pizza oven, with the following characteristics:
6
-
7
- * crust - read / write. A value representing the type of pizza crust (normal, thin, or deep dish)
8
- * toppings - read / write. A value representing which toppings to include (pepperoni, mushrooms, extra cheese, etc.)
9
- * bake - write / notify. The value written is the temperature at which to bake the pizza. When baking is finished, the central is notified with a bake result (half baked, crispy, burnt, etc.)
10
-
11
- To run the peripheral example:
12
-
13
- node peripheral
14
-
15
- And on another computer, connect as a central from [noble](https://github.com/sandeepmistry/noble/tree/master/examples/pizza).
16
- You can also use a [web app](http://strangesast.github.io/bleno-web-pizza-example) using [Web Bluetooth](https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web).
@@ -1,34 +0,0 @@
1
- #pragma once
2
-
3
- #include <napi.h>
4
-
5
- #include "ble_manager.h"
6
-
7
- class BlenoMac : public Napi::ObjectWrap<BlenoMac>
8
- {
9
- public:
10
- BlenoMac(const Napi::CallbackInfo&);
11
- Napi::Value Init(const Napi::CallbackInfo&);
12
- Napi::Value CleanUp(const Napi::CallbackInfo&);
13
- Napi::Value Scan(const Napi::CallbackInfo&);
14
- Napi::Value StopScan(const Napi::CallbackInfo&);
15
- Napi::Value Connect(const Napi::CallbackInfo&);
16
- Napi::Value Disconnect(const Napi::CallbackInfo&);
17
- Napi::Value UpdateRSSI(const Napi::CallbackInfo&);
18
- Napi::Value DiscoverServices(const Napi::CallbackInfo&);
19
- Napi::Value DiscoverIncludedServices(const Napi::CallbackInfo& info);
20
- Napi::Value DiscoverCharacteristics(const Napi::CallbackInfo& info);
21
- Napi::Value Read(const Napi::CallbackInfo& info);
22
- Napi::Value Write(const Napi::CallbackInfo& info);
23
- Napi::Value Notify(const Napi::CallbackInfo& info);
24
- Napi::Value DiscoverDescriptors(const Napi::CallbackInfo& info);
25
- Napi::Value ReadValue(const Napi::CallbackInfo& info);
26
- Napi::Value WriteValue(const Napi::CallbackInfo& info);
27
- Napi::Value ReadHandle(const Napi::CallbackInfo& info);
28
- Napi::Value WriteHandle(const Napi::CallbackInfo& info);
29
-
30
- static Napi::Function GetClass(Napi::Env);
31
-
32
- private:
33
- BLEManager* manager;
34
- };
@@ -1,267 +0,0 @@
1
- //
2
- // bleno_mac.mm
3
- // bleno-mac-native
4
- //
5
- // Created by Georg Vienna on 28.08.18.
6
- //
7
- #include "bleno_mac.h"
8
-
9
- #include "napi_objc.h"
10
-
11
- #define THROW(msg) \
12
- Napi::TypeError::New(info.Env(), msg).ThrowAsJavaScriptException(); \
13
- return Napi::Value();
14
-
15
- #define ARG1(type1) \
16
- if (!info[0].Is##type1()) { \
17
- THROW("There should be one argument: (" #type1 ")") \
18
- }
19
-
20
- #define ARG2(type1, type2) \
21
- if (!info[0].Is##type1() || !info[1].Is##type2()) { \
22
- THROW("There should be 2 arguments: (" #type1 ", " #type2 ")"); \
23
- }
24
-
25
- #define ARG3(type1, type2, type3) \
26
- if (!info[0].Is##type1() || !info[1].Is##type2() || !info[2].Is##type3()) { \
27
- THROW("There should be 3 arguments: (" #type1 ", " #type2 ", " #type3 ")"); \
28
- }
29
-
30
- #define ARG4(type1, type2, type3, type4) \
31
- if (!info[0].Is##type1() || !info[1].Is##type2() || !info[2].Is##type3() || !info[3].Is##type4()) { \
32
- THROW("There should be 4 arguments: (" #type1 ", " #type2 ", " #type3 ", " #type4 ")"); \
33
- }
34
-
35
- #define ARG5(type1, type2, type3, type4, type5) \
36
- if (!info[0].Is##type1() || !info[1].Is##type2() || !info[2].Is##type3() || !info[3].Is##type4() || !info[4].Is##type5()) { \
37
- THROW("There should be 5 arguments: (" #type1 ", " #type2 ", " #type3 ", " #type4 ", " #type5 ")"); \
38
- }
39
-
40
- #define CHECK_MANAGER() \
41
- if(!manager) { \
42
- THROW("BLEManager has already been cleaned up"); \
43
- }
44
-
45
- BlenoMac::BlenoMac(const Napi::CallbackInfo& info) : ObjectWrap(info) {
46
- }
47
-
48
- Napi::Value BlenoMac::Init(const Napi::CallbackInfo& info) {
49
- Napi::Function emit = info.This().As<Napi::Object>().Get("emit").As<Napi::Function>();
50
- manager = [[BLEManager alloc] init];
51
- manager->emit.Wrap(info.This(), emit);
52
- return Napi::Value();
53
- }
54
-
55
- // startScanning(serviceUuids, allowDuplicates)
56
- Napi::Value BlenoMac::Scan(const Napi::CallbackInfo& info) {
57
- CHECK_MANAGER()
58
- NSArray* array = getUuidArray(info[0]);
59
- // default value NO
60
- auto duplicates = getBool(info[1], NO);
61
- [manager scan:array allowDuplicates:duplicates];
62
- return Napi::Value();
63
- }
64
-
65
- // stopScanning()
66
- Napi::Value BlenoMac::StopScan(const Napi::CallbackInfo& info) {
67
- CHECK_MANAGER()
68
- [manager stopScan];
69
- return Napi::Value();
70
- }
71
-
72
- // connect(deviceUuid)
73
- Napi::Value BlenoMac::Connect(const Napi::CallbackInfo& info) {
74
- CHECK_MANAGER()
75
- ARG1(String)
76
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
77
- [manager connect:uuid];
78
- return Napi::Value();
79
- }
80
-
81
- // disconnect(deviceUuid)
82
- Napi::Value BlenoMac::Disconnect(const Napi::CallbackInfo& info) {
83
- CHECK_MANAGER()
84
- ARG1(String)
85
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
86
- [manager disconnect:uuid];
87
- return Napi::Value();
88
- }
89
-
90
- // updateRssi(deviceUuid)
91
- Napi::Value BlenoMac::UpdateRSSI(const Napi::CallbackInfo& info) {
92
- CHECK_MANAGER()
93
- ARG1(String)
94
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
95
- [manager updateRSSI:uuid];
96
- return Napi::Value();
97
- }
98
-
99
- // discoverServices(deviceUuid, uuids)
100
- Napi::Value BlenoMac::DiscoverServices(const Napi::CallbackInfo& info) {
101
- CHECK_MANAGER()
102
- ARG1(String)
103
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
104
- NSArray* array = getUuidArray(info[1]);
105
- [manager discoverServices:uuid serviceUuids:array];
106
- return Napi::Value();
107
- }
108
-
109
- // discoverIncludedServices(deviceUuid, serviceUuid, serviceUuids)
110
- Napi::Value BlenoMac::DiscoverIncludedServices(const Napi::CallbackInfo& info) {
111
- CHECK_MANAGER()
112
- ARG2(String, String)
113
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
114
- auto service = napiToUuidString(info[1].As<Napi::String>());
115
- NSArray* serviceUuids = getUuidArray(info[2]);
116
- [manager discoverIncludedServices:uuid forService:service services:serviceUuids];
117
- return Napi::Value();
118
- }
119
-
120
- // discoverCharacteristics(deviceUuid, serviceUuid, characteristicUuids)
121
- Napi::Value BlenoMac::DiscoverCharacteristics(const Napi::CallbackInfo& info) {
122
- CHECK_MANAGER()
123
- ARG2(String, String)
124
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
125
- auto service = napiToUuidString(info[1].As<Napi::String>());
126
- NSArray* characteristics = getUuidArray(info[2]);
127
- [manager discoverCharacteristics:uuid forService:service characteristics:characteristics];
128
- return Napi::Value();
129
- }
130
-
131
- // read(deviceUuid, serviceUuid, characteristicUuid)
132
- Napi::Value BlenoMac::Read(const Napi::CallbackInfo& info) {
133
- CHECK_MANAGER()
134
- ARG3(String, String, String)
135
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
136
- auto service = napiToUuidString(info[1].As<Napi::String>());
137
- auto characteristic = napiToUuidString(info[2].As<Napi::String>());
138
- [manager read:uuid service:service characteristic:characteristic];
139
- return Napi::Value();
140
- }
141
-
142
- // write(deviceUuid, serviceUuid, characteristicUuid, data, withoutResponse)
143
- Napi::Value BlenoMac::Write(const Napi::CallbackInfo& info) {
144
- CHECK_MANAGER()
145
- ARG5(String, String, String, Buffer, Boolean)
146
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
147
- auto service = napiToUuidString(info[1].As<Napi::String>());
148
- auto characteristic = napiToUuidString(info[2].As<Napi::String>());
149
- auto data = napiToData(info[3].As<Napi::Buffer<Byte>>());
150
- auto withoutResponse = info[4].As<Napi::Boolean>().Value();
151
- [manager write:uuid service:service characteristic:characteristic data:data withoutResponse:withoutResponse];
152
- return Napi::Value();
153
- }
154
-
155
- // notify(deviceUuid, serviceUuid, characteristicUuid, notify)
156
- Napi::Value BlenoMac::Notify(const Napi::CallbackInfo& info) {
157
- CHECK_MANAGER()
158
- ARG4(String, String, String, Boolean)
159
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
160
- auto service = napiToUuidString(info[1].As<Napi::String>());
161
- auto characteristic = napiToUuidString(info[2].As<Napi::String>());
162
- auto on = info[3].As<Napi::Boolean>().Value();
163
- [manager notify:uuid service:service characteristic:characteristic on:on];
164
- return Napi::Value();
165
- }
166
-
167
- // discoverDescriptors(deviceUuid, serviceUuid, characteristicUuid)
168
- Napi::Value BlenoMac::DiscoverDescriptors(const Napi::CallbackInfo& info) {
169
- CHECK_MANAGER()
170
- ARG3(String, String, String)
171
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
172
- auto service = napiToUuidString(info[1].As<Napi::String>());
173
- auto characteristic = napiToUuidString(info[2].As<Napi::String>());
174
- [manager discoverDescriptors:uuid service:service characteristic:characteristic];
175
- return Napi::Value();
176
- }
177
-
178
- // readValue(deviceUuid, serviceUuid, characteristicUuid, descriptorUuid)
179
- Napi::Value BlenoMac::ReadValue(const Napi::CallbackInfo& info) {
180
- CHECK_MANAGER()
181
- ARG4(String, String, String, String)
182
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
183
- auto service = napiToUuidString(info[1].As<Napi::String>());
184
- auto characteristic = napiToUuidString(info[2].As<Napi::String>());
185
- auto descriptor = napiToUuidString(info[3].As<Napi::String>());
186
- [manager readValue:uuid service:service characteristic:characteristic descriptor:descriptor];
187
- return Napi::Value();
188
- }
189
-
190
- // writeValue(deviceUuid, serviceUuid, characteristicUuid, descriptorUuid, data)
191
- Napi::Value BlenoMac::WriteValue(const Napi::CallbackInfo& info) {
192
- CHECK_MANAGER()
193
- ARG5(String, String, String, String, Buffer)
194
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
195
- auto service = napiToUuidString(info[1].As<Napi::String>());
196
- auto characteristic = napiToUuidString(info[2].As<Napi::String>());
197
- auto descriptor = napiToUuidString(info[3].As<Napi::String>());
198
- auto data = napiToData(info[4].As<Napi::Buffer<Byte>>());
199
- [manager writeValue:uuid service:service characteristic:characteristic descriptor:descriptor data: data];
200
- return Napi::Value();
201
- }
202
-
203
- // readHandle(deviceUuid, handle)
204
- Napi::Value BlenoMac::ReadHandle(const Napi::CallbackInfo& info) {
205
- CHECK_MANAGER()
206
- ARG2(String, Number)
207
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
208
- auto handle = napiToNumber(info[1].As<Napi::Number>());
209
- [manager readHandle:uuid handle:handle];
210
- return Napi::Value();
211
- }
212
-
213
- // writeHandle(deviceUuid, handle, data, (unused)withoutResponse)
214
- Napi::Value BlenoMac::WriteHandle(const Napi::CallbackInfo& info) {
215
- CHECK_MANAGER()
216
- ARG3(String, Number, Buffer)
217
- auto uuid = napiToUuidString(info[0].As<Napi::String>());
218
- auto handle = napiToNumber(info[1].As<Napi::Number>());
219
- auto data = napiToData(info[2].As<Napi::Buffer<Byte>>());
220
- [manager writeHandle:uuid handle:handle data: data];
221
- return Napi::Value();
222
- }
223
-
224
- Napi::Value BlenoMac::CleanUp(const Napi::CallbackInfo& info) {
225
- CHECK_MANAGER()
226
- CFRelease((__bridge CFTypeRef)manager);
227
- manager = nil;
228
- return Napi::Value();
229
- }
230
-
231
- Napi::Value BlenoMac::Stop(const Napi::CallbackInfo& info) {
232
- CHECK_MANAGER()
233
- CleanUp(info);
234
- return Napi::Value();
235
- }
236
-
237
- Napi::Function BlenoMac::GetClass(Napi::Env env) {
238
- return DefineClass(env, "BlenoMac", {
239
- BlenoMac::InstanceMethod("init", &BlenoMac::Init),
240
- BlenoMac::InstanceMethod("startScanning", &BlenoMac::Scan),
241
- BlenoMac::InstanceMethod("stopScanning", &BlenoMac::StopScan),
242
- BlenoMac::InstanceMethod("connect", &BlenoMac::Connect),
243
- BlenoMac::InstanceMethod("disconnect", &BlenoMac::Disconnect),
244
- BlenoMac::InstanceMethod("updateRssi", &BlenoMac::UpdateRSSI),
245
- BlenoMac::InstanceMethod("discoverServices", &BlenoMac::DiscoverServices),
246
- BlenoMac::InstanceMethod("discoverIncludedServices", &BlenoMac::DiscoverIncludedServices),
247
- BlenoMac::InstanceMethod("discoverCharacteristics", &BlenoMac::DiscoverCharacteristics),
248
- BlenoMac::InstanceMethod("read", &BlenoMac::Read),
249
- BlenoMac::InstanceMethod("write", &BlenoMac::Write),
250
- BlenoMac::InstanceMethod("notify", &BlenoMac::Notify),
251
- BlenoMac::InstanceMethod("discoverDescriptors", &BlenoMac::DiscoverDescriptors),
252
- BlenoMac::InstanceMethod("readValue", &BlenoMac::ReadValue),
253
- BlenoMac::InstanceMethod("writeValue", &BlenoMac::WriteValue),
254
- BlenoMac::InstanceMethod("readHandle", &BlenoMac::ReadValue),
255
- BlenoMac::InstanceMethod("writeHandle", &BlenoMac::WriteValue),
256
- BlenoMac::InstanceMethod("cleanUp", &BlenoMac::CleanUp),
257
- BlenoMac::InstanceMethod("stop", &BlenoMac::Stop),
258
- });
259
- }
260
-
261
- Napi::Object Init(Napi::Env env, Napi::Object exports) {
262
- Napi::String name = Napi::String::New(env, "BlenoMac");
263
- exports.Set(name, BlenoMac::GetClass(env));
264
- return exports;
265
- }
266
-
267
- NODE_API_MODULE(addon, Init)
@@ -1,23 +0,0 @@
1
- #pragma once
2
-
3
- using Data = std::vector<uint8_t>;
4
-
5
- enum AddressType {
6
- PUBLIC,
7
- RANDOM,
8
- UNKNOWN,
9
- };
10
-
11
- class Peripheral {
12
- public:
13
- Peripheral() : address("unknown"), addressType(UNKNOWN), connectable(false) {
14
- }
15
- std::string address;
16
- AddressType addressType;
17
- bool connectable;
18
- std::string name;
19
- int txPowerLevel;
20
- Data manufacturerData;
21
- std::vector<std::pair<std::string, Data>> serviceData;
22
- std::vector<std::string> serviceUuids;
23
- };
package/with-bindings.js DELETED
@@ -1,5 +0,0 @@
1
- const Bleno = require('./lib/bleno');
2
-
3
- module.exports = function (bindings) {
4
- return new Bleno(bindings);
5
- };
@@ -1,6 +0,0 @@
1
- module.exports = function (options) {
2
- const Bleno = require('./lib/bleno');
3
- const bindings = require('./lib/resolve-bindings')(options);
4
-
5
- return new Bleno(bindings);
6
- };