diff --git a/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java b/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java index 37621d8..1f73976 100644 --- a/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java +++ b/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java @@ -26,12 +26,20 @@ public class ChannelState { @Schema(description = "剩余容量(单位:mL)") private Double remainingVolume; - @Schema(description = "通道配置的溶液") - private ChannelSolution solution; + @Schema(description = "溶液id") + private Long solutionId; - public ChannelState(ChannelCode channelCode, Double remainingVolume, ChannelSolution solution) { + @Schema(description = "溶液名称") + private String solutionName; + + @Schema(description = "溶液浓度") + private String concentration; + + public ChannelState(ChannelCode channelCode, Double remainingVolume, Long solutionId, String solutionName, String concentration) { this.channelCode = channelCode; this.remainingVolume = remainingVolume; - this.solution = solution; + this.solutionId = solutionId; + this.solutionName = solutionName; + this.concentration = concentration; } } 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 f31e208..b7b1d33 100644 --- a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java @@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.iflytop.handacid.app.common.enums.ChannelCode; import com.iflytop.handacid.app.core.state.ChannelState; import com.iflytop.handacid.app.core.state.DeviceState; -import com.iflytop.handacid.app.model.bo.ChannelSolution; import com.iflytop.handacid.common.model.entity.Channel; import com.iflytop.handacid.common.service.ChannelService; import com.iflytop.handacid.hardware.service.AppEventBusService; @@ -54,8 +53,7 @@ public class DeviceInitService { for (ChannelCode code : ChannelCode.values()) { //初始化通道 Channel channel = channelService.getOne(new LambdaQueryWrapper<>(new Channel()).eq(Channel::getCode, code)); - ChannelSolution channelSolution = new ChannelSolution(channel.getSolutionId(), channel.getSolutionName(), channel.getConcentration()); - ChannelState channelState = channelStateObjectProvider.getObject(code, channel.getVolume(), channelSolution); + ChannelState channelState = channelStateObjectProvider.getObject(code, channel.getVolume(), channel.getSolutionId(), channel.getSolutionName(), channel.getConcentration()); deviceState.getChannelStateMap().put(code, channelState); } log.info("初始化 initDeviceState完毕"); diff --git a/src/main/java/com/iflytop/handacid/hardware/command/handlers/CeramicPumpHandler.java b/src/main/java/com/iflytop/handacid/hardware/command/handlers/CeramicPumpHandler.java index 6c4576c..82693f5 100644 --- a/src/main/java/com/iflytop/handacid/hardware/command/handlers/CeramicPumpHandler.java +++ b/src/main/java/com/iflytop/handacid/hardware/command/handlers/CeramicPumpHandler.java @@ -26,8 +26,8 @@ public class CeramicPumpHandler extends CommandHandler { private final CeramicPumpDriver driver_; private final Map stepMotorMIdMap_ = Map.ofEntries( - Map.entry(Device.CERAMIC_PUMP_1, CeramicPumpDriverSlaveId.CERAMIC_PUMP1_ID), - Map.entry(Device.CERAMIC_PUMP_2, CeramicPumpDriverSlaveId.CERAMIC_PUMP2_ID) + Map.entry(Device.PUMP_1, CeramicPumpDriverSlaveId.CERAMIC_PUMP1_ID), + Map.entry(Device.PUMP_2, CeramicPumpDriverSlaveId.CERAMIC_PUMP2_ID) ); private final Map supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream(). collect(Collectors.toMap(Map.Entry::getKey, entry -> MId.NotSet)); diff --git a/src/main/java/com/iflytop/handacid/hardware/command/handlers/HeatRodHandler.java b/src/main/java/com/iflytop/handacid/hardware/command/handlers/HeatRodHandler.java deleted file mode 100644 index 08d458c..0000000 --- a/src/main/java/com/iflytop/handacid/hardware/command/handlers/HeatRodHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.iflytop.handacid.hardware.command.handlers; - -import com.iflytop.handacid.app.core.command.DeviceCommand; -import com.iflytop.handacid.common.enums.Action; -import com.iflytop.handacid.common.enums.Device; -import com.iflytop.handacid.hardware.command.CommandHandler; -import com.iflytop.handacid.hardware.drivers.TecHeaterRodDriver; -import com.iflytop.handacid.hardware.type.MId; -import com.iflytop.handacid.hardware.type.TecHeaterRodMId; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import java.util.Map; -import java.util.Set; - -@Slf4j -@Component -@RequiredArgsConstructor -public class HeatRodHandler extends CommandHandler { - private final TecHeaterRodDriver driver_; - - private final Map supportCmdDeviceTecHeaterRodMIdMap = Map.ofEntries( - Map.entry(Device.HEAT_ROD_1, TecHeaterRodMId.HeaterRod1), - Map.entry(Device.HEAT_ROD_2, TecHeaterRodMId.HeaterRod2) - ); - - private final Map supportCmdDeviceMIdMap = Map.ofEntries( - Map.entry(Device.HEAT_ROD_1, MId.HeaterRod1), - Map.entry(Device.HEAT_ROD_2, MId.HeaterRod2) - ); - - private final Set supportActions = Set.of(Action.OPEN, Action.CLOSE); - - @Override - protected Map getSupportCmdDeviceMIdMap() - { - return supportCmdDeviceMIdMap; - } - - @Override - protected Set getSupportActions() { - return supportActions; - } - - @Override - protected void checkParams(DeviceCommand command) throws Exception { - // 检查参数 - if (command.getAction() == Action.OPEN) { - // 检查参数 - } - - } - - MId getMId(Device cmdDevice){ - return supportCmdDeviceMIdMap.get(cmdDevice); - } - - @Override - public void handleCommand(DeviceCommand command) throws Exception { - // 发送命令 - - if (command.getAction() == Action.OPEN) { - Double temp = command.getParam().getTemperature(); - driver_.open(supportCmdDeviceTecHeaterRodMIdMap.get(command.getDevice()), temp); - - } else if (command.getAction() == Action.CLOSE) { - driver_.close(supportCmdDeviceTecHeaterRodMIdMap.get(command.getDevice())); - } - } -} diff --git a/src/main/java/com/iflytop/handacid/hardware/command/handlers/MiniServoHandler.java b/src/main/java/com/iflytop/handacid/hardware/command/handlers/MiniServoHandler.java deleted file mode 100644 index 259b5d6..0000000 --- a/src/main/java/com/iflytop/handacid/hardware/command/handlers/MiniServoHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.iflytop.handacid.hardware.command.handlers; - - -import com.iflytop.handacid.app.core.command.DeviceCommand; -import com.iflytop.handacid.common.enums.Action; -import com.iflytop.handacid.common.enums.Device; -import com.iflytop.handacid.hardware.command.CommandHandler; -import com.iflytop.handacid.hardware.drivers.MiniServoDriverWrapper; -import com.iflytop.handacid.hardware.type.MId; -import com.iflytop.handacid.hardware.type.Servo.MiniServoMId; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -@Slf4j -@Component -@RequiredArgsConstructor -public class MiniServoHandler extends CommandHandler { - private final MiniServoDriverWrapper driver_; - - private final Map servoMIdMap_ = Map.ofEntries( - Map.entry(Device.CLAW, MiniServoMId.RobotArmClawSV) - ); - private final Map supportCmdDeviceMIdMap = servoMIdMap_.entrySet().stream(). - collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); - private final Set supportActions = Set.of(Action.SET, Action.ORIGIN, Action.MOVE, Action.STOP); - - @Override - protected Map getSupportCmdDeviceMIdMap() - { - return supportCmdDeviceMIdMap; - } - - @Override - protected Set getSupportActions() { - return supportActions; - } - - @Override - public void handleCommand(DeviceCommand command) throws Exception { - // 发送命令 - MiniServoMId servoMId = servoMIdMap_.get(command.getDevice()); - if(command.getAction() == Action.STOP) { - driver_.stop(servoMId); - } - else if(command.getAction() == Action.MOVE) { - double position = command.getParam().getPosition(); - driver_.moveTo(servoMId, position); - } - else if(command.getAction() == Action.SET) { - Double speed = command.getParam().getSpeed(); - if(speed != null) { - driver_.setSpeed(servoMId, speed); - } - } - } -} diff --git a/src/main/java/com/iflytop/handacid/hardware/command/handlers/TricolorLightHandler.java b/src/main/java/com/iflytop/handacid/hardware/command/handlers/TricolorLightHandler.java deleted file mode 100644 index c73f2ae..0000000 --- a/src/main/java/com/iflytop/handacid/hardware/command/handlers/TricolorLightHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.iflytop.handacid.hardware.command.handlers; - - -import com.iflytop.handacid.app.core.command.DeviceCommand; -import com.iflytop.handacid.common.enums.Action; -import com.iflytop.handacid.common.enums.Device; -import com.iflytop.handacid.common.enums.TricolorLightColor; -import com.iflytop.handacid.hardware.command.CommandHandler; -import com.iflytop.handacid.hardware.drivers.TricolorLightDriver; -import com.iflytop.handacid.hardware.type.MId; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import java.security.InvalidParameterException; -import java.util.Map; -import java.util.Set; - -/** - * 三色灯 - */ -@Slf4j -@Component -@RequiredArgsConstructor -public class TricolorLightHandler extends CommandHandler { - private final TricolorLightDriver tricolorLightDriver; - - private final Map supportCmdDeviceMIdMap = Map.ofEntries( - Map.entry(Device.TRICOLOR_LIGHT, MId.IO1_TriColorLight) - ); - - private final Set supportActions = Set.of(Action.OPEN, Action.CLOSE); - - @Override - protected Map getSupportCmdDeviceMIdMap() - { - return supportCmdDeviceMIdMap; - } - - @Override - protected Set getSupportActions() { - return supportActions; - } - - @Override - protected void checkParams(DeviceCommand command) throws Exception { - // 检查参数 - if (command.getAction() == Action.OPEN) { - // 检查参数 - TricolorLightColor cmdColor = command.getParam().getColor(); - getCmdColor(cmdColor); - } - - } - - TricolorLightDriver.Color getCmdColor(TricolorLightColor cmdColor){ - switch (cmdColor){ - case RED: - return TricolorLightDriver.Color.RED; - case GREEN: - return TricolorLightDriver.Color.GREEN; - case BLUE: - return TricolorLightDriver.Color.BLUE; - default: - throw new InvalidParameterException("颜色参数错误"); - } - } - - MId getMId(Device cmdDevice){ - return supportCmdDeviceMIdMap.get(cmdDevice); - } - - @Override - public void handleCommand(DeviceCommand command) throws Exception { - // 发送命令 - if (command.getAction() == Action.OPEN) { - TricolorLightColor cmdColor = command.getParam().getColor(); - TricolorLightDriver.Color color = getCmdColor(cmdColor); - tricolorLightDriver.open(getMId(command.getDevice()), color); - } else if (command.getAction() == Action.CLOSE) { - tricolorLightDriver.close(getMId(command.getDevice())); - } - } -} diff --git a/src/main/java/com/iflytop/handacid/hardware/service/GDDeviceStatusService.java b/src/main/java/com/iflytop/handacid/hardware/service/GDDeviceStatusService.java index bd4fa00..99a29b7 100644 --- a/src/main/java/com/iflytop/handacid/hardware/service/GDDeviceStatusService.java +++ b/src/main/java/com/iflytop/handacid/hardware/service/GDDeviceStatusService.java @@ -6,7 +6,6 @@ import com.iflytop.handacid.hardware.drivers.StepMotorCtrlDriver; import com.iflytop.handacid.hardware.exception.HardwareException; import com.iflytop.handacid.hardware.type.IO.InputIOMId; import com.iflytop.handacid.hardware.type.StepMotor.StepMotorMId; -import com.iflytop.handacid.hardware.type.driver.HeaterRodSlavedId; import com.iflytop.handacid.hardware.utils.Math.StepMotorConverter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -43,18 +42,6 @@ public class GDDeviceStatusService { } /** - * 获取加热棒温度 - * - * @param heaterRodSlavedId - * @return - * @throws Exception - */ - public Double getHeaterRodTemperature(HeaterRodSlavedId heaterRodSlavedId) throws Exception { - return null; - //return heaterRodDriver.getTemperature(heaterRodSlavedId); - } - - /** * 获取电机位置 * * @param stepMotorMId diff --git a/src/main/java/com/iflytop/handacid/hardware/type/CeramicPumpDriverSlaveId.java b/src/main/java/com/iflytop/handacid/hardware/type/CeramicPumpDriverSlaveId.java index 608d063..678188c 100644 --- a/src/main/java/com/iflytop/handacid/hardware/type/CeramicPumpDriverSlaveId.java +++ b/src/main/java/com/iflytop/handacid/hardware/type/CeramicPumpDriverSlaveId.java @@ -4,8 +4,8 @@ import com.iflytop.handacid.common.enums.Device; public enum CeramicPumpDriverSlaveId { - CERAMIC_PUMP1_ID(Device.CERAMIC_PUMP_1, 0x11), - CERAMIC_PUMP2_ID(Device.CERAMIC_PUMP_2, 0x12), + CERAMIC_PUMP1_ID(Device.PUMP_1, 0x11), + CERAMIC_PUMP2_ID(Device.PUMP_2, 0x12), ; private final Device cmdDevice; diff --git a/src/main/java/com/iflytop/handacid/hardware/type/driver/HeaterRodSlavedId.java b/src/main/java/com/iflytop/handacid/hardware/type/driver/HeaterRodSlavedId.java deleted file mode 100644 index 6bd0c6b..0000000 --- a/src/main/java/com/iflytop/handacid/hardware/type/driver/HeaterRodSlavedId.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.iflytop.handacid.hardware.type.driver; - - -import com.iflytop.handacid.common.enums.Device; -import com.iflytop.handacid.hardware.type.MId; - -public enum HeaterRodSlavedId { - HEATER_ROD1_ID(Device.HEAT_ROD_1, 1, MId.IO1_ADC, 1), - HEATER_ROD2_ID(Device.HEAT_ROD_2, 2, MId.IO1_ADC, 2), - ; - - private final Device device; - private final Integer slaveId; - private final MId mid; - private final Integer adcCurrentIndex; // ADC电流索引 - - HeaterRodSlavedId(Device device, Integer slaveId, MId mid, Integer adcCurrentIndex) { - this.device = device; - this.slaveId = slaveId; - this.mid = mid; - this.adcCurrentIndex = adcCurrentIndex; - } - - public Device getCmdDevice() { - return device; - } - - public Integer getSlaveId() { - return slaveId; - } - - public MId getMid() { - return mid; - } - - public Integer getAdcCurrentIndex() { - return adcCurrentIndex; - } - - static public HeaterRodSlavedId getByCmdDevice(Device device) { - for (HeaterRodSlavedId value : HeaterRodSlavedId.values()) { - if (value.device == device) { - return value; - } - } - return null; - } -}