UNPKG

node-red-contrib-clowire

Version:

clowire for node-red

34 lines (25 loc) 689 B
/** * buf数据to对象 * * data 命令缓冲 */ module.exports.buf2obj = function (data, obj) { if(!data) return if (data[3] !== obj.uid || data[4] !== obj.address) return if (data[1] !== 0x03 || data[2] !==0xc0) return return { id: obj.uid, address: obj.address, uid: obj.entity_id } } /** * obj转buf * @param {*} obj * */ module.exports.obj2buf = function (obj, obj1) { const { entity_id, state } = obj if (obj1.entity_id === entity_id) { let buf = [0xb2, 0x03, 0xc1, obj1.uid, obj1.address, 0x02, 0x00, 0x2b] if (state === 'on') buf[5] = 0x01 return buf } else return null }