Bladeren bron

雷达平台后端修改

Rgx 3 maanden geleden
bovenliggende
commit
2e64c9c89f

+ 1 - 1
src/main/java/com/example/backend/controller/RadarStatusController.java

@@ -36,7 +36,7 @@ public class RadarStatusController {
             for(String key : radarStatusService.getPlatforms()){
                 Platform p = new Platform();
                 p.setPlatformID(key);
-                p.setPlatformName("干扰平台-"+key);
+                p.setPlatformName("雷达平台-"+key);
                 list.add(p);
             }
             return ResponseEntity.ok(list);

+ 37 - 6
src/main/java/com/example/backend/dds/DataReaderListenerImpl.java

@@ -8,6 +8,7 @@ package com.example.backend.dds;/*
 import DDS.*;
 import OpenDDS.DCPS.*;
 import OpenDDS.DCPS.transport.*;
+import com.example.backend.model.MessageStatus;
 import com.example.backend.model.Position;
 import org.omg.CORBA.StringSeqHolder;
 import Messenger.*;
@@ -34,6 +35,7 @@ public class DataReaderListenerImpl extends DDS._DataReaderListenerLocalBase {
     public Map<String, Position> radarPositionMap = new ConcurrentHashMap<>();
     public Map<String, List<String>> coopTeamMap = new ConcurrentHashMap<>();
     public final Map<String, List<com.example.backend.model.Message>> messageList = new ConcurrentHashMap<>();
+    public Map<String, MessageStatus> messageStatusMap = new ConcurrentHashMap<>();
 
     private void initialize_counts() {
         if (counts.size() > 0) {
@@ -110,7 +112,7 @@ public class DataReaderListenerImpl extends DDS._DataReaderListenerLocalBase {
                     String[] countList = messageList[0].split(" ");
                     int count = Integer.parseInt(countList[0]);
                     int radarCount = Integer.parseInt(countList[1]);
-                    //侦察
+                    //干扰平台
                     for(int i=1;i<=count;i++){
                         String[] s = messageList[i].split(" ");
                         Position p = new Position();
@@ -122,13 +124,14 @@ public class DataReaderListenerImpl extends DDS._DataReaderListenerLocalBase {
                         p.z = Double.parseDouble(s[6]);
                         positionMap.put(s[0],p);
                     }
-                    //雷达
+                    //雷达平台
                     for(int i=count+1;i<=radarCount+count;i++){
                         String[] s = messageList[i].split(" ");
                         Position p = new Position();
-                        p.coopID = "未知";
-                        p.jaming = "未知";
-                        p.isReal = "未知";
+                        p.radar = s[0];
+                        p.collaborationNumber = s[1];
+                        p.interferenceStrategy = s[2];
+                        p.isReal = s[3];
                         p.x = Double.parseDouble(s[4]);
                         p.y = Double.parseDouble(s[5]);
                         p.z = Double.parseDouble(s[6]);
@@ -195,7 +198,8 @@ public class DataReaderListenerImpl extends DDS._DataReaderListenerLocalBase {
                     String[] messageList = message.split("\n");
                     String[] countList = messageList[0].split(" ");
                     if(Integer.parseInt(countList[2])<=versionID)return;//旧版本或重复
-                    for(int i=1;i<=Integer.parseInt(countList[0]);i++){
+                    int start = Integer.parseInt(countList[0]);
+                    for(int i=1+start; i<messageList.length; i++){
                         String[] s = messageList[i].split(" ");
                         String coopID = s[0];
                         List<String> list = new ArrayList<>();
@@ -206,6 +210,32 @@ public class DataReaderListenerImpl extends DDS._DataReaderListenerLocalBase {
                     }
                     isTeam = 1;
                 }
+                if(mh.value.subject.equals("9")){
+                    // 收到分组状态参数控制
+                    String message = mh.value.text;
+                    String[] s = message.split(" ");
+                    MessageStatus m = new MessageStatus();
+                    m.startUp = s[1];
+                    m.quite = s[2];
+                    m.mode = s[3];
+                    messageStatusMap.put(s[0],m);
+                }
+                if(mh.value.subject.equals("10")){
+                    // 收到分组状态参数初始化
+                    String message = mh.value.text;
+                    String[] messageList = message.split("\n");
+                    String[] countList = messageList[0].split(" ");
+                    int start = Integer.parseInt(countList[0]);
+                    for(int i=1+start;i<messageList.length;i++){
+                        String[] s = messageList[i].split(" ");
+                        String platformID = s[0];
+                        MessageStatus m = new MessageStatus();
+                        m.startUp = s[1];
+                        m.quite = s[2];
+                        m.mode = s[3];
+                        messageStatusMap.put(platformID,m);
+                    }
+                }
                 if (invalid_count == true) {
                     System.out.println("ERROR: Invalid message.count (" + mh.value.count + ")");
                 }
@@ -272,6 +302,7 @@ public class DataReaderListenerImpl extends DDS._DataReaderListenerLocalBase {
         this.radarPositionMap.clear();
         this.coopTeamMap.clear();
         this.messageList.clear();
+        this.messageStatusMap.clear();
         this.isInit = 0;
         this.isRecall = 0;
         this.isTeam = 0;

+ 37 - 5
src/main/java/com/example/backend/dds/TestPublisher.java

@@ -9,9 +9,12 @@ import DDS.*;
 import OpenDDS.DCPS.*;
 import org.omg.CORBA.StringSeqHolder;
 import Messenger.*;
+import org.springframework.stereotype.Component;
 
+import javax.annotation.PreDestroy;
 import java.util.concurrent.*;
 
+@Component
 public class TestPublisher {
 
     private static final int N_MSGS = 20;
@@ -36,11 +39,20 @@ public class TestPublisher {
     private final ExecutorService executor = Executors.newSingleThreadExecutor();
     private volatile boolean running = true;
     public TestPublisher() throws Exception {
-        String[] s = new String[4];
-        s[0] = "-DCPSBit";
-        s[1] = "0";
-        s[2] = "-DCPSConfigFile";
-        s[3] = "D:/dds/open-dds_3.16/OpenDDS-3.16/OpenDDS-3.16/java/tests/messenger/tcp.ini";
+        //String[] s = new String[4];
+//        s[0] = "-DCPSBit";
+//        s[1] = "0";
+//        s[2] = "-DCPSConfigFile";
+//        s[3] = "D:/dds/open-dds_3.16/OpenDDS-3.16/OpenDDS-3.16/java/tests/messenger/tcp.ini";
+//        executor.submit(() -> initialize(s)); // 初始化放在后台线程
+        // 创建参数数组(长度调整为6)
+        String[] s = new String[6];
+        s[0] = "-DCPSBit";               // 启用Bit通信(保持原有配置)
+        s[1] = "0";                      // Bit值
+        s[2] = "-DCPSDefaultDiscovery";  // 指定发现机制为InfoRepo
+        s[3] = "DEFAULT_REPO";           // 使用集中式InfoRepo
+        s[4] = "-DCPSInfoRepo";          // InfoRepo的corbaloc地址
+        s[5] = "corbaloc:iiop:10.195.84.22:12345/DCPSInfoRepo"; // 替换为实际IP和端口
         executor.submit(() -> initialize(s)); // 初始化放在后台线程
     }
     public static boolean checkReliable(String[] args) {
@@ -237,5 +249,25 @@ public class TestPublisher {
         }
     }
 
+    public void disconnect() {
+        running = false;
+        executor.shutdownNow();
+
+        if (dw != null) {
+            pub.delete_datawriter(dw);
+        }
+        if (pub != null) {
+            dp.delete_publisher(pub);
+        }
+
+        if (dp != null) {
+            dpf.delete_participant(dp);
+        }
+    }
+
+    @PreDestroy
+    public void preDestroy(){
+        disconnect();
+    }
 
 }

+ 37 - 5
src/main/java/com/example/backend/dds/TestSubscriber.java

@@ -9,11 +9,14 @@ import DDS.*;
 import OpenDDS.DCPS.*;
 import org.omg.CORBA.StringSeqHolder;
 import Messenger.*;
+import org.springframework.stereotype.Component;
 
+import javax.annotation.PreDestroy;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicReference;
 
+@Component
 public class TestSubscriber {
     private DomainParticipantFactory dpf;
     private DomainParticipant dp;
@@ -41,11 +44,18 @@ public class TestSubscriber {
         return false;
     }
     public TestSubscriber() throws Exception {
-        String[] s = new String[4];
-        s[0] = "-DCPSBit";
-        s[1] = "0";
-        s[2] = "-DCPSConfigFile";
-        s[3] = "D:/dds/open-dds_3.16/OpenDDS-3.16/OpenDDS-3.16/java/tests/messenger/tcp.ini";
+//        String[] s = new String[4];
+//        s[0] = "-DCPSBit";
+//        s[1] = "0";
+//        s[2] = "-DCPSConfigFile";
+//        s[3] = "D:/dds/open-dds_3.16/OpenDDS-3.16/OpenDDS-3.16/java/tests/messenger/tcp.ini";
+        String[] s = new String[6];
+        s[0] = "-DCPSBit";               // 启用Bit通信(保持原有配置)
+        s[1] = "0";                      // Bit值
+        s[2] = "-DCPSDefaultDiscovery";  // 指定发现机制为InfoRepo
+        s[3] = "DEFAULT_REPO";           // 使用集中式InfoRepo
+        s[4] = "-DCPSInfoRepo";          // InfoRepo的corbaloc地址
+        s[5] = "corbaloc:iiop:10.195.84.22:12345/DCPSInfoRepo"; // 替换为实际IP和端口
         executor.submit(() -> initialize(s));
     }
     public String getText(){
@@ -185,5 +195,27 @@ public class TestSubscriber {
             }
         }
     }
+    public void disconnect() {
+        // 停止线程
+        running = false;
+        executor.shutdownNow();
+
+        // 释放 DDS 资源
+        if (dr != null) {
+            sub.delete_datareader(dr);
+        }
+        if (sub != null) {
+            dp.delete_subscriber(sub);
+        }
+
+        if (dp != null) {
+            dpf.delete_participant(dp);
+        }
+    }
+
+    @PreDestroy
+    public void preDestroy(){
+        disconnect();
+    }
 
 }

+ 35 - 1
src/main/java/com/example/backend/model/Position.java

@@ -55,5 +55,39 @@ public class Position {
     }
 
     public String jaming;
-    public String isReal;
+
+    public String isReal; // 是否实物
+
+    public String radar; //雷达平台id
+
+    public String collaborationNumber; // 协同编号
+
+    public String interferenceStrategy; // 干扰策略
+
+    public String getRadar() {
+        return radar;
+    }
+
+    public void setRadar(String radar) {
+        this.radar = radar;
+    }
+
+    public String getCollaborationNumber() {
+        return collaborationNumber;
+    }
+
+    public void setCollaborationNumber(String collaborationNumber) {
+        this.collaborationNumber = collaborationNumber;
+    }
+
+    public String getInterferenceStrategy() {
+        return interferenceStrategy;
+    }
+
+    public void setInterferenceStrategy(String interferenceStrategy) {
+        this.interferenceStrategy = interferenceStrategy;
+    }
+
+
+
 }

+ 16 - 10
src/main/java/com/example/backend/service/RadarStatusService.java

@@ -3,6 +3,7 @@ package com.example.backend.service;
 import com.example.backend.dds.TestSubscriber;
 import com.example.backend.dds.TestPublisher;
 import com.example.backend.model.*;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
@@ -31,8 +32,12 @@ public class RadarStatusService {
     private final Map<String, List<Message>> outmessageList = new ConcurrentHashMap<>();
     private final Map<String, List<ecmParams>> ecmParamsList = new ConcurrentHashMap<>();
     private final Map<String, ecmStatus> ecmStatusList = new ConcurrentHashMap<>();
-    public final TestSubscriber subscriber = new TestSubscriber();
-    public final TestPublisher publisher = new TestPublisher();
+
+    @Autowired
+    public TestSubscriber subscriber;
+
+    @Autowired
+    public TestPublisher publisher;
 
     
     // 设置队列最大容量
@@ -117,14 +122,14 @@ public class RadarStatusService {
     @PostConstruct
     public void init() {
         // 初始化默认平台的状态和参数
-        for(String key : subscriber.listener.positionMap.keySet()){
+        for(String key : subscriber.listener.radarPositionMap.keySet()){
             initializePlatform(key);
         }
 
     }
 
     public Set<String> getPlatforms(){
-        return subscriber.listener.positionMap.keySet();
+        return subscriber.listener.radarPositionMap.keySet();
     }
 
     // 初始化平台数据
@@ -253,9 +258,9 @@ public class RadarStatusService {
 
     // 获取位置信息
     public Position getPositionById(String platformId) {
-        for(String key : subscriber.listener.positionMap.keySet()){
+        for(String key : subscriber.listener.radarPositionMap.keySet()){
             if(key.equals(platformId)){
-                return subscriber.listener.positionMap.get(key);
+                return subscriber.listener.radarPositionMap.get(key);
             }
         }
         return null;
@@ -354,11 +359,15 @@ public class RadarStatusService {
 
     //获取消息数据 链路状态相关方法
     public MessageStatus getMsgStatusById(String PlatformID){
+
         return messageStatusMap.get(PlatformID);
     }
 
     public void setMsgStatusById(String PlatformID,MessageStatus m){
-        messageStatusMap.put(PlatformID,m);
+        // messageStatusMap.put(PlatformID,m);
+        subscriber.listener.messageStatusMap.put(PlatformID,m);
+        publisher.publishMessage("5","9",m.startUp+" "+m.quite+" "+m.mode);
+
     }
 
     public List<Message> getMsgListById(String PlatformID){
@@ -453,9 +462,6 @@ public class RadarStatusService {
             }
         }
         List<String> list = new ArrayList<>();
-        list.add("101");
-        list.add("102");
-        list.add("103");
         return list;
     }