From 6c25b37827c1923d0339e7a1317a0a63a3114833 Mon Sep 17 00:00:00 2001 From: stream Date: Mon, 17 Nov 2025 19:01:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BE=B9=E7=BC=98=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=B0=81=E8=A3=85=EF=BC=9B=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=8D=95=E4=B8=AA=E8=8A=82=E7=82=B9=E8=B0=83=E7=94=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/api/EdgeCameraController.java | 51 +++----- .../api/EdgeMicrophoneController.java | 97 ++++---------- .../web/controller/test/TeFlowController.java | 9 ++ .../microphone/EdgeMicrophoneVolumeVO.java | 12 ++ .../client/service/EdgeCameraService.java | 23 ++-- .../client/service/EdgeMicrophoneService.java | 55 ++------ .../client/service/EdgeSpeakerService.java | 2 +- .../service/impl/EdgeCameraServiceImpl.java | 73 ++++++----- .../impl/EdgeMicrophoneServiceImpl.java | 92 +++++-------- .../service/impl/EdgeSpeakerServiceImpl.java | 3 +- .../java/com/cmvr/test/enums/ActionEnum.java | 18 +-- .../edge/EdgeCameraOperateService.java | 9 +- .../edge/EdgeMicrophoneOperateService.java | 13 +- .../edge/EdgeSpeakerOperateService.java | 31 ++--- .../{ => edge}/vi/ViCorpusOperateService.java | 5 +- .../{ => edge}/vi/ViPlayOperateService.java | 5 +- .../{ => edge}/vi/ViSchemeOperateService.java | 5 +- .../runtime/operator/vi/VIOperateService.java | 12 -- .../operator/vi/ViNodeOperateHandler.java | 28 ---- .../test/model/vo/FlowActionRequestVO.java | 21 +++ .../service/FlowActionExecutorService.java | 123 ++++++++++++++++++ 21 files changed, 342 insertions(+), 345 deletions(-) create mode 100644 cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/model/microphone/EdgeMicrophoneVolumeVO.java rename cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/{ => edge}/vi/ViCorpusOperateService.java (92%) rename cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/{ => edge}/vi/ViPlayOperateService.java (95%) rename cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/{ => edge}/vi/ViSchemeOperateService.java (95%) delete mode 100644 cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/VIOperateService.java delete mode 100644 cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViNodeOperateHandler.java create mode 100644 cmvr-iot-test/src/main/java/com/cmvr/test/model/vo/FlowActionRequestVO.java create mode 100644 cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowActionExecutorService.java diff --git a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/api/EdgeCameraController.java b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/api/EdgeCameraController.java index a744883..12d9f66 100644 --- a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/api/EdgeCameraController.java +++ b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/api/EdgeCameraController.java @@ -3,13 +3,13 @@ package com.cmvr.web.controller.api; import com.alibaba.fastjson2.JSON; import com.cmvr.common.core.controller.BaseController; import com.cmvr.common.core.domain.AjaxResult; +import com.cmvr.edge.client.model.EdgeCommonVO; import com.cmvr.edge.client.service.EdgeCameraService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @Api(tags = "边缘--相机") @@ -22,64 +22,43 @@ public class EdgeCameraController extends BaseController { @ApiOperation("获取相机状态") @GetMapping("/status") - public AjaxResult status( - @RequestParam("deviceId") String deviceId, - @RequestParam("terminalId") String terminalId - ) { - return success(JSON.toJSONString(edgeCameraService.status(terminalId, deviceId))); + public AjaxResult status(EdgeCommonVO edgeCommonVO) { + return success(JSON.toJSONString(edgeCameraService.status(edgeCommonVO))); } @ApiOperation("开启相机") @GetMapping("/start") - public AjaxResult start( - @RequestParam("deviceId") String deviceId, - @RequestParam("terminalId") String terminalId - ) { - return success(edgeCameraService.start(terminalId, deviceId)); + public AjaxResult start(EdgeCommonVO edgeCommonVO) { + return success(edgeCameraService.start(edgeCommonVO)); } @ApiOperation("关闭相机") @GetMapping("/stop") - public AjaxResult stop( - @RequestParam("deviceId") String deviceId, - @RequestParam("terminalId") String terminalId - ) { - return success(edgeCameraService.stop(terminalId, deviceId)); + public AjaxResult stop(EdgeCommonVO edgeCommonVO) { + return success(edgeCameraService.stop(edgeCommonVO)); } @ApiOperation("获取图片") @GetMapping("/getRGBImage") - public AjaxResult getRGBImage( - @RequestParam("deviceId") String deviceId, - @RequestParam("terminalId") String terminalId - ) { - return success(edgeCameraService.getRGBImage(terminalId, deviceId)); + public AjaxResult getRGBImage(EdgeCommonVO edgeCommonVO) { + return success(edgeCameraService.getRGBImage(edgeCommonVO)); } @ApiOperation("开始录制视频") @GetMapping("/startRecording") - public AjaxResult startRecording( - @RequestParam("deviceId") String deviceId, - @RequestParam("terminalId") String terminalId - ) { - return success(edgeCameraService.startRecording(terminalId, deviceId)); + public AjaxResult startRecording(EdgeCommonVO edgeCommonVO) { + return success(edgeCameraService.startRecording(edgeCommonVO)); } @ApiOperation("停止录制视频") @GetMapping("/stopRecording") - public AjaxResult stopRecording( - @RequestParam("deviceId") String deviceId, - @RequestParam("terminalId") String terminalId - ) { - return success(edgeCameraService.stopRecording(terminalId, deviceId)); + public AjaxResult stopRecording(EdgeCommonVO edgeCommonVO) { + return success(edgeCameraService.stopRecording(edgeCommonVO)); } @ApiOperation("获取图片和视频") @GetMapping("/getRGBDImages") - public AjaxResult getRGBDImages( - @RequestParam("deviceId") String deviceId, - @RequestParam("terminalId") String terminalId - ) { - return success(edgeCameraService.getRGBDImages(terminalId, deviceId)); + public AjaxResult getRGBDImages(EdgeCommonVO edgeCommonVO) { + return success(edgeCameraService.getRGBDImages(edgeCommonVO)); } } diff --git a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/api/EdgeMicrophoneController.java b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/api/EdgeMicrophoneController.java index 86a9674..8289e9e 100644 --- a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/api/EdgeMicrophoneController.java +++ b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/api/EdgeMicrophoneController.java @@ -1,17 +1,17 @@ package com.cmvr.web.controller.api; -import cmvr.api.MicrophoneCommand; -import com.cmvr.edge.client.service.EdgeMicrophoneService; import com.cmvr.common.core.domain.AjaxResult; +import com.cmvr.edge.client.model.EdgeCommonVO; +import com.cmvr.edge.client.model.microphone.EdgeMicrophoneVolumeVO; +import com.cmvr.edge.client.service.EdgeMicrophoneService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; import lombok.RequiredArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import java.util.HashMap; -import java.util.Map; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * 麦克风管理 @@ -27,107 +27,54 @@ public class EdgeMicrophoneController { @ApiOperation("获取麦克风状态") @PreAuthorize("@ss.hasPermi('system:microphone:query')") @GetMapping("/status") - public AjaxResult getStatus( - @ApiParam(value = "终端设备ID", required = true) - @RequestParam String terminalId, - @ApiParam(value = "设备ID", required = true) - @RequestParam String deviceId) { - try { - MicrophoneCommand.GetMicStateCommand.Feedback feedback = microphoneService.getStatus(terminalId, deviceId); - MicrophoneCommand.MicState state = feedback.getState(); - - Map result = new HashMap<>(); - Map header = new HashMap<>(); - header.put("deviceId", deviceId); - header.put("timestamp", feedback.getHeader().getTimestamp().getSeconds()); - result.put("header", header); - - Map stateMap = new HashMap<>(); - stateMap.put("isInitialized", state.getIsInitialized()); - stateMap.put("isRunning", state.getIsRunning()); - stateMap.put("isRecording", state.getIsRecording()); - stateMap.put("volume", state.getVolume()); - stateMap.put("errorMessage", state.getErrorMessage()); - result.put("state", stateMap); - - return AjaxResult.success(result); - } catch (Exception e) { - return AjaxResult.error("获取麦克风状态失败:" + e.getMessage()); - } + public AjaxResult getStatus(EdgeCommonVO edgeCommonVO) { + return AjaxResult.success(microphoneService.getStatus(edgeCommonVO)); } @ApiOperation("开始录音") @PreAuthorize("@ss.hasPermi('system:microphone:record')") @PostMapping("/start") - public AjaxResult startRecord( - @ApiParam(value = "终端设备ID", required = true) - @RequestParam String terminalId, - @ApiParam(value = "设备ID", required = true) - @RequestParam String deviceId, - @ApiParam(value = "录音文件路径", required = true) - @RequestParam String filePath) { - microphoneService.startRecord(terminalId, deviceId, filePath); - return AjaxResult.success(); + public AjaxResult startRecord(EdgeCommonVO edgeCommonVO) { + String filePath = microphoneService.startRecord(edgeCommonVO); + return AjaxResult.success(filePath); } @ApiOperation("停止录音") @PreAuthorize("@ss.hasPermi('system:microphone:stop')") @PostMapping("/stop") - public AjaxResult stopRecord( - @ApiParam(value = "终端设备ID", required = true) - @RequestParam String terminalId, - @ApiParam(value = "设备ID", required = true) - @RequestParam String deviceId) { - microphoneService.stopRecord(terminalId, deviceId); + public AjaxResult stopRecord(EdgeCommonVO edgeCommonVO) { + microphoneService.stopRecord(edgeCommonVO); return AjaxResult.success(); } @ApiOperation("暂停录音") @PreAuthorize("@ss.hasPermi('system:microphone:pause')") @PostMapping("/pause") - public AjaxResult pauseRecord( - @ApiParam(value = "终端设备ID", required = true) - @RequestParam String terminalId, - @ApiParam(value = "设备ID", required = true) - @RequestParam String deviceId) { - microphoneService.pauseRecord(terminalId, deviceId); + public AjaxResult pauseRecord(EdgeCommonVO edgeCommonVO) { + microphoneService.pauseRecord(edgeCommonVO); return AjaxResult.success(); } @ApiOperation("恢复录音") @PreAuthorize("@ss.hasPermi('system:microphone:resume')") @PostMapping("/resume") - public AjaxResult resumeRecord( - @ApiParam(value = "终端设备ID", required = true) - @RequestParam String terminalId, - @ApiParam(value = "设备ID", required = true) - @RequestParam String deviceId) { - microphoneService.resumeRecord(terminalId, deviceId); + public AjaxResult resumeRecord(EdgeCommonVO edgeCommonVO) { + microphoneService.resumeRecord(edgeCommonVO); return AjaxResult.success(); } @ApiOperation("设置音量") @PreAuthorize("@ss.hasPermi('system:microphone:volume')") @PostMapping("/volume") - public AjaxResult setVolume( - @ApiParam(value = "终端设备ID", required = true) - @RequestParam String terminalId, - @ApiParam(value = "设备ID", required = true) - @RequestParam String deviceId, - @ApiParam(value = "音量大小(0-100)", required = true) - @RequestParam int volume) { - microphoneService.setVolume(terminalId, deviceId, volume); + public AjaxResult setVolume(EdgeMicrophoneVolumeVO edgeMicrophoneVolumeVO) { + microphoneService.setVolume(edgeMicrophoneVolumeVO); return AjaxResult.success(); } @ApiOperation("获取音量") @PreAuthorize("@ss.hasPermi('system:microphone:volume')") @GetMapping("/volume") - public AjaxResult getVolume( - @ApiParam(value = "终端设备ID", required = true) - @RequestParam String terminalId, - @ApiParam(value = "设备ID", required = true) - @RequestParam String deviceId) { - return AjaxResult.success(microphoneService.getVolume(terminalId, deviceId)); + public AjaxResult getVolume(EdgeCommonVO edgeCommonVO) { + return AjaxResult.success(microphoneService.getVolume(edgeCommonVO)); } } \ No newline at end of file diff --git a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowController.java b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowController.java index 589c670..f90e64e 100644 --- a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowController.java +++ b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowController.java @@ -6,9 +6,11 @@ import com.cmvr.test.flow.context.TaskContextManager; import com.cmvr.test.flow.control.FlowControlService; import com.cmvr.test.flow.runtime.engine.FlowTaskRuntimeService; import com.cmvr.test.model.domain.TeDetectionItem; +import com.cmvr.test.model.vo.FlowActionRequestVO; import com.cmvr.test.model.vo.TeFlowViewVO; import com.cmvr.test.model.vo.TeTaskExecuteNormalVO; import com.cmvr.test.model.vo.TeTaskExecuteTrailVO; +import com.cmvr.test.service.FlowActionExecutorService; import com.cmvr.test.service.ITeDetectionItemService; import com.cmvr.test.service.ITeNodeInstService; import io.swagger.annotations.Api; @@ -34,6 +36,7 @@ public class TeFlowController extends BaseController { private final FlowTaskRuntimeService flowTaskRuntimeService; private final TaskContextManager taskContextManager; private final FlowControlService flowControlService; + private final FlowActionExecutorService flowActionExecutorService; @ApiOperation("流程发布") @PostMapping("/publish") @@ -86,4 +89,10 @@ public class TeFlowController extends BaseController { flowControlService.resume(instId); return AjaxResult.success(); } + + @PostMapping("/action") + @ApiOperation("单个节点执行") + public AjaxResult actionExecute(@RequestBody FlowActionRequestVO flowActionRequestVO) { + return AjaxResult.ok(flowActionExecutorService.actionExecute(flowActionRequestVO)); + } } \ No newline at end of file diff --git a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/model/microphone/EdgeMicrophoneVolumeVO.java b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/model/microphone/EdgeMicrophoneVolumeVO.java new file mode 100644 index 0000000..c7c9ced --- /dev/null +++ b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/model/microphone/EdgeMicrophoneVolumeVO.java @@ -0,0 +1,12 @@ +package com.cmvr.edge.client.model.microphone; + +import com.cmvr.edge.client.model.EdgeCommonVO; +import lombok.Data; + +import java.util.List; + +@Data +public class EdgeMicrophoneVolumeVO extends EdgeCommonVO { + /** 音量 */ + private int volume; +} diff --git a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeCameraService.java b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeCameraService.java index 42564f9..8b5da75 100644 --- a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeCameraService.java +++ b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeCameraService.java @@ -1,6 +1,7 @@ package com.cmvr.edge.client.service; import cmvr.api.CameraCommand; +import com.cmvr.edge.client.model.EdgeCommonVO; import io.grpc.stub.StreamObserver; /** @@ -11,47 +12,47 @@ public interface EdgeCameraService { /** * 获取相机状态 */ - public CameraCommand.CameraState status(String terminalId, String deviceId); + public CameraCommand.CameraState status(EdgeCommonVO edgeCommonVO); /** * 校验相机状态 */ - public boolean checkStatus(String terminalId, String deviceId); + public boolean checkStatus(EdgeCommonVO edgeCommonVO); /** * 开始相机服务 */ - public String start(String terminalId, String deviceId); + public String start(EdgeCommonVO edgeCommonVO); /** * 结束相机服务 */ - public String stop(String terminalId, String deviceId); + public String stop(EdgeCommonVO edgeCommonVO); /** * 获取相机图片 */ - public String getRGBImage(String terminalId, String deviceId); + public String getRGBImage(EdgeCommonVO edgeCommonVO); /** * 开始录制视频 */ - public String startRecording(String terminalId, String deviceId); + public String startRecording(EdgeCommonVO edgeCommonVO); /** * 停止录制视频 */ - public String stopRecording(String terminalId, String deviceId); + public String stopRecording(EdgeCommonVO edgeCommonVO); /** * 获取相机图片组 */ - public String getRGBDImages(String terminalId, String deviceId); + public String getRGBDImages(EdgeCommonVO edgeCommonVO); - StreamObserver getRGBImageStream(String terminalId, String deviceId); + StreamObserver getRGBImageStream(EdgeCommonVO edgeCommonVO); - void getDepthImageStream(String terminalId, String deviceId); - void getRGBDImagesStream(String terminalId, String deviceId); + void getDepthImageStream(EdgeCommonVO edgeCommonVO); + void getRGBDImagesStream(EdgeCommonVO edgeCommonVO); diff --git a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeMicrophoneService.java b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeMicrophoneService.java index f1cd75d..6d66a8b 100644 --- a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeMicrophoneService.java +++ b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeMicrophoneService.java @@ -1,6 +1,8 @@ package com.cmvr.edge.client.service; import cmvr.api.MicrophoneCommand; +import com.cmvr.edge.client.model.EdgeCommonVO; +import com.cmvr.edge.client.model.microphone.EdgeMicrophoneVolumeVO; /** * 边缘麦克风服务接口 @@ -10,75 +12,36 @@ import cmvr.api.MicrophoneCommand; public interface EdgeMicrophoneService { /** * 获取麦克风当前状态 - * 通过gRPC调用获取麦克风的运行状态,包括是否正在录音、音量等信息 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @return MicState 返回麦克风的当前状态 - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ - MicrophoneCommand.GetMicStateCommand.Feedback getStatus(String terminalId, String deviceId); + String getStatus(EdgeCommonVO edgeCommonVO); /** * 开始录音 - * 通过gRPC调用开始录音,将录音保存到指定路径 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @param filePath 录音文件的保存路径 - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ - void startRecord(String terminalId, String deviceId, String filePath); + String startRecord(EdgeCommonVO edgeCommonVO); /** * 停止录音 - * 通过gRPC调用停止麦克风的当前录音 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ - void stopRecord(String terminalId, String deviceId); + String stopRecord(EdgeCommonVO edgeCommonVO); /** * 暂停录音 - * 通过gRPC调用暂停麦克风的当前录音 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ - void pauseRecord(String terminalId, String deviceId); + void pauseRecord(EdgeCommonVO edgeCommonVO); /** * 恢复录音 - * 通过gRPC调用恢复麦克风之前暂停的录音 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ - void resumeRecord(String terminalId, String deviceId); + void resumeRecord(EdgeCommonVO edgeCommonVO); /** * 设置麦克风音量 - * 通过gRPC调用设置麦克风的音量大小 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @param volume 音量大小(0-100) - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ - void setVolume(String terminalId, String deviceId, int volume); + void setVolume(EdgeMicrophoneVolumeVO edgeMicrophoneVolumeVO); /** * 获取当前音量 - * 通过gRPC调用获取麦克风的当前音量大小 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @return int 返回当前音量大小(0-100) - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ - int getVolume(String terminalId, String deviceId); + int getVolume(EdgeCommonVO edgeCommonVO); } \ No newline at end of file diff --git a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeSpeakerService.java b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeSpeakerService.java index c68d976..485d8c3 100644 --- a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeSpeakerService.java +++ b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/EdgeSpeakerService.java @@ -30,7 +30,7 @@ public interface EdgeSpeakerService { * @param audioPath 音频文件的路径 * @throws RuntimeException 当gRPC调用失败时抛出异常 */ - void playAudio(String terminalId, String deviceId, String audioPath); + String playAudio(String terminalId, String deviceId, String audioPath); /** * 停止当前播放 diff --git a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeCameraServiceImpl.java b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeCameraServiceImpl.java index 6cabbf4..b6186fb 100644 --- a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeCameraServiceImpl.java +++ b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeCameraServiceImpl.java @@ -10,6 +10,7 @@ import com.cmvr.common.enums.FileType; import com.cmvr.common.exception.GlobalException; import com.cmvr.edge.client.file.ByteArrayMultipartFile; import com.cmvr.edge.client.manage.GrpcServiceManager; +import com.cmvr.edge.client.model.EdgeCommonVO; import com.cmvr.edge.client.service.EdgeCameraService; import com.cmvr.edge.client.service.EdgeStreamService; import com.cmvr.edge.client.utils.EdgeCommonUtil; @@ -61,17 +62,17 @@ public class EdgeCameraServiceImpl implements EdgeCameraService, EdgeStreamServi private final MessagePushService messagePushService; @Override - public CameraCommand.CameraState status(String terminalId, String deviceId) { - CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, CameraServiceGrpc.CameraServiceBlockingStub.class); + public CameraCommand.CameraState status(EdgeCommonVO edgeCommonVO) { + CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), CameraServiceGrpc.CameraServiceBlockingStub.class); CameraCommand.GetCameraStateCommand.Request request = CameraCommand.GetCameraStateCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); return executeGrpcCall(() -> stub.getStatus(request)).getState(); } @Override - public boolean checkStatus(String terminalId, String deviceId) { - CameraCommand.CameraState state = status(terminalId, deviceId); + public boolean checkStatus(EdgeCommonVO edgeCommonVO) { + CameraCommand.CameraState state = status(edgeCommonVO); if (state.getIsError()) { throw new GlobalException("Camera is in error state"); } @@ -79,34 +80,34 @@ public class EdgeCameraServiceImpl implements EdgeCameraService, EdgeStreamServi } @Override - public String start(String terminalId, String deviceId) { - CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, CameraServiceGrpc.CameraServiceBlockingStub.class); + public String start(EdgeCommonVO edgeCommonVO) { + CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), CameraServiceGrpc.CameraServiceBlockingStub.class); CameraCommand.StartCameraCommand.Request request = CameraCommand.StartCameraCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); Common.CommandHeader.Feedback header = executeGrpcCall(() -> stub.startCamera(request)).getHeader(); return JSON.toJSONString(header); } @Override - public String stop(String terminalId, String deviceId) { - CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, CameraServiceGrpc.CameraServiceBlockingStub.class); + public String stop(EdgeCommonVO edgeCommonVO) { + CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), CameraServiceGrpc.CameraServiceBlockingStub.class); CameraCommand.StopCameraCommand.Request request = CameraCommand.StopCameraCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); Common.CommandHeader.Feedback header = executeGrpcCall(() -> stub.stopCamera(request)).getHeader(); return JSON.toJSONString(header); } @Override - public String getRGBImage(String terminalId, String deviceId) { + public String getRGBImage(EdgeCommonVO edgeCommonVO) { - if (!checkStatus(terminalId, deviceId)) { - start(terminalId, deviceId); + if (!checkStatus(edgeCommonVO)) { + start(edgeCommonVO); } - CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, CameraServiceGrpc.CameraServiceBlockingStub.class); + CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), CameraServiceGrpc.CameraServiceBlockingStub.class); CameraCommand.GetRGBImageCommand.Request request = CameraCommand.GetRGBImageCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); CameraCommand.GetRGBImageCommand.Feedback feedback = executeGrpcCall(() -> stub.getRGBImage(request)); CameraCommand.FrameData frame = feedback.getColorFrame(); @@ -127,15 +128,15 @@ public class EdgeCameraServiceImpl implements EdgeCameraService, EdgeStreamServi } @Override - public String startRecording(String terminalId, String deviceId) { - if (!checkStatus(terminalId, deviceId)) { - start(terminalId, deviceId); + public String startRecording(EdgeCommonVO edgeCommonVO) { + if (!checkStatus(edgeCommonVO)) { + start(edgeCommonVO); } - CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, CameraServiceGrpc.CameraServiceBlockingStub.class); - String videoPath = StrUtil.format("{}/{}_{}.mp4", "/home/share/assets/video", deviceId, System.currentTimeMillis()); + CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), CameraServiceGrpc.CameraServiceBlockingStub.class); + String videoPath = StrUtil.format("{}/{}_{}.mp4", "/home/share/assets/video", edgeCommonVO.getDeviceId(), System.currentTimeMillis()); CameraCommand.StartCameraRecordingCommand.Request request = CameraCommand.StartCameraRecordingCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .setVideoPath(videoPath) .build(); executeGrpcCall(() -> stub.startRecording(request)); @@ -143,24 +144,24 @@ public class EdgeCameraServiceImpl implements EdgeCameraService, EdgeStreamServi } @Override - public String stopRecording(String terminalId, String deviceId) { - CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, CameraServiceGrpc.CameraServiceBlockingStub.class); + public String stopRecording(EdgeCommonVO edgeCommonVO) { + CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), CameraServiceGrpc.CameraServiceBlockingStub.class); CameraCommand.StopCameraRecordingCommand.Request request = CameraCommand.StopCameraRecordingCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); Common.CommandHeader.Feedback header = executeGrpcCall(() -> stub.stopRecording(request)).getHeader(); return JSON.toJSONString(header); } @Override - public String getRGBDImages(String terminalId, String deviceId) { - if (!checkStatus(terminalId, deviceId)) { - start(terminalId, deviceId); + public String getRGBDImages(EdgeCommonVO edgeCommonVO) { + if (!checkStatus(edgeCommonVO)) { + start(edgeCommonVO); } - CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, CameraServiceGrpc.CameraServiceBlockingStub.class); + CameraServiceGrpc.CameraServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), CameraServiceGrpc.CameraServiceBlockingStub.class); CameraCommand.GetRGBDImagesCommand.Request request = CameraCommand.GetRGBDImagesCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); CameraCommand.GetRGBDImagesCommand.Feedback feedback = executeGrpcCall(() -> stub.getRGBDImages(request)); @@ -197,10 +198,12 @@ public class EdgeCameraServiceImpl implements EdgeCameraService, EdgeStreamServi private boolean isCollectingFrames = false; @Override - public StreamObserver getRGBImageStream(String terminalId, String deviceId) { - if (!checkStatus(terminalId, deviceId)) { - start(terminalId, deviceId); + public StreamObserver getRGBImageStream(EdgeCommonVO edgeCommonVO) { + if (!checkStatus(edgeCommonVO)) { + start(edgeCommonVO); } + String terminalId = edgeCommonVO.getTerminalId(); + String deviceId = edgeCommonVO.getDeviceId(); CameraServiceGrpc.CameraServiceStub stub = grpcServiceManager.getGrpcClient(terminalId, CameraServiceGrpc.CameraServiceStub.class); // 创建StreamObserver来处理响应 StreamObserver responseObserver = new StreamObserver() { @@ -262,12 +265,12 @@ public class EdgeCameraServiceImpl implements EdgeCameraService, EdgeStreamServi } @Override - public void getDepthImageStream(String terminalId, String deviceId) { + public void getDepthImageStream(EdgeCommonVO edgeCommonVO) { } @Override - public void getRGBDImagesStream(String terminalId, String deviceId) { + public void getRGBDImagesStream(EdgeCommonVO edgeCommonVO) { } diff --git a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeMicrophoneServiceImpl.java b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeMicrophoneServiceImpl.java index 1619481..dee167a 100644 --- a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeMicrophoneServiceImpl.java +++ b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeMicrophoneServiceImpl.java @@ -1,17 +1,18 @@ package com.cmvr.edge.client.service.impl; -import cmvr.api.Common; -import cmvr.api.MicrophoneCommand; import cmvr.api.MicPhoneServiceGrpc; +import cmvr.api.MicrophoneCommand; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSON; import com.cmvr.edge.client.manage.GrpcServiceManager; +import com.cmvr.edge.client.model.EdgeCommonVO; +import com.cmvr.edge.client.model.microphone.EdgeMicrophoneVolumeVO; import com.cmvr.edge.client.service.EdgeMicrophoneService; import com.cmvr.edge.client.utils.EdgeCommonUtil; -import io.grpc.ManagedChannel; import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import com.google.protobuf.Timestamp; /** * 边缘麦克风服务实现类 @@ -36,21 +37,17 @@ public class EdgeMicrophoneServiceImpl implements EdgeMicrophoneService { /** * 获取麦克风当前状态 * 通过gRPC调用获取麦克风的运行状态,包括是否正在录音、音量等信息 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @return MicState 返回麦克风的当前状态 - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ @Override - public MicrophoneCommand.GetMicStateCommand.Feedback getStatus(String terminalId, String deviceId) { + public String getStatus(EdgeCommonVO edgeCommonVO) { try { - MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); + MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); MicrophoneCommand.GetMicStateCommand.Request request = MicrophoneCommand.GetMicStateCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); // 直接返回完整的 Feedback - return stub.getStatus(request); + MicrophoneCommand.GetMicStateCommand.Feedback feedback = stub.getStatus(request); + return JSON.toJSONString(feedback.getState()); } catch (Exception e) { logger.error("获取麦克风状态失败", e); throw new RuntimeException("获取麦克风状态失败", e); @@ -60,17 +57,14 @@ public class EdgeMicrophoneServiceImpl implements EdgeMicrophoneService { /** * 开始录音 * 通过gRPC调用开始录音,将录音保存到指定路径 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @param filePath 录音文件的保存路径 - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ @Override - public void startRecord(String terminalId, String deviceId, String filePath) { + public String startRecord(EdgeCommonVO edgeCommonVO) { + String deviceId = edgeCommonVO.getDeviceId(); try { // 获取gRPC客户端存根 - MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); + MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); + String filePath = StrUtil.format("{}/{}_{}.mp4", "/home/share/assets/video", deviceId, System.currentTimeMillis()); // 构建请求消息 MicrophoneCommand.StartMicRecordingCommand.Request request = MicrophoneCommand.StartMicRecordingCommand.Request.newBuilder() @@ -80,6 +74,7 @@ public class EdgeMicrophoneServiceImpl implements EdgeMicrophoneService { // 发送请求 stub.startRecord(request); + return filePath; } catch (Exception e) { logger.error("开始录音失败", e); throw new RuntimeException("开始录音失败", e); @@ -89,24 +84,21 @@ public class EdgeMicrophoneServiceImpl implements EdgeMicrophoneService { /** * 停止录音 * 通过gRPC调用停止麦克风的当前录音 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ @Override - public void stopRecord(String terminalId, String deviceId) { + public String stopRecord(EdgeCommonVO edgeCommonVO) { try { // 获取gRPC客户端存根 - MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); + MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); // 构建请求消息 MicrophoneCommand.StopMicRecordingCommand.Request request = MicrophoneCommand.StopMicRecordingCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); // 发送请求 - stub.stopRecord(request); + MicrophoneCommand.StopMicRecordingCommand.Feedback feedback = stub.stopRecord(request); + return JSON.toJSONString(feedback.getHeader()); } catch (Exception e) { logger.error("停止录音失败", e); throw new RuntimeException("停止录音失败", e); @@ -116,20 +108,16 @@ public class EdgeMicrophoneServiceImpl implements EdgeMicrophoneService { /** * 暂停录音 * 通过gRPC调用暂停麦克风的当前录音 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ @Override - public void pauseRecord(String terminalId, String deviceId) { + public void pauseRecord(EdgeCommonVO edgeCommonVO) { try { // 获取gRPC客户端存根 - MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); + MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); // 构建请求消息 MicrophoneCommand.PauseMicRecordingCommand.Request request = MicrophoneCommand.PauseMicRecordingCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); // 发送请求 @@ -143,20 +131,16 @@ public class EdgeMicrophoneServiceImpl implements EdgeMicrophoneService { /** * 恢复录音 * 通过gRPC调用恢复麦克风之前暂停的录音 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ @Override - public void resumeRecord(String terminalId, String deviceId) { + public void resumeRecord(EdgeCommonVO edgeCommonVO) { try { // 获取gRPC客户端存根 - MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); + MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); // 构建请求消息 MicrophoneCommand.ResumeMicRecordingCommand.Request request = MicrophoneCommand.ResumeMicRecordingCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); // 发送请求 @@ -170,22 +154,17 @@ public class EdgeMicrophoneServiceImpl implements EdgeMicrophoneService { /** * 设置麦克风音量 * 通过gRPC调用设置麦克风的音量大小 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @param volume 音量大小(0-100) - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ @Override - public void setVolume(String terminalId, String deviceId, int volume) { + public void setVolume(EdgeMicrophoneVolumeVO edgeMicrophoneVolumeVO) { try { // 获取gRPC客户端存根 - MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); + MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeMicrophoneVolumeVO.getTerminalId(), MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); // 构建请求消息 MicrophoneCommand.SetMicPhoneVolumeCommand.Request request = MicrophoneCommand.SetMicPhoneVolumeCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) - .setVolume(volume) + .setHeader(EdgeCommonUtil.buildRequest(edgeMicrophoneVolumeVO.getDeviceId())) + .setVolume(edgeMicrophoneVolumeVO.getVolume()) .build(); // 发送请求 @@ -199,21 +178,16 @@ public class EdgeMicrophoneServiceImpl implements EdgeMicrophoneService { /** * 获取当前音量 * 通过gRPC调用获取麦克风的当前音量大小 - * - * @param terminalId 终端设备ID - * @param deviceId 设备ID - * @return int 返回当前音量大小(0-100) - * @throws RuntimeException 当gRPC调用失败时抛出异常 */ @Override - public int getVolume(String terminalId, String deviceId) { + public int getVolume(EdgeCommonVO edgeCommonVO) { try { // 获取gRPC客户端存根 - MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); + MicPhoneServiceGrpc.MicPhoneServiceBlockingStub stub = grpcServiceManager.getGrpcClient(edgeCommonVO.getTerminalId(), MicPhoneServiceGrpc.MicPhoneServiceBlockingStub.class); // 构建请求消息 MicrophoneCommand.GetMicPhoneVolumeCommand.Request request = MicrophoneCommand.GetMicPhoneVolumeCommand.Request.newBuilder() - .setHeader(EdgeCommonUtil.buildRequest(deviceId)) + .setHeader(EdgeCommonUtil.buildRequest(edgeCommonVO.getDeviceId())) .build(); // 发送请求并获取响应 diff --git a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeSpeakerServiceImpl.java b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeSpeakerServiceImpl.java index c1264c3..958a323 100644 --- a/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeSpeakerServiceImpl.java +++ b/cmvr-iot-api/cmvr-iot-edge/cmvr-iot-grpc-client/src/main/java/com/cmvr/edge/client/service/impl/EdgeSpeakerServiceImpl.java @@ -70,7 +70,7 @@ public class EdgeSpeakerServiceImpl implements EdgeSpeakerService { * @throws RuntimeException 当gRPC调用失败时抛出异常 */ @Override - public void playAudio(String terminalId, String deviceId, String audioPath) { + public String playAudio(String terminalId, String deviceId, String audioPath) { try { // 获取gRPC客户端存根 SpeakerServiceGrpc.SpeakerServiceBlockingStub stub = grpcServiceManager.getGrpcClient(terminalId, SpeakerServiceGrpc.SpeakerServiceBlockingStub.class); @@ -86,6 +86,7 @@ public class EdgeSpeakerServiceImpl implements EdgeSpeakerService { if (!feedback.getHeader().getSuccess()) { throw new RuntimeException((feedback.getHeader().getErrorMessage())); } + return JSON.toJSONString(feedback.getHeader()); } catch (Exception e) { logger.error("播放音频失败", e); throw new RuntimeException("播放音频失败", e); diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/enums/ActionEnum.java b/cmvr-iot-test/src/main/java/com/cmvr/test/enums/ActionEnum.java index 2f4539b..c271595 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/enums/ActionEnum.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/enums/ActionEnum.java @@ -40,8 +40,13 @@ public enum ActionEnum { MICROPHONE_STOP("EDGE", "MICROPHONE_STOP", "停止麦克风"), // ---------------扬声器(人工嘴)--------------- - SPEAKER_PLAYAUDIO("EDGE", "SPEAKER_PLAYAUDIO", "播放音频"), - CORPUS_PLAY("EDGE", "CORPUS_PLAY", "播放语料"), + // ---------------语料--------------- + VI_CORPUS_WAKE("EDGE", "VI_CORPUS_WAKE", "唤醒语料处理"), + VI_CORPUS_SINGLE("EDGE", "VI_CORPUS_SINGLE", "测试语料-单次对话语料处理"), + VI_CORPUS_CONTINUOUS("EDGE", "VI_CORPUS_CONTINUOUS", "测试语料-连续对话语料处理"), + VI_PLAY_CORPUS("EDGE", "VI_PLAY_CORPUS", "播放语料"), + // ---------------方案--------------- + VI_SCHEME("EDGE", "VI_SCHEME", "语音交互-方案处理"), // ---------------机械臂--------------- TOUCH("EDGE", "TOUCH", "触控"), @@ -57,15 +62,6 @@ public enum ActionEnum { INTENT_RECOGNITION("LLM", "INTENT_RECOGNITION", "意图识别"), GENERATE_ADVANCED_AUDIO("LLM", "GENERATE_ADVANCED_AUDIO", "tts语音合成"), - // 语音交互 - // ---------------语料--------------- - VI_CORPUS_WAKE("VI", "VI_CORPUS_WAKE", "唤醒语料处理"), - VI_CORPUS_SINGLE("VI", "VI_CORPUS_SINGLE", "测试语料-单次对话语料处理"), - VI_CORPUS_CONTINUOUS("VI", "VI_CORPUS_CONTINUOUS", "测试语料-连续对话语料处理"), - VI_PLAY_CORPUS("VI", "VI_PLAY_CORPUS", "播放语料"), - // ---------------方案--------------- - VI_SCHEME("VI", "VI_SCHEME", "语音交互-方案处理"), - ; diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeCameraOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeCameraOperateService.java index 2b9d8a9..9e4ccdd 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeCameraOperateService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeCameraOperateService.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson2.JSONObject; import com.cmvr.common.enums.FileType; import com.cmvr.common.exception.GlobalException; +import com.cmvr.edge.client.model.EdgeCommonVO; import com.cmvr.edge.client.service.EdgeCameraService; import com.cmvr.test.enums.ActionEnum; import com.cmvr.test.flow.context.TaskInstHolder; @@ -41,6 +42,10 @@ public class EdgeCameraOperateService implements EdgeOperateService { JSONObject output = new JSONObject(); + EdgeCommonVO edgeCommonVO = new EdgeCommonVO(); + edgeCommonVO.setDeviceId(deviceId); + edgeCommonVO.setTerminalId(terminalId); + switch (action) { case CAMERA_START: { // String result = edgeCameraService.start(terminalId, deviceId); @@ -84,7 +89,7 @@ public class EdgeCameraOperateService implements EdgeOperateService { } case CAMERA_RECORDING_START: { - String videoUrl = edgeCameraService.startRecording(terminalId, deviceId); + String videoUrl = edgeCameraService.startRecording(edgeCommonVO); videoUrl = StrUtil.format("{}/{}", "http://10.148.108.162/system/video", StrUtil.subAfter(videoUrl, "/", true)); // String videoUrl = "http://10.148.108.162/system/video/cam4_1752225205349.mp4"; // JSONArray videoUrls = new JSONArray(); @@ -104,7 +109,7 @@ public class EdgeCameraOperateService implements EdgeOperateService { } case CAMERA_RECORDING_STOP: { - edgeCameraService.stopRecording(terminalId, deviceId); + edgeCameraService.stopRecording(edgeCommonVO); // todo 结束录像获取视频路径输出 // // 获取视频录制开始节点的id // FlowNodeWrapper startRecordNode = message.getGraph() diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeMicrophoneOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeMicrophoneOperateService.java index 5dffd28..644e6a9 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeMicrophoneOperateService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeMicrophoneOperateService.java @@ -1,11 +1,10 @@ package com.cmvr.test.flow.runtime.operator.edge; -import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson2.JSONObject; import com.cmvr.common.exception.GlobalException; +import com.cmvr.edge.client.model.EdgeCommonVO; import com.cmvr.edge.client.service.EdgeMicrophoneService; import com.cmvr.test.enums.ActionEnum; -import com.cmvr.test.flow.context.TaskInstHolder; import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage; import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult; import lombok.RequiredArgsConstructor; @@ -32,18 +31,18 @@ public class EdgeMicrophoneOperateService implements EdgeOperateService { String terminalId = message.getTerminalId(); JSONObject output = new JSONObject(); - + EdgeCommonVO edgeCommonVO = new EdgeCommonVO(); + edgeCommonVO.setDeviceId(deviceId); + edgeCommonVO.setTerminalId(terminalId); switch (action) { case MICROPHONE_START: { - String audioPath = - StrUtil.format("{}/{}_{}", "/home/share/assets/audio", deviceId, System.currentTimeMillis()); - edgeMicrophoneService.startRecord(terminalId, deviceId, audioPath); + String audioPath = edgeMicrophoneService.startRecord(edgeCommonVO); output.put("audioUrl", audioPath); break; } case MICROPHONE_STOP: { - edgeMicrophoneService.stopRecord(terminalId, deviceId); + edgeMicrophoneService.stopRecord(edgeCommonVO); break; } diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeSpeakerOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeSpeakerOperateService.java index e75ccfc..3d648d7 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeSpeakerOperateService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/EdgeSpeakerOperateService.java @@ -24,14 +24,14 @@ public class EdgeSpeakerOperateService implements EdgeOperateService { @Override public TaskNodeExecuteResult execute(TaskNodeExecuteMessage message) { - ActionEnum action = message.getAction(); - JSONObject inputParams = message.getInputParams(); - String deviceId = inputParams.getString("deviceId"); - String terminalId = message.getTerminalId(); - switch (action) { - case SPEAKER_PLAYAUDIO: { - log.info("speaker play audio"); - // todo 音频暂时随机播放 +// ActionEnum action = message.getAction(); +// JSONObject inputParams = message.getInputParams(); +// String deviceId = inputParams.getString("deviceId"); +// String terminalId = message.getTerminalId(); +// switch (action) { +// case SPEAKER_PLAYAUDIO: { +// log.info("speaker play audio"); +// // todo 音频暂时随机播放 // List all = edgeSpeakerService.getAll(); // for (int i = 0; i < 3; i++) { @@ -57,12 +57,13 @@ public class EdgeSpeakerOperateService implements EdgeOperateService { // throw new RuntimeException(e); // } // } - break; - } - - default: - throw new GlobalException("不支持的扬声器操作类型: " + action); - } - return TaskNodeExecuteResult.success(); +// break; +// } +// +// default: +// throw new GlobalException("不支持的扬声器操作类型: " + action); +// } +// return TaskNodeExecuteResult.success(); + return null; } } diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViCorpusOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViCorpusOperateService.java similarity index 92% rename from cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViCorpusOperateService.java rename to cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViCorpusOperateService.java index 3ba345b..c5cb851 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViCorpusOperateService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViCorpusOperateService.java @@ -1,4 +1,4 @@ -package com.cmvr.test.flow.runtime.operator.vi; +package com.cmvr.test.flow.runtime.operator.edge.vi; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; @@ -6,6 +6,7 @@ import com.cmvr.common.exception.GlobalException; import com.cmvr.test.enums.ActionEnum; import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage; import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult; +import com.cmvr.test.flow.runtime.operator.edge.EdgeOperateService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -15,7 +16,7 @@ import java.util.List; @Slf4j @Service @RequiredArgsConstructor -public class ViCorpusOperateService implements VIOperateService { +public class ViCorpusOperateService implements EdgeOperateService { @Override public boolean supports(ActionEnum action) { diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViPlayOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViPlayOperateService.java similarity index 95% rename from cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViPlayOperateService.java rename to cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViPlayOperateService.java index ffd262d..50ce611 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViPlayOperateService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViPlayOperateService.java @@ -1,4 +1,4 @@ -package com.cmvr.test.flow.runtime.operator.vi; +package com.cmvr.test.flow.runtime.operator.edge.vi; import cmvr.api.SpeakerCommand; import com.alibaba.fastjson2.JSONObject; @@ -9,6 +9,7 @@ import com.cmvr.edge.client.service.EdgeSpeakerService; import com.cmvr.test.enums.ActionEnum; import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage; import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult; +import com.cmvr.test.flow.runtime.operator.edge.EdgeOperateService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -23,7 +24,7 @@ import java.io.File; @Slf4j @Service @RequiredArgsConstructor -public class ViPlayOperateService implements VIOperateService { +public class ViPlayOperateService implements EdgeOperateService { private final EdgeSpeakerService edgeSpeakerService; private final EdgeBioHeadService edgeBioHeadService; diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViSchemeOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViSchemeOperateService.java similarity index 95% rename from cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViSchemeOperateService.java rename to cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViSchemeOperateService.java index d321a09..1f3bc29 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViSchemeOperateService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViSchemeOperateService.java @@ -1,4 +1,4 @@ -package com.cmvr.test.flow.runtime.operator.vi; +package com.cmvr.test.flow.runtime.operator.edge.vi; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; @@ -9,6 +9,7 @@ import com.cmvr.common.exception.GlobalException; import com.cmvr.test.enums.ActionEnum; import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage; import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult; +import com.cmvr.test.flow.runtime.operator.edge.EdgeOperateService; import com.cmvr.test.service.ex.ExViCorpusService; import com.cmvr.test.service.ex.ExViSchemeService; import lombok.RequiredArgsConstructor; @@ -24,7 +25,7 @@ import java.util.stream.Collectors; @Slf4j @Service @RequiredArgsConstructor -public class ViSchemeOperateService implements VIOperateService { +public class ViSchemeOperateService implements EdgeOperateService { private final ExViSchemeService exViSchemeService; private final ExViCorpusService exViCorpusService; diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/VIOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/VIOperateService.java deleted file mode 100644 index eef9c6d..0000000 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/VIOperateService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.cmvr.test.flow.runtime.operator.vi; - -import com.cmvr.test.enums.ActionEnum; -import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage; -import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult; - -public interface VIOperateService { - - boolean supports(ActionEnum action); - - TaskNodeExecuteResult execute(TaskNodeExecuteMessage message); -} diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViNodeOperateHandler.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViNodeOperateHandler.java deleted file mode 100644 index 36c8681..0000000 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/vi/ViNodeOperateHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.cmvr.test.flow.runtime.operator.vi; - -import com.cmvr.common.exception.GlobalException; -import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage; -import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult; -import com.cmvr.test.flow.runtime.operator.AbstractNodeOperateHandler; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Slf4j -@Component("VI") -@RequiredArgsConstructor -public class ViNodeOperateHandler extends AbstractNodeOperateHandler { - - private final List viOperateServices; - - @Override - protected TaskNodeExecuteResult doExecute(TaskNodeExecuteMessage message) { - return viOperateServices.stream() - .filter(s -> s.supports(message.getAction())) - .findFirst() - .map(s -> s.execute(message)) - .orElseThrow(() -> new GlobalException("不支持的语音交互操作: " + message.getAction())); - } -} diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/model/vo/FlowActionRequestVO.java b/cmvr-iot-test/src/main/java/com/cmvr/test/model/vo/FlowActionRequestVO.java new file mode 100644 index 0000000..d9f9147 --- /dev/null +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/model/vo/FlowActionRequestVO.java @@ -0,0 +1,21 @@ +package com.cmvr.test.model.vo; + +import com.alibaba.fastjson2.JSONObject; +import lombok.Data; + +/** + * 工作流节点执行请求 + */ +@Data +public class FlowActionRequestVO { + + /** + * 动作 + */ + private String action; + + /** + * 执行参数 + */ + private JSONObject payload; +} diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowActionExecutorService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowActionExecutorService.java new file mode 100644 index 0000000..997ebd0 --- /dev/null +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowActionExecutorService.java @@ -0,0 +1,123 @@ +package com.cmvr.test.service; + +import cn.hutool.core.util.ObjUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSONObject; +import com.cmvr.common.exception.GlobalException; +import com.cmvr.edge.client.model.EdgeCommonVO; +import com.cmvr.edge.client.model.biohead.EdgeFacialExpressionVO; +import com.cmvr.edge.client.model.humanoid.EdgeMoveJVO; +import com.cmvr.edge.client.service.EdgeBioHeadService; +import com.cmvr.edge.client.service.EdgeCameraService; +import com.cmvr.edge.client.service.EdgeHumanoidRobotService; +import com.cmvr.edge.client.service.EdgeMicrophoneService; +import com.cmvr.edge.client.service.EdgeSpeakerService; +import com.cmvr.test.enums.ActionEnum; +import com.cmvr.test.model.vo.FlowActionRequestVO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class FlowActionExecutorService { + private final EdgeCameraService edgeCameraService; + private final EdgeBioHeadService edgeBioHeadService; + private final EdgeMicrophoneService edgeMicrophoneService; + private final EdgeSpeakerService edgeSpeakerService; + private final EdgeHumanoidRobotService edgeHumanoidRobotService; + + public String actionExecute(FlowActionRequestVO req) { + + ActionEnum action = ActionEnum.fromAction(req.getAction()); + + if (ObjUtil.isEmpty(action)) { + throw new GlobalException("不存在此行为!"); + } + + switch (action.getOperate()) { + case "EDGE": + return executeEdgeAction(action, req); + + case "LLM": + return executeLLMAction(action, req); + + default: + throw new GlobalException("仅设备和大模型 Action 可调用!"); + } + } + + private String executeEdgeAction(ActionEnum action, FlowActionRequestVO req) { + JSONObject payload = req.getPayload(); + String terminalId = payload.getString("terminalId"); + String deviceId = payload.getString("deviceId"); + + if (StrUtil.isEmpty(terminalId) || StrUtil.isEmpty(deviceId)) { + throw new GlobalException("EDGE 类型动作必须提供 terminalId 和 deviceId"); + } + + EdgeCommonVO edgeCommonVO = new EdgeCommonVO(); + edgeCommonVO.setTerminalId(terminalId); + edgeCommonVO.setDeviceId(deviceId); + switch (action) { + // ==== 相机 ==== + case CAMERA_START: + return edgeCameraService.start(edgeCommonVO); + case CAMERA_STOP: + return edgeCameraService.stop(edgeCommonVO); + case CAMERA_GETRGBIMAGE: + return edgeCameraService.getRGBImage(edgeCommonVO); + case CAMERA_RECORDING_START: + return edgeCameraService.startRecording(edgeCommonVO); + case CAMERA_RECORDING_STOP: + return edgeCameraService.stopRecording(edgeCommonVO); + + // ==== 麦克风 ==== + case MICROPHONE_START: + return edgeMicrophoneService.startRecord(edgeCommonVO); + case MICROPHONE_STOP: + return edgeMicrophoneService.stopRecord(edgeCommonVO); + + // ==== 触控 ==== + case TOUCH: + EdgeMoveJVO edgeMoveJVO = payload.to(EdgeMoveJVO.class); + return edgeHumanoidRobotService.moveJ(edgeMoveJVO); + + // ==== 语料 ==== + case VI_PLAY_CORPUS: + String audioPath = payload.getString("audioPath"); + return edgeSpeakerService.playAudio(terminalId, deviceId, audioPath); + + // ==== 头部 ==== + case BIO_HEAD_SPEAK_START: + return edgeBioHeadService.speakStart(edgeCommonVO); + case BIO_HEAD_SPEAK_STOP: + return edgeBioHeadService.speakStop(edgeCommonVO); + case BIO_HEAD_SPECIAL_EXPRESSION: + EdgeFacialExpressionVO edgeFacialExpressionVO = payload.to(EdgeFacialExpressionVO.class); + edgeFacialExpressionVO.setTerminalId(terminalId); + edgeFacialExpressionVO.setDeviceId(deviceId); + return edgeBioHeadService.setExpression(edgeFacialExpressionVO); + + default: + throw new UnsupportedOperationException("未实现的 EDGE Action: " + action.name()); + } + } + + private String executeLLMAction(ActionEnum action, FlowActionRequestVO req) { + log.info("LLM 执行动作: {}", action); + + switch (action) { + case TOUCH_COORDINATES: + return "LLM 触控坐标 OK"; + case INTENT_RECOGNITION: + return "LLM 意图识别 OK"; + case GENERATE_ADVANCED_AUDIO: + return "LLM 高级音频生成 OK"; + default: + throw new UnsupportedOperationException("未实现的 LLM Action: " + action); + } + } +} +