-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbluetooth.js
55 lines (43 loc) · 2.24 KB
/
bluetooth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const $ = require('nodobjc');
$.framework('CoreBluetooth');
$.framework('IOBluetooth');
const ANNE_PRO_SERVICE_UUID = $('f000ffc0-0451-4000-b000-000000000000');
const ANNE_PRO_READ_UUID = $('f000ffc1-0451-4000-b000-000000000000');
const ANNE_PRO_WRITE_UUID = $('f000ffc2-0451-4000-b000-000000000000');
const CentralManager = $.CBCentralManager('alloc');
const CBUUID = $.CBUUID('alloc');
const anneProServiceCBUUID = CBUUID('initWithString', ANNE_PRO_SERVICE_UUID);
console.log('anneProServiceCBUUID', anneProServiceCBUUID);
const CBCentralManagerDelegate = $.NSObject.extend('CBCentralManagerDelegate');
CBCentralManagerDelegate.addMethod('centralManagerDidUpdateState:', 'v@:@', function ($self, $_cmd, $centralManager) {
console.log('stateUpdate', arguments);
});
CBCentralManagerDelegate.addMethod('centralManager:didDiscoverPeripheral:advertisementData:RSSI:',
'v@:@@@@', function ($self, $_cmd, $centralManager, $peripheral, $advertisementData, $RSSI) {
console.log('didDiscoverPeripheral', arguments);
});
CBCentralManagerDelegate.addMethod('centralManager:didConnectPeripheral:',
'v@:@@', function ($self, $_cmd, $centralManager, $peripheral) {
console.log('didConnectPeripheral', arguments);
});
const delegate = CBCentralManagerDelegate('alloc')('init');
const centralManager = CentralManager('initWithDelegate', delegate, 'queue', null);
console.log('delegate', delegate);
console.log('delegate', centralManager('delegate'));
const array = $.NSMutableArray('alloc')('init');
array('addObject', anneProServiceCBUUID);
const peripherals = centralManager('retrieveConnectedPeripheralsWithServices', array);
const count = peripherals('count');
if (count < 1) {
console.log('No Anne Pro found');
process.exit(1);
}
const peripheral = peripherals('objectAtIndex', 0);
console.log('peripheral', peripheral);
// console.log('services', peripheral('services'));
peripheral('discoverServices:');
// console.log('peripheral.methods()', peripheral.methods());
// peripheral('discoverCharacteristics:forService:', )
// centralManager('connectPeripheral', peripheral, 'options', null);
// console.log('CBCentralManagerDelegate', CBCentralManagerDelegate);
// setTimeout(() => console.log('done'), 30000);