add:fr200蓝牙连接兼容;fix:绑定仪器时缓存数据key值修改

master
blak-kong 2 years ago
parent 8ebb6bb667
commit 43f8ed43ea

@ -0,0 +1,90 @@
/**蓝牙命令合集*/
export const fr200BleCommand = {
/**发送配对码*/
match: {
commandType: "BleMatch",
bleCommandType: "SendMatchCode",
},
InfoQuery: {
/**查询版本指令*/
versionInfo: {
commandType: "InfoQuery",
infoQueryType: "versionInfo",
otaDeviceType: "FR200",
},
/**时间同步*/
timeSync: {
commandType: "InfoQuery",
infoQueryType: "timeSync",
date: new Date(),
},
/**查询离线记录概要*/
clockSummary: {
commandType: "InfoQuery",
infoQueryType: "offlineClockInInfo",
dataType: "summary",
},
/**查询离线明细第一条*/
clockDetail: {
commandType: "InfoQuery",
infoQueryType: "offlineClockInInfo",
dataType: "detail",
dataIndex: 0,
},
},
};
/**控制设备命令合集*/
export const fr200DeviceControlCommand = {
/**查询设备状态指令*/
queryDeviceStatus: {
commandType: "DeviceStatusSync",
deviceSyncCommandType: "onlySyncStatusToDevice",
},
/**控制设备暂停 pause暂停 working启动 end关闭*/
pause: {
commandType: "DeviceControl",
workStatus: "pause",
},
standby: {
commandType: "DeviceControl",
workStatus: "standby",
},
end: {
commandType: "DeviceControl",
workStatus: "end",
},
/**
* '脸部' = 'workFace',
* '眼部' = 'workEye',
* '颈纹' = 'workNeck',
* '进入水分测试模式' = 'switchTestMode',
* '启动水分测试模式' = 'startTestMode',
* face
* eyes
* neck
* moistureTest
*/
// 普通工作模式
work: {
commandType: "DeviceControl",
workStatus: "working",
workMode: "face",
},
// 切换/进入水分测试
switchTestMode: {
commandType: "DeviceControl",
workStatus: "working",
workMode: "moistureTest",
testStatus: "standby",
},
// 启动水分测试
startTestMode: {
commandType: "DeviceControl",
workStatus: "working",
workMode: "moistureTest",
testStatus: "start",
},
};

