sige 1 year ago
parent
commit
39d649a6ac
  1. 115
      src/main/java/a8k/hardware/controler/Controler.java
  2. 35
      src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java
  3. 11
      src/main/java/a8k/utils/HardwareServiceAction.java
  4. 11
      src/main/java/a8k/utils/HardwareServiceActionParam.java

115
src/main/java/a8k/hardware/controler/Controler.java

@ -1,9 +1,7 @@
package a8k.hardware.controler;
import a8k.appbean.ecode.AppRet;
import a8k.service.db.entity.HardwareServiceSetting;
import a8k.utils.HardwareService;
import a8k.utils.HardwareServiceParam;
import a8k.utils.HardwareServiceParams;
import a8k.utils.*;
import com.iflytop.uf.UfApplication;
import com.iflytop.uf.util.UfClassHelper;
import org.springframework.stereotype.Controller;
@ -11,6 +9,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -99,5 +98,115 @@ public class Controler {
return AppRet.success();
}
@PostMapping("/api/service-config/service-action-list")
@ResponseBody
public AppRet<Object> serviceActionList( @RequestBody Map<String, Object> params ) throws Exception {
String serviceKey = (String)params.get("serviceKey");
Class<?> serviceClass = null;
var classes = UfClassHelper.getAllClassesInPackage("a8k");
for (var clazz : classes) {
var hardwareServiceAnnotation = clazz.getAnnotation(HardwareService.class);
if (null == hardwareServiceAnnotation || !clazz.getSimpleName().equals(serviceKey)) {
continue ;
}
serviceClass = clazz;
break;
}
List<Map<String,Object>> actions = new ArrayList<>();
if ( null == serviceClass ) {
return AppRet.success(actions);
}
var methodList = serviceClass.getMethods();
for ( var method : methodList ) {
var actionAnnotation = method.getAnnotation(HardwareServiceAction.class);
if ( null == actionAnnotation ) {
continue ;
}
var action = new HashMap<String,Object>();
action.put("key", method.getName());
action.put("name", actionAnnotation.name());
action.put("group", actionAnnotation.group());
var actionParams = new ArrayList<Map<String,Object>>();
var actionParamList = method.getParameters();
for ( var param : actionParamList ) {
var actionParam = new HashMap<String, Object>();
actionParam.put("key", param.getName());
actionParam.put("type", param.getType().getName());
if ( param.getType().isEnum() ) {
actionParam.put("type", "Enum");
actionParam.put("typeEnum", param.getType().getName());
var paramOptions = new ArrayList<Map<String,Object>>();
var values = param.getType().getEnumConstants();
for ( var value : values ) {
var str = value.toString();
var paramOption = new HashMap<String, Object>();
paramOption.put("name", str);
paramOption.put("value", str);
paramOptions.add(paramOption);
}
actionParam.put("options", paramOptions);
}
actionParam.put("name", param.getName());
var annotation = param.getAnnotation(HardwareServiceActionParam.class);
if ( null != annotation ) {
actionParam.put("name", annotation.name());
}
actionParams.add(actionParam);
}
action.put("params", actionParams);
actions.add(action);
}
return AppRet.success(actions);
}
@PostMapping("/api/service-config/service-action-exec")
@ResponseBody
public AppRet<Object> serviceActionExecute( @RequestBody Map<String, Object> params ) throws Exception {
String serviceKey = (String)params.get("serviceKey");
Class<?> serviceClass = null;
var classes = UfClassHelper.getAllClassesInPackage("a8k");
for (var clazz : classes) {
var hardwareServiceAnnotation = clazz.getAnnotation(HardwareService.class);
if (null == hardwareServiceAnnotation || !clazz.getSimpleName().equals(serviceKey)) {
continue ;
}
serviceClass = clazz;
break;
}
if ( null == serviceClass ) {
return AppRet.success();
}
var actionName = (String)params.get("action");
var actionParams = (List<Object>)params.get("params");
var actionParamTypes = (List<String>)params.get("paramTypes");
Class<?>[] parameterTypes = new Class[actionParams.size()];
for(int i = 0; i < actionParams.size(); ++i) {
var name = actionParamTypes.get(i);
parameterTypes[i] = Class.forName(name);
}
Method method = serviceClass.getMethod(actionName, parameterTypes);
var parameters = method.getParameters();
for ( int i=0; i<parameters.length; i++ ) {
var parameter = parameters[i];
if ( parameter.getType().isEnum() ) {
var methodValueOf = parameter.getType().getMethod("valueOf", String.class);
var value = methodValueOf.invoke(null, actionParams.get(i));
actionParams.set(i, value);
}
}
var service = UfApplication.getContext().getBean(serviceClass);
Object actionResult = null;
if ( method.getReturnType().equals(Void.TYPE) ) {
method.invoke(service, actionParams.toArray());
} else {
actionResult = method.invoke(service, actionParams.toArray());
}
return AppRet.success(actionResult);
}
}

35
src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java

