Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use debug() instead of console.log() in index.js #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Able = require('./lib/able');

var util = require('util');
var debug = require('debug')('BleAncs');
var debug = require('debug');
var debugStatus = debug('ble-ancs:status');
var debugNotifications = debug('ble-ancs:notifications');
var events = require('events');

var AblePrimaryService = require('./lib/primary-service.js');
Expand Down Expand Up @@ -37,12 +39,12 @@ util.inherits(BleAncs, events.EventEmitter);
BleAncs.prototype.discoverServicesAndCharacteristics = function(callback) {
this._peripheral.findServiceAndCharacteristics(SERVICE_UUID, [], function(error, services, characteristics) {
for (var i in characteristics) {
/* console.log("CHARECTERISTIC: "+characteristics[i]);
/* debugStatus("CHARECTERISTIC: "+characteristics[i]);
if (characteristics[i].uuid == NOTIFICATION_SOURCE_UUID) {
console.log("NOTIFICATION_SOURCE_UUID");
debugStatus("NOTIFICATION_SOURCE_UUID");
}
if (characteristics[i].uuid == DATA_SOURCE_UUID) {
console.log("DATA_SOURCE_UUID");
debugStatus("DATA_SOURCE_UUID");
}*/
this._characteristics[characteristics[i].uuid] = characteristics[i];
}
Expand All @@ -52,7 +54,7 @@ BleAncs.prototype.discoverServicesAndCharacteristics = function(callback) {

this._characteristics[NOTIFICATION_SOURCE_UUID].notify(true);
this._characteristics[DATA_SOURCE_UUID].notify(true);

callback();
}.bind(this));
};
Expand All @@ -61,11 +63,11 @@ BleAncs.prototype.onNotification = function(data) {
var notification = new Notification(this, data);

if (notification.event == 'removed') {
debug('Notification Removed: ' + notification);
debugNotifications('Notification Removed: ' + notification);
} else if (notification.event == 'added') {
debug('Notification Added: ' + notification);
debugNotifications('Notification Added: ' + notification);
} else if (notification.event == 'added') {
debug('Notification Modified: ' + notification);
debugNotifications('Notification Modified: ' + notification);
}

if (notification.uid in this._notifications) {
Expand Down Expand Up @@ -114,7 +116,7 @@ BleAncs.prototype.requestNotificationAttribute = function(uid, attributeId, maxL


BleAncs.prototype.onStateChange = function(state) {
console.log('on -> stateChange: ' + state);
debugStatus('on -> stateChange: ' + state);

if (state === 'poweredOn') {
if (this._able.startAdvertisingWithEIRData) {
Expand Down Expand Up @@ -156,7 +158,7 @@ BleAncs.prototype.onStateChange = function(state) {

BleAncs.prototype.onAccept = function(peripheral) {

console.log('on -> accept: ' );
debugStatus('on -> accept: ' );
this._peripheral = peripheral;


Expand All @@ -167,7 +169,7 @@ BleAncs.prototype.onAccept = function(peripheral) {

BleAncs.prototype.onAdvertisingStart = function(error) {

console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));
debugStatus('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));

this._able.setServices( [ new AblePrimaryService({
uuid: '13333333333333333333333333333337', //'7905f431b5ce4e99a40f4b1e122d00d0',
Expand All @@ -182,22 +184,22 @@ BleAncs.prototype.onMtuChange = function() {


BleAncs.prototype.onEncryptChange = function() {
console.log("able encryptChange!!!");
debugStatus("able encryptChange!!!");
this.discoverServicesAndCharacteristics(function() {
});
};


BleAncs.prototype.onEncryptFail = function() {
console.log("able -> encryptFail");
debugStatus("able -> encryptFail");
};

BleAncs.prototype.onConnect = function() {
console.log('able -> connect');
debugStatus('able -> connect');
};

BleAncs.prototype.onDisconnect = function() {
console.log('Got a disconnect');
debugStatus('Got a disconnect');



Expand Down
28 changes: 14 additions & 14 deletions lib/hci-socket/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var AbleBindings = function() {

this._hci.on('addressChange', this.onAddressChange.bind(this));


this._gap.on('scanStart', this.onScanStart.bind(this));
this._gap.on('scanStop', this.onScanStop.bind(this));
this._gap.on('discover', this.onDiscover.bind(this));
Expand Down Expand Up @@ -77,7 +77,7 @@ AbleBindings.prototype.connect = function(peripheralUuid) {
var address = this._addresses[peripheralUuid];
var addressType = this._addresseTypes[peripheralUuid];

console.log("Connect - uuid: " + peripheralUuid + " addres: " + address);
debug("Connect - uuid: " + peripheralUuid + " addres: " + address);
if (!this._pendingConnection) {
this._pendingConnection = true;

Expand Down Expand Up @@ -133,13 +133,13 @@ AbleBindings.prototype.onStateChange = function(state) {


if (state === 'unauthorized') {
console.log('able warning: adapter state unauthorized, please run as root or with sudo');
console.log(' or see README for information on running without root/sudo:');
console.log(' https://github.com/sandeepmistry/able#running-on-linux');
debug('able warning: adapter state unauthorized, please run as root or with sudo');
debug(' or see README for information on running without root/sudo:');
debug(' https://github.com/sandeepmistry/able#running-on-linux');
} else if (state === 'unsupported') {
console.log('able warning: adapter does not support Bluetooth Low Energy (BLE, Bluetooth Smart).');
console.log(' Try to run with environment variable:');
console.log(' [sudo] NOBLE_HCI_DEVICE_ID=x node ...');
debug('able warning: adapter does not support Bluetooth Low Energy (BLE, Bluetooth Smart).');
debug(' Try to run with environment variable:');
debug(' [sudo] NOBLE_HCI_DEVICE_ID=x node ...');
}

this.emit('stateChange', state);
Expand Down Expand Up @@ -205,7 +205,7 @@ AbleBindings.prototype.onLeConnComplete = function(status, handle, role, address
this._handles[uuid] = handle;
this._handles[handle] = uuid;



this._gatts[handle].on('mtu', this.onMtu.bind(this));
this._gatts[handle].on('servicesDiscover', this.onServicesDiscovered.bind(this));
Expand Down Expand Up @@ -234,10 +234,10 @@ AbleBindings.prototype.onLeConnComplete = function(status, handle, role, address
//this._gatts[handle].setServices([]);
this._gatt.setAclStream(aclStream);
this._gatts[handle]._handles = [];
console.log("Bleno: Handle: " + handle + " UUID: " + uuid + " address " + address);
debug("Bleno: Handle: " + handle + " UUID: " + uuid + " address " + address);
if (this._connectionQueue.length > 0) {
var peripheralUuid = this._connectionQueue.shift();
console.log("Perh: " + peripheralUuid + " address: " + address);
debug("Perh: " + peripheralUuid + " address: " + address);
}

this._addresses[uuid] = address;
Expand Down Expand Up @@ -269,7 +269,7 @@ AbleBindings.prototype.onLeConnUpdateComplete = function(status, handle, interva
if (status === 0) {
//end bleno code
debug('\t\taddress: ' + this._address);
debug('\t\thandle: ' + this._handle);
debug('\t\thandle: ' + this._handle);
debug('\t\tgatt: ' + this._gatts[handle]);
debug('\t\thandles: ' + this._handles[handle]);
} else {
Expand All @@ -281,7 +281,7 @@ AbleBindings.prototype.onLeConnUpdateComplete = function(status, handle, interva
AbleBindings.prototype.onDisconnComplete = function(handle, reason) {
debug('disconnComplete');
var uuid = this._handles[handle];
console.log('\t\tHande:' + handle + '\tuuid: ' + uuid );
debug('\t\tHande:' + handle + '\tuuid: ' + uuid );
if (uuid) {
this._aclStreams[handle].push(null, null);
this._gatts[handle].removeAllListeners();
Expand Down Expand Up @@ -344,7 +344,7 @@ AbleBindings.prototype.onEncryptChange = function(handle, encrypt) {
/* if (this._handle === handle && this._aclStream) {
this._aclStream.pushEncrypt(encrypt);
}*/


var aclStream = this._aclStreams[handle];
debug("onEncryptChange: " + handle);
Expand Down
6 changes: 3 additions & 3 deletions lib/hci-socket/smp.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ util.inherits(Smp, events.EventEmitter);


Smp.prototype.sendPairingRequest = function() {
console.log("Sending pairing request");
debug("Sending pairing request");
this._preq = new Buffer([
SMP_PAIRING_REQUEST,
0x03, //0x04, // IO capability: NoInputNoOutput
Expand All @@ -73,7 +73,7 @@ Smp.prototype.sendPairingRequest = function() {

Smp.prototype.handlePairingRequest = function(data) {
this._preq = data;
console.log("Recieved a Pairing Request");
debug("Recieved a Pairing Request");
this._pres = new Buffer([
SMP_PAIRING_RESPONSE,
0x03, // IO capability: NoInputNoOutput
Expand All @@ -91,7 +91,7 @@ Smp.prototype.handlePairingRequest = function(data) {
/*
Smp.prototype.handlePairingRequest = function(data) {
this._preq = data;
console.log("Recieved a Pairing Request");
debug("Recieved a Pairing Request");
this._pres = new Buffer([
SMP_PAIRING_RESPONSE,
0x03, // IO capability: NoInputNoOutput
Expand Down