Skip to content

Commit

Permalink
possible fix+tests for rangeError in #12
Browse files Browse the repository at this point in the history
  • Loading branch information
jankolkmeier committed Apr 14, 2015
1 parent be7c2bb commit 889e588
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/xbee-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ XBeeAPI.prototype.parseRaw = function(buffer) {
S.escape_next = false;
}

S.buffer.writeUInt8(S.b, S.offset++);
if (!S.waiting) {
S.buffer.writeUInt8(S.b, S.offset++);
}

if (S.offset === 1) {
continue;
Expand Down
20 changes: 20 additions & 0 deletions test/xbee-api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,26 @@ exports['API Frame Parsing'] = {
parser(null, rawFrame);
},

'Leading Garbage': function(test) {
test.expect(4);
var xbeeAPI = new xbee_api.XBeeAPI();
var parser = xbeeAPI.rawParser();
xbeeAPI.once("frame_object", function(frame) {
test.equal(frame.remote64, '0013a20040522baa', "Parse remote64");
test.equal(frame.remote16, '7d84', "Parse remote16");
test.equal(frame.receiveOptions, 1, "Parse receive options");
test.deepEqual(frame.data, new Buffer([ 0x52, 0x78, 0x44, 0x61, 0x74, 0x61 ]));
test.done();
});
// Receive Packet; 0x90; Receive packet with chars RxData
var garbage = [];
for (var i=0; i<520; i++) garbage.push(0x00);
var garbageBuffer = new Buffer(garbage);
var rawFrame = new Buffer([ 0x7E, 0x00, 0x12, 0x90, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x52, 0x2B, 0xAA, 0x7D, 0x84, 0x01, 0x52, 0x78, 0x44, 0x61, 0x74, 0x61, 0x0D ]);
var garbagedFrame = Buffer.concat([garbageBuffer, rawFrame]);
parser(null, garbagedFrame);
},

'Receive Packet 16-bit IO': function(test) {
test.expect(3);
var xbeeAPI = new xbee_api.XBeeAPI({api_mode:1});
Expand Down

0 comments on commit 889e588

Please sign in to comment.