Skip to content

Commit

Permalink
Fix/test question (#12)
Browse files Browse the repository at this point in the history
* feat: add global loading

* fix: unconnected burn-in model always upgrades

* fix: file name too long, UI error

* feat: configurable client ID

* feat: internationalization

* fix: timeout undefined error

* feat: concurrent data processing

* fix: user prompted without selecting serial port

* feat: xiao Single-step execution

* feat: disconnect first before switching

* feat: add come to v2 support

* feat: come to update uniform_type

* fix: burned but not deduced
  • Loading branch information
wutiange authored Jan 12, 2024
1 parent 562a8ba commit 6d9ad7e
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 149 deletions.
89 changes: 40 additions & 49 deletions src/hooks/senseCraftAIComesToFlash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ export async function fetchConstant() {
.then((res) => res.data);
}

export async function fetchModelDetail(modelId: string, needParams?: string[]) {
export async function fetchModelDetail(
modelId: string,
token: string,
needParams?: string[]
) {
const response: Record<string, any> = await fetch(
`https://sensecraft.seeed.cc/aiserverapi/model/view_model?model_id=${modelId}`
`https://sensecraft.seeed.cc/aiserverapi/model/view_model?model_id=${modelId}`,
{ headers: { Authorization: token } }
).then((res) => res.json());
if (response?.code !== '0') {
throw new Error(response.msg);
Expand All @@ -39,28 +44,18 @@ export async function fetchModelFileUrl(modelId: string, token: string) {
const useSenseCraftAIComesToFlash = () => {
const route = useRoute();
const deviceStore = useDeviceStore();
const { id: modelId, token } = route.query ?? {};
const { id: modelId, token, uniform_type: uniformType } = route.query ?? {};
const handleSenseCraftAI = async () => {
if (!(modelId && token && route.name === 'process')) {
return {};
}
const [
[
modelImg,
deviceTypes,
labels,
description,
size,
name,
aiFramework,
modelFormat,
],
[modelImg, labels, description, size, name, aiFramework, modelFormat],
modelFile,
constant,
] = await Promise.all<any>([
fetchModelDetail(modelId as string, [
fetchModelDetail(modelId as string, token as string, [
'pic_url',
'uniform_types',
'labels',
'description',
'model_size',
Expand All @@ -71,41 +66,37 @@ const useSenseCraftAIComesToFlash = () => {
fetchModelFileUrl(modelId as string, token as string),
fetchConstant(),
]);
if (deviceTypes.length > 0) {
const deviceType: string = deviceTypes[0];
const deviceKeyToId: Record<string, string> = {
'32': DeviceType.XiaoEsp32s3,
};
if (typeof deviceKeyToId[deviceType] === 'string') {
deviceStore.setDeviceTypeById(deviceKeyToId[deviceType]);
}
deviceStore.setComeToSenseCraftAI({
model: {
description,
classes:
labels?.reduce(
(
arr: string[],
e: { object_id: string; object_name: string }
) => {
arr[Number(e.object_id)] = e.object_name;
return arr;
},
[]
) ?? [],
algorithm: constant.ai_framework_array[aiFramework as string],
name,
version: modelFile.version ?? '1.0.0',
category: modelFile.algorithm[0].algorithm_name ?? 'Object Detection',
model_type: constant.model_format_array[modelFormat],
size,
modelImg,
isCustom: true,
},
modelUrl: modelFile.arguments.url,
});
deviceStore.setFlashWay(FlashWayType.ComeToSenseCraftAI);
const deviceType: string = uniformType as string;
const deviceKeyToId: Record<string, string> = {
'32': DeviceType.XiaoEsp32s3,
'36': DeviceType.GroveAIWE2,
};
if (typeof deviceKeyToId[deviceType] === 'string') {
deviceStore.setDeviceTypeById(deviceKeyToId[deviceType]);
}
deviceStore.setComeToSenseCraftAI({
model: {
description,
classes:
labels?.reduce(
(arr: string[], e: { object_id: string; object_name: string }) => {
arr[Number(e.object_id)] = e.object_name;
return arr;
},
[]
) ?? [],
algorithm: constant.ai_framework_array[aiFramework as string],
name,
version: modelFile.version ?? '1.0.0',
category: modelFile.algorithm[0].algorithm_name ?? 'Object Detection',
model_type: constant.model_format_array[modelFormat],
size,
modelImg,
isCustom: true,
},
modelUrl: modelFile.arguments.url,
});
deviceStore.setFlashWay(FlashWayType.ComeToSenseCraftAI);
return null;
};
onMounted(async () => {
Expand Down
3 changes: 3 additions & 0 deletions src/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default {
'menu.faq': 'FAQ',
'navbar.docs': 'Docs',
'navbar.action.locale': 'Switch to English',
'navbar.swap.confirm.text':
'Switching while connected will cause the current connection to be disconnected. Are you sure you want to switch?',
'navbar.switch': 'Switch',
'confirm': 'Confirm',
'cancel': 'Cancel',
'config.save.success': 'Save Success',
Expand Down
2 changes: 2 additions & 0 deletions src/locale/en-US/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export default {
'workplace.config.mqtt': 'MQTT',
'workplace.config.mqtt.host': 'Host',
'workplace.config.mqtt.port': 'Port',
'workplace.config.mqtt.clientId': 'clientId',
'workplace.config.mqtt.username': 'Username',
'workplace.config.mqtt.password': 'Password',
'workplace.config.mqtt.ssl': 'SSL',
'workplace.config.mqtt.message.host': 'Please enter host',
'workplace.config.mqtt.message.port': 'Please enter port',
'workplace.config.mqtt.message.clientId': 'Please enter clientId',
'workplace.config.mqtt.message.username': 'Please enter username',
'workplace.config.mqtt.message.password': 'Please enter password',
'workplace.output.title': 'Output',
Expand Down
3 changes: 3 additions & 0 deletions src/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default {
'menu.faq': '常见问题',
'navbar.docs': '文档中心',
'navbar.action.locale': '切换为中文',
'navbar.swap.confirm.text':
'当处于连接状态下切换会导致当前连接断开,确定切换嘛?',
'navbar.switch': '切换',
'confirm': '确定',
'cancel': '取消',
'config.save.success': '保存成功',
Expand Down
2 changes: 2 additions & 0 deletions src/locale/zh-CN/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export default {
'workplace.config.mqtt': 'MQTT配置',
'workplace.config.mqtt.host': '主机',
'workplace.config.mqtt.port': '端口',
'workplace.config.mqtt.clientId': '客户端ID',
'workplace.config.mqtt.username': '用户名',
'workplace.config.mqtt.password': '密码',
'workplace.config.mqtt.ssl': 'SSL',
'workplace.config.mqtt.message.host': '请输入主机',
'workplace.config.mqtt.message.port': '请输入端口',
'workplace.config.mqtt.message.clientId': '请输入客户端ID',
'workplace.config.mqtt.message.username': '请输入用户名',
'workplace.config.mqtt.message.password': '请输入密码',
'workplace.output.title': '输出',
Expand Down
47 changes: 37 additions & 10 deletions src/pages/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<a-select
:model-value="deviceStore.deviceType.name"
:style="{}"
@update:model-value="deviceStore.setDeviceType"
@update:model-value="onSwapDeviceType"
>
<a-option v-for="deviceType in DEVICE_LIST" :key="deviceType.id">{{
deviceType.name
Expand Down Expand Up @@ -161,11 +161,20 @@
>
</li>
</ul>
<a-modal
v-model:visible="visible"
:hide-title="true"
:ok-text="$t('navbar.switch')"
@ok="onConfirmSwitch"
@cancel="onCancel"
>
<span>{{ $t('navbar.swap.confirm.text') }}</span>
</a-modal>
</div>
</template>

<script lang="ts" setup>
import { computed, ref, inject, watch } from 'vue';
import { computed, ref, inject } from 'vue';
import { useDark, useToggle, useFullscreen } from '@vueuse/core';
import { useI18n } from 'vue-i18n';
import { Message } from '@arco-design/web-vue';
Expand All @@ -183,11 +192,12 @@
const deviceStore = useDeviceStore();
const { t } = useI18n();
const { device, term } = useDeviceManager();
const visible = ref(false);
const { changeLocale, currentLocale } = useLocale();
const { isFullscreen, toggle: toggleFullScreen } = useFullscreen();
const locales = [...LOCALE_OPTIONS];
const loading = ref(false);
let tempDeviceType = deviceStore.deviceType.name;
const theme = computed(() => {
return appStore.theme;
Expand Down Expand Up @@ -222,6 +232,21 @@
const triggerBtn = ref();
const onSwapDeviceType = (
value:
| string
| number
| Record<string, any>
| (string | number | Record<string, any>)[]
) => {
if (deviceStore.deviceStatus === DeviceStatus.SerialConnected) {
visible.value = true;
tempDeviceType = value as string;
} else {
deviceStore.setDeviceType(value as string);
}
};
const setDropDownVisible = () => {
const event = new MouseEvent('click', {
view: window,
Expand Down Expand Up @@ -259,13 +284,15 @@
}
}
// Clear the logs when switching
watch(
() => deviceStore.deviceType,
() => {
device.value.cleanLogger();
}
);
const onCancel = () => {
visible.value = false;
};
const onConfirmSwitch = async () => {
await disconnect();
deviceStore.setDeviceType(tempDeviceType);
onCancel();
};
</script>

<style scoped lang="less">
Expand Down
45 changes: 32 additions & 13 deletions src/pages/setup/config/components/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@
allow-clear
/>
</a-form-item>
<a-form-item
field="mqtt.clientId"
:label="$t('workplace.config.mqtt.clientId')"
>
<a-input
v-model="config.mqtt.clientId"
:placeholder="$t('workplace.config.mqtt.message.clientId')"
size="large"
allow-clear
/>
</a-form-item>
<a-form-item
v-if="!config.mqtt.ssl"
field="mqtt.username"
Expand Down Expand Up @@ -134,6 +145,7 @@
encryption: '0',
},
mqtt: {
clientId: '',
enabled: false,
host: '',
port: 1883,
Expand Down Expand Up @@ -180,9 +192,10 @@
}
if (!config.mqtt.enabled) {
ret = await device.value?.setMqttServer('', 0, '', '', 0);
ret = await device.value?.setMqttServer('', '', 0, '', '', 0);
} else {
ret = await device.value?.setMqttServer(
config.mqtt.clientId,
config.mqtt.host,
config.mqtt.port,
config.mqtt.username,
Expand All @@ -206,20 +219,26 @@
retry(() => device.value?.getWifi(), 5, 500, null),
retry(() => device.value?.getMqttServer(), 5, 500, null),
]);
if (config?.wifi) {
config.wifi.password = wifi.config.password;
config.wifi.ssid = wifi.config.name;
config.wifi.encryption = wifi.config.security.toString();
}
config.wifi.password = wifi.config.password;
config.wifi.ssid = wifi.config.name;
config.wifi.encryption = wifi.config.security.toString();
if (mqtt.config.address !== '') {
config.mqtt.enabled = true;
config.mqtt.host = mqtt.config.address;
config.mqtt.port = mqtt.config.port;
config.mqtt.username = mqtt.config.username;
config.mqtt.password = mqtt.config.password;
config.mqtt.ssl = mqtt.config.use_ssl;
} else {
config.mqtt.enabled = false;
if (mqtt?.config) {
if (mqtt.config.address !== '') {
config.mqtt.enabled = true;
config.mqtt.clientId = mqtt.config.client_id;
config.mqtt.host = mqtt.config.address;
config.mqtt.port = mqtt.config.port;
config.mqtt.username = mqtt.config.username;
config.mqtt.password = mqtt.config.password;
config.mqtt.ssl = mqtt.config.use_ssl;
} else {
config.mqtt.enabled = false;
}
}
oldConfig = JSON.parse(JSON.stringify(config));
loaded.value = true;
change.value = true;
Expand Down
10 changes: 8 additions & 2 deletions src/pages/setup/process/components/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@
const iou = ref(deviceStore.tiou);
const setConfidence = async (value: number | [number, number]) => {
await device.value?.setScore(value as number);
const result = await device.value?.setScore(value as number);
if (Number(result) === Number(value)) {
deviceStore.setScore(Number(result));
}
};
const setIou = async (value: number | [number, number]) => {
await device.value?.setIOU(value as number);
const result = await device.value?.setIOU(value as number);
if (Number(result) === Number(value)) {
deviceStore.setIOU(Number(result));
}
};
const handelConfidenceChange = throttle(setConfidence, 1000);
Expand Down
13 changes: 10 additions & 3 deletions src/pages/setup/process/components/Device.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@
</div>

<div
v-if="deviceStore.flashWay === FlashWayType.Custom"
v-if="
deviceStore.flashWay === FlashWayType.Custom &&
deviceStore.deviceStatus === DeviceStatus.SerialConnected
"
:class="[
'custom-model-wrapper',
{ 'custom-model-selected': isSelectedCustomModel },
Expand Down Expand Up @@ -431,7 +434,11 @@
const version = deviceStore.firmware?.version;
const bins = deviceStore.firmware?.bins ?? [];
const fileArray = [];
const currentVersion = deviceStore.deviceVersion;
let currentVersion = deviceStore.deviceVersion;
// When there is no current version number, you need to obtain the version number first before continuing with the operation.
if (currentVersion === null) {
currentVersion = await device.value?.getVersion();
}
if (!currentVersion || version !== currentVersion) {
if (bins.length === 0) {
throw new Error(t('workplace.device.message.firmware.no'));
Expand Down Expand Up @@ -470,7 +477,6 @@
}
loadingTip.value = t('workplace.device.message.tip.flashing');
deviceStore.setDeviceStatus(DeviceStatus.Flashing);
deviceStore.setCurrentAvailableModel(false);
const result = await props.flasher.onWriteFlash(fileArray);
if (result) {
if (props.flasher.isNeedResetDevice) {
Expand All @@ -487,6 +493,7 @@
await device.value?.deleteAction();
deviceStore.setCurrentModel(finallyModel);
}
deviceStore.setCurrentAvailableModel(false);
deviceStore.setDeviceStatus(DeviceStatus.SerialConnected);
} else {
await device.value.disconnect();
Expand Down
Loading

0 comments on commit 6d9ad7e

Please sign in to comment.