Browse Source

增加加热棒指令配置

master
HSZ_HeSongZhen 1 week ago
parent
commit
aa3ea916a1
  1. 72
      src/main/java/com/iflytop/colortitration/hardware/command/handlers/HeatRodHandler.java
  2. 2
      src/main/java/com/iflytop/colortitration/hardware/command/handlers/MiniServoHandler.java
  3. 93
      src/main/java/com/iflytop/colortitration/hardware/drivers/TecHeaterRodDriver.java
  4. 8
      src/main/java/com/iflytop/colortitration/hardware/type/CmdId.java
  5. 2
      src/main/java/com/iflytop/colortitration/hardware/type/MId.java
  6. 39
      src/main/java/com/iflytop/colortitration/hardware/type/RegIndex.java
  7. 33
      src/main/java/com/iflytop/colortitration/hardware/type/TecHeaterRegIndex.java
  8. 16
      src/main/java/com/iflytop/colortitration/hardware/type/TecHeaterRodMId.java

72
src/main/java/com/iflytop/colortitration/hardware/command/handlers/HeatRodHandler.java

@ -0,0 +1,72 @@
package com.iflytop.colortitration.hardware.command.handlers;
import com.iflytop.colortitration.app.core.command.DeviceCommand;
import com.iflytop.colortitration.common.enums.Action;
import com.iflytop.colortitration.common.enums.Device;
import com.iflytop.colortitration.hardware.command.CommandHandler;
import com.iflytop.colortitration.hardware.drivers.TecHeaterRodDriver;
import com.iflytop.colortitration.hardware.type.MId;
import com.iflytop.colortitration.hardware.type.TecHeaterRodMId;
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 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()));
}
}
}

2
src/main/java/com/iflytop/colortitration/hardware/command/handlers/ClawHandler.java → src/main/java/com/iflytop/colortitration/hardware/command/handlers/MiniServoHandler.java

