UNPKG

node-red-contrib-hasskit

Version:

hasskit for node-red

35 lines (32 loc) 1.02 kB
const states = {}; /** * buf数据to对象 * * data 命令缓冲 */ module.exports.buf2obj = function (data, obj) { if (!data) return; if (data[0] !== obj.uid || data[2] !== 0x10 || data[1] !== 0x20) return; console.log(data); if (data[3] - 0x10 !== obj.address) return; return { id: obj.uid, address: obj.address, uid: obj.entity_id }; }; /** * obj转buf * @param {*} obj * */ module.exports.obj2buf = function ({ entity_id, state }, obj1) { //if (states[obj1.uid] === undefined) states[obj1.uid] = 0; //状态暂存 console.log('obj1',state) if (obj1.entity_id === entity_id) { let buf = [obj1.uid, 0x06, 0x10, 0x20 + obj1.address, 0, 0x00]; if (state === 'on') { buf[5] = 1 //states[obj1.uid] | (1 << (obj1.address - 1)); } else { // buf[5] = states[obj1.uid] & ~(1 << (obj1.address - 1)); } // states[obj1.uid] = buf[5]; return buf; } else return null; };