diff --git a/pom.xml b/pom.xml
index 5d0259c..426f6f7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,6 +65,11 @@
cn.hutool
hutool-all
+
+ org.bouncycastle
+ bcprov-jdk15on
+ 1.70
+
org.apache.commons
commons-lang3
diff --git a/src/main/java/com/iot/modbus_rtcp/controller/ModbusTCPController.java b/src/main/java/com/iot/modbus_rtcp/controller/ModbusTCPController.java
index 99b3ab0..70a73ac 100644
--- a/src/main/java/com/iot/modbus_rtcp/controller/ModbusTCPController.java
+++ b/src/main/java/com/iot/modbus_rtcp/controller/ModbusTCPController.java
@@ -10,12 +10,10 @@ import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import java.util.List;
+import java.util.Set;
/**
* Modbus-TCP协议API
@@ -25,7 +23,7 @@ import java.util.List;
@RestController
@RequestMapping("modbus-tcp")
public class ModbusTCPController implements ApplicationRunner {
- private NettyServer nettyServer;
+ public static NettyServer nettyServer;
@PreDestroy
private void destroy() {
@@ -88,6 +86,16 @@ public class ModbusTCPController implements ApplicationRunner {
return Response.succeed();
}
+ /**
+ * 在綫設備列表
+ *
+ * @return
+ */
+ @GetMapping("/online")
+ public Response> online() {
+ return Response.succeed(this.nettyServer.getGroup().onlineGateway());
+ }
+
@Override
public void run(ApplicationArguments args) throws Exception {
this.nettyServer = new NettyServer(502, 10);
diff --git a/src/main/java/com/iot/modbus_rtcp/jobs/AutoCollectJobs.java b/src/main/java/com/iot/modbus_rtcp/jobs/AutoCollectJobs.java
index aa8c0b8..7d298f1 100644
--- a/src/main/java/com/iot/modbus_rtcp/jobs/AutoCollectJobs.java
+++ b/src/main/java/com/iot/modbus_rtcp/jobs/AutoCollectJobs.java
@@ -14,6 +14,11 @@ import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
@@ -24,11 +29,25 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class AutoCollectJobs {
- private static final String SQL = "SELECT ref_id as deviceId, command, message_length messageLength FROM commands " +
+ private static final String SQL = "SELECT id as commandId, ref_id as deviceId, command, " +
+ "message_length messageLength, '4B454E454E4731343030303030333538' as identifier FROM commands " +
"WHERE type = 'COLLECTION' and ref_type = 'DEVICE' and id < 10099 order by id";
private final JdbcTemplate jdbcTemplate;
private final ModbusTCPController controller;
+ private final ThreadPoolExecutor collectThreadPool = new ThreadPoolExecutor(Math.min(10, Runtime.getRuntime().availableProcessors())
+ , Math.min(100, Runtime.getRuntime().availableProcessors()), 60, TimeUnit.SECONDS,
+ new ArrayBlockingQueue<>(5000), new ThreadFactory() {
+ AtomicInteger index = new AtomicInteger(1);
+
+ @Override
+ public Thread newThread(Runnable runnable) {
+ Thread thread = new Thread(runnable, "Modbus-auto-collect-thread-" + index.getAndIncrement());
+ thread.setDaemon(true);
+ thread.setPriority(Thread.MIN_PRIORITY);
+ return thread;
+ }
+ }, new ThreadPoolExecutor.CallerRunsPolicy());
@Scheduled(cron = "0/30 * * * * ? ")
public void autoCollect() {
@@ -38,19 +57,30 @@ public class AutoCollectJobs {
List