plg 11 months ago
parent
commit
27af926a88
1 changed files with 68 additions and 1 deletions
  1. 68 1
      src/main/index.js

+ 68 - 1
src/main/index.js

@@ -643,7 +643,7 @@ function handleByteTwo(mac) {
         parseList = ringTwo.deqN(bigPackageLen)
       }
       const temp = new Buffer(parseList)
-      decodeByte(temp,mac)
+      decodeByteTwo(temp,mac)
       // console.log(parseList)
     }
   }
@@ -684,6 +684,43 @@ function decodeByte(temp,mac) {
   return map
 }
 
+
+function decodeByteTwo(temp,mac) {
+  const utcTime = getUtcTime()
+  // console.log(temp)
+  const map = new Map()
+  // map.set("utcTime",utcTime)
+  // 判断大小包
+  if (temp.length === smallPackageLen) { // 先校验再计算rawWaveData
+    if (byteSumCheckTwo(temp)) {
+      const rawWaveData = getRawWaveValueTwo(temp[5], temp[6])
+      map.set('rawWaveData', rawWaveData)
+    }
+  } else {
+    if (byteSumCheckTwo(temp)) {
+      // console.log(temp)
+      map.set('Signal', temp.readUInt8(4))
+      map.set('Delta', temp.readUInt8(7) * 256 * 256 + temp.readUInt8(8) * 256 + temp.readUInt8(9))
+      map.set('Theta', temp.readUInt8(10) * 256 * 256 + temp.readUInt8(11) * 256 + temp.readUInt8(12))
+      map.set('LowAlpha', temp.readUInt8(13) * 256 * 256 + temp.readUInt8(14) * 256 + temp.readUInt8(15))
+      map.set('HighAlpha', temp.readUInt8(16) * 256 * 256 + temp.readUInt8(17) * 256 + temp.readUInt8(18))
+      map.set('LowBeta', temp.readUInt8(19) * 256 * 256 + temp.readUInt8(20) * 256 + temp.readUInt8(21))
+      map.set('HighBeta', temp.readUInt8(22) * 256 * 256 + temp.readUInt8(23) * 256 + temp.readUInt8(24))
+      map.set('LowGamma', temp.readUInt8(25) * 256 * 256 + temp.readUInt8(26) * 256 + temp.readUInt8(27))
+      map.set('MiddleGamma', temp.readUInt8(28) * 256 * 256 + temp.readUInt8(29) * 256 + temp.readUInt8(30))
+      map.set('Attention', temp.readUInt8(32))
+      map.set('Meditation', temp.readUInt8(34))
+    }
+  }
+  // console.log(map.size)
+  for (const [key, value] of map) {
+    // console.log(key + ' ============ ' + value)
+  }
+  mainWindow.webContents.send('accelerationData-message-two', {arg:map,mac:mac})
+  return map
+}
+
+
 function getRawWaveValue(highOrderByte, lowOrderByte) {
   const hi = highOrderByte
   const lo = lowOrderByte & 0xFF
@@ -694,6 +731,16 @@ function getRawWaveValue(highOrderByte, lowOrderByte) {
   return value
 }
 
+function getRawWaveValueTwo(highOrderByte, lowOrderByte) {
+  const hi = highOrderByte
+  const lo = lowOrderByte & 0xFF
+  let value = (hi << 8) | lo
+  if (value > 32768) {
+    value = value - 65536
+  }
+  return value
+}
+
 // 检查校验和aa aa 04 80 02 ff f8 86sum = ((0x80 + 0x02 + xxHigh + xxLow)^ 0xFFFFFFFF) & 0xFF
 function byteSumCheck(byteTemp) {
   if (byteTemp.length === smallPackageLen) {
@@ -714,6 +761,26 @@ function byteSumCheck(byteTemp) {
   }
 }
 
+// 检查校验和aa aa 04 80 02 ff f8 86sum = ((0x80 + 0x02 + xxHigh + xxLow)^ 0xFFFFFFFF) & 0xFF
+function byteSumCheckTwo(byteTemp) {
+  if (byteTemp.length === smallPackageLen) {
+    if ((((byteTemp[3] + byteTemp[4] + byteTemp[5] + byteTemp[6]) ^ 0xffffffff) & 0xff) === byteTemp[7]) {
+      // console.log('sum check ok!');
+      return true
+    } else {
+      // console.log('sum check false!');
+      return false
+    }
+  } else {
+    if (byteTemp[0] === 0xaa && byteTemp[1] === 0xaa && byteTemp[2] === 0x20 && byteTemp[3] === 0x02 &&
+      byteTemp[5] === 0x83 && byteTemp[6] === 0x18 && byteTemp[31] === 0x04 && byteTemp[33] === 0x05) {
+      return true
+    } else {
+      return false
+    }
+  }
+}
+
 // 获取到com端口
 SerialPort.list().then(ports => {
   ports.forEach(function (port) {