|
@@ -0,0 +1,365 @@
|
|
|
+package io.renren.dds;/*
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * Distributed under the OpenDDS License.
|
|
|
+ * See: http://www.opendds.org/license.html
|
|
|
+ */
|
|
|
+
|
|
|
+import DDS.*;
|
|
|
+import Messenger.*;
|
|
|
+import OpenDDS.DCPS.*;
|
|
|
+import OpenDDS.DCPS.transport.*;
|
|
|
+import com.spotify.docker.client.exceptions.DockerException;
|
|
|
+import io.minio.errors.*;
|
|
|
+import io.renren.modules.sys.controller.algs.algTrainController;
|
|
|
+import io.renren.modules.sys.entity.algs.AlgTrain;
|
|
|
+import io.renren.modules.sys.entity.algs.Algorithm;
|
|
|
+import io.renren.modules.sys.service.AlgTrainService;
|
|
|
+import io.renren.modules.sys.service.AlgsService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+//import com.example.backend.model.MessageStatus;
|
|
|
+//import com.example.backend.model.Position;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.security.InvalidKeyException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class DataReaderListenerImpl extends DDS._DataReaderListenerLocalBase {
|
|
|
+
|
|
|
+ private int num_msgs = 0;
|
|
|
+ public int isInit = 0;
|
|
|
+ public int isRecall = 0;
|
|
|
+ public int isTeam = 0;
|
|
|
+ public int isRequest = 0;
|
|
|
+ public int versionID = 1;
|
|
|
+ public String text = "";
|
|
|
+ private static final int N_EXPECTED = 40;
|
|
|
+ private ArrayList<Boolean> counts = new ArrayList<Boolean>(N_EXPECTED);
|
|
|
+// public Map<String, Position> positionMap = new ConcurrentHashMap<>();
|
|
|
+// public Map<String, Position> radarPositionMap = new ConcurrentHashMap<>();
|
|
|
+// public Map<String, List<String>> coopTeamMap = new ConcurrentHashMap<>();
|
|
|
+ public final Map<String, List<io.renren.modules.sys.entity.Message>> messageList = new ConcurrentHashMap<>();
|
|
|
+ public Map<String, AlgTrain> algMap = new ConcurrentHashMap<>();
|
|
|
+// public Map<String, MessageStatus> messageStatusMap = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ AlgTrainService algTrainService;
|
|
|
+ @Autowired
|
|
|
+ private io.renren.modules.sys.controller.algs.algTrainController algTrainController;
|
|
|
+
|
|
|
+ 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;
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+
|
|
|
+ // 定义格式(例如:yyyy-MM-dd HH:mm:ss)
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ // 格式化时间
|
|
|
+ String formattedDateTime = now.format(formatter);
|
|
|
+ if(mh.value.subject.equals("1")){
|
|
|
+ if(isInit==1){
|
|
|
+ System.out.println("已完成初始化,丢弃");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //收到初始化消息 完成初始化
|
|
|
+ isInit = 1;
|
|
|
+ String message = mh.value.text;
|
|
|
+ String[] messageList = message.split("\n");
|
|
|
+ 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();
|
|
|
+// p.coopID = s[1];
|
|
|
+// p.jaming = s[2];
|
|
|
+// p.isReal = s[3];
|
|
|
+// p.x = Double.parseDouble(s[4]);
|
|
|
+// p.y = Double.parseDouble(s[5]);
|
|
|
+// 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.x = Double.parseDouble(s[4]);
|
|
|
+// p.y = Double.parseDouble(s[5]);
|
|
|
+// p.z = Double.parseDouble(s[6]);
|
|
|
+// radarPositionMap.put(s[0],p);
|
|
|
+ }
|
|
|
+ //回复初始化应答
|
|
|
+ isRecall = 1;
|
|
|
+ }
|
|
|
+ if(mh.value.subject.equals("3")){
|
|
|
+ //收到平台位置信息
|
|
|
+ if(isInit==0){
|
|
|
+ System.out.println("未完成初始化,丢弃");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String message = mh.value.text;
|
|
|
+ String[] messageList = message.split("\n");
|
|
|
+ for(int i=1;i<messageList.length;i++){
|
|
|
+ String[] s = messageList[i].split(" ");
|
|
|
+// Position p = new Position();
|
|
|
+// p.coopID = positionMap.get(s[0]).coopID;
|
|
|
+// p.jaming = positionMap.get(s[0]).jaming;
|
|
|
+// p.isReal = positionMap.get(s[0]).isReal;
|
|
|
+// p.x = Double.parseDouble(s[1]);
|
|
|
+// p.y = Double.parseDouble(s[2]);
|
|
|
+// p.z = Double.parseDouble(s[3]);
|
|
|
+// positionMap.put(s[0],p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(mh.value.subject.equals("2")){
|
|
|
+ if(mh.value.text.equals("4")){
|
|
|
+ resetAll();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(mh.value.subject.equals("5")){
|
|
|
+ //收到雷达脉冲消息
|
|
|
+ String[] s = mh.value.from.split(" ");
|
|
|
+ String recivier = s[2];
|
|
|
+ String sender = s[0];
|
|
|
+// List<com.example.backend.model.Message> list = messageList.get(recivier)==null ? new ArrayList<>() : messageList.get(recivier);
|
|
|
+// list.add(new com.example.backend.model.Message(formattedDateTime,sender,"雷达脉冲",mh.value.text,"0"));
|
|
|
+// messageList.put(recivier,list);
|
|
|
+
|
|
|
+ }
|
|
|
+ if(mh.value.subject.equals("6")){
|
|
|
+ //收到电子干扰消息
|
|
|
+ String[] s = mh.value.from.split(" ");
|
|
|
+ String recivier = s[2];
|
|
|
+ String sender = s[0];
|
|
|
+// List<com.example.backend.model.Message> list = messageList.get(recivier)==null ? new ArrayList<>() : messageList.get(recivier);
|
|
|
+// list.add(new com.example.backend.model.Message(formattedDateTime,sender,"电子干扰",mh.value.text,"0"));
|
|
|
+// messageList.put(recivier,list);
|
|
|
+
|
|
|
+ }
|
|
|
+ if(mh.value.subject.equals("7")){
|
|
|
+ //收到综合情报消息
|
|
|
+ String[] s = mh.value.from.split(" ");
|
|
|
+ String recivier = s[2];
|
|
|
+ String sender = s[0];
|
|
|
+// List<com.example.backend.model.Message> list = messageList.get(recivier)==null ? new ArrayList<>() : messageList.get(recivier);
|
|
|
+// list.add(new com.example.backend.model.Message(formattedDateTime,sender,"综合情报",mh.value.text,"0"));
|
|
|
+// messageList.put(recivier,list);
|
|
|
+
|
|
|
+ }
|
|
|
+ if(mh.value.subject.equals("4")){
|
|
|
+ //收到网络分组信息
|
|
|
+ String message = mh.value.text;
|
|
|
+ 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++){
|
|
|
+ String[] s = messageList[i].split(" ");
|
|
|
+ String coopID = s[0];
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for(int j=2;j<s.length;j++){
|
|
|
+ list.add(s[j]);
|
|
|
+ }
|
|
|
+// coopTeamMap.put(coopID,list);
|
|
|
+ }
|
|
|
+ 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(" ");
|
|
|
+ for(int i=1;i<=Integer.parseInt(countList[0]);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(mh.value.subject.equals("11")){
|
|
|
+ // 使用算法文件消息
|
|
|
+ String message = mh.value.text;
|
|
|
+ String[] messageList = message.split("\n");
|
|
|
+ String[] countList = messageList[0].split(" ");
|
|
|
+ for(int i=1;i<=Integer.parseInt(countList[0]);i++){
|
|
|
+ String[] s = messageList[i].split(" ");
|
|
|
+ String platformID = s[0];
|
|
|
+ AlgTrain algTrain = algTrainService.selectByMissName(s[1]);
|
|
|
+ algMap.put(platformID,algTrain);
|
|
|
+// if (algTrain != null){
|
|
|
+// try {
|
|
|
+// algTrainController.startTraining(String.valueOf(algTrain.getAlgorithmTrainingId()));
|
|
|
+// } catch (Exception e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(mh.value.subject.equals("111")){
|
|
|
+ //收到算法请求信息
|
|
|
+ isRequest = 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 resetAll(){
|
|
|
+// this.positionMap.clear();
|
|
|
+// this.radarPositionMap.clear();
|
|
|
+// this.coopTeamMap.clear();
|
|
|
+ this.messageList.clear();
|
|
|
+// this.messageStatusMap.clear();
|
|
|
+ this.isInit = 0;
|
|
|
+ this.isRecall = 0;
|
|
|
+ this.isTeam = 0;
|
|
|
+ this.isRequest = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|