|
|
|
@ -71,11 +71,12 @@ Page({
|
|
|
|
|
getBluetoothDevices() {
|
|
|
|
|
wx.onBluetoothDeviceFound((res) => {
|
|
|
|
|
// 过滤出名称以 "GJ-SH-01" 开头的设备
|
|
|
|
|
const targetDevices = res.devices.filter(device => device.name && device.name.startsWith("J2203"));
|
|
|
|
|
const targetDevices = res.devices.filter(device => device.name && (device.name.startsWith("J2203") || device.name.startsWith("小柏智能手表")));
|
|
|
|
|
|
|
|
|
|
// 遍历并连接符合条件的设备
|
|
|
|
|
targetDevices.forEach(device => {
|
|
|
|
|
console.log("找到符合规则的蓝牙设备:", device);
|
|
|
|
|
console.log("device.advertisData:",new Uint8Array(device.advertisData))
|
|
|
|
|
const hexStr = this.uint8ArrayToMac(new Uint8Array(device.advertisData))
|
|
|
|
|
console.log("advertisData: ",hexStr)
|
|
|
|
|
// 连接指定设备
|
|
|
|
@ -232,7 +233,7 @@ Page({
|
|
|
|
|
// 需要调用下一个指令(血氧)
|
|
|
|
|
this.sendHealthCommand(0x66)
|
|
|
|
|
}
|
|
|
|
|
// console.log("心率数据:",heartRateList);
|
|
|
|
|
console.log("心率数据:",heartRateList);
|
|
|
|
|
// console.log("呼吸率数据:",respList);
|
|
|
|
|
// 调用后台接口 todo ....
|
|
|
|
|
|
|
|
|
@ -299,7 +300,7 @@ Page({
|
|
|
|
|
let list = this.data.sleepList;
|
|
|
|
|
if(list.length > 0){
|
|
|
|
|
let arr = CommonUtil.assembleSleepData(list);
|
|
|
|
|
arr.forEach(item =>{
|
|
|
|
|
arr.forEach((item,index) =>{
|
|
|
|
|
// 排序算法
|
|
|
|
|
item.sleepList.sort((a, b) => {
|
|
|
|
|
// 先比较 yyyyMMdd
|
|
|
|
@ -309,12 +310,15 @@ Page({
|
|
|
|
|
// 再比较 minute
|
|
|
|
|
return a.minute - b.minute;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
item.sleepList[index].minute = item.sleepList[index].minute -1;
|
|
|
|
|
item.sleepList[index].status = 1
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
console.log("接口需要的睡眠数据:",arr);
|
|
|
|
|
|
|
|
|
|
// // 更新缓存
|
|
|
|
|
// HealthDataCache.updateSleepData(list[0].time);
|
|
|
|
|
// 更新缓存
|
|
|
|
|
HealthDataCache.updateSleepData(list[0].date);
|
|
|
|
|
|
|
|
|
|
// 调用接口传睡眠后,清空数据
|
|
|
|
|
this.setData({
|
|
|
|
@ -325,20 +329,19 @@ Page({
|
|
|
|
|
let sleepList = ParseDataPacket.parseSleepList(dataView,0);
|
|
|
|
|
// 排序,minute 越大排前面
|
|
|
|
|
sleepList.sort((a, b) => {
|
|
|
|
|
return Number(b.minute) - Number(a.minute); // b.minute > a.minute 排前面
|
|
|
|
|
return Number(a.minute) - Number(b.minute); // b.minute > a.minute 排前面
|
|
|
|
|
});
|
|
|
|
|
console.log("排序后数据:",sleepList)
|
|
|
|
|
// 获取当前已存在的 sleepList(如果有)
|
|
|
|
|
let currentSleepList = this.data.sleepList || [];
|
|
|
|
|
|
|
|
|
|
// 将新的 sleepList 追加到现有的 sleepList 中
|
|
|
|
|
let updatedSleepList = currentSleepList.concat(sleepList);
|
|
|
|
|
// 将 sleepList 放在前面,currentSleepList 放在后面,实现新的数据插入在前
|
|
|
|
|
let updatedSleepList = sleepList.concat(currentSleepList);;
|
|
|
|
|
|
|
|
|
|
// 更新 data 中的 sleepList
|
|
|
|
|
this.setData({
|
|
|
|
|
sleepList: updatedSleepList
|
|
|
|
|
});
|
|
|
|
|
console.log("data数据:",this.data.sleepList)
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
@ -364,7 +367,11 @@ Page({
|
|
|
|
|
// const batteryPacket = DataPacket.generateBatteryCheckPacket();
|
|
|
|
|
// SendCommandUtil.sendPackage(this.data.deviceId,batteryPacket);
|
|
|
|
|
|
|
|
|
|
// const HRPacket = DataPacket.generateReadHRDataPacket();
|
|
|
|
|
// SendCommandUtil.sendPackage(this.data.deviceId,HRPacket);
|
|
|
|
|
|
|
|
|
|
this.sendHealthCommand(0x53)
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getStep(){
|
|
|
|
@ -378,6 +385,31 @@ Page({
|
|
|
|
|
if(cmd == null){
|
|
|
|
|
cmd = 0x55;
|
|
|
|
|
}
|
|
|
|
|
if(cmd == 0x55){
|
|
|
|
|
// 获取当前时间
|
|
|
|
|
let currentTime = Math.floor(new Date().getTime() / 1000);
|
|
|
|
|
// 如果是第一次调用,则不判断时间,如果是第二次调用,要判断本次调用与上次是否间隔18秒(因手表机制问题,不能频繁发送指令给手表端)
|
|
|
|
|
console.log(this.data.initTime,this.data.initIndex)
|
|
|
|
|
if(this.data.initIndex === 0){
|
|
|
|
|
this.setData({
|
|
|
|
|
initIndex: this.data.initIndex + 1,
|
|
|
|
|
initTime: currentTime
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// 初始时间
|
|
|
|
|
let initTime = this.data.initTime
|
|
|
|
|
let timeDifference = currentTime - initTime;
|
|
|
|
|
if(this.data.initIndex > 0 && timeDifference > 20){
|
|
|
|
|
this.setData({
|
|
|
|
|
initIndex: this.data.initIndex + 1,
|
|
|
|
|
initTime: currentTime
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let packet = DataPacket.generateReadDataPacket(cmd);
|
|
|
|
|
console.log("发送指令到设备端>>>:", this.uint8ArrayToHex(packet));
|
|
|
|
|
SendCommandUtil.sendPackage(this.data.deviceId, packet);
|
|
|
|
|