From 148d8bf6a3e05c92a27f1ce304c9f7b244c4043d Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Tue, 27 Feb 2024 14:13:48 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/bluetoot/connection/index.tsx | 111 ++--- .../bluetoot/update-wl200/index.less | 36 ++ .../bluetoot/update-wl200/index.tsx | 462 ++++++++++++++++++ src/pages/iotCarePlan/iotCarePlan.tsx | 70 ++- src/utils/request.js | 3 +- 5 files changed, 588 insertions(+), 94 deletions(-) create mode 100644 src/components/bluetoot/update-wl200/index.less create mode 100644 src/components/bluetoot/update-wl200/index.tsx diff --git a/src/components/bluetoot/connection/index.tsx b/src/components/bluetoot/connection/index.tsx index 91e6a77..35cf451 100644 --- a/src/components/bluetoot/connection/index.tsx +++ b/src/components/bluetoot/connection/index.tsx @@ -53,15 +53,22 @@ import { showModal, msg } from "@/utils/traoAPI"; import InstrumentTypeEnum from "../InstrumentTypeEnum"; import OtaDeviceTypeEnum from "../OtaDeviceTypeEnum"; +// 定义一个变量,用于存放获取版本定时器 let isGetVersionTimer: any = null; +// 定义一个变量,用于存放获取子设备定时器 let isGetSubDeviceTimer: any = null; +// 定义一个变量,用于存放获取同步录制定时器 let isGetSyncRecordingTimer: any = null; +// 定义一个变量,用于存放超时定时器 let overTimer: any = null; +// 定义一个变量,用于存放获取子设备定时器次数 let isGetSubDeviceTimerNum = 0; +// 定义一个变量,用于存放发送获取版本定时器 let sendgetversionTimer: any = null; +// 定义一个变量,用于存放发送获取版本定时器次数 let sendGetVersionTimerNum = 0; let searchBluetootTimers: any = null; // 搜索蓝牙定时器 @@ -121,9 +128,9 @@ class ConnectionBluetoot extends Component { clearTimeout(isGetVersionTimer); clearTimeout(isGetSyncRecordingTimer); if (overTimer) clearTimeout(overTimer); + // 重新开始 this.again(); - // this.triggerEvent("close", "connection_guide"); - console.log("this.close"); + // 关闭弹窗 this.onClose(); Taro.closeBluetoothAdapter(); } @@ -428,17 +435,15 @@ class ConnectionBluetoot extends Component { 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 + 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( @@ -469,8 +474,8 @@ class ConnectionBluetoot extends Component { islian: true, // 不需要离线记录,但暂未完全删除这部分逻辑,所以直接设为true }); - this.pairingChange(this.state); // 临时添加,用于跳转 - // this.detectVersionUpdate(); // 获取升级信息 + // this.pairingChange(this.state); // 临时添加,用于跳转 + this.detectVersionUpdate(); // 获取升级信息 // todo 连接成功需删除离线记录,暂时未缓存离线记录 if (this.state.connectionSuccess) return; // 暂时不需要查询是否连接子设备, 直接进入查询版本信息 @@ -533,7 +538,7 @@ class ConnectionBluetoot extends Component { // const hadOpen = checkSameKey(pages, matchPageList, 'route'); // if (!hadOpen) { // this.triggerEvent("pairingChange", { deviceVersionNo }); - this.pairingChange({ deviceVersionNo }); + // this.pairingChange({ deviceVersionNo }); // } // } else { // this.sendSyncRecording() @@ -635,11 +640,14 @@ class ConnectionBluetoot extends Component { infoQueryType: "versionInfo", otaDeviceType, }; + // const value = + // deviceInfo.model == InstrumentTypeEnum.WL200 + // ? deviceToolKitInstanceM01.toBleCommand(versionCommand as any) + // : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); const value = - deviceInfo.model == InstrumentTypeEnum.WL200 - ? deviceToolKitInstanceM01.toBleCommand(versionCommand as any) + deviceInfo.type == InstrumentTypeEnum.WL200 + ? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any) : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); - // const value = deviceInfo.type == instrumentTypeEnum.WL200 ? deviceToolKitInstanceWL200.toBleCommand(versionCommand) : deviceToolKitInstanceM01.toBleCommand(versionCommand); sendCommand({ value }); } } @@ -648,7 +656,7 @@ class ConnectionBluetoot extends Component { sendofflist() { // log.info() if (this.state.offlineDataindex == this.state.offlineDataList.length) { - console.log("离线记录获取完成"); + console.log("离线记录获取完成", this.state); // log.info(commandMap.finishOfflineData, this.state.offlineDataList); /**** * 发送同步时间 @@ -658,8 +666,6 @@ class ConnectionBluetoot extends Component { console.log("版本号:" + this.state.versionInfo.version); this.setState({ islian: true }); clearTimeout(connectionTimer); - // this.triggerEvent("offlineChange", this.state); - console.log("this.triggerEvent", this.state); this.offlineChange(this.state); return false; } @@ -752,64 +758,6 @@ class ConnectionBluetoot extends Component { }); } - /** 发送记录 */ - sendOfflistPost(str) { - let facehour = hex2int(str.substring(12, 14)); //脸部小时 - let faceminutes = hex2int(str.substring(14, 16)); //脸部分钟 - let faceseconds = hex2int(str.substring(16, 18)); //脸部秒 - let faceposition1 = hex2int(str.substring(18, 20)); //当前档位 - let facenum = hex2int(str.substring(20, 22)); //次数 - let faceyear = hex2int(str.substring(22, 24)); //年份 - let facemonth = hex2int(str.substring(24, 26)); //月份 - let faceday = hex2int(str.substring(26, 28)); //日期 - - let eyehour = hex2int(str.substring(28, 30)); //眼部小时 - let eyeminutes = hex2int(str.substring(30, 32)); //眼部分钟 - let eyeseconds = hex2int(str.substring(32, 34)); //眼部秒 - let eyeposition1 = hex2int(str.substring(34, 36)); //当前档位 - let eyenum = hex2int(str.substring(36, 38)); //次数 - let eyeyear = hex2int(str.substring(38, 40)); //年份 - let eyemonth = hex2int(str.substring(40, 42)); //月份 - let eyeday = hex2int(str.substring(42, 44)); //日期 - // console.log('脸部小时:' + facehour) - // console.log('脸部分钟:' + faceminutes) - // console.log('脸部秒:' + faceseconds) - // console.log('当前档位:' + faceposition1) - // console.log('脸部次数:' + facenum) - // console.log('年:' + faceyear) - // console.log('月:' + facemonth) - // console.log('日:' + faceday) - // console.log('-------------------') - // console.log('眼部小时:' + eyehour) - // console.log('眼部分钟:' + eyeminutes) - // console.log('眼部秒:' + eyeseconds) - // console.log('当前档位:' + eyeposition1) - // console.log('眼部次数:' + eyenum) - // console.log('年:' + eyeyear) - // console.log('月:' + eyemonth) - // console.log('日:' + eyeday) - let { offlineDataList } = this.state; - offlineDataList.push({ - facehour, - faceminutes, - faceseconds, - faceposition1, - facenum, - faceyear, - facemonth, - faceday, - eyehour, - eyeminutes, - eyeseconds, - eyeposition1, - eyenum, - eyeyear, - eyemonth, - eyeday, - }); - this.setState({ offlineDataList }); - } - /** 同步时间 */ sendAsyncTime() { console.log("同步时间"); @@ -973,7 +921,7 @@ class ConnectionBluetoot extends Component { // 获取版本信息 detectVersionUpdate() { this.closeQuerySubDevice(); - this.sendGetVersion(); + this.sendGetVersion(); // 获取版本信息 sendGetVersionTimerNum = 0; // 600毫秒查询一次版本号是否返回,若返回则跳转护理页 if (isGetVersionTimer) clearTimeout(isGetVersionTimer); @@ -989,7 +937,6 @@ class ConnectionBluetoot extends Component { this.setState({ connectionStatus: true, }); - // this.triggerEvent("pairingChange", this.state); console.log("this.pairingChange", this.state); this.pairingChange(this.state); } else { diff --git a/src/components/bluetoot/update-wl200/index.less b/src/components/bluetoot/update-wl200/index.less new file mode 100644 index 0000000..5bb8f2a --- /dev/null +++ b/src/components/bluetoot/update-wl200/index.less @@ -0,0 +1,36 @@ +.common-progress-box { + padding: 50rpx; +} +.progress { + display: flex; + margin-top: 10rpx; + font-size: 24rpx; + font-family: PingFang SC; + font-weight: 500; + color: #999999; + align-items: center; + + .van-progress { + width: 440rpx; + .van-progress__portion { + background: linear-gradient(90deg, #ffe9c7, #eecda1); + border-radius: 6rpx; + height: 12rpx; + .van-progress__pivot { + display: none; + } + } + } + + .percent { + margin-left: 52rpx; + } +} + +.progress-tips { + font-family: PingFang SC; + font-weight: 500; + font-size: 26rpx; + color: #666666; + line-height: 60rpx; +} diff --git a/src/components/bluetoot/update-wl200/index.tsx b/src/components/bluetoot/update-wl200/index.tsx new file mode 100644 index 0000000..d31f281 --- /dev/null +++ b/src/components/bluetoot/update-wl200/index.tsx @@ -0,0 +1,462 @@ +import Taro from "@tarojs/taro"; +import classnames from "classnames"; + +import { Component, PropsWithChildren, useEffect, useState } from "react"; +import { Block, View, Text, PageMeta } from "@tarojs/components"; +import { Popup, Progress } from "@antmjs/vantui"; + +import { connect } from "react-redux"; +import { + msg, + back, + showModal, + go, + loading, + getStorageSync, +} from "@/utils/traoAPI"; +import { InstrumentInfo } from "@/utils/Interface"; +import { + notifyBLECharacteristicValueChange, + writeBLECharacteristicValue, + sendCommand, +} from "@/utils/bluetoothWXAPI"; +import { + ab2hex, + ccrc8, + filterBleData, + hex2int, + string2buffer, +} from "@/utils/util"; +import { + Stringkit, + TResponseFromDevice, +} from "@flossom-npm/iot-translater-we100"; + +// 通过设备类型判断给 deviceToolKitInstance 赋值 +import { DeviceToolKit as DeviceToolKitWE100 } from "@flossom-npm/iot-translater-we100"; + +import InstrumentTypeEnum from "../InstrumentTypeEnum"; +import OtaDeviceTypeEnum from "../OtaDeviceTypeEnum"; + +// 临时替代 +var log = console; +var deviceToolKitInstance: any = null; +deviceToolKitInstance = new DeviceToolKitWE100("WE100", "WL200"); + +import "./index.less"; + +class UpdateIotWL200 extends Component { + constructor(props) { + super(props); + this.state = { + name: "UpdateIotWL200", + progressbar: 1, // 进度条 + + currentDevice: {}, + + hadStartOta: false, // 是否开始ota + }; + } + + $instance = Taro.getCurrentInstance(); + $checkTimer: any = null; + // 与页面渲染无关的数据 + $otaDataGroup: any = { + // 包大小,面罩设置为100,主机设置为240 + packageSize: 240, //每个包的大小上限(单位是字节) + otaBin: null, //固件包buffer形式,从16进制字符串转换成 + otaHexString: "", //固件包的16进制字符串,从后端接口返回 + packageLength: 0, //升级包的总长度(单位是字节) + packageCount: 0, //分包后的总包数 + otaData: [], //分包数组 + packageCrc8: "", //总包的校验码 + versionNo: "", //包的版本号 + otaCurrentPackageIndex: 0, //现在正在传输的分包索引 + countDown: 7, + }; + + async onLoad() {} + componentDidMount() { + this.initData(); + } + + async initData() { + console.log("UpdateIotWL200"); + let objStr = getStorageSync("instrument_detail"); + if (objStr) { + let info = JSON.parse(objStr); + + this.setState({ + currentDevice: info, + }); + + if (info.model == InstrumentTypeEnum.WL200) { + deviceToolKitInstance = new DeviceToolKitWE100("WE100", "WL200"); + } else { + deviceToolKitInstance = new DeviceToolKitWE100("WE100", "M01"); + } + } + setTimeout(() => { + this.notifyBLECharacteristicValueChange(); + this.getDeviceUpgrade(); + }); + } + + /** + * 拆分升级包 + */ + async getUpgradeData() { + //解析获取升级包更新数据 + const { otaHexString, packageSize } = this.$otaDataGroup; + if (!otaHexString?.length) { + return []; + } + let arr: any = []; + for (let i = 0, len = otaHexString.length; i < len; i += packageSize * 2) { + let index = i + packageSize * 2; + let value = otaHexString.slice(i, index); + arr.push(value); + } + return arr; + } + /** + * 重置OTA状态 + */ + resetOta() { + this.$otaDataGroup = { + ...this.$otaDataGroup, + otaCurrentPackageIndex: 0, + otaData: [], + }; + } + /** + * 启动ota + */ + startOTA() { + this.resetOta(); + const { currentDevice } = this.state; + let jsoncmd = { + commandType: "OTAStart", + otaDeviceType: "", + versionNo: this.$otaDataGroup.versionNo, + }; + // 根据设备类型传 otaDeviceType + if (currentDevice.model == InstrumentTypeEnum.M01) { + jsoncmd.otaDeviceType = OtaDeviceTypeEnum.WE100; + } else { + jsoncmd.otaDeviceType = OtaDeviceTypeEnum.WL200; + } + // deviceToolKitInstance.setDebug(true) + + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + console.log(jsoncmd); + sendCommand({ value }).then((res) => { + this.setState({ + hadStartOta: true, + }); + this.createTimer(); + }); + } + /** + * 准备ota + */ + preOTA() { + const { packageCount, packageLength, packageCrc8, versionNo } = + this.$otaDataGroup; + let jsoncmd = { + commandType: "OTAPrepare", + packageCount, + packageLength, + packageCrc8, + versionNo, + }; + console.info("OTAPrepare json => ", jsoncmd); + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + sendCommand({ value }); + } + /** + * ota升级 + */ + processOTA(i, data) { + const { packageCount, packageLength } = this.$otaDataGroup; + if (!packageLength) { + this.quitOTA(); + } + let jsoncmd = { + commandType: "OTAUpdating", + packageCount, + packageLength, + currentPackageNo: i + 1, + currentPackageLength: data.length / 2, + currentPackageContent: data, + }; + console.info("OTAUpdating json => ", jsoncmd); + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + sendCommand({ value }); + } + /** + * ota升级完成 + */ + async finishedOTA() { + let jsoncmd = { + commandType: "OTAUpdateFinish", + versionNo: this.$otaDataGroup.versionNo, + }; + clearInterval(this.$checkTimer); + log.info("ota成功日志, 清除计时器"); + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + sendCommand({ value }).then((res) => { + this.resetOta(); + }); + } + /** + * ota升级强制退出 + */ + quitOTA(errorString = "") { + // log.info('ota失败日志', errorString); + console.log("ota失败日志", errorString); + const errorMap = { + packageError: "总包错误", + packageNumError: "包号错误", + checkedError: "校验错误", + dataLengthError: "数据总长度错误", + dataCRCError: "数据总数CRC错误", + updateTimeOut: "数据更新超时", + }; + let jsoncmd = { + commandType: "OTAQuit", + }; + //@ts-ignore + const value = deviceToolKitInstance.toBleCommand(jsoncmd); + sendCommand({ value }) + .then((res) => { + this.resetOta(); + // this.showError(errorMap[errorString] || tipMap[errorString] || '发生错误') + }) + .catch((err) => { + if (!this.state.hadShowError) { + this.setState({ + hadShowError: true, + }); + // log.info('ota失败日志', '发送日志OTAQuit失败', err); + console.info("ota失败日志", "发送日志OTAQuit失败", err); + // this.showError(errorMap[errorString] || tipMap[errorString] || '发生错误') + } + }); + } + + /** + * 处理返回的数据 OTA用 + */ + async parseData(json) { + console.log("parseData json.commandType", json.commandType); + if (!json || !json.commandType) return; + switch (json.commandType) { + case "OTAStart": + if (json.responseStatus == "OK") { + const otaData = await this.getUpgradeData(); + this.$otaDataGroup = { + ...this.$otaDataGroup, + otaData, + }; + this.$otaDataGroup.otaCurrentPackageIndex = 0; + this.preOTA(); + } else { + this.quitOTA(json.responseStatus); + } + break; + case "OTAPrepare": + if (json.responseStatus == "OK") { + this.processOTA(0, this.$otaDataGroup.otaData[0]); + } else { + this.quitOTA(json.responseStatus); + } + break; + case "OTAUpdating": + if (json.responseStatus == "OK") { + let ota = this.$otaDataGroup; + let progressbar = + (ota.otaCurrentPackageIndex / ota.packageCount) * 100; + this.setState({ + progressbar: (progressbar <= 1 ? 1 : progressbar).toFixed(0), + }); + if (!json.currentPackageNo) { + return; + } + if (json.currentPackageNo < this.$otaDataGroup.packageCount) { + this.$otaDataGroup.otaCurrentPackageIndex++; + this.processOTA( + this.$otaDataGroup.otaCurrentPackageIndex, + this.$otaDataGroup.otaData[ + this.$otaDataGroup.otaCurrentPackageIndex + ] + ); + } else { + this.finishedOTA(); + } + } else { + this.quitOTA(json.responseStatus); + } + break; + case "OTAUpdateFinish": + console.log("完成OTA传输"); + log.info("ota成功日志, 但是这个分支什么都没做"); + // quitOTA() + break; + default: + break; + } + } + /** + * 从后端拉取固件包,并初始化ota流程的所需对象 + */ + getDeviceUpgrade = async () => { + let res: any = await InstrumentInfo.getUpgrade({ + instrumentId: this.state.currentDevice.id, + isWe200: true, + }); + if (res.data.data == "解析失败") { + // this.showError('文件解析失败'); + return; + } + if (res.data.code !== 200) { + return; + } + const otaHexString = res.data.data; + const otaBin = string2buffer(res.data.data); + const packageLength = otaBin?.byteLength || 0; + const packageSize = this.$otaDataGroup.packageSize; + const packageCrc8 = Stringkit.getCrc8CodeByString(otaHexString); + const packageCount = Math.ceil(packageLength / packageSize); + let { iotVersion: versionNo } = this.state.currentDevice; + this.$otaDataGroup = { + ...this.$otaDataGroup, + otaHexString, + otaBin, + packageLength, + packageSize, + packageCrc8, + packageCount, + versionNo, + }; + console.log("this.$otaDataGroup ", this.$otaDataGroup); + }; + + notifyBLECharacteristicValueChange = () => { + const bluetoothInfo = this.props.bluetoothInfo; + notifyBLECharacteristicValueChange({ + deviceId: bluetoothInfo.deviceId, + servicesuuid: bluetoothInfo.servicesuuid, + characteristicsuuid1: bluetoothInfo.characteristicsuuid1, + characteristicsuuid0: bluetoothInfo.characteristicsuuid0, + }).then((res) => { + Taro.onBLECharacteristicValueChange((value) => { + // let str = ab2hex(value.value); //转为16进制字符串 + // console.log('返回',str) + const jsonStatus = deviceToolKitInstance.toJsonStatus(value.value); + log.info("OTA页面设备响应数据打印==》", JSON.stringify(jsonStatus)); + console.info("onBLECharacteristicValueChange json => ", jsonStatus); + this.$otaDataGroup.currentPackageNo = jsonStatus.currentPackageNo; + + this.$otaDataGroup.countDown = 7; + this.parseData(jsonStatus); + }); + setTimeout(() => { + this.startOTA(); + }, 500); + }); + }; + + createTimer() { + log.info("设备ota计时器创建成功"); + this.$checkTimer = setInterval(() => { + // 超过7s没有回包, 直接断开 + if (this.$otaDataGroup.countDown <= 0 && this.state.hadStartOta) { + if (this.state.currentDevice.model == InstrumentTypeEnum.M01) { + this.quitOTA("shutDownMaskTip"); + } else { + this.quitOTA("updateTimeOut"); + } + } else { + this.$otaDataGroup.countDown--; + } + console.log(this.$otaDataGroup.countDown); + }, 1000); + } + + //升级销毁页面时关闭小程序蓝牙 + onUnload() { + if (this.$checkTimer) clearInterval(this.$checkTimer); + Taro.closeBluetoothAdapter(); + } + + onPullDownRefresh() { + Taro.stopPullDownRefresh(); + } + + onClose = () => { + this.props.close(); + }; + + onConfirm = () => { + this.props.confirm(); + }; + + onClickStop = (e) => { + e.stopPropagation(); + }; + + render() { + let { isShow } = this.props; + return ( + + + + + + 设备升级中 + + + + + + {0.01 * 100}% + + 注意事项: + 1.保持设备开机状态 + 2.请勿切出该页面 + + + + + + ); + } +} + +const mapStateToProps = (state) => ({ + bluetoothInfo: state.deviceInfo.bluetoothInfo, +}); +const mapDispatchToProps = (dispatch) => ({}); +export default connect(mapStateToProps, mapDispatchToProps)(UpdateIotWL200); diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index ec2e5af..b7b6d82 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -35,6 +35,8 @@ import { getStorageSync, setStorageSync } from "@/utils/traoAPI"; import { InstrumentInfo } from "@/utils/Interface"; import "./iotCarePlan.less"; +import UpdateIotWL200 from "@/components/bluetoot/update-wl200/index"; + // import log from "@/utils/log"; // log.info("123456info", 123456, { sdfasdf: 123 }); @@ -146,6 +148,10 @@ class IotCarePlan extends Component { model: "", }, // 当前设备 + // 升级弹窗 + isShowUpdateVersionTip: false, // 升级提示 + isShowVersionUpgrading: false, // 升级中 + /** 连接设备 */ hasVersion: false, // 是否已查询到版本号 curDeviceInfo: {}, // 当前设备信息 @@ -280,6 +286,8 @@ class IotCarePlan extends Component { queryInstructionParams ); }); + + // 监听蓝牙连接状态改变 Taro.onBLEConnectionStateChange(this.listener); await this.notifyBLECharacteristicValueChange(); @@ -288,6 +296,7 @@ class IotCarePlan extends Component { listener = (res) => { console.log("listener res", res); if (res?.connected) return; + // 蓝牙未连接才执行下面逻辑 Taro.offBLECharacteristicValueChange((res) => { console.log("offBLECharacteristicValueChange", res); }); @@ -774,18 +783,20 @@ class IotCarePlan extends Component { }; checkOta = async (versionNo) => { - const { iot_versions } = this.state.curDeviceInfo; - let isNeedToUpdateBl = isNeedToUpdate(versionNo, iot_versions); + const { iotVersion } = this.state.currentDevice; + let isNeedToUpdateBl = isNeedToUpdate(versionNo, iotVersion); console.log( `设备版本号: ${versionNo}`, - `后台版本号: ${iot_versions}`, + `后台版本号: ${iotVersion}`, `是否需要升级: ${isNeedToUpdateBl}` ); if (isNeedToUpdateBl) { - this.setState({ - isAskedOta: true, - // currentShowDialog: 'offlineDialog', - }); + // 暂停查询, 不然无法升级面罩 + this.setState({ isShowUpdateVersionTip: true }); + // this.setState({ + // isAskedOta: true, + // // currentShowDialog: 'offlineDialog', + // }); // this.confirmOta(); } }; @@ -1464,10 +1475,25 @@ class IotCarePlan extends Component { }; /** 护理记录 End */ + /** iot版本升级 */ + cancelUpdateVersionTip = () => { + this.setState({ isShowUpdateVersionTip: false }); + }; + confirmUpdateVersionTip = () => { + // 开始升级 + this.setState({ + isShowUpdateVersionTip: false, + isShowVersionUpgrading: true, + }); + }; + /** iot版本升级 END */ + render() { let { name, title, + isShowUpdateVersionTip, + isShowVersionUpgrading, isShowStepTips, isConnectionBlutoot, isShowNurse, @@ -1495,11 +1521,33 @@ class IotCarePlan extends Component { + {isShowVersionUpgrading && ( + + )} + + 检测到设备有升级请求 + 是否进行升级? + + } + textAlgin="center" + cancelButtonText="取消" + confirmButtonText="确定" + close={this.cancelUpdateVersionTip} + confirm={this.confirmUpdateVersionTip} + /> + + { confirm={this.confirmEndBtn} /> { // typeof res.data.msg == "string" // ? res.data.msg // : "系统异常,请联系管理人员"; + console.log("500 ===》", res.data.msg); if (msg == "请不要操作太快哦") { reject(res); return false; @@ -80,7 +81,7 @@ export const Ajax = (params) => { Taro.showModal({ title: "提示", - content: String(res.data.msg), + content: String(msg), showCancel: false, }); // reject(res); From 6c6b7ab6627ac1e54c8d185a735064ef704ca7dd Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Tue, 27 Feb 2024 20:41:02 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E5=8F=91=E7=AE=8D=E5=9B=BA=E4=BB=B6?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=AE=8C=E6=88=90=EF=BC=8Cwl200=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=B8=AD=EF=BC=8C=E7=9B=AE=E5=89=8D=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?wl200=E5=9B=BA=E4=BB=B6=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/components/bluetoot/connection/index.tsx | 210 ++++++++++-------- .../bluetoot/update-wl200/index.tsx | 59 +++-- src/pages/index/index.tsx | 139 ++++-------- src/pages/iotCarePlan/iotCarePlan.tsx | 2 + 5 files changed, 212 insertions(+), 200 deletions(-) diff --git a/package.json b/package.json index 115d2ad..0295a77 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "dependencies": { "@antmjs/vantui": "^3.2.2", "@flossom-npm/iot-translater": "^1.0.8", - "@flossom-npm/iot-translater-we100": "^1.0.66", + "@flossom-npm/iot-translater-we100": "^1.1.1", "@reduxjs/toolkit": "^2.0.1", "@taroify/core": "^0.1.1-alpha.8", "@tarojs/components": "3.6.19", diff --git a/src/components/bluetoot/connection/index.tsx b/src/components/bluetoot/connection/index.tsx index 35cf451..6d419e1 100644 --- a/src/components/bluetoot/connection/index.tsx +++ b/src/components/bluetoot/connection/index.tsx @@ -32,22 +32,30 @@ import { getofflineData, hex2int, getTimeCode, + isNeedToUpdate, } from "@/utils/util"; const log = require("@/utils/log"); import commandMap from "@/utils/commandMap"; import { bleCommandSamples } from "./test"; import { DeviceToolKit as DeviceToolKitWE100 } from "@flossom-npm/iot-translater-we100"; -const deviceToolKitInstanceWL200 = new DeviceToolKitWE100("WE100", "WL200"); +const deviceToolKitInstanceWL200 = new DeviceToolKitWE100("WL200", "WL200"); deviceToolKitInstanceWL200.setDebug(true); +// const _deviceToolKitInstanceWL200 = new DeviceToolKitWE100("WE100", "WL200"); + const deviceToolKitInstanceM01 = new DeviceToolKitWE100("WE100", "M01"); deviceToolKitInstanceM01.setDebug(true); const deviceToolKitInstanceFR200 = new DeviceToolKitFR200("FR200"); import { DeviceToolKit as DeviceToolKitFR200 } from "@flossom-npm/iot-translater"; -import { showModal, msg } from "@/utils/traoAPI"; +import { + showModal, + msg, + setStorageSync, + getStorageSync, +} from "@/utils/traoAPI"; // const { InstrumentTypeEnum, OtaDeviceTypeEnum } = app.globalData; import InstrumentTypeEnum from "../InstrumentTypeEnum"; @@ -72,10 +80,10 @@ let sendgetversionTimer: any = null; let sendGetVersionTimerNum = 0; let searchBluetootTimers: any = null; // 搜索蓝牙定时器 -let searchBluetootTimersNum = 0; // 搜索蓝牙秒数 +let searchBluetootTimersNum = 15; // 搜索蓝牙秒数 15秒 let connectionTimer: any = null; // 连接蓝牙定时器 -let connectionTimerNum = 0; +let connectionTimerNumber = 10000; // 连接蓝牙超时毫秒 let sendPairingTimer: any = null; // 发送配对 @@ -106,6 +114,16 @@ class ConnectionBluetoot extends Component { offlineDataindex: 0, //离线记录发送下标index versionInfo: {}, //版本号 offlineDataList: [], //离线数据 + + prefix: "12CAA", // WL200蓝牙搜索前缀 + + // WL200匹配 + tranType: [ + "WE100", // 发箍 + "WE200", // 发箍 + "WL200", // 发箍 + "12CAA", // 面罩前缀名 + ], }; } @@ -122,6 +140,14 @@ class ConnectionBluetoot extends Component { async initData() {} + isWL200() { + let currentDevicesName = getStorageSync("currentDevicesName"); + if (currentDevicesName.indexOf("12CAA") > -1) { + return true; + } + return false; + } + close() { clearInterval(sendPairingTimer); clearInterval(sendgetversionTimer); @@ -267,7 +293,7 @@ class ConnectionBluetoot extends Component { "searchBluetootTimersNum value => ", searchBluetootTimersNum ); - if (searchBluetootTimersNum === 8) { + if (searchBluetootTimersNum === 15) { clearInterval(searchBluetootTimers); this.setState({ error: true, @@ -289,43 +315,36 @@ class ConnectionBluetoot extends Component { onBluetoothDeviceFound() { Taro.onBluetoothDeviceFound((item: any) => { console.log("蓝牙查找item", item, item.devices[0].name); - /* - * 这里增加判断,类型不同识别的设备名称不一样 - * type1 FR200 - * type2 WM100 - * type3 we100 - * type4 FR380 - * */ - // const tranType = { - // 1: "FR200", - // 3: "WE200", // WL200 - // 4: "FR380", - // 5: "FR390", - // 6: "WE200", // M01 - // }; - // let type = this.props.yiqiInfo.model || "FR200"; - let type = "WE200"; - // this.props.yiqiInfo.model = type; - console.log("this.props.yiqiInfo.model", this.props.yiqiInfo.model); console.info("搜索到到蓝牙设备 value => ", item.devices[0]?.name); + console.log(">>>>>>>当前传入设备类型>>>>>", this.props.yiqiInfo.model); + // 先匹配到哪个连接哪个 + let tranType = [ + this.props.yiqiInfo.model, // 当前传入设备类型 + ...this.state.tranType, + ]; for (let i = 0; i < item.devices.length; i++) { - if ( - item.devices[i].connectable && - (item.devices[i].localName - ? item.devices[i].localName - : item.devices[i].name - ).indexOf(`${type}`) !== -1 - ) { - console.log("连接的设备信息", item.devices[i], type); + let devicesName = item.devices[i].localName || item.devices[i].name; + console.log("devicesName", devicesName); + console.log("tranType", tranType); + // 是否匹配可连接设备 + let isAvailable = tranType.some( + (item) => devicesName && devicesName.indexOf(item) > -1 + ); + console.log("isAvailable", isAvailable); + // 判断设备是否可连接 + if (item.devices[i].connectable && isAvailable) { + // 缓存当前连接设备名 可能是发箍或面罩 + setStorageSync("currentDevicesName", devicesName); + console.log("连接的设备信息", item.devices[i], devicesName); + let params = { deviceId: item.devices[i].deviceId, }; - this.props.setDeviceId(params); + this.props.setDeviceId(params); // 设置蓝牙连接设备ID setTimeout(() => { clearInterval(searchBluetootTimers); Taro.stopBluetoothDevicesDiscovery(); //停止搜索蓝牙 - // app.globalData.deviceInfo.deviceId = item.devices[i].deviceId; this.createBLEConnection(); }, 10); break; @@ -343,10 +362,6 @@ class ConnectionBluetoot extends Component { } 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) => { @@ -362,7 +377,7 @@ class ConnectionBluetoot extends Component { if (overTimer) clearTimeout(overTimer); this.failErrorCode(-1, "连接蓝牙失败,请重新开机后重试"); } - }, 10000); + }, connectionTimerNumber); } this.getBLEDeviceServices(); //获取特征 } else { @@ -424,6 +439,7 @@ class ConnectionBluetoot extends Component { console.log("onBLECharacteristicValueChange value => ", value); let str = ab2hex(value.value); //转为16进制字符串 console.log("转为16进制字符串 str", str); + let connectionStatus = [ "FR200", "WL200", @@ -434,27 +450,29 @@ class ConnectionBluetoot extends Component { let jsonStatus: any = null; let querySubDeviceArrayBuffer; + if (deviceInfo.model == "WL200") { - querySubDeviceArrayBuffer = - deviceToolKitInstanceWL200.toBleCommand( - bleCommandSamples.querySubDevice as any + if (this.isWL200()) { + jsonStatus = deviceToolKitInstanceWL200.toJsonStatus( + value.value ); - jsonStatus = deviceToolKitInstanceWL200.toJsonStatus(value.value); - // jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value); - // querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand( - // bleCommandSamples.querySubDevice as any - // ); // todo + querySubDeviceArrayBuffer = + deviceToolKitInstanceWL200.toBleCommand( + bleCommandSamples.querySubDevice as any + ); + } else { + jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value); + querySubDeviceArrayBuffer = + deviceToolKitInstanceM01.toBleCommand( + bleCommandSamples.querySubDevice as any + ); + } } else if (deviceInfo.model == "M01") { jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value); querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand( bleCommandSamples.querySubDevice as any ); } - // log.info( - // commandMap.reciviedBLECommand, - // `仪器模式: ${deviceInfo.model}`, - // jsonStatus - // ); console.log( commandMap.reciviedBLECommand, `仪器模式: ${deviceInfo.model}`, @@ -487,7 +505,7 @@ class ConnectionBluetoot extends Component { }*/ } break; - case "BleStatusSync": + case "BleStatusSync": // 设备连接状态 if (jsonStatus.connectMessage?.connectType == "CONNECTED") { switch (jsonStatus.connectMessage?.deviceName) { case OtaDeviceTypeEnum.WE100: @@ -523,9 +541,24 @@ class ConnectionBluetoot extends Component { subDeviceConnectedStatus: true, synchronousStatus: true, }); - const deviceVersionNo = jsonStatus.versionNo; - const latestVersionNo = deviceInfo.iot_versions; - // const isNeedToUpdateBl = isNeedToUpdate(deviceVersionNo, latestVersionNo) + + let currentDevicesName = getStorageSync("currentDevicesName"); + let deviceVersionNo = jsonStatus.versionNo; + let latestVersionNo = deviceInfo.iotVersion; + if (currentDevicesName.indexOf("12CAA") < -1) { + latestVersionNo = deviceInfo.we200IotVersion; + } + const isNeedToUpdateBl = isNeedToUpdate( + deviceVersionNo, + latestVersionNo + ); + console.log("deviceInfo", deviceInfo); + console.log("isNeedToUpdateBl", isNeedToUpdateBl); + if (isNeedToUpdateBl) { + // 版本号需要更新,显示更新弹窗 + this.props.upgradeFun(); + } + // 判断是否需要升级 // M01和WL200 不需要在这里进行蓝牙更新 // if (isNeedToUpdateBl) { @@ -551,9 +584,12 @@ class ConnectionBluetoot extends Component { hasSyncRecord: true, synchronousStatus: true, }); - console.log("offlineClockSummary value =>", jsonStatus); - // this.triggerEvent("pairingChange", this.state); - this.pairingChange(this.state); + console.log( + "离线汇总offlineClockSummary value =>", + jsonStatus + ); + // this.triggerEvent("pairingChange", this.state); + // this.pairingChange(this.state); // TODO 查询离线记录结果 default: break; @@ -629,25 +665,20 @@ class ConnectionBluetoot extends Component { value: `dbf0a00300${ccrc8("dbf0a00300")}de`, }); } else { - // const otaDeviceType = deviceInfo.type == instrumentTypeEnum.WL200 ? OtaDeviceTypeEnum.WL200 : OtaDeviceTypeEnum.WE100; - // 通过发箍连 都用we100 - const otaDeviceType = - deviceInfo.model == InstrumentTypeEnum.WL200 - ? OtaDeviceTypeEnum.WE100 - : OtaDeviceTypeEnum.WE100; + const otaDeviceType = this.isWL200() + ? OtaDeviceTypeEnum.WL200 + : OtaDeviceTypeEnum.WE100; const versionCommand = { commandType: "InfoQuery", infoQueryType: "versionInfo", otaDeviceType, }; - // const value = - // deviceInfo.model == InstrumentTypeEnum.WL200 - // ? deviceToolKitInstanceM01.toBleCommand(versionCommand as any) - // : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); - const value = - deviceInfo.type == InstrumentTypeEnum.WL200 - ? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any) - : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); + console.log("versionCommand", versionCommand); + + // 区分WL200 和 发箍 + const value = this.isWL200() + ? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any) + : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); sendCommand({ value }); } } @@ -710,14 +741,20 @@ class ConnectionBluetoot extends Component { ); break; case InstrumentTypeEnum.WL200: - // console.log("WL200无法配对,只能用M01"); console.log("正在发送WL200", bleCommandSamples.match); - // matchArrayBuffer = deviceToolKitInstanceWL200.toBleCommand( - // bleCommandSamples.match as any - // ); - matchArrayBuffer = deviceToolKitInstanceM01.toBleCommand( - bleCommandSamples.match as any - ); + let currentDevicesName = getStorageSync("currentDevicesName"); + // 区分面罩和发箍 + if (currentDevicesName.indexOf("12CAA") > -1) { + console.log("12CAA"); + matchArrayBuffer = deviceToolKitInstanceWL200.toBleCommand( + bleCommandSamples.match as any + ); + } else { + matchArrayBuffer = deviceToolKitInstanceM01.toBleCommand( + bleCommandSamples.match as any + ); + } + break; case InstrumentTypeEnum.FR380: writeBLECharacteristicValue({ @@ -905,7 +942,8 @@ class ConnectionBluetoot extends Component { isGetSubDeviceTimer = setInterval(() => { sendCommand({ value }); isGetSubDeviceTimerNum += 1; - if (isGetSubDeviceTimerNum == 8) { + // 15秒超时 + if (isGetSubDeviceTimerNum === 15) { this.closeQuerySubDevice(); this.setState({ error: true, @@ -928,7 +966,6 @@ class ConnectionBluetoot extends Component { isGetVersionTimer = setInterval(() => { if (this.state.hasVersionInfo) { if (isGetVersionTimer) clearTimeout(isGetVersionTimer); - // that.sendSyncRecording() } else { sendGetVersionTimerNum += 1; if (sendGetVersionTimerNum >= 10) { @@ -937,8 +974,8 @@ class ConnectionBluetoot extends Component { this.setState({ connectionStatus: true, }); - console.log("this.pairingChange", this.state); - this.pairingChange(this.state); + console.log("超时未返回版本号 this.pairingChange", this.state); + // this.pairingChange(this.state); } else { this.sendGetVersion(); } @@ -963,10 +1000,9 @@ class ConnectionBluetoot extends Component { commandType: "InfoQuery", infoQueryType: "offlineClockSummary", }; - const value = - deviceInfo.model == InstrumentTypeEnum.WL200 - ? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any) - : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); + const value = this.isWL200() + ? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any) + : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); sendCommand({ value }).then(); if (isGetSyncRecordingTimer) clearTimeout(isGetSyncRecordingTimer); isGetSyncRecordingTimer = setTimeout(() => { diff --git a/src/components/bluetoot/update-wl200/index.tsx b/src/components/bluetoot/update-wl200/index.tsx index d31f281..92ef3e4 100644 --- a/src/components/bluetoot/update-wl200/index.tsx +++ b/src/components/bluetoot/update-wl200/index.tsx @@ -40,8 +40,12 @@ import OtaDeviceTypeEnum from "../OtaDeviceTypeEnum"; // 临时替代 var log = console; -var deviceToolKitInstance: any = null; -deviceToolKitInstance = new DeviceToolKitWE100("WE100", "WL200"); + +let deviceToolKitInstance: any = null; +// WE200 M01 M02都是WE200 +let deviceToolKitInstanceM01 = new DeviceToolKitWE100("WE100", "M01"); +// WL200面罩 +let deviceToolKitInstanceWL200 = new DeviceToolKitWE100("WL200", "WL200"); import "./index.less"; @@ -80,8 +84,24 @@ class UpdateIotWL200 extends Component { this.initData(); } + isWL200() { + let currentDevicesName = getStorageSync("currentDevicesName"); + if (currentDevicesName.indexOf("12CAA") > -1) { + return true; + } + return false; + } + async initData() { console.log("UpdateIotWL200"); + if (this.isWL200()) { + console.log("WL200更新"); + deviceToolKitInstance = deviceToolKitInstanceWL200; + } else { + console.log("WE100更新"); + deviceToolKitInstance = deviceToolKitInstanceM01; + } + let objStr = getStorageSync("instrument_detail"); if (objStr) { let info = JSON.parse(objStr); @@ -89,12 +109,6 @@ class UpdateIotWL200 extends Component { this.setState({ currentDevice: info, }); - - if (info.model == InstrumentTypeEnum.WL200) { - deviceToolKitInstance = new DeviceToolKitWE100("WE100", "WL200"); - } else { - deviceToolKitInstance = new DeviceToolKitWE100("WE100", "M01"); - } } setTimeout(() => { this.notifyBLECharacteristicValueChange(); @@ -134,22 +148,22 @@ class UpdateIotWL200 extends Component { */ startOTA() { this.resetOta(); - const { currentDevice } = this.state; let jsoncmd = { commandType: "OTAStart", otaDeviceType: "", versionNo: this.$otaDataGroup.versionNo, }; // 根据设备类型传 otaDeviceType - if (currentDevice.model == InstrumentTypeEnum.M01) { - jsoncmd.otaDeviceType = OtaDeviceTypeEnum.WE100; - } else { + if (this.isWL200()) { jsoncmd.otaDeviceType = OtaDeviceTypeEnum.WL200; + } else { + jsoncmd.otaDeviceType = OtaDeviceTypeEnum.WE100; } - // deviceToolKitInstance.setDebug(true) + + console.log("startOTA jsoncmd", jsoncmd); //@ts-ignore - const value = deviceToolKitInstance.toBleCommand(jsoncmd); + const value = deviceToolKitInstance.toBleCommand(jsoncmd as any); console.log(jsoncmd); sendCommand({ value }).then((res) => { this.setState({ @@ -173,7 +187,7 @@ class UpdateIotWL200 extends Component { }; console.info("OTAPrepare json => ", jsoncmd); //@ts-ignore - const value = deviceToolKitInstance.toBleCommand(jsoncmd); + const value = deviceToolKitInstance.toBleCommand(jsoncmd as any); sendCommand({ value }); } /** @@ -194,7 +208,7 @@ class UpdateIotWL200 extends Component { }; console.info("OTAUpdating json => ", jsoncmd); //@ts-ignore - const value = deviceToolKitInstance.toBleCommand(jsoncmd); + const value = deviceToolKitInstance.toBleCommand(jsoncmd as any); sendCommand({ value }); } /** @@ -208,7 +222,7 @@ class UpdateIotWL200 extends Component { clearInterval(this.$checkTimer); log.info("ota成功日志, 清除计时器"); //@ts-ignore - const value = deviceToolKitInstance.toBleCommand(jsoncmd); + const value = deviceToolKitInstance.toBleCommand(jsoncmd as any); sendCommand({ value }).then((res) => { this.resetOta(); }); @@ -231,7 +245,7 @@ class UpdateIotWL200 extends Component { commandType: "OTAQuit", }; //@ts-ignore - const value = deviceToolKitInstance.toBleCommand(jsoncmd); + const value = deviceToolKitInstance.toBleCommand(jsoncmd as any); sendCommand({ value }) .then((res) => { this.resetOta(); @@ -357,7 +371,7 @@ class UpdateIotWL200 extends Component { Taro.onBLECharacteristicValueChange((value) => { // let str = ab2hex(value.value); //转为16进制字符串 // console.log('返回',str) - const jsonStatus = deviceToolKitInstance.toJsonStatus(value.value); + const jsonStatus: any = deviceToolKitInstance.toJsonStatus(value.value); log.info("OTA页面设备响应数据打印==》", JSON.stringify(jsonStatus)); console.info("onBLECharacteristicValueChange json => ", jsonStatus); this.$otaDataGroup.currentPackageNo = jsonStatus.currentPackageNo; @@ -376,7 +390,7 @@ class UpdateIotWL200 extends Component { this.$checkTimer = setInterval(() => { // 超过7s没有回包, 直接断开 if (this.$otaDataGroup.countDown <= 0 && this.state.hadStartOta) { - if (this.state.currentDevice.model == InstrumentTypeEnum.M01) { + if (!this.isWL200()) { this.quitOTA("shutDownMaskTip"); } else { this.quitOTA("updateTimeOut"); @@ -412,6 +426,7 @@ class UpdateIotWL200 extends Component { render() { let { isShow } = this.props; + let { progressbar } = this.state; return ( @@ -437,11 +452,11 @@ class UpdateIotWL200 extends Component { - {0.01 * 100}% + {progressbar}% 注意事项: 1.保持设备开机状态 diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 6c0b876..fb5322e 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -25,10 +25,12 @@ import PopupBinding from "@/components/popup/popup-binding"; import PopupSiteSwiper from "@/components/popup/popup-site-swiper"; import PopupAlert from "@/components/popup/popup-alert"; +import PopupConfirm from "@/components/popup/popup-confirm"; import type CustomTabBar from "@/custom-tab-bar"; import Navbar from "@/components/navbar/navbar"; import ConnectionBluetoot from "@/components/bluetoot/connection"; +import UpdateIotWL200 from "@/components/bluetoot/update-wl200/index"; /** 自定义组件 **/ import { @@ -134,6 +136,10 @@ class Index extends Component { connectInstrument: {}, yiqiinfo: {}, /* END */ + + // 设备升级弹窗 + isShowUpdateVersionTip: false, // 升级提示 + isShowVersionUpgrading: false, // 升级中 }; } @@ -650,96 +656,7 @@ class Index extends Component { versionInfo, }); let offlinelist: any = []; - offlineDataList.map((item, index) => { - let obj: any = { - clock_day: "", - status: 3, - second: 120, - screne_id: "", - screne_name: "离线打卡", - model_face_ward: 0, - model_face_use: 0, - model_face_type: "", - model_eye_ward: 0, - model_eye_use: 0, - model_eye_type: "", - instrument_id: this.state.connectInstrument.id, - }; - - //判断日期是否正常,如果不正常不处理 --- 脸部 - if ( - item.faceyear > 0 && - item.faceyear <= 99 && - item.facemonth >= 1 && - item.facemonth <= 12 && - item.faceday >= 1 && - item.faceday <= 31 - ) { - if ( - item.facehour > 0 || - (item.faceminutes > 0 && item.faceminutes < 60) || - (item.faceseconds > 0 && item.faceseconds < 60) - ) { - //脸部离线记录有值 - obj.model_face_use = - Number(item.facehour) * 60 * 60 + - Number(item.faceminutes) * 60 + - Number(item.faceseconds); - obj.model_face_ward = item.faceposition1; - obj.clock_day = `20${String(item.faceyear).padStart(2, "0")}-${String( - item.facemonth - ).padStart(2, "0")}-${String(item.faceday).padStart(2, "0")}`; - } - } - //判断日期是否正常,如果不正常不处理 --- 眼部 - if ( - item.eyeyear > 0 && - item.eyeyear <= 99 && - item.eyemonth >= 1 && - item.eyemonth <= 12 && - item.eyeday >= 1 && - item.eyeday <= 31 - ) { - if ( - item.eyehour > 0 || - (item.eyeminutes > 0 && item.eyeminutes < 60) || - (item.eyeseconds > 0 && item.eyeseconds < 60) - ) { - //眼部离线记录有值 - obj.model_eye_use = - Number(item.eyehour) * 60 * 60 + - Number(item.eyeminutes) * 60 + - Number(item.eyeseconds); - obj.model_eye_ward = item.eyeposition1; - obj.clock_day = `20${String(item.eyeyear).padStart(2, "0")}-${String( - item.eyemonth - ).padStart(2, "0")}-${String(item.eyeday).padStart(2, "0")}`; - } - } - obj.second = obj.model_face_use + obj.model_eye_use; - - if ( - item.faceyear > 0 && - item.faceyear <= 99 && - (item.facemonth == 1 || item.facemonth <= 12) && - (item.faceday == 1 || item.faceday <= 31) - ) { - let dayTime = new Date(`${obj.clock_day.replace(/-/g, "/")}`).getTime(); //离线记录的日期 - let now = new Date( - `${new Date().getFullYear()}/${String( - new Date().getMonth() + 1 - ).padStart(2, "0")}/${String(new Date().getDate()).padStart(2, "0")}` - ).getTime(); //当前日期 - /** - * 过滤7天前的离线记录 - * - */ - if (dayTime <= now && dayTime >= now - 24 * 60 * 60 * 1000 * 6) { - offlinelist.push(obj); - } - } - }); console.log(offlinelist); }; @@ -752,8 +669,25 @@ class Index extends Component { connectionConfirm = async () => { this.connectionClose(); }; - /*蓝牙 END*/ + + /** iot版本升级 */ + // 是否更新弹窗 + upgradeFun = () => { + this.setState({ isShowUpdateVersionTip: true, isConnectShow: false }); + }; + cancelUpdateVersionTip = () => { + this.setState({ isShowUpdateVersionTip: false }); + }; + confirmUpdateVersionTip = () => { + // 开始升级 + this.setState({ + isShowUpdateVersionTip: false, + isShowVersionUpgrading: true, + }); + }; + /** iot版本升级 END */ + render() { let { calendarComplete, @@ -777,6 +711,10 @@ class Index extends Component { instrumentInfo, instrumentList, + // 升级弹窗 + isShowUpdateVersionTip, + isShowVersionUpgrading, + // 蓝牙连接 isConnectShow, connectInstrument, @@ -785,6 +723,26 @@ class Index extends Component { return ( + {isShowVersionUpgrading && ( + + )} + + 检测到设备有升级请求 + 是否进行升级? + + } + textAlgin="center" + cancelButtonText="取消" + confirmButtonText="确定" + close={this.cancelUpdateVersionTip} + confirm={this.confirmUpdateVersionTip} + /> { confirm={this.connectionConfirm} offlineChange={this.offlineChange} pairingChange={this.pairingChange} + upgradeFun={this.upgradeFun} /> )} {/* */} diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index b7b6d82..249ec5d 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -584,6 +584,8 @@ class IotCarePlan extends Component { // }); } }; + + // 蓝牙特征更改 notifyBLECharacteristicValueChange = () => { console.log("notifyBLECharacteristicValueChange deviceInfo 参数为=>"); const bluetoothInfo = this.props.bluetoothInfo; From aec9e1ee3e5385b680b471c02136c0774bbf465b Mon Sep 17 00:00:00 2001 From: blak-kong <546598185@qq.com> Date: Wed, 28 Feb 2024 16:26:12 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E4=B8=B4=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/bluetoot/connection/index.tsx | 61 ++------ .../bluetoot/update-wl200/index.tsx | 22 +-- src/pages/index/index.tsx | 141 ++++++++++++++---- src/pages/iotCarePlan/iotCarePlan.tsx | 59 -------- 4 files changed, 136 insertions(+), 147 deletions(-) diff --git a/src/components/bluetoot/connection/index.tsx b/src/components/bluetoot/connection/index.tsx index 6d419e1..ea52e68 100644 --- a/src/components/bluetoot/connection/index.tsx +++ b/src/components/bluetoot/connection/index.tsx @@ -316,10 +316,10 @@ class ConnectionBluetoot extends Component { Taro.onBluetoothDeviceFound((item: any) => { console.log("蓝牙查找item", item, item.devices[0].name); console.info("搜索到到蓝牙设备 value => ", item.devices[0]?.name); - console.log(">>>>>>>当前传入设备类型>>>>>", this.props.yiqiInfo.model); + console.log(">>>>>>>当前传入设备类型>>>>>", this.props.deviceInfo.model); // 先匹配到哪个连接哪个 let tranType = [ - this.props.yiqiInfo.model, // 当前传入设备类型 + this.props.deviceInfo.model, // 当前传入设备类型 ...this.state.tranType, ]; for (let i = 0; i < item.devices.length; i++) { @@ -361,7 +361,7 @@ class ConnectionBluetoot extends Component { await closeBLEConnection(this.props.bluetoothInfo.deviceId); } catch (e) {} clearTimeout(connectionTimer); - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; /*********开始主动连接*******/ createBLEConnection(this.props.bluetoothInfo.deviceId) .then((res) => { @@ -369,9 +369,6 @@ class ConnectionBluetoot extends Component { let { errno, errMsg } = res; if (errno == 0) { if (deviceInfo.model === "WL200") { - this.setState({ - connectionStatus: true, - }); connectionTimer = setTimeout(() => { if (!this.state.islian) { if (overTimer) clearTimeout(overTimer); @@ -422,7 +419,7 @@ class ConnectionBluetoot extends Component { /** 7.通知BLE特征值更改 */ notifyBLECharacteristicValueChange() { console.log("7.通知BLE特征值更改"); - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; const bluetoothInfo = this.props.bluetoothInfo; notifyBLECharacteristicValueChange({ deviceId: bluetoothInfo.deviceId, @@ -440,14 +437,6 @@ class ConnectionBluetoot extends Component { let str = ab2hex(value.value); //转为16进制字符串 console.log("转为16进制字符串 str", str); - let connectionStatus = [ - "FR200", - "WL200", - "FR380", - "FR390", - "M01", - ].includes(deviceInfo.model); - let jsonStatus: any = null; let querySubDeviceArrayBuffer; @@ -488,7 +477,6 @@ class ConnectionBluetoot extends Component { if (overTimer) clearTimeout(overTimer); this.setState({ connectionSuccess: true, - connectionStatus, islian: true, // 不需要离线记录,但暂未完全删除这部分逻辑,所以直接设为true }); @@ -548,34 +536,15 @@ class ConnectionBluetoot extends Component { if (currentDevicesName.indexOf("12CAA") < -1) { latestVersionNo = deviceInfo.we200IotVersion; } + // 判断版本号是否需要升级 const isNeedToUpdateBl = isNeedToUpdate( deviceVersionNo, latestVersionNo ); - console.log("deviceInfo", deviceInfo); - console.log("isNeedToUpdateBl", isNeedToUpdateBl); if (isNeedToUpdateBl) { - // 版本号需要更新,显示更新弹窗 + // 版本号需要更新: 告诉父级页面,关闭连接弹窗,显示更新弹窗 this.props.upgradeFun(); } - - // 判断是否需要升级 - // 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); @@ -651,7 +620,7 @@ class ConnectionBluetoot extends Component { // 8.发送指令:获取仪器版本号 sendGetVersion() { - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; const isFRDevice = ["FR200", "FR380", "FR390"].includes(deviceInfo.model); // log.info(commandMap.sendVersionCommand, `仪器:${deviceInfo.model}`); console.log(commandMap.sendVersionCommand, `仪器:${deviceInfo.model}`); @@ -730,7 +699,7 @@ class ConnectionBluetoot extends Component { /** 9.发送配对码 */ sendPairingSignal() { console.log("9.发送配对码 sendPairingSignal"); - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; // log.info(commandMap.sendMatchCode, `仪器:${deviceInfo.model}发送匹配码`); console.log(commandMap.sendMatchCode, `仪器:${deviceInfo.model}发送匹配码`); let matchArrayBuffer: any = null; @@ -971,9 +940,7 @@ class ConnectionBluetoot extends Component { if (sendGetVersionTimerNum >= 10) { // 超时未返回版本号 if (isGetVersionTimer) clearTimeout(isGetVersionTimer); - this.setState({ - connectionStatus: true, - }); + console.log("超时未返回版本号 this.pairingChange", this.state); // this.pairingChange(this.state); } else { @@ -995,7 +962,7 @@ class ConnectionBluetoot extends Component { /** 发送同步记录 */ sendSyncRecording() { - const { yiqiInfo: deviceInfo } = this.props; + const { deviceInfo } = this.props; const versionCommand = { commandType: "InfoQuery", infoQueryType: "offlineClockSummary", @@ -1036,18 +1003,16 @@ class ConnectionBluetoot extends Component { }; render() { - let { name, isConnection, connectionStatus, connectionSuccess, error } = - this.state; - let { yiqiInfo } = this.props; + let { name, isConnection, connectionSuccess, error } = this.state; + let { deviceInfo } = this.props; return ( { break; case "OTAUpdateFinish": console.log("完成OTA传输"); - log.info("ota成功日志, 但是这个分支什么都没做"); + this.setState({ + progressbar: 100, + }); + this.finishFun(); // quitOTA() break; default: @@ -331,7 +334,7 @@ class UpdateIotWL200 extends Component { getDeviceUpgrade = async () => { let res: any = await InstrumentInfo.getUpgrade({ instrumentId: this.state.currentDevice.id, - isWe200: true, + isWe200: !this.isWL200(), }); if (res.data.data == "解析失败") { // this.showError('文件解析失败'); @@ -412,16 +415,17 @@ class UpdateIotWL200 extends Component { Taro.stopPullDownRefresh(); } - onClose = () => { - this.props.close(); + onClickStop = (e) => { + e.stopPropagation(); }; - onConfirm = () => { - this.props.confirm(); + // 错误关闭回调 + errorFun = () => { + this.props.errorFun(); }; - - onClickStop = (e) => { - e.stopPropagation(); + // 升级完成回调 + finishFun = () => { + this.props.finishFun(); }; render() { diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index fb5322e..3a55dcc 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -9,6 +9,7 @@ import { Image, Swiper, SwiperItem, + RichText, } from "@tarojs/components"; /*** redux ***/ @@ -58,7 +59,7 @@ import { const log = require("@/utils/log"); import commandMap from "@/utils/commandMap"; -import InstrumentTypeEnum from "@/components/bluetoot/instrumentTypeEnum"; +import InstrumentTypeEnum from "@/components/bluetoot/InstrumentTypeEnum"; import OtaDeviceTypeEnum from "@/components/bluetoot/OtaDeviceTypeEnum"; class Index extends Component { @@ -133,13 +134,14 @@ class Index extends Component { /** 蓝牙相关 */ isConnectShow: false, - connectInstrument: {}, - yiqiinfo: {}, + connectInstrument: {}, // 当前连接设备 /* END */ // 设备升级弹窗 isShowUpdateVersionTip: false, // 升级提示 isShowVersionUpgrading: false, // 升级中 + isShowVersionUpgradFinish: false, // 升级完成:升级内容公告 + versionUpgradFinishNodes: "", // 公告内容 }; } @@ -671,21 +673,60 @@ class Index extends Component { }; /*蓝牙 END*/ - /** iot版本升级 */ + /** 设备iot固件版本升级 */ // 是否更新弹窗 upgradeFun = () => { this.setState({ isShowUpdateVersionTip: true, isConnectShow: false }); }; cancelUpdateVersionTip = () => { + // 关闭提示 this.setState({ isShowUpdateVersionTip: false }); }; confirmUpdateVersionTip = () => { - // 开始升级 + // 提示升级与开始升级 this.setState({ isShowUpdateVersionTip: false, isShowVersionUpgrading: true, }); }; + + // 完成升级 + wl200UpgradeFinishFun = (isWL200) => { + let { connectInstrument } = this.state; + console.log("connectInstrument", connectInstrument); + let content = ""; + if (isWL200) { + content = connectInstrument.iotVersionUpgrade; + } else { + content = connectInstrument.we200IotVersionUpgrade; + } + let nodes = decodeURIComponent(content || ""); + nodes = nodes.replace(/\ { + this.setState({ + isShowVersionUpgrading: false, + }); + }; + // 关闭升级完成公告 + onVersionUpgradFinish = () => { + this.setState({ + isShowVersionUpgradFinish: false, + }); + }; /** iot版本升级 END */ render() { @@ -714,6 +755,8 @@ class Index extends Component { // 升级弹窗 isShowUpdateVersionTip, isShowVersionUpgrading, + isShowVersionUpgradFinish, + versionUpgradFinishNodes, // 蓝牙连接 isConnectShow, @@ -723,25 +766,20 @@ class Index extends Component { return ( - {isShowVersionUpgrading && ( - - )} - - 检测到设备有升级请求 - 是否进行升级? + 序列号信息仍在更新,请联系微信小助理 + 协助您绑定仪器 } + confirmButtonText="知道了" textAlgin="center" - cancelButtonText="取消" - confirmButtonText="确定" - close={this.cancelUpdateVersionTip} - confirm={this.confirmUpdateVersionTip} + isClose={false} + close={this.onBindErrorClose} + confirm={this.onBindErrorConfirm} /> { isClose={false} close={this.onBindErrorClose} confirm={this.onBindErrorConfirm} - > + /> { isClose={false} close={this.onBeforeBindClose} confirm={this.onBeforeBindConfirm} - > + /> {/* { close={this.closeSiteSwiper} confirm={this.closeSiteSwiper} /> - - {isConnectShow && ( - + )} + + 检测到设备有升级请求 + 是否进行升级? + + } + textAlgin="center" + cancelButtonText="取消" + confirmButtonText="确定" + close={this.cancelUpdateVersionTip} + confirm={this.confirmUpdateVersionTip} /> - )} - {/* */} + {isShowVersionUpgrading && ( + + )} + + + + + + } + confirmButtonText="知道了" + textAlgin="left" + isClose + close={this.onVersionUpgradFinish} + confirm={this.onVersionUpgradFinish} + /> + {/* IOT相关弹窗 END */} + { model: "", }, // 当前设备 - // 升级弹窗 - isShowUpdateVersionTip: false, // 升级提示 - isShowVersionUpgrading: false, // 升级中 - /** 连接设备 */ hasVersion: false, // 是否已查询到版本号 curDeviceInfo: {}, // 当前设备信息 @@ -703,7 +699,6 @@ class IotCarePlan extends Component { this.setState({ hasVersion: true, }); - this.checkOta(jsonStatus.versionNo); } break; // 当前报告 @@ -784,25 +779,6 @@ class IotCarePlan extends Component { }); }; - checkOta = async (versionNo) => { - const { iotVersion } = this.state.currentDevice; - let isNeedToUpdateBl = isNeedToUpdate(versionNo, iotVersion); - console.log( - `设备版本号: ${versionNo}`, - `后台版本号: ${iotVersion}`, - `是否需要升级: ${isNeedToUpdateBl}` - ); - if (isNeedToUpdateBl) { - // 暂停查询, 不然无法升级面罩 - this.setState({ isShowUpdateVersionTip: true }); - // this.setState({ - // isAskedOta: true, - // // currentShowDialog: 'offlineDialog', - // }); - // this.confirmOta(); - } - }; - //待完善,以后同步设备数据到小程序的事件,在这个事件里判断是否需要更新页面(是否需要触发setData) updateDeviceSyncData = (newData, jsonStatus) => { DeviceSyncData = { @@ -1477,19 +1453,6 @@ class IotCarePlan extends Component { }; /** 护理记录 End */ - /** iot版本升级 */ - cancelUpdateVersionTip = () => { - this.setState({ isShowUpdateVersionTip: false }); - }; - confirmUpdateVersionTip = () => { - // 开始升级 - this.setState({ - isShowUpdateVersionTip: false, - isShowVersionUpgrading: true, - }); - }; - /** iot版本升级 END */ - render() { let { name, @@ -1523,29 +1486,7 @@ class IotCarePlan extends Component { - {isShowVersionUpgrading && ( - - )} - - - 检测到设备有升级请求 - 是否进行升级? - - } - textAlgin="center" - cancelButtonText="取消" - confirmButtonText="确定" - close={this.cancelUpdateVersionTip} - confirm={this.confirmUpdateVersionTip} - /> - Date: Wed, 28 Feb 2024 20:38:16 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/bluetoot/connection/index.tsx | 14 +- .../iotCarePlan/components/Footer/index.tsx | 6 +- src/pages/iotCarePlan/iotCarePlan.tsx | 312 ++++----- src/pages/recording/recording.tsx | 613 ++++++++++-------- src/pages/register/register.tsx | 26 +- 5 files changed, 508 insertions(+), 463 deletions(-) diff --git a/src/components/bluetoot/connection/index.tsx b/src/components/bluetoot/connection/index.tsx index ea52e68..30f890a 100644 --- a/src/components/bluetoot/connection/index.tsx +++ b/src/components/bluetoot/connection/index.tsx @@ -533,7 +533,7 @@ class ConnectionBluetoot extends Component { let currentDevicesName = getStorageSync("currentDevicesName"); let deviceVersionNo = jsonStatus.versionNo; let latestVersionNo = deviceInfo.iotVersion; - if (currentDevicesName.indexOf("12CAA") < -1) { + if (currentDevicesName.indexOf("12CAA") === -1) { latestVersionNo = deviceInfo.we200IotVersion; } // 判断版本号是否需要升级 @@ -541,9 +541,14 @@ class ConnectionBluetoot extends Component { deviceVersionNo, latestVersionNo ); + console.log("isNeedToUpdateBl", isNeedToUpdateBl); if (isNeedToUpdateBl) { // 版本号需要更新: 告诉父级页面,关闭连接弹窗,显示更新弹窗 this.props.upgradeFun(); + } else { + // 不需要升级,跳转进入仪器详情页 + if (isGetVersionTimer) clearTimeout(isGetVersionTimer); + this.pairingChange(this.state); } break; case "offlineClockSummary": @@ -648,6 +653,7 @@ class ConnectionBluetoot extends Component { const value = this.isWL200() ? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any) : deviceToolKitInstanceM01.toBleCommand(versionCommand as any); + sendCommand({ value }); } } @@ -807,9 +813,6 @@ class ConnectionBluetoot extends Component { case 10000: errorText = "未初始化蓝牙适配器"; break; - case 10000: - errorText = "未初始化蓝牙适配器"; - break; case 10001: errorText = "当前蓝牙适配器不可用"; break; @@ -940,14 +943,13 @@ class ConnectionBluetoot extends Component { if (sendGetVersionTimerNum >= 10) { // 超时未返回版本号 if (isGetVersionTimer) clearTimeout(isGetVersionTimer); - console.log("超时未返回版本号 this.pairingChange", this.state); // this.pairingChange(this.state); } else { this.sendGetVersion(); } } - }, 600); + }, 1000); // 5秒后没有收到版本返回,直接跳去护理页 // if (isGetVersionTimer) clearTimeout(isGetVersionTimer); diff --git a/src/pages/iotCarePlan/components/Footer/index.tsx b/src/pages/iotCarePlan/components/Footer/index.tsx index 0061056..f4e3fe3 100644 --- a/src/pages/iotCarePlan/components/Footer/index.tsx +++ b/src/pages/iotCarePlan/components/Footer/index.tsx @@ -5,7 +5,7 @@ import { useState, useEffect } from "react"; import "./index.less"; interface Props { - isConnectionBlutoot: boolean; + isCanClick: boolean; isShowNurse: boolean; isStopNurse: boolean; onEmitStartNurse: Function; // 每次点击item,回调事件和数据给父组件 @@ -13,7 +13,7 @@ interface Props { onEmitEndPlan: Function; } function Index({ - isConnectionBlutoot, + isCanClick, isShowNurse, isStopNurse, onEmitStartNurse, @@ -37,7 +37,7 @@ function Index({ {!isShowNurse && ( - {isConnectionBlutoot ? ( + {isCanClick ? ( 开始护理 diff --git a/src/pages/iotCarePlan/iotCarePlan.tsx b/src/pages/iotCarePlan/iotCarePlan.tsx index 30cbaba..1ebe153 100644 --- a/src/pages/iotCarePlan/iotCarePlan.tsx +++ b/src/pages/iotCarePlan/iotCarePlan.tsx @@ -57,8 +57,7 @@ import { } from "@/utils/util"; import { DeviceToolKit as DeviceToolKitWE100 } from "@flossom-npm/iot-translater-we100"; import commandMap from "@/utils/commandMap"; -const deviceToolKitInstanceWE100 = new DeviceToolKitWE100("WE100", "M01"); -const deviceToolKitInstanceWL200 = new DeviceToolKitWE100("WE100", "WL200"); +const deviceToolKitInstanceWL200 = new DeviceToolKitWE100("WL200", "WL200"); let currentTimeTimer: any = null; // 当前项目时间定时器 let CountdownTimer: any = null; @@ -70,22 +69,6 @@ let switchModeStatus = "free"; // 用于标记是否在切换模式中, free: // 设备运行时间校准频率,每多少秒校准一次 const TIME_CALIBRATION_FREQUENCY = 5; -// 模式类型 -const WORK_MODE_NAME_ENUM = { - POWERFULSOOTHING: "powerfulSoothing", - STABILITY: "Stability", - BRIGHTEN: "Brighten", - FIRMSKIN: "FirmSkin", - MaskCustom: "MaskCustom", - BrightenStand: "BrightenStand", - FirmSkinStand: "FirmSkinStand", - SmallpoxSoothingPro: "SmallpoxSoothingPro", - SmallpoxSoothing: "SmallpoxSoothing", - MixNursePro: "MixNursePro", - MixNurse: "MixNurse", - ScalpCare: "ScalpCare", -}; - // 组合模式:分别对应的是哪几个模式类型 // 黄光590nm // 红光630nm @@ -114,12 +97,12 @@ const MODE_WORKING_ENUM = { END: "end", }; -// 倒计时时间 +// 不同模式启动前的倒计时时间 let CountDownTime = { powerfulSoothing: 6, - Stability: 4, - Brighten: 4, - FirmSkin: 4, + Stability: 3, + Brighten: 3, + FirmSkin: 3, MaskCustom: 6, BrightenStand: 6, FirmSkinStand: 6, @@ -134,7 +117,7 @@ let DeviceSyncData = { totalWorkingMinutes: 0, totalWorkingSeconds: 0, }; -let deviceToolKitInstance = deviceToolKitInstanceWE100; // we100 +let deviceToolKitInstance = deviceToolKitInstanceWL200; class IotCarePlan extends Component { constructor(props) { @@ -142,20 +125,18 @@ class IotCarePlan extends Component { this.state = { name: "iotCarePlan", title: "美容仪名字", // 页面标题 - instrument: "WE200", + // 当前设备 currentDevice: { name: "", model: "", - }, // 当前设备 + }, /** 连接设备 */ hasVersion: false, // 是否已查询到版本号 - curDeviceInfo: {}, // 当前设备信息 basicModeList: [], //模式列表 modelActiveIndex: 0, //模式下标 sliderProgress: 22, - isStandStatus: false, // 支架开启状态(支架就是舱体) - facialMaskConnectStatus: 0, // 面罩连接状态 0未连接 1已连接 + facialMaskConnectStatus: 1, // 面罩连接状态 0未连接 1已连接 workStatus: "", // 工作状态 Electricity: 4, // WL200电量 matrixElectricity: 4, // WE200发箍电量 @@ -164,10 +145,7 @@ class IotCarePlan extends Component { gear: { gear: 1 }, currentShowDialog: "", - // countdown: 3, // 倒计时 step: 1, // 1:选择模式并播放视频, 2:护理中 - isCheckedMaskVersion: false, // 是否检查过固件版本了 - isAskedOta: false, // 询问过用户是否需要OTA showVideoPlayBtn: true, // 视频播放按钮 duration: 0, // 视频总时长 hadShowBreakTips: false, // 是否展示过支架断开提示 @@ -175,12 +153,15 @@ class IotCarePlan extends Component { /** 连接设备 End */ + /** 护理过程 */ + isStandStatus: false, // 当前模式是否舱体/支架模式 isShowStepTips: false, // 是否显示介绍步骤弹窗 - isConnectionBlutoot: false, // 是否已连接蓝牙 + isConnectionBlutoot: true, // 是否已连接蓝牙 isShowNurse: false, // 是否开始并显示护理 isStopNurse: false, // 是否暂停护理 isEndNurse: false, // 是否结束护理 errorTips: "", // 错误提示 + /** 护理过程 END*/ // 模式列表 isSwitchActiveMode: false, // 是否显示弹窗切换模式 @@ -198,21 +179,20 @@ class IotCarePlan extends Component { startSource: "", stopSource: "", }, + // 模式组合 isCombineSuccess: false, // 组合模式是否设置成功 - // 倒计时 isShowCountdown: false, // 倒计时弹窗 countdown: 3, - // 是否结束护理 isEndCarePlan: false, - // 最后执行步骤位置 endPlace: "", currentTime: "01:00", }; } + hadGotInstrumentHistoryData = false; // 已缓存仪器历史数据 async onLoad() { // 保持屏幕常亮 @@ -244,7 +224,7 @@ class IotCarePlan extends Component { currentDevice: info, }); - this.GetModeList(info.id); + await this.GetModeList(info.id); console.log("info"); // 如果不存在设备模式值,则判断为首次进入,弹窗提示 @@ -321,7 +301,9 @@ class IotCarePlan extends Component { ModeList: res.data.data, }); - this.modeCurrentFun(res.data.data[0]); + setTimeout(() => { + this.modeCurrentFun(res.data.data[0]); + }); } else { this.setState({ ModeList: res.data.data }); } @@ -360,6 +342,17 @@ class IotCarePlan extends Component { /** 选中护理模式 */ modeCurrentFun = async (data) => { + let { isStandStatus } = this.state; + // 舱体模式无法对应的时候,置灰开始按钮 + let isCabinMode = data.isCabinMode === 1; + if (isStandStatus === isCabinMode) { + this.setState({ isCanClick: true }); + } else { + this.setState({ isCanClick: false }); + } + console.log("isStandStatus", isStandStatus, isCabinMode); + console.log("isStandStatus === isCabinMode", isStandStatus === isCabinMode); + let currentServiceData = { startSource: "", stopSource: "", @@ -431,22 +424,19 @@ class IotCarePlan extends Component { ModeType: modeArray[modeClass], isShowNurse: true, isStopNurse: true, - isStandStatus: this.state.ActiveModeItem.isCabinMode === 1, workStatus: "pause", step: 2, }); - this.handleWorkStatus(false, MODE_WORKING_ENUM.STANDBY); + setTimeout(() => { + this.handleWorkStatus(false, MODE_WORKING_ENUM.STANDBY); + }); }; /** 开始护理按钮:点击开始,页面进行到下一步 */ onStartNurse = async () => { - this.stepNext(); - return; - let { isConnectionBlutoot } = this.state; - if (isConnectionBlutoot) { + let { isCanClick } = this.state; + if (isCanClick) { this.stepNext(); - } else { - // todo 提示未连接蓝牙 } }; /** 切换光照 */ @@ -474,6 +464,7 @@ class IotCarePlan extends Component { /** 蓝牙相关 */ switchBLEMatch = (jsonStatus: any) => { + console.log("蓝牙相关", jsonStatus); switch (jsonStatus.bleCommandType) { // 如果设备配对链接发送配对码的时候,设备应答小程序配对码是否正确。 case "SendMatchCode": @@ -485,39 +476,34 @@ class IotCarePlan extends Component { // 附属设备状态主动上报,这种指令是主机主动上报某个附属设备断开或者连上了 case "BleStatusSync": + console.log("BleStatusSync", jsonStatus); switch (jsonStatus.connectMessage?.deviceName) { - case "WL200": - console.log( - "BleStatusSync 附属设备状态主动上报,这种指令是主机主动上报某个附属设备断开或者连上", - jsonStatus.connectMessage?.connectType == "CONNECTED" - ); - if (jsonStatus.connectMessage?.connectType == "CONNECTED") { - // 已连接WL200 - this.setState({ isConnectionBlutoot: true }); - - // 附属设备连接成功,如何区分是哪个设备? - this.setState({ - facialMaskConnectStatus: 1, // 面罩已连接 - }); - deviceToolKitInstance = deviceToolKitInstanceWL200; - console.log( - "检查版本isCheckedMaskVersion", - this.state.isCheckedMaskVersion - ); - if (!this.state.isCheckedMaskVersion) { - this.checkVersion(); - } - } else { - // WL200连接失败 - // deviceToolKitInstance = deviceToolKitInstanceWE100; - // // TODO 护理中(step==2)时, 如果断开, 可能需要暂停 - console.log("WL200连接失败或断开"); - this.setState({ - facialMaskConnectStatus: 0, - }); - } - break; - // 是否附属设备是否连接支架 + // 附属设备是否WL200 + // case "WL200": + // console.log( + // "BleStatusSync 附属设备状态主动上报,这种指令是主机主动上报某个附属设备断开或者连上", + // jsonStatus.connectMessage?.connectType == "CONNECTED" + // ); + // if (jsonStatus.connectMessage?.connectType == "CONNECTED") { + // // 已连接WL200 + // this.setState({ isConnectionBlutoot: true }); + + // // 附属设备连接成功,如何区分是哪个设备? + // this.setState({ + // facialMaskConnectStatus: 1, // 面罩已连接 + // }); + // deviceToolKitInstance = deviceToolKitInstanceWL200; + // } else { + // // WL200连接失败 + // // deviceToolKitInstance = deviceToolKitInstanceWE100; + // // // TODO 护理中(step==2)时, 如果断开, 可能需要暂停 + // console.log("WL200连接失败或断开"); + // this.setState({ + // facialMaskConnectStatus: 0, + // }); + // } + // break; + // 附属设备是否连接支架 case "Stand": if (jsonStatus.connectMessage?.connectType == "CONNECTED") { this.setState({ @@ -534,50 +520,28 @@ class IotCarePlan extends Component { case "QueryMatchStatus": const isStandDevice = jsonStatus?.subDeviceList?.includes("Stand") || false; - const isConnectedMask = - jsonStatus?.subDeviceList?.includes("WL200") || false; - deviceToolKitInstance = isConnectedMask - ? deviceToolKitInstanceWL200 - : deviceToolKitInstanceWE100; + deviceToolKitInstance = deviceToolKitInstanceWL200; - console.log("连接and更改成功 deviceToolKitInstance", isConnectedMask); - if (!this.state.isCheckedMaskVersion && isConnectedMask) { - this.checkVersion(); // 检查版本 - } console.log("支架是否链接", isStandDevice); - console.log("面罩是否链接", isConnectedMask); - if (isConnectedMask) { - this.setState({ - isConnectionBlutoot: true, - facialMaskConnectStatus: 1, + + this.setState({ + isStandStatus: isStandDevice, + }); + + // 连上面罩后, 获取仪器记录, 与缓存信息对比, + if (!this.hadGotInstrumentHistoryData) { + // 查询护理记录 + this.getInstrumentHistoryData(); + // 如果不延时, 无法获取到仪器状态 + const queryDeviceArrayBuffer = deviceToolKitInstance.toBleCommand( + bleCommandSamples.queryDeviceStatus as any + ); + console.log("发送查询设备指令 获取仪器状态"); + sendCommand({ + value: queryDeviceArrayBuffer, }); } - - // 连上面罩后, 获取仪器记录, 与缓存信息对比, - // if ( - // isConnectedMask && - // !this.state.hadGotInstrumentHistoryData - // ) { - // // 如果不延时, 无法获取到仪器状态 - // const queryDeviceArrayBuffer = - // deviceToolKitInstance.toBleCommand( - // bleCommandSamples.queryDeviceStatus as any - // ); - // console.log("发送查询设备指令"); - // sendCommand({ - // value: queryDeviceArrayBuffer, - // }); - // // 打开ota页面需要关闭 - // // that.data.getInstrumentHistoryDataTimer = setTimeout(() => { - // // that.getInstrumentHistoryData(); - // // }, 3000); - // } - // this.setData({ - // isStandStatus: isStandDevice, - // facialMaskConnectStatus: `${isConnectedMask ? 1 : 0}`, - // // currentTime: this.data.standInfo.currentTime - // }); } }; @@ -666,7 +630,7 @@ class IotCarePlan extends Component { switch (jsonStatus.infoQueryType) { // 自定义模式设置 case "customModeSet": - console.log(">>>>>>>>>>>>>>>自定义模式>>>>>>>>>>>>>>>"); + console.log(">>>>>>>>>>>>>>>设置自定义模式>>>>>>>>>>>>>>>"); console.log( "InfoQuery customModeSet responseStatus=====>", jsonStatus @@ -681,28 +645,25 @@ class IotCarePlan extends Component { break; // 自定义模式信息 case "customModeInfo": + console.log(">>>>>>>>>>>>>>>查询自定义模式信息>>>>>>>>>>>>>>>"); console.log( "InfoQuery customModeInfo responseStatus=====>", jsonStatus ); - break; case "versionInfo": - console.log( - "InfoQuery versionInfo responseStatus=====>", - jsonStatus - ); - if (jsonStatus.versionNo) { - // 清理计时器 - if (checkVersionTimeout) clearTimeout(checkVersionTimeout); - if (this.state.hasVersion) return; - this.setState({ - hasVersion: true, - }); - } break; // 当前报告 case "currentMaskReportInfo": + // 每次切换模式并开始运行后,生成一个新的自增ID + // commandType: "InfoQuery" + // createDate: "" + // gear: 0 + // id: 73 + // infoQueryType: "currentMaskReportInfo" + // neededTotalSeconds: 900 + // totalSeconds: 0 + // workMode: "BrightenStand" console.log("当前面罩报告 currentMaskReportInfo", jsonStatus); // if (!this.state.hadCheckReport) { // this.state.hadCheckReport = true; @@ -750,35 +711,6 @@ class IotCarePlan extends Component { }); }; - // 检查版本 - checkVersion = () => { - this.sendCheckVersion(); - this.setState({ - isCheckedMaskVersion: true, - }); - if (checkVersionTimeout) clearTimeout(checkVersionTimeout); - checkVersionTimeout = setTimeout(() => { - if (this.state.hasVersion) { - if (checkVersionTimeout) clearTimeout(checkVersionTimeout); - } else { - this.sendCheckVersion(); - } - }, 600); - }; - // 检查版本指令 - sendCheckVersion = () => { - deviceToolKitInstance.setDebug(true); - // 加定时器查询版本 - const queryVersion = deviceToolKitInstance.toBleCommand({ - commandType: "InfoQuery", - infoQueryType: "versionInfo", - otaDeviceType: "WL200", - }); - sendCommand({ - value: queryVersion, - }); - }; - //待完善,以后同步设备数据到小程序的事件,在这个事件里判断是否需要更新页面(是否需要触发setData) updateDeviceSyncData = (newData, jsonStatus) => { DeviceSyncData = { @@ -885,9 +817,9 @@ class IotCarePlan extends Component { this.setState({ isShowCountdown: false, }); - if (nowModeItem?.isStandMode && step == 2) { + if (nowModeItem?.isCabinMode && step == 2) { opts.currentTime = nowModeItem.modeTime; - } else if (!nowModeItem?.isStandMode && step == 2) { + } else if (!nowModeItem?.isCabinMode && step == 2) { // fix: 启动非支架模式倒计时时,连上支架,仪器的状态变为standby opts.step = 1; } @@ -956,7 +888,7 @@ class IotCarePlan extends Component { }, end: () => { // 仪器返回护理结束, 支架模式不需要了 - // if (modeItem.isStandMode) { + // if (modeItem.isCabinMode) { // this.onPauseTap(); // } // 已进入了报告阶段, 防止重复进入, 主要防止在手动点击结束护理接收到仪器消息 @@ -1128,9 +1060,9 @@ class IotCarePlan extends Component { const sendParams = { ...deviceCommandSamples.pause, workMode: ActiveModeItem.modeType, // 使用模式 - // workMode: "MaskCustom", workStatus: newWorkStatus, }; + console.log("准备发送自定义指令", ActiveModeItem, sendParams); const pauseArrayBuffer = deviceToolKitInstance.toBleCommand( sendParams as any ); @@ -1162,21 +1094,23 @@ class IotCarePlan extends Component { hadClickStart: false, }); }, 500); + const { ActiveModeItem, workStatus, isStandStatus, facialMaskConnectStatus, - customModeData, } = this.state; - const modelActiveItem = ActiveModeItem; - // log.info( - // commandMap.WL200Command, - // "点击开始护理按钮", - // `当前模式: ${modelActiveIndex}`, - // `当前面罩状态:${facialMaskConnectStatus}`, - // `当前仪器模式:${workStatus}` - // ); + + if (isStandStatus === 1 && ActiveModeItem.isCabinMode === 0) { + console.log("已连接舱体,只可选择舱体模式"); + return; + } + if (isStandStatus === 0 && ActiveModeItem.isCabinMode === 1) { + console.log("未连接舱体!"); + return; + } + console.info( commandMap.WL200Command, "点击开始护理按钮", @@ -1184,7 +1118,7 @@ class IotCarePlan extends Component { `当前面罩状态:${facialMaskConnectStatus}`, `当前仪器模式:${workStatus}` ); - console.log(modelActiveItem); + console.log(ActiveModeItem); console.log("isStandStatus:" + isStandStatus); console.log( workStatus !== MODE_WORKING_ENUM.WORKING && @@ -1198,12 +1132,12 @@ class IotCarePlan extends Component { return; } // 如果是强效舒缓,需要判断是否连接支架 - if (modelActiveItem.isStandMode && !isStandStatus) { + if (ActiveModeItem.isCabinMode && !isStandStatus) { this.showTips( `检测到舱体未连接成功,请确认面罩开机后与舱体连接,并接通舱体电源` ); return; - } else if (!modelActiveItem.isStandMode && isStandStatus) { + } else if (!ActiveModeItem.isCabinMode && isStandStatus) { this.showTips(`检测到面罩仍和舱体连接中,请分离后切换`); return; } @@ -1211,7 +1145,7 @@ class IotCarePlan extends Component { ActiveModeItem.modeType === "MaskCustom" && !this.state.isCombineSuccess ) { - this.showTips(`${modelActiveItem.modeName}模式设置失败,请联系小助手`); + this.showTips(`${ActiveModeItem.modeName}模式设置失败,请联系小助手`); return; } // 开始执行护理 @@ -1268,6 +1202,20 @@ class IotCarePlan extends Component { } } + getInstrumentHistoryData() { + this.hadGotInstrumentHistoryData = true; + console.log("发送获取currentMaskReportInfo指令"); + setTimeout(() => { + const queryCurrentMaskReportInfoBuffer = + deviceToolKitInstance.toBleCommand({ + ...(bleCommandSamples.queryCurrentMaskReportInfo as any), + }); + sendCommand({ + value: queryCurrentMaskReportInfoBuffer, + }); + }, 3000); + } + // 删除WL200护理历史 rmWL200NursingHistory(WL200NursingHistory, hard = false) {} @@ -1296,11 +1244,6 @@ class IotCarePlan extends Component { totalWorkingSeconds, }; }); - console.log( - "组合时间ServiceTimeData", - serviceData, - ActiveModeItem.serviceData - ); return serviceData; } // 设置护理时间组合 @@ -1319,14 +1262,12 @@ class IotCarePlan extends Component { let oldTime = old.totalWorkingMinutes * 60 + old.totalWorkingSeconds; let value = oldTime + curTime; - console.log("value", value); ModeStepTimeArray.push(value); return { totalWorkingMinutes: newTotalWorkingMinutes, totalWorkingSeconds: newTotalWorkingSeconds, }; } - console.log("curTime", curTime); ModeStepTimeArray.push(curTime); return { totalWorkingMinutes: newTotalWorkingMinutes, @@ -1460,7 +1401,7 @@ class IotCarePlan extends Component { isShowUpdateVersionTip, isShowVersionUpgrading, isShowStepTips, - isConnectionBlutoot, + isCanClick, isShowNurse, isStopNurse, ModeList, @@ -1487,6 +1428,7 @@ class IotCarePlan extends Component { + {