Skip to content

Commit

Permalink
Merge pull request #3 from VanCoding/master
Browse files Browse the repository at this point in the history
work-around for Node.js 10
  • Loading branch information
futomi authored Jun 10, 2018
2 parents 9005b23 + 5f87f47 commit 3ce4b8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/lifx-lan-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Date: 2018-06-09
* ---------------------------------------------------------------- */
'use strict';
const readUInt64LE = require("./readUInt64LE");

/* ------------------------------------------------------------------
* Constructor: LifxLanParser()
Expand Down Expand Up @@ -99,7 +100,7 @@ LifxLanParser.prototype._parsePayload = function(type, pbuf) {
} else if(type === 15) { // StateHostFirmware - 15
if(psize === 20) {
payload = {
build : new Date(this._conv64BitTimeStampToMsec(pbuf, 0)),
build : new Date(parseInt(readUInt64(pbuf,0) / 1000000, 10)),
version : pbuf.readUInt32LE(16)
};
}
Expand All @@ -114,7 +115,7 @@ LifxLanParser.prototype._parsePayload = function(type, pbuf) {
} else if(type === 19) { // StateWifiFirmware - 19
if(psize === 20) {
payload = {
build : new Date(this._conv64BitTimeStampToMsec(pbuf, 0)),
build : new Date(parseInt(readUInt64LE(pbuf,0) / 1000000, 10)),
version : pbuf.readUInt32LE(16)
};
}
Expand Down Expand Up @@ -174,25 +175,25 @@ LifxLanParser.prototype._parsePayload = function(type, pbuf) {
} else if(type === 35) { // StateInfo - 35
if(psize === 24) {
payload = {
time : new Date(this._conv64BitTimeStampToMsec(pbuf, 0)),
uptime : this._conv64BitTimeStampToMsec(pbuf, 8), // msec
downtime : this._conv64BitTimeStampToMsec(pbuf, 16) // msec
time : new Date(parseInt(readUInt64LE(pbuf,0) / 1000000, 10)),
uptime : Math.round(readUInt64LE(pbuf,8) / 1000000), // msec
downtime : Math.round(readUInt64LE(pbuf,16) / 1000000) // msec
};
}
} else if(type === 50) { // StateLocation - 50
if(psize === 56) {
payload = {
guid : pbuf.slice(0, 16).toString('hex'),
label : this._convertBufferToString(pbuf.slice(16, 48)),
updated : new Date(this._conv64BitTimeStampToMsec(pbuf, 48))
updated : new Date(parseInt(readUInt64LE(pbuf,48) / 1000000, 10))
};
}
} else if(type === 53) { // StateGroup - 53
if(psize === 56) {
payload = {
guid : pbuf.slice(0, 16).toString('hex'),
label : this._convertBufferToString(pbuf.slice(16, 48)),
updated : new Date(this._conv64BitTimeStampToMsec(pbuf, 48))
updated : new Date(parseInt(readUInt64LE(pbuf,48) / 1000000, 10))
};
}
} else if(type === 59) { // EchoResponse - 59
Expand Down
3 changes: 3 additions & 0 deletions lib/readUInt64LE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(buffer,offset){
return buffer.readUIntLE(offset,6)<<16+buffer.readUIntLE(offset+6,2);
}

0 comments on commit 3ce4b8f

Please sign in to comment.