1.完成获取星锁状态
This commit is contained in:
parent
b73d40db62
commit
e3b963b76a
@ -34,7 +34,8 @@ export default {
|
||||
commKey: new Uint8Array(16),
|
||||
signKey: new Uint8Array(16),
|
||||
showList: true,
|
||||
number: 1
|
||||
number: 1,
|
||||
lockStatus: new Uint8Array(1)
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
@ -134,8 +135,8 @@ export default {
|
||||
for(let i = 0; i < 12; i++){
|
||||
newBinaryData[i] = binaryData[i]
|
||||
}
|
||||
for(let i = 12; i < 92; i++){
|
||||
newBinaryData[i] = encrypted[i - 12]
|
||||
for(let i = 0; i < 80; i++){
|
||||
newBinaryData[i + 12] = encrypted[i]
|
||||
}
|
||||
console.log('crc前的数据', Array.from(newBinaryData))
|
||||
let resultBuffer = new ArrayBuffer(94)
|
||||
@ -144,8 +145,8 @@ export default {
|
||||
resultBinaryData[i] = newBinaryData[i]
|
||||
}
|
||||
|
||||
resultBinaryData[92] = crc.crc16kermit(resultBuffer) / 256
|
||||
resultBinaryData[93] = crc.crc16kermit(resultBuffer) % 256
|
||||
resultBinaryData[92] = crc.crc16kermit(newBuffer) / 256
|
||||
resultBinaryData[93] = crc.crc16kermit(newBuffer) % 256
|
||||
this.writeBLECharacteristicValue(resultBuffer)
|
||||
},
|
||||
// 十六进制字符串转Uint8Array
|
||||
@ -402,6 +403,15 @@ export default {
|
||||
console.log('commKey', Array.from(that.commKey))
|
||||
console.log('signKey', Array.from(that.signKey))
|
||||
}
|
||||
} else if(binaryData[7] === 0x23) {
|
||||
const cebBinaryData = binaryData.slice(12, binaryData.length - 2)
|
||||
console.log('sm4返回参数', Array.from(cebBinaryData))
|
||||
const decrypted = sm4.decrypt(cebBinaryData, that.commKey, { mode: 'ecb', output: 'array' })
|
||||
console.log('ecb解密后的数据', decrypted)
|
||||
if(decrypted[0] === 48 && decrypted[1] === 64) {
|
||||
that.lockStatus = decrypted
|
||||
console.log('锁状态', that.lockStatus)
|
||||
}
|
||||
}
|
||||
},
|
||||
// 监听特征值变化
|
||||
@ -418,12 +428,10 @@ export default {
|
||||
success(res) {
|
||||
console.log(res)
|
||||
uni.onBLECharacteristicValueChange(function (res) {
|
||||
console.log('设备特征值改变')
|
||||
console.log(res)
|
||||
let binaryData = new Uint8Array(res.value)
|
||||
console.log('设备返回的数据', Array.from(binaryData), Array.from(binaryData, byte =>
|
||||
byte.toString(16)).join(','))
|
||||
if(binaryData[0] === 239 && binaryData[1] === 1 && binaryData[2] === 238 && binaryData[3] === 2) {
|
||||
console.log('设备返回的数据', Array.from(binaryData), Array.from(binaryData, byte =>
|
||||
byte.toString(16)).join(','))
|
||||
length = binaryData[8] * 256 + binaryData[9]
|
||||
if(length + 14 > binaryData.length) {
|
||||
completeData = binaryData
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user