@ -9,6 +9,8 @@ import a8k.base_hardware.A8kCanBusService;
import a8k.service.db.dao.A8kTubeInfoDao;
import a8k.service.db.dao.SamplesPreProcessModuleCtrlParamsService;
import a8k.utils.HardwareService;
import a8k.utils.HardwareServiceAction;
import a8k.utils.HardwareServiceActionParam;
import com.iflytop.uf.util.UfCommon;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
@ -32,9 +34,7 @@ public class SamplesPreProcessModuleCtrlService {
基础方法
=======================================================================================*/
/**
* 按照一定顺序归零设备
*/
@HardwareServiceAction(name="归零")
public void moveToZero() throws HardwareException, InterruptedException {
var params = this.samplesPreProcessModuleCtrlParamsService;
this.a8kCanBusService.callblockcmd(
@ -75,11 +75,8 @@ public class SamplesPreProcessModuleCtrlService {
*/
}
/**
* 使能模组
* @param enable 是否使能模组
*/
public void enableModule(Boolean enable) throws HardwareException {
@HardwareServiceAction(name="使能")
public void enableModule(@HardwareServiceActionParam(name="使能") Boolean enable) throws HardwareException {
this.a8kCanBusService.callcmd(
MId.ShakeModShakeM.toInt(),
CmdId.step_motor_enable.toInt(),
@ -122,6 +119,7 @@ public class SamplesPreProcessModuleCtrlService {
* @param tubeType TubeType_HighBlood,TubeType_ShortBlood,TubeType_Mini,TubeType_MiniBlood,TubeType_BulletTube1P5,TubeType_BulletTube0P5
* @param judgeCapExist 是否判断试管帽子存在与否
*/
@HardwareServiceAction(name="取试管")
public A8kEcode takeTube(String tubeType, Boolean judgeCapExist) throws HardwareException, InterruptedException {
var params = this.samplesPreProcessModuleCtrlParamsService;
this.a8kCanBusService.callblockcmd(
@ -241,6 +239,7 @@ public class SamplesPreProcessModuleCtrlService {
/**
* 取试管帽
*/
@HardwareServiceAction(name="取试管帽")
public A8kEcode takeTubeCap( String tubeType ) throws HardwareException, InterruptedException {
var params = this.samplesPreProcessModuleCtrlParamsService;
this.a8kCanBusService.callblockcmd(
@ -295,6 +294,7 @@ public class SamplesPreProcessModuleCtrlService {
/**
* 盖试管帽并将试管移动回试管架中
*/
@HardwareServiceAction(name="盖试管帽并送回试管架")
public void pushBackTubeCapAndTakeBakTube(String tubeType) throws HardwareException, InterruptedException {
var params = this.samplesPreProcessModuleCtrlParamsService;
this.a8kCanBusService.callblockcmd(
@ -356,7 +356,8 @@ public class SamplesPreProcessModuleCtrlService {
* @param times 摇匀次数
* @param shakeDegree 摇匀角度
*/
public void ShakeTube(String tubeType, Integer times, Integer shakeDegree) throws HardwareException, InterruptedException {
@HardwareServiceAction(name="摇匀")
public void ShakeTube(A8kTubeType tubeType, Integer times, Integer shakeDegree) throws HardwareException, InterruptedException {
var params = this.samplesPreProcessModuleCtrlParamsService;
var standByPos = params.getShakeMotor_standbyPos();
var startPos = standByPos - shakeDegree/2;
@ -371,24 +372,18 @@ public class SamplesPreProcessModuleCtrlService {
);
}
/**
* 打开气溶胶风扇
*/
@HardwareServiceAction(name="打开气溶胶风扇")
public void openAerosolFan() throws HardwareException {
var params = this.samplesPreProcessModuleCtrlParamsService;
this.a8kCanBusService.callcmd(MId.WbTubeFanMod.toInt(), CmdId.fan_controler_set_speed.toInt(), params.getAerosolFanLevel());
}
/**
* 关闭气溶胶风扇
*/
@HardwareServiceAction(name="关闭气溶胶风扇")
public void closeAerosolFan() throws HardwareException {
this.a8kCanBusService.callcmd(MId.WbTubeFanMod.toInt(), CmdId.fan_controler_set_speed.toInt(), 0);
}
/**
* 设备初始化时复位
*/
@HardwareServiceAction(name="设备初始化时复位")
public void moduleResetWhenPowerOn() throws HardwareException, InterruptedException {
var params = this.samplesPreProcessModuleCtrlParamsService;
this.a8kCanBusService.callblockcmd(
@ -424,9 +419,7 @@ public class SamplesPreProcessModuleCtrlService {
this.a8kCanBusService.waitForMod(MId.ShakeModShakeM, params.getActionOvertime());
}
/**
* 设备运行时复位
*/
@HardwareServiceAction(name="设备运行时复位")
public void moduleRuntimeReset() throws HardwareException, InterruptedException {
var params = this.samplesPreProcessModuleCtrlParamsService;
this.a8kCanBusService.callblockcmd(

11
src/main/java/a8k/utils/HardwareServiceAction.java

@ -0,0 +1,11 @@
package a8k.utils;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface HardwareServiceAction {
String name();
String group() default "";
}

11
src/main/java/a8k/utils/HardwareServiceActionParam.java

@ -0,0 +1,11 @@
package a8k.utils;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface HardwareServiceActionParam {
String name();
}
Loading…
Cancel
Save