|
|
|
|
@ -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 {
|
|
|
|
|
@ -305,11 +308,22 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
).indexOf(`${type}`) !== -1
|
|
|
|
|
) {
|
|
|
|
|
console.info("连接的设备信息", item.devices[i], type);
|
|
|
|
|
let params = {
|
|
|
|
|
deviceId: item.devices[i].deviceId,
|
|
|
|
|
servicesuuid: item.devices[i].serviceId,
|
|
|
|
|
characteristicsuuid0: item.devices[i].characteristics[0].uuid,
|
|
|
|
|
characteristicsuuid1: item.devices[i].characteristics[1].uuid,
|
|
|
|
|
characteristicId: "",
|
|
|
|
|
};
|
|
|
|
|
this.props.setBluetoothInfo(params);
|
|
|
|
|
|
|
|
|
|
clearInterval(searchBluetootTimers);
|
|
|
|
|
Taro.stopBluetoothDevicesDiscovery(); //停止搜索蓝牙
|
|
|
|
|
// app.globalData.deviceInfo.deviceId = item.devices[i].deviceId;
|
|
|
|
|
this.createBLEConnection();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
console.log("this.props.bluetoothInfo", this.props.bluetoothInfo);
|
|
|
|
|
clearInterval(searchBluetootTimers);
|
|
|
|
|
Taro.stopBluetoothDevicesDiscovery(); //停止搜索蓝牙
|
|
|
|
|
// app.globalData.deviceInfo.deviceId = item.devices[i].deviceId;
|
|
|
|
|
this.createBLEConnection();
|
|
|
|
|
}, 10);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -327,13 +341,10 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
/*********开始主动连接*******/
|
|
|
|
|
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 (this.props.yiqiInfo.model === "WL200") {
|
|
|
|
|
this.setState({
|
|
|
|
|
connectionStatus: true,
|
|
|
|
|
});
|
|
|
|
|
@ -358,14 +369,19 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
|
|
|
|
|
/** 6.获取蓝牙特征值 */
|
|
|
|
|
getBLEDeviceServices() {
|
|
|
|
|
console.log("========6.获取蓝牙特征值========");
|
|
|
|
|
getBLEDeviceServices(this.props.bluetoothInfo.deviceId)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
console.log("特征值", res);
|
|
|
|
|
let bluetoothInfo = this.props.bluetoothInfo;
|
|
|
|
|
bluetoothInfo.servicesuuid = res.servicesuuid;
|
|
|
|
|
bluetoothInfo.characteristicsuuid1 = res.characteristicsuuid1;
|
|
|
|
|
bluetoothInfo.characteristicsuuid0 = res.characteristicsuuid0;
|
|
|
|
|
this.props.setBluetoothInfo(bluetoothInfo);
|
|
|
|
|
this.notifyBLECharacteristicValueChange();
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.notifyBLECharacteristicValueChange();
|
|
|
|
|
}, 10);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
let { errno, errMsg } = err;
|
|
|
|
|
@ -376,8 +392,10 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
|
|
|
|
|
/** 7.通知BLE特征值更改 */
|
|
|
|
|
notifyBLECharacteristicValueChange() {
|
|
|
|
|
console.log("7.通知BLE特征值更改");
|
|
|
|
|
const { yiqiInfo: deviceInfo } = this.props;
|
|
|
|
|
const bluetoothInfo = this.props.bluetoothInfo;
|
|
|
|
|
console.log("bluetoothInfo", bluetoothInfo);
|
|
|
|
|
notifyBLECharacteristicValueChange({
|
|
|
|
|
deviceId: bluetoothInfo.deviceId,
|
|
|
|
|
servicesuuid: bluetoothInfo.servicesuuid,
|
|
|
|
|
@ -391,24 +409,22 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
console.info("onBLECharacteristicValueChange value => ", value);
|
|
|
|
|
let str = ab2hex(value.value); //转为16进制字符串
|
|
|
|
|
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));
|
|
|
|
|
"FR200",
|
|
|
|
|
"WL200",
|
|
|
|
|
"FR380",
|
|
|
|
|
"FR390",
|
|
|
|
|
"M01",
|
|
|
|
|
].includes(deviceInfo.model);
|
|
|
|
|
const isFRDevice = ["FR200", "FR380", "FR390"].includes(
|
|
|
|
|
deviceInfo.model
|
|
|
|
|
);
|
|
|
|
|
if (isFRDevice) {
|
|
|
|
|
this.setState({
|
|
|
|
|
connectionStatus,
|
|
|
|
|
});
|
|
|
|
|
log.info(
|
|
|
|
|
commandMap.reciviedBLECommand,
|
|
|
|
|
`仪器类型: ${deviceInfo.type}`,
|
|
|
|
|
`仪器模式: ${deviceInfo.model}`,
|
|
|
|
|
value
|
|
|
|
|
);
|
|
|
|
|
filterBleData(str).forEach((item) => {
|
|
|
|
|
@ -454,8 +470,8 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
`connection_guide, ${deviceInfo.type}:${versionInfo.version}`
|
|
|
|
|
);
|
|
|
|
|
if (
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.FR380 ||
|
|
|
|
|
deviceInfo.type == InstrumentTypeEnum.FR390
|
|
|
|
|
deviceInfo.model == "FR380" ||
|
|
|
|
|
deviceInfo.model == "FR390"
|
|
|
|
|
) {
|
|
|
|
|
console.log("跳转护理页");
|
|
|
|
|
// this.triggerEvent("offlineChange", this.state);
|
|
|
|
|
@ -510,7 +526,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
} else {
|
|
|
|
|
let jsonStatus: any = null;
|
|
|
|
|
let querySubDeviceArrayBuffer;
|
|
|
|
|
if (deviceInfo.type == InstrumentTypeEnum.WL200) {
|
|
|
|
|
if (deviceInfo.model == "WL200") {
|
|
|
|
|
// querySubDeviceArrayBuffer = deviceToolKitInstanceWL200.toBleCommand(bleCommandSamples.querySubDevice);
|
|
|
|
|
// jsonStatus = deviceToolKitInstanceWL200.toJsonStatus(value.value);
|
|
|
|
|
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value);
|
|
|
|
|
@ -518,7 +534,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
deviceToolKitInstanceM01.toBleCommand(
|
|
|
|
|
bleCommandSamples.querySubDevice as any
|
|
|
|
|
); // todo
|
|
|
|
|
} else if (deviceInfo.type == InstrumentTypeEnum.M01) {
|
|
|
|
|
} else if (deviceInfo.model == "M01") {
|
|
|
|
|
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value);
|
|
|
|
|
querySubDeviceArrayBuffer =
|
|
|
|
|
deviceToolKitInstanceM01.toBleCommand(
|
|
|
|
|
@ -527,7 +543,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
}
|
|
|
|
|
log.info(
|
|
|
|
|
commandMap.reciviedBLECommand,
|
|
|
|
|
`仪器类型: ${deviceInfo.type}`,
|
|
|
|
|
`仪器模式: ${deviceInfo.model}`,
|
|
|
|
|
jsonStatus
|
|
|
|
|
);
|
|
|
|
|
if (jsonStatus?.commandType === "BleMatch") {
|
|
|
|
|
@ -633,22 +649,19 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
* type4 FR380
|
|
|
|
|
*/
|
|
|
|
|
console.log("发送配对码");
|
|
|
|
|
if (deviceInfo.type == InstrumentTypeEnum.FR200) {
|
|
|
|
|
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(() => {
|
|
|
|
|
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(() => {
|
|
|
|
|
@ -682,11 +695,7 @@ 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));
|
|
|
|
|
const isFRDevice = ["FR200", "FR380", "FR390"].includes(deviceInfo.model);
|
|
|
|
|
log.info(commandMap.sendVersionCommand, `仪器:${deviceInfo.type}`);
|
|
|
|
|
if (isFRDevice) {
|
|
|
|
|
writeBLECharacteristicValue({
|
|
|
|
|
@ -768,7 +777,7 @@ class ConnectionBluetoot extends Component<any, any> {
|
|
|
|
|
const { yiqiInfo: deviceInfo } = this.props;
|
|
|
|
|
log.info(commandMap.sendMatchCode, `仪器:${deviceInfo.type}发送匹配码`);
|
|
|
|
|
let matchArrayBuffer: any = null;
|
|
|
|
|
switch (deviceInfo.type) {
|
|
|
|
|
switch (deviceInfo.model) {
|
|
|
|
|
case InstrumentTypeEnum.FR200:
|
|
|
|
|
matchArrayBuffer = deviceToolKitInstanceFR200.toBleCommand(
|
|
|
|
|
bleCommandSamples.match as any
|
|
|
|
|
@ -1078,7 +1087,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();
|
|
|
|
|
@ -1135,5 +1144,8 @@ const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
setBluetoothInfo(data) {
|
|
|
|
|
dispatch(setBluetoothInfo(data));
|
|
|
|
|
},
|
|
|
|
|
setDeviceId(data) {
|
|
|
|
|
dispatch(setDeviceId(data));
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ConnectionBluetoot);
|
|
|
|
|
|