|
@@ -424,7 +424,6 @@ class Manager {
|
|
|
var that = this;
|
|
|
const time_util = require('./../../utils/time_util');
|
|
|
var characteristics = res.characteristics;
|
|
|
- console.log("gadsfasdfadfaf===啊啊啊啊==" + JSON.stringify(characteristics));
|
|
|
if (characteristics.length <= 0) {
|
|
|
failed();
|
|
|
return;
|
|
@@ -479,8 +478,6 @@ class Manager {
|
|
|
|
|
|
// 监听特征值变化
|
|
|
monitorCharacteristicValueChange(device, serviceId, notifyCharaterId) {
|
|
|
- console.log("gadsfasdfadfaf===wwww==" + device.deviceId + "===" + serviceId +
|
|
|
- "===" + notifyCharaterId);
|
|
|
return new Promise((resolve, reject) => {
|
|
|
var deviceId = device.deviceId;
|
|
|
wx.notifyBLECharacteristicValueChange({
|
|
@@ -489,12 +486,10 @@ class Manager {
|
|
|
serviceId: serviceId,
|
|
|
characteristicId: notifyCharaterId,
|
|
|
success: function (res) {
|
|
|
- console.log("啊是的发生的发生等份===cccc==" + JSON.stringify(res));
|
|
|
resolve(true);
|
|
|
},
|
|
|
///{"errno":1500104,"errMsg":"notifyBLECharacteristicValueChange:fail:no descriptor"}
|
|
|
fail: function (res) {
|
|
|
- console.log("啊是的发生的发生等份===dddd==" + JSON.stringify(res));
|
|
|
resolve(false);
|
|
|
}
|
|
|
});
|
|
@@ -504,15 +499,17 @@ class Manager {
|
|
|
///收取到的数据转换为文字
|
|
|
onBLECharacteristicValueChange(callback) {
|
|
|
wx.onBLECharacteristicValueChange(function (characteristic) {
|
|
|
- console.log("gadsfasdfadfaf===666==" + JSON.stringify(r));
|
|
|
- var receiveText = hex_util.buf2string(characteristic);
|
|
|
- console.log("gadsfasdfadfaf===777==" + receiveText);
|
|
|
+ //characteristic: {"value":{},"deviceId":"22:10:14:95:F0:1E","serviceId":"0000FFE5-0000-1000-8000-00805F9B34FB","characteristicId":"0000FFE5-0001-1000-8000-00805F9B34FB"}
|
|
|
+ // const hex_util = require('../hex_util');
|
|
|
+ // var receiveText = hex_util.buf2string(characteristic);
|
|
|
let buffer = characteristic.value
|
|
|
let dataView = new DataView(buffer)
|
|
|
let dataResult = []
|
|
|
for (let i = 0; i < dataView.byteLength; i++) {
|
|
|
dataResult.push(dataView.getUint8(i))
|
|
|
}
|
|
|
+ ///109,113,116,116
|
|
|
+ ///114,101,99,118,95,102,105,110,105,115,104
|
|
|
callback(dataResult);
|
|
|
});
|
|
|
}
|
|
@@ -535,30 +532,17 @@ class Manager {
|
|
|
|
|
|
///发送数据
|
|
|
sendData(device, data) {
|
|
|
+ var that = this;
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- var that = this;
|
|
|
- var length = data.length;
|
|
|
- console.log("gadsfasdfadfaf===hhh==" + length + "===" + data);
|
|
|
- var buffer = new ArrayBuffer(length);
|
|
|
+ var buffer = new ArrayBuffer(data.length);
|
|
|
// 下面是赋值,不能删
|
|
|
const dataView = new DataView(buffer);
|
|
|
- for (var i = 0; i < length; i++) {
|
|
|
- // console.log("gadsfasdfadfaf===iii==" + i + "===" + data[i]);
|
|
|
- dataView.setUint8(i, data[i]);
|
|
|
- }
|
|
|
- // data.forEach((value, index) => {
|
|
|
- // dataView.setUint8(index, value); // 将每个16进制数值写入到 buffer 中
|
|
|
- // });
|
|
|
-
|
|
|
-
|
|
|
- console.log("gadsfasdfadfaf===ccc==" + that.writeServiceId);
|
|
|
- console.log("gadsfasdfadfaf===ddd==" + that.writeCharaterId);
|
|
|
- console.log("gadsfasdfadfaf===eee==" + buffer);
|
|
|
+ // 将每个16进制数值写入到 buffer 中
|
|
|
+ data.forEach((value, index) => {
|
|
|
+ dataView.setUint8(index, value);
|
|
|
+ });
|
|
|
|
|
|
- // serviceId: that.publicDevice.serviceId, //服务通道,这里主要是notify
|
|
|
- // characteristicId: characteristicId, //notify uuid
|
|
|
var deviceId = device.deviceId;
|
|
|
- console.log("gadsfasdfadfaf===bbb==" + deviceId);
|
|
|
wx.writeBLECharacteristicValue({
|
|
|
deviceId: deviceId,
|
|
|
serviceId: that.writeServiceId,
|
|
@@ -589,7 +573,6 @@ module.exports = Manager;
|
|
|
// var notifyCharaterId = "";
|
|
|
// var notifyServiceId = "";
|
|
|
|
|
|
-// console.log("gadsfasdfadfaf===xxxx==" + JSON.stringify(res.characteristics));
|
|
|
// for (var i = 0; i < res.characteristics.length; i++) {
|
|
|
// var properties = res.characteristics[i].properties;
|
|
|
// var charaterId = res.characteristics[i].uuid;
|
|
@@ -598,9 +581,6 @@ module.exports = Manager;
|
|
|
// if (properties.notify) {
|
|
|
// notifyCharaterId = charaterId;
|
|
|
// notifyServiceId = services[index].uuid;
|
|
|
-// console.log("gadsfasdfadfaf===xxxx==" + properties.write);
|
|
|
-// console.log("gadsfasdfadfaf===yyy==" + properties.writeWithoutResponse);
|
|
|
-// console.log("gadsfasdfadfaf===zzz==" + JSON.stringify(res.characteristics[i]));
|
|
|
// notify = true;
|
|
|
// }
|
|
|
// }
|
|
@@ -626,7 +606,6 @@ module.exports = Manager;
|
|
|
// if (index == services.length) {
|
|
|
// fail();
|
|
|
// } else {
|
|
|
-// console.log("gadsfasdfadfaf===yyy==");
|
|
|
// that.getCharacteristics(device, services, index, notify, write, read, succeed, fail);
|
|
|
// }
|
|
|
// } else {
|