6155完成部分协议对接

This commit is contained in:
liub
2025-08-15 16:39:00 +08:00
parent 6ef2bb08b9
commit e95b2466e1
10 changed files with 871 additions and 708 deletions

View File

@ -2,17 +2,14 @@
<view class="message-popup" :class="{ 'show': config.show }">
<view class="mask" @click="closeMenu" :class="{ 'show': config.show }"
:style="{backgroundColor:config.maskBgColor,display:(config.showMask?'':'none')}"
>
:style="{backgroundColor:config.maskBgColor,display:(config.showMask?'':'none')}">
</view>
<view class="bottom-slide-menu" :style="{ backgroundColor: config.bgColor }" :class="{ 'show': config.show }"
@touchmove.stop.prevent>
<view class="menu-header" :class="config.showHeader?'':'displayNone'">
<view class="title" :style="{ color: config.textColor}">{{ config.title }}</view>
<view class="close-icon" @click="closeMenu"
:style="{display:(config.showClose?'':'none')}"
>
<view class="close-icon" @click="closeMenu" :style="{display:(config.showClose?'':'none')}">
<image src="/static/Images/public/close.png" mode="aspectFit"></image>
</view>
</view>
@ -28,8 +25,14 @@
<view class="p100" :style="{backgroundColor:config.activeIndex==index?config.itemBgColor:'',
justifyContent:config.textAlign
}">
<view class="imgContent" :style="{
height:config.itemHeight,
width:config.itemHeight
}">
<image v-if="item.icon" :src="item.icon" mode="aspectFit"></image>
</view>
<text>{{ item.text }}</text>
</view>
@ -112,7 +115,6 @@
}
}
</script>
<style>
@ -126,7 +128,7 @@
}
.p100 {
width: 100%;
width: calc(100% - 20rpx);
height: 100%;
border-radius: 8rpx;
display: flex;
@ -136,7 +138,8 @@
justify-content: flex-start;
align-items: center;
box-sizing: border-box;
padding: 0rpx 20rpx;
padding: 0rpx 20rpx 0rpx 0rpx;
margin-left: 20rpx;
}
.displayNone {
@ -151,7 +154,7 @@
z-index: 9999;
transition: transform 0.3s ease-out;
transform: translateY(100%);
border-radius: 16rpx 16rpx 0 0;
border-radius: 32rpx 32rpx 0 0;
box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
}
@ -217,11 +220,24 @@
width: 100%;
box-sizing: border-box;
position: relative;
margin-bottom: 20rpx;
}
.menu-item image {
width: 40rpx;
height: 40rpx;
}
.imgContent {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: center;
align-items: center;
background: #4a4a4a;
border-radius: 10rpx;
margin-right: 20rpx;
}

View File

@ -1,19 +1,13 @@
<template>
<view>
<!-- 只创建一个Canvas用于复用 -->
<canvas
type="2d"
canvas-id="reusableCanvas"
:width="currentCanvasWidth"
:height="currentCanvasHeight"
class="offscreen-canvas"
></canvas>
<canvas type="2d" canvas-id="reusableCanvas" :width="currentCanvasWidth" :height="currentCanvasHeight"
class="offscreen-canvas"></canvas>
</view>
</template>
<script>
export default {
name: "TextToHex",
name: "TextToHexV1",
props: {
txts: {
type: Array,
@ -27,11 +21,11 @@
},
bgColor: {
type: String,
default:"#000000"
default: "#ffffff"
},
color: {
type: String,
default:"#FFFFFF"
default: "#000000"
}
},
data() {
@ -72,16 +66,50 @@
* 复用单个Canvas处理所有文本行
*/
async drawAndGetPixels() {
if (this.validTxts.length === 0) {
return [];
let convertCharToMatrix=function(imageData) {
// console.log("imgData=",imageData)
let matrix = [];
// 逐行处理
for (let y = 0; y < 16; y++) {
let byte1 = 0,
byte2 = 0;
// 每行16个像素分为两个字节
for (let x = 0; x < 16; x++) {
// 计算像素在imageData中的索引 (RGBA格式)
let index = (y * 16 + x) * 4;
let red = imageData[index];
// 黑色像素R值较低视为1白色视为0
let isBlack = red < 128;
if (x < 8) {
// 第一个字节左8位
if (isBlack) {
byte1 |= 0x80 >> x; // 从左到右设置位
}
} else {
// 第二个字节右8位
if (isBlack) {
byte2 |= 0x80 >> (x - 8);
}
}
}
const result = [];
const ctx = this.ctx;
// 将字节转换为两位十六进制字符串
matrix.push('0x' + byte1.toString(16).padStart(2, '0').toUpperCase());
matrix.push('0x' + byte2.toString(16).padStart(2, '0').toUpperCase());
}
return matrix;
}
let drawTxt=async (textLine)=> {
let result = {};
let ctx = this.ctx;
// 循环处理每行文本
for (let i = 0; i < this.validTxts.length; i++) {
const textLine = this.validTxts[i];
// 1. 动态调整Canvas尺寸
this.currentCanvasWidth = this.calcLineWidth(textLine);
this.currentCanvasHeight = this.fontSize;
@ -93,16 +121,16 @@
ctx.setFillStyle(this.color);
ctx.setTextBaseline('middle');
ctx.setFontSize(this.fontSize);
ctx.font = `${this.fontSize}px SimHei, Microsoft YaHei, Arial, sans-serif`;
ctx.font = `${this.fontSize}px "PingFang SC", PingFang SC, Arial, sans-serif`;
// 4. 绘制当前行文本
let currentX = 0;
const currentY = this.fontSize / 2;
let currentY = this.fontSize / 2;
for (let j = 0; j < textLine.length; j++) {
const char = textLine[j];
let char = textLine[j];
ctx.fillText(char, currentX, currentY);
// 按实际字符宽度计算间距
const charWidth = ctx.measureText(char).width;
let charWidth = ctx.measureText(char).width;
currentX += charWidth;
}
@ -116,25 +144,42 @@
width: this.currentCanvasWidth,
height: this.currentCanvasHeight,
success: res => {
result.push({
result={
line: textLine,
pixelData: res.data,
width: this.currentCanvasWidth,
height: this.currentCanvasHeight
});
};
resolve();
},
fail: err => {
// console.error(`处理第${i+1}行失败:`, err);
reject(err);
reject(err)
}
});
});
});
}
return result;
}
let arr = [];
// 循环处理每行文本
for (let i = 0; i < this.validTxts.length; i++) {
let linePixls = [];
let item = this.validTxts[i];
console.log("item=",item);
for (var j = 0; j < item.length; j++) {
let result = await drawTxt(item[j]);
linePixls.push(convertCharToMatrix(result.pixelData));
}
console.log("hexs=",linePixls.join(","));
arr.push(linePixls);
}
return arr;
}
}
};
</script>

View File

@ -23,10 +23,10 @@
return {
visible: false,
dotsCount: 12,
dotColors: ['#CEF231c2'],
dotColors: ['#CEF231'],
text: '请稍候...',//文本文字
textColor: '#FFFFFFde',//文本颜色
radius: 35,//圆的半径
radius: 32,//圆的半径
duration: 1200,//动画的播放速度
colorIndex: 0
}
@ -158,7 +158,7 @@
position: absolute;
top: 50%;
left: 50%;
width: 4rpx;
width: 6rpx;
height: 30rpx;
border-radius: 12rpx;
/* margin-top: -4rpx;

View File

@ -24,11 +24,11 @@
<view class="eqinfo">
<view class="item">
<text class="lbl">蓝牙名称</text>
<text class="value">{{formData.name}}</text>
<text class="value">{{formData.blename}}</text>
</view>
<view class="item">
<text class="lbl">信号强度</text>
<text class="value">{{formData.RSSI}}</text>
<text class="lbl">设备名称</text>
<text class="value">{{formData.deviceName}}</text>
</view>
<view class="item">
<text class="lbl">设备状态</text>
@ -83,26 +83,23 @@
<text class="usrtitle fleft">人员信息登记</text>
<view class="btnSend fright" v-on:click.stop="sendUsr">发送</view>
<view class="clear"></view>
<TextToHex class="TextToHex" ref="textToHex" :txts="textLines" :bgColor="'#000000'" :color="'#FFFFFF'"
:fontSize="16" />
<TextToHex class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#000000'"
:color="'#FFFFFF'" :fontSize="16" />
</view>
<view class="item">
<text class="lbl">单位</text>
<input class="value" v-model="textLines[0]" placeholder="请输入单位" placeholder-class="usrplace" />
<input class="value" v-model="formData.textLines[0]" placeholder="请输入单位" placeholder-class="usrplace" />
</view>
<view class="item">
<text class="lbl">部门</text>
<input class="value" v-model="formData.textLines[1]" placeholder="请输入姓名" placeholder-class="usrplace" />
</view>
<view class="item">
<text class="lbl">姓名</text>
<input class="value" v-model="textLines[1]" placeholder="请输入姓名" placeholder-class="usrplace" />
</view>
<view class="item">
<text class="lbl">职位</text>
<input class="value" v-model="textLines[2]" placeholder="请输入职位" placeholder-class="usrplace" />
</view>
<view class="item">
<text class="lbl">ID号</text>
<input class="value" v-model="textLines[3]" placeholder="请输入ID" placeholder-class="usrplace" />
<input class="value" v-model="formData.textLines[2]" placeholder="请输入职位" placeholder-class="usrplace" />
</view>
</view>
<view class="proinfo lamp">
<text class="title">产品信息</text>
@ -141,25 +138,31 @@
</view>
</BottomSlideMenuPlus>
<Progress :config="Status.Progress"></Progress>
<global-loading ref="loading" />
</view>
</template>
<script>
import TextToHexVue from '@/components/TextToHex/TextToHex.vue';
import bleTool from '@/utils/BleHelper.js';
import {
showLoading,
hideLoading,
updateLoading
} from '@/utils/loading.js'
var ble = null;
var these = null;
export default {
data() {
return {
Status: {
refferKey: '',
Pop: {
showPop: false, //是否显示弹窗
popType: 'custom',
textColor: '#ffffffde',
bgColor: '#383934bd',
borderColor: '#BBE600',
textColor: '#ffffffde',
buttonBgColor: '#BBE600',
buttonTextColor: '#232323DE',
iconUrl: '',
@ -206,105 +209,77 @@
showMask: true,
maskBgColor: '#00000066',
showClose: false
},
Progress: {
show: false, //是否显示
height: '20rpx',
showMask: true, //是否显示mask
maskBgColor: '#00000000', //mask背景颜色
contentBgColor: '#121212', //总背景颜色
showText: true, //是否显示当前进度的文字
txtColor: '#ffffffde', //文字的颜色
curr: 20, //当前进度
total: 100, //总进度
proBgColor: '#2a2a2a', //进度条底色,
proBorder: '', //进度条border
currBgColor: '#bbe600', //当前进度底色
currBorder: '', //当前进度border
borderRadius: '10rpx'
}
},
formData: {
img: '/static/images/6155/DeviceDetail/equip.png',
battary: '60',
xuhang: '1小时',
name: 'JQZM-EF4651',
RSSI: '-30',
statu: '运行中',
liangDu: '50',
id: ''
},
cEdit: {
img: '',
battary: '',
xuhang: '',
deviceName: '',
RSSI: '',
statu: '正常',
liangDu: '100',
id: '',
deviceId: '',
textLines: ['我爱你', '中国', '五星红旗'],
mode: ''
},
textLines: ['黄石消防支队','菜英俊','小队长','HSXF01061'],
device: {
deviceId: '',
writeServiceId: '',
wirteCharactId: '',
notifyServiceid: '',
notifyCharactId: ''
}
}
},
onUnload() {
ble.removeReceiveCallback(this);
},
onLoad: function() {
var these = this;
let eventChannel = this.getOpenerEventChannel();
//eventChannel.on('deviceControl', function(data) {
let data = {
data: {
deviceMac: '35:06:00:EF:46:51',
bluetoothName: 'JQZM-EF4651',
deviceName: 'JQZM-EF4651',
devicePic: '',
id: '35:06:00:EF:46:51'
}
};
console.log("收到父页面的参数:" + JSON.stringify(data));
var device = data.data;
these.device.deviceId = device.deviceMac;
these.formData.name = device.bluetoothName ? device.bluetoothName : device.deviceName;
these.formData.img = device.devicePic;
these.formData.id = device.id;
//})
these = this;
ble = bleTool.getBleTool();
ble.addReceiveCallback(these.bleValueNotify);
let eventChannel = this.getOpenerEventChannel();
let startLink=()=>{
ble.addDeviceFound((res) => {
console.log("发现新设备,",res);
let f = res.devices.find((v) => {
return v.name == device.deviceName;
});
if (f) {
console.log("找到了目标设备,正在连接:"+f.deviceId)
these.device.deviceId = f.deviceId;
these.formData.id = f.deviceId;
ble.LinkBlue(f.deviceId);
}
});
eventChannel.on('detailData', function(data) {
ble.StartSearch();
}
if(ble.data.LinkedList && ble.data.LinkedList.length>0){
let device = data.data;
console.log("收到父页面的参数:" + JSON.stringify(device));
let f = ble.data.LinkedList.find((v) => {
return v.name==device.deviceName;
if (v.macAddress == device.deviceMac) {
console.log("找到设备了", v);
these.formData.deviceId = v.deviceId;
return true;
}
return false;
});
if (!f) {
startLink();
}else{
these.device.deviceId = f.deviceId;
these.formData.id = f.deviceId;
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
return;
}
}else{
startLink();
let form = f.formData;
if (form) {
let keys = Object.keys(form);
for (var i = keys.length; i >= 0; i--) {
let key = keys[i];
these.formData[key] = form[key];
}
}
these.formData.blename = f.name ? f.name : "Unname";
these.formData.deviceName = device.deviceName;
these.formData.img = device.devicePic;
these.formData.id = device.id;
these.formData.deviceId = f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
these.setBleFormData();
});
},
onHide: function() {
@ -312,46 +287,7 @@
},
onBackPress(e) {
var these = this;
console.log("these.device=" + JSON.stringify(these.device));
if (these.device.deviceId) {
if (e.from === 'backbutton') {
let res = {
devices: ble.data.LinkedList
};
if (res.devices.length == 0) {
console.log("没有已连接的蓝牙设备")
uni.navigateBack();
return false;
}
let f = res.devices.find(function(v) {
return v.deviceId == these.device.deviceId;
});
if (!f) {
console.log("该设备没有连接")
uni.navigateBack();
return false;
}
uni.showModal({
title: '提示',
content: '是否断开与设备的蓝牙连接?',
success: function(res) {
if (res.confirm) {
ble.disconnectDevice(these.device.deviceId);
}
uni.navigateBack();
}
});
return true;
}
}
return false;
ble.removeReceiveCallback();
},
computed: {
@ -374,40 +310,123 @@
},
methods: {
getDevice: function() {
var these = this;
console.log("these.device=",these.device);
console.log("LinkedList=",ble.data.LinkedList.LinkedList);
console.log("LinkedList=", ble.data.LinkedList);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == these.device.deviceId;
return v.deviceId == these.formData.deviceId;
});
return f;
},
bleValueNotify: function(data) {
console.log("读取到设备发送的数据:" + JSON.stringify(data));
// data.characteristicId
// data.deviceId
// data.serviceId
// data.value
//
bleValueNotify: function(receive) {
console.log("处理接收到的数据:" + receive);
let bytes = receive.bytes;
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
try {
let staticLevelByte = bytes[2];
let getName = function(type) {
let name = "";
switch (type) {
case 0x02:
name = '弱光';
break;
case 0x04:
name = '工作光';
break;
case 0x01:
name = '强光';
break;
case 0x03:
name = '爆闪';
break;
case 0x00:
name = '关闭';
break;
}
return name;
}
let staticLevelText = getName(staticLevelByte);
// 解析照明档位
let lightingLevelByte = bytes[3];
let lightingLevelText = getName(lightingLevelByte);
// 解析剩余电量
let batteryLevelByte = bytes[4];
// 电量百分比范围检查
let batteryLevel = Math.max(0, Math.min(100, batteryLevelByte));
//充电状态
let warn = bytes[5];
if (warn == 0x00) {
warn = '未充电';
} else if (warn == 0x01) {
warn = '充电中';
}
// 解析剩余照明时间(第三和第四字节,小端序)
let lightingTime = "";
let HH = Math.max(0, Math.min(100, bytes[6]));
let mm = Math.max(0, Math.min(100, bytes[7]));
lightingTime = HH + "小时" + mm + "分钟";
this.formData.mode = staticLevelText;
this.formData.fuMode = lightingLevelText;
this.formData.battary = batteryLevel;
this.formData.statu = warn;
this.formData.xuhang = lightingTime;
this.setBleFormData();
} catch (error) {
console.log('数据解析错误:', error);
}
}
},
proParam: function() {
uni.showToast({
title: '敬请期待'
})
uni.navigateTo({
url: '/pages/common/productDes/index?id=' + this.formData.id,
success(ev) {
}
});
},
handRemark: function() {
this.alert('提示', "敬请期待");
uni.navigateTo({
url: '/pages/common/operatingInstruct/index?id=' + this.formData.id,
success(ev) {
}
});
},
handVideo: function() {
this.alert('提示', "敬请期待");
uni.navigateTo({
url: '/pages/common/operationVideo/index?id=' + this.formData.id,
success(ev) {
}
});
},
checkImgUpload: function() {
console.log("123213213213");
var these = this;
let f = these.getDevice();
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
return;
}
// 处理像素数据并发送
var processAndSendImageData = function(pixels) {
@ -428,18 +447,18 @@
// 总数据包数
const totalPackets = 52;
let currentPacket = 1;
f = these.getDevice();
if (f) {
// 发送单个数据包
const sendNextPacket = () => {
if (currentPacket > totalPackets) {
uni.hideLoading();
hideLoading(these);
these.Status.BottomMenu.show = false;
these.Status.Progress.show = false;
these.Status.Pop.showPop = true;
these.Status.Pop.message = "上传成功";
these.Status.Pop.iconUrl =
"/static/images/6155/DeviceDetail/uploadSuccess.png";
these.showPop({
message: "上传成功",
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
});
resolve();
return;
}
@ -495,45 +514,38 @@
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
}
console.log(
`发送数据包${currentPacket}/${totalPackets},${dataView.getUint8(0)} ${dataView.getUint8(1)} ${dataView.getUint8(2)}`
)
//发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
30)
.then(() => {
console.log("发送一个包完成了");
these.Status.Progress.curr = currentPacket;
updateLoading(these, {
text: "正在发送" + currentPacket + "/" +
totalPackets
})
currentPacket++;
setTimeout(sendNextPacket, 100);
}).catch(err => {
console.log("发送数据包失败了" + JSON.stringify(err));
// this.isSending = false;
console.log("发送数据包失败了", err);
these.Status.BottomMenu.show = false;
these.Status.Progress.show = false;
these.alert("发送数据包失败了");
uni.hideLoading();
these.showPop({
message: "发送数据包失败了" + err.msg,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
hideLoading(these);
reject(err);
});
}
// 开始发送数据
sendNextPacket();
}
});
}
@ -547,17 +559,15 @@
url: "/pages/6155/ImgCrop",
events: {
ImgCutOver: function(data) {
console.log("我收到裁剪后的图片了,感谢老铁," + data)
uni.showLoading({
title: "正在发送..."
showLoading(these, {
text: "正在发送0/52"
});
these.Status.Progress.show = true;
these.Status.Progress.curr = 0;
these.Status.Progress.total = 52;
these.Status.BottomMenu.show = false;
setTimeout(function() {
processAndSendImageData(data).catch(() => {
processAndSendImageData(data).catch((ex) => {
console.log("出现异常", ex);
});
}, 0)
@ -585,7 +595,7 @@
},
ModeSetting: function(type) {
this.cEdit.mode = type;
this.formData.mode = type;
let items = [];
let title = '';
switch (type) {
@ -595,6 +605,10 @@
text: '强光',
icon: '/static/images/6155/DeviceDetail/qiang.png'
},
{
text: '工作光',
icon: '/static/images/6155/DeviceDetail/fan.png'
},
{
text: '弱光',
icon: '/static/images/6155/DeviceDetail/ruo.png'
@ -602,6 +616,10 @@
{
text: '爆闪',
icon: '/static/images/6155/DeviceDetail/shan.png'
},
{
text: '关闭',
icon: '/static/images/6155/DeviceDetail/close.png'
}
];
break;
@ -635,76 +653,90 @@
//发送指令给设备
switch (this.Status.BottomMenu.type) {
case "main":
this.setMode(this.Status.BottomMenu.activeIndex);
this.setMode(this.Status.BottomMenu.activeIndex, this.Status.BottomMenu.type);
break;
case "fu":
this.setMode(this.Status.BottomMenu.activeIndex);
this.setMode(this.Status.BottomMenu.activeIndex, this.Status.BottomMenu.type);
break;
}
this.closeMenu();
},
setMode(mode) {
setMode(mode, type) {
let dataValue = 0;
this.setBleFormData();
if (type == 'main') {
type = 0x04;
} else if (type == 'fu') {
type = 0x05;
}
this.currentMode = mode;
let dataValue = 0;
switch (mode) {
case 0:
dataValue = 0x01;
console.log('开始切换到弱光模式');
break;
case 1:
dataValue = 0x02;
console.log('开始切换到工作光模式');
break;
case 2:
dataValue = 0x03;
console.log('开始切换到强光模式');
break;
case 2:
dataValue = 0x04;
console.log('开始切换到爆闪模式');
break;
case 2:
dataValue = 0x02;
break;
case 3:
dataValue = 0x03;
break;
case 4:
dataValue = 0x00; // 爆关闭主灯光
console.log('关闭主灯光');
dataValue = 0x00;
break;
}
// 构建数据包
const buffer = new ArrayBuffer(8);
const dataView = new DataView(buffer);
var buffer = new ArrayBuffer(6);
var dataView = new DataView(buffer);
dataView.setUint8(0, 0x4A); // 帧头
dataView.setUint8(1, 0x51);
dataView.setUint8(2, 0x4F);
dataView.setUint8(3, 0x43);
if (this.Status.BottomMenu.type == 'main') {
//主灯模式
dataView.setUint8(4, 0x04); // 帧类型
} else {
//副灯模式
dataView.setUint8(4, 0x05); // 帧类型
}
dataView.setUint8(5, dataValue); // 数据
dataView.setUint16(6, '9C41');
dataView.setUint8(0, 0xFA); // 帧头
dataView.setUint8(1, dataValue); // 帧类型
dataView.setUint8(2, 0x00); // 数据
dataView.setUint8(3, 0x01); // 数据
dataView.setUint8(4, 0x00); // 数据
dataView.setUint8(5, 0xFF); // 数据
let f = this.getDevice();
// 发送数据
if(f){
if (!f) {
these.showPop({
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
return;
}
showLoading(these, {
text: "请稍候..."
});
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
}).catch((ex) => {
these.showPop({
message: "发送失败," + ex.msg,
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}).finally(() => {
hideLoading(these);
});
}
@ -721,32 +753,71 @@
}
this.Status.BottomMenu.activeIndex = index;
},
setBleFormData() {
ble.data.LinkedList.find((v) => {
if (v.deviceId == these.formData.deviceId) {
v.formData = these.formData;
return true;
}
return false;
});
uni.setStorage({
key: ble.StorageKey,
data: ble.data.LinkedList
})
},
HidePop: function() {
if (this.Status.Pop.clickEvt == 'SendUsr') {
}
this.Status.Pop.showPop = false;
},
async sendUsr(){
showPop: function(option) {
// this.alert(JSON.stringify(this.user));
//生成位图并分包发送 //暂时弹出成功提示
var these = this;
if (!option) {
option = {
a: 1
};
}
let keys = Object.keys(option);
for (var i = 0; i < keys.length; i++) {
let key = keys[i];
these.Status.Pop[key] = option[key];
}
if (!option.borderColor) {
option.borderColor = '#BBE600';
option.buttonBgColor = '#BBE600';
}
these.Status.Pop.showPop = true;
},
sendUsr() {
let f = this.getDevice();
if (!f) {
these.showPop({
text: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
return;
}
showLoading(these, {
text: "请稍候..."
});
this.setBleFormData();
let task = async () => {
var sendTxtPackge = (rgbdata, type, str) => {
var promise = new Promise((resolve, reject) => {
try {
let packetSize = 120; //每包均分的数量
let packetSize = rgbdata.length; //每包均分的数量
let mode = rgbdata.length % packetSize; //最后一包的数量
let cnt = parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 : 0); //总包数量
let cnt = parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 :
0); //总包数量
let curr = 1; //当前包序号
let sendNext = () => {
@ -755,48 +826,50 @@
resolve();
return;
}
console.log("正在发送" + curr + "/" + cnt)
let bufferSize = 0;
if (curr == 1) {
bufferSize = packetSize * 2 + 5;
} else if (curr == cnt) {
bufferSize = mode > 0 ? (mode * 2) : (packetSize * 2);
} else {
bufferSize = packetSize * 2;
}
let bufferSize = 261;
console.log("bufferSize=", bufferSize)
let buffer = new ArrayBuffer(bufferSize);
let dataView = new DataView(buffer);
let startIndex = (curr - 1) * packetSize;
let endIndex = Math.min(startIndex + packetSize, rgbdata.length);
let endIndex = Math.min(startIndex + packetSize, rgbdata
.length);
if (startIndex > endIndex) {
return;
}
let packetData = rgbdata.slice(startIndex, endIndex); //取一片数据发送
let packetData = rgbdata.slice(startIndex,
endIndex); //取一片数据发送
let start = 0;
if (curr == 1) {
dataView.setUint8(0, 0x70);
dataView.setUint8(1, 0x65);
dataView.setUint8(2, type);
dataView.setUint16(3, str.length, false);
start = 5;
dataView.setUint8(0, 0xFA);
dataView.setUint8(1, type);
dataView.setUint8(2, 0x01);
dataView.setUint8(3, 0x00);
// dataView.setUint16(2, str.length, false);
start = 4;
}
for (let i = 0; i < packetData.length; i++) {
dataView.setUint16(start + i * 2, packetData[i], false); // 大端字节序
dataView.setUint8(start + i, packetData[i]);
}
dataView.setUint8(bufferSize - 1, 0xFF);
let inteval = parseInt(this.inteval ? this.inteval : 0);
//发送数据包
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
console.log("发送成功,准备发送下一包" + curr)
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
.wirteCharactId, 30).then(() => {
curr++;
setTimeout(sendNext, inteval);
}).catch(err => {
console.log("出现错误", err)
if (err.code == '10007') {
setTimeout(sendNext, inteval);
} else {
@ -808,7 +881,8 @@
sendNext();
} catch (ex) {
console.log("出现异常", ex)
console.log("ex=", ex);
reject(ex);
}
});
@ -816,48 +890,63 @@
return promise;
}
var result = await this.$refs.textToHex.drawAndGetPixels();
result = result.map(level1 => {
return level1.flat(Infinity);
});
let h3dic = [0x06, 0x07, 0x08];
let pros = [];
let flag = true;
for (var i = 0; i < result.length; i++) {
let str = this.textLines[i];
let str = this.formData.textLines[i];
if (str.length > 0) {
let width = str.length * 16;
var rgb = ble.convertToRGB565(result[i].pixelData, width, 16);
var rgb = result[i];
try {
console.log("1111");
await sendTxtPackge(rgb, h3dic[i], str);
console.log("222222");
} catch (ex) {
flag = false;
console.log("33333");
break;
}
}
}
hideLoading(these);
if (flag) {
uni.showModal({
title:"提示",
content:"发送成功"
})
console.log("发送成功");
this.showPop( {
message: "发送成功"
});
} else {
uni.showModal({
title:"错误",
content:"出现了异常发送失败"
})
this.showPop({
message: "出现异常发送失败",
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
borderColor: "#e034344d",
buttonBgColor: "#E03434",
});
}
}
setTimeout(task, 0);
},
ack: function() {
var these = this;
let eventChannel = this.getOpenerEventChannel();
eventChannel.emit('ack', {
data: '我已收到了您的消息,谢谢。'
@ -869,6 +958,7 @@
//给蓝牙设备发送信号更新亮度
setTimeout(() => {
this.sendBrightness();
this.setBleFormData();
}, 10);
},
sendBrightness: function() {
@ -1217,10 +1307,10 @@
}
.usrinfo .btnSend {
line-height: 40rpx;
line-height: 65rpx;
border-radius: 8px;
width: 82rpx;
height: 40rpx;
width: 120rpx;
height: 65rpx;
color: rgba(35, 35, 35, 0.87);
font-family: "PingFang SC";
font-size: 20rpx;
@ -1338,36 +1428,6 @@
}
/* .custom-slider .uni-slider-handle-wrapper {
height: 60rpx !important;
border-radius: 3px;
}
.custom-slider .uni-slider-active {
background-color: #FF6B6B !important;
}
.custom-slider .uni-slider-handle {
width: 60rpx !important;
height: 60rpx !important;
border-radius: 16rpx !important;
background-color: #FFFFFFde !important;
margin-top: -15px !important;
border: none !important;
}
.custom-slider .uni-slider-thumb {
width: 60rpx !important;
height: 60rpx !important;
border-radius: 16rpx !important;
background-color: #00000000 !important;
border: none !important;
} */
.addIco {
width: 100%;
height: 360rpx;

View File

@ -309,6 +309,7 @@
these.formData.deviceName = device.deviceName;
these.formData.img = device.devicePic;
these.formData.id = device.id;
these.formData.deviceId=f.deviceId;
ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId);
these.setBleFormData();
@ -321,9 +322,7 @@
},
onBackPress(e) {
ble.removeReceiveCallback();
},
computed: {
RSSIRemark: function() {
@ -488,7 +487,8 @@
},
getDevice: function() {
console.log("LinkedList=",ble.data.LinkedList);
console.log("formData=",these.formData);
let f = ble.data.LinkedList.find((v) => {
return v.deviceId == these.formData.deviceId;
});
@ -1112,6 +1112,10 @@
let key = keys[i];
these.Status.Pop[key] = option[key];
}
if (!option.borderColor) {
option.borderColor = '#BBE600';
option.buttonBgColor = '#BBE600';
}
these.Status.Pop.showPop = true;
},
sendUsr: function() {
@ -1126,9 +1130,7 @@
];
showLoading(this, {
text: "请稍候..."
});
let f = this.getDevice();
if (!f) {
these.showPop({
@ -1139,7 +1141,9 @@
});
return;
}
showLoading(this, {
text: "请稍候..."
});
var sendText = function() {

View File

@ -19,13 +19,18 @@
连接
</view>
<global-loading ref="loading" />
</view>
</template>
<script>
import request from '@/utils/request.js';
import bleTool from '@/utils/BleHelper.js'
import {
showLoading,
hideLoading,
updateLoading
} from '@/utils/loading.js'
var these = null;
var eventChannel = null;
var ble=null;
@ -110,9 +115,9 @@
}
these.Statu.bound = null;
these.Statu.boundRemark = "";
uni.showLoading({
mask: true,
title: "连接中..."
showLoading(these,{
text: "连接中..."
})
let promise = request({
url: '/app/device/bind',
@ -142,7 +147,7 @@
these.Statu.bound = false;
these.Statu.boundRemark = '出现了未知的异常,操作失败';
}).finally(() => {
uni.hideLoading();
hideLoading(this);
});
}
}

View File

@ -81,12 +81,20 @@
</view>
</view>
</BottomSlideMenuPlus>
<global-loading ref="loading" />
</view>
</template>
<script>
import bleTool from '@/utils/BleHelper.js';
import request from '@/utils/request.js';
import {
showLoading,
hideLoading,
updateLoading
} from '@/utils/loading.js'
var ble = null;
var these = null;
export default {
@ -131,7 +139,8 @@
},
onBackPress: (e) => {
ble.StopSearch();
ble.removeDeviceFound();
ble.removeReceiveCallback();
},
onLoad() {
these = this;
@ -142,6 +151,9 @@
for (var i = 0; i < arr.length; i++) {
arr[i].linkStatu = false;
if(!arr[i].name){
continue;
}
let f = these.EquipMents.find(function(v) {
return v.deviceId == arr[i].deviceId;
});
@ -229,9 +241,8 @@
},
Link: function(item, index) {
uni.showLoading({
title: "正在连接",
mask: true
showLoading(this,{
text: "正在连接"
});
setTimeout(() => {
let serviceid=null;
@ -262,7 +273,7 @@
content:"连接失败:"+ex.msg
});
}).finally(()=>{
uni.hideLoading();
hideLoading(this);
});
}, 0);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -446,11 +446,13 @@ class BleHelper {
str += String.fromCharCode(uint8Array[i]);
}
let header = "mac address:";
if (str.indexOf(header) == 0) {
if (str.indexOf(header) == 0) { //650以文本传输mac
this.data.LinkedList.find((v) => {
if (v.deviceId == receive.deviceId) {
v.macAddress = str.replace(header,"");
if (v.deviceId == receive
.deviceId) {
v.macAddress = str.replace(
header, "");
console.log("收到mac地址:", str)
}
});
@ -458,7 +460,20 @@ class BleHelper {
.LinkedList);
}
if (bytes[0] == 0xFC) { //6155以0xFC开头代表mac地址
if (arr.length >= 7) {
let mac = arr.slice(1, 7).join(":");
this.data.LinkedList.find((v) => {
if (v.deviceId == receive
.deviceId) {
v.macAddress = mac;
console.log("收到mac地址:", str)
}
});
uni.setStorageSync(this.StorageKey, this
.data.LinkedList);
}
}
} catch (ex) {
////console.log("将数据转文本失败", ex);
}
@ -546,7 +561,7 @@ class BleHelper {
return new Promise((resolve, reject) => {
uni.startBluetoothDevicesDiscovery({
services: [],
allowDuplicatesKey: false,
allowDuplicatesKey: true,
success: (res) => {
//console.log('开始搜索蓝牙设备成功');
resolve(res);
@ -629,8 +644,7 @@ class BleHelper {
}
console.log("c=", c);
let startSubScribe = (id, serviceId, characteristicId) => {
console.log("id, serviceId, characteristicId=" + id + "," + serviceId +
"," + characteristicId);
return new Promise((succ, err) => {
uni.notifyBLECharacteristicValueChange({
deviceId: id,
@ -652,10 +666,7 @@ class BleHelper {
succ();
},
fail: (ex) => {
console.log("deviceId=", id);
console.log("serviceId=", serviceId);
console.log("characteristicId=",
characteristicId);
err(this.getError(ex));
}
});
@ -676,10 +687,10 @@ class BleHelper {
results.forEach((result, index) => {
if (result.status === "fulfilled") {
console.log(`操作${index + 1}成功:`, result.value);
//console.log(`操作${index + 1}成功:`, result.value);
} else {
console.log(`操作${index + 1}失败:`, result.reason
.message);
// console.log(`操作${index + 1}失败:`, result.reason
// .message);
}
});
@ -752,7 +763,7 @@ class BleHelper {
return this.subScribe(id, true);
})
.then((res) => {
console.log('所有操作成功完成', res);
console.log('设备连接成功,初始化完成', res);
console.log("LinkedList=", this.data
.LinkedList);
resolve();
@ -1160,10 +1171,14 @@ class BleHelper {
return v.deviceId == deviceid;
});
if (!f) {
reject({code:'-9',msg:'蓝牙未连接过此设备,请重新使用蓝牙添加该设备'});
reject({
code: '-9',
msg: '蓝牙未连接过此设备,请重新使用蓝牙添加该设备'
});
retrn;
}
this.LinkBlue(f.deviceId,f.writeServiceId,f.wirteCharactId,f.notifyCharactId).then((res) => {
this.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then((
res) => {
console.log("连接成功");
return sendBuffer();
}).then(() => {

View File

@ -9,7 +9,14 @@ export const showLoading = (ev,options) => {
if(!options){
options={a:1};
}
ev.$refs.loading.show(options)
if(!options.text && options.title){
options.text=options.title;
}
if(!options.text){
options.text="请稍候...";
}
ev.$refs.loading.show(options);
}