From b63c15dbae6411ffe77f73d4a3de17177da2b8a5 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 6 Oct 2024 17:25:56 +0800 Subject: [PATCH] recode some code --- .../service/appdata/AppFrontEndEventRouter.java | 8 +-- .../a8k/service/appdata/AppProjInfoMgrService.java | 11 ++- .../java/a8k/service/appdata/AppSettingsMgr.java | 29 ++++---- .../a8k/service/appdata/AppUserMgrService.java | 35 ++++----- .../service/appdevicectrl/MainFlowCtrlService.java | 14 ++-- .../calibration/PositionCalibration.java | 24 +++---- .../commonctrl/HardwareCommonCtrl.java | 36 ++++------ .../ctrl/ReactionPlatesTransmitCtrl.java | 26 +++---- .../devicedriver/ctrl/SamplesPreProcesCtrl.java | 4 +- .../devicedriver/testscript/TestScript.java | 4 +- src/main/java/a8k/type/appret/AppRet.java | 84 +++------------------- src/main/java/a8k/type/ecode/AppEcode.java | 31 ++++++++ src/main/java/a8k/type/ecode/ErrorContext.java | 31 -------- 13 files changed, 132 insertions(+), 205 deletions(-) create mode 100644 src/main/java/a8k/type/ecode/AppEcode.java delete mode 100644 src/main/java/a8k/type/ecode/ErrorContext.java diff --git a/src/main/java/a8k/service/appdata/AppFrontEndEventRouter.java b/src/main/java/a8k/service/appdata/AppFrontEndEventRouter.java index da2b096..c0d54f6 100644 --- a/src/main/java/a8k/service/appdata/AppFrontEndEventRouter.java +++ b/src/main/java/a8k/service/appdata/AppFrontEndEventRouter.java @@ -77,15 +77,15 @@ public class AppFrontEndEventRouter implements AppEventListener { // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @ExtApiFn(name = "取出第一个事件") - public AppRet pollAppEvent() { + public AppEvent pollAppEvent() { AppEvent event = pollAppEventFromQueue(); - return AppRet.success(event); + return (event); } @ExtApiFn(name = "读取所有事件(不清空)") - public AppRet> readAllAppEvents() { + public List readAllAppEvents() { List events = new java.util.ArrayList<>(appEventQueue); - return AppRet.success(events); + return (events); } diff --git a/src/main/java/a8k/service/appdata/AppProjInfoMgrService.java b/src/main/java/a8k/service/appdata/AppProjInfoMgrService.java index 26f63f1..9f5da51 100644 --- a/src/main/java/a8k/service/appdata/AppProjInfoMgrService.java +++ b/src/main/java/a8k/service/appdata/AppProjInfoMgrService.java @@ -113,11 +113,11 @@ public class AppProjInfoMgrService implements AppEventListener { // ID卡管理 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @ExtApiFn(name = "读取当前挂载的ID卡信息", order = ORDER.readIDCardInfo) - public AppRet readMountedIDCardInfo() { + public A8kIdCardInfo readMountedIDCardInfo() throws AppException { if (mountedIdCardInfo == null) { - return AppRet.fail(A8kEcode.A8kIdCardNotMounted.index); + throw new AppException(A8kEcode.A8kIdCardNotMounted.index); } - return AppRet.success(mountedIdCardInfo); + return mountedIdCardInfo; } @ExtApiFn(name = "保存挂载ID卡信息", order = ORDER.saveIDCardInfo) @@ -126,10 +126,9 @@ public class AppProjInfoMgrService implements AppEventListener { } @ExtApiFn(name = "获取ID卡信息列表", order = ORDER.getProjectInfoList) - public AppRet> getProjectInfoList() { - return AppRet.success(a8kProjIdCardDBService.getAllIdCards()); + public List getProjectInfoList() { + return a8kProjIdCardDBService.getAllIdCards(); } - //TODO: 删除 @ExtApiFn(name = "获取预设项目信息", group = "预设项目信息") diff --git a/src/main/java/a8k/service/appdata/AppSettingsMgr.java b/src/main/java/a8k/service/appdata/AppSettingsMgr.java index 937297c..0a7aea6 100644 --- a/src/main/java/a8k/service/appdata/AppSettingsMgr.java +++ b/src/main/java/a8k/service/appdata/AppSettingsMgr.java @@ -12,6 +12,7 @@ import a8k.controler.extapi.pagecontrol.ExtApiTabConfig; import a8k.dbservice.type.appsetting.AppSettingTab; import a8k.dbservice.type.appsetting.AppSettingName; import a8k.hardware.type.a8kcanprotocol.A8kEcode; +import a8k.type.exception.AppException; import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; import org.slf4j.Logger; @@ -75,41 +76,41 @@ public class AppSettingsMgr { // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @ExtApiFn(name = "getAppSettings", order = ORDER.getAppSettings) - public AppRet> getAppSettings() { - return AppRet.success(appSettingDBService.getAllSettings()); + public List getAppSettings() { + return (appSettingDBService.getAllSettings()); } @ExtApiFn(name = "getAppSettingByName", order = ORDER.getAppSettingByName) - public AppRet getAppSettingByName(AppSettingName name) { - return AppRet.success(appSettingDBService.getSettingByName(name)); + public AppSetting getAppSettingByName(AppSettingName name) { + return (appSettingDBService.getSettingByName(name)); } @ExtApiFn(name = "getAppSettingByTab", order = ORDER.getAppSettingByTab) - public AppRet> getAppSettingByTab(AppSettingTab tab) { - return AppRet.success(appSettingDBService.getSettingsByTab(tab)); + public List getAppSettingByTab(AppSettingTab tab) { + return (appSettingDBService.getSettingsByTab(tab)); } @ExtApiFn(name = "getTabs", order = ORDER.getTabs) - public AppRet getTabs() { - return AppRet.success(AppSettingTab.values()); + public AppSettingTab[] getTabs() { + return (AppSettingTab.values()); } @ExtApiFn(name = "getAppSettingTypesRange", order = ORDER.getAppSettingTypesRange) - public AppRet getAppSettingTypesRange() { - return AppRet.success(AppSettingType.values()); + public AppSettingType[] getAppSettingTypesRange() { + return (AppSettingType.values()); } @ExtApiFn(name = "getAppSettingNamesRange", order = ORDER.getAppSettingNamesRange) - public AppRet getAppSettingNamesRange() { - return AppRet.success(AppSettingName.values()); + public AppSettingName[] getAppSettingNamesRange() { + return (AppSettingName.values()); } @ExtApiFn(name = "setOptionVal", order = ORDER.setOptionVal) - public AppRet setOptionVal(AppSettingName optionName, String val) { + public AppSetting setOptionVal(AppSettingName optionName, String val) throws AppException { logger.info("setOptionVal {}={}", optionName, val); if (!isOptionLegal(optionName, val)) { - return AppRet.fail(A8kEcode.FrontendParamTypeError.index); + throw new AppException(A8kEcode.FrontendParamTypeError.index); } appSettingDBService.updateSetting(optionName, val); return getAppSettingByName(optionName); diff --git a/src/main/java/a8k/service/appdata/AppUserMgrService.java b/src/main/java/a8k/service/appdata/AppUserMgrService.java index 911d162..0ed6ad1 100644 --- a/src/main/java/a8k/service/appdata/AppUserMgrService.java +++ b/src/main/java/a8k/service/appdata/AppUserMgrService.java @@ -8,6 +8,7 @@ import a8k.dbservice.type.UsrRole; import a8k.type.appret.AppRet; import a8k.controler.extapi.utils.ExtApiFn; import a8k.hardware.type.a8kcanprotocol.A8kEcode; +import a8k.type.exception.AppException; import jakarta.annotation.Resource; import org.slf4j.Logger; import org.springframework.stereotype.Component; @@ -44,16 +45,16 @@ public class AppUserMgrService { // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @ExtApiFn(name = "用户登录", order = ORDER.login) - public AppRet login(String account, String password) { + public AppUser login(String account, String password) throws AppException { var usr = appUsrDBService.getUsrByAccount(account); if (usr == null) - return AppRet.fail(A8kEcode.UsrNotExitError.index); + throw new AppException(A8kEcode.UsrNotExitError.index); if (!usr.password.equals(password)) { - return AppRet.fail(A8kEcode.UsrPasswdError.index); + throw new AppException(A8kEcode.UsrPasswdError.index); } loginUsr = usr; - return AppRet.success(usr); + return (usr); } @ExtApiFn(name = "用户登出", order = ORDER.unlogin) @@ -62,21 +63,21 @@ public class AppUserMgrService { } @ExtApiFn(name = "获取当前用户", order = ORDER.getLoginUsr) - public AppRet getLoginUsr() { - return AppRet.success(loginUsr); + public AppUser getLoginUsr() { + return (loginUsr); } @ExtApiFn(name = "获取用户列表", order = ORDER.getUsrlist) - public AppRet> getUsrlist() { - return AppRet.success(appUsrDBService.getAllUsr()); + public List getUsrlist() { + return (appUsrDBService.getAllUsr()); } @ExtApiFn(name = "用户添加", order = ORDER.addUser) - public AppRet> addUser(String account, String password, UsrRole type) { + public List addUser(String account, String password, UsrRole type) throws AppException { var user = appUsrDBService.getUsrByAccount(account); if (user != null) { - return AppRet.fail(A8kEcode.UsrAlreadyExistError.index); + throw new AppException(A8kEcode.UsrAlreadyExistError.index); } user = new AppUser(account, password, type); appUsrDBService.addUser(user); @@ -84,16 +85,16 @@ public class AppUserMgrService { } @ExtApiFn(name = "删除用户", order = ORDER.delUser) - public AppRet> delUser(String account) { + public List delUser(String account) { appUsrDBService.deleteUserByAccount(account); return getUsrlist(); } @ExtApiFn(name = "修改用户密码", order = ORDER.modifyUsrPwd) - public AppRet> modifyUsrPwd(String account, String password) { + public List modifyUsrPwd(String account, String password) throws AppException { var user = appUsrDBService.getUsrByAccount(account); if (user == null) { - return AppRet.fail(A8kEcode.UsrNotExitError.index); + throw new AppException(A8kEcode.UsrNotExitError.index); } user.password = password; appUsrDBService.updateUser(user); @@ -101,10 +102,10 @@ public class AppUserMgrService { } @ExtApiFn(name = "修改用户权限", order = ORDER.modifyUsrRole) - public AppRet> modifyUsrRole(String account, UsrRole usrRole) { + public List modifyUsrRole(String account, UsrRole usrRole) throws AppException { var user = appUsrDBService.getUsrByAccount(account); if (user == null) { - return AppRet.fail(A8kEcode.UsrNotExitError.index); + throw new AppException(A8kEcode.UsrNotExitError.index); } user.usrRole = usrRole; appUsrDBService.updateUser(user); @@ -112,10 +113,10 @@ public class AppUserMgrService { } @ExtApiFn(name = "修改用户名称", order = ORDER.modifyUsrAccount) - public AppRet> modifyUsrAccount(String account, String newaccount) { + public List modifyUsrAccount(String account, String newaccount) throws AppException { var user = appUsrDBService.getUsrByAccount(account); if (user == null) { - return AppRet.fail(A8kEcode.UsrNotExitError.index); + throw new AppException(A8kEcode.UsrNotExitError.index); } user.account = newaccount; appUsrDBService.updateUser(user); diff --git a/src/main/java/a8k/service/appdevicectrl/MainFlowCtrlService.java b/src/main/java/a8k/service/appdevicectrl/MainFlowCtrlService.java index e6fb62f..586a490 100644 --- a/src/main/java/a8k/service/appdevicectrl/MainFlowCtrlService.java +++ b/src/main/java/a8k/service/appdevicectrl/MainFlowCtrlService.java @@ -46,13 +46,13 @@ public class MainFlowCtrlService { logger.info("className {}",DO_STOP.class.getName()); - for (A8kActionStepType actionType : A8kActionStepType.values()) { - if (actionType.equals(A8kActionStepType.DO_CLEAR_ERROR)) { - continue; - } - A8kStepAction action = SpringBootBeanUtil.getBean(actionType.name(), A8kStepAction.class); - scheduler.regFn(action); - } +// for (A8kActionStepType actionType : A8kActionStepType.values()) { +// if (actionType.equals(A8kActionStepType.DO_CLEAR_ERROR)) { +// continue; +// } +// A8kStepAction action = SpringBootBeanUtil.getBean(actionType.name(), A8kStepAction.class); +// scheduler.regFn(action); +// } //启动调度 scheduler.startScheduler(); diff --git a/src/main/java/a8k/service/devicedriver/calibration/PositionCalibration.java b/src/main/java/a8k/service/devicedriver/calibration/PositionCalibration.java index 7a88c02..37151ab 100644 --- a/src/main/java/a8k/service/devicedriver/calibration/PositionCalibration.java +++ b/src/main/java/a8k/service/devicedriver/calibration/PositionCalibration.java @@ -59,34 +59,34 @@ public class PositionCalibration { @ExtApiFn(name = "试管夹平移电机-读取位置", group = "通过归零测量位置") - public AppRet readXPosByMoveZero() throws AppException { - return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.FeedingModXM, timep.getActionOvertime())); + public Integer readXPosByMoveZero() throws AppException { + return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.FeedingModXM, timep.getActionOvertime())); } @ExtApiFn(name = "通过归零读取<板夹仓>位置", group = "通过归零测量位置") - public AppRet readPlatesBoxYMPosByMoveToZero() throws AppException { - return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.PlatesBoxYM, timep.getActionOvertime())); + public Integer readPlatesBoxYMPosByMoveToZero() throws AppException { + return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.PlatesBoxYM, timep.getActionOvertime())); } @ExtApiFn(name = "通过归零读取<推杆>位置", group = "通过归零测量位置") - public AppRet readPlatesBoxPusherMPosByMoveToZero() throws AppException { - return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.PlatesBoxPusherM, timep.getActionOvertime())); + public Integer readPlatesBoxPusherMPosByMoveToZero() throws AppException { + return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.PlatesBoxPusherM, timep.getActionOvertime())); } @ExtApiFn(name = "通过归零读取<拉杆>位置", group = "通过归零测量位置") - public AppRet readOptModPullMPosByMoveToZero() throws AppException { - return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.OptModPullM, timep.getActionOvertime())); + public Integer readOptModPullMPosByMoveToZero() throws AppException { + return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.OptModPullM, timep.getActionOvertime())); } @ExtApiFn(name = "通过归零读取<光学模组扫描器>位置", group = "通过归零测量位置") - public AppRet readOptModScannerMPosByMoveToZero() throws AppException { - return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.OptModScannerM, timep.getActionOvertime())); + public Integer readOptModScannerMPosByMoveToZero() throws AppException { + return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.OptModScannerM, timep.getActionOvertime())); } @ExtApiFn(name = "通过归零读取<摇匀模组Z轴>位置", group = "通过归零测量位置") - public AppRet readShakeModGripperZMPosByMoveToZero() throws AppException { - return AppRet.success(canBus.stepMotorReadPosByMoveToZeroBlock(MId.ShakeModGripperZM, timep.getActionOvertime())); + public Integer readShakeModGripperZMPosByMoveToZero() throws AppException { + return (canBus.stepMotorReadPosByMoveToZeroBlock(MId.ShakeModGripperZM, timep.getActionOvertime())); } diff --git a/src/main/java/a8k/service/devicedriver/commonctrl/HardwareCommonCtrl.java b/src/main/java/a8k/service/devicedriver/commonctrl/HardwareCommonCtrl.java index ef85b5f..1b36519 100644 --- a/src/main/java/a8k/service/devicedriver/commonctrl/HardwareCommonCtrl.java +++ b/src/main/java/a8k/service/devicedriver/commonctrl/HardwareCommonCtrl.java @@ -44,43 +44,41 @@ public class HardwareCommonCtrl { // CHECK // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - private AppRet checkDeviceStateBeforeRunToZero() throws AppException { + private void checkDeviceStateBeforeRunToZero() throws AppException { logger.info("checkDeviceStateBeforeRunToZero"); //试管平移通道是否有障碍 if (canBus.getIOState(IOId.THChInterPPS) || canBus.getIOState(IOId.THChOuterPPS)) { logger.warn("THChInterPPS or THChOuterPPS is trigger"); - return AppRet.fail(A8kEcode.TubeXChannelIsNotEmpty.index); + throw new AppException(A8kEcode.TubeXChannelIsNotEmpty.index); } //板夹仓盖子是否盖上 if (!canBus.getIOState(IOId.PlateBoxCoverClosurePPS)) { - return AppRet.fail(A8kEcode.PlateBoxNotCover.index); + throw new AppException(A8kEcode.PlateBoxNotCover.index); } //板夹仓卡板检测 if (canBus.getIOState(IOId.PlateBoxPlateStuckPPS)) { - return AppRet.fail(A8kEcode.PlateStuckDetectorSensorTrigger.index); + throw new AppException(A8kEcode.PlateStuckDetectorSensorTrigger.index); } //检查钩板电机是否处于终点位置 if (!canBus.getIOState(IOId.PullerMZeroPPS)) { - return AppRet.fail(A8kEcode.PullerMInitPosError.index); + throw new AppException(A8kEcode.PullerMInitPosError.index); } //检查板夹仓光电是否处于起点位置 if (!canBus.getIOState(IOId.PusherMZeroPPS)) { - return AppRet.fail(A8kEcode.PusherMInitPosError.index); + throw new AppException(A8kEcode.PusherMInitPosError.index); } //板夹仓光电 if (canBus.getIOState(IOId.RecycleBinOverflowPPS)) { - return AppRet.fail(A8kEcode.RecycleBinOverflow.index); + throw new AppException(A8kEcode.RecycleBinOverflow.index); } - - return AppRet.success(); } - private AppRet moveMotorToZero() throws AppException { + private void moveMotorToZero() throws AppException { //进出料初始化 canBus.stepMotorEasyMoveToZeroBlock(MId.FeedingModXM, timep.getRuntoZeroActionOvertime()); @@ -110,16 +108,13 @@ public class HardwareCommonCtrl { // TODO canBus.stepMotorEasyMoveToZeroBlock(MId.PipetteModZM, timep.getRuntoZeroActionOvertime()); //转盘归零 canBus.stepMotorEasyMoveToZeroBlock(MId.IncubatorRotateCtrlM, timep.getRuntoZeroActionOvertime()); - - - return AppRet.success(); } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Expose API // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @ExtApiFn(name = "设备初始化", order = ORDER.initializeDevice) - public AppRet initializeDevice() throws AppException { + public void initializeDevice() throws AppException { logger.info("Initializing device ..."); boolean initSuc = false; workState = true; @@ -129,16 +124,12 @@ public class HardwareCommonCtrl { canBus.setIOState(IOId.RecycleBinOverflowPPSPowerCtrl, true); //检查设备状态 - ecode = checkDeviceStateBeforeRunToZero(); - if (!ecode.isSuccess()) { - return AppRet.fail(ecode); - } + checkDeviceStateBeforeRunToZero(); + // 复位设备 logger.info("moveMotorToZero"); - ecode = moveMotorToZero(); - if (!ecode.isSuccess()) { - return AppRet.fail(ecode); - } + moveMotorToZero(); + initSuc = true; logger.info("Device initialization completed"); @@ -154,7 +145,6 @@ public class HardwareCommonCtrl { } } } - return AppRet.success("初始化完成"); } diff --git a/src/main/java/a8k/service/devicedriver/ctrl/ReactionPlatesTransmitCtrl.java b/src/main/java/a8k/service/devicedriver/ctrl/ReactionPlatesTransmitCtrl.java index 8776503..ff9c263 100644 --- a/src/main/java/a8k/service/devicedriver/ctrl/ReactionPlatesTransmitCtrl.java +++ b/src/main/java/a8k/service/devicedriver/ctrl/ReactionPlatesTransmitCtrl.java @@ -128,13 +128,13 @@ public class ReactionPlatesTransmitCtrl { @ExtApiFn(name = "推板", group = "单步") - public AppRet pushPlate(ConsumableGroup PBCh, IncubatorPos turntablePosIndex) throws AppException { + public PlateInfo pushPlate(ConsumableGroup PBCh, IncubatorPos turntablePosIndex) throws AppException { trunableMoveToPushPos(turntablePosIndex); canBus.stepMotorEasyMoveToBlock(MId.PlatesBoxYM, pp.getPBCh0Pos() + PBCh.off * pp.getPBChSpacing(), timep.getActionOvertime()); canBus.plateCodeScanerPushCardAndScanBlock(MId.PlatesBoxScanner, pp.getPusherEndPos(), 10000); canBus.stepMotorEasyMoveToZeroPointQuickBlock(MId.PlatesBoxPusherM, timep.getActionOvertime()); canBus.stepMotorEasyMoveToZeroPointQuickBlock(MId.PlatesBoxYM, timep.getActionOvertime()); - return AppRet.success(canBus.plateCodeScannerReadCode(MId.PlatesBoxScanner)); + return (canBus.plateCodeScannerReadCode(MId.PlatesBoxScanner)); } public void pushPlateQuick(ConsumableGroup PBCh, IncubatorPos turntablePosIndex) throws AppException { @@ -175,7 +175,7 @@ public class ReactionPlatesTransmitCtrl { // return AppRet.success(new A8kScanCurve(scanDataCurve, refLine)); // } - private AppRet packetOptDisplayScanCurve(List scanDataCurve) { + private A8kScanCurve packetOptDisplayScanCurve(List scanDataCurve) { A8kScanCurve scanCurve = new A8kScanCurve(); logger.info("pointNum: " + scanDataCurve.size()); scanCurve.scanDataCurve = A8kOptAlgo.preProcessOptData(scanDataCurve); @@ -185,20 +185,20 @@ public class ReactionPlatesTransmitCtrl { for (int i = 1; i < 6; i++) { scanCurve.refLine.add(40 * i); } - return AppRet.success(scanCurve); + return scanCurve; } - @ExtApiFn(name = "T光学扫码", group = "光学调试") - public AppRet optTScan(OptScanDirection direction, Integer scanerGain) throws AppException { - // canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_t_pos_offset, getTOptPosOffset()); - // canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_t_reverse_scan_pos_offset,getTOptPosOffset()-1200); - // canBus.optTStartScanBlock(MId.OptMod, direction, getOptTLasterGain(), scanerGain, getOptScanOvertime()); - // return packetOptDisplayScanCurve(canBus.optReadRaw(MId.OptMod)); - return AppRet.fail(A8kEcode.CmdNotSupport.index); - } +// @ExtApiFn(name = "T光学扫码", group = "光学调试") +// public A8kScanCurve optTScan(OptScanDirection direction, Integer scanerGain) throws AppException { +// // canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_t_pos_offset, getTOptPosOffset()); +// // canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_t_reverse_scan_pos_offset,getTOptPosOffset()-1200); +// // canBus.optTStartScanBlock(MId.OptMod, direction, getOptTLasterGain(), scanerGain, getOptScanOvertime()); +// // return packetOptDisplayScanCurve(canBus.optReadRaw(MId.OptMod)); +// return A8kEcode.CmdNotSupport.index; +// } @ExtApiFn(name = "F光学扫码", group = "光学调试") - public AppRet optFScan(OptScanDirection direction, Integer scanerGain) throws AppException { + public A8kScanCurve optFScan(OptScanDirection direction, Integer scanerGain) throws AppException { //getFOptPosOffset canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_f_pos_offset, pp.getFOptPosOffset()); canBus.moduleSetReg(MId.OptMod, RegIndex.kreg_a8k_opt_f_reverse_scan_pos_offset, pp.getFOptPosOffset() - 1200); diff --git a/src/main/java/a8k/service/devicedriver/ctrl/SamplesPreProcesCtrl.java b/src/main/java/a8k/service/devicedriver/ctrl/SamplesPreProcesCtrl.java index b0b0f67..69d462b 100644 --- a/src/main/java/a8k/service/devicedriver/ctrl/SamplesPreProcesCtrl.java +++ b/src/main/java/a8k/service/devicedriver/ctrl/SamplesPreProcesCtrl.java @@ -112,7 +112,7 @@ public class SamplesPreProcesCtrl { * @param highTube true/false */ @ExtApiFn(name = "取试管", group = "单步", order = ORDER.takeTubeAndJudgeTubeExist) - public AppRet takeTubeAndJudgeTubeExist(Boolean highTube) throws AppException { + public Boolean takeTubeAndJudgeTubeExist(Boolean highTube) throws AppException { /* * 校验: * 1.当前摇匀模组设计到的电机是否都处于待机位 @@ -194,7 +194,7 @@ public class SamplesPreProcesCtrl { } else { modGroupMoveToZeroQuick(); } - return AppRet.success(tubeCapExist); + return tubeCapExist; } @ExtApiFn(name = "摇匀", group = "单步", order = ORDER.shakeTube) diff --git a/src/main/java/a8k/service/devicedriver/testscript/TestScript.java b/src/main/java/a8k/service/devicedriver/testscript/TestScript.java index d23c291..dd65881 100644 --- a/src/main/java/a8k/service/devicedriver/testscript/TestScript.java +++ b/src/main/java/a8k/service/devicedriver/testscript/TestScript.java @@ -197,7 +197,7 @@ public class TestScript { } @ExtApiFn(name = "测试摇匀模组", group = "摇匀模组测试", order = ORDER.testSamplePreProcessModule) - public AppRet testSamplePreProcessModule() throws AppException { + public Object testSamplePreProcessModule() throws AppException { // checkTestScriptWorkFlag(); // testScriptWorkFlag = true; @@ -236,7 +236,7 @@ public class TestScript { // testScriptWorkFlag = false; // } - return AppRet.message("测试完成", null); + return null; } diff --git a/src/main/java/a8k/type/appret/AppRet.java b/src/main/java/a8k/type/appret/AppRet.java index 374e80f..a5d3b2f 100644 --- a/src/main/java/a8k/type/appret/AppRet.java +++ b/src/main/java/a8k/type/appret/AppRet.java @@ -1,6 +1,6 @@ package a8k.type.appret; -import a8k.type.ecode.ErrorContext; +import a8k.type.ecode.AppEcode; import a8k.hardware.type.a8kcanprotocol.CmdId; import a8k.hardware.type.a8kcanprotocol.MId; import a8k.hardware.type.a8kcanprotocol.A8kEcode; @@ -8,26 +8,16 @@ import a8k.type.exception.AppException; import lombok.Getter; public class AppRet { - - AppRetType appRetType = AppRetType.SUCCESS; - + public AppRetType appRetType = AppRetType.SUCCESS; // 错误信息 - @Getter - ErrorContext ecode = null; - + public AppEcode ecode = null; // 显示给用户的内容 - @Getter - String message = null; - + public String message = null; //异常触发上下文 - @Getter - String traceInfo = null; - + public String traceInfo = null; // 携带的对象 - @Getter - String dataType; - @Getter - T data; + public String dataType; + public T data; // 接口请求时间 @Getter @@ -41,19 +31,10 @@ public class AppRet { return !AppRetType.FAILURE.equals(appRetType); } - public static AppRet message(String message, T data) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.SUCCESS; - r.message = message; - r.dataType = null == data ? null : data.getClass().getSimpleName(); - return r; - } - public static AppRet success(T data) { AppRet r = new AppRet<>(); - r.data = data; r.appRetType = AppRetType.SUCCESS; - r.dataType = null == data ? null : data.getClass().getSimpleName(); + r.data = data; return r; } @@ -63,51 +44,6 @@ public class AppRet { return r; } - public static AppRet fail(Integer errorCode, MId mid, CmdId cmd) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - r.ecode = new ErrorContext(errorCode, mid, cmd); - r.message = r.ecode.toDisPlayString(); - return r; - } - - public static AppRet fail(Integer errorCode, MId mid) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - - r.ecode = new ErrorContext(errorCode, mid, null); - r.message = r.ecode.toDisPlayString(); - return r; - } - - public static AppRet fail(Integer errorCode) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - - r.ecode = new ErrorContext(errorCode, null, null); - r.message = r.ecode.toDisPlayString(); - return r; - } - - public static AppRet fail(Integer errorCode,String message) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - - r.ecode = new ErrorContext(errorCode, null, null); - r.message = message; - return r; - } - - public static AppRet fail(AppRet ret) { - AppRet r = new AppRet<>(); - r.appRetType = AppRetType.FAILURE; - - r.ecode = new ErrorContext(ret.getEcode().code, ret.getEcode().relateMid, ret.getEcode().relateCmd); - 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()) { @@ -118,7 +54,7 @@ public class AppRet { r.appRetType = AppRetType.FAILURE; if (e instanceof AppException hexcep) { - r.ecode = new ErrorContext(hexcep.getErrorCode(), hexcep.getModuleId(), hexcep.getCmdId()); + r.ecode = new AppEcode(hexcep.getErrorCode(), hexcep.getModuleId(), hexcep.getCmdId()); r.traceInfo = trace; r.message = r.ecode.toDisPlayString(); if (hexcep.getExtmessage() != null) { @@ -126,7 +62,7 @@ public class AppRet { } } else { - r.ecode = new ErrorContext(A8kEcode.CodeError.index, null, null); + r.ecode = new AppEcode(A8kEcode.CodeError.index, null, null); r.traceInfo = trace; r.message = e.getMessage(); } diff --git a/src/main/java/a8k/type/ecode/AppEcode.java b/src/main/java/a8k/type/ecode/AppEcode.java new file mode 100644 index 0000000..890ed16 --- /dev/null +++ b/src/main/java/a8k/type/ecode/AppEcode.java @@ -0,0 +1,31 @@ +package a8k.type.ecode; + +import a8k.hardware.type.a8kcanprotocol.A8kEcode; +import a8k.hardware.type.a8kcanprotocol.CmdId; +import a8k.hardware.type.a8kcanprotocol.MId; + +public class AppEcode { + public Integer code; + public String codeName; + public MId relateMid; + public CmdId relateCmd; + + public AppEcode(Integer errorCode, MId mid, CmdId cmd) { + this.code = errorCode; + this.codeName = A8kEcode.toDisPlayString(errorCode); + this.relateMid = mid; + this.relateCmd = cmd; + } + + public String toDisPlayString() { + String info; + info = String.format("错误: (%s)%d", A8kEcode.toDisPlayString(code), code); + if (relateMid != null) { + info += String.format("\n 相关模块: %s", relateMid.chname); + } + if (relateCmd != null) { + info += String.format("\n 相关指令: %s", relateCmd.chName); + } + return info; + } +} \ No newline at end of file diff --git a/src/main/java/a8k/type/ecode/ErrorContext.java b/src/main/java/a8k/type/ecode/ErrorContext.java deleted file mode 100644 index 8958d6e..0000000 --- a/src/main/java/a8k/type/ecode/ErrorContext.java +++ /dev/null @@ -1,31 +0,0 @@ -package a8k.type.ecode; - -import a8k.hardware.type.a8kcanprotocol.A8kEcode; -import a8k.hardware.type.a8kcanprotocol.CmdId; -import a8k.hardware.type.a8kcanprotocol.MId; - -public class ErrorContext { - public Integer code; - public String codeName; - public MId relateMid; - public CmdId relateCmd; - - public ErrorContext(Integer errorCode, MId mid, CmdId cmd) { - this.code = errorCode; - this.codeName = A8kEcode.toDisPlayString(errorCode); - this.relateMid = mid; - this.relateCmd = cmd; - } - - public String toDisPlayString() { - String info; - info = String.format("错误: (%s)%d", A8kEcode.toDisPlayString(code), code); - if (relateMid != null) { - info += String.format("\n 相关模块: %s", relateMid.chname); - } - if (relateCmd != null) { - info += String.format("\n 相关指令: %s", relateCmd.chName); - } - return info; - } -}