continuing

This commit is contained in:
Martin Donnelly 2016-07-06 14:50:09 +01:00
parent ec53900dc5
commit 96aafb1e07

View File

@ -21,38 +21,47 @@ var bluetest = module.exports = function(options) {
'use strict';
var core = {
mac:''
mac: '',
gatt: null
};
core.gattConnected = function() {
};
core.connectGatt = function() {
logger.info('trying to connect using gatttool');
var gatt = spawn('gatttool',['-I']);
core.gatt = spawn('gatttool',['-I']);
var cStr;
gatt.on('error', function(err) {
core.gatt.on('error', function(err) {
logger.error(err);
});
gatt.on('exit', function(code) {
core.gatt.on('exit', function(code) {
logger.debug('gatt exit code', code);
});
gatt.on('message', function(m) {
core.gatt.on('message', function(m) {
logger.info(m);
});
core.gatt.stdout.on('data', (data) => {
gatt.stdout.on('data', (data) => {
logger.info(`stdout: ${data}`);
if (data.indexOf('Connection successful') > -1) {
logger.debug('Gatt connected!!!!!');
busEmitter.emit('connected');
}
});
gatt.stderr.on('data', (data) => {
core.gatt.stderr.on('data', (data) => {
logger.info(`stderr: ${data}`);
});
gatt.on('close', (code) => {
core.gatt.on('close', (code) => {
logger.warn(`child process exited with code ${code}`);
});
@ -60,8 +69,8 @@ var bluetest = module.exports = function(options) {
logger.info('Trying to connect to ', core.mac);
cStr = 'connect ' + core.mac + '\n';
gatt.stdin.write(cStr);
gatt.stdin.write('primary');
core.gatt.stdin.write(cStr);
};
@ -71,7 +80,6 @@ var bluetest = module.exports = function(options) {
var tool_path = '';
var hcidev = 'hvi0';
//If ()
if (typeof options.mac !== 'undefined') {
core.mac = options.mac;
} else {