k1){
- k = 1e-8;
- }
- else{
- k=(k1-Math.abs(v))/(k1-k0);
- k=k*k*(k0/Math.abs(v));
- }
- P.set(i,i,P.get(i,i)*k); //P(i,i)=P(i,i)*k;
- }
-
- if(x_prev==0) {
- x_prev = X.get(0);
- }
- else if(Math.abs(x_prev-X.get(0))<0.1) {
- break;
- }
- x_prev = X.get(0);
- iterNum++;
- }
-
- //x=x0+x_prev;%求出的最后长度 初值+改正数
- return (x0+x_prev);
- }
-
-}
diff --git a/sec-beidou-rtcm/src/test/java/FocusCalculatorTest.java b/sec-beidou-rtcm/src/test/java/FocusCalculatorTest.java
index e155883e..385aba6a 100644
--- a/sec-beidou-rtcm/src/test/java/FocusCalculatorTest.java
+++ b/sec-beidou-rtcm/src/test/java/FocusCalculatorTest.java
@@ -22,8 +22,7 @@ import java.util.ListIterator;
classes = {
FocusCalculatorTest.class,
FocusCalculator1.class,
- FocusCalculator2.class,
- FocusCalculator3.class
+ FocusCalculator2.class
}
)
diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssGroupController.java b/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssGroupController.java
index 4b183186..a4043dab 100644
--- a/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssGroupController.java
+++ b/sec-beidou/src/main/java/com/imdroid/beidou/controller/GnssGroupController.java
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imdroid.beidou.common.HttpResult;
+import com.imdroid.secapi.client.RtcmClient;
import com.imdroid.secapi.dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -18,9 +19,10 @@ public class GnssGroupController extends BasicController {
GnssGroupMapper gnssGroupMapper;
@Autowired
GnssGroupCalcMapper gnssGroupCalcMapper;
-
@Autowired
GnssDeviceMapper deviceMapper;
+ @Autowired
+ RtcmClient rtcmClient;
/********* 推送页面 *********/
@RequestMapping("/page/table/gnss_add_group")
@@ -125,7 +127,10 @@ public class GnssGroupController extends BasicController {
}
if (num == 0) {
return HttpResult.failed();
- } else return HttpResult.ok();
+ } else{
+ rtcmClient.groupParamChanged();
+ return HttpResult.ok();
+ }
}
@PostMapping("/gnss/group/delete_calc")
@@ -141,7 +146,10 @@ public class GnssGroupController extends BasicController {
int num = gnssGroupCalcMapper.deleteById(del_id);
if (num == 0) {
return HttpResult.failed();
- } else return HttpResult.ok();
+ } else{
+ rtcmClient.groupParamChanged();
+ return HttpResult.ok();
+ }
}
}
diff --git a/sec-beidou/src/main/java/com/imdroid/beidou/task/DatasetCleaner.java b/sec-beidou/src/main/java/com/imdroid/beidou/task/DatasetCleaner.java
index ec6902a1..70540dbf 100644
--- a/sec-beidou/src/main/java/com/imdroid/beidou/task/DatasetCleaner.java
+++ b/sec-beidou/src/main/java/com/imdroid/beidou/task/DatasetCleaner.java
@@ -76,7 +76,7 @@ public class DatasetCleaner {
void checkFwdDataset(){
long before = System.currentTimeMillis() -
- (long)365 * 24 * 3600 * 1000;
+ (long)180 * 24 * 3600 * 1000;
Timestamp t = new Timestamp(before);
int count = fwdRecordMapper.deleteTimeBefore(t);
log.info("clean fwd dataset num: "+count);
diff --git a/sec-beidou/src/main/resources/templates/page/gnss_data_calc.html b/sec-beidou/src/main/resources/templates/page/gnss_data_calc.html
index 5f36c65f..4bb5262a 100644
--- a/sec-beidou/src/main/resources/templates/page/gnss_data_calc.html
+++ b/sec-beidou/src/main/resources/templates/page/gnss_data_calc.html
@@ -92,9 +92,9 @@
{field: 'rpose', title: '相对东', templet: "{{d.rpose==null?'':d.rpose.toFixed(2)}}
"},
{field: 'rposn', title: '相对北', templet: "{{d.rposn==null?'':d.rposn.toFixed(2)}}
"},
{field: 'rposd', title: '相对天', templet: "{{d.rposd==null?'':d.rposd.toFixed(2)}}
"},
- {field: 'auxe', title: '辅助东', templet: "{{d.auxe==null?'':d.auxe.toFixed(2)}}
"},
- {field: 'auxn', title: '辅助北', templet: "{{d.auxn==null?'':d.auxn.toFixed(2)}}
"},
- {field: 'auxd', title: '辅助天', templet: "{{d.auxd==null?'':d.auxd.toFixed(2)}}
"},
+ //{field: 'auxe', title: '辅助东', templet: "{{d.auxe==null?'':d.auxe.toFixed(2)}}
"},
+ //{field: 'auxn', title: '辅助北', templet: "{{d.auxn==null?'':d.auxn.toFixed(2)}}
"},
+ //{field: 'auxd', title: '辅助天', templet: "{{d.auxd==null?'':d.auxd.toFixed(2)}}
"},
{field: 'enabled', title: '有效',templet: '#enabledTrans'},
{field: 'pps', title: '平均延迟'}
];
diff --git a/sec-test-device/pom.xml b/sec-test-device/pom.xml
new file mode 100644
index 00000000..271a8f75
--- /dev/null
+++ b/sec-test-device/pom.xml
@@ -0,0 +1,128 @@
+
+
+ 4.0.0
+
+ com.imdroid
+ security-monitor
+ 1.0-SNAPSHOT
+
+
+ sec-test-device
+
+
+ 11
+ 11
+ UTF-8
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ true
+
+
+
+ org.slf4j
+ slf4j-api
+
+
+ ch.qos.logback
+ logback-classic
+
+
+ io.netty
+ netty-all
+ 4.1.78.Final
+
+
+ com.google.code.gson
+ gson
+ 2.9.1
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.13
+
+
+
+ com.imdroid
+ sec-api
+ 1.0-SNAPSHOT
+
+
+ com.imdroid
+ sec-common
+ 1.0-SNAPSHOT
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ com.alibaba
+ fastjson
+ 1.2.76
+
+
+
+ org.eclipse.paho
+ org.eclipse.paho.client.mqttv3
+ 1.2.5
+
+
+
+
+ ${project.artifactId}
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 11
+ 11
+
+
+
+
+
+
+
+ central
+ ali-mirror
+ https://maven.aliyun.com/repository/central
+
+ true
+
+
+ true
+
+
+
+
+
\ No newline at end of file
diff --git a/sec-test-device/src/main/java/com/imdroid/beidou/test_device/BeidouTestApp.java b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/BeidouTestApp.java
new file mode 100644
index 00000000..fcf765b9
--- /dev/null
+++ b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/BeidouTestApp.java
@@ -0,0 +1,24 @@
+package com.imdroid.beidou.test_device;
+
+import com.imdroid.beidou.test_device.task.BeidouDevice;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ComponentScan;
+
+
+/**
+ * @author Layton
+ * @date 2023/1/31 20:33
+ */
+@SpringBootApplication(scanBasePackages = {"com.imdroid"})
+@ComponentScan({"com.imdroid.*"})
+public class BeidouTestApp {
+
+ public static void main(String[] args) {
+
+ SpringApplication.run(BeidouTestApp.class, args);
+ BeidouDevice beidouDevice = new BeidouDevice();
+ beidouDevice.connectServer();
+ beidouDevice.run();
+ }
+}
diff --git a/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/TCPClient.java b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/TCPClient.java
new file mode 100644
index 00000000..81ebc18e
--- /dev/null
+++ b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/TCPClient.java
@@ -0,0 +1,127 @@
+package com.imdroid.beidou.test_device.service;
+
+import com.imdroid.common.util.ThreadManager;
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.*;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioSocketChannel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+import java.time.LocalDateTime;
+import java.util.concurrent.TimeUnit;
+
+public class TCPClient {
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ private String host;
+
+ private int port;
+
+ private Bootstrap bootstrap;
+ private EventLoopGroup group;
+ private Channel channel;
+ LocalDateTime connectTime = LocalDateTime.now();
+ TCPListener listener;
+
+ public void start() {
+ new Thread(this::connect, "forwarder tcp-client").start();
+ }
+
+ public void init(String dest_addr, int dest_port, TCPListener listener) {
+ this.host = dest_addr;
+ this.port = dest_port;
+ this.listener = listener;
+
+ //客户端需要一个事件循环组
+ group = new NioEventLoopGroup();
+ //创建客户端启动对象
+ // bootstrap 可重用, 只需在NettyClient实例化的时候初始化即可.
+ bootstrap = new Bootstrap();
+ bootstrap.group(group)
+ .channel(NioSocketChannel.class)
+ .handler(new ChannelInitializer() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ //加入处理器
+ ch.pipeline().addLast(new TcpMessageHandler(TCPClient.this));
+ }
+ });
+ }
+
+ public void connect() {
+ logger.info("netty client starting");
+ //启动客户端去连接服务器端
+ try {
+ ChannelFuture cf = bootstrap.connect(host, port);
+ cf.addListener(new ChannelFutureListener() {
+ @Override
+ public void operationComplete(ChannelFuture future) throws Exception {
+ if (!future.isSuccess()) {
+ //重连交给后端线程执行
+ future.channel().eventLoop().schedule(() -> {
+ logger.info("tcp client reconnect");
+ try {
+ connect();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }, 5000, TimeUnit.MILLISECONDS);
+ } else {
+ logger.info("tcp client start success!");
+ }
+ }
+ });
+ //对通道关闭进行监听
+ this.channel = cf.channel();
+ this.channel.closeFuture().sync();
+ } catch (Exception e) {
+ logger.error("netty client error:", e);
+ }
+ }
+
+ public void writeAndFlush(String json) {
+ ByteBuf sendBuffer = Unpooled.buffer();
+ sendBuffer.writeBytes(json.getBytes(StandardCharsets.UTF_8));
+ channel.writeAndFlush(sendBuffer).addListener(future -> {
+ if (future.isSuccess()) {
+ logger.info("send to tcp:"+host+" succeed.");
+ } else {
+ logger.info("send to tcp:"+host+" failed.");
+ if(listener!=null){
+ listener.onMessage("failed");
+ }
+ }
+ });
+ }
+
+ public void onConnected(){
+ connectTime = LocalDateTime.now();
+ }
+
+ public void onDisconnect(){
+ if(connectTime.isBefore(LocalDateTime.now().minusMinutes(1))) {
+ connect();
+ }
+ else{
+ ThreadManager.getScheduledThreadPool().schedule(() -> {
+ try {
+ connect();
+ } catch (Exception e) {
+ logger.error(e.toString());
+ }
+ },60, TimeUnit.SECONDS);
+ }
+ }
+
+ public void onMessage(String msg){
+ if(listener!=null){
+ listener.onMessage(msg);
+ }
+ }
+
+}
diff --git a/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/TCPListener.java b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/TCPListener.java
new file mode 100644
index 00000000..cf1e9d10
--- /dev/null
+++ b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/TCPListener.java
@@ -0,0 +1,7 @@
+package com.imdroid.beidou.test_device.service;
+
+public interface TCPListener {
+ void onConnected();
+ void onDisconnect();
+ void onMessage(String msg);
+}
diff --git a/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/TcpMessageHandler.java b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/TcpMessageHandler.java
new file mode 100644
index 00000000..1158427c
--- /dev/null
+++ b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/TcpMessageHandler.java
@@ -0,0 +1,52 @@
+package com.imdroid.beidou.test_device.service;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.Charset;
+
+/**
+ * @author Layton
+ * @date 2023/2/18 20:36
+ */
+public class TcpMessageHandler extends SimpleChannelInboundHandler {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ private final TCPClient tcpClient;
+
+ public TcpMessageHandler(TCPClient tcpClient) {
+ this.tcpClient = tcpClient;
+ }
+
+ @Override
+ protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf buf) throws Exception {
+ String msg = buf.toString(Charset.defaultCharset());
+ tcpClient.onMessage(msg);
+ if (logger.isDebugEnabled()) {
+ logger.debug("receive server message:" + msg);
+ }
+ }
+
+ @Override
+ public void channelActive(ChannelHandlerContext ctx) throws Exception {
+ logger.info("tcp channel active");
+ tcpClient.onConnected();
+ }
+
+ @Override
+ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+ logger.info("tcp channel inactive");
+ tcpClient.onDisconnect();
+ }
+
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ logger.error("TcpMessageHandler error: {}", cause.toString());
+ ctx.close();
+ }
+
+}
diff --git a/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/UDPClient.java b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/UDPClient.java
new file mode 100644
index 00000000..3ee125a8
--- /dev/null
+++ b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/service/UDPClient.java
@@ -0,0 +1,41 @@
+package com.imdroid.beidou.test_device.service;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+public class UDPClient {
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ private DatagramSocket socket;
+
+ private InetAddress inetAddress;
+
+ private String host;
+
+ private int port;
+
+ public void init(String host, int port) {
+ this.host = host;
+ this.port = port;
+ try {
+ logger.info("UDP client init "+host + ":" + port);
+ this.socket = new DatagramSocket();
+ this.inetAddress = InetAddress.getByName(host);
+ } catch (Exception e) {
+ logger.error("初始化udp客户端失败:", e);
+ }
+ }
+
+ public void sendData(byte[] data) {
+ try {
+ DatagramPacket packet = new DatagramPacket(data, data.length, inetAddress, port);
+ socket.send(packet);
+ } catch (Exception e) {
+ logger.error("udp推送gnss数据异常:", e);
+ }
+ }
+}
diff --git a/sec-test-device/src/main/java/com/imdroid/beidou/test_device/task/BeidouDevice.java b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/task/BeidouDevice.java
new file mode 100644
index 00000000..ed58de38
--- /dev/null
+++ b/sec-test-device/src/main/java/com/imdroid/beidou/test_device/task/BeidouDevice.java
@@ -0,0 +1,87 @@
+package com.imdroid.beidou.test_device.task;
+
+import com.imdroid.beidou.test_device.service.UDPClient;
+import com.imdroid.common.util.ByteUtil;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class BeidouDevice {
+ private String host="127.0.0.1";
+
+ private int port=9903;
+
+ UDPClient udpClient;
+ public void connectServer(){
+ udpClient = new UDPClient();
+ udpClient.init(host, port);
+ }
+
+ public void run(){
+ try{
+ //execute("C:\\Users\\wd\\Desktop\\log\\b562_2412270_1xx.log");
+ //execute("C:\\Users\\wd\\Desktop\\log\\b562_2412270_2xx.log");
+ //execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_1xx.log");
+ //execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_2xx.log");
+ //execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_3xx.log");
+ //execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_4xx.log");
+ //execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_5xx.log");
+ //execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_6xx.log");
+
+ execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_0416_1.log");
+ execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_0416_2.log");
+ execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_0416_1xx.log");
+ execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_0416_2xx.log");
+ execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_0416_3xx.log");
+ execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_0416_4xx.log");
+ execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_0416_5xx.log");
+ execute("C:\\Users\\wd\\Desktop\\log\\b562_2412254_0416_6xx.log");
+ }
+ catch (Exception e){
+
+ }
+ System.out.println("finish!");
+ }
+
+ public void execute(String dataFileName) throws IOException {
+ FileReader fr=null;
+ BufferedReader br=null;
+ try {
+ fr = new FileReader(dataFileName);
+ br = new BufferedReader(fr);
+ String line = "";
+ String[] arrs = null;
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+
+ long lastTime = 0;
+ int b562Count = 0;
+ int cycleCount = 0;
+
+ while ((line = br.readLine()) != null) {
+ arrs = line.split(" ");
+ if(arrs.length != 3) continue;
+ Date time = sdf.parse(arrs[0] + " " + arrs[1]);
+
+ if (lastTime!=0 && Math.abs(time.getTime() - lastTime) > 60 * 1000) {//超过1分钟为一个周期
+ Thread.sleep(30 * 1000);
+ cycleCount++;
+ System.out.println(time+" cycle "+cycleCount+", b562 num "+b562Count);
+ }
+ udpClient.sendData(ByteUtil.hexStringTobyte(arrs[2]));
+ b562Count++;
+ lastTime = time.getTime();
+ Thread.sleep(100);
+ }
+ br.close();
+ fr.close();
+ }
+ catch (Exception e){
+ e.printStackTrace();
+ if(br!=null) br.close();
+ if(fr!=null) fr.close();
+ }
+ }
+}
diff --git a/sec-test-device/src/main/resources/application.properties b/sec-test-device/src/main/resources/application.properties
new file mode 100644
index 00000000..9ac62967
--- /dev/null
+++ b/sec-test-device/src/main/resources/application.properties
@@ -0,0 +1,22 @@
+server.port=9916
+server.servlet.context-path=/gnss
+
+spring.application.name=test-gnss
+spring.application.build=20240106
+
+spring.jpa.show-sql = true
+spring.jpa.hibernate.ddl-auto = none
+spring.jpa.database-platform = org.hibernate.dialect.MySQLDialect
+spring.datasource.url = jdbc:mysql://localhost:3306/beidou?characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+spring.datasource.username = admin
+spring.datasource.password = DBMgr_2022
+spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
+
+spring.jackson.dateFormat = yyyy-MM-dd HH:mm:ss
+spring.jackson.time-zone = GMT+8
+
+app.format.date = yyyy-MM-dd
+app.format.time = HH:mm:ss
+app.format.datetime = yyyy-MM-dd HH:mm:ss
+
+mybatis-plus.configuration.map-underscore-to-camel-case=false