@ -37,17 +37,19 @@ import {
// const log = require("@/utils/log");
import commandMap from "@/utils/commandMap";
import { bleCommandSamples } from "./wl200";
import { fr200BleCommand, fr200DeviceControlCommand } from "./fr200";
import { DeviceToolKit as DeviceToolKitWE100 } from "@flossom-npm/iot-translater-we100";
import { DeviceToolKit as DeviceToolKitFR200 } from "@flossom-npm/iot-translater";
const deviceToolKitInstanceWL200 = new DeviceToolKitWE100("WL200", "WL200");
deviceToolKitInstanceWL200.setDebug(true);
const deviceToolKitInstanceM01 = new DeviceToolKitWE100("WE100", "M01");
deviceToolKitInstanceM01.setDebug(true);
const deviceToolKitInstanceFR200 = new DeviceToolKitFR200("FR200");
deviceToolKitInstanceFR200.setDebug(true);
import { DeviceToolKit as DeviceToolKitFR200 } from "@flossom-npm/iot-translater";
import {
showModal,
msg,
@ -113,13 +115,13 @@ class ConnectionBluetoot extends Component<any, any> {
versionInfo: {}, //版本号
offlineDataList: [], //离线数据
prefix: "12CAA", // WL200蓝牙搜索前缀
// WL200匹配
tranType: [
"WE100", // 发箍
"WE200", // 发箍
"WL200", // 面罩
"12CAA", // 面罩前缀名
"FR200", // FR200
],
currentDeviceType: "", // 现在的设备类型: WE200 WL200
@ -422,6 +424,40 @@ class ConnectionBluetoot extends Component<any, any> {
});
}
/**获取附属设备信息与设置当前设备名字*/
getQueryMatchStatusAndSetName(value) {
const { deviceInfo } = this.props;
let querySubDeviceArrayBuffer: any = null;
let jsonStatus: any = null;
if (deviceInfo.model == "WL200") {
if (this.isWL200()) {
this.setState({ currentDeviceType: "WL200" });
jsonStatus = deviceToolKitInstanceWL200.toJsonStatus(value);
querySubDeviceArrayBuffer = deviceToolKitInstanceWL200.toBleCommand(
bleCommandSamples.querySubDevice as any
);
} else {
this.setState({ currentDeviceType: "WE200" });
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value);
querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand(
bleCommandSamples.querySubDevice as any
);
}
} else if (deviceInfo.model == "M01") {
this.setState({ currentDeviceType: "M01" });
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value);
querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand(
bleCommandSamples.querySubDevice as any
);
} else if (deviceInfo.model === "FR200") {
// FR200 不需要查询子设备
jsonStatus = deviceToolKitInstanceFR200.toJsonStatus(value.value);
this.setState({ currentDeviceType: "FR200" });
}
// if (querySubDeviceArrayBuffer) this.sendQuerySubDevice(querySubDeviceArrayBuffer)
return jsonStatus;
}
/** 7.通知BLE特征值更改 */
notifyBLECharacteristicValueChange() {
console.log("7.通知BLE特征值更改");
@ -443,39 +479,13 @@ class ConnectionBluetoot extends Component<any, any> {
let str = ab2hex(value.value); //转为16进制字符串
console.log("转为16进制字符串 str", str);
let jsonStatus: any = null;
let querySubDeviceArrayBuffer;
if (deviceInfo.model == "WL200") {
if (this.isWL200()) {
this.setState({ currentDeviceType: "WL200" });
jsonStatus = deviceToolKitInstanceWL200.toJsonStatus(
value.value
);
querySubDeviceArrayBuffer =
deviceToolKitInstanceWL200.toBleCommand(
bleCommandSamples.querySubDevice as any
);
} else {
this.setState({ currentDeviceType: "WE200" });
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value);
querySubDeviceArrayBuffer =
deviceToolKitInstanceM01.toBleCommand(
bleCommandSamples.querySubDevice as any
);
}
} else if (deviceInfo.model == "M01") {
this.setState({ currentDeviceType: "M01" });
jsonStatus = deviceToolKitInstanceM01.toJsonStatus(value.value);
querySubDeviceArrayBuffer = deviceToolKitInstanceM01.toBleCommand(
bleCommandSamples.querySubDevice as any
);
}
let jsonStatus = this.getQueryMatchStatusAndSetName(value.value);
console.log(
commandMap.reciviedBLECommand,
`仪器模式: ${deviceInfo.model}`,
jsonStatus
);
console.log("jsonStatus", jsonStatus);
if (jsonStatus?.commandType === "BleMatch") {
switch (jsonStatus?.bleCommandType) {
@ -489,17 +499,9 @@ class ConnectionBluetoot extends Component<any, any> {
islian: true, // 不需要离线记录但暂未完全删除这部分逻辑所以直接设为true
});
// this.pairingChange(this.state); // 临时添加,用于跳转
this.detectVersionUpdate(); // 获取升级信息
// todo 连接成功需删除离线记录,暂时未缓存离线记录
if (this.state.connectionSuccess) return;
// 暂时不需要查询是否连接子设备, 直接进入查询版本信息
// this.detectVersionUpdate();
/*if(deviceInfo.type == instrumentTypeEnum.M01) {
this.detectVersionUpdate()
} else {
this.sendQuerySubDevice(querySubDeviceArrayBuffer)
}*/
}
break;
case "BleStatusSync": // 设备连接状态
@ -519,6 +521,10 @@ class ConnectionBluetoot extends Component<any, any> {
console.log("面罩连上了 value => ", jsonStatus);
this.detectVersionUpdate();
break;
case "FR200":
console.log("FR200连上了 value => ", jsonStatus);
this.detectVersionUpdate();
break;
default:
break;
}
@ -526,7 +532,10 @@ class ConnectionBluetoot extends Component<any, any> {
console.log("BleStatusSync value => ", jsonStatus);
break;
case "QueryMatchStatus":
console.log("QueryMatchStatus value => ", jsonStatus);
console.log(
"查询附属设备QueryMatchStatus value => ",
jsonStatus
);
break;
default:
break;
@ -536,16 +545,6 @@ class ConnectionBluetoot extends Component<any, any> {
console.log("当前设备:", jsonStatus.otaDeviceType);
console.log("当前设备版本号:", jsonStatus.versionNo);
if (
jsonStatus.otaDeviceType === "WE100" ||
jsonStatus.otaDeviceType === "WE200"
) {
console.log("closeBLEConnection");
setTimeout(() => {
this.againConnection();
}, 1000);
}
switch (jsonStatus.infoQueryType) {
case "versionInfo":
if (this.state.hasVersionInfo) return;
@ -560,7 +559,7 @@ class ConnectionBluetoot extends Component<any, any> {
let currentDevicesName = getStorageSync("currentDevicesName");
let deviceVersionNo = jsonStatus.versionNo;
let latestVersionNo = deviceInfo.iotVersion;
if (currentDevicesName.indexOf("12CAA") === -1) {
if (currentDevicesName.indexOf("WE") > -1) {
latestVersionNo = deviceInfo.we200IotVersion;
}
// 判断版本号是否需要升级
@ -573,6 +572,16 @@ class ConnectionBluetoot extends Component<any, any> {
// 版本号需要更新: 告诉父级页面,关闭连接弹窗,显示更新弹窗
this.props.upgradeFun();
} else {
if (
currentDevicesName === "WE100" ||
currentDevicesName === "WE200"
) {
console.log("closeBLEConnection");
setTimeout(() => {
this.againConnection();
}, 1000);
return;
}
console.log("不需要升级,跳转进入仪器详情页");
// 不需要升级,跳转进入仪器详情页
if (isGetVersionTimer) clearTimeout(isGetVersionTimer);
@ -615,7 +624,6 @@ class ConnectionBluetoot extends Component<any, any> {
} else if (deviceInfo.model == "WL200" || deviceInfo.model == "M01") {
if (sendPairingTimer) clearInterval(sendPairingTimer);
sendPairingTimer = setInterval(() => {
console.log("test WL200");
this.sendPairingSignal();
}, 1000);
} else if (
@ -661,44 +669,54 @@ class ConnectionBluetoot extends Component<any, any> {
}
}
const isWEorWL = ["WL200", "WE200", "WE100"].includes(model);
const isFRDevice = ["FR200", "FR380", "FR390"].includes(model);
console.log(commandMap.sendVersionCommand, `仪器:${model}`);
if (isFRDevice) {
writeBLECharacteristicValue({
//发送获取仪器版本号
deviceId: this.props.bluetoothInfo.deviceId,
servicesuuid: this.props.bluetoothInfo.servicesuuid,
characteristicsuuid1: this.props.bluetoothInfo.characteristicsuuid1,
characteristicsuuid0: this.props.bluetoothInfo.characteristicsuuid0,
value: `dbf0a00300${ccrc8("dbf0a00300")}de`,
});
} else {
const otaDeviceType = this.isWL200()
? OtaDeviceTypeEnum.WL200
: OtaDeviceTypeEnum.WE100;
if (model === "FR200") {
const value = deviceToolKitInstanceFR200.toBleCommand(
fr200BleCommand.InfoQuery.versionInfo as any
);
sendCommand({ value });
} else {
writeBLECharacteristicValue({
//发送获取仪器版本号
deviceId: this.props.bluetoothInfo.deviceId,
servicesuuid: this.props.bluetoothInfo.servicesuuid,
characteristicsuuid1: this.props.bluetoothInfo.characteristicsuuid1,
characteristicsuuid0: this.props.bluetoothInfo.characteristicsuuid0,
value: `dbf0a00300${ccrc8("dbf0a00300")}de`,
});
}
} else if (isWEorWL) {
const versionCommand = {
commandType: "InfoQuery",
infoQueryType: "versionInfo",
otaDeviceType,
otaDeviceType: "",
};
console.log("versionCommand", versionCommand);
// 区分WL200 和 发箍
const value = this.isWL200()
? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any)
: deviceToolKitInstanceM01.toBleCommand(versionCommand as any);
console.log(otaDeviceType, " value", value);
sendCommand({ value });
if (this.isWL200()) {
// WL200
const otaDeviceType = OtaDeviceTypeEnum.WL200;
versionCommand.otaDeviceType = otaDeviceType;
const value = deviceToolKitInstanceWL200.toBleCommand(
versionCommand as any
);
sendCommand({ value });
} else {
// WE200 WE100
const otaDeviceType = OtaDeviceTypeEnum.WE100;
versionCommand.otaDeviceType = otaDeviceType;
const value = deviceToolKitInstanceM01.toBleCommand(
versionCommand as any
);
sendCommand({ value });
}
}
}
/** 获取离线记录 */
sendofflist() {
// log.info()
if (this.state.offlineDataindex == this.state.offlineDataList.length) {
console.log("离线记录获取完成", this.state);
// log.info(commandMap.finishOfflineData, this.state.offlineDataList);
/****
*
* ****/
@ -711,51 +729,65 @@ class ConnectionBluetoot extends Component<any, any> {
return false;
}
console.log("发送获取离线记录(细)指令");
// log.info(commandMap.finishOfflineData, "发送获取离线记录(细)指令");
writeBLECharacteristicValue({
//发送获取离线记录
deviceId: this.props.bluetoothInfo.deviceId,
servicesuuid: this.props.bluetoothInfo.servicesuuid,
characteristicsuuid1: this.props.bluetoothInfo.characteristicsuuid1,
characteristicsuuid0: this.props.bluetoothInfo.characteristicsuuid0,
value: this.state.offlineData[this.state.offlineDataList.length],
});
const { deviceInfo } = this.props;
let model = deviceInfo.model;
if (model === "FR200") {
let matchArrayBuffer = deviceToolKitInstanceFR200.toBleCommand(
fr200BleCommand.InfoQuery.clockDetail as any
);
sendCommand({ value: matchArrayBuffer });
} else {
writeBLECharacteristicValue({
//发送获取离线记录
deviceId: this.props.bluetoothInfo.deviceId,
servicesuuid: this.props.bluetoothInfo.servicesuuid,
characteristicsuuid1: this.props.bluetoothInfo.characteristicsuuid1,
characteristicsuuid0: this.props.bluetoothInfo.characteristicsuuid0,
value: this.state.offlineData[this.state.offlineDataList.length],
});
}
}
/** 获取离线记录(汇总) */
sendofflistSummary() {
let str = "DBF0A00200";
console.log("发送离线记录汇总指令 ==》", str);
this.setState({ offlineDataList: [] }); // 置空重查离线记录
// log.info(commandMap.finishOfflineData, `发送获取离线记录(总)指令`);
writeBLECharacteristicValue({
//发送获取离线记录
deviceId: this.props.bluetoothInfo.deviceId,
servicesuuid: this.props.bluetoothInfo.servicesuuid,
characteristicsuuid1: this.props.bluetoothInfo.characteristicsuuid1,
characteristicsuuid0: this.props.bluetoothInfo.characteristicsuuid0,
value: `${str}${ccrc8(str)}DE`,
});
const { deviceInfo } = this.props;
let model = deviceInfo.model;
if (model === "FR200") {
let matchArrayBuffer = deviceToolKitInstanceFR200.toBleCommand(
fr200BleCommand.InfoQuery.clockSummary as any
);
sendCommand({ value: matchArrayBuffer });
} else {
writeBLECharacteristicValue({
//发送获取离线记录
deviceId: this.props.bluetoothInfo.deviceId,
servicesuuid: this.props.bluetoothInfo.servicesuuid,
characteristicsuuid1: this.props.bluetoothInfo.characteristicsuuid1,
characteristicsuuid0: this.props.bluetoothInfo.characteristicsuuid0,
value: `${str}${ccrc8(str)}DE`,
});
}
}
/** 9.发送配对码 */
sendPairingSignal() {
console.log("9.发送配对码 sendPairingSignal");
const { deviceInfo } = this.props;
// log.info(commandMap.sendMatchCode, `仪器:${deviceInfo.model}发送匹配码`);
console.log(commandMap.sendMatchCode, `仪器:${deviceInfo.model}发送匹配码`);
let matchArrayBuffer: any = null;
switch (deviceInfo.model) {
case InstrumentTypeEnum.FR200:
matchArrayBuffer = deviceToolKitInstanceFR200.toBleCommand(
bleCommandSamples.match as any
fr200BleCommand.match as any
);
break;
case InstrumentTypeEnum.WL200:
console.log("正在发送WL200", bleCommandSamples.match);
let currentDevicesName = getStorageSync("currentDevicesName");
// 区分面罩和发箍
if (currentDevicesName.indexOf("12CAA") > -1) {
console.log("12CAA");
matchArrayBuffer = deviceToolKitInstanceWL200.toBleCommand(
bleCommandSamples.match as any
);
@ -945,6 +977,8 @@ class ConnectionBluetoot extends Component<any, any> {
errorText,
});
}
/**发送消息获取子设备*/
sendQuerySubDevice(value) {
isGetSubDeviceTimer = setInterval(() => {
sendCommand({ value });
@ -995,14 +1029,35 @@ class ConnectionBluetoot extends Component<any, any> {
/** 发送同步记录 */
sendSyncRecording() {
const versionCommand = {
const clockSummaryCommand = {
commandType: "InfoQuery",
infoQueryType: "offlineClockSummary",
};
const value = this.isWL200()
? deviceToolKitInstanceWL200.toBleCommand(versionCommand as any)
: deviceToolKitInstanceM01.toBleCommand(versionCommand as any);
sendCommand({ value }).then();
const { deviceInfo } = this.props;
let model = deviceInfo.model;
if (model === "WL200") {
if (!this.isWL200()) {
model = "WE200";
}
}
const isWEorWL = ["WL200", "WE200", "WE100"].includes(model);
const isFRDevice = ["FR200", "FR380", "FR390"].includes(model);
if (isFRDevice) {
if (model === "FR200") {
let value = deviceToolKitInstanceFR200.toBleCommand(
fr200BleCommand.InfoQuery.clockSummary as any
);
sendCommand({ value }).then();
}
} else if (isWEorWL) {
const value = this.isWL200()
? deviceToolKitInstanceWL200.toBleCommand(clockSummaryCommand as any)
: deviceToolKitInstanceM01.toBleCommand(clockSummaryCommand as any);
sendCommand({ value }).then();
}
if (isGetSyncRecordingTimer) clearTimeout(isGetSyncRecordingTimer);
isGetSyncRecordingTimer = setTimeout(() => {
if (this.state.hasSyncRecord) {

File diff suppressed because it is too large Load Diff

@ -334,11 +334,6 @@ export default class Instrument extends Component<any, any> {
let code = Number(res.code); // 强制类型转换
setTimeout(() => {
if (code === 200) {
// msg("绑定成功");
// setTimeout(() => {
// setStorageSync("instrument_item", JSON.stringify(channelInfo));
// go("/pages/instrument/intro?id=" + channelInfo.id);
// }, 1000);
this.openBindingVisible();
} else if (code === 202) {
this.changeBindBox();
@ -375,7 +370,7 @@ export default class Instrument extends Component<any, any> {
if (code === 200) {
msg("绑定成功");
setTimeout(() => {
setStorageSync("instrument_item", JSON.stringify(channelInfo));
setStorageSync("instrument_detail", JSON.stringify(channelInfo));
go("/pages/instrument/intro?id=" + channelInfo.id);
}, 1000);
} else if (res.data.code === 202) {
@ -406,7 +401,7 @@ export default class Instrument extends Component<any, any> {
if (res.data.code === 200) {
this.setState({ isVisibleBinding: false });
msg("绑定成功");
setStorageSync("instrument_item", JSON.stringify(channelInfo));
setStorageSync("instrument_detail", JSON.stringify(channelInfo));
setTimeout(() => {
go("/pages/instrument/intro?id=" + channelInfo.id);
}, 1000);

Loading…
Cancel
Save