增加102J蓝牙协议待设备验证
This commit is contained in:
@ -2,6 +2,9 @@ import Common from '@/utils/Common.js'
|
||||
import {
|
||||
parseBleData
|
||||
} from '@/api/100J/HBY100-J.js'
|
||||
import {
|
||||
parseHby102jUplink
|
||||
} from '@/api/102J/hby102jBleProtocol.js'
|
||||
import {
|
||||
MsgSuccess,
|
||||
MsgError,
|
||||
@ -27,6 +30,7 @@ class BleReceive {
|
||||
'/pages/4877/BJQ4877': this.Receive_4877.bind(this),
|
||||
'/pages/100/HBY100': this.Receive_100.bind(this),
|
||||
'/pages/102/HBY102': this.Receive_102.bind(this),
|
||||
'/pages/102J/HBY102J': this.Receive_102J.bind(this),
|
||||
'/pages/6170/deviceControl/index': this.Receive_6170.bind(this),
|
||||
'/pages/100J/HBY100-J': this.Receive_100J.bind(this),
|
||||
'/pages/6075J/BJQ6075J': this.Receive_6075.bind(this),
|
||||
@ -66,15 +70,24 @@ class BleReceive {
|
||||
|
||||
|
||||
ReceiveData(receive, f, path, recArr) {
|
||||
// 100J:首页等场景 LinkedList 项可能未带齐 mac/device,但语音分片上传依赖 parseBleData 消费 FB 05
|
||||
// AE30 服务:100J 与 102J 为同一套蓝牙芯片(GATT 相同),应用层协议不同。
|
||||
// 100J:f 未就绪时仍需 parseBleData 消费 FB 05 等语音/文件应答。
|
||||
// 102J:上行 FB 21–28 为晶全协议,不得走 100J parseBleData,避免误触发语音/文件回调。
|
||||
const sid = receive && receive.serviceId ? String(receive.serviceId) : '';
|
||||
const is100JAe30 = /ae30/i.test(sid);
|
||||
const isAe30 = /ae30/i.test(sid);
|
||||
const fReady = f && f.macAddress && f.device && f.device.id;
|
||||
if (is100JAe30 && receive && receive.bytes && receive.bytes.length >= 3 && !fReady) {
|
||||
try {
|
||||
parseBleData(new Uint8Array(receive.bytes));
|
||||
} catch (e) {
|
||||
console.warn('[100J] ReceiveData 兜底解析失败', e);
|
||||
const u8Early = receive && receive.bytes && receive.bytes.length >= 4
|
||||
? new Uint8Array(receive.bytes)
|
||||
: null;
|
||||
const is102JFbControl = u8Early && u8Early[0] === 0xfb && u8Early[u8Early.length - 1] === 0xff
|
||||
&& u8Early[1] >= 0x21 && u8Early[1] <= 0x28;
|
||||
if (isAe30 && receive && receive.bytes && receive.bytes.length >= 3 && !fReady) {
|
||||
if (!is102JFbControl) {
|
||||
try {
|
||||
parseBleData(new Uint8Array(receive.bytes));
|
||||
} catch (e) {
|
||||
console.warn('[100J/AE30] ReceiveData 兜底 parseBleData 失败', e);
|
||||
}
|
||||
}
|
||||
return receive;
|
||||
}
|
||||
@ -103,8 +116,8 @@ class BleReceive {
|
||||
}
|
||||
|
||||
} else {
|
||||
// 100J AE30 二进制帧在 f 不完整时已在上方 parseBleData,此处不再误报「无法处理」
|
||||
if (!is100JAe30) {
|
||||
// AE30:100J 在 f 不完整时已在上方 parseBleData;102J 控制帧被有意跳过 parseBleData
|
||||
if (!isAe30) {
|
||||
console.error("已收到该消息,但无法处理", receive, "f:", f);
|
||||
}
|
||||
}
|
||||
@ -944,6 +957,147 @@ class BleReceive {
|
||||
|
||||
}
|
||||
|
||||
Receive_102J(receive, f, path, recArr) {
|
||||
let receiveData = {}
|
||||
try {
|
||||
if (receive && receive.bytes && receive.bytes.length >= 3) {
|
||||
receiveData = parseHby102jUplink(new Uint8Array(receive.bytes))
|
||||
}
|
||||
|
||||
let recCnt = recArr.find((v) => {
|
||||
return v.key.replace(/\//g, '').toLowerCase() == f.device.detailPageUrl
|
||||
.replace(/\//g, '').toLowerCase()
|
||||
})
|
||||
if (!recCnt) {
|
||||
let msgs = []
|
||||
if (receiveData.sta_PowerPercent <= 20 && receiveData.sta_charge == 0) {
|
||||
msgs.push("设备'" + f.device.deviceName + "'电量低")
|
||||
}
|
||||
if (receiveData.sta_Intrusion === 1) {
|
||||
msgs.push("设备'" + f.device.deviceName + "'闯入报警中")
|
||||
}
|
||||
if (this.ref && msgs.length > 0) {
|
||||
const text = msgs.join(',')
|
||||
MsgError(text, '', this.ref, () => {
|
||||
MsgClear(this.ref)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (f.device && path === 'pages/common/index') {
|
||||
let linkKey = '102J_' + f.device.id + '_linked'
|
||||
let warnKey = '102J_' + f.device.id + '_warning'
|
||||
let time = new Date()
|
||||
|
||||
if (receiveData.sta_tomac) {
|
||||
if (receiveData.sta_tomac.indexOf(':') === -1) {
|
||||
receiveData.sta_tomac = receiveData.sta_tomac.replace(/(.{2})/g, '$1:').slice(0, -1)
|
||||
}
|
||||
uni.getStorageInfo({
|
||||
success: function(res) {
|
||||
let arr = []
|
||||
let linked = {
|
||||
linkId: f.linkId,
|
||||
read: false,
|
||||
linkEqs: [{
|
||||
linkTime: time,
|
||||
linkMac: f.macAddress
|
||||
}, {
|
||||
linkTime: time,
|
||||
linkMac: receiveData.sta_tomac
|
||||
}]
|
||||
}
|
||||
if (res.keys.includes(linkKey)) {
|
||||
arr = uni.getStorageSync(linkKey)
|
||||
}
|
||||
if (arr.length === 0) {
|
||||
arr.unshift(linked)
|
||||
} else {
|
||||
let dev = arr.find((v) => {
|
||||
if (v.linkId === f.linkId) {
|
||||
let vl = v.linkEqs.find((cvl) => {
|
||||
if (cvl.linkMac === receiveData.sta_tomac) {
|
||||
v.read = false
|
||||
cvl.linkTime = time
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
if (!vl) {
|
||||
v.linkEqs.push({
|
||||
linkTime: time,
|
||||
linkMac: receiveData.sta_tomac
|
||||
})
|
||||
}
|
||||
return vl
|
||||
}
|
||||
return false
|
||||
})
|
||||
if (!dev) {
|
||||
arr.unshift(linked)
|
||||
}
|
||||
}
|
||||
uni.setStorage({
|
||||
key: linkKey,
|
||||
data: arr
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let warnArrs = []
|
||||
let guid = Common.guid()
|
||||
if (receiveData.sta_sosadd) {
|
||||
if (receiveData.sta_sosadd.indexOf(':') === -1) {
|
||||
receiveData.sta_sosadd = receiveData.sta_sosadd.replace(/(.{2})/g, '$1:').slice(0, -1)
|
||||
}
|
||||
warnArrs.push({
|
||||
linkId: f.linkId,
|
||||
read: false,
|
||||
key: guid,
|
||||
warnType: '闯入报警',
|
||||
warnMac: receiveData.sta_sosadd,
|
||||
warnTime: time,
|
||||
warnName: ''
|
||||
})
|
||||
}
|
||||
|
||||
if (receiveData.sta_LedType === 'led_alarm' || receiveData.ins_LedType === 'led_alarm') {
|
||||
warnArrs.push({
|
||||
linkId: f.linkId,
|
||||
read: false,
|
||||
key: guid,
|
||||
warnType: '强制报警',
|
||||
warnMac: f.macAddress,
|
||||
warnTime: time,
|
||||
warnName: ''
|
||||
})
|
||||
}
|
||||
|
||||
if (warnArrs.length > 0) {
|
||||
uni.getStorageInfo({
|
||||
success: function(res) {
|
||||
let arr = []
|
||||
if (res.keys.includes(warnKey)) {
|
||||
arr = uni.getStorageSync(warnKey)
|
||||
arr = warnArrs.concat(arr)
|
||||
} else {
|
||||
arr = warnArrs
|
||||
}
|
||||
uni.setStorage({
|
||||
key: warnKey,
|
||||
data: arr
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
receiveData = {}
|
||||
console.log('Receive_102J 解析失败', error)
|
||||
}
|
||||
return receiveData
|
||||
}
|
||||
|
||||
Receive_6075(receive, f, path, recArr) {
|
||||
let receiveData = {};
|
||||
|
||||
Reference in New Issue
Block a user