123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- 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)
- 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);
- },
- // 查询当前模式
- searchModel:function () {
- let data = [];
- data.push(0x05);
- data.push(0x00);
- data.push(0x01);
- data.push(0x00);
- return Buffer(data);
- },
- // 进入配置模式
- inSetModel:function () {
- let data = [];
- data.push(0x05);
- data.push(0x00);
- data.push(0x02);
- data.push(0x00);
- return Buffer(data);
- },
- // 进入传输模式
- inTransModel:function () {
- let data = [];
- data.push(0x05);
- data.push(0x00);
- data.push(0x03);
- data.push(0x00);
- return Buffer(data);
- },
- // 蓝牙模块发送 查询配置指令
- blueToothSendCommand:function (arrData,cmd,type) {
- let head = 0xf7
- let realcmd = 0x00
- if(type == 'get') {
- realcmd = 0x01
- } else {
- realcmd = 0x02
- }
- let id = 0x00
- if(cmd == 'wifiAccount') {
- id = 0xa1
- } else if (cmd == 'wifiIp') {
- id = 0xa2
- } else if(cmd == 'serverIp') {
- id = 0xa3
- }
- let data = [];
- data.push(head)
- // 计算长度
- let size = (1+1+arrData.length)
- 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
- }
|