|
@ -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.ChannelCode; |
|
|
import com.iflytop.handacid.app.common.enums.SolutionAddMode; |
|
|
import com.iflytop.handacid.app.common.enums.SolutionAddMode; |
|
|
import com.iflytop.handacid.app.common.enums.SystemConfigKey; |
|
|
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.DeviceCommand; |
|
|
import com.iflytop.handacid.app.core.command.DeviceCommandGenerator; |
|
|
import com.iflytop.handacid.app.core.command.DeviceCommandGenerator; |
|
|
import com.iflytop.handacid.app.core.state.ChannelState; |
|
|
import com.iflytop.handacid.app.core.state.ChannelState; |
|
@ -27,6 +29,7 @@ import jakarta.annotation.PostConstruct; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.ObjectProvider; |
|
|
import org.springframework.beans.factory.ObjectProvider; |
|
|
|
|
|
import org.springframework.context.SmartLifecycle; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
@ -47,16 +50,15 @@ public class DeviceInitService { |
|
|
private final SolutionService solutionService; |
|
|
private final SolutionService solutionService; |
|
|
private final SystemConfigService systemConfigService; |
|
|
private final SystemConfigService systemConfigService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
@PostConstruct |
|
|
public void init() { |
|
|
public void init() { |
|
|
eventBus.regListener(this::onAppEvent); |
|
|
eventBus.regListener(this::onAppEvent); |
|
|
|
|
|
initDeviceState(); |
|
|
new Thread(() -> { |
|
|
new Thread(() -> { |
|
|
try { |
|
|
try { |
|
|
log.info("初始化开始"); |
|
|
log.info("初始化开始"); |
|
|
initDeviceSetData();//初始化设备参数 |
|
|
initDeviceSetData();//初始化设备参数 |
|
|
initEnable();//使能 |
|
|
initEnable();//使能 |
|
|
initDeviceState(); |
|
|
|
|
|
log.info("初始化完毕"); |
|
|
log.info("初始化完毕"); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
throw new RuntimeException(e); |
|
|
throw new RuntimeException(e); |
|
@ -74,18 +76,19 @@ public class DeviceInitService { |
|
|
/** |
|
|
/** |
|
|
* 初始化所有设备使能 |
|
|
* 初始化所有设备使能 |
|
|
*/ |
|
|
*/ |
|
|
public void initEnable() { |
|
|
|
|
|
|
|
|
public void initEnable() throws Exception { |
|
|
DeviceCommand pump1Enable = DeviceCommandGenerator.pump1Enable(); |
|
|
DeviceCommand pump1Enable = DeviceCommandGenerator.pump1Enable(); |
|
|
deviceCommandService.sendCommand(pump1Enable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandFuture pump1EnableFuture = deviceCommandService.sendCommand(pump1Enable); |
|
|
|
|
|
CommandUtil.wait(pump1EnableFuture); |
|
|
DeviceCommand pump2Enable = DeviceCommandGenerator.pump2Enable(); |
|
|
DeviceCommand pump2Enable = DeviceCommandGenerator.pump2Enable(); |
|
|
deviceCommandService.sendCommand(pump2Enable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandFuture pump2EnableFuture = deviceCommandService.sendCommand(pump2Enable); |
|
|
|
|
|
CommandUtil.wait(pump2EnableFuture); |
|
|
DeviceCommand pump3Enable = DeviceCommandGenerator.pump3Enable(); |
|
|
DeviceCommand pump3Enable = DeviceCommandGenerator.pump3Enable(); |
|
|
deviceCommandService.sendCommand(pump3Enable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandFuture pump3EnableFuture = deviceCommandService.sendCommand(pump3Enable); |
|
|
|
|
|
CommandUtil.wait(pump3EnableFuture); |
|
|
DeviceCommand pump4Enable = DeviceCommandGenerator.pump4Enable(); |
|
|
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)); |
|
|
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()); |
|
|
ChannelState channelState = channelStateObjectProvider.getObject(code, channel.getConcentration(), channel.getTargetVolume(), channel.getReceivedVolume(), channel.getCurrentVolume()); |
|
|
Solution solution = solutionService.getById(channel.getSolutionId()); |
|
|
Solution solution = solutionService.getById(channel.getSolutionId()); |
|
|
if(solution != null) { |
|
|
|
|
|
|
|
|
if (solution != null) { |
|
|
channelState.setSolutionId(solution.getId()); |
|
|
channelState.setSolutionId(solution.getId()); |
|
|
channelState.setSolutionName(solution.getName()); |
|
|
channelState.setSolutionName(solution.getName()); |
|
|
} |
|
|
} |
|
@ -114,7 +117,7 @@ public class DeviceInitService { |
|
|
* 初始化设备参数 |
|
|
* 初始化设备参数 |
|
|
*/ |
|
|
*/ |
|
|
public void initDeviceSetData() throws Exception { |
|
|
public void initDeviceSetData() throws Exception { |
|
|
if (deviceState.isVirtual() || deviceState.isInitComplete()) { |
|
|
|
|
|
|
|
|
if (deviceState.isVirtual()) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
List<DeviceParamConfig> deviceParamConfigs = deviceParamConfigService.list(); |
|
|
List<DeviceParamConfig> deviceParamConfigs = deviceParamConfigService.list(); |
|
@ -128,6 +131,7 @@ public class DeviceInitService { |
|
|
while (!success) { |
|
|
while (!success) { |
|
|
try { |
|
|
try { |
|
|
canBusService.moduleSetReg(MId.valueOf(data.getMid()), RegIndex.valueOf(data.getRegIndex()), data.getRegInitVal()); |
|
|
canBusService.moduleSetReg(MId.valueOf(data.getMid()), RegIndex.valueOf(data.getRegIndex()), data.getRegInitVal()); |
|
|
|
|
|
log.info(data.getMid() + data.getRegIndex()); |
|
|
success = true; |
|
|
success = true; |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("设备初始化写入参数失败,错误: {}", e.getMessage()); |
|
|
log.error("设备初始化写入参数失败,错误: {}", e.getMessage()); |
|
|