var machineInfo = require('./global') var checksum = require('./checksum') module.exports = { // 开始取零 beginSetZero:function () { let data = []; data.push(0x04); data.push(0x00); data.push(0x02); data.push(0x00); return Buffer(data); }, // 停止取零 endSetZero:function () { let data = []; data.push(0x04); data.push(0x00); data.push(0x04); data.push(0x00); return Buffer(data); }, // 开始采集 startCollection:function () { let data = []; data.push(0x04); data.push(0x00); data.push(0x03); data.push(0x00); return Buffer(data); }, // 停止采集 endCollection:function () { let data = []; data.push(0x04); data.push(0x00); data.push(0x04); data.push(0x00); return Buffer(data); }, // 复位 resetDevice:function () { let data = []; data.push(0x16); data.push(0x00); return Buffer(data); }, // 查询采样频率、传感器阈值 驱动电压、功能角色、设备型号指令 sendMsg:function (arrData,cmd,type) { let head = 0xf5 let realcmd = 0x00 if(type == 'get') { realcmd = 0x01 } else { realcmd = 0x02 } let id = getWhichCmd(cmd) let data = []; data.push(head) // 计算长度 let size = (1+1+arrData.length).toString(16) data.push(size) data.push(0x00) data.push(realcmd) data.push(id) let sum = 0 for(let i in arrData) { data.push(parseInt(arrData[i],16)) sum += parseInt(arrData[i],16) } let checkSum = (realcmd + id + sum) & 0xff data.push(checkSum) console.log(Buffer(data)) return Buffer(data); }, } function getWhichCmd(cmd) { let returnCmd = 0x00 switch (cmd) { case 'caiyang': returnCmd = 0x01 break; case 'chuangan': returnCmd = 0x02 break; case 'qudong': returnCmd = 0x03; break; case 'gongneng': returnCmd = 0x04 break; case 'shebei': returnCmd = 0x05 break } return returnCmd }