@neurodevs/ndx-native 7.0.0 → 7.1.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 +22 -13
- package/build/__tests__/impl/LibndxAdapter.test.js +110 -49
- package/build/__tests__/impl/LibndxAdapter.test.js.map +1 -1
- package/build/impl/LibndxAdapter.d.ts +22 -10
- package/build/impl/LibndxAdapter.js +32 -10
- package/build/impl/LibndxAdapter.js.map +1 -1
- package/build/testDoubles/Libndx/FakeLibndx.d.ts +11 -7
- package/build/testDoubles/Libndx/FakeLibndx.js +24 -12
- package/build/testDoubles/Libndx/FakeLibndx.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/impl/LibndxAdapter.test.ts +138 -49
- package/src/impl/LibndxAdapter.ts +84 -20
- package/src/testDoubles/Libndx/FakeLibndx.ts +29 -13
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { BleBackendOptions, WriteBleCharacteristicOptions,
|
|
1
|
+
import { AddBleCharCallbacksOptions, BleBackendOptions, WriteBleCharacteristicOptions, UsbBackendOptions, WriteUsbBackendOptions, Libndx, LibndxAdapterOptions, StartBleBackendOptions, NativeResult, BleRssiOptions, DiscoverBleUuidOptions } from '../../impl/LibndxAdapter.js';
|
|
2
2
|
export default class FakeLibndx implements Libndx {
|
|
3
3
|
static callsToConstructor: (LibndxAdapterOptions | undefined)[];
|
|
4
4
|
static callsToDiscoverBleUuid: DiscoverBleUuidOptions[];
|
|
5
5
|
static callsToCreateBleBackend: BleBackendOptions[];
|
|
6
6
|
static callsToStartBleBackend: StartBleBackendOptions[];
|
|
7
|
+
static callsToAddBleCharCallbacks: AddBleCharCallbacksOptions[];
|
|
7
8
|
static callsToWriteBleCharacteristic: WriteBleCharacteristicOptions[];
|
|
8
9
|
static callsToStopBleBackend: BleBackendOptions[];
|
|
9
10
|
static callsToSetBleRssiInterval: BleRssiOptions[];
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
static
|
|
11
|
+
static callsToCreateUsbBackend: UsbBackendOptions[];
|
|
12
|
+
static callsToStartUsbBackend: UsbBackendOptions[];
|
|
13
|
+
static callsToWriteUsbBackend: WriteUsbBackendOptions[];
|
|
14
|
+
static callsToStopUsbBackend: UsbBackendOptions[];
|
|
13
15
|
static fakeResult: NativeResult;
|
|
14
16
|
constructor(options?: LibndxAdapterOptions);
|
|
15
17
|
discoverBleUuid(options: DiscoverBleUuidOptions): NativeResult;
|
|
16
18
|
createBleBackend(options: BleBackendOptions): NativeResult;
|
|
17
19
|
startBleBackend(options: StartBleBackendOptions): NativeResult;
|
|
20
|
+
addBleCharCallbacks(options: AddBleCharCallbacksOptions): NativeResult;
|
|
18
21
|
writeBleCharacteristic(options: WriteBleCharacteristicOptions): NativeResult;
|
|
19
22
|
setBleRssiInterval(options: BleRssiOptions): NativeResult;
|
|
20
23
|
stopBleBackend(options: BleBackendOptions): NativeResult;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
createUsbBackend(options: UsbBackendOptions): NativeResult;
|
|
25
|
+
startUsbBackend(options: UsbBackendOptions): NativeResult;
|
|
26
|
+
writeUsbBackend(options: WriteUsbBackendOptions): NativeResult;
|
|
27
|
+
stopUsbBackend(options: UsbBackendOptions): NativeResult;
|
|
24
28
|
static resetTestDouble(): void;
|
|
25
29
|
}
|
|
@@ -3,12 +3,14 @@ export default class FakeLibndx {
|
|
|
3
3
|
static callsToDiscoverBleUuid = [];
|
|
4
4
|
static callsToCreateBleBackend = [];
|
|
5
5
|
static callsToStartBleBackend = [];
|
|
6
|
+
static callsToAddBleCharCallbacks = [];
|
|
6
7
|
static callsToWriteBleCharacteristic = [];
|
|
7
8
|
static callsToStopBleBackend = [];
|
|
8
9
|
static callsToSetBleRssiInterval = [];
|
|
9
|
-
static
|
|
10
|
-
static
|
|
11
|
-
static
|
|
10
|
+
static callsToCreateUsbBackend = [];
|
|
11
|
+
static callsToStartUsbBackend = [];
|
|
12
|
+
static callsToWriteUsbBackend = [];
|
|
13
|
+
static callsToStopUsbBackend = [];
|
|
12
14
|
static fakeResult = { status: 200 };
|
|
13
15
|
constructor(options) {
|
|
14
16
|
FakeLibndx.callsToConstructor.push(options);
|
|
@@ -25,6 +27,10 @@ export default class FakeLibndx {
|
|
|
25
27
|
FakeLibndx.callsToStartBleBackend.push(options);
|
|
26
28
|
return FakeLibndx.fakeResult;
|
|
27
29
|
}
|
|
30
|
+
addBleCharCallbacks(options) {
|
|
31
|
+
FakeLibndx.callsToAddBleCharCallbacks.push(options);
|
|
32
|
+
return FakeLibndx.fakeResult;
|
|
33
|
+
}
|
|
28
34
|
writeBleCharacteristic(options) {
|
|
29
35
|
FakeLibndx.callsToWriteBleCharacteristic.push(options);
|
|
30
36
|
return FakeLibndx.fakeResult;
|
|
@@ -37,16 +43,20 @@ export default class FakeLibndx {
|
|
|
37
43
|
FakeLibndx.callsToStopBleBackend.push(options);
|
|
38
44
|
return FakeLibndx.fakeResult;
|
|
39
45
|
}
|
|
40
|
-
|
|
41
|
-
FakeLibndx.
|
|
46
|
+
createUsbBackend(options) {
|
|
47
|
+
FakeLibndx.callsToCreateUsbBackend.push(options);
|
|
48
|
+
return FakeLibndx.fakeResult;
|
|
49
|
+
}
|
|
50
|
+
startUsbBackend(options) {
|
|
51
|
+
FakeLibndx.callsToStartUsbBackend.push(options);
|
|
42
52
|
return FakeLibndx.fakeResult;
|
|
43
53
|
}
|
|
44
|
-
|
|
45
|
-
FakeLibndx.
|
|
54
|
+
writeUsbBackend(options) {
|
|
55
|
+
FakeLibndx.callsToWriteUsbBackend.push(options);
|
|
46
56
|
return FakeLibndx.fakeResult;
|
|
47
57
|
}
|
|
48
|
-
|
|
49
|
-
FakeLibndx.
|
|
58
|
+
stopUsbBackend(options) {
|
|
59
|
+
FakeLibndx.callsToStopUsbBackend.push(options);
|
|
50
60
|
return FakeLibndx.fakeResult;
|
|
51
61
|
}
|
|
52
62
|
static resetTestDouble() {
|
|
@@ -54,12 +64,14 @@ export default class FakeLibndx {
|
|
|
54
64
|
FakeLibndx.callsToDiscoverBleUuid = [];
|
|
55
65
|
FakeLibndx.callsToCreateBleBackend = [];
|
|
56
66
|
FakeLibndx.callsToStartBleBackend = [];
|
|
67
|
+
FakeLibndx.callsToAddBleCharCallbacks = [];
|
|
57
68
|
FakeLibndx.callsToWriteBleCharacteristic = [];
|
|
58
69
|
FakeLibndx.callsToStopBleBackend = [];
|
|
59
70
|
FakeLibndx.callsToSetBleRssiInterval = [];
|
|
60
|
-
FakeLibndx.
|
|
61
|
-
FakeLibndx.
|
|
62
|
-
FakeLibndx.
|
|
71
|
+
FakeLibndx.callsToCreateUsbBackend = [];
|
|
72
|
+
FakeLibndx.callsToStartUsbBackend = [];
|
|
73
|
+
FakeLibndx.callsToWriteUsbBackend = [];
|
|
74
|
+
FakeLibndx.callsToStopUsbBackend = [];
|
|
63
75
|
}
|
|
64
76
|
}
|
|
65
77
|
//# sourceMappingURL=FakeLibndx.js.map
|
|
@@ -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":"AAcA,MAAM,CAAC,OAAO,OAAO,UAAU;IACpB,MAAM,CAAC,kBAAkB,GAAyC,EAAE,CAAA;IACpE,MAAM,CAAC,sBAAsB,GAA6B,EAAE,CAAA;IAC5D,MAAM,CAAC,uBAAuB,GAAwB,EAAE,CAAA;IACxD,MAAM,CAAC,sBAAsB,GAA6B,EAAE,CAAA;IAC5D,MAAM,CAAC,0BAA0B,GAAiC,EAAE,CAAA;IACpE,MAAM,CAAC,6BAA6B,GACvC,EAAE,CAAA;IACC,MAAM,CAAC,qBAAqB,GAAwB,EAAE,CAAA;IACtD,MAAM,CAAC,yBAAyB,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"}
|
package/package.json
CHANGED
|
@@ -25,7 +25,8 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
25
25
|
private static readonly bleValueToWrite = this.generateId()
|
|
26
26
|
private static readonly bleRssiIntervalMs = Math.random()
|
|
27
27
|
|
|
28
|
-
private static readonly
|
|
28
|
+
private static readonly usbSerialNumber = this.generateId()
|
|
29
|
+
private static readonly usbValueToWrite = this.generateId()
|
|
29
30
|
|
|
30
31
|
private static readonly charCallbacks = [
|
|
31
32
|
{
|
|
@@ -53,6 +54,11 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
53
54
|
onConnected: unknown
|
|
54
55
|
charCallbacks: CharacteristicCallback[]
|
|
55
56
|
}[] = []
|
|
57
|
+
private static readonly callsToAddBleCharCallbacks: {
|
|
58
|
+
uuid: string
|
|
59
|
+
charCallbacks: unknown
|
|
60
|
+
numCallbacks: number
|
|
61
|
+
}[] = []
|
|
56
62
|
private static readonly callsToWriteBle: string[][] = []
|
|
57
63
|
private static readonly callsToSetBleRssiInterval: {
|
|
58
64
|
uuid: string
|
|
@@ -61,9 +67,10 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
61
67
|
}[] = []
|
|
62
68
|
private static readonly callsToStopBle: string[][] = []
|
|
63
69
|
|
|
64
|
-
private static readonly
|
|
65
|
-
private static readonly
|
|
66
|
-
private static readonly
|
|
70
|
+
private static readonly callsToCreateUsb: string[][] = []
|
|
71
|
+
private static readonly callsToStartUsb: string[][] = []
|
|
72
|
+
private static readonly callsToWriteUsb: string[][] = []
|
|
73
|
+
private static readonly callsToStopUsb: string[][] = []
|
|
67
74
|
|
|
68
75
|
protected static async beforeEach() {
|
|
69
76
|
await super.beforeEach()
|
|
@@ -114,12 +121,14 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
114
121
|
'str discover_ble_uuid(str name_prefix, OnDiscoveredFn *on_discovered)',
|
|
115
122
|
'str create_ble_backend(str config)',
|
|
116
123
|
'str start_ble_backend(str uuid, OnConnectedFn *on_connected, CharCallback *callbacks, int num_callbacks)',
|
|
124
|
+
'str add_ble_char_callbacks(str uuid, CharCallback *callbacks, int num_callbacks)',
|
|
117
125
|
'str write_ble_characteristic(str uuid, str charUuid, str value)',
|
|
118
126
|
'str set_ble_rssi_interval(str uuid, int interval_ms, OnRssiFn *on_rssi)',
|
|
119
127
|
'str stop_ble_backend(str uuid)',
|
|
120
|
-
'str
|
|
121
|
-
'str
|
|
122
|
-
'str
|
|
128
|
+
'str create_usb_backend(str config)',
|
|
129
|
+
'str start_usb_backend(str serial)',
|
|
130
|
+
'str write_usb_backend(str serial, str value)',
|
|
131
|
+
'str stop_usb_backend(str serial)',
|
|
123
132
|
],
|
|
124
133
|
'Did not register expected koffi func signatures!'
|
|
125
134
|
)
|
|
@@ -317,6 +326,36 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
317
326
|
)
|
|
318
327
|
}
|
|
319
328
|
|
|
329
|
+
@test()
|
|
330
|
+
protected static async addBleCharCallbacksCallsBindingWithExpectedArgs() {
|
|
331
|
+
this.addBleCharCallbacks()
|
|
332
|
+
|
|
333
|
+
const call = this.callsToAddBleCharCallbacks[0]
|
|
334
|
+
|
|
335
|
+
assert.isEqual(
|
|
336
|
+
call.uuid,
|
|
337
|
+
this.bleDeviceUuid,
|
|
338
|
+
'addBleCharCallbacks did not pass expected uuid to binding!'
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
assert.isEqual(
|
|
342
|
+
call.numCallbacks,
|
|
343
|
+
this.charCallbacks.length,
|
|
344
|
+
'addBleCharCallbacks did not pass expected callback count to binding!'
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@test()
|
|
349
|
+
protected static async addBleCharCallbacksReturnsJson() {
|
|
350
|
+
const json = this.addBleCharCallbacks()
|
|
351
|
+
|
|
352
|
+
assert.isEqualDeep(
|
|
353
|
+
json,
|
|
354
|
+
this.successfulResult,
|
|
355
|
+
'addBleCharCallbacks did not return a JSON string!'
|
|
356
|
+
)
|
|
357
|
+
}
|
|
358
|
+
|
|
320
359
|
@test()
|
|
321
360
|
protected static async writeBleCharacteristicCallsBindingWithExpectedArgs() {
|
|
322
361
|
this.writeBleCharacteristic()
|
|
@@ -414,68 +453,90 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
414
453
|
}
|
|
415
454
|
|
|
416
455
|
@test()
|
|
417
|
-
protected static async
|
|
418
|
-
this.
|
|
456
|
+
protected static async createUsbBackendCallsBindingWithExpectedArgs() {
|
|
457
|
+
this.createUsbBackend()
|
|
419
458
|
|
|
420
459
|
assert.isEqualDeep(
|
|
421
|
-
this.
|
|
422
|
-
JSON.stringify({
|
|
423
|
-
'
|
|
460
|
+
this.callsToCreateUsb[0][0],
|
|
461
|
+
JSON.stringify({ serial_number: this.usbSerialNumber }),
|
|
462
|
+
'createUsbBackend did not call binding with expected args!'
|
|
424
463
|
)
|
|
425
464
|
}
|
|
426
465
|
|
|
427
466
|
@test()
|
|
428
|
-
protected static async
|
|
429
|
-
const json = this.
|
|
467
|
+
protected static async createUsbBackendReturnsJson() {
|
|
468
|
+
const json = this.createUsbBackend()
|
|
430
469
|
|
|
431
470
|
assert.isEqualDeep(
|
|
432
471
|
json,
|
|
433
472
|
this.successfulResult,
|
|
434
|
-
'
|
|
473
|
+
'createUsbBackend did not return a JSON string!'
|
|
435
474
|
)
|
|
436
475
|
}
|
|
437
476
|
|
|
438
477
|
@test()
|
|
439
|
-
protected static async
|
|
440
|
-
this.
|
|
478
|
+
protected static async startUsbBackendCallsBindingWithExpectedArgs() {
|
|
479
|
+
this.startUsbBackend()
|
|
441
480
|
|
|
442
481
|
assert.isEqual(
|
|
443
|
-
this.
|
|
444
|
-
this.
|
|
445
|
-
'
|
|
482
|
+
this.callsToStartUsb[0][0],
|
|
483
|
+
this.usbSerialNumber,
|
|
484
|
+
'startUsbBackend did not call binding with expected args!'
|
|
446
485
|
)
|
|
447
486
|
}
|
|
448
487
|
|
|
449
488
|
@test()
|
|
450
|
-
protected static async
|
|
451
|
-
const json = this.
|
|
489
|
+
protected static async startUsbBackendReturnsJson() {
|
|
490
|
+
const json = this.startUsbBackend()
|
|
452
491
|
|
|
453
492
|
assert.isEqualDeep(
|
|
454
493
|
json,
|
|
455
494
|
this.successfulResult,
|
|
456
|
-
'
|
|
495
|
+
'startUsbBackend did not return a JSON string!'
|
|
457
496
|
)
|
|
458
497
|
}
|
|
459
498
|
|
|
460
499
|
@test()
|
|
461
|
-
protected static async
|
|
462
|
-
this.
|
|
500
|
+
protected static async writeUsbBackendCallsBindingWithExpectedArgs() {
|
|
501
|
+
this.writeUsbBackend()
|
|
502
|
+
|
|
503
|
+
assert.isEqualDeep(
|
|
504
|
+
this.callsToWriteUsb[0],
|
|
505
|
+
[this.usbSerialNumber, this.usbValueToWrite],
|
|
506
|
+
'writeUsbBackend did not call binding with expected args!'
|
|
507
|
+
)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
@test()
|
|
511
|
+
protected static async writeUsbBackendReturnsJson() {
|
|
512
|
+
const json = this.writeUsbBackend()
|
|
513
|
+
|
|
514
|
+
assert.isEqualDeep(
|
|
515
|
+
json,
|
|
516
|
+
this.successfulResult,
|
|
517
|
+
'writeUsbBackend did not return a JSON string!'
|
|
518
|
+
)
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
@test()
|
|
522
|
+
protected static async stopUsbBackendCallsBindingWithExpectedArgs() {
|
|
523
|
+
this.stopUsbBackend()
|
|
463
524
|
|
|
464
525
|
assert.isEqual(
|
|
465
|
-
this.
|
|
466
|
-
this.
|
|
467
|
-
'
|
|
526
|
+
this.callsToStopUsb[0][0],
|
|
527
|
+
this.usbSerialNumber,
|
|
528
|
+
'stopUsbBackend did not call binding with expected args!'
|
|
468
529
|
)
|
|
469
530
|
}
|
|
470
531
|
|
|
471
532
|
@test()
|
|
472
|
-
protected static async
|
|
473
|
-
const json = this.
|
|
533
|
+
protected static async stopUsbBackendReturnsJson() {
|
|
534
|
+
const json = this.stopUsbBackend()
|
|
474
535
|
|
|
475
536
|
assert.isEqualDeep(
|
|
476
537
|
json,
|
|
477
538
|
this.successfulResult,
|
|
478
|
-
'
|
|
539
|
+
'stopUsbBackend did not return a JSON string!'
|
|
479
540
|
)
|
|
480
541
|
}
|
|
481
542
|
|
|
@@ -502,6 +563,13 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
502
563
|
})
|
|
503
564
|
}
|
|
504
565
|
|
|
566
|
+
private static addBleCharCallbacks() {
|
|
567
|
+
return this.instance.addBleCharCallbacks({
|
|
568
|
+
deviceUuid: this.bleDeviceUuid,
|
|
569
|
+
charCallbacks: this.charCallbacks,
|
|
570
|
+
})
|
|
571
|
+
}
|
|
572
|
+
|
|
505
573
|
private static writeBleCharacteristic() {
|
|
506
574
|
return this.instance.writeBleCharacteristic({
|
|
507
575
|
deviceUuid: this.bleDeviceUuid,
|
|
@@ -524,21 +592,28 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
524
592
|
})
|
|
525
593
|
}
|
|
526
594
|
|
|
527
|
-
private static
|
|
528
|
-
return this.instance.
|
|
529
|
-
serialNumber: this.
|
|
595
|
+
private static createUsbBackend() {
|
|
596
|
+
return this.instance.createUsbBackend({
|
|
597
|
+
serialNumber: this.usbSerialNumber,
|
|
598
|
+
})
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
private static startUsbBackend() {
|
|
602
|
+
return this.instance.startUsbBackend({
|
|
603
|
+
serialNumber: this.usbSerialNumber,
|
|
530
604
|
})
|
|
531
605
|
}
|
|
532
606
|
|
|
533
|
-
private static
|
|
534
|
-
return this.instance.
|
|
535
|
-
serialNumber: this.
|
|
607
|
+
private static writeUsbBackend() {
|
|
608
|
+
return this.instance.writeUsbBackend({
|
|
609
|
+
serialNumber: this.usbSerialNumber,
|
|
610
|
+
value: this.usbValueToWrite,
|
|
536
611
|
})
|
|
537
612
|
}
|
|
538
613
|
|
|
539
|
-
private static
|
|
540
|
-
return this.instance.
|
|
541
|
-
serialNumber: this.
|
|
614
|
+
private static stopUsbBackend() {
|
|
615
|
+
return this.instance.stopUsbBackend({
|
|
616
|
+
serialNumber: this.usbSerialNumber,
|
|
542
617
|
})
|
|
543
618
|
}
|
|
544
619
|
|
|
@@ -563,6 +638,14 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
563
638
|
})
|
|
564
639
|
return JSON.stringify(this.successfulResult)
|
|
565
640
|
},
|
|
641
|
+
add_ble_char_callbacks: (args: any) => {
|
|
642
|
+
this.callsToAddBleCharCallbacks.push({
|
|
643
|
+
uuid: args[0],
|
|
644
|
+
charCallbacks: args[1],
|
|
645
|
+
numCallbacks: args[2],
|
|
646
|
+
})
|
|
647
|
+
return JSON.stringify(this.successfulResult)
|
|
648
|
+
},
|
|
566
649
|
write_ble_characteristic: (args) => {
|
|
567
650
|
this.callsToWriteBle.push(args)
|
|
568
651
|
return JSON.stringify(this.successfulResult)
|
|
@@ -579,16 +662,20 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
579
662
|
this.callsToStopBle.push(args)
|
|
580
663
|
return JSON.stringify(this.successfulResult)
|
|
581
664
|
},
|
|
582
|
-
|
|
583
|
-
this.
|
|
665
|
+
create_usb_backend: (args) => {
|
|
666
|
+
this.callsToCreateUsb.push(args)
|
|
667
|
+
return JSON.stringify(this.successfulResult)
|
|
668
|
+
},
|
|
669
|
+
start_usb_backend: (args) => {
|
|
670
|
+
this.callsToStartUsb.push(args)
|
|
584
671
|
return JSON.stringify(this.successfulResult)
|
|
585
672
|
},
|
|
586
|
-
|
|
587
|
-
this.
|
|
673
|
+
write_usb_backend: (args) => {
|
|
674
|
+
this.callsToWriteUsb.push(args)
|
|
588
675
|
return JSON.stringify(this.successfulResult)
|
|
589
676
|
},
|
|
590
|
-
|
|
591
|
-
this.
|
|
677
|
+
stop_usb_backend: (args) => {
|
|
678
|
+
this.callsToStopUsb.push(args)
|
|
592
679
|
return JSON.stringify(this.successfulResult)
|
|
593
680
|
},
|
|
594
681
|
}
|
|
@@ -598,11 +685,13 @@ export default class LibndxAdapterTest extends AbstractPackageTest {
|
|
|
598
685
|
this.callsToDiscoverBle.length = 0
|
|
599
686
|
this.callsToCreateBle.length = 0
|
|
600
687
|
this.callsToStartBle.length = 0
|
|
688
|
+
this.callsToAddBleCharCallbacks.length = 0
|
|
601
689
|
this.callsToStopBle.length = 0
|
|
602
690
|
this.callsToSetBleRssiInterval.length = 0
|
|
603
|
-
this.
|
|
604
|
-
this.
|
|
605
|
-
this.
|
|
691
|
+
this.callsToCreateUsb.length = 0
|
|
692
|
+
this.callsToStartUsb.length = 0
|
|
693
|
+
this.callsToWriteUsb.length = 0
|
|
694
|
+
this.callsToStopUsb.length = 0
|
|
606
695
|
}
|
|
607
696
|
|
|
608
697
|
private static clearAndFakeFfi() {
|
|
@@ -69,6 +69,10 @@ export default class LibndxAdapter implements Libndx {
|
|
|
69
69
|
const wrap1 = (f: (a: string) => string) => (args: [string]) =>
|
|
70
70
|
f(args[0])
|
|
71
71
|
|
|
72
|
+
const wrap2 =
|
|
73
|
+
(f: (a: string, b: string) => string) => (args: [string, string]) =>
|
|
74
|
+
f(args[0], args[1])
|
|
75
|
+
|
|
72
76
|
const wrap3 =
|
|
73
77
|
(f: (a: string, b: string, c: string) => string) =>
|
|
74
78
|
(args: [string, string, string]) =>
|
|
@@ -79,6 +83,11 @@ export default class LibndxAdapter implements Libndx {
|
|
|
79
83
|
(args: [string, unknown, unknown, number]) =>
|
|
80
84
|
f(args[0], args[1], args[2], args[3])
|
|
81
85
|
|
|
86
|
+
const wrapAddBleCharCallbacks =
|
|
87
|
+
(f: (a: string, b: unknown, c: number) => string) =>
|
|
88
|
+
(args: [string, unknown, number]) =>
|
|
89
|
+
f(args[0], args[1], args[2])
|
|
90
|
+
|
|
82
91
|
const wrapSetBleRssiInterval =
|
|
83
92
|
(f: (a: string, b: number, c: unknown) => string) =>
|
|
84
93
|
(args: [string, number, unknown]) =>
|
|
@@ -103,6 +112,11 @@ export default class LibndxAdapter implements Libndx {
|
|
|
103
112
|
'str start_ble_backend(str uuid, OnConnectedFn *on_connected, CharCallback *callbacks, int num_callbacks)'
|
|
104
113
|
)
|
|
105
114
|
),
|
|
115
|
+
add_ble_char_callbacks: wrapAddBleCharCallbacks(
|
|
116
|
+
lib.func(
|
|
117
|
+
'str add_ble_char_callbacks(str uuid, CharCallback *callbacks, int num_callbacks)'
|
|
118
|
+
)
|
|
119
|
+
),
|
|
106
120
|
write_ble_characteristic: wrap3(
|
|
107
121
|
lib.func(
|
|
108
122
|
'str write_ble_characteristic(str uuid, str charUuid, str value)'
|
|
@@ -114,14 +128,17 @@ export default class LibndxAdapter implements Libndx {
|
|
|
114
128
|
)
|
|
115
129
|
),
|
|
116
130
|
stop_ble_backend: wrap1(lib.func('str stop_ble_backend(str uuid)')),
|
|
117
|
-
|
|
118
|
-
lib.func('str
|
|
131
|
+
create_usb_backend: wrap1(
|
|
132
|
+
lib.func('str create_usb_backend(str config)')
|
|
133
|
+
),
|
|
134
|
+
start_usb_backend: wrap1(
|
|
135
|
+
lib.func('str start_usb_backend(str serial)')
|
|
119
136
|
),
|
|
120
|
-
|
|
121
|
-
lib.func('str
|
|
137
|
+
write_usb_backend: wrap2(
|
|
138
|
+
lib.func('str write_usb_backend(str serial, str value)')
|
|
122
139
|
),
|
|
123
|
-
|
|
124
|
-
lib.func('str
|
|
140
|
+
stop_usb_backend: wrap1(
|
|
141
|
+
lib.func('str stop_usb_backend(str serial)')
|
|
125
142
|
),
|
|
126
143
|
}
|
|
127
144
|
}
|
|
@@ -204,6 +221,33 @@ export default class LibndxAdapter implements Libndx {
|
|
|
204
221
|
)
|
|
205
222
|
}
|
|
206
223
|
|
|
224
|
+
public addBleCharCallbacks(options: AddBleCharCallbacksOptions) {
|
|
225
|
+
const { deviceUuid, charCallbacks } = options
|
|
226
|
+
|
|
227
|
+
const registered = charCallbacks.map(
|
|
228
|
+
({ charUuid, charName, onData }) => ({
|
|
229
|
+
charUuid,
|
|
230
|
+
charName,
|
|
231
|
+
onData: LibndxAdapter.koffiRegister(
|
|
232
|
+
onData,
|
|
233
|
+
LibndxAdapter.koffiPointer(
|
|
234
|
+
LibndxAdapter.getCharCallbackProto()!
|
|
235
|
+
)
|
|
236
|
+
),
|
|
237
|
+
})
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
this.registeredCallbacks.push(...registered)
|
|
241
|
+
|
|
242
|
+
return JSON.parse(
|
|
243
|
+
this.bindings.add_ble_char_callbacks([
|
|
244
|
+
deviceUuid,
|
|
245
|
+
registered,
|
|
246
|
+
registered.length,
|
|
247
|
+
])
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
207
251
|
public writeBleCharacteristic(options: WriteBleCharacteristicOptions) {
|
|
208
252
|
const { deviceUuid, charUuid: characteristicUuid, value } = options
|
|
209
253
|
|
|
@@ -238,21 +282,29 @@ export default class LibndxAdapter implements Libndx {
|
|
|
238
282
|
return JSON.parse(this.bindings.stop_ble_backend([deviceUuid]))
|
|
239
283
|
}
|
|
240
284
|
|
|
241
|
-
public
|
|
285
|
+
public createUsbBackend(options: UsbBackendOptions) {
|
|
242
286
|
const { serialNumber } = options
|
|
243
|
-
const configJson = JSON.stringify({ serialNumber })
|
|
287
|
+
const configJson = JSON.stringify({ serial_number: serialNumber })
|
|
244
288
|
|
|
245
|
-
return JSON.parse(this.bindings.
|
|
289
|
+
return JSON.parse(this.bindings.create_usb_backend([configJson]))
|
|
246
290
|
}
|
|
247
291
|
|
|
248
|
-
public
|
|
292
|
+
public startUsbBackend(options: UsbBackendOptions) {
|
|
249
293
|
const { serialNumber } = options
|
|
250
|
-
return JSON.parse(this.bindings.
|
|
294
|
+
return JSON.parse(this.bindings.start_usb_backend([serialNumber]))
|
|
251
295
|
}
|
|
252
296
|
|
|
253
|
-
public
|
|
297
|
+
public writeUsbBackend(options: WriteUsbBackendOptions) {
|
|
298
|
+
const { serialNumber, value } = options
|
|
299
|
+
|
|
300
|
+
return JSON.parse(
|
|
301
|
+
this.bindings.write_usb_backend([serialNumber, value])
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
public stopUsbBackend(options: UsbBackendOptions) {
|
|
254
306
|
const { serialNumber } = options
|
|
255
|
-
return JSON.parse(this.bindings.
|
|
307
|
+
return JSON.parse(this.bindings.stop_usb_backend([serialNumber]))
|
|
256
308
|
}
|
|
257
309
|
|
|
258
310
|
private static getCharCallbackProto() {
|
|
@@ -311,12 +363,14 @@ export interface Libndx {
|
|
|
311
363
|
discoverBleUuid(options: DiscoverBleUuidOptions): NativeResult
|
|
312
364
|
createBleBackend(options: BleBackendOptions): NativeResult
|
|
313
365
|
startBleBackend(options: StartBleBackendOptions): NativeResult
|
|
366
|
+
addBleCharCallbacks(options: AddBleCharCallbacksOptions): NativeResult
|
|
314
367
|
writeBleCharacteristic(options: WriteBleCharacteristicOptions): NativeResult
|
|
315
368
|
setBleRssiInterval(options: BleRssiOptions): NativeResult
|
|
316
369
|
stopBleBackend(options: BleBackendOptions): NativeResult
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
370
|
+
createUsbBackend(options: UsbBackendOptions): NativeResult
|
|
371
|
+
startUsbBackend(options: UsbBackendOptions): NativeResult
|
|
372
|
+
writeUsbBackend(options: WriteUsbBackendOptions): NativeResult
|
|
373
|
+
stopUsbBackend(options: UsbBackendOptions): NativeResult
|
|
320
374
|
}
|
|
321
375
|
|
|
322
376
|
export type LibndxConstructor = new (options?: LibndxAdapterOptions) => Libndx
|
|
@@ -339,6 +393,10 @@ export interface StartBleBackendOptions extends BleBackendOptions {
|
|
|
339
393
|
charCallbacks: CharacteristicCallback[]
|
|
340
394
|
}
|
|
341
395
|
|
|
396
|
+
export interface AddBleCharCallbacksOptions extends BleBackendOptions {
|
|
397
|
+
charCallbacks: CharacteristicCallback[]
|
|
398
|
+
}
|
|
399
|
+
|
|
342
400
|
export interface BleRssiOptions extends BleBackendOptions {
|
|
343
401
|
intervalMs: number
|
|
344
402
|
onRssi: (rssi: number) => void
|
|
@@ -356,20 +414,26 @@ export interface CharacteristicCallback {
|
|
|
356
414
|
onData: (data: Buffer, length: number, timestampSec: number) => void
|
|
357
415
|
}
|
|
358
416
|
|
|
359
|
-
export interface
|
|
417
|
+
export interface UsbBackendOptions {
|
|
360
418
|
serialNumber: string
|
|
361
419
|
}
|
|
362
420
|
|
|
421
|
+
export interface WriteUsbBackendOptions extends UsbBackendOptions {
|
|
422
|
+
value: string
|
|
423
|
+
}
|
|
424
|
+
|
|
363
425
|
export interface LibndxBindings {
|
|
364
426
|
discover_ble_uuid(args: [string, unknown]): string
|
|
365
427
|
create_ble_backend(args: [string]): string
|
|
366
428
|
start_ble_backend(args: [string, unknown, unknown, number]): string
|
|
429
|
+
add_ble_char_callbacks(args: [string, unknown, number]): string
|
|
367
430
|
write_ble_characteristic(args: [string, string, string]): string
|
|
368
431
|
set_ble_rssi_interval(args: [string, number, unknown]): string
|
|
369
432
|
stop_ble_backend(args: [string]): string
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
433
|
+
create_usb_backend(args: [string]): string
|
|
434
|
+
start_usb_backend(args: [string]): string
|
|
435
|
+
write_usb_backend(args: [string, string]): string
|
|
436
|
+
stop_usb_backend(args: [string]): string
|
|
373
437
|
}
|
|
374
438
|
|
|
375
439
|
export interface NativePeripheral {
|