package com.iflytop.handacid.app.service; import cn.hutool.json.JSONObject; import com.iflytop.handacid.app.core.command.DeviceCommand; import com.iflytop.handacid.common.enums.Action; import com.iflytop.handacid.common.enums.Device; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; /** * 虚拟设备服务 */ @Service @RequiredArgsConstructor public class VirtualDeviceService { private final DeviceCommandService deviceCommandService; public void completeCommandResponse(DeviceCommand cmdToDevice) { new Thread(() -> { try { JSONObject jsonObject = new JSONObject(); jsonObject.putOnce("cmdId", cmdToDevice.getCmdId()); jsonObject.putOnce("success", true); String code = cmdToDevice.getCmdCode(); Action action = cmdToDevice.getAction(); Device device = cmdToDevice.getDevice(); if (code.contains("controlMotorCmd")) { if (Action.ORIGIN.equals(action)) { Thread.sleep(3000); } else if (!Action.SET.equals(action)) {//非设置电机参数,也就是电机移动 Thread.sleep(500); } } else if (code.contains("getInfoCmd")) { } deviceCommandService.completeCommandResponse(jsonObject); } catch (InterruptedException e) { // 处理中断异常 Thread.currentThread().interrupt(); } }).start(); } }