|
|
|
@ -5,6 +5,7 @@ |
|
|
|
* |
|
|
|
* 功能包括: |
|
|
|
* - 设备编码读取与设置 (getId/setId) |
|
|
|
* - 相机流地址读取与设置 (getCapture/setCapture) |
|
|
|
* - 数据帧率读取与设置 (getDataFps/setDataFps) |
|
|
|
* - 异常超时监控读取与设置 (getAlert/setAlert) |
|
|
|
* - 滤波配置读取与设置 (getWin/setWin) |
|
|
|
@ -36,6 +37,9 @@ const DEFAULT_SETTINGS = { |
|
|
|
// 设备编码
|
|
|
|
deviceId: '', |
|
|
|
|
|
|
|
// 相机流地址
|
|
|
|
capture: '', |
|
|
|
|
|
|
|
// 数据帧率
|
|
|
|
dataFps: 10, |
|
|
|
|
|
|
|
@ -72,6 +76,7 @@ const SAVE_RESPONSE_TIMEOUT = 10 * 1000; |
|
|
|
|
|
|
|
const SAVE_ITEMS = { |
|
|
|
setId: '设备编码', |
|
|
|
setCapture: '相机流地址', |
|
|
|
setDataFps: '数据帧率', |
|
|
|
setAlert: '异常监控配置', |
|
|
|
setWin: '滤波配置', |
|
|
|
@ -94,6 +99,8 @@ const useAdvancedSettings = () => { |
|
|
|
// WebSocket 订阅 - 监听所有来自设备的响应
|
|
|
|
const { latest: getIdResponse } = useWebSocketSubscription('dev', 'getId'); |
|
|
|
const { latest: setIdResponse } = useWebSocketSubscription('dev', 'setId'); |
|
|
|
const { latest: getCaptureResponse } = useWebSocketSubscription('dev', 'getCapture'); |
|
|
|
const { latest: setCaptureResponse } = useWebSocketSubscription('dev', 'setCapture'); |
|
|
|
const { latest: getDataFpsResponse } = useWebSocketSubscription('dev', 'getDataFps'); |
|
|
|
const { latest: setDataFpsResponse } = useWebSocketSubscription('dev', 'setDataFps'); |
|
|
|
const { latest: getAlertResponse } = useWebSocketSubscription('dev', 'getAlert'); |
|
|
|
@ -130,6 +137,33 @@ const useAdvancedSettings = () => { |
|
|
|
} |
|
|
|
}, [setIdResponse]); |
|
|
|
|
|
|
|
/** |
|
|
|
* 处理相机流地址读取响应 |
|
|
|
*/ |
|
|
|
useEffect(() => { |
|
|
|
if (getCaptureResponse?.values?.capture !== undefined) { |
|
|
|
console.log('📥 收到相机流地址:', getCaptureResponse.values.capture); |
|
|
|
setSettings(prev => ({ |
|
|
|
...prev, |
|
|
|
capture: getCaptureResponse.values.capture |
|
|
|
})); |
|
|
|
setFetchStatus(prev => ({ ...prev, capture: 'success' })); |
|
|
|
} |
|
|
|
}, [getCaptureResponse]); |
|
|
|
|
|
|
|
/** |
|
|
|
* 处理相机流地址设置响应 |
|
|
|
*/ |
|
|
|
useEffect(() => { |
|
|
|
if (setCaptureResponse?.values?.operate !== undefined) { |
|
|
|
if (setCaptureResponse.values.operate) { |
|
|
|
|
|
|
|
} else { |
|
|
|
message.error('相机流地址设置失败'); |
|
|
|
} |
|
|
|
} |
|
|
|
}, [setCaptureResponse]); |
|
|
|
|
|
|
|
/** |
|
|
|
* 处理数据帧率读取响应 |
|
|
|
*/ |
|
|
|
@ -276,6 +310,27 @@ const useAdvancedSettings = () => { |
|
|
|
return sendCommand('setId', { id }); |
|
|
|
}, [sendCommand]); |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取相机流地址 |
|
|
|
*/ |
|
|
|
const fetchCaptureConfig = useCallback(() => { |
|
|
|
setFetchStatus(prev => ({ ...prev, capture: 'loading' })); |
|
|
|
return sendCommand('getCapture', {}); |
|
|
|
}, [sendCommand]); |
|
|
|
|
|
|
|
/** |
|
|
|
* 更新相机流地址 |
|
|
|
*/ |
|
|
|
const updateCaptureConfig = useCallback((capture) => { |
|
|
|
const captureValue = typeof capture === 'string' ? capture.trim() : ''; |
|
|
|
if (!captureValue) { |
|
|
|
message.warning('请输入相机流地址'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return sendCommand('setCapture', { capture: captureValue }); |
|
|
|
}, [sendCommand]); |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取数据帧率 |
|
|
|
*/ |
|
|
|
@ -424,6 +479,11 @@ const useAdvancedSettings = () => { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!settings.capture || !settings.capture.trim()) { |
|
|
|
message.warning('请输入相机流地址'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (settings.dataFps < 1 || settings.dataFps > 30) { |
|
|
|
message.warning('数据帧率范围为 1-30 Hz'); |
|
|
|
return false; |
|
|
|
@ -472,6 +532,10 @@ const useAdvancedSettings = () => { |
|
|
|
cmd: 'setId', |
|
|
|
values: { id: settings.deviceId } |
|
|
|
}, |
|
|
|
{ |
|
|
|
cmd: 'setCapture', |
|
|
|
values: { capture: settings.capture.trim() } |
|
|
|
}, |
|
|
|
{ |
|
|
|
cmd: 'setDataFps', |
|
|
|
values: { dataFps: settings.dataFps } |
|
|
|
@ -525,17 +589,18 @@ const useAdvancedSettings = () => { |
|
|
|
// 所有指令都用 setTimeout 包裹,首个指令也延迟,避免第一个指令丢包
|
|
|
|
fetchDeviceId() |
|
|
|
setTimeout(() => fetchDeviceId(), 50); |
|
|
|
setTimeout(() => fetchDataFps(), 150); |
|
|
|
setTimeout(() => fetchAlertConfig(), 250); |
|
|
|
setTimeout(() => fetchFilterConfig(), 350); |
|
|
|
setTimeout(() => fetchMqttConfig(), 450); |
|
|
|
setTimeout(() => fetchCaptureConfig(), 150); |
|
|
|
setTimeout(() => fetchDataFps(), 250); |
|
|
|
setTimeout(() => fetchAlertConfig(), 350); |
|
|
|
setTimeout(() => fetchFilterConfig(), 450); |
|
|
|
setTimeout(() => fetchMqttConfig(), 550); |
|
|
|
|
|
|
|
// 等待所有响应
|
|
|
|
setTimeout(() => { |
|
|
|
setLoading(false); |
|
|
|
console.log('配置获取完成'); |
|
|
|
}, 2000); |
|
|
|
}, [isConnected, isReady, fetchDeviceId, fetchDataFps, fetchAlertConfig, fetchFilterConfig, fetchMqttConfig]); |
|
|
|
}, [isConnected, isReady, fetchDeviceId, fetchCaptureConfig, fetchDataFps, fetchAlertConfig, fetchFilterConfig, fetchMqttConfig]); |
|
|
|
|
|
|
|
/** |
|
|
|
* 保存所有配置 |
|
|
|
@ -613,6 +678,8 @@ const useAdvancedSettings = () => { |
|
|
|
// 单项操作
|
|
|
|
fetchDeviceId, |
|
|
|
updateDeviceId, |
|
|
|
fetchCaptureConfig, |
|
|
|
updateCaptureConfig, |
|
|
|
fetchDataFps, |
|
|
|
updateDataFps, |
|
|
|
fetchAlertConfig, |
|
|
|
|