Skip to content

Commit

Permalink
Completed Packet documentation and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwippermann committed Feb 13, 2014
1 parent 4aced40 commit a5c8967
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 137 deletions.
32 changes: 26 additions & 6 deletions src/packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,36 @@ var optionKeys = [



var Packet = Header.extend({
var Packet = Header.extend(/** @lends Packet# */ {

/**
* The command field of this VBus packet. See the VBus Protocol specification for details.
* @type {number}
*/
command: 0,

/**
* The number of frames of this VBus packet. Each frame can hold four bytes of payload.
* @type {number}
*/
frameCount: 0,

/**
* The buffer containing the frame data of this VBus packet.
*/
frameData: null,

/**
* Creates a new Packet instance and optionally initializes its members with the given values.
*
* @constructs
* @augments Header
* @param {object} options Initialization values for this instance's members
* @param {number} options.command {@link Packet#command}
* @param {number} options.frameCount {@link Packet#frameCount}
* @param {Buffer} options.frameData {@link Packet#frameData}
* @see Header#constructor
*/
constructor: function(options) {
Header.call(this, options);

Expand All @@ -50,11 +72,9 @@ var Packet = Header.extend({
var buffer;
if (origBuffer === undefined) {
buffer = new Buffer(length);
} else if (start + length <= end) {
buffer = origBuffer.slice(start, start + length);
} else {
buffer = origBuffer.slice(start, end);
}

if (buffer.length < length) {
throw new Error('Buffer too small');
}

Expand Down Expand Up @@ -93,7 +113,7 @@ var Packet = Header.extend({
return result;
},

}, {
}, /** @lends Packet */ {

fromLiveBuffer: function(buffer, start, end) {
var frameCount = buffer [start + 8];
Expand Down

0 comments on commit a5c8967

Please sign in to comment.