Skip to content

Commit

Permalink
Merge pull request #34 from jankolkmeier/rangeErrorWorkaround
Browse files Browse the repository at this point in the history
don't write to full buffers
  • Loading branch information
jankolkmeier committed Jan 8, 2016
2 parents 5c540f5 + 246d0eb commit 5e6daf8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/xbee-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ XBeeAPI.prototype.parseRaw = function(buffer) {
var S = this.parseState;
for(var i = 0; i < buffer.length; i++) {
S.b = buffer[i];
if (S.b === C.START_BYTE && S.waiting) {
if (S.b === C.START_BYTE) {
S.buffer = new Buffer(128);
S.length = 0;
S.total = 0;
Expand All @@ -159,7 +159,12 @@ XBeeAPI.prototype.parseRaw = function(buffer) {
}

if (!S.waiting) {
S.buffer.writeUInt8(S.b, S.offset++);
if (S.buffer.length > S.offset) {
S.buffer.writeUInt8(S.b, S.offset++);
} else {
console.log("We would have a problem...");
S.waiting = true;
}
}

if (S.offset === 1) {
Expand Down

0 comments on commit 5e6daf8

Please sign in to comment.