加酸仪(java版本)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB

2 weeks ago
  1. package com.iflytop.handacid.app.service;
  2. import cn.hutool.json.JSONObject;
  3. import com.iflytop.handacid.app.core.command.DeviceCommand;
  4. import com.iflytop.handacid.common.enums.Action;
  5. import com.iflytop.handacid.common.enums.Device;
  6. import lombok.RequiredArgsConstructor;
  7. import org.springframework.stereotype.Service;
  8. /**
  9. * 虚拟设备服务
  10. */
  11. @Service
  12. @RequiredArgsConstructor
  13. public class VirtualDeviceService {
  14. private final DeviceCommandService deviceCommandService;
  15. public void completeCommandResponse(DeviceCommand cmdToDevice) {
  16. new Thread(() -> {
  17. try {
  18. JSONObject jsonObject = new JSONObject();
  19. jsonObject.putOnce("cmdId", cmdToDevice.getCmdId());
  20. jsonObject.putOnce("success", true);
  21. String code = cmdToDevice.getCmdCode();
  22. Action action = cmdToDevice.getAction();
  23. Device device = cmdToDevice.getDevice();
  24. if (code.contains("controlMotorCmd")) {
  25. if (Action.ORIGIN.equals(action)) {
  26. Thread.sleep(3000);
  27. } else if (!Action.SET.equals(action)) {//非设置电机参数,也就是电机移动
  28. Thread.sleep(500);
  29. }
  30. } else if (code.contains("getInfoCmd")) {
  31. }
  32. deviceCommandService.completeCommandResponse(jsonObject);
  33. } catch (InterruptedException e) {
  34. // 处理中断异常
  35. Thread.currentThread().interrupt();
  36. }
  37. }).start();
  38. }
  39. }