临时提交

master
blak-kong 2 years ago
parent 51a77ece7f
commit c2cfcd5f90

@ -1,10 +1,16 @@
const InstrumentTypeEnum = { const InstrumentTypeEnum = {
//仪器类型 //仪器类型
FR200: 1, // FR200: 1,
MATRIX: 2, // MATRIX: 2,
WL200: 3, // WL200: 3,
FR380: 4, // FR380: 4,
FR390: 5, // FR390: 5,
M01: 6, // M01: 6,
FR200: "FR200",
MATRIX: "MATRIX",
WL200: "WL200",
FR380: "FR380",
FR390: "FR390",
M01: "M01",
}; };
export default InstrumentTypeEnum; export default InstrumentTypeEnum;

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

@ -573,22 +573,21 @@ class Index extends Component<any, any> {
goNursing = (item) => { goNursing = (item) => {
console.log("goNursing", item); console.log("goNursing", item);
setStorageSync("instrument_detail", JSON.stringify(item)); setStorageSync("instrument_detail", JSON.stringify(item));
// setStorageSync("connectInstrument", JSON.stringify(item)); // setStorageSync("connectInstrument", JSON.stringify(item));
// this.setState({ instrument_detail: item }); this.setState({ connectInstrument: item });
// this.setState({ connectInstrument: item }); setTimeout(() => this.bindBlockLeft());
// setTimeout(() => this.bindBlockLeft());
// isConnectShow // isConnectShow
setTimeout(() => { // setTimeout(() => {
go("/pages/instrumentClickinUpload/index?id=" + item.id); // go("/pages/instrumentClickinUpload/index?id=" + item.id);
}, 10); // }, 10);
// go("/pages/instrument/intro?id=" + item.id); // go("/pages/instrument/intro?id=" + item.id);
}; };
/* 扫码进入逻辑 */ /* 扫码进入逻辑 */
/** 蓝牙逻辑 */ /** 蓝牙逻辑 */
bindBlockLeft() { bindBlockLeft() {
console.log("this.state.userinfo", this.state.userinfo);
if (!this.state.userinfo.mobile) { if (!this.state.userinfo.mobile) {
//未注册授权 //未注册授权
this.alertRegister(); this.alertRegister();
@ -596,6 +595,9 @@ class Index extends Component<any, any> {
} }
if (this.state.connectInstrument.type === 1) { if (this.state.connectInstrument.type === 1) {
//非IOT //非IOT
setTimeout(() => {
go("/pages/instrumentClickinUpload/index");
}, 10);
} else { } else {
Taro.getSystemInfo({ Taro.getSystemInfo({
success: (res) => { success: (res) => {
@ -716,6 +718,7 @@ class Index extends Component<any, any> {
//连接完成时数据的回调 //连接完成时数据的回调
offlineChange = async (e) => { offlineChange = async (e) => {
console.log("offlineChange", e);
const that = this; const that = this;
log.info( log.info(
commandMap.versionInfoHome, commandMap.versionInfoHome,
@ -1131,6 +1134,8 @@ class Index extends Component<any, any> {
yiqiInfo={connectInstrument} yiqiInfo={connectInstrument}
close={this.connectionClose} close={this.connectionClose}
confirm={this.connectionConfirm} confirm={this.connectionConfirm}
offlineChange={this.offlineChange}
pairingChange={this.pairingChange}
/> />
)} )}
{/* <ConnectionBluetoot /> */} {/* <ConnectionBluetoot /> */}

@ -18,10 +18,29 @@ const deviceInfoReducer = createSlice({
state = JSON.parse(JSON.stringify(payload)); state = JSON.parse(JSON.stringify(payload));
}, },
setBluetoothInfo(state, { payload }) { setBluetoothInfo(state, { payload }) {
state.bluetoothInfo = JSON.parse(JSON.stringify(payload)); console.log("setBluetoothInfo payload", payload);
// state.bluetoothInfo = JSON.parse(JSON.stringify(payload));
// console.log("state.bluetoothInfo", state.bluetoothInfo);
state.bluetoothInfo.deviceId = payload.deviceId;
if (payload.servicesuuid) {
state.bluetoothInfo.servicesuuid = payload.servicesuuid;
}
if (payload.characteristicsuuid0) {
state.bluetoothInfo.characteristicsuuid0 = payload.characteristicsuuid0;
}
if (payload.characteristicsuuid1) {
state.bluetoothInfo.characteristicsuuid1 = payload.characteristicsuuid1;
}
if (payload.characteristicId) {
state.bluetoothInfo.characteristicId = payload.characteristicId;
}
},
setDeviceId(state, { payload }) {
console.log("setDeviceId payload", payload);
state.bluetoothInfo.deviceId = payload.deviceId;
}, },
}, },
}); });
export const { setBluetoothInfo } = deviceInfoReducer.actions; export const { setBluetoothInfo, setDeviceId } = deviceInfoReducer.actions;
export default deviceInfoReducer.reducer; export default deviceInfoReducer.reducer;

Loading…
Cancel
Save