100J蓝牙上传语音待验证
This commit is contained in:
@ -244,7 +244,8 @@
|
||||
deviceVoiceBroadcast,
|
||||
updateBleStatus,
|
||||
parseBleData,
|
||||
fetchBlePowerStatus
|
||||
fetchBlePowerStatus,
|
||||
fetchBleLocation
|
||||
} from '@/api/100J/HBY100-J.js'
|
||||
import BleHelper from '@/utils/BleHelper.js';
|
||||
var bleTool = BleHelper.getBleTool();
|
||||
@ -613,7 +614,7 @@
|
||||
this.createThrottledFunctions();
|
||||
|
||||
// 注册蓝牙相关事件
|
||||
bleTool.addReceiveCallback(this.bleValueNotify, "HBY100J");
|
||||
bleTool.addReceiveCallback(this.bleValueNotify.bind(this), "HBY100J");
|
||||
bleTool.addDisposeCallback(this.bleStateBreak, "HBY100J");
|
||||
bleTool.addRecoveryCallback(this.bleStateRecovry, "HBY100J");
|
||||
bleTool.addStateBreakCallback(this.bleStateBreak, "HBY100J");
|
||||
@ -1082,11 +1083,17 @@
|
||||
}
|
||||
let bleDeviceId = res.deviceId;
|
||||
updateBleStatus(true, bleDeviceId, this.deviceInfo.deviceId);
|
||||
// 蓝牙连接成功后主动拉取电源状态(电量、续航时间)
|
||||
fetchBlePowerStatus().catch(() => {});
|
||||
// 蓝牙连接成功后主动拉取电源状态、定位(优先蓝牙,设备也会每1分钟主动上报)
|
||||
// 两指令间隔 150ms,避免 writeBLECharacteristicValue:fail property not support
|
||||
fetchBlePowerStatus()
|
||||
.then(() => new Promise(r => setTimeout(r, 150)))
|
||||
.then(() => fetchBleLocation())
|
||||
.catch(() => {});
|
||||
},
|
||||
previewImg(img) {},
|
||||
bleValueNotify: function(receive, device, path, recArr) { //订阅消息
|
||||
// 仅处理当前设备的数据(device 为 LinkedList 中匹配 receive.deviceId 的项)
|
||||
if (device && device.device && this.deviceInfo.deviceId && device.device.id != this.deviceInfo.deviceId) return;
|
||||
// 解析蓝牙上报数据 (协议: FC=MAC主动上报, FB=指令响应)
|
||||
if (!receive.bytes || receive.bytes.length < 3) return;
|
||||
const parsedData = parseBleData(receive.bytes);
|
||||
@ -1096,16 +1103,23 @@
|
||||
if (parsedData.type === 'mac' && parsedData.macAddress) {
|
||||
this.formData.macAddress = parsedData.macAddress;
|
||||
this.device.deviceMac = parsedData.macAddress;
|
||||
this.deviceInfo.deviceMac = parsedData.macAddress;
|
||||
this.$set(this.deviceInfo, 'deviceMac', parsedData.macAddress);
|
||||
return;
|
||||
}
|
||||
|
||||
// 5.4 设备位置 (0x03):主动查询响应或设备定时上报(1分钟),优先蓝牙
|
||||
// 使用 $set 确保 Vue2 能检测新增属性并触发视图更新
|
||||
if (parsedData.longitude !== undefined && parsedData.latitude !== undefined) {
|
||||
this.$set(this.deviceInfo, 'longitude', parsedData.longitude);
|
||||
this.$set(this.deviceInfo, 'latitude', parsedData.latitude);
|
||||
}
|
||||
|
||||
// 5.5 获取设备电源状态 (0x04)
|
||||
if (parsedData.batteryPercentage !== undefined) {
|
||||
this.deviceInfo.batteryPercentage = parsedData.batteryPercentage;
|
||||
this.$set(this.deviceInfo, 'batteryPercentage', parsedData.batteryPercentage);
|
||||
}
|
||||
if (parsedData.batteryRemainingTime !== undefined) {
|
||||
this.deviceInfo.batteryRemainingTime = parsedData.batteryRemainingTime;
|
||||
this.$set(this.deviceInfo, 'batteryRemainingTime', parsedData.batteryRemainingTime);
|
||||
}
|
||||
|
||||
if (this.deviceInfo.batteryPercentage <= 20) {
|
||||
|
||||
Reference in New Issue
Block a user