|
@@ -24,6 +24,17 @@ let shooting = false
|
|
|
|
|
|
|
|
const TAKE_PHOTO_TIMEOUT = 10 * 60 * 1000
|
|
const TAKE_PHOTO_TIMEOUT = 10 * 60 * 1000
|
|
|
const MCU_ERRORS = ['mcu设备未连接', 'mcu设备未初始化', '当前有未完成的任务']
|
|
const MCU_ERRORS = ['mcu设备未连接', 'mcu设备未初始化', '当前有未完成的任务']
|
|
|
|
|
+const LINK_ERRORS = [
|
|
|
|
|
+ '相机未连接',
|
|
|
|
|
+ '请检查相机',
|
|
|
|
|
+ '请先连接相机',
|
|
|
|
|
+ '相机是否连接',
|
|
|
|
|
+ 'MCU 连接失败',
|
|
|
|
|
+ 'MCU连接失败',
|
|
|
|
|
+ 'MCU串口未连接',
|
|
|
|
|
+ 'mcu设备未连接',
|
|
|
|
|
+ 'MCU硬件连接失败',
|
|
|
|
|
+]
|
|
|
|
|
|
|
|
type IpcLike = {
|
|
type IpcLike = {
|
|
|
on: (channel: string, listener: (...args: any[]) => void) => void
|
|
on: (channel: string, listener: (...args: any[]) => void) => void
|
|
@@ -148,6 +159,7 @@ function waitForShoot(ipc: IpcLike) {
|
|
|
runMcu: icpList.socket.message + '_run_mcu',
|
|
runMcu: icpList.socket.message + '_run_mcu',
|
|
|
mcu: icpList.socket.message + '_mcu',
|
|
mcu: icpList.socket.message + '_mcu',
|
|
|
photoTake: icpList.socket.message + '_photo_take',
|
|
photoTake: icpList.socket.message + '_photo_take',
|
|
|
|
|
+ imageProcess: icpList.socket.message + '_image_process',
|
|
|
finish: icpList.socket.message + '_photo_take_finish',
|
|
finish: icpList.socket.message + '_photo_take_finish',
|
|
|
stop: icpList.socket.message + '_run_mcu_stop',
|
|
stop: icpList.socket.message + '_run_mcu_stop',
|
|
|
}
|
|
}
|
|
@@ -164,20 +176,32 @@ function waitForShoot(ipc: IpcLike) {
|
|
|
resolveFn(result)
|
|
resolveFn(result)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const failIfLinkLost = (result: any) => {
|
|
|
|
|
+ const msg = linkErrorMessage(result)
|
|
|
|
|
+ if (!msg) return false
|
|
|
|
|
+ done({ code: 1, msg }, true)
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
handlers[channels.runMcu] = (_event, result) => {
|
|
handlers[channels.runMcu] = (_event, result) => {
|
|
|
|
|
+ if (failIfLinkLost(result)) return
|
|
|
if (result && result.code !== 0) {
|
|
if (result && result.code !== 0) {
|
|
|
done({ code: 1, msg: result.msg || '拍照失败' })
|
|
done({ code: 1, msg: result.msg || '拍照失败' })
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
handlers[channels.mcu] = (_event, result) => {
|
|
handlers[channels.mcu] = (_event, result) => {
|
|
|
|
|
+ if (failIfLinkLost(result)) return
|
|
|
const msg = String(result?.msg || '')
|
|
const msg = String(result?.msg || '')
|
|
|
if (result?.code === 1 && MCU_ERRORS.some((item) => msg.includes(item))) {
|
|
if (result?.code === 1 && MCU_ERRORS.some((item) => msg.includes(item))) {
|
|
|
done({ code: 1, msg }, true)
|
|
done({ code: 1, msg }, true)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
handlers[channels.photoTake] = (_event, result) => {
|
|
handlers[channels.photoTake] = (_event, result) => {
|
|
|
|
|
+ if (failIfLinkLost(result)) return
|
|
|
if (result?.code !== 0 && result?.msg) stepError = result.msg
|
|
if (result?.code !== 0 && result?.msg) stepError = result.msg
|
|
|
}
|
|
}
|
|
|
|
|
+ handlers[channels.imageProcess] = (_event, result) => {
|
|
|
|
|
+ failIfLinkLost(result)
|
|
|
|
|
+ }
|
|
|
handlers[channels.stop] = (_event, result) => {
|
|
handlers[channels.stop] = (_event, result) => {
|
|
|
stopped = true
|
|
stopped = true
|
|
|
stepError = result?.msg || '拍摄已终止'
|
|
stepError = result?.msg || '拍摄已终止'
|
|
@@ -217,6 +241,15 @@ function waitForShoot(ipc: IpcLike) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function linkErrorMessage(result: any): string | null {
|
|
|
|
|
+ const msg = String(result?.msg || '')
|
|
|
|
|
+ if (!msg) return null
|
|
|
|
|
+ if (LINK_ERRORS.some((item) => msg.includes(item))) return msg
|
|
|
|
|
+ const status = result?.status ?? result?.device_status
|
|
|
|
|
+ if (status === -1 && (msg.includes('相机') || msg.includes('MCU') || msg.includes('mcu'))) return msg
|
|
|
|
|
+ return null
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function keepOn(ipc: IpcLike, channel: string, handler: (...args: any[]) => void) {
|
|
function keepOn(ipc: IpcLike, channel: string, handler: (...args: any[]) => void) {
|
|
|
let set = keptListeners.get(channel)
|
|
let set = keptListeners.get(channel)
|
|
|
if (!set) {
|
|
if (!set) {
|