跟朱工合并7305的功能
# Conflicts: # utils/BleHelper.js # utils/BleReceive.js
This commit is contained in:
@ -240,7 +240,7 @@
|
|||||||
mode: '',
|
mode: '',
|
||||||
bleStatu: ''
|
bleStatu: ''
|
||||||
},
|
},
|
||||||
inteval: 200,
|
inteval: 500,
|
||||||
device: {
|
device: {
|
||||||
id: "",
|
id: "",
|
||||||
deviceName: "",
|
deviceName: "",
|
||||||
@ -466,10 +466,12 @@
|
|||||||
return f;
|
return f;
|
||||||
},
|
},
|
||||||
bleValueNotify: function(receive, device, path) {
|
bleValueNotify: function(receive, device, path) {
|
||||||
|
|
||||||
if (this.Status.pageHide) {
|
if (this.Status.pageHide) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let json = recei.ReceiveData(receive, device, path);
|
let json = recei.ReceiveData(receive, device, path);
|
||||||
|
|
||||||
if (!json) {
|
if (!json) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -479,6 +481,12 @@
|
|||||||
these.formData[key] = json[key];
|
these.formData[key] = json[key];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if ('statu' in json) {
|
||||||
|
these.formData.statu = json.statu == '1' ? '充电中' : '未充电';
|
||||||
|
}
|
||||||
|
if ('xuhang' in json) {
|
||||||
|
these.formData.xuhang = json.xuhang;
|
||||||
|
}
|
||||||
|
|
||||||
if ('battary' in json && this.formData.battary <= 20) {
|
if ('battary' in json && this.formData.battary <= 20) {
|
||||||
this.showPop({
|
this.showPop({
|
||||||
@ -561,92 +569,85 @@
|
|||||||
// 分包发送图片数据
|
// 分包发送图片数据
|
||||||
var sendImagePackets = function(packetData) {
|
var sendImagePackets = function(packetData) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
// 总数据包数
|
// 1. 构建一个包含完整头、数据和尾的完整数据包
|
||||||
const totalPackets = 3;
|
const header = [0xFA, 0x09, 0x04, 0x00];
|
||||||
let currentPacket = 1;
|
const footer = [0xFF];
|
||||||
|
const imageData = packetData.map(hex => parseInt(hex, 16));
|
||||||
|
|
||||||
|
// 确保图像数据为1024字节,不足则补0
|
||||||
// 发送单个数据包
|
while (imageData.length < 1024) {
|
||||||
const sendNextPacket = () => {
|
imageData.push(0x00);
|
||||||
if (currentPacket > totalPackets) {
|
|
||||||
setTimeout(() => {
|
|
||||||
hideLoading(these);
|
|
||||||
these.Status.BottomMenu.show = false;
|
|
||||||
|
|
||||||
these.showPop({
|
|
||||||
message: "上传成功",
|
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
|
|
||||||
borderColor: '#BBE600',
|
|
||||||
buttonBgColor: '#BBE600'
|
|
||||||
});
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
}, 0)
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fullPacket = new Uint8Array([...header, ...imageData.slice(0, 1024), ...footer]);
|
||||||
|
const fullBuffer = fullPacket.buffer;
|
||||||
|
|
||||||
|
// 2. 将完整数据包切片成20字节的小块进行发送
|
||||||
|
const chunkSize = 20;
|
||||||
|
const numChunks = Math.ceil(fullBuffer.byteLength / chunkSize);
|
||||||
|
let chunkIndex = 0;
|
||||||
|
|
||||||
|
const sendNextChunk = () => {
|
||||||
let start = 0;
|
if (chunkIndex >= numChunks) {
|
||||||
let bufferSize = 343; //总共1029字节3包,正好每包343字节
|
setTimeout(() => {
|
||||||
//FA 09 04 00 1024字节 FF
|
hideLoading(these);
|
||||||
var buffer = new ArrayBuffer(bufferSize);
|
these.Status.BottomMenu.show = false;
|
||||||
var dataView = new DataView(buffer);
|
these.showPop({
|
||||||
if (currentPacket == 1) {
|
message: "上传成功",
|
||||||
dataView.setUint8(0, 0xFA); // 帧头
|
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
|
||||||
dataView.setUint8(1, 0x09); // 帧头
|
borderColor: '#BBE600',
|
||||||
dataView.setUint8(2, 0x04); // 帧头
|
buttonBgColor: '#BBE600'
|
||||||
dataView.setUint8(3, 0x00); // 帧头
|
});
|
||||||
|
resolve();
|
||||||
|
}, 0);
|
||||||
for (let i = 0; i < packetData.length; i++) {
|
return;
|
||||||
dataView.setUint8(4 + i, parseInt(packetData[i], 16));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (currentPacket == totalPackets) {
|
|
||||||
dataView.setUint8(bufferSize - 1, 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
//发送数据包
|
const start = chunkIndex * chunkSize;
|
||||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
|
const end = Math.min(start + chunkSize, fullBuffer.byteLength);
|
||||||
30)
|
const chunk = fullBuffer.slice(start, end);
|
||||||
.then(() => {
|
|
||||||
|
const hexArray = Array.from(new Uint8Array(chunk)).map(b => b.toString(16).padStart(2, '0'));
|
||||||
|
console.log(`发送图片数据块 ${chunkIndex + 1}/${numChunks}:`, hexArray.join(' '));
|
||||||
|
|
||||||
|
updateLoading(these, {
|
||||||
updateLoading(these, {
|
text: "正在发送 " + (chunkIndex + 1) + "/" + numChunks
|
||||||
text: "正在发送" + currentPacket + "/" + totalPackets
|
|
||||||
|
|
||||||
})
|
|
||||||
currentPacket++;
|
|
||||||
|
|
||||||
setTimeout(sendNextPacket, 100);
|
|
||||||
}).catch(err => {
|
|
||||||
if (err.code == 10007) {
|
|
||||||
setTimeout(sendNextPacket, 100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("发送数据包失败了", err);
|
|
||||||
|
|
||||||
these.Status.BottomMenu.show = false;
|
|
||||||
these.showPop({
|
|
||||||
message: "发送数据包失败了" + err.msg,
|
|
||||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
|
||||||
borderColor: "#e034344d",
|
|
||||||
buttonBgColor: "#E03434",
|
|
||||||
});
|
|
||||||
|
|
||||||
hideLoading(these);
|
|
||||||
reject(err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ble.sendData(f.deviceId, chunk, f.writeServiceId, f.wirteCharactId, 100)
|
||||||
|
.then(() => {
|
||||||
|
chunkIndex++;
|
||||||
|
setTimeout(sendNextChunk, 30); // 每个小包之间延时30ms
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
if (err.code == 10007 || err.code == -1) {
|
||||||
|
setTimeout(sendNextChunk, 30);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("发送数据包失败了", err);
|
||||||
|
|
||||||
|
these.Status.BottomMenu.show = false;
|
||||||
|
these.showPop({
|
||||||
|
message: "发送数据包失败了: " + err.msg,
|
||||||
|
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||||
|
borderColor: "#e034344d",
|
||||||
|
buttonBgColor: "#E03434",
|
||||||
|
});
|
||||||
|
|
||||||
|
hideLoading(these);
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
sendNextChunk();
|
||||||
|
|
||||||
|
} catch (ex) {
|
||||||
|
console.error("构建图片数据包失败", ex);
|
||||||
|
hideLoading(these);
|
||||||
|
reject(ex);
|
||||||
}
|
}
|
||||||
// 开始发送数据
|
|
||||||
sendNextPacket();
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1050,77 +1051,60 @@
|
|||||||
|
|
||||||
var promise = new Promise((resolve, reject) => {
|
var promise = new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
|
// 1. 构建一个包含完整包头、数据和包尾的261字节数据包
|
||||||
|
const bufferSize = 261;
|
||||||
|
let fullBuffer = new ArrayBuffer(bufferSize);
|
||||||
|
let dataView = new DataView(fullBuffer);
|
||||||
|
|
||||||
let packetSize = rgbdata.length; //每包均分的数量
|
dataView.setUint8(0, 0xFA);
|
||||||
let mode = rgbdata.length % packetSize; //最后一包的数量
|
dataView.setUint8(1, type);
|
||||||
let cnt =
|
dataView.setUint8(2, 0x01);
|
||||||
1; // parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 :0); //总包数量
|
dataView.setUint8(3, 0x00);
|
||||||
let curr = 1; //当前包序号
|
|
||||||
|
|
||||||
let sendNext = () => {
|
for (let i = 0; i < rgbdata.length; i++) {
|
||||||
|
dataView.setUint8(4 + i, rgbdata[i]);
|
||||||
|
}
|
||||||
|
// 用0填充剩余部分,直到最后一个字节
|
||||||
|
for (let i = 4 + rgbdata.length; i < bufferSize - 1; i++) {
|
||||||
|
dataView.setUint8(i, 0x00);
|
||||||
|
}
|
||||||
|
|
||||||
if (curr > cnt) {
|
dataView.setUint8(bufferSize - 1, 0xFF);
|
||||||
|
|
||||||
|
// 2. 将完整数据包切片成20字节的小块进行发送
|
||||||
|
const chunkSize = 20;
|
||||||
|
const numChunks = Math.ceil(fullBuffer.byteLength / chunkSize);
|
||||||
|
let chunkIndex = 0;
|
||||||
|
|
||||||
|
let sendNextChunk = () => {
|
||||||
|
if (chunkIndex >= numChunks) {
|
||||||
resolve();
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let bufferSize = 261;
|
const start = chunkIndex * chunkSize;
|
||||||
|
const end = Math.min(start + chunkSize, fullBuffer.byteLength);
|
||||||
|
const chunk = fullBuffer.slice(start, end);
|
||||||
|
|
||||||
|
const hexArray = Array.from(new Uint8Array(chunk)).map(b => b.toString(16).padStart(2, '0'));
|
||||||
|
console.log(`发送数据块 ${chunkIndex + 1}/${numChunks}:`, hexArray.join(' '));
|
||||||
|
|
||||||
console.log("bufferSize=", bufferSize)
|
ble.sendData(f.deviceId, chunk, f.writeServiceId, f.wirteCharactId, 100).then(() => {
|
||||||
|
chunkIndex++;
|
||||||
let buffer = new ArrayBuffer(bufferSize);
|
setTimeout(sendNextChunk, 30); // 每个小包之间延时30ms
|
||||||
let dataView = new DataView(buffer);
|
|
||||||
let startIndex = (curr - 1) * packetSize;
|
|
||||||
|
|
||||||
let endIndex = Math.min(startIndex + packetSize, rgbdata
|
|
||||||
.length);
|
|
||||||
if (startIndex > endIndex) {
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let packetData = rgbdata.slice(startIndex,
|
|
||||||
endIndex); //取一片数据发送
|
|
||||||
console.log("packetData.length=", packetData.length);
|
|
||||||
let start = 0;
|
|
||||||
if (curr == 1) {
|
|
||||||
dataView.setUint8(0, 0xFA);
|
|
||||||
dataView.setUint8(1, type);
|
|
||||||
dataView.setUint8(2, 0x01);
|
|
||||||
dataView.setUint8(3, 0x00);
|
|
||||||
|
|
||||||
|
|
||||||
start = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < packetData.length; i++) {
|
|
||||||
dataView.setUint8(start + i, packetData[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
dataView.setUint8(bufferSize - 1, 0xFF);
|
|
||||||
|
|
||||||
let inteval = parseInt(this.inteval ? this.inteval : 50);
|
|
||||||
console.log("inteval=", inteval)
|
|
||||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
|
|
||||||
.wirteCharactId, 100).then(() => {
|
|
||||||
|
|
||||||
curr++;
|
|
||||||
setTimeout(sendNext, inteval);
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
|
||||||
if (err.code == '10007') {
|
if (err.code == '10007') {
|
||||||
setTimeout(sendNext, inteval);
|
setTimeout(sendNextChunk, 30);
|
||||||
} else {
|
} else {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendNext();
|
sendNextChunk();
|
||||||
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.log("ex=", ex);
|
console.log("ex=", ex);
|
||||||
|
|
||||||
reject(ex);
|
reject(ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1164,7 +1148,7 @@
|
|||||||
// console.log("222222");
|
// console.log("222222");
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
flag = false;
|
flag = false;
|
||||||
console.log("33333");
|
console.log("发送数据包出现异常", ex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -729,12 +729,13 @@ class BleHelper {
|
|||||||
this.updateCache();
|
this.updateCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("str=", str);
|
// console.log("str1=", str);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error("将数据转文本失败", ex);
|
console.error("将数据转文本失败", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log("11111");
|
||||||
let recData = {
|
let recData = {
|
||||||
deviceId: receive.deviceId,
|
deviceId: receive.deviceId,
|
||||||
serviceId: receive.serviceId,
|
serviceId: receive.serviceId,
|
||||||
@ -1222,6 +1223,7 @@ class BleHelper {
|
|||||||
}
|
}
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
startgetService(id);
|
startgetService(id);
|
||||||
|
|
||||||
}, 100+repeatCnt*300);
|
}, 100+repeatCnt*300);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,27 +1,9 @@
|
|||||||
class BleReceive {
|
class BleReceive {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.StorageKey = "linkedDevices";
|
this.StorageKey = "linkedDevices";
|
||||||
this.ReceiveDic=[
|
|
||||||
{
|
|
||||||
url:'/pages/6155/deviceDetail',
|
|
||||||
method:this.Receive_6155
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url:'/pages/7305/BJQ7305',
|
|
||||||
method:this.Receive_6155
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url:'/pages/650/HBY650',
|
|
||||||
method:this.Receive_650
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url:'/pages/670/HBY670',
|
|
||||||
method:this.Receive_670
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
getCurrentPagePath() {
|
getCurrentPagePath() {
|
||||||
|
|
||||||
const pages = getCurrentPages();
|
const pages = getCurrentPages();
|
||||||
@ -68,31 +50,19 @@ class BleReceive {
|
|||||||
ReceiveData(receive,f,path,recArr) {
|
ReceiveData(receive,f,path,recArr) {
|
||||||
if(f && f.macAddress && f.device && f.device.id){
|
if(f && f.macAddress && f.device && f.device.id){
|
||||||
let data={};
|
let data={};
|
||||||
|
if(f.device.detailPageUrl=='/pages/6155/deviceDetail' || f.device.detailPageUrl=='/pages/7305/BJQ7305'){
|
||||||
let rec=this.ReceiveDic.find(r=>{
|
// console.log("该设备是6155");
|
||||||
return r.url==f.device.detailPageUrl;
|
data= this.Receive_6155(receive,f,path,recArr);
|
||||||
})
|
|
||||||
if(rec){
|
|
||||||
data=rec.method(receive,f,path,recArr);
|
|
||||||
}
|
}
|
||||||
// if(f.device.detailPageUrl=='/pages/6155/deviceDetail'){
|
|
||||||
// // console.log("该设备是6155");
|
|
||||||
// data= this.Receive_6155(receive,f,path,recArr);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if(f.device.detailPageUrl=='/pages/7305/BJQ7305'){
|
if(f.device.detailPageUrl=='/pages/650/HBY650'){
|
||||||
// // console.log("该设备是7305");
|
// console.log("该设备是650");
|
||||||
// data= this.Receive_6155(receive,f,path,recArr);
|
data= this.Receive_650(receive,f,path,recArr);
|
||||||
// }
|
}
|
||||||
|
if(f.device.detailPageUrl=='/pages/670/HBY670'){
|
||||||
// if(f.device.detailPageUrl=='/pages/650/HBY650'){
|
// console.log("该设备是670");
|
||||||
// // console.log("该设备是650");
|
data= this.Receive_670(receive,f,path,recArr);
|
||||||
// data= this.Receive_650(receive,f,path,recArr);
|
}
|
||||||
// }
|
|
||||||
// if(f.device.detailPageUrl=='/pages/670/HBY670'){
|
|
||||||
// // console.log("该设备是670");
|
|
||||||
// data= this.Receive_670(receive,f,path,recArr);
|
|
||||||
// }
|
|
||||||
// console.log("收到数据并处理完毕,",data);
|
// console.log("收到数据并处理完毕,",data);
|
||||||
return data;
|
return data;
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
Reference in New Issue
Block a user