|
|
@@ -10,6 +10,19 @@ const socketStore = socket();
|
|
|
const clientStore = client();
|
|
|
const userInfoStore = useUserInfo();
|
|
|
|
|
|
+export type SerialPortStatus = 'connected' | 'occupied' | 'idle'
|
|
|
+
|
|
|
+export interface SerialPortInfo {
|
|
|
+ name: string
|
|
|
+ status: SerialPortStatus
|
|
|
+ role?: string
|
|
|
+}
|
|
|
+
|
|
|
+const SERIAL_STATUS_TEXT: Record<SerialPortStatus, string> = {
|
|
|
+ connected: '已连接',
|
|
|
+ occupied: '占用',
|
|
|
+ idle: '空闲',
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* 定义检查信息的Store
|
|
|
@@ -83,6 +96,171 @@ export const checkInfo = defineStore('checkInfo', () => {
|
|
|
isInitSend:false,
|
|
|
status:0,
|
|
|
})
|
|
|
+
|
|
|
+ // MCU 是否已拿到设备 ID(连接标记,不等于初始化完成)
|
|
|
+ const mcuConnected = ref(false)
|
|
|
+ const mcuDeviceId = ref<number | null>(null)
|
|
|
+ const serialPorts = ref<SerialPortInfo[]>([])
|
|
|
+ let hardwareInfoListenerBound = false
|
|
|
+
|
|
|
+ const serialSummary = computed(() => {
|
|
|
+ if (!serialPorts.value.length) return ''
|
|
|
+ return serialPorts.value
|
|
|
+ .map((port) => `${port.name}${SERIAL_STATUS_TEXT[port.status] || port.status}`)
|
|
|
+ .join('、')
|
|
|
+ })
|
|
|
+
|
|
|
+ function upsertSerialPort(name: string, status: SerialPortStatus, role?: string) {
|
|
|
+ if (!name) return
|
|
|
+ const upper = String(name).toUpperCase()
|
|
|
+ const idx = serialPorts.value.findIndex((port) => port.name.toUpperCase() === upper)
|
|
|
+ if (idx >= 0) {
|
|
|
+ serialPorts.value[idx] = {
|
|
|
+ ...serialPorts.value[idx],
|
|
|
+ status,
|
|
|
+ role: role || serialPorts.value[idx].role,
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ serialPorts.value.push({ name: upper, status, role })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function applyHardwareCheckInfo(data: any) {
|
|
|
+ if (!data) return
|
|
|
+ if (data.mcu) {
|
|
|
+ if (typeof data.mcu.connected === 'boolean') {
|
|
|
+ mcuConnected.value = data.mcu.connected
|
|
|
+ }
|
|
|
+ if (data.mcu.device_id != null && data.mcu.device_id !== '') {
|
|
|
+ mcuDeviceId.value = Number(data.mcu.device_id)
|
|
|
+ mcuConnected.value = true
|
|
|
+ }
|
|
|
+ if (data.mcu.port_name) {
|
|
|
+ upsertSerialPort(data.mcu.port_name, 'connected', 'MCU')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (data.device_id != null && data.device_id !== '') {
|
|
|
+ mcuDeviceId.value = Number(data.device_id)
|
|
|
+ mcuConnected.value = true
|
|
|
+ }
|
|
|
+ if (Array.isArray(data.serial_ports)) {
|
|
|
+ serialPorts.value = data.serial_ports
|
|
|
+ .map((port: any) => ({
|
|
|
+ name: String(port?.name || '').toUpperCase(),
|
|
|
+ status: (['connected', 'occupied', 'idle'].includes(port?.status)
|
|
|
+ ? port.status
|
|
|
+ : 'idle') as SerialPortStatus,
|
|
|
+ role: port?.role,
|
|
|
+ }))
|
|
|
+ .filter((port: SerialPortInfo) => port.name)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function parseComFromText(text: string): string | null {
|
|
|
+ if (!text) return null
|
|
|
+ const match = String(text).match(/COM\d+/i)
|
|
|
+ return match ? match[0].toUpperCase() : null
|
|
|
+ }
|
|
|
+
|
|
|
+ function parseMcuMessageForHardware(result: any) {
|
|
|
+ if (!result) return
|
|
|
+ const msg = result.msg || ''
|
|
|
+ const data = result.data
|
|
|
+ const inner = data?.data
|
|
|
+
|
|
|
+ if (result.msg_type === 'hardware_check_info' || result.msg_type === 'get_hardware_check_info') {
|
|
|
+ applyHardwareCheckInfo(data)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (data?.serial_ports || data?.mcu) {
|
|
|
+ applyHardwareCheckInfo(data)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data?._type === 'select_port_name' && inner) {
|
|
|
+ if (inner.port_name) {
|
|
|
+ const isMcu = inner.device_name === 'mcu' || inner.device_name === 'MCU'
|
|
|
+ upsertSerialPort(inner.port_name, 'connected', isMcu ? 'MCU' : inner.device_name)
|
|
|
+ if (isMcu) mcuConnected.value = true
|
|
|
+ } else {
|
|
|
+ Object.keys(inner).forEach((key) => {
|
|
|
+ if (/^COM\d+/i.test(key)) {
|
|
|
+ const existing = serialPorts.value.find((port) => port.name.toUpperCase() === key.toUpperCase())
|
|
|
+ upsertSerialPort(key, existing?.status === 'connected' ? 'connected' : 'idle')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data?._type === 'remove_port' && (inner?.port_name || data?.data?.port_name)) {
|
|
|
+ const portName = String(inner?.port_name || data.data.port_name).toUpperCase()
|
|
|
+ serialPorts.value = serialPorts.value.filter((port) => port.name.toUpperCase() !== portName)
|
|
|
+ }
|
|
|
+
|
|
|
+ const textSources = [
|
|
|
+ msg,
|
|
|
+ typeof inner === 'string' ? inner : '',
|
|
|
+ inner?.text,
|
|
|
+ typeof data?.data === 'string' ? data.data : '',
|
|
|
+ ].filter(Boolean) as string[]
|
|
|
+
|
|
|
+ textSources.forEach((text) => {
|
|
|
+ const comName = parseComFromText(text)
|
|
|
+ if (!comName) return
|
|
|
+ if (text.includes('被占用')) {
|
|
|
+ upsertSerialPort(comName, 'occupied')
|
|
|
+ } else if (text.includes('开始识别接口')) {
|
|
|
+ const existing = serialPorts.value.find((port) => port.name === comName)
|
|
|
+ if (!existing || existing.status === 'idle') {
|
|
|
+ upsertSerialPort(comName, 'idle')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (msg.includes('MCU 已连接') || msg.includes('MCU已连接') || msg.includes('MCU连接成功')) {
|
|
|
+ mcuConnected.value = true
|
|
|
+ if (inner?.device_id != null) mcuDeviceId.value = Number(inner.device_id)
|
|
|
+ if (inner?.port_name) {
|
|
|
+ upsertSerialPort(inner.port_name, 'connected', 'MCU')
|
|
|
+ } else {
|
|
|
+ const lastIdle = [...serialPorts.value].reverse().find((port) => port.status === 'idle')
|
|
|
+ if (lastIdle) {
|
|
|
+ upsertSerialPort(lastIdle.name, 'connected', 'MCU')
|
|
|
+ } else if (serialPorts.value.length === 1) {
|
|
|
+ upsertSerialPort(serialPorts.value[0].name, 'connected', 'MCU')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (msg.includes('MCU 连接失败') || msg.includes('MCU串口未连接')) {
|
|
|
+ mcuConnected.value = false
|
|
|
+ mcuDeviceId.value = null
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function resetHardwareSummary() {
|
|
|
+ mcuConnected.value = false
|
|
|
+ mcuDeviceId.value = null
|
|
|
+ serialPorts.value = []
|
|
|
+ }
|
|
|
+
|
|
|
+ function ensureHardwareInfoListener() {
|
|
|
+ if (!clientStore.isClient || hardwareInfoListenerBound) return
|
|
|
+ hardwareInfoListenerBound = true
|
|
|
+ const handler = (_event: any, result: any) => {
|
|
|
+ if (result?.data) applyHardwareCheckInfo(result.data)
|
|
|
+ }
|
|
|
+ clientStore.ipc.on(icpList.socket.message + '_hardware_check_info', handler)
|
|
|
+ clientStore.ipc.on(icpList.socket.message + '_get_hardware_check_info', handler)
|
|
|
+ }
|
|
|
+
|
|
|
+ function requestHardwareCheckInfo() {
|
|
|
+ ensureHardwareInfoListener()
|
|
|
+ if (!clientStore.isClient) return
|
|
|
+ socketStore.sendMessage({
|
|
|
+ type: 'get_hardware_check_info',
|
|
|
+ data: null,
|
|
|
+ })
|
|
|
+ }
|
|
|
// 计算完成进度
|
|
|
const getProgress = computed(() => {
|
|
|
let completed = 0;
|
|
|
@@ -101,7 +279,7 @@ export const checkInfo = defineStore('checkInfo', () => {
|
|
|
clearInterval(CKTimerInterval)
|
|
|
checkTime.value = 0
|
|
|
mcu.isInitSend = false
|
|
|
- return '拍照机连接失败,请重新检查,可以尝试重新启动拍照机,插拔USB口,强制初始化等,请检查相机和支撑转盘是否待机休眠。如果确认未休眠,请检查各种连接线是否,正常连上。然后再重试一次,一直无法解决问题,请致电:15957854217,18805712182。';
|
|
|
+ return 'MCU硬件连接失败,请重新检查,可以尝试重新启动MCU硬件,插拔USB口,强制初始化等,请检查相机和支撑转盘是否待机休眠。如果确认未休眠,请检查各种连接线是否,正常连上。然后再重试一次,一直无法解决问题,请致电:15957854217,18805712182。';
|
|
|
}
|
|
|
for (const device of Object.values(devices)) {
|
|
|
if (device.status === -1 && device.msg_type !== 'connect_bluetooth') {
|
|
|
@@ -191,11 +369,13 @@ export const checkInfo = defineStore('checkInfo', () => {
|
|
|
try {
|
|
|
await socketStore.connectSocket();
|
|
|
await socketStore.sendMessage({ type: messageType });
|
|
|
+ clientStore.ipc.removeAllListeners(icpList.socket.message+'_'+deviceName);
|
|
|
clientStore.ipc.on(icpList.socket.message+'_'+deviceName, (event, result) => {
|
|
|
|
|
|
console.log(result);
|
|
|
if (result && checkTime.value > 0) {
|
|
|
if(deviceName === 'mcu'){
|
|
|
+ parseMcuMessageForHardware(result)
|
|
|
if(result.status === 2 ){
|
|
|
if(!mcu.isInitSend){
|
|
|
socketStore.sendMessage({
|
|
|
@@ -218,6 +398,10 @@ export const checkInfo = defineStore('checkInfo', () => {
|
|
|
}
|
|
|
}
|
|
|
if([-1,0].includes(result.status)){
|
|
|
+ // 扫描到的某个 CH34 口被占用,不作为 MCU 整体连接失败
|
|
|
+ if ((result.msg || '').includes('被占用')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
/* if(result.status === -1 ){
|
|
|
if(mcuErrorCount.value === 0){
|
|
|
mcuErrorCount.value++;
|
|
|
@@ -267,6 +451,7 @@ export const checkInfo = defineStore('checkInfo', () => {
|
|
|
await checkDevice(deviceName, devices[deviceName].msg_type);
|
|
|
}
|
|
|
}
|
|
|
+ requestHardwareCheckInfo();
|
|
|
|
|
|
};
|
|
|
|
|
|
@@ -280,7 +465,9 @@ export const checkInfo = defineStore('checkInfo', () => {
|
|
|
}
|
|
|
mcu.status = -0;
|
|
|
mcu.isInitSend = false;
|
|
|
+ resetHardwareSummary();
|
|
|
checkTime.value++;
|
|
|
+ if (CKTimerInterval) clearInterval(CKTimerInterval)
|
|
|
CKTimerInterval = setInterval(()=>{
|
|
|
checkTime.value++;
|
|
|
|
|
|
@@ -294,11 +481,11 @@ export const checkInfo = defineStore('checkInfo', () => {
|
|
|
devices.mcu.status = -1;
|
|
|
mcu.status = -1;
|
|
|
mcu.isInitSend = false;
|
|
|
- devices.mcu.msg = '拍照机连接失败';
|
|
|
+ devices.mcu.msg = 'MCU硬件连接失败';
|
|
|
}
|
|
|
if( devices.cam_control.status !== 2 ){
|
|
|
devices.cam_control.status = -1;
|
|
|
- devices.cam_control.msg = '拍照机连接失败';
|
|
|
+ devices.cam_control.msg = 'MCU硬件连接失败';
|
|
|
}
|
|
|
}
|
|
|
},1000)
|
|
|
@@ -326,6 +513,12 @@ export const checkInfo = defineStore('checkInfo', () => {
|
|
|
set_blue_tooth_scan_NO,
|
|
|
checkAction,
|
|
|
reCheckAction,
|
|
|
+ mcuConnected,
|
|
|
+ mcuDeviceId,
|
|
|
+ serialPorts,
|
|
|
+ serialSummary,
|
|
|
+ requestHardwareCheckInfo,
|
|
|
+ resetHardwareSummary,
|
|
|
// 多相机模式相关
|
|
|
cameraList,
|
|
|
currentCameraKey,
|