|
|
|
|
@ -8,7 +8,10 @@ import DeviceConnectPopup from "../device-connection-popup/device-connection-pop
|
|
|
|
|
|
|
|
|
|
/*** redux ***/
|
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import { setBluetoothInfo } from "../../../store/features/deviceInfo";
|
|
|
|
|
import {
|
|
|
|
|
setBluetoothInfo,
|
|
|
|
|
setDeviceId,
|
|
|
|
|
} from "../../../store/features/deviceInfo";
|
|
|
|
|
/*** redux end ***/
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
@ -47,7 +50,7 @@ import { DeviceToolKit as DeviceToolKitFR200 } from "@flossom-npm/iot-translater
|
|
|
|
|
import { showModal, msg } from "@/utils/traoAPI";
|
|
|
|
|
|
|
|
|
|
// const { InstrumentTypeEnum, OtaDeviceTypeEnum } = app.globalData;
|
|
|
|
|
import InstrumentTypeEnum from "../instrumentTypeEnum";
|
|
|
|
|
import InstrumentTypeEnum from "../InstrumentTypeEnum";
|
|
|
|
|
import OtaDeviceTypeEnum from "../OtaDeviceTypeEnum";
|
|
|
|
|
|
|
|
|
|
let isGetVersionTimer: any = null;
|
|
|
|
|
@ -67,7 +70,7 @@ let searchBluetootTimersNum = 0; // 搜索蓝牙秒数
|
|
|
|
|
let connectionTimer: any = null; // 连接蓝牙定时器
|
|
|
|
|
let connectionTimerNum = 0;
|
|
|
|
|
|
|
|
|
|
let sendPairingTimer: any = null;
|
|
|
|
|
let sendPairingTimer: any = null; // 发送配对
|
|
|
|
|
|
|
|
|
|
import "./index.less";
|
|
|
|
|
|
|
|
|
|
@ -143,7 +146,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
/** 开始连接 */
|
|
|
|
|
connection() {
|
|
|
|
|
this.setState({
|
|
|
|
|
isConnection: true,
|
|
|
|
|
isConnection: false,
|
|
|
|
|
});
|
|
|
|
|
//初始化 蓝牙连接
|
|
|
|
|
this.bluetoothInit();
|
|
|
|
|
@ -210,7 +213,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
openBluetoothAdapter() {
|
|
|
|
|
openBluetoothAdapter()
|
|
|
|
|
.then((res) => {
|
|
|
|
|
console.info("openBluetoothAdapter res value =>", res);
|
|
|
|
|
console.log("openBluetoothAdapter res value =>", res);
|
|
|
|
|
let { errno, errMsg } = res;
|
|
|
|
|
if (errno == 0) {
|
|
|
|
|
this.startBluetoothDevicesDiscovery();
|
|
|
|
|
@ -233,7 +236,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
this.close();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.info("openBluetoothAdapter err value => ", err);
|
|
|
|
|
console.log("openBluetoothAdapter err value => ", err);
|
|
|
|
|
this.failErrorCode(errno, errMsg);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@ -295,7 +298,9 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
// };
|
|
|
|
|
// let type = this.props.yiqiInfo.model || "FR200";
|
|
|
|
|
let type = "WE200";
|
|
|
|
|
// console.info('搜索到到蓝牙设备 value => ', item.devices[0]?.name)
|
|
|
|
|
// this.props.yiqiInfo.model = type;
|
|
|
|
|
console.log("this.props.yiqiInfo.model", this.props.yiqiInfo.model);
|
|
|
|
|
console.info("搜索到到蓝牙设备 value => ", item.devices[0]?.name);
|
|
|
|
|
for (let i = 0; i < item.devices.length; i++) {
|
|
|
|
|
if (
|
|
|
|
|
item.devices[i].connectable &&
|
|
|
|
|
@ -304,12 +309,18 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
: item.devices[i].name
|
|
|
|
|
).indexOf(`${type}`) !== -1
|
|
|
|
|
) {
|
|
|
|
|
console.info("连接的设备信息", item.devices[i], type);
|
|
|
|
|
console.log("连接的设备信息", item.devices[i], type);
|
|
|
|
|
let params = {
|
|
|
|
|
deviceId: item.devices[i].deviceId,
|
|
|
|
|
};
|
|
|
|
|
this.props.setDeviceId(params);
|
|
|
|
|
|
|
|
|
|
clearInterval(searchBluetootTimers);
|
|
|
|
|
Taro.stopBluetoothDevicesDiscovery(); //停止搜索蓝牙
|
|
|
|
|
// app.globalData.deviceInfo.deviceId = item.devices[i].deviceId;
|
|
|
|
|
this.createBLEConnection();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
clearInterval(searchBluetootTimers);
|
|
|
|
|
Taro.stopBluetoothDevicesDiscovery(); //停止搜索蓝牙
|
|
|
|
|
// app.globalData.deviceInfo.deviceId = item.devices[i].deviceId;
|
|
|
|
|
this.createBLEConnection();
|
|
|
|
|
}, 10);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -319,21 +330,23 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
/** 5.新建蓝牙连接 */
|
|
|
|
|
async createBLEConnection() {
|
|
|
|
|
console.log("========新建蓝牙连接========");
|
|
|
|
|
this.setState({ isConnection: true }); // 开始蓝牙连接
|
|
|
|
|
try {
|
|
|
|
|
await closeBLEConnection(this.props.bluetoothInfo.deviceId);
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
clearTimeout(connectionTimer);
|
|
|
|
|
const { yiqiInfo: deviceInfo } = this.props;
|
|
|
|
|
console.log(
|
|
|
|
|
"this.props.bluetoothInfo.deviceId",
|
|
|
|
|
this.props.bluetoothInfo.deviceId
|
|
|
|
|
);
|
|
|
|
|
/*********开始主动连接*******/
|
|
|
|
|
createBLEConnection(this.props.bluetoothInfo.deviceId)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
console.log("createBLEConnection", res);
|
|
|
|
|
let { errno, errMsg } = res;
|
|
|
|
|
if (errno == 0) {
|
|
|
|
|
if (
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.FR200 ||
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.FR380 ||
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.FR390
|
|
|
|
|
) {
|
|
|
|
|
if (deviceInfo.model === "WL200") {
|
|
|
|
|
this.setState({
|
|
|
|
|
connectionStatus: true,
|
|
|
|
|
});
|
|
|
|
|
@ -358,24 +371,35 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
|
|
|
|
|
/** 6.获取蓝牙特征值 */
|
|
|
|
|
getBLEDeviceServices() {
|
|
|
|
|
console.log("========6.获取蓝牙特征值========");
|
|
|
|
|
getBLEDeviceServices(this.props.bluetoothInfo.deviceId)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
let bluetoothInfo = this.props.bluetoothInfo;
|
|
|
|
|
bluetoothInfo.servicesuuid = res.servicesuuid;
|
|
|
|
|
bluetoothInfo.characteristicsuuid1 = res.characteristicsuuid1;
|
|
|
|
|
bluetoothInfo.characteristicsuuid0 = res.characteristicsuuid0;
|
|
|
|
|
this.props.setBluetoothInfo(bluetoothInfo);
|
|
|
|
|
this.notifyBLECharacteristicValueChange();
|
|
|
|
|
console.log("特征值", res);
|
|
|
|
|
let params = {
|
|
|
|
|
deviceId: this.props.bluetoothInfo.deviceId,
|
|
|
|
|
servicesuuid: res.servicesuuid,
|
|
|
|
|
characteristicsuuid1: res.characteristicsuuid1,
|
|
|
|
|
characteristicsuuid0: res.characteristicsuuid0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
console.log("getBLEDeviceServices", params);
|
|
|
|
|
// 获取并修改蓝牙特征值
|
|
|
|
|
this.props.setBluetoothInfo(params);
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.notifyBLECharacteristicValueChange();
|
|
|
|
|
}, 10);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
let { errno, errMsg } = err;
|
|
|
|
|
console.info("getBLEDeviceServices error =>", err);
|
|
|
|
|
console.log("getBLEDeviceServices error =>", err);
|
|
|
|
|
this.failErrorCode(errno, errMsg);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 7.通知BLE特征值更改 */
|
|
|
|
|
notifyBLECharacteristicValueChange() {
|
|
|
|
|
console.log("7.通知BLE特征值更改");
|
|
|
|
|
const { yiqiInfo: deviceInfo } = this.props;
|
|
|
|
|
const bluetoothInfo = this.props.bluetoothInfo;
|
|
|
|
|
notifyBLECharacteristicValueChange({
|
|
|
|
|
@ -387,240 +411,145 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
.then((ress) => {
|
|
|
|
|
let { errno, errMsg } = ress;
|
|
|
|
|
if (errno == 0) {
|
|
|
|
|
// 订阅特征码变化
|
|
|
|
|
Taro.onBLECharacteristicValueChange((value) => {
|
|
|
|
|
console.info("onBLECharacteristicValueChange value => ", value);
|
|
|
|
|
// 配对成功进入?
|
|
|
|
|
console.log("onBLECharacteristicValueChange value => ", value);
|
|
|
|
|
let str = ab2hex(value.value); //转为16进制字符串
|
|
|
|
|
console.log("转为16进制字符串 str", str);
|
|
|
|
|
let connectionStatus = [
|
|
|
|
|
InstrumentTypeEnum.FR200,
|
|
|
|
|
InstrumentTypeEnum.WL200,
|
|
|
|
|
InstrumentTypeEnum.FR380,
|
|
|
|
|
InstrumentTypeEnum.FR390,
|
|
|
|
|
InstrumentTypeEnum.M01,
|
|
|
|
|
].includes(Number(deviceInfo.type));
|
|
|
|
|
const isFRDevice = [
|
|
|
|
|
InstrumentTypeEnum.FR200,
|
|
|
|
|
InstrumentTypeEnum.FR380,
|
|
|
|
|
InstrumentTypeEnum.FR390,
|
|
|
|
|
].includes(Number(deviceInfo.type));
|
|
|
|
|
if (isFRDevice) {
|
|
|
|
|
this.setState({
|
|
|
|
|
connectionStatus,
|
|
|
|
|
});
|
|
|
|
|
log.info(
|
|
|
|
|
commandMap.reciviedBLECommand,
|
|
|
|
|
`仪器类型: ${deviceInfo.type}`,
|
|
|
|
|
value
|
|
|
|
|
);
|
|
|
|
|
filterBleData(str).forEach((item) => {
|
|
|
|
|
console.log("设备响应数据===》", item);
|
|
|
|
|
if (item.indexOf(`dbf0a8010155`) !== -1) {
|
|
|
|
|
//配对成功
|
|
|
|
|
log.info("蓝牙配对成功");
|
|
|
|
|
clearInterval(sendPairingTimer);
|
|
|
|
|
this.setState({ islian: true });
|
|
|
|
|
|
|
|
|
|
console.log("获取设备版本号");
|
|
|
|
|
this.sendGetVersion();
|
|
|
|
|
sendgetversionTimer = setInterval(() => {
|
|
|
|
|
this.sendGetVersion();
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
"FR200",
|
|
|
|
|
"WL200",
|
|
|
|
|
"FR380",
|
|
|
|
|
"FR390",
|
|
|
|
|
"M01",
|
|
|
|
|
].includes(deviceInfo.model);
|
|
|
|
|
|
|
|
|
|
if (item.indexOf("dbf0a0030b") !== -1) {
|
|
|
|
|
// 版本号获取成功
|
|
|
|
|
clearInterval(sendgetversionTimer);
|
|
|
|
|
let v1 = String(hex2int(str.substring(10, 12))).padStart(
|
|
|
|
|
2,
|
|
|
|
|
"0"
|
|
|
|
|
);
|
|
|
|
|
let v2 = String(hex2int(str.substring(12, 14))).padStart(
|
|
|
|
|
2,
|
|
|
|
|
"0"
|
|
|
|
|
);
|
|
|
|
|
let v3 = String(hex2int(str.substring(14, 16))).padStart(
|
|
|
|
|
2,
|
|
|
|
|
"0"
|
|
|
|
|
);
|
|
|
|
|
let versionInfo = {
|
|
|
|
|
v1,
|
|
|
|
|
v2,
|
|
|
|
|
v3,
|
|
|
|
|
version: `${v1}${v2}${v3}`,
|
|
|
|
|
};
|
|
|
|
|
this.setState({ versionInfo });
|
|
|
|
|
console.log("版本号:" + versionInfo.version);
|
|
|
|
|
log.info(
|
|
|
|
|
commandMap.versionInfoCG,
|
|
|
|
|
`connection_guide, ${deviceInfo.type}:${versionInfo.version}`
|
|
|
|
|
);
|
|
|
|
|
if (
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.FR380 ||
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.FR390
|
|
|
|
|
) {
|
|
|
|
|
console.log("跳转护理页");
|
|
|
|
|
// this.triggerEvent("offlineChange", this.state);
|
|
|
|
|
this.offlineChange(this.state);
|
|
|
|
|
} else {
|
|
|
|
|
if (this.state.isgetoffline) {
|
|
|
|
|
// 获取离线记录
|
|
|
|
|
console.log("获取离线记录(总)");
|
|
|
|
|
this.sendofflistSummary();
|
|
|
|
|
} else {
|
|
|
|
|
console.log("跳转护理页");
|
|
|
|
|
// that.triggerEvent("offlineChange", this.state);
|
|
|
|
|
this.offlineChange(this.state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.indexOf("dbf0a0020b") !== -1) {
|
|
|
|
|
//离线护理记录(总)获取成功
|
|
|
|
|
// 先获取记录总条数,再获取详细
|
|
|
|
|
console.log("获取离线记录总条数====>", item);
|
|
|
|
|
log.info(
|
|
|
|
|
commandMap.finishOfflineData,
|
|
|
|
|
`接收到总的离线记录=》${item}`
|
|
|
|
|
);
|
|
|
|
|
// this.state.offlineDataindex =
|
|
|
|
|
// 7 || Number(item.substring(24, 2));
|
|
|
|
|
let offlineDataindex = 7 || Number(item.substring(24, 2));
|
|
|
|
|
this.setState({ offlineDataindex });
|
|
|
|
|
if (this.state.offlineDataindex > 0) {
|
|
|
|
|
this.sendofflist();
|
|
|
|
|
} else {
|
|
|
|
|
// this.triggerEvent("offlineChange", that.data);
|
|
|
|
|
this.offlineChange(this.state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (item.indexOf("dbf0a00211") !== -1) {
|
|
|
|
|
//设备响应离线护理记录(细)
|
|
|
|
|
log.info(
|
|
|
|
|
commandMap.finishOfflineData,
|
|
|
|
|
"接收到详细离线记录, 准备进入sendofflist"
|
|
|
|
|
);
|
|
|
|
|
this.sendOfflistPost(str);
|
|
|
|
|
this.sendofflist();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.indexOf("dbf0a001006dde") !== -1) {
|
|
|
|
|
// 同步时间
|
|
|
|
|
// that.sendAsyncTime()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
let jsonStatus: any = null;
|
|
|
|
|
let querySubDeviceArrayBuffer;
|
|
|
|
|
if (deviceInfo.type == InstrumentTypeEnum.WL200) {
|
|
|
|
|
// querySubDeviceArrayBuffer = deviceToolKitInstanceWL200.toBleCommand(bleCommandSamples.querySubDevice);
|
|
|
|
|
// jsonStatus = deviceToolKitInstanceWL200.toJsonStatus(value.value);
|
|
|
|
|
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value);
|
|
|
|
|
querySubDeviceArrayBuffer =
|
|
|
|
|
deviceToolKitInstanceM01.toBleCommand(
|
|
|
|
|
bleCommandSamples.querySubDevice as any
|
|
|
|
|
); // todo
|
|
|
|
|
} else if (deviceInfo.type == InstrumentTypeEnum.M01) {
|
|
|
|
|
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value);
|
|
|
|
|
querySubDeviceArrayBuffer =
|
|
|
|
|
deviceToolKitInstanceM01.toBleCommand(
|
|
|
|
|
bleCommandSamples.querySubDevice as any
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
log.info(
|
|
|
|
|
commandMap.reciviedBLECommand,
|
|
|
|
|
`仪器类型: ${deviceInfo.type}`,
|
|
|
|
|
jsonStatus
|
|
|
|
|
let jsonStatus: any = null;
|
|
|
|
|
let querySubDeviceArrayBuffer;
|
|
|
|
|
if (deviceInfo.model == "WL200") {
|
|
|
|
|
// querySubDeviceArrayBuffer =
|
|
|
|
|
// deviceToolKitInstanceWL200.toBleCommand(
|
|
|
|
|
// bleCommandSamples.querySubDevice as any
|
|
|
|
|
// );
|
|
|
|
|
// jsonStatus = deviceToolKitInstanceWL200.toJsonStatus(
|
|
|
|
|
// value.value
|
|
|
|
|
// );
|
|
|
|
|
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value);
|
|
|
|
|
querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand(
|
|
|
|
|
bleCommandSamples.querySubDevice as any
|
|
|
|
|
); // todo
|
|
|
|
|
} else if (deviceInfo.model == "M01") {
|
|
|
|
|
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value);
|
|
|
|
|
querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand(
|
|
|
|
|
bleCommandSamples.querySubDevice as any
|
|
|
|
|
);
|
|
|
|
|
if (jsonStatus?.commandType === "BleMatch") {
|
|
|
|
|
switch (jsonStatus?.bleCommandType) {
|
|
|
|
|
case "SendMatchCode":
|
|
|
|
|
if (jsonStatus.matchedSuccess) {
|
|
|
|
|
console.log("蓝牙配对成功");
|
|
|
|
|
clearInterval(sendPairingTimer);
|
|
|
|
|
if (overTimer) clearTimeout(overTimer);
|
|
|
|
|
if (this.state.connectionSuccess) return;
|
|
|
|
|
this.setState({
|
|
|
|
|
connectionSuccess: true,
|
|
|
|
|
connectionStatus,
|
|
|
|
|
});
|
|
|
|
|
// 暂时不需要查询是否连接子设备, 直接进入查询版本信息
|
|
|
|
|
this.detectVersionUpdate();
|
|
|
|
|
/*if(deviceInfo.type == instrumentTypeEnum.M01) {
|
|
|
|
|
}
|
|
|
|
|
// log.info(
|
|
|
|
|
// commandMap.reciviedBLECommand,
|
|
|
|
|
// `仪器模式: ${deviceInfo.model}`,
|
|
|
|
|
// jsonStatus
|
|
|
|
|
// );
|
|
|
|
|
console.log(
|
|
|
|
|
commandMap.reciviedBLECommand,
|
|
|
|
|
`仪器模式: ${deviceInfo.model}`,
|
|
|
|
|
jsonStatus
|
|
|
|
|
);
|
|
|
|
|
console.log("jsonStatus", jsonStatus);
|
|
|
|
|
if (jsonStatus?.commandType === "BleMatch") {
|
|
|
|
|
switch (jsonStatus?.bleCommandType) {
|
|
|
|
|
case "SendMatchCode":
|
|
|
|
|
if (jsonStatus.matchedSuccess) {
|
|
|
|
|
console.log("BleMatch蓝牙配对成功");
|
|
|
|
|
clearInterval(sendPairingTimer);
|
|
|
|
|
if (overTimer) clearTimeout(overTimer);
|
|
|
|
|
this.setState({
|
|
|
|
|
connectionSuccess: true,
|
|
|
|
|
connectionStatus,
|
|
|
|
|
islian: true, // 不需要离线记录,但暂未完全删除这部分逻辑,所以直接设为true
|
|
|
|
|
});
|
|
|
|
|
// this.detectVersionUpdate(); // 获取升级信息
|
|
|
|
|
// todo 连接成功需删除离线记录,暂时未缓存离线记录
|
|
|
|
|
if (this.state.connectionSuccess) return;
|
|
|
|
|
// 暂时不需要查询是否连接子设备, 直接进入查询版本信息
|
|
|
|
|
// this.detectVersionUpdate();
|
|
|
|
|
/*if(deviceInfo.type == instrumentTypeEnum.M01) {
|
|
|
|
|
this.detectVersionUpdate()
|
|
|
|
|
} else {
|
|
|
|
|
this.sendQuerySubDevice(querySubDeviceArrayBuffer)
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "BleStatusSync":
|
|
|
|
|
if (jsonStatus.connectMessage?.connectType == "CONNECTED") {
|
|
|
|
|
switch (jsonStatus.connectMessage?.deviceName) {
|
|
|
|
|
case OtaDeviceTypeEnum.WE100:
|
|
|
|
|
case OtaDeviceTypeEnum.FACIALMASK:
|
|
|
|
|
console.log("面膜连上了 value => ", jsonStatus);
|
|
|
|
|
this.detectVersionUpdate();
|
|
|
|
|
break;
|
|
|
|
|
case OtaDeviceTypeEnum.WL200:
|
|
|
|
|
console.log("面罩连上了 value => ", jsonStatus);
|
|
|
|
|
this.detectVersionUpdate();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "BleStatusSync":
|
|
|
|
|
if (jsonStatus.connectMessage?.connectType == "CONNECTED") {
|
|
|
|
|
switch (jsonStatus.connectMessage?.deviceName) {
|
|
|
|
|
case OtaDeviceTypeEnum.WE100:
|
|
|
|
|
case OtaDeviceTypeEnum.FACIALMASK:
|
|
|
|
|
console.log("面膜连上了 value => ", jsonStatus);
|
|
|
|
|
this.detectVersionUpdate();
|
|
|
|
|
break;
|
|
|
|
|
case OtaDeviceTypeEnum.WL200:
|
|
|
|
|
console.log("面罩连上了 value => ", jsonStatus);
|
|
|
|
|
this.detectVersionUpdate();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.info("BleStatusSync value => ", jsonStatus);
|
|
|
|
|
break;
|
|
|
|
|
case "QueryMatchStatus":
|
|
|
|
|
console.info("QueryMatchStatus value => ", jsonStatus);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (jsonStatus?.commandType === "InfoQuery") {
|
|
|
|
|
switch (jsonStatus.infoQueryType) {
|
|
|
|
|
case "versionInfo":
|
|
|
|
|
if (this.state.hasVersionInfo) return;
|
|
|
|
|
clearTimeout(isGetVersionTimer);
|
|
|
|
|
this.setState({
|
|
|
|
|
hasVersionInfo: true, // 已返回版本信息
|
|
|
|
|
connectionStatus: true,
|
|
|
|
|
subDeviceConnectedStatus: true,
|
|
|
|
|
synchronousStatus: true,
|
|
|
|
|
});
|
|
|
|
|
const deviceVersionNo = jsonStatus.versionNo;
|
|
|
|
|
const latestVersionNo = deviceInfo.iot_versions;
|
|
|
|
|
// const isNeedToUpdateBl = isNeedToUpdate(deviceVersionNo, latestVersionNo)
|
|
|
|
|
// 判断是否需要升级
|
|
|
|
|
// M01和WL200 不需要在这里进行蓝牙更新
|
|
|
|
|
// if (isNeedToUpdateBl) {
|
|
|
|
|
// const pages = getCurrentPages();
|
|
|
|
|
// const matchPageList = [{
|
|
|
|
|
// route: 'pages/MatrixWL200/pages/index/index'
|
|
|
|
|
// },{
|
|
|
|
|
// route: 'pages/MatrixM01/pages/index/index'
|
|
|
|
|
// }];
|
|
|
|
|
// const hadOpen = checkSameKey(pages, matchPageList, 'route');
|
|
|
|
|
// if (!hadOpen) {
|
|
|
|
|
// this.triggerEvent("pairingChange", { deviceVersionNo });
|
|
|
|
|
this.pairingChange({ deviceVersionNo });
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// this.sendSyncRecording()
|
|
|
|
|
// }
|
|
|
|
|
break;
|
|
|
|
|
case "offlineClockSummary":
|
|
|
|
|
clearTimeout(isGetSyncRecordingTimer);
|
|
|
|
|
if (this.state.hasSyncRecord) return;
|
|
|
|
|
this.setState({
|
|
|
|
|
hasSyncRecord: true,
|
|
|
|
|
synchronousStatus: true,
|
|
|
|
|
});
|
|
|
|
|
console.info("offlineClockSummary value =>", jsonStatus);
|
|
|
|
|
// this.triggerEvent("pairingChange", this.state);
|
|
|
|
|
this.pairingChange(this.state);
|
|
|
|
|
// TODO 查询离线记录结果
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log("BleStatusSync value => ", jsonStatus);
|
|
|
|
|
break;
|
|
|
|
|
case "QueryMatchStatus":
|
|
|
|
|
console.log("QueryMatchStatus value => ", jsonStatus);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (jsonStatus?.commandType === "InfoQuery") {
|
|
|
|
|
console.log("查询版本信息", jsonStatus);
|
|
|
|
|
switch (jsonStatus.infoQueryType) {
|
|
|
|
|
case "versionInfo":
|
|
|
|
|
if (this.state.hasVersionInfo) return;
|
|
|
|
|
clearTimeout(isGetVersionTimer);
|
|
|
|
|
this.setState({
|
|
|
|
|
hasVersionInfo: true, // 已返回版本信息
|
|
|
|
|
connectionStatus: true,
|
|
|
|
|
subDeviceConnectedStatus: true,
|
|
|
|
|
synchronousStatus: true,
|
|
|
|
|
});
|
|
|
|
|
const deviceVersionNo = jsonStatus.versionNo;
|
|
|
|
|
const latestVersionNo = deviceInfo.iot_versions;
|
|
|
|
|
// const isNeedToUpdateBl = isNeedToUpdate(deviceVersionNo, latestVersionNo)
|
|
|
|
|
// 判断是否需要升级
|
|
|
|
|
// M01和WL200 不需要在这里进行蓝牙更新
|
|
|
|
|
// if (isNeedToUpdateBl) {
|
|
|
|
|
// const pages = getCurrentPages();
|
|
|
|
|
// const matchPageList = [{
|
|
|
|
|
// route: 'pages/MatrixWL200/pages/index/index'
|
|
|
|
|
// },{
|
|
|
|
|
// route: 'pages/MatrixM01/pages/index/index'
|
|
|
|
|
// }];
|
|
|
|
|
// const hadOpen = checkSameKey(pages, matchPageList, 'route');
|
|
|
|
|
// if (!hadOpen) {
|
|
|
|
|
// this.triggerEvent("pairingChange", { deviceVersionNo });
|
|
|
|
|
this.pairingChange({ deviceVersionNo });
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// this.sendSyncRecording()
|
|
|
|
|
// }
|
|
|
|
|
break;
|
|
|
|
|
case "offlineClockSummary":
|
|
|
|
|
clearTimeout(isGetSyncRecordingTimer);
|
|
|
|
|
if (this.state.hasSyncRecord) return;
|
|
|
|
|
this.setState({
|
|
|
|
|
hasSyncRecord: true,
|
|
|
|
|
synchronousStatus: true,
|
|
|
|
|
});
|
|
|
|
|
console.log("offlineClockSummary value =>", jsonStatus);
|
|
|
|
|
// this.triggerEvent("pairingChange", this.state);
|
|
|
|
|
this.pairingChange(this.state);
|
|
|
|
|
// TODO 查询离线记录结果
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@ -632,23 +561,21 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
* type3 we100
|
|
|
|
|
* type4 FR380
|
|
|
|
|
*/
|
|
|
|
|
console.log("发送配对码");
|
|
|
|
|
if (deviceInfo.type == InstrumentTypeEnum.FR200) {
|
|
|
|
|
console.log("发送配对码", deviceInfo.model);
|
|
|
|
|
if (deviceInfo.model == "FR200") {
|
|
|
|
|
if (sendPairingTimer) clearInterval(sendPairingTimer);
|
|
|
|
|
sendPairingTimer = setInterval(() => {
|
|
|
|
|
this.sendPairingSignal();
|
|
|
|
|
}, 1000);
|
|
|
|
|
} else if (
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.WL200 ||
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.M01
|
|
|
|
|
) {
|
|
|
|
|
} else if (deviceInfo.model == "WL200" || deviceInfo.model == "M01") {
|
|
|
|
|
if (sendPairingTimer) clearInterval(sendPairingTimer);
|
|
|
|
|
sendPairingTimer = setInterval(() => {
|
|
|
|
|
console.log("test WL200");
|
|
|
|
|
this.sendPairingSignal();
|
|
|
|
|
}, 1000);
|
|
|
|
|
} else if (
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.FR380 ||
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.FR390
|
|
|
|
|
deviceInfo.model == "FR380" ||
|
|
|
|
|
deviceInfo.model == "FR390"
|
|
|
|
|
) {
|
|
|
|
|
if (sendPairingTimer) clearInterval(sendPairingTimer);
|
|
|
|
|
sendPairingTimer = setInterval(() => {
|
|
|
|
|
@ -659,7 +586,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
overTimer = setTimeout(() => {
|
|
|
|
|
if (this.state.islian) {
|
|
|
|
|
console.log("超时跳转护理页");
|
|
|
|
|
log.info("超时跳转护理页");
|
|
|
|
|
// log.info("超时跳转护理页");
|
|
|
|
|
// 已配对成功,其它操作导致超时未跳转则直接跳转
|
|
|
|
|
// this.triggerEvent("offlineChange", this.state);
|
|
|
|
|
this.offlineChange(this.state);
|
|
|
|
|
@ -682,12 +609,9 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
// 8.发送指令:获取仪器版本号
|
|
|
|
|
sendGetVersion() {
|
|
|
|
|
const { yiqiInfo: deviceInfo } = this.props;
|
|
|
|
|
const isFRDevice = [
|
|
|
|
|
InstrumentTypeEnum.FR200,
|
|
|
|
|
InstrumentTypeEnum.FR380,
|
|
|
|
|
InstrumentTypeEnum.FR390,
|
|
|
|
|
].includes(Number(deviceInfo.type));
|
|
|
|
|
log.info(commandMap.sendVersionCommand, `仪器:${deviceInfo.type}`);
|
|
|
|
|
const isFRDevice = ["FR200", "FR380", "FR390"].includes(deviceInfo.model);
|
|
|
|
|
// log.info(commandMap.sendVersionCommand, `仪器:${deviceInfo.model}`);
|
|
|
|
|
console.log(commandMap.sendVersionCommand, `仪器:${deviceInfo.model}`);
|
|
|
|
|
if (isFRDevice) {
|
|
|
|
|
writeBLECharacteristicValue({
|
|
|
|
|
//发送获取仪器版本号
|
|
|
|
|
@ -701,7 +625,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
// const otaDeviceType = deviceInfo.type == instrumentTypeEnum.WL200 ? OtaDeviceTypeEnum.WL200 : OtaDeviceTypeEnum.WE100;
|
|
|
|
|
// 通过发箍连 都用we100
|
|
|
|
|
const otaDeviceType =
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.WL200
|
|
|
|
|
deviceInfo.model == InstrumentTypeEnum.WL200
|
|
|
|
|
? OtaDeviceTypeEnum.WE100
|
|
|
|
|
: OtaDeviceTypeEnum.WE100;
|
|
|
|
|
const versionCommand = {
|
|
|
|
|
@ -710,7 +634,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
otaDeviceType,
|
|
|
|
|
};
|
|
|
|
|
const value =
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.WL200
|
|
|
|
|
deviceInfo.model == InstrumentTypeEnum.WL200
|
|
|
|
|
? deviceToolKitInstanceM01.toBleCommand(versionCommand as any)
|
|
|
|
|
: deviceToolKitInstanceM01.toBleCommand(versionCommand as any);
|
|
|
|
|
// const value = deviceInfo.type == instrumentTypeEnum.WL200 ? deviceToolKitInstanceWL200.toBleCommand(versionCommand) : deviceToolKitInstanceM01.toBleCommand(versionCommand);
|
|
|
|
|
@ -723,7 +647,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
// log.info()
|
|
|
|
|
if (this.state.offlineDataindex == this.state.offlineDataList.length) {
|
|
|
|
|
console.log("离线记录获取完成");
|
|
|
|
|
log.info(commandMap.finishOfflineData, this.state.offlineDataList);
|
|
|
|
|
// log.info(commandMap.finishOfflineData, this.state.offlineDataList);
|
|
|
|
|
/****
|
|
|
|
|
* 发送同步时间
|
|
|
|
|
* ****/
|
|
|
|
|
@ -738,7 +662,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
console.log("发送获取离线记录(细)指令");
|
|
|
|
|
log.info(commandMap.finishOfflineData, "发送获取离线记录(细)指令");
|
|
|
|
|
// log.info(commandMap.finishOfflineData, "发送获取离线记录(细)指令");
|
|
|
|
|
writeBLECharacteristicValue({
|
|
|
|
|
//发送获取离线记录
|
|
|
|
|
deviceId: this.props.bluetoothInfo.deviceId,
|
|
|
|
|
@ -753,7 +677,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
let str = "DBF0A00200";
|
|
|
|
|
console.log("发送离线记录汇总指令 ==》", str);
|
|
|
|
|
this.setState({ offlineDataList: [] }); // 置空重查离线记录
|
|
|
|
|
log.info(commandMap.finishOfflineData, `发送获取离线记录(总)指令`);
|
|
|
|
|
// log.info(commandMap.finishOfflineData, `发送获取离线记录(总)指令`);
|
|
|
|
|
writeBLECharacteristicValue({
|
|
|
|
|
//发送获取离线记录
|
|
|
|
|
deviceId: this.props.bluetoothInfo.deviceId,
|
|
|
|
|
@ -764,18 +688,26 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 9.发送配对码 */
|
|
|
|
|
sendPairingSignal() {
|
|
|
|
|
console.log("9.发送配对码 sendPairingSignal");
|
|
|
|
|
const { yiqiInfo: deviceInfo } = this.props;
|
|
|
|
|
log.info(commandMap.sendMatchCode, `仪器:${deviceInfo.type}发送匹配码`);
|
|
|
|
|
// log.info(commandMap.sendMatchCode, `仪器:${deviceInfo.model}发送匹配码`);
|
|
|
|
|
console.log(commandMap.sendMatchCode, `仪器:${deviceInfo.model}发送匹配码`);
|
|
|
|
|
let matchArrayBuffer: any = null;
|
|
|
|
|
switch (deviceInfo.type) {
|
|
|
|
|
switch (deviceInfo.model) {
|
|
|
|
|
case InstrumentTypeEnum.FR200:
|
|
|
|
|
matchArrayBuffer = deviceToolKitInstanceFR200.toBleCommand(
|
|
|
|
|
bleCommandSamples.match as any
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case InstrumentTypeEnum.WL200:
|
|
|
|
|
matchArrayBuffer = deviceToolKitInstanceWL200.toBleCommand(
|
|
|
|
|
// console.log("WL200无法配对,只能用M01");
|
|
|
|
|
console.log("正在发送WL200", bleCommandSamples.match);
|
|
|
|
|
// matchArrayBuffer = deviceToolKitInstanceWL200.toBleCommand(
|
|
|
|
|
// bleCommandSamples.match as any
|
|
|
|
|
// );
|
|
|
|
|
matchArrayBuffer = deviceToolKitInstanceM01.toBleCommand(
|
|
|
|
|
bleCommandSamples.match as any
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
@ -805,15 +737,17 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (matchArrayBuffer)
|
|
|
|
|
sendCommand({ value: matchArrayBuffer })
|
|
|
|
|
.then(() => {})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
// 下发配对指令失败,走重连操作
|
|
|
|
|
clearInterval(sendPairingTimer);
|
|
|
|
|
// wx.closeBLEConnection();
|
|
|
|
|
this.createBLEConnection();
|
|
|
|
|
});
|
|
|
|
|
if (matchArrayBuffer) console.log("matchArrayBuffer", matchArrayBuffer);
|
|
|
|
|
sendCommand({ value: matchArrayBuffer })
|
|
|
|
|
.then((res) => {
|
|
|
|
|
console.log("matchArrayBuffer res", res);
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
// 下发配对指令失败,走重连操作
|
|
|
|
|
clearInterval(sendPairingTimer);
|
|
|
|
|
// wx.closeBLEConnection();
|
|
|
|
|
this.createBLEConnection();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 发送记录 */
|
|
|
|
|
@ -891,7 +825,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
errorCode(errno, errMsg) {
|
|
|
|
|
clearInterval(searchBluetootTimers);
|
|
|
|
|
clearInterval(sendgetversionTimer);
|
|
|
|
|
console.info("errorCode err => ", errno, errMsg);
|
|
|
|
|
// console.info("errorCode err => ", errno, errMsg);
|
|
|
|
|
if (errno == 10001 || errno == 10009) {
|
|
|
|
|
let t2 =
|
|
|
|
|
errno == 10001
|
|
|
|
|
@ -965,10 +899,11 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
failErrorCode(errno, errMsg) {
|
|
|
|
|
console.info("failErrorCode err => ", errno, errMsg);
|
|
|
|
|
console.log("failErrorCode err => ", errno, errMsg);
|
|
|
|
|
clearInterval(searchBluetootTimers);
|
|
|
|
|
clearInterval(sendgetversionTimer);
|
|
|
|
|
log.info("连接仪器失败", errno, errMsg);
|
|
|
|
|
// log.info("连接仪器失败", errno, errMsg);
|
|
|
|
|
console.log("连接仪器失败", errno, errMsg);
|
|
|
|
|
let errorText = "";
|
|
|
|
|
switch (errno) {
|
|
|
|
|
case 1500101:
|
|
|
|
|
@ -1071,6 +1006,8 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
// this.sendSyncRecording()
|
|
|
|
|
// }, 5000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 发送同步记录 */
|
|
|
|
|
sendSyncRecording() {
|
|
|
|
|
const { yiqiInfo: deviceInfo } = this.props;
|
|
|
|
|
const versionCommand = {
|
|
|
|
|
@ -1078,7 +1015,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
infoQueryType: "offlineClockSummary",
|
|
|
|
|
};
|
|
|
|
|
const value =
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.WL200
|
|
|
|
|
deviceInfo.model == InstrumentTypeEnum.WL200
|
|
|
|
|
? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any)
|
|
|
|
|
: deviceToolKitInstanceM01.toBleCommand(versionCommand as any);
|
|
|
|
|
sendCommand({ value }).then();
|
|
|
|
|
@ -1100,6 +1037,11 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
this.props.confirm("confirm");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onReconnect = () => {
|
|
|
|
|
console.log("onReconnect");
|
|
|
|
|
// this.props.confirm("confirm");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pairingChange = (data) => {
|
|
|
|
|
this.props.pairingChange(data);
|
|
|
|
|
};
|
|
|
|
|
@ -1109,17 +1051,21 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
let { name, isConnection, connectionStatus } = this.state;
|
|
|
|
|
let { name, isConnection, connectionStatus, connectionSuccess, error } =
|
|
|
|
|
this.state;
|
|
|
|
|
let { yiqiInfo } = this.props;
|
|
|
|
|
return (
|
|
|
|
|
<Block>
|
|
|
|
|
<DeviceConnectPopup
|
|
|
|
|
close={this.onClose}
|
|
|
|
|
confirm={this.onConfirm}
|
|
|
|
|
reconnect={this.onReconnect}
|
|
|
|
|
data={yiqiInfo}
|
|
|
|
|
isShow={true}
|
|
|
|
|
connectionStatus={connectionStatus}
|
|
|
|
|
// connectionStatus={connectionStatus}
|
|
|
|
|
connectionSuccess={connectionSuccess}
|
|
|
|
|
isConnection={isConnection}
|
|
|
|
|
error={error}
|
|
|
|
|
title="面罩模式启动中"
|
|
|
|
|
/>
|
|
|
|
|
<View>{name}</View>
|
|
|
|
|
@ -1135,5 +1081,8 @@ const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
setBluetoothInfo(data) {
|
|
|
|
|
dispatch(setBluetoothInfo(data));
|
|
|
|
|
},
|
|
|
|
|
setDeviceId(data) {
|
|
|
|
|
dispatch(setDeviceId(data));
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ConnectionBluetoot);
|
|
|
|
|
|