continuing

This commit is contained in:
Martin Donnelly 2016-07-06 16:15:40 +01:00
parent f9de9bd79a
commit ae2a3aa6c5

View File

@ -9,6 +9,7 @@
var cp = require('child_process');
var spawn = cp.spawn;
var fork = cp.fork;
var spawnP = require('child-process-promise').spawn;
var EventEmitter = require('events');
var busEmitter = new EventEmitter();
@ -32,6 +33,51 @@ var bluetest = module.exports = function(options) {
core.gatt.stdin.write('primary\n');
};
core.connectGattP = function() {
core.gatt = spawn('gatttool',['-I']);
var child = core.gatt.childProcess;
child.on('error', function(err) {
logger.error('child',err);
});
child.on('exit', function(code) {
logger.debug('child','gatt exit code', code);
});
child.on('message', function(m) {
logger.info('child',m);
});
child.stdout.on('data', (data) => {
logger.info('child',`stdout: ${data}`);
if (data.indexOf('Connection successful') > -1) {
busEmitter.emit('child','connected');
}
});
child.stderr.on('data', (data) => {
logger.info('child',`stderr: ${data}`);
});
child.on('close', (code) => {
logger.warn('child',`child process exited with code ${code}`);
});
core.gatt.then(function () {
console.log('[spawn] done!');
})
.catch(function (err) {
console.error('[spawn] ERROR: ', err);
});
};
core.connectGatt = function() {
logger.info('trying to connect using gatttool');
core.gatt = spawn('gatttool',['-I']);
@ -105,7 +151,7 @@ var bluetest = module.exports = function(options) {
} else {
core.connectGatt();
core.connectGattP();
}