diff --git a/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java index 6f737f4..70ee41c 100644 --- a/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java +++ b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java @@ -63,7 +63,7 @@ public class PumpRotateStartCommand extends BaseCommandHandler { CommandUtil.wait(newPositionCommandFuture); Double newPosition = (Double) newPositionCommandFuture.getResponseResult().getJSONObject("data").get("position"); log.info("currentPosition: {}, newPosition: {}", currentPosition, newPosition); - webSocketSender.pushPumpPosition(newPosition - currentPosition); + webSocketSender.pushPumpPosition((newPosition - currentPosition) / 100); } else { DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelCode); CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); diff --git a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java index 7dfa835..9d7b467 100644 --- a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.iflytop.handacid.app.common.enums.ChannelCode; import com.iflytop.handacid.app.common.enums.SolutionAddMode; import com.iflytop.handacid.app.common.enums.SystemConfigKey; +import com.iflytop.handacid.app.common.utils.CommandUtil; +import com.iflytop.handacid.app.core.command.CommandFuture; import com.iflytop.handacid.app.core.command.DeviceCommand; import com.iflytop.handacid.app.core.command.DeviceCommandGenerator; import com.iflytop.handacid.app.core.state.ChannelState; @@ -27,6 +29,7 @@ import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.context.SmartLifecycle; import org.springframework.stereotype.Service; import java.util.List; @@ -47,16 +50,15 @@ public class DeviceInitService { private final SolutionService solutionService; private final SystemConfigService systemConfigService; - @PostConstruct public void init() { eventBus.regListener(this::onAppEvent); + initDeviceState(); new Thread(() -> { try { log.info("初始化开始"); initDeviceSetData();//初始化设备参数 initEnable();//使能 - initDeviceState(); log.info("初始化完毕"); } catch (Exception e) { throw new RuntimeException(e); @@ -74,18 +76,19 @@ public class DeviceInitService { /** * 初始化所有设备使能 */ - public void initEnable() { + public void initEnable() throws Exception { DeviceCommand pump1Enable = DeviceCommandGenerator.pump1Enable(); - deviceCommandService.sendCommand(pump1Enable); - + CommandFuture pump1EnableFuture = deviceCommandService.sendCommand(pump1Enable); + CommandUtil.wait(pump1EnableFuture); DeviceCommand pump2Enable = DeviceCommandGenerator.pump2Enable(); - deviceCommandService.sendCommand(pump2Enable); - + CommandFuture pump2EnableFuture = deviceCommandService.sendCommand(pump2Enable); + CommandUtil.wait(pump2EnableFuture); DeviceCommand pump3Enable = DeviceCommandGenerator.pump3Enable(); - deviceCommandService.sendCommand(pump3Enable); - + CommandFuture pump3EnableFuture = deviceCommandService.sendCommand(pump3Enable); + CommandUtil.wait(pump3EnableFuture); DeviceCommand pump4Enable = DeviceCommandGenerator.pump4Enable(); - deviceCommandService.sendCommand(pump4Enable); + CommandFuture pump4EnableFuture = deviceCommandService.sendCommand(pump4Enable); + CommandUtil.wait(pump4EnableFuture); } /** @@ -98,7 +101,7 @@ public class DeviceInitService { Channel channel = channelService.getOne(new LambdaQueryWrapper<>(new Channel()).eq(Channel::getCode, code)); ChannelState channelState = channelStateObjectProvider.getObject(code, channel.getConcentration(), channel.getTargetVolume(), channel.getReceivedVolume(), channel.getCurrentVolume()); Solution solution = solutionService.getById(channel.getSolutionId()); - if(solution != null) { + if (solution != null) { channelState.setSolutionId(solution.getId()); channelState.setSolutionName(solution.getName()); } @@ -114,7 +117,7 @@ public class DeviceInitService { * 初始化设备参数 */ public void initDeviceSetData() throws Exception { - if (deviceState.isVirtual() || deviceState.isInitComplete()) { + if (deviceState.isVirtual()) { return; } List deviceParamConfigs = deviceParamConfigService.list(); @@ -128,6 +131,7 @@ public class DeviceInitService { while (!success) { try { canBusService.moduleSetReg(MId.valueOf(data.getMid()), RegIndex.valueOf(data.getRegIndex()), data.getRegInitVal()); + log.info(data.getMid() + data.getRegIndex()); success = true; } catch (Exception e) { log.error("设备初始化写入参数失败,错误: {}", e.getMessage());