|
|
@ -16,6 +16,7 @@ import com.iflytop.sgs.common.enums.HeatModuleCode; |
|
|
|
import com.iflytop.sgs.common.enums.cmd.CmdColor; |
|
|
|
import com.iflytop.sgs.common.service.CanBusService; |
|
|
|
import com.iflytop.sgs.hardware.exception.HardwareException; |
|
|
|
import com.iflytop.sgs.hardware.service.setup.A8kSubModuleRegInitService; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
@ -38,26 +39,34 @@ public class DeviceInitService { |
|
|
|
private final ObjectProvider<HeatModuleState> heatModuleStateProvider; |
|
|
|
private final ObjectProvider<SolutionContainerState> solutionContainerStateProvider; |
|
|
|
private final DeviceLightSoundService deviceLightSoundService; |
|
|
|
private final A8kSubModuleRegInitService a8kSubModuleRegInitService; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() { |
|
|
|
public void init() throws InterruptedException { |
|
|
|
while (!a8kSubModuleRegInitService.getIsInited()) { |
|
|
|
Thread.sleep(100); |
|
|
|
} |
|
|
|
new Thread(() -> { |
|
|
|
try { |
|
|
|
Thread.sleep(2000); |
|
|
|
CompletableFuture.runAsync(() -> { |
|
|
|
DeviceCommandBundle deviceCommandBundle = DeviceCommandGenerator.tricolorLightOpen(CmdColor.blue); |
|
|
|
deviceCommandService.sendCommand(deviceCommandBundle); |
|
|
|
try { |
|
|
|
deviceLightSoundService.openColor(CmdColor.blue); |
|
|
|
} catch (HardwareException e) { |
|
|
|
log.error("设备初始化灯光失败,CmdColor.blue"); |
|
|
|
} |
|
|
|
}); |
|
|
|
initDeviceState(); |
|
|
|
initDeviceSetData(); |
|
|
|
canBusService.initOvertime(); |
|
|
|
initEnable(); |
|
|
|
initSensorState(); |
|
|
|
CompletableFuture.runAsync(() -> { |
|
|
|
try { |
|
|
|
deviceLightSoundService.openColor(CmdColor.green); |
|
|
|
} catch (HardwareException e) { |
|
|
|
log.error("设备初始化灯光失败,Color.GREEN"); |
|
|
|
log.error("设备初始化灯光失败,CmdColor.green"); |
|
|
|
} |
|
|
|
}); |
|
|
|
deviceStateService.getDeviceState().setInitComplete(true); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("设备初始化失败", e); |
|
|
@ -73,7 +82,6 @@ public class DeviceInitService { |
|
|
|
if (deviceStateService.getDeviceState().isVirtual() || deviceStateService.getDeviceState().isInitComplete()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
//从数据库中读取数据通过串口进行数据初始化 |
|
|
|
List<DeviceParamConfig> deviceParamConfigs = deviceParamConfigService.list(); |
|
|
|
for (DeviceParamConfig deviceParamConfig : deviceParamConfigs) { |
|
|
|
DeviceInitializationData data = new DeviceInitializationData(); |
|
|
@ -81,17 +89,19 @@ public class DeviceInitService { |
|
|
|
data.setMid(deviceParamConfig.getMid()); |
|
|
|
data.setRegIndex(deviceParamConfig.getRegIndex()); |
|
|
|
data.setRegInitVal(deviceParamConfig.getRegVal()); |
|
|
|
boolean success = false; // 标记是否执行成功 |
|
|
|
while (!success) { |
|
|
|
try { |
|
|
|
canBusService.moduleSetRegByApp(data.getMid(), data.getRegIndex(), data.getRegInitVal()); |
|
|
|
success = true; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("设备初始化写入参数失败,2秒后重试", e); |
|
|
|
log.error("设备初始化写入参数失败,错误: {}", e.getMessage()); |
|
|
|
Thread.sleep(2000); |
|
|
|
canBusService.moduleSetRegByApp(data.getMid(), data.getRegIndex(), data.getRegInitVal()); |
|
|
|
//initDeviceSetData(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化所有设备使能 |
|
|
|