devicestack
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -1,3 +0,18 @@ | ||
function Command() {} | ||
var _ = require('lodash'); | ||
function Command() { | ||
var self = this; | ||
if (this.log) { | ||
this.log = _.wrap(this.log, function(func, msg) { | ||
func(self.constructor.name + ': ' + msg); | ||
}); | ||
} else if (Command.prototype.log) { | ||
Command.prototype.log = _.wrap(Command.prototype.log, function(func, msg) { | ||
func(self.constructor.name + ': ' + msg); | ||
}); | ||
this.log = Command.prototype.log; | ||
} | ||
} | ||
/** | ||
@@ -4,0 +19,0 @@ * Executes this command. |
@@ -130,2 +130,5 @@ var util = require('util'), | ||
/* Same as removeListener */ | ||
DeviceGuider.prototype.off = DeviceGuider.prototype.removeListener; | ||
/** | ||
@@ -132,0 +135,0 @@ * Checks if the connectionMode will change and returns true or false. |
@@ -39,3 +39,7 @@ var DeviceGuider = require('./deviceguider'), | ||
SerialDeviceGuider.prototype.connect = function(port, callback) { | ||
this.connectDevice(new this.deviceLoader.Device(port), callback); | ||
var device = this.currentState.getDeviceByPort(port); | ||
if (!device) { | ||
device = new this.deviceLoader.Device(port); | ||
} | ||
this.connectDevice(device, callback); | ||
}; | ||
@@ -42,0 +46,0 @@ |
var _ = require('lodash'); | ||
function Task() {} | ||
function Task() { | ||
var self = this; | ||
if (this.log) { | ||
this.log = _.wrap(this.log, function(func, msg) { | ||
func(self.constructor.name + ': ' + msg); | ||
}); | ||
} else if (Task.prototype.log) { | ||
Task.prototype.log = _.wrap(Task.prototype.log, function(func, msg) { | ||
func(self.constructor.name + ': ' + msg); | ||
}); | ||
this.log = Task.prototype.log; | ||
} | ||
} | ||
Task.prototype.perform = function(connection, callback) { | ||
@@ -49,2 +62,3 @@ throw new Error('Implement the perform function!'); | ||
if (this.log) { this.log('Start executing TASK: ' + taskOrCommand.constructor.name); } | ||
connection.executeTask(taskOrCommand, ignoreQueue, callback); | ||
@@ -54,2 +68,3 @@ | ||
if (this.log) { this.log('Start executing COMMAND: ' + taskOrCommand.constructor.name); } | ||
taskOrCommand.execute(connection, callback); | ||
@@ -59,2 +74,3 @@ | ||
if (this.log) { this.log('Start executing...'); } | ||
connection.executeTask(this, ignoreQueue, callback); | ||
@@ -61,0 +77,0 @@ |
{ | ||
"name": "devicestack", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "This module helps you to represent a device and its protocol.", | ||
@@ -23,3 +23,3 @@ "private": false, | ||
"optionalDependencies": { | ||
"serialport": "https://github.com/adrai/node-serialport/tarball/master" | ||
"serialport": "https://github.com/KABA-CCEAC/node-serialport.git/node-serialport/tarball/master" | ||
}, | ||
@@ -26,0 +26,0 @@ "devDependencies": { |
@@ -343,3 +343,3 @@ <pre> | ||
Converts a byte array to a number. | ||
[0x01, 0x00].toNumber() // returns 64 | ||
[0x01, 0x00].toNumber() // returns 256 | ||
@@ -366,6 +366,14 @@ ### array | toBuffer | ||
### buffer | toNumber | ||
Converts a buffer object to a number. | ||
(new Buffer([0x01, 0x00])).toNumber() // returns 256 | ||
### number | toArray | ||
Converts a number to a byte array. | ||
64.toArray() // returns [0x01, 0x00] | ||
(256).toArray() // returns [0x01, 0x00] | ||
### number | toBuffer | ||
Converts a number to a buffer object. | ||
(256).toArray() // returns [0x01, 0x00] | ||
### string | toArray | ||
@@ -372,0 +380,0 @@ Converts a hex string to a byte array. |
@@ -65,3 +65,3 @@ if (!Array.prototype.toHexDebug) { | ||
* @example: | ||
* [0x01, 0x00].toNumber(); // returns 64 | ||
* [0x01, 0x00].toNumber(); // returns 256 | ||
*/ | ||
@@ -68,0 +68,0 @@ Array.prototype.toNumber = function() { |
@@ -35,2 +35,21 @@ if (!Buffer.prototype.toHexDebug) { | ||
}; | ||
} | ||
if (!Buffer.prototype.toNumber) { | ||
/** | ||
* Converts a buffer object to a number. | ||
* @return {Number} The result number. | ||
* | ||
* @example: | ||
* new Buffer([0x01, 0x00]).toNumber(); // returns 256 | ||
*/ | ||
Buffer.prototype.toNumber = function() { | ||
var value = 0; | ||
for ( var i = 0; i < this.length; i++) { | ||
value = (value * 256) + this[i]; | ||
} | ||
return value; | ||
}; | ||
} |
@@ -9,3 +9,3 @@ if (!Number.prototype.toArray) { | ||
* @example: | ||
* 64.toArray(); // returns [0x01, 0x00] | ||
* (256).toArray(); // returns [0x01, 0x00] | ||
*/ | ||
@@ -37,2 +37,14 @@ Number.prototype.toArray = function(size) { | ||
}; | ||
/** | ||
* Converts a number to a buffer object. | ||
* @param {Number} size The size of the array . [optional] | ||
* @return {Buffer} The result array. | ||
* | ||
* @example: | ||
* (256).toBuffer(); // returns [0x01, 0x00] | ||
*/ | ||
Number.prototype.toBuffer = function(size) { | ||
return new Buffer(this.toArray(size)); | ||
}; | ||
} |
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
93505
2007
738