From e52c925ef6aeea91ea4fb761d631e16738d5d90d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=95=AC=E6=82=A6?= Date: Wed, 13 Dec 2023 15:32:37 +0800 Subject: [PATCH] fix: is id not name --- src/hooks/senseCraftAIComesToFlash.ts | 3 +-- src/locale/en-US/process.ts | 1 + src/locale/zh-CN/process.ts | 3 +++ src/pages/components/Navbar.vue | 3 ++- src/pages/setup/process/components/Device.vue | 20 ++++++++++++------- src/store/modules/device/index.ts | 13 ++++++------ src/utils/flash.ts | 17 ++++++++++++++++ 7 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 src/utils/flash.ts diff --git a/src/hooks/senseCraftAIComesToFlash.ts b/src/hooks/senseCraftAIComesToFlash.ts index 36111f0..b5bfe5b 100644 --- a/src/hooks/senseCraftAIComesToFlash.ts +++ b/src/hooks/senseCraftAIComesToFlash.ts @@ -76,7 +76,7 @@ const useSenseCraftAIComesToFlash = () => { '32': DeviceType.XiaoEsp32s3, }; if (typeof deviceKeyToId[deviceType] === 'string') { - deviceStore.setDeviceType(deviceKeyToId[deviceType]); + deviceStore.setDeviceTypeById(deviceKeyToId[deviceType]); } deviceStore.setComeToSenseCraftAI({ model: { @@ -102,7 +102,6 @@ const useSenseCraftAIComesToFlash = () => { isCustom: true, }, modelUrl: modelFile.arguments.url, - isFlashed: false, }); deviceStore.setFlashWay(FlashWayType.ComeToSenseCraftAI); } diff --git a/src/locale/en-US/process.ts b/src/locale/en-US/process.ts index 17f6723..01da3f9 100644 --- a/src/locale/en-US/process.ts +++ b/src/locale/en-US/process.ts @@ -126,4 +126,5 @@ export default { 'There may be a problem with the firmware, please re-burn it.', 'workplace.serial.device.flash.confirm': 'Clicking confirm will deploy the model to the device', + 'workplace.serial.device.port.occupied': 'Device is occupied', }; diff --git a/src/locale/zh-CN/process.ts b/src/locale/zh-CN/process.ts index 425ca44..fd311bd 100644 --- a/src/locale/zh-CN/process.ts +++ b/src/locale/zh-CN/process.ts @@ -55,6 +55,8 @@ export default { 'workplace.device.use.aimodel': '可用的AI模型', 'workplace.device.upload.aimodel': '上传自定义AI模型', 'workplace.device.select.aimodel': '请选择预设AI模型或上传自定义AI模型', + 'workplace.device.select.comeToSenseCraft': + '将Al模型发送到设备并预览推理结果', 'workplace.device.send': '发送', 'workplace.device.model.aimodel': '自定义AI模型', 'workplace.device.model.sendmodel': '发送模型', @@ -111,4 +113,5 @@ export default { 'workplace.serial.no.port': '用户未选择端口', 'workplace.serial.command.timeout': '固件可能存在问题,请重新烧录', 'workplace.serial.device.flash.confirm': '点击确定将部署模型到设备', + 'workplace.serial.device.port.occupied': '设备已被占用', }; diff --git a/src/pages/components/Navbar.vue b/src/pages/components/Navbar.vue index ca11bb1..10fbaac 100644 --- a/src/pages/components/Navbar.vue +++ b/src/pages/components/Navbar.vue @@ -176,6 +176,7 @@ import useDeviceManager from '@/hooks/deviceManager'; import { DEVICE_LIST } from '@/sscma/constants'; import { FlashWayType } from '@/store/modules/device'; + import { flashErrorHandle } from '@/utils/flash'; import Menu from './Menu.vue'; const appStore = useAppStore(); @@ -241,7 +242,7 @@ } } catch (error: any) { console.error('Device connection failed: ', error); - Message.error(t('workplace.serial.connected.failed')); + flashErrorHandle(error, t('workplace.serial.connected.failed')); term.writeln(`Error: ${error?.message}`); } finally { loading.value = false; diff --git a/src/pages/setup/process/components/Device.vue b/src/pages/setup/process/components/Device.vue index 5072c13..b709df4 100644 --- a/src/pages/setup/process/components/Device.vue +++ b/src/pages/setup/process/components/Device.vue @@ -262,6 +262,7 @@ import FlasherInterface from '@/sscma/FlasherInterface'; import useDeviceManager from '@/hooks/deviceManager'; import { FlashWayType } from '@/store/modules/device'; + import { flashErrorHandle } from '@/utils/flash'; export type FileType = { data: T; @@ -421,10 +422,15 @@ }; const comeToSenseCraftAIFlash = async () => { - await flashFirmware().finally(() => { - deviceStore.setComeToSenseCraftAIIsFlashed(true); - }); - isComeToFlashFinished.value = true; + try { + await flashFirmware(); + isComeToFlashFinished.value = true; + } catch (error: any) { + flashErrorHandle(error); + } finally { + loadingTip.value = ''; + loading.value = false; + } }; const handleUpload = async () => { @@ -456,7 +462,7 @@ await flashFirmware(); } catch (error: any) { console.error(error); - Message.error(error?.message ?? ''); + flashErrorHandle(error); term.writeln(`Error: ${error?.message}`); } finally { loadingTip.value = ''; @@ -526,7 +532,7 @@ return true; } catch (error: any) { console.error(error); - Message.error(error?.message); + flashErrorHandle(error); } finally { loadingTip.value = ''; loading.value = false; @@ -562,7 +568,7 @@ async () => { if ( deviceStore.flashWay === FlashWayType.ComeToSenseCraftAI && - !deviceStore.comeToSenseCraftAI.isFlashed + !isComeToFlashFinished.value ) { visible.value = true; } diff --git a/src/store/modules/device/index.ts b/src/store/modules/device/index.ts index bf302a9..1b188f6 100644 --- a/src/store/modules/device/index.ts +++ b/src/store/modules/device/index.ts @@ -22,9 +22,7 @@ export type ComeToSenseCraftAIType = { isCustom: boolean; }; modelUrl: string; - isFlashed: boolean; }; - const useDeviceStore = defineStore('device', { state: () => ({ deviceStatus: DeviceStatus.UnConnected, @@ -85,6 +83,12 @@ const useDeviceStore = defineStore('device', { this.deviceType = { ...DEVICE_LIST[index] }; } }, + setDeviceTypeById(id: string) { + const index = DEVICE_LIST.findIndex((e) => e.id === id); + if (index !== -1) { + this.deviceType = { ...DEVICE_LIST[index] }; + } + }, setDeviceName(name: string) { this.deviceName = name; }, @@ -97,11 +101,6 @@ const useDeviceStore = defineStore('device', { setComeToSenseCraftAI(data: ComeToSenseCraftAIType) { this.comeToSenseCraftAI = data; }, - setComeToSenseCraftAIIsFlashed(isFlashed: boolean) { - if (typeof this.comeToSenseCraftAI === 'object') { - this.comeToSenseCraftAI.isFlashed = isFlashed; - } - }, setFlashWay(flashWay: number) { this.flashWay = flashWay; }, diff --git a/src/utils/flash.ts b/src/utils/flash.ts new file mode 100644 index 0000000..1ced32b --- /dev/null +++ b/src/utils/flash.ts @@ -0,0 +1,17 @@ +import { Message } from '@arco-design/web-vue'; +import i18n from '@/locale'; + +export function flashErrorHandle(error?: Error, defaultMsg?: string) { + if ( + [ + `Failed to execute 'open' on 'SerialPort': Failed to open serial port.`, + `Failed to execute 'close' on 'SerialPort': The port is already closed.`, + ].includes(error?.message ?? '') + ) { + Message.error(i18n.global.t('workplace.serial.device.port.occupied')); + } else { + Message.error(defaultMsg ?? error?.message ?? ''); + } +} + +export default null;