diff --git a/src/main/java/com/iflytop/sgs/app/controller/DevicePointController.java b/src/main/java/com/iflytop/sgs/app/controller/DevicePointController.java index 7e632e4..5ca3606 100644 --- a/src/main/java/com/iflytop/sgs/app/controller/DevicePointController.java +++ b/src/main/java/com/iflytop/sgs/app/controller/DevicePointController.java @@ -4,6 +4,7 @@ import com.iflytop.sgs.app.model.dto.AddDevicePositionDTO; import com.iflytop.sgs.app.model.entity.DevicePosition; import com.iflytop.sgs.app.model.vo.DevicePositionVO; import com.iflytop.sgs.app.service.api.DevicePositionService; +import com.iflytop.sgs.common.enums.DevicePartId; import com.iflytop.sgs.common.result.Result; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; diff --git a/src/main/java/com/iflytop/sgs/app/controller/MotorController.java b/src/main/java/com/iflytop/sgs/app/controller/MotorController.java new file mode 100644 index 0000000..ab8de4d --- /dev/null +++ b/src/main/java/com/iflytop/sgs/app/controller/MotorController.java @@ -0,0 +1,36 @@ +package com.iflytop.sgs.app.controller; + +import com.iflytop.sgs.app.service.device.DeviceSensorService; +import com.iflytop.sgs.common.enums.DevicePartId; +import com.iflytop.sgs.common.result.Result; +import com.iflytop.sgs.hardware.exception.HardwareException; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +/** + * 认证控制 + */ +@Tag(name = "设备") +@RestController +@RequestMapping("/api/motor") +@RequiredArgsConstructor +@Slf4j +public class MotorController { + + private DeviceSensorService deviceSensorService; + + @Operation(summary = "获取当前电机位置") + @GetMapping("/position/{motor}") + public Result getPosition(@PathVariable String motor) { + DevicePartId devicePartId = DevicePartId.valueOf(motor); + try { + Double position = deviceSensorService.getSensorStatus(devicePartId); + return Result.success(position); + } catch (HardwareException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java b/src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java index 2a665d9..34e2233 100644 --- a/src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java +++ b/src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java @@ -44,10 +44,5 @@ public class DeviceInitService { heatArea.add(new HeatModuleState(code)); } } - @Scheduled(fixedRate = 1000) - public void initDeviceSensor() { - - - } } diff --git a/src/main/java/com/iflytop/sgs/app/service/device/DeviceSensorService.java b/src/main/java/com/iflytop/sgs/app/service/device/DeviceSensorService.java index 80941f0..f5ed2ca 100644 --- a/src/main/java/com/iflytop/sgs/app/service/device/DeviceSensorService.java +++ b/src/main/java/com/iflytop/sgs/app/service/device/DeviceSensorService.java @@ -1,11 +1,17 @@ package com.iflytop.sgs.app.service.device; +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.bo.status.device.SolutionModuleState; +import com.iflytop.sgs.common.enums.ContainerCode; import com.iflytop.sgs.common.enums.DevicePartId; import com.iflytop.sgs.common.enums.DeviceSensorCode; +import com.iflytop.sgs.common.enums.HeatModuleCode; import com.iflytop.sgs.common.service.GDDeviceStatusService; import com.iflytop.sgs.hardware.exception.HardwareException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.util.List; @@ -15,6 +21,7 @@ import java.util.List; @RequiredArgsConstructor public class DeviceSensorService { private final GDDeviceStatusService deviceStatusService; + private final DeviceStateService deviceStateService; /* * 获取传感器状态 @@ -30,5 +37,34 @@ public class DeviceSensorService { return deviceStatusService.getStepMotorPostion(devicePartId.name()); } + @Scheduled(fixedRate = 1000) + public void deviceSensorSchedule() throws HardwareException { + HeatModuleState heat_module_01 = deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_01); + heat_module_01.setTrayStatus(this.getSensorStatus(DeviceSensorCode.HEATER_TRAY_1_EXIST)); + + HeatModuleState heat_module_02 = deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_02); + heat_module_02.setTrayStatus(this.getSensorStatus(DeviceSensorCode.HEATER_TRAY_2_EXIST)); + + HeatModuleState heat_module_03 = deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_03); + heat_module_03.setTrayStatus(this.getSensorStatus(DeviceSensorCode.HEATER_TRAY_3_EXIST)); + + HeatModuleState heat_module_04 = deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_04); + heat_module_04.setTrayStatus(this.getSensorStatus(DeviceSensorCode.HEATER_TRAY_4_EXIST)); + SolutionModuleState solutionModuleState = deviceStateService.getDeviceState().getSolutionModule(); + //todo 需要确认传感器个数以及这个传感器是否是加液传感器 + solutionModuleState.setFeedAreaTrayStatus(this.getSensorStatus(DeviceSensorCode.LIQUID_TRAY_EXIST)); + + SolutionContainerState container_01 = solutionModuleState.getContainerStateByCode(ContainerCode.container_01); + container_01.setEmpty(this.getSensorStatus(DeviceSensorCode.THIN_LOW_LEVEL)); + SolutionContainerState container_02 = solutionModuleState.getContainerStateByCode(ContainerCode.container_02); + container_02.setEmpty(this.getSensorStatus(DeviceSensorCode.THICK_LOW_LEVEL)); + SolutionContainerState container_03 = solutionModuleState.getContainerStateByCode(ContainerCode.container_03); + container_03.setEmpty(this.getSensorStatus(DeviceSensorCode.WATER_LOW_LEVEL)); + SolutionContainerState container_04 = solutionModuleState.getContainerStateByCode(ContainerCode.container_04); + container_04.setFull(this.getSensorStatus(DeviceSensorCode.WASTE_HIGH_LEVEL)); + + + } + }