feat: 边缘系统参数封装;新增单个节点调用接口
This commit is contained in:
parent
8f5097bffb
commit
6c25b37827
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<String, Object> result = new HashMap<>();
|
||||
Map<String, Object> header = new HashMap<>();
|
||||
header.put("deviceId", deviceId);
|
||||
header.put("timestamp", feedback.getHeader().getTimestamp().getSeconds());
|
||||
result.put("header", header);
|
||||
|
||||
Map<String, Object> 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));
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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<CameraCommand.GetRGBImageStreamCommand.Request> getRGBImageStream(String terminalId, String deviceId);
|
||||
StreamObserver<CameraCommand.GetRGBImageStreamCommand.Request> getRGBImageStream(EdgeCommonVO edgeCommonVO);
|
||||
|
||||
void getDepthImageStream(String terminalId, String deviceId);
|
||||
void getRGBDImagesStream(String terminalId, String deviceId);
|
||||
void getDepthImageStream(EdgeCommonVO edgeCommonVO);
|
||||
void getRGBDImagesStream(EdgeCommonVO edgeCommonVO);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
|
||||
/**
|
||||
* 停止当前播放
|
||||
|
||||
@ -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<CameraCommand.GetRGBImageStreamCommand.Request> getRGBImageStream(String terminalId, String deviceId) {
|
||||
if (!checkStatus(terminalId, deviceId)) {
|
||||
start(terminalId, deviceId);
|
||||
public StreamObserver<CameraCommand.GetRGBImageStreamCommand.Request> 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<CameraCommand.GetRGBImageStreamCommand.Feedback> responseObserver = new StreamObserver<CameraCommand.GetRGBImageStreamCommand.Feedback>() {
|
||||
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
|
||||
// 发送请求并获取响应
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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", "语音交互-方案处理"),
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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<String> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
@ -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;
|
||||
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
@ -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<VIOperateService> 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()));
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user