Browse Source

fix:初始化使能失败修改

master
王梦远 2 months ago
parent
commit
1b4ac20d3e
  1. 4
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeepCloseCommand.java
  2. 4
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeepOpenCommand.java
  3. 73
      src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java
  4. 11
      src/main/java/com/iflytop/sgs/common/service/CanBusService.java
  5. 22
      src/main/java/com/iflytop/sgs/hardware/comm/can/A8kCanBusService.java
  6. 2
      src/main/java/com/iflytop/sgs/hardware/command/handlers/LeiSaiServoHandler.java
  7. 3
      src/main/java/com/iflytop/sgs/hardware/command/handlers/MotorHandler.java
  8. 2
      src/main/resources/application-dev.yml

4
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeeCloseCommand.java → src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeepCloseCommand.java

@ -20,8 +20,8 @@ import java.util.concurrent.CompletableFuture;
@Slf4j
@Component
@RequiredArgsConstructor
@CommandDebugMapping("bee_close")
public class DebugBeeCloseCommand extends BaseCommandHandler {
@CommandDebugMapping("beep_close")
public class DebugBeepCloseCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override

4
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeeOpenCommand.java → src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeepOpenCommand.java

@ -23,8 +23,8 @@ import java.util.concurrent.CompletableFuture;
@Slf4j
@Component
@RequiredArgsConstructor
@CommandDebugMapping("bee_open")
public class DebugBeeOpenCommand extends BaseCommandHandler {
@CommandDebugMapping("beep_open")
public class DebugBeepOpenCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override

73
src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java

@ -1,8 +1,20 @@
package com.iflytop.sgs.app.service.device;
import com.iflytop.sgs.app.model.bo.DeviceInitializationData;
import com.iflytop.sgs.app.model.bo.status.device.DeviceState;
import com.iflytop.sgs.app.model.bo.status.device.HeatModuleState;
import com.iflytop.sgs.app.model.bo.status.device.SolutionContainerState;
import com.iflytop.sgs.app.model.entity.Container;
import com.iflytop.sgs.app.model.entity.DeviceParamConfig;
import com.iflytop.sgs.app.service.api.ContainerService;
import com.iflytop.sgs.app.service.api.DeviceParamConfigService;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.enums.ContainerCode;
import com.iflytop.sgs.common.enums.ContainerType;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import com.iflytop.sgs.common.enums.cmd.CmdColor;
import com.iflytop.sgs.common.service.CanBusService;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -10,6 +22,7 @@ import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@Slf4j
@Service
@ -17,14 +30,24 @@ import java.util.List;
public class DeviceInitService {
private final DeviceStateService deviceStateService;
private final ObjectProvider<HeatModuleState> heatModuleStateProvider;
private final ContainerService containerService;
private final DeviceParamConfigService deviceParamConfigService;
private final CanBusService canBusService;
private final DeviceCommandService deviceCommandService;
@PostConstruct
public void init() {
new Thread(() -> {
try {
Thread.sleep(2000);
CompletableFuture.runAsync(() -> {
DeviceCommandBundle deviceCommandBundle = DeviceCommandGenerator.tricolorLightOpen(CmdColor.blue);
deviceCommandService.sendCommand(deviceCommandBundle);
});
initDeviceState();
initDeviceSetData();
canBusService.initOvertime();
initEnable();
deviceStateService.getDeviceState().setInitComplete(true);
} catch (Exception e) {
log.error("设备初始化失败", e);
@ -34,10 +57,50 @@ public class DeviceInitService {
public void initDeviceSetData() throws Exception {
if (deviceStateService.getDeviceState().isVirtual() || deviceStateService.getDeviceState().isInitComplete()) {
return;
}
//从数据库中读取数据通过串口进行数据初始化
List<DeviceParamConfig> deviceParamConfigs = deviceParamConfigService.list();
for (DeviceParamConfig deviceParamConfig : deviceParamConfigs) {
DeviceInitializationData data = new DeviceInitializationData();
data.setId(Math.toIntExact(deviceParamConfig.getId()));
data.setMid(deviceParamConfig.getMid());
data.setRegIndex(deviceParamConfig.getRegIndex());
data.setRegInitVal(deviceParamConfig.getRegVal());
try {
canBusService.moduleSetRegByApp(data.getMid(), data.getRegIndex(), data.getRegInitVal());
} catch (Exception e) {
log.error("设备初始化写入参数失败,2秒后重试", e);
Thread.sleep(2000);
initDeviceSetData();
}
}
}
/**
* 初始化所有设备使能
*/
public void initEnable() throws Exception {
//门电机
DeviceCommandBundle doorEnableDeviceCommandBundle = DeviceCommandGenerator.doorEnable();
deviceCommandService.sendCommand(doorEnableDeviceCommandBundle);
//x轴
DeviceCommandBundle xEnableDeviceCommandBundle = DeviceCommandGenerator.transferXEnable();
deviceCommandService.sendCommand(xEnableDeviceCommandBundle);
//z轴
DeviceCommandBundle yEnableDeviceCommandBundle = DeviceCommandGenerator.transferZEnable();
deviceCommandService.sendCommand(yEnableDeviceCommandBundle);
//机械臂
DeviceCommandBundle liquidMotorEnableDeviceCommandBundle = DeviceCommandGenerator.liquidMotorEnable();
deviceCommandService.sendCommand(liquidMotorEnableDeviceCommandBundle);
//蠕动泵
DeviceCommandBundle liquidPumpEnableDeviceCommandBundle = DeviceCommandGenerator.liquidPumpEnable();
deviceCommandService.sendCommand(liquidPumpEnableDeviceCommandBundle);
}
public void initDeviceState() {
//初始化加热模块属性
DeviceState deviceState = deviceStateService.getDeviceState();
@ -45,5 +108,15 @@ public class DeviceInitService {
for (HeatModuleCode code : HeatModuleCode.values()) {
heatArea.add(heatModuleStateProvider.getObject(code));
}
List<Container> containerList = containerService.getList();
List<SolutionContainerState> solutionBucket = deviceState.getSolutionModule().getSolutionContainer();
for (Container container : containerList) {
if (container.getType() == 0) {
solutionBucket.add(new SolutionContainerState(container.getId(), ContainerCode.valueOf(container.getCode()), ContainerType.solution));
} else {
solutionBucket.add(new SolutionContainerState(container.getId(), ContainerCode.valueOf(container.getCode()), ContainerType.waste));
}
}
}
}

11
src/main/java/com/iflytop/sgs/common/service/CanBusService.java

@ -0,0 +1,11 @@
package com.iflytop.sgs.common.service;
import com.iflytop.sgs.hardware.exception.HardwareException;
public interface CanBusService {
void moduleSetRegByApp(String mid, String regindex, Integer reg) throws HardwareException;
void initOvertime();
}

22
src/main/java/com/iflytop/sgs/hardware/comm/can/A8kCanBusService.java

@ -1,5 +1,7 @@
package com.iflytop.sgs.hardware.comm.can;
import com.iflytop.sgs.common.service.CanBusService;
import com.iflytop.sgs.hardware.constants.ActionOvertimeConstant;
import com.iflytop.sgs.hardware.exception.HardwareException;
import com.iflytop.sgs.hardware.type.*;
import com.iflytop.sgs.hardware.type.error.A8kEcode;
@ -10,14 +12,17 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorMId;
import java.net.URISyntaxException;
@Component
@Slf4j
public class A8kCanBusService {
public class A8kCanBusService implements CanBusService {
@Resource
A8kCanBusConnection connection;
@Resource
ActionOvertimeConstant actionOvertimeConstant;
@Value("${device.enableCanBus}")
Boolean enableCanBus;
@ -76,6 +81,21 @@ public class A8kCanBusService {
public ModuleStatus moduleGetStatus(MId id) throws HardwareException {
return connection.moduleGetStatus(id);
}
public void moduleSetRegByApp(String id, String regindex, Integer reg) throws HardwareException {
MId mId=MId.valueOf(id);
RegIndex regIndex=RegIndex.valueOf(reg);
this.moduleSetReg(mId,regIndex,reg);
}
/**
* 设置各动作超时时间
*/
@Override
public void initOvertime() {
actionOvertimeConstant.pushNewConfig(StepMotorMId.DoorM, CmdId.step_motor_easy_move_to_zero, 30 * 1000);
actionOvertimeConstant.pushNewConfig(StepMotorMId.LiquidM, CmdId.step_motor_easy_move_to_zero, 30 * 1000);
actionOvertimeConstant.pushNewConfig(StepMotorMId.LiquidPumpM, CmdId.step_motor_easy_move_to_zero, 30 * 1000);
actionOvertimeConstant.pushNewConfig(StepMotorMId.ZM, CmdId.step_motor_easy_move_to_zero, 30 * 1000);
}
public void moduleSetReg(MId id, RegIndex regindex, Integer reg) throws HardwareException {
connection.callcmd2(id, CmdId.module_set_reg, 100, regindex.index, reg);

2
src/main/java/com/iflytop/sgs/hardware/command/handlers/LeiSaiServoHandler.java

@ -25,7 +25,7 @@ public class LeiSaiServoHandler extends CommandHandler {
private final LeiSaiServoWrapperDriver driver_;
private final Map<CmdDevice, LeisaiServoMId> motorIdMap_ = Map.ofEntries(
Map.entry(CmdDevice.door_motor, LeisaiServoMId.XSV)
Map.entry(CmdDevice.x_motor, LeisaiServoMId.XSV)
);
private final Map<CmdDevice, MId> supportCmdDeviceMIdMap = motorIdMap_.entrySet().stream().
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid));

3
src/main/java/com/iflytop/sgs/hardware/command/handlers/MotorHandler.java

@ -26,7 +26,8 @@ public class MotorHandler extends CommandHandler {
private final Map<CmdDevice, StepMotorMId> stepMotorMIdMap_ = Map.ofEntries(
Map.entry(CmdDevice.door_motor, StepMotorMId.DoorM),
Map.entry(CmdDevice.z_motor, StepMotorMId.ZM),
Map.entry(CmdDevice.liquid_motor, StepMotorMId.LiquidM) // TODO: 蠕动泵后期可能会调整方案
Map.entry(CmdDevice.liquid_motor, StepMotorMId.LiquidM),
Map.entry(CmdDevice.liquid_pump, StepMotorMId.LiquidPumpM)// TODO: 蠕动泵后期可能会调整方案
);
private final Map<CmdDevice, MId> supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream().
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid));

2
src/main/resources/application-dev.yml

@ -36,7 +36,7 @@ command_bus:
device.enableCanBus: true
iflytophald:
ip: 192.168.8.168
ip: 192.168.10.168
cmdch.port: 19004
datach.port: 19005

Loading…
Cancel
Save