ty130316261 3 lat temu
rodzic
commit
5319b2eada

+ 49 - 11
zd-modules/zd-netty/src/main/java/com/zd/netty/sdk/DeJuRFIDService.java

@@ -7,6 +7,7 @@ import com.gg.reader.api.protocol.gx.*;
 import com.zd.common.core.exception.ServiceException;
 import com.zd.netty.service.ISendService;
 import com.zd.netty.service.IService;
+import com.zd.netty.thread.ThreadPoolTaskConfig;
 import com.zd.system.api.domain.InventoryTag;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 import lombok.extern.slf4j.Slf4j;
@@ -28,6 +29,9 @@ public class DeJuRFIDService implements IService {
 
     private final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
 
+    @Resource
+    private ThreadPoolTaskConfig threadPoolTaskConfig;
+
     @Override
     public void start(RemoteLabHardware hardware) {
         GClient client;
@@ -41,7 +45,6 @@ public class DeJuRFIDService implements IService {
         if (client.openTcp(ipAddress + ":8160", 2000)) {
             // 订阅标签上报事件
             subscribeHandler(client);
-
             // 功率配置, 将4个天线功率都设置为30dBm.
             Integer uniformPower = hardware.getUniformPower();
             MsgBaseGetPower msgBaseGetPower = new MsgBaseGetPower();
@@ -69,17 +72,19 @@ public class DeJuRFIDService implements IService {
                 log.info("Power configuration error.");
             }
 
-            MsgAppSetBeep msgAppSetBeep = new MsgAppSetBeep();
-            msgAppSetBeep.setBeepMode(hardware.getSessionIndex() > 1 ? 1 : 0);
-            msgAppSetBeep.setBeepStatus(1);
-            client.sendSynMsg(msgAppSetBeep);
+            //蜂鸣器设置
+//            MsgAppSetBeep msgAppSetBeep = new MsgAppSetBeep();
+//            msgAppSetBeep.setBeepMode(hardware.getSessionIndex() > 1 ? 1 : 0);
+//            msgAppSetBeep.setBeepStatus(1);
+//            client.sendSynMsg(msgAppSetBeep);
+//
+//            if (0 == msgAppSetBeep.getRtCode()) {
+//                log.info("Beep epc successful.");
+//            } else {
+//                log.info("Beep epc error.");
+//            }
 
-            if (0 == msgAppSetBeep.getRtCode()) {
-                log.info("Beep epc successful.");
-            } else {
-                log.info("Beep epc error.");
-            }
-            // 4个天线读卡, 读取EPC数据区以及TID数据区
+            //天线读卡, 读取EPC数据区以及TID数据区
             MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc();
             switch (hardware.getChannels()) {
                 case 4:
@@ -134,10 +139,43 @@ public class DeJuRFIDService implements IService {
      */
     private void subscribeHandler(GClient client) {
         client.onTagEpcLog = (s, logBaseEpcInfo) -> {
+            //灯带设置
+            MsgAppSetGpo msgAppSetGpo=new MsgAppSetGpo();
+            msgAppSetGpo.setGpo1(1);
+            msgAppSetGpo.setGpo2(1);
+            msgAppSetGpo.setGpo3(1);
+            msgAppSetGpo.setGpo4(1);
+            msgAppSetGpo.setGpo5(1);
+            msgAppSetGpo.setGpo6(1);
+            msgAppSetGpo.setGpo7(1);
+            msgAppSetGpo.setGpo8(1);
+            client.sendSynMsg(msgAppSetGpo);
+            if (0 == msgAppSetGpo.getRtCode()) {
+                log.info("Gpo epc successful.");
+            } else {
+                log.error("Gpo epc error.");
+            }
             if (logBaseEpcInfo.getResult() == 0) {
                 InventoryTag tag = new InventoryTag();
                 BeanUtils.copyProperties(logBaseEpcInfo, tag);
                 sendService.send(tag);
+                threadPoolTaskConfig.getAsyncExecutor().execute(() -> {
+                    MsgAppSetGpo msgAppSetGpo1 =new MsgAppSetGpo();
+                    msgAppSetGpo1.setGpo1(0);
+                    msgAppSetGpo1.setGpo2(0);
+                    msgAppSetGpo1.setGpo3(0);
+                    msgAppSetGpo1.setGpo4(0);
+                    msgAppSetGpo1.setGpo5(0);
+                    msgAppSetGpo1.setGpo6(0);
+                    msgAppSetGpo1.setGpo7(0);
+                    msgAppSetGpo1.setGpo8(0);
+                    client.sendSynMsg(msgAppSetGpo1);
+                    if (0 == msgAppSetGpo1.getRtCode()) {
+                        log.info("Gpo epc successful.");
+                    } else {
+                        log.error("Gpo epc error.");
+                    }
+                },10000);
             }
         };
 

+ 35 - 0
zd-modules/zd-netty/src/main/java/com/zd/netty/thread/ThreadPoolTaskConfig.java

@@ -0,0 +1,35 @@
+package com.zd.netty.thread;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.ThreadPoolExecutor;
+
+@Configuration
+@EnableAsync
+public class ThreadPoolTaskConfig {
+
+    private static final int corePoolSize = 10;       		// 核心线程数(默认线程数)
+    private static final int maxPoolSize = 100;			    // 最大线程数
+    private static final int keepAliveTime = 10;			// 允许线程空闲时间(单位:默认为秒)
+    private static final int queueCapacity = 200;			// 缓冲队列数
+    private static final String threadNamePrefix = "Async-Service-"; // 线程池名前缀
+
+    @Bean("taskExecutor") // bean的名称,默认为首字母小写的方法名
+    public ThreadPoolTaskExecutor getAsyncExecutor(){
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(corePoolSize);
+        executor.setMaxPoolSize(maxPoolSize);
+        executor.setQueueCapacity(queueCapacity);
+        executor.setKeepAliveSeconds(keepAliveTime);
+        executor.setThreadNamePrefix(threadNamePrefix);
+
+        // 线程池对拒绝任务的处理策略
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        // 初始化
+        executor.initialize();
+        return executor;
+    }
+}