devicestack
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -9,3 +9,3 @@ var index; | ||
index.VERSION = '0.0.1'; | ||
index.VERSION = require('./package.json').version; | ||
@@ -12,0 +12,0 @@ require('./util/index'); |
@@ -24,3 +24,3 @@ var util = require('util') | ||
this.currentState = { | ||
connectionMode: 'autoconnectOne', | ||
connectionMode: 'manualconnect', | ||
plugged: [], | ||
@@ -99,9 +99,12 @@ connected: [], | ||
DeviceGuider.prototype.checkConnectionMode = function(mode) { | ||
return mode !== this.currentState.connectionMode; | ||
}; | ||
DeviceGuider.prototype.changeConnectionMode = function(mode) { | ||
var somethingChanged = false; | ||
var self = this; | ||
if (mode !== this.currentState.connectionMode) { | ||
somethingChanged = true; | ||
this.currentState.connectionMode = mode; | ||
} | ||
var somethingChanged = this.checkConnectionMode(mode); | ||
this.currentState.connectionMode = mode; | ||
@@ -143,5 +146,12 @@ if (somethingChanged) { | ||
DeviceGuider.prototype.manualconnect = function(callback) { | ||
DeviceGuider.prototype.manualconnect = function(holdConnections, callback) { | ||
var self = this; | ||
if (arguments.length === 1) { | ||
if (_.isFunction(holdConnections)) { | ||
callback = holdConnections; | ||
holdConnections = false; | ||
} | ||
} | ||
if (this.changeConnectionMode('manualconnect')) { | ||
@@ -152,7 +162,11 @@ if (this.currentState.connected.length === 0) { | ||
async.forEachSeries(this.currentState.connected, function(dc, clb) { | ||
self.closeConnection(dc.connection, clb); | ||
}, function(err) { | ||
if (callback) { return callback(err); } | ||
}); | ||
if (!holdConnections) { | ||
async.forEachSeries(this.currentState.connected, function(dc, clb) { | ||
self.closeConnection(dc.connection, clb); | ||
}, function(err) { | ||
if (callback) { return callback(err); } | ||
}); | ||
} else { | ||
if (callback) { return callback(null); } | ||
} | ||
} else { | ||
@@ -159,0 +173,0 @@ if (callback) { return callback(null); } |
@@ -50,3 +50,3 @@ var EventEmitter2 = require('eventemitter2').EventEmitter2 | ||
DeviceLoader.prototype.startLookup = function(interval) { | ||
DeviceLoader.prototype.startLookup = function(interval, callback) { | ||
if (this.lookupIntervalId) { | ||
@@ -56,9 +56,24 @@ this.stopLookup(); | ||
if (!callback && _.isFunction(interval)) { | ||
callback = interval; | ||
interval = null; | ||
} | ||
var self = this; | ||
interval = interval || 300; | ||
interval = interval || 150; | ||
this.oldDevices = []; | ||
this.lookupIntervalId = setInterval(function() { | ||
self.trigger(); | ||
}, interval); | ||
this.trigger(function(err, devices) { | ||
var triggering = false; | ||
self.lookupIntervalId = setInterval(function() { | ||
if (triggering) return; | ||
triggering = true; | ||
self.trigger(function() { | ||
triggering = false; | ||
}); | ||
}, interval); | ||
if (callback) { callback(err, devices); } | ||
}); | ||
}; | ||
@@ -65,0 +80,0 @@ |
@@ -22,19 +22,7 @@ var EventEmitter2 = require('eventemitter2').EventEmitter2 | ||
if (deviceOrFrameHandler) { | ||
var incomming = []; | ||
this.incomming = []; | ||
deviceOrFrameHandler.on('receive', function (frame) { | ||
var unwrappedFrame; | ||
if (self.analyzeNextFrame) { | ||
// extract frames, ananylze stuff | ||
incomming = incomming.concat(Array.prototype.slice.call(frame, 0)); | ||
var nextFrame = null; | ||
while ((nextFrame = self.analyzeNextFrame(incomming))) { | ||
if (self.unwrapFrame) { | ||
unwrappedFrame = self.unwrapFrame(_.clone(nextFrame)); | ||
if (self.log) self.log('receive unwrapped frame: ' + unwrappedFrame.toHexDebug()); | ||
self.emit('receive', unwrappedFrame); | ||
} else { | ||
if (self.log) self.log('receive frame: ' + nextFrame.toHexDebug()); | ||
self.emit('receive', nextFrame); | ||
} | ||
} | ||
self.incomming = self.incomming.concat(Array.prototype.slice.call(frame, 0)); | ||
} else { | ||
@@ -71,2 +59,4 @@ if (self.unwrapFrame) { | ||
}); | ||
this.start(); | ||
} | ||
@@ -76,2 +66,51 @@ | ||
FrameHandler.prototype.start = function(interval, callback) { | ||
if (!callback && _.isFunction(interval)) { | ||
callback = interval; | ||
interval = null; | ||
} | ||
if (!this.analyzeNextFrame) { | ||
if (callback) { callback(null); } | ||
return; | ||
} | ||
if (this.lookupIntervalId) { | ||
this.stopLookup(); | ||
} | ||
var self = this; | ||
interval = interval || 50; | ||
var analyzing = false; | ||
this.lookupIntervalId = setInterval(function() { | ||
if (analyzing) { | ||
return; | ||
} | ||
analyzing = true; | ||
var nextFrame; | ||
while ((nextFrame = self.analyzeNextFrame(self.incomming))) { | ||
if (self.unwrapFrame) { | ||
unwrappedFrame = self.unwrapFrame(_.clone(nextFrame)); | ||
if (self.log) self.log('receive unwrapped frame: ' + unwrappedFrame.toHexDebug()); | ||
self.emit('receive', unwrappedFrame); | ||
} else { | ||
if (self.log) self.log('receive frame: ' + nextFrame.toHexDebug()); | ||
self.emit('receive', nextFrame); | ||
} | ||
} | ||
analyzing = false; | ||
}, interval); | ||
if (callback) { callback(null); } | ||
}; | ||
FrameHandler.prototype.stop = function() { | ||
if (this.lookupIntervalId) { | ||
clearInterval(this.lookupIntervalId); | ||
this.lookupIntervalId = null; | ||
} | ||
}; | ||
FrameHandler.prototype.send = function(data) { | ||
@@ -78,0 +117,0 @@ this.emit('send', data); |
{ | ||
"name": "devicestack", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "This module helps you to represent a device and its protocol.", | ||
@@ -17,3 +17,2 @@ "private": false, | ||
"eventemitter2": ">=0.4.10", | ||
"serialport": ">=1.0.8", | ||
"lodash": ">=0.8.2", | ||
@@ -23,2 +22,5 @@ "node-uuid": ">=1.4.0", | ||
}, | ||
"optionalDependencies": { | ||
"serialport": ">=1.0.8" | ||
}, | ||
"devDependencies": { | ||
@@ -29,3 +31,3 @@ "mocha": ">=1.0.1", | ||
"scripts": { | ||
"test": "mocha test/deviceTest.js && mocha test/connectionTest.js && mocha test/framehandlerTest.js && mocha test/deviceloaderTest.js && mocha test/deviceguiderTest.js" | ||
"test": "mocha" | ||
}, | ||
@@ -32,0 +34,0 @@ "repository": { |
@@ -12,5 +12,8 @@ var expect = require('expect.js') | ||
beforeEach(function() { | ||
connection = new Connection(device); | ||
}); | ||
it('it should have all expected values', function() { | ||
connection = new Connection(device); | ||
expect(connection.id).to.be.a('string'); | ||
@@ -17,0 +20,0 @@ expect(connection.close).to.be.a('function'); |
@@ -23,16 +23,2 @@ var expect = require('expect.js') | ||
describe('having plugged devices', function() { | ||
it('it should emit plug', function(done) { | ||
deviceguider.once('plug', function(device) { | ||
expect(device).to.be.an('object'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('calling getCurrentState', function() { | ||
@@ -137,2 +123,3 @@ | ||
deviceguider.autoconnectOne(function(err, connection) { | ||
expect(connection).to.be.ok(err); | ||
expect(connection).to.be.an('object'); | ||
@@ -139,0 +126,0 @@ |
var expect = require('expect.js') | ||
, deviceloader = require('./fixture/deviceloader'); | ||
, deviceloader = require('./fixture/deviceloader').create(); | ||
@@ -4,0 +4,0 @@ describe('DeviceLoader', function() { |
var DeviceGuider = require('../../index').DeviceGuider | ||
, util = require('util') | ||
, deviceLoader = require('./deviceloader'); | ||
, util = require('util'); | ||
@@ -8,3 +7,3 @@ function MyDeviceGuider() { | ||
// call super class | ||
DeviceGuider.call(this, deviceLoader); | ||
DeviceGuider.call(this, require('./deviceloader').create()); | ||
} | ||
@@ -11,0 +10,0 @@ |
@@ -12,2 +12,4 @@ var DeviceLoader = require('../../index').DeviceLoader | ||
this.Device = Device; | ||
this.startDevices = [ | ||
@@ -30,2 +32,5 @@ new Device(), | ||
module.exports = new MyDeviceLoader(); | ||
module.exports = new MyDeviceLoader(); | ||
module.exports.create = function() { | ||
return new MyDeviceLoader(); | ||
}; |
@@ -20,2 +20,13 @@ if (!Array.prototype.toHexDebug) { | ||
}; | ||
} | ||
if (!Array.prototype.toNumber) { | ||
Array.prototype.toNumber = function() { | ||
var value = 0; | ||
for ( var i = 0; i < this.length; i++) { | ||
value = (value * 256) + this[i]; | ||
} | ||
return value; | ||
}; | ||
} |
require('./array'); | ||
require('./buffer'); | ||
require('./buffer'); | ||
require('./number'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61818
32
1330
- Removedserialport@>=1.0.8