Skip to content

Commit

Permalink
Allow debugging of sendData
Browse files Browse the repository at this point in the history
  • Loading branch information
lprhodes committed Feb 8, 2018
1 parent e67b621 commit 9123e33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ device.prototype.getType = function(){
return this.type;
}

device.prototype.sendPacket = function( command, payload){
device.prototype.sendPacket = function(command, payload, debug = false){
this.count = (this.count + 1) & 0xffff;
var packet = Buffer.alloc(0x38,0);
packet[0x00] = 0x5a;
Expand Down Expand Up @@ -317,9 +317,14 @@ device.prototype.sendPacket = function( command, payload){
packet[0x20] = checksum & 0xff;
packet[0x21] = checksum >> 8;

// console.log('packet', packet.toString('hex'))
if (debug) {
console.log('packet', packet.toString('hex'))
}

this.cs.sendto(packet, 0, packet.length, this.host.port, this.host.address);
this.cs.send(packet, 0, packet.length, this.host.port, this.host.address, (err, bytes) => {
if (debug && err) console.log('send packet error', err)
if (debug) console.log('sent packet - bytes: ', bytes)
});
}

device.prototype.rm = function(isPlus){
Expand Down Expand Up @@ -356,10 +361,10 @@ device.prototype.rm = function(isPlus){
}
}

this.sendData = function(data){
this.sendData = function(data, debug = false){
packet = new Buffer([0x02, 0x00, 0x00, 0x00]);
packet = Buffer.concat([packet, data]);
this.sendPacket(0x6a, packet);
this.sendPacket(0x6a, packet, debug);
}

this.enterLearning = function(){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "broadlinkjs-rm",
"version": "0.2.1",
"version": "0.2.2",
"description": "A Node.JS fork of broadlinkjs specifically intended for interacting with RM devices in homebridge-broadlink-rm",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 9123e33

Please sign in to comment.