|
@@ -22,17 +22,17 @@ var FlagOpenControl = false;
|
|
|
//2021年11月10日14:59:38
|
|
|
// 0为旧 1为新
|
|
|
var services = [
|
|
|
- "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
|
|
|
- "0000fff0-0000-1000-8000-00805f9b34fb"
|
|
|
+ "6e400001-b5a3-f393-e0a9-e50e24dcca9e".toUpperCase(),
|
|
|
+ "0000fff0-0000-1000-8000-00805f9b34fb".toUpperCase()
|
|
|
]
|
|
|
var charateristics = [
|
|
|
{
|
|
|
- notify: "6e400003-b5a3-f393-e0a9-e50e24dcca9e",
|
|
|
- write: "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
|
|
|
+ notify: "6e400003-b5a3-f393-e0a9-e50e24dcca9e".toUpperCase(),
|
|
|
+ write: "6e400002-b5a3-f393-e0a9-e50e24dcca9e".toUpperCase()
|
|
|
},
|
|
|
{
|
|
|
- notify: "0000fff1-0000-1000-8000-00805f9b34fb",
|
|
|
- write: "0000fff2-0000-1000-8000-00805f9b34fb"
|
|
|
+ notify: "0000fff1-0000-1000-8000-00805f9b34fb".toUpperCase(),
|
|
|
+ write: "0000fff2-0000-1000-8000-00805f9b34fb".toUpperCase()
|
|
|
},
|
|
|
]
|
|
|
|
|
@@ -42,9 +42,9 @@ function getServicesAndCharateristc() {
|
|
|
let $deviceId = game_store.getters.getDeviceId();
|
|
|
let $index = $brainSn.toUpperCase().indexOf("JELLYFISH") != -1 ? 0 : 1;
|
|
|
return {
|
|
|
- deviceId:$deviceId,
|
|
|
- service:services[$index],
|
|
|
- charateristic:charateristics[$index]
|
|
|
+ deviceId: $deviceId,
|
|
|
+ service: services[$index],
|
|
|
+ charateristic: charateristics[$index]
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -274,83 +274,72 @@ export default {
|
|
|
},
|
|
|
|
|
|
// //获取蓝牙设备服务
|
|
|
- // getBLEDeviceServices(deviceId) {
|
|
|
- // const $this = this;
|
|
|
- // current_device_mac = deviceId
|
|
|
- // wx.getBLEDeviceServices({
|
|
|
- // deviceId,
|
|
|
- // success: (res) => {
|
|
|
- // for (let i = 0; i < res.services.length; i++) {
|
|
|
- // console.log("serviceItem:" + res.services[i].uuid);
|
|
|
- // if (res.services[i].uuid.indexOf('6E') != -1 || res.services[i].uuid.indexOf('0000FFF0') != -1) {
|
|
|
- // console.log("SelectedServiceItem:" + res.services[i].uuid);
|
|
|
- // $this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid);
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // },
|
|
|
- // fail(res) {
|
|
|
- // console.log("连接蓝牙成功,获取服务失败");
|
|
|
- // },
|
|
|
- // });
|
|
|
- // },
|
|
|
- //
|
|
|
- // //获取蓝牙设备某个服务中所有特征值
|
|
|
- // getBLEDeviceCharacteristics(deviceId, serviceId) {
|
|
|
- // console.log(deviceId, serviceId);
|
|
|
- // const $this = this;
|
|
|
- // wx.getBLEDeviceCharacteristics({
|
|
|
- // deviceId,
|
|
|
- // serviceId,
|
|
|
- // success: (res) => {
|
|
|
- // console.log("getBLEDeviceCharacteristics success", res.characteristics);
|
|
|
- // for (let i = 0; i < res.characteristics.length; i++) {
|
|
|
- // let item = res.characteristics[i];
|
|
|
- // if (item.properties.read) {
|
|
|
- // wx.readBLECharacteristicValue({
|
|
|
- // deviceId,
|
|
|
- // serviceId,
|
|
|
- // characteristicId: item.uuid,
|
|
|
- // });
|
|
|
- // }
|
|
|
- // if (item.properties.write) {
|
|
|
- // $this.deviceId = deviceId;
|
|
|
- // $this.serviceId = serviceId;
|
|
|
- // $this.cid = item.uuid;
|
|
|
- // game_store.setters.setDeviceId(deviceId);
|
|
|
- // game_store.setters.setServiceId(serviceId);
|
|
|
- // game_store.setters.setCid(item.uuid);
|
|
|
- // //打开数据帧
|
|
|
- // $this.sendOpenBigData();
|
|
|
- // }
|
|
|
- //
|
|
|
- // if (item.properties.notify || item.properties.indicate) {
|
|
|
- // wx.notifyBLECharacteristicValueChange({
|
|
|
- // deviceId,
|
|
|
- // serviceId,
|
|
|
- // characteristicId: item.uuid,
|
|
|
- // state: true,
|
|
|
- // });
|
|
|
- // game_store.setters.setReadCid(item.uuid);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // },
|
|
|
- // fail(res) {
|
|
|
- // console.error("getBLEDeviceCharacteristics", res);
|
|
|
- // },
|
|
|
- // });
|
|
|
- // },
|
|
|
-
|
|
|
- openNotify($this){
|
|
|
+ getBLEDeviceServices(deviceId) {
|
|
|
+ const that = this;
|
|
|
+ current_device_mac = deviceId
|
|
|
+ wx.getBLEDeviceServices({
|
|
|
+ deviceId,
|
|
|
+ success: (res) => {
|
|
|
+ for (let i = 0; i < res.services.length; i++) {
|
|
|
+ console.log("serviceItem:" + res.services[i].uuid);
|
|
|
+ if (res.services[i].uuid.indexOf('6E') != -1 || res.services[i].uuid.indexOf('0000FFF0') != -1) {
|
|
|
+ console.log("SelectedServiceItem:" + res.services[i].uuid);
|
|
|
+ that.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.log("连接蓝牙成功,获取服务失败");
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ //获取蓝牙设备某个服务中所有特征值
|
|
|
+ getBLEDeviceCharacteristics(deviceId, serviceId) {
|
|
|
+ console.log(deviceId, serviceId);
|
|
|
+ const $this = this;
|
|
|
+ wx.getBLEDeviceCharacteristics({
|
|
|
+ deviceId,
|
|
|
+ serviceId,
|
|
|
+ success: (res) => {
|
|
|
+ console.log("getBLEDeviceCharacteristics success", res.characteristics);
|
|
|
+ for (let i = 0; i < res.characteristics.length; i++) {
|
|
|
+ let item = res.characteristics[i];
|
|
|
+ if (item.properties.write) {
|
|
|
+ $this.deviceId = deviceId;
|
|
|
+ $this.serviceId = serviceId;
|
|
|
+ $this.cid = item.uuid;
|
|
|
+ //打开数据帧
|
|
|
+ $this.sendOpenBigData();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.properties.notify || item.properties.indicate) {
|
|
|
+ wx.notifyBLECharacteristicValueChange({
|
|
|
+ deviceId,
|
|
|
+ serviceId,
|
|
|
+ characteristicId: item.uuid,
|
|
|
+ state: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ console.error("getBLEDeviceCharacteristics", res);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ openNotify($this) {
|
|
|
let that = this;
|
|
|
let $deviceInfo = getServicesAndCharateristc();
|
|
|
console.log($deviceInfo)
|
|
|
wx.notifyBLECharacteristicValueChange({
|
|
|
- deviceId:$deviceInfo.deviceId,
|
|
|
- serviceId:$deviceInfo.service,
|
|
|
+ deviceId: $deviceInfo.deviceId,
|
|
|
+ serviceId: $deviceInfo.service,
|
|
|
characteristicId: $deviceInfo.charateristic.notify,
|
|
|
state: true,
|
|
|
- success(){
|
|
|
+ success() {
|
|
|
that.watchingDevice($this)
|
|
|
that.sendOpenBigData();
|
|
|
}
|
|
@@ -374,9 +363,18 @@ export default {
|
|
|
const that = this;
|
|
|
wx.onBLECharacteristicValueChange((characteristic) => {
|
|
|
let hexStr = that.ab2hex(characteristic.value);
|
|
|
- if (hexStr.toUpperCase().indexOf("AADD") != -1) {
|
|
|
- console.log(hexStr);
|
|
|
- }
|
|
|
+
|
|
|
+ wx.getSystemInfo({
|
|
|
+ success(res) {
|
|
|
+ if (res.platform == "ios") {
|
|
|
+ console.log(hexStr)
|
|
|
+ } else {
|
|
|
+ if (hexStr.toUpperCase().indexOf("AADD") != -1) {
|
|
|
+ console.log(hexStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
let $data = that.get_big_data(hexStr);
|
|
|
let $game_status = game_store.getters.getGameStatus();
|
|
|
|
|
@@ -631,6 +629,7 @@ export default {
|
|
|
return $errmsg;
|
|
|
},
|
|
|
//写入buffer
|
|
|
+
|
|
|
WriteBufferInBle($hex, $buffer_len = 8) {
|
|
|
let $deviceInfo = getServicesAndCharateristc();
|
|
|
let $hex_header = "aa cc ";
|
|
@@ -662,7 +661,7 @@ export default {
|
|
|
},
|
|
|
fail: function (err) {
|
|
|
console.log($hex + "写入失败");
|
|
|
- console.log(err);
|
|
|
+ console.log(err,$deviceInfo);
|
|
|
},
|
|
|
});
|
|
|
},
|