From efb04282287bde53c07078fa6275fb14e273fd84 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 9 Sep 2024 09:46:52 +0800 Subject: [PATCH] recode --- src/main/java/a8k/algo/opt_algo/A8kOptAlgo.java | 81 -- src/main/java/a8k/appbase/A8kScanCurve.java | 17 - src/main/java/a8k/appbase/ConsumableGroup.java | 12 - src/main/java/a8k/appbase/HardwareException.java | 63 -- src/main/java/a8k/appbase/IncubatorPos.java | 10 - src/main/java/a8k/appbase/OptScanDirection.java | 9 - src/main/java/a8k/appbase/PlateInfo.java | 23 - src/main/java/a8k/appbase/ProjectInfoSimple.java | 21 - src/main/java/a8k/appbase/SampleTubeState.java | 8 - .../a8k/appbase/TargetPosMeasureDirection.java | 5 - src/main/java/a8k/appbase/appret/AppRet.java | 152 ---- src/main/java/a8k/appbase/appret/AppRetType.java | 8 - .../java/a8k/appbase/cfg/BottleGroupsPosInfo.java | 85 -- src/main/java/a8k/appbase/cfg/BottlesPosInfo.java | 43 - src/main/java/a8k/appbase/cfg/HbotLimitArea.java | 36 - src/main/java/a8k/appbase/cfg/KeyValType.java | 24 - .../java/a8k/appbase/cfg/LargeBottleBufferPos.java | 65 -- src/main/java/a8k/appbase/cfg/PipetteCfg.java | 10 - .../java/a8k/appbase/cfg/Plates2dCodeScanPos.java | 23 - src/main/java/a8k/appbase/cfg/Pos2d.java | 22 - src/main/java/a8k/appbase/cfg/Pos3d.java | 24 - src/main/java/a8k/appbase/cfg/SampleZPosInfo.java | 17 - .../java/a8k/appbase/cfg/TipPickUpPosInfo.java | 78 -- src/main/java/a8k/appbase/cfg/TubeSamplePos.java | 15 - .../java/a8k/appbase/ecode/AppRetEcodeInfo.java | 89 --- .../java/a8k/appbase/sampleinfo/SampleInfo.java | 12 - src/main/java/a8k/appbase/type/A8kTubeType.java | 17 - src/main/java/a8k/appbase/type/BloodType.java | 6 - .../appeventbus/AppEventBusService.java | 69 ++ .../baseservice/appeventbus/AppEventListener.java | 7 + .../appevent/A8kCanBusOnConnectEvent.java | 7 + .../appeventbus/appevent/A8kHardwareReport.java | 23 + .../appeventbus/appevent/A8kStateChangeEvent.java | 8 + .../baseservice/appeventbus/appevent/AppEvent.java | 8 + .../appeventbus/appevent/AppStepNotifyEvent.java | 15 + .../appevent/AppWarningNotifyEvent.java | 15 + .../appevent/NewAppIDCardDetectEvent.java | 26 + src/main/java/a8k/db/AppSetting.java | 203 ----- src/main/java/a8k/db/AppUser.java | 44 - src/main/java/a8k/db/DBTableVersion.java | 38 - src/main/java/a8k/db/HardwareServiceSetting.java | 89 --- src/main/java/a8k/db/LanguageDictIterm.java | 18 - src/main/java/a8k/db/MdbOption.java | 84 -- src/main/java/a8k/db/ProjectColor.java | 19 - src/main/java/a8k/db/ProjectInfo.java | 211 ----- src/main/java/a8k/dbservice/AppSetting.java | 203 +++++ src/main/java/a8k/dbservice/AppUser.java | 44 + src/main/java/a8k/dbservice/DBTableVersion.java | 38 + .../java/a8k/dbservice/HardwareServiceSetting.java | 89 +++ src/main/java/a8k/dbservice/LanguageDictIterm.java | 18 + src/main/java/a8k/dbservice/MdbOption.java | 84 ++ src/main/java/a8k/dbservice/ProjectColor.java | 19 + src/main/java/a8k/dbservice/ProjectInfo.java | 211 +++++ src/main/java/a8k/hardware/A8kCanBusService.java | 888 +++++++++++++++++++++ .../java/a8k/hardware/A8kModParamInitializer.java | 127 +++ .../custom_param_mgr/A8kModCustomParam.java | 10 + .../custom_param_mgr/A8kModCustomParamMgr.java | 35 + .../custom_param_mgr/ModCustomParamId.java | 14 + .../java/a8k/hardware/type/PipetteSampleData.java | 7 + .../service/appeventbus/AppEventBusService.java | 69 -- .../a8k/service/appeventbus/AppEventListener.java | 7 - .../appevent/A8kCanBusOnConnectEvent.java | 7 - .../appeventbus/appevent/A8kHardwareReport.java | 23 - .../appeventbus/appevent/A8kStateChangeEvent.java | 8 - .../a8k/service/appeventbus/appevent/AppEvent.java | 8 - .../appeventbus/appevent/AppStepNotifyEvent.java | 15 - .../appevent/AppWarningNotifyEvent.java | 15 - .../appevent/NewAppIDCardDetectEvent.java | 26 - .../service/hardware/canbus/A8kCanBusService.java | 888 --------------------- .../hardware/canbus/A8kModParamInitializer.java | 127 --- .../canbus/custom_param_mgr/A8kModCustomParam.java | 10 - .../custom_param_mgr/A8kModCustomParamMgr.java | 35 - .../canbus/custom_param_mgr/ModCustomParamId.java | 14 - .../hardware/canbus/data/PipetteSampleData.java | 7 - .../service/hardware/canbus/protocol/A8kEcode.java | 167 ---- .../hardware/canbus/protocol/A8kPacket.java | 161 ---- .../service/hardware/canbus/protocol/CmdId.java | 202 ----- .../a8k/service/hardware/canbus/protocol/IOId.java | 38 - .../a8k/service/hardware/canbus/protocol/MId.java | 89 --- .../hardware/canbus/protocol/ModuleStatus.java | 24 - .../hardware/canbus/protocol/ModuleType.java | 27 - .../service/hardware/canbus/protocol/RegIndex.java | 208 ----- src/main/java/a8k/type/A8kScanCurve.java | 17 + src/main/java/a8k/type/ConsumableGroup.java | 12 + src/main/java/a8k/type/HardwareException.java | 63 ++ src/main/java/a8k/type/IncubatorPos.java | 10 + src/main/java/a8k/type/OptScanDirection.java | 9 + src/main/java/a8k/type/PlateInfo.java | 23 + src/main/java/a8k/type/ProjectInfoSimple.java | 21 + src/main/java/a8k/type/SampleTubeState.java | 8 + .../java/a8k/type/TargetPosMeasureDirection.java | 5 + .../java/a8k/type/a8kcanprotocol/A8kEcode.java | 167 ++++ .../java/a8k/type/a8kcanprotocol/A8kPacket.java | 161 ++++ src/main/java/a8k/type/a8kcanprotocol/CmdId.java | 202 +++++ src/main/java/a8k/type/a8kcanprotocol/IOId.java | 38 + src/main/java/a8k/type/a8kcanprotocol/MId.java | 89 +++ .../java/a8k/type/a8kcanprotocol/ModuleStatus.java | 24 + .../java/a8k/type/a8kcanprotocol/ModuleType.java | 27 + .../java/a8k/type/a8kcanprotocol/RegIndex.java | 208 +++++ src/main/java/a8k/type/appret/AppRet.java | 152 ++++ src/main/java/a8k/type/appret/AppRetType.java | 8 + .../java/a8k/type/cfg/BottleGroupsPosInfo.java | 85 ++ src/main/java/a8k/type/cfg/BottlesPosInfo.java | 43 + src/main/java/a8k/type/cfg/HbotLimitArea.java | 36 + src/main/java/a8k/type/cfg/KeyValType.java | 24 + .../java/a8k/type/cfg/LargeBottleBufferPos.java | 65 ++ src/main/java/a8k/type/cfg/PipetteCfg.java | 10 + .../java/a8k/type/cfg/Plates2dCodeScanPos.java | 23 + src/main/java/a8k/type/cfg/Pos2d.java | 22 + src/main/java/a8k/type/cfg/Pos3d.java | 24 + src/main/java/a8k/type/cfg/SampleZPosInfo.java | 17 + src/main/java/a8k/type/cfg/TipPickUpPosInfo.java | 78 ++ src/main/java/a8k/type/cfg/TubeSamplePos.java | 15 + src/main/java/a8k/type/ecode/AppRetEcodeInfo.java | 89 +++ src/main/java/a8k/type/sampleinfo/SampleInfo.java | 12 + src/main/java/a8k/type/type/A8kTubeType.java | 17 + src/main/java/a8k/type/type/BloodType.java | 6 + src/main/java/a8k/utils/opt_algo/A8kOptAlgo.java | 81 ++ 118 files changed, 3856 insertions(+), 3856 deletions(-) delete mode 100644 src/main/java/a8k/algo/opt_algo/A8kOptAlgo.java delete mode 100644 src/main/java/a8k/appbase/A8kScanCurve.java delete mode 100644 src/main/java/a8k/appbase/ConsumableGroup.java delete mode 100644 src/main/java/a8k/appbase/HardwareException.java delete mode 100644 src/main/java/a8k/appbase/IncubatorPos.java delete mode 100644 src/main/java/a8k/appbase/OptScanDirection.java delete mode 100644 src/main/java/a8k/appbase/PlateInfo.java delete mode 100644 src/main/java/a8k/appbase/ProjectInfoSimple.java delete mode 100644 src/main/java/a8k/appbase/SampleTubeState.java delete mode 100644 src/main/java/a8k/appbase/TargetPosMeasureDirection.java delete mode 100644 src/main/java/a8k/appbase/appret/AppRet.java delete mode 100644 src/main/java/a8k/appbase/appret/AppRetType.java delete mode 100644 src/main/java/a8k/appbase/cfg/BottleGroupsPosInfo.java delete mode 100644 src/main/java/a8k/appbase/cfg/BottlesPosInfo.java delete mode 100644 src/main/java/a8k/appbase/cfg/HbotLimitArea.java delete mode 100644 src/main/java/a8k/appbase/cfg/KeyValType.java delete mode 100644 src/main/java/a8k/appbase/cfg/LargeBottleBufferPos.java delete mode 100644 src/main/java/a8k/appbase/cfg/PipetteCfg.java delete mode 100644 src/main/java/a8k/appbase/cfg/Plates2dCodeScanPos.java delete mode 100644 src/main/java/a8k/appbase/cfg/Pos2d.java delete mode 100644 src/main/java/a8k/appbase/cfg/Pos3d.java delete mode 100644 src/main/java/a8k/appbase/cfg/SampleZPosInfo.java delete mode 100644 src/main/java/a8k/appbase/cfg/TipPickUpPosInfo.java delete mode 100644 src/main/java/a8k/appbase/cfg/TubeSamplePos.java delete mode 100644 src/main/java/a8k/appbase/ecode/AppRetEcodeInfo.java delete mode 100644 src/main/java/a8k/appbase/sampleinfo/SampleInfo.java delete mode 100644 src/main/java/a8k/appbase/type/A8kTubeType.java delete mode 100644 src/main/java/a8k/appbase/type/BloodType.java create mode 100644 src/main/java/a8k/baseservice/appeventbus/AppEventBusService.java create mode 100644 src/main/java/a8k/baseservice/appeventbus/AppEventListener.java create mode 100644 src/main/java/a8k/baseservice/appeventbus/appevent/A8kCanBusOnConnectEvent.java create mode 100644 src/main/java/a8k/baseservice/appeventbus/appevent/A8kHardwareReport.java create mode 100644 src/main/java/a8k/baseservice/appeventbus/appevent/A8kStateChangeEvent.java create mode 100644 src/main/java/a8k/baseservice/appeventbus/appevent/AppEvent.java create mode 100644 src/main/java/a8k/baseservice/appeventbus/appevent/AppStepNotifyEvent.java create mode 100644 src/main/java/a8k/baseservice/appeventbus/appevent/AppWarningNotifyEvent.java create mode 100644 src/main/java/a8k/baseservice/appeventbus/appevent/NewAppIDCardDetectEvent.java delete mode 100644 src/main/java/a8k/db/AppSetting.java delete mode 100644 src/main/java/a8k/db/AppUser.java delete mode 100644 src/main/java/a8k/db/DBTableVersion.java delete mode 100644 src/main/java/a8k/db/HardwareServiceSetting.java delete mode 100644 src/main/java/a8k/db/LanguageDictIterm.java delete mode 100644 src/main/java/a8k/db/MdbOption.java delete mode 100644 src/main/java/a8k/db/ProjectColor.java delete mode 100644 src/main/java/a8k/db/ProjectInfo.java create mode 100644 src/main/java/a8k/dbservice/AppSetting.java create mode 100644 src/main/java/a8k/dbservice/AppUser.java create mode 100644 src/main/java/a8k/dbservice/DBTableVersion.java create mode 100644 src/main/java/a8k/dbservice/HardwareServiceSetting.java create mode 100644 src/main/java/a8k/dbservice/LanguageDictIterm.java create mode 100644 src/main/java/a8k/dbservice/MdbOption.java create mode 100644 src/main/java/a8k/dbservice/ProjectColor.java create mode 100644 src/main/java/a8k/dbservice/ProjectInfo.java create mode 100644 src/main/java/a8k/hardware/A8kCanBusService.java create mode 100644 src/main/java/a8k/hardware/A8kModParamInitializer.java create mode 100644 src/main/java/a8k/hardware/custom_param_mgr/A8kModCustomParam.java create mode 100644 src/main/java/a8k/hardware/custom_param_mgr/A8kModCustomParamMgr.java create mode 100644 src/main/java/a8k/hardware/custom_param_mgr/ModCustomParamId.java create mode 100644 src/main/java/a8k/hardware/type/PipetteSampleData.java delete mode 100644 src/main/java/a8k/service/appeventbus/AppEventBusService.java delete mode 100644 src/main/java/a8k/service/appeventbus/AppEventListener.java delete mode 100644 src/main/java/a8k/service/appeventbus/appevent/A8kCanBusOnConnectEvent.java delete mode 100644 src/main/java/a8k/service/appeventbus/appevent/A8kHardwareReport.java delete mode 100644 src/main/java/a8k/service/appeventbus/appevent/A8kStateChangeEvent.java delete mode 100644 src/main/java/a8k/service/appeventbus/appevent/AppEvent.java delete mode 100644 src/main/java/a8k/service/appeventbus/appevent/AppStepNotifyEvent.java delete mode 100644 src/main/java/a8k/service/appeventbus/appevent/AppWarningNotifyEvent.java delete mode 100644 src/main/java/a8k/service/appeventbus/appevent/NewAppIDCardDetectEvent.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/A8kCanBusService.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/A8kModParamInitializer.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/custom_param_mgr/A8kModCustomParam.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/custom_param_mgr/A8kModCustomParamMgr.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/custom_param_mgr/ModCustomParamId.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/data/PipetteSampleData.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/protocol/A8kEcode.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/protocol/A8kPacket.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/protocol/CmdId.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/protocol/IOId.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/protocol/MId.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/protocol/ModuleStatus.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/protocol/ModuleType.java delete mode 100644 src/main/java/a8k/service/hardware/canbus/protocol/RegIndex.java create mode 100644 src/main/java/a8k/type/A8kScanCurve.java create mode 100644 src/main/java/a8k/type/ConsumableGroup.java create mode 100644 src/main/java/a8k/type/HardwareException.java create mode 100644 src/main/java/a8k/type/IncubatorPos.java create mode 100644 src/main/java/a8k/type/OptScanDirection.java create mode 100644 src/main/java/a8k/type/PlateInfo.java create mode 100644 src/main/java/a8k/type/ProjectInfoSimple.java create mode 100644 src/main/java/a8k/type/SampleTubeState.java create mode 100644 src/main/java/a8k/type/TargetPosMeasureDirection.java create mode 100644 src/main/java/a8k/type/a8kcanprotocol/A8kEcode.java create mode 100644 src/main/java/a8k/type/a8kcanprotocol/A8kPacket.java create mode 100644 src/main/java/a8k/type/a8kcanprotocol/CmdId.java create mode 100644 src/main/java/a8k/type/a8kcanprotocol/IOId.java create mode 100644 src/main/java/a8k/type/a8kcanprotocol/MId.java create mode 100644 src/main/java/a8k/type/a8kcanprotocol/ModuleStatus.java create mode 100644 src/main/java/a8k/type/a8kcanprotocol/ModuleType.java create mode 100644 src/main/java/a8k/type/a8kcanprotocol/RegIndex.java create mode 100644 src/main/java/a8k/type/appret/AppRet.java create mode 100644 src/main/java/a8k/type/appret/AppRetType.java create mode 100644 src/main/java/a8k/type/cfg/BottleGroupsPosInfo.java create mode 100644 src/main/java/a8k/type/cfg/BottlesPosInfo.java create mode 100644 src/main/java/a8k/type/cfg/HbotLimitArea.java create mode 100644 src/main/java/a8k/type/cfg/KeyValType.java create mode 100644 src/main/java/a8k/type/cfg/LargeBottleBufferPos.java create mode 100644 src/main/java/a8k/type/cfg/PipetteCfg.java create mode 100644 src/main/java/a8k/type/cfg/Plates2dCodeScanPos.java create mode 100644 src/main/java/a8k/type/cfg/Pos2d.java create mode 100644 src/main/java/a8k/type/cfg/Pos3d.java create mode 100644 src/main/java/a8k/type/cfg/SampleZPosInfo.java create mode 100644 src/main/java/a8k/type/cfg/TipPickUpPosInfo.java create mode 100644 src/main/java/a8k/type/cfg/TubeSamplePos.java create mode 100644 src/main/java/a8k/type/ecode/AppRetEcodeInfo.java create mode 100644 src/main/java/a8k/type/sampleinfo/SampleInfo.java create mode 100644 src/main/java/a8k/type/type/A8kTubeType.java create mode 100644 src/main/java/a8k/type/type/BloodType.java create mode 100644 src/main/java/a8k/utils/opt_algo/A8kOptAlgo.java diff --git a/src/main/java/a8k/algo/opt_algo/A8kOptAlgo.java b/src/main/java/a8k/algo/opt_algo/A8kOptAlgo.java deleted file mode 100644 index a1bf674..0000000 --- a/src/main/java/a8k/algo/opt_algo/A8kOptAlgo.java +++ /dev/null @@ -1,81 +0,0 @@ -package a8k.algo.opt_algo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -public class A8kOptAlgo { - static Logger logger = LoggerFactory.getLogger(A8kOptAlgo.class); - - static private List createDoubleList(int size) { - List list = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - list.add(0.0); - } - return list; - } - - static private List integerToDouble(List input) { - List output = new ArrayList<>(input.size()); - for (Integer i : input) { - output.add(i.doubleValue()); - } - return output; - } - - static private List doubleToInteger(List input) { - List output = new ArrayList<>(input.size()); - for (Double i : input) { - output.add(i.intValue()); - } - return output; - } - - static public List preProcessOptData(List input) { - List inputRaw = integerToDouble(input); - List upSamplingRaw = superSampling(inputRaw, 5); - List subSamplingRaw = subSampling(upSamplingRaw, 24); - return doubleToInteger(subSamplingRaw); - } - - - static public List superSampling(List input, Integer factor) { - int outputLength = input.size() * factor; - List upSamplingRaw = createDoubleList(outputLength); - - for (int si = 0, di = 0; si < input.size() - 1; di++) { - Double a = upSamplingRaw.set(di * factor, input.get(si)); - Double b = upSamplingRaw.set((di + 1) * factor, input.get(++si)); - - Double slope = (b - a) / factor; - - for (int i = 0; i < factor - 1; i++) { - int baseIndex = (di * factor) + i; - upSamplingRaw.set(baseIndex + 1, upSamplingRaw.get(baseIndex) + slope); - } - } - return upSamplingRaw; - } - - static public List subSampling(List inputRaw, Integer nSubSampleRate) { - int nSum = 0; - double fAvg = 0.0; - int subIndex = 0; - int nOutputLength = inputRaw.size() / nSubSampleRate; - - List subSampledRaw = createDoubleList(nOutputLength); - - for (int index = 0; index < inputRaw.size(); index++) { - if (index % nSubSampleRate == 0 && index > 0) { - fAvg = (double) nSum / nSubSampleRate; - subSampledRaw.set(subIndex++, fAvg); - nSum = 0; - } - nSum += inputRaw.get(index); - } - subSampledRaw.set(nOutputLength - 1, subSampledRaw.get(nOutputLength - 2)); - return subSampledRaw; - } -} diff --git a/src/main/java/a8k/appbase/A8kScanCurve.java b/src/main/java/a8k/appbase/A8kScanCurve.java deleted file mode 100644 index 9fb9019..0000000 --- a/src/main/java/a8k/appbase/A8kScanCurve.java +++ /dev/null @@ -1,17 +0,0 @@ -package a8k.appbase; - -import java.util.List; - -public class A8kScanCurve { - public List scanDataCurve; - public List refCurve; - public List refLine; - - public A8kScanCurve() { - } - - public A8kScanCurve(List scanDataCurve, List refLine) { - this.scanDataCurve = scanDataCurve; - this.refLine = refLine; - } -} diff --git a/src/main/java/a8k/appbase/ConsumableGroup.java b/src/main/java/a8k/appbase/ConsumableGroup.java deleted file mode 100644 index 7bdfdc3..0000000 --- a/src/main/java/a8k/appbase/ConsumableGroup.java +++ /dev/null @@ -1,12 +0,0 @@ -package a8k.appbase; - -public enum ConsumableGroup { - GROUP1, GROUP2, GROUP3, GROUP4, GROUP5, GROUP6; - - final public int off; - - ConsumableGroup() { - this.off = this.ordinal(); - } - -} diff --git a/src/main/java/a8k/appbase/HardwareException.java b/src/main/java/a8k/appbase/HardwareException.java deleted file mode 100644 index 5330e28..0000000 --- a/src/main/java/a8k/appbase/HardwareException.java +++ /dev/null @@ -1,63 +0,0 @@ -package a8k.appbase; - -import a8k.service.hardware.canbus.protocol.A8kEcode; -import a8k.service.hardware.canbus.protocol.CmdId; -import a8k.service.hardware.canbus.protocol.MId; - -public class HardwareException extends Exception { - // 构造函数 - - A8kEcode errorCode; - MId moduleId; - CmdId cmdId; - String extmessage; - - public HardwareException() { - super(); - } - - public HardwareException(MId mid, A8kEcode ecode) { - super(String.format("Module ID %s has error code %s", mid, ecode)); - this.errorCode = ecode; - this.moduleId = mid; - this.cmdId = null; - } - - public HardwareException(MId mid, A8kEcode ecode, CmdId cmd) { - super(String.format("Module ID %s has error code %s", mid, ecode)); - this.errorCode = ecode; - this.moduleId = mid; - this.cmdId = cmd; - } - - public HardwareException(A8kEcode ecode, String extmessage) { - super(String.format("Error code %s", ecode)); - this.errorCode = ecode; - this.moduleId = null; - this.cmdId = null; - this.extmessage = extmessage; - } - - public HardwareException(A8kEcode ecode) { - super(String.format("Error code %s", ecode)); - this.errorCode = ecode; - this.moduleId = null; - this.cmdId = null; - } - - public MId getModuleId() { - return moduleId; - } - - public A8kEcode getErrorCode() { - return errorCode; - } - - public CmdId getCmdId() { - return cmdId; - } - - public String getExtMessage() { - return extmessage; - } -} diff --git a/src/main/java/a8k/appbase/IncubatorPos.java b/src/main/java/a8k/appbase/IncubatorPos.java deleted file mode 100644 index 9d6ee07..0000000 --- a/src/main/java/a8k/appbase/IncubatorPos.java +++ /dev/null @@ -1,10 +0,0 @@ -package a8k.appbase; - -public enum IncubatorPos { - SPACE01, SPACE02, SPACE03, SPACE04, SPACE05, SPACE06, SPACE07, SPACE08, SPACE09, SPACE10, SPACE11, SPACE12, SPACE13, SPACE14, SPACE15, SPACE16, SPACE17, SPACE18, SPACE19, SPACE20; - - final public Integer off; - private IncubatorPos() { - this.off = ordinal(); - } -} diff --git a/src/main/java/a8k/appbase/OptScanDirection.java b/src/main/java/a8k/appbase/OptScanDirection.java deleted file mode 100644 index 1b6f603..0000000 --- a/src/main/java/a8k/appbase/OptScanDirection.java +++ /dev/null @@ -1,9 +0,0 @@ -package a8k.appbase; - -public enum OptScanDirection { - POSITIVE, NEGATIVE; - - public Integer getInteger() { - return this == POSITIVE ? 1 : -1; - } -} diff --git a/src/main/java/a8k/appbase/PlateInfo.java b/src/main/java/a8k/appbase/PlateInfo.java deleted file mode 100644 index bb94f7f..0000000 --- a/src/main/java/a8k/appbase/PlateInfo.java +++ /dev/null @@ -1,23 +0,0 @@ -package a8k.appbase; - - -public class PlateInfo { - - public Integer lot; - public Integer item; - public Boolean legal; - public String rawcode; - - public PlateInfo() { - } - - public PlateInfo(Integer lot, Integer item) { - this.lot = lot; - this.item = item; - } - - - public String toString() { - return String.format("%02d-%02d", lot, item); - } -} diff --git a/src/main/java/a8k/appbase/ProjectInfoSimple.java b/src/main/java/a8k/appbase/ProjectInfoSimple.java deleted file mode 100644 index e6e19e7..0000000 --- a/src/main/java/a8k/appbase/ProjectInfoSimple.java +++ /dev/null @@ -1,21 +0,0 @@ -package a8k.appbase; - -import a8k.db.ProjectInfo; - -public class ProjectInfoSimple { - String projectName; //项目名称 - String lotName; //批次名称 - String expiryDate; //有效日期 - - public ProjectInfoSimple(String projectName, String lotName, String expiryDate) { - this.projectName = projectName; - this.lotName = lotName; - this.expiryDate = expiryDate; - } - - public ProjectInfoSimple(ProjectInfo pinfo) { - this.projectName = pinfo.projectName; - this.lotName = pinfo.lotName; - this.expiryDate = pinfo.expiryDate; - } -} diff --git a/src/main/java/a8k/appbase/SampleTubeState.java b/src/main/java/a8k/appbase/SampleTubeState.java deleted file mode 100644 index e763f24..0000000 --- a/src/main/java/a8k/appbase/SampleTubeState.java +++ /dev/null @@ -1,8 +0,0 @@ -package a8k.appbase; - -/** - * 样品试管状态 - */ -public class SampleTubeState { - String tubeType; -} diff --git a/src/main/java/a8k/appbase/TargetPosMeasureDirection.java b/src/main/java/a8k/appbase/TargetPosMeasureDirection.java deleted file mode 100644 index 5d5ec77..0000000 --- a/src/main/java/a8k/appbase/TargetPosMeasureDirection.java +++ /dev/null @@ -1,5 +0,0 @@ -package a8k.appbase; - -public enum TargetPosMeasureDirection { - NOTCARE, POSITIVE, NEGATIVE; -} diff --git a/src/main/java/a8k/appbase/appret/AppRet.java b/src/main/java/a8k/appbase/appret/AppRet.java deleted file mode 100644 index dde53bb..0000000 --- a/src/main/java/a8k/appbase/appret/AppRet.java +++ /dev/null @@ -1,152 +0,0 @@ -package a8k.appbase.appret; - -import a8k.appbase.ecode.AppRetEcodeInfo; -import a8k.service.hardware.canbus.protocol.CmdId; -import a8k.service.hardware.canbus.protocol.MId; -import a8k.service.hardware.canbus.protocol.A8kEcode; -import a8k.appbase.HardwareException; - -public class AppRet { - - public AppRetType appRetType = AppRetType.NORMAL; - - //错误信息 - AppRetEcodeInfo ecode = null; - String traceInfo = null; - - //携带的对象 - String dataType; - T data; - - //显示给用户的内容 - String message = null; - long timestamp;//接口请求时间 - - - public AppRet() { - this.timestamp = System.currentTimeMillis(); - } - - public boolean isSuccess() { - return !AppRetType.FAILURE.equals(appRetType); - } - - public long getTimestamp() { - return timestamp; - } - - public AppRetEcodeInfo getEcode() { - return ecode; - } - - public T getData() { - return data; - } - - public String getTraceInfo() { - return traceInfo; - } - - public String getMessage() { - return message; - } - - public String getDataType() { - return dataType; - } - - - public static AppRet message(String message, T data) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.MESSAGE; - r.message = message; - r.dataType = null == data ? null : data.getClass().getSimpleName(); - return r; - } - - public static AppRet reconfirm(String message) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.RECONFIRM; - r.message = message; - return r; - } - - public static AppRet success(T data) { - AppRet r = new AppRet<>(); - r.data = data; - r.appRetType = AppRetType.NORMAL; - r.dataType = null == data ? null : data.getClass().getSimpleName(); - return r; - } - - - public static AppRet success() { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.NORMAL; - return r; - } - - - public static AppRet fail(A8kEcode errorCode, MId mid, CmdId cmd) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - r.ecode = new AppRetEcodeInfo(errorCode, mid, cmd); - r.message = r.ecode.toDisPlayString(); - return r; - } - - public static AppRet fail(A8kEcode errorCode, MId mid) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - - r.ecode = new AppRetEcodeInfo(errorCode, mid, null); - r.message = r.ecode.toDisPlayString(); - return r; - } - - public static AppRet fail(A8kEcode errorCode) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - - r.ecode = new AppRetEcodeInfo(errorCode, null, null); - r.message = r.ecode.toDisPlayString(); - return r; - } - - public static AppRet fail(AppRet ret) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - - r.ecode = new AppRetEcodeInfo(ret.getEcode().errorCode, ret.getEcode().mid, ret.getEcode().cmd); - r.data = null; - r.message = r.ecode.toDisPlayString(); - return r; - } - - public static AppRet fail(Exception e) { - StringBuilder traceSb = new StringBuilder(); - for (var trace : e.getStackTrace()) { - traceSb.append(trace.toString()).append("\n"); - } - String trace = traceSb.toString(); - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - - if (e instanceof HardwareException hexcep) { - r.ecode = new AppRetEcodeInfo(hexcep.getErrorCode(), hexcep.getModuleId(), hexcep.getCmdId()); - r.traceInfo = trace; - r.message = r.ecode.toDisPlayString(); - if (hexcep.getExtMessage() != null) { - r.message = r.message + "\n 额外信息:"+hexcep.getExtMessage(); - } - - } else { - r.ecode = new AppRetEcodeInfo(A8kEcode.CodeException, null, null); - r.traceInfo = trace; - r.message = e.getMessage(); - } - return r; - } - - -} diff --git a/src/main/java/a8k/appbase/appret/AppRetType.java b/src/main/java/a8k/appbase/appret/AppRetType.java deleted file mode 100644 index 8660a1c..0000000 --- a/src/main/java/a8k/appbase/appret/AppRetType.java +++ /dev/null @@ -1,8 +0,0 @@ -package a8k.appbase.appret; - -public enum AppRetType { - NORMAL, - FAILURE, - RECONFIRM, - MESSAGE, -} diff --git a/src/main/java/a8k/appbase/cfg/BottleGroupsPosInfo.java b/src/main/java/a8k/appbase/cfg/BottleGroupsPosInfo.java deleted file mode 100644 index e057705..0000000 --- a/src/main/java/a8k/appbase/cfg/BottleGroupsPosInfo.java +++ /dev/null @@ -1,85 +0,0 @@ -package a8k.appbase.cfg; - -import a8k.utils.HbotScanerPosComputer; - -public class BottleGroupsPosInfo { - - static public Integer cgetMAX_GROUP_COL() {return 3;} - - static public Integer cgetMAX_GROUP_ROW() {return 2;} - - static public Integer cgetMAX_GROUP() {return cgetMAX_GROUP_COL() * cgetMAX_GROUP_ROW();} - - public Pos2d topLelf;//左上角部分坐标 - - public Integer groupXSpacing; //x间隔 - public Integer groupYSpacing; //y间隔 - - public Pos2d scanCodeRelaPos; //扫码相对位置 - - public Integer posTestZ; - - public BottlesPosInfo smallBottleBufferPos; //小瓶缓冲液位置信息 - public BottlesPosInfo detectMaterialPos; //探测物质位置信息 - - - // BottlesPosInfo - - public BottleGroupsPosInfo() { - topLelf = new Pos2d(0, 0); - groupXSpacing = 0; - groupYSpacing = 0; - scanCodeRelaPos = new Pos2d(0, 0); - smallBottleBufferPos = new BottlesPosInfo(); - detectMaterialPos = new BottlesPosInfo(); - } - - public BottleGroupsPosInfo(Pos2d topLelf, - Integer groupXSpacing, - Integer groupYSpacing, - Pos2d scanCodeRelaPos, - Integer posTestZ, - BottlesPosInfo smallBottleBufferPos, - BottlesPosInfo detectMaterialPos) { - this.topLelf = topLelf; - this.groupXSpacing = groupXSpacing; - this.groupYSpacing = groupYSpacing; - this.scanCodeRelaPos = scanCodeRelaPos; - this.smallBottleBufferPos = smallBottleBufferPos; - this.detectMaterialPos = detectMaterialPos; - this.posTestZ = posTestZ; - } - - Pos2d cgetTopLelf(Integer group) { - - int row = group / cgetMAX_GROUP_COL(); - int col = group % cgetMAX_GROUP_COL(); - - return new Pos2d(topLelf.x + col * groupXSpacing, topLelf.y + row * groupYSpacing); - } - - public Pos2d cgetScanPos(Integer group) { - Pos2d topLelf = cgetTopLelf(group); - if (topLelf == null) { - return null; - } - return HbotScanerPosComputer.getScanPos(new Pos2d(topLelf.x + scanCodeRelaPos.x, topLelf.y + scanCodeRelaPos.y)); - } - - - public Pos2d cgetSmallBottleBufferPos(Integer group, Integer bottleIndex) { - Pos2d topLelf = cgetTopLelf(group); - return smallBottleBufferPos.cgetBotPos(topLelf, bottleIndex); - } - - public Pos2d cgetDetectMaterialPos(Integer group, Integer bottleIndex) { - Pos2d topLelf = cgetTopLelf(group); - return detectMaterialPos.cgetBotPos(topLelf, bottleIndex); - } - - Pos3d cgetSmallBottlePiercedPos(Integer group, Integer bottleIndex) { - Pos2d topLelf = cgetTopLelf(group); - Pos2d bottlePos = smallBottleBufferPos.cgetBotPos(topLelf, bottleIndex); - return new Pos3d(bottlePos.x, bottlePos.y, smallBottleBufferPos.piercedPosZ); - } -} diff --git a/src/main/java/a8k/appbase/cfg/BottlesPosInfo.java b/src/main/java/a8k/appbase/cfg/BottlesPosInfo.java deleted file mode 100644 index e41e8af..0000000 --- a/src/main/java/a8k/appbase/cfg/BottlesPosInfo.java +++ /dev/null @@ -1,43 +0,0 @@ -package a8k.appbase.cfg; - -public class BottlesPosInfo { - - static public Integer cgetMAX_COL() {return 5;} - - static public Integer cgetMAX_ROW() {return 5;} - - static public Integer cgetMAX() {return cgetMAX_COL() * cgetMAX_ROW();} - - public Pos2d relaTopLelf; - public Integer xSpacing; - public Integer ySpacing; - public Integer piercedPosZ; - - public BottlesPosInfo() { - relaTopLelf = new Pos2d(0, 0); - xSpacing = 0; - ySpacing = 0; - piercedPosZ = 0; - } - - - public BottlesPosInfo(Pos2d relaTopLelf, Integer xSpacing, Integer ySpacing, Integer piercedPosZ) { - this.relaTopLelf = relaTopLelf; - this.xSpacing = xSpacing; - this.ySpacing = ySpacing; - this.piercedPosZ = piercedPosZ; - } - - public Pos2d cgetBotPos(Pos2d groupPos, Integer index) { - Integer row = index / cgetMAX_COL(); - Integer col = index % cgetMAX_COL(); - - Integer x = relaTopLelf.x + col * xSpacing; - Integer y = relaTopLelf.y + row * ySpacing; - - return new Pos2d(x + groupPos.x, y + groupPos.y); - - } - - -} diff --git a/src/main/java/a8k/appbase/cfg/HbotLimitArea.java b/src/main/java/a8k/appbase/cfg/HbotLimitArea.java deleted file mode 100644 index be10761..0000000 --- a/src/main/java/a8k/appbase/cfg/HbotLimitArea.java +++ /dev/null @@ -1,36 +0,0 @@ -package a8k.appbase.cfg; - -public class HbotLimitArea { - - - public Integer topLX; - public Integer topLY; - - public Integer bottoLX; - public Integer bottoLY; - - public HbotLimitArea(Integer topLX, Integer topLY, Integer bottoLX, Integer bottoLY) { - this.topLX = topLX; - this.topLY = topLY; - this.bottoLX = bottoLX; - this.bottoLY = bottoLY; - } - - public HbotLimitArea() { - this.topLX = 0; - this.topLY = 0; - this.bottoLX = 0; - this.bottoLY = 0; - } - - public Boolean checkIsInArea(Integer x, Integer y) { - if (x >= topLX && x <= bottoLX && y >= topLY && y <= bottoLY) { - return true; - } - return false; - } - - public Boolean checkIsInArea(Pos2d pos) { - return checkIsInArea(pos.x, pos.y); - } -} diff --git a/src/main/java/a8k/appbase/cfg/KeyValType.java b/src/main/java/a8k/appbase/cfg/KeyValType.java deleted file mode 100644 index 34fbdaa..0000000 --- a/src/main/java/a8k/appbase/cfg/KeyValType.java +++ /dev/null @@ -1,24 +0,0 @@ -package a8k.appbase.cfg; - -public enum KeyValType { - Pos3d("Pos3d"),// - Pos2d("Pos2d"),// - Bool("Bool"),// - Int("Int"),// - String("String"),// - LargeBottleBufferPosInfo("LargeBottleBufferPosInfo"),// - Plates2dCodeScanPosInfo("Plates2dCodeScanPosInfo"),// - SmallBottleBufferPosInfo("SmallBottleBufferPosInfo"),// - TipPickUpPosInfo("TipPickUpPosInfo"),// - TubeSamplePos("TubeSamplePos"),// - PipetteCfg("PipetteCfg"),// - Float("Float"); - - - final public String name; - - KeyValType(String name) { - this.name = name; - } - -} diff --git a/src/main/java/a8k/appbase/cfg/LargeBottleBufferPos.java b/src/main/java/a8k/appbase/cfg/LargeBottleBufferPos.java deleted file mode 100644 index 40d7251..0000000 --- a/src/main/java/a8k/appbase/cfg/LargeBottleBufferPos.java +++ /dev/null @@ -1,65 +0,0 @@ -package a8k.appbase.cfg; - -import a8k.utils.HbotScanerPosComputer; - -/** - * 大瓶缓冲液位置信息 - */ -public class LargeBottleBufferPos { - public Pos2d topLelf = new Pos2d(0, 0); - - public Pos2d hole0 = new Pos2d(0, 0); - public Integer holeXSpacing = 0; //x间隔 - public Integer holeYSpacing = 0; //y间隔 - - public Pos2d scan0 = new Pos2d(0, 0); - public Integer scanPosXSpacing = 0; //扫码位置x间隔 - public Integer scanPosYSpacing = 0; //扫码位置y间隔 - - - public Integer cgetCOL() { - return 3; - } - - public Integer cgetROW() { - return 2; - } - - public Integer cgetBottleCount() { - return cgetCOL() * cgetROW(); - } - - public LargeBottleBufferPos() { - } - - public LargeBottleBufferPos(Pos2d topLelf, Pos2d hole0, Integer holeXSpacing, Integer holeYSpacing, Pos2d scan0, Integer scanPosXSpacing, Integer scanPosYSpacing) { - this.topLelf = topLelf; - this.holeXSpacing = holeXSpacing; - this.holeYSpacing = holeYSpacing; - this.scanPosXSpacing = scanPosXSpacing; - this.scanPosYSpacing = scanPosYSpacing; - this.hole0 = hole0; - this.scan0 = scan0; - } - - public Pos2d cgetBottlePos(Integer bottleIndex) { - Integer row = bottleIndex / cgetCOL(); - Integer col = bottleIndex % cgetCOL(); - - Integer x = topLelf.x + hole0.x + col * holeXSpacing; - Integer y = topLelf.y + hole0.y + row * holeYSpacing; - - return new Pos2d(x, y); - } - - public Pos2d cgetScanPos(Integer bottleIndex) { - Integer row = bottleIndex / cgetCOL(); - Integer col = bottleIndex % cgetCOL(); - - Integer x = topLelf.x + scan0.x + col * scanPosXSpacing; - Integer y = topLelf.y + scan0.y + row * scanPosYSpacing; - - return HbotScanerPosComputer.getScanPos(new Pos2d(x, y)); - - } -} diff --git a/src/main/java/a8k/appbase/cfg/PipetteCfg.java b/src/main/java/a8k/appbase/cfg/PipetteCfg.java deleted file mode 100644 index fc4c605..0000000 --- a/src/main/java/a8k/appbase/cfg/PipetteCfg.java +++ /dev/null @@ -1,10 +0,0 @@ -package a8k.appbase.cfg; - -public class PipetteCfg { - public Integer LLFCThresh;//液面跟随电容阈值 - public Integer LLFPThresh;//液面跟随压力阈值 - - public Integer operatVerifFeatureTime;//操作验证特征时间 - public Integer operatVerifPThresh;//压力阈值 - public Integer tolerance; //吸空检测容差值 -} diff --git a/src/main/java/a8k/appbase/cfg/Plates2dCodeScanPos.java b/src/main/java/a8k/appbase/cfg/Plates2dCodeScanPos.java deleted file mode 100644 index 0ee7bee..0000000 --- a/src/main/java/a8k/appbase/cfg/Plates2dCodeScanPos.java +++ /dev/null @@ -1,23 +0,0 @@ -package a8k.appbase.cfg; - -/** - * 板夹仓扫码信息 - */ -public class Plates2dCodeScanPos { - public Pos2d ch0ScanPos; //通道1扫码位置 - public Integer scanYSpacing; //扫码间隔 - - public Plates2dCodeScanPos() { - ch0ScanPos = new Pos2d(0, 0); - scanYSpacing = 0; - } - - public Plates2dCodeScanPos(Pos2d ch0ScanPos, Integer scanYSpacing) { - this.ch0ScanPos = ch0ScanPos; - this.scanYSpacing = scanYSpacing; - } - - public Pos2d cgetScanPos(int ch) { - return new Pos2d(ch0ScanPos.x, ch0ScanPos.y + ch * scanYSpacing); - } -} diff --git a/src/main/java/a8k/appbase/cfg/Pos2d.java b/src/main/java/a8k/appbase/cfg/Pos2d.java deleted file mode 100644 index 99f1625..0000000 --- a/src/main/java/a8k/appbase/cfg/Pos2d.java +++ /dev/null @@ -1,22 +0,0 @@ -package a8k.appbase.cfg; - -public class Pos2d { - - public Integer x; - public Integer y; - - public Pos2d(Integer x, Integer y) { - this.x = x; - this.y = y; - } - - public Pos2d() { - this.x = 0; - this.y = 0; - } - - public String toString() { - return String.format("(%d, %d)", x, y); - } - -} diff --git a/src/main/java/a8k/appbase/cfg/Pos3d.java b/src/main/java/a8k/appbase/cfg/Pos3d.java deleted file mode 100644 index f419848..0000000 --- a/src/main/java/a8k/appbase/cfg/Pos3d.java +++ /dev/null @@ -1,24 +0,0 @@ -package a8k.appbase.cfg; - -public class Pos3d { - public Integer x = 0; - public Integer y = 0; - public Integer z = 0; - - public Pos3d() { - } - - public Pos3d(Integer x, Integer y, Integer z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Pos2d getXYPos() { - return new Pos2d(x, y); - } - - public String toString() { - return String.format("(%d, %d, %d)", x, y, z); - } -} diff --git a/src/main/java/a8k/appbase/cfg/SampleZPosInfo.java b/src/main/java/a8k/appbase/cfg/SampleZPosInfo.java deleted file mode 100644 index 4062eee..0000000 --- a/src/main/java/a8k/appbase/cfg/SampleZPosInfo.java +++ /dev/null @@ -1,17 +0,0 @@ -package a8k.appbase.cfg; - -public class SampleZPosInfo { - public Integer sampleZPos;//采样探测起始位 - public Integer sampleZDepth;//采样深度 - - /* - * 如果样本容器直径不随液面高度变化,那么LLFVelK=0,LLFVel=常数 - * 液面跟随速度=LLFVelK*液面相对起始位置高度+LLFVel - * - * 如果样本容器直径随液面高度变化,那么LLFVelK=常数,LLFVel=常数 - * 液面跟随速度=LLFVelK*液面相对起始位置高度+LLFVel - */ - - public Integer LLFVelK;//液面跟随速度 - public Integer LLFVel;//液面跟随速度 -} diff --git a/src/main/java/a8k/appbase/cfg/TipPickUpPosInfo.java b/src/main/java/a8k/appbase/cfg/TipPickUpPosInfo.java deleted file mode 100644 index ef08e28..0000000 --- a/src/main/java/a8k/appbase/cfg/TipPickUpPosInfo.java +++ /dev/null @@ -1,78 +0,0 @@ -package a8k.appbase.cfg; - -public class TipPickUpPosInfo { - - public Pos2d g0tl; - public Pos2d g1tl; - public Pos2d g2tl; - - public Double xSpacing; //x间隔 - public Double ySpacing; //y间隔 - - public Integer g0PickUpZPos; //拾取高度 - public Integer g1PickUpZPos; //拾取高度 - public Integer g2PickUpZPos; //拾取高度 - - static public Integer cgetTipNum() {return 12 * 10;} - - static public Integer cgetCOL_MAX() {return 12;} - - static public Integer cgetROW_MAX() {return 10;} - - public TipPickUpPosInfo() { - g0tl = new Pos2d(0, 0); - g1tl = new Pos2d(0, 0); - g2tl = new Pos2d(0, 0); - xSpacing = 0.0; - ySpacing = 0.0; - g0PickUpZPos = 0; - g1PickUpZPos = 0; - g2PickUpZPos = 0; - } - - public TipPickUpPosInfo(Pos2d g0tl, Pos2d g1tl, Pos2d g2tl, Double xSpacing, Double ySpacing, Integer g0PickUpZPos, Integer g1PickUpZPos, Integer g2PickUpZPos) { - this.g0tl = g0tl; - this.g1tl = g1tl; - this.g2tl = g2tl; - this.xSpacing = xSpacing; - this.ySpacing = ySpacing; - this.g0PickUpZPos = g0PickUpZPos; - this.g1PickUpZPos = g1PickUpZPos; - this.g2PickUpZPos = g2PickUpZPos; - } - - Pos2d getTopLeft(Integer group) { - if (group == 0) { - return g0tl; - } else if (group == 1) { - return g1tl; - } else if (group == 2) { - return g2tl; - } else { - return new Pos2d(0, 0); - } - } - - public Pos2d getTipPos(Integer group, Integer index) { - int row; //行 - int col; //列 - - row = index / cgetCOL_MAX(); - col = index % cgetCOL_MAX(); - - Pos2d topleft = getTopLeft(group); - return new Pos2d((int) (topleft.x + col * xSpacing), (int) (topleft.y + row * ySpacing)); - } - - public Integer getPickUpZPos(Integer group) { - if (group == 0) { - return g0PickUpZPos; - } else if (group == 1) { - return g1PickUpZPos; - } else if (group == 2) { - return g2PickUpZPos; - } else { - return 0; - } - } -} diff --git a/src/main/java/a8k/appbase/cfg/TubeSamplePos.java b/src/main/java/a8k/appbase/cfg/TubeSamplePos.java deleted file mode 100644 index 8f004fb..0000000 --- a/src/main/java/a8k/appbase/cfg/TubeSamplePos.java +++ /dev/null @@ -1,15 +0,0 @@ -package a8k.appbase.cfg; - -public class TubeSamplePos { - - Pos2d sampleXYPos0; //不需要脱帽盖帽摇匀的取样位置 - Pos2d sampleXYPos1; //需要脱帽盖帽摇匀的取样位置 - - SampleZPosInfo HighBlood; //sampleXYPos1 - SampleZPosInfo ShortBlood;//sampleXYPos1 - - SampleZPosInfo Mini; //sampleXYPos0 - SampleZPosInfo MiniBlood; //sampleXYPos0 - SampleZPosInfo BulletTube1P5; //sampleXYPos0 - SampleZPosInfo BulletTube0P5; //sampleXYPos0 -} diff --git a/src/main/java/a8k/appbase/ecode/AppRetEcodeInfo.java b/src/main/java/a8k/appbase/ecode/AppRetEcodeInfo.java deleted file mode 100644 index 50d8531..0000000 --- a/src/main/java/a8k/appbase/ecode/AppRetEcodeInfo.java +++ /dev/null @@ -1,89 +0,0 @@ -package a8k.appbase.ecode; - -import a8k.service.hardware.canbus.protocol.A8kEcode; -import a8k.service.hardware.canbus.protocol.CmdId; -import a8k.service.hardware.canbus.protocol.MId; - -public class AppRetEcodeInfo { - public A8kEcode errorCode; - public MId mid; - public CmdId cmd; - - public AppRetEcodeInfo(A8kEcode errorCode, MId mid, CmdId cmd) { - this.errorCode = errorCode; - this.mid = mid; - this.cmd = cmd; - } - - //code - - public Integer getCode() { - return errorCode.index; - } - - public String getCodeChName() { - return errorCode.getChname(); - } - - public String getCodeName() { - return errorCode.toString(); - } - - //mid code - - public Integer getMidCode() { - if (mid == null) { - return null; - } - return mid.toInt(); - } - - public String getMidChName() { - if (mid == null) { - return null; - } - return mid.chname; - } - - public String getMidCodeName() { - if (mid == null) { - return null; - } - return mid.toString(); - } - - //cmd code - - public Integer getCmdCode() { - if (cmd == null) { - return null; - } - return cmd.toInt(); - } - - public String getCmdChName() { - if (cmd == null) { - return null; - } - return cmd.chName; - } - - public String getCmdCodeName() { - if (cmd == null) { - return null; - } - return cmd.toString(); - } - - public String toDisPlayString() { - String info; - info = String.format("错误: %s", errorCode.chname); - if (mid != null) { - info += String.format("\n 相关模块: %s", mid.chname); - } - if (cmd != null) { - info += String.format("\n 相关指令: %s", cmd.chName); - } - return info; - } -} diff --git a/src/main/java/a8k/appbase/sampleinfo/SampleInfo.java b/src/main/java/a8k/appbase/sampleinfo/SampleInfo.java deleted file mode 100644 index 47c44b3..0000000 --- a/src/main/java/a8k/appbase/sampleinfo/SampleInfo.java +++ /dev/null @@ -1,12 +0,0 @@ -package a8k.appbase.sampleinfo; - -import a8k.appbase.type.BloodType; - -import java.util.List; - -public class SampleInfo { - public String udpid; //用户输入的样本ID,不做逻辑,只做展示 - public String barcodeid; //用于请求用户信息的条码ID - public List projectCodes = null; //项目代码 - public BloodType bloodType = BloodType.WHOLE_BLOOD; //血型 -} diff --git a/src/main/java/a8k/appbase/type/A8kTubeType.java b/src/main/java/a8k/appbase/type/A8kTubeType.java deleted file mode 100644 index 603249a..0000000 --- a/src/main/java/a8k/appbase/type/A8kTubeType.java +++ /dev/null @@ -1,17 +0,0 @@ -package a8k.appbase.type; - - -public enum A8kTubeType { - - BloodTube("0000"), //全血试管 - ShortBloodTube("0000"), //全血试管 - MiniTube("1111"), //迷你试管 - MiniBlood("2222"), //阳普管 - BulletTube1P5("5555"),//子弹头试管1.5mL - BulletTube0P5("4444"); //子弹头试管0.5mL - - final public String scanCode; - A8kTubeType(String scanCode) { - this.scanCode = scanCode; - } -} diff --git a/src/main/java/a8k/appbase/type/BloodType.java b/src/main/java/a8k/appbase/type/BloodType.java deleted file mode 100644 index b2e4846..0000000 --- a/src/main/java/a8k/appbase/type/BloodType.java +++ /dev/null @@ -1,6 +0,0 @@ -package a8k.appbase.type; - -public enum BloodType { - WHOLE_BLOOD, - SERUM; -} diff --git a/src/main/java/a8k/baseservice/appeventbus/AppEventBusService.java b/src/main/java/a8k/baseservice/appeventbus/AppEventBusService.java new file mode 100644 index 0000000..2aa0061 --- /dev/null +++ b/src/main/java/a8k/baseservice/appeventbus/AppEventBusService.java @@ -0,0 +1,69 @@ +package a8k.service.appeventbus; + +import a8k.service.appeventbus.appevent.AppEvent; +import jakarta.annotation.PostConstruct; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +@Component +public class AppEventBusService implements ApplicationListener { + public static final Logger logger = LoggerFactory.getLogger(AppEventBusService.class); + + Thread eventProcessorThread; + BlockingQueue eventQueue = new LinkedBlockingQueue<>(); + List listeners = new ArrayList<>(); + + @PostConstruct + public void init() { + + } + + public void regListener(AppEventListener listener) { + listeners.add(listener); + } + + + public void pushEvent(AppEvent event) { + logger.info("pushEvent: {}", event); + eventQueue.add(event); + } + + private void eventBusSchedule() { + while (!Thread.currentThread().isInterrupted()) { + try { + AppEvent event = eventQueue.take(); + callOnEvent(event); + } catch (InterruptedException ignored) { + } + } + } + + private void callOnEvent(AppEvent event) { + logger.info("Processing event: {}", event); + for (AppEventListener listener : listeners) { + listener.onAppEvent(event); + } + } + + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + logger.info("Spring context refreshed"); + if (eventProcessorThread == null) { + eventProcessorThread = new Thread(new Runnable() { + public void run() { + logger.info("Starting event bus schedule"); + eventBusSchedule(); + } + }); + eventProcessorThread.start(); + } + } +} diff --git a/src/main/java/a8k/baseservice/appeventbus/AppEventListener.java b/src/main/java/a8k/baseservice/appeventbus/AppEventListener.java new file mode 100644 index 0000000..48f0fdc --- /dev/null +++ b/src/main/java/a8k/baseservice/appeventbus/AppEventListener.java @@ -0,0 +1,7 @@ +package a8k.service.appeventbus; + +import a8k.service.appeventbus.appevent.AppEvent; + +public interface AppEventListener { + public void onAppEvent(AppEvent event); +} diff --git a/src/main/java/a8k/baseservice/appeventbus/appevent/A8kCanBusOnConnectEvent.java b/src/main/java/a8k/baseservice/appeventbus/appevent/A8kCanBusOnConnectEvent.java new file mode 100644 index 0000000..e71dd04 --- /dev/null +++ b/src/main/java/a8k/baseservice/appeventbus/appevent/A8kCanBusOnConnectEvent.java @@ -0,0 +1,7 @@ +package a8k.service.appeventbus.appevent; + +public class A8kCanBusOnConnectEvent extends AppEvent { + public A8kCanBusOnConnectEvent() { + super(A8kCanBusOnConnectEvent.class.getSimpleName()); + } +} diff --git a/src/main/java/a8k/baseservice/appeventbus/appevent/A8kHardwareReport.java b/src/main/java/a8k/baseservice/appeventbus/appevent/A8kHardwareReport.java new file mode 100644 index 0000000..dfeaab9 --- /dev/null +++ b/src/main/java/a8k/baseservice/appeventbus/appevent/A8kHardwareReport.java @@ -0,0 +1,23 @@ +package a8k.service.appeventbus.appevent; + +import a8k.service.hardware.canbus.protocol.A8kPacket; +import org.springframework.lang.NonNull; + +/** + * A8k底层硬件上报事件 + */ +public class A8kHardwareReport extends AppEvent{ + A8kPacket reportPacket; + public A8kHardwareReport(@NonNull A8kPacket packet) { + super(A8kHardwareReport.class.getSimpleName()); + this.reportPacket = packet; + } + + public A8kPacket getReportPacket(){ + return reportPacket; + } + + public String toString(){ + return String.format("|Event A8kHardwareReport :%s|", reportPacket.toString()); + } +} diff --git a/src/main/java/a8k/baseservice/appeventbus/appevent/A8kStateChangeEvent.java b/src/main/java/a8k/baseservice/appeventbus/appevent/A8kStateChangeEvent.java new file mode 100644 index 0000000..f90b827 --- /dev/null +++ b/src/main/java/a8k/baseservice/appeventbus/appevent/A8kStateChangeEvent.java @@ -0,0 +1,8 @@ +package a8k.service.appeventbus.appevent; + +public class A8kStateChangeEvent extends AppEvent { + + A8kStateChangeEvent(String displayInfo) { + super(A8kStateChangeEvent.class.getSimpleName()); + } +} diff --git a/src/main/java/a8k/baseservice/appeventbus/appevent/AppEvent.java b/src/main/java/a8k/baseservice/appeventbus/appevent/AppEvent.java new file mode 100644 index 0000000..846e1ef --- /dev/null +++ b/src/main/java/a8k/baseservice/appeventbus/appevent/AppEvent.java @@ -0,0 +1,8 @@ +package a8k.service.appeventbus.appevent; + +public class AppEvent { + public String typeName; + public AppEvent(String typeName) { + this.typeName = typeName; + } +} diff --git a/src/main/java/a8k/baseservice/appeventbus/appevent/AppStepNotifyEvent.java b/src/main/java/a8k/baseservice/appeventbus/appevent/AppStepNotifyEvent.java new file mode 100644 index 0000000..b219cbc --- /dev/null +++ b/src/main/java/a8k/baseservice/appeventbus/appevent/AppStepNotifyEvent.java @@ -0,0 +1,15 @@ +package a8k.service.appeventbus.appevent; + + +public class AppStepNotifyEvent extends AppEvent { + String displayInfo; + + AppStepNotifyEvent(String displayInfo) { + super(AppStepNotifyEvent.class.getSimpleName()); + this.displayInfo = displayInfo; + } + + public String getDisplayInfo() { + return displayInfo; + } +} diff --git a/src/main/java/a8k/baseservice/appeventbus/appevent/AppWarningNotifyEvent.java b/src/main/java/a8k/baseservice/appeventbus/appevent/AppWarningNotifyEvent.java new file mode 100644 index 0000000..29ea334 --- /dev/null +++ b/src/main/java/a8k/baseservice/appeventbus/appevent/AppWarningNotifyEvent.java @@ -0,0 +1,15 @@ +package a8k.service.appeventbus.appevent; + +public class AppWarningNotifyEvent extends AppEvent { + String displayInfo; + + AppWarningNotifyEvent(String displayInfo) { + super(AppWarningNotifyEvent.class.getSimpleName()); + this.displayInfo = displayInfo; + } + + public String getDisplayInfo() { + return displayInfo; + } + +} diff --git a/src/main/java/a8k/baseservice/appeventbus/appevent/NewAppIDCardDetectEvent.java b/src/main/java/a8k/baseservice/appeventbus/appevent/NewAppIDCardDetectEvent.java new file mode 100644 index 0000000..217e1c4 --- /dev/null +++ b/src/main/java/a8k/baseservice/appeventbus/appevent/NewAppIDCardDetectEvent.java @@ -0,0 +1,26 @@ +package a8k.service.appeventbus.appevent; + +import a8k.dbservice.ProjectInfo; + +public class NewAppIDCardDetectEvent extends AppEvent { + Boolean newIdCardInfo; + ProjectInfo projectInfo; + + public NewAppIDCardDetectEvent() { + super(NewAppIDCardDetectEvent.class.getSimpleName()); + } + + public NewAppIDCardDetectEvent(Boolean newIdCardInfo, ProjectInfo projectInfo) { + super(NewAppIDCardDetectEvent.class.getSimpleName()); + this.newIdCardInfo = newIdCardInfo; + this.projectInfo = projectInfo; + } + + public Boolean getNewIdCardInfo() { + return newIdCardInfo; + } + + public ProjectInfo getProjectInfo() { + return projectInfo; + } +} diff --git a/src/main/java/a8k/db/AppSetting.java b/src/main/java/a8k/db/AppSetting.java deleted file mode 100644 index 8c8dc07..0000000 --- a/src/main/java/a8k/db/AppSetting.java +++ /dev/null @@ -1,203 +0,0 @@ -package a8k.db; - -import a8k.service.appsettings.base.AppSettingTab; -import a8k.service.appsettings.base.AppOptionName; -import a8k.service.appsettings.base.AppSettingType; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.iflytop.uf.UfActiveRecord; -import com.iflytop.uf.UfActiveRecordField; -import com.iflytop.uf.util.UfJsonHelper; - -import java.util.Arrays; - - -public class AppSetting extends UfActiveRecord { - @UfActiveRecordField - public String type; //支持类型范围 AppSettingType - @UfActiveRecordField - public String tab; //返回名字为英文,前端需要根据英文名字进行翻译 - @UfActiveRecordField - public String name; //返回名字为英文,前端需要根据英文名字进行翻译 - @UfActiveRecordField - public Integer display = 1;// 是否显示 - @UfActiveRecordField - public Integer priority;// 优先级 数值越大越靠后 - - // - //整形和浮点型的单位数值范围 - // - @UfActiveRecordField - public Integer checkValRange;//是否检查输入参数范围 - @UfActiveRecordField - public Double minVal; //最小值 - @UfActiveRecordField - public Double maxVal; //最大值 - - //枚举单位数值范围 - @UfActiveRecordField - public String valueEnumRange; //枚举范围,用逗号分隔 - - //值 - @UfActiveRecordField - public String value; //Value - - @JsonIgnore - public static String getTableName() { - return "AppSetting" + "Table"; - } - - public void setPriority(Integer priority) { - this.priority = priority; - } - - @JsonIgnore - public Integer getIntegerValue() { - return Integer.parseInt(value); - } - - // - // BUILDER - // - - @JsonIgnore - static AppSettingTab currentBuildGroup; - @JsonIgnore - static Integer buildPriority = 0; - static Boolean buildHidden = false; - - static public void setBuildGroup(AppSettingTab group) { - currentBuildGroup = group; - buildPriority = 0; - buildHidden = false; - } - - static public void setBuildHidden(Boolean hidden) { - buildHidden = hidden; - } - - - public static void addIntegerOption(AppOptionName name, Boolean checkValRange, Double minVal, Double maxVal, Integer value) { - var option = new AppSetting(); - option.type = AppSettingType.INTEGER.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.checkValRange = checkValRange ? 1 : 0; - option.minVal = minVal; - option.maxVal = maxVal; - option.value = String.valueOf(value); - option.priority = buildPriority++; - option.save(); - } - - public static void addIntegerOption(AppOptionName name, Integer value) { - addIntegerOption(name, false, 0.0, 0.0, value); - } - - public static void addDoubleOption(AppOptionName name, Boolean checkValRange, Double minVal, Double maxVal, Double value) { - var option = new AppSetting(); - option.type = AppSettingType.DOUBLE.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.checkValRange = checkValRange ? 1 : 0; - option.minVal = minVal; - option.maxVal = maxVal; - option.value = String.valueOf(value); - option.priority = buildPriority++; - option.save(); - } - - public static void addDoubleOption(AppOptionName name, Double value) { - addDoubleOption(name, false, 0.0, 0.0, value); - } - - public static void addStringOption(AppOptionName name, String value) { - var option = new AppSetting(); - option.type = AppSettingType.STRING.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.value = value; - option.priority = buildPriority++; - option.save(); - } - - public static void addBooleanOption(AppOptionName name, Boolean value) { - var option = new AppSetting(); - option.type = AppSettingType.BOOLEAN.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.value = value ? "1" : "0"; - option.priority = buildPriority++; - option.save(); - } - - public static void addDateOption(AppOptionName name, String value) { - var option = new AppSetting(); - option.type = AppSettingType.DATE.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.value = value; - option.priority = buildPriority++; - option.save(); - } - - public static void addTimeOption(AppOptionName name, String value) { - var option = new AppSetting(); - option.type = AppSettingType.TIME.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.value = value; - option.priority = buildPriority++; - option.save(); - } - - public static void addTimezoneOption(AppOptionName name, String value) { - var option = new AppSetting(); - option.type = AppSettingType.TIMEZONE.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.value = value; - option.priority = buildPriority++; - option.save(); - } - - public static void addIpOption(AppOptionName name, String value) { - var option = new AppSetting(); - option.type = AppSettingType.IP.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.value = value; - option.priority = buildPriority++; - option.save(); - } - - public static void addEnumOption(AppOptionName name, String[] valueEnumRange, String value) { - var option = new AppSetting(); - option.type = AppSettingType.ENUM.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.valueEnumRange = UfJsonHelper.objectToJson(valueEnumRange); - option.value = value; - option.priority = buildPriority++; - option.save(); - } - - public static void addFixStringOption(AppOptionName name, String value) { - var option = new AppSetting(); - option.type = AppSettingType.FIX_STRING.name(); - option.tab = currentBuildGroup.name(); - option.name = name.name(); - option.value = value; - option.priority = buildPriority++; - option.save(); - } - // public static void addSpecialPageOption(AppSettingName name, String value) { - // var option = new AppSetting(); - // option.type = AppSettingType.SPECIAL_PAGE.name(); - // option.group = currentBuildGroup.name(); - // option.name = name.name(); - // option.value = value; - // option.priority = buildPriority++; - // option.save(); - // } - -} diff --git a/src/main/java/a8k/db/AppUser.java b/src/main/java/a8k/db/AppUser.java deleted file mode 100644 index 8a97350..0000000 --- a/src/main/java/a8k/db/AppUser.java +++ /dev/null @@ -1,44 +0,0 @@ -package a8k.db; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.iflytop.uf.UfActiveRecord; -import com.iflytop.uf.UfActiveRecordField; - -public class AppUser extends UfActiveRecord { - @UfActiveRecordField - public String account; - - @JsonIgnore - @UfActiveRecordField - public String password = ""; - - @UfActiveRecordField - public Integer isAdmin = 0; - - @UfActiveRecordField - public Integer isBuiltInUser = 0; - - // get table name - public static String getTableName() { - return "AppUser" + "Table"; - } - - // check if password matches - public Boolean matchPassword(String password) { - return this.password.equals(password); - } - - public Boolean isAdmin() { - if (isAdmin == null) { - return false; - } - return isAdmin != 0; - } - - public Boolean isBuiltInUser() { - if (isBuiltInUser == null) { - return false; - } - return isBuiltInUser != 0; - } -} diff --git a/src/main/java/a8k/db/DBTableVersion.java b/src/main/java/a8k/db/DBTableVersion.java deleted file mode 100644 index 17fae4a..0000000 --- a/src/main/java/a8k/db/DBTableVersion.java +++ /dev/null @@ -1,38 +0,0 @@ -package a8k.db; - -import com.iflytop.uf.UfActiveRecord; -import com.iflytop.uf.UfActiveRecordField; - -import java.util.Map; - -public class DBTableVersion extends UfActiveRecord { - @UfActiveRecordField - public String tableName; - @UfActiveRecordField - public Integer version; - - public static String getTableName() { - return DBTableVersion.class.getSimpleName() + "Table"; - } - - public static void setTableVersion(String tableName, Integer version) { - var dbDataVersion = UfActiveRecord.findOne(DBTableVersion.class, Map.of("tableName", tableName)); - if (null == dbDataVersion) { - dbDataVersion = new DBTableVersion(); - dbDataVersion.tableName = tableName; - dbDataVersion.version = version; - dbDataVersion.save(); - } else { - dbDataVersion.version = version; - dbDataVersion.save(); - } - } - - public static Integer getTableVersion(String tableName) { - var dbDataVersion = UfActiveRecord.findOne(DBTableVersion.class, Map.of("tableName", tableName)); - if (null == dbDataVersion) { - return 0; - } - return dbDataVersion.version; - } -} diff --git a/src/main/java/a8k/db/HardwareServiceSetting.java b/src/main/java/a8k/db/HardwareServiceSetting.java deleted file mode 100644 index c11091e..0000000 --- a/src/main/java/a8k/db/HardwareServiceSetting.java +++ /dev/null @@ -1,89 +0,0 @@ -package a8k.db; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.iflytop.uf.UfActiveRecord; -import com.iflytop.uf.UfActiveRecordField; -import com.iflytop.uf.util.UfJsonHelper; - -import java.util.Map; - -public class HardwareServiceSetting extends UfActiveRecord { - @UfActiveRecordField - public String key; - @UfActiveRecordField - public String serviceName; //属于哪个服务的, hardware目录下的类名 - @UfActiveRecordField - public String valType; - @UfActiveRecordField - public String val; - - public static String getTableName() { - return "HardwareServiceSetting" + "Table"; - } - - public static void deleteAllByServiceName(String serviceName) { - var items = UfActiveRecord.find(HardwareServiceSetting.class, Map.of("ServiceName", serviceName)); - for (var item : items) { - item.delete(); - } - } - - public void setValue(Object value) throws Exception { - if (value instanceof String) { - this.val = (String) value; - } else if (value instanceof Integer) { - this.val = String.valueOf((Integer) value); - } else if (value instanceof Map) { - this.val = UfJsonHelper.objectToJson(value); - } else { - this.val = UfJsonHelper.objectToJson(value); - } - } - - public static HardwareServiceSetting getOption(String service, String key) { - var option = UfActiveRecord.findOne(HardwareServiceSetting.class, Map.of("serviceName", service, "key", key)); - if (null == option) { - option = new HardwareServiceSetting(); - option.serviceName = service; - option.key = key; - option.val = null; - } - return option; - } - - - public static void setOption(String service, String key, Object value) throws Exception { - var options = getOption(service, key); - options.setValue(value); - options.save(); - } - - - public static T getObject(String service, String key, Class clazs, T defaultVal) { - var option = UfActiveRecord.findOne(HardwareServiceSetting.class, Map.of("serviceName", service, "key", key)); - if (option == null) { - return defaultVal; - } - ObjectMapper mapper = new ObjectMapper(); - try { - return mapper.readValue(option.val, clazs); - } catch (JsonProcessingException e) { - return defaultVal; - } - } - - public static Integer getInteger(String service, String key, Integer defaultValue) { - var option = HardwareServiceSetting.getOption(service, key); - if (null == option.val) { - return defaultValue; - } - return Integer.parseInt(option.val); - } - - public static void setInteger(String service, String key, Integer value) { - var option = HardwareServiceSetting.getOption(service, key); - option.val = String.valueOf(value); - option.save(); - } -} diff --git a/src/main/java/a8k/db/LanguageDictIterm.java b/src/main/java/a8k/db/LanguageDictIterm.java deleted file mode 100644 index b46da6b..0000000 --- a/src/main/java/a8k/db/LanguageDictIterm.java +++ /dev/null @@ -1,18 +0,0 @@ -package a8k.db; - -import com.iflytop.uf.UfActiveRecord; -import com.iflytop.uf.UfActiveRecordField; - -public class LanguageDictIterm extends UfActiveRecord { - - @UfActiveRecordField - public String key; - @UfActiveRecordField - public String country; - @UfActiveRecordField - public String value; - // get table name - public static String getTableName() { - return String.format("%sTable", LanguageDictIterm.class.getSimpleName()); - } -} diff --git a/src/main/java/a8k/db/MdbOption.java b/src/main/java/a8k/db/MdbOption.java deleted file mode 100644 index ca766bd..0000000 --- a/src/main/java/a8k/db/MdbOption.java +++ /dev/null @@ -1,84 +0,0 @@ -package a8k.db; -import com.iflytop.uf.UfActiveRecord; -import com.iflytop.uf.UfActiveRecordField; -import java.util.Map; -public class MdbOption extends UfActiveRecord { - @UfActiveRecordField - public String key; - - @UfActiveRecordField - public String value; - - @UfActiveRecordField - public String comment; - - @UfActiveRecordField - public String editable; - - @UfActiveRecordField - public String dataType; - - @UfActiveRecordField - public String unit; - - // get table name - public static String getTableName() { - return "app_options"; - } - - // get option - public static String getString(String key, String defaultValue ) { - var option = UfActiveRecord.findOne(MdbOption.class, Map.of("key", key)); - if ( null == option ) { - return defaultValue; - } - return option.value; - } - - // get option string - public static String getString( String key ) { - var option = UfActiveRecord.findOne(MdbOption.class, Map.of("key", key)); - if ( null == option ) { - throw new RuntimeException("Option not found : " + key); - } - return option.value; - } - - // get option - public static Integer getInteger(String key, Integer defaultValue ) { - var option = MdbOption.getString(key, defaultValue.toString()); - return Integer.parseInt(option); - } - - // get option - public static Integer getInteger( String key ) { - var option = MdbOption.getString(key); - return Integer.parseInt(option); - } - - // get option - public static Double getDouble(String key, Double defaultValue ) { - var option = MdbOption.getString(key, defaultValue.toString()); - return Double.parseDouble(option); - } - - // get option value as double - public static Double getDouble( String key ) { - var option = MdbOption.getString(key); - return Double.parseDouble(option); - } - - // get as boolean - public static Boolean getBoolean( String key, Boolean defaultValue ) { - var option = MdbOption.getString(key, defaultValue ? "1" : "0"); - option = option.toLowerCase(); - return "1".equals(option) || "true".equals(option) || "yes".equals(option) || "on".equals(option); - } - - // get option value as boolean - public static Boolean getBoolean( String key ) { - var option = MdbOption.getString(key); - option = option.toLowerCase(); - return "1".equals(option) || "true".equals(option) || "yes".equals(option) || "on".equals(option); - } -} diff --git a/src/main/java/a8k/db/ProjectColor.java b/src/main/java/a8k/db/ProjectColor.java deleted file mode 100644 index 0df34b3..0000000 --- a/src/main/java/a8k/db/ProjectColor.java +++ /dev/null @@ -1,19 +0,0 @@ -package a8k.db; - -import com.iflytop.uf.UfActiveRecord; -import com.iflytop.uf.UfActiveRecordField; - -public class ProjectColor extends UfActiveRecord { - - @UfActiveRecordField - public String color; - @UfActiveRecordField - public String projectId; - @UfActiveRecordField - public Integer index; - - public static String getTableName() { - return "ProjectColorTable"; - } - -} diff --git a/src/main/java/a8k/db/ProjectInfo.java b/src/main/java/a8k/db/ProjectInfo.java deleted file mode 100644 index de698e4..0000000 --- a/src/main/java/a8k/db/ProjectInfo.java +++ /dev/null @@ -1,211 +0,0 @@ -package a8k.db; - -import com.iflytop.uf.UfActiveRecord; -import com.iflytop.uf.UfActiveRecordField; - -import java.util.Date; - -//ref:https://iflytop1.feishu.cn/wiki/HvDlwbEWDi4fgkkL6qSc2iLGnte -public class ProjectInfo extends UfActiveRecord { - - public static String getTableName() { - return "ProjectInfoTable"; - } - - @UfActiveRecordField - public Integer buildIn;//是否是内置,如果是内置则不显示,作为项目的默认值使用 - - @UfActiveRecordField - public String insertTime = new Date().toString(); //插入时间 - - @UfActiveRecordField - public String projectName; //项目名称 - @UfActiveRecordField - public String lotName; //批次名称 - @UfActiveRecordField - public String expiryDate; //有效日期 - @UfActiveRecordField - public String projectCode; //项目名称代码 - @UfActiveRecordField - public Integer palteCode; // 板条条码代码 - @UfActiveRecordField - public Integer updateChipVersion; // 更新芯片版本号 - @UfActiveRecordField - public Double QCPeakMinVal; // 质控峰最小值 - @UfActiveRecordField - public Double QCPeakMaxVal; // 质控峰最大值 设置值x10最大不超过250000 - @UfActiveRecordField - public Integer optType; //光学类型 光学类型(0=自动;1=F光学;2=T光学;3=F/T光学;其他=无效;) - @UfActiveRecordField - public Integer optFixedGainSetting; //光学固定增益设置 - @UfActiveRecordField - public Integer optAreaPeakCount; //光学面积峰个数 - @UfActiveRecordField - public Integer calculationDirection; //计算方向 - @UfActiveRecordField - public Integer sampleType; //样本类型 - @UfActiveRecordField - public Integer equipmentManufacturer; //设备厂商 - @UfActiveRecordField - public Integer tOptIlluminationTime; //T光学持续光照时间 - @UfActiveRecordField - public Integer incMultiInstruDataMerge; //是否包含多款仪器数据合并 - @UfActiveRecordField - public Integer multiInstruDataMerge; //多款仪器数据合并 - @UfActiveRecordField - public Integer wBloodSampleVol; //全血样本量 - @UfActiveRecordField - public Integer serumSampleVol; //血清/血浆样本量 - @UfActiveRecordField - public Integer tubeMixingCount; //试管混匀次数 - @UfActiveRecordField - public Integer bufferBottleSize; //缓冲液瓶大小 - @UfActiveRecordField - public Integer bufferBottleCapacity; //缓冲液瓶容量 - @UfActiveRecordField - public Integer buffLiquidAspirMixingCnt; //缓冲液吸吐混匀次数 - @UfActiveRecordField - public Integer buffLiquidAspirMixingVol; //缓冲液吐混混匀量 - @UfActiveRecordField - public Integer buffLiquidReactionTime; //缓冲液反应时间 - @UfActiveRecordField - public Integer reactionPlateReactionTime; //反应板反应时间 - @UfActiveRecordField - public Integer reactionPlateDropletVol; //反应板滴样量 - @UfActiveRecordField - public Integer resultDecimalPlaces; //结果小数点位数 - @UfActiveRecordField - public Integer scanningRange; //扫描范围 - - //当前项目是几联卡项目 - //项目1 结果曲线是否为分段函数 - //项目2 结果曲线是否为分段函数 - //项目3 结果曲线是否为分段函数 - - @UfActiveRecordField - public Integer projectNum; //当前项目是几联卡项目 - @UfActiveRecordField - public Integer project1CurveType; //项目1 结果曲线是否为分段函数 - @UfActiveRecordField - public Integer project2CurveType; //项目2 结果曲线是否为分段函数 - @UfActiveRecordField - public Integer project3CurveType; //项目3 结果曲线是否为分段函数 - - //非分段函数 - @UfActiveRecordField - public Integer p0FnX; //函数未知数是 - @UfActiveRecordField - public Double p0FnXMin; //函数未知数下限闻值 - @UfActiveRecordField - public Double p0FnXMax; //函数未知数上限闻值 - @UfActiveRecordField - public Double p0FnSerumA; //A - @UfActiveRecordField - public Double p0FnSerumB; //B - @UfActiveRecordField - public Double p0FnSerumC; //C - @UfActiveRecordField - public Double p0FnSerumD; //D - @UfActiveRecordField - public Double p0FnRtSerumUpLimit; //结果上限 - @UfActiveRecordField - public Double p0FnRtSerumLowLimit; //结果下限 - - @UfActiveRecordField - public Double p0FnBloodA; //A - @UfActiveRecordField - public Double p0FnBloodB; //B - @UfActiveRecordField - public Double p0FnBloodC; //C - @UfActiveRecordField - public Double p0FnBloodD; //D - @UfActiveRecordField - public Double p0FnRtBloodUpLimit; //结果上限 - @UfActiveRecordField - public Double p0FnRtBloodLowLimit; //结果下限 - - //分段函数 - @UfActiveRecordField - public Integer p0PwFnJudeX; //分界判断数据来源 - @UfActiveRecordField - public Double p0PwFnJudeThres; //分界判断数据值 - @UfActiveRecordField - public Double p0PwFnLCX; //低浓度未知数 - @UfActiveRecordField - public Double p0PwFnHCX; //高浓度未知数 - @UfActiveRecordField - public Double p0PwFnXMin; //函数未知数下限闻值 - @UfActiveRecordField - public Double p0PwFnXMax; //函数未知数上限闻值 - - @UfActiveRecordField - public Double p0PwFnLCSerumA; //A - @UfActiveRecordField - public Double p0PwFnLCSerumB; //B - @UfActiveRecordField - public Double p0PwFnLCSerumC; //C - @UfActiveRecordField - public Double p0PwFnLCSerumD; //D - @UfActiveRecordField - public Double p0PwFnLCRtSerumUpLimit; //结果上限 - @UfActiveRecordField - public Double p0PwFnLCRtSerumLowLimit; //结果下限 - - @UfActiveRecordField - public Double p0PwFnHCSerumA; //A - @UfActiveRecordField - public Double p0PwFnHCSerumB; //B - @UfActiveRecordField - public Double p0PwFnHCSerumC; //C - @UfActiveRecordField - public Double p0PwFnHCSerumD; //D - @UfActiveRecordField - public Double p0PwFnHCRtSerumUpLimit; //结果上限 - @UfActiveRecordField - public Double p0PwFnHCRtSerumLowLimit; //结果下限 - - @UfActiveRecordField - public Double p0PwFnLCBloodA; //A - @UfActiveRecordField - public Double p0PwFnLCBloodB; //B - @UfActiveRecordField - public Double p0PwFnLCBloodC; //C - @UfActiveRecordField - public Double p0PwFnLCBloodD; //D - @UfActiveRecordField - public Double p0PwFnLCRtBloodUpLimit; //结果上限 - @UfActiveRecordField - public Double p0PwFnLCRtBloodLowLimit; //结果下限 - - @UfActiveRecordField - public Double p0PwFnHCBloodA; //A - @UfActiveRecordField - public Double p0PwFnHCBloodB; //B - @UfActiveRecordField - public Double p0PwFnHCBloodC; //C - @UfActiveRecordField - public Double p0PwFnHCBloodD; //D - @UfActiveRecordField - public Double p0PwFnHCRtBloodUpLimit; //结果上限 - @UfActiveRecordField - public Double p0PwFnHCRtBloodLowLimit; //结果下限 - - //结果 - @UfActiveRecordField - public Integer ret1Unit; //单位 - @UfActiveRecordField - public Integer ret2Unit; //单位 - @UfActiveRecordField - public Integer ret3Unit; //单位 - - @UfActiveRecordField - public Double ret2UnitFnA; // - @UfActiveRecordField - public Double ret2UnitFnB; // - - @UfActiveRecordField - public Double ret3UnitFnA; // - @UfActiveRecordField - public Double ret3UnitFnB; // - -} diff --git a/src/main/java/a8k/dbservice/AppSetting.java b/src/main/java/a8k/dbservice/AppSetting.java new file mode 100644 index 0000000..8c8dc07 --- /dev/null +++ b/src/main/java/a8k/dbservice/AppSetting.java @@ -0,0 +1,203 @@ +package a8k.db; + +import a8k.service.appsettings.base.AppSettingTab; +import a8k.service.appsettings.base.AppOptionName; +import a8k.service.appsettings.base.AppSettingType; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.UfActiveRecordField; +import com.iflytop.uf.util.UfJsonHelper; + +import java.util.Arrays; + + +public class AppSetting extends UfActiveRecord { + @UfActiveRecordField + public String type; //支持类型范围 AppSettingType + @UfActiveRecordField + public String tab; //返回名字为英文,前端需要根据英文名字进行翻译 + @UfActiveRecordField + public String name; //返回名字为英文,前端需要根据英文名字进行翻译 + @UfActiveRecordField + public Integer display = 1;// 是否显示 + @UfActiveRecordField + public Integer priority;// 优先级 数值越大越靠后 + + // + //整形和浮点型的单位数值范围 + // + @UfActiveRecordField + public Integer checkValRange;//是否检查输入参数范围 + @UfActiveRecordField + public Double minVal; //最小值 + @UfActiveRecordField + public Double maxVal; //最大值 + + //枚举单位数值范围 + @UfActiveRecordField + public String valueEnumRange; //枚举范围,用逗号分隔 + + //值 + @UfActiveRecordField + public String value; //Value + + @JsonIgnore + public static String getTableName() { + return "AppSetting" + "Table"; + } + + public void setPriority(Integer priority) { + this.priority = priority; + } + + @JsonIgnore + public Integer getIntegerValue() { + return Integer.parseInt(value); + } + + // + // BUILDER + // + + @JsonIgnore + static AppSettingTab currentBuildGroup; + @JsonIgnore + static Integer buildPriority = 0; + static Boolean buildHidden = false; + + static public void setBuildGroup(AppSettingTab group) { + currentBuildGroup = group; + buildPriority = 0; + buildHidden = false; + } + + static public void setBuildHidden(Boolean hidden) { + buildHidden = hidden; + } + + + public static void addIntegerOption(AppOptionName name, Boolean checkValRange, Double minVal, Double maxVal, Integer value) { + var option = new AppSetting(); + option.type = AppSettingType.INTEGER.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.checkValRange = checkValRange ? 1 : 0; + option.minVal = minVal; + option.maxVal = maxVal; + option.value = String.valueOf(value); + option.priority = buildPriority++; + option.save(); + } + + public static void addIntegerOption(AppOptionName name, Integer value) { + addIntegerOption(name, false, 0.0, 0.0, value); + } + + public static void addDoubleOption(AppOptionName name, Boolean checkValRange, Double minVal, Double maxVal, Double value) { + var option = new AppSetting(); + option.type = AppSettingType.DOUBLE.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.checkValRange = checkValRange ? 1 : 0; + option.minVal = minVal; + option.maxVal = maxVal; + option.value = String.valueOf(value); + option.priority = buildPriority++; + option.save(); + } + + public static void addDoubleOption(AppOptionName name, Double value) { + addDoubleOption(name, false, 0.0, 0.0, value); + } + + public static void addStringOption(AppOptionName name, String value) { + var option = new AppSetting(); + option.type = AppSettingType.STRING.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.value = value; + option.priority = buildPriority++; + option.save(); + } + + public static void addBooleanOption(AppOptionName name, Boolean value) { + var option = new AppSetting(); + option.type = AppSettingType.BOOLEAN.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.value = value ? "1" : "0"; + option.priority = buildPriority++; + option.save(); + } + + public static void addDateOption(AppOptionName name, String value) { + var option = new AppSetting(); + option.type = AppSettingType.DATE.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.value = value; + option.priority = buildPriority++; + option.save(); + } + + public static void addTimeOption(AppOptionName name, String value) { + var option = new AppSetting(); + option.type = AppSettingType.TIME.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.value = value; + option.priority = buildPriority++; + option.save(); + } + + public static void addTimezoneOption(AppOptionName name, String value) { + var option = new AppSetting(); + option.type = AppSettingType.TIMEZONE.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.value = value; + option.priority = buildPriority++; + option.save(); + } + + public static void addIpOption(AppOptionName name, String value) { + var option = new AppSetting(); + option.type = AppSettingType.IP.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.value = value; + option.priority = buildPriority++; + option.save(); + } + + public static void addEnumOption(AppOptionName name, String[] valueEnumRange, String value) { + var option = new AppSetting(); + option.type = AppSettingType.ENUM.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.valueEnumRange = UfJsonHelper.objectToJson(valueEnumRange); + option.value = value; + option.priority = buildPriority++; + option.save(); + } + + public static void addFixStringOption(AppOptionName name, String value) { + var option = new AppSetting(); + option.type = AppSettingType.FIX_STRING.name(); + option.tab = currentBuildGroup.name(); + option.name = name.name(); + option.value = value; + option.priority = buildPriority++; + option.save(); + } + // public static void addSpecialPageOption(AppSettingName name, String value) { + // var option = new AppSetting(); + // option.type = AppSettingType.SPECIAL_PAGE.name(); + // option.group = currentBuildGroup.name(); + // option.name = name.name(); + // option.value = value; + // option.priority = buildPriority++; + // option.save(); + // } + +} diff --git a/src/main/java/a8k/dbservice/AppUser.java b/src/main/java/a8k/dbservice/AppUser.java new file mode 100644 index 0000000..8a97350 --- /dev/null +++ b/src/main/java/a8k/dbservice/AppUser.java @@ -0,0 +1,44 @@ +package a8k.db; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.UfActiveRecordField; + +public class AppUser extends UfActiveRecord { + @UfActiveRecordField + public String account; + + @JsonIgnore + @UfActiveRecordField + public String password = ""; + + @UfActiveRecordField + public Integer isAdmin = 0; + + @UfActiveRecordField + public Integer isBuiltInUser = 0; + + // get table name + public static String getTableName() { + return "AppUser" + "Table"; + } + + // check if password matches + public Boolean matchPassword(String password) { + return this.password.equals(password); + } + + public Boolean isAdmin() { + if (isAdmin == null) { + return false; + } + return isAdmin != 0; + } + + public Boolean isBuiltInUser() { + if (isBuiltInUser == null) { + return false; + } + return isBuiltInUser != 0; + } +} diff --git a/src/main/java/a8k/dbservice/DBTableVersion.java b/src/main/java/a8k/dbservice/DBTableVersion.java new file mode 100644 index 0000000..17fae4a --- /dev/null +++ b/src/main/java/a8k/dbservice/DBTableVersion.java @@ -0,0 +1,38 @@ +package a8k.db; + +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.UfActiveRecordField; + +import java.util.Map; + +public class DBTableVersion extends UfActiveRecord { + @UfActiveRecordField + public String tableName; + @UfActiveRecordField + public Integer version; + + public static String getTableName() { + return DBTableVersion.class.getSimpleName() + "Table"; + } + + public static void setTableVersion(String tableName, Integer version) { + var dbDataVersion = UfActiveRecord.findOne(DBTableVersion.class, Map.of("tableName", tableName)); + if (null == dbDataVersion) { + dbDataVersion = new DBTableVersion(); + dbDataVersion.tableName = tableName; + dbDataVersion.version = version; + dbDataVersion.save(); + } else { + dbDataVersion.version = version; + dbDataVersion.save(); + } + } + + public static Integer getTableVersion(String tableName) { + var dbDataVersion = UfActiveRecord.findOne(DBTableVersion.class, Map.of("tableName", tableName)); + if (null == dbDataVersion) { + return 0; + } + return dbDataVersion.version; + } +} diff --git a/src/main/java/a8k/dbservice/HardwareServiceSetting.java b/src/main/java/a8k/dbservice/HardwareServiceSetting.java new file mode 100644 index 0000000..c11091e --- /dev/null +++ b/src/main/java/a8k/dbservice/HardwareServiceSetting.java @@ -0,0 +1,89 @@ +package a8k.db; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.UfActiveRecordField; +import com.iflytop.uf.util.UfJsonHelper; + +import java.util.Map; + +public class HardwareServiceSetting extends UfActiveRecord { + @UfActiveRecordField + public String key; + @UfActiveRecordField + public String serviceName; //属于哪个服务的, hardware目录下的类名 + @UfActiveRecordField + public String valType; + @UfActiveRecordField + public String val; + + public static String getTableName() { + return "HardwareServiceSetting" + "Table"; + } + + public static void deleteAllByServiceName(String serviceName) { + var items = UfActiveRecord.find(HardwareServiceSetting.class, Map.of("ServiceName", serviceName)); + for (var item : items) { + item.delete(); + } + } + + public void setValue(Object value) throws Exception { + if (value instanceof String) { + this.val = (String) value; + } else if (value instanceof Integer) { + this.val = String.valueOf((Integer) value); + } else if (value instanceof Map) { + this.val = UfJsonHelper.objectToJson(value); + } else { + this.val = UfJsonHelper.objectToJson(value); + } + } + + public static HardwareServiceSetting getOption(String service, String key) { + var option = UfActiveRecord.findOne(HardwareServiceSetting.class, Map.of("serviceName", service, "key", key)); + if (null == option) { + option = new HardwareServiceSetting(); + option.serviceName = service; + option.key = key; + option.val = null; + } + return option; + } + + + public static void setOption(String service, String key, Object value) throws Exception { + var options = getOption(service, key); + options.setValue(value); + options.save(); + } + + + public static T getObject(String service, String key, Class clazs, T defaultVal) { + var option = UfActiveRecord.findOne(HardwareServiceSetting.class, Map.of("serviceName", service, "key", key)); + if (option == null) { + return defaultVal; + } + ObjectMapper mapper = new ObjectMapper(); + try { + return mapper.readValue(option.val, clazs); + } catch (JsonProcessingException e) { + return defaultVal; + } + } + + public static Integer getInteger(String service, String key, Integer defaultValue) { + var option = HardwareServiceSetting.getOption(service, key); + if (null == option.val) { + return defaultValue; + } + return Integer.parseInt(option.val); + } + + public static void setInteger(String service, String key, Integer value) { + var option = HardwareServiceSetting.getOption(service, key); + option.val = String.valueOf(value); + option.save(); + } +} diff --git a/src/main/java/a8k/dbservice/LanguageDictIterm.java b/src/main/java/a8k/dbservice/LanguageDictIterm.java new file mode 100644 index 0000000..b46da6b --- /dev/null +++ b/src/main/java/a8k/dbservice/LanguageDictIterm.java @@ -0,0 +1,18 @@ +package a8k.db; + +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.UfActiveRecordField; + +public class LanguageDictIterm extends UfActiveRecord { + + @UfActiveRecordField + public String key; + @UfActiveRecordField + public String country; + @UfActiveRecordField + public String value; + // get table name + public static String getTableName() { + return String.format("%sTable", LanguageDictIterm.class.getSimpleName()); + } +} diff --git a/src/main/java/a8k/dbservice/MdbOption.java b/src/main/java/a8k/dbservice/MdbOption.java new file mode 100644 index 0000000..ca766bd --- /dev/null +++ b/src/main/java/a8k/dbservice/MdbOption.java @@ -0,0 +1,84 @@ +package a8k.db; +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.UfActiveRecordField; +import java.util.Map; +public class MdbOption extends UfActiveRecord { + @UfActiveRecordField + public String key; + + @UfActiveRecordField + public String value; + + @UfActiveRecordField + public String comment; + + @UfActiveRecordField + public String editable; + + @UfActiveRecordField + public String dataType; + + @UfActiveRecordField + public String unit; + + // get table name + public static String getTableName() { + return "app_options"; + } + + // get option + public static String getString(String key, String defaultValue ) { + var option = UfActiveRecord.findOne(MdbOption.class, Map.of("key", key)); + if ( null == option ) { + return defaultValue; + } + return option.value; + } + + // get option string + public static String getString( String key ) { + var option = UfActiveRecord.findOne(MdbOption.class, Map.of("key", key)); + if ( null == option ) { + throw new RuntimeException("Option not found : " + key); + } + return option.value; + } + + // get option + public static Integer getInteger(String key, Integer defaultValue ) { + var option = MdbOption.getString(key, defaultValue.toString()); + return Integer.parseInt(option); + } + + // get option + public static Integer getInteger( String key ) { + var option = MdbOption.getString(key); + return Integer.parseInt(option); + } + + // get option + public static Double getDouble(String key, Double defaultValue ) { + var option = MdbOption.getString(key, defaultValue.toString()); + return Double.parseDouble(option); + } + + // get option value as double + public static Double getDouble( String key ) { + var option = MdbOption.getString(key); + return Double.parseDouble(option); + } + + // get as boolean + public static Boolean getBoolean( String key, Boolean defaultValue ) { + var option = MdbOption.getString(key, defaultValue ? "1" : "0"); + option = option.toLowerCase(); + return "1".equals(option) || "true".equals(option) || "yes".equals(option) || "on".equals(option); + } + + // get option value as boolean + public static Boolean getBoolean( String key ) { + var option = MdbOption.getString(key); + option = option.toLowerCase(); + return "1".equals(option) || "true".equals(option) || "yes".equals(option) || "on".equals(option); + } +} diff --git a/src/main/java/a8k/dbservice/ProjectColor.java b/src/main/java/a8k/dbservice/ProjectColor.java new file mode 100644 index 0000000..0df34b3 --- /dev/null +++ b/src/main/java/a8k/dbservice/ProjectColor.java @@ -0,0 +1,19 @@ +package a8k.db; + +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.UfActiveRecordField; + +public class ProjectColor extends UfActiveRecord { + + @UfActiveRecordField + public String color; + @UfActiveRecordField + public String projectId; + @UfActiveRecordField + public Integer index; + + public static String getTableName() { + return "ProjectColorTable"; + } + +} diff --git a/src/main/java/a8k/dbservice/ProjectInfo.java b/src/main/java/a8k/dbservice/ProjectInfo.java new file mode 100644 index 0000000..de698e4 --- /dev/null +++ b/src/main/java/a8k/dbservice/ProjectInfo.java @@ -0,0 +1,211 @@ +package a8k.db; + +import com.iflytop.uf.UfActiveRecord; +import com.iflytop.uf.UfActiveRecordField; + +import java.util.Date; + +//ref:https://iflytop1.feishu.cn/wiki/HvDlwbEWDi4fgkkL6qSc2iLGnte +public class ProjectInfo extends UfActiveRecord { + + public static String getTableName() { + return "ProjectInfoTable"; + } + + @UfActiveRecordField + public Integer buildIn;//是否是内置,如果是内置则不显示,作为项目的默认值使用 + + @UfActiveRecordField + public String insertTime = new Date().toString(); //插入时间 + + @UfActiveRecordField + public String projectName; //项目名称 + @UfActiveRecordField + public String lotName; //批次名称 + @UfActiveRecordField + public String expiryDate; //有效日期 + @UfActiveRecordField + public String projectCode; //项目名称代码 + @UfActiveRecordField + public Integer palteCode; // 板条条码代码 + @UfActiveRecordField + public Integer updateChipVersion; // 更新芯片版本号 + @UfActiveRecordField + public Double QCPeakMinVal; // 质控峰最小值 + @UfActiveRecordField + public Double QCPeakMaxVal; // 质控峰最大值 设置值x10最大不超过250000 + @UfActiveRecordField + public Integer optType; //光学类型 光学类型(0=自动;1=F光学;2=T光学;3=F/T光学;其他=无效;) + @UfActiveRecordField + public Integer optFixedGainSetting; //光学固定增益设置 + @UfActiveRecordField + public Integer optAreaPeakCount; //光学面积峰个数 + @UfActiveRecordField + public Integer calculationDirection; //计算方向 + @UfActiveRecordField + public Integer sampleType; //样本类型 + @UfActiveRecordField + public Integer equipmentManufacturer; //设备厂商 + @UfActiveRecordField + public Integer tOptIlluminationTime; //T光学持续光照时间 + @UfActiveRecordField + public Integer incMultiInstruDataMerge; //是否包含多款仪器数据合并 + @UfActiveRecordField + public Integer multiInstruDataMerge; //多款仪器数据合并 + @UfActiveRecordField + public Integer wBloodSampleVol; //全血样本量 + @UfActiveRecordField + public Integer serumSampleVol; //血清/血浆样本量 + @UfActiveRecordField + public Integer tubeMixingCount; //试管混匀次数 + @UfActiveRecordField + public Integer bufferBottleSize; //缓冲液瓶大小 + @UfActiveRecordField + public Integer bufferBottleCapacity; //缓冲液瓶容量 + @UfActiveRecordField + public Integer buffLiquidAspirMixingCnt; //缓冲液吸吐混匀次数 + @UfActiveRecordField + public Integer buffLiquidAspirMixingVol; //缓冲液吐混混匀量 + @UfActiveRecordField + public Integer buffLiquidReactionTime; //缓冲液反应时间 + @UfActiveRecordField + public Integer reactionPlateReactionTime; //反应板反应时间 + @UfActiveRecordField + public Integer reactionPlateDropletVol; //反应板滴样量 + @UfActiveRecordField + public Integer resultDecimalPlaces; //结果小数点位数 + @UfActiveRecordField + public Integer scanningRange; //扫描范围 + + //当前项目是几联卡项目 + //项目1 结果曲线是否为分段函数 + //项目2 结果曲线是否为分段函数 + //项目3 结果曲线是否为分段函数 + + @UfActiveRecordField + public Integer projectNum; //当前项目是几联卡项目 + @UfActiveRecordField + public Integer project1CurveType; //项目1 结果曲线是否为分段函数 + @UfActiveRecordField + public Integer project2CurveType; //项目2 结果曲线是否为分段函数 + @UfActiveRecordField + public Integer project3CurveType; //项目3 结果曲线是否为分段函数 + + //非分段函数 + @UfActiveRecordField + public Integer p0FnX; //函数未知数是 + @UfActiveRecordField + public Double p0FnXMin; //函数未知数下限闻值 + @UfActiveRecordField + public Double p0FnXMax; //函数未知数上限闻值 + @UfActiveRecordField + public Double p0FnSerumA; //A + @UfActiveRecordField + public Double p0FnSerumB; //B + @UfActiveRecordField + public Double p0FnSerumC; //C + @UfActiveRecordField + public Double p0FnSerumD; //D + @UfActiveRecordField + public Double p0FnRtSerumUpLimit; //结果上限 + @UfActiveRecordField + public Double p0FnRtSerumLowLimit; //结果下限 + + @UfActiveRecordField + public Double p0FnBloodA; //A + @UfActiveRecordField + public Double p0FnBloodB; //B + @UfActiveRecordField + public Double p0FnBloodC; //C + @UfActiveRecordField + public Double p0FnBloodD; //D + @UfActiveRecordField + public Double p0FnRtBloodUpLimit; //结果上限 + @UfActiveRecordField + public Double p0FnRtBloodLowLimit; //结果下限 + + //分段函数 + @UfActiveRecordField + public Integer p0PwFnJudeX; //分界判断数据来源 + @UfActiveRecordField + public Double p0PwFnJudeThres; //分界判断数据值 + @UfActiveRecordField + public Double p0PwFnLCX; //低浓度未知数 + @UfActiveRecordField + public Double p0PwFnHCX; //高浓度未知数 + @UfActiveRecordField + public Double p0PwFnXMin; //函数未知数下限闻值 + @UfActiveRecordField + public Double p0PwFnXMax; //函数未知数上限闻值 + + @UfActiveRecordField + public Double p0PwFnLCSerumA; //A + @UfActiveRecordField + public Double p0PwFnLCSerumB; //B + @UfActiveRecordField + public Double p0PwFnLCSerumC; //C + @UfActiveRecordField + public Double p0PwFnLCSerumD; //D + @UfActiveRecordField + public Double p0PwFnLCRtSerumUpLimit; //结果上限 + @UfActiveRecordField + public Double p0PwFnLCRtSerumLowLimit; //结果下限 + + @UfActiveRecordField + public Double p0PwFnHCSerumA; //A + @UfActiveRecordField + public Double p0PwFnHCSerumB; //B + @UfActiveRecordField + public Double p0PwFnHCSerumC; //C + @UfActiveRecordField + public Double p0PwFnHCSerumD; //D + @UfActiveRecordField + public Double p0PwFnHCRtSerumUpLimit; //结果上限 + @UfActiveRecordField + public Double p0PwFnHCRtSerumLowLimit; //结果下限 + + @UfActiveRecordField + public Double p0PwFnLCBloodA; //A + @UfActiveRecordField + public Double p0PwFnLCBloodB; //B + @UfActiveRecordField + public Double p0PwFnLCBloodC; //C + @UfActiveRecordField + public Double p0PwFnLCBloodD; //D + @UfActiveRecordField + public Double p0PwFnLCRtBloodUpLimit; //结果上限 + @UfActiveRecordField + public Double p0PwFnLCRtBloodLowLimit; //结果下限 + + @UfActiveRecordField + public Double p0PwFnHCBloodA; //A + @UfActiveRecordField + public Double p0PwFnHCBloodB; //B + @UfActiveRecordField + public Double p0PwFnHCBloodC; //C + @UfActiveRecordField + public Double p0PwFnHCBloodD; //D + @UfActiveRecordField + public Double p0PwFnHCRtBloodUpLimit; //结果上限 + @UfActiveRecordField + public Double p0PwFnHCRtBloodLowLimit; //结果下限 + + //结果 + @UfActiveRecordField + public Integer ret1Unit; //单位 + @UfActiveRecordField + public Integer ret2Unit; //单位 + @UfActiveRecordField + public Integer ret3Unit; //单位 + + @UfActiveRecordField + public Double ret2UnitFnA; // + @UfActiveRecordField + public Double ret2UnitFnB; // + + @UfActiveRecordField + public Double ret3UnitFnA; // + @UfActiveRecordField + public Double ret3UnitFnB; // + +} diff --git a/src/main/java/a8k/hardware/A8kCanBusService.java b/src/main/java/a8k/hardware/A8kCanBusService.java new file mode 100644 index 0000000..080801e --- /dev/null +++ b/src/main/java/a8k/hardware/A8kCanBusService.java @@ -0,0 +1,888 @@ +package a8k.service.hardware.canbus; + +import a8k.baseservice.appeventbus.appevent.A8kCanBusOnConnectEvent; +import a8k.type.OptScanDirection; +import a8k.type.PlateInfo; +import a8k.service.hardware.canbus.custom_param_mgr.A8kModCustomParamMgr; +import a8k.service.hardware.canbus.data.PipetteSampleData; +import a8k.service.hardware.canbus.protocol.*; +import a8k.service.hardware.canbus.protocol.MId; +import a8k.type.HardwareException; +import a8k.type.cfg.Pos2d; +import a8k.baseservice.appeventbus.appevent.A8kHardwareReport; +import a8k.baseservice.appeventbus.AppEventBusService; +import a8k.utils.ByteArray; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.Resource; +import org.java_websocket.client.WebSocketClient; +import org.java_websocket.enums.ReadyState; +import org.java_websocket.handshake.ServerHandshake; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.*; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +@Component +public class A8kCanBusService { + public static final Logger logger = LoggerFactory.getLogger(A8kCanBusService.class); + + /** + * receiptQueue + * waittingReceiptIndex + * + * onPacket + * if(receipt) + * send_receipt_queue + * + * + * sendcmd + * send cmd + * waiting for receipt + * for(){ + * if(receipt.packetIndex == receiptIndex){ + * return; + * } + * wait + * } + * + */ + + @Resource + private AppEventBusService eventBus; + + @Resource + private A8kModCustomParamMgr customParamMgr; + + public String uri; // assign by application.yml + private WebSocketClient client; + private A8kPacket txPacketContext; + + // 接收回执上下文 + public BlockingQueue receiptQueue = new LinkedBlockingQueue(); // + boolean isWaitingReceipt = false; // + int waitingReceiptIndex = 0;// + + // 发送包的packetIndex + int packetIndex = 0;// + + // 调试标志位 + boolean debugFlag = true;// + // websocket自动重连时间 + Timer autoConnectTimer = new Timer();// + + + Map lastCmdMap = new HashMap<>(); + + @PostConstruct + public void init() throws URISyntaxException { + + logger.info("BaseHardwareService initilized"); + packetIndex = 0; + if (this.uri == null) { + // this.uri = "ws://127.0.0.1:19005"; + this.uri = "ws://192.168.8.10:19005"; + } + + URI uri = new URI(this.uri); + client = new WebSocketClient(uri) { + @Override + public void onOpen(ServerHandshake serverHandshake) { + logger.info("a8k canbus connect sucess"); + eventBus.pushEvent(new A8kCanBusOnConnectEvent()); + } + + @Override + public void onMessage(String s) { + processMessage(s); + } + + @Override + public void onClose(int i, String s, boolean b) { + logger.warn("a8k canbus lost connection..."); + } + + @Override + public void onError(Exception e) { + logger.info("onError"); + } + }; + client.connect(); + + autoConnectTimer.schedule(new TimerTask() { + @Override + public void run() { + if (!client.isOpen()) { + if (client.getReadyState().equals(ReadyState.NOT_YET_CONNECTED)) { + try { + client.connect(); + } catch (IllegalStateException e) { + } + } else if (client.getReadyState().equals(ReadyState.CLOSED)) { + client.reconnect(); + } + } + } + }, 0, 1000); + } + + public void forceShutdown() { + client.close(); + } + + + private A8kPacket packParamsToPacket(Integer moduleId, Integer cmdId, Integer[] params) { + int subCmdId = cmdId & 0xFF; + int mainCmdId = (cmdId >> 8) & 0xFFFF; + int bufferSize = 2 + 2 + 1 + 1 + 2 + 4 * params.length; // PacketIndex - MainCmdId - SubCmdId - CmdType - + // ModuleId - Parameters + ByteBuffer buffer = ByteBuffer.allocate(bufferSize); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.putShort((short) 0); // PacketIndex + buffer.putShort((short) mainCmdId); // MainCmdId + buffer.put((byte) subCmdId); // SubCmdId + buffer.put((byte) 0); // CmdType + buffer.putShort(moduleId.shortValue()); // ModuleId + for (int value : params) { + buffer.putInt(value); + } + return new A8kPacket(buffer.array()); + } + + private void setTxPacketContext(A8kPacket packet) { + txPacketContext = packet; + } + + synchronized private A8kPacket getTxPacketContext() { + return txPacketContext; + } + + + public byte[] a8kIdcardReaderReadRaw() throws HardwareException { + int i = 0; + byte[] result = new byte[0]; + while (true) { + var rxPacket = callcmd(MId.A8kIdCardReader.toInt(), CmdId.a8000_idcard_reader_read_raw.toInt(), i++); + if (rxPacket.getCmdContent().length == 0) { + break; + } + result = ByteArray.concat(result, rxPacket.getCmdContent()); + } + return result; + } + + + public void pipetteCtrlInitDevice(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_ctrl_init_device.toInt()); + } + + public void pipetteCtrlInitDeviceBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { + pipetteCtrlInitDevice(id); + waitForMod(id, actionOvertime); + } + + public void pipetteCtrlPutTip(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_ctrl_put_tip.toInt()); + } + + public void pipetteCtrlPutTipBlock(MId id) throws HardwareException, InterruptedException { + pipetteCtrlPutTip(id); + waitForMod(id, 10000); + } + + + public void pipetteCtrlPrepare(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_lld_prepare.toInt()); + } + + public void pipetteCtrlPlld(MId id, int zdpos, int p_threshold) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_plld.toInt(), zdpos, p_threshold); + } + + public void pipetteCtrlClld(MId id, int zdpos, int c_threshold) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_clld.toInt(), zdpos, c_threshold); + } + + public void pipetteCtrlMlld(MId id, int zdpos, int c_threshold, int p_threshold) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_mlld.toInt(), zdpos, c_threshold, p_threshold); + } + + public Integer pipetteCtrlLldIsDetectLiquid(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.pipette_lld_is_detect_liquid.toInt()); + return packet.getContentI32(0); + } + + public void pipetteAspirate(MId id, int ul) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_aspirate.toInt(), ul); + } + + public void pipetteDistribut(MId id, int ul) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_distribut.toInt(), ul); + } + + public void pipetteShakeUp(MId id, int ul, int times) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_shake_up.toInt(), ul, times); + } + + public void pipetteAspirateLlf(MId id, int ul, int zmotor_v) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_aspirate_llf.toInt(), ul, zmotor_v); + } + + public void pipetteDistributLlf(MId id, int ul, int zmotor_v) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_distribut_llf.toInt(), ul, zmotor_v); + } + + public void pipetteShakeUpLlf(MId id, int ul, int zmotor_v, int times) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_shake_up_llf.toInt(), ul, zmotor_v, times); + } + + public void pipetteEnableZmotor(MId id, int enable) throws HardwareException { + callcmd(id.toInt(), CmdId.pipette_enable_zmotor.toInt(), enable); + } + + public PipetteSampleData pipetteGetSensorSampleData(MId id, int index) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.pipette_get_sensor_sample_data.toInt(), index); + if (packet.getCmdContent().length == 0) { + return null; + } + PipetteSampleData sampleData = new PipetteSampleData(); + sampleData.motorPos = packet.getContentI32(0); + sampleData.cval = packet.getContentI32(1); + sampleData.pval = packet.getContentI32(2); + return sampleData; + } + + public void optTStartScan(MId id, OptScanDirection scanDirection, Integer lasterGain, Integer scanGain) throws HardwareException, InterruptedException { + callcmd(id.toInt(), CmdId.a8k_opt_v2_t_start_scan.toInt(), scanDirection.getInteger(), lasterGain, scanGain); + } + + public void optTStartScanBlock(MId id, OptScanDirection scanDirection, Integer lasterGain, Integer scanGain, Integer actionOvertime) throws HardwareException, InterruptedException { + optTStartScan(id, scanDirection, lasterGain, scanGain); + waitForMod(id, actionOvertime); + } + + public void optFStartScan(MId id, OptScanDirection scanDirection, Integer lasterGain, Integer scanGain) throws HardwareException, InterruptedException { + callcmd(id.toInt(), CmdId.a8k_opt_v2_f_start_scan.toInt(), scanDirection.getInteger(), lasterGain, scanGain); + } + + public void optFStartScanBlock(MId id, OptScanDirection scanDirection, Integer lasterGain, Integer scanGain, Integer actionOvertime) throws HardwareException, InterruptedException { + optFStartScan(id, scanDirection, lasterGain, scanGain); + waitForMod(id, actionOvertime); + } + + public List optReadRaw(MId id) throws HardwareException, InterruptedException { + int i = 0; + List result = new ArrayList<>(); + while (true) { + var rxPacket = callcmd(id.toInt(), CmdId.a8k_opt_v2_read_raw.toInt(), i++); + if (rxPacket.getCmdContent().length == 0) { + break; + } + var rawdata = ByteArray.readU16bitArray(rxPacket.getCmdContent()); + result.addAll(Arrays.asList(rawdata)); + } + return result; + } + + + public void plateCodeScanerPushCardAndScan(MId id, Integer finalStopPos) throws HardwareException, InterruptedException { + callcmd(id.toInt(), CmdId.plate_code_scaner_push_card_and_scan.toInt(), finalStopPos); + } + + public void plateCodeScanerPushCardAndScanBlock(MId id, Integer finalStopPos, Integer actionOvertime) throws HardwareException, InterruptedException { + plateCodeScanerPushCardAndScan(id, finalStopPos); + waitForMod(id, actionOvertime); + } + + public void plateCodeScanerStopScan(MId id) throws HardwareException, InterruptedException { + callcmd(id.toInt(), CmdId.plate_code_scaner_stop_scan.toInt()); + } + + public List plateCodeScanerReadRawResult(MId id) throws HardwareException, InterruptedException { + int i = 0; + List result = new ArrayList<>(); + while (true) { + var rxPacket = callcmd(id.toInt(), CmdId.plate_code_scaner_read_result.toInt(), i++); + if (rxPacket.getCmdContent().length == 0) { + break; + } + var rawdata = ByteArray.readU16bitArray(rxPacket.getCmdContent()); + result.addAll(Arrays.asList(rawdata)); + } + return result; + } + + public PlateInfo plateCodeScannerReadCode(MId mid) throws HardwareException { + var receipt = callcmd(mid.toInt(), CmdId.plate_code_scaner_read_code.toInt()); + PlateInfo plateInfo = new PlateInfo(); + plateInfo.rawcode = Integer.toBinaryString(receipt.getContentI32(0)); + plateInfo.legal = receipt.getContentI32(1) != 0; + plateInfo.lot = receipt.getContentI32(2); + plateInfo.item = receipt.getContentI32(3); + return plateInfo; + } + + public void plateCodeScanerOpenLaser(MId id) throws HardwareException, InterruptedException { + callcmd(id.toInt(), CmdId.plate_code_scaner_open_laser.toInt()); + } + + public void plateCodeScanerCloseLaser(MId id) throws HardwareException, InterruptedException { + callcmd(id.toInt(), CmdId.plate_code_scaner_close_laser.toInt()); + } + + + public Integer plateCodeScanerAdcReadRaw(MId id) throws HardwareException, InterruptedException { + var packet = callcmd(id.toInt(), CmdId.plate_code_scaner_adc_readraw.toInt()); + return packet.getContentI32(0); + } + + + public void fanControlerSetSpeed(MId id, int speed) throws HardwareException, InterruptedException { + callcmd(id.toInt(), CmdId.fan_controler_set_speed.toInt(), speed); + } + + + public void codeScanerStartScan(MId id) throws HardwareException, InterruptedException { + callcmd(id.toInt(), CmdId.code_scaner_start_scan.toInt()); + } + + public void codeScanerStopScan(MId id) throws HardwareException, InterruptedException { + callcmd(id.toInt(), CmdId.code_scaner_stop_scan.toInt()); + } + + public String codeScanerReadScanerResult(MId id) throws HardwareException, InterruptedException { + A8kPacket ack = callcmd(id.toInt(), CmdId.code_scaner_read_scaner_result.toInt()); + var contentBytes = ack.getCmdContent(); + return new String(contentBytes); + } + + public Boolean codeScanerResultIsReady(MId id) throws HardwareException, InterruptedException { + var packet = callcmd(id.toInt(), CmdId.code_scaner_result_is_ready.toInt()); + return packet.getContentI32(0) != 0; + } + + public String codeScanerWaittingForResult(MId mid, Integer acitionOvertime) throws HardwareException, InterruptedException { + long startedAt = System.currentTimeMillis(); + do { + if (codeScanerResultIsReady(mid)) + break; + long now = System.currentTimeMillis(); + if (now - startedAt > acitionOvertime) { + codeScanerStopScan(mid); + return null; + } + Thread.sleep(100); + } while (true); + codeScanerStopScan(mid); + return codeScanerReadScanerResult(mid); + } + + // + // module opeation + // + public void modulePing(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.module_ping.toInt()); + } + + public void moduleStop(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.module_stop.toInt()); + } + + public ModuleStatus getModuleStatus(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.module_get_status.toInt()); + return ModuleStatus.valueOf(packet.getContentI32(0)); + + } + + public void moduleSetReg(MId id, RegIndex regindex, Integer reg) throws HardwareException { + callcmd(id.toInt(), CmdId.module_set_reg.toInt(), regindex.index, reg); + } + + public Integer moduleGetReg(MId id, RegIndex regindex) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.module_get_reg.toInt(), regindex.index); + return packet.getContentI32(0); + } + + public A8kEcode moduleGetError(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.module_get_error.toInt()); + return A8kEcode.valueOf(packet.getContentI32(0)); + } + + public void moduleClearError(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.module_clear_error.toInt()); + } + + public void moduleActiveCfg(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.module_active_cfg.toInt()); + } + + + public void hbotEnable(MId mid, int enable) throws HardwareException { + callcmd(mid.toInt(), CmdId.xymotor_enable.toInt(), enable); + } + + public void hbotMoveBy(MId mid, int x, int y) throws HardwareException { + callcmd(mid.toInt(), CmdId.xymotor_move_by.toInt(), x, y); + } + + public void hbotMoveByBlock(MId mid, int x, int y, Integer actionOvertime) throws HardwareException, InterruptedException { + hbotMoveBy(mid, x, y); + waitForMod(mid, actionOvertime); + } + + public void hbotMoveTo(MId mid, int x, int y) throws HardwareException { + callcmd(mid.toInt(), CmdId.xymotor_move_to.toInt(), x, y); + } + + public void hbotMoveToBlock(MId mid, int x, int y, Integer actionOvertime) throws HardwareException, InterruptedException { + hbotMoveTo(mid, x, y); + waitForMod(mid, actionOvertime); + } + + public void hbotMoveToZero(MId mid) throws HardwareException { + callcmd(mid.toInt(), CmdId.xymotor_move_to_zero.toInt()); + } + + public void hbotMoveToZeroBlock(MId mid, Integer actionOvertime) throws HardwareException, InterruptedException { + hbotMoveToZero(mid); + waitForMod(mid, actionOvertime); + } + + public Pos2d hbotReadPos(MId mid) throws HardwareException { + Pos2d pos = new Pos2d(0, 0); + var packet = callcmd(mid.toInt(), CmdId.xymotor_read_pos.toInt()); + pos.x = packet.getContentI32(0); + pos.y = packet.getContentI32(1); + return pos; + } + + public Boolean hbotReadInio(MId mid, int ioIndex) throws HardwareException { + var packet = callcmd(mid.toInt(), CmdId.xymotor_read_inio.toInt(), ioIndex); + return packet.getContentI32(0) != 0; + } + + public void hbotSetPos(MId mid, int x, int y) throws HardwareException { + callcmd(mid.toInt(), CmdId.xymotor_set_pos.toInt(), x, y); + } + + + public void hbotMoveByDirect(MId mid, int motor1_dpos, int motor2_dpos) throws HardwareException { + callcmd(mid.toInt(), CmdId.xymotor_motor_move_by_direct.toInt(), motor1_dpos, motor2_dpos); + } + + public int hbotReadEncDirect(MId mid) throws HardwareException { + var packet = callcmd(mid.toInt(), CmdId.xymotor_read_enc_direct.toInt()); + return packet.getContentI32(0); + } + + public int hbotReadInioIndexInStm32(MId mid, int ioIndex) throws HardwareException { + var packet = callcmd(mid.toInt(), CmdId.xymotor_read_inio_index_in_stm32.toInt(), ioIndex); + return packet.getContentI32(0); + } + + + // + // stepMotor + // + public void stepMotorEnable(MId mid, int enable) throws HardwareException { + callcmd(mid.toInt(), CmdId.step_motor_enable.toInt(), enable); + } + + public Integer stepMotorReadPos(MId id) throws HardwareException { + A8kPacket packet = callcmd(id.toInt(), CmdId.step_motor_read_pos.toInt()); + return packet.getContentI32(0); + } + + public void stepMotorEasyRotate(MId id, int direction) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_easy_rotate.toInt(), direction); + } + + public void stepMotorEasyMoveBy(MId id, int dpos) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_easy_move_by.toInt(), dpos); + } + + public void stepMotorEasyMoveByBlock(MId id, int dpos, Integer actionOvertime) throws HardwareException, InterruptedException { + stepMotorEasyMoveBy(id, dpos); + waitForMod(id, actionOvertime); + } + + public void stepMotorEasyMoveTo(MId id, int pos) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_easy_move_to.toInt(), pos); + } + + public void stepMotorEasyMoveToBlock(MId id, int pos, Integer actionOvertime) throws HardwareException, InterruptedException { + stepMotorEasyMoveTo(id, pos); + waitForMod(id, actionOvertime); + } + + public void stepMotorEasyMoveToZero(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_easy_move_to_zero.toInt()); + } + + public void stepMotorEasyMoveToZeroBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { + stepMotorEasyMoveToZero(id); + waitForMod(id, actionOvertime); + } + + public Integer stepMotorReadPosByMoveToZeroBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { + stepMotorEnable(id, 1); + stepMotorEasyMoveToZeroBlock(id, actionOvertime); + Integer nowpos = stepMotorReadPos(id); + Integer measurepos = -moduleGetReg(id, RegIndex.kreg_step_motor_dpos) + nowpos; + stepMotorEnable(id, 0); + return measurepos; + } + + public void stepMotorEasySetCurrentPos(MId id, int pos) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_easy_set_current_pos.toInt(), pos); + } + + public void stepMotorEasyMoveToIo(MId id, int io) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_easy_move_to_io.toInt(), io); + } + + // step_motor_easy_move_to_zero_point_quick + + public void stepMotorEasyMoveToZeroPointQuick(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_easy_move_to_zero_point_quick.toInt()); + } + + public void stepMotorEasyMoveToZeroPointQuickBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { + stepMotorEasyMoveToZeroPointQuick(id); + waitForMod(id, actionOvertime); + } + + public void stepMotorStop(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_stop.toInt(),0); + } + + public void stepMotorActiveCfg(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_active_cfg.toInt()); + } + + public Boolean stepMotorReadIoState(MId id, int ioindex) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.step_motor_read_io_state.toInt(), ioindex); + return packet.getContentI32(0) != 0; + } + + public void stepMotorEasyMoveToEndPoint(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_easy_move_to_end_point.toInt()); + } + + public void stepMotorEasyMoveToEndPointBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { + stepMotorEasyMoveToEndPoint(id); + waitForMod(id, actionOvertime); + } + + public void stepMotorEasyReciprocatingMotion(MId id, int startpos, int endpos, int times) throws HardwareException { + callcmd(id.toInt(), CmdId.step_motor_easy_reciprocating_motion.toInt(), startpos, endpos, times); + } + + public void stepMotorEasyReciprocatingMotionBlock(MId id, int startpos, int endpos, int times, Integer actionOvertime) throws HardwareException, InterruptedException { + stepMotorEasyReciprocatingMotion(id, startpos, endpos, times); + waitForMod(id, actionOvertime); + } + // + // MINI_SERVO + // + + public void miniServoEnable(MId id, int enable) throws HardwareException { + callcmd(id.toInt(), CmdId.mini_servo_enable.toInt(), enable); + } + + public int miniServoReadPos(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.mini_servo_read_pos.toInt()); + return packet.getContentI32(0); + } + + + public void miniServoActiveCfg(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.mini_servo_active_cfg.toInt()); + } + + public void miniServoStop(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.mini_servo_stop.toInt()); + } + + public void miniServoSetMidPoint(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.mini_servo_set_mid_point.toInt()); + } + + public int miniServoReadIoState(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.mini_servo_read_io_state.toInt()); + return packet.getContentI32(0); + } + + public void miniServoMoveTo(MId id, int pos) throws HardwareException { + callcmd(id.toInt(), CmdId.mini_servo_move_to.toInt(), pos); + } + + public void miniServoMoveToBlock(MId id, int pos, Integer actionOvertime) throws HardwareException, InterruptedException { + miniServoMoveTo(id, pos); + waitForMod(id, actionOvertime); + } + + public void miniServoRotate(MId id, int direction) throws HardwareException { + callcmd(id.toInt(), CmdId.mini_servo_rotate.toInt(), direction); + } + + public void miniServoRotateBlock(MId id, int direction, Integer actionOvertime) throws HardwareException, InterruptedException { + miniServoRotate(id, direction); + waitForMod(id, actionOvertime); + } + + public void miniServoRotateWithTorque(MId id, int torque) throws HardwareException { + callcmd(id.toInt(), CmdId.mini_servo_rotate_with_torque.toInt(), torque); + } + + public void miniServoRotateWithTorqueBlock(MId id, int torque, Integer actionOvertime) throws HardwareException, InterruptedException { + miniServoRotateWithTorque(id, torque); + miniServoWaitIsNotMove(id, actionOvertime); + } + + public void miniServoWaitIsNotMove(MId id, int acitionOvertime) throws HardwareException, InterruptedException { + long startedAt = System.currentTimeMillis(); + do { + var isMove = moduleGetReg(id, RegIndex.kreg_mini_servo_is_move); + if (isMove != 0) { + break; + } + long now = System.currentTimeMillis(); + if (now - startedAt > acitionOvertime) { + throw new HardwareException(id, A8kEcode.Overtime); + } + + } while (true); + } + + public Boolean priGetIOState(IOId ioid) throws HardwareException { + if (ioid.mtype == ModuleType.kboard) { + return callcmd(ioid.mid.toInt(), CmdId.extboard_read_inio.toInt(), ioid.ioIndex).getContentI32(0) != 0; + } else if (ioid.mtype == ModuleType.ktmc_step_motor) { + return callcmd(ioid.mid.toInt(), CmdId.step_motor_read_io_state.toInt(), ioid.ioIndex).getContentI32(0) != 0; + } else if (ioid.mtype == ModuleType.kmini_servo_motor_module) { + return callcmd(ioid.mid.toInt(), CmdId.mini_servo_read_io_state.toInt(), ioid.ioIndex).getContentI32(0) != 0; + } else { + throw new HardwareException(ioid.mid, A8kEcode.IllegalOperation); + } + } + + public Boolean getIOState(IOId ioid) throws HardwareException { + while (true) { + Boolean firstReadIO = priGetIOState(ioid); + Boolean secondReadIO = priGetIOState(ioid); + if (firstReadIO == secondReadIO) { + return firstReadIO; + } else { + logger.warn("getIOState {} not match, retry", ioid); + } + } + } + + + public void setIOState(IOId ioid, boolean val) throws HardwareException { + if (ioid.mtype == ModuleType.kboard) { + callcmd(ioid.mid.toInt(), CmdId.extboard_write_outio.toInt(), ioid.ioIndex, val ? 1 : 0); + } else { + throw new HardwareException(ioid.mid, A8kEcode.IllegalOperation); + } + } + + + public void waitForMods(MId[] mids, Integer acitionOvertime) throws InterruptedException, HardwareException { + for (MId mid : mids) { + waitForMod(mid, acitionOvertime); + } + } + + public void waitForMod(MId mid, Integer acitionOvertime) throws InterruptedException, HardwareException { + long startedAt = System.currentTimeMillis(); + // Thread.sleep(300); + // CmdId action = lastCmdMap.get(mid); + CmdId action = lastCmdMapGet(mid); + do { + ModuleStatus statu = null; + try { + statu = getModuleStatus(mid); + } catch (HardwareException ignored) { + } + if (statu == ModuleStatus.IDLE) { + break; + } else if (statu == ModuleStatus.ERROR) { + logger.error("{} waitting for action {} , catch error {}", mid, action, moduleGetError(mid)); + throw new HardwareException(mid, moduleGetError(mid)); + } + + long now = System.currentTimeMillis(); + if (now - startedAt > acitionOvertime) { + logger.error("{} waitting for action {} overtime", mid, action); + try { + moduleStop(mid); + } catch (HardwareException ignored) { + } + throw new HardwareException(mid, A8kEcode.ActionOvertime); + } + Thread.sleep(100); + } while (true); + } + + public A8kPacket callcmd(Integer moduleId, Integer cmdId) throws HardwareException { + return this.callcmd(moduleId, cmdId, new Integer[]{}); + } + + public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0) throws HardwareException { + return this.callcmd(moduleId, cmdId, new Integer[]{p0}); + } + + public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1) throws HardwareException { + return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1}); + } + + public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2) throws HardwareException { + return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2}); + } + + public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3) throws HardwareException { + return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2, p3}); + } + + + public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer[] params) throws HardwareException { + var packet = packParamsToPacket(moduleId, cmdId, params); + return sendCmdAutoResend(packet, A8kPacket.CMD_OVERTIME); + } + + synchronized public A8kPacket sendCmdAutoResend(A8kPacket pack, int overtime) throws HardwareException { + // 调用sendCmd, + // 如果捕获到超时异常,则重发,最多重发三次 + // 如果是其他异常,则直接抛出异常。 + for (int i = 0; i < 5; i++) { + try { + return this.sendCmd(pack, A8kPacket.CMD_OVERTIME); + } catch (HardwareException e) { + if (e.getErrorCode() != A8kEcode.Overtime) { + throw e; + } + } + try { + Thread.sleep(100); + } catch (InterruptedException ignore) { + } + logger.error("send cmd {} fail, retry {}", pack, i); + } + throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.Overtime); + } + + + private A8kPacket sendCmd(A8kPacket pack, int overtime) throws HardwareException { + pack.setPacketIndex(packetIndex); + waitingReceiptIndex = packetIndex; + packetIndex = packetIndex + 1; + if (packetIndex > 10000) { + packetIndex = 1; + } + receiptQueue.clear(); + isWaitingReceipt = true; + String txpacket = pack.toByteString(); + + CmdId cmdid = CmdId.valueOf(pack.getCmdId()); + if (cmdid == null) { + throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.CmdIdNotSupport); + } + if (debugFlag && pack.isTrace()) { + String packstr = pack.toString(); + logger.info("Tx:|RAW:{}| {}", txpacket, packstr); + } + + if (cmdid.actionCmd) { + lastCmdMapPut(MId.valueOf(pack.getModuleId()), CmdId.valueOf(pack.getCmdId())); + } + + txPacketContext = pack; + client.send(txpacket); + A8kPacket receipt; + try { + receipt = receiptQueue.poll(overtime, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + isWaitingReceipt = false; + throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.Overtime); + } + isWaitingReceipt = false; + if (receipt == null) { + throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.Overtime); + } + + if (receipt.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { + throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.valueOf(receipt.getContentI32(0))); + } + try { + Thread.sleep(10); + } catch (InterruptedException ignored) { + } + return receipt; + } + + /** + * + */ + private void processMessage(String s) { + byte[] rx = ByteArray.hexStringToBytes(s); + if (rx == null || rx.length == 0) { + logger.warn("rx is empty"); + return; + } + + if (rx.length < A8kPacket.PACKET_MIN_LEN) { + logger.warn("rx is too short"); + return; + } + + A8kPacket packet = new A8kPacket(rx); + + if (!packet.isSupportPacket()) { + logger.warn("Rx packet not support: {}", packet); + return; + } + + A8kPacket tpCxt = this.txPacketContext; + if (debugFlag) { + if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK) { + if (tpCxt != null && tpCxt.getPacketIndex() == packet.getPacketIndex()) { + if (tpCxt.isTrace()) { + logger.info("RX-ACK |RAW:{}| {}", s, packet); + } + } + } else { + logger.info("RX |RAW:{}| {}", s, packet); + } + } + + + if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK || packet.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { + if (isWaitingReceipt) { + if (waitingReceiptIndex == packet.getPacketIndex()) { + receiptQueue.add(packet); + } + } + } + + if (packet.getPacketType() == A8kPacket.PACKET_TYPE_EVENT) { + eventBus.pushEvent(new A8kHardwareReport(packet)); + } + } + + synchronized void lastCmdMapPut(MId mid, CmdId cmdId) { + lastCmdMap.put(mid, cmdId); + } + + synchronized CmdId lastCmdMapGet(MId mid) { + return lastCmdMap.get(mid); + } +} diff --git a/src/main/java/a8k/hardware/A8kModParamInitializer.java b/src/main/java/a8k/hardware/A8kModParamInitializer.java new file mode 100644 index 0000000..c286669 --- /dev/null +++ b/src/main/java/a8k/hardware/A8kModParamInitializer.java @@ -0,0 +1,127 @@ +package a8k.service.hardware.canbus; + +import a8k.baseservice.appeventbus.AppEventBusService; +import a8k.baseservice.appeventbus.appevent.A8kCanBusOnConnectEvent; +import a8k.baseservice.appeventbus.appevent.AppEvent; +import a8k.baseservice.appeventbus.AppEventListener; +import a8k.type.HardwareException; +import a8k.service.hardware.canbus.custom_param_mgr.ModCustomParamId; +import a8k.service.hardware.canbus.custom_param_mgr.A8kModCustomParamMgr; +import a8k.service.hardware.canbus.protocol.MId; +import a8k.service.hardware.canbus.protocol.RegIndex; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class A8kModParamInitializer implements AppEventListener { + static Logger logger = LoggerFactory.getLogger(A8kModParamInitializer.class); + + @Resource + AppEventBusService eventBus; + + @Resource + A8kCanBusService canBus; + + @Resource + A8kModCustomParamMgr customParamMgr; + + @PostConstruct + public void init() { + logger.info("A8kModInitializer init"); + eventBus.regListener(this); + } + + public void initA8kCustcomParams() { + customParamMgr.setCustomParam(MId.FeedingModXM, ModCustomParamId.MOTOR_STANDY_POS_COMPENSATE, -10); + customParamMgr.setCustomParam(MId.ShakeModGripperZM, ModCustomParamId.MOTOR_STANDY_POS_COMPENSATE, -10); + customParamMgr.setCustomParam(MId.ShakeModClampingM, ModCustomParamId.MOTOR_STANDY_POS_COMPENSATE, -10); + } + + public void initA8kModParams() throws HardwareException { + /* + * 设置位置偏差容忍度 + * 1.如果电机配置有编码器器,则每次调用moveBy,moveTo都会进行位置检查 + * 2.如果电机没有配备编码,则每次调用moveQuickToZeroPoint,都会进行一次位置检查 + */ + canBus.moduleSetReg(MId.FeedingModXM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); + canBus.moduleSetReg(MId.ShakeModClampingM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); + canBus.moduleSetReg(MId.ShakeModGripperZM, RegIndex.kret_step_motor_pos_devi_tolerance, 20); + canBus.moduleSetReg(MId.ShakeModShakeM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); + canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); + canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); + canBus.moduleSetReg(MId.OptModPullM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); + canBus.moduleSetReg(MId.OptModScannerM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); + canBus.moduleSetReg(MId.PipetteModZM, RegIndex.kret_step_motor_pos_devi_tolerance, 20); + canBus.moduleSetReg(MId.IncubatorRotateCtrlM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); + + canBus.moduleSetReg(MId.FeedingModXM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); + canBus.moduleSetReg(MId.ShakeModClampingM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); + canBus.moduleSetReg(MId.ShakeModGripperZM, RegIndex.kret_step_motor_io_trigger_append_distance, 20); + canBus.moduleSetReg(MId.ShakeModShakeM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); + canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); + canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kret_step_motor_io_trigger_append_distance, 3); + canBus.moduleSetReg(MId.OptModPullM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); + canBus.moduleSetReg(MId.OptModScannerM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); + canBus.moduleSetReg(MId.PipetteModZM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); + canBus.moduleSetReg(MId.IncubatorRotateCtrlM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); + + canBus.moduleSetReg(MId.ShakeModGripperYSV, RegIndex.kreg_mini_servo_limit_torque, 700); + + + // + canBus.moduleSetReg(MId.OptModPullM, RegIndex.kreg_step_motor_run_to_zero_speed, 500); + canBus.moduleSetReg(MId.OptModPullM, RegIndex.kreg_step_motor_default_velocity, 2200); + canBus.moduleSetReg(MId.OptModPullM, RegIndex.kreg_step_motor_irun, 31); + + canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kreg_step_motor_default_velocity, 1800); + canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kreg_step_motor_irun, 31); + + canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kreg_step_motor_default_velocity, 1800); + canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kreg_step_motor_irun, 25); + + //Hbot-丢步容忍距离 + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_pos_devi_tolerance, 5); + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_io_trigger_append_distance, 10); + + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_min_x, -100); + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_min_y, -100); + + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_vstart, 1); + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_a1, 5); + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_amax, 15); + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_v1, 100); + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_dmax, 15); + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_d1, 5); + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_vstop, 1); + canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_tzerowait, 300); + + canBus.moduleSetReg(MId.PipetteModZM, RegIndex.kreg_step_motor_default_velocity, 1500); + +// canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_run_to_zero_speed, 300); +// canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_one_circle_pulse, 7215); + // canBus.moduleSetReg(MId.OptModPullM, RegIndex.kreg_step_motor_run_to_zero_speed, 500); + + } + + public void forceInitA8kModParams() { + try { + logger.info("forceInitA8kModParams"); + initA8kModParams(); + } catch (HardwareException e) { + logger.error("init hardware param fail......", e); + //TODO:校验这里的逻辑 + canBus.forceShutdown(); + } + } + + + @Override + public void onAppEvent(AppEvent event) { + if (event instanceof A8kCanBusOnConnectEvent) { + forceInitA8kModParams(); + } + } +} diff --git a/src/main/java/a8k/hardware/custom_param_mgr/A8kModCustomParam.java b/src/main/java/a8k/hardware/custom_param_mgr/A8kModCustomParam.java new file mode 100644 index 0000000..ec8bb45 --- /dev/null +++ b/src/main/java/a8k/hardware/custom_param_mgr/A8kModCustomParam.java @@ -0,0 +1,10 @@ +package a8k.service.hardware.canbus.custom_param_mgr; + +import a8k.service.hardware.canbus.protocol.MId; + +public class A8kModCustomParam { + MId mid; + public ModCustomParamId id; + public Integer value; + +} diff --git a/src/main/java/a8k/hardware/custom_param_mgr/A8kModCustomParamMgr.java b/src/main/java/a8k/hardware/custom_param_mgr/A8kModCustomParamMgr.java new file mode 100644 index 0000000..62a7588 --- /dev/null +++ b/src/main/java/a8k/hardware/custom_param_mgr/A8kModCustomParamMgr.java @@ -0,0 +1,35 @@ +package a8k.service.hardware.canbus.custom_param_mgr; + +import a8k.service.hardware.canbus.protocol.MId; +import org.springframework.stereotype.Component; + +import java.util.Set; + +@Component +public class A8kModCustomParamMgr { + + Set customParamSet; + + public Integer getCustomParam(MId mid, ModCustomParamId id) { + for (A8kModCustomParam param : customParamSet) { + if (param.mid == mid && param.id == id) { + return param.value; + } + } + return id.defaultVal; + } + + public void setCustomParam(MId mid, ModCustomParamId id, Integer val) { + for (A8kModCustomParam param : customParamSet) { + if (param.mid == mid && param.id == id) { + param.value = val; + return; + } + } + A8kModCustomParam param = new A8kModCustomParam(); + param.mid = mid; + param.id = id; + param.value = val; + customParamSet.add(param); + } +} diff --git a/src/main/java/a8k/hardware/custom_param_mgr/ModCustomParamId.java b/src/main/java/a8k/hardware/custom_param_mgr/ModCustomParamId.java new file mode 100644 index 0000000..6fab35b --- /dev/null +++ b/src/main/java/a8k/hardware/custom_param_mgr/ModCustomParamId.java @@ -0,0 +1,14 @@ +package a8k.service.hardware.canbus.custom_param_mgr; + +public enum ModCustomParamId { + + MOTOR_STANDY_POS_COMPENSATE("电机待机位置零点补偿"),//待机位置 = 零点- 零点补偿 + ; + public final String desc; + public final Integer defaultVal; + + ModCustomParamId(String desc) { + this.desc = desc; + this.defaultVal = 0; + } +} diff --git a/src/main/java/a8k/hardware/type/PipetteSampleData.java b/src/main/java/a8k/hardware/type/PipetteSampleData.java new file mode 100644 index 0000000..3dad5ee --- /dev/null +++ b/src/main/java/a8k/hardware/type/PipetteSampleData.java @@ -0,0 +1,7 @@ +package a8k.service.hardware.canbus.data; + +public class PipetteSampleData { + public Integer motorPos; + public Integer cval; + public Integer pval; +} diff --git a/src/main/java/a8k/service/appeventbus/AppEventBusService.java b/src/main/java/a8k/service/appeventbus/AppEventBusService.java deleted file mode 100644 index 2aa0061..0000000 --- a/src/main/java/a8k/service/appeventbus/AppEventBusService.java +++ /dev/null @@ -1,69 +0,0 @@ -package a8k.service.appeventbus; - -import a8k.service.appeventbus.appevent.AppEvent; -import jakarta.annotation.PostConstruct; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.ContextRefreshedEvent; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - -@Component -public class AppEventBusService implements ApplicationListener { - public static final Logger logger = LoggerFactory.getLogger(AppEventBusService.class); - - Thread eventProcessorThread; - BlockingQueue eventQueue = new LinkedBlockingQueue<>(); - List listeners = new ArrayList<>(); - - @PostConstruct - public void init() { - - } - - public void regListener(AppEventListener listener) { - listeners.add(listener); - } - - - public void pushEvent(AppEvent event) { - logger.info("pushEvent: {}", event); - eventQueue.add(event); - } - - private void eventBusSchedule() { - while (!Thread.currentThread().isInterrupted()) { - try { - AppEvent event = eventQueue.take(); - callOnEvent(event); - } catch (InterruptedException ignored) { - } - } - } - - private void callOnEvent(AppEvent event) { - logger.info("Processing event: {}", event); - for (AppEventListener listener : listeners) { - listener.onAppEvent(event); - } - } - - @Override - public void onApplicationEvent(ContextRefreshedEvent event) { - logger.info("Spring context refreshed"); - if (eventProcessorThread == null) { - eventProcessorThread = new Thread(new Runnable() { - public void run() { - logger.info("Starting event bus schedule"); - eventBusSchedule(); - } - }); - eventProcessorThread.start(); - } - } -} diff --git a/src/main/java/a8k/service/appeventbus/AppEventListener.java b/src/main/java/a8k/service/appeventbus/AppEventListener.java deleted file mode 100644 index 48f0fdc..0000000 --- a/src/main/java/a8k/service/appeventbus/AppEventListener.java +++ /dev/null @@ -1,7 +0,0 @@ -package a8k.service.appeventbus; - -import a8k.service.appeventbus.appevent.AppEvent; - -public interface AppEventListener { - public void onAppEvent(AppEvent event); -} diff --git a/src/main/java/a8k/service/appeventbus/appevent/A8kCanBusOnConnectEvent.java b/src/main/java/a8k/service/appeventbus/appevent/A8kCanBusOnConnectEvent.java deleted file mode 100644 index e71dd04..0000000 --- a/src/main/java/a8k/service/appeventbus/appevent/A8kCanBusOnConnectEvent.java +++ /dev/null @@ -1,7 +0,0 @@ -package a8k.service.appeventbus.appevent; - -public class A8kCanBusOnConnectEvent extends AppEvent { - public A8kCanBusOnConnectEvent() { - super(A8kCanBusOnConnectEvent.class.getSimpleName()); - } -} diff --git a/src/main/java/a8k/service/appeventbus/appevent/A8kHardwareReport.java b/src/main/java/a8k/service/appeventbus/appevent/A8kHardwareReport.java deleted file mode 100644 index dfeaab9..0000000 --- a/src/main/java/a8k/service/appeventbus/appevent/A8kHardwareReport.java +++ /dev/null @@ -1,23 +0,0 @@ -package a8k.service.appeventbus.appevent; - -import a8k.service.hardware.canbus.protocol.A8kPacket; -import org.springframework.lang.NonNull; - -/** - * A8k底层硬件上报事件 - */ -public class A8kHardwareReport extends AppEvent{ - A8kPacket reportPacket; - public A8kHardwareReport(@NonNull A8kPacket packet) { - super(A8kHardwareReport.class.getSimpleName()); - this.reportPacket = packet; - } - - public A8kPacket getReportPacket(){ - return reportPacket; - } - - public String toString(){ - return String.format("|Event A8kHardwareReport :%s|", reportPacket.toString()); - } -} diff --git a/src/main/java/a8k/service/appeventbus/appevent/A8kStateChangeEvent.java b/src/main/java/a8k/service/appeventbus/appevent/A8kStateChangeEvent.java deleted file mode 100644 index f90b827..0000000 --- a/src/main/java/a8k/service/appeventbus/appevent/A8kStateChangeEvent.java +++ /dev/null @@ -1,8 +0,0 @@ -package a8k.service.appeventbus.appevent; - -public class A8kStateChangeEvent extends AppEvent { - - A8kStateChangeEvent(String displayInfo) { - super(A8kStateChangeEvent.class.getSimpleName()); - } -} diff --git a/src/main/java/a8k/service/appeventbus/appevent/AppEvent.java b/src/main/java/a8k/service/appeventbus/appevent/AppEvent.java deleted file mode 100644 index 846e1ef..0000000 --- a/src/main/java/a8k/service/appeventbus/appevent/AppEvent.java +++ /dev/null @@ -1,8 +0,0 @@ -package a8k.service.appeventbus.appevent; - -public class AppEvent { - public String typeName; - public AppEvent(String typeName) { - this.typeName = typeName; - } -} diff --git a/src/main/java/a8k/service/appeventbus/appevent/AppStepNotifyEvent.java b/src/main/java/a8k/service/appeventbus/appevent/AppStepNotifyEvent.java deleted file mode 100644 index b219cbc..0000000 --- a/src/main/java/a8k/service/appeventbus/appevent/AppStepNotifyEvent.java +++ /dev/null @@ -1,15 +0,0 @@ -package a8k.service.appeventbus.appevent; - - -public class AppStepNotifyEvent extends AppEvent { - String displayInfo; - - AppStepNotifyEvent(String displayInfo) { - super(AppStepNotifyEvent.class.getSimpleName()); - this.displayInfo = displayInfo; - } - - public String getDisplayInfo() { - return displayInfo; - } -} diff --git a/src/main/java/a8k/service/appeventbus/appevent/AppWarningNotifyEvent.java b/src/main/java/a8k/service/appeventbus/appevent/AppWarningNotifyEvent.java deleted file mode 100644 index 29ea334..0000000 --- a/src/main/java/a8k/service/appeventbus/appevent/AppWarningNotifyEvent.java +++ /dev/null @@ -1,15 +0,0 @@ -package a8k.service.appeventbus.appevent; - -public class AppWarningNotifyEvent extends AppEvent { - String displayInfo; - - AppWarningNotifyEvent(String displayInfo) { - super(AppWarningNotifyEvent.class.getSimpleName()); - this.displayInfo = displayInfo; - } - - public String getDisplayInfo() { - return displayInfo; - } - -} diff --git a/src/main/java/a8k/service/appeventbus/appevent/NewAppIDCardDetectEvent.java b/src/main/java/a8k/service/appeventbus/appevent/NewAppIDCardDetectEvent.java deleted file mode 100644 index f9a7ad8..0000000 --- a/src/main/java/a8k/service/appeventbus/appevent/NewAppIDCardDetectEvent.java +++ /dev/null @@ -1,26 +0,0 @@ -package a8k.service.appeventbus.appevent; - -import a8k.db.ProjectInfo; - -public class NewAppIDCardDetectEvent extends AppEvent { - Boolean newIdCardInfo; - ProjectInfo projectInfo; - - public NewAppIDCardDetectEvent() { - super(NewAppIDCardDetectEvent.class.getSimpleName()); - } - - public NewAppIDCardDetectEvent(Boolean newIdCardInfo, ProjectInfo projectInfo) { - super(NewAppIDCardDetectEvent.class.getSimpleName()); - this.newIdCardInfo = newIdCardInfo; - this.projectInfo = projectInfo; - } - - public Boolean getNewIdCardInfo() { - return newIdCardInfo; - } - - public ProjectInfo getProjectInfo() { - return projectInfo; - } -} diff --git a/src/main/java/a8k/service/hardware/canbus/A8kCanBusService.java b/src/main/java/a8k/service/hardware/canbus/A8kCanBusService.java deleted file mode 100644 index 8aaf518..0000000 --- a/src/main/java/a8k/service/hardware/canbus/A8kCanBusService.java +++ /dev/null @@ -1,888 +0,0 @@ -package a8k.service.hardware.canbus; - -import a8k.service.appeventbus.appevent.A8kCanBusOnConnectEvent; -import a8k.appbase.OptScanDirection; -import a8k.appbase.PlateInfo; -import a8k.service.hardware.canbus.custom_param_mgr.A8kModCustomParamMgr; -import a8k.service.hardware.canbus.data.PipetteSampleData; -import a8k.service.hardware.canbus.protocol.*; -import a8k.service.hardware.canbus.protocol.MId; -import a8k.appbase.HardwareException; -import a8k.appbase.cfg.Pos2d; -import a8k.service.appeventbus.appevent.A8kHardwareReport; -import a8k.service.appeventbus.AppEventBusService; -import a8k.utils.ByteArray; -import jakarta.annotation.PostConstruct; -import jakarta.annotation.Resource; -import org.java_websocket.client.WebSocketClient; -import org.java_websocket.enums.ReadyState; -import org.java_websocket.handshake.ServerHandshake; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.*; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; - -@Component -public class A8kCanBusService { - public static final Logger logger = LoggerFactory.getLogger(A8kCanBusService.class); - - /** - * receiptQueue - * waittingReceiptIndex - * - * onPacket - * if(receipt) - * send_receipt_queue - * - * - * sendcmd - * send cmd - * waiting for receipt - * for(){ - * if(receipt.packetIndex == receiptIndex){ - * return; - * } - * wait - * } - * - */ - - @Resource - private AppEventBusService eventBus; - - @Resource - private A8kModCustomParamMgr customParamMgr; - - public String uri; // assign by application.yml - private WebSocketClient client; - private A8kPacket txPacketContext; - - // 接收回执上下文 - public BlockingQueue receiptQueue = new LinkedBlockingQueue(); // - boolean isWaitingReceipt = false; // - int waitingReceiptIndex = 0;// - - // 发送包的packetIndex - int packetIndex = 0;// - - // 调试标志位 - boolean debugFlag = true;// - // websocket自动重连时间 - Timer autoConnectTimer = new Timer();// - - - Map lastCmdMap = new HashMap<>(); - - @PostConstruct - public void init() throws URISyntaxException { - - logger.info("BaseHardwareService initilized"); - packetIndex = 0; - if (this.uri == null) { - // this.uri = "ws://127.0.0.1:19005"; - this.uri = "ws://192.168.8.10:19005"; - } - - URI uri = new URI(this.uri); - client = new WebSocketClient(uri) { - @Override - public void onOpen(ServerHandshake serverHandshake) { - logger.info("a8k canbus connect sucess"); - eventBus.pushEvent(new A8kCanBusOnConnectEvent()); - } - - @Override - public void onMessage(String s) { - processMessage(s); - } - - @Override - public void onClose(int i, String s, boolean b) { - logger.warn("a8k canbus lost connection..."); - } - - @Override - public void onError(Exception e) { - logger.info("onError"); - } - }; - client.connect(); - - autoConnectTimer.schedule(new TimerTask() { - @Override - public void run() { - if (!client.isOpen()) { - if (client.getReadyState().equals(ReadyState.NOT_YET_CONNECTED)) { - try { - client.connect(); - } catch (IllegalStateException e) { - } - } else if (client.getReadyState().equals(ReadyState.CLOSED)) { - client.reconnect(); - } - } - } - }, 0, 1000); - } - - public void forceShutdown() { - client.close(); - } - - - private A8kPacket packParamsToPacket(Integer moduleId, Integer cmdId, Integer[] params) { - int subCmdId = cmdId & 0xFF; - int mainCmdId = (cmdId >> 8) & 0xFFFF; - int bufferSize = 2 + 2 + 1 + 1 + 2 + 4 * params.length; // PacketIndex - MainCmdId - SubCmdId - CmdType - - // ModuleId - Parameters - ByteBuffer buffer = ByteBuffer.allocate(bufferSize); - buffer.order(ByteOrder.LITTLE_ENDIAN); - buffer.putShort((short) 0); // PacketIndex - buffer.putShort((short) mainCmdId); // MainCmdId - buffer.put((byte) subCmdId); // SubCmdId - buffer.put((byte) 0); // CmdType - buffer.putShort(moduleId.shortValue()); // ModuleId - for (int value : params) { - buffer.putInt(value); - } - return new A8kPacket(buffer.array()); - } - - private void setTxPacketContext(A8kPacket packet) { - txPacketContext = packet; - } - - synchronized private A8kPacket getTxPacketContext() { - return txPacketContext; - } - - - public byte[] a8kIdcardReaderReadRaw() throws HardwareException { - int i = 0; - byte[] result = new byte[0]; - while (true) { - var rxPacket = callcmd(MId.A8kIdCardReader.toInt(), CmdId.a8000_idcard_reader_read_raw.toInt(), i++); - if (rxPacket.getCmdContent().length == 0) { - break; - } - result = ByteArray.concat(result, rxPacket.getCmdContent()); - } - return result; - } - - - public void pipetteCtrlInitDevice(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_ctrl_init_device.toInt()); - } - - public void pipetteCtrlInitDeviceBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { - pipetteCtrlInitDevice(id); - waitForMod(id, actionOvertime); - } - - public void pipetteCtrlPutTip(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_ctrl_put_tip.toInt()); - } - - public void pipetteCtrlPutTipBlock(MId id) throws HardwareException, InterruptedException { - pipetteCtrlPutTip(id); - waitForMod(id, 10000); - } - - - public void pipetteCtrlPrepare(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_lld_prepare.toInt()); - } - - public void pipetteCtrlPlld(MId id, int zdpos, int p_threshold) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_plld.toInt(), zdpos, p_threshold); - } - - public void pipetteCtrlClld(MId id, int zdpos, int c_threshold) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_clld.toInt(), zdpos, c_threshold); - } - - public void pipetteCtrlMlld(MId id, int zdpos, int c_threshold, int p_threshold) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_mlld.toInt(), zdpos, c_threshold, p_threshold); - } - - public Integer pipetteCtrlLldIsDetectLiquid(MId id) throws HardwareException { - var packet = callcmd(id.toInt(), CmdId.pipette_lld_is_detect_liquid.toInt()); - return packet.getContentI32(0); - } - - public void pipetteAspirate(MId id, int ul) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_aspirate.toInt(), ul); - } - - public void pipetteDistribut(MId id, int ul) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_distribut.toInt(), ul); - } - - public void pipetteShakeUp(MId id, int ul, int times) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_shake_up.toInt(), ul, times); - } - - public void pipetteAspirateLlf(MId id, int ul, int zmotor_v) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_aspirate_llf.toInt(), ul, zmotor_v); - } - - public void pipetteDistributLlf(MId id, int ul, int zmotor_v) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_distribut_llf.toInt(), ul, zmotor_v); - } - - public void pipetteShakeUpLlf(MId id, int ul, int zmotor_v, int times) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_shake_up_llf.toInt(), ul, zmotor_v, times); - } - - public void pipetteEnableZmotor(MId id, int enable) throws HardwareException { - callcmd(id.toInt(), CmdId.pipette_enable_zmotor.toInt(), enable); - } - - public PipetteSampleData pipetteGetSensorSampleData(MId id, int index) throws HardwareException { - var packet = callcmd(id.toInt(), CmdId.pipette_get_sensor_sample_data.toInt(), index); - if (packet.getCmdContent().length == 0) { - return null; - } - PipetteSampleData sampleData = new PipetteSampleData(); - sampleData.motorPos = packet.getContentI32(0); - sampleData.cval = packet.getContentI32(1); - sampleData.pval = packet.getContentI32(2); - return sampleData; - } - - public void optTStartScan(MId id, OptScanDirection scanDirection, Integer lasterGain, Integer scanGain) throws HardwareException, InterruptedException { - callcmd(id.toInt(), CmdId.a8k_opt_v2_t_start_scan.toInt(), scanDirection.getInteger(), lasterGain, scanGain); - } - - public void optTStartScanBlock(MId id, OptScanDirection scanDirection, Integer lasterGain, Integer scanGain, Integer actionOvertime) throws HardwareException, InterruptedException { - optTStartScan(id, scanDirection, lasterGain, scanGain); - waitForMod(id, actionOvertime); - } - - public void optFStartScan(MId id, OptScanDirection scanDirection, Integer lasterGain, Integer scanGain) throws HardwareException, InterruptedException { - callcmd(id.toInt(), CmdId.a8k_opt_v2_f_start_scan.toInt(), scanDirection.getInteger(), lasterGain, scanGain); - } - - public void optFStartScanBlock(MId id, OptScanDirection scanDirection, Integer lasterGain, Integer scanGain, Integer actionOvertime) throws HardwareException, InterruptedException { - optFStartScan(id, scanDirection, lasterGain, scanGain); - waitForMod(id, actionOvertime); - } - - public List optReadRaw(MId id) throws HardwareException, InterruptedException { - int i = 0; - List result = new ArrayList<>(); - while (true) { - var rxPacket = callcmd(id.toInt(), CmdId.a8k_opt_v2_read_raw.toInt(), i++); - if (rxPacket.getCmdContent().length == 0) { - break; - } - var rawdata = ByteArray.readU16bitArray(rxPacket.getCmdContent()); - result.addAll(Arrays.asList(rawdata)); - } - return result; - } - - - public void plateCodeScanerPushCardAndScan(MId id, Integer finalStopPos) throws HardwareException, InterruptedException { - callcmd(id.toInt(), CmdId.plate_code_scaner_push_card_and_scan.toInt(), finalStopPos); - } - - public void plateCodeScanerPushCardAndScanBlock(MId id, Integer finalStopPos, Integer actionOvertime) throws HardwareException, InterruptedException { - plateCodeScanerPushCardAndScan(id, finalStopPos); - waitForMod(id, actionOvertime); - } - - public void plateCodeScanerStopScan(MId id) throws HardwareException, InterruptedException { - callcmd(id.toInt(), CmdId.plate_code_scaner_stop_scan.toInt()); - } - - public List plateCodeScanerReadRawResult(MId id) throws HardwareException, InterruptedException { - int i = 0; - List result = new ArrayList<>(); - while (true) { - var rxPacket = callcmd(id.toInt(), CmdId.plate_code_scaner_read_result.toInt(), i++); - if (rxPacket.getCmdContent().length == 0) { - break; - } - var rawdata = ByteArray.readU16bitArray(rxPacket.getCmdContent()); - result.addAll(Arrays.asList(rawdata)); - } - return result; - } - - public PlateInfo plateCodeScannerReadCode(MId mid) throws HardwareException { - var receipt = callcmd(mid.toInt(), CmdId.plate_code_scaner_read_code.toInt()); - PlateInfo plateInfo = new PlateInfo(); - plateInfo.rawcode = Integer.toBinaryString(receipt.getContentI32(0)); - plateInfo.legal = receipt.getContentI32(1) != 0; - plateInfo.lot = receipt.getContentI32(2); - plateInfo.item = receipt.getContentI32(3); - return plateInfo; - } - - public void plateCodeScanerOpenLaser(MId id) throws HardwareException, InterruptedException { - callcmd(id.toInt(), CmdId.plate_code_scaner_open_laser.toInt()); - } - - public void plateCodeScanerCloseLaser(MId id) throws HardwareException, InterruptedException { - callcmd(id.toInt(), CmdId.plate_code_scaner_close_laser.toInt()); - } - - - public Integer plateCodeScanerAdcReadRaw(MId id) throws HardwareException, InterruptedException { - var packet = callcmd(id.toInt(), CmdId.plate_code_scaner_adc_readraw.toInt()); - return packet.getContentI32(0); - } - - - public void fanControlerSetSpeed(MId id, int speed) throws HardwareException, InterruptedException { - callcmd(id.toInt(), CmdId.fan_controler_set_speed.toInt(), speed); - } - - - public void codeScanerStartScan(MId id) throws HardwareException, InterruptedException { - callcmd(id.toInt(), CmdId.code_scaner_start_scan.toInt()); - } - - public void codeScanerStopScan(MId id) throws HardwareException, InterruptedException { - callcmd(id.toInt(), CmdId.code_scaner_stop_scan.toInt()); - } - - public String codeScanerReadScanerResult(MId id) throws HardwareException, InterruptedException { - A8kPacket ack = callcmd(id.toInt(), CmdId.code_scaner_read_scaner_result.toInt()); - var contentBytes = ack.getCmdContent(); - return new String(contentBytes); - } - - public Boolean codeScanerResultIsReady(MId id) throws HardwareException, InterruptedException { - var packet = callcmd(id.toInt(), CmdId.code_scaner_result_is_ready.toInt()); - return packet.getContentI32(0) != 0; - } - - public String codeScanerWaittingForResult(MId mid, Integer acitionOvertime) throws HardwareException, InterruptedException { - long startedAt = System.currentTimeMillis(); - do { - if (codeScanerResultIsReady(mid)) - break; - long now = System.currentTimeMillis(); - if (now - startedAt > acitionOvertime) { - codeScanerStopScan(mid); - return null; - } - Thread.sleep(100); - } while (true); - codeScanerStopScan(mid); - return codeScanerReadScanerResult(mid); - } - - // - // module opeation - // - public void modulePing(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.module_ping.toInt()); - } - - public void moduleStop(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.module_stop.toInt()); - } - - public ModuleStatus getModuleStatus(MId id) throws HardwareException { - var packet = callcmd(id.toInt(), CmdId.module_get_status.toInt()); - return ModuleStatus.valueOf(packet.getContentI32(0)); - - } - - public void moduleSetReg(MId id, RegIndex regindex, Integer reg) throws HardwareException { - callcmd(id.toInt(), CmdId.module_set_reg.toInt(), regindex.index, reg); - } - - public Integer moduleGetReg(MId id, RegIndex regindex) throws HardwareException { - var packet = callcmd(id.toInt(), CmdId.module_get_reg.toInt(), regindex.index); - return packet.getContentI32(0); - } - - public A8kEcode moduleGetError(MId id) throws HardwareException { - var packet = callcmd(id.toInt(), CmdId.module_get_error.toInt()); - return A8kEcode.valueOf(packet.getContentI32(0)); - } - - public void moduleClearError(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.module_clear_error.toInt()); - } - - public void moduleActiveCfg(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.module_active_cfg.toInt()); - } - - - public void hbotEnable(MId mid, int enable) throws HardwareException { - callcmd(mid.toInt(), CmdId.xymotor_enable.toInt(), enable); - } - - public void hbotMoveBy(MId mid, int x, int y) throws HardwareException { - callcmd(mid.toInt(), CmdId.xymotor_move_by.toInt(), x, y); - } - - public void hbotMoveByBlock(MId mid, int x, int y, Integer actionOvertime) throws HardwareException, InterruptedException { - hbotMoveBy(mid, x, y); - waitForMod(mid, actionOvertime); - } - - public void hbotMoveTo(MId mid, int x, int y) throws HardwareException { - callcmd(mid.toInt(), CmdId.xymotor_move_to.toInt(), x, y); - } - - public void hbotMoveToBlock(MId mid, int x, int y, Integer actionOvertime) throws HardwareException, InterruptedException { - hbotMoveTo(mid, x, y); - waitForMod(mid, actionOvertime); - } - - public void hbotMoveToZero(MId mid) throws HardwareException { - callcmd(mid.toInt(), CmdId.xymotor_move_to_zero.toInt()); - } - - public void hbotMoveToZeroBlock(MId mid, Integer actionOvertime) throws HardwareException, InterruptedException { - hbotMoveToZero(mid); - waitForMod(mid, actionOvertime); - } - - public Pos2d hbotReadPos(MId mid) throws HardwareException { - Pos2d pos = new Pos2d(0, 0); - var packet = callcmd(mid.toInt(), CmdId.xymotor_read_pos.toInt()); - pos.x = packet.getContentI32(0); - pos.y = packet.getContentI32(1); - return pos; - } - - public Boolean hbotReadInio(MId mid, int ioIndex) throws HardwareException { - var packet = callcmd(mid.toInt(), CmdId.xymotor_read_inio.toInt(), ioIndex); - return packet.getContentI32(0) != 0; - } - - public void hbotSetPos(MId mid, int x, int y) throws HardwareException { - callcmd(mid.toInt(), CmdId.xymotor_set_pos.toInt(), x, y); - } - - - public void hbotMoveByDirect(MId mid, int motor1_dpos, int motor2_dpos) throws HardwareException { - callcmd(mid.toInt(), CmdId.xymotor_motor_move_by_direct.toInt(), motor1_dpos, motor2_dpos); - } - - public int hbotReadEncDirect(MId mid) throws HardwareException { - var packet = callcmd(mid.toInt(), CmdId.xymotor_read_enc_direct.toInt()); - return packet.getContentI32(0); - } - - public int hbotReadInioIndexInStm32(MId mid, int ioIndex) throws HardwareException { - var packet = callcmd(mid.toInt(), CmdId.xymotor_read_inio_index_in_stm32.toInt(), ioIndex); - return packet.getContentI32(0); - } - - - // - // stepMotor - // - public void stepMotorEnable(MId mid, int enable) throws HardwareException { - callcmd(mid.toInt(), CmdId.step_motor_enable.toInt(), enable); - } - - public Integer stepMotorReadPos(MId id) throws HardwareException { - A8kPacket packet = callcmd(id.toInt(), CmdId.step_motor_read_pos.toInt()); - return packet.getContentI32(0); - } - - public void stepMotorEasyRotate(MId id, int direction) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_easy_rotate.toInt(), direction); - } - - public void stepMotorEasyMoveBy(MId id, int dpos) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_easy_move_by.toInt(), dpos); - } - - public void stepMotorEasyMoveByBlock(MId id, int dpos, Integer actionOvertime) throws HardwareException, InterruptedException { - stepMotorEasyMoveBy(id, dpos); - waitForMod(id, actionOvertime); - } - - public void stepMotorEasyMoveTo(MId id, int pos) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_easy_move_to.toInt(), pos); - } - - public void stepMotorEasyMoveToBlock(MId id, int pos, Integer actionOvertime) throws HardwareException, InterruptedException { - stepMotorEasyMoveTo(id, pos); - waitForMod(id, actionOvertime); - } - - public void stepMotorEasyMoveToZero(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_easy_move_to_zero.toInt()); - } - - public void stepMotorEasyMoveToZeroBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { - stepMotorEasyMoveToZero(id); - waitForMod(id, actionOvertime); - } - - public Integer stepMotorReadPosByMoveToZeroBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { - stepMotorEnable(id, 1); - stepMotorEasyMoveToZeroBlock(id, actionOvertime); - Integer nowpos = stepMotorReadPos(id); - Integer measurepos = -moduleGetReg(id, RegIndex.kreg_step_motor_dpos) + nowpos; - stepMotorEnable(id, 0); - return measurepos; - } - - public void stepMotorEasySetCurrentPos(MId id, int pos) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_easy_set_current_pos.toInt(), pos); - } - - public void stepMotorEasyMoveToIo(MId id, int io) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_easy_move_to_io.toInt(), io); - } - - // step_motor_easy_move_to_zero_point_quick - - public void stepMotorEasyMoveToZeroPointQuick(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_easy_move_to_zero_point_quick.toInt()); - } - - public void stepMotorEasyMoveToZeroPointQuickBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { - stepMotorEasyMoveToZeroPointQuick(id); - waitForMod(id, actionOvertime); - } - - public void stepMotorStop(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_stop.toInt(),0); - } - - public void stepMotorActiveCfg(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_active_cfg.toInt()); - } - - public Boolean stepMotorReadIoState(MId id, int ioindex) throws HardwareException { - var packet = callcmd(id.toInt(), CmdId.step_motor_read_io_state.toInt(), ioindex); - return packet.getContentI32(0) != 0; - } - - public void stepMotorEasyMoveToEndPoint(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_easy_move_to_end_point.toInt()); - } - - public void stepMotorEasyMoveToEndPointBlock(MId id, Integer actionOvertime) throws HardwareException, InterruptedException { - stepMotorEasyMoveToEndPoint(id); - waitForMod(id, actionOvertime); - } - - public void stepMotorEasyReciprocatingMotion(MId id, int startpos, int endpos, int times) throws HardwareException { - callcmd(id.toInt(), CmdId.step_motor_easy_reciprocating_motion.toInt(), startpos, endpos, times); - } - - public void stepMotorEasyReciprocatingMotionBlock(MId id, int startpos, int endpos, int times, Integer actionOvertime) throws HardwareException, InterruptedException { - stepMotorEasyReciprocatingMotion(id, startpos, endpos, times); - waitForMod(id, actionOvertime); - } - // - // MINI_SERVO - // - - public void miniServoEnable(MId id, int enable) throws HardwareException { - callcmd(id.toInt(), CmdId.mini_servo_enable.toInt(), enable); - } - - public int miniServoReadPos(MId id) throws HardwareException { - var packet = callcmd(id.toInt(), CmdId.mini_servo_read_pos.toInt()); - return packet.getContentI32(0); - } - - - public void miniServoActiveCfg(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.mini_servo_active_cfg.toInt()); - } - - public void miniServoStop(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.mini_servo_stop.toInt()); - } - - public void miniServoSetMidPoint(MId id) throws HardwareException { - callcmd(id.toInt(), CmdId.mini_servo_set_mid_point.toInt()); - } - - public int miniServoReadIoState(MId id) throws HardwareException { - var packet = callcmd(id.toInt(), CmdId.mini_servo_read_io_state.toInt()); - return packet.getContentI32(0); - } - - public void miniServoMoveTo(MId id, int pos) throws HardwareException { - callcmd(id.toInt(), CmdId.mini_servo_move_to.toInt(), pos); - } - - public void miniServoMoveToBlock(MId id, int pos, Integer actionOvertime) throws HardwareException, InterruptedException { - miniServoMoveTo(id, pos); - waitForMod(id, actionOvertime); - } - - public void miniServoRotate(MId id, int direction) throws HardwareException { - callcmd(id.toInt(), CmdId.mini_servo_rotate.toInt(), direction); - } - - public void miniServoRotateBlock(MId id, int direction, Integer actionOvertime) throws HardwareException, InterruptedException { - miniServoRotate(id, direction); - waitForMod(id, actionOvertime); - } - - public void miniServoRotateWithTorque(MId id, int torque) throws HardwareException { - callcmd(id.toInt(), CmdId.mini_servo_rotate_with_torque.toInt(), torque); - } - - public void miniServoRotateWithTorqueBlock(MId id, int torque, Integer actionOvertime) throws HardwareException, InterruptedException { - miniServoRotateWithTorque(id, torque); - miniServoWaitIsNotMove(id, actionOvertime); - } - - public void miniServoWaitIsNotMove(MId id, int acitionOvertime) throws HardwareException, InterruptedException { - long startedAt = System.currentTimeMillis(); - do { - var isMove = moduleGetReg(id, RegIndex.kreg_mini_servo_is_move); - if (isMove != 0) { - break; - } - long now = System.currentTimeMillis(); - if (now - startedAt > acitionOvertime) { - throw new HardwareException(id, A8kEcode.Overtime); - } - - } while (true); - } - - public Boolean priGetIOState(IOId ioid) throws HardwareException { - if (ioid.mtype == ModuleType.kboard) { - return callcmd(ioid.mid.toInt(), CmdId.extboard_read_inio.toInt(), ioid.ioIndex).getContentI32(0) != 0; - } else if (ioid.mtype == ModuleType.ktmc_step_motor) { - return callcmd(ioid.mid.toInt(), CmdId.step_motor_read_io_state.toInt(), ioid.ioIndex).getContentI32(0) != 0; - } else if (ioid.mtype == ModuleType.kmini_servo_motor_module) { - return callcmd(ioid.mid.toInt(), CmdId.mini_servo_read_io_state.toInt(), ioid.ioIndex).getContentI32(0) != 0; - } else { - throw new HardwareException(ioid.mid, A8kEcode.IllegalOperation); - } - } - - public Boolean getIOState(IOId ioid) throws HardwareException { - while (true) { - Boolean firstReadIO = priGetIOState(ioid); - Boolean secondReadIO = priGetIOState(ioid); - if (firstReadIO == secondReadIO) { - return firstReadIO; - } else { - logger.warn("getIOState {} not match, retry", ioid); - } - } - } - - - public void setIOState(IOId ioid, boolean val) throws HardwareException { - if (ioid.mtype == ModuleType.kboard) { - callcmd(ioid.mid.toInt(), CmdId.extboard_write_outio.toInt(), ioid.ioIndex, val ? 1 : 0); - } else { - throw new HardwareException(ioid.mid, A8kEcode.IllegalOperation); - } - } - - - public void waitForMods(MId[] mids, Integer acitionOvertime) throws InterruptedException, HardwareException { - for (MId mid : mids) { - waitForMod(mid, acitionOvertime); - } - } - - public void waitForMod(MId mid, Integer acitionOvertime) throws InterruptedException, HardwareException { - long startedAt = System.currentTimeMillis(); - // Thread.sleep(300); - // CmdId action = lastCmdMap.get(mid); - CmdId action = lastCmdMapGet(mid); - do { - ModuleStatus statu = null; - try { - statu = getModuleStatus(mid); - } catch (HardwareException ignored) { - } - if (statu == ModuleStatus.IDLE) { - break; - } else if (statu == ModuleStatus.ERROR) { - logger.error("{} waitting for action {} , catch error {}", mid, action, moduleGetError(mid)); - throw new HardwareException(mid, moduleGetError(mid)); - } - - long now = System.currentTimeMillis(); - if (now - startedAt > acitionOvertime) { - logger.error("{} waitting for action {} overtime", mid, action); - try { - moduleStop(mid); - } catch (HardwareException ignored) { - } - throw new HardwareException(mid, A8kEcode.ActionOvertime); - } - Thread.sleep(100); - } while (true); - } - - public A8kPacket callcmd(Integer moduleId, Integer cmdId) throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[]{}); - } - - public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0) throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[]{p0}); - } - - public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1) throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1}); - } - - public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2) throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2}); - } - - public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3) throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2, p3}); - } - - - public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer[] params) throws HardwareException { - var packet = packParamsToPacket(moduleId, cmdId, params); - return sendCmdAutoResend(packet, A8kPacket.CMD_OVERTIME); - } - - synchronized public A8kPacket sendCmdAutoResend(A8kPacket pack, int overtime) throws HardwareException { - // 调用sendCmd, - // 如果捕获到超时异常,则重发,最多重发三次 - // 如果是其他异常,则直接抛出异常。 - for (int i = 0; i < 5; i++) { - try { - return this.sendCmd(pack, A8kPacket.CMD_OVERTIME); - } catch (HardwareException e) { - if (e.getErrorCode() != A8kEcode.Overtime) { - throw e; - } - } - try { - Thread.sleep(100); - } catch (InterruptedException ignore) { - } - logger.error("send cmd {} fail, retry {}", pack, i); - } - throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.Overtime); - } - - - private A8kPacket sendCmd(A8kPacket pack, int overtime) throws HardwareException { - pack.setPacketIndex(packetIndex); - waitingReceiptIndex = packetIndex; - packetIndex = packetIndex + 1; - if (packetIndex > 10000) { - packetIndex = 1; - } - receiptQueue.clear(); - isWaitingReceipt = true; - String txpacket = pack.toByteString(); - - CmdId cmdid = CmdId.valueOf(pack.getCmdId()); - if (cmdid == null) { - throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.CmdIdNotSupport); - } - if (debugFlag && pack.isTrace()) { - String packstr = pack.toString(); - logger.info("Tx:|RAW:{}| {}", txpacket, packstr); - } - - if (cmdid.actionCmd) { - lastCmdMapPut(MId.valueOf(pack.getModuleId()), CmdId.valueOf(pack.getCmdId())); - } - - txPacketContext = pack; - client.send(txpacket); - A8kPacket receipt; - try { - receipt = receiptQueue.poll(overtime, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - isWaitingReceipt = false; - throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.Overtime); - } - isWaitingReceipt = false; - if (receipt == null) { - throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.Overtime); - } - - if (receipt.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { - throw new HardwareException(MId.valueOf(pack.getModuleId()), A8kEcode.valueOf(receipt.getContentI32(0))); - } - try { - Thread.sleep(10); - } catch (InterruptedException ignored) { - } - return receipt; - } - - /** - * - */ - private void processMessage(String s) { - byte[] rx = ByteArray.hexStringToBytes(s); - if (rx == null || rx.length == 0) { - logger.warn("rx is empty"); - return; - } - - if (rx.length < A8kPacket.PACKET_MIN_LEN) { - logger.warn("rx is too short"); - return; - } - - A8kPacket packet = new A8kPacket(rx); - - if (!packet.isSupportPacket()) { - logger.warn("Rx packet not support: {}", packet); - return; - } - - A8kPacket tpCxt = this.txPacketContext; - if (debugFlag) { - if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK) { - if (tpCxt != null && tpCxt.getPacketIndex() == packet.getPacketIndex()) { - if (tpCxt.isTrace()) { - logger.info("RX-ACK |RAW:{}| {}", s, packet); - } - } - } else { - logger.info("RX |RAW:{}| {}", s, packet); - } - } - - - if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK || packet.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { - if (isWaitingReceipt) { - if (waitingReceiptIndex == packet.getPacketIndex()) { - receiptQueue.add(packet); - } - } - } - - if (packet.getPacketType() == A8kPacket.PACKET_TYPE_EVENT) { - eventBus.pushEvent(new A8kHardwareReport(packet)); - } - } - - synchronized void lastCmdMapPut(MId mid, CmdId cmdId) { - lastCmdMap.put(mid, cmdId); - } - - synchronized CmdId lastCmdMapGet(MId mid) { - return lastCmdMap.get(mid); - } -} diff --git a/src/main/java/a8k/service/hardware/canbus/A8kModParamInitializer.java b/src/main/java/a8k/service/hardware/canbus/A8kModParamInitializer.java deleted file mode 100644 index 33a12da..0000000 --- a/src/main/java/a8k/service/hardware/canbus/A8kModParamInitializer.java +++ /dev/null @@ -1,127 +0,0 @@ -package a8k.service.hardware.canbus; - -import a8k.service.appeventbus.AppEventBusService; -import a8k.service.appeventbus.appevent.A8kCanBusOnConnectEvent; -import a8k.service.appeventbus.appevent.AppEvent; -import a8k.service.appeventbus.AppEventListener; -import a8k.appbase.HardwareException; -import a8k.service.hardware.canbus.custom_param_mgr.ModCustomParamId; -import a8k.service.hardware.canbus.custom_param_mgr.A8kModCustomParamMgr; -import a8k.service.hardware.canbus.protocol.MId; -import a8k.service.hardware.canbus.protocol.RegIndex; -import jakarta.annotation.PostConstruct; -import jakarta.annotation.Resource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -@Component -public class A8kModParamInitializer implements AppEventListener { - static Logger logger = LoggerFactory.getLogger(A8kModParamInitializer.class); - - @Resource - AppEventBusService eventBus; - - @Resource - A8kCanBusService canBus; - - @Resource - A8kModCustomParamMgr customParamMgr; - - @PostConstruct - public void init() { - logger.info("A8kModInitializer init"); - eventBus.regListener(this); - } - - public void initA8kCustcomParams() { - customParamMgr.setCustomParam(MId.FeedingModXM, ModCustomParamId.MOTOR_STANDY_POS_COMPENSATE, -10); - customParamMgr.setCustomParam(MId.ShakeModGripperZM, ModCustomParamId.MOTOR_STANDY_POS_COMPENSATE, -10); - customParamMgr.setCustomParam(MId.ShakeModClampingM, ModCustomParamId.MOTOR_STANDY_POS_COMPENSATE, -10); - } - - public void initA8kModParams() throws HardwareException { - /* - * 设置位置偏差容忍度 - * 1.如果电机配置有编码器器,则每次调用moveBy,moveTo都会进行位置检查 - * 2.如果电机没有配备编码,则每次调用moveQuickToZeroPoint,都会进行一次位置检查 - */ - canBus.moduleSetReg(MId.FeedingModXM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); - canBus.moduleSetReg(MId.ShakeModClampingM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); - canBus.moduleSetReg(MId.ShakeModGripperZM, RegIndex.kret_step_motor_pos_devi_tolerance, 20); - canBus.moduleSetReg(MId.ShakeModShakeM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); - canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); - canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); - canBus.moduleSetReg(MId.OptModPullM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); - canBus.moduleSetReg(MId.OptModScannerM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); - canBus.moduleSetReg(MId.PipetteModZM, RegIndex.kret_step_motor_pos_devi_tolerance, 20); - canBus.moduleSetReg(MId.IncubatorRotateCtrlM, RegIndex.kret_step_motor_pos_devi_tolerance, 5); - - canBus.moduleSetReg(MId.FeedingModXM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); - canBus.moduleSetReg(MId.ShakeModClampingM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); - canBus.moduleSetReg(MId.ShakeModGripperZM, RegIndex.kret_step_motor_io_trigger_append_distance, 20); - canBus.moduleSetReg(MId.ShakeModShakeM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); - canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); - canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kret_step_motor_io_trigger_append_distance, 3); - canBus.moduleSetReg(MId.OptModPullM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); - canBus.moduleSetReg(MId.OptModScannerM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); - canBus.moduleSetReg(MId.PipetteModZM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); - canBus.moduleSetReg(MId.IncubatorRotateCtrlM, RegIndex.kret_step_motor_io_trigger_append_distance, 10); - - canBus.moduleSetReg(MId.ShakeModGripperYSV, RegIndex.kreg_mini_servo_limit_torque, 700); - - - // - canBus.moduleSetReg(MId.OptModPullM, RegIndex.kreg_step_motor_run_to_zero_speed, 500); - canBus.moduleSetReg(MId.OptModPullM, RegIndex.kreg_step_motor_default_velocity, 2200); - canBus.moduleSetReg(MId.OptModPullM, RegIndex.kreg_step_motor_irun, 31); - - canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kreg_step_motor_default_velocity, 1800); - canBus.moduleSetReg(MId.PlatesBoxPusherM, RegIndex.kreg_step_motor_irun, 31); - - canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kreg_step_motor_default_velocity, 1800); - canBus.moduleSetReg(MId.PlatesBoxYM, RegIndex.kreg_step_motor_irun, 25); - - //Hbot-丢步容忍距离 - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_pos_devi_tolerance, 5); - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_io_trigger_append_distance, 10); - - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_min_x, -100); - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_min_y, -100); - - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_vstart, 1); - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_a1, 5); - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_amax, 15); - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_v1, 100); - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_dmax, 15); - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_d1, 5); - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_vstop, 1); - canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_tzerowait, 300); - - canBus.moduleSetReg(MId.PipetteModZM, RegIndex.kreg_step_motor_default_velocity, 1500); - -// canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_run_to_zero_speed, 300); -// canBus.moduleSetReg(MId.HbotM, RegIndex.kreg_xyrobot_one_circle_pulse, 7215); - // canBus.moduleSetReg(MId.OptModPullM, RegIndex.kreg_step_motor_run_to_zero_speed, 500); - - } - - public void forceInitA8kModParams() { - try { - logger.info("forceInitA8kModParams"); - initA8kModParams(); - } catch (HardwareException e) { - logger.error("init hardware param fail......", e); - //TODO:校验这里的逻辑 - canBus.forceShutdown(); - } - } - - - @Override - public void onAppEvent(AppEvent event) { - if (event instanceof A8kCanBusOnConnectEvent) { - forceInitA8kModParams(); - } - } -} diff --git a/src/main/java/a8k/service/hardware/canbus/custom_param_mgr/A8kModCustomParam.java b/src/main/java/a8k/service/hardware/canbus/custom_param_mgr/A8kModCustomParam.java deleted file mode 100644 index ec8bb45..0000000 --- a/src/main/java/a8k/service/hardware/canbus/custom_param_mgr/A8kModCustomParam.java +++ /dev/null @@ -1,10 +0,0 @@ -package a8k.service.hardware.canbus.custom_param_mgr; - -import a8k.service.hardware.canbus.protocol.MId; - -public class A8kModCustomParam { - MId mid; - public ModCustomParamId id; - public Integer value; - -} diff --git a/src/main/java/a8k/service/hardware/canbus/custom_param_mgr/A8kModCustomParamMgr.java b/src/main/java/a8k/service/hardware/canbus/custom_param_mgr/A8kModCustomParamMgr.java deleted file mode 100644 index 62a7588..0000000 --- a/src/main/java/a8k/service/hardware/canbus/custom_param_mgr/A8kModCustomParamMgr.java +++ /dev/null @@ -1,35 +0,0 @@ -package a8k.service.hardware.canbus.custom_param_mgr; - -import a8k.service.hardware.canbus.protocol.MId; -import org.springframework.stereotype.Component; - -import java.util.Set; - -@Component -public class A8kModCustomParamMgr { - - Set customParamSet; - - public Integer getCustomParam(MId mid, ModCustomParamId id) { - for (A8kModCustomParam param : customParamSet) { - if (param.mid == mid && param.id == id) { - return param.value; - } - } - return id.defaultVal; - } - - public void setCustomParam(MId mid, ModCustomParamId id, Integer val) { - for (A8kModCustomParam param : customParamSet) { - if (param.mid == mid && param.id == id) { - param.value = val; - return; - } - } - A8kModCustomParam param = new A8kModCustomParam(); - param.mid = mid; - param.id = id; - param.value = val; - customParamSet.add(param); - } -} diff --git a/src/main/java/a8k/service/hardware/canbus/custom_param_mgr/ModCustomParamId.java b/src/main/java/a8k/service/hardware/canbus/custom_param_mgr/ModCustomParamId.java deleted file mode 100644 index 6fab35b..0000000 --- a/src/main/java/a8k/service/hardware/canbus/custom_param_mgr/ModCustomParamId.java +++ /dev/null @@ -1,14 +0,0 @@ -package a8k.service.hardware.canbus.custom_param_mgr; - -public enum ModCustomParamId { - - MOTOR_STANDY_POS_COMPENSATE("电机待机位置零点补偿"),//待机位置 = 零点- 零点补偿 - ; - public final String desc; - public final Integer defaultVal; - - ModCustomParamId(String desc) { - this.desc = desc; - this.defaultVal = 0; - } -} diff --git a/src/main/java/a8k/service/hardware/canbus/data/PipetteSampleData.java b/src/main/java/a8k/service/hardware/canbus/data/PipetteSampleData.java deleted file mode 100644 index 3dad5ee..0000000 --- a/src/main/java/a8k/service/hardware/canbus/data/PipetteSampleData.java +++ /dev/null @@ -1,7 +0,0 @@ -package a8k.service.hardware.canbus.data; - -public class PipetteSampleData { - public Integer motorPos; - public Integer cval; - public Integer pval; -} diff --git a/src/main/java/a8k/service/hardware/canbus/protocol/A8kEcode.java b/src/main/java/a8k/service/hardware/canbus/protocol/A8kEcode.java deleted file mode 100644 index c9db525..0000000 --- a/src/main/java/a8k/service/hardware/canbus/protocol/A8kEcode.java +++ /dev/null @@ -1,167 +0,0 @@ -package a8k.service.hardware.canbus.protocol; - -public enum A8kEcode { - // - // FOR APP - // - Success(0, "成功"), // - TubeNotHasHat(1, "全血试管未盖帽"), // - SampleLiquidLevelWasNotDetected(2, "取样时未探测到液面"),// - LargeBufferNotEnough(3, "大瓶缓冲液不足"), // - UserDoesNotExist(5, "用户不存在"), // - GripperMPosError(6, "抓手舵机位置异常"), // - GripperZMPosError(8, "抓手升降电机位置异常"), // - GripperYMPosError(9, "抓手前后移动舵机位置异常"),// - TubesInShakeModule(10, "摇匀模组位置有试管"),// - PlateStuckDetectorSensorTrigger(11, "卡板检查光电触发"),// - PlateBoxNotCover(12, "板夹仓盖子未关闭"),// - PullerMInitPosError(13, "板夹钩爪电机没有处于转盘中央"),// - PusherMInitPosError(14, "板夹仓推杆电机没有处于零点位置"),// - RecycleBinOverflow(15, "回收仓满"),// - MotorLostStep(16, "电机丢步"),// - ActionOvertime(17, "动作执行超时"),// - CodeException(18, "代码异常"),// - ShakeModGripperZMNotInZeroPos(19, "抓手升降电机没有在零位"),// - MNotInZeroPos(20, "电机没有在零点"),// - TubeXChannelIsNotEmpty(21, "试管架平移通道有异物"),// - TubeTypeNotSupport(22, "试管类型不支持"),// - CmdIdNotSupport(23, "不支持指令"),// - PullPlateFail(24, "钩板卡板"),// - ShakeModGripperYSVInXYPublicArea(25, "摇匀模组抓手在XY公共区域"),// - ZMNotAtZPosWhenHbotTryMove(26, "HBOT启动时,Z轴电机没有在原点"),// - TakeTipFail(27, "取Tip失败"),// - PutTipFail(28, "放Tip失败"),// - StopByUser(29, "用户停止"),// - ScanTimeout(30, "扫码超时"),// - InfeedOvertimeFail(31, "入料超时"),// - OutfeedOvertimeFail(32, "出料超时"),// - TestScripIsRunning(33, "测试脚本正在运行"),// - - - PasswdError(100, "密码错误"), // - UsrNotExitError(101, "用户不存在"), // - UsrExistError(102, "用户已存在"), // - UsrNotAllowBeDeleted(103, "用户不允许被删除"), // - - TubeHolderCfgNotExist(200, "试管架配置不存在"), // - TubeCfgNotExist(201, "试管配置不存在"), // - - A8kIDCardOffline(300, "未检测到ID卡"), // - A8kIDCardContentError(301, "ID卡内容错误"), // - A8kIDCardVersionIsLow(302, "ID卡版本过低"), // - - AppOptionIsInvalid(400, "参数操作"), // - - // - // FOR HARDWARE - // - // kxymotor_not_move_to_zero = 1310, - // kstep_motor_not_move_to_zero = 1612, - - - HardwareError(1001, "硬件错误"),// - ParamOutOfRange(1102, "参数范围错误"),// - CmdNotSupport(1103, "指令不支持"),// - DeviceIsBusy(1104, "设备忙"),// - DeviceIsOffline(1105, "设备丢弃"),// - Overtime(1106, "超时"),// - Noack(1107, "没有回执"),// - Errorack(1108, "错误回执"),// - DeviceOffline(1109, "设备离线"),// - SubdeviceOvertime(1111, "子设备超时"),// - BufferNotEnough(1112, "缓存溢出"),// - CmdParamNumError(1114, "指令参数数量不对"),// - CheckcodeIsError(1115, "校验码错误"),// - IllegalOperation(1116, "非法操作"),// - ModuleOpeationBreakByUser(1202, "模块操作被用户中断"),// - ModuleNotFindReg(1207, "找不到对应的寄存器"),// - XYMotorXFindZeroEdgeFail(1306, "X轴找零失败"),// - XYMotorYFindZeroEdgeFail(1307, "Y轴找零失败"),// - XYMotorNotEnable(1308, "XY轴未使能"),// - XYMotorTargetPosOutofRange(1309, "XY轴目标位置超出范围"),// - XYmotorNotMoveToZero(1310, "XY轴未回零"),// - - PipetteErrorNoerror(1400, "PipetteErrorNoerror"),// - PipetteErrorInitfail(1401, "PipetteErrorInitfail"),// - PipetteErrorInvalidcmd(1402, "PipetteErrorInvalidcmd"),// - PipetteErrorInvalidarg(1403, "PipetteErrorInvalidarg"),// - PipetteErrorPressuresensorerror(1404, "PipetteErrorPressuresensorerror"),// - PipetteErrorOverpressure(1405, "PipetteErrorOverpressure"),// - PipetteErrorLlderror(1406, "PipetteErrorLlderror"),// - PipetteErrorDevicenotinit(1407, "PipetteErrorDevicenotinit"),// - PipetteErrorTippoperror(1408, "PipetteErrorTippoperror"),// - PipetteErrorPumpoverload(1409, "PipetteErrorPumpoverload"),// - PipetteErrorTipdrop(1410, "PipetteErrorTipdrop"),// - PipetteErrorCanbuserror(1411, "PipetteErrorCanbuserror"),// - PipetteErrorInvalidchecksum(1412, "PipetteErrorInvalidchecksum"),// - PipetteErrorEepromerror(1413, "PipetteErrorEepromerror"),// - PipetteErrorCmdbufferempty(1414, "PipetteErrorCmdbufferempty"),// - PipetteErrorCmdbufferoverflow(1415, "PipetteErrorCmdbufferoverflow"),// - PipetteErrorTipblock(1416, "PipetteErrorTipblock"),// - PipetteErrorAirsuction(1417, "PipetteErrorAirsuction"),// - PipetteErrorBubble(1418, "PipetteErrorBubble"),// - PipetteErrorVolumeerror(1419, "PipetteErrorVolumeerror"),// - PipetteErrorTipalreadyload(1420, "PipetteErrorTipalreadyload"),// - PipetteErrorTiploadfail(1421, "PipetteErrorTiploadfail"),// - PipetteErrorUninited(1501, "PipetteErrorUninited"),// - PipetteErrorNotLldPrepare(1502, "PipetteErrorNotLldPrepare"),// - PipetteErrorTipisloadWhenLldPrepare(1500, "PipetteErrorTipisloadWhenLldPrepare"),// - PipetteErrorPumpLoadValIsNotEmpty(1503, "PipetteErrorPumpLoadValIsNotEmpty"),// - StepMotorNotFoundZeroPoint(1600, "步进电机未找到零点"),// - StepMotorNotGoZero(1601, "步进电机未回零"),// - StepMotorOverTemperature(1602, "步进电机过温"),// - StepMotorOverVoltage(1603, "步进电机过压"),// - StepMotorRunOvertime(1604, "步进电机运行超时"),// - StepMotorNotEnable(1605, "步进电机未使能"),// - StepMotorIoindexOutOfRange(1606, "步进电机IO索引超出范围"),// - StepMotorSubicReset(1607, "步进电机子设备复位"),// - StepMotorDrvErr(1608, "步进电机驱动错误"),// - StepMotorUvCp(1609, "步进电机UV CP"),// - StepMotorNotFoundPointEdge(1610, "步进电机未找到零点边沿"),// - StepMotorLostStep(1611, "步进电机丢步"),// - StepMotorNotMoveToZero(1612, "步进电机未回零"),// - - MiniServoNotEnable(1700, "舵机未使能"),// - MiniServoModeNotSupport(1701, "舵机模式不支持"),// - FanHardwareFault(1800, "风扇硬件故障"),// - WaterCoolingFanError(1900, "水冷风扇故障"),// - WaterCoolingTemperatureSensorError(1902, "水冷温度传感器故障"),// - WaterCoolingPumpIsError(1903, "水冷水泵故障"),// - WaterCoolingPelterIsError(1904, "水冷电热片故障"),// - ; - - public int index; - public String chname; - - A8kEcode(int index, String chname) { - this.index = index; - this.chname = chname; - } - - public int toInt() { - return index; - } - - public static A8kEcode valueOf(int val) { - A8kEcode[] values = A8kEcode.values(); - for (A8kEcode e : values) { - if (e.toInt() == val) - return e; - } - return null; - } - - public static String toString(int val) { - A8kEcode[] values = A8kEcode.values(); - for (A8kEcode e : values) { - if (e.toInt() == val) { - return e.toString(); - } - } - return "unkown(" + val + ")"; - } - - public String getChname() { - return chname; - } -} diff --git a/src/main/java/a8k/service/hardware/canbus/protocol/A8kPacket.java b/src/main/java/a8k/service/hardware/canbus/protocol/A8kPacket.java deleted file mode 100644 index bc6e445..0000000 --- a/src/main/java/a8k/service/hardware/canbus/protocol/A8kPacket.java +++ /dev/null @@ -1,161 +0,0 @@ -package a8k.service.hardware.canbus.protocol; - -import a8k.utils.ByteArray; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class A8kPacket { - /** - * typedef struct { - * uint16_t packetindex; // 0: - * uint16_t cmdMainId; // 2: - * uint8_t cmdSubId; // 4: - * uint8_t packetType; // 5: - * uint16_t moduleid; // 6: - * uint8_t data[]; // 8: - * } zcr_cmd_header_t; - *

- * kptv2_cmd = 0, - * kptv2_ack = 1, - * kptv2_error_ack = 2, - * kptv2_event = 3, - */ - public static final Logger logger = LoggerFactory.getLogger(A8kPacket.class); - - byte[] raw; - - public static final int PACKET_MIN_LEN = 8; - - public static final int PACKET_INDEX_OFF = 0; - public static final int CMD_ID_OFF = 2; - public static final int PACKET_TYPE_OFF = 5; - public static final int MODULE_ID_OFF = 6; - public static final int DATA_BEGIN_OFF = 8; - - - public static final int PACKET_TYPE_CMD = 0; - public static final int PACKET_TYPE_ACK = 1; - public static final int PACKET_TYPE_ERROR_ACK = 2; - public static final int PACKET_TYPE_EVENT = 3; - - public static final int CMD_OVERTIME = 2000; - - public A8kPacket(byte[] cmd) { - raw = new byte[cmd.length]; System.arraycopy(cmd, 0, raw, 0, cmd.length); - } - - public void setPacketIndex(int packetIndex) { - ByteArray.setU16bit(raw, 0, packetIndex); - } - - public int getPacketIndex() { - return ByteArray.readU16bit(raw, 0); - } - - public int getCmdId() { - return ByteArray.readU16bit((raw), 2) * 256 + ByteArray.readU8bit(raw, 4); - } - - public int getPacketType() { - return ByteArray.readU8bit(raw, 5); - } - - public int getModuleId() { - return ByteArray.readU16bit(raw, 6); - } - - public byte[] getCmdContent() { - if (raw.length < 8) { - return new byte[0]; - } byte[] cmdcontent = new byte[raw.length - 8]; System.arraycopy(raw, 8, cmdcontent, 0, raw.length - 8); return cmdcontent; - } - - public int getContentI32(int index) { - return ByteArray.read32bit(raw, 8 + index * 4); - } - - public String toByteString() { - return ByteArray.toByteString(raw); - } - - public String toString() { - int packetType = getPacketType(); String ret = ""; - - CmdId cmdId = CmdId.valueOf(getCmdId()); - assert cmdId != null; - if (packetType == PACKET_TYPE_CMD) { - - if (cmdId.equals(CmdId.module_get_reg) || cmdId.equals(CmdId.module_set_reg)) { - RegIndex regIndex = RegIndex.valueOf(getContentI32(0)); - if (regIndex != null) { - ret = String.format("[CMD ] index:[%d] %s %s %s(%d) %d", getPacketIndex(), cmdId, MId.valueOf(getModuleId()),regIndex, regIndex.index, getContentI32(1)); - } else { - ret = String.format("[CMD ] index:[%d] %s unkown_index(%d) %d", getPacketIndex(), cmdId, getContentI32(0), getContentI32(1)); - } - } else { - if (cmdId.cmdAttachType == CmdId.ATTACH_IS_INT32) { - ret = String.format("[CMD ] index:[%d] (%s %s(%d) :param:[%s])", getPacketIndex(), cmdId, MId.valueOf(getModuleId()), getModuleId(), formatInt32ATTACH(getCmdContent())); - } else { - ret = String.format("[CMD ] index:[%d] (%s %s(%d) :param:[%s])", getPacketIndex(), cmdId, MId.valueOf(getModuleId()), getModuleId(), ByteArray.toByteString(getCmdContent())); - } - } - - } else if (packetType == PACKET_TYPE_ACK) { - if (cmdId.receiptAttachType == CmdId.ATTACH_IS_INT32) { - ret = String.format("[ACK ] index:[%d] (%s :[%s])", getPacketIndex(), cmdId, formatInt32ATTACH(getCmdContent())); - } else { - ret = String.format("[ACK ] index:[%d] (%s :[%s])", getPacketIndex(), cmdId, ByteArray.toByteString(getCmdContent())); - } - } else if (packetType == PACKET_TYPE_ERROR_ACK) { - ret = String.format("[EACK ] index:[%d] (%s :[%s])", getPacketIndex(), cmdId, A8kEcode.toString(getContentI32(0))); - } else if (packetType == PACKET_TYPE_EVENT) { - if (cmdId.cmdAttachType == CmdId.ATTACH_IS_INT32) { - ret = String.format("[EVENT] index:[%d] (%s %s(%d) :[%s])", getPacketIndex(), cmdId, MId.valueOf(getModuleId()), getModuleId(), formatInt32ATTACH(getCmdContent())); - } else { - ret = String.format("[EVENT] index:[%d] (%s %s(%d) :[%s])", getPacketIndex(), cmdId, MId.valueOf(getModuleId()), getModuleId(), ByteArray.toByteString(getCmdContent())); - } - } else { - ret = String.format("Unknown packet type: %d", packetType); - } return ret; - } - - private String formatInt32ATTACH(byte[] attach) { - StringBuilder ret = new StringBuilder(); for (int i = 0; i < attach.length; i += 4) { - if (i + 3 >= attach.length) - break; if (i != 0) - ret.append(","); ret.append(String.format("%d", ByteArray.read32bit(attach, i))); - } return ret.toString(); - } - - public Boolean isSupportPacket() { - CmdId cmdid = CmdId.valueOf(getCmdId()); - if (cmdid == null) { - return false; - } - if (CmdId.module_get_reg.equals(cmdid) || CmdId.module_set_reg.equals(cmdid)) { - if (getPacketType() == PACKET_TYPE_CMD) { - RegIndex regIndex = RegIndex.valueOf(getContentI32(0)); - return regIndex != null; - } - } - return true; - } - - - public Boolean isTrace() { - if (!isSupportPacket()) { - return false; - } - CmdId cmdid = CmdId.valueOf(getCmdId()); - assert cmdid != null; - - if (CmdId.module_get_reg.equals(cmdid) || CmdId.module_set_reg.equals(cmdid)) { - RegIndex regIndex = RegIndex.valueOf(getContentI32(0)); - assert regIndex != null; - return regIndex.trace; - } else { - return cmdid.trace; - } - } - -} diff --git a/src/main/java/a8k/service/hardware/canbus/protocol/CmdId.java b/src/main/java/a8k/service/hardware/canbus/protocol/CmdId.java deleted file mode 100644 index f712e4a..0000000 --- a/src/main/java/a8k/service/hardware/canbus/protocol/CmdId.java +++ /dev/null @@ -1,202 +0,0 @@ -package a8k.service.hardware.canbus.protocol; - -public enum CmdId { - - - NotSet(0xFFFF, "NOACTION"),// - - board_reset(0x0000, "复位板子"),// - event_bus_reg_change_report(0x0064, "寄存器修改事件"),// - // - module_ping(0x0100, "MODULE_PING"),// - module_get_status(0x0104, "读取模块状态", false),// - module_stop(0x0101, "模块停止"),// - module_set_reg(0x0105, "写入寄存器"),// - module_get_reg(0x0106, "获取寄存器"),// - module_get_error(0x010a, "读取模块错误", false),// - module_clear_error(0x010b, "清除模块错误"),// - module_active_cfg(0x0110, "激活配置"),// - // - xymotor_enable(0x0301, "XYMOTOR_ENABLE"),// - xymotor_move_by(0x0302, "XYMOTOR_MOVE_BY"),// - xymotor_move_to(0x0303, "XYMOTOR_MOVE_TO"),// - xymotor_move_to_zero(0x0304, "XYMOTOR_MOVE_TO_ZERO"),// - xymotor_read_pos(0x0306, "XYMOTOR_READ_POS",false),// - xymotor_read_inio_index_in_stm32(0x0307, "XYMOTOR_READ_INIO_INDEX_IN_STM32"),// - xymotor_read_inio(0x0308, "XYMOTOR_READ_INIO", false),// - xymotor_set_pos(0x0309, "XYMOTOR_SET_POS"),// - xymotor_motor_move_by_direct(0x030a, "XYMOTOR_MOTOR_MOVE_BY_DIRECT"),// - xymotor_read_enc_direct(0x030b, "XYMOTOR_READ_ENC_DIRECT"),// - // - pipette_ctrl_init_device(0x7201, "PIPETTE_CTRL_INIT_DEVICE"),// - pipette_ctrl_put_tip(0x7202, "PIPETTE_CTRL_PUT_TIP"),// - pipette_ctrl_move_to_ul(0x7203, "PIPETTE_CTRL_MOVE_TO_UL"),// - pipette_lld_prepare(0x7204, "PIPETTE_LLD_PREPARE"),// - pipette_plld(0x7205, "PIPETTE_PLLD"),// - pipette_clld(0x7206, "PIPETTE_CLLD"),// - pipette_mlld(0x7207, "PIPETTE_MLLD"),// - pipette_lld_is_detect_liquid(0x7208, "PIPETTE_LLD_IS_DETECT_LIQUID"),// - pipette_aspirate(0x7209, "PIPETTE_ASPIRATE"),// - pipette_distribut(0x720a, "PIPETTE_DISTRIBUT"),// - pipette_shake_up(0x720b, "PIPETTE_SHAKE_UP"),// - pipette_enable_zmotor(0x7214, "PIPETTE_ENABLE_ZMOTOR"),// - pipette_write_cmd_direct(0x7215, "PIPETTE_WRITE_CMD_DIRECT"),// - pipette_get_sensor_sample_data(0x7216, "PIPETTE_GET_SENSOR_SAMPLE_DATA"),// - pipette_get_sensor_sample_data_num(0x7217, "PIPETTE_GET_SENSOR_SAMPLE_DATA_NUM"),// - pipette_sensor_sample_data_report(0x7232, "PIPETTE_SENSOR_SAMPLE_DATA_REPORT"),// - pipette_aspirate_llf(0x720c, "PIPETTE_ASPIRATE_LLF"),// - pipette_distribut_llf(0x720d, "PIPETTE_DISTRIBUT_LLF"),// - pipette_shake_up_llf(0x720e, "PIPETTE_SHAKE_UP_LLF"),// - - a8k_opt_v2_read_raw(0x0609, "A8K_OPT_V2_READ_RAW", CmdId.ATTACH_IS_INT32, CmdId.ATTACH_IS_BYTES),// - // - a8k_opt_v2_t_start_scan(0x0700, "A8K_OPT_V2_T_START_SCAN"),// - a8k_opt_v2_f_start_scan(0x0701, "A8K_OPT_V2_F_START_SCAN"),// - a8k_opt_v2_t_open_laster(0x070a, "A8K_OPT_V2_T_OPEN_LASTER"),// - a8k_opt_v2_t_close_laster(0x070b, "A8K_OPT_V2_T_CLOSE_LASTER"),// - a8k_opt_v2_t_readVal(0x070c, "A8K_OPT_V2_T_READVAL"),// - a8k_opt_v2_f_open_laster(0x070d, "A8K_OPT_V2_F_OPEN_LASTER"),// - a8k_opt_v2_f_close_laster(0x070e, "A8K_OPT_V2_F_CLOSE_LASTER"),// - a8k_opt_v2_f_readVal(0x070f, "A8K_OPT_V2_F_READVAL"),// - // - step_motor_enable(0x0201, "STEP_MOTOR_ENABLE"),// - step_motor_read_pos(0x020b, "STEP_MOTOR_READ_POS"),// - step_motor_easy_rotate(0x0211, "STEP_MOTOR_EASY_ROTATE"),// - step_motor_easy_move_by(0x0212, "STEP_MOTOR_EASY_MOVE_BY"),// - step_motor_easy_move_to(0x0213, "STEP_MOTOR_EASY_MOVE_TO"),// - step_motor_easy_move_to_zero(0x0214, "STEP_MOTOR_EASY_MOVE_TO_ZERO"),// - step_motor_easy_set_current_pos(0x0215, "STEP_MOTOR_EASY_SET_CURRENT_POS"),// - step_motor_easy_move_to_io(0x0216, "STEP_MOTOR_EASY_MOVE_TO_IO"),// - step_motor_stop(0x0228, "STEP_MOTOR_STOP"),// - step_motor_active_cfg(0x0229, "STEP_MOTOR_ACTIVE_CFG"),// - step_motor_read_io_state(0x022a, "STEP_MOTOR_READ_IO_STATE", false),// - step_motor_easy_move_to_end_point(0x022c, "STEP_MOTOR_EASY_MOVE_TO_END_POINT"),// - step_motor_read_tmc5130_status(0x0232, "STEP_MOTOR_READ_TMC5130_STATUS"),// - step_motor_read_tmc5130_state(0x0233, "STEP_MOTOR_READ_TMC5130_STATE"),// - step_motor_read_io_index_in_stm32(0x0238, "STEP_MOTOR_READ_IO_INDEX_IN_STM32"),// - step_motor_set_subdevice_reg(0x0239, "STEP_MOTOR_SET_SUBDEVICE_REG"),// - step_motor_get_subdevice_reg(0x023a, "STEP_MOTOR_GET_SUBDEVICE_REG"),// - step_motor_easy_reciprocating_motion(0x022d, "STEP_MOTOR_EASY_RECIPROCATING_MOTION"),// - step_motor_easy_move_to_zero_point_quick(0x022e, "STEP_MOTOR_EASY_MOVE_TO_ZERO_POINT_QUICK"),// - // - mini_servo_enable(0x6601, "MINI_SERVO_ENABLE"),// - mini_servo_read_pos(0x6602, "MINI_SERVO_READ_POS"),// - mini_servo_active_cfg(0x6603, "MINI_SERVO_ACTIVE_CFG"),// - mini_servo_stop(0x6604, "MINI_SERVO_STOP"),// - mini_servo_set_mid_point(0x6607, "MINI_SERVO_SET_MID_POINT"),// - mini_servo_read_io_state(0x6608, "MINI_SERVO_READ_IO_STATE"),// - mini_servo_move_to(0x6609, "MINI_SERVO_MOVE_TO"),// - mini_servo_rotate(0x660a, "MINI_SERVO_ROTATE"),// - mini_servo_rotate_with_torque(0x660b, "MINI_SERVO_ROTATE_WITH_TORQUE"),// - mini_servo_set_cur_pos(0x660c, "MINI_SERVO_SET_CUR_POS"),// - // - extboard_read_inio(0x6701, "EXTBOARD_READ_INIO", false),// - extboard_write_outio(0x6702, "EXTBOARD_WRITE_OUTIO"),// - extboard_read_muti_inio(0x6703, "EXTBOARD_READ_MUTI_INIO", false),// - extboard_read_inio_index_in_stm32(0x6704, "EXTBOARD_READ_INIO_INDEX_IN_STM32"),// - extboard_read_outio_index_in_stm32(0x6705, "EXTBOARD_READ_OUTIO_INDEX_IN_STM32"),// - extboard_read_outio(0x6706, "EXTBOARD_READ_OUTIO"),// - code_scaner_start_scan(0x6801, "CODE_SCANER_START_SCAN"),// - code_scaner_stop_scan(0x6802, "CODE_SCANER_STOP_SCAN"),// - code_scaner_result_is_ready(0x6803, "CODE_SCANER_RESULT_IS_READY",false),// - code_scaner_read_scaner_result(0x6804, "CODE_SCANER_READ_SCANER_RESULT"),// - code_scaner_get_result_length(0x6805, "CODE_SCANER_GET_RESULT_LENGTH"),// - // - fan_controler_set_speed(0x6900, "FAN_CONTROLER_SET_SPEED"),// - // - temp_controler_start_hearting(0x7000, "TEMP_CONTROLER_START_HEARTING"),// - temp_controler_stop_hearting(0x7001, "TEMP_CONTROLER_STOP_HEARTING"),// - temp_controler_set_peltier_power_level(0x7002, "TEMP_CONTROLER_SET_PELTIER_POWER_LEVEL"),// - temp_controler_set_pump_level(0x7003, "TEMP_CONTROLER_SET_PUMP_LEVEL"),// - temp_controler_set_fan_level(0x7004, "TEMP_CONTROLER_SET_FAN_LEVEL"),// - temp_controler_enable_log(0x7005, "TEMP_CONTROLER_ENABLE_LOG"),// - // - a8000_idcard_reader_read_raw(0x7100, "A8000_IDCARD_READER_READ_RAW", CmdId.ATTACH_IS_INT32, CmdId.ATTACH_IS_BYTES,false),// - a8000_idcard_write_raw(0x7101, "A8000_IDCARD_WRITE_RAW", CmdId.ATTACH_IS_BYTES, CmdId.ATTACH_IS_INT32,false),// - a8000_idcard_erase(0x7102, "A8000_IDCARD_ERASE"),// - a8000_idcard_earse_unlock(0x7103, "A8000_IDCARD_EARSE_UNLOCK"),// - // - event_a8000_idcard_online(0x71c8, "EVENT_A8000_IDCARD_ONLINE"),// - event_a8000_idcard_offline(0x71c9, "EVENT_A8000_IDCARD_OFFLINE"),// - // - plate_code_scaner_push_card_and_scan(0x7301, "PLATE_CODE_SCANER_PUSH_CARD_AND_SCAN"),// - plate_code_scaner_stop_scan(0x7302, "PLATE_CODE_SCANER_STOP_SCAN"),// - plate_code_scaner_read_result(0x7303, "PLATE_CODE_SCANER_READ_RESULT"),// - plate_code_scaner_read_result_point_num(0x7304, "PLATE_CODE_SCANER_READ_RESULT_POINT_NUM"),// - plate_code_scaner_read_code(0x7305, "PLATE_CODE_SCANER_READ_CODE"),// - plate_code_scaner_adc_readraw(0x7306, "PLATE_CODE_SCANER_ADC_READRAW"),// - plate_code_scaner_open_laser(0x7307, "PLATE_CODE_SCANER_OPEN_LASER"),// - plate_code_scaner_close_laser(0x7308, "PLATE_CODE_SCANER_CLOSE_LASER"),// - ; - - public final static int ATTACH_IS_BYTES = 1; - public final static int ATTACH_IS_INT32 = 2; - - public int index; - public String chName; - public int cmdAttachType = ATTACH_IS_INT32; - public int receiptAttachType = ATTACH_IS_INT32; - public boolean trace = true; - public boolean actionCmd = true; - - CmdId(int index, String chname) { - this.index = index; - this.chName = chname; - } - - CmdId(int index, String chname, boolean trace) { - this.index = index; - this.chName = chname; - this.trace = trace; - this.actionCmd = trace; - } - - CmdId(int index, String chname, int cmdAttachType, int receiptAttachType) { - this.index = index; - this.chName = chname; - this.cmdAttachType = cmdAttachType; - this.receiptAttachType = receiptAttachType; - } - - CmdId(int index, String chname, int cmdAttachType, int receiptAttachType, boolean trace) { - this.index = index; - this.chName = chname; - this.cmdAttachType = cmdAttachType; - this.receiptAttachType = receiptAttachType; - this.trace = trace; - } - - - public int toInt() { - return index; - } - - public static CmdId valueOf(int val) { - CmdId[] values = CmdId.values(); - for (CmdId e : values) { - if (e.toInt() == val) - return e; - } - return null; - } - - public static String toString(int val) { - CmdId[] values = CmdId.values(); - for (CmdId e : values) { - if (e.toInt() == val) { - return e.toString(); - } - } - return "unkown(" + val + ")"; - } - - public String getChname() { - return chName; - } - - public Boolean eq(Integer index) { - return this.index == index; - } - - -} diff --git a/src/main/java/a8k/service/hardware/canbus/protocol/IOId.java b/src/main/java/a8k/service/hardware/canbus/protocol/IOId.java deleted file mode 100644 index cee92af..0000000 --- a/src/main/java/a8k/service/hardware/canbus/protocol/IOId.java +++ /dev/null @@ -1,38 +0,0 @@ -package a8k.service.hardware.canbus.protocol; - -public enum IOId { - TubeHeightPPS(ModuleType.kboard, MId.FeedingModBoard, 0), //高低试管检测IO - THChOuterPPS(ModuleType.kboard, MId.FeedingModBoard, 1),//试管架转移通道有无检测 外 - THChInterPPS(ModuleType.kboard, MId.FeedingModBoard, 2),//试管架转移通道有无检测 内 - OutfeedPPS(ModuleType.kboard, MId.FeedingModBoard, 3),//试管出料位置 试管架有无检测 - TubeExistPPS(ModuleType.kboard, MId.FeedingModBoard, 4),//试管有无光电 - InfeedPPS(ModuleType.kboard, MId.FeedingModBoard, 5),//试管架入料位置 试管架有无检测 - - RecycleBinOverflowPPS(ModuleType.kboard, MId.PlatesBoxTCMBoard, 2),//废料桶满溢检测 - RecycleBinOverflowPPSPowerCtrl(ModuleType.kboard, MId.PlatesBoxTCMBoard, 0),//废料桶光栅电源 - - PlateBoxCoverClosurePPS(ModuleType.kboard, MId.PlatesBoxBoard, 0),//板夹仓舱盖闭合检测 - PlateBoxPlateStuckPPS(ModuleType.kboard, MId.PlatesBoxBoard, 1),//板夹仓卡板检测 - - //转盘逻辑相关光电 - //钩板电机,零点光电,终点光电 - PullerMZeroPPS(ModuleType.ktmc_step_motor, MId.OptModPullM, 0),// - PullerMEndPPS(ModuleType.ktmc_step_motor, MId.OptModPullM, 1),// - //推板电机,零点光电,终点光电 - PusherMZeroPPS(ModuleType.ktmc_step_motor, MId.PlatesBoxPusherM, 0),// - PusherMEndPPS(ModuleType.ktmc_step_motor, MId.PlatesBoxPusherM, 1),// - - ; - - - final public ModuleType mtype; - final public MId mid; - final public int ioIndex; - - IOId(ModuleType mtype, MId mid, int ioIndex) { - this.mtype = mtype; - this.mid = mid; - this.ioIndex = ioIndex; - } - -} diff --git a/src/main/java/a8k/service/hardware/canbus/protocol/MId.java b/src/main/java/a8k/service/hardware/canbus/protocol/MId.java deleted file mode 100644 index fb42e8d..0000000 --- a/src/main/java/a8k/service/hardware/canbus/protocol/MId.java +++ /dev/null @@ -1,89 +0,0 @@ -package a8k.service.hardware.canbus.protocol; - -public enum MId { - NotSet(0, "未设置"),// - HbotBoard(10, "机械臂板模块"),// - HbotM(11, "机械臂XY"),// - // - PlatesBoxBoard(20, "板夹仓模块"),// - PlatesBoxYM(21, "板夹仓移动电机"),// - PlatesBoxPusherM(22, "板夹仓推杆电机"),// - PlatesBoxScanner(23, "板夹仓扫码模组"),// - // - ShakeModBoard(30, "摇匀模组板"),// - ShakeModClampingM(31, "试管固定夹爪电机"),// - ShakeModGripperZM(32, "摇匀升降电机"),// - ShakeModShakeM(33, "试管摇匀电机"),// - ShakeModGripperYSV(34, "摇匀前后移动舵机"),// - ShakeModGripperSV(35, "摇匀试管帽夹爪舵机"),// - ShakeModTubeScanerClampingSV(36, "试管架扫码夹紧舵机"),// - ShakeModTubeScanerRotateSV(37, "试管架旋转舵机"),// - // - PlatesBoxTCMBoard(40, "反应板夹温度控制板"),// - PlatesBoxTCM(41, "反应板夹温度控制模块"),// - WbTubeFanMod(42, "气溶胶风扇"),// - // - IncubatorTCMBoard(50, "温度控制"),// - IncubatorTCM(51, "温度控制"),// - // - FeedingModBoard(60, "出入料模块"),// - FeedingModInfeedM(61, "入料电机"),// - FeedingModXM(62, "试管架平移电机"),// - FeedingModOutfeedM(63, "出料电机"),// - FeedingModScannerMod(64, "试管架扫码器"),// - // - IncubatorRotateBoard(70, "孵育盘旋转板"),// - IncubatorRotateCtrlM(71, "孵育盘旋转"),// - // - PipetteModBoard(80, "机械臂Z轴板"),// - PipetteModZM(81, "机械臂Z"),// - PipetteMod(82, "移液枪"),// - PipetteModCodeScanner(83, "物料扫码器"),// - // - OptModBoard(90, "光学模组板"),// - OptModScannerM(91, "板卡扫描电机"),// - OptModPullM(92, "板卡推杆电机"),// - OptMod(93, "扫描仪"),// - // - A8kIdCardReaderBoard(100, "A8K读卡器板"),// - A8kIdCardReader(101, "A8K读卡器"),// - ; - - - final public String chname; - final public int index; - - MId(int index, String chname) { - this.chname = chname; - this.index = index; - } - - public int toInt() { - return index; - } - - - public static MId valueOf(Integer val) { - return valueOf(val.intValue()); - } - - public static MId valueOf(int val) { - MId[] values = MId.values(); - for (MId e : values) { - if (e.toInt() == val) - return e; - } - return null; - } - - public static String toString(int val) { - MId[] values = MId.values(); - for (MId e : values) { - if (e.toInt() == val) { - return e.toString(); - } - } - return "unkown(" + val + ")"; - } - -} diff --git a/src/main/java/a8k/service/hardware/canbus/protocol/ModuleStatus.java b/src/main/java/a8k/service/hardware/canbus/protocol/ModuleStatus.java deleted file mode 100644 index 2381573..0000000 --- a/src/main/java/a8k/service/hardware/canbus/protocol/ModuleStatus.java +++ /dev/null @@ -1,24 +0,0 @@ -package a8k.service.hardware.canbus.protocol; - -public enum ModuleStatus { - IDLE(0), // - BUSY(1), // - ERROR(2),// - ; - - final public int index; - - ModuleStatus(int index) { - this.index = index; - } - - public int getIndex() { - return index; - } - - public static ModuleStatus valueOf(int value) { // 手写的从int到enum的转换函数 - assert (value >= 0 && value < 2); - return values()[value]; - } - -} diff --git a/src/main/java/a8k/service/hardware/canbus/protocol/ModuleType.java b/src/main/java/a8k/service/hardware/canbus/protocol/ModuleType.java deleted file mode 100644 index 8ade0ce..0000000 --- a/src/main/java/a8k/service/hardware/canbus/protocol/ModuleType.java +++ /dev/null @@ -1,27 +0,0 @@ -package a8k.service.hardware.canbus.protocol; - -public enum ModuleType { - khbot_module(1), // hbot模块 - ktemperature_ctrl_module(3), // 温度控制 - kfan_ctrl_module(5), // 风扇控制 - kcode_scaner(6), // 扫码器 - kpipette_ctrl_module(7), // 移液体枪控制 - ka8000_optical_module(8), // a8000光学模组 - ktmc_step_motor(10), // 步进电机 - kmini_servo_motor_module(11), // 舵机 - kboard(12), // 板子 - ka8000_idcard_reader(13), // id卡读卡器 - ka8000_plate_code_scaner(14); // 反应板条扫码器 - - final private int val; - - ModuleType(int val) { - this.val = val; - } - - public int getVal() { - return val; - } - - -} diff --git a/src/main/java/a8k/service/hardware/canbus/protocol/RegIndex.java b/src/main/java/a8k/service/hardware/canbus/protocol/RegIndex.java deleted file mode 100644 index 6c5de69..0000000 --- a/src/main/java/a8k/service/hardware/canbus/protocol/RegIndex.java +++ /dev/null @@ -1,208 +0,0 @@ -package a8k.service.hardware.canbus.protocol; - -public enum RegIndex { - - /******************************************************************************* - * 模块通用配置和状态 * - *******************************************************************************/ - kreg_module_version(0), // 模块版本 - kreg_module_type(1), // 模块类型 - kreg_module_status(2), // 0idle,1busy,2error - kreg_module_errorcode(3), // inited_flag - - kreg_extboard_resetflag(100), - - /*********************************************************************************************************************** - * 水冷温度控制器 * - ***********************************************************************************************************************/ - kreg_water_cooling_tmp_controler_pid_target(3000), // 目标数值 - kreg_water_cooling_tmp_controler_pid_nowoutput(3001), // 当前输出 - kreg_water_cooling_tmp_controler_pid_feedbackval(3002), // 当前输出 - kreg_water_cooling_tmp_controler_temp0(3003), // 温度1 - kreg_water_cooling_tmp_controler_temp1(3004), // 温度2 - kreg_water_cooling_tmp_controler_temp2(3005), // 温度3 - kreg_water_cooling_tmp_controler_temp3(3006), // 温度4 - - kreg_water_cooling_tmp_controler_pid_kp(3050), // kp - kreg_water_cooling_tmp_controler_pid_ki(3051), // ki - kreg_water_cooling_tmp_controler_pid_kd(3052), // kd - kreg_water_cooling_tmp_controler_pid_max_output(3053), // 最大输出 - kreg_water_cooling_tmp_controler_pid_min_output(3054), // 最小输出 - kreg_water_cooling_tmp_controler_pid_max_integral(3055), // 最大积分 - kreg_water_cooling_tmp_controler_pid_min_integral(3056), // 最小积分 - kreg_water_cooling_tmp_controler_pid_error_limit(3057), // 误差限制 - kreg_water_cooling_tmp_controler_pid_compute_interval(3058), // 计算间隔 - - /******************************************************************************* - * 移液枪状态 * - *******************************************************************************/ - kreg_pipette_pos_ul(4000), // 移液枪位置 - kreg_pipette_capactitance_val(4001), // 移液枪电容值 - kreg_pipette_tip_state(4002, false), // 移动液枪tip状态 - - kreg_pipette_limit_ul(4051), // - kreg_pipette_pump_acc(4052), // - kreg_pipette_pump_dec(4053), // - kreg_pipette_pump_vstart(4054), // - kreg_pipette_pump_vstop(4055), // - kreg_pipette_pump_vmax(4056), // - kreg_pipette_aspirate_distribut_pump_vel(4057), // - kreg_pipette_lld_pump_vel(4058), // - kreg_pipette_lld_motor_vel_rpm(4059), // - kreg_pipette_lld_detect_period_ms(4060), // - kreg_pipette_lld_prepare_pos(4061), // - kreg_pipette_lld_prepare_distribut_pos(4062), // - - /** - * @brief - * - * ------------------------------------------------------ - * - * - * 扫描零点偏移:(F光学向左扫描的起始位置) - * 扫描方向:1:板卡箭头方向,-1板卡箭头反方向 - * 扫描点数:固定为1200 - * 扫描步距:固定为1 - * - * 返回点数:(1200) - * - * - */ - // 坐标参数 - - kreg_a8k_opt_t_pos_offset(4501), // T光学正向扫描,扫描起始位距离零点的偏移 - kreg_a8k_opt_f_pos_offset(4502), // F光学正向扫描,扫描起始位距离零点的偏移 - kreg_a8k_opt_t_reverse_scan_pos_offset(4503), // T光学逆向扫描,扫描起始位距离零点的偏移 - kreg_a8k_opt_f_reverse_scan_pos_offset(4504), // F光学逆向扫描,扫描起始位距离零点的偏移 - kreg_a8k_opt_scan_step_interval(4505), // 参数固定:为1 - kreg_a8k_opt_scan_pointnum(4506), // 参数固定:为1200个点 - - /*********************************************************************************************************************** - * XYROBOT * - ***********************************************************************************************************************/ - - kreg_xyrobot_io_state(9900, false), // - kreg_xyrobot_is_enable(9901), // - kreg_xyrobot_robot_type(9950), // - kreg_xyrobot_one_circle_pulse(9951), // - kreg_xyrobot_one_circle_pulse_denominator(9952), // - kreg_xyrobot_ihold(9954), // - kreg_xyrobot_irun(9955), // - kreg_xyrobot_iholddelay(9956), // - kreg_xyrobot_iglobalscaler(9957), // - kreg_xyrobot_vstart(9958), // - kreg_xyrobot_a1(9959), // - kreg_xyrobot_amax(9960), // - kreg_xyrobot_v1(9961), // - kreg_xyrobot_dmax(9962), // - kreg_xyrobot_d1(9963), // - kreg_xyrobot_vstop(9964), // - kreg_xyrobot_tzerowait(9965), // - kreg_xyrobot_enc_resolution(9966), // - kreg_xyrobot_enable_enc(9967), // - kreg_xyrobot_x_shaft(9968), // - kreg_xyrobot_y_shaft(9969), // - kreg_xyrobot_min_x(9972), // - kreg_xyrobot_min_y(9973), // - kreg_xyrobot_max_x(9974), // - kreg_xyrobot_max_y(9975), // - kreg_xyrobot_run_to_zero_speed(9976), // - kreg_xyrobot_look_zero_edge_speed(9977), // - kreg_xyrobot_shift_x(9978), // - kreg_xyrobot_shift_y(9979), // - kreg_xyrobot_pos_devi_tolerance(9980), // - kreg_xyrobot_io_trigger_append_distance(9981), // - kreg_xyrobot_default_velocity(10000), // - - /*********************************************************************************************************************** - * step_motor * - ***********************************************************************************************************************/ - - kreg_step_motor_pos(10101), // 机器人x坐标 - kreg_step_motor_is_enable(10102), // 是否使能 - kreg_step_motor_dpos(10103), // 执行完上一条指令后的相对位移 - kreg_step_motor_shift(10150), // x偏移 - kreg_step_motor_shaft(10151), // x轴是否反转 - kreg_step_motor_one_circle_pulse(10152), // x轴一圈脉冲数 - kreg_step_motor_one_circle_pulse_denominator(10153), // 设置一圈脉冲数的分母 - kreg_step_motor_default_velocity(10154), // 默认速度 - kreg_step_motor_ihold(10158), // 步进电机电流配置 - kreg_step_motor_irun(10159), // 步进电机电流配置 - kreg_step_motor_iholddelay(10160), // 步进电机电流配置 - kreg_step_motor_iglobalscaler(10161), // 步进电机电流配置 - kreg_step_motor_run_to_zero_speed(10173), // 回零速度 - kreg_step_motor_look_zero_edge_speed(10175), // 找零边缘速度 - kreg_step_motor_max_d(10178), // 最大限制距离 - kreg_step_motor_min_d(10179), // 最小限制距离 - kreg_step_motor_in_debug_mode(10180), // 驱动器处于调试模式 - kreg_step_motor_vstart(10181), // a1起作用的速度 - kreg_step_motor_a1(10182), // - kreg_step_motor_amax(10183), // - kreg_step_motor_v1(10184), // - kreg_step_motor_dmax(10185), // - kreg_step_motor_d1(10186), // - kreg_step_motor_vstop(10187), // - kreg_step_motor_tzerowait(10188), // - kreg_step_motor_enc_resolution(10189), // 编码器分辨率 1000,1024,4000,4096,16384 - kreg_step_motor_enable_enc(10190), // - kreg_step_motor_dzero_pos(10191), // 驱动器处于调试模式 - kret_step_motor_pos_devi_tolerance(10192), // 位置偏差容忍度 - kret_step_motor_io_trigger_append_distance(10193), // 移动到io时,附加的距离 - - - /*********************************************************************************************************************** - * step_motor * - ***********************************************************************************************************************/ - - kreg_mini_servo_pos(10201), // 位置 - kreg_mini_servo_limit_velocity(10251), // 限制速度 - kreg_mini_servo_limit_torque(10252), // 限制扭矩 - kreg_mini_servo_protective_torque(10253), // 保护扭矩 - kreg_mini_servo_is_move(10254), // 是否在运动 - /*********************************************************************************************************************** - * ID_CARD_READER * - ***********************************************************************************************************************/ - - kreg_id_card_reader_raw_sector_size(10301), // - kreg_id_card_reader_raw_sector_num(10302), // - kreg_id_card_reader_is_online(10303,false), // - - /*********************************************************************************************************************** - * 板夹仓扫码 * - ***********************************************************************************************************************/ - - kreg_plate_code_scaner_laster_intensity(10401), // - kreg_plate_code_scaner_scan_gain(10402), // - kreg_plate_code_scaner_scan_velocity(10403), // - kreg_plate_code_scaner_scan_start_pos(10404), // - kreg_plate_code_scaner_final_stop_pos(10405), // - kreg_plate_code_scaner_code_judgment_threshold(10406), // - kreg_plate_code_scaner_item(10407), // - kreg_plate_code_scaner_lot(10408), // - kreg_plate_code_scaner_rawcode(10409), // - kreg_plate_code_scaner_code_legal(10410); // - - public final int index; - public final Boolean trace; - - RegIndex(int regIndex) { - this.index = regIndex; - this.trace = true; - } - - RegIndex(int regIndex, Boolean trace) { - this.index = regIndex; - this.trace = trace; - } - - public static RegIndex valueOf(int val) { - RegIndex[] values = RegIndex.values(); - for (RegIndex regindex : values) { - if (regindex.index == val) { - return regindex; - } - } - return null; - } - -} diff --git a/src/main/java/a8k/type/A8kScanCurve.java b/src/main/java/a8k/type/A8kScanCurve.java new file mode 100644 index 0000000..9fb9019 --- /dev/null +++ b/src/main/java/a8k/type/A8kScanCurve.java @@ -0,0 +1,17 @@ +package a8k.appbase; + +import java.util.List; + +public class A8kScanCurve { + public List scanDataCurve; + public List refCurve; + public List refLine; + + public A8kScanCurve() { + } + + public A8kScanCurve(List scanDataCurve, List refLine) { + this.scanDataCurve = scanDataCurve; + this.refLine = refLine; + } +} diff --git a/src/main/java/a8k/type/ConsumableGroup.java b/src/main/java/a8k/type/ConsumableGroup.java new file mode 100644 index 0000000..7bdfdc3 --- /dev/null +++ b/src/main/java/a8k/type/ConsumableGroup.java @@ -0,0 +1,12 @@ +package a8k.appbase; + +public enum ConsumableGroup { + GROUP1, GROUP2, GROUP3, GROUP4, GROUP5, GROUP6; + + final public int off; + + ConsumableGroup() { + this.off = this.ordinal(); + } + +} diff --git a/src/main/java/a8k/type/HardwareException.java b/src/main/java/a8k/type/HardwareException.java new file mode 100644 index 0000000..5330e28 --- /dev/null +++ b/src/main/java/a8k/type/HardwareException.java @@ -0,0 +1,63 @@ +package a8k.appbase; + +import a8k.service.hardware.canbus.protocol.A8kEcode; +import a8k.service.hardware.canbus.protocol.CmdId; +import a8k.service.hardware.canbus.protocol.MId; + +public class HardwareException extends Exception { + // 构造函数 + + A8kEcode errorCode; + MId moduleId; + CmdId cmdId; + String extmessage; + + public HardwareException() { + super(); + } + + public HardwareException(MId mid, A8kEcode ecode) { + super(String.format("Module ID %s has error code %s", mid, ecode)); + this.errorCode = ecode; + this.moduleId = mid; + this.cmdId = null; + } + + public HardwareException(MId mid, A8kEcode ecode, CmdId cmd) { + super(String.format("Module ID %s has error code %s", mid, ecode)); + this.errorCode = ecode; + this.moduleId = mid; + this.cmdId = cmd; + } + + public HardwareException(A8kEcode ecode, String extmessage) { + super(String.format("Error code %s", ecode)); + this.errorCode = ecode; + this.moduleId = null; + this.cmdId = null; + this.extmessage = extmessage; + } + + public HardwareException(A8kEcode ecode) { + super(String.format("Error code %s", ecode)); + this.errorCode = ecode; + this.moduleId = null; + this.cmdId = null; + } + + public MId getModuleId() { + return moduleId; + } + + public A8kEcode getErrorCode() { + return errorCode; + } + + public CmdId getCmdId() { + return cmdId; + } + + public String getExtMessage() { + return extmessage; + } +} diff --git a/src/main/java/a8k/type/IncubatorPos.java b/src/main/java/a8k/type/IncubatorPos.java new file mode 100644 index 0000000..9d6ee07 --- /dev/null +++ b/src/main/java/a8k/type/IncubatorPos.java @@ -0,0 +1,10 @@ +package a8k.appbase; + +public enum IncubatorPos { + SPACE01, SPACE02, SPACE03, SPACE04, SPACE05, SPACE06, SPACE07, SPACE08, SPACE09, SPACE10, SPACE11, SPACE12, SPACE13, SPACE14, SPACE15, SPACE16, SPACE17, SPACE18, SPACE19, SPACE20; + + final public Integer off; + private IncubatorPos() { + this.off = ordinal(); + } +} diff --git a/src/main/java/a8k/type/OptScanDirection.java b/src/main/java/a8k/type/OptScanDirection.java new file mode 100644 index 0000000..1b6f603 --- /dev/null +++ b/src/main/java/a8k/type/OptScanDirection.java @@ -0,0 +1,9 @@ +package a8k.appbase; + +public enum OptScanDirection { + POSITIVE, NEGATIVE; + + public Integer getInteger() { + return this == POSITIVE ? 1 : -1; + } +} diff --git a/src/main/java/a8k/type/PlateInfo.java b/src/main/java/a8k/type/PlateInfo.java new file mode 100644 index 0000000..bb94f7f --- /dev/null +++ b/src/main/java/a8k/type/PlateInfo.java @@ -0,0 +1,23 @@ +package a8k.appbase; + + +public class PlateInfo { + + public Integer lot; + public Integer item; + public Boolean legal; + public String rawcode; + + public PlateInfo() { + } + + public PlateInfo(Integer lot, Integer item) { + this.lot = lot; + this.item = item; + } + + + public String toString() { + return String.format("%02d-%02d", lot, item); + } +} diff --git a/src/main/java/a8k/type/ProjectInfoSimple.java b/src/main/java/a8k/type/ProjectInfoSimple.java new file mode 100644 index 0000000..e6e19e7 --- /dev/null +++ b/src/main/java/a8k/type/ProjectInfoSimple.java @@ -0,0 +1,21 @@ +package a8k.appbase; + +import a8k.db.ProjectInfo; + +public class ProjectInfoSimple { + String projectName; //项目名称 + String lotName; //批次名称 + String expiryDate; //有效日期 + + public ProjectInfoSimple(String projectName, String lotName, String expiryDate) { + this.projectName = projectName; + this.lotName = lotName; + this.expiryDate = expiryDate; + } + + public ProjectInfoSimple(ProjectInfo pinfo) { + this.projectName = pinfo.projectName; + this.lotName = pinfo.lotName; + this.expiryDate = pinfo.expiryDate; + } +} diff --git a/src/main/java/a8k/type/SampleTubeState.java b/src/main/java/a8k/type/SampleTubeState.java new file mode 100644 index 0000000..e763f24 --- /dev/null +++ b/src/main/java/a8k/type/SampleTubeState.java @@ -0,0 +1,8 @@ +package a8k.appbase; + +/** + * 样品试管状态 + */ +public class SampleTubeState { + String tubeType; +} diff --git a/src/main/java/a8k/type/TargetPosMeasureDirection.java b/src/main/java/a8k/type/TargetPosMeasureDirection.java new file mode 100644 index 0000000..5d5ec77 --- /dev/null +++ b/src/main/java/a8k/type/TargetPosMeasureDirection.java @@ -0,0 +1,5 @@ +package a8k.appbase; + +public enum TargetPosMeasureDirection { + NOTCARE, POSITIVE, NEGATIVE; +} diff --git a/src/main/java/a8k/type/a8kcanprotocol/A8kEcode.java b/src/main/java/a8k/type/a8kcanprotocol/A8kEcode.java new file mode 100644 index 0000000..c9db525 --- /dev/null +++ b/src/main/java/a8k/type/a8kcanprotocol/A8kEcode.java @@ -0,0 +1,167 @@ +package a8k.service.hardware.canbus.protocol; + +public enum A8kEcode { + // + // FOR APP + // + Success(0, "成功"), // + TubeNotHasHat(1, "全血试管未盖帽"), // + SampleLiquidLevelWasNotDetected(2, "取样时未探测到液面"),// + LargeBufferNotEnough(3, "大瓶缓冲液不足"), // + UserDoesNotExist(5, "用户不存在"), // + GripperMPosError(6, "抓手舵机位置异常"), // + GripperZMPosError(8, "抓手升降电机位置异常"), // + GripperYMPosError(9, "抓手前后移动舵机位置异常"),// + TubesInShakeModule(10, "摇匀模组位置有试管"),// + PlateStuckDetectorSensorTrigger(11, "卡板检查光电触发"),// + PlateBoxNotCover(12, "板夹仓盖子未关闭"),// + PullerMInitPosError(13, "板夹钩爪电机没有处于转盘中央"),// + PusherMInitPosError(14, "板夹仓推杆电机没有处于零点位置"),// + RecycleBinOverflow(15, "回收仓满"),// + MotorLostStep(16, "电机丢步"),// + ActionOvertime(17, "动作执行超时"),// + CodeException(18, "代码异常"),// + ShakeModGripperZMNotInZeroPos(19, "抓手升降电机没有在零位"),// + MNotInZeroPos(20, "电机没有在零点"),// + TubeXChannelIsNotEmpty(21, "试管架平移通道有异物"),// + TubeTypeNotSupport(22, "试管类型不支持"),// + CmdIdNotSupport(23, "不支持指令"),// + PullPlateFail(24, "钩板卡板"),// + ShakeModGripperYSVInXYPublicArea(25, "摇匀模组抓手在XY公共区域"),// + ZMNotAtZPosWhenHbotTryMove(26, "HBOT启动时,Z轴电机没有在原点"),// + TakeTipFail(27, "取Tip失败"),// + PutTipFail(28, "放Tip失败"),// + StopByUser(29, "用户停止"),// + ScanTimeout(30, "扫码超时"),// + InfeedOvertimeFail(31, "入料超时"),// + OutfeedOvertimeFail(32, "出料超时"),// + TestScripIsRunning(33, "测试脚本正在运行"),// + + + PasswdError(100, "密码错误"), // + UsrNotExitError(101, "用户不存在"), // + UsrExistError(102, "用户已存在"), // + UsrNotAllowBeDeleted(103, "用户不允许被删除"), // + + TubeHolderCfgNotExist(200, "试管架配置不存在"), // + TubeCfgNotExist(201, "试管配置不存在"), // + + A8kIDCardOffline(300, "未检测到ID卡"), // + A8kIDCardContentError(301, "ID卡内容错误"), // + A8kIDCardVersionIsLow(302, "ID卡版本过低"), // + + AppOptionIsInvalid(400, "参数操作"), // + + // + // FOR HARDWARE + // + // kxymotor_not_move_to_zero = 1310, + // kstep_motor_not_move_to_zero = 1612, + + + HardwareError(1001, "硬件错误"),// + ParamOutOfRange(1102, "参数范围错误"),// + CmdNotSupport(1103, "指令不支持"),// + DeviceIsBusy(1104, "设备忙"),// + DeviceIsOffline(1105, "设备丢弃"),// + Overtime(1106, "超时"),// + Noack(1107, "没有回执"),// + Errorack(1108, "错误回执"),// + DeviceOffline(1109, "设备离线"),// + SubdeviceOvertime(1111, "子设备超时"),// + BufferNotEnough(1112, "缓存溢出"),// + CmdParamNumError(1114, "指令参数数量不对"),// + CheckcodeIsError(1115, "校验码错误"),// + IllegalOperation(1116, "非法操作"),// + ModuleOpeationBreakByUser(1202, "模块操作被用户中断"),// + ModuleNotFindReg(1207, "找不到对应的寄存器"),// + XYMotorXFindZeroEdgeFail(1306, "X轴找零失败"),// + XYMotorYFindZeroEdgeFail(1307, "Y轴找零失败"),// + XYMotorNotEnable(1308, "XY轴未使能"),// + XYMotorTargetPosOutofRange(1309, "XY轴目标位置超出范围"),// + XYmotorNotMoveToZero(1310, "XY轴未回零"),// + + PipetteErrorNoerror(1400, "PipetteErrorNoerror"),// + PipetteErrorInitfail(1401, "PipetteErrorInitfail"),// + PipetteErrorInvalidcmd(1402, "PipetteErrorInvalidcmd"),// + PipetteErrorInvalidarg(1403, "PipetteErrorInvalidarg"),// + PipetteErrorPressuresensorerror(1404, "PipetteErrorPressuresensorerror"),// + PipetteErrorOverpressure(1405, "PipetteErrorOverpressure"),// + PipetteErrorLlderror(1406, "PipetteErrorLlderror"),// + PipetteErrorDevicenotinit(1407, "PipetteErrorDevicenotinit"),// + PipetteErrorTippoperror(1408, "PipetteErrorTippoperror"),// + PipetteErrorPumpoverload(1409, "PipetteErrorPumpoverload"),// + PipetteErrorTipdrop(1410, "PipetteErrorTipdrop"),// + PipetteErrorCanbuserror(1411, "PipetteErrorCanbuserror"),// + PipetteErrorInvalidchecksum(1412, "PipetteErrorInvalidchecksum"),// + PipetteErrorEepromerror(1413, "PipetteErrorEepromerror"),// + PipetteErrorCmdbufferempty(1414, "PipetteErrorCmdbufferempty"),// + PipetteErrorCmdbufferoverflow(1415, "PipetteErrorCmdbufferoverflow"),// + PipetteErrorTipblock(1416, "PipetteErrorTipblock"),// + PipetteErrorAirsuction(1417, "PipetteErrorAirsuction"),// + PipetteErrorBubble(1418, "PipetteErrorBubble"),// + PipetteErrorVolumeerror(1419, "PipetteErrorVolumeerror"),// + PipetteErrorTipalreadyload(1420, "PipetteErrorTipalreadyload"),// + PipetteErrorTiploadfail(1421, "PipetteErrorTiploadfail"),// + PipetteErrorUninited(1501, "PipetteErrorUninited"),// + PipetteErrorNotLldPrepare(1502, "PipetteErrorNotLldPrepare"),// + PipetteErrorTipisloadWhenLldPrepare(1500, "PipetteErrorTipisloadWhenLldPrepare"),// + PipetteErrorPumpLoadValIsNotEmpty(1503, "PipetteErrorPumpLoadValIsNotEmpty"),// + StepMotorNotFoundZeroPoint(1600, "步进电机未找到零点"),// + StepMotorNotGoZero(1601, "步进电机未回零"),// + StepMotorOverTemperature(1602, "步进电机过温"),// + StepMotorOverVoltage(1603, "步进电机过压"),// + StepMotorRunOvertime(1604, "步进电机运行超时"),// + StepMotorNotEnable(1605, "步进电机未使能"),// + StepMotorIoindexOutOfRange(1606, "步进电机IO索引超出范围"),// + StepMotorSubicReset(1607, "步进电机子设备复位"),// + StepMotorDrvErr(1608, "步进电机驱动错误"),// + StepMotorUvCp(1609, "步进电机UV CP"),// + StepMotorNotFoundPointEdge(1610, "步进电机未找到零点边沿"),// + StepMotorLostStep(1611, "步进电机丢步"),// + StepMotorNotMoveToZero(1612, "步进电机未回零"),// + + MiniServoNotEnable(1700, "舵机未使能"),// + MiniServoModeNotSupport(1701, "舵机模式不支持"),// + FanHardwareFault(1800, "风扇硬件故障"),// + WaterCoolingFanError(1900, "水冷风扇故障"),// + WaterCoolingTemperatureSensorError(1902, "水冷温度传感器故障"),// + WaterCoolingPumpIsError(1903, "水冷水泵故障"),// + WaterCoolingPelterIsError(1904, "水冷电热片故障"),// + ; + + public int index; + public String chname; + + A8kEcode(int index, String chname) { + this.index = index; + this.chname = chname; + } + + public int toInt() { + return index; + } + + public static A8kEcode valueOf(int val) { + A8kEcode[] values = A8kEcode.values(); + for (A8kEcode e : values) { + if (e.toInt() == val) + return e; + } + return null; + } + + public static String toString(int val) { + A8kEcode[] values = A8kEcode.values(); + for (A8kEcode e : values) { + if (e.toInt() == val) { + return e.toString(); + } + } + return "unkown(" + val + ")"; + } + + public String getChname() { + return chname; + } +} diff --git a/src/main/java/a8k/type/a8kcanprotocol/A8kPacket.java b/src/main/java/a8k/type/a8kcanprotocol/A8kPacket.java new file mode 100644 index 0000000..bc6e445 --- /dev/null +++ b/src/main/java/a8k/type/a8kcanprotocol/A8kPacket.java @@ -0,0 +1,161 @@ +package a8k.service.hardware.canbus.protocol; + +import a8k.utils.ByteArray; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class A8kPacket { + /** + * typedef struct { + * uint16_t packetindex; // 0: + * uint16_t cmdMainId; // 2: + * uint8_t cmdSubId; // 4: + * uint8_t packetType; // 5: + * uint16_t moduleid; // 6: + * uint8_t data[]; // 8: + * } zcr_cmd_header_t; + *

+ * kptv2_cmd = 0, + * kptv2_ack = 1, + * kptv2_error_ack = 2, + * kptv2_event = 3, + */ + public static final Logger logger = LoggerFactory.getLogger(A8kPacket.class); + + byte[] raw; + + public static final int PACKET_MIN_LEN = 8; + + public static final int PACKET_INDEX_OFF = 0; + public static final int CMD_ID_OFF = 2; + public static final int PACKET_TYPE_OFF = 5; + public static final int MODULE_ID_OFF = 6; + public static final int DATA_BEGIN_OFF = 8; + + + public static final int PACKET_TYPE_CMD = 0; + public static final int PACKET_TYPE_ACK = 1; + public static final int PACKET_TYPE_ERROR_ACK = 2; + public static final int PACKET_TYPE_EVENT = 3; + + public static final int CMD_OVERTIME = 2000; + + public A8kPacket(byte[] cmd) { + raw = new byte[cmd.length]; System.arraycopy(cmd, 0, raw, 0, cmd.length); + } + + public void setPacketIndex(int packetIndex) { + ByteArray.setU16bit(raw, 0, packetIndex); + } + + public int getPacketIndex() { + return ByteArray.readU16bit(raw, 0); + } + + public int getCmdId() { + return ByteArray.readU16bit((raw), 2) * 256 + ByteArray.readU8bit(raw, 4); + } + + public int getPacketType() { + return ByteArray.readU8bit(raw, 5); + } + + public int getModuleId() { + return ByteArray.readU16bit(raw, 6); + } + + public byte[] getCmdContent() { + if (raw.length < 8) { + return new byte[0]; + } byte[] cmdcontent = new byte[raw.length - 8]; System.arraycopy(raw, 8, cmdcontent, 0, raw.length - 8); return cmdcontent; + } + + public int getContentI32(int index) { + return ByteArray.read32bit(raw, 8 + index * 4); + } + + public String toByteString() { + return ByteArray.toByteString(raw); + } + + public String toString() { + int packetType = getPacketType(); String ret = ""; + + CmdId cmdId = CmdId.valueOf(getCmdId()); + assert cmdId != null; + if (packetType == PACKET_TYPE_CMD) { + + if (cmdId.equals(CmdId.module_get_reg) || cmdId.equals(CmdId.module_set_reg)) { + RegIndex regIndex = RegIndex.valueOf(getContentI32(0)); + if (regIndex != null) { + ret = String.format("[CMD ] index:[%d] %s %s %s(%d) %d", getPacketIndex(), cmdId, MId.valueOf(getModuleId()),regIndex, regIndex.index, getContentI32(1)); + } else { + ret = String.format("[CMD ] index:[%d] %s unkown_index(%d) %d", getPacketIndex(), cmdId, getContentI32(0), getContentI32(1)); + } + } else { + if (cmdId.cmdAttachType == CmdId.ATTACH_IS_INT32) { + ret = String.format("[CMD ] index:[%d] (%s %s(%d) :param:[%s])", getPacketIndex(), cmdId, MId.valueOf(getModuleId()), getModuleId(), formatInt32ATTACH(getCmdContent())); + } else { + ret = String.format("[CMD ] index:[%d] (%s %s(%d) :param:[%s])", getPacketIndex(), cmdId, MId.valueOf(getModuleId()), getModuleId(), ByteArray.toByteString(getCmdContent())); + } + } + + } else if (packetType == PACKET_TYPE_ACK) { + if (cmdId.receiptAttachType == CmdId.ATTACH_IS_INT32) { + ret = String.format("[ACK ] index:[%d] (%s :[%s])", getPacketIndex(), cmdId, formatInt32ATTACH(getCmdContent())); + } else { + ret = String.format("[ACK ] index:[%d] (%s :[%s])", getPacketIndex(), cmdId, ByteArray.toByteString(getCmdContent())); + } + } else if (packetType == PACKET_TYPE_ERROR_ACK) { + ret = String.format("[EACK ] index:[%d] (%s :[%s])", getPacketIndex(), cmdId, A8kEcode.toString(getContentI32(0))); + } else if (packetType == PACKET_TYPE_EVENT) { + if (cmdId.cmdAttachType == CmdId.ATTACH_IS_INT32) { + ret = String.format("[EVENT] index:[%d] (%s %s(%d) :[%s])", getPacketIndex(), cmdId, MId.valueOf(getModuleId()), getModuleId(), formatInt32ATTACH(getCmdContent())); + } else { + ret = String.format("[EVENT] index:[%d] (%s %s(%d) :[%s])", getPacketIndex(), cmdId, MId.valueOf(getModuleId()), getModuleId(), ByteArray.toByteString(getCmdContent())); + } + } else { + ret = String.format("Unknown packet type: %d", packetType); + } return ret; + } + + private String formatInt32ATTACH(byte[] attach) { + StringBuilder ret = new StringBuilder(); for (int i = 0; i < attach.length; i += 4) { + if (i + 3 >= attach.length) + break; if (i != 0) + ret.append(","); ret.append(String.format("%d", ByteArray.read32bit(attach, i))); + } return ret.toString(); + } + + public Boolean isSupportPacket() { + CmdId cmdid = CmdId.valueOf(getCmdId()); + if (cmdid == null) { + return false; + } + if (CmdId.module_get_reg.equals(cmdid) || CmdId.module_set_reg.equals(cmdid)) { + if (getPacketType() == PACKET_TYPE_CMD) { + RegIndex regIndex = RegIndex.valueOf(getContentI32(0)); + return regIndex != null; + } + } + return true; + } + + + public Boolean isTrace() { + if (!isSupportPacket()) { + return false; + } + CmdId cmdid = CmdId.valueOf(getCmdId()); + assert cmdid != null; + + if (CmdId.module_get_reg.equals(cmdid) || CmdId.module_set_reg.equals(cmdid)) { + RegIndex regIndex = RegIndex.valueOf(getContentI32(0)); + assert regIndex != null; + return regIndex.trace; + } else { + return cmdid.trace; + } + } + +} diff --git a/src/main/java/a8k/type/a8kcanprotocol/CmdId.java b/src/main/java/a8k/type/a8kcanprotocol/CmdId.java new file mode 100644 index 0000000..f712e4a --- /dev/null +++ b/src/main/java/a8k/type/a8kcanprotocol/CmdId.java @@ -0,0 +1,202 @@ +package a8k.service.hardware.canbus.protocol; + +public enum CmdId { + + + NotSet(0xFFFF, "NOACTION"),// + + board_reset(0x0000, "复位板子"),// + event_bus_reg_change_report(0x0064, "寄存器修改事件"),// + // + module_ping(0x0100, "MODULE_PING"),// + module_get_status(0x0104, "读取模块状态", false),// + module_stop(0x0101, "模块停止"),// + module_set_reg(0x0105, "写入寄存器"),// + module_get_reg(0x0106, "获取寄存器"),// + module_get_error(0x010a, "读取模块错误", false),// + module_clear_error(0x010b, "清除模块错误"),// + module_active_cfg(0x0110, "激活配置"),// + // + xymotor_enable(0x0301, "XYMOTOR_ENABLE"),// + xymotor_move_by(0x0302, "XYMOTOR_MOVE_BY"),// + xymotor_move_to(0x0303, "XYMOTOR_MOVE_TO"),// + xymotor_move_to_zero(0x0304, "XYMOTOR_MOVE_TO_ZERO"),// + xymotor_read_pos(0x0306, "XYMOTOR_READ_POS",false),// + xymotor_read_inio_index_in_stm32(0x0307, "XYMOTOR_READ_INIO_INDEX_IN_STM32"),// + xymotor_read_inio(0x0308, "XYMOTOR_READ_INIO", false),// + xymotor_set_pos(0x0309, "XYMOTOR_SET_POS"),// + xymotor_motor_move_by_direct(0x030a, "XYMOTOR_MOTOR_MOVE_BY_DIRECT"),// + xymotor_read_enc_direct(0x030b, "XYMOTOR_READ_ENC_DIRECT"),// + // + pipette_ctrl_init_device(0x7201, "PIPETTE_CTRL_INIT_DEVICE"),// + pipette_ctrl_put_tip(0x7202, "PIPETTE_CTRL_PUT_TIP"),// + pipette_ctrl_move_to_ul(0x7203, "PIPETTE_CTRL_MOVE_TO_UL"),// + pipette_lld_prepare(0x7204, "PIPETTE_LLD_PREPARE"),// + pipette_plld(0x7205, "PIPETTE_PLLD"),// + pipette_clld(0x7206, "PIPETTE_CLLD"),// + pipette_mlld(0x7207, "PIPETTE_MLLD"),// + pipette_lld_is_detect_liquid(0x7208, "PIPETTE_LLD_IS_DETECT_LIQUID"),// + pipette_aspirate(0x7209, "PIPETTE_ASPIRATE"),// + pipette_distribut(0x720a, "PIPETTE_DISTRIBUT"),// + pipette_shake_up(0x720b, "PIPETTE_SHAKE_UP"),// + pipette_enable_zmotor(0x7214, "PIPETTE_ENABLE_ZMOTOR"),// + pipette_write_cmd_direct(0x7215, "PIPETTE_WRITE_CMD_DIRECT"),// + pipette_get_sensor_sample_data(0x7216, "PIPETTE_GET_SENSOR_SAMPLE_DATA"),// + pipette_get_sensor_sample_data_num(0x7217, "PIPETTE_GET_SENSOR_SAMPLE_DATA_NUM"),// + pipette_sensor_sample_data_report(0x7232, "PIPETTE_SENSOR_SAMPLE_DATA_REPORT"),// + pipette_aspirate_llf(0x720c, "PIPETTE_ASPIRATE_LLF"),// + pipette_distribut_llf(0x720d, "PIPETTE_DISTRIBUT_LLF"),// + pipette_shake_up_llf(0x720e, "PIPETTE_SHAKE_UP_LLF"),// + + a8k_opt_v2_read_raw(0x0609, "A8K_OPT_V2_READ_RAW", CmdId.ATTACH_IS_INT32, CmdId.ATTACH_IS_BYTES),// + // + a8k_opt_v2_t_start_scan(0x0700, "A8K_OPT_V2_T_START_SCAN"),// + a8k_opt_v2_f_start_scan(0x0701, "A8K_OPT_V2_F_START_SCAN"),// + a8k_opt_v2_t_open_laster(0x070a, "A8K_OPT_V2_T_OPEN_LASTER"),// + a8k_opt_v2_t_close_laster(0x070b, "A8K_OPT_V2_T_CLOSE_LASTER"),// + a8k_opt_v2_t_readVal(0x070c, "A8K_OPT_V2_T_READVAL"),// + a8k_opt_v2_f_open_laster(0x070d, "A8K_OPT_V2_F_OPEN_LASTER"),// + a8k_opt_v2_f_close_laster(0x070e, "A8K_OPT_V2_F_CLOSE_LASTER"),// + a8k_opt_v2_f_readVal(0x070f, "A8K_OPT_V2_F_READVAL"),// + // + step_motor_enable(0x0201, "STEP_MOTOR_ENABLE"),// + step_motor_read_pos(0x020b, "STEP_MOTOR_READ_POS"),// + step_motor_easy_rotate(0x0211, "STEP_MOTOR_EASY_ROTATE"),// + step_motor_easy_move_by(0x0212, "STEP_MOTOR_EASY_MOVE_BY"),// + step_motor_easy_move_to(0x0213, "STEP_MOTOR_EASY_MOVE_TO"),// + step_motor_easy_move_to_zero(0x0214, "STEP_MOTOR_EASY_MOVE_TO_ZERO"),// + step_motor_easy_set_current_pos(0x0215, "STEP_MOTOR_EASY_SET_CURRENT_POS"),// + step_motor_easy_move_to_io(0x0216, "STEP_MOTOR_EASY_MOVE_TO_IO"),// + step_motor_stop(0x0228, "STEP_MOTOR_STOP"),// + step_motor_active_cfg(0x0229, "STEP_MOTOR_ACTIVE_CFG"),// + step_motor_read_io_state(0x022a, "STEP_MOTOR_READ_IO_STATE", false),// + step_motor_easy_move_to_end_point(0x022c, "STEP_MOTOR_EASY_MOVE_TO_END_POINT"),// + step_motor_read_tmc5130_status(0x0232, "STEP_MOTOR_READ_TMC5130_STATUS"),// + step_motor_read_tmc5130_state(0x0233, "STEP_MOTOR_READ_TMC5130_STATE"),// + step_motor_read_io_index_in_stm32(0x0238, "STEP_MOTOR_READ_IO_INDEX_IN_STM32"),// + step_motor_set_subdevice_reg(0x0239, "STEP_MOTOR_SET_SUBDEVICE_REG"),// + step_motor_get_subdevice_reg(0x023a, "STEP_MOTOR_GET_SUBDEVICE_REG"),// + step_motor_easy_reciprocating_motion(0x022d, "STEP_MOTOR_EASY_RECIPROCATING_MOTION"),// + step_motor_easy_move_to_zero_point_quick(0x022e, "STEP_MOTOR_EASY_MOVE_TO_ZERO_POINT_QUICK"),// + // + mini_servo_enable(0x6601, "MINI_SERVO_ENABLE"),// + mini_servo_read_pos(0x6602, "MINI_SERVO_READ_POS"),// + mini_servo_active_cfg(0x6603, "MINI_SERVO_ACTIVE_CFG"),// + mini_servo_stop(0x6604, "MINI_SERVO_STOP"),// + mini_servo_set_mid_point(0x6607, "MINI_SERVO_SET_MID_POINT"),// + mini_servo_read_io_state(0x6608, "MINI_SERVO_READ_IO_STATE"),// + mini_servo_move_to(0x6609, "MINI_SERVO_MOVE_TO"),// + mini_servo_rotate(0x660a, "MINI_SERVO_ROTATE"),// + mini_servo_rotate_with_torque(0x660b, "MINI_SERVO_ROTATE_WITH_TORQUE"),// + mini_servo_set_cur_pos(0x660c, "MINI_SERVO_SET_CUR_POS"),// + // + extboard_read_inio(0x6701, "EXTBOARD_READ_INIO", false),// + extboard_write_outio(0x6702, "EXTBOARD_WRITE_OUTIO"),// + extboard_read_muti_inio(0x6703, "EXTBOARD_READ_MUTI_INIO", false),// + extboard_read_inio_index_in_stm32(0x6704, "EXTBOARD_READ_INIO_INDEX_IN_STM32"),// + extboard_read_outio_index_in_stm32(0x6705, "EXTBOARD_READ_OUTIO_INDEX_IN_STM32"),// + extboard_read_outio(0x6706, "EXTBOARD_READ_OUTIO"),// + code_scaner_start_scan(0x6801, "CODE_SCANER_START_SCAN"),// + code_scaner_stop_scan(0x6802, "CODE_SCANER_STOP_SCAN"),// + code_scaner_result_is_ready(0x6803, "CODE_SCANER_RESULT_IS_READY",false),// + code_scaner_read_scaner_result(0x6804, "CODE_SCANER_READ_SCANER_RESULT"),// + code_scaner_get_result_length(0x6805, "CODE_SCANER_GET_RESULT_LENGTH"),// + // + fan_controler_set_speed(0x6900, "FAN_CONTROLER_SET_SPEED"),// + // + temp_controler_start_hearting(0x7000, "TEMP_CONTROLER_START_HEARTING"),// + temp_controler_stop_hearting(0x7001, "TEMP_CONTROLER_STOP_HEARTING"),// + temp_controler_set_peltier_power_level(0x7002, "TEMP_CONTROLER_SET_PELTIER_POWER_LEVEL"),// + temp_controler_set_pump_level(0x7003, "TEMP_CONTROLER_SET_PUMP_LEVEL"),// + temp_controler_set_fan_level(0x7004, "TEMP_CONTROLER_SET_FAN_LEVEL"),// + temp_controler_enable_log(0x7005, "TEMP_CONTROLER_ENABLE_LOG"),// + // + a8000_idcard_reader_read_raw(0x7100, "A8000_IDCARD_READER_READ_RAW", CmdId.ATTACH_IS_INT32, CmdId.ATTACH_IS_BYTES,false),// + a8000_idcard_write_raw(0x7101, "A8000_IDCARD_WRITE_RAW", CmdId.ATTACH_IS_BYTES, CmdId.ATTACH_IS_INT32,false),// + a8000_idcard_erase(0x7102, "A8000_IDCARD_ERASE"),// + a8000_idcard_earse_unlock(0x7103, "A8000_IDCARD_EARSE_UNLOCK"),// + // + event_a8000_idcard_online(0x71c8, "EVENT_A8000_IDCARD_ONLINE"),// + event_a8000_idcard_offline(0x71c9, "EVENT_A8000_IDCARD_OFFLINE"),// + // + plate_code_scaner_push_card_and_scan(0x7301, "PLATE_CODE_SCANER_PUSH_CARD_AND_SCAN"),// + plate_code_scaner_stop_scan(0x7302, "PLATE_CODE_SCANER_STOP_SCAN"),// + plate_code_scaner_read_result(0x7303, "PLATE_CODE_SCANER_READ_RESULT"),// + plate_code_scaner_read_result_point_num(0x7304, "PLATE_CODE_SCANER_READ_RESULT_POINT_NUM"),// + plate_code_scaner_read_code(0x7305, "PLATE_CODE_SCANER_READ_CODE"),// + plate_code_scaner_adc_readraw(0x7306, "PLATE_CODE_SCANER_ADC_READRAW"),// + plate_code_scaner_open_laser(0x7307, "PLATE_CODE_SCANER_OPEN_LASER"),// + plate_code_scaner_close_laser(0x7308, "PLATE_CODE_SCANER_CLOSE_LASER"),// + ; + + public final static int ATTACH_IS_BYTES = 1; + public final static int ATTACH_IS_INT32 = 2; + + public int index; + public String chName; + public int cmdAttachType = ATTACH_IS_INT32; + public int receiptAttachType = ATTACH_IS_INT32; + public boolean trace = true; + public boolean actionCmd = true; + + CmdId(int index, String chname) { + this.index = index; + this.chName = chname; + } + + CmdId(int index, String chname, boolean trace) { + this.index = index; + this.chName = chname; + this.trace = trace; + this.actionCmd = trace; + } + + CmdId(int index, String chname, int cmdAttachType, int receiptAttachType) { + this.index = index; + this.chName = chname; + this.cmdAttachType = cmdAttachType; + this.receiptAttachType = receiptAttachType; + } + + CmdId(int index, String chname, int cmdAttachType, int receiptAttachType, boolean trace) { + this.index = index; + this.chName = chname; + this.cmdAttachType = cmdAttachType; + this.receiptAttachType = receiptAttachType; + this.trace = trace; + } + + + public int toInt() { + return index; + } + + public static CmdId valueOf(int val) { + CmdId[] values = CmdId.values(); + for (CmdId e : values) { + if (e.toInt() == val) + return e; + } + return null; + } + + public static String toString(int val) { + CmdId[] values = CmdId.values(); + for (CmdId e : values) { + if (e.toInt() == val) { + return e.toString(); + } + } + return "unkown(" + val + ")"; + } + + public String getChname() { + return chName; + } + + public Boolean eq(Integer index) { + return this.index == index; + } + + +} diff --git a/src/main/java/a8k/type/a8kcanprotocol/IOId.java b/src/main/java/a8k/type/a8kcanprotocol/IOId.java new file mode 100644 index 0000000..cee92af --- /dev/null +++ b/src/main/java/a8k/type/a8kcanprotocol/IOId.java @@ -0,0 +1,38 @@ +package a8k.service.hardware.canbus.protocol; + +public enum IOId { + TubeHeightPPS(ModuleType.kboard, MId.FeedingModBoard, 0), //高低试管检测IO + THChOuterPPS(ModuleType.kboard, MId.FeedingModBoard, 1),//试管架转移通道有无检测 外 + THChInterPPS(ModuleType.kboard, MId.FeedingModBoard, 2),//试管架转移通道有无检测 内 + OutfeedPPS(ModuleType.kboard, MId.FeedingModBoard, 3),//试管出料位置 试管架有无检测 + TubeExistPPS(ModuleType.kboard, MId.FeedingModBoard, 4),//试管有无光电 + InfeedPPS(ModuleType.kboard, MId.FeedingModBoard, 5),//试管架入料位置 试管架有无检测 + + RecycleBinOverflowPPS(ModuleType.kboard, MId.PlatesBoxTCMBoard, 2),//废料桶满溢检测 + RecycleBinOverflowPPSPowerCtrl(ModuleType.kboard, MId.PlatesBoxTCMBoard, 0),//废料桶光栅电源 + + PlateBoxCoverClosurePPS(ModuleType.kboard, MId.PlatesBoxBoard, 0),//板夹仓舱盖闭合检测 + PlateBoxPlateStuckPPS(ModuleType.kboard, MId.PlatesBoxBoard, 1),//板夹仓卡板检测 + + //转盘逻辑相关光电 + //钩板电机,零点光电,终点光电 + PullerMZeroPPS(ModuleType.ktmc_step_motor, MId.OptModPullM, 0),// + PullerMEndPPS(ModuleType.ktmc_step_motor, MId.OptModPullM, 1),// + //推板电机,零点光电,终点光电 + PusherMZeroPPS(ModuleType.ktmc_step_motor, MId.PlatesBoxPusherM, 0),// + PusherMEndPPS(ModuleType.ktmc_step_motor, MId.PlatesBoxPusherM, 1),// + + ; + + + final public ModuleType mtype; + final public MId mid; + final public int ioIndex; + + IOId(ModuleType mtype, MId mid, int ioIndex) { + this.mtype = mtype; + this.mid = mid; + this.ioIndex = ioIndex; + } + +} diff --git a/src/main/java/a8k/type/a8kcanprotocol/MId.java b/src/main/java/a8k/type/a8kcanprotocol/MId.java new file mode 100644 index 0000000..fb42e8d --- /dev/null +++ b/src/main/java/a8k/type/a8kcanprotocol/MId.java @@ -0,0 +1,89 @@ +package a8k.service.hardware.canbus.protocol; + +public enum MId { + NotSet(0, "未设置"),// + HbotBoard(10, "机械臂板模块"),// + HbotM(11, "机械臂XY"),// + // + PlatesBoxBoard(20, "板夹仓模块"),// + PlatesBoxYM(21, "板夹仓移动电机"),// + PlatesBoxPusherM(22, "板夹仓推杆电机"),// + PlatesBoxScanner(23, "板夹仓扫码模组"),// + // + ShakeModBoard(30, "摇匀模组板"),// + ShakeModClampingM(31, "试管固定夹爪电机"),// + ShakeModGripperZM(32, "摇匀升降电机"),// + ShakeModShakeM(33, "试管摇匀电机"),// + ShakeModGripperYSV(34, "摇匀前后移动舵机"),// + ShakeModGripperSV(35, "摇匀试管帽夹爪舵机"),// + ShakeModTubeScanerClampingSV(36, "试管架扫码夹紧舵机"),// + ShakeModTubeScanerRotateSV(37, "试管架旋转舵机"),// + // + PlatesBoxTCMBoard(40, "反应板夹温度控制板"),// + PlatesBoxTCM(41, "反应板夹温度控制模块"),// + WbTubeFanMod(42, "气溶胶风扇"),// + // + IncubatorTCMBoard(50, "温度控制"),// + IncubatorTCM(51, "温度控制"),// + // + FeedingModBoard(60, "出入料模块"),// + FeedingModInfeedM(61, "入料电机"),// + FeedingModXM(62, "试管架平移电机"),// + FeedingModOutfeedM(63, "出料电机"),// + FeedingModScannerMod(64, "试管架扫码器"),// + // + IncubatorRotateBoard(70, "孵育盘旋转板"),// + IncubatorRotateCtrlM(71, "孵育盘旋转"),// + // + PipetteModBoard(80, "机械臂Z轴板"),// + PipetteModZM(81, "机械臂Z"),// + PipetteMod(82, "移液枪"),// + PipetteModCodeScanner(83, "物料扫码器"),// + // + OptModBoard(90, "光学模组板"),// + OptModScannerM(91, "板卡扫描电机"),// + OptModPullM(92, "板卡推杆电机"),// + OptMod(93, "扫描仪"),// + // + A8kIdCardReaderBoard(100, "A8K读卡器板"),// + A8kIdCardReader(101, "A8K读卡器"),// + ; + + + final public String chname; + final public int index; + + MId(int index, String chname) { + this.chname = chname; + this.index = index; + } + + public int toInt() { + return index; + } + + + public static MId valueOf(Integer val) { + return valueOf(val.intValue()); + } + + public static MId valueOf(int val) { + MId[] values = MId.values(); + for (MId e : values) { + if (e.toInt() == val) + return e; + } + return null; + } + + public static String toString(int val) { + MId[] values = MId.values(); + for (MId e : values) { + if (e.toInt() == val) { + return e.toString(); + } + } + return "unkown(" + val + ")"; + } + +} diff --git a/src/main/java/a8k/type/a8kcanprotocol/ModuleStatus.java b/src/main/java/a8k/type/a8kcanprotocol/ModuleStatus.java new file mode 100644 index 0000000..2381573 --- /dev/null +++ b/src/main/java/a8k/type/a8kcanprotocol/ModuleStatus.java @@ -0,0 +1,24 @@ +package a8k.service.hardware.canbus.protocol; + +public enum ModuleStatus { + IDLE(0), // + BUSY(1), // + ERROR(2),// + ; + + final public int index; + + ModuleStatus(int index) { + this.index = index; + } + + public int getIndex() { + return index; + } + + public static ModuleStatus valueOf(int value) { // 手写的从int到enum的转换函数 + assert (value >= 0 && value < 2); + return values()[value]; + } + +} diff --git a/src/main/java/a8k/type/a8kcanprotocol/ModuleType.java b/src/main/java/a8k/type/a8kcanprotocol/ModuleType.java new file mode 100644 index 0000000..8ade0ce --- /dev/null +++ b/src/main/java/a8k/type/a8kcanprotocol/ModuleType.java @@ -0,0 +1,27 @@ +package a8k.service.hardware.canbus.protocol; + +public enum ModuleType { + khbot_module(1), // hbot模块 + ktemperature_ctrl_module(3), // 温度控制 + kfan_ctrl_module(5), // 风扇控制 + kcode_scaner(6), // 扫码器 + kpipette_ctrl_module(7), // 移液体枪控制 + ka8000_optical_module(8), // a8000光学模组 + ktmc_step_motor(10), // 步进电机 + kmini_servo_motor_module(11), // 舵机 + kboard(12), // 板子 + ka8000_idcard_reader(13), // id卡读卡器 + ka8000_plate_code_scaner(14); // 反应板条扫码器 + + final private int val; + + ModuleType(int val) { + this.val = val; + } + + public int getVal() { + return val; + } + + +} diff --git a/src/main/java/a8k/type/a8kcanprotocol/RegIndex.java b/src/main/java/a8k/type/a8kcanprotocol/RegIndex.java new file mode 100644 index 0000000..6c5de69 --- /dev/null +++ b/src/main/java/a8k/type/a8kcanprotocol/RegIndex.java @@ -0,0 +1,208 @@ +package a8k.service.hardware.canbus.protocol; + +public enum RegIndex { + + /******************************************************************************* + * 模块通用配置和状态 * + *******************************************************************************/ + kreg_module_version(0), // 模块版本 + kreg_module_type(1), // 模块类型 + kreg_module_status(2), // 0idle,1busy,2error + kreg_module_errorcode(3), // inited_flag + + kreg_extboard_resetflag(100), + + /*********************************************************************************************************************** + * 水冷温度控制器 * + ***********************************************************************************************************************/ + kreg_water_cooling_tmp_controler_pid_target(3000), // 目标数值 + kreg_water_cooling_tmp_controler_pid_nowoutput(3001), // 当前输出 + kreg_water_cooling_tmp_controler_pid_feedbackval(3002), // 当前输出 + kreg_water_cooling_tmp_controler_temp0(3003), // 温度1 + kreg_water_cooling_tmp_controler_temp1(3004), // 温度2 + kreg_water_cooling_tmp_controler_temp2(3005), // 温度3 + kreg_water_cooling_tmp_controler_temp3(3006), // 温度4 + + kreg_water_cooling_tmp_controler_pid_kp(3050), // kp + kreg_water_cooling_tmp_controler_pid_ki(3051), // ki + kreg_water_cooling_tmp_controler_pid_kd(3052), // kd + kreg_water_cooling_tmp_controler_pid_max_output(3053), // 最大输出 + kreg_water_cooling_tmp_controler_pid_min_output(3054), // 最小输出 + kreg_water_cooling_tmp_controler_pid_max_integral(3055), // 最大积分 + kreg_water_cooling_tmp_controler_pid_min_integral(3056), // 最小积分 + kreg_water_cooling_tmp_controler_pid_error_limit(3057), // 误差限制 + kreg_water_cooling_tmp_controler_pid_compute_interval(3058), // 计算间隔 + + /******************************************************************************* + * 移液枪状态 * + *******************************************************************************/ + kreg_pipette_pos_ul(4000), // 移液枪位置 + kreg_pipette_capactitance_val(4001), // 移液枪电容值 + kreg_pipette_tip_state(4002, false), // 移动液枪tip状态 + + kreg_pipette_limit_ul(4051), // + kreg_pipette_pump_acc(4052), // + kreg_pipette_pump_dec(4053), // + kreg_pipette_pump_vstart(4054), // + kreg_pipette_pump_vstop(4055), // + kreg_pipette_pump_vmax(4056), // + kreg_pipette_aspirate_distribut_pump_vel(4057), // + kreg_pipette_lld_pump_vel(4058), // + kreg_pipette_lld_motor_vel_rpm(4059), // + kreg_pipette_lld_detect_period_ms(4060), // + kreg_pipette_lld_prepare_pos(4061), // + kreg_pipette_lld_prepare_distribut_pos(4062), // + + /** + * @brief + * + * ------------------------------------------------------ + * + * + * 扫描零点偏移:(F光学向左扫描的起始位置) + * 扫描方向:1:板卡箭头方向,-1板卡箭头反方向 + * 扫描点数:固定为1200 + * 扫描步距:固定为1 + * + * 返回点数:(1200) + * + * + */ + // 坐标参数 + + kreg_a8k_opt_t_pos_offset(4501), // T光学正向扫描,扫描起始位距离零点的偏移 + kreg_a8k_opt_f_pos_offset(4502), // F光学正向扫描,扫描起始位距离零点的偏移 + kreg_a8k_opt_t_reverse_scan_pos_offset(4503), // T光学逆向扫描,扫描起始位距离零点的偏移 + kreg_a8k_opt_f_reverse_scan_pos_offset(4504), // F光学逆向扫描,扫描起始位距离零点的偏移 + kreg_a8k_opt_scan_step_interval(4505), // 参数固定:为1 + kreg_a8k_opt_scan_pointnum(4506), // 参数固定:为1200个点 + + /*********************************************************************************************************************** + * XYROBOT * + ***********************************************************************************************************************/ + + kreg_xyrobot_io_state(9900, false), // + kreg_xyrobot_is_enable(9901), // + kreg_xyrobot_robot_type(9950), // + kreg_xyrobot_one_circle_pulse(9951), // + kreg_xyrobot_one_circle_pulse_denominator(9952), // + kreg_xyrobot_ihold(9954), // + kreg_xyrobot_irun(9955), // + kreg_xyrobot_iholddelay(9956), // + kreg_xyrobot_iglobalscaler(9957), // + kreg_xyrobot_vstart(9958), // + kreg_xyrobot_a1(9959), // + kreg_xyrobot_amax(9960), // + kreg_xyrobot_v1(9961), // + kreg_xyrobot_dmax(9962), // + kreg_xyrobot_d1(9963), // + kreg_xyrobot_vstop(9964), // + kreg_xyrobot_tzerowait(9965), // + kreg_xyrobot_enc_resolution(9966), // + kreg_xyrobot_enable_enc(9967), // + kreg_xyrobot_x_shaft(9968), // + kreg_xyrobot_y_shaft(9969), // + kreg_xyrobot_min_x(9972), // + kreg_xyrobot_min_y(9973), // + kreg_xyrobot_max_x(9974), // + kreg_xyrobot_max_y(9975), // + kreg_xyrobot_run_to_zero_speed(9976), // + kreg_xyrobot_look_zero_edge_speed(9977), // + kreg_xyrobot_shift_x(9978), // + kreg_xyrobot_shift_y(9979), // + kreg_xyrobot_pos_devi_tolerance(9980), // + kreg_xyrobot_io_trigger_append_distance(9981), // + kreg_xyrobot_default_velocity(10000), // + + /*********************************************************************************************************************** + * step_motor * + ***********************************************************************************************************************/ + + kreg_step_motor_pos(10101), // 机器人x坐标 + kreg_step_motor_is_enable(10102), // 是否使能 + kreg_step_motor_dpos(10103), // 执行完上一条指令后的相对位移 + kreg_step_motor_shift(10150), // x偏移 + kreg_step_motor_shaft(10151), // x轴是否反转 + kreg_step_motor_one_circle_pulse(10152), // x轴一圈脉冲数 + kreg_step_motor_one_circle_pulse_denominator(10153), // 设置一圈脉冲数的分母 + kreg_step_motor_default_velocity(10154), // 默认速度 + kreg_step_motor_ihold(10158), // 步进电机电流配置 + kreg_step_motor_irun(10159), // 步进电机电流配置 + kreg_step_motor_iholddelay(10160), // 步进电机电流配置 + kreg_step_motor_iglobalscaler(10161), // 步进电机电流配置 + kreg_step_motor_run_to_zero_speed(10173), // 回零速度 + kreg_step_motor_look_zero_edge_speed(10175), // 找零边缘速度 + kreg_step_motor_max_d(10178), // 最大限制距离 + kreg_step_motor_min_d(10179), // 最小限制距离 + kreg_step_motor_in_debug_mode(10180), // 驱动器处于调试模式 + kreg_step_motor_vstart(10181), // a1起作用的速度 + kreg_step_motor_a1(10182), // + kreg_step_motor_amax(10183), // + kreg_step_motor_v1(10184), // + kreg_step_motor_dmax(10185), // + kreg_step_motor_d1(10186), // + kreg_step_motor_vstop(10187), // + kreg_step_motor_tzerowait(10188), // + kreg_step_motor_enc_resolution(10189), // 编码器分辨率 1000,1024,4000,4096,16384 + kreg_step_motor_enable_enc(10190), // + kreg_step_motor_dzero_pos(10191), // 驱动器处于调试模式 + kret_step_motor_pos_devi_tolerance(10192), // 位置偏差容忍度 + kret_step_motor_io_trigger_append_distance(10193), // 移动到io时,附加的距离 + + + /*********************************************************************************************************************** + * step_motor * + ***********************************************************************************************************************/ + + kreg_mini_servo_pos(10201), // 位置 + kreg_mini_servo_limit_velocity(10251), // 限制速度 + kreg_mini_servo_limit_torque(10252), // 限制扭矩 + kreg_mini_servo_protective_torque(10253), // 保护扭矩 + kreg_mini_servo_is_move(10254), // 是否在运动 + /*********************************************************************************************************************** + * ID_CARD_READER * + ***********************************************************************************************************************/ + + kreg_id_card_reader_raw_sector_size(10301), // + kreg_id_card_reader_raw_sector_num(10302), // + kreg_id_card_reader_is_online(10303,false), // + + /*********************************************************************************************************************** + * 板夹仓扫码 * + ***********************************************************************************************************************/ + + kreg_plate_code_scaner_laster_intensity(10401), // + kreg_plate_code_scaner_scan_gain(10402), // + kreg_plate_code_scaner_scan_velocity(10403), // + kreg_plate_code_scaner_scan_start_pos(10404), // + kreg_plate_code_scaner_final_stop_pos(10405), // + kreg_plate_code_scaner_code_judgment_threshold(10406), // + kreg_plate_code_scaner_item(10407), // + kreg_plate_code_scaner_lot(10408), // + kreg_plate_code_scaner_rawcode(10409), // + kreg_plate_code_scaner_code_legal(10410); // + + public final int index; + public final Boolean trace; + + RegIndex(int regIndex) { + this.index = regIndex; + this.trace = true; + } + + RegIndex(int regIndex, Boolean trace) { + this.index = regIndex; + this.trace = trace; + } + + public static RegIndex valueOf(int val) { + RegIndex[] values = RegIndex.values(); + for (RegIndex regindex : values) { + if (regindex.index == val) { + return regindex; + } + } + return null; + } + +} diff --git a/src/main/java/a8k/type/appret/AppRet.java b/src/main/java/a8k/type/appret/AppRet.java new file mode 100644 index 0000000..dde53bb --- /dev/null +++ b/src/main/java/a8k/type/appret/AppRet.java @@ -0,0 +1,152 @@ +package a8k.appbase.appret; + +import a8k.appbase.ecode.AppRetEcodeInfo; +import a8k.service.hardware.canbus.protocol.CmdId; +import a8k.service.hardware.canbus.protocol.MId; +import a8k.service.hardware.canbus.protocol.A8kEcode; +import a8k.appbase.HardwareException; + +public class AppRet { + + public AppRetType appRetType = AppRetType.NORMAL; + + //错误信息 + AppRetEcodeInfo ecode = null; + String traceInfo = null; + + //携带的对象 + String dataType; + T data; + + //显示给用户的内容 + String message = null; + long timestamp;//接口请求时间 + + + public AppRet() { + this.timestamp = System.currentTimeMillis(); + } + + public boolean isSuccess() { + return !AppRetType.FAILURE.equals(appRetType); + } + + public long getTimestamp() { + return timestamp; + } + + public AppRetEcodeInfo getEcode() { + return ecode; + } + + public T getData() { + return data; + } + + public String getTraceInfo() { + return traceInfo; + } + + public String getMessage() { + return message; + } + + public String getDataType() { + return dataType; + } + + + public static AppRet message(String message, T data) { + AppRet r = new AppRet<>(); + r.appRetType = AppRetType.MESSAGE; + r.message = message; + r.dataType = null == data ? null : data.getClass().getSimpleName(); + return r; + } + + public static AppRet reconfirm(String message) { + AppRet r = new AppRet<>(); + r.appRetType = AppRetType.RECONFIRM; + r.message = message; + return r; + } + + public static AppRet success(T data) { + AppRet r = new AppRet<>(); + r.data = data; + r.appRetType = AppRetType.NORMAL; + r.dataType = null == data ? null : data.getClass().getSimpleName(); + return r; + } + + + public static AppRet success() { + AppRet r = new AppRet<>(); + r.appRetType = AppRetType.NORMAL; + return r; + } + + + public static AppRet fail(A8kEcode errorCode, MId mid, CmdId cmd) { + AppRet r = new AppRet<>(); + r.appRetType = AppRetType.FAILURE; + r.ecode = new AppRetEcodeInfo(errorCode, mid, cmd); + r.message = r.ecode.toDisPlayString(); + return r; + } + + public static AppRet fail(A8kEcode errorCode, MId mid) { + AppRet r = new AppRet<>(); + r.appRetType = AppRetType.FAILURE; + + r.ecode = new AppRetEcodeInfo(errorCode, mid, null); + r.message = r.ecode.toDisPlayString(); + return r; + } + + public static AppRet fail(A8kEcode errorCode) { + AppRet r = new AppRet<>(); + r.appRetType = AppRetType.FAILURE; + + r.ecode = new AppRetEcodeInfo(errorCode, null, null); + r.message = r.ecode.toDisPlayString(); + return r; + } + + public static AppRet fail(AppRet ret) { + AppRet r = new AppRet<>(); + r.appRetType = AppRetType.FAILURE; + + r.ecode = new AppRetEcodeInfo(ret.getEcode().errorCode, ret.getEcode().mid, ret.getEcode().cmd); + r.data = null; + r.message = r.ecode.toDisPlayString(); + return r; + } + + public static AppRet fail(Exception e) { + StringBuilder traceSb = new StringBuilder(); + for (var trace : e.getStackTrace()) { + traceSb.append(trace.toString()).append("\n"); + } + String trace = traceSb.toString(); + AppRet r = new AppRet<>(); + r.appRetType = AppRetType.FAILURE; + + if (e instanceof HardwareException hexcep) { + r.ecode = new AppRetEcodeInfo(hexcep.getErrorCode(), hexcep.getModuleId(), hexcep.getCmdId()); + r.traceInfo = trace; + r.message = r.ecode.toDisPlayString(); + if (hexcep.getExtMessage() != null) { + r.message = r.message + "\n 额外信息:"+hexcep.getExtMessage(); + } + + } else { + r.ecode = new AppRetEcodeInfo(A8kEcode.CodeException, null, null); + r.traceInfo = trace; + r.message = e.getMessage(); + } + return r; + } + + +} diff --git a/src/main/java/a8k/type/appret/AppRetType.java b/src/main/java/a8k/type/appret/AppRetType.java new file mode 100644 index 0000000..8660a1c --- /dev/null +++ b/src/main/java/a8k/type/appret/AppRetType.java @@ -0,0 +1,8 @@ +package a8k.appbase.appret; + +public enum AppRetType { + NORMAL, + FAILURE, + RECONFIRM, + MESSAGE, +} diff --git a/src/main/java/a8k/type/cfg/BottleGroupsPosInfo.java b/src/main/java/a8k/type/cfg/BottleGroupsPosInfo.java new file mode 100644 index 0000000..e057705 --- /dev/null +++ b/src/main/java/a8k/type/cfg/BottleGroupsPosInfo.java @@ -0,0 +1,85 @@ +package a8k.appbase.cfg; + +import a8k.utils.HbotScanerPosComputer; + +public class BottleGroupsPosInfo { + + static public Integer cgetMAX_GROUP_COL() {return 3;} + + static public Integer cgetMAX_GROUP_ROW() {return 2;} + + static public Integer cgetMAX_GROUP() {return cgetMAX_GROUP_COL() * cgetMAX_GROUP_ROW();} + + public Pos2d topLelf;//左上角部分坐标 + + public Integer groupXSpacing; //x间隔 + public Integer groupYSpacing; //y间隔 + + public Pos2d scanCodeRelaPos; //扫码相对位置 + + public Integer posTestZ; + + public BottlesPosInfo smallBottleBufferPos; //小瓶缓冲液位置信息 + public BottlesPosInfo detectMaterialPos; //探测物质位置信息 + + + // BottlesPosInfo + + public BottleGroupsPosInfo() { + topLelf = new Pos2d(0, 0); + groupXSpacing = 0; + groupYSpacing = 0; + scanCodeRelaPos = new Pos2d(0, 0); + smallBottleBufferPos = new BottlesPosInfo(); + detectMaterialPos = new BottlesPosInfo(); + } + + public BottleGroupsPosInfo(Pos2d topLelf, + Integer groupXSpacing, + Integer groupYSpacing, + Pos2d scanCodeRelaPos, + Integer posTestZ, + BottlesPosInfo smallBottleBufferPos, + BottlesPosInfo detectMaterialPos) { + this.topLelf = topLelf; + this.groupXSpacing = groupXSpacing; + this.groupYSpacing = groupYSpacing; + this.scanCodeRelaPos = scanCodeRelaPos; + this.smallBottleBufferPos = smallBottleBufferPos; + this.detectMaterialPos = detectMaterialPos; + this.posTestZ = posTestZ; + } + + Pos2d cgetTopLelf(Integer group) { + + int row = group / cgetMAX_GROUP_COL(); + int col = group % cgetMAX_GROUP_COL(); + + return new Pos2d(topLelf.x + col * groupXSpacing, topLelf.y + row * groupYSpacing); + } + + public Pos2d cgetScanPos(Integer group) { + Pos2d topLelf = cgetTopLelf(group); + if (topLelf == null) { + return null; + } + return HbotScanerPosComputer.getScanPos(new Pos2d(topLelf.x + scanCodeRelaPos.x, topLelf.y + scanCodeRelaPos.y)); + } + + + public Pos2d cgetSmallBottleBufferPos(Integer group, Integer bottleIndex) { + Pos2d topLelf = cgetTopLelf(group); + return smallBottleBufferPos.cgetBotPos(topLelf, bottleIndex); + } + + public Pos2d cgetDetectMaterialPos(Integer group, Integer bottleIndex) { + Pos2d topLelf = cgetTopLelf(group); + return detectMaterialPos.cgetBotPos(topLelf, bottleIndex); + } + + Pos3d cgetSmallBottlePiercedPos(Integer group, Integer bottleIndex) { + Pos2d topLelf = cgetTopLelf(group); + Pos2d bottlePos = smallBottleBufferPos.cgetBotPos(topLelf, bottleIndex); + return new Pos3d(bottlePos.x, bottlePos.y, smallBottleBufferPos.piercedPosZ); + } +} diff --git a/src/main/java/a8k/type/cfg/BottlesPosInfo.java b/src/main/java/a8k/type/cfg/BottlesPosInfo.java new file mode 100644 index 0000000..e41e8af --- /dev/null +++ b/src/main/java/a8k/type/cfg/BottlesPosInfo.java @@ -0,0 +1,43 @@ +package a8k.appbase.cfg; + +public class BottlesPosInfo { + + static public Integer cgetMAX_COL() {return 5;} + + static public Integer cgetMAX_ROW() {return 5;} + + static public Integer cgetMAX() {return cgetMAX_COL() * cgetMAX_ROW();} + + public Pos2d relaTopLelf; + public Integer xSpacing; + public Integer ySpacing; + public Integer piercedPosZ; + + public BottlesPosInfo() { + relaTopLelf = new Pos2d(0, 0); + xSpacing = 0; + ySpacing = 0; + piercedPosZ = 0; + } + + + public BottlesPosInfo(Pos2d relaTopLelf, Integer xSpacing, Integer ySpacing, Integer piercedPosZ) { + this.relaTopLelf = relaTopLelf; + this.xSpacing = xSpacing; + this.ySpacing = ySpacing; + this.piercedPosZ = piercedPosZ; + } + + public Pos2d cgetBotPos(Pos2d groupPos, Integer index) { + Integer row = index / cgetMAX_COL(); + Integer col = index % cgetMAX_COL(); + + Integer x = relaTopLelf.x + col * xSpacing; + Integer y = relaTopLelf.y + row * ySpacing; + + return new Pos2d(x + groupPos.x, y + groupPos.y); + + } + + +} diff --git a/src/main/java/a8k/type/cfg/HbotLimitArea.java b/src/main/java/a8k/type/cfg/HbotLimitArea.java new file mode 100644 index 0000000..be10761 --- /dev/null +++ b/src/main/java/a8k/type/cfg/HbotLimitArea.java @@ -0,0 +1,36 @@ +package a8k.appbase.cfg; + +public class HbotLimitArea { + + + public Integer topLX; + public Integer topLY; + + public Integer bottoLX; + public Integer bottoLY; + + public HbotLimitArea(Integer topLX, Integer topLY, Integer bottoLX, Integer bottoLY) { + this.topLX = topLX; + this.topLY = topLY; + this.bottoLX = bottoLX; + this.bottoLY = bottoLY; + } + + public HbotLimitArea() { + this.topLX = 0; + this.topLY = 0; + this.bottoLX = 0; + this.bottoLY = 0; + } + + public Boolean checkIsInArea(Integer x, Integer y) { + if (x >= topLX && x <= bottoLX && y >= topLY && y <= bottoLY) { + return true; + } + return false; + } + + public Boolean checkIsInArea(Pos2d pos) { + return checkIsInArea(pos.x, pos.y); + } +} diff --git a/src/main/java/a8k/type/cfg/KeyValType.java b/src/main/java/a8k/type/cfg/KeyValType.java new file mode 100644 index 0000000..34fbdaa --- /dev/null +++ b/src/main/java/a8k/type/cfg/KeyValType.java @@ -0,0 +1,24 @@ +package a8k.appbase.cfg; + +public enum KeyValType { + Pos3d("Pos3d"),// + Pos2d("Pos2d"),// + Bool("Bool"),// + Int("Int"),// + String("String"),// + LargeBottleBufferPosInfo("LargeBottleBufferPosInfo"),// + Plates2dCodeScanPosInfo("Plates2dCodeScanPosInfo"),// + SmallBottleBufferPosInfo("SmallBottleBufferPosInfo"),// + TipPickUpPosInfo("TipPickUpPosInfo"),// + TubeSamplePos("TubeSamplePos"),// + PipetteCfg("PipetteCfg"),// + Float("Float"); + + + final public String name; + + KeyValType(String name) { + this.name = name; + } + +} diff --git a/src/main/java/a8k/type/cfg/LargeBottleBufferPos.java b/src/main/java/a8k/type/cfg/LargeBottleBufferPos.java new file mode 100644 index 0000000..40d7251 --- /dev/null +++ b/src/main/java/a8k/type/cfg/LargeBottleBufferPos.java @@ -0,0 +1,65 @@ +package a8k.appbase.cfg; + +import a8k.utils.HbotScanerPosComputer; + +/** + * 大瓶缓冲液位置信息 + */ +public class LargeBottleBufferPos { + public Pos2d topLelf = new Pos2d(0, 0); + + public Pos2d hole0 = new Pos2d(0, 0); + public Integer holeXSpacing = 0; //x间隔 + public Integer holeYSpacing = 0; //y间隔 + + public Pos2d scan0 = new Pos2d(0, 0); + public Integer scanPosXSpacing = 0; //扫码位置x间隔 + public Integer scanPosYSpacing = 0; //扫码位置y间隔 + + + public Integer cgetCOL() { + return 3; + } + + public Integer cgetROW() { + return 2; + } + + public Integer cgetBottleCount() { + return cgetCOL() * cgetROW(); + } + + public LargeBottleBufferPos() { + } + + public LargeBottleBufferPos(Pos2d topLelf, Pos2d hole0, Integer holeXSpacing, Integer holeYSpacing, Pos2d scan0, Integer scanPosXSpacing, Integer scanPosYSpacing) { + this.topLelf = topLelf; + this.holeXSpacing = holeXSpacing; + this.holeYSpacing = holeYSpacing; + this.scanPosXSpacing = scanPosXSpacing; + this.scanPosYSpacing = scanPosYSpacing; + this.hole0 = hole0; + this.scan0 = scan0; + } + + public Pos2d cgetBottlePos(Integer bottleIndex) { + Integer row = bottleIndex / cgetCOL(); + Integer col = bottleIndex % cgetCOL(); + + Integer x = topLelf.x + hole0.x + col * holeXSpacing; + Integer y = topLelf.y + hole0.y + row * holeYSpacing; + + return new Pos2d(x, y); + } + + public Pos2d cgetScanPos(Integer bottleIndex) { + Integer row = bottleIndex / cgetCOL(); + Integer col = bottleIndex % cgetCOL(); + + Integer x = topLelf.x + scan0.x + col * scanPosXSpacing; + Integer y = topLelf.y + scan0.y + row * scanPosYSpacing; + + return HbotScanerPosComputer.getScanPos(new Pos2d(x, y)); + + } +} diff --git a/src/main/java/a8k/type/cfg/PipetteCfg.java b/src/main/java/a8k/type/cfg/PipetteCfg.java new file mode 100644 index 0000000..fc4c605 --- /dev/null +++ b/src/main/java/a8k/type/cfg/PipetteCfg.java @@ -0,0 +1,10 @@ +package a8k.appbase.cfg; + +public class PipetteCfg { + public Integer LLFCThresh;//液面跟随电容阈值 + public Integer LLFPThresh;//液面跟随压力阈值 + + public Integer operatVerifFeatureTime;//操作验证特征时间 + public Integer operatVerifPThresh;//压力阈值 + public Integer tolerance; //吸空检测容差值 +} diff --git a/src/main/java/a8k/type/cfg/Plates2dCodeScanPos.java b/src/main/java/a8k/type/cfg/Plates2dCodeScanPos.java new file mode 100644 index 0000000..0ee7bee --- /dev/null +++ b/src/main/java/a8k/type/cfg/Plates2dCodeScanPos.java @@ -0,0 +1,23 @@ +package a8k.appbase.cfg; + +/** + * 板夹仓扫码信息 + */ +public class Plates2dCodeScanPos { + public Pos2d ch0ScanPos; //通道1扫码位置 + public Integer scanYSpacing; //扫码间隔 + + public Plates2dCodeScanPos() { + ch0ScanPos = new Pos2d(0, 0); + scanYSpacing = 0; + } + + public Plates2dCodeScanPos(Pos2d ch0ScanPos, Integer scanYSpacing) { + this.ch0ScanPos = ch0ScanPos; + this.scanYSpacing = scanYSpacing; + } + + public Pos2d cgetScanPos(int ch) { + return new Pos2d(ch0ScanPos.x, ch0ScanPos.y + ch * scanYSpacing); + } +} diff --git a/src/main/java/a8k/type/cfg/Pos2d.java b/src/main/java/a8k/type/cfg/Pos2d.java new file mode 100644 index 0000000..99f1625 --- /dev/null +++ b/src/main/java/a8k/type/cfg/Pos2d.java @@ -0,0 +1,22 @@ +package a8k.appbase.cfg; + +public class Pos2d { + + public Integer x; + public Integer y; + + public Pos2d(Integer x, Integer y) { + this.x = x; + this.y = y; + } + + public Pos2d() { + this.x = 0; + this.y = 0; + } + + public String toString() { + return String.format("(%d, %d)", x, y); + } + +} diff --git a/src/main/java/a8k/type/cfg/Pos3d.java b/src/main/java/a8k/type/cfg/Pos3d.java new file mode 100644 index 0000000..f419848 --- /dev/null +++ b/src/main/java/a8k/type/cfg/Pos3d.java @@ -0,0 +1,24 @@ +package a8k.appbase.cfg; + +public class Pos3d { + public Integer x = 0; + public Integer y = 0; + public Integer z = 0; + + public Pos3d() { + } + + public Pos3d(Integer x, Integer y, Integer z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Pos2d getXYPos() { + return new Pos2d(x, y); + } + + public String toString() { + return String.format("(%d, %d, %d)", x, y, z); + } +} diff --git a/src/main/java/a8k/type/cfg/SampleZPosInfo.java b/src/main/java/a8k/type/cfg/SampleZPosInfo.java new file mode 100644 index 0000000..4062eee --- /dev/null +++ b/src/main/java/a8k/type/cfg/SampleZPosInfo.java @@ -0,0 +1,17 @@ +package a8k.appbase.cfg; + +public class SampleZPosInfo { + public Integer sampleZPos;//采样探测起始位 + public Integer sampleZDepth;//采样深度 + + /* + * 如果样本容器直径不随液面高度变化,那么LLFVelK=0,LLFVel=常数 + * 液面跟随速度=LLFVelK*液面相对起始位置高度+LLFVel + * + * 如果样本容器直径随液面高度变化,那么LLFVelK=常数,LLFVel=常数 + * 液面跟随速度=LLFVelK*液面相对起始位置高度+LLFVel + */ + + public Integer LLFVelK;//液面跟随速度 + public Integer LLFVel;//液面跟随速度 +} diff --git a/src/main/java/a8k/type/cfg/TipPickUpPosInfo.java b/src/main/java/a8k/type/cfg/TipPickUpPosInfo.java new file mode 100644 index 0000000..ef08e28 --- /dev/null +++ b/src/main/java/a8k/type/cfg/TipPickUpPosInfo.java @@ -0,0 +1,78 @@ +package a8k.appbase.cfg; + +public class TipPickUpPosInfo { + + public Pos2d g0tl; + public Pos2d g1tl; + public Pos2d g2tl; + + public Double xSpacing; //x间隔 + public Double ySpacing; //y间隔 + + public Integer g0PickUpZPos; //拾取高度 + public Integer g1PickUpZPos; //拾取高度 + public Integer g2PickUpZPos; //拾取高度 + + static public Integer cgetTipNum() {return 12 * 10;} + + static public Integer cgetCOL_MAX() {return 12;} + + static public Integer cgetROW_MAX() {return 10;} + + public TipPickUpPosInfo() { + g0tl = new Pos2d(0, 0); + g1tl = new Pos2d(0, 0); + g2tl = new Pos2d(0, 0); + xSpacing = 0.0; + ySpacing = 0.0; + g0PickUpZPos = 0; + g1PickUpZPos = 0; + g2PickUpZPos = 0; + } + + public TipPickUpPosInfo(Pos2d g0tl, Pos2d g1tl, Pos2d g2tl, Double xSpacing, Double ySpacing, Integer g0PickUpZPos, Integer g1PickUpZPos, Integer g2PickUpZPos) { + this.g0tl = g0tl; + this.g1tl = g1tl; + this.g2tl = g2tl; + this.xSpacing = xSpacing; + this.ySpacing = ySpacing; + this.g0PickUpZPos = g0PickUpZPos; + this.g1PickUpZPos = g1PickUpZPos; + this.g2PickUpZPos = g2PickUpZPos; + } + + Pos2d getTopLeft(Integer group) { + if (group == 0) { + return g0tl; + } else if (group == 1) { + return g1tl; + } else if (group == 2) { + return g2tl; + } else { + return new Pos2d(0, 0); + } + } + + public Pos2d getTipPos(Integer group, Integer index) { + int row; //行 + int col; //列 + + row = index / cgetCOL_MAX(); + col = index % cgetCOL_MAX(); + + Pos2d topleft = getTopLeft(group); + return new Pos2d((int) (topleft.x + col * xSpacing), (int) (topleft.y + row * ySpacing)); + } + + public Integer getPickUpZPos(Integer group) { + if (group == 0) { + return g0PickUpZPos; + } else if (group == 1) { + return g1PickUpZPos; + } else if (group == 2) { + return g2PickUpZPos; + } else { + return 0; + } + } +} diff --git a/src/main/java/a8k/type/cfg/TubeSamplePos.java b/src/main/java/a8k/type/cfg/TubeSamplePos.java new file mode 100644 index 0000000..8f004fb --- /dev/null +++ b/src/main/java/a8k/type/cfg/TubeSamplePos.java @@ -0,0 +1,15 @@ +package a8k.appbase.cfg; + +public class TubeSamplePos { + + Pos2d sampleXYPos0; //不需要脱帽盖帽摇匀的取样位置 + Pos2d sampleXYPos1; //需要脱帽盖帽摇匀的取样位置 + + SampleZPosInfo HighBlood; //sampleXYPos1 + SampleZPosInfo ShortBlood;//sampleXYPos1 + + SampleZPosInfo Mini; //sampleXYPos0 + SampleZPosInfo MiniBlood; //sampleXYPos0 + SampleZPosInfo BulletTube1P5; //sampleXYPos0 + SampleZPosInfo BulletTube0P5; //sampleXYPos0 +} diff --git a/src/main/java/a8k/type/ecode/AppRetEcodeInfo.java b/src/main/java/a8k/type/ecode/AppRetEcodeInfo.java new file mode 100644 index 0000000..50d8531 --- /dev/null +++ b/src/main/java/a8k/type/ecode/AppRetEcodeInfo.java @@ -0,0 +1,89 @@ +package a8k.appbase.ecode; + +import a8k.service.hardware.canbus.protocol.A8kEcode; +import a8k.service.hardware.canbus.protocol.CmdId; +import a8k.service.hardware.canbus.protocol.MId; + +public class AppRetEcodeInfo { + public A8kEcode errorCode; + public MId mid; + public CmdId cmd; + + public AppRetEcodeInfo(A8kEcode errorCode, MId mid, CmdId cmd) { + this.errorCode = errorCode; + this.mid = mid; + this.cmd = cmd; + } + + //code + + public Integer getCode() { + return errorCode.index; + } + + public String getCodeChName() { + return errorCode.getChname(); + } + + public String getCodeName() { + return errorCode.toString(); + } + + //mid code + + public Integer getMidCode() { + if (mid == null) { + return null; + } + return mid.toInt(); + } + + public String getMidChName() { + if (mid == null) { + return null; + } + return mid.chname; + } + + public String getMidCodeName() { + if (mid == null) { + return null; + } + return mid.toString(); + } + + //cmd code + + public Integer getCmdCode() { + if (cmd == null) { + return null; + } + return cmd.toInt(); + } + + public String getCmdChName() { + if (cmd == null) { + return null; + } + return cmd.chName; + } + + public String getCmdCodeName() { + if (cmd == null) { + return null; + } + return cmd.toString(); + } + + public String toDisPlayString() { + String info; + info = String.format("错误: %s", errorCode.chname); + if (mid != null) { + info += String.format("\n 相关模块: %s", mid.chname); + } + if (cmd != null) { + info += String.format("\n 相关指令: %s", cmd.chName); + } + return info; + } +} diff --git a/src/main/java/a8k/type/sampleinfo/SampleInfo.java b/src/main/java/a8k/type/sampleinfo/SampleInfo.java new file mode 100644 index 0000000..47c44b3 --- /dev/null +++ b/src/main/java/a8k/type/sampleinfo/SampleInfo.java @@ -0,0 +1,12 @@ +package a8k.appbase.sampleinfo; + +import a8k.appbase.type.BloodType; + +import java.util.List; + +public class SampleInfo { + public String udpid; //用户输入的样本ID,不做逻辑,只做展示 + public String barcodeid; //用于请求用户信息的条码ID + public List projectCodes = null; //项目代码 + public BloodType bloodType = BloodType.WHOLE_BLOOD; //血型 +} diff --git a/src/main/java/a8k/type/type/A8kTubeType.java b/src/main/java/a8k/type/type/A8kTubeType.java new file mode 100644 index 0000000..603249a --- /dev/null +++ b/src/main/java/a8k/type/type/A8kTubeType.java @@ -0,0 +1,17 @@ +package a8k.appbase.type; + + +public enum A8kTubeType { + + BloodTube("0000"), //全血试管 + ShortBloodTube("0000"), //全血试管 + MiniTube("1111"), //迷你试管 + MiniBlood("2222"), //阳普管 + BulletTube1P5("5555"),//子弹头试管1.5mL + BulletTube0P5("4444"); //子弹头试管0.5mL + + final public String scanCode; + A8kTubeType(String scanCode) { + this.scanCode = scanCode; + } +} diff --git a/src/main/java/a8k/type/type/BloodType.java b/src/main/java/a8k/type/type/BloodType.java new file mode 100644 index 0000000..b2e4846 --- /dev/null +++ b/src/main/java/a8k/type/type/BloodType.java @@ -0,0 +1,6 @@ +package a8k.appbase.type; + +public enum BloodType { + WHOLE_BLOOD, + SERUM; +} diff --git a/src/main/java/a8k/utils/opt_algo/A8kOptAlgo.java b/src/main/java/a8k/utils/opt_algo/A8kOptAlgo.java new file mode 100644 index 0000000..a1bf674 --- /dev/null +++ b/src/main/java/a8k/utils/opt_algo/A8kOptAlgo.java @@ -0,0 +1,81 @@ +package a8k.algo.opt_algo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class A8kOptAlgo { + static Logger logger = LoggerFactory.getLogger(A8kOptAlgo.class); + + static private List createDoubleList(int size) { + List list = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + list.add(0.0); + } + return list; + } + + static private List integerToDouble(List input) { + List output = new ArrayList<>(input.size()); + for (Integer i : input) { + output.add(i.doubleValue()); + } + return output; + } + + static private List doubleToInteger(List input) { + List output = new ArrayList<>(input.size()); + for (Double i : input) { + output.add(i.intValue()); + } + return output; + } + + static public List preProcessOptData(List input) { + List inputRaw = integerToDouble(input); + List upSamplingRaw = superSampling(inputRaw, 5); + List subSamplingRaw = subSampling(upSamplingRaw, 24); + return doubleToInteger(subSamplingRaw); + } + + + static public List superSampling(List input, Integer factor) { + int outputLength = input.size() * factor; + List upSamplingRaw = createDoubleList(outputLength); + + for (int si = 0, di = 0; si < input.size() - 1; di++) { + Double a = upSamplingRaw.set(di * factor, input.get(si)); + Double b = upSamplingRaw.set((di + 1) * factor, input.get(++si)); + + Double slope = (b - a) / factor; + + for (int i = 0; i < factor - 1; i++) { + int baseIndex = (di * factor) + i; + upSamplingRaw.set(baseIndex + 1, upSamplingRaw.get(baseIndex) + slope); + } + } + return upSamplingRaw; + } + + static public List subSampling(List inputRaw, Integer nSubSampleRate) { + int nSum = 0; + double fAvg = 0.0; + int subIndex = 0; + int nOutputLength = inputRaw.size() / nSubSampleRate; + + List subSampledRaw = createDoubleList(nOutputLength); + + for (int index = 0; index < inputRaw.size(); index++) { + if (index % nSubSampleRate == 0 && index > 0) { + fAvg = (double) nSum / nSubSampleRate; + subSampledRaw.set(subIndex++, fAvg); + nSum = 0; + } + nSum += inputRaw.get(index); + } + subSampledRaw.set(nOutputLength - 1, subSampledRaw.get(nOutputLength - 2)); + return subSampledRaw; + } +}