9 changed files with 17 additions and 288 deletions
-
16src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java
-
4src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java
-
4src/main/java/com/iflytop/handacid/hardware/command/handlers/CeramicPumpHandler.java
-
71src/main/java/com/iflytop/handacid/hardware/command/handlers/HeatRodHandler.java
-
61src/main/java/com/iflytop/handacid/hardware/command/handlers/MiniServoHandler.java
-
84src/main/java/com/iflytop/handacid/hardware/command/handlers/TricolorLightHandler.java
-
13src/main/java/com/iflytop/handacid/hardware/service/GDDeviceStatusService.java
-
4src/main/java/com/iflytop/handacid/hardware/type/CeramicPumpDriverSlaveId.java
-
48src/main/java/com/iflytop/handacid/hardware/type/driver/HeaterRodSlavedId.java
@ -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<Device, TecHeaterRodMId> supportCmdDeviceTecHeaterRodMIdMap = Map.ofEntries( |
|
||||
Map.entry(Device.HEAT_ROD_1, TecHeaterRodMId.HeaterRod1), |
|
||||
Map.entry(Device.HEAT_ROD_2, TecHeaterRodMId.HeaterRod2) |
|
||||
); |
|
||||
|
|
||||
private final Map<Device, MId> supportCmdDeviceMIdMap = Map.ofEntries( |
|
||||
Map.entry(Device.HEAT_ROD_1, MId.HeaterRod1), |
|
||||
Map.entry(Device.HEAT_ROD_2, MId.HeaterRod2) |
|
||||
); |
|
||||
|
|
||||
private final Set<Action> supportActions = Set.of(Action.OPEN, Action.CLOSE); |
|
||||
|
|
||||
@Override |
|
||||
protected Map<Device, MId> getSupportCmdDeviceMIdMap() |
|
||||
{ |
|
||||
return supportCmdDeviceMIdMap; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected Set<Action> 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())); |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -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<Device, MiniServoMId> servoMIdMap_ = Map.ofEntries( |
|
||||
Map.entry(Device.CLAW, MiniServoMId.RobotArmClawSV) |
|
||||
); |
|
||||
private final Map<Device, MId> supportCmdDeviceMIdMap = servoMIdMap_.entrySet().stream(). |
|
||||
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|
||||
private final Set<Action> supportActions = Set.of(Action.SET, Action.ORIGIN, Action.MOVE, Action.STOP); |
|
||||
|
|
||||
@Override |
|
||||
protected Map<Device, MId> getSupportCmdDeviceMIdMap() |
|
||||
{ |
|
||||
return supportCmdDeviceMIdMap; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected Set<Action> 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); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -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<Device, MId> supportCmdDeviceMIdMap = Map.ofEntries( |
|
||||
Map.entry(Device.TRICOLOR_LIGHT, MId.IO1_TriColorLight) |
|
||||
); |
|
||||
|
|
||||
private final Set<Action> supportActions = Set.of(Action.OPEN, Action.CLOSE); |
|
||||
|
|
||||
@Override |
|
||||
protected Map<Device, MId> getSupportCmdDeviceMIdMap() |
|
||||
{ |
|
||||
return supportCmdDeviceMIdMap; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
protected Set<Action> 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())); |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -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; |
|
||||
} |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue