添加蓝牙通讯握手
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
featrueValueCallback: null,//蓝牙特征变化回调
|
featrueValueCallback: null, //蓝牙特征变化回调
|
||||||
BleChangeCallback:null,//蓝牙状态变化回调
|
BleChangeCallback: null, //蓝牙状态变化回调
|
||||||
//引导用户打开蓝牙
|
//引导用户打开蓝牙
|
||||||
showBluetoothGuide: function(showTip) {
|
showBluetoothGuide: function(showTip) {
|
||||||
let platform = process.env.UNI_PLATFORM;
|
let platform = process.env.UNI_PLATFORM;
|
||||||
@ -89,7 +89,7 @@ export default {
|
|||||||
uni.getBluetoothAdapterState({
|
uni.getBluetoothAdapterState({
|
||||||
success(res1) {
|
success(res1) {
|
||||||
|
|
||||||
console.log("当前蓝牙适配器状态:" + JSON.stringify(res1))
|
//console.log("当前蓝牙适配器状态:" + JSON.stringify(res1))
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(res1);
|
callback(res1);
|
||||||
}
|
}
|
||||||
@ -126,8 +126,8 @@ export default {
|
|||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
uni.onBluetoothAdapterStateChange(function(state) {
|
uni.onBluetoothAdapterStateChange(function(state) {
|
||||||
console.log('蓝牙状态发生变化:' + JSON.stringify(state));
|
//console.log('蓝牙状态发生变化:' + JSON.stringify(state));
|
||||||
if(this.BleChangeCallback){
|
if (this.BleChangeCallback) {
|
||||||
this.BleChangeCallback()
|
this.BleChangeCallback()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -232,7 +232,7 @@ export default {
|
|||||||
StopSearch: function() {
|
StopSearch: function() {
|
||||||
uni.stopBluetoothDevicesDiscovery({
|
uni.stopBluetoothDevicesDiscovery({
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log("停止搜索蓝牙设备成功")
|
//console.log("停止搜索蓝牙设备成功")
|
||||||
},
|
},
|
||||||
fail() {
|
fail() {
|
||||||
console.log("无法停止蓝牙搜索")
|
console.log("无法停止蓝牙搜索")
|
||||||
@ -241,8 +241,7 @@ export default {
|
|||||||
},
|
},
|
||||||
//获取已连接的设备
|
//获取已连接的设备
|
||||||
getLinkBlue: function(callback) {
|
getLinkBlue: function(callback) {
|
||||||
uni.getConnectedBluetoothDevices({
|
uni.getConnectedBluetoothDevices({
|
||||||
services: ["0xFFE0"],
|
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(res);
|
callback(res);
|
||||||
@ -250,7 +249,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: function(ex) {
|
fail: function(ex) {
|
||||||
console.log("获取已连接设备异常");
|
console.log("获取已连接设备异常",ex);
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({
|
callback({
|
||||||
devices: []
|
devices: []
|
||||||
@ -261,7 +260,7 @@ export default {
|
|||||||
},
|
},
|
||||||
//连接某个设备
|
//连接某个设备
|
||||||
LinkBlue: function(deviceId, callback, error) {
|
LinkBlue: function(deviceId, callback, error) {
|
||||||
|
//console.log("deviceId="+deviceId)
|
||||||
this.StopSearch();
|
this.StopSearch();
|
||||||
var these = this;
|
var these = this;
|
||||||
let key = "linkedDevices";
|
let key = "linkedDevices";
|
||||||
@ -274,54 +273,58 @@ export default {
|
|||||||
var str = uni.getStorageSync(key);
|
var str = uni.getStorageSync(key);
|
||||||
if (str) {
|
if (str) {
|
||||||
linkedDevices = JSON.parse(str);
|
linkedDevices = JSON.parse(str);
|
||||||
}else{
|
} else {
|
||||||
linkedDevices=[];
|
linkedDevices = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//连接成功的回调
|
//连接成功的回调
|
||||||
var lindedCallback = function () {
|
var lindedCallback = function(id,flag) {
|
||||||
|
|
||||||
let c = linkedDevices.find(function (v) {
|
let c = linkedDevices.find(function(v) {
|
||||||
return v.deviceId == deviceId;
|
return v.deviceId == deviceId;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (c) {
|
if (c && !flag) {
|
||||||
console.log("连接成功开始监听特征变化")
|
console.log("连接成功开始监听特征变化,deviceid="+deviceId+',serviceId='+c.notifyServiceid+',characteristicId='+c.notifyCharactId)
|
||||||
//监听设备的特征变化
|
//监听设备的特征变化
|
||||||
uni.notifyBLECharacteristicValueChange({
|
setTimeout(()=>{
|
||||||
deviceId: deviceId,
|
uni.notifyBLECharacteristicValueChange({
|
||||||
serviceId: c.notifyServiceid,
|
deviceId: deviceId,
|
||||||
characteristicId: c.notifyCharactId,
|
serviceId: c.notifyServiceid,
|
||||||
state: true,
|
characteristicId: c.notifyCharactId,
|
||||||
success: function (res) {
|
state: true,
|
||||||
console.log("开始监听成功。。。。")
|
success: function(res) {
|
||||||
if(res.errCode=='0'){
|
console.log("开始监听成功。。。。",res)
|
||||||
//订阅特征值
|
//订阅特征值
|
||||||
uni.onBLECharacteristicValueChange(function(data){
|
|
||||||
// data.characteristicId
|
|
||||||
// data.deviceId
|
|
||||||
// data.serviceId
|
|
||||||
// data.value
|
|
||||||
console.log("监听到特征值:"+JSON.stringify(data));
|
|
||||||
|
|
||||||
if(these.featrueValueCallback){
|
uni.onBLECharacteristicValueChange(function(data) {
|
||||||
these.featrueValueCallback(data);
|
// data.characteristicId
|
||||||
}
|
// data.deviceId
|
||||||
});
|
// data.serviceId
|
||||||
|
// data.value
|
||||||
|
console.log("监听到特征值:" + JSON.stringify(data));
|
||||||
|
|
||||||
|
if (these.featrueValueCallback) {
|
||||||
|
these.featrueValueCallback(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
},1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(deviceId);
|
callback(deviceId,flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var linkState = function(res) {
|
var linkState = function(res) {
|
||||||
console.log("获取已连接的设备回调" + JSON.stringify(res))
|
//console.log("获取已连接的设备回调" + JSON.stringify(res))
|
||||||
let flag = res.devices.find(function(v) {
|
let flag = res.devices.find(function(v) {
|
||||||
if (v.deviceId == deviceId) {
|
if (v.deviceId == deviceId) {
|
||||||
return true;
|
return true;
|
||||||
@ -329,82 +332,97 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
if (flag) {
|
if (flag) {
|
||||||
console.log("设备状态已连接");
|
//console.log("设备状态已连接");
|
||||||
|
|
||||||
lindedCallback(deviceId);
|
lindedCallback(deviceId,true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
console.log("设备未连接");
|
console.log("设备未连接:"+deviceId);
|
||||||
linkDevice(deviceId);
|
linkDevice(deviceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var linkDevice = function(id) {
|
var linkDevice = function() {
|
||||||
console.log("正在连接"+id);
|
console.log("正在连接" + deviceId);
|
||||||
uni.createBLEConnection({
|
uni.createBLEConnection({
|
||||||
deviceId: id,
|
deviceId: deviceId,
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
success: function(info) {
|
success: function(info) {
|
||||||
|
|
||||||
console.log("连接成功");
|
console.log("连接成功");
|
||||||
|
|
||||||
uni.setBLEMTU({
|
var call = () => {
|
||||||
deviceId: id,
|
if (linkedDevices) {
|
||||||
mtu: 512,
|
console.log("11111" + JSON.stringify(linkedDevices));
|
||||||
success: () => {
|
f = linkedDevices.find(function(v) {
|
||||||
console.log("mtu设置成功");
|
return v.deviceId == deviceId;
|
||||||
if(linkedDevices){
|
});
|
||||||
console.log("11111"+JSON.stringify(linkedDevices));
|
} else {
|
||||||
f = linkedDevices.find(function (v) {
|
console.log("22222")
|
||||||
return v.deviceId == id;
|
f = null;
|
||||||
});
|
|
||||||
}else{
|
|
||||||
console.log("22222")
|
|
||||||
f=null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!f) {
|
|
||||||
console.log("缓存中没有找到该设备")
|
|
||||||
|
|
||||||
these.getLinkBlue(function (res) {
|
|
||||||
if (res.devices && res.devices.length) {
|
|
||||||
let f = res.devices.find(function (v) {
|
|
||||||
return v.deviceId == id;
|
|
||||||
});
|
|
||||||
linkedDevices.push(f);
|
|
||||||
uni.setStorageSync(key, JSON.stringify(linkedDevices));
|
|
||||||
|
|
||||||
getService(id);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
console.log("缓存中已连接过");
|
|
||||||
if (!f.services) {
|
|
||||||
getService(id);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
lindedCallback(id);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
fail: function() {
|
|
||||||
console.log("mtu设置失败")
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!f) {
|
||||||
|
console.log("缓存中没有找到该设备")
|
||||||
|
|
||||||
|
these.getLinkBlue(function(res) {
|
||||||
|
if (res.devices && res.devices.length) {
|
||||||
|
let f = res.devices.find(function(v) {
|
||||||
|
return v.deviceId == deviceId;
|
||||||
|
});
|
||||||
|
linkedDevices.push(f);
|
||||||
|
uni.setStorageSync(key, JSON.stringify(
|
||||||
|
linkedDevices));
|
||||||
|
|
||||||
|
getService(deviceId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log("缓存中已连接过");
|
||||||
|
if (!f.services) {
|
||||||
|
getService(deviceId);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
lindedCallback(deviceId,false);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
let os = uni.getSystemInfoSync().osName;
|
||||||
|
if (os == 'android') {
|
||||||
|
uni.setBLEMTU({
|
||||||
|
deviceId: deviceId,
|
||||||
|
mtu: 512,
|
||||||
|
success: () => {
|
||||||
|
//console.log("mtu设置成功");
|
||||||
|
},
|
||||||
|
fail: function() {
|
||||||
|
console.log("mtu设置失败")
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
call();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
call();
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
fail: function(ex) {
|
fail: function(ex) {
|
||||||
if (error) {
|
if (ex) {
|
||||||
console.log("蓝牙连接失败" + JSON.stringify(error));
|
console.log("蓝牙连接失败" + JSON.stringify(ex));
|
||||||
error(ex);
|
if(error){
|
||||||
|
error(ex);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -435,9 +453,9 @@ export default {
|
|||||||
Promise.all(promises)
|
Promise.all(promises)
|
||||||
.then(results => {
|
.then(results => {
|
||||||
console.log('所有操作成功完成', results);
|
console.log('所有操作成功完成', results);
|
||||||
|
|
||||||
lindedCallback(id);
|
lindedCallback(id,false);
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('至少一个操作失败', error);
|
console.error('至少一个操作失败', error);
|
||||||
@ -447,9 +465,9 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
repeatCnt++;
|
repeatCnt++;
|
||||||
if (repeatCnt > 5) {
|
if (repeatCnt > 5) {
|
||||||
|
|
||||||
lindedCallback(id);
|
lindedCallback(id,false);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@ -498,10 +516,14 @@ export default {
|
|||||||
if (notiChar) {
|
if (notiChar) {
|
||||||
v.notifyServiceid = serviceId;
|
v.notifyServiceid = serviceId;
|
||||||
v.notifyCharactId = notiChar.uuid;
|
v.notifyCharactId = notiChar.uuid;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uni.setStorageSync(key, JSON.stringify(linkedDevices));
|
uni.setStorageSync(key, JSON.stringify(linkedDevices));
|
||||||
resolve(res);
|
resolve(res);
|
||||||
},
|
},
|
||||||
@ -522,9 +544,9 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("正在获取蓝牙适配器状态")
|
//console.log("正在获取蓝牙适配器状态")
|
||||||
this.CheckBlue((res) => {
|
this.CheckBlue((res) => {
|
||||||
console.log("蓝牙状态:" + JSON.stringify(res));
|
//console.log("蓝牙状态:" + JSON.stringify(res));
|
||||||
if (res.available) {
|
if (res.available) {
|
||||||
this.getLinkBlue(linkState);
|
this.getLinkBlue(linkState);
|
||||||
} else {
|
} else {
|
||||||
@ -580,13 +602,13 @@ export default {
|
|||||||
reject(`deviceid为空,请输入要发送的设备`);
|
reject(`deviceid为空,请输入要发送的设备`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("准备发送数据包");
|
console.log("准备发送数据包");
|
||||||
let key = "linkedDevices";
|
let key = "linkedDevices";
|
||||||
var store = uni.getStorageInfoSync();
|
var store = uni.getStorageInfoSync();
|
||||||
var f = store.keys.find(function(v) {
|
var f = store.keys.find(function(v) {
|
||||||
return v == key;
|
return v == key;
|
||||||
});
|
});
|
||||||
console.log("倒计时:5");
|
console.log("倒计时:5");
|
||||||
var linkedDevices = [];
|
var linkedDevices = [];
|
||||||
if (f) {
|
if (f) {
|
||||||
var str = uni.getStorageSync(key);
|
var str = uni.getStorageSync(key);
|
||||||
@ -595,35 +617,19 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
console.log("倒计时:4");
|
console.log("倒计时:4");
|
||||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
||||||
console.log("倒计时:3");
|
console.log("倒计时:3");
|
||||||
f = linkedDevices.find(function(v) {
|
f = linkedDevices.find(function(v) {
|
||||||
return v.deviceId == deviceid;
|
return v.deviceId == deviceid;
|
||||||
|
|
||||||
});
|
});
|
||||||
console.log("f=" + JSON.stringify(f));
|
console.log("f=" + JSON.stringify(f));
|
||||||
// console.log("deviceid=" + deviceid);
|
// console.log("deviceid=" + deviceid);
|
||||||
console.log("倒计时:2");
|
console.log("倒计时:2");
|
||||||
if (f) {
|
if (f) {
|
||||||
console.log("倒计时:1");
|
console.log("倒计时:1");
|
||||||
uni.writeBLECharacteristicValue({
|
these.sendDataNew(f.deviceId,f.writeServiceId,f.wirteCharactId,buffer).then(succ).catch(err);
|
||||||
deviceId: f.deviceId,
|
|
||||||
serviceId: f.writeServiceId,
|
|
||||||
characteristicId: f.wirteCharactId,
|
|
||||||
value: buffer,
|
|
||||||
success: () => {
|
|
||||||
console.log("发送数据成功");
|
|
||||||
resolve();
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
console.log("发送数据失败" + JSON.stringify(err));
|
|
||||||
reject(`发送数据失败: ${err.errMsg}`);
|
|
||||||
},
|
|
||||||
complete: function() {
|
|
||||||
console.log("发送数据complete");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
reject(`已连接设备中无法找到此设备`);
|
reject(`已连接设备中无法找到此设备`);
|
||||||
// console.log("警报:已连接设备中无法找到此设备")
|
// console.log("警报:已连接设备中无法找到此设备")
|
||||||
@ -636,36 +642,67 @@ export default {
|
|||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
sendDataNew: function(deviceid, serviceId, characteristicId, buffer) {
|
sendDataNew: function(deviceid, serviceId, characteristicId, buffer) {
|
||||||
|
|
||||||
console.log("准备向设备发送数据,deviceid=" + deviceid);
|
//console.log("准备向设备发送数据,deviceid=" + deviceid+',serviceId='+serviceId+',characteristicId='+characteristicId);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.writeBLECharacteristicValue({
|
let promise = new Promise((succ, err) => {
|
||||||
deviceId: deviceid,
|
uni.writeBLECharacteristicValue({
|
||||||
serviceId: serviceId,
|
deviceId: deviceid,
|
||||||
characteristicId: characteristicId,
|
serviceId: serviceId,
|
||||||
value: buffer,
|
characteristicId: characteristicId,
|
||||||
success: () => {
|
value: buffer,
|
||||||
console.log("发送数据成功");
|
success: () => {
|
||||||
resolve();
|
//console.log("发送数据成功");
|
||||||
},
|
succ();
|
||||||
fail: (err) => {
|
},
|
||||||
console.log("发送数据失败" + JSON.stringify(err));
|
fail: (ex) => {
|
||||||
reject(`发送数据失败: ${err.errMsg}`);
|
console.log("发送数据失败" + JSON.stringify(ex));
|
||||||
},
|
err(ex);
|
||||||
complete: function() {
|
}
|
||||||
console.log("发送数据complete");
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (uni.getSystemInfoSync().osName.toLowerCase() == 'ios') {
|
||||||
|
|
||||||
|
//专业给IOS填坑,uni.writeBLECharacteristicValue在IOS上不进入任何回调
|
||||||
|
|
||||||
|
function timeout(ms) {
|
||||||
|
return new Promise((_, err) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
err({
|
||||||
|
code: -1,
|
||||||
|
errMsg: '超时了'
|
||||||
|
})
|
||||||
|
}, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise.race([promise, timeout(50)]).then(resolve).catch((ex) => {
|
||||||
|
console.log("ex=", ex);
|
||||||
|
if (ex.code == -1) {
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
reject(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}).finally(() => {
|
||||||
|
console.log("完成了")
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
promise.then(resolve).catch(reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
10
pages.json
10
pages.json
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"path": "pages/common/login/index",
|
"path": "pages/common/login/index",
|
||||||
"style": {
|
"style": {
|
||||||
@ -121,12 +122,21 @@
|
|||||||
"fullscreen": true
|
"fullscreen": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path" : "pages/650/HBY650",
|
||||||
|
"style" :
|
||||||
|
{
|
||||||
|
"navigationBarTitleText" : "HBY650"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/common/map/index",
|
"path": "pages/common/map/index",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "地图"
|
"navigationBarTitleText": "地图"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
],
|
],
|
||||||
"tabBar": {
|
"tabBar": {
|
||||||
"color": "#fff",
|
"color": "#fff",
|
||||||
|
|||||||
@ -144,8 +144,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ble from '../../api/6155/BlueHelper';
|
import ble from '@/api/6155/BlueHelper';
|
||||||
import { deviceReName } from '../../api/common';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@ -230,7 +229,7 @@ import { deviceReName } from '../../api/common';
|
|||||||
RSSI: '-30',
|
RSSI: '-30',
|
||||||
statu: '运行中',
|
statu: '运行中',
|
||||||
liangDu: '50',
|
liangDu: '50',
|
||||||
id:''
|
id: ''
|
||||||
},
|
},
|
||||||
cEdit: {
|
cEdit: {
|
||||||
mode: ''
|
mode: ''
|
||||||
@ -242,7 +241,11 @@ import { deviceReName } from '../../api/common';
|
|||||||
id: 'HSXF01061'
|
id: 'HSXF01061'
|
||||||
},
|
},
|
||||||
device: {
|
device: {
|
||||||
deviceId: ''
|
deviceId: '',
|
||||||
|
writeServiceId: '',
|
||||||
|
wirteCharactId: '',
|
||||||
|
notifyServiceid:'',
|
||||||
|
notifyCharactId:''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -253,20 +256,20 @@ import { deviceReName } from '../../api/common';
|
|||||||
|
|
||||||
eventChannel.on('detailData', function(data) {
|
eventChannel.on('detailData', function(data) {
|
||||||
|
|
||||||
|
|
||||||
console.log("收到父页面的参数:" + JSON.stringify(data));
|
console.log("收到父页面的参数:" + JSON.stringify(data));
|
||||||
var device = data.data;
|
var device = data.data;
|
||||||
these.device.deviceId = device.deviceMac;
|
these.device.deviceId = device.deviceMac;
|
||||||
these.formData.name=device.bluetoothName?device.bluetoothName:device.deviceName;
|
these.formData.name = device.bluetoothName ? device.bluetoothName : device.deviceName;
|
||||||
these.formData.img=device.devicePic;
|
these.formData.img = device.devicePic;
|
||||||
these.formData.id=device.id;
|
these.formData.id = device.id;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ble.featrueValueCallback = these.bleValueNotify;
|
ble.featrueValueCallback = these.bleValueNotify;
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
onHide: function() {
|
onHide: function() {
|
||||||
|
|
||||||
@ -299,7 +302,7 @@ import { deviceReName } from '../../api/common';
|
|||||||
content: '是否断开与设备的蓝牙连接?',
|
content: '是否断开与设备的蓝牙连接?',
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
disconnectDevice(these.device.deviceId);
|
ble.disconnectDevice(these.device.deviceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
@ -332,6 +335,49 @@ import { deviceReName } from '../../api/common';
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getDevice: function() {
|
||||||
|
var these = this;
|
||||||
|
|
||||||
|
if (this.device.deviceId && this.device.writeServiceId && this.device.wirteCharactId) {
|
||||||
|
return this.device;
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = "linkedDevices";
|
||||||
|
var store = uni.getStorageInfoSync();
|
||||||
|
var f = store.keys.find(function(v) {
|
||||||
|
return v == key;
|
||||||
|
});
|
||||||
|
// console.log("倒计时:5");
|
||||||
|
var linkedDevices = [];
|
||||||
|
if (f) {
|
||||||
|
var str = uni.getStorageSync(key);
|
||||||
|
if (str) {
|
||||||
|
linkedDevices = JSON.parse(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// console.log("倒计时:4");
|
||||||
|
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
||||||
|
// console.log("倒计时:3");
|
||||||
|
f = linkedDevices.find(function(v) {
|
||||||
|
if(v.deviceId == these.device.deviceId){
|
||||||
|
these.device.writeServiceId=v.writeServiceId;
|
||||||
|
these.device.wirteCharactId=v.wirteCharactId;
|
||||||
|
these.device.notifyServiceid=v.notifyServiceid;
|
||||||
|
these.device.notifyCharactId=v.notifyCharactId;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
f = null;
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
},
|
||||||
bleValueNotify: function(data) {
|
bleValueNotify: function(data) {
|
||||||
console.log("读取到设备发送的数据:" + JSON.stringify(data));
|
console.log("读取到设备发送的数据:" + JSON.stringify(data));
|
||||||
// data.characteristicId
|
// data.characteristicId
|
||||||
@ -343,9 +389,9 @@ import { deviceReName } from '../../api/common';
|
|||||||
},
|
},
|
||||||
|
|
||||||
proParam: function() {
|
proParam: function() {
|
||||||
|
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title:'敬请期待'
|
title: '敬请期待'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handRemark: function() {
|
handRemark: function() {
|
||||||
@ -404,139 +450,114 @@ import { deviceReName } from '../../api/common';
|
|||||||
// 分包发送图片数据
|
// 分包发送图片数据
|
||||||
var sendImagePackets = function(imageData) {
|
var sendImagePackets = function(imageData) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// this.isSending = true;
|
|
||||||
// this.progress = 0;
|
|
||||||
// this.currentPacket = 0;
|
|
||||||
|
|
||||||
// 总数据包数
|
// 总数据包数
|
||||||
const totalPackets = 52;
|
const totalPackets = 52;
|
||||||
let currentPacket = 1;
|
let currentPacket = 1;
|
||||||
|
f = these.getDevice();
|
||||||
let key = "linkedDevices";
|
|
||||||
var store = uni.getStorageInfoSync();
|
|
||||||
var f = store.keys.find(function(v) {
|
|
||||||
return v == key;
|
|
||||||
});
|
|
||||||
// console.log("倒计时:5");
|
|
||||||
var linkedDevices = [];
|
|
||||||
if (f) {
|
if (f) {
|
||||||
var str = uni.getStorageSync(key);
|
// 发送单个数据包
|
||||||
if (str) {
|
const sendNextPacket = () => {
|
||||||
linkedDevices = JSON.parse(str);
|
if (currentPacket > totalPackets) {
|
||||||
}
|
uni.hideLoading();
|
||||||
|
these.Status.BottomMenu.show = false;
|
||||||
}
|
these.Status.Progress.show = false;
|
||||||
// console.log("倒计时:4");
|
these.Status.Pop.showPop = true;
|
||||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
these.Status.Pop.message = "上传成功";
|
||||||
// console.log("倒计时:3");
|
these.Status.Pop.iconUrl =
|
||||||
f = linkedDevices.find(function(v) {
|
"/static/images/6155/DeviceDetail/uploadSuccess.png";
|
||||||
return v.deviceId == these.device.deviceId;
|
resolve();
|
||||||
|
return;
|
||||||
});
|
|
||||||
if (f) {
|
|
||||||
// 发送单个数据包
|
|
||||||
const sendNextPacket = () => {
|
|
||||||
if (currentPacket > totalPackets) {
|
|
||||||
uni.hideLoading();
|
|
||||||
these.Status.BottomMenu.show = false;
|
|
||||||
these.Status.Progress.show = false;
|
|
||||||
these.Status.Pop.showPop = true;
|
|
||||||
these.Status.Pop.message = "上传成功";
|
|
||||||
these.Status.Pop.iconUrl =
|
|
||||||
"/static/images/6155/DeviceDetail/uploadSuccess.png";
|
|
||||||
resolve();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算当前包的数据
|
|
||||||
let packetSize = 250;
|
|
||||||
if (currentPacket <= 51) {
|
|
||||||
packetSize = 250; // 前51个包每个500字节
|
|
||||||
} else {
|
|
||||||
packetSize = 50; // 最后一个包100字节
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建数据包
|
|
||||||
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);
|
|
||||||
|
|
||||||
// 填充头部
|
|
||||||
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);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (packetData.length == 250) {
|
|
||||||
dataView.setUint8(3, 0x01);
|
|
||||||
dataView.setUint8(4, 0xF4);
|
|
||||||
} else {
|
|
||||||
dataView.setUint8(3, 0x00);
|
|
||||||
dataView.setUint8(4, 0x64);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 填充数据(每个RGB565值占2字节)
|
|
||||||
for (let i = 0; i < packetData.length; i++) {
|
|
||||||
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
|
|
||||||
}
|
|
||||||
console.log(
|
|
||||||
`发送数据包${currentPacket}/${totalPackets},${dataView.getUint8(0)} ${dataView.getUint8(1)} ${dataView.getUint8(2)}`
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//发送数据包
|
|
||||||
ble.sendDataNew(f.deviceId, f.writeServiceId, f.wirteCharactId, buffer)
|
|
||||||
.then(() => {
|
|
||||||
console.log("发送一个包完成了");
|
|
||||||
these.Status.Progress.curr = currentPacket;
|
|
||||||
currentPacket++;
|
|
||||||
|
|
||||||
setTimeout(sendNextPacket, 100);
|
|
||||||
}).catch(err => {
|
|
||||||
console.log("发送数据包失败了" + JSON.stringify(err));
|
|
||||||
// this.isSending = false;
|
|
||||||
these.Status.BottomMenu.show = false;
|
|
||||||
these.Status.Progress.show = false;
|
|
||||||
these.alert("发送数据包失败了");
|
|
||||||
uni.hideLoading();
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算当前包的数据
|
||||||
// 开始发送数据
|
let packetSize = 250;
|
||||||
sendNextPacket();
|
if (currentPacket <= 51) {
|
||||||
|
packetSize = 250; // 前51个包每个500字节
|
||||||
|
} else {
|
||||||
|
packetSize = 50; // 最后一个包100字节
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建数据包
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 填充头部
|
||||||
|
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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (packetData.length == 250) {
|
||||||
|
dataView.setUint8(3, 0x01);
|
||||||
|
dataView.setUint8(4, 0xF4);
|
||||||
|
} else {
|
||||||
|
dataView.setUint8(3, 0x00);
|
||||||
|
dataView.setUint8(4, 0x64);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 填充数据(每个RGB565值占2字节)
|
||||||
|
for (let i = 0; i < packetData.length; i++) {
|
||||||
|
dataView.setUint16(5 + i * 2, packetData[i], false); // 大端字节序
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
`发送数据包${currentPacket}/${totalPackets},${dataView.getUint8(0)} ${dataView.getUint8(1)} ${dataView.getUint8(2)}`
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//发送数据包
|
||||||
|
ble.sendDataNew(f.deviceId, f.writeServiceId, f.wirteCharactId, buffer)
|
||||||
|
.then(() => {
|
||||||
|
console.log("发送一个包完成了");
|
||||||
|
these.Status.Progress.curr = currentPacket;
|
||||||
|
currentPacket++;
|
||||||
|
|
||||||
|
setTimeout(sendNextPacket, 100);
|
||||||
|
}).catch(err => {
|
||||||
|
console.log("发送数据包失败了" + JSON.stringify(err));
|
||||||
|
// this.isSending = false;
|
||||||
|
these.Status.BottomMenu.show = false;
|
||||||
|
these.Status.Progress.show = false;
|
||||||
|
these.alert("发送数据包失败了");
|
||||||
|
uni.hideLoading();
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 开始发送数据
|
||||||
|
sendNextPacket();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,7 +593,7 @@ import { deviceReName } from '../../api/common';
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
fail(ex) {
|
fail(ex) {
|
||||||
console.log("跳转页面失败"+JSON.stringify(ex));
|
console.log("跳转页面失败" + JSON.stringify(ex));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -594,8 +615,7 @@ import { deviceReName } from '../../api/common';
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case "main":
|
case "main":
|
||||||
title = '主灯模式';
|
title = '主灯模式';
|
||||||
items = [
|
items = [{
|
||||||
{
|
|
||||||
text: '强光',
|
text: '强光',
|
||||||
icon: '/static/images/6155/DeviceDetail/qiang.png'
|
icon: '/static/images/6155/DeviceDetail/qiang.png'
|
||||||
},
|
},
|
||||||
@ -682,24 +702,26 @@ import { deviceReName } from '../../api/common';
|
|||||||
const dataView = new DataView(buffer);
|
const dataView = new DataView(buffer);
|
||||||
|
|
||||||
dataView.setUint8(0, 0x4A); // 帧头
|
dataView.setUint8(0, 0x4A); // 帧头
|
||||||
dataView.setUint8(1, 0x51);
|
dataView.setUint8(1, 0x51);
|
||||||
dataView.setUint8(2, 0x4F);
|
dataView.setUint8(2, 0x4F);
|
||||||
dataView.setUint8(3, 0x43);
|
dataView.setUint8(3, 0x43);
|
||||||
|
|
||||||
|
|
||||||
if(this.Status.BottomMenu.type=='main'){
|
if (this.Status.BottomMenu.type == 'main') {
|
||||||
//主灯模式
|
//主灯模式
|
||||||
dataView.setUint8(4, 0x04); // 帧类型
|
dataView.setUint8(4, 0x04); // 帧类型
|
||||||
}else{
|
} else {
|
||||||
//副灯模式
|
//副灯模式
|
||||||
dataView.setUint8(4, 0x05); // 帧类型
|
dataView.setUint8(4, 0x05); // 帧类型
|
||||||
}
|
}
|
||||||
dataView.setUint8(5, dataValue); // 数据
|
dataView.setUint8(5, dataValue); // 数据
|
||||||
dataView.setUint16(6, '9C41');
|
dataView.setUint16(6, '9C41');
|
||||||
|
|
||||||
|
let f = this.getDevice();
|
||||||
// 发送数据
|
// 发送数据
|
||||||
ble.LinkBlue(this.device.deviceId, () => {
|
ble.LinkBlue(f.deviceId, () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
ble.sendData(this.device.deviceId, buffer);
|
ble.sendDataNew(f.deviceId, f.writeServiceId, f.wirteCharactId, buffer);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -800,28 +822,33 @@ import { deviceReName } from '../../api/common';
|
|||||||
|
|
||||||
|
|
||||||
console.log("dataView.length=" + dataView.byteLength)
|
console.log("dataView.length=" + dataView.byteLength)
|
||||||
// 发送数据包
|
|
||||||
ble.LinkBlue(these.device.deviceId, () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
ble.sendData(these.device.deviceId, buffer).then(() => {
|
|
||||||
// 更新进度
|
|
||||||
console.log(
|
|
||||||
`发送文字数据包 ${currentPacket}/${totalPackets}: ${text}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// 发送下一个包
|
let f = these.getDevice();
|
||||||
currentPacket++;
|
if (f) {
|
||||||
setTimeout(sendNextPacket, 100);
|
// 发送数据包
|
||||||
}).catch(err => {
|
ble.LinkBlue(f.deviceId, () => {
|
||||||
// this.isSendingText = false;
|
setTimeout(() => {
|
||||||
uni.showToast({
|
ble.sendDataNew(f.deviceId, f.writeServiceId, f
|
||||||
title: '文字发送失败',
|
.wirteCharactId, buffer).then(() => {
|
||||||
icon: 'none'
|
// 更新进度
|
||||||
|
console.log(
|
||||||
|
`发送文字数据包 ${currentPacket}/${totalPackets}: ${text}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// 发送下一个包
|
||||||
|
currentPacket++;
|
||||||
|
setTimeout(sendNextPacket, 100);
|
||||||
|
}).catch(err => {
|
||||||
|
// this.isSendingText = false;
|
||||||
|
uni.showToast({
|
||||||
|
title: '文字发送失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}, 0);
|
||||||
}, 0);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// }).catch(err => {
|
// }).catch(err => {
|
||||||
// this.isSendingText = false;
|
// this.isSendingText = false;
|
||||||
@ -868,41 +895,43 @@ import { deviceReName } from '../../api/common';
|
|||||||
dataView.setUint8(3, 0x00); // 数据长度
|
dataView.setUint8(3, 0x00); // 数据长度
|
||||||
dataView.setUint8(4, 0x01); // 数据长度
|
dataView.setUint8(4, 0x01); // 数据长度
|
||||||
dataView.setUint8(5, data); // 数据
|
dataView.setUint8(5, data); // 数据
|
||||||
|
let f = this.getDevice();
|
||||||
|
if (f) {
|
||||||
|
// 发送数据
|
||||||
|
ble.LinkBlue(f.deviceId, () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
ble.sendDataNew(f.deviceId, f.writeServiceId, f.wirteCharactId, buffer);
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
// 发送数据
|
});
|
||||||
ble.LinkBlue(this.device.deviceId, () => {
|
}
|
||||||
setTimeout(() => {
|
|
||||||
ble.sendData(this.device.deviceId, buffer);
|
|
||||||
}, 1000)
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
},
|
||||||
//获取当前设备状态
|
//获取当前设备状态
|
||||||
GetDeviceStatu:function(){
|
GetDeviceStatu: function() {
|
||||||
//数据头 命令码 数据 校验码
|
//数据头 命令码 数据 校验码
|
||||||
//JQOC 0B 00 9C41
|
//JQOC 0B 00 9C41
|
||||||
|
|
||||||
//硬件响应
|
//硬件响应
|
||||||
//数据头 命令码 主灯模式 副灯模式 亮度(%) 电量(%) 充电状态 校验码
|
//数据头 命令码 主灯模式 副灯模式 亮度(%) 电量(%) 充电状态 校验码
|
||||||
//JQOC 0B 01 01 64 85 01 9C41
|
//JQOC 0B 01 01 64 85 01 9C41
|
||||||
this.sendCmd('0x0B');
|
this.sendCmd('0x0B');
|
||||||
},
|
},
|
||||||
//设备重启
|
//设备重启
|
||||||
DeviceReStart:function(){
|
DeviceReStart: function() {
|
||||||
//数据头 命令码 数据 校验码
|
//数据头 命令码 数据 校验码
|
||||||
//JQOC 0C 01 9C412
|
//JQOC 0C 01 9C412
|
||||||
this.sendCmd('0x0C');
|
this.sendCmd('0x0C');
|
||||||
},
|
},
|
||||||
//恢复出厂设置
|
//恢复出厂设置
|
||||||
DeviceReSet:function(){
|
DeviceReSet: function() {
|
||||||
//数据头 命令码 数据 校验码
|
//数据头 命令码 数据 校验码
|
||||||
//JQOC 0D 01 9C412
|
//JQOC 0D 01 9C412
|
||||||
this.sendCmd('0x0D');
|
this.sendCmd('0x0D');
|
||||||
},
|
},
|
||||||
sendCmd:function(type,callback){
|
sendCmd: function(type, callback) {
|
||||||
//数据头 命令码 数据 校验码
|
//数据头 命令码 数据 校验码
|
||||||
|
|
||||||
const buffer = new ArrayBuffer(7);
|
const buffer = new ArrayBuffer(7);
|
||||||
const dataView = new DataView(buffer);
|
const dataView = new DataView(buffer);
|
||||||
let data = '0x' + parseInt(this.formData.liangDu).toString(16);
|
let data = '0x' + parseInt(this.formData.liangDu).toString(16);
|
||||||
@ -911,16 +940,19 @@ import { deviceReName } from '../../api/common';
|
|||||||
dataView.setUint8(1, type); // 帧类型:亮度调节
|
dataView.setUint8(1, type); // 帧类型:亮度调节
|
||||||
dataView.setUint8(2, '0x01'); // 包序号
|
dataView.setUint8(2, '0x01'); // 包序号
|
||||||
dataView.setUint8(3, '9C41'); // 数据长度
|
dataView.setUint8(3, '9C41'); // 数据长度
|
||||||
|
let f = this.getDevice();
|
||||||
// 发送数据
|
if (f) {
|
||||||
ble.LinkBlue(this.device.deviceId, () => {
|
// 发送数据
|
||||||
setTimeout(() => {
|
ble.LinkBlue(f.deviceId, () => {
|
||||||
ble.sendData(this.device.deviceId, buffer);
|
setTimeout(() => {
|
||||||
}, 100)
|
ble.sendDataNew(f.deviceId, f.writeServiceId, f.wirteCharactId, buffer);
|
||||||
});
|
}, 100)
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
1813
pages/650/HBY650.vue
Normal file
1813
pages/650/HBY650.vue
Normal file
File diff suppressed because it is too large
Load Diff
@ -357,7 +357,7 @@
|
|||||||
|
|
||||||
if (item.typeName == '6155') {
|
if (item.typeName == '6155') {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/6155/deviceDetail",
|
url: "/pages/650/HBY650",
|
||||||
events: {
|
events: {
|
||||||
ack: function(data) {
|
ack: function(data) {
|
||||||
|
|
||||||
|
|||||||
BIN
static/images/6155/DeviceDetail/Hby650.png
Normal file
BIN
static/images/6155/DeviceDetail/Hby650.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@ -125,7 +125,7 @@ String.prototype.transFloat = function() {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
if (uni.getSystemInfoSync().platform){
|
if (uni.getSystemInfoSync().platform.toLowerCase()=='android' || uni.getSystemInfoSync().platform.toLowerCase()=='ios'){
|
||||||
uni.onBluetoothAdapterStateChange(function(res) {
|
uni.onBluetoothAdapterStateChange(function(res) {
|
||||||
if (!res.available) {
|
if (!res.available) {
|
||||||
isOpen = false
|
isOpen = false
|
||||||
|
|||||||
@ -1,13 +1,8 @@
|
|||||||
|
|
||||||
var isReady=false;var onReadyCallbacks=[];
|
var isReady=false;var onReadyCallbacks=[];
|
||||||
var isServiceReady=false;var onServiceReadyCallbacks=[];
|
var isServiceReady=false;var onServiceReadyCallbacks=[];
|
||||||
<<<<<<< HEAD
|
var __uniConfig = {"pages":["pages/650/HBY650","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/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"],"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.75","entryPagePath":"pages/650/HBY650","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
|
||||||
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/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"],"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.75","entryPagePath":"pages/common/login/index","networkTimeout":{"request":60000,"connectSocket":60000,"uploadFile":60000,"downloadFile":60000}};
|
var __uniRoutes = [{"path":"/pages/650/HBY650","meta":{"isQuit":true},"window":{"navigationBarTitleText":"HBY650"}},{"path":"/pages/common/login/index","meta":{},"window":{"navigationStyle":"custom"}},{"path":"/pages/common/index/index","meta":{"isQuit":true,"isTabBar":true},"window":{"navigationStyle":"custom"}},{"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/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":"地图"}}];
|
||||||
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"}},{"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/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}}];
|
|
||||||
=======
|
|
||||||
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/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"],"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.64","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"}},{"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/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":"地图"}}];
|
|
||||||
>>>>>>> 56f05e7eec738c788fc1d3cd6bcfcf9aacde170c
|
|
||||||
__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.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()})}});
|
__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}}}});
|
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}}}});
|
||||||
|
|||||||
7945
unpackage/dist/dev/app-plus/app-service.js
vendored
7945
unpackage/dist/dev/app-plus/app-service.js
vendored
File diff suppressed because one or more lines are too long
7717
unpackage/dist/dev/app-plus/app-view.js
vendored
7717
unpackage/dist/dev/app-plus/app-view.js
vendored
File diff suppressed because one or more lines are too long
122
utils/gbk.js
Normal file
122
utils/gbk.js
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
const BASE_URL = 'http://192.168.2.34:8000';
|
const BASE_URL = 'http://192.168.110.54:8000';
|
||||||
const request = (options) => {
|
const request = (options) => {
|
||||||
console.log("options"+JSON.stringify(options))
|
console.log("options"+JSON.stringify(options))
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -19,9 +19,11 @@ const request = (options) => {
|
|||||||
header: options.header || {},
|
header: options.header || {},
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
|
console.log("请求成功",res);
|
||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
|
console.log("请求失败",err);
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user