Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bglib

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bglib - npm Package Compare versions

Comparing version 0.0.8 to 0.0.14

lib/bglib-errors-change.js

127

bglib.js

@@ -1,8 +0,6 @@

var libRes = require('./libs/bglib-responses');
var libEvent = require('./libs/bglib-events');
var libRes = require('./lib/bglib-responses');
var libEvent = require('./lib/bglib-events');
var _bglibPMode = 0;
var DEBUG = 1;
var DEBUG = 0;
var _bgmessageType = {

@@ -344,3 +342,3 @@ Command : 0 << 7,

bglib.prototype.setPacketMode = function(pMode) {
this.packetMode = true;
this.packetMode = pMode;
}

@@ -423,3 +421,2 @@

// Eventually do something smarter here
console.log("Yeah, it was maybe here...")
console.log(e);

@@ -434,3 +431,2 @@ continue;

};
// Return all the packets

@@ -522,2 +518,3 @@ callback && callback(err, parsedReturn);

}
var packet = new Packet(type_hilen & 0x80, type_hilen & 0x08, cls, command, payload, this.packetMode);

@@ -544,63 +541,8 @@

/************************************************
Temporary Buffer methods. Will be removed once Tessel
natively supports Buffer concat and slice
************************************************/
Buffer.concat = function(bufArray, optionalLength) {
var len = 0;
var buffer;
if (!optionalLength) {
for (var i = 0; i < bufArray.length; i++) {
len += bufArray[i].length;
}
buffer = new Buffer(len);
}
else {
buffer = new Buffer(optionalLength);
}
var index = 0;
for (var i = 0; i < bufArray.length; i++) {
for (var j = 0; j < bufArray[i].length; j++) {
buffer[index++] = bufArray[i][j];
}
}
return buffer;
bglib.prototype.debugPacket = function(packet) {
for (var i = 0; i < packet.length; i++) {
console.log("Byte at index", i, "is", packet[i]);
}
}
Buffer.prototype.slice = function(start, end) {
var len = this.length;
start = ~~start;
end = (end == undefined) ? len : ~~end;
if (start < 0) {
start += len;
if (start < 0) start = 0;
}
else if (start > len) {
start = len;
}
if (end < 0) {
end += len;
if (end < 0)
end = 0;
} else if (end > len) {
end = len;
}
if (end < start)
end = start;
var newLen = end-start;
var buf = new Buffer(newLen);
for (var i = 0; i < newLen; i++) {
buf[i] = this[start + i];
}
return buf;
}
/*******************************************************/

@@ -616,3 +558,3 @@

// To allow consumers to not pass in an empty array when
// To allow users to not pass in an empty array when
// they don't have params, check if the callback

@@ -641,2 +583,3 @@ // was passed as second argument

}
var paramCode = command.paramCode;

@@ -653,3 +596,3 @@

// This parameter should be 32 bits
// This parameter is 32 bits
case 7:

@@ -663,3 +606,4 @@ case 6:

} else {
}
else {
// Add each byte of param to array

@@ -702,3 +646,6 @@ var rBuf = new Buffer(4);

case 8:
var data = [];
if (!Array.isArray(param) && typeof param != "string") {
return callback && callback(new Error("Invalid parameter type. Should be an Array or string"));
}
var dataLength = param.length;

@@ -708,11 +655,9 @@

command.header.payloadLowBits = totalPacketSize & 0xFF
command.header.payloadHighBits = totalPacketSize >> 8
data.push(dataLength);
data.push(param);
command.header.payloadLowBits = totalPacketSize & 0xFF;
command.header.payloadHighBits = totalPacketSize >> 8;
var dataBuf = new Buffer(data);
var dataBuf = Buffer.concat([new Buffer([dataLength]), new Buffer(param)], dataLength + 1);
payloadBuffer = Buffer.concat([payloadBuffer, dataBuf], payloadBuffer.length + dataBuf.length);
break;

@@ -729,16 +674,17 @@

var data = [];
var dataLength = param.length;
if (!Array.isArray(param) && typeof param != "string") {
return callback && callback(new Error("Invalid parameter type. Should be an Array or string"));
}
// Times two because these are uint16s
var dataLength = param.length * 2;
var totalPacketSize = dataLength + command.header.lolen;
command.header.payloadLowBits = totalPacketSize & 0xFF
command.header.payloadHighBits = totalPacketSize >> 8
data.push(dataLength);
data.push(param);
var dataBuf = new Buffer(data);
command.header.payloadLowBits = totalPacketSize & 0xFF;
command.header.payloadHighBits = totalPacketSize >> 8;
var dataBuf = Buffer.concat([new Buffer([dataLength]), new Buffer(param)], dataLength + 1);
payloadBuffer = Buffer.concat([payloadBuffer, dataBuf], payloadBuffer.length + dataBuf.length);
break;

@@ -749,3 +695,2 @@ }

}
// Make the packet with the payload and header

@@ -772,3 +717,3 @@ var packet = new Packet(_bgmessageType.Command,

// And the param code indicates that there should be, throw an err
if (paramCode) return callback(new Error("Invalid parameters passed"));
if (paramCode) return callback(new Error("Need to pass in parameters"));

@@ -783,3 +728,3 @@ // If there shouldn't be, just return

if (numParams != params.length) {
return callback(new Error("Invalid parameters passed"));
return callback(new Error("Invalid number of parameters passed for method"));
} else {

@@ -786,0 +731,0 @@ return callback(null);

{
"name": "bglib",
"version": "0.0.8",
"version": "0.0.014",
"description": "Create and parse packets for the BlueGiga BLE112 and BLE113",

@@ -13,3 +13,4 @@ "main": "bglib.js",

"directories": {
"libs": "libraries"
"lib": "libraries",
"test" : "Test script"
},

@@ -24,3 +25,6 @@ "keywords": [

"energy"
]
],
"dependencies" : {
"ble-ad-parser" : "*"
}
}

@@ -22,6 +22,6 @@ // An embarrasingly unexhaustive test of bglib functionality

&& response.cClass == 6, "Invalid packet created.");
console.log("Packet", response);
console.log("Complex Packet Creation Passed.");
});
bglib.getPacket(bglib.api.systemHello, ["Invalid", "params"], function(err, response) {

@@ -44,3 +44,3 @@ assert(err, "Unable to detect invalid number of parameters.");

assert(parsedPackets.length == 4, "Packets not parsed correctly");
console.log(parsedPackets[0].response.data)
console.log("Packet Parsing Passed.");

@@ -47,0 +47,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc