xyh hace 3 meses
padre
commit
7e331d456b

+ 212 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/dds/DataReaderListenerImpl.java

@@ -0,0 +1,212 @@
+package com.orangeforms.webadmin.dds;/*
+ *
+ *
+ * Distributed under the OpenDDS License.
+ * See: http://www.opendds.org/license.html
+ */
+
+import DDS.*;
+import OpenDDS.DCPS.*;
+import OpenDDS.DCPS.transport.*;
+import org.omg.CORBA.StringSeqHolder;
+import Messenger.*;
+
+import java.util.*;
+
+import com.orangeforms.webadmin.dds.initState;
+import com.orangeforms.webadmin.dds.jamingRunningState;
+import com.orangeforms.webadmin.dds.singleRadarPlatform;
+import com.orangeforms.webadmin.dds.singleJamingPlatform;
+import com.orangeforms.webadmin.dds.runState;
+
+public class DataReaderListenerImpl extends DDS._DataReaderListenerLocalBase {
+
+    private int num_msgs = 0;
+    public String text = "";
+    private static final int N_EXPECTED = 40;
+    private ArrayList<Boolean> counts = new ArrayList<Boolean>(N_EXPECTED);
+    public initState init = new initState();
+    public runState run = new runState();
+    public List<singleJamingPlatform> jamingList = new ArrayList<>();
+    public List<singleRadarPlatform> radarList = new ArrayList<>();
+    public List<initAlg> algList = new ArrayList<>();
+    public Map<String,jamingRunningState> jamingRunningStates = new HashMap<>();
+    public int needToInit = 0;//为1时需要发送初始化信息
+    public int needToAlg = 0;//为1时需要发送算法信息
+
+
+    private void initialize_counts() {
+        if (counts.size() > 0) {
+          return;
+        }
+
+        for (int i = 0; i < N_EXPECTED; ++i) {
+            counts.add(false);
+        }
+    }
+
+    public synchronized void on_data_available(DDS.DataReader reader) {
+
+        initialize_counts();
+
+        MessageDataReader mdr = MessageDataReaderHelper.narrow(reader);
+        if (mdr == null) {
+            System.err.println("ERROR: read: narrow failed.");
+            return;
+        }
+
+        MessageHolder mh = new MessageHolder(new Message());
+        SampleInfoHolder sih = new SampleInfoHolder(new SampleInfo(0, 0, 0,
+            new DDS.Time_t(), 0, 0, 0, 0, 0, 0, 0, false, 0));
+        int status = mdr.take_next_sample(mh, sih);
+
+        if (status == RETCODE_OK.value) {
+
+            System.out.println("SampleInfo.sample_rank = "
+                                + sih.value.sample_rank);
+            System.out.println("SampleInfo.instance_state = "
+                                + sih.value.instance_state);
+
+            if (sih.value.valid_data) {
+
+                String prefix = "";
+                boolean invalid_count = false;
+                if (mh.value.count < 0 || mh.value.count >= counts.size()) {
+                    invalid_count = true;
+                }
+                else {
+                    if (counts.get(mh.value.count) == false){
+                        counts.set(mh.value.count, true);
+                    }
+                    else {
+                        prefix = "ERROR: Repeat ";
+                    }
+                }
+                System.out.println(prefix + "Message: subject    = " + mh.value.subject);
+                System.out.println("         subject_id = "
+                                   + mh.value.subject_id);
+                System.out.println("         from       = " + mh.value.from);
+                System.out.println("         count      = " + mh.value.count);
+                System.out.println("         text       = " + mh.value.text);
+                System.out.println("SampleInfo.sample_rank = "
+                                   + sih.value.sample_rank);
+                text = mh.value.text;
+                if(mh.value.subject.equals("11")){
+                    //收到初始化应答 处理逻辑
+                    if(mh.value.from.equals("2")){
+                        init.platformInit = 1;
+                    }
+                    else if(mh.value.from.equals("3")){
+                        init.dataChangeInit = 1;
+                    }
+
+                    if(init.dataChangeInit==1&&init.platformInit==1){
+                        needToInit = 0;
+                        init.ifBegin = 1;
+                    }
+                }
+                else if(mh.value.subject.equals("12")){
+                    //收到初始化请求 处理逻辑
+                    needToInit = 1;
+                }
+                else if(mh.value.subject.equals("111")){
+                    //收到算法使用请求 处理逻辑
+                    needToAlg = 1;
+                }
+                else if (mh.value.subject.equals("21")) {
+                    //收到导调应答
+                    if(Objects.equals(mh.value.from, "2") &&run.platformState!=0){
+                        run.platformState= Integer.parseInt(mh.value.text);
+                    }
+                    else if(Objects.equals(mh.value.from, "3") &&run.dataChangeState!=0){
+                        run.dataChangeState = Integer.parseInt(mh.value.text);
+                    }
+                }
+                else if(mh.value.subject.equals("8")){
+                    //收到心跳数据
+                    if(Objects.equals(mh.value.from, "2") &&run.platformState==0){
+                        run.platformState=1;
+                    }
+                    else if(Objects.equals(mh.value.from, "3") &&run.dataChangeState==0){
+                        run.dataChangeState = 1;
+                    }
+                    else if(Objects.equals(mh.value.from, "5") &&run.radarPlatformState==0){
+                        run.radarPlatformState = 1;
+                    }
+                    else if(Objects.equals(mh.value.from, "4") &&run.algPlatformState==0){
+                        run.algPlatformState = 1;
+                    }
+                }
+                if (invalid_count == true) {
+                    System.out.println("ERROR: Invalid message.count (" + mh.value.count + ")");
+                }
+                if (!mh.value.from.equals("Comic Book Guy") && !mh.value.from.equals("OpenDDS-Java")) {
+                    System.out.println("ERROR: Invalid message.from (" + mh.value.from + ")");
+                }
+                if (!mh.value.subject.equals("Review")) {
+                    System.out.println("ERROR: Invalid message.subject (" + mh.value.subject + ")");
+                }
+                if (!mh.value.text.equals("Worst. Movie. Ever.")) {
+                    System.out.println("ERROR: Invalid message.text (" + mh.value.text + ")");
+                }
+                if (mh.value.subject_id != 99) {
+                    System.out.println("ERROR: Invalid message.subject_id (" + mh.value.subject_id + ")");
+                }
+            }
+            else if (sih.value.instance_state ==
+                     NOT_ALIVE_DISPOSED_INSTANCE_STATE.value) {
+                System.out.println("instance is disposed");
+            }
+            else if (sih.value.instance_state ==
+                     NOT_ALIVE_NO_WRITERS_INSTANCE_STATE.value) {
+                System.out.println("instance is unregistered");
+            }
+            else {
+                System.out.println("DataReaderListenerImpl::on_data_available: "
+                                   + "ERROR: received unknown instance state "
+                                   + sih.value.instance_state);
+            }
+
+        } else if (status == RETCODE_NO_DATA.value) {
+            System.err.println("ERROR: reader received DDS::RETCODE_NO_DATA!");
+        } else {
+            System.err.println("ERROR: read Message: Error: " + status);
+        }
+    }
+
+    public void on_requested_deadline_missed(DDS.DataReader reader, DDS.RequestedDeadlineMissedStatus status) {
+        System.err.println("DataReaderListenerImpl.on_requested_deadline_missed");
+    }
+
+    public void on_requested_incompatible_qos(DDS.DataReader reader, DDS.RequestedIncompatibleQosStatus status) {
+        System.err.println("DataReaderListenerImpl.on_requested_incompatible_qos");
+    }
+
+    public void on_sample_rejected(DDS.DataReader reader, DDS.SampleRejectedStatus status) {
+        System.err.println("DataReaderListenerImpl.on_sample_rejected");
+    }
+
+    public void on_liveliness_changed(DDS.DataReader reader, DDS.LivelinessChangedStatus status) {
+        System.err.println("DataReaderListenerImpl.on_liveliness_changed");
+    }
+
+    public void on_subscription_matched(DDS.DataReader reader, DDS.SubscriptionMatchedStatus status) {
+        System.err.println("DataReaderListenerImpl.on_subscription_matched");
+    }
+
+    public void on_sample_lost(DDS.DataReader reader, DDS.SampleLostStatus status) {
+        System.err.println("DataReaderListenerImpl.on_sample_lost");
+    }
+
+    public void report_validity() {
+        int count = 0;
+        int missed_counts = 0;
+        for (Boolean val : counts) {
+            if (val == false)
+                ++missed_counts;
+        }
+        if (missed_counts > 0) {
+            System.out.println("ERROR: Missing " + missed_counts + " messages");
+        }
+    }
+}

+ 248 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/dds/TestPublisher.java

@@ -0,0 +1,248 @@
+package com.orangeforms.webadmin.dds;/*
+ *
+ *
+ * Distributed under the OpenDDS License.
+ * See: http://www.opendds.org/license.html
+ */
+
+import DDS.*;
+import OpenDDS.DCPS.*;
+import org.omg.CORBA.StringSeqHolder;
+import Messenger.*;
+
+import java.util.concurrent.*;
+
+public class TestPublisher {
+
+    private static final int N_MSGS = 20;
+    private int count = 0;
+    private DomainParticipantFactory dpf;
+    private DomainParticipant dp;
+    private MessageTypeSupportImpl servant;
+    private Topic top;
+    private Publisher pub;
+    private DataWriterQos dw_qos;
+    private DataWriterQosHolder qosh;
+    private DataReaderListenerImpl listener;
+    private DataWriter dw ;
+    private StatusCondition sc;
+    private WaitSet ws;
+    private PublicationMatchedStatusHolder matched;
+    private Duration_t timeout;
+    private MessageDataWriter mdw;
+    private int instanceHandle;
+    private BlockingQueue<Message> messageQueue = new LinkedBlockingQueue<>();
+    private volatile boolean isInitialized = false;
+    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[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:192.168.5.81:12345/DCPSInfoRepo"; // 替换为实际IP和端口
+        executor.submit(() -> initialize(s)); // 初始化放在后台线程
+    }
+    public static boolean checkReliable(String[] args) {
+        for (int i = 0; i < args.length; ++i) {
+            if (args[i].equals("-r")) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static boolean checkWaitForAcks(String[] args) {
+        for (int i = 0; i < args.length; ++i) {
+            if (args[i].equals("-w")) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private void initialize(String[] args) {
+        try {
+            // ... 原有初始化代码到创建DataWriter为止...
+            System.out.println("Start Publisher");
+            boolean reliable = checkReliable(args);
+            boolean waitForAcks = checkWaitForAcks(args);
+
+            dpf =
+                    TheParticipantFactory.WithArgs(new StringSeqHolder(args));
+            if (dpf == null) {
+                System.err.println("ERROR: Domain Participant Factory not found");
+                return;
+            }
+            dp = dpf.create_participant(4,
+                    PARTICIPANT_QOS_DEFAULT.get(), null, DEFAULT_STATUS_MASK.value);
+            if (dp == null) {
+                System.err.println("ERROR: Domain Participant creation failed");
+                return;
+            }
+
+            servant = new MessageTypeSupportImpl();
+            if (servant.register_type(dp, "") != RETCODE_OK.value) {
+                System.err.println("ERROR: register_type failed");
+                return;
+            }
+
+            top = dp.create_topic("Movie Discussion List",
+                    servant.get_type_name(),
+                    TOPIC_QOS_DEFAULT.get(),
+                    null,
+                    DEFAULT_STATUS_MASK.value);
+            if (top == null) {
+                System.err.println("ERROR: Topic creation failed");
+                return;
+            }
+
+            pub = dp.create_publisher(PUBLISHER_QOS_DEFAULT.get(), null,
+                    DEFAULT_STATUS_MASK.value);
+            if (pub == null) {
+                System.err.println("ERROR: Publisher creation failed");
+                return;
+            }
+
+            // Use the default transport configuration (do nothing)
+
+            dw_qos = new DataWriterQos();
+            dw_qos.durability = new DurabilityQosPolicy();
+            dw_qos.durability.kind = DurabilityQosPolicyKind.from_int(0);
+            dw_qos.durability_service = new DurabilityServiceQosPolicy();
+            dw_qos.durability_service.history_kind = HistoryQosPolicyKind.from_int(0);
+            dw_qos.durability_service.service_cleanup_delay = new Duration_t();
+            dw_qos.deadline = new DeadlineQosPolicy();
+            dw_qos.deadline.period = new Duration_t();
+            dw_qos.latency_budget = new LatencyBudgetQosPolicy();
+            dw_qos.latency_budget.duration = new Duration_t();
+            dw_qos.liveliness = new LivelinessQosPolicy();
+            dw_qos.liveliness.kind = LivelinessQosPolicyKind.from_int(0);
+            dw_qos.liveliness.lease_duration = new Duration_t();
+            dw_qos.reliability = new ReliabilityQosPolicy();
+            dw_qos.reliability.kind = ReliabilityQosPolicyKind.from_int(0);
+            dw_qos.reliability.max_blocking_time = new Duration_t();
+            dw_qos.destination_order = new DestinationOrderQosPolicy();
+            dw_qos.destination_order.kind = DestinationOrderQosPolicyKind.from_int(0);
+            dw_qos.history = new HistoryQosPolicy();
+            dw_qos.history.kind = HistoryQosPolicyKind.from_int(0);
+            dw_qos.resource_limits = new ResourceLimitsQosPolicy();
+            dw_qos.transport_priority = new TransportPriorityQosPolicy();
+            dw_qos.lifespan = new LifespanQosPolicy();
+            dw_qos.lifespan.duration = new Duration_t();
+            dw_qos.user_data = new UserDataQosPolicy();
+            dw_qos.user_data.value = new byte[0];
+            dw_qos.ownership = new OwnershipQosPolicy();
+            dw_qos.ownership.kind = OwnershipQosPolicyKind.from_int(0);
+            dw_qos.ownership_strength = new OwnershipStrengthQosPolicy();
+            dw_qos.writer_data_lifecycle = new WriterDataLifecycleQosPolicy();
+            dw_qos.representation = new DataRepresentationQosPolicy();
+            dw_qos.representation.value = new short[0];
+
+            qosh = new DataWriterQosHolder(dw_qos);
+            pub.get_default_datawriter_qos(qosh);
+            qosh.value.history.kind = HistoryQosPolicyKind.KEEP_ALL_HISTORY_QOS;
+            if (reliable) {
+                qosh.value.reliability.kind =
+                        ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS;
+            }
+            dw = pub.create_datawriter(top,
+                    qosh.value,
+                    null,
+                    DEFAULT_STATUS_MASK.value);
+            if (dw == null) {
+                System.err.println("ERROR: DataWriter creation failed");
+                return;
+            }
+            System.out.println("Publisher Created DataWriter");
+
+            sc = dw.get_statuscondition();
+            sc.set_enabled_statuses(PUBLICATION_MATCHED_STATUS.value);
+            ws = new WaitSet();
+            ws.attach_condition(sc);
+            matched =
+                    new PublicationMatchedStatusHolder(new PublicationMatchedStatus());
+            timeout = new Duration_t(DURATION_INFINITE_SEC.value,
+                    DURATION_INFINITE_NSEC.value);
+
+
+
+            ws.detach_condition(sc);
+
+            mdw = MessageDataWriterHelper.narrow(dw);
+            // 等待匹配的逻辑保持原样
+            while (running) {
+                System.out.println("等待match中");
+                final int result = dw.get_publication_matched_status(matched);
+                if (result != RETCODE_OK.value) {
+                    System.err.println("ERROR: get_publication_matched_status()" +
+                            "failed.");
+                    return;
+                }
+                // 原有匹配等待逻辑...
+                if (matched.value.current_count >= 1) {
+                    System.out.println("Publisher Matched");
+                    isInitialized = true;
+                    break;
+                }
+                // 修改等待时间为有限等待
+                Duration_t timeout = new Duration_t(1, 0);
+                ConditionSeqHolder cond = new ConditionSeqHolder(new Condition[]{});
+                ws.wait(cond, timeout);
+            }
+
+            // 创建消息模板
+            Message template = new Message();
+            template.subject_id = 99;
+            instanceHandle = mdw.register_instance(template);
+
+            // 启动消息处理线程
+            executor.submit(this::processMessageQueue);
+
+        } catch (Exception e) {
+            // 异常处理...
+        }
+    }
+    public void publishMessage(String from, String subject, String text) {
+        if (!isInitialized) {
+            throw new IllegalStateException("Publisher not initialized");
+        }
+
+        Message msg = new Message();
+        msg.subject_id = 99;
+        msg.from = from;
+        msg.subject = subject;
+        msg.text = text;
+        msg.count = count++; // 根据需求调整
+
+        messageQueue.offer(msg); // 非阻塞式添加
+    }
+
+    private void processMessageQueue() {
+        try {
+            while (running) {
+                Message msg = messageQueue.poll(1, TimeUnit.SECONDS); // 带超时的获取
+                if (msg != null) {
+                    int ret;
+                    do {
+                        ret = mdw.write(msg, instanceHandle);
+                        if (ret != RETCODE_OK.value) {
+                            Thread.sleep(100); // 失败时短暂等待
+                        }
+                    } while (running && ret == RETCODE_TIMEOUT.value);
+                }
+            }
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+        }
+    }
+
+
+}

+ 196 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/dds/TestSubscriber.java

@@ -0,0 +1,196 @@
+package com.orangeforms.webadmin.dds;/*
+ *
+ *
+ * Distributed under the OpenDDS License.
+ * See: http://www.opendds.org/license.html
+ */
+
+import DDS.*;
+import OpenDDS.DCPS.*;
+import org.omg.CORBA.StringSeqHolder;
+import Messenger.*;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class TestSubscriber {
+    private DomainParticipantFactory dpf;
+    private DomainParticipant dp;
+    private MessageTypeSupportImpl servant;
+    private Topic top;
+    private Subscriber sub;
+    private DataReaderQos dr_qos;
+    private DataReaderQosHolder qosh;
+    public DataReaderListenerImpl listener = new DataReaderListenerImpl();
+    private DataReader dr;
+    private StatusCondition sc;
+    private WaitSet ws;
+    private SubscriptionMatchedStatusHolder matched;
+    private Duration_t timeout;
+    // 添加线程控制相关成员
+    private final ExecutorService executor = Executors.newSingleThreadExecutor();
+    private volatile boolean running = true;
+
+    public static boolean checkReliable(String[] args) {
+        for (int i = 0; i < args.length; ++i) {
+            if (args[i].equals("-r")) {
+                return true;
+            }
+        }
+        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[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:192.168.5.81:12345/DCPSInfoRepo"; // 替换为实际IP和端口
+        executor.submit(() -> initialize(s));
+    }
+    public String getText(){
+        return listener.text;
+    }
+    private void initialize(String[] args) {
+        try {
+            // ... 保持原有初始化代码到创建DataReader为止...
+
+            System.out.println("Start Subscriber");
+            boolean reliable = checkReliable(args);
+
+            dpf =
+                    TheParticipantFactory.WithArgs(new StringSeqHolder(args));
+            if (dpf == null) {
+                System.err.println("ERROR: Domain Participant Factory not found");
+                return;
+            }
+            dp = dpf.create_participant(4,
+                    PARTICIPANT_QOS_DEFAULT.get(), null, DEFAULT_STATUS_MASK.value);
+            if (dp == null) {
+                System.err.println("ERROR: Domain Participant creation failed");
+                return;
+            }
+
+            servant = new MessageTypeSupportImpl();
+            if (servant.register_type(dp, "") != RETCODE_OK.value) {
+                System.err.println("ERROR: register_type failed");
+                return;
+            }
+            top = dp.create_topic("Movie Discussion List",
+                    servant.get_type_name(),
+                    TOPIC_QOS_DEFAULT.get(),
+                    null,
+                    DEFAULT_STATUS_MASK.value);
+            if (top == null) {
+                System.err.println("ERROR: Topic creation failed");
+                return;
+            }
+
+            sub = dp.create_subscriber(SUBSCRIBER_QOS_DEFAULT.get(),
+                    null, DEFAULT_STATUS_MASK.value);
+            if (sub == null) {
+                System.err.println("ERROR: Subscriber creation failed");
+                return;
+            }
+
+            // Use the default transport (do nothing)
+
+            dr_qos = new DataReaderQos();
+            dr_qos.durability = new DurabilityQosPolicy();
+            dr_qos.durability.kind = DurabilityQosPolicyKind.from_int(0);
+            dr_qos.deadline = new DeadlineQosPolicy();
+            dr_qos.deadline.period = new Duration_t();
+            dr_qos.latency_budget = new LatencyBudgetQosPolicy();
+            dr_qos.latency_budget.duration = new Duration_t();
+            dr_qos.liveliness = new LivelinessQosPolicy();
+            dr_qos.liveliness.kind = LivelinessQosPolicyKind.from_int(0);
+            dr_qos.liveliness.lease_duration = new Duration_t();
+            dr_qos.reliability = new ReliabilityQosPolicy();
+            dr_qos.reliability.kind = ReliabilityQosPolicyKind.from_int(0);
+            dr_qos.reliability.max_blocking_time = new Duration_t();
+            dr_qos.destination_order = new DestinationOrderQosPolicy();
+            dr_qos.destination_order.kind = DestinationOrderQosPolicyKind.from_int(0);
+            dr_qos.history = new HistoryQosPolicy();
+            dr_qos.history.kind = HistoryQosPolicyKind.from_int(0);
+            dr_qos.resource_limits = new ResourceLimitsQosPolicy();
+            dr_qos.user_data = new UserDataQosPolicy();
+            dr_qos.user_data.value = new byte[0];
+            dr_qos.ownership = new OwnershipQosPolicy();
+            dr_qos.ownership.kind = OwnershipQosPolicyKind.from_int(0);
+            dr_qos.time_based_filter = new TimeBasedFilterQosPolicy();
+            dr_qos.time_based_filter.minimum_separation = new Duration_t();
+            dr_qos.reader_data_lifecycle = new ReaderDataLifecycleQosPolicy();
+            dr_qos.reader_data_lifecycle.autopurge_nowriter_samples_delay = new Duration_t();
+            dr_qos.reader_data_lifecycle.autopurge_disposed_samples_delay = new Duration_t();
+            dr_qos.representation = new DataRepresentationQosPolicy();
+            dr_qos.representation.value = new short[0];
+
+            qosh = new DataReaderQosHolder(dr_qos);
+            sub.get_default_datareader_qos(qosh);
+            if (reliable) {
+                qosh.value.reliability.kind =
+                        ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS;
+            }
+            qosh.value.history.kind = HistoryQosPolicyKind.KEEP_ALL_HISTORY_QOS;
+
+
+            dr = sub.create_datareader(top,
+                    qosh.value,
+                    listener,
+                    DEFAULT_STATUS_MASK.value);
+            if (dr == null) {
+                System.err.println("ERROR: DataReader creation failed");
+                return;
+            }
+
+            sc = dr.get_statuscondition();
+            sc.set_enabled_statuses(SUBSCRIPTION_MATCHED_STATUS.value);
+            ws = new WaitSet();
+            ws.attach_condition(sc);
+            matched =
+                    new SubscriptionMatchedStatusHolder(new SubscriptionMatchedStatus());
+
+//        timeout = new Duration_t(DURATION_INFINITE_SEC.value,
+//                DURATION_INFINITE_NSEC.value);
+
+            boolean matched_pub = false;
+
+
+             timeout = new Duration_t(1, 0); // 1秒超时
+
+            while (running) {
+                final int result = dr.get_subscription_matched_status(matched);
+                if (result != RETCODE_OK.value) {
+                    System.err.println("ERROR: get_subscription_matched_status() failed");
+                    break;
+                }
+
+                if (matched.value.current_count > 0) {
+                    System.out.println("Subscriber Matched");
+                    break;
+                }
+
+                ConditionSeqHolder cond = new ConditionSeqHolder(new Condition[]{});
+                if (ws.wait(cond, timeout) != RETCODE_OK.value && running) {
+                    System.err.println("ERROR: wait() failed");
+                    break;
+                }
+            }
+
+            System.out.println("Subscriber initialization completed");
+
+        } catch (Exception e) {
+            if (running) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+}

+ 22 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/dds/initAlg.java

@@ -0,0 +1,22 @@
+package com.orangeforms.webadmin.dds;
+
+public class initAlg {
+    public String platformID;
+    public String alg;
+
+    public String getPlatformID() {
+        return platformID;
+    }
+
+    public void setPlatformID(String platformID) {
+        this.platformID = platformID;
+    }
+
+    public String getAlg() {
+        return alg;
+    }
+
+    public void setAlg(String alg) {
+        this.alg = alg;
+    }
+}

+ 12 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/dds/initState.java

@@ -0,0 +1,12 @@
+package com.orangeforms.webadmin.dds;
+
+public class initState {
+    //本平台是否开始模拟状态位 0未开始 1已开始
+    public int ifBegin = 0;
+    //任务系统是否完成初始化状态位 0未完成 1已完成
+    public int platformInit = 0;
+    //数据交换平台是否完成初始化状态为 0未完成 1已完成
+    public int dataChangeInit = 0;
+
+
+}

+ 60 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/dds/jamingRunningState.java

@@ -0,0 +1,60 @@
+package com.orangeforms.webadmin.dds;
+
+public class jamingRunningState {
+    public String platformID;
+    public double x;
+
+    public String getPlatformID() {
+        return platformID;
+    }
+
+    public void setPlatformID(String platformID) {
+        this.platformID = platformID;
+    }
+
+    public double getX() {
+        return x;
+    }
+
+    public void setX(double x) {
+        this.x = x;
+    }
+
+    public double getY() {
+        return y;
+    }
+
+    public void setY(double y) {
+        this.y = y;
+    }
+
+    public double getZ() {
+        return z;
+    }
+
+    public void setZ(double z) {
+        this.z = z;
+    }
+
+    public int getIsAlive() {
+        return isAlive;
+    }
+
+    public void setIsAlive(int isAlive) {
+        this.isAlive = isAlive;
+    }
+
+    public double y;
+    public double z;
+    public int isAlive;
+
+    public String getPolicy() {
+        return policy;
+    }
+
+    public void setPolicy(String policy) {
+        this.policy = policy;
+    }
+
+    public String policy = "无";
+}

+ 13 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/dds/runState.java

@@ -0,0 +1,13 @@
+package com.orangeforms.webadmin.dds;
+
+public class runState {
+    //任务系统运行状态 0离线 1运行中 2暂停
+    public int platformState = 0;
+    //数据交换平台运行状态 0离线 1运行中 2暂停
+    public int dataChangeState = 0;
+
+    public int radarPlatformState = 0;
+
+    public int algPlatformState = 0;
+
+}

+ 85 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/dds/singleJamingPlatform.java

@@ -0,0 +1,85 @@
+package com.orangeforms.webadmin.dds;
+
+public class singleJamingPlatform {
+    public int getPlatformID() {
+        return platformID;
+    }
+
+    public void setPlatformID(int platformID) {
+        this.platformID = platformID;
+    }
+
+    public int getTeamID() {
+        return teamID;
+    }
+
+    public void setTeamID(int teamID) {
+        this.teamID = teamID;
+    }
+
+
+
+    public int getIsCoop() {
+        return isCoop;
+    }
+
+    public void setIsCoop(int isCoop) {
+        this.isCoop = isCoop;
+    }
+
+    public int getIsReal() {
+        return isReal;
+    }
+
+    public void setIsReal(int isReal) {
+        this.isReal = isReal;
+    }
+
+    public double getX() {
+        return x;
+    }
+
+    public void setX(double x) {
+        this.x = x;
+    }
+
+    public double getY() {
+        return y;
+    }
+
+    public void setY(double y) {
+        this.y = y;
+    }
+
+    public double getZ() {
+        return z;
+    }
+
+    public void setZ(double z) {
+        this.z = z;
+    }
+
+    //平台唯一id
+    public int platformID;
+    //平台协同编队号 不协同为0
+    public int teamID=0;
+
+    public String getPolicy() {
+        return policy;
+    }
+
+    public void setPolicy(String policy) {
+        this.policy = policy;
+    }
+
+    //平台干扰决策
+    public String policy;
+    //平台是否协同
+    public int isCoop;
+    //平台是否实物
+    public int isReal=1;
+    //起始坐标
+    public double x;
+    public double y;
+    public double z;
+}

+ 85 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/dds/singleRadarPlatform.java

@@ -0,0 +1,85 @@
+package com.orangeforms.webadmin.dds;
+
+public class singleRadarPlatform {
+    //平台唯一id
+    public int platformID;
+
+    public int getPlatformID() {
+        return platformID;
+    }
+
+    public void setPlatformID(int platformID) {
+        this.platformID = platformID;
+    }
+
+    public int getTeamID() {
+        return teamID;
+    }
+
+    public void setTeamID(int teamID) {
+        this.teamID = teamID;
+    }
+
+
+    public int getIsCoop() {
+        return isCoop;
+    }
+
+    public void setIsCoop(int isCoop) {
+        this.isCoop = isCoop;
+    }
+
+    public int getIsReal() {
+        return isReal;
+    }
+
+    public void setIsReal(int isReal) {
+        this.isReal = isReal;
+    }
+
+    public double getX() {
+        return x;
+    }
+
+    public void setX(double x) {
+        this.x = x;
+    }
+
+    public double getY() {
+        return y;
+    }
+
+    public void setY(double y) {
+        this.y = y;
+    }
+
+    public double getZ() {
+        return z;
+    }
+
+    public void setZ(double z) {
+        this.z = z;
+    }
+
+    //平台协同编队号 不协同为0
+    public int teamID=0;
+
+    public String getPolicy() {
+        return policy;
+    }
+
+    public void setPolicy(String policy) {
+        this.policy = policy;
+    }
+
+    //平台抗干扰策略
+    public String policy;
+    //平台是否协同
+    public int isCoop;
+    //是否实物模拟
+    public int isReal=1;
+    //起始坐标
+    public double x;
+    public double y;
+    public double z;
+}

+ 151 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/upms/controller/DdsController.java

@@ -0,0 +1,151 @@
+package com.orangeforms.webadmin.upms.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.orangeforms.webadmin.dds.initAlg;
+import com.orangeforms.webadmin.dds.jamingRunningState;
+import com.orangeforms.webadmin.dds.singleJamingPlatform;
+import com.orangeforms.webadmin.dds.singleRadarPlatform;
+import com.orangeforms.webadmin.upms.dto.InitRequestDto;
+import com.orangeforms.webadmin.upms.model.SysMenu;
+import lombok.extern.slf4j.Slf4j;
+import com.orangeforms.webadmin.upms.service.*;
+import com.orangeforms.common.core.annotation.NoAuthInterface;
+import com.orangeforms.common.core.annotation.MyRequestBody;
+import com.orangeforms.common.core.constant.ErrorCodeEnum;
+import com.orangeforms.common.core.object.*;
+import com.orangeforms.common.core.util.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.*;
+
+/**
+ * DDS接口控制器类。
+ *
+ * @author xyh
+ */
+@Slf4j
+@RestController
+@RequestMapping("/admin/upms/dds")
+public class DdsController {
+    @Autowired
+    private DdsService ddsService;
+
+    /**
+     * 导入初始化信息接口
+     *
+
+     * @return 应答结果对象,其中包括JWT的Token数据,以及菜单列表。
+     */
+    @NoAuthInterface
+    @PostMapping("/init")
+    public ResponseResult<Void> init(
+            @MyRequestBody singleJamingPlatform jaming) throws Exception {
+
+        if (MyCommonUtil.existBlankArgument(jaming)) {
+            return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
+        }
+
+        ddsService.setJamingList(jaming);
+        return ResponseResult.success();
+    }
+    /**
+     * 导入初始化信息接口
+     *
+
+     * @return 应答结果对象,其中包括JWT的Token数据,以及菜单列表。
+     */
+    @NoAuthInterface
+    @PostMapping("/initRadar")
+    public ResponseResult<Void> initRadar(
+            @MyRequestBody singleRadarPlatform radar) throws Exception {
+
+        if (MyCommonUtil.existBlankArgument(radar)) {
+            return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
+        }
+
+        ddsService.setRadarList(radar);
+        return ResponseResult.success();
+    }
+
+    /**
+     * 导入使用算法信息接口
+     *
+
+     * @return 应答结果对象,其中包括JWT的Token数据,以及菜单列表。
+     */
+    @NoAuthInterface
+    @PostMapping("/initAlg")
+    public ResponseResult<Void> initAlg(
+            @MyRequestBody initAlg alg) throws Exception {
+
+        if (MyCommonUtil.existBlankArgument(alg)) {
+            return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
+        }
+
+        ddsService.setAlgList(alg);
+        return ResponseResult.success();
+    }
+
+    /**
+     * 导调控制接口
+     *
+     * @param order 导调命令。
+     * @return 应答结果对象,其中包括JWT的Token数据,以及菜单列表。
+     */
+    @NoAuthInterface
+    @PostMapping("/order")
+    public ResponseResult<Void> order(
+            @MyRequestBody int order) throws Exception {
+        ddsService.sendControlOrder(order);
+
+        return ResponseResult.success();
+    }
+
+    /**
+     * 平台位置信息接口
+     *
+     * @param
+     * @return 应答结果对象,其中包括JWT的Token数据,以及菜单列表。
+     */
+    @NoAuthInterface
+    @PostMapping("/jaming")
+    public ResponseResult<Void> jaming(
+            @MyRequestBody jamingRunningState singleJaming) throws Exception {
+        if (MyCommonUtil.existBlankArgument(singleJaming)) {
+            return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
+        }
+        ddsService.setRunningState(singleJaming);
+        return ResponseResult.success();
+    }
+
+    /**
+     * 查询所有状态信息
+     *
+     * @return 应答结果对象,其中包括JWT的Token数据,以及菜单列表。
+     */
+    @GetMapping("/getAllState")
+    public ResponseResult<JSONObject> getAllState() {
+        JSONObject jsonData = new JSONObject();
+        jsonData.put("init", ddsService.getInitState());
+        jsonData.put("run", ddsService.getRunState());
+        jsonData.put("order",ddsService.getOrder());
+        return ResponseResult.success(jsonData);
+    }
+
+    /**
+     * 模拟结束
+     *
+     * @param
+     * @return 应答结果对象,其中包括JWT的Token数据,以及菜单列表。
+     */
+    @NoAuthInterface
+    @PostMapping("/end")
+    public ResponseResult<Void> end(
+            ) throws Exception {
+
+        ddsService.sendControlOrder(4);
+        return ResponseResult.success();
+    }
+
+}

+ 26 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/upms/dto/InitRequestDto.java

@@ -0,0 +1,26 @@
+package com.orangeforms.webadmin.upms.dto;
+import com.orangeforms.webadmin.dds.singleJamingPlatform;
+import com.orangeforms.webadmin.dds.singleRadarPlatform;
+
+import java.util.List;
+
+public class InitRequestDto {
+    private List<singleJamingPlatform> jamingList;
+    private List<singleRadarPlatform> radarList;
+
+    public List<singleJamingPlatform> getJamingList() {
+        return jamingList;
+    }
+
+    public void setJamingList(List<singleJamingPlatform> jamingList) {
+        this.jamingList = jamingList;
+    }
+
+    public List<singleRadarPlatform> getRadarList() {
+        return radarList;
+    }
+
+    public void setRadarList(List<singleRadarPlatform> radarList) {
+        this.radarList = radarList;
+    }
+}

+ 47 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/upms/service/DdsService.java

@@ -0,0 +1,47 @@
+package com.orangeforms.webadmin.upms.service;
+
+import com.orangeforms.webadmin.dds.*;
+
+import java.util.List;
+
+/**
+ * DDS服务接口
+ * 负责保存初始化相关数据,进行初始化业务
+ * 进行导调控制以及心跳管理
+ */
+public interface DdsService {
+
+    //获取各个系统的初始化状态
+    initState getInitState();
+
+    //获得各个系统的运行状态
+    runState getRunState();
+
+    //设置干扰平台初始化映射表
+    void setJamingList(singleJamingPlatform single);
+
+    //设置雷达平台初始化映射表
+    void setRadarList(singleRadarPlatform single);
+
+    //设置算法平台初始化映射表
+    void setAlgList(initAlg alg);
+
+
+    //设置当前的平台位置信息
+    void setRunningState(jamingRunningState state);
+
+    jamingRunningState getPositionById(String platformID);
+
+    //发送平台初始化信息
+    void sendInit();
+
+    void sendAlg();
+
+    //发送干扰平台位置信息
+    void sendJamingRunningState();
+
+    //发送导调控制
+    void sendControlOrder(int order);
+
+    int getOrder();
+}

+ 179 - 0
application-webadmin/src/main/java/com/orangeforms/webadmin/upms/service/impl/DdsServiceImpl.java

@@ -0,0 +1,179 @@
+package com.orangeforms.webadmin.upms.service.impl;
+
+import com.orangeforms.webadmin.dds.*;
+import com.orangeforms.webadmin.upms.service.DdsService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Slf4j
+@Service("ddsService")
+public class DdsServiceImpl implements DdsService {
+
+
+    public TestSubscriber subscriber = new TestSubscriber();;
+    public TestPublisher publisher = new TestPublisher();;
+    public int order;//当前导调控制命令
+
+    public DdsServiceImpl() throws Exception {
+    }
+
+    @Async
+    @Scheduled(fixedRate = 3000) // 每3秒执行一次
+    public void checkInitStateTask() {
+        if (subscriber != null && subscriber.listener != null) {
+        synchronized (subscriber.listener) {
+            // 读写操作
+                // 根据你的具体业务逻辑判断状态
+                if (subscriber.listener.needToInit==1) {
+                    sendInit();          // 触发处理方法
+                }
+                if (subscriber.listener.needToAlg==1) {
+                    sendAlg();          // 触发处理方法
+                 }
+                if (subscriber.listener.init.platformInit==1&&!subscriber.listener.jamingRunningStates.isEmpty()) {
+                    sendJamingRunningState();
+                }
+            }
+        }
+    }
+
+    @Override
+    public initState getInitState() {
+        return subscriber.listener.init;
+    }
+
+    @Override
+    public runState getRunState() {
+        return subscriber.listener.run;
+    }
+
+
+
+    @Override
+    public void setJamingList(singleJamingPlatform single) {
+        synchronized (subscriber.listener) {
+            // 读写操作
+            for(singleJamingPlatform e : subscriber.listener.jamingList){
+                if(e.platformID==single.platformID)return;
+            }
+            subscriber.listener.jamingList.add(single);
+            jamingRunningState j = new jamingRunningState();
+            j.platformID = String.valueOf(single.platformID);
+            j.isAlive = 1;
+            j.x = single.x;
+            j.y = single.y;
+            j.z = single.z;
+            j.policy = single.policy;
+            subscriber.listener.jamingRunningStates.put(String.valueOf(single.platformID),j);
+        }
+
+    }
+
+
+
+    @Override
+    public void setRadarList(singleRadarPlatform single) {
+        synchronized (subscriber.listener) {
+            // 读写操作
+            for(singleRadarPlatform e : subscriber.listener.radarList){
+                if(e.platformID==single.platformID)return;
+            }
+            subscriber.listener.radarList.add(single);
+
+        }
+
+    }
+
+    @Override
+    public void setAlgList(initAlg alg) {
+        synchronized (subscriber.listener) {
+            // 读写操作
+            for(initAlg e : subscriber.listener.algList){
+                if(e.platformID==alg.platformID)return;
+            }
+            subscriber.listener.algList.add(alg);
+
+        }
+
+    }
+
+
+    @Override
+    public void setRunningState(jamingRunningState state) {
+        synchronized (subscriber.listener) {
+            subscriber.listener.jamingRunningStates.put(state.platformID, state);
+
+        }
+    }
+
+    @Override
+    public jamingRunningState getPositionById(String platformID){
+        synchronized (subscriber.listener) {
+            if(subscriber.listener.jamingRunningStates.containsKey(platformID)){
+                return subscriber.listener.jamingRunningStates.get(platformID);
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public void sendInit() {
+        if(subscriber.listener.jamingList.size()==0&&subscriber.listener.radarList.size()==0)return;
+        String text = "";
+        text += subscriber.listener.jamingList.size()+" "+subscriber.listener.radarList.size()+"\n";
+        for (singleJamingPlatform jaming : subscriber.listener.jamingList){
+            text += jaming.platformID+" "+jaming.teamID+" "+jaming.policy+" "+jaming.isReal
+            +" "+jaming.x+" "+jaming.y+" "+jaming.z+"\n";
+        }
+        for (singleRadarPlatform radar : subscriber.listener.radarList){
+            text += radar.platformID+" "+radar.teamID+" "+radar.policy+" "+radar.isReal
+                    +" "+radar.x+" "+radar.y+" "+radar.z+"\n";
+        }
+        publisher.publishMessage("1","1",text);
+        subscriber.listener.needToInit=0;
+    }
+
+    @Override
+    public void sendAlg() {
+        if(subscriber.listener.algList.size()==0)return;
+        String text = "";
+        for (initAlg alg : subscriber.listener.algList){
+            text += alg.platformID+" "+alg.alg+"\n";
+        }
+
+        publisher.publishMessage("1","110",text);
+        subscriber.listener.needToAlg=0;
+    }
+
+
+    @Override
+    public void sendJamingRunningState() {
+        String text = "";
+        text += subscriber.listener.jamingRunningStates.size()+"\n";
+        for (jamingRunningState jaming : subscriber.listener.jamingRunningStates.values()){
+            text += jaming.platformID+" "+jaming.x+" "+jaming.y+" "+jaming.z
+                    +" "+jaming.isAlive+"\n";
+        }
+        publisher.publishMessage("1","3",text);
+    }
+
+    @Override
+    public void sendControlOrder(int order) {
+        subscriber.listener.radarList.clear();
+        subscriber.listener.jamingList.clear();
+        subscriber.listener.jamingRunningStates.clear();
+        subscriber.listener.needToInit = 0;
+        this.order = order;
+        String text = String.valueOf(this.order);
+        publisher.publishMessage("1","2",text);
+    }
+
+    @Override
+    public int getOrder() {
+        return order;
+    }
+}