@ -19,7 +19,7 @@ import java.util.stream.Collectors;
@Slf4j
@Component
@RequiredArgsConstructor
public class ClawHandler extends CommandHandler {
public class MiniServoHandler extends CommandHandler {
private final MiniServoDriverWrapper driver_;
private final Map<Device, MiniServoMId> servoMIdMap_ = Map.ofEntries(

93
src/main/java/com/iflytop/colortitration/hardware/drivers/TecHeaterRodDriver.java

@ -0,0 +1,93 @@
package com.iflytop.colortitration.hardware.drivers;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.iflytop.colortitration.hardware.comm.can.A8kCanBusService;
import com.iflytop.colortitration.hardware.exception.HardwareException;
import com.iflytop.colortitration.hardware.type.A8kPacket;
import com.iflytop.colortitration.hardware.type.CmdId;
import com.iflytop.colortitration.hardware.type.TecHeaterRegIndex;
import com.iflytop.colortitration.hardware.type.TecHeaterRodMId;
import com.iflytop.colortitration.hardware.utils.ZJsonHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Component
@Slf4j
@RequiredArgsConstructor
public class TecHeaterRodDriver {
final private A8kCanBusService canBus;
static final Double DEFAULT_TARGET_TEMPERATURE = 100.0;
static final Integer DEFAULT_CHANNEL = 1;
// application API
public void open(TecHeaterRodMId id, Double temperature) throws HardwareException {
this.enable(id, true);
this.setTargetTemperature(id, temperature);
}
public void close(TecHeaterRodMId id) throws HardwareException {
this.enable(id, false);
}
// driver API
public void openPower(TecHeaterRodMId id, boolean is_open) throws HardwareException {
log.info("openPower called with id: {}, is_open: {}", id, is_open);
Integer powerOn = is_open ? 1 : 0;
canBus.callcmd(id.mid, CmdId.tec103_heater_power_on, powerOn);
}
public void enable(TecHeaterRodMId id, boolean is_enable) throws HardwareException {
log.info("enable called with id: {}, is_enable: {}", id, is_enable);
Integer enable = is_enable ? 1 : 0;
canBus.callcmd(id.mid, CmdId.tec103_heater_enable, DEFAULT_CHANNEL, enable);
}
public void setTargetTemperature(TecHeaterRodMId id, Double targetTemperature) throws HardwareException {
Integer targetTemperatureInt = (int) (targetTemperature * DEFAULT_TARGET_TEMPERATURE);
log.info("setTargetTemperature called with id: {}, targetTemperature: {}", id, targetTemperature);
canBus.callcmd(id.mid, CmdId.tec103_heater_set_target_temperature, DEFAULT_CHANNEL, targetTemperatureInt);
}
public Double readTemperature(TecHeaterRodMId id) throws HardwareException {
log.info("readTemperature called with id: {}", id);
A8kPacket packet = canBus.callcmd(id.mid, CmdId.tec103_heater_read_temperature, DEFAULT_CHANNEL);
return packet.getContentI32(0) / DEFAULT_TARGET_TEMPERATURE;
}
public void factoryReset(TecHeaterRodMId id) throws HardwareException {
log.info("factoryReset called with id: {}", id);
canBus.callcmd(id.mid, CmdId.tec103_heater_factory_reset);
}
public void reset(TecHeaterRodMId id) throws HardwareException {
log.info("reset called with id: {}", id);
canBus.callcmd(id.mid, CmdId.liquid_valve_reset);
}
public void waitForMod(TecHeaterRodMId id, Integer overtime) throws HardwareException {
canBus.waitForMod(id.mid, overtime);
}
public void setReg(TecHeaterRodMId id, TecHeaterRegIndex regindex, int val) throws HardwareException {
log.info("setReg called with id: {}, regindex: {}, val: {}", id, regindex, val);
canBus.moduleSetReg(id.mid, regindex.regIndex, val);
}
public Integer getReg(TecHeaterRodMId id, TecHeaterRegIndex regindex) throws HardwareException {
log.info("getReg called with id: {}, regindex: {}", id, regindex);
return canBus.moduleGetReg(id.mid, regindex.regIndex);
}
public Object getAllReg(TecHeaterRodMId id) throws HardwareException {
log.info("getAllReg called with id: {}", id);
ObjectNode node = ZJsonHelper.createObjectNode();
for (TecHeaterRegIndex regIndex : TecHeaterRegIndex.values()) {
Integer regVal = getReg(id, regIndex);
log.info("read reg {} -> {}", regIndex, regVal);
node.put(regIndex.name(), getReg(id, regIndex));
}
return node;
}
}

8
src/main/java/com/iflytop/colortitration/hardware/type/CmdId.java

@ -110,7 +110,13 @@ public enum CmdId {
liquid_valve_stop(0x5704, "LIQUID_VALVE_STOP"),
liquid_valve_reset(0x5705, "LIQUID_VALVE_RESET"),
liquid_valve_home_reset(0x5706, "LIQUID_VALVE_HOME_RESET"),
liquid_valve_force_stop(0x5707, "LIQUID_VALVE_FORCE_STOP");
liquid_valve_force_stop(0x5707, "LIQUID_VALVE_FORCE_STOP"),
tec103_heater_power_on(0x5801, "TEC103_HEATER_POWER_ON"),
tec103_heater_enable(0x5802, "TEC103_HEATER_ENABLE"),
tec103_heater_set_target_temperature(0x5803, "TEC103_HEATER_SET_TARGET_TEMPERATURE"),
tec103_heater_read_temperature(0x5804, "TEC103_HEATER_READ_TEMPERATURE"),
tec103_heater_factory_reset(0x5805, "TEC103_HEATER_FACTORY_RESET"),
;
public final static int ATTACH_IS_BYTES = 1;

2
src/main/java/com/iflytop/colortitration/hardware/type/MId.java

@ -40,6 +40,8 @@ public enum MId {
TitratorStir2M(77, "滴定仪搅拌2泵"),
Titrator1M(78, "滴定仪1泵"),
Titrator2M(79, "滴定仪2泵"),
HeaterRod1(80, "加热棒1"),
HeaterRod2(81, "加热棒2"),
;
final public String description;

39
src/main/java/com/iflytop/colortitration/hardware/type/RegIndex.java

@ -155,6 +155,45 @@ public enum RegIndex {
kreg_leisai_servo_high_velocity(10707), // 高速
kreg_leisai_servo_acc_time(10708), // 加速度时间
kreg_leisai_servo_dcc_time(10709), // 减速度时间
kreg_tec103_heater1_target_temp(10800), // 目标温度
kreg_tec103_heater1_real_temp(10801), // 读取温度
kreg_tec103_heater1_sensor_r(10802), // 查询传感器电阻值
kreg_tec103_heater1_polynomial(10803), // 温度求解模型选择
kreg_tec103_heater1_ntc_b(10804), // NTC B值
kreg_tec103_heater1_ntc_r0(10805), // NTC R0值
kreg_tec103_heater1_output_enable(10807), // 使能
kreg_tec103_heater1_output_max_duty(10808), // 最大输出占空比
kreg_tec103_heater1_output_mode(10809), // 输出模式
kreg_tec103_heater1_output_pol(10810), // 输出极性
kreg_tec103_heater1_output_percent(10811), // 输出电压百分比
kreg_tec103_heater1_pwm_freq(10812), // PWM引脚输出频率
kreg_tec103_heater1_over_temp_protect_mode(10813), // 传感器过温保护模式
kreg_tec103_heater1_p(10814), // P参数
kreg_tec103_heater1_i(10815), // I参数
kreg_tec103_heater1_d(10816), // D参数
kreg_tec103_heater1_pid_self_tune(10817), // PID自整定
kreg_tec103_heater2_target_temp(10830), // 目标温度
kreg_tec103_heater2_real_temp(10831), // 读取温度
kreg_tec103_heater2_sensor_r(10832), // 查询传感器电阻值
kreg_tec103_heater2_polynomial(10833), // 温度求解模型选择
kreg_tec103_heater2_ntc_b(10834), // NTC B值
kreg_tec103_heater2_ntc_r0(10835), // NTC R0值
kreg_tec103_heater2_output_enable(10837), // 使能
kreg_tec103_heater2_output_max_duty(10838), // 最大输出占空比
kreg_tec103_heater2_output_mode(10839), // 输出模式
kreg_tec103_heater2_output_pol(10840), // 输出极性
kreg_tec103_heater2_output_percent(10841), // 输出电压百分比
kreg_tec103_heater2_pwm_freq(10842), // PWM引脚输出频率
kreg_tec103_heater2_over_temp_protect_mode(10843), // 传感器过温保护模式
kreg_tec103_heater2_p(10844), // P参数
kreg_tec103_heater2_i(10845), // I参数
kreg_tec103_heater2_d(10846), // D参数
kreg_tec103_heater2_pid_self_tune(10847), // PID自整定
kreg_tec103_heater_version(10860), // 版本号
kreg_tec103_heater_address(10861), // 从机地址
kreg_tec103_heater_baud_rate(10862), // 波特率
kreg_tec103_heater_e_code(10863), // 错误码
;
public final int index;

33
src/main/java/com/iflytop/colortitration/hardware/type/TecHeaterRegIndex.java

@ -0,0 +1,33 @@
package com.iflytop.colortitration.hardware.type;
public enum TecHeaterRegIndex {
kreg_tec103_heater1_target_temp(RegIndex.kreg_tec103_heater1_target_temp),
kreg_tec103_heater1_real_temp(RegIndex.kreg_tec103_heater1_real_temp),
kreg_tec103_heater1_sensor_r(RegIndex.kreg_tec103_heater1_sensor_r),
kreg_tec103_heater1_polynomial(RegIndex.kreg_tec103_heater1_polynomial),
kreg_tec103_heater1_ntc_b(RegIndex.kreg_tec103_heater1_ntc_b),
kreg_tec103_heater1_ntc_r0(RegIndex.kreg_tec103_heater1_ntc_r0),
kreg_tec103_heater1_output_enable(RegIndex.kreg_tec103_heater1_output_enable),
kreg_tec103_heater1_output_max_duty(RegIndex.kreg_tec103_heater1_output_max_duty),
kreg_tec103_heater1_output_mode(RegIndex.kreg_tec103_heater1_output_mode),
kreg_tec103_heater1_output_pol(RegIndex.kreg_tec103_heater1_output_pol),
kreg_tec103_heater1_output_percent(RegIndex.kreg_tec103_heater1_output_percent),
kreg_tec103_heater1_pwm_freq(RegIndex.kreg_tec103_heater1_pwm_freq),
kreg_tec103_heater1_over_temp_protect_mode(RegIndex.kreg_tec103_heater1_over_temp_protect_mode),
kreg_tec103_heater1_p(RegIndex.kreg_tec103_heater1_p),
kreg_tec103_heater1_i(RegIndex.kreg_tec103_heater1_i),
kreg_tec103_heater1_d(RegIndex.kreg_tec103_heater1_d),
kreg_tec103_heater1_pid_self_tune(RegIndex.kreg_tec103_heater1_pid_self_tune),
kreg_tec103_heater_version(RegIndex.kreg_tec103_heater_version),
kreg_tec103_heater_address(RegIndex.kreg_tec103_heater_address),
kreg_tec103_heater_baud_rate(RegIndex.kreg_tec103_heater_baud_rate),
kreg_tec103_heater_e_code(RegIndex.kreg_tec103_heater_e_code),
;
public final RegIndex regIndex;
TecHeaterRegIndex(RegIndex regIndex) {
this.regIndex = regIndex;
}
}

16
src/main/java/com/iflytop/colortitration/hardware/type/TecHeaterRodMId.java

@ -0,0 +1,16 @@
package com.iflytop.colortitration.hardware.type;
import org.springframework.util.Assert;
public enum TecHeaterRodMId {
HeaterRod1(MId.HeaterRod1),
HeaterRod2(MId.HeaterRod2),
;
final public MId mid;
TecHeaterRodMId(MId mid) {
Assert.isTrue(this.name().equals(mid.name()), "IO1_ChimeBuzzer Init fail");
this.mid = mid;
}
}
Loading…
Cancel
Save