1.完成获取星锁状态相关逻辑(目前写入成功无回复)
This commit is contained in:
parent
a569cabf76
commit
b73d40db62
@ -10,6 +10,7 @@
|
|||||||
<view v-else>
|
<view v-else>
|
||||||
<button @click="getPublicKey">获取锁公钥</button>
|
<button @click="getPublicKey">获取锁公钥</button>
|
||||||
<button @click="getCommKey">获取锁私钥</button>
|
<button @click="getCommKey">获取锁私钥</button>
|
||||||
|
<button @click="getLockStatus">获取锁状态</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
@ -61,6 +62,92 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 获取锁状态
|
||||||
|
getLockStatus() {
|
||||||
|
// 头部数据
|
||||||
|
let buffer = new ArrayBuffer(12)
|
||||||
|
let binaryData = new Uint8Array(buffer)
|
||||||
|
|
||||||
|
// 固定包头
|
||||||
|
binaryData[0] = 0xEF
|
||||||
|
binaryData[1] = 0x01
|
||||||
|
binaryData[2] = 0xEE
|
||||||
|
binaryData[3] = 0x02
|
||||||
|
|
||||||
|
// 包类型 发送
|
||||||
|
binaryData[4] = 0x01
|
||||||
|
|
||||||
|
// 包序号
|
||||||
|
binaryData[5] = this.number / 256
|
||||||
|
binaryData[6] = this.number % 256
|
||||||
|
this.number++
|
||||||
|
|
||||||
|
// 包标识
|
||||||
|
binaryData[7] = 0x23
|
||||||
|
|
||||||
|
// 数据长度
|
||||||
|
binaryData[8] = 80 / 256
|
||||||
|
binaryData[9] = 80 % 256
|
||||||
|
binaryData[10] = 70 / 256
|
||||||
|
binaryData[11] = 70 % 256
|
||||||
|
|
||||||
|
console.log('请求头', Array.from(binaryData))
|
||||||
|
|
||||||
|
// 入参
|
||||||
|
let paramsBuffer = new ArrayBuffer(70)
|
||||||
|
let paramsBinaryData = new Uint8Array(paramsBuffer)
|
||||||
|
|
||||||
|
// 命令
|
||||||
|
paramsBinaryData[0] = 0x3040 / 256
|
||||||
|
paramsBinaryData[1] = 0x3040 % 256
|
||||||
|
|
||||||
|
// 设备ID
|
||||||
|
for(let i=0; i < this.lockId.length; i++){
|
||||||
|
paramsBinaryData[2 + i] = this.lockId.charCodeAt(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// userId
|
||||||
|
const authUserId = '294'
|
||||||
|
for(let i=0; i < authUserId.length; i++){
|
||||||
|
paramsBinaryData[42 + i] = authUserId.charCodeAt(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
const nowTime = parseInt(new Date().getTime() / 1000)
|
||||||
|
|
||||||
|
paramsBinaryData[62] = (nowTime & 0xff000000) >> 24
|
||||||
|
paramsBinaryData[62 + 1] = (nowTime & 0xff0000) >> 16
|
||||||
|
paramsBinaryData[62 + 2] = (nowTime & 0xff00) >> 8
|
||||||
|
paramsBinaryData[62 + 3] = (nowTime & 0xff)
|
||||||
|
|
||||||
|
paramsBinaryData[66] = (nowTime & 0xff000000) >> 24
|
||||||
|
paramsBinaryData[66 + 1] = (nowTime & 0xff0000) >> 16
|
||||||
|
paramsBinaryData[66 + 2] = (nowTime & 0xff00) >> 8
|
||||||
|
paramsBinaryData[66 + 3] = (nowTime & 0xff)
|
||||||
|
|
||||||
|
console.log('ecb加密前入参', Array.from(paramsBinaryData))
|
||||||
|
console.log('密钥', Array.from(this.commKey))
|
||||||
|
const encrypted = sm4.encrypt(paramsBinaryData, this.commKey, { mode: 'ecb', output: 'array' })
|
||||||
|
console.log('ecb加密后的数据', Array.from(encrypted))
|
||||||
|
|
||||||
|
let newBuffer = new ArrayBuffer(92)
|
||||||
|
let newBinaryData = new Uint8Array(newBuffer)
|
||||||
|
for(let i = 0; i < 12; i++){
|
||||||
|
newBinaryData[i] = binaryData[i]
|
||||||
|
}
|
||||||
|
for(let i = 12; i < 92; i++){
|
||||||
|
newBinaryData[i] = encrypted[i - 12]
|
||||||
|
}
|
||||||
|
console.log('crc前的数据', Array.from(newBinaryData))
|
||||||
|
let resultBuffer = new ArrayBuffer(94)
|
||||||
|
let resultBinaryData = new Uint8Array(resultBuffer)
|
||||||
|
for(let i = 0; i < 92; i++){
|
||||||
|
resultBinaryData[i] = newBinaryData[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
resultBinaryData[92] = crc.crc16kermit(resultBuffer) / 256
|
||||||
|
resultBinaryData[93] = crc.crc16kermit(resultBuffer) % 256
|
||||||
|
this.writeBLECharacteristicValue(resultBuffer)
|
||||||
|
},
|
||||||
// 十六进制字符串转Uint8Array
|
// 十六进制字符串转Uint8Array
|
||||||
hexToUint8Array(hex) {
|
hexToUint8Array(hex) {
|
||||||
if (hex.length % 2 !== 0) {
|
if (hex.length % 2 !== 0) {
|
||||||
@ -74,7 +161,6 @@ export default {
|
|||||||
},
|
},
|
||||||
// 获取私钥
|
// 获取私钥
|
||||||
getCommKey() {
|
getCommKey() {
|
||||||
const cmdId = 0x3091
|
|
||||||
const keyId = '0'
|
const keyId = '0'
|
||||||
const authUserId = '294'
|
const authUserId = '294'
|
||||||
const nowTime = parseInt(new Date().getTime() / 1000)
|
const nowTime = parseInt(new Date().getTime() / 1000)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user