@neurodevs/ndx-native 1.0.1 → 2.0.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.
- package/build/__tests__/impl/LibndxAdapter.test.d.ts +44 -9
- package/build/__tests__/impl/LibndxAdapter.test.js +248 -52
- package/build/__tests__/impl/LibndxAdapter.test.js.map +1 -1
- package/build/impl/LibndxAdapter.d.ts +11 -0
- package/build/impl/LibndxAdapter.js +26 -2
- package/build/impl/LibndxAdapter.js.map +1 -1
- package/build/testDoubles/Libndx/FakeLibndx.d.ts +6 -1
- package/build/testDoubles/Libndx/FakeLibndx.js +21 -8
- package/build/testDoubles/Libndx/FakeLibndx.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/impl/LibndxAdapter.test.ts +297 -45
- package/src/impl/LibndxAdapter.ts +39 -2
- package/src/testDoubles/Libndx/FakeLibndx.ts +25 -8
|
@@ -2,52 +2,65 @@ export default class FakeLibndx {
|
|
|
2
2
|
static callsToConstructor = [];
|
|
3
3
|
static callsToCreateBleBackend = [];
|
|
4
4
|
static callsToStartBleBackend = [];
|
|
5
|
+
static callsToWriteBle = [];
|
|
5
6
|
static callsToStopBleBacked = [];
|
|
6
7
|
static callsToDestroyBleBackend = [];
|
|
8
|
+
static callsToGetRssiBleBackend = [];
|
|
7
9
|
static callsToCreateFtdiBackend = [];
|
|
8
10
|
static callsToStartFtdiBackend = [];
|
|
9
11
|
static callsToStopFtdiBackend = [];
|
|
10
12
|
static callsToDestroyFtdiBackend = [];
|
|
13
|
+
static fakeResult = '';
|
|
11
14
|
constructor(options) {
|
|
12
15
|
FakeLibndx.callsToConstructor.push(options);
|
|
13
16
|
}
|
|
14
17
|
createBleBackend(options) {
|
|
15
18
|
FakeLibndx.callsToCreateBleBackend.push(options);
|
|
16
|
-
return
|
|
19
|
+
return FakeLibndx.fakeResult;
|
|
17
20
|
}
|
|
18
21
|
startBleBackend(options) {
|
|
19
22
|
FakeLibndx.callsToStartBleBackend.push(options);
|
|
20
|
-
return
|
|
23
|
+
return FakeLibndx.fakeResult;
|
|
24
|
+
}
|
|
25
|
+
writeBleCharacteristic(options) {
|
|
26
|
+
FakeLibndx.callsToWriteBle.push(options);
|
|
27
|
+
return FakeLibndx.fakeResult;
|
|
28
|
+
}
|
|
29
|
+
readBleRssi(options) {
|
|
30
|
+
FakeLibndx.callsToGetRssiBleBackend.push(options);
|
|
31
|
+
return FakeLibndx.fakeResult;
|
|
21
32
|
}
|
|
22
33
|
stopBleBackend(options) {
|
|
23
34
|
FakeLibndx.callsToStopBleBacked.push(options);
|
|
24
|
-
return
|
|
35
|
+
return FakeLibndx.fakeResult;
|
|
25
36
|
}
|
|
26
37
|
destroyBleBackend(options) {
|
|
27
38
|
FakeLibndx.callsToDestroyBleBackend.push(options);
|
|
28
|
-
return
|
|
39
|
+
return FakeLibndx.fakeResult;
|
|
29
40
|
}
|
|
30
41
|
createFtdiBackend(options) {
|
|
31
42
|
FakeLibndx.callsToCreateFtdiBackend.push(options);
|
|
32
|
-
return
|
|
43
|
+
return FakeLibndx.fakeResult;
|
|
33
44
|
}
|
|
34
45
|
startFtdiBackend(options) {
|
|
35
46
|
FakeLibndx.callsToStartFtdiBackend.push(options);
|
|
36
|
-
return
|
|
47
|
+
return FakeLibndx.fakeResult;
|
|
37
48
|
}
|
|
38
49
|
stopFtdiBackend(options) {
|
|
39
50
|
FakeLibndx.callsToStopFtdiBackend.push(options);
|
|
40
|
-
return
|
|
51
|
+
return FakeLibndx.fakeResult;
|
|
41
52
|
}
|
|
42
53
|
destroyFtdiBackend(options) {
|
|
43
54
|
FakeLibndx.callsToDestroyFtdiBackend.push(options);
|
|
44
|
-
return
|
|
55
|
+
return FakeLibndx.fakeResult;
|
|
45
56
|
}
|
|
46
57
|
static resetTestDouble() {
|
|
47
58
|
FakeLibndx.callsToConstructor = [];
|
|
48
59
|
FakeLibndx.callsToCreateBleBackend = [];
|
|
49
60
|
FakeLibndx.callsToStartBleBackend = [];
|
|
61
|
+
FakeLibndx.callsToWriteBle = [];
|
|
50
62
|
FakeLibndx.callsToStopBleBacked = [];
|
|
63
|
+
FakeLibndx.callsToGetRssiBleBackend = [];
|
|
51
64
|
FakeLibndx.callsToDestroyBleBackend = [];
|
|
52
65
|
FakeLibndx.callsToCreateFtdiBackend = [];
|
|
53
66
|
FakeLibndx.callsToStartFtdiBackend = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeLibndx.js","sourceRoot":"","sources":["../../../src/testDoubles/Libndx/FakeLibndx.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FakeLibndx.js","sourceRoot":"","sources":["../../../src/testDoubles/Libndx/FakeLibndx.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -21,13 +21,28 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
21
21
|
private static ffiRsDefineOptions?: FfiRsDefineOptions
|
|
22
22
|
|
|
23
23
|
private static readonly bleDeviceUuid = this.generateId()
|
|
24
|
+
private static readonly bleCharacteristicUuid = this.generateId()
|
|
25
|
+
private static readonly bleValueToWrite = this.generateId()
|
|
26
|
+
|
|
24
27
|
private static readonly ftdiSerialNumber = this.generateId()
|
|
25
28
|
|
|
29
|
+
private static readonly callsToCreateBle: string[][] = []
|
|
30
|
+
private static readonly callsToStartBle: string[][] = []
|
|
31
|
+
private static readonly callsToWriteBle: string[][] = []
|
|
32
|
+
private static readonly callsToReadRssi: string[][] = []
|
|
33
|
+
private static readonly callsToStopBle: string[][] = []
|
|
34
|
+
private static readonly callsToDestroyBle: string[][] = []
|
|
35
|
+
private static readonly callsToCreateFtdi: string[][] = []
|
|
36
|
+
private static readonly callsToStartFtdi: string[][] = []
|
|
37
|
+
private static readonly callsToStopFtdi: string[][] = []
|
|
38
|
+
private static readonly callsToDestroyFtdi: string[][] = []
|
|
39
|
+
|
|
26
40
|
protected static async beforeEach() {
|
|
27
41
|
await super.beforeEach()
|
|
28
42
|
|
|
29
43
|
this.shouldThrowWhenLoadingBindings = false
|
|
30
44
|
this.fakeBindings = this.FakeBindings()
|
|
45
|
+
this.resetCallsToFakeBindings()
|
|
31
46
|
this.clearAndFakeFfi()
|
|
32
47
|
|
|
33
48
|
this.resetInstance()
|
|
@@ -77,6 +92,20 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
77
92
|
retType: DataType.String,
|
|
78
93
|
paramsType: [DataType.String],
|
|
79
94
|
},
|
|
95
|
+
write_ble_characteristic: {
|
|
96
|
+
library: 'ndx',
|
|
97
|
+
retType: DataType.String,
|
|
98
|
+
paramsType: [
|
|
99
|
+
DataType.String,
|
|
100
|
+
DataType.String,
|
|
101
|
+
DataType.String,
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
read_ble_rssi: {
|
|
105
|
+
library: 'ndx',
|
|
106
|
+
retType: DataType.String,
|
|
107
|
+
paramsType: [DataType.String],
|
|
108
|
+
},
|
|
80
109
|
stop_ble_backend: {
|
|
81
110
|
library: 'ndx',
|
|
82
111
|
retType: DataType.String,
|
|
@@ -125,80 +154,197 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
125
154
|
}
|
|
126
155
|
|
|
127
156
|
@test()
|
|
128
|
-
protected static async
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
157
|
+
protected static async createBleBackendCallsBindingWithExpectedArgs() {
|
|
158
|
+
this.createBleBackend()
|
|
159
|
+
|
|
160
|
+
assert.isEqualDeep(
|
|
161
|
+
this.callsToCreateBle[0][0],
|
|
162
|
+
JSON.stringify({ uuid: this.bleDeviceUuid }),
|
|
163
|
+
'createBleBackend did not call binding with expected args!'
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@test()
|
|
168
|
+
protected static async createBleBackendReturnsJsonString() {
|
|
169
|
+
const raw = this.createBleBackend()
|
|
132
170
|
const json = JSON.parse(raw)
|
|
133
171
|
|
|
134
172
|
assert.isTruthy(json, 'createBleBackend did not return a JSON string!')
|
|
135
173
|
}
|
|
136
174
|
|
|
137
175
|
@test()
|
|
138
|
-
protected static async
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
176
|
+
protected static async startBleBackendCallsBindingWithExpectedArgs() {
|
|
177
|
+
this.startBleBackend()
|
|
178
|
+
|
|
179
|
+
assert.isEqual(
|
|
180
|
+
this.callsToStartBle[0][0],
|
|
181
|
+
this.bleDeviceUuid,
|
|
182
|
+
'startBleBackend did not call binding with expected args!'
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@test()
|
|
187
|
+
protected static async startBleBackendReturnsJsonString() {
|
|
188
|
+
const raw = this.startBleBackend()
|
|
142
189
|
const json = JSON.parse(raw)
|
|
143
190
|
|
|
144
191
|
assert.isTruthy(json, 'startBleBackend did not return a JSON string!')
|
|
145
192
|
}
|
|
146
193
|
|
|
147
194
|
@test()
|
|
148
|
-
protected static async
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
195
|
+
protected static async writeBleCharacteristicCallsBindingWithExpectedArgs() {
|
|
196
|
+
this.writeBleCharacteristic()
|
|
197
|
+
|
|
198
|
+
assert.isEqualDeep(
|
|
199
|
+
this.callsToWriteBle[0],
|
|
200
|
+
[
|
|
201
|
+
this.bleDeviceUuid,
|
|
202
|
+
this.bleCharacteristicUuid,
|
|
203
|
+
this.bleValueToWrite,
|
|
204
|
+
],
|
|
205
|
+
'writeBleCharacteristic did not call binding with expected args!'
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@test()
|
|
210
|
+
protected static async writeBleCharacteristicReturnsJsonString() {
|
|
211
|
+
const raw = this.writeBleCharacteristic()
|
|
212
|
+
const json = JSON.parse(raw)
|
|
213
|
+
|
|
214
|
+
assert.isTruthy(
|
|
215
|
+
json,
|
|
216
|
+
'writeBleCharacteristic did not return a JSON string!'
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@test()
|
|
221
|
+
protected static async getRssiBleBackendCallsBindingWithExpectedArgs() {
|
|
222
|
+
this.getRssiBleBackend()
|
|
223
|
+
|
|
224
|
+
assert.isEqual(
|
|
225
|
+
this.callsToReadRssi[0][0],
|
|
226
|
+
this.bleDeviceUuid,
|
|
227
|
+
'getRssiBleBackend did not call binding with expected args!'
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
@test()
|
|
232
|
+
protected static async getRssiBleBackendReturnsJson() {
|
|
233
|
+
const raw = this.getRssiBleBackend()
|
|
234
|
+
const json = JSON.parse(raw)
|
|
235
|
+
|
|
236
|
+
assert.isTruthy(json, 'getRssiBleBackend did not return a JSON string!')
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@test()
|
|
240
|
+
protected static async stopBleBackendCallsBindingWithExpectedArgs() {
|
|
241
|
+
this.stopBleBackend()
|
|
242
|
+
|
|
243
|
+
assert.isEqual(
|
|
244
|
+
this.callsToStopBle[0][0],
|
|
245
|
+
this.bleDeviceUuid,
|
|
246
|
+
'stopBleBackend did not call binding with expected args!'
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@test()
|
|
251
|
+
protected static async stopBleBackendReturnsJsonString() {
|
|
252
|
+
const raw = this.stopBleBackend()
|
|
152
253
|
const json = JSON.parse(raw)
|
|
153
254
|
|
|
154
255
|
assert.isTruthy(json, 'stopBleBackend did not return a JSON string!')
|
|
155
256
|
}
|
|
156
257
|
|
|
157
258
|
@test()
|
|
158
|
-
protected static async
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
259
|
+
protected static async destroyBleBackendCallsBindingWithExpectedArgs() {
|
|
260
|
+
this.destroyBleBackend()
|
|
261
|
+
|
|
262
|
+
assert.isEqual(
|
|
263
|
+
this.callsToDestroyBle[0][0],
|
|
264
|
+
this.bleDeviceUuid,
|
|
265
|
+
'destroyBleBackend did not call binding with expected args!'
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
@test()
|
|
270
|
+
protected static async destroyBleBackendReturnsJson() {
|
|
271
|
+
const raw = this.destroyBleBackend()
|
|
162
272
|
const json = JSON.parse(raw)
|
|
163
273
|
|
|
164
274
|
assert.isTruthy(json, 'destroyBleBackend did not return a JSON string!')
|
|
165
275
|
}
|
|
166
276
|
|
|
167
277
|
@test()
|
|
168
|
-
protected static async
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
278
|
+
protected static async createFtdiBackendCallsBindingWithExpectedArgs() {
|
|
279
|
+
this.createFtdiBackend()
|
|
280
|
+
|
|
281
|
+
assert.isEqualDeep(
|
|
282
|
+
this.callsToCreateFtdi[0][0],
|
|
283
|
+
JSON.stringify({ serialNumber: this.ftdiSerialNumber }),
|
|
284
|
+
'createFtdiBackend did not call binding with expected args!'
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
@test()
|
|
289
|
+
protected static async createFtdiBackendReturnsJsonString() {
|
|
290
|
+
const raw = this.createFtdiBackend()
|
|
172
291
|
const json = JSON.parse(raw)
|
|
173
292
|
|
|
174
293
|
assert.isTruthy(json, 'createFtdiBackend did not return a JSON string!')
|
|
175
294
|
}
|
|
176
295
|
|
|
177
296
|
@test()
|
|
178
|
-
protected static async
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
297
|
+
protected static async startFtdiBackendCallsBindingWithExpectedArgs() {
|
|
298
|
+
this.startFtdiBackend()
|
|
299
|
+
|
|
300
|
+
assert.isEqual(
|
|
301
|
+
this.callsToStartFtdi[0][0],
|
|
302
|
+
this.ftdiSerialNumber,
|
|
303
|
+
'startFtdiBackend did not call binding with expected args!'
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
@test()
|
|
308
|
+
protected static async startFtdiBackendReturnsJsonString() {
|
|
309
|
+
const raw = this.startFtdiBackend()
|
|
182
310
|
const json = JSON.parse(raw)
|
|
183
311
|
|
|
184
312
|
assert.isTruthy(json, 'startFtdiBackend did not return a JSON string!')
|
|
185
313
|
}
|
|
186
314
|
|
|
187
315
|
@test()
|
|
188
|
-
protected static async
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
316
|
+
protected static async stopFtdiBackendCallsBindingWithExpectedArgs() {
|
|
317
|
+
this.stopFtdiBackend()
|
|
318
|
+
|
|
319
|
+
assert.isEqual(
|
|
320
|
+
this.callsToStopFtdi[0][0],
|
|
321
|
+
this.ftdiSerialNumber,
|
|
322
|
+
'stopFtdiBackend did not call binding with expected args!'
|
|
323
|
+
)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
@test()
|
|
327
|
+
protected static async stopFtdiBackendReturnsJsonString() {
|
|
328
|
+
const raw = this.stopFtdiBackend()
|
|
192
329
|
const json = JSON.parse(raw)
|
|
193
330
|
|
|
194
331
|
assert.isTruthy(json, 'stopFtdiBackend did not return a JSON string!')
|
|
195
332
|
}
|
|
196
333
|
|
|
197
334
|
@test()
|
|
198
|
-
protected static async
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
335
|
+
protected static async destroyFtdiBackendCallsBindingWithExpectedArgs() {
|
|
336
|
+
this.destroyFtdiBackend()
|
|
337
|
+
|
|
338
|
+
assert.isEqual(
|
|
339
|
+
this.callsToDestroyFtdi[0][0],
|
|
340
|
+
this.ftdiSerialNumber,
|
|
341
|
+
'destroyFtdiBackend did not call binding with expected args!'
|
|
342
|
+
)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
@test()
|
|
346
|
+
protected static async destroyFtdiBackendReturnsJsonString() {
|
|
347
|
+
const raw = this.destroyFtdiBackend()
|
|
202
348
|
const json = JSON.parse(raw)
|
|
203
349
|
|
|
204
350
|
assert.isTruthy(
|
|
@@ -207,6 +353,125 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
207
353
|
)
|
|
208
354
|
}
|
|
209
355
|
|
|
356
|
+
private static createBleBackend() {
|
|
357
|
+
return this.instance.createBleBackend({
|
|
358
|
+
deviceUuid: this.bleDeviceUuid,
|
|
359
|
+
})
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
private static startBleBackend() {
|
|
363
|
+
return this.instance.startBleBackend({
|
|
364
|
+
deviceUuid: this.bleDeviceUuid,
|
|
365
|
+
})
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private static writeBleCharacteristic() {
|
|
369
|
+
return this.instance.writeBleCharacteristic({
|
|
370
|
+
deviceUuid: this.bleDeviceUuid,
|
|
371
|
+
characteristicUuid: this.bleCharacteristicUuid,
|
|
372
|
+
value: this.bleValueToWrite,
|
|
373
|
+
})
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
private static stopBleBackend() {
|
|
377
|
+
return this.instance.stopBleBackend({
|
|
378
|
+
deviceUuid: this.bleDeviceUuid,
|
|
379
|
+
})
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
private static destroyBleBackend() {
|
|
383
|
+
return this.instance.destroyBleBackend({
|
|
384
|
+
deviceUuid: this.bleDeviceUuid,
|
|
385
|
+
})
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private static getRssiBleBackend() {
|
|
389
|
+
return this.instance.readBleRssi({
|
|
390
|
+
deviceUuid: this.bleDeviceUuid,
|
|
391
|
+
})
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
private static createFtdiBackend() {
|
|
395
|
+
return this.instance.createFtdiBackend({
|
|
396
|
+
serialNumber: this.ftdiSerialNumber,
|
|
397
|
+
})
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
private static startFtdiBackend() {
|
|
401
|
+
return this.instance.startFtdiBackend({
|
|
402
|
+
serialNumber: this.ftdiSerialNumber,
|
|
403
|
+
})
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
private static stopFtdiBackend() {
|
|
407
|
+
return this.instance.stopFtdiBackend({
|
|
408
|
+
serialNumber: this.ftdiSerialNumber,
|
|
409
|
+
})
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private static destroyFtdiBackend() {
|
|
413
|
+
return this.instance.destroyFtdiBackend({
|
|
414
|
+
serialNumber: this.ftdiSerialNumber,
|
|
415
|
+
})
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private static FakeBindings(): LibndxBindings {
|
|
419
|
+
return {
|
|
420
|
+
create_ble_backend: (args) => {
|
|
421
|
+
this.callsToCreateBle.push(args)
|
|
422
|
+
return JSON.stringify({})
|
|
423
|
+
},
|
|
424
|
+
start_ble_backend: (args) => {
|
|
425
|
+
this.callsToStartBle.push(args)
|
|
426
|
+
return JSON.stringify({})
|
|
427
|
+
},
|
|
428
|
+
write_ble_characteristic: (args) => {
|
|
429
|
+
this.callsToWriteBle.push(args)
|
|
430
|
+
return JSON.stringify({})
|
|
431
|
+
},
|
|
432
|
+
read_ble_rssi: (args) => {
|
|
433
|
+
this.callsToReadRssi.push(args)
|
|
434
|
+
return JSON.stringify({})
|
|
435
|
+
},
|
|
436
|
+
stop_ble_backend: (args) => {
|
|
437
|
+
this.callsToStopBle.push(args)
|
|
438
|
+
return JSON.stringify({})
|
|
439
|
+
},
|
|
440
|
+
destroy_ble_backend: (args) => {
|
|
441
|
+
this.callsToDestroyBle.push(args)
|
|
442
|
+
return JSON.stringify({})
|
|
443
|
+
},
|
|
444
|
+
create_ftdi_backend: (args) => {
|
|
445
|
+
this.callsToCreateFtdi.push(args)
|
|
446
|
+
return JSON.stringify({})
|
|
447
|
+
},
|
|
448
|
+
start_ftdi_backend: (args) => {
|
|
449
|
+
this.callsToStartFtdi.push(args)
|
|
450
|
+
return JSON.stringify({})
|
|
451
|
+
},
|
|
452
|
+
stop_ftdi_backend: (args) => {
|
|
453
|
+
this.callsToStopFtdi.push(args)
|
|
454
|
+
return JSON.stringify({})
|
|
455
|
+
},
|
|
456
|
+
destroy_ftdi_backend: (args) => {
|
|
457
|
+
this.callsToDestroyFtdi.push(args)
|
|
458
|
+
return JSON.stringify({})
|
|
459
|
+
},
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
private static resetCallsToFakeBindings() {
|
|
464
|
+
this.callsToCreateBle.length = 0
|
|
465
|
+
this.callsToStartBle.length = 0
|
|
466
|
+
this.callsToStopBle.length = 0
|
|
467
|
+
this.callsToDestroyBle.length = 0
|
|
468
|
+
this.callsToReadRssi.length = 0
|
|
469
|
+
this.callsToCreateFtdi.length = 0
|
|
470
|
+
this.callsToStartFtdi.length = 0
|
|
471
|
+
this.callsToStopFtdi.length = 0
|
|
472
|
+
this.callsToDestroyFtdi.length = 0
|
|
473
|
+
}
|
|
474
|
+
|
|
210
475
|
private static clearAndFakeFfi() {
|
|
211
476
|
delete this.ffiRsOpenOptions
|
|
212
477
|
delete this.ffiRsDefineOptions
|
|
@@ -254,19 +519,6 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
254
519
|
`.replace(/\s+/g, '')
|
|
255
520
|
}
|
|
256
521
|
|
|
257
|
-
private static FakeBindings(): LibndxBindings {
|
|
258
|
-
return {
|
|
259
|
-
create_ble_backend: () => JSON.stringify({}),
|
|
260
|
-
start_ble_backend: () => JSON.stringify({}),
|
|
261
|
-
stop_ble_backend: () => JSON.stringify({}),
|
|
262
|
-
destroy_ble_backend: () => JSON.stringify({}),
|
|
263
|
-
create_ftdi_backend: () => JSON.stringify({}),
|
|
264
|
-
start_ftdi_backend: () => JSON.stringify({}),
|
|
265
|
-
stop_ftdi_backend: () => JSON.stringify({}),
|
|
266
|
-
destroy_ftdi_backend: () => JSON.stringify({}),
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
522
|
private static resetInstance() {
|
|
271
523
|
LibndxAdapter.resetInstance()
|
|
272
524
|
}
|
|
@@ -61,6 +61,16 @@ export default class LibndxAdapter implements Libndx {
|
|
|
61
61
|
retType: DataType.String,
|
|
62
62
|
paramsType: [DataType.String],
|
|
63
63
|
},
|
|
64
|
+
write_ble_characteristic: {
|
|
65
|
+
library: 'ndx',
|
|
66
|
+
retType: DataType.String,
|
|
67
|
+
paramsType: [DataType.String, DataType.String, DataType.String],
|
|
68
|
+
},
|
|
69
|
+
read_ble_rssi: {
|
|
70
|
+
library: 'ndx',
|
|
71
|
+
retType: DataType.String,
|
|
72
|
+
paramsType: [DataType.String],
|
|
73
|
+
},
|
|
64
74
|
stop_ble_backend: {
|
|
65
75
|
library: 'ndx',
|
|
66
76
|
retType: DataType.String,
|
|
@@ -120,7 +130,8 @@ export default class LibndxAdapter implements Libndx {
|
|
|
120
130
|
|
|
121
131
|
public createBleBackend(options: BleBackendOptions) {
|
|
122
132
|
const { deviceUuid } = options
|
|
123
|
-
|
|
133
|
+
const configJson = JSON.stringify({ uuid: deviceUuid })
|
|
134
|
+
return this.bindings.create_ble_backend([configJson])
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
public startBleBackend(options: BleBackendOptions) {
|
|
@@ -128,6 +139,21 @@ export default class LibndxAdapter implements Libndx {
|
|
|
128
139
|
return this.bindings.start_ble_backend([deviceUuid])
|
|
129
140
|
}
|
|
130
141
|
|
|
142
|
+
public writeBleCharacteristic(options: BleWriteOptions) {
|
|
143
|
+
const { deviceUuid, characteristicUuid, value } = options
|
|
144
|
+
|
|
145
|
+
return this.bindings.write_ble_characteristic([
|
|
146
|
+
deviceUuid,
|
|
147
|
+
characteristicUuid,
|
|
148
|
+
value,
|
|
149
|
+
])
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public readBleRssi(options: BleBackendOptions) {
|
|
153
|
+
const { deviceUuid } = options
|
|
154
|
+
return this.bindings.read_ble_rssi([deviceUuid])
|
|
155
|
+
}
|
|
156
|
+
|
|
131
157
|
public stopBleBackend(options: BleBackendOptions) {
|
|
132
158
|
const { deviceUuid } = options
|
|
133
159
|
return this.bindings.stop_ble_backend([deviceUuid])
|
|
@@ -140,7 +166,8 @@ export default class LibndxAdapter implements Libndx {
|
|
|
140
166
|
|
|
141
167
|
public createFtdiBackend(options: FtdiBackendOptions) {
|
|
142
168
|
const { serialNumber } = options
|
|
143
|
-
|
|
169
|
+
const configJson = JSON.stringify({ serialNumber })
|
|
170
|
+
return this.bindings.create_ftdi_backend([configJson])
|
|
144
171
|
}
|
|
145
172
|
|
|
146
173
|
public startFtdiBackend(options: FtdiBackendOptions) {
|
|
@@ -170,6 +197,8 @@ export default class LibndxAdapter implements Libndx {
|
|
|
170
197
|
export interface Libndx {
|
|
171
198
|
createBleBackend(options: BleBackendOptions): string
|
|
172
199
|
startBleBackend(options: BleBackendOptions): string
|
|
200
|
+
writeBleCharacteristic(options: BleWriteOptions): string
|
|
201
|
+
readBleRssi(options: BleBackendOptions): string
|
|
173
202
|
stopBleBackend(options: BleBackendOptions): string
|
|
174
203
|
destroyBleBackend(options: BleBackendOptions): string
|
|
175
204
|
createFtdiBackend(options: FtdiBackendOptions): string
|
|
@@ -188,6 +217,12 @@ export interface BleBackendOptions {
|
|
|
188
217
|
deviceUuid: string
|
|
189
218
|
}
|
|
190
219
|
|
|
220
|
+
export interface BleWriteOptions {
|
|
221
|
+
deviceUuid: string
|
|
222
|
+
characteristicUuid: string
|
|
223
|
+
value: string
|
|
224
|
+
}
|
|
225
|
+
|
|
191
226
|
export interface FtdiBackendOptions {
|
|
192
227
|
serialNumber: string
|
|
193
228
|
}
|
|
@@ -195,6 +230,8 @@ export interface FtdiBackendOptions {
|
|
|
195
230
|
export interface LibndxBindings {
|
|
196
231
|
create_ble_backend(args: [string]): string
|
|
197
232
|
start_ble_backend(args: [string]): string
|
|
233
|
+
write_ble_characteristic(args: [string, string, string]): string
|
|
234
|
+
read_ble_rssi(args: [string]): string
|
|
198
235
|
stop_ble_backend(args: [string]): string
|
|
199
236
|
destroy_ble_backend(args: [string]): string
|
|
200
237
|
create_ftdi_backend(args: [string]): string
|