diff --git a/src/main/java/a8k/app/hardware/driver/PipetteCtrlDriverV2.java b/src/main/java/a8k/app/hardware/driver/PipetteCtrlDriverV2.java index 9548910..5eb341b 100644 --- a/src/main/java/a8k/app/hardware/driver/PipetteCtrlDriverV2.java +++ b/src/main/java/a8k/app/hardware/driver/PipetteCtrlDriverV2.java @@ -367,195 +367,59 @@ public class PipetteCtrlDriverV2 { canBus.waitForMod(MId.PipetteMod, actionOvertimeConstant.get(MId.PipetteMod, action)); } + + // // Config // + public void applyLiquidInfo(LiquidConfigCpyIdx cpyIdx, PipetteLiquidInfo val) throws AppException { + val.serialization((index, itermVal) -> setLiquidInfo(cpyIdx.toInteger(), index, itermVal)); + } + + public PipetteLiquidInfo getLiquidInfo(LiquidConfigCpyIdx cpyIdx) throws AppException { + return PipetteLiquidInfo.build((LiquidInfoIndex index) -> getLiquidInfo(cpyIdx.toInteger(), index)); + } + public void applyPlatInfo(Integer cpyIdx, PipettePlatInfo val) throws AppException { - setPlatInfo(cpyIdx, PlatformInfoIndex.workRefPos, val.workRefPos); - setPlatInfo(cpyIdx, PlatformInfoIndex.tipPickingPos, val.tipPickingPos); - setPlatInfo(cpyIdx, PlatformInfoIndex.tipPickingSearchRange, val.tipPickingSearchRange); - setPlatInfo(cpyIdx, PlatformInfoIndex.tipPickingAppendDistance, val.tipPickingAppendDistance); - setPlatInfo(cpyIdx, PlatformInfoIndex.tipDepositPos, val.tipDepositPos); - setPlatInfo(cpyIdx, PlatformInfoIndex.transformPos, val.transformPos); - setPlatInfo(cpyIdx, PlatformInfoIndex.tipType, val.tipType); - setPlatInfo(cpyIdx, PlatformInfoIndex.tipLength, val.tipLength); + val.serialization((index, itermVal) -> setPlatInfo(cpyIdx, index, itermVal)); } public PipettePlatInfo getPlatInfo(Integer cpyIdx) throws AppException { - PipettePlatInfo val = new PipettePlatInfo(); - val.workRefPos = getPlatInfo(cpyIdx, PlatformInfoIndex.workRefPos); - val.tipPickingPos = getPlatInfo(cpyIdx, PlatformInfoIndex.tipPickingPos); - val.tipPickingSearchRange = getPlatInfo(cpyIdx, PlatformInfoIndex.tipPickingSearchRange); - val.tipPickingAppendDistance = getPlatInfo(cpyIdx, PlatformInfoIndex.tipPickingAppendDistance); - val.tipDepositPos = getPlatInfo(cpyIdx, PlatformInfoIndex.tipDepositPos); - val.transformPos = getPlatInfo(cpyIdx, PlatformInfoIndex.transformPos); - val.tipType = getPlatInfo(cpyIdx, PlatformInfoIndex.tipType); - val.tipLength = getPlatInfo(cpyIdx, PlatformInfoIndex.tipLength); - val.mark = getPlatInfo(cpyIdx, PlatformInfoIndex.mark); - return val; + return PipettePlatInfo.build((PlatformInfoIndex index) -> getPlatInfo(cpyIdx, index)); } public void applyContainerInfo(ContainerCpyId cpyIdx, PipetteContainerInfo val) throws AppException { - setContainerInfo(cpyIdx, ContainerInfoIndex.containerType, val.containerType); - setContainerInfo(cpyIdx, ContainerInfoIndex.containerNeckPos, val.containerNeckPos); - setContainerInfo(cpyIdx, ContainerInfoIndex.containerDepth, val.containerDepth); - setContainerInfo(cpyIdx, ContainerInfoIndex.containerRound, val.containerRound); - setContainerInfo(cpyIdx, ContainerInfoIndex.containerBottomSectionHeight, val.containerBottomSectionHeight); - setContainerInfo(cpyIdx, ContainerInfoIndex.immersionDepth, val.immersionDepth); - setContainerInfo(cpyIdx, ContainerInfoIndex.leavingHeight, val.leavingHeight); - setContainerInfo(cpyIdx, ContainerInfoIndex.jetHeight, val.jetHeight); - setContainerInfo(cpyIdx, ContainerInfoIndex.lldStartSearchDepth, val.lldStartSearchDepth); - setContainerInfo(cpyIdx, ContainerInfoIndex.fixAspirationDepth, val.fixAspirationDepth); - setContainerInfo(cpyIdx, ContainerInfoIndex.llfVConvertCoefficient, val.llfVConvertCoefficient); - setContainerInfo(cpyIdx, ContainerInfoIndex.pierceDepth, val.pierceDepth); + val.serialization((index, itermVal) -> setContainerInfo(cpyIdx.toInteger(), index, itermVal)); } public PipetteContainerInfo getContainerInfo(ContainerCpyId cpyIdx) throws AppException { - PipetteContainerInfo val = new PipetteContainerInfo(); - val.containerType = getContainerInfo(cpyIdx, ContainerInfoIndex.containerType); - val.containerNeckPos = getContainerInfo(cpyIdx, ContainerInfoIndex.containerNeckPos); - val.containerDepth = getContainerInfo(cpyIdx, ContainerInfoIndex.containerDepth); - val.containerRound = getContainerInfo(cpyIdx, ContainerInfoIndex.containerRound); - val.containerBottomSectionHeight = getContainerInfo(cpyIdx, ContainerInfoIndex.containerBottomSectionHeight); - val.immersionDepth = getContainerInfo(cpyIdx, ContainerInfoIndex.immersionDepth); - val.leavingHeight = getContainerInfo(cpyIdx, ContainerInfoIndex.leavingHeight); - val.jetHeight = getContainerInfo(cpyIdx, ContainerInfoIndex.jetHeight); - val.lldStartSearchDepth = getContainerInfo(cpyIdx, ContainerInfoIndex.lldStartSearchDepth); - val.fixAspirationDepth = getContainerInfo(cpyIdx, ContainerInfoIndex.fixAspirationDepth); - val.llfVConvertCoefficient = getContainerInfo(cpyIdx, ContainerInfoIndex.llfVConvertCoefficient); - val.pierceDepth = getContainerInfo(cpyIdx, ContainerInfoIndex.pierceDepth); - val.mark = getContainerInfo(cpyIdx, ContainerInfoIndex.mark); - return val; + return PipetteContainerInfo.build((ContainerInfoIndex index) -> getContainerInfo(cpyIdx.toInteger(), index)); } - public void applyLiquidInfo(LiquidConfigCpyIdx cpyIdx, PipetteLiquidInfo val) throws AppException { - setLiquidInfo(cpyIdx, LiquidInfoIndex.plldPmVCpyId, val.plldPmVCpyId); - setLiquidInfo(cpyIdx, LiquidInfoIndex.plldThreshold, val.plldThreshold); - setLiquidInfo(cpyIdx, LiquidInfoIndex.plldZmVel, val.plldZmVel); - setLiquidInfo(cpyIdx, LiquidInfoIndex.emptyTipPmVCpyId, val.emptyTipPmVCpyId); - setLiquidInfo(cpyIdx, LiquidInfoIndex.blowoutAirVolume, val.blowoutAirVolume); - setLiquidInfo(cpyIdx, LiquidInfoIndex.blowoutAirPmVCpyId, val.blowoutAirPmVCpyId); - setLiquidInfo(cpyIdx, LiquidInfoIndex.overAspiratedVolume, val.overAspiratedVolume); - setLiquidInfo(cpyIdx, LiquidInfoIndex.overAspiratedPmVCpyId, val.overAspiratedPmVCpyId); - setLiquidInfo(cpyIdx, LiquidInfoIndex.aspirationPmVCpyIdLow, val.aspirationPmVCpyIdLow); - setLiquidInfo(cpyIdx, LiquidInfoIndex.aspirationPmVCpyIdHigh, val.aspirationPmVCpyIdHigh); - setLiquidInfo(cpyIdx, LiquidInfoIndex.aspirationVolumeBreakVal, val.aspirationVolumeBreakVal); - setLiquidInfo(cpyIdx, LiquidInfoIndex.volumeCalibrationCoefficientB, val.volumeCalibrationCoefficientB); - setLiquidInfo(cpyIdx, LiquidInfoIndex.volumeCalibrationCoefficientK, val.volumeCalibrationCoefficientK); - setLiquidInfo(cpyIdx, LiquidInfoIndex.settlingTime, val.settlingTime); - setLiquidInfo(cpyIdx, LiquidInfoIndex.transportVolume, val.transportVolume); - setLiquidInfo(cpyIdx, LiquidInfoIndex.transportVolumePmVCpyId, val.transportVolumePmVCpyId); - setLiquidInfo(cpyIdx, LiquidInfoIndex.mixPmVCpyId, val.mixPmVCpyId); - } - - public PipetteLiquidInfo getLiquidInfo(LiquidConfigCpyIdx cpyIdx) throws AppException { - PipetteLiquidInfo val = new PipetteLiquidInfo(); - val.plldPmVCpyId = getLiquidInfo(cpyIdx, LiquidInfoIndex.plldPmVCpyId); - val.plldThreshold = getLiquidInfo(cpyIdx, LiquidInfoIndex.plldThreshold); - val.plldZmVel = getLiquidInfo(cpyIdx, LiquidInfoIndex.plldZmVel); - val.emptyTipPmVCpyId = getLiquidInfo(cpyIdx, LiquidInfoIndex.emptyTipPmVCpyId); - val.blowoutAirVolume = getLiquidInfo(cpyIdx, LiquidInfoIndex.blowoutAirVolume); - val.blowoutAirPmVCpyId = getLiquidInfo(cpyIdx, LiquidInfoIndex.blowoutAirPmVCpyId); - val.overAspiratedVolume = getLiquidInfo(cpyIdx, LiquidInfoIndex.overAspiratedVolume); - val.overAspiratedPmVCpyId = getLiquidInfo(cpyIdx, LiquidInfoIndex.overAspiratedPmVCpyId); - val.aspirationPmVCpyIdLow = getLiquidInfo(cpyIdx, LiquidInfoIndex.aspirationPmVCpyIdLow); - val.aspirationPmVCpyIdHigh = getLiquidInfo(cpyIdx, LiquidInfoIndex.aspirationPmVCpyIdHigh); - val.aspirationVolumeBreakVal = getLiquidInfo(cpyIdx, LiquidInfoIndex.aspirationVolumeBreakVal); - val.volumeCalibrationCoefficientB = getLiquidInfo(cpyIdx, LiquidInfoIndex.volumeCalibrationCoefficientB); - val.volumeCalibrationCoefficientK = getLiquidInfo(cpyIdx, LiquidInfoIndex.volumeCalibrationCoefficientK); - val.settlingTime = getLiquidInfo(cpyIdx, LiquidInfoIndex.settlingTime); - val.transportVolume = getLiquidInfo(cpyIdx, LiquidInfoIndex.transportVolume); - val.transportVolumePmVCpyId = getLiquidInfo(cpyIdx, LiquidInfoIndex.transportVolumePmVCpyId); - val.mixPmVCpyId = getLiquidInfo(cpyIdx, LiquidInfoIndex.mixPmVCpyId); - val.mark = getLiquidInfo(cpyIdx, LiquidInfoIndex.mark); - return val; - } public void setPMVCfg(PMVCpyIdx idx, PipettePMVCfg val) throws AppException { - setPMVCfg(idx, PMVConfigIndex.acc, val.acc); - setPMVCfg(idx, PMVConfigIndex.dec, val.dec); - setPMVCfg(idx, PMVConfigIndex.vStart, val.vStart); - setPMVCfg(idx, PMVConfigIndex.vStop, val.vStop); - setPMVCfg(idx, PMVConfigIndex.vMax, val.vMax); - + val.serialization((index, itermVal) -> setPMVCfg(idx, index, itermVal)); } public PipettePMVCfg getPMVCfg(PMVCpyIdx idx) throws AppException { - PipettePMVCfg val = new PipettePMVCfg(); - val.acc = getPMVCfg(idx, PMVConfigIndex.acc); - val.dec = getPMVCfg(idx, PMVConfigIndex.dec); - val.vStart = getPMVCfg(idx, PMVConfigIndex.vStart); - val.vStop = getPMVCfg(idx, PMVConfigIndex.vStop); - val.vMax = getPMVCfg(idx, PMVConfigIndex.vMax); - val.mark = getPMVCfg(idx, PMVConfigIndex.mark); - return val; + return PipettePMVCfg.build((PMVConfigIndex index) -> getPMVCfg(idx, index)); } public void setZMBCfg(PipetteZMBCfg val) throws AppException { - setZMBCfg(ZMBasicConfigIndex.shaft, val.shaft); - setZMBCfg(ZMBasicConfigIndex.oneCirclePulse, val.oneCirclePulse); - setZMBCfg(ZMBasicConfigIndex.oneCirclePulseDenominator, val.oneCirclePulseDenominator); - setZMBCfg(ZMBasicConfigIndex.ihold, val.ihold); - setZMBCfg(ZMBasicConfigIndex.irun, val.irun); - setZMBCfg(ZMBasicConfigIndex.iholddelay, val.iholddelay); - setZMBCfg(ZMBasicConfigIndex.iglobalscaler, val.iglobalscaler); - setZMBCfg(ZMBasicConfigIndex.mind, val.minD); - setZMBCfg(ZMBasicConfigIndex.maxd, val.maxD); - setZMBCfg(ZMBasicConfigIndex.tzerowait, val.tzerowait); - setZMBCfg(ZMBasicConfigIndex.encResolution, val.encResolution); - setZMBCfg(ZMBasicConfigIndex.enableEnc, val.enableEnc); - setZMBCfg(ZMBasicConfigIndex.dzero, val.dzero); - setZMBCfg(ZMBasicConfigIndex.ioTriggerAppendDistance, val.ioTriggerAppendDistance); - setZMBCfg(ZMBasicConfigIndex.posDeviTolerance, val.posDeviTolerance); - setZMBCfg(ZMBasicConfigIndex.mres, val.mres); + val.serialization(this::setZMBCfg); } public PipetteZMBCfg getZMBCfg() throws AppException { - PipetteZMBCfg val = new PipetteZMBCfg(); - val.shaft = getZMBCfg(ZMBasicConfigIndex.shaft); - val.oneCirclePulse = getZMBCfg(ZMBasicConfigIndex.oneCirclePulse); - val.oneCirclePulseDenominator = getZMBCfg(ZMBasicConfigIndex.oneCirclePulseDenominator); - val.ihold = getZMBCfg(ZMBasicConfigIndex.ihold); - val.irun = getZMBCfg(ZMBasicConfigIndex.irun); - val.iholddelay = getZMBCfg(ZMBasicConfigIndex.iholddelay); - val.iglobalscaler = getZMBCfg(ZMBasicConfigIndex.iglobalscaler); - val.minD = getZMBCfg(ZMBasicConfigIndex.mind); - val.maxD = getZMBCfg(ZMBasicConfigIndex.maxd); - val.tzerowait = getZMBCfg(ZMBasicConfigIndex.tzerowait); - val.encResolution = getZMBCfg(ZMBasicConfigIndex.encResolution); - val.enableEnc = getZMBCfg(ZMBasicConfigIndex.enableEnc); - val.dzero = getZMBCfg(ZMBasicConfigIndex.dzero); - val.ioTriggerAppendDistance = getZMBCfg(ZMBasicConfigIndex.ioTriggerAppendDistance); - val.posDeviTolerance = getZMBCfg(ZMBasicConfigIndex.posDeviTolerance); - val.mres = getZMBCfg(ZMBasicConfigIndex.mres); - val.mark = getZMBCfg(ZMBasicConfigIndex.mark); - return val; + return PipetteZMBCfg.build(this::getZMBCfg); } public void setZMVCfg(ZMVCpyIdx idx, PipetteZMVCfg val) throws AppException { - setZMVCfg(idx, ZMVConfigIndex.vstart, val.vstart); - setZMVCfg(idx, ZMVConfigIndex.a1, val.a1); - setZMVCfg(idx, ZMVConfigIndex.amax, val.amax); - setZMVCfg(idx, ZMVConfigIndex.v1, val.v1); - setZMVCfg(idx, ZMVConfigIndex.dmax, val.dmax); - setZMVCfg(idx, ZMVConfigIndex.d1, val.d1); - setZMVCfg(idx, ZMVConfigIndex.vstop, val.vstop); - setZMVCfg(idx, ZMVConfigIndex.vmax, val.vmax); + val.serialization((index, itermVal) -> setZMVCfg(idx, index, itermVal)); } public PipetteZMVCfg getZMVCfg(ZMVCpyIdx idx) throws AppException { - PipetteZMVCfg val = new PipetteZMVCfg(); - val.vstart = getZMVCfg(idx, ZMVConfigIndex.vstart); - val.a1 = getZMVCfg(idx, ZMVConfigIndex.a1); - val.amax = getZMVCfg(idx, ZMVConfigIndex.amax); - val.v1 = getZMVCfg(idx, ZMVConfigIndex.v1); - val.dmax = getZMVCfg(idx, ZMVConfigIndex.dmax); - val.d1 = getZMVCfg(idx, ZMVConfigIndex.d1); - val.vstop = getZMVCfg(idx, ZMVConfigIndex.vstop); - val.vmax = getZMVCfg(idx, ZMVConfigIndex.vmax); - val.mark = getZMVCfg(idx, ZMVConfigIndex.mark); - return val; + return PipetteZMVCfg.build((ZMVConfigIndex index) -> getZMVCfg(idx, index)); } public PipetteConfig getConfig() throws AppException { diff --git a/src/main/java/a8k/app/hardware/type/pipette_module/cfg/LiquidInfoIndex.java b/src/main/java/a8k/app/hardware/type/pipette_module/cfg/LiquidInfoIndex.java index ff0f769..d0e8809 100644 --- a/src/main/java/a8k/app/hardware/type/pipette_module/cfg/LiquidInfoIndex.java +++ b/src/main/java/a8k/app/hardware/type/pipette_module/cfg/LiquidInfoIndex.java @@ -60,8 +60,13 @@ public enum LiquidInfoIndex { // // 混匀pm速率 // // mixPmVCpyId, // 混匀时泵机速率配置 + // + // 分配配置 + // + jetPmVCpyId, // 喷射时泵机速率配置 jet_pm_vcpyid + distributePmVCpyId, // 分配时泵机速率配置 distribu_pm_vpyid mark, - ; + ; public Integer toInteger() { return ordinal(); diff --git a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteContainerInfo.java b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteContainerInfo.java index 2333f21..b716f01 100644 --- a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteContainerInfo.java +++ b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteContainerInfo.java @@ -1,5 +1,10 @@ package a8k.app.hardware.type.pipette_module.cfgbean; +import a8k.app.hardware.type.pipette_module.cfg.ContainerInfoIndex; +import a8k.app.type.exception.AppException; + +import java.lang.reflect.Field; + public class PipetteContainerInfo { public Integer containerType = 0; // 容器类型 0:平面 1:flat(平底) 2:conical(锥底) 3:round(圆底) public Integer containerNeckPos = 0; // 容器,瓶口位置(相对位置0.1mm) !discard 废弃不再使用 @@ -14,4 +19,53 @@ public class PipetteContainerInfo { public Integer llfVConvertCoefficient = 0; // 液面跟随转换系数 0.0001 llf_zm_vel = aspiration_pm_vel * llf_vconvert_coneff * 0.0001 public Integer pierceDepth = 0; // 穿刺深度(0.1mm),用于刺破容器防尘膜 public Integer mark = 0; // 结构体最后一个数值,设置9973,用于保证单片机端和java端均正确更新了枚举 + + + @FunctionalInterface + public interface AssignObjectItemFn { + Integer assignVal(ContainerInfoIndex index) throws AppException; + } + + @FunctionalInterface + public interface SerializationObjectItemFn { + void serializeObject(ContainerInfoIndex index, Integer itermVal) throws AppException; + } + + public static PipetteContainerInfo build(AssignObjectItemFn assignFn) throws AppException { + PipetteContainerInfo info = new PipetteContainerInfo(); + info.assignObject(assignFn); + return info; + } + + public void assignObject(AssignObjectItemFn assignFn) throws AppException { + for (ContainerInfoIndex idx : ContainerInfoIndex.values()) { + try { + PipetteContainerInfo.class.getDeclaredField(idx.name()).set(this, assignFn.assignVal(idx)); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + } + + + public void serialization(SerializationObjectItemFn fn) throws AppException { + for (ContainerInfoIndex idx : ContainerInfoIndex.values()) { + try { + Integer val = (Integer) PipetteContainerInfo.class.getDeclaredField(idx.name()).get(this); + fn.serializeObject(idx, val); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + public static void main(String[] args) throws AppException { + PipetteContainerInfo info = new PipetteContainerInfo(); + info.assignObject(Enum::ordinal); + + info.serialization((index, val) -> { + System.out.println("Index: " + index + ", Value: " + val); + }); + } + } diff --git a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteLiquidInfo.java b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteLiquidInfo.java index 41d4dca..21821c1 100644 --- a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteLiquidInfo.java +++ b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteLiquidInfo.java @@ -1,6 +1,13 @@ package a8k.app.hardware.type.pipette_module.cfgbean; +import a8k.app.hardware.type.pipette_module.cfg.LiquidInfoIndex; +import a8k.app.type.exception.AppException; + +import java.lang.reflect.Field; + public class PipetteLiquidInfo { + + /** * @brief * @@ -82,6 +89,61 @@ public class PipetteLiquidInfo { // // 混匀pm速率 // - public Integer mixPmVCpyId = 0; // 混匀时泵机速率配置 - public Integer mark = 0; // 结构体最后一个数值,设置9973,用于保证单片机端和java端均正确更新了枚举 + public Integer mixPmVCpyId = 0; // 混匀时泵机速率配置 + // + // 分配配置 + // + public Integer jetPmVCpyId = 0; // 喷射时泵机速率配置 jet_pm_vcpyid + public Integer distributePmVCpyId = 0; // 分配时泵机速率配置 distribu_pm_vpyid + + public Integer mark = 0; // 结构体最后一个数值,设置9973,用于保证单片机端和java端均正确更新了枚举 + + + @FunctionalInterface + public interface AssignObjectItemFn { + Integer assignVal(LiquidInfoIndex index) throws AppException; + } + + @FunctionalInterface + public interface SerializationObjectItemFn { + void serializeObject(LiquidInfoIndex index, Integer itermVal) throws AppException; + } + + + public static PipetteLiquidInfo build(AssignObjectItemFn assignFn) throws AppException { + PipetteLiquidInfo info = new PipetteLiquidInfo(); + info.assignObject(assignFn); + return info; + } + + public void assignObject(AssignObjectItemFn assignFn) throws AppException { + for (LiquidInfoIndex idx : LiquidInfoIndex.values()) { + try { + PipetteLiquidInfo.class.getDeclaredField(idx.name()).set(this, assignFn.assignVal(idx)); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + } + + public void serialization(SerializationObjectItemFn fn) throws AppException { + for (LiquidInfoIndex idx : LiquidInfoIndex.values()) { + try { + Integer val = (Integer) PipetteLiquidInfo.class.getDeclaredField(idx.name()).get(this); + fn.serializeObject(idx, val); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + public static void main(String[] args) throws AppException { + PipetteLiquidInfo info = new PipetteLiquidInfo(); + info.assignObject(Enum::ordinal); + + info.serialization((index, val) -> { + System.out.println("Index: " + index + ", Value: " + val); + }); + } + } diff --git a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipettePMVCfg.java b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipettePMVCfg.java index d8a6900..46c0ce3 100644 --- a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipettePMVCfg.java +++ b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipettePMVCfg.java @@ -1,5 +1,10 @@ package a8k.app.hardware.type.pipette_module.cfgbean; +import a8k.app.hardware.type.pipette_module.cfg.PMVConfigIndex; +import a8k.app.type.exception.AppException; + +import java.lang.reflect.Field; + public class PipettePMVCfg { public Integer acc = 0; public Integer dec = 0; @@ -7,4 +12,51 @@ public class PipettePMVCfg { public Integer vStop = 0; public Integer vMax = 0; public Integer mark = 0; // 结构体最后一个数值,设置9973,用于保证单片机端和java端均正确更新了枚举 + + + @FunctionalInterface + public interface AssignObjectItemFn { + Integer assignVal(PMVConfigIndex index) throws AppException; + } + + @FunctionalInterface + public interface SerializationObjectItemFn { + void serializeObject(PMVConfigIndex index, Integer itermVal) throws AppException; + } + + public static PipettePMVCfg build(AssignObjectItemFn assignFn) throws AppException { + PipettePMVCfg info = new PipettePMVCfg(); + info.assignObject(assignFn); + return info; + } + + public void assignObject(AssignObjectItemFn assignFn) throws AppException { + for (PMVConfigIndex idx : PMVConfigIndex.values()) { + try { + PipettePMVCfg.class.getDeclaredField(idx.name()).set(this, assignFn.assignVal(idx)); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + } + + public void serialization(SerializationObjectItemFn fn) throws AppException { + for (PMVConfigIndex idx : PMVConfigIndex.values()) { + try { + Integer val = (Integer) PipettePMVCfg.class.getDeclaredField(idx.name()).get(this); + fn.serializeObject(idx, val); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + public static void main(String[] args) throws AppException { + PipettePMVCfg info = new PipettePMVCfg(); + info.assignObject(Enum::ordinal); + + info.serialization((index, val) -> { + System.out.println("Index: " + index + ", Value: " + val); + }); + } } diff --git a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipettePlatInfo.java b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipettePlatInfo.java index 5242b6c..8b35580 100644 --- a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipettePlatInfo.java +++ b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipettePlatInfo.java @@ -1,5 +1,10 @@ package a8k.app.hardware.type.pipette_module.cfgbean; +import a8k.app.hardware.type.pipette_module.cfg.PlatformInfoIndex; +import a8k.app.type.exception.AppException; + +import java.lang.reflect.Field; + public class PipettePlatInfo { /** * @brief 工作参考平面 @@ -27,4 +32,52 @@ public class PipettePlatInfo { public Integer tipLength = 0; // tip长度 public Integer mark = 0; // 结构体最后一个数值,设置9973,用于保证单片机端和java端均正确更新了枚举 + + + @FunctionalInterface + public interface AssignObjectItemFn { + Integer assignVal(PlatformInfoIndex index) throws AppException; + } + + @FunctionalInterface + public interface SerializationObjectItemFn { + void serializeObject(PlatformInfoIndex index, Integer itermVal) throws AppException; + } + + public static PipettePlatInfo build(AssignObjectItemFn assignFn) throws AppException { + PipettePlatInfo info = new PipettePlatInfo(); + info.assignObject(assignFn); + return info; + } + + public void assignObject(AssignObjectItemFn assignFn) throws AppException { + for (PlatformInfoIndex idx : PlatformInfoIndex.values()) { + try { + PipettePlatInfo.class.getDeclaredField(idx.name()).set(this, assignFn.assignVal(idx)); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + } + + public void serialization(SerializationObjectItemFn fn) throws AppException { + for (PlatformInfoIndex idx : PlatformInfoIndex.values()) { + try { + Integer val = (Integer) PipettePlatInfo.class.getDeclaredField(idx.name()).get(this); + fn.serializeObject(idx, val); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + public static void main(String[] args) throws AppException { + PipettePlatInfo info = new PipettePlatInfo(); + info.assignObject(Enum::ordinal); + + info.serialization((index, val) -> { + System.out.println("Index: " + index + ", Value: " + val); + }); + } + } diff --git a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteZMBCfg.java b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteZMBCfg.java index 99baec1..5287c2e 100644 --- a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteZMBCfg.java +++ b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteZMBCfg.java @@ -1,5 +1,8 @@ package a8k.app.hardware.type.pipette_module.cfgbean; +import a8k.app.hardware.type.pipette_module.cfg.ZMBasicConfigIndex; +import a8k.app.type.exception.AppException; + public class PipetteZMBCfg { public Integer shaft = 0; // Z轴电机运动方向调整 public Integer oneCirclePulse = 0; // 电子齿轮比-分子 @@ -8,8 +11,8 @@ public class PipetteZMBCfg { public Integer irun = 0; // public Integer iholddelay = 0; // public Integer iglobalscaler = 0; // - public Integer minD = 0; // - public Integer maxD = 0; // + public Integer mind = 0; // + public Integer maxd = 0; // public Integer tzerowait = 0; // public Integer encResolution = 0; // public Integer enableEnc = 0; // @@ -18,4 +21,52 @@ public class PipetteZMBCfg { public Integer posDeviTolerance = 0; // public Integer mres = 0; // public Integer mark = 0; // 结构体最后一个数值,设置9973,用于保证单片机端和java端均正确更新了枚举 + + + @FunctionalInterface + public interface AssignObjectItemFn { + Integer assignVal(ZMBasicConfigIndex index) throws AppException; + } + + @FunctionalInterface + public interface SerializationObjectItemFn { + void serializeObject(ZMBasicConfigIndex index, Integer itermVal) throws AppException; + } + + public static PipetteZMBCfg build(AssignObjectItemFn assignFn) throws AppException { + PipetteZMBCfg info = new PipetteZMBCfg(); + info.assignObject(assignFn); + return info; + } + + public void assignObject(AssignObjectItemFn assignFn) throws AppException { + for (ZMBasicConfigIndex idx : ZMBasicConfigIndex.values()) { + try { + PipetteZMBCfg.class.getDeclaredField(idx.name()).set(this, assignFn.assignVal(idx)); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + } + + + public void serialization(SerializationObjectItemFn fn) throws AppException { + for (ZMBasicConfigIndex idx : ZMBasicConfigIndex.values()) { + try { + Integer val = (Integer) PipetteZMBCfg.class.getDeclaredField(idx.name()).get(this); + fn.serializeObject(idx, val); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + public static void main(String[] args) throws AppException { + PipetteZMBCfg info = new PipetteZMBCfg(); + info.assignObject(Enum::ordinal); + + info.serialization((index, val) -> { + System.out.println("Index: " + index + ", Value: " + val); + }); + } } diff --git a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteZMVCfg.java b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteZMVCfg.java index 0792e0d..bc32672 100644 --- a/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteZMVCfg.java +++ b/src/main/java/a8k/app/hardware/type/pipette_module/cfgbean/PipetteZMVCfg.java @@ -1,5 +1,8 @@ package a8k.app.hardware.type.pipette_module.cfgbean; +import a8k.app.hardware.type.pipette_module.cfg.ZMVConfigIndex; +import a8k.app.type.exception.AppException; + public class PipetteZMVCfg { public Integer vstart = 0; public Integer a1 = 0; @@ -10,4 +13,52 @@ public class PipetteZMVCfg { public Integer vstop = 0; public Integer vmax = 0; public Integer mark = 0; // 结构体最后一个数值,设置9973,用于保证单片机端和java端均正确更新了枚举 + + + @FunctionalInterface + public interface AssignObjectItemFn { + Integer assignVal(ZMVConfigIndex index) throws AppException; + } + + @FunctionalInterface + public interface SerializationObjectItemFn { + void serializeObject(ZMVConfigIndex index, Integer itermVal) throws AppException; + } + + public static PipetteZMVCfg build(AssignObjectItemFn assignFn) throws AppException { + PipetteZMVCfg info = new PipetteZMVCfg(); + info.assignObject(assignFn); + return info; + } + + + public void assignObject(AssignObjectItemFn assignFn) throws AppException { + for (ZMVConfigIndex idx : ZMVConfigIndex.values()) { + try { + PipetteZMVCfg.class.getDeclaredField(idx.name()).set(this, assignFn.assignVal(idx)); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } + } + + public void serialization(SerializationObjectItemFn fn) throws AppException { + for (ZMVConfigIndex idx : ZMVConfigIndex.values()) { + try { + Integer val = (Integer) PipetteZMVCfg.class.getDeclaredField(idx.name()).get(this); + fn.serializeObject(idx, val); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + public static void main(String[] args) throws AppException { + PipetteZMVCfg info = new PipetteZMVCfg(); + info.assignObject(Enum::ordinal); + + info.serialization((index, val) -> { + System.out.println("Index: " + index + ", Value: " + val); + }); + } }