Merge branch 'main' of http://47.107.152.87:3000/dyf/APP
This commit is contained in:
11
App.vue
11
App.vue
@ -47,6 +47,8 @@
|
||||
|
||||
<style lang="scss">
|
||||
@import 'vk-uview-ui/index.scss';
|
||||
/* #ifdef APP-ANDROID */
|
||||
//苹果应用以下样式后Slider不可拖动
|
||||
uni-slider .uni-slider-handle-wrapper {
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
@ -61,7 +63,8 @@
|
||||
uni-slider .uni-slider-handle-wrapper {
|
||||
height: 88rpx;
|
||||
position: relative;
|
||||
}
|
||||
// }
|
||||
/* #endif */
|
||||
.custom-file-picker .file-picker__box-content {
|
||||
background: rgba(26, 26, 26, 1);
|
||||
border: none !important;
|
||||
@ -91,4 +94,10 @@
|
||||
font-family: "PingFang SC";
|
||||
src: url("~@/static/fonts/PingFangSC.ttf") format("opentype");
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "PingFangBold";
|
||||
src: url("~@/static/fonts/PingFangBold.ttf") format("opentype");
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@ -17,6 +17,7 @@ function getdata(data,url,method){
|
||||
console.log("res=",res);
|
||||
resolve(res);
|
||||
}).catch(ex=>{
|
||||
console.log("ex=",ex);
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,194 +0,0 @@
|
||||
<template>
|
||||
<view>
|
||||
<canvas type="2d" canvas-id="reusableCanvas" :width="currentCanvasWidth" :height="currentCanvasHeight"
|
||||
class="offscreen-canvas"></canvas>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "TextToHexV1",
|
||||
props: {
|
||||
txts: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
validator: (value) => value.every(item => typeof item === 'string')
|
||||
},
|
||||
fontSize: {
|
||||
type: Number,
|
||||
default: 16,
|
||||
validator: (value) => value > 0 && value <= 100
|
||||
},
|
||||
bgColor: {
|
||||
type: String,
|
||||
default: "#ffffff"
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: "#000000"
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 当前Canvas的宽高(动态调整)
|
||||
currentCanvasWidth: 0,
|
||||
currentCanvasHeight: 0,
|
||||
// Canvas上下文(复用)
|
||||
ctx: null
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
validTxts() {
|
||||
return this.txts.filter(line => line.trim() !== '');
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// 初始化Canvas上下文(只创建一次)
|
||||
this.ctx = uni.createCanvasContext('reusableCanvas', this);
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 估算单行文本所需的Canvas宽度
|
||||
*/
|
||||
calcLineWidth(textLine) {
|
||||
return textLine.length * this.fontSize;
|
||||
},
|
||||
|
||||
/**
|
||||
* 清除Canvas内容
|
||||
*/
|
||||
clearCanvas() {
|
||||
this.ctx.setFillStyle(this.bgColor);
|
||||
this.ctx.fillRect(0, 0, this.currentCanvasWidth, this.currentCanvasHeight);
|
||||
},
|
||||
|
||||
/**
|
||||
* 复用单个Canvas处理所有文本行
|
||||
*/
|
||||
async drawAndGetPixels() {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将字节转换为两位十六进制字符串
|
||||
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;
|
||||
|
||||
// 1. 动态调整Canvas尺寸
|
||||
this.currentCanvasWidth = this.calcLineWidth(textLine);
|
||||
this.currentCanvasHeight = this.fontSize;
|
||||
|
||||
// 2. 清空Canvas(绘制背景)
|
||||
this.clearCanvas();
|
||||
|
||||
// 3. 设置文字样式
|
||||
ctx.setFillStyle(this.color);
|
||||
ctx.setTextBaseline('middle');
|
||||
ctx.setFontSize(this.fontSize);
|
||||
ctx.font = `${this.fontSize}px "PingFang SC", PingFang SC, Arial, sans-serif`;
|
||||
|
||||
// 4. 绘制当前行文本
|
||||
let currentX = 0;
|
||||
let currentY = this.fontSize / 2;
|
||||
for (let j = 0; j < textLine.length; j++) {
|
||||
let char = textLine[j];
|
||||
ctx.fillText(char, currentX, currentY);
|
||||
// 按实际字符宽度计算间距
|
||||
let charWidth = ctx.measureText(char).width;
|
||||
currentX += charWidth;
|
||||
}
|
||||
|
||||
// 5. 异步绘制并获取像素数据(串行处理避免冲突)
|
||||
await new Promise((resolve, reject) => {
|
||||
ctx.draw(false, () => {
|
||||
uni.canvasGetImageData({
|
||||
canvasId: 'reusableCanvas',
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: this.currentCanvasWidth,
|
||||
height: this.currentCanvasHeight,
|
||||
success: res => {
|
||||
|
||||
result={
|
||||
line: textLine,
|
||||
pixelData: res.data,
|
||||
width: this.currentCanvasWidth,
|
||||
height: this.currentCanvasHeight
|
||||
};
|
||||
resolve();
|
||||
},
|
||||
fail: err => {
|
||||
// console.error(`处理第${i+1}行失败:`, 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>
|
||||
|
||||
<style>
|
||||
.offscreen-canvas {
|
||||
position: fixed;
|
||||
left: -9999px;
|
||||
top: -9999px;
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
||||
@ -51,7 +51,7 @@
|
||||
* 估算单行文本所需的Canvas宽度
|
||||
*/
|
||||
calcLineWidth(textLine) {
|
||||
return textLine.length * this.fontSize;
|
||||
return textLine.length * 16;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -112,7 +112,7 @@
|
||||
|
||||
// 1. 动态调整Canvas尺寸
|
||||
this.currentCanvasWidth = this.calcLineWidth(textLine);
|
||||
this.currentCanvasHeight = this.fontSize;
|
||||
this.currentCanvasHeight = 16;
|
||||
|
||||
// 2. 清空Canvas(绘制背景)
|
||||
this.clearCanvas();
|
||||
@ -120,8 +120,9 @@
|
||||
// 3. 设置文字样式
|
||||
ctx.setFillStyle(this.color);
|
||||
ctx.setTextBaseline('middle');
|
||||
// ctx.setTextAlign('center')
|
||||
ctx.setFontSize(this.fontSize);
|
||||
ctx.font = `${this.fontSize}px "PingFang SC", PingFang SC, Arial, sans-serif`;
|
||||
ctx.font = `${this.fontSize}px "PingFangBold", "PingFang SC", Arial, sans-serif`;
|
||||
|
||||
// 4. 绘制当前行文本
|
||||
let currentX = 0;
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
const config = {
|
||||
// 开发环境
|
||||
development: {
|
||||
BASE_URL: 'http://192.168.2.34:8000',
|
||||
BASE_URL: 'http://192.168.110.56:8000',
|
||||
API_PREFIX: '',
|
||||
// MQTT 配置
|
||||
MQTT_HOST: '47.120.79.150',
|
||||
MQTT_PORT: 9083,
|
||||
MQTT_PORT: 8083,
|
||||
MQTT_USERNAME: 'admin',
|
||||
MQTT_PASSWORD: '#YtvpSfCNG'
|
||||
},
|
||||
@ -16,7 +16,7 @@ const config = {
|
||||
API_PREFIX: '',
|
||||
// MQTT 配置
|
||||
MQTT_HOST: '47.120.79.150',
|
||||
MQTT_PORT: 9083,
|
||||
MQTT_PORT: 8083,
|
||||
MQTT_USERNAME: 'admin',
|
||||
MQTT_PASSWORD: '#YtvpSfCNG'
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name" : "JingQuan",
|
||||
"name" : "星汉物联",
|
||||
"appid" : "__UNI__A21EF43",
|
||||
"description" : "设备管控",
|
||||
"versionName" : "1.0.9",
|
||||
"versionName" : "1.0.25",
|
||||
"versionCode" : "100",
|
||||
"transformPx" : false,
|
||||
/* 5+App特有相关 */
|
||||
@ -21,7 +21,6 @@
|
||||
"Bluetooth" : {},
|
||||
"Barcode" : {},
|
||||
"Camera" : {},
|
||||
"Maps" : {},
|
||||
"OAuth" : {},
|
||||
"Geolocation" : {}
|
||||
},
|
||||
|
||||
28
pages.json
28
pages.json
@ -142,13 +142,13 @@
|
||||
{
|
||||
"path": "pages/common/addBLE/addEquip",
|
||||
"style": {
|
||||
"navigationBarTitleText": "添加设备"
|
||||
"navigationBarTitleText": "扫描设备"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/common/addBLE/LinkBle",
|
||||
"style": {
|
||||
"navigationBarTitleText": "扫描到的设备"
|
||||
"navigationBarTitleText": "绑定设备"
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -226,6 +226,12 @@
|
||||
"navigationBarTitleText": "呼叫"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "设备类型"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/VideoSend",
|
||||
"style": {
|
||||
@ -291,11 +297,6 @@
|
||||
"style": {
|
||||
"navigationBarTitleText": "HBY670"
|
||||
}
|
||||
}, {
|
||||
"path": "pages/BlueTooth/ModeSetting/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "设备类型"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/670/HBY670",
|
||||
@ -315,6 +316,19 @@
|
||||
"style": {
|
||||
"navigationBarTitleText": "历史记录"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/BlueTooth/ModeSetting/4877",
|
||||
"style": {
|
||||
"navigationBarTitleText": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path" : "pages/7305/BJQ7305",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText" : "BJQ7305"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -35,11 +35,11 @@
|
||||
handleCrop(e) {
|
||||
|
||||
var these = this;
|
||||
|
||||
const eventChannel = these.getOpenerEventChannel();
|
||||
this.Statu = true;
|
||||
console.log("裁剪完成");
|
||||
console.log(e.tempFilePath);
|
||||
//
|
||||
eventChannel.emit('ImgCutOver_Path',e.tempFilePath);
|
||||
const ctx = uni.createCanvasContext('splashCanvas', this);
|
||||
ctx.drawImage(
|
||||
e.tempFilePath,
|
||||
@ -56,7 +56,7 @@
|
||||
height: 80,
|
||||
success: (res) => {
|
||||
// 处理像素数据并发送
|
||||
const eventChannel = these.getOpenerEventChannel();
|
||||
|
||||
console.log("res.data.length="+res.data.length);
|
||||
eventChannel.emit('ImgCutOverPath', {
|
||||
picPath: e.tempFilePath
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
<text class="value">{{formData.deviceName}}</text>
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="lbl">设备状态</text>
|
||||
<text class="lbl">充电状态</text>
|
||||
<text class="value">{{formData.statu}}</text>
|
||||
</view>
|
||||
</view>
|
||||
@ -55,7 +55,7 @@
|
||||
</view>
|
||||
<view class="rightTxt">
|
||||
<text class="bigTxt">主灯模式</text>
|
||||
<text class="smallTxt">强光模式</text>
|
||||
<text class="smallTxt">{{getMode}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mode marginLeft fleft" v-on:click.stop="ModeSetting('fu')">
|
||||
@ -83,8 +83,8 @@
|
||||
<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="formData.textLines" :bgColor="'#000000'"
|
||||
:color="'#FFFFFF'" :fontSize="16" />
|
||||
<TextToHexV1 class="TextToHex" ref="textToHex" :txts="formData.textLines" :bgColor="'#FFFFFF'"
|
||||
:color="'#000000'" :fontSize="14" />
|
||||
</view>
|
||||
|
||||
<view class="item">
|
||||
@ -143,17 +143,26 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import TextToHexVue from '@/components/TextToHex/TextToHex.vue';
|
||||
import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue';
|
||||
import bleTool from '@/utils/BleHelper.js';
|
||||
|
||||
import usrApi from '@/api/670/HBY670.js'
|
||||
import {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js'
|
||||
import BleReceive from '@/utils/BleReceive';
|
||||
|
||||
|
||||
var ble = null;
|
||||
var these = null;
|
||||
var BrighInteval = null;
|
||||
var recei = null;
|
||||
|
||||
export default {
|
||||
components: {
|
||||
TextToHexV1
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
Status: {
|
||||
@ -221,10 +230,29 @@
|
||||
liangDu: '100',
|
||||
id: '',
|
||||
deviceId: '',
|
||||
textLines: ['我爱你', '中国', '五星红旗'],
|
||||
textLines: ['', '', ''],
|
||||
mode: ''
|
||||
},
|
||||
|
||||
inteval: 200,
|
||||
device: {
|
||||
id: "",
|
||||
deviceName: "",
|
||||
deviceImei: "",
|
||||
deviceMac: "",
|
||||
communicationMode: 0,
|
||||
devicePic: "",
|
||||
typeName: "",
|
||||
bluetoothName: null,
|
||||
deviceStatus: null,
|
||||
bindingTime: "",
|
||||
onlineStatus: 0,
|
||||
battery: "0",
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
alarmStatus: null,
|
||||
detailPageUrl: "/pages/6155/deviceDetail",
|
||||
showConfirm: false
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
@ -233,7 +261,54 @@
|
||||
},
|
||||
onLoad: function() {
|
||||
these = this;
|
||||
recei = BleReceive.getBleReceive();
|
||||
ble = bleTool.getBleTool();
|
||||
// let bleName = 'FB_Site_UART'; //JQZM-EF4651 FB_Site_UART
|
||||
|
||||
|
||||
// let f = ble.data.LinkedList.find((v) => {
|
||||
// if (v.name == bleName) {
|
||||
// console.log("找到设备了", v);
|
||||
// these.formData.deviceId = v.deviceId;
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// });
|
||||
|
||||
// let link = () => {
|
||||
// if (bleName == 'FB_Site_UART') {
|
||||
// ble.LinkBlue(f.deviceId, '0000AE30-0000-1000-8000-00805F9B34FB',
|
||||
// '0000AE03-0000-1000-8000-00805F9B34FB', '0000AE02-0000-1000-8000-00805F9B34FB');
|
||||
// } else {
|
||||
// ble.LinkBlue(f.deviceId, '0000FFE0-0000-1000-8000-00805F9B34FB',
|
||||
// '0000FFE1-0000-1000-8000-00805F9B34FB', '0000FFE2-0000-1000-8000-00805F9B34FB');
|
||||
// }
|
||||
|
||||
// }
|
||||
// if (!f) {
|
||||
|
||||
|
||||
// ble.addDeviceFound((res) => {
|
||||
// // console.log("发现新设备", res);
|
||||
// f = res.devices.find((v) => {
|
||||
// return v.name == bleName;
|
||||
// });
|
||||
// if (f) {
|
||||
|
||||
// console.log("找到目标设备了", f);
|
||||
// these.formData.deviceId = f.deviceId;
|
||||
|
||||
// link();
|
||||
|
||||
// ble.StopSearch();
|
||||
// }
|
||||
// });
|
||||
|
||||
// ble.StartSearch();
|
||||
// } else {
|
||||
// link();
|
||||
// }
|
||||
console.log("6155");
|
||||
ble.addReceiveCallback(these.bleValueNotify);
|
||||
let eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
@ -241,7 +316,8 @@
|
||||
|
||||
|
||||
let device = data.data;
|
||||
console.log("收到父页面的参数:" + JSON.stringify(device));
|
||||
these.device = device;
|
||||
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
if (v.macAddress == device.deviceMac) {
|
||||
console.log("找到设备了", v);
|
||||
@ -253,12 +329,7 @@
|
||||
if (!f) {
|
||||
|
||||
|
||||
these.showPop({
|
||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
these.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
let form = f.formData;
|
||||
@ -306,21 +377,54 @@
|
||||
if (this.formData.RSSI < -85 && this.formData.RSSI >= -100) {
|
||||
remark = '微弱';
|
||||
}
|
||||
},
|
||||
getMode() {
|
||||
let txt = "关闭";
|
||||
if (this.Status.BottomMenu.type == 'fu') {
|
||||
return txt;
|
||||
}
|
||||
switch (this.formData.mode) {
|
||||
case 0:
|
||||
|
||||
|
||||
txt = "强光模式";
|
||||
|
||||
break;
|
||||
case 1:
|
||||
txt = "弱光模式";
|
||||
break;
|
||||
|
||||
case 2:
|
||||
txt = "爆闪模式";
|
||||
break;
|
||||
case 3:
|
||||
txt = "关闭";
|
||||
break;
|
||||
default:
|
||||
txt = "关闭";
|
||||
break;
|
||||
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getDevice: function() {
|
||||
console.log("LinkedList=", ble.data.LinkedList);
|
||||
console.log("formData=", these.formData);
|
||||
// console.log("LinkedList=", ble.data.LinkedList);
|
||||
// console.log("formData=", these.formData);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
return v.deviceId == these.formData.deviceId;
|
||||
return v.macAddress == these.device.deviceMac;
|
||||
});
|
||||
|
||||
return f;
|
||||
},
|
||||
bleValueNotify: function(receive) {
|
||||
console.log("处理接收到的数据:" + receive);
|
||||
bleValueNotify: function(receive, device, path) {
|
||||
|
||||
let str = recei.ReceiveData(receive, device, path);
|
||||
|
||||
console.log("处理接收到的数据:" + str);
|
||||
return;
|
||||
let data = recei.ReceiveData(receive, device, path);
|
||||
let bytes = receive.bytes;
|
||||
|
||||
if (bytes[0] == 0xFB && bytes[1] == 0x64 && bytes.length >= 8) {
|
||||
@ -383,6 +487,15 @@
|
||||
this.formData.statu = warn;
|
||||
this.formData.xuhang = lightingTime;
|
||||
|
||||
if (batteryLevel <= 20) {
|
||||
this.showPop({
|
||||
message: "设备电量低",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
}
|
||||
|
||||
this.setBleFormData();
|
||||
} catch (error) {
|
||||
console.log('数据解析错误:', error);
|
||||
@ -416,16 +529,40 @@
|
||||
}
|
||||
});
|
||||
},
|
||||
checkImgUpload: function() {
|
||||
let f = these.getDevice();
|
||||
|
||||
if (!f) {
|
||||
these.showPop({
|
||||
showBleUnConnect() {
|
||||
this.showPop({
|
||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
buttonText: '去连接',
|
||||
okCallback: function() {
|
||||
console.log("1111");
|
||||
uni.navigateTo({
|
||||
url: "/pages/common/addBLE/addEquip",
|
||||
events: {
|
||||
BindOver: function(data) {
|
||||
console.log(data)
|
||||
}
|
||||
},
|
||||
success: function(res) {
|
||||
// 通过eventChannel向被打开页面传送数据
|
||||
res.eventChannel.emit('detailData', {
|
||||
data: these.device
|
||||
})
|
||||
},
|
||||
fail(ex) {
|
||||
console.log("跳转失败", ex);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
checkImgUpload: function() {
|
||||
let f = these.getDevice();
|
||||
|
||||
if (!f) {
|
||||
these.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -433,10 +570,55 @@
|
||||
var processAndSendImageData = function(pixels) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 创建RGB565格式的像素数据
|
||||
const rgb565Data = ble.convertToRGB565(pixels);
|
||||
const arr = ble.convertToRGB565(pixels, 'bgr');
|
||||
|
||||
var list = [];
|
||||
let index = 0; // 用于追踪arr的当前位置
|
||||
let packetSize = 2048;
|
||||
let cSize = 248;
|
||||
// 外层循环:7个主要元素(i从1到7)
|
||||
for (let i = 1; i < 8; i++) {
|
||||
let secondLevel = [];
|
||||
let secondCnt = 0;
|
||||
// 中层循环:每个主要元素包含9个子数组(j从1到9)
|
||||
for (let j = 1; j < 10; j++) {
|
||||
// 确定当前子数组的长度:前8个是254,第9个是64
|
||||
|
||||
let thirdLevel = [];
|
||||
|
||||
// 从arr中提取相应数量的元素
|
||||
for (let k = 0; k < cSize && index < arr.length; k++) {
|
||||
|
||||
if (secondCnt == packetSize) {
|
||||
break;
|
||||
}
|
||||
thirdLevel.push(arr[index]);
|
||||
secondCnt++;
|
||||
index++;
|
||||
}
|
||||
|
||||
secondLevel.push(thirdLevel);
|
||||
}
|
||||
list.push(secondLevel);
|
||||
}
|
||||
|
||||
console.log("list=", list);
|
||||
|
||||
let length = 0;
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const item = list[i];
|
||||
let clength = 0;
|
||||
for (let j = 0; j < item.length; j++) {
|
||||
const element = item[j];
|
||||
console.log("第" + i + "包,第" + j + "小包,长度:" + element.length)
|
||||
length += element.length;
|
||||
clength += element.length;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
// 分包发送
|
||||
sendImagePackets(rgb565Data).then(resolve).catch(reject);
|
||||
sendImagePackets(list).then(resolve).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
@ -446,90 +628,116 @@
|
||||
var sendImagePackets = function(imageData) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 总数据包数
|
||||
const totalPackets = 52;
|
||||
const totalPackets = 7;
|
||||
let currentPacket = 1;
|
||||
let childPacket = 1;
|
||||
let totalChildPacket = 9;
|
||||
|
||||
|
||||
// 发送单个数据包
|
||||
const sendNextPacket = () => {
|
||||
if (currentPacket > totalPackets) {
|
||||
setTimeout(() => {
|
||||
hideLoading(these);
|
||||
these.Status.BottomMenu.show = false;
|
||||
|
||||
these.showPop({
|
||||
message: "上传成功",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
|
||||
borderColor: '#BBE600',
|
||||
buttonBgColor: '#BBE600'
|
||||
});
|
||||
|
||||
resolve();
|
||||
}, 20000)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算当前包的数据
|
||||
let packetSize = 250;
|
||||
if (currentPacket <= 51) {
|
||||
packetSize = 250; // 前51个包每个500字节
|
||||
} else {
|
||||
packetSize = 50; // 最后一个包100字节
|
||||
}
|
||||
var packetData = imageData[currentPacket - 1][childPacket - 1];
|
||||
// if (packetData.length == 0) {
|
||||
// hideLoading(these);
|
||||
// these.Status.BottomMenu.show = false;
|
||||
|
||||
// 创建数据包
|
||||
const startIndex = (currentPacket - 1) * packetSize;
|
||||
const endIndex = Math.min(startIndex + packetSize, imageData
|
||||
.length);
|
||||
if (startIndex > endIndex) {
|
||||
return;
|
||||
}
|
||||
const packetData = imageData.slice(startIndex,
|
||||
endIndex); // imageData.subarray(startIndex, endIndex);
|
||||
console.log("imageData.length=" + imageData.length +
|
||||
",startIndex=" +
|
||||
startIndex +
|
||||
",endIndex=" + endIndex + ",数据包长度" + (endIndex -
|
||||
startIndex) +
|
||||
',packetData.length=' + packetData.length);
|
||||
// 构建数据包
|
||||
const bufferSize = 5 + packetData.length * 2; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
// these.showPop({
|
||||
// message: "上传成功",
|
||||
// iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png"
|
||||
// });
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x02); // 帧类型:开机画面
|
||||
dataView.setUint8(2, '0x' + currentPacket.toString(16).padStart(2,
|
||||
'0')); // 包序号
|
||||
// if(packetData.length==250)
|
||||
// {
|
||||
// dataView.setUint8(3, 0x01);
|
||||
// dataView.setUint8(4, 0xFF);
|
||||
// resolve();
|
||||
// return;
|
||||
// }
|
||||
let start = 0;
|
||||
let bufferSize = packetData.length * 2;
|
||||
|
||||
if (packetData.length == 250) {
|
||||
dataView.setUint8(3, 0x01);
|
||||
dataView.setUint8(4, 0xF4);
|
||||
} else {
|
||||
dataView.setUint8(3, 0x00);
|
||||
dataView.setUint8(4, 0x64);
|
||||
if (currentPacket == 7) {
|
||||
if (childPacket > 2 && childPacket < 9) {
|
||||
bufferSize = 496;
|
||||
} else if (childPacket == 9) {
|
||||
bufferSize = 128;
|
||||
}
|
||||
}
|
||||
|
||||
if (childPacket == 1) {
|
||||
bufferSize = bufferSize + 8
|
||||
start = 8;
|
||||
}
|
||||
if (childPacket == 9) { //|| (currentPacket==7 && childPacket==3
|
||||
bufferSize = bufferSize + 1
|
||||
}
|
||||
|
||||
|
||||
//FA 09 10 04 FC 09 [00] [01] + 4096字节+FF 数据格式
|
||||
var buffer = new ArrayBuffer(bufferSize);
|
||||
var dataView = new DataView(buffer);
|
||||
if (childPacket == 1) {
|
||||
dataView.setUint8(0, 0xFA); // 帧头
|
||||
dataView.setUint8(1, 0x09); // 帧头
|
||||
dataView.setUint8(2, 0x10); // 帧头
|
||||
dataView.setUint8(3, 0x04); // 帧头
|
||||
dataView.setUint8(4, 0xFC); // 帧头
|
||||
dataView.setUint8(5, 0x09); // 帧头
|
||||
|
||||
dataView.setUint8(6, 0x00); // 图序号,图片固定0,视频的话要写序号
|
||||
dataView.setUint8(7, currentPacket); //子包序号
|
||||
}
|
||||
|
||||
// 填充数据(每个RGB565值占2字节)
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
|
||||
dataView.setUint16(start + i * 2, packetData[i], false); //本包数据,大端字节序
|
||||
}
|
||||
console.log("packetData.length=", packetData.length);
|
||||
console.log("bufferSize=", bufferSize)
|
||||
if (childPacket == 9) { // || (currentPacket==7 && childPacket==3
|
||||
dataView.setUint8(bufferSize - 1, 0xFF);
|
||||
}
|
||||
|
||||
//发送数据包
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
|
||||
30)
|
||||
.then(() => {
|
||||
console.log("发送一个包完成了");
|
||||
|
||||
let curr = childPacket + (currentPacket - 1) *
|
||||
totalChildPacket;
|
||||
console.log("第" + currentPacket + "大包,第" + childPacket +
|
||||
"小包发送完成,总计:" + curr);
|
||||
updateLoading(these, {
|
||||
text: "正在发送" + currentPacket + "/" +
|
||||
totalPackets
|
||||
text: "正在发送" + curr + "/63"
|
||||
|
||||
})
|
||||
if (childPacket == 9) {
|
||||
currentPacket++;
|
||||
childPacket = 1;
|
||||
} else {
|
||||
childPacket++;
|
||||
}
|
||||
|
||||
setTimeout(sendNextPacket, 100);
|
||||
}).catch(err => {
|
||||
if (err.code == 10007) {
|
||||
setTimeout(sendNextPacket, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("发送数据包失败了", err);
|
||||
|
||||
these.Status.BottomMenu.show = false;
|
||||
@ -567,7 +775,8 @@
|
||||
|
||||
these.Status.BottomMenu.show = false;
|
||||
setTimeout(function() {
|
||||
processAndSendImageData(data.piexls).catch((ex) => {
|
||||
processAndSendImageData(data.piexls).catch((
|
||||
ex) => {
|
||||
console.log("出现异常", ex);
|
||||
});
|
||||
}, 0)
|
||||
@ -606,10 +815,10 @@
|
||||
text: '强光',
|
||||
icon: '/static/images/6155/DeviceDetail/qiang.png'
|
||||
},
|
||||
{
|
||||
text: '工作光',
|
||||
icon: '/static/images/6155/DeviceDetail/fan.png'
|
||||
},
|
||||
// {
|
||||
// text: '工作光',
|
||||
// icon: '/static/images/6155/DeviceDetail/fan.png'
|
||||
// },
|
||||
{
|
||||
text: '弱光',
|
||||
icon: '/static/images/6155/DeviceDetail/ruo.png'
|
||||
@ -662,42 +871,40 @@
|
||||
}
|
||||
this.closeMenu();
|
||||
},
|
||||
|
||||
setMode(mode, type) {
|
||||
|
||||
let dataValue = 0;
|
||||
this.setBleFormData();
|
||||
|
||||
|
||||
if (type == 'main') {
|
||||
|
||||
type = 0x04;
|
||||
} else if (type == 'fu') {
|
||||
|
||||
type = 0x05;
|
||||
}
|
||||
|
||||
this.currentMode = mode;
|
||||
|
||||
|
||||
switch (mode) {
|
||||
case 0:
|
||||
|
||||
|
||||
if (type == 'main') {
|
||||
|
||||
dataValue = 0x01;
|
||||
} else if (type == 'fu') {
|
||||
|
||||
dataValue = 0x04;
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
dataValue = 0x04;
|
||||
break;
|
||||
case 2:
|
||||
dataValue = 0x02;
|
||||
break;
|
||||
case 3:
|
||||
// case 2:
|
||||
// dataValue = 0x02;
|
||||
// break;
|
||||
case 2:
|
||||
dataValue = 0x03;
|
||||
break;
|
||||
case 4:
|
||||
dataValue = 0x00;
|
||||
case 3:
|
||||
dataValue = 0x0B;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// console.log("dataValue=", dataValue)
|
||||
// 构建数据包
|
||||
var buffer = new ArrayBuffer(6);
|
||||
var dataView = new DataView(buffer);
|
||||
@ -713,12 +920,7 @@
|
||||
// 发送数据
|
||||
|
||||
if (!f) {
|
||||
these.showPop({
|
||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
these.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -727,7 +929,8 @@
|
||||
});
|
||||
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 30).then(() => {
|
||||
|
||||
this.formData.mode = mode;
|
||||
this.setBleFormData();
|
||||
}).catch((ex) => {
|
||||
these.showPop({
|
||||
message: "发送失败," + ex.msg,
|
||||
@ -771,38 +974,54 @@
|
||||
|
||||
},
|
||||
HidePop: function() {
|
||||
console.log("1111");
|
||||
if (this.Status.Pop.clickEvt == 'SendUsr') {
|
||||
|
||||
}
|
||||
if (this.Status.Pop.okCallback) {
|
||||
this.Status.Pop.okCallback();
|
||||
}
|
||||
this.Status.Pop.showPop = false;
|
||||
},
|
||||
showPop: function(option) {
|
||||
|
||||
if (!option) {
|
||||
option = {
|
||||
a: 1
|
||||
hideLoading(this);
|
||||
let defaultCfg = {
|
||||
showHeader: false,
|
||||
headerTxt: "",
|
||||
showHeader: false,
|
||||
showCancel: false,
|
||||
borderColor: '#BBE600',
|
||||
buttonBgColor: '#BBE600',
|
||||
okCallback: null,
|
||||
cancelCallback: null,
|
||||
popType: 'custom',
|
||||
buttonText: '确定',
|
||||
clickEvt: ''
|
||||
};
|
||||
if (!option) {
|
||||
|
||||
}
|
||||
let keys = Object.keys(option);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
these.Status.Pop[key] = option[key];
|
||||
this.Status.Pop[key] = option[key];
|
||||
}
|
||||
if (!option.borderColor) {
|
||||
option.borderColor = '#BBE600';
|
||||
option.buttonBgColor = '#BBE600';
|
||||
keys = Object.keys(defaultCfg);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
if (key in option) {
|
||||
continue;
|
||||
}
|
||||
these.Status.Pop.showPop = true;
|
||||
this.Status.Pop[key] = defaultCfg[key];
|
||||
}
|
||||
|
||||
this.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",
|
||||
});
|
||||
these.showBleUnConnect()
|
||||
return;
|
||||
}
|
||||
showLoading(these, {
|
||||
@ -817,8 +1036,8 @@
|
||||
|
||||
let packetSize = rgbdata.length; //每包均分的数量
|
||||
let mode = rgbdata.length % packetSize; //最后一包的数量
|
||||
let cnt = parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 :
|
||||
0); //总包数量
|
||||
let cnt =
|
||||
1; // parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 :0); //总包数量
|
||||
let curr = 1; //当前包序号
|
||||
|
||||
let sendNext = () => {
|
||||
@ -831,6 +1050,7 @@
|
||||
let bufferSize = 261;
|
||||
|
||||
console.log("bufferSize=", bufferSize)
|
||||
|
||||
let buffer = new ArrayBuffer(bufferSize);
|
||||
let dataView = new DataView(buffer);
|
||||
let startIndex = (curr - 1) * packetSize;
|
||||
@ -844,7 +1064,7 @@
|
||||
|
||||
let packetData = rgbdata.slice(startIndex,
|
||||
endIndex); //取一片数据发送
|
||||
|
||||
console.log("packetData.length=", packetData.length);
|
||||
let start = 0;
|
||||
if (curr == 1) {
|
||||
dataView.setUint8(0, 0xFA);
|
||||
@ -852,7 +1072,7 @@
|
||||
dataView.setUint8(2, 0x01);
|
||||
dataView.setUint8(3, 0x00);
|
||||
|
||||
// dataView.setUint16(2, str.length, false);
|
||||
|
||||
start = 4;
|
||||
}
|
||||
|
||||
@ -862,8 +1082,8 @@
|
||||
|
||||
dataView.setUint8(bufferSize - 1, 0xFF);
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 0);
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 50);
|
||||
console.log("inteval=", inteval)
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
|
||||
.wirteCharactId, 30).then(() => {
|
||||
|
||||
@ -892,12 +1112,36 @@
|
||||
|
||||
}
|
||||
|
||||
|
||||
var result = await this.$refs.textToHex.drawAndGetPixels();
|
||||
|
||||
console.log("11111");
|
||||
var result = null;
|
||||
try {
|
||||
console.log("this.$refs.textToHex=", this.$refs.textToHex);
|
||||
result = await this.$refs.textToHex.drawAndGetPixels();
|
||||
} catch (ex) {
|
||||
console.log("ex=", ex);
|
||||
}
|
||||
if (!result) {
|
||||
hideLoading(this);
|
||||
return;
|
||||
}
|
||||
console.log("result=", result);
|
||||
result = result.map(level1 => {
|
||||
return level1.flat(Infinity);
|
||||
});
|
||||
console.log("result=", result);
|
||||
|
||||
// var str1="FA 06 01 00 FF FF F7 9F EF 6F EC F7 EA 09 CF FF AF FB EF EB EF EB EC 6B EF EB EC 6B EF EB EF FB EE 63 FF FF FF FF F7 9F EF 6F EC F7 EA 09 CF FF AF FB EF EB EF EB EC 6B EF EB EC 6B EF EB EF FB EE 63 FF FF FF FF F7 FF 81 03 ED BB DD B7 CB CF F3 C7 CD 39 BE FF FE FF C0 03 FE FB FD FB F3 F7 8F 87 FF FF FF FF FE FF FE FF FE FF C0 03 FF FB FD FB FD FB FD FB FD FB FB FB FB FF F7 F7 EF F7 9F 8F FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
|
||||
// var str2="FA 07 01 00 FF FF EE DD EE DF EF 5B AB DF AA 03 AE FF AE FF EE 03 EE FF EE FF EE 03 EE FF EE FF EE E3 FF FF FF FF EE DD EE DF EF 5B AB DF AA 03 AE FF AE FF EE 03 EE FF EE FF EE 03 EE FF EE FF EE E3 FF FF FF FF EF 77 EF 73 EF 7F 80 01 EF 7F EF 7F EF 03 E7 3B 8E BB EE D7 EE EF ED E7 ED 9B 8B 7D FF FF FF FF FF FF F7 EF F7 F7 EF F7 DF FB FF FF FF FF FE FF 80 01 FE 7F FD BF FB DF F7 E7 9F F9 FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
|
||||
// var str3="FA 08 01 00 FF FF EF DF EC 01 EF FF AB FF AA 03 AA FB AE FB EE 03 EF DF EF DF EE DB ED DF ED DD EF 1F FF FF FF FF EF BF EF 87 81 77 EE F7 EC 03 81 7F EF 7F EF 7F EF 03 81 7F EF 7F EF 7D EF 7D EF 03 FF FF FF FF F9 F1 CF BF DF FF DF FF C1 FF DD 81 DD F7 DD F7 C1 F7 DF 77 FF 77 BF 77 BF 77 FF F7 FF FF FF FF FD FF FD FF FB FF FB FF F0 07 E7 F7 EF F7 D8 07 BF F7 FF F7 F8 07 FF F7 FF F7 FF C7 FF FF FF FF FF FF FF FF FF FF FE FF FE 7F FE 7F FE FF FD BF FD FF FB DF F7 EF EF F7 DF FB BF FD FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF"
|
||||
|
||||
// let arr1=('0x'+(str1.split(' ').join(",0x"))).split(',');
|
||||
// let arr2=('0x'+(str2.split(' ').join(",0x"))).split(',');
|
||||
// let arr3=('0x'+(str3.split(' ').join(",0x"))).split(',');
|
||||
|
||||
// result=[arr1,arr2,arr3];
|
||||
|
||||
|
||||
// console.log("result=",result);
|
||||
|
||||
|
||||
let h3dic = [0x06, 0x07, 0x08];
|
||||
@ -913,9 +1157,9 @@
|
||||
var rgb = result[i];
|
||||
|
||||
try {
|
||||
console.log("1111");
|
||||
// console.log("1111");
|
||||
await sendTxtPackge(rgb, h3dic[i], str);
|
||||
console.log("222222");
|
||||
// console.log("222222");
|
||||
} catch (ex) {
|
||||
flag = false;
|
||||
console.log("33333");
|
||||
@ -929,9 +1173,24 @@
|
||||
hideLoading(these);
|
||||
if (flag) {
|
||||
console.log("发送成功");
|
||||
this.showPop( {
|
||||
message: "发送成功"
|
||||
this.showPop({
|
||||
message: "发送成功",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
|
||||
borderColor: '#BBE600',
|
||||
buttonBgColor: '#BBE600'
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
let json = {
|
||||
deviceId: these.device.id,
|
||||
name: these.formData.textLines[1],
|
||||
position: these.formData.textLines[0],
|
||||
unitName: these.formData.textLines[2],
|
||||
code: ""
|
||||
};
|
||||
usrApi.sendUsr(json)
|
||||
} else {
|
||||
this.showPop({
|
||||
message: "出现异常发送失败",
|
||||
@ -956,23 +1215,25 @@
|
||||
},
|
||||
sliderChange: function(evt) {
|
||||
this.formData.liangDu = evt.detail.value;
|
||||
clearTimeout(BrighInteval)
|
||||
//给蓝牙设备发送信号更新亮度
|
||||
setTimeout(() => {
|
||||
BrighInteval = setTimeout(() => {
|
||||
this.sendBrightness();
|
||||
this.setBleFormData();
|
||||
}, 10);
|
||||
}, 100);
|
||||
},
|
||||
sendBrightness: function() {
|
||||
const buffer = new ArrayBuffer(6);
|
||||
const dataView = new DataView(buffer);
|
||||
let data = '0x' + parseInt(this.formData.liangDu).toString(16);
|
||||
console.log("亮度:" + this.formData.liangDu + ',16进制:' + data);
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x01); // 帧类型:亮度调节
|
||||
dataView.setUint8(2, 0x01); // 包序号
|
||||
dataView.setUint8(3, 0x00); // 数据长度
|
||||
dataView.setUint8(4, 0x01); // 数据长度
|
||||
dataView.setUint8(5, data); // 数据
|
||||
dataView.setUint8(0, 0xFA); // 帧头
|
||||
dataView.setUint8(1, 0x05); // 帧类型:亮度调节
|
||||
dataView.setUint8(2, 0x00); // 包序号
|
||||
dataView.setUint8(3, 0x01); // 包序号
|
||||
dataView.setUint8(4, data); // 数据长度
|
||||
dataView.setUint8(5, 0xFF); // 数据长度
|
||||
|
||||
let f = this.getDevice();
|
||||
if (f) {
|
||||
// 发送数据
|
||||
|
||||
@ -173,6 +173,9 @@
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js'
|
||||
import {request,baseURL} from '../../utils/request';
|
||||
|
||||
import usrApi from '@/api/670/HBY670.js'
|
||||
const pagePath = "pages/650/HBY650";
|
||||
var ble = null;
|
||||
var these = null;
|
||||
@ -259,7 +262,26 @@
|
||||
iswarn: false
|
||||
},
|
||||
rgb565Data: [],
|
||||
videoHexArray: []
|
||||
videoHexArray: [],
|
||||
device: {
|
||||
id: "",
|
||||
deviceName: "",
|
||||
deviceImei: "",
|
||||
deviceMac: "",
|
||||
communicationMode: 0,
|
||||
devicePic: "",
|
||||
typeName: "",
|
||||
bluetoothName: null,
|
||||
deviceStatus: null,
|
||||
bindingTime: "",
|
||||
onlineStatus: 0,
|
||||
battery: "0",
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
alarmStatus: null,
|
||||
detailPageUrl: "/pages/650/HBY650",
|
||||
showConfirm: false
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
@ -271,6 +293,7 @@
|
||||
these = this;
|
||||
recei = BleReceive.getBleReceive();
|
||||
ble = BleTool.getBleTool();
|
||||
console.log("650")
|
||||
ble.addReceiveCallback(these.bleValueNotify);
|
||||
let eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
@ -278,7 +301,7 @@
|
||||
|
||||
console.log("收到父页面的参数:" + JSON.stringify(data));
|
||||
var device = data.data;
|
||||
|
||||
these.device=device;
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
if (v.macAddress == device.deviceMac) {
|
||||
console.log("找到设备了", v);
|
||||
@ -290,12 +313,7 @@
|
||||
if (!f) {
|
||||
|
||||
|
||||
these.showPop({
|
||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
these.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
let form = f.formData;
|
||||
@ -374,9 +392,9 @@
|
||||
return className;
|
||||
},
|
||||
bleValueNotify: function(receive, device, path) { //订阅消息
|
||||
|
||||
console.log("收到设备的数据", data)
|
||||
let data = recei.ReceiveData(receive, device, pagePath);
|
||||
console.log("收到设备的数据",data)
|
||||
|
||||
if (data) {
|
||||
if ("staBlue_picture" in data) {
|
||||
//重发图片
|
||||
@ -403,7 +421,7 @@ console.log("收到设备的数据",data)
|
||||
let keys = Object.keys(data);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
if(key in these.formData){
|
||||
if (key in these.formData) {
|
||||
these.formData[key] = data[key];
|
||||
}
|
||||
|
||||
@ -434,7 +452,7 @@ console.log("收到设备的数据",data)
|
||||
// console.log("LinkedList=", ble.data.LinkedList);
|
||||
// console.log("formData=", these.formData);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
return v.deviceId == these.formData.deviceId;
|
||||
return v.macAddress == these.device.deviceMac;
|
||||
});
|
||||
|
||||
return f;
|
||||
@ -533,12 +551,7 @@ console.log("收到设备的数据",data)
|
||||
these.setBleFormData();
|
||||
});
|
||||
} else {
|
||||
these.showPop({
|
||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
these.showBleUnConnect();
|
||||
hideLoading(these);
|
||||
}
|
||||
}
|
||||
@ -547,6 +560,34 @@ console.log("收到设备的数据",data)
|
||||
|
||||
|
||||
},
|
||||
showBleUnConnect(){
|
||||
|
||||
this.showPop({
|
||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
buttonText:'去连接',
|
||||
okCallback:function(){
|
||||
console.log("1111");
|
||||
uni.navigateTo({
|
||||
url:"/pages/common/addBLE/addEquip",
|
||||
events: {
|
||||
BindOver: function(data) {
|
||||
console.log(data)
|
||||
}
|
||||
},
|
||||
success: function(res) {
|
||||
// 通过eventChannel向被打开页面传送数据
|
||||
res.eventChannel.emit('detailData', { data: these.device })
|
||||
},
|
||||
fail(ex){
|
||||
console.log("跳转失败",ex);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
LampToggle: function() {
|
||||
|
||||
this.formData.cMode = !this.formData.cMode;
|
||||
@ -606,10 +647,11 @@ console.log("收到设备的数据",data)
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadSuccess.png",
|
||||
});
|
||||
if (!ReSendNo) {
|
||||
setTimeout(()=>{
|
||||
these.HoldYouHand("transmit complete", 0, f.deviceId, f
|
||||
setTimeout(() => {
|
||||
these.HoldYouHand("transmit complete", 0, f
|
||||
.deviceId, f
|
||||
.writeServiceId, f.wirteCharactId);
|
||||
},500);
|
||||
}, 500);
|
||||
|
||||
}
|
||||
|
||||
@ -635,7 +677,7 @@ console.log("收到设备的数据",data)
|
||||
const packetData = these.rgb565Data.slice(startIndex,
|
||||
endIndex);
|
||||
// 构建数据包
|
||||
const bufferSize =505;// 5 + packetData.length * 2; // 头部5字节 + 数据部分
|
||||
const bufferSize = 505; // 5 + packetData.length * 2; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
|
||||
@ -774,14 +816,16 @@ console.log("收到设备的数据",data)
|
||||
console.log("准备发送一段数据");
|
||||
if (currentPacket > totalPackets) {
|
||||
if (!ReSendNo) {
|
||||
setTimeout(()=>{
|
||||
these.HoldYouHand("transmit complete", 0, f.deviceId, f
|
||||
.writeServiceId, f.wirteCharactId).then(()=>{
|
||||
setTimeout(() => {
|
||||
these.HoldYouHand("transmit complete", 0, f
|
||||
.deviceId, f
|
||||
.writeServiceId, f.wirteCharactId).then(
|
||||
() => {
|
||||
console.log("全部发送完毕")
|
||||
}).catch((ex)=>{
|
||||
console.log("出现异常",ex);
|
||||
}).catch((ex) => {
|
||||
console.log("出现异常", ex);
|
||||
});
|
||||
},500);
|
||||
}, 500);
|
||||
|
||||
}
|
||||
these.Status.BottomMenu.show = false;
|
||||
@ -902,13 +946,28 @@ console.log("收到设备的数据",data)
|
||||
let p1 = these.HoldYouHand("video transmit start", 2200, f.deviceId, f.writeServiceId,
|
||||
f.wirteCharactId);
|
||||
let p2 = new Promise((succ, err) => {
|
||||
|
||||
const token = uni.getStorageSync('token');
|
||||
const clientid = uni.getStorageSync('clientID');
|
||||
if (!token) {
|
||||
err({
|
||||
code: 401,
|
||||
msg: "请先登陆后再试"
|
||||
});
|
||||
hideLoading(these);
|
||||
return;
|
||||
}
|
||||
|
||||
uni.uploadFile({
|
||||
url: 'http://114.55.111.217/video/upload',
|
||||
// url: 'http://114.55.111.217/video/upload',
|
||||
url: baseURL+"app/video/upload",
|
||||
filePath: videoPath,
|
||||
name: 'file',
|
||||
header: {
|
||||
"Method": "POST",
|
||||
"Content-Type": "multipart/form-data"
|
||||
"Content-Type": "multipart/form-data",
|
||||
"Authorization": 'Bearer ' + token,
|
||||
"clientid": clientid
|
||||
},
|
||||
timeout: 600000,
|
||||
fail: (ex) => {
|
||||
@ -1103,12 +1162,7 @@ console.log("收到设备的数据",data)
|
||||
|
||||
let f = this.getDevice();
|
||||
if (!f) {
|
||||
these.showPop({
|
||||
message: "蓝牙未连接过该设备,请使用蓝牙重新添加该设备",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
these.showBleUnConnect();
|
||||
return;
|
||||
}
|
||||
showLoading(this, {
|
||||
@ -1130,10 +1184,11 @@ console.log("收到设备的数据",data)
|
||||
|
||||
if (currentPacket > totalPackets) {
|
||||
if (!ReSendNo) {
|
||||
setTimeout(()=>{
|
||||
these.HoldYouHand("transmit complete", 0, f.deviceId, f.writeServiceId, f
|
||||
setTimeout(() => {
|
||||
these.HoldYouHand("transmit complete", 0, f.deviceId, f
|
||||
.writeServiceId, f
|
||||
.wirteCharactId);
|
||||
},500);
|
||||
}, 500);
|
||||
|
||||
}
|
||||
|
||||
@ -1155,6 +1210,16 @@ console.log("收到设备的数据",data)
|
||||
visibleClose: true
|
||||
});
|
||||
these.setBleFormData();
|
||||
|
||||
|
||||
let json = {
|
||||
deviceId: these.device.id,
|
||||
name: these.formData.company,
|
||||
position: these.formData.name,
|
||||
unitName: these.formData.job,
|
||||
code: these.formData.id
|
||||
};
|
||||
usrApi.sendUsr(json)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1219,7 +1284,7 @@ console.log("收到设备的数据",data)
|
||||
}
|
||||
|
||||
|
||||
if(ReSendNo){
|
||||
if (ReSendNo) {
|
||||
sendText(ReSendNo);
|
||||
return;
|
||||
}
|
||||
@ -1261,6 +1326,7 @@ console.log("收到设备的数据",data)
|
||||
}
|
||||
console.log("开始握手");
|
||||
|
||||
let send = () => {
|
||||
ble.sendData(deviceid, buffer, serviceid, characid, 10).then(
|
||||
() => {
|
||||
setTimeout(() => {
|
||||
@ -1268,9 +1334,18 @@ console.log("收到设备的数据",data)
|
||||
resolve(true);
|
||||
}, pauseTime);
|
||||
}).catch(err => {
|
||||
console.log("握手没有成功", )
|
||||
if (err.code == 10007) {
|
||||
send();
|
||||
} else {
|
||||
console.log("握手没有成功", err)
|
||||
reject(err);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
send();
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
</view>
|
||||
|
||||
<view class="warnnig" v-bind:class="formData.staticWarn?'':'displayNone'">
|
||||
<view>警告!环境存在漏电电源!</view>
|
||||
<view>警告!设备静止报警中!</view>
|
||||
<view class="netContent">
|
||||
<view v-bind:class="getWarnStyle(1)" class="net netone"></view>
|
||||
<view v-bind:class="getWarnStyle(2)" class="net nettwo"></view>
|
||||
@ -55,7 +55,7 @@
|
||||
</view>
|
||||
<view class="warnnig" v-bind:class="(formData.qzwarn && Status.staticWarn.time)?'':'displayNone'"
|
||||
@click="CloseWarn(true)">
|
||||
<view>设备强制闪烁报警中!</view>
|
||||
<view>设备强制报警中!</view>
|
||||
<view class="netContent">
|
||||
{{Status.staticWarn.time}}s
|
||||
</view>
|
||||
@ -90,7 +90,9 @@
|
||||
:src="formData.SOS=='sg'?'/static/images/670/sgActive.png':'/static/images/670/sg.png'"
|
||||
mode="aspectFit"></image>
|
||||
</view>
|
||||
<view class="txt">声光报警</view>
|
||||
<view :class="(formData.qzwarn && Status.staticWarn.time)?'':'displayNone'">
|
||||
报警中{{Status.staticWarn.time}}</view>
|
||||
<view :class="(formData.qzwarn && Status.staticWarn.time)?'displayNone':''" class="txt">声光报警</view>
|
||||
</view>
|
||||
<view class="item" @click="sosSetting('rb')" :class="formData.SOS=='rb'?'active':''">
|
||||
<view class="imgContent center">
|
||||
@ -249,7 +251,13 @@
|
||||
hideLoading,
|
||||
updateLoading
|
||||
} from '@/utils/loading.js'
|
||||
const pagePath = "pages/650/HBY650";
|
||||
import {
|
||||
request,
|
||||
baseURL
|
||||
} from '../../utils/request';
|
||||
|
||||
|
||||
const pagePath = "pages/670/HBY670";
|
||||
var ble = null;
|
||||
var these = null;
|
||||
var recei = null;
|
||||
@ -290,7 +298,8 @@
|
||||
visiblePrompt: false,
|
||||
promptTitle: '设备名称',
|
||||
modelValue: '',
|
||||
visibleClose: false
|
||||
visibleClose: false,
|
||||
|
||||
},
|
||||
BottomMenu: {
|
||||
show: false,
|
||||
@ -338,7 +347,7 @@
|
||||
Lat: "", //纬度
|
||||
address: "", //地址
|
||||
modeCurr: "", //档位
|
||||
SOS: "sg", //sos
|
||||
SOS: "", //sos
|
||||
lightCurr: "qiang", //照明模式
|
||||
company: "", //单位
|
||||
usrname: "", //姓名
|
||||
@ -394,6 +403,7 @@
|
||||
these = this;
|
||||
recei = BleReceive.getBleReceive();
|
||||
ble = BleTool.getBleTool();
|
||||
console.log("670")
|
||||
ble.addReceiveCallback(these.bleValueNotify);
|
||||
let eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
@ -629,7 +639,7 @@
|
||||
receiveData.modeCurr = staticLevelText;
|
||||
receiveData.lightCurr = lightingLevelText;
|
||||
receiveData.xuhang = json.sta_PowerTime + "分钟";
|
||||
receiveData.battary = json.sta_PowerPercent ;
|
||||
receiveData.battary = json.sta_PowerPercent;
|
||||
|
||||
receiveData.warnLevel = warn;
|
||||
receiveData.staticWarn = staticWarn;
|
||||
@ -682,9 +692,9 @@
|
||||
if (this.formData.imei) {
|
||||
this.initMQ();
|
||||
}
|
||||
if (these.formData.staticWarn) { //有静止报警
|
||||
if (this.formData.staticWarn) { //有静止报警
|
||||
these.showPop({
|
||||
message: "环境存在漏电电源",
|
||||
message: "设备静止报警中",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/warnning.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
@ -695,14 +705,14 @@
|
||||
|
||||
}
|
||||
|
||||
these.setBleFormData();
|
||||
this.setBleFormData();
|
||||
},
|
||||
getDevice: function() {
|
||||
|
||||
// console.log("LinkedList=", ble.data.LinkedList);
|
||||
// console.log("formData=", these.formData);
|
||||
console.log("LinkedList=", ble.data.LinkedList);
|
||||
console.log("this.device=", this.device);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
return v.deviceId == these.formData.deviceId;
|
||||
return v.macAddress == these.device.deviceMac;
|
||||
});
|
||||
|
||||
return f;
|
||||
@ -799,15 +809,15 @@
|
||||
|
||||
setTimeout(task, 0);
|
||||
},
|
||||
CloseWarn: function(ispop) {
|
||||
let closeEvt=()=>{
|
||||
{
|
||||
CloseWarn: function(ispop) { //解除强制报警
|
||||
let closeEvt = () => {
|
||||
|
||||
these.Status.Pop.showPop = false;
|
||||
|
||||
these.formData.qzwarn = false;
|
||||
clearInterval(these.Status.staticWarn.inteval);
|
||||
|
||||
let closeSOS=()=>{
|
||||
let requestCloseSOS = () => {
|
||||
let json = {
|
||||
ins_SOSGrade: [0]
|
||||
};
|
||||
@ -815,8 +825,9 @@
|
||||
|
||||
this.sendMQ(json).then((res) => {
|
||||
console.log("4g发送成功");
|
||||
|
||||
}).catch((ex) => {
|
||||
console.log("ex=",ex);
|
||||
console.log("ex=", ex);
|
||||
these.showPop({
|
||||
message: "通信异常,请检查手机或设备网络",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
@ -826,34 +837,15 @@
|
||||
|
||||
}).finally(() => {
|
||||
hideLoading(these);
|
||||
this.formData.SOS = 'close';
|
||||
these.setBleFormData();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
let closeWarn=()=>{
|
||||
let json = {
|
||||
ins_ShakeBit: [0]
|
||||
};
|
||||
|
||||
|
||||
this.sendMQ(json).then((res) => {
|
||||
console.log("4g发送成功");
|
||||
}).catch((ex) => {
|
||||
console.log("ex=",ex);
|
||||
these.showPop({
|
||||
message: "通信异常,请检查手机或设备网络",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
});
|
||||
|
||||
}).finally(() => {
|
||||
hideLoading(these);
|
||||
these.setBleFormData();
|
||||
});
|
||||
}
|
||||
|
||||
let f = this.getDevice();
|
||||
let buffer = null;
|
||||
if (f) {
|
||||
@ -861,50 +853,53 @@
|
||||
buffer = new ArrayBuffer(6);
|
||||
let dataView = new DataView(buffer);
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x06); // 帧类型
|
||||
dataView.setUint8(2, 0x01); // 包序号
|
||||
dataView.setUint8(3, 0x00); // 数据长度
|
||||
dataView.setUint8(4, 0x01); // 数据长度
|
||||
dataView.setUint8(5, 0x71); // 数据
|
||||
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(
|
||||
() => {
|
||||
console.log("关闭强制报警成功")
|
||||
dataView.setUint8(0, 0x55); // 帧头
|
||||
dataView.setUint8(1, 0x05); // 帧类型
|
||||
dataView.setUint8(2, 0x01); // 包序号
|
||||
dataView.setUint8(3, 0x00); // 数据长度
|
||||
dataView.setUint8(4, 0x01); // 数据长度
|
||||
dataView.setUint8(5, 0x68);
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(()=>{
|
||||
console.log("成功");
|
||||
});
|
||||
dataView.setUint8(5, 0x6A); // 数据
|
||||
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId, 10).then(
|
||||
() => {
|
||||
console.log("关闭强制报警成功")
|
||||
|
||||
}).catch(ex => {
|
||||
closeSOS();
|
||||
closeWarn();
|
||||
requestCloseSOS();
|
||||
}).finally(() => {
|
||||
this.formData.SOS = 'close';
|
||||
these.setBleFormData();
|
||||
});
|
||||
|
||||
} else {
|
||||
closeSOS();
|
||||
closeWarn();
|
||||
requestCloseSOS();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(!ispop){
|
||||
if (!ispop) {
|
||||
closeEvt();
|
||||
return;
|
||||
}
|
||||
this.showQzWarn(closeEvt);
|
||||
|
||||
},
|
||||
showQzWarn(callback) {
|
||||
let message = '持续报警时间' + this.Status.staticWarn.time;
|
||||
if (this.Status.Pop.clickEvt == 'time' && this.Status.Pop.showPop) {
|
||||
this.Status.Pop.message = message
|
||||
return;
|
||||
}
|
||||
this.showPop({
|
||||
showHeader: true,
|
||||
headerTxt: "强制报警",
|
||||
message: '持续报警时间' + this.Status.staticWarn.time,
|
||||
message: message,
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
buttonText:"解除报警",
|
||||
okCallback: closeEvt
|
||||
buttonText: "解除报警",
|
||||
okCallback: callback,
|
||||
clickEvt: 'time'
|
||||
});
|
||||
|
||||
},
|
||||
sosSetting: function(type) {
|
||||
if (this.formData.SOS == type) {
|
||||
@ -915,7 +910,7 @@
|
||||
text: "请稍候..."
|
||||
});
|
||||
let task = () => {
|
||||
this.formData.SOS = type;
|
||||
|
||||
let dic = {
|
||||
ble: {
|
||||
rb: 0x68,
|
||||
@ -937,6 +932,8 @@
|
||||
let requestSend = () => {
|
||||
this.sendMQ(json).then((res) => {
|
||||
console.log("4g发送成功");
|
||||
|
||||
|
||||
}).catch((ex) => {
|
||||
console.log("ex=", ex);
|
||||
these.showPop({
|
||||
@ -954,7 +951,7 @@
|
||||
|
||||
}
|
||||
|
||||
let SendCmd = () => {
|
||||
let bleSendCmd = () => {
|
||||
let f = this.getDevice();
|
||||
let buffer = null;
|
||||
if (f) {
|
||||
@ -972,21 +969,6 @@
|
||||
() => {
|
||||
console.log("蓝牙发送成功了");
|
||||
|
||||
dic = {
|
||||
close: 0x71
|
||||
}
|
||||
if (type in dic) {
|
||||
dataView.setUint8(1, 0x06); // 帧类型
|
||||
dataView.setUint8(5, 0x71); // 数据
|
||||
|
||||
} else {
|
||||
dataView.setUint8(1, 0x06); // 帧类型
|
||||
dataView.setUint8(5, 0x70); // 数据
|
||||
}
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f.wirteCharactId,
|
||||
10).then(() => {
|
||||
console.log("蓝牙发送报警成功", type);
|
||||
})
|
||||
|
||||
hideLoading(these);
|
||||
these.setBleFormData();
|
||||
@ -1000,33 +982,70 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (type !== 'sg') {
|
||||
SendCmd();
|
||||
} else {
|
||||
let OpenSOS = () => {
|
||||
these.formData.qzwarn = true; //标记为强制报警了
|
||||
|
||||
these.Status.staticWarn.time = 50;
|
||||
this.formData.SOS = type;
|
||||
|
||||
let loopFunc = () => {
|
||||
if (these.Status.staticWarn.inteval === null) {
|
||||
return;
|
||||
}
|
||||
if (these.Status.staticWarn.time === 0) {
|
||||
|
||||
|
||||
clearInterval(these.Status.staticWarn.inteval);
|
||||
these.Status.staticWarn.inteval = null;
|
||||
these.formData.qzwarn = false;
|
||||
these.formData.SOS = 'close';
|
||||
these.CloseWarn(false);
|
||||
return;
|
||||
}
|
||||
these.Status.staticWarn.time = these.Status.staticWarn
|
||||
.time - 1;
|
||||
|
||||
if (these.Status.Pop.clickEvt == 'time' && this.Status.Pop.showPop) {
|
||||
console.log("111111");
|
||||
this.showQzWarn(this.Status.Pop.okCallback);
|
||||
}
|
||||
}
|
||||
these.Status.staticWarn.inteval = setInterval(() => {
|
||||
loopFunc();
|
||||
}, 1000)
|
||||
|
||||
bleSendCmd();
|
||||
}
|
||||
|
||||
|
||||
if (type == 'rb') { //红蓝报警
|
||||
this.formData.SOS = type;
|
||||
bleSendCmd();
|
||||
return;
|
||||
}
|
||||
if (type == 'sg') //强制报警
|
||||
{
|
||||
|
||||
this.showPop({
|
||||
message: '确定开启声光报警模式?',
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
okCallback: function() {
|
||||
these.formData.qzwarn = true;
|
||||
|
||||
these.Status.staticWarn.time = 5;
|
||||
these.Status.staticWarn.inteval = setInterval(() => {
|
||||
if (these.Status.staticWarn.time === 0) {
|
||||
clearInterval(these.Status.staticWarn.inteval);
|
||||
these.formData.qzwarn = false;
|
||||
these.CloseWarn(false);
|
||||
okCallback: OpenSOS,
|
||||
buttonText: "开启"
|
||||
});
|
||||
return;
|
||||
}
|
||||
these.Status.staticWarn.time = these.Status.staticWarn
|
||||
.time - 1;
|
||||
}, 1000)
|
||||
if (type == 'close') {
|
||||
|
||||
SendCmd();
|
||||
if (this.formData.SOS = 'sg') { //解除声光报警
|
||||
this.CloseWarn(true);
|
||||
} else {
|
||||
this.formData.SOS = type;
|
||||
bleSendCmd();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1101,8 +1120,14 @@
|
||||
these.setBleFormData();
|
||||
}).catch((ex) => {
|
||||
//使用4G发送
|
||||
if (ex.code == 10007) {
|
||||
console.log("蓝牙发送失败,正在重试");
|
||||
task();
|
||||
} else {
|
||||
console.log("蓝牙发送失败,转4g发送", ex);
|
||||
requestSend();
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
console.log("找不到蓝牙设备,使用4G发送")
|
||||
@ -1382,7 +1407,7 @@
|
||||
}).catch((ex) => {
|
||||
console.log("出现异常", ex);
|
||||
});
|
||||
}, 500);
|
||||
}, 3000);
|
||||
|
||||
}
|
||||
these.Status.BottomMenu.show = false;
|
||||
@ -1437,6 +1462,8 @@
|
||||
dataView.setUint8(6 + i, '0x' + packetData[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
let inteval = 30;
|
||||
console.log("开始发送一段视频"); //
|
||||
ble.sendData(f.deviceId, buffer, f.writeServiceId, f
|
||||
@ -1487,6 +1514,40 @@
|
||||
}
|
||||
|
||||
var sendVideo = (videoPath) => {
|
||||
|
||||
let f = these.getDevice();
|
||||
if (!f) {
|
||||
these.showPop({
|
||||
message: "蓝牙未连接,请连接后再试",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
buttonText: '去连接',
|
||||
okCallback: function() {
|
||||
console.log("1111");
|
||||
uni.navigateTo({
|
||||
url: "/pages/common/addBLE/addEquip",
|
||||
events: {
|
||||
BindOver: function(data) {
|
||||
console.log(data)
|
||||
}
|
||||
},
|
||||
success: function(res) {
|
||||
// 通过eventChannel向被打开页面传送数据
|
||||
res.eventChannel.emit('detailData', {
|
||||
data: these.device
|
||||
})
|
||||
},
|
||||
fail(ex) {
|
||||
console.log("跳转失败", ex);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
let uploadVideo = () => {
|
||||
|
||||
if (these.videoHexArray.length > 0) {
|
||||
@ -1495,7 +1556,9 @@
|
||||
return;
|
||||
|
||||
}
|
||||
console.log("开始处理,正在上传");
|
||||
console.log("开始处理,正在上传", f);
|
||||
const token = uni.getStorageSync('token');
|
||||
const clientid = uni.getStorageSync('clientID');
|
||||
|
||||
showLoading(these, {
|
||||
text: "上传中"
|
||||
@ -1503,13 +1566,25 @@
|
||||
let p1 = these.HoldYouHand("video transmit start", 2200, f.deviceId, f.writeServiceId,
|
||||
f.wirteCharactId);
|
||||
let p2 = new Promise((succ, err) => {
|
||||
if (!token) {
|
||||
err({
|
||||
code: 401,
|
||||
msg: "请先登陆后再试"
|
||||
});
|
||||
hideLoading(these);
|
||||
return;
|
||||
}
|
||||
console.log("baseURL=", baseURL);
|
||||
uni.uploadFile({
|
||||
url: 'http://114.55.111.217/video/upload',
|
||||
// url: 'http://114.55.111.217/video/upload',
|
||||
url: baseURL + "/app/video/upload",
|
||||
filePath: videoPath,
|
||||
name: 'file',
|
||||
header: {
|
||||
"Method": "POST",
|
||||
"Content-Type": "multipart/form-data"
|
||||
"Content-Type": "multipart/form-data",
|
||||
"Authorization": 'Bearer ' + token,
|
||||
"clientid": clientid
|
||||
},
|
||||
timeout: 600000,
|
||||
fail: (ex) => {
|
||||
@ -1564,7 +1639,7 @@
|
||||
});
|
||||
})
|
||||
}
|
||||
let f = these.getDevice();
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1695,7 +1770,9 @@
|
||||
buttonBgColor: '#BBE600',
|
||||
okCallback: null,
|
||||
cancelCallback: null,
|
||||
popType: 'custom'
|
||||
popType: 'custom',
|
||||
buttonText: '确定',
|
||||
clickEvt: ''
|
||||
};
|
||||
if (!option) {
|
||||
|
||||
@ -1703,7 +1780,7 @@
|
||||
let keys = Object.keys(option);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
these.Status.Pop[key] = option[key];
|
||||
this.Status.Pop[key] = option[key];
|
||||
}
|
||||
keys = Object.keys(defaultCfg);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
@ -1711,10 +1788,10 @@
|
||||
if (key in option) {
|
||||
continue;
|
||||
}
|
||||
these.Status.Pop[key] = defaultCfg[key];
|
||||
this.Status.Pop[key] = defaultCfg[key];
|
||||
}
|
||||
|
||||
these.Status.Pop.showPop = true;
|
||||
this.Status.Pop.showPop = true;
|
||||
},
|
||||
sendUsr: function(ReSendNo) {
|
||||
|
||||
@ -1818,6 +1895,16 @@
|
||||
});
|
||||
these.setBleFormData();
|
||||
hideLoading(these);
|
||||
|
||||
|
||||
let json = {
|
||||
deviceId: these.device.id,
|
||||
name: these.formData.company,
|
||||
position: these.formData.usrname,
|
||||
unitName: these.formData.job,
|
||||
code: these.formData.usrid
|
||||
};
|
||||
api.sendUsr(json)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1909,18 +1996,10 @@
|
||||
text: "请稍候..."
|
||||
});
|
||||
this.setBleFormData();
|
||||
let arr = [];
|
||||
if (this.formData.msgTxt.length > 8) {
|
||||
arr.push(this.formData.msgTxt.substring(0, 8));
|
||||
arr.push(this.formData.msgTxt.substring(8));
|
||||
} else {
|
||||
let index = Math.floor(this.formData.msgTxt.length / 2)
|
||||
arr.push(this.formData.msgTxt.substring(0, index));
|
||||
arr.push(this.formData.msgTxt.substring(index));
|
||||
}
|
||||
|
||||
|
||||
let data = {
|
||||
"sendMsg": arr.join('|'),
|
||||
"sendMsg": this.formData.msgTxt,
|
||||
"deviceIds": [
|
||||
this.device.id
|
||||
],
|
||||
|
||||
1720
pages/7305/BJQ7305.vue
Normal file
1720
pages/7305/BJQ7305.vue
Normal file
File diff suppressed because it is too large
Load Diff
1267
pages/BlueTooth/ModeSetting/4877.vue
Normal file
1267
pages/BlueTooth/ModeSetting/4877.vue
Normal file
File diff suppressed because it is too large
Load Diff
@ -219,7 +219,7 @@
|
||||
|
||||
<script>
|
||||
import gbk from '@/utils/gbk.js';
|
||||
import TextToHexVue from '@/components/TextToHex/TextToHex.vue';
|
||||
import TextToHexVue from '@/components/TextToHex/TextToHexV1.vue';
|
||||
export default {
|
||||
comments: {
|
||||
TextToHexVue
|
||||
|
||||
@ -240,6 +240,8 @@
|
||||
import gbk from '@/utils/gbk.js';
|
||||
import TextToHexV1 from '@/components/TextToHex/TextToHexV1.vue';
|
||||
import Common from '../../../utils/Common';
|
||||
import BleHelper from '../../../utils/BleHelper';
|
||||
var ble=BleHelper.getBleTool();
|
||||
export default {
|
||||
components: {
|
||||
TextToHexV1
|
||||
@ -251,7 +253,7 @@
|
||||
|
||||
canvasTop: '-1000px',
|
||||
canvasLeft: '-1000px',
|
||||
inteval: 100,
|
||||
inteval: 1000,
|
||||
isLoading: false,
|
||||
isBluetoothOpen: false,
|
||||
isSearching: false,
|
||||
@ -270,7 +272,7 @@
|
||||
logList: [],
|
||||
packetCount: 1,
|
||||
currentPage: 'deviceList',
|
||||
targetDeviceName: 'JQZM-EF4651',
|
||||
targetDeviceName: 'JQZM-EF4651',//FB_Site_UART
|
||||
currentTab: 'mode',
|
||||
brightness: 50,
|
||||
brightnessTimer: null,
|
||||
@ -287,7 +289,7 @@
|
||||
totalPackets: 100,
|
||||
imageWidth: 0,
|
||||
imageHeight: 0,
|
||||
textLines: ['下雨了', '天亮了', '连接成功'],
|
||||
textLines: ['那个', '你看到我的小熊', '了吗'],
|
||||
textProgress: 0,
|
||||
currentTextPacket: 0,
|
||||
totalTextPackets: 4,
|
||||
@ -308,6 +310,7 @@
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
|
||||
this.initBluetoothAdapter();
|
||||
},
|
||||
methods: {
|
||||
@ -335,32 +338,41 @@
|
||||
},
|
||||
// 蓝牙初始化
|
||||
initBluetoothAdapter() {
|
||||
ble.addDeviceFound(this.onDeviceFound);
|
||||
console.log('开始初始化蓝牙适配器');
|
||||
uni.openBluetoothAdapter({
|
||||
success: (res) => {
|
||||
ble.OpenBlue().then((res)=>{
|
||||
this.isBluetoothOpen = true;
|
||||
this.bluetoothStatus = '已开启';
|
||||
console.log('蓝牙适配器初始化成功');
|
||||
this.getBluetoothAdapterState();
|
||||
ble.StartSearch();
|
||||
}).catch((err)=>{
|
||||
this.isBluetoothOpen = true;
|
||||
this.bluetoothStatus = '已开启';
|
||||
});
|
||||
// uni.openBluetoothAdapter({
|
||||
// success: (res) => {
|
||||
// this.isBluetoothOpen = true;
|
||||
// this.bluetoothStatus = '已开启';
|
||||
// console.log('蓝牙适配器初始化成功');
|
||||
// this.getBluetoothAdapterState();
|
||||
|
||||
// 自动开始搜索设备
|
||||
this.startSearch();
|
||||
},
|
||||
fail: (err) => {
|
||||
this.bluetoothStatus = '初始化失败';
|
||||
console.log(`蓝牙适配器初始化失败: ${err.errMsg}`);
|
||||
if (err.errCode === 10001) {
|
||||
uni.onBluetoothAdapterStateChange((res) => {
|
||||
if (res.available) {
|
||||
this.isBluetoothOpen = true;
|
||||
this.bluetoothStatus = '已开启';
|
||||
console.log('蓝牙适配器已开启');
|
||||
this.startSearch();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
// // 自动开始搜索设备
|
||||
// this.startSearch();
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// this.bluetoothStatus = '初始化失败';
|
||||
// console.log(`蓝牙适配器初始化失败: ${err.errMsg}`);
|
||||
// if (err.errCode === 10001) {
|
||||
// uni.onBluetoothAdapterStateChange((res) => {
|
||||
// if (res.available) {
|
||||
// this.isBluetoothOpen = true;
|
||||
// this.bluetoothStatus = '已开启';
|
||||
// console.log('蓝牙适配器已开启');
|
||||
// this.startSearch();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
},
|
||||
|
||||
// 获取蓝牙适配器状态
|
||||
@ -418,39 +430,46 @@
|
||||
this.deviceList = [];
|
||||
this.searchTips = '搜索中...';
|
||||
console.log('开始搜索蓝牙设备');
|
||||
|
||||
uni.startBluetoothDevicesDiscovery({
|
||||
services: ["0xFFE0"],
|
||||
allowDuplicatesKey: false,
|
||||
success: (res) => {
|
||||
ble.StartSearch().then(()=>{
|
||||
console.log('开始搜索蓝牙设备成功');
|
||||
this.onDeviceFound();
|
||||
|
||||
|
||||
},
|
||||
fail: (err) => {
|
||||
}).catch((err)=>{
|
||||
this.isSearching = false;
|
||||
this.searchTips = '搜索失败';
|
||||
console.log(`搜索蓝牙设备失败: ${err.errMsg}`);
|
||||
}
|
||||
});
|
||||
// uni.startBluetoothDevicesDiscovery({
|
||||
|
||||
// allowDuplicatesKey: false,
|
||||
// success: (res) => {
|
||||
// console.log('开始搜索蓝牙设备成功');
|
||||
// this.onDeviceFound();
|
||||
|
||||
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// this.isSearching = false;
|
||||
// this.searchTips = '搜索失败';
|
||||
// console.log(`搜索蓝牙设备失败: ${err.errMsg}`);
|
||||
// }
|
||||
// });
|
||||
},
|
||||
|
||||
// 停止搜索蓝牙设备
|
||||
stopSearch() {
|
||||
this.isSearching = false;
|
||||
this.searchTips = this.deviceList.length > 0 ? '搜索完成' : '未发现蓝牙设备';
|
||||
|
||||
uni.stopBluetoothDevicesDiscovery({
|
||||
success: () => {
|
||||
console.log('停止搜索蓝牙设备');
|
||||
}
|
||||
});
|
||||
ble.StartSearch();
|
||||
// uni.stopBluetoothDevicesDiscovery({
|
||||
// success: () => {
|
||||
// console.log('停止搜索蓝牙设备');
|
||||
// }
|
||||
// });
|
||||
},
|
||||
|
||||
// 监听发现新设备
|
||||
onDeviceFound() {
|
||||
uni.onBluetoothDeviceFound((res) => {
|
||||
onDeviceFound(res) {
|
||||
// uni.onBluetoothDeviceFound((res) => {
|
||||
// console.log("发现新设备",res);
|
||||
var device = res.devices[0];
|
||||
if (!device.name && !device.localName) return;
|
||||
// if ((device.name || device.localName) === this.targetDeviceName) {
|
||||
@ -467,24 +486,62 @@
|
||||
this.deviceList[index].RSSI = device.RSSI;
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
// 如果找到目标设备,自动连接
|
||||
if ((device.name || device.localName) === this.targetDeviceName) {
|
||||
console.log(`发现目标设备: ${JSON.stringify(device)}`);
|
||||
this.connectDevice(device.deviceId, this.targetDeviceName,device);
|
||||
}
|
||||
});
|
||||
// });
|
||||
},
|
||||
|
||||
// 连接蓝牙设备
|
||||
connectDevice(deviceId, deviceName,device) {
|
||||
if (this.isConnected && this.connectedDeviceId === deviceId) return;
|
||||
|
||||
let gotoDetail=()=>{
|
||||
ble.StopSearch();
|
||||
uni.navigateTo({
|
||||
url:"/pages/6155/deviceDetail",
|
||||
success(res) {
|
||||
res.eventChannel.emit('detailData', {
|
||||
data: {deviceId:deviceId},
|
||||
deviceType: '',
|
||||
apiType: 'listA' //标识,根据这个参数,区分普通详情,分享跳转详情,查不一样的权限信息
|
||||
});
|
||||
},fail(ex){
|
||||
console.log("跳转失败",ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (this.isConnected && this.connectedDeviceId === deviceId) {
|
||||
gotoDetail();
|
||||
return;
|
||||
};
|
||||
|
||||
this.isLoading = true;
|
||||
if(device){
|
||||
console.log("device=",device);
|
||||
}
|
||||
|
||||
let promise=null;
|
||||
if (deviceName == 'FB_Site_UART') {
|
||||
promise=ble.LinkBlue(deviceId, '0000AE30-0000-1000-8000-00805F9B34FB',
|
||||
'0000AE03-0000-1000-8000-00805F9B34FB', '0000AE02-0000-1000-8000-00805F9B34FB');
|
||||
} else {
|
||||
promise=ble.LinkBlue(deviceId, '0000FFE0-0000-1000-8000-00805F9B34FB',
|
||||
'0000FFE1-0000-1000-8000-00805F9B34FB', '0000FFE2-0000-1000-8000-00805F9B34FB');
|
||||
}
|
||||
|
||||
promise.then(res=>{
|
||||
console.log("连接成功了");
|
||||
gotoDetail();
|
||||
this.isConnected=true;
|
||||
}).catch(err=>{
|
||||
console.log("连接失败了",err);
|
||||
this.isConnected=false;
|
||||
});
|
||||
return;
|
||||
console.log(`开始连接设备: ${deviceName}`);
|
||||
var these = this;
|
||||
uni.createBLEConnection({
|
||||
@ -502,16 +559,20 @@
|
||||
setTimeout(function() {
|
||||
uni.setBLEMTU({
|
||||
deviceId: deviceId,
|
||||
mtu: 1024,
|
||||
mtu: 512,
|
||||
success: (info) => {
|
||||
console.log("设置mtu成功",info)
|
||||
these.getDeviceServices(deviceId);
|
||||
},
|
||||
fail: (ex) => {
|
||||
console.log("设置mtu失败" + JSON.stringify(ex));
|
||||
these.getDeviceServices(deviceId);
|
||||
},finally(){
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
these.getDeviceServices(deviceId);
|
||||
|
||||
}, 2000)
|
||||
// 获取服务和特征值
|
||||
|
||||
@ -648,7 +709,7 @@
|
||||
deviceId: deviceId,
|
||||
success: (res) => {
|
||||
|
||||
these.addLog("发现服务" + JSON.stringify(res.services));
|
||||
console.log("发现服务" + JSON.stringify(res.services));
|
||||
if (res.services.length == 0) {
|
||||
setTimeout(function() {
|
||||
these.getDeviceServices(deviceId);
|
||||
@ -662,11 +723,11 @@
|
||||
});
|
||||
|
||||
if (targetService) {
|
||||
these.addLog(`找到目标服务: ${targetService.uuid}`);
|
||||
console.log(`找到目标服务: ${targetService.uuid}`);
|
||||
this.serviceId = targetService.uuid;
|
||||
this.getDeviceCharacteristics(deviceId, targetService.uuid);
|
||||
} else {
|
||||
these.addLog("没找到目标服务");
|
||||
console.log("没找到目标服务");
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
@ -684,7 +745,7 @@
|
||||
serviceId: serviceId,
|
||||
success: (res) => {
|
||||
console.log(`获取设备特征值成功,共发现 ${res.characteristics.length} 个特征值`);
|
||||
these.addLog(`获取设备成功:${JSON.stringify(res.characteristics)}`);
|
||||
console.log(`获取设备成功:${JSON.stringify(res.characteristics)}`);
|
||||
// 查找可写特征值
|
||||
var writeChar = res.characteristics.find(char => {
|
||||
return char.uuid.indexOf("FFE1") > -1 || char.uuid.indexOf(
|
||||
@ -818,7 +879,7 @@
|
||||
"续航时间:"+this.receiveData.time
|
||||
];
|
||||
this.logList=[];
|
||||
this.addLog(arr.join(","));
|
||||
console.log(arr.join(","));
|
||||
} catch (error) {
|
||||
console.log('数据解析错误:',error);
|
||||
}
|
||||
@ -833,14 +894,14 @@
|
||||
let arr=hexs.split(' ');
|
||||
if(arr.length>=7){
|
||||
this.receiveData.macAddress=arr.slice(1,7).join(":");
|
||||
this.addLog("设备mac地址:"+this.receiveData.macAddress);
|
||||
console.log("设备mac地址:"+this.receiveData.macAddress);
|
||||
}else{
|
||||
|
||||
this.addLog("收到无效的数据");
|
||||
console.log("收到无效的数据");
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.addLog("收到无效的数据");
|
||||
console.log("收到无效的数据");
|
||||
|
||||
}
|
||||
}
|
||||
@ -929,7 +990,7 @@
|
||||
setMode(mode, type) {
|
||||
this.logList = [];
|
||||
if (!this.isConnected) {
|
||||
this.addLog("未连接设备")
|
||||
console.log("未连接设备")
|
||||
uni.showToast({
|
||||
title: '未连接设备',
|
||||
icon: 'none'
|
||||
@ -1195,10 +1256,33 @@
|
||||
processAndSendImageData(pixels) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 创建RGB565格式的像素数据
|
||||
var rgb565Data = this.convertToRGB565(pixels, 160, 80);
|
||||
// console.log("rgb565Data=,",rgb565Data);
|
||||
var arr = this.convertToRGB565(pixels, 160, 80);
|
||||
|
||||
var list = [];
|
||||
let index = 0; // 用于追踪arr的当前位置
|
||||
|
||||
// 外层循环:7个主要元素(i从1到7)
|
||||
for (let i = 1; i < 8; i++) {
|
||||
let secondLevel = [];
|
||||
// 中层循环:每个主要元素包含9个子数组(j从1到9)
|
||||
for (let j = 1; j < 10; j++) {
|
||||
// 确定当前子数组的长度:前8个是254,第9个是16
|
||||
let length = (j < 9) ? 248 : 128;
|
||||
let thirdLevel = [];
|
||||
|
||||
// 从arr中提取相应数量的元素
|
||||
for (let k = 0; k < length && index < arr.length; k++) {
|
||||
thirdLevel.push(arr[index]);
|
||||
index++;
|
||||
}
|
||||
|
||||
secondLevel.push(thirdLevel);
|
||||
}
|
||||
list.push(secondLevel);
|
||||
}
|
||||
|
||||
// 分包发送
|
||||
this.sendImagePackets(rgb565Data).then(resolve).catch(reject);
|
||||
this.sendImagePackets(list).then(resolve).catch(reject);
|
||||
});
|
||||
},
|
||||
|
||||
@ -1221,8 +1305,11 @@
|
||||
var b = pixels[i + 2];
|
||||
|
||||
|
||||
//var rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||
var bgr565 = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
|
||||
// var rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||
|
||||
|
||||
var bgr565 = ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3);
|
||||
|
||||
result[index++] = bgr565;
|
||||
}
|
||||
|
||||
@ -1239,68 +1326,61 @@
|
||||
// 总数据包数
|
||||
|
||||
let currentPacket = 1;
|
||||
let packetSize = 120;
|
||||
let mode = imageData.length % packetSize;
|
||||
let totalPackets = parseInt(imageData.length / packetSize) + (mode > 0 ? 1 : 0)
|
||||
|
||||
let totalPackets =7;
|
||||
let childPacket=1;
|
||||
let totalChildPacket=9;
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 100);
|
||||
this.totalPackets = totalPackets;
|
||||
this.totalPackets = 57;
|
||||
// 发送单个数据包
|
||||
var sendNextPacket = () => {
|
||||
if (currentPacket > totalPackets) {
|
||||
if (currentPacket> totalPackets) {
|
||||
this.isSending = false;
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
var packetData = imageData[currentPacket-1][childPacket-1];
|
||||
if(packetData.length==0){
|
||||
this.isSending = false;
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
var start = 0;
|
||||
var dataLength = 0;
|
||||
var bufferSize = 0;
|
||||
if (currentPacket == 1) {
|
||||
bufferSize = packetSize * 2 + 5;
|
||||
dataLength = packetSize * 2;
|
||||
start = 5;
|
||||
} else if (currentPacket == totalPackets) {
|
||||
bufferSize = mode > 0 ? (mode * 2) : (packetSize * 2);
|
||||
dataLength = bufferSize
|
||||
} else {
|
||||
bufferSize = packetSize * 2;
|
||||
dataLength = bufferSize;
|
||||
}
|
||||
// 创建数据包
|
||||
var startIndex = (currentPacket - 1) * packetSize;
|
||||
var endIndex = Math.min(startIndex + packetSize, imageData.length);
|
||||
if (startIndex > endIndex) {
|
||||
return;
|
||||
}
|
||||
|
||||
var packetData = imageData.slice(startIndex,
|
||||
endIndex); // imageData.subarray(startIndex, endIndex);
|
||||
|
||||
// 构建数据包
|
||||
|
||||
|
||||
var buffer = new ArrayBuffer(bufferSize);
|
||||
var buffer = new ArrayBuffer(500);
|
||||
var dataView = new DataView(buffer);
|
||||
|
||||
if (currentPacket == 1) { //第一包要填充头部
|
||||
|
||||
// 填充头部
|
||||
dataView.setUint8(0, 0x70); // 帧头
|
||||
dataView.setUint8(1, 0x65); // 帧头
|
||||
dataView.setUint8(2, 0x0A); // 帧类型
|
||||
dataView.setUint16(3, dataLength, false); //包长度
|
||||
}
|
||||
dataView.setUint8(0, 0xFB); // 帧头
|
||||
dataView.setUint8(1, 0x09); // 帧头
|
||||
dataView.setUint8(2, currentPacket); // 包序号
|
||||
dataView.setUint8(3, childPacket); //子包序号
|
||||
|
||||
|
||||
for (let i = 0; i < packetData.length; i++) {
|
||||
dataView.setUint16(start + i * 2, packetData[i], false); //本包数据,大端字节序
|
||||
dataView.setUint16(4 + i * 2, packetData[i], false); //本包数据,大端字节序
|
||||
}
|
||||
|
||||
if(packetData.length<248){
|
||||
for (var i = 4+packetData.length*2; i < 500; i++) {
|
||||
dataView.setUint8(i, 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
//发送数据包
|
||||
this.sendData(buffer).then(() => {
|
||||
// 更新进度
|
||||
this.currentPacket = currentPacket;
|
||||
this.progress = Math.round((currentPacket / totalPackets) * totalPackets);
|
||||
|
||||
this.currentPacket =childPacket+ (currentPacket-1)*totalChildPacket;
|
||||
this.progress = Math.round((this.currentPacket / this.totalPackets) * 100);
|
||||
if(childPacket==9){
|
||||
currentPacket++;
|
||||
childPacket=1;
|
||||
}else{
|
||||
childPacket++;
|
||||
}
|
||||
|
||||
|
||||
setTimeout(sendNextPacket, inteval);
|
||||
}).catch(err => {
|
||||
@ -1332,7 +1412,7 @@
|
||||
title: "请稍候....",
|
||||
mask: true
|
||||
});
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: '开始发送文字'
|
||||
});
|
||||
@ -1346,7 +1426,7 @@
|
||||
let mode = rgbdata.length % packetSize; //最后一包的数量
|
||||
let cnt = parseInt(rgbdata.length / packetSize) + (mode > 0 ? 1 : 0); //总包数量
|
||||
let curr = 1; //当前包序号
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: '当前包' + curr
|
||||
});
|
||||
@ -1356,7 +1436,7 @@
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "正在向设备发送" + curr + "/" + cnt
|
||||
})
|
||||
@ -1372,13 +1452,13 @@
|
||||
let buffer = new ArrayBuffer(bufferSize);
|
||||
let dataView = new DataView(buffer);
|
||||
let startIndex = (curr - 1) * packetSize;
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "分片大小" + bufferSize
|
||||
})
|
||||
let endIndex = Math.min(startIndex + packetSize, rgbdata.length);
|
||||
if (startIndex > endIndex) {
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "发送完成"
|
||||
})
|
||||
@ -1386,7 +1466,7 @@
|
||||
}
|
||||
|
||||
let packetData = rgbdata.slice(startIndex, endIndex); //取一片数据发送
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "获取到分片"
|
||||
})
|
||||
@ -1396,8 +1476,6 @@
|
||||
dataView.setUint8(1, type);
|
||||
dataView.setUint8(2, 0x01);
|
||||
dataView.setUint8(3, 0x00);
|
||||
|
||||
// dataView.setUint16(2, str.length, false);
|
||||
start = 4;
|
||||
}
|
||||
|
||||
@ -1406,7 +1484,7 @@
|
||||
}
|
||||
|
||||
dataView.setUint8(bufferSize - 1, 0xFF);
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "数据准备就绪"
|
||||
})
|
||||
@ -1414,7 +1492,7 @@
|
||||
|
||||
//发送数据包
|
||||
this.sendData(buffer).then(() => {
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "发送成功,准备发送下一包"
|
||||
})
|
||||
@ -1422,7 +1500,7 @@
|
||||
setTimeout(sendNext, inteval);
|
||||
}).catch(err => {
|
||||
console.log("err=", err);
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "出现错误" + JSON.stringify(err)
|
||||
});
|
||||
@ -1438,7 +1516,7 @@
|
||||
sendNext();
|
||||
} catch (ex) {
|
||||
console.log("ex=", ex);
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "出现异常1" + JSON.stringify(ex)
|
||||
})
|
||||
@ -1450,12 +1528,12 @@
|
||||
|
||||
}
|
||||
|
||||
// this.addLog({
|
||||
// console.log({
|
||||
// date: Common.DateFormat(),
|
||||
// remark: '正在取模'
|
||||
// });
|
||||
var result = await this.$refs.textToHex.drawAndGetPixels();
|
||||
// this.addLog({
|
||||
// console.log({
|
||||
// date: Common.DateFormat(),
|
||||
// remark: '取模成功'
|
||||
// });
|
||||
@ -1464,6 +1542,19 @@
|
||||
});
|
||||
|
||||
|
||||
// console.log("result=",result);
|
||||
// var str1="00 00 0E 58 7C 4C 08 44 08 40 7F FE 08 60 08 64 0B 6C 7F 38 78 30 08 72 08 D2 0B 9E 38 0C 00 00 00 00 1F F8 18 08 1F F8 18 18 18 18 1F F8 00 00 7F FE 01 80 19 80 19 F8 3D 80 67 80 61 FE 00 00 00 00 01 80 01 80 3F FC 3F FC 21 84 21 84 21 84 21 84 3F FC 21 84 01 80 01 80 01 80 01 80 00 00 00 00 7F FE 7F FE 60 06 6F F6 61 86 61 86 6F E6 61 86 61 A6 61 A6 6F F6 60 06 7F FE 7F FE 00 00 00 00 01 80 01 80 01 80 01 80 01 80 01 80 03 C0 02 40 06 60 0C 30 0C 10 38 1C 70 0E 40 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
// var str2="00 00 3F FC 3F 00 19 98 7F FE 7F FE 66 06 1F F8 04 00 0F F8 0F F8 1A 30 31 E0 73 F0 4E 1C 00 00 00 00 7F FE 7F FE 60 06 6F F6 61 86 61 86 6F E6 61 86 61 A6 61 A6 6F F6 60 06 7F FE 7F FE 00 00 00 00 01 00 3F F6 03 0C 01 18 7F FE 01 C0 03 80 1F F8 78 08 08 08 0F F8 08 08 0F F8 0F F8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
// var str3="00 00 3F FC 3F FC 01 80 01 80 01 00 7F FE 03 80 03 C0 02 40 06 60 0C 30 18 18 30 0C 60 06 00 00 00 00 7F FE 7F FE 01 00 01 00 01 C0 01 E0 01 38 01 0C 01 00 01 00 01 00 01 00 01 00 01 00 00 00 00 00 33 00 13 00 1B 00 7F FC 7F FC 02 04 02 04 02 84 06 C4 04 64 0C 24 18 0C 30 0C 60 78 00 00 00 00 04 20 0C 20 08 30 18 18 10 18 31 0C 63 06 43 02 06 20 04 30 0C 10 18 18 3F F8 18 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
|
||||
|
||||
// let arr1=('0x'+(str1.split(' ').join(",0x"))).split(',');
|
||||
// let arr2=('0x'+(str2.split(' ').join(",0x"))).split(',');
|
||||
// let arr3=('0x'+(str3.split(' ').join(",0x"))).split(',');
|
||||
|
||||
// result=[arr1,arr2,arr3];
|
||||
|
||||
console.log("result=",result);
|
||||
|
||||
let h3dic = [0x06, 0x07, 0x08];
|
||||
let pros = [];
|
||||
let flag = true;
|
||||
@ -1475,7 +1566,7 @@
|
||||
|
||||
let width = str.length * 16;
|
||||
var rgb = result[i];
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: '开始发送第' + (i + 1)
|
||||
});
|
||||
@ -1509,12 +1600,13 @@
|
||||
|
||||
// 发送数据通用方法
|
||||
sendData(buffer) {
|
||||
this.addLog("设备就绪,正在握手");
|
||||
console.log("设备就绪,正在握手");
|
||||
return new Promise((resolve, reject) => {
|
||||
this.addLog("握手成功,正在发送");
|
||||
this.addLog("设备id:" + this.connectedDeviceId);
|
||||
this.addLog("服务id:" + this.serviceId);
|
||||
this.addLog("特征id:" + this.writeCharacteristicId);
|
||||
console.log("握手成功,正在发送");
|
||||
console.log("设备id:" + this.connectedDeviceId);
|
||||
console.log("服务id:" + this.serviceId);
|
||||
console.log("特征id:" + this.writeCharacteristicId);
|
||||
let promise1=new Promise((succ,err)=>{
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: this.connectedDeviceId,
|
||||
serviceId: this.serviceId,
|
||||
@ -1522,28 +1614,50 @@
|
||||
writeType:plus.os.name=='Android'?'writeNoResponse':'write',
|
||||
value: buffer,
|
||||
success: () => {
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "发送数据成功"
|
||||
})
|
||||
resolve();
|
||||
succ();
|
||||
|
||||
},
|
||||
fail: (err) => {
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "发送数据失败" + JSON.stringify(err)
|
||||
})
|
||||
reject(err);
|
||||
err(err);
|
||||
},
|
||||
complete: () => {
|
||||
this.addLog({
|
||||
console.log({
|
||||
date: Common.DateFormat(),
|
||||
remark: "向设备写入数据完成"
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let promise2=new Promise((succ,err)=>{
|
||||
setTimeout(()=>{
|
||||
err({
|
||||
code: -1,
|
||||
errMsg: '超时了'
|
||||
});
|
||||
},50)
|
||||
})
|
||||
|
||||
Promise.race([promise1, promise2]).then(resolve).catch((ex) => {
|
||||
console.log("ex=", ex);
|
||||
if (ex.code == -1) {
|
||||
resolve(ex);
|
||||
} else {
|
||||
reject(ex);
|
||||
}
|
||||
|
||||
}).finally(() => {
|
||||
//console.log("完成了")
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// 添加日志
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -698,101 +698,224 @@
|
||||
uni.onBLECharacteristicValueChange((
|
||||
receive) => {
|
||||
|
||||
var bytesToHexString =function(bytes) {
|
||||
var bytesToHexString =
|
||||
function(bytes) {
|
||||
return bytes.map(
|
||||
byte =>byte.toString(16).padStart(2, '0')
|
||||
byte =>
|
||||
byte
|
||||
.toString(
|
||||
16)
|
||||
.padStart(
|
||||
2, '0')
|
||||
).join(' ')
|
||||
}
|
||||
|
||||
|
||||
var parseData = (bytes) => {
|
||||
if (bytes.length <7) {
|
||||
console.log('数据包长度不足,至少需要6个字节');
|
||||
var parseData = (
|
||||
bytes) => {
|
||||
if (bytes.length <
|
||||
7) {
|
||||
console.log(
|
||||
'数据包长度不足,至少需要6个字节'
|
||||
);
|
||||
return;
|
||||
}
|
||||
let date = new Date();
|
||||
this.receiveData.date =date.getHours() +":" + date.getMinutes() +":" + date.getSeconds();
|
||||
if(bytes[0]==0x55){
|
||||
let date =
|
||||
new Date();
|
||||
this.receiveData
|
||||
.date = date
|
||||
.getHours() +
|
||||
":" + date
|
||||
.getMinutes() +
|
||||
":" + date
|
||||
.getSeconds();
|
||||
if (bytes[0] ==
|
||||
0x55) {
|
||||
try {
|
||||
// 跳过帧头(第一个字节),从第二个字节开始解析
|
||||
let staticLevelByte = bytes[1];
|
||||
let staticLevelText = '未知';
|
||||
switch ( staticLevelByte ) {
|
||||
let staticLevelByte =
|
||||
bytes[
|
||||
1];
|
||||
let staticLevelText =
|
||||
'未知';
|
||||
switch (
|
||||
staticLevelByte
|
||||
) {
|
||||
case 0x65:
|
||||
staticLevelText = '高档';
|
||||
staticLevelText
|
||||
=
|
||||
'高档';
|
||||
break;
|
||||
case 0x66:
|
||||
staticLevelText = '中档';
|
||||
staticLevelText
|
||||
=
|
||||
'中档';
|
||||
break;
|
||||
case 0x67:
|
||||
staticLevelText = '低档';
|
||||
staticLevelText
|
||||
=
|
||||
'低档';
|
||||
break;
|
||||
case 0x68:
|
||||
staticLevelText = '关闭';
|
||||
staticLevelText
|
||||
=
|
||||
'关闭';
|
||||
break;
|
||||
}
|
||||
|
||||
// 解析照明档位
|
||||
let lightingLevelByte = bytes[2];
|
||||
let lightingLevelText = lightingLevelByte === 0x6e ? '开启':'关闭';
|
||||
let lightingLevelByte =
|
||||
bytes[
|
||||
2];
|
||||
let lightingLevelText =
|
||||
lightingLevelByte ===
|
||||
0x6e ?
|
||||
'开启' :
|
||||
'关闭';
|
||||
|
||||
// 解析剩余照明时间(第三和第四字节,小端序)
|
||||
let lightingTime =(bytes[3] <<8) | bytes[4];
|
||||
let lightingTime =
|
||||
(bytes[
|
||||
3] <<
|
||||
8
|
||||
) |
|
||||
bytes[
|
||||
4];
|
||||
|
||||
// 解析剩余电量
|
||||
let batteryLevelByte = bytes[5];
|
||||
let batteryLevelByte =
|
||||
bytes[
|
||||
5];
|
||||
// 电量百分比范围检查
|
||||
let batteryLevel = Math.max(0,Math.min(100, batteryLevelByte));
|
||||
let batteryLevel =
|
||||
Math
|
||||
.max(0,
|
||||
Math
|
||||
.min(
|
||||
100,
|
||||
batteryLevelByte
|
||||
)
|
||||
);
|
||||
|
||||
let warn=bytes[6];
|
||||
if(warn==0x00){
|
||||
warn='无预警';
|
||||
let warn =
|
||||
bytes[
|
||||
6];
|
||||
if (warn ==
|
||||
0x00) {
|
||||
warn =
|
||||
'无预警';
|
||||
} else if (
|
||||
warn ==
|
||||
0x01) {
|
||||
warn =
|
||||
'弱预警';
|
||||
} else if (
|
||||
warn ==
|
||||
0x02) {
|
||||
warn =
|
||||
'中预警';
|
||||
} else if (
|
||||
warn ==
|
||||
0x03) {
|
||||
warn =
|
||||
'强预警';
|
||||
} else if (
|
||||
warn ==
|
||||
0x04) {
|
||||
warn =
|
||||
'非常强预警';
|
||||
}
|
||||
else if(warn==0x01){
|
||||
warn='弱预警';
|
||||
}
|
||||
else if(warn==0x02){
|
||||
warn='中预警';
|
||||
}
|
||||
else if(warn==0x03){
|
||||
warn='强预警';
|
||||
}
|
||||
else if(warn==0x04){
|
||||
warn='非常强预警';
|
||||
}
|
||||
console.log(warn)
|
||||
console.log('解析结果:', {
|
||||
console
|
||||
.log(
|
||||
warn
|
||||
)
|
||||
console
|
||||
.log(
|
||||
'解析结果:', {
|
||||
staticLevel: staticLevelText,
|
||||
lightingLevel: lightingLevelText,
|
||||
lightingTime: `${lightingTime} 分钟`,
|
||||
batteryLevel: `${batteryLevel}%`
|
||||
});
|
||||
|
||||
this.receiveData.staticLevel =staticLevelText;
|
||||
this.receiveData.lightingLevel =lightingLevelText;
|
||||
this.receiveData.lightingTime =lightingTime +'分钟';
|
||||
this.receiveData.batteryLevel =batteryLevel +'%';
|
||||
this.receiveData.warnLevel=warn;
|
||||
} catch (error) {
|
||||
console.log('数据解析错误:',error);
|
||||
this.receiveData
|
||||
.staticLevel =
|
||||
staticLevelText;
|
||||
this.receiveData
|
||||
.lightingLevel =
|
||||
lightingLevelText;
|
||||
this.receiveData
|
||||
.lightingTime =
|
||||
lightingTime +
|
||||
'分钟';
|
||||
this.receiveData
|
||||
.batteryLevel =
|
||||
batteryLevel +
|
||||
'%';
|
||||
this.receiveData
|
||||
.warnLevel =
|
||||
warn;
|
||||
} catch (
|
||||
error) {
|
||||
console
|
||||
.log(
|
||||
'数据解析错误:',
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
else{
|
||||
try{
|
||||
let uint8Array = new Uint8Array(receive.value);
|
||||
let str = '';
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
} else {
|
||||
try {
|
||||
let uint8Array =
|
||||
new Uint8Array(
|
||||
receive
|
||||
.value
|
||||
);
|
||||
let str =
|
||||
'';
|
||||
for (let i =
|
||||
0; i <
|
||||
uint8Array
|
||||
.length; i++
|
||||
) {
|
||||
// 将每个字节转换为对应的字符
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
str +=
|
||||
String
|
||||
.fromCharCode(
|
||||
uint8Array[
|
||||
i
|
||||
]
|
||||
);
|
||||
}
|
||||
if(str.indexOf('mac address:')==0){
|
||||
this.receiveData.macAddress=str.split(':')[1];
|
||||
console.log("收到mac地址:",)
|
||||
}else{
|
||||
console.log("收到无法解析的字符串:",str)
|
||||
if (str
|
||||
.indexOf(
|
||||
'mac address:'
|
||||
) ==
|
||||
0) {
|
||||
this.receiveData
|
||||
.macAddress =
|
||||
str
|
||||
.split(
|
||||
':'
|
||||
)[
|
||||
1
|
||||
];
|
||||
console
|
||||
.log(
|
||||
"收到mac地址:",
|
||||
)
|
||||
} else {
|
||||
console
|
||||
.log(
|
||||
"收到无法解析的字符串:",
|
||||
str
|
||||
)
|
||||
}
|
||||
}catch(ex){
|
||||
console.log("将数据转文本失败",ex);
|
||||
} catch (ex) {
|
||||
console
|
||||
.log(
|
||||
"将数据转文本失败",
|
||||
ex
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1885,15 +2008,18 @@
|
||||
.txt {
|
||||
border: 1px solid #000000;
|
||||
}
|
||||
.w50{
|
||||
|
||||
.w50 {
|
||||
width: 50%;
|
||||
color: #656363;
|
||||
font-size: 26prx;
|
||||
}
|
||||
.fleft{
|
||||
|
||||
.fleft {
|
||||
float: left;
|
||||
}
|
||||
.clear{
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
}
|
||||
</style>
|
||||
@ -226,11 +226,10 @@
|
||||
<script>
|
||||
import gbk from '@/utils/gbk.js';
|
||||
import MqttClient from '@/utils/mqtt.js';
|
||||
import {
|
||||
request,
|
||||
import request,{
|
||||
baseURL
|
||||
} from '@/utils/request.js';
|
||||
var videoChannel=null;
|
||||
var videoChannel = null;
|
||||
var mqttClient = null;
|
||||
export default {
|
||||
data() {
|
||||
@ -303,7 +302,7 @@
|
||||
videoHeight: "",
|
||||
videoDuration: "",
|
||||
currentSOS: "",
|
||||
reSendNumber:null
|
||||
reSendNumber: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -678,46 +677,42 @@
|
||||
);
|
||||
} else {
|
||||
try {
|
||||
let json=JSON.parse(str);
|
||||
if("staBlue_picture" in json){
|
||||
let json = JSON.parse(str);
|
||||
if ("staBlue_picture" in json) {
|
||||
//重发图片
|
||||
console.log("收到重新发送图片的命令");
|
||||
this.reSendNumber=json.staBlue_picture;
|
||||
setTimeout(()=>{
|
||||
this.sendImagePackets(this.rgb565Data,json.staBlue_picture);
|
||||
},0);
|
||||
this.reSendNumber = json.staBlue_picture;
|
||||
setTimeout(() => {
|
||||
this.sendImagePackets(this.rgb565Data, json.staBlue_picture);
|
||||
}, 0);
|
||||
|
||||
|
||||
return ;
|
||||
}
|
||||
else if("staBlue_text" in json){
|
||||
return;
|
||||
} else if ("staBlue_text" in json) {
|
||||
//重发文本
|
||||
console.log("收到重新发送文本的命令");
|
||||
this.reSendNumber=json.staBlue_text;
|
||||
setTimeout(()=>{
|
||||
this.sendText(null,json.staBlue_text);
|
||||
},0)
|
||||
this.reSendNumber = json.staBlue_text;
|
||||
setTimeout(() => {
|
||||
this.sendText(null, json.staBlue_text);
|
||||
}, 0)
|
||||
|
||||
|
||||
return ;
|
||||
}
|
||||
else if("staBlue_vidio" in json){
|
||||
return;
|
||||
} else if ("staBlue_vidio" in json) {
|
||||
//重发视频
|
||||
console.log("收到重新发送视频的命令");
|
||||
|
||||
videoChannel.emit("ReSendVideo", {
|
||||
videoNo:json.staBlue_vidio
|
||||
videoNo: json.staBlue_vidio
|
||||
});
|
||||
|
||||
return ;
|
||||
}
|
||||
else if("staBlue" in json){
|
||||
if(json.staBlue=="finish"){
|
||||
return;
|
||||
} else if ("staBlue" in json) {
|
||||
if (json.staBlue == "finish") {
|
||||
console.log("收到设备回复,全部传输完成");
|
||||
}
|
||||
return ;
|
||||
}
|
||||
else{
|
||||
return;
|
||||
} else {
|
||||
console.log("无法解析该文本");
|
||||
}
|
||||
|
||||
@ -1471,11 +1466,10 @@
|
||||
events: {
|
||||
ImgCutOver: function(data) {
|
||||
console.log("111111");
|
||||
console.log("data=", data.length);
|
||||
console.log("data=", data);
|
||||
these.rgb565Data = these.convertToRGB565(
|
||||
data);
|
||||
console.log("rgb565=", these.rgb565Data
|
||||
.length);
|
||||
data.piexls);
|
||||
console.log("rgb565=", these.rgb565Data);
|
||||
},
|
||||
ImgCutOver_Path: function(data) {
|
||||
these.tempImagePath = data;
|
||||
@ -1627,7 +1621,7 @@
|
||||
this.currentPacket = ReSendNo;
|
||||
this.currentPacket = ReSendNo;
|
||||
totalPackets = ReSendNo;
|
||||
currentPacket=ReSendNo;
|
||||
currentPacket = ReSendNo;
|
||||
}
|
||||
// 发送单个数据包
|
||||
let sendNextPacket = () => {
|
||||
@ -1635,7 +1629,7 @@
|
||||
this.isSending = false;
|
||||
if (!ReSendNo) {
|
||||
this.bleSendComplete();
|
||||
}else{
|
||||
} else {
|
||||
// this.reSendNumber="";
|
||||
}
|
||||
resolve();
|
||||
@ -1743,9 +1737,9 @@
|
||||
});
|
||||
}
|
||||
|
||||
if(ReSendNo){
|
||||
if (ReSendNo) {
|
||||
sendNextPacket();
|
||||
}else{
|
||||
} else {
|
||||
HoldYouHand();
|
||||
}
|
||||
|
||||
@ -1877,7 +1871,7 @@
|
||||
console.log('文字发送完成');
|
||||
if (!ReSendNo) {
|
||||
this.bleSendComplete();
|
||||
}else{
|
||||
} else {
|
||||
// this.reSendNumber="";
|
||||
}
|
||||
|
||||
@ -2002,10 +1996,9 @@
|
||||
});
|
||||
});
|
||||
}
|
||||
if(!ReSendNo){
|
||||
if (!ReSendNo) {
|
||||
HoldYouHand();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
sendNextPacket();
|
||||
}
|
||||
|
||||
@ -2017,13 +2010,13 @@
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
dataView.setUint8(i, str.charCodeAt(i));
|
||||
}
|
||||
setTimeout(()=>{
|
||||
setTimeout(() => {
|
||||
this.sendData(buffer).then(() => {
|
||||
console.log("完成指令发送成功");
|
||||
}).catch(err => {
|
||||
console.log("完成指令发送失败");
|
||||
});
|
||||
},500)
|
||||
}, 500)
|
||||
|
||||
},
|
||||
// 将文字转换为GBK编码(使用第三方库或API)
|
||||
@ -2074,7 +2067,7 @@
|
||||
url: "/pages/BlueTooth/ModeSetting/VideoSend_670",
|
||||
success: (res) => {
|
||||
let channel = res.eventChannel;
|
||||
videoChannel=channel;
|
||||
videoChannel = channel;
|
||||
channel.emit("receiveDevice", {
|
||||
connectedDeviceId: this.connectedDeviceId,
|
||||
serviceId: this.serviceId,
|
||||
@ -2085,7 +2078,7 @@
|
||||
});
|
||||
},
|
||||
fail(ex) {
|
||||
console.log("出现异常,",ex);
|
||||
console.log("出现异常,", ex);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
<template>
|
||||
<view class="content">
|
||||
<canvas canvas-id="flashCanvas"
|
||||
style="width: 160px; height: 80px; z-index: 9999;position: fixed; top:-9999px;left:-9999px;"></canvas>
|
||||
|
||||
<f-video ref="compARef" :src="videoPath" :direction="-90" :autoplay="true" @shotVideoClick="shotVideoClick"
|
||||
:videoWidth="videoWidth" :videoHeight="videoHeight"></f-video>
|
||||
|
||||
|
||||
<view>
|
||||
重发包序号:{{reSendNumber}}
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>发送间隔</text>
|
||||
<input type="text" v-model="inteval" />
|
||||
</view>
|
||||
<view>
|
||||
<button @click="checkVideo">选择视频</button>
|
||||
<!-- <button @click="CutImg">发送</button> -->
|
||||
|
||||
<button @click="uploadVideo">发送</button>
|
||||
</view>
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Common from '@/utils/Common';
|
||||
import Common from '@/utils/Common';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@ -51,7 +51,7 @@ import Common from '@/utils/Common';
|
||||
videoWidth: 320,
|
||||
videoHeight: 160,
|
||||
videoDuration: 2,
|
||||
|
||||
reSendNumber:null,
|
||||
hexArray: []
|
||||
|
||||
}
|
||||
@ -64,7 +64,17 @@ import Common from '@/utils/Common';
|
||||
this.serviceId = data.serviceId;
|
||||
this.writeCharacteristicId = data.writeCharacteristicId;
|
||||
this.notifyCharacteristicId = data.notifyCharacteristicId;
|
||||
})
|
||||
});
|
||||
|
||||
eventChannel.on('ReSendVideo', (data) => {
|
||||
//重新发送某一包
|
||||
this.reSendNumber = data.videoNo;
|
||||
setTimeout(() => {
|
||||
this.shotVideoClick(this.hexArray, 'rgb565', data.videoNo);
|
||||
}, 0);
|
||||
|
||||
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
checkVideo: function() {
|
||||
@ -76,9 +86,12 @@ import Common from '@/utils/Common';
|
||||
success: (res) => {
|
||||
this.videoPath = res.tempFilePath;
|
||||
|
||||
|
||||
|
||||
|
||||
this.imgs = [];
|
||||
this.hexArray = [];
|
||||
this.$refs.compARef.base64 = [];
|
||||
|
||||
this.videoWidth = res.width;
|
||||
this.videoHeight = res.height;
|
||||
this.videoDuration = res.duration;
|
||||
@ -95,7 +108,7 @@ import Common from '@/utils/Common';
|
||||
return;
|
||||
|
||||
}
|
||||
if(!this.videoPath){
|
||||
if (!this.videoPath) {
|
||||
uni.showToast({
|
||||
title: "请选择视频",
|
||||
icon: 'fail'
|
||||
@ -108,11 +121,12 @@ import Common from '@/utils/Common';
|
||||
title: "上传中"
|
||||
});
|
||||
|
||||
let p2=new Promise((resolve,reject)=>{
|
||||
let p2 = new Promise((resolve, reject) => {
|
||||
let start = new Date();
|
||||
console.log("Common.baseURL="+Common.baseURL);
|
||||
console.log("Common.baseURL=" + Common.baseURL);
|
||||
uni.uploadFile({
|
||||
url:Common.baseURL+'video/upload',
|
||||
// url: Common.baseURL + 'video/upload',
|
||||
url:'http://192.168.110.56:8000/app/video/upload',
|
||||
filePath: this.videoPath,
|
||||
name: 'file',
|
||||
header: {
|
||||
@ -142,12 +156,12 @@ import Common from '@/utils/Common';
|
||||
});
|
||||
});
|
||||
|
||||
let p1=this.HoldYouHand();
|
||||
let p1 = this.HoldYouHand();
|
||||
|
||||
Promise.all([p2,p1]).then((arr)=>{
|
||||
Promise.all([p2, p1]).then((arr) => {
|
||||
|
||||
if(arr[1]===true){
|
||||
let res=arr[0];
|
||||
if (arr[1] === true) {
|
||||
let res = arr[0];
|
||||
res = JSON.parse(res.data);
|
||||
|
||||
if (res.data) {
|
||||
@ -167,18 +181,33 @@ import Common from '@/utils/Common';
|
||||
title: '错误'
|
||||
})
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
uni.showModal({
|
||||
content:"与设备握手失败了",
|
||||
title:"错误"
|
||||
content: "与设备握手失败了",
|
||||
title: "错误"
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
bleSendComplete() {
|
||||
var str = "transmit complete"; //握手的协议字符串
|
||||
let buffer = new ArrayBuffer(str.length);
|
||||
let dataView = new DataView(buffer);
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
dataView.setUint8(i, str.charCodeAt(i));
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.sendData(buffer).then(() => {
|
||||
console.log("完成指令发送成功");
|
||||
}).catch(err => {
|
||||
console.log("完成指令发送失败");
|
||||
});
|
||||
}, 3000)
|
||||
|
||||
shotVideoClick: function(array, type) {
|
||||
},
|
||||
shotVideoClick: function(array, type, ReSendNo) {
|
||||
//console.log("处理视频完成", array);
|
||||
//console.log("type=" + type)
|
||||
//console.log("array=", array);
|
||||
@ -197,12 +226,25 @@ import Common from '@/utils/Common';
|
||||
const totalPackets = 1536;
|
||||
this.totalPackets = totalPackets;
|
||||
let currentPacket = 1;
|
||||
if (ReSendNo) {
|
||||
console.log("11111");
|
||||
this.progress = ReSendNo - 1;
|
||||
this.currentPacket = ReSendNo - 1;
|
||||
console.log("22222");
|
||||
|
||||
this.totalPackets = ReSendNo;
|
||||
console.log("11111=",ReSendNo);
|
||||
}
|
||||
// 发送单个数据包
|
||||
const sendNextPacket = () => {
|
||||
////console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
|
||||
console.log("currentPacket="+currentPacket+",imageData.length="+imageData.length);
|
||||
if (currentPacket > totalPackets) {
|
||||
this.isSending = false;
|
||||
if (!ReSendNo) {
|
||||
this.bleSendComplete();
|
||||
} else {
|
||||
// this.reSendNumber="";
|
||||
}
|
||||
resolve();
|
||||
|
||||
return;
|
||||
@ -221,11 +263,11 @@ import Common from '@/utils/Common';
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
////console.log("111111");
|
||||
console.log("111111");
|
||||
const packetData = imageData.slice(startIndex, endIndex);
|
||||
|
||||
// 构建数据包
|
||||
////console.log("packetData.length"+packetData.length);
|
||||
console.log("packetData.length"+packetData.length);
|
||||
const bufferSize = 506; // 头部5字节 + 数据部分
|
||||
const buffer = new ArrayBuffer(bufferSize);
|
||||
const dataView = new DataView(buffer);
|
||||
@ -256,11 +298,16 @@ import Common from '@/utils/Common';
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 0);
|
||||
this.sendData(buffer).then(() => {
|
||||
if(ReSendNo){
|
||||
this.isSending = false;
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
// 更新进度
|
||||
this.currentPacket = currentPacket;
|
||||
this.progress = Math.round((currentPacket / totalPackets) *
|
||||
100);
|
||||
//console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
|
||||
console.log(`发送数据包完成 ${currentPacket}/${totalPackets}`);
|
||||
|
||||
// 发送下一个包(添加延迟避免蓝牙缓冲区溢出)
|
||||
currentPacket++;
|
||||
@ -294,12 +341,13 @@ import Common from '@/utils/Common';
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff-s) / 60;
|
||||
let m = (diff - s) / 60;
|
||||
console.log("发送完成,耗时:" + m + "分" + s + "秒");
|
||||
uni.showToast({
|
||||
title: "发送完成,耗时:" + m + "分" + s + "秒",
|
||||
icon: 'success'
|
||||
})
|
||||
uni.showModal({
|
||||
content:"发送完成,耗时:" + m + "分" + s + "秒",
|
||||
title:"提示"
|
||||
});
|
||||
|
||||
}).catch((ex1) => {
|
||||
//console.log("出现了异常", ex1)
|
||||
}).finally(() => {
|
||||
@ -313,11 +361,11 @@ import Common from '@/utils/Common';
|
||||
},
|
||||
HoldYouHand() {
|
||||
|
||||
var promise=new Promise((resolve,reject)=>{
|
||||
try{
|
||||
let start=new Date();
|
||||
var promise = new Promise((resolve, reject) => {
|
||||
try {
|
||||
let start = new Date();
|
||||
var str = "video transmit start"; //握手的协议字符串
|
||||
console.log("开始握手:"+str)
|
||||
console.log("开始握手:" + str)
|
||||
|
||||
// 1. 创建 ArrayBuffer 和 DataView
|
||||
const buffer = new ArrayBuffer(str.length);
|
||||
@ -330,14 +378,14 @@ import Common from '@/utils/Common';
|
||||
//console.log("111111");
|
||||
this.sendData(buffer).then(() => {
|
||||
// 开始发送第一个包
|
||||
setTimeout(()=>{
|
||||
setTimeout(() => {
|
||||
|
||||
let end = new Date();
|
||||
var diff = (end.getTime() - start.getTime()) / 1000;
|
||||
let s = diff % 60;
|
||||
let m = (diff - s) / 60;
|
||||
|
||||
console.log("握手成功并完成2200ms等待,耗时"+m+"分"+s+"秒");
|
||||
console.log("握手成功并完成2200ms等待,耗时" + m + "分" + s + "秒");
|
||||
|
||||
resolve(true);
|
||||
}, 2200);
|
||||
@ -346,7 +394,7 @@ import Common from '@/utils/Common';
|
||||
//console.log("握手没有成功");
|
||||
reject(err);
|
||||
});
|
||||
}catch(ex){
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
|
||||
@ -415,18 +463,8 @@ import Common from '@/utils/Common';
|
||||
promise.then(resolve).catch(reject);
|
||||
}
|
||||
});
|
||||
},
|
||||
CutImg: function() {
|
||||
if (this.imgs.length == 30) {
|
||||
this.shotVideoClick(this.imgs, 'img');
|
||||
return;
|
||||
}
|
||||
//console.log("开始处理视频")
|
||||
uni.showLoading({
|
||||
title: '开始处理'
|
||||
});
|
||||
this.$refs.compARef.shotVideoClick(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -469,4 +507,19 @@ import Common from '@/utils/Common';
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.splash-frame {
|
||||
height: 320rpx;
|
||||
width: 640rpx;
|
||||
border: 2rpx solid #409eff;
|
||||
border-radius: 8rpx;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.splash-frame image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
</style>
|
||||
@ -1,7 +1,5 @@
|
||||
<template>
|
||||
<view class="content">
|
||||
<canvas canvas-id="flashCanvas"
|
||||
style="width: 160px; height: 80px; z-index: 9999;position: fixed; top:-9999px;left:-9999px;"></canvas>
|
||||
|
||||
<view>
|
||||
<view>
|
||||
@ -287,6 +285,11 @@ var mqttClient=null;
|
||||
|
||||
let inteval = parseInt(this.inteval ? this.inteval : 0);
|
||||
this.sendData(buffer).then(() => {
|
||||
if(ReSendNo){
|
||||
this.isSending = false;
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
// 更新进度
|
||||
this.currentPacket = currentPacket;
|
||||
this.progress = Math.round((currentPacket / totalPackets) *
|
||||
@ -401,7 +404,7 @@ var mqttClient=null;
|
||||
}).catch(err => {
|
||||
console.log("完成指令发送失败");
|
||||
});
|
||||
},1500)
|
||||
},3000)
|
||||
|
||||
},
|
||||
sendData(buffer) {
|
||||
|
||||
@ -19,10 +19,10 @@
|
||||
name: '/pages/BlueTooth/ModeSetting/HBY650',
|
||||
url: 'HBY650'
|
||||
},
|
||||
{
|
||||
name: '/pages/BlueTooth/ModeSetting/HBY650_1',
|
||||
url: 'HBY650_V1'
|
||||
},
|
||||
// {
|
||||
// name: '/pages/BlueTooth/ModeSetting/HBY650_1',
|
||||
// url: 'HBY650_V1'
|
||||
// },
|
||||
|
||||
{
|
||||
name: '/pages/BlueTooth/ModeSetting/HBY6155',
|
||||
@ -36,7 +36,10 @@
|
||||
name: "/pages/BlueTooth/ModeSetting/HBY670V1",
|
||||
url: 'HBY670'
|
||||
},
|
||||
|
||||
{
|
||||
name: "/pages/BlueTooth/ModeSetting/4877",
|
||||
url: '4877'
|
||||
},
|
||||
{
|
||||
name: '/pages/MapTest/MapTest',
|
||||
url: '地图测试'
|
||||
|
||||
@ -12,14 +12,14 @@
|
||||
设备名:{{device.deviceName}}
|
||||
</view>
|
||||
<view class="deviceId">
|
||||
ID:{{device.deviceId}}
|
||||
设备Mac:{{device.macAddress}}
|
||||
</view>
|
||||
<view class="bound" v-bind:class="boundStatu">
|
||||
{{Statu.boundRemark}}
|
||||
</view>
|
||||
</view>
|
||||
<view class="btnLink" @click="Link()">
|
||||
连接
|
||||
绑定
|
||||
</view>
|
||||
|
||||
<global-loading ref="loading" />
|
||||
@ -35,11 +35,12 @@
|
||||
updateLoading
|
||||
} from '@/utils/loading.js';
|
||||
|
||||
const pagePath="pages/common/addBLE/LinkBle";
|
||||
const pagePath = "pages/common/addBLE/LinkBle";
|
||||
|
||||
var these = null;
|
||||
var eventChannel = null;
|
||||
var ble = null;
|
||||
var timeInteval = null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -57,7 +58,8 @@
|
||||
],
|
||||
"linkStatu": false,
|
||||
"macAddress": ""
|
||||
}
|
||||
},
|
||||
serverDevice:null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -84,32 +86,33 @@
|
||||
onLoad(option) {
|
||||
these = this;
|
||||
ble = bleTool.getBleTool();
|
||||
ble.addReceiveCallback((receive,f,path) => {
|
||||
console.log("LinkBle")
|
||||
ble.addReceiveCallback((receive, f, path) => {
|
||||
console.log("收到设备消息,", receive);
|
||||
if (these.device.deviceId == receive.deviceId) {
|
||||
// console.log("11111");
|
||||
console.log("11111:",receive);
|
||||
|
||||
if (receive.bytes[0] == 0xFC || receive.str.indexOf('mac address:') == 0) {
|
||||
if (f && f.macAddress) {
|
||||
these.device.macAddress = f.macAddress;
|
||||
// console.log("222222");
|
||||
console.log("222222");
|
||||
these.initDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
},pagePath);
|
||||
}, pagePath);
|
||||
eventChannel = this.getOpenerEventChannel();
|
||||
eventChannel.on('LinkItem', function(data) {
|
||||
console.log("data=",data);
|
||||
console.log("data=", data);
|
||||
let f = ble.data.LinkedList.find((v) => {
|
||||
return v.deviceId == data.deviceId;
|
||||
});
|
||||
if (f) {
|
||||
let keys=Object.keys(f);
|
||||
keys.forEach((v,index)=>{
|
||||
these.device[v]=f[v];
|
||||
let keys = Object.keys(f);
|
||||
keys.forEach((v, index) => {
|
||||
these.device[v] = f[v];
|
||||
})
|
||||
console.log("LinkedList=",ble.data.LinkedList)
|
||||
console.log("LinkedList=", ble.data.LinkedList)
|
||||
console.log("f=", f);
|
||||
console.log("获取到设备", these.device);
|
||||
if (f.macAddress) {
|
||||
@ -121,14 +124,19 @@
|
||||
console.log("未获取到设备");
|
||||
}
|
||||
})
|
||||
|
||||
// let inteval = setInterval(this.initDevice, 5000);
|
||||
},
|
||||
methods: {
|
||||
|
||||
initDevice: function() {
|
||||
clearTimeout(timeInteval);
|
||||
|
||||
timeInteval = setTimeout(() => {
|
||||
showLoading(these, {
|
||||
text: '正在获取设备信息'
|
||||
});
|
||||
console.log("these.device=",these.device);
|
||||
console.log("these.device=", these.device);
|
||||
request({
|
||||
url: '/app/device/getDeviceInfoByDeviceMac',
|
||||
method: 'GET',
|
||||
@ -139,13 +147,17 @@
|
||||
console.log("获取设备信息", res);
|
||||
if (res && res.code == 200) {
|
||||
let data = res.data;
|
||||
this.serverDevice=data;
|
||||
if (data) {
|
||||
let keys = Object.keys(data);
|
||||
ble.data.LinkedList.find((v) => {
|
||||
if(v.deviceId == these.device.deviceId){
|
||||
if (v.deviceId == these.device.deviceId) {
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
v[key] = data[key];
|
||||
// if(!v.device){
|
||||
// v.device={};
|
||||
// }
|
||||
// v.device[key] = data[key];
|
||||
// console.log("key="+key);
|
||||
// console.log("value="+data[key]);
|
||||
|
||||
@ -154,12 +166,12 @@
|
||||
|
||||
}
|
||||
|
||||
ble.setBleData();
|
||||
// ble.setBleData();
|
||||
}
|
||||
});
|
||||
|
||||
console.log("device=",these.device);
|
||||
console.log("LinkedList=",ble.data.LinkedList);
|
||||
console.log("device=", these.device);
|
||||
console.log("LinkedList=", ble.data.LinkedList);
|
||||
|
||||
|
||||
}
|
||||
@ -170,6 +182,9 @@
|
||||
}).finally(() => {
|
||||
hideLoading(these);
|
||||
});
|
||||
|
||||
}, 500);
|
||||
|
||||
},
|
||||
Link() {
|
||||
// 调用绑定设备接口
|
||||
@ -207,6 +222,22 @@
|
||||
if (res.code == 200) {
|
||||
these.Statu.bound = true;
|
||||
these.Statu.boundRemark = "设备绑定成功!";
|
||||
let data=these.serverDevice;
|
||||
let keys = Object.keys(data);
|
||||
ble.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == these.device.deviceId) {
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
if(!v.device){
|
||||
v.device={};
|
||||
}
|
||||
v.device[key] = data[key];
|
||||
}
|
||||
|
||||
ble.updateCache();
|
||||
}
|
||||
});
|
||||
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
|
||||
uni.$emit("refreshDeviceList");
|
||||
@ -222,6 +253,7 @@
|
||||
}).catch((ex) => {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = '出现了未知的异常,操作失败';
|
||||
console.log("ex=",ex);
|
||||
}).finally(() => {
|
||||
hideLoading(this);
|
||||
});
|
||||
|
||||
@ -97,6 +97,7 @@
|
||||
const pagePath="pages/common/addBLE/addEquip";
|
||||
var ble = null;
|
||||
var these = null;
|
||||
var eventChannel=null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -128,7 +129,11 @@
|
||||
|
||||
},
|
||||
PairEquip: [], //已配对设备
|
||||
EquipMents: [] //搜索出来的设备
|
||||
EquipMents: [], //搜索出来的设备
|
||||
device:null,
|
||||
item:{
|
||||
deviceId:''
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -145,7 +150,8 @@
|
||||
},
|
||||
onUnload(){
|
||||
ble.StopSearch();
|
||||
|
||||
ble.removeDeviceFound(pagePath);
|
||||
ble.removeReceiveCallback(pagePath);
|
||||
},
|
||||
onLoad() {
|
||||
these = this;
|
||||
@ -170,13 +176,23 @@
|
||||
|
||||
}
|
||||
}
|
||||
},pagePath);
|
||||
// ble.addReceiveCallback((receivData) => {
|
||||
}, pagePath);
|
||||
// console.log("addEquip")
|
||||
// ble.addReceiveCallback((receivData,f,path,arr) => {
|
||||
// console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
|
||||
// if (this.item.deviceId == receivData.deviceId) {
|
||||
// console.log("11111:",receivData);
|
||||
|
||||
// // let data=uni.getStorageSync(ble.StorageKey);
|
||||
// console.log("LinkedList=",ble.data.LinkedList);
|
||||
// },pagePath);
|
||||
|
||||
// }
|
||||
|
||||
// });
|
||||
eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
eventChannel.on('detailData', function(rec) {
|
||||
console.log("接收到父页面的参数:",rec);
|
||||
these.device=rec.data;
|
||||
});
|
||||
},
|
||||
|
||||
onShow: function() {
|
||||
@ -223,7 +239,7 @@
|
||||
ble.showBlueSetting(false);
|
||||
},
|
||||
Link: function(item, index) {
|
||||
|
||||
this.item.deviceId=item.deviceId;
|
||||
showLoading(this,{
|
||||
text: "正在连接"
|
||||
});
|
||||
@ -241,6 +257,18 @@
|
||||
these.PairEquip.push(item);
|
||||
}
|
||||
console.log("连接成功");
|
||||
if(these.device){//从设备详情过来的,回设备详情去
|
||||
ble.data.LinkedList.find(v=>{
|
||||
if(v.deviceId==item.deviceId){
|
||||
v.device=these.device;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
ble.updateCache();
|
||||
uni.navigateBack();
|
||||
return;
|
||||
}
|
||||
uni.navigateTo({
|
||||
url:"/pages/common/addBLE/LinkBle",
|
||||
events:{
|
||||
|
||||
@ -144,6 +144,8 @@
|
||||
deviceUnbind, //删除设备
|
||||
deviceReName
|
||||
} from '@/api/common/index.js'
|
||||
import BleHelper from '@/utils/BleHelper.js';
|
||||
var ble=null;
|
||||
export default {
|
||||
onPullDownRefresh() {
|
||||
// 执行下拉刷新时的操作,比如重新获取数据
|
||||
@ -389,6 +391,8 @@
|
||||
this.deleteShow = false
|
||||
// 关闭所有滑动项
|
||||
this.$refs.swipeAction.closeAll();
|
||||
|
||||
ble && ble.DropDevice(data.id);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
@ -555,6 +559,7 @@
|
||||
console.log('列表收到消息了么');
|
||||
this.onIntall()
|
||||
});
|
||||
ble=BleHelper.getBleTool();
|
||||
},
|
||||
beforeDestroy() {
|
||||
// 组件销毁前移除监听器
|
||||
|
||||
BIN
static/fonts/PingFangBold.ttf
Normal file
BIN
static/fonts/PingFangBold.ttf
Normal file
Binary file not shown.
@ -1,8 +1,8 @@
|
||||
|
||||
var isReady=false;var onReadyCallbacks=[];
|
||||
var isServiceReady=false;var onServiceReadyCallbacks=[];
|
||||
var __uniConfig = {"pages":["pages/common/login/index","pages/common/index/index","pages/common/user/index","pages/common/scan/scan","pages/common/qrcode/qrcode","pages/common/send/index","pages/common/userAgreement/index","pages/common/privacyAgreement/index","pages/common/aboutUs/index","pages/6170/deviceControl/index","pages/6170/callPolice/index","pages/210/deviceControl/index","pages/common/operationVideo/index","pages/common/addvideo/index","pages/common/operatingInstruct/index","pages/common/productDes/index","pages/common/addBLE/addEquip","pages/common/addBLE/LinkBle","pages/6155/deviceDetail","pages/6155/ImgCrop","pages/common/map/index","pages/common/allType/index","pages/6170/allShare/index","pages/6170/share/index","pages/6170/shareDevices/index","pages/6170/shareManagement/index","pages/210/onlineDevice/index","pages/210/addDevice/index","pages/210/historyRecords/index","pages/210/call/index"],"window":{"navigationBarTextStyle":"white","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#121212","backgroundColor":"#121212"},"tabBar":{"color":"#fff","selectedColor":"#BBE600","backgroundColor":"#202020","list":[{"pagePath":"pages/common/index/index","text":"我的设备","iconPath":"/static/tabs/device.png","selectedIconPath":"/static/tabs/device-HL.png"},{"pagePath":"pages/common/user/index","text":"我的","iconPath":"/static/tabs/my.png","selectedIconPath":"/static/tabs/my-HL.png"}]},"darkmode":false,"nvueCompiler":"uni-app","nvueStyleCompiler":"uni-app","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"JingQuan","compilerVersion":"4.66","entryPagePath":"pages/common/login/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
|
||||
var __uniRoutes = [{"path":"/pages/common/login/index","meta":{"isQuit":true},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/index/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationStyle":"custom","enablePullDownRefresh":true}},{"path":"/pages/common/user/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationBarTitleText":"我的"}},{"path":"/pages/common/scan/scan","meta":{},"window":{"navigationBarTitleText":"扫描"}},{"path":"/pages/common/qrcode/qrcode","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/common/send/index","meta":{},"window":{"navigationBarTitleText":"发送信息"}},{"path":"/pages/common/userAgreement/index","meta":{},"window":{"navigationBarTitleText":"用户协议"}},{"path":"/pages/common/privacyAgreement/index","meta":{},"window":{"navigationBarTitleText":"隐私协议"}},{"path":"/pages/common/aboutUs/index","meta":{},"window":{"navigationBarTitleText":"关于我们"}},{"path":"/pages/6170/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/6170/callPolice/index","meta":{},"window":{"navigationBarTitleText":"报警"}},{"path":"/pages/210/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operationVideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addvideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operatingInstruct/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/productDes/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addBLE/addEquip","meta":{},"window":{"navigationBarTitleText":"添加设备"}},{"path":"/pages/common/addBLE/LinkBle","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/6155/deviceDetail","meta":{},"window":{"navigationBarTitleText":"HBY 6155"}},{"path":"/pages/6155/ImgCrop","meta":{},"window":{"navigationBarTitleText":"图像裁剪","navigationStyle":"custom","fullscreen":true}},{"path":"/pages/common/map/index","meta":{},"window":{"navigationBarTitleText":"地图"}},{"path":"/pages/common/allType/index","meta":{},"window":{"navigationBarTitleText":"所有类型"}},{"path":"/pages/6170/allShare/index","meta":{},"window":{"navigationBarTitleText":"所有分享"}},{"path":"/pages/6170/share/index","meta":{},"window":{"navigationBarTitleText":"分享"}},{"path":"/pages/6170/shareDevices/index","meta":{},"window":{"navigationBarTitleText":"分享设备"}},{"path":"/pages/6170/shareManagement/index","meta":{},"window":{"navigationBarTitleText":"分享管理"}},{"path":"/pages/210/onlineDevice/index","meta":{},"window":{"navigationBarTitleText":"联机设备"}},{"path":"/pages/210/addDevice/index","meta":{},"window":{"navigationBarTitleText":"添加联机设备"}},{"path":"/pages/210/historyRecords/index","meta":{},"window":{"navigationBarTitleText":"历史记录"}},{"path":"/pages/210/call/index","meta":{},"window":{"navigationBarTitleText":"呼叫"}}];
|
||||
var __uniConfig = {"pages":["pages/common/login/index","pages/common/index/index","pages/common/user/index","pages/common/scan/scan","pages/common/qrcode/qrcode","pages/common/send/index","pages/common/userAgreement/index","pages/common/privacyAgreement/index","pages/common/aboutUs/index","pages/6170/deviceControl/index","pages/6170/callPolice/index","pages/210/deviceControl/index","pages/common/operationVideo/index","pages/common/addvideo/index","pages/common/operatingInstruct/index","pages/common/productDes/index","pages/common/addBLE/addEquip","pages/common/addBLE/LinkBle","pages/6155/deviceDetail","pages/6155/ImgCrop","pages/common/map/index","pages/common/allType/index","pages/6170/allShare/index","pages/6170/share/index","pages/6170/shareDevices/index","pages/6170/shareManagement/index","pages/210/onlineDevice/index","pages/210/addDevice/index","pages/210/historyRecords/index","pages/210/call/index","pages/BlueTooth/ModeSetting/index","pages/BlueTooth/ModeSetting/VideoSend","pages/BlueTooth/ModeSetting/VideoSend_1","pages/BlueTooth/ModeSetting/VideoSend_670","pages/BlueTooth/ModeSetting/HBY650","pages/BlueTooth/ModeSetting/HBY650_1","pages/BlueTooth/ModeSetting/ModeSetting","pages/BlueTooth/ModeSetting/update","pages/BlueTooth/ModeSetting/HBY6155","pages/BlueTooth/ModeSetting/HBY6155V1","pages/BlueTooth/ModeSetting/HBY670V1","pages/670/HBY670","pages/650/HBY650","pages/670/History","pages/BlueTooth/ModeSetting/4877","pages/7305/BJQ7305"],"window":{"navigationBarTextStyle":"white","navigationBarTitleText":"uni-app","navigationBarBackgroundColor":"#121212","backgroundColor":"#121212"},"tabBar":{"color":"#fff","selectedColor":"#BBE600","backgroundColor":"#202020","list":[{"pagePath":"pages/common/index/index","text":"我的设备","iconPath":"/static/tabs/device.png","selectedIconPath":"/static/tabs/device-HL.png"},{"pagePath":"pages/common/user/index","text":"我的","iconPath":"/static/tabs/my.png","selectedIconPath":"/static/tabs/my-HL.png"}]},"darkmode":false,"nvueCompiler":"uni-app","nvueStyleCompiler":"uni-app","renderer":"auto","splashscreen":{"alwaysShowBeforeRender":true,"autoclose":false},"appname":"星汉物联","compilerVersion":"4.75","entryPagePath":"pages/common/login/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
|
||||
var __uniRoutes = [{"path":"/pages/common/login/index","meta":{"isQuit":true},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/index/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationStyle":"custom","enablePullDownRefresh":true}},{"path":"/pages/common/user/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationBarTitleText":"我的"}},{"path":"/pages/common/scan/scan","meta":{},"window":{"navigationBarTitleText":"扫描"}},{"path":"/pages/common/qrcode/qrcode","meta":{},"window":{"navigationBarTitleText":"扫描到的设备"}},{"path":"/pages/common/send/index","meta":{},"window":{"navigationBarTitleText":"发送信息","enablePullDownRefresh":true}},{"path":"/pages/common/userAgreement/index","meta":{},"window":{"navigationBarTitleText":"用户协议"}},{"path":"/pages/common/privacyAgreement/index","meta":{},"window":{"navigationBarTitleText":"隐私协议"}},{"path":"/pages/common/aboutUs/index","meta":{},"window":{"navigationBarTitleText":"关于我们"}},{"path":"/pages/6170/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/6170/callPolice/index","meta":{},"window":{"navigationBarTitleText":"报警","enablePullDownRefresh":true}},{"path":"/pages/210/deviceControl/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operationVideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addvideo/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/operatingInstruct/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/productDes/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/addBLE/addEquip","meta":{},"window":{"navigationBarTitleText":"扫描设备"}},{"path":"/pages/common/addBLE/LinkBle","meta":{},"window":{"navigationBarTitleText":"绑定设备"}},{"path":"/pages/6155/deviceDetail","meta":{},"window":{"navigationBarTitleText":"HBY 6155"}},{"path":"/pages/6155/ImgCrop","meta":{},"window":{"navigationBarTitleText":"图像裁剪","navigationStyle":"custom","fullscreen":true}},{"path":"/pages/common/map/index","meta":{},"window":{"navigationBarTitleText":"地图"}},{"path":"/pages/common/allType/index","meta":{},"window":{"navigationBarTitleText":"所有类型"}},{"path":"/pages/6170/allShare/index","meta":{},"window":{"navigationBarTitleText":"所有分享"}},{"path":"/pages/6170/share/index","meta":{},"window":{"navigationBarTitleText":"分享"}},{"path":"/pages/6170/shareDevices/index","meta":{},"window":{"navigationBarTitleText":"分享设备"}},{"path":"/pages/6170/shareManagement/index","meta":{},"window":{"navigationBarTitleText":"分享管理"}},{"path":"/pages/210/onlineDevice/index","meta":{},"window":{"navigationBarTitleText":"联机设备"}},{"path":"/pages/210/addDevice/index","meta":{},"window":{"navigationBarTitleText":"添加联机设备"}},{"path":"/pages/210/historyRecords/index","meta":{},"window":{"navigationBarTitleText":"历史记录"}},{"path":"/pages/210/call/index","meta":{},"window":{"navigationBarTitleText":"呼叫"}},{"path":"/pages/BlueTooth/ModeSetting/index","meta":{},"window":{"navigationBarTitleText":"设备类型"}},{"path":"/pages/BlueTooth/ModeSetting/VideoSend","meta":{},"window":{"navigationBarTitleText":"发送视频"}},{"path":"/pages/BlueTooth/ModeSetting/VideoSend_1","meta":{},"window":{"navigationBarTitleText":"发送视频"}},{"path":"/pages/BlueTooth/ModeSetting/VideoSend_670","meta":{},"window":{"navigationBarTitleText":"发送视频"}},{"path":"/pages/BlueTooth/ModeSetting/HBY650","meta":{},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/BlueTooth/ModeSetting/HBY650_1","meta":{},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/BlueTooth/ModeSetting/ModeSetting","meta":{},"window":{"navigationBarTitleText":"7307-0.96TFT"}},{"path":"/pages/BlueTooth/ModeSetting/update","meta":{},"window":{"navigationBarTitleText":"版本更新"}},{"path":"/pages/BlueTooth/ModeSetting/HBY6155","meta":{},"window":{"navigationBarTitleText":"HBY6155"}},{"path":"/pages/BlueTooth/ModeSetting/HBY6155V1","meta":{},"window":{"navigationBarTitleText":"HBY6155_V1"}},{"path":"/pages/BlueTooth/ModeSetting/HBY670V1","meta":{},"window":{"navigationBarTitleText":"HBY670"}},{"path":"/pages/670/HBY670","meta":{},"window":{"navigationBarTitleText":"HBY670","navigationStyle":"custom"}},{"path":"/pages/650/HBY650","meta":{},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/670/History","meta":{},"window":{"navigationBarTitleText":"历史记录"}},{"path":"/pages/BlueTooth/ModeSetting/4877","meta":{},"window":{"navigationBarTitleText":""}},{"path":"/pages/7305/BJQ7305","meta":{},"window":{"navigationBarTitleText":"BJQ7305"}}];
|
||||
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
||||
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
||||
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,global:void 0,window:void 0,document:void 0,frames:void 0,self:void 0,location:void 0,navigator:void 0,localStorage:void 0,history:void 0,Caches:void 0,screen:void 0,alert:void 0,confirm:void 0,prompt:void 0,fetch:void 0,XMLHttpRequest:void 0,WebSocket:void 0,webkit:void 0,print:void 0}}}});
|
||||
|
||||
16183
unpackage/dist/dev/app-plus/app-service.js
vendored
16183
unpackage/dist/dev/app-plus/app-service.js
vendored
File diff suppressed because one or more lines are too long
17567
unpackage/dist/dev/app-plus/app-view.js
vendored
17567
unpackage/dist/dev/app-plus/app-view.js
vendored
File diff suppressed because one or more lines are too long
2
unpackage/dist/dev/app-plus/manifest.json
vendored
2
unpackage/dist/dev/app-plus/manifest.json
vendored
File diff suppressed because one or more lines are too long
2
unpackage/dist/dev/app-plus/view.css
vendored
2
unpackage/dist/dev/app-plus/view.css
vendored
File diff suppressed because one or more lines are too long
4
unpackage/dist/dev/app-plus/view.umd.min.js
vendored
4
unpackage/dist/dev/app-plus/view.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -40,9 +40,9 @@ class BleHelper {
|
||||
onDeviceFound: [], //发现新设备的事件
|
||||
receivDataCallback: [] //接收到数据的事件
|
||||
}
|
||||
this.addReceiveCallback((a,b,c)=>{
|
||||
recei.ReceiveData(a,b,c);
|
||||
}, "BleReceiveData");
|
||||
// this.addReceiveCallback((a, b, c) => {
|
||||
// recei.ReceiveData(a, b, c);
|
||||
// }, "BleReceiveData");
|
||||
this.dic = {
|
||||
errRemarks: [{
|
||||
key: '10000',
|
||||
@ -104,16 +104,49 @@ class BleHelper {
|
||||
}
|
||||
}
|
||||
|
||||
DropDevice(bleId, deviceId) {
|
||||
let flag = false;
|
||||
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
||||
let item = this.data.LinkedList[i];
|
||||
if (bleId) {
|
||||
if (item.deviceId == bleId) {
|
||||
this.data.LinkedList.splice(i, 1);
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (item.device && item.device.id) {
|
||||
this.data.LinkedList.splice(i, 1);
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
this.updateCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
updateCache() {
|
||||
console.log("this.StorageKey=", this.StorageKey)
|
||||
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
||||
}
|
||||
|
||||
linkAllDevices() {
|
||||
// console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
||||
console.log("模块启动时,自动连接已连接过的设备", this.data.LinkedList);
|
||||
|
||||
if (this.data.LinkedList && this.data.LinkedList.length > 0) {
|
||||
for (var i = 0; i < this.data.LinkedList.length; i++) {
|
||||
let device = this.data.LinkedList[i];
|
||||
// console.log("自动连接:" + device.deviceId);
|
||||
// console.log("自动连接绑定过的设备:" + device.deviceId);
|
||||
if (device.macAddress && device.device && device.device.id) {
|
||||
this.LinkBlue(device.deviceId, device.writeServiceId, device.wirteCharactId, device
|
||||
.notifyCharactId);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
// console.log("无设备连接");
|
||||
}
|
||||
@ -159,7 +192,7 @@ class BleHelper {
|
||||
let key = currKey ? currKey : this.getCurrentPagePath();
|
||||
|
||||
if (key) {
|
||||
console.log("key=" + key);
|
||||
// console.log("key=" + key);
|
||||
let f = this.cfg.onDeviceFound.findIndex((v) => {
|
||||
return v.key == key;
|
||||
});
|
||||
@ -202,7 +235,7 @@ class BleHelper {
|
||||
removeReceiveCallback(currKey) {
|
||||
let key = currKey ? currKey : this.getCurrentPagePath();
|
||||
if (key) {
|
||||
console.log("移除消息回调:" + key);
|
||||
// console.log("移除消息回调:" + key);
|
||||
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
||||
return v.key == key;
|
||||
});
|
||||
@ -335,8 +368,8 @@ class BleHelper {
|
||||
}
|
||||
uni.getBluetoothAdapterState({
|
||||
success: (info) => {
|
||||
this.data.available=info.available;
|
||||
this.data.discovering=info.discovering;
|
||||
this.data.available = info.available;
|
||||
this.data.discovering = info.discovering;
|
||||
resolve(info);
|
||||
},
|
||||
fail: (ex1) => {
|
||||
@ -365,7 +398,7 @@ class BleHelper {
|
||||
success: (args) => {
|
||||
// console.log("蓝牙初始化成功:" + JSON.stringify(args));
|
||||
this.data.isOpenBlue = true;
|
||||
this.data.available=true;
|
||||
this.data.available = true;
|
||||
resolve(true);
|
||||
|
||||
if (this.data.isSubscribe) { //整个App生命周期,只订阅一次
|
||||
@ -386,7 +419,7 @@ class BleHelper {
|
||||
this.data.discovering = state.discovering;
|
||||
if (this.data.available && this.data
|
||||
.isOpenBlue) { //蓝牙状态再次可用,重连所有设备
|
||||
|
||||
this.linkAllDevices();
|
||||
|
||||
}
|
||||
|
||||
@ -396,8 +429,8 @@ class BleHelper {
|
||||
v.notifyState = false;
|
||||
return true;
|
||||
});
|
||||
uni.setStorageSync(this.StorageKey, this.data
|
||||
.LinkedList);
|
||||
|
||||
this.updateCache();
|
||||
}
|
||||
});
|
||||
|
||||
@ -414,8 +447,7 @@ class BleHelper {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
uni.setStorageSync(this.StorageKey, this.data
|
||||
.LinkedList);
|
||||
this.updateCache();
|
||||
} else {
|
||||
// console.log("蓝牙连接已恢复,", res);
|
||||
}
|
||||
@ -437,8 +469,8 @@ class BleHelper {
|
||||
|
||||
uni.onBLECharacteristicValueChange((receive) => {
|
||||
//订阅消息
|
||||
// console.log("收到订阅消息",receive);
|
||||
let f=this.data.LinkedList.find((v) => {
|
||||
console.log("收到订阅消息", receive);
|
||||
let f = this.data.LinkedList.find((v) => {
|
||||
return v.deviceId == receive.deviceId;
|
||||
})
|
||||
let dataView = new DataView(receive.value);
|
||||
@ -458,24 +490,35 @@ class BleHelper {
|
||||
// 将每个字节转换为对应的字符
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
}
|
||||
|
||||
let header = "mac address:";
|
||||
if (str.indexOf(header) == 0) { //650以文本传输mac
|
||||
|
||||
console.log("str=", str);
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == receive
|
||||
.deviceId) {
|
||||
v.macAddress = str.replace(
|
||||
let macStr = str.replace(
|
||||
header, "");
|
||||
// console.log("收到mac地址:", str)
|
||||
if (macStr.includes(':')) {
|
||||
v.macAddress = macStr;
|
||||
} else {
|
||||
v.macAddress = macStr
|
||||
.replace(
|
||||
/(.{2})/g, '$1:')
|
||||
.slice(0, -1)
|
||||
}
|
||||
str = header + v.macAddress;
|
||||
console.log("收到mac地址:", v
|
||||
.macAddress)
|
||||
}
|
||||
});
|
||||
uni.setStorageSync(this.StorageKey, this.data
|
||||
.LinkedList);
|
||||
this.updateCache();
|
||||
}
|
||||
|
||||
if (bytes[0] == 0xFC) { //6155以0xFC开头代表mac地址
|
||||
// console.log("收到mac地址:", bytes)
|
||||
console.log("收到mac地址:", bytes)
|
||||
if (bytes.length >= 7) {
|
||||
console.log("hexs=", hexs);
|
||||
let mac = hexs.slice(1, 7).join(":")
|
||||
.toUpperCase();
|
||||
this.data.LinkedList.find((v) => {
|
||||
@ -485,12 +528,12 @@ class BleHelper {
|
||||
// console.log("收到mac地址:", str)
|
||||
}
|
||||
});
|
||||
uni.setStorageSync(this.StorageKey, this
|
||||
.data.LinkedList);
|
||||
this.updateCache();
|
||||
}
|
||||
}
|
||||
console.log("str=", str);
|
||||
} catch (ex) {
|
||||
////console.log("将数据转文本失败", ex);
|
||||
console.log("将数据转文本失败", ex);
|
||||
}
|
||||
let recData = {
|
||||
deviceId: receive.deviceId,
|
||||
@ -501,22 +544,37 @@ class BleHelper {
|
||||
hexs: hexs
|
||||
};
|
||||
// console.log("监听到特征值:" + JSON.stringify(recData));
|
||||
try {
|
||||
if (this.cfg.receivDataCallback) {
|
||||
|
||||
if (this.cfg.receivDataCallback.length > 0) {
|
||||
|
||||
let path = this.getCurrentPagePath();
|
||||
|
||||
this.cfg.receivDataCallback.forEach((rec) => {
|
||||
|
||||
console.log("有人订阅消息")
|
||||
this.cfg.receivDataCallback.forEach((
|
||||
rec) => {
|
||||
console.log("有人订阅消息111",)
|
||||
if (rec.callback) {
|
||||
rec.callback(recData, f, path);
|
||||
try{
|
||||
rec.callback(recData, f,
|
||||
path, this.cfg
|
||||
.receivDataCallback);
|
||||
}catch(err){
|
||||
console.log("订阅消息出现异常",err);
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
} else {
|
||||
console.log("无人订阅消息");
|
||||
}
|
||||
} else {
|
||||
console.log("无人订阅receivDataCallback,不处理数据");
|
||||
}
|
||||
} catch (ex) {
|
||||
console.log("ex=", ex);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -586,7 +644,7 @@ class BleHelper {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.startBluetoothDevicesDiscovery({
|
||||
services: [],
|
||||
allowDuplicatesKey: true,
|
||||
allowDuplicatesKey: false,
|
||||
success: (res) => {
|
||||
//console.log('开始搜索蓝牙设备成功');
|
||||
resolve(res);
|
||||
@ -667,10 +725,12 @@ class BleHelper {
|
||||
return;
|
||||
}
|
||||
}
|
||||
console.log("c=", c);
|
||||
// console.log("c=", c);
|
||||
let startSubScribe = (id, serviceId, characteristicId) => {
|
||||
// console.log("serviceId=", serviceId);
|
||||
// console.log("characteristicId=", characteristicId);
|
||||
let p1 = new Promise((succ, err) => {
|
||||
|
||||
return new Promise((succ, err) => {
|
||||
uni.notifyBLECharacteristicValueChange({
|
||||
deviceId: id,
|
||||
serviceId: serviceId,
|
||||
@ -678,7 +738,7 @@ class BleHelper {
|
||||
state: state,
|
||||
success: (res) => {
|
||||
if (state) {
|
||||
// console.log("订阅消息成功", res);
|
||||
console.log("订阅消息成功", res);
|
||||
} else {
|
||||
console.log("取消订阅成功", res);
|
||||
}
|
||||
@ -688,7 +748,10 @@ class BleHelper {
|
||||
v.notifyState = state;
|
||||
}
|
||||
});
|
||||
succ();
|
||||
// console.log("success SubScribe");
|
||||
succ(
|
||||
res
|
||||
); //见了鬼了,有时候执行了succ但promise永远pending了
|
||||
},
|
||||
fail: (ex) => {
|
||||
|
||||
@ -696,8 +759,27 @@ class BleHelper {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let p2 = new Promise((succ, err) => {
|
||||
setTimeout(() => {
|
||||
err({
|
||||
code: -1
|
||||
});
|
||||
}, 50);
|
||||
});
|
||||
return new Promise((succ, err) => {
|
||||
Promise.race([p1, p2]).then(succ).catch(ex => {
|
||||
if (ex.code == -1) {
|
||||
succ();
|
||||
return;
|
||||
}
|
||||
err(ex);
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
let promies = new Array();
|
||||
if (c.Characteristics && c.Characteristics.length) {
|
||||
for (var i = 0; i < c.Characteristics.length; i++) {
|
||||
let item = c.Characteristics[i];
|
||||
let serviceId = item.serviceId;
|
||||
@ -707,12 +789,16 @@ class BleHelper {
|
||||
promies.push(startSubScribe(deviceId, serviceId, characteristicId));
|
||||
}
|
||||
}
|
||||
if (promies.length > 0) {
|
||||
Promise.allSettled(promies).then((results) => {
|
||||
}
|
||||
|
||||
if (promies.length > 0) {
|
||||
|
||||
// console.log("234324324324");
|
||||
Promise.allSettled(promies).then((results) => {
|
||||
// console.log("11111");
|
||||
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);
|
||||
@ -721,15 +807,19 @@ class BleHelper {
|
||||
|
||||
resolve();
|
||||
}).catch((ex) => {
|
||||
// console.log("222222");
|
||||
reject(ex);
|
||||
}).finally(() => {
|
||||
// console.log("finally")
|
||||
});
|
||||
} else {
|
||||
// console.log("33333");
|
||||
resolve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}, 20);
|
||||
}, 800);
|
||||
|
||||
});
|
||||
}
|
||||
@ -755,8 +845,7 @@ class BleHelper {
|
||||
v.services = res.services;
|
||||
}
|
||||
});
|
||||
uni.setStorageSync(this.StorageKey,
|
||||
this.data.LinkedList);
|
||||
this.updateCache();
|
||||
|
||||
var promises = [];
|
||||
let se = res.services.find((v) => {
|
||||
@ -896,7 +985,7 @@ class BleHelper {
|
||||
|
||||
|
||||
|
||||
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
||||
this.updateCache();
|
||||
resolve(res);
|
||||
},
|
||||
fail: (ex) => {
|
||||
@ -936,23 +1025,30 @@ class BleHelper {
|
||||
|
||||
//连接设备
|
||||
var linkDevice = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 添加重试次数限制
|
||||
let retryCount = 0;
|
||||
const maxRetries = 5; // 最大重试次数
|
||||
|
||||
const connect = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (fIndex > -1 && f?.Linked) {
|
||||
console.log("当前已连接,跳过其他步骤")
|
||||
// console.log("当前已连接,跳过其他步骤");
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
if(!this.data.available){
|
||||
reject(this.getError({code:10001}));
|
||||
|
||||
if (!this.data.available) {
|
||||
reject(this.getError({
|
||||
code: 10001
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("正在连接" + deviceId);
|
||||
uni.createBLEConnection({
|
||||
deviceId: deviceId,
|
||||
timeout: 3000,
|
||||
timeout: 30000,
|
||||
success: (info) => {
|
||||
|
||||
console.log("新连接成功", this.data.LinkedList);
|
||||
this.getLinkBlue().then((arr) => {
|
||||
let cr = arr.devices.find(c => {
|
||||
@ -961,49 +1057,64 @@ class BleHelper {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
if (fIndex > -1) {
|
||||
this.data.LinkedList[fIndex].Linked = true;
|
||||
} else {
|
||||
this.data.LinkedList.push(cr);
|
||||
}
|
||||
|
||||
uni.setStorageSync(this.StorageKey, this.data
|
||||
this.updateCache();
|
||||
console.log("LinkedList=", this.data
|
||||
.LinkedList);
|
||||
|
||||
let os = plus.os.name;
|
||||
if (os == 'android') {
|
||||
// 处理 MTU 设置
|
||||
if (plus.os.name === 'Android') {
|
||||
uni.setBLEMTU({
|
||||
deviceId: deviceId,
|
||||
mtu: 512,
|
||||
success: (mtu) => {
|
||||
|
||||
////console.log("mtu设置成功");
|
||||
console.log("mtu设置成功",
|
||||
mtu);
|
||||
resolve(true);
|
||||
},
|
||||
fail: () => {
|
||||
////console.log("mtu设置失败")
|
||||
console.log("mtu设置失败");
|
||||
resolve(
|
||||
true
|
||||
); // MTU设置失败不影响连接成功
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
resolve(true);
|
||||
|
||||
}
|
||||
}).catch((ex) => {
|
||||
|
||||
reject(this.getError(ex));
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
fail: (ex) => {
|
||||
ex = this.getError(ex)
|
||||
ex = this.getError(ex);
|
||||
console.log("蓝牙连接失败" + JSON.stringify(ex));
|
||||
|
||||
// 连接超时后自动重试
|
||||
if (ex.code === 10012 && retryCount < maxRetries) {
|
||||
retryCount++;
|
||||
console.log(`重试连接 (${retryCount}/${maxRetries})`);
|
||||
// 使用 setTimeout 避免递归调用栈溢出
|
||||
setTimeout(() => {
|
||||
connect().then(resolve).catch(reject);
|
||||
}, 1000); // 延迟1秒后重试
|
||||
} else {
|
||||
reject(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return connect();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1013,19 +1124,32 @@ class BleHelper {
|
||||
////console.log("2222222");
|
||||
return linkDevice(deviceId);
|
||||
}).then((res) => {
|
||||
////console.log("11111111");
|
||||
|
||||
if (res) { //新连接
|
||||
// console.log("11111111");
|
||||
if (fIndex == -1) {
|
||||
console.log("开始获取服务", targetServiceId)
|
||||
// console.log("开始获取服务", targetServiceId)
|
||||
return this.getService(deviceId, targetServiceId, writeCharId,
|
||||
notifyCharId); //获取服务
|
||||
} else {
|
||||
if (f.wirteCharactId && f.notifyCharactId) {
|
||||
if (!f.notifyState) {
|
||||
// console.log("开始订阅特征");
|
||||
this.subScribe(deviceId, true);
|
||||
} else {
|
||||
console.log("不订阅消息");
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
} else {
|
||||
console.log("开始获取服务", targetServiceId)
|
||||
return this.getService(deviceId, targetServiceId, writeCharId,
|
||||
notifyCharId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} else { //已连接过,直接订阅消息
|
||||
// console.log("11111111");
|
||||
if (fIndex > -1 && f && !f.notifyState) {
|
||||
|
||||
this.subScribe(deviceId, true);
|
||||
@ -1034,13 +1158,13 @@ class BleHelper {
|
||||
}
|
||||
|
||||
}).then(() => {
|
||||
|
||||
// console.log("then.....");
|
||||
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 500);
|
||||
}).catch((ex) => {
|
||||
////console.log("出现异常", ex);
|
||||
console.log("出现异常", ex);
|
||||
reject(ex);
|
||||
});
|
||||
});
|
||||
@ -1156,7 +1280,7 @@ class BleHelper {
|
||||
characteristicId: device.wirteCharactId,
|
||||
value: buffer,
|
||||
success: () => {
|
||||
console.log("发送数据成功");
|
||||
// console.log("发送数据成功");
|
||||
succ();
|
||||
},
|
||||
fail: (ex) => {
|
||||
@ -1181,7 +1305,7 @@ class BleHelper {
|
||||
}
|
||||
|
||||
Promise.race([timeOut(ms), promise]).then(resolve).catch((ex) => {
|
||||
console.log("ex=", ex);
|
||||
// console.log("ex=", ex);
|
||||
if (ex.code == -1) {
|
||||
resolve(ex);
|
||||
} else {
|
||||
@ -1244,7 +1368,7 @@ class BleHelper {
|
||||
let a = pixels[i + 3];
|
||||
|
||||
if (type == 'bgr') {
|
||||
result[index++] = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
|
||||
result[index++] = ((b & 0xF8) << 8) | ((g & 0xFC) << 3) | (r >> 3);
|
||||
} else {
|
||||
result[index++] = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||
}
|
||||
@ -1254,9 +1378,7 @@ class BleHelper {
|
||||
return result;
|
||||
}
|
||||
|
||||
setBleData() {
|
||||
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let instance = null;
|
||||
|
||||
@ -44,31 +44,33 @@ class BleReceive {
|
||||
}
|
||||
|
||||
|
||||
ReceiveData(receive,f,path) {
|
||||
if(f && f.macAddress && f.id){
|
||||
ReceiveData(receive,f,path,recArr) {
|
||||
if(f && f.macAddress && f.device && f.device.id){
|
||||
let data={};
|
||||
if(f.detailPageUrl=='/pages/6155/deviceDetail'){
|
||||
if(f.device.detailPageUrl=='/pages/6155/deviceDetail'){
|
||||
// console.log("该设备是6155");
|
||||
data= this.Receive_6155(receive,f,path);
|
||||
data= this.Receive_6155(receive,f,path,recArr);
|
||||
}
|
||||
|
||||
if(f.detailPageUrl=='/pages/650/HBY650'){
|
||||
if(f.device.detailPageUrl=='/pages/650/HBY650'){
|
||||
// console.log("该设备是650");
|
||||
data= this.Receive_650(receive,f,path);
|
||||
data= this.Receive_650(receive,f,path,recArr);
|
||||
}
|
||||
if(f.detailPageUrl=='/pages/670/HBY670'){
|
||||
if(f.device.detailPageUrl=='/pages/670/HBY670'){
|
||||
// console.log("该设备是670");
|
||||
data= this.Receive_670(receive,f,path);
|
||||
data= this.Receive_670(receive,f,path,recArr);
|
||||
}
|
||||
// console.log("收到数据并处理完毕,",data);
|
||||
return data;
|
||||
}else{
|
||||
console.log("已收到该消息,但无法处理",receive);
|
||||
}
|
||||
// console.log("已收到该消息,但无法处理",receive);
|
||||
|
||||
return receive;
|
||||
|
||||
}
|
||||
|
||||
Receive_650(receive,f,path) {
|
||||
Receive_650(receive,f,path,recArr) {
|
||||
console.log("通用程序正在处理650的数据",receive);
|
||||
|
||||
var parseData = () => {
|
||||
@ -251,8 +253,8 @@ class BleReceive {
|
||||
|
||||
}
|
||||
|
||||
Receive_670(receive,f,path){
|
||||
|
||||
Receive_670(receive,f,path,recArr){
|
||||
console.log("pagh=",path);
|
||||
var todo = (bytes) =>{
|
||||
// console.log("todo",receive);
|
||||
let receiveData = {};
|
||||
@ -314,6 +316,21 @@ class BleReceive {
|
||||
receiveData.staticWarn = staticWarn;
|
||||
receiveData.fourGStrenth = fourGStrenth;
|
||||
receiveData.SOS=sosTxt;
|
||||
|
||||
this.setBleFormData(receiveData,f);
|
||||
console.log("recArr=",recArr);
|
||||
let recCnt=recArr.find(v=>{
|
||||
return v.key == f.device.detailPageUrl;
|
||||
});
|
||||
if(!recCnt){
|
||||
if (this.formData.staticWarn) { //有静止报警
|
||||
uni.showModal({
|
||||
title:"警告",
|
||||
content:"设备静止报警中",
|
||||
showCancel:false
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch(error) {
|
||||
console.log('数据解析错误:', error);
|
||||
}
|
||||
@ -392,8 +409,81 @@ class BleReceive {
|
||||
|
||||
return data;
|
||||
}
|
||||
Receive_6155() {
|
||||
console.log("通用程序正在处理6155的数据");
|
||||
Receive_6155(receive,f,path,recArr) {
|
||||
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 + "分钟";
|
||||
let formData={};
|
||||
formData.mode = staticLevelText;
|
||||
formData.fuMode = lightingLevelText;
|
||||
formData.battary = batteryLevel;
|
||||
formData.statu = warn;
|
||||
formData.xuhang = lightingTime;
|
||||
|
||||
if (batteryLevel <= 20) {
|
||||
uni.showModal({
|
||||
content:"设备电量低",
|
||||
title:"提示"
|
||||
});
|
||||
|
||||
}
|
||||
this.setBleFormData(formData,f);
|
||||
return formData;
|
||||
} catch (error) {
|
||||
console.log('数据解析错误:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
107
utils/update.js
107
utils/update.js
@ -1,3 +1,5 @@
|
||||
import request,{baseURL} from '@/utils/request.js'
|
||||
|
||||
/**
|
||||
* 检查并执行wgt热更新
|
||||
* @param {String} updateUrl - 检查更新的接口地址
|
||||
@ -13,53 +15,90 @@ function checkAndUpdateWgt(updateUrl) {
|
||||
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
|
||||
const currentVersion = widgetInfo.version;
|
||||
console.log("当前版本:" + currentVersion);
|
||||
// 2. 调用后端接口检查是否有更新
|
||||
uni.request({
|
||||
url: updateUrl,
|
||||
method: 'GET',
|
||||
data: {
|
||||
currentVersion: currentVersion,
|
||||
platform: uni.getSystemInfoSync().platform
|
||||
},
|
||||
success: (res) => {
|
||||
uni.hideLoading();
|
||||
console.log("res=", res)
|
||||
if (res.statusCode === 200) {
|
||||
|
||||
const updateInfo = res.data.data;
|
||||
if (!updateInfo.hasUpdate) {
|
||||
request({
|
||||
url:'/app/auth/version',
|
||||
method: 'get'
|
||||
}).then(res=>{
|
||||
console.log("检查版本更新:",res);
|
||||
let os=plus.os.name.toLowerCase();
|
||||
if(res.code!=200){
|
||||
return;
|
||||
}
|
||||
// 3. 显示更新提示
|
||||
let f=res.data.find(v=>{
|
||||
if(v.dictLabel.toLowerCase()==os){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if(f){
|
||||
if(f.dictValue==currentVersion){
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: '检测到更新',
|
||||
content: updateInfo.description || '有新版本可用,是否立即更新?',
|
||||
content: '当前版本“'+currentVersion+'”,发现新版本“'+f.dictValue+'”,是否立即更新?',
|
||||
confirmText: '立即更新',
|
||||
cancelText: '稍后更新',
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
downloadAndInstallWgt(updateInfo.downloadUrl);
|
||||
downloadAndInstallWgt(f.remark);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '当前已是最新版本',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '检查更新失败',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
console.error('检查更新失败:', err);
|
||||
}
|
||||
|
||||
|
||||
}).catch(ex=>{
|
||||
console.log("检查更新失败:",ex);
|
||||
});
|
||||
// 2. 调用后端接口检查是否有更新
|
||||
// uni.request({
|
||||
// url: updateUrl,
|
||||
// method: 'GET',
|
||||
// data: {
|
||||
// currentVersion: currentVersion,
|
||||
// platform: uni.getSystemInfoSync().platform
|
||||
// },
|
||||
// success: (res) => {
|
||||
// uni.hideLoading();
|
||||
// console.log("res=", res)
|
||||
// if (res.statusCode === 200) {
|
||||
|
||||
// const updateInfo = res.data.data;
|
||||
// if (!updateInfo.hasUpdate) {
|
||||
// return;
|
||||
// }
|
||||
// // 3. 显示更新提示
|
||||
// uni.showModal({
|
||||
// title: '检测到更新',
|
||||
// content: updateInfo.description || '有新版本可用,是否立即更新?',
|
||||
// confirmText: '立即更新',
|
||||
// cancelText: '稍后更新',
|
||||
// success: (modalRes) => {
|
||||
// if (modalRes.confirm) {
|
||||
// downloadAndInstallWgt(updateInfo.downloadUrl);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// } else {
|
||||
// uni.showToast({
|
||||
// title: '当前已是最新版本',
|
||||
// icon: 'none',
|
||||
// duration: 2000
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// uni.hideLoading();
|
||||
// uni.showToast({
|
||||
// title: '检查更新失败',
|
||||
// icon: 'none',
|
||||
// duration: 2000
|
||||
// });
|
||||
// console.error('检查更新失败:', err);
|
||||
// }
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user