完成008A功能开发
This commit is contained in:
@ -16,7 +16,7 @@ import {
|
||||
} from '@/utils/MsgPops.js';
|
||||
import Common from '@/utils/Common.js';
|
||||
import api from '@/api/670/HBY670.js'
|
||||
|
||||
import gbk from '@/utils/gbk.js'
|
||||
|
||||
class SendBatchData {
|
||||
|
||||
@ -28,9 +28,13 @@ class SendBatchData {
|
||||
this.ble = _ble;
|
||||
}
|
||||
|
||||
//发送开机视频
|
||||
//发送开机视频,1536包
|
||||
SendVideo(bufferSize) {
|
||||
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
const platform = systemInfo.platform;
|
||||
const isIOS = platform === 'ios';
|
||||
|
||||
let these = this.these;
|
||||
let f = this.f;
|
||||
let ble = this.ble;
|
||||
@ -49,7 +53,7 @@ class SendBatchData {
|
||||
console.log("开始发送分片数据");
|
||||
return new Promise((resolve, reject) => {
|
||||
if (f) {
|
||||
ble.data.voiceUploading=true;
|
||||
ble.data.voiceUploading = true;
|
||||
// 总数据包数
|
||||
var totalPackets = 1536; //36;
|
||||
|
||||
@ -64,7 +68,7 @@ class SendBatchData {
|
||||
const sendNextVideoPacket = () => {
|
||||
// console.log("准备发送一段数据");
|
||||
if (currentPacket > totalPackets) {
|
||||
ble.data.voiceUploading=false;
|
||||
ble.data.voiceUploading = false;
|
||||
if (!ReSendNo) {
|
||||
setTimeout(() => {
|
||||
|
||||
@ -76,7 +80,7 @@ class SendBatchData {
|
||||
}).catch((ex) => {
|
||||
console.log("出现异常", ex);
|
||||
});
|
||||
}, 500);
|
||||
}, 2000);
|
||||
|
||||
}
|
||||
|
||||
@ -128,10 +132,10 @@ class SendBatchData {
|
||||
|
||||
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint8(beginIndex + i, packetData[i]);
|
||||
dataView.setUint8(beginIndex + i, parseInt(packetData[i], 16));
|
||||
}
|
||||
|
||||
let inteval = 80;
|
||||
let inteval = isIOS ? 300 : 80;
|
||||
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
|
||||
.wirteCharactId, 10).then(() => {
|
||||
@ -152,7 +156,7 @@ class SendBatchData {
|
||||
currentPacket);
|
||||
setTimeout(sendNextVideoPacket, 800);
|
||||
} else {
|
||||
ble.data.voiceUploading=false;
|
||||
ble.data.voiceUploading = false;
|
||||
hideLoading(these);
|
||||
|
||||
showPop({
|
||||
@ -194,7 +198,7 @@ class SendBatchData {
|
||||
|
||||
ble.sendString(f.deviceId, "video transmit start", f
|
||||
.writeServiceId, f.wirteCharactId).then(res => {
|
||||
ble.data.voiceUploading=true;
|
||||
ble.data.voiceUploading = true;
|
||||
setTimeout(() => {
|
||||
console.log("握手成功了");
|
||||
resolve(true);
|
||||
@ -244,6 +248,8 @@ class SendBatchData {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
Promise.all([p1, p2]).then((arr) => {
|
||||
@ -327,9 +333,7 @@ class SendBatchData {
|
||||
let duration = res.duration;
|
||||
|
||||
// 获取平台信息
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
const platform = systemInfo.platform;
|
||||
const isIOS = platform === 'ios';
|
||||
|
||||
|
||||
console.log("平台:", platform, "uni.chooseVideo返回 - 宽度:", width, "高度:", height,
|
||||
"时长:", duration);
|
||||
@ -379,7 +383,7 @@ class SendBatchData {
|
||||
}
|
||||
|
||||
|
||||
//发送图片,
|
||||
//发送图片,52包
|
||||
SendImg() {
|
||||
let these = this.these;
|
||||
let f = this.f;
|
||||
@ -558,7 +562,7 @@ class SendBatchData {
|
||||
});
|
||||
}
|
||||
|
||||
//发送人员信息
|
||||
//发送人员信息(点阵)
|
||||
SendUsr(totalRows) {
|
||||
|
||||
let these = this.these;
|
||||
@ -594,14 +598,17 @@ class SendBatchData {
|
||||
//握手
|
||||
let holdHand = (hexs, time) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("11111");
|
||||
|
||||
|
||||
these.sendData(hexs, 'ble', "string").then(res => {
|
||||
ble.sendString(f.deviceId, hexs, null, null, 15).then(res => {
|
||||
console.log("22222")
|
||||
setTimeout(() => {
|
||||
resolve(res)
|
||||
}, time);
|
||||
|
||||
}).catch(ex => {
|
||||
console.log("33333", ex);
|
||||
console.error("握手失败")
|
||||
reject(ex)
|
||||
});
|
||||
@ -715,7 +722,7 @@ class SendBatchData {
|
||||
setTimeout(() => {
|
||||
Promise.allSettled([holdHand('word transmit start', 2200), drawText()]).then(results => {
|
||||
if (results[0].status == 'rejected') {
|
||||
MsgError("与蓝牙设备握手失败,请重试", '', these);
|
||||
MsgError("与蓝牙设备握手失败,请重试," + results[0].reason, '', these);
|
||||
setTimeout(() => {
|
||||
hideLoading(these)
|
||||
}, 500);
|
||||
@ -749,11 +756,267 @@ class SendBatchData {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
SendMsg(){
|
||||
|
||||
|
||||
|
||||
SendMsgByGBK(txts, _mq) {
|
||||
debugger;
|
||||
let these = this.these;
|
||||
let f = this.f;
|
||||
let ble = this.ble;
|
||||
let mq = _mq;
|
||||
if (!these.permissions.includes('5') && these.Status.apiType !== 'listA') {
|
||||
|
||||
showPop({
|
||||
message: '无操作权限',
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
buttonTextColor: "#FFFFFFde",
|
||||
okCallback: null,
|
||||
buttonText: "确定"
|
||||
}, these)
|
||||
return;
|
||||
}
|
||||
|
||||
showLoading(these, {
|
||||
text: "请稍候..."
|
||||
});
|
||||
let send = (txt) => {
|
||||
|
||||
return mq.publish("B/" + these.device.deviceImei, txt);
|
||||
}
|
||||
|
||||
|
||||
let curr = 0;
|
||||
let sendNext = () => {
|
||||
if (curr >= txts.length) {
|
||||
hideLoading(these);
|
||||
MsgSuccess("发送成功", '', these);
|
||||
return;
|
||||
}
|
||||
let txt = txts[curr];
|
||||
let arr = gbk.encode(txt)
|
||||
console.log("正在发送:", txt);
|
||||
|
||||
let json = {
|
||||
ins_msg: [curr + 1]
|
||||
}
|
||||
|
||||
let gbkData = gbk.arr2hex(arr);
|
||||
for (let i = 0; i < gbkData.length; i += 2) {
|
||||
let value = parseInt(gbkData[i] + "" + gbkData[i + 1], 16);
|
||||
json.ins_msg.push(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
txt = JSON.stringify(json);
|
||||
updateLoading(these, {
|
||||
text: '正在发送' + (curr + 1) + '/' + txts.length
|
||||
});
|
||||
if (send(txt)) {
|
||||
curr++;
|
||||
setTimeout(sendNext, 200);
|
||||
} else {
|
||||
MsgError("发送失败了,请检查网络连接后重试", '', these);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setTimeout(sendNext, 2200);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
HoldYouHand(cmd, timeout) {
|
||||
let these = this.these;
|
||||
let f = this.f;
|
||||
let ble = this.ble;
|
||||
return new Promise((resolve, reject) => {
|
||||
ble.sendString(f.deviceId, cmd, f
|
||||
.writeServiceId, f.wirteCharactId).then(res => {
|
||||
|
||||
if (timeout) {
|
||||
setTimeout(() => {
|
||||
console.log("握手成功了");
|
||||
resolve(true);
|
||||
}, timeout);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(true);
|
||||
|
||||
}).catch(ex => {
|
||||
reject(ex);
|
||||
console.error("发送文本‘" + cmd + "’失败");
|
||||
console.error("ex=", ex);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
sendUsrByGBK(textLines, ReSendNo) {
|
||||
let these = this.these;
|
||||
let f = this.f;
|
||||
let ble = this.ble;
|
||||
if (!these.permissions.includes('4') && these.Status.apiType !== 'listA') {
|
||||
|
||||
showPop({
|
||||
message: '无操作权限',
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
okCallback: null,
|
||||
buttonText: "确定"
|
||||
}, these)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
showLoading(these, {
|
||||
text: "请稍候..."
|
||||
});
|
||||
var sendText = () => {
|
||||
// 总数据包数
|
||||
let totalPackets = textLines.length;
|
||||
let currentPacket = 1;
|
||||
// console.log("currentPacket=",currentPacket);
|
||||
// console.log("ReSendNo=",ReSendNo);
|
||||
if (ReSendNo) {
|
||||
totalPackets = ReSendNo;
|
||||
currentPacket = ReSendNo;
|
||||
}
|
||||
// console.log("currentPacket=",currentPacket);
|
||||
// 发送单个数据包
|
||||
const sendNextPacket = () => {
|
||||
|
||||
if (currentPacket > totalPackets) {
|
||||
if (!ReSendNo) {
|
||||
setTimeout(() => {
|
||||
this.HoldYouHand("transmit complete");
|
||||
}, 500);
|
||||
|
||||
}
|
||||
|
||||
showPop({
|
||||
showPop: true, //是否显示弹窗
|
||||
popType: 'custom',
|
||||
bgColor: '#383934bd',
|
||||
borderColor: '#BBE600',
|
||||
textColor: '#ffffffde',
|
||||
buttonBgColor: '#BBE600',
|
||||
buttonTextColor: '#232323DE',
|
||||
iconUrl: '/static/images/6155/DeviceDetail/sendSucc.png',
|
||||
message: '人员信息发送成功',
|
||||
buttonText: '确定',
|
||||
clickEvt: 'SendUsr',
|
||||
visiblePrompt: false,
|
||||
promptTitle: '',
|
||||
modelValue: '',
|
||||
visibleClose: true
|
||||
}, these);
|
||||
these.setBleFormData();
|
||||
|
||||
|
||||
let json = {
|
||||
deviceId: these.device.id,
|
||||
name: these.formData.name,
|
||||
position: these.formData.job,
|
||||
unitName: these.formData.company,
|
||||
code: these.formData.id
|
||||
};
|
||||
api.sendUsr(json)
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取当前行文字
|
||||
const text = textLines[currentPacket - 1] || '';
|
||||
let arr = gbk.encode(text)
|
||||
let gbkData = gbk.arr2hex(arr);
|
||||
|
||||
console.log("正在发送:" + text);
|
||||
console.log("正在发送:" + arr);
|
||||
// 构建数据包
|
||||
const bufferSize = 5 + gbkData.length / 2; // 头部4字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x03); // 帧类型:文字
|
||||
dataView.setUint8(2, currentPacket.toString(16)); // 包序号
|
||||
dataView.setUint16(3, text.length, false); // 数据长度
|
||||
|
||||
|
||||
// 填充数据
|
||||
let index = 0;
|
||||
for (var i = 0; i < gbkData.length; i += 2) {
|
||||
let value = parseInt(gbkData[i] + "" + gbkData[i + 1], 16);
|
||||
console.log("value=", value)
|
||||
dataView.setUint8(5 + index, value);
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
// 发送数据包
|
||||
|
||||
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(() => {
|
||||
// 更新进度
|
||||
console.log(
|
||||
`发送文字数据包 ${currentPacket}/${totalPackets}: ${text}`
|
||||
);
|
||||
|
||||
// 发送下一个包
|
||||
currentPacket++;
|
||||
setTimeout(sendNextPacket, 80);
|
||||
}).catch(err => {
|
||||
|
||||
showPop({
|
||||
message: "文字发送失败," + err.msg,
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
}, these);
|
||||
}).finally(() => {
|
||||
hideLoading(these);
|
||||
});
|
||||
};
|
||||
|
||||
// 开始发送第一个包
|
||||
sendNextPacket();
|
||||
}
|
||||
|
||||
|
||||
if (ReSendNo) {
|
||||
sendText(ReSendNo);
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.HoldYouHand("word transmit start", 120).then(
|
||||
() => {
|
||||
|
||||
setTimeout(sendText, 200);
|
||||
}).catch((ex) => {
|
||||
console.log("握手没有成功", ex);
|
||||
hideLoading(these);
|
||||
showPop({
|
||||
message: ex.msg,
|
||||
iconUrl: "/static/images/common/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
}, these);
|
||||
});
|
||||
}, 0);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default SendBatchData;
|
||||
Reference in New Issue
Block a user