北斗数据流SDK
更新时间:2023-10-28
注意
北斗数据流SDK For Java 采用springboot集成北斗数据流的方法,支持几行代码可以创建一个TCP服务或Ntrip服务。
Maven仓库配置
步骤一:设置仓库凭证 请在settings.xml文件中设置以下仓库的访问凭证,通常settings.xml在$HOME/.m2/文件目录下。
<servers>
<server>
<id>navmg-public</id>
<username>xxxxxxxxxxxxxxxxxx</username>
<password>xxxxxxxxxxx</password>
</server>
</servers>
<servers>
<server>
<id>navmg-public</id>
<username>xxxxxxxxxxxxxxxxxx</username>
<password>xxxxxxxxxxx</password>
</server>
</servers>
凭证获取
username
为仓库的用户名 password
为仓库的密码
请联系我们的相关开发人员获取凭证信息
步骤二:配置仓库和包信息 在settings.xml文件节点中加入对应的仓库使用地址。
<repositories>
<repository>
<id>navmg-public</id>
<url>http://maven.navmg.com/repository/navmg-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<repositories>
<repository>
<id>navmg-public</id>
<url>http://maven.navmg.com/repository/navmg-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
步骤三:配置仓库镜像地址 在settings.xml文件节点中加入对应的仓库使用地址。
<mirrors>
<mirror>
<id>navmg-public</id>
<mirrorOf>*</mirrorOf>
<name>Navmg Readable Name for this Mirror.</name>
<url>http://maven.navmg.com/repository/navmg-public/</url>
</mirror>
</mirrors>
<mirrors>
<mirror>
<id>navmg-public</id>
<mirrorOf>*</mirrorOf>
<name>Navmg Readable Name for this Mirror.</name>
<url>http://maven.navmg.com/repository/navmg-public/</url>
</mirror>
</mirrors>
Maven下载SDK
说明
请先参考客户端的环境配置,配置maven仓库的地址,再进行下面的操作教程
在你的java项目pom.xml
文件<denpendencies></denpendencies>
节点中加入你要引用的文件信息
<dependencies>
<dependency>
<groupId>com.xcbd</groupId>
<artifactId>rtlogging</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.xcbd</groupId>
<artifactId>rtlogging</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
SDK使用教程
1、项目中application.properties
文件中添加配置,配置信息来自服务端的基础环境
rtlogging.caster-enable=true
rtlogging.caster-server-port=9090
rtlogging.caster-client-port=9095
rtlogging.mtrip-enable=false
rtlogging.mtrip-port=9010
rtlogging.rtcm-path=/app/raw/
rtlogging.caster-enable=true
rtlogging.caster-server-port=9090
rtlogging.caster-client-port=9095
rtlogging.mtrip-enable=false
rtlogging.mtrip-port=9010
rtlogging.rtcm-path=/app/raw/
说明
rtlogging.caster-enable
是否开启ntrip caster服务
rtlogging.caster-server-port
ntrip caster服务端的监听端口
rtlogging.caster-client-port
ntrip caster客户端的监听端口
rtlogging.mtrip-enable
是否开启mtrip服务
rtlogging.mtrip-port
mtrip服务监听的端口
rtlogging.rtcm-path
北斗数据流文件存储的路径
2、代码中直接配置引用
import org.springframework.beans.factory.annotation.Autowired;
@Autowired
private TcpServer tcpServer;
@Autowired
private TcpClient tcpClient;
@Autowired
private NtripClient ntripClient;
@Autowired
private NtripClientCaster ntripClientCaster;
@Autowired
private NtripServerCaster ntripServerCaster;
import org.springframework.beans.factory.annotation.Autowired;
@Autowired
private TcpServer tcpServer;
@Autowired
private TcpClient tcpClient;
@Autowired
private NtripClient ntripClient;
@Autowired
private NtripClientCaster ntripClientCaster;
@Autowired
private NtripServerCaster ntripServerCaster;
3、调用方法
ntrip caster相关的调用方法
// 初始化监听ntrip caster server 端口
this.ntripServerCaster.init(this.rtloggingProperties.getCasterServerPort());
// 初始化监听ntrip caster client 端口
this.ntripClientCaster.init(this.rtloggingProperties.getCasterClientPort());
// 设置ntrip caster client 认证回调
this.ntripClientCaster.setINtripAuthCallback((mountPoint, username, password) -> StringUtils.isNotBlank(mountPoint) && StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password) && StringUtils.equals(mountPoint, password) && StringUtils.equals(username, password));
// 设置ntrip caster server 认证回调
this.ntripServerCaster.setINtripServerAuthCallback((mountPoint, password) -> StringUtils.isNotBlank(mountPoint) && StringUtils.isNotBlank(password) && StringUtils.equals(mountPoint, password));
// 设置ntrip caster client 和 ntrip caster server之间相互绑定
this.ntripServerCaster.setNtripClientCaster(this.ntripClientCaster);
// 设置ntrip caster server数据接收回调
this.ntripServerCaster.setIDataCallback(this.fileService::writeHourRtcmFile);
// 初始化监听ntrip caster server 端口
this.ntripServerCaster.init(this.rtloggingProperties.getCasterServerPort());
// 初始化监听ntrip caster client 端口
this.ntripClientCaster.init(this.rtloggingProperties.getCasterClientPort());
// 设置ntrip caster client 认证回调
this.ntripClientCaster.setINtripAuthCallback((mountPoint, username, password) -> StringUtils.isNotBlank(mountPoint) && StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password) && StringUtils.equals(mountPoint, password) && StringUtils.equals(username, password));
// 设置ntrip caster server 认证回调
this.ntripServerCaster.setINtripServerAuthCallback((mountPoint, password) -> StringUtils.isNotBlank(mountPoint) && StringUtils.isNotBlank(password) && StringUtils.equals(mountPoint, password));
// 设置ntrip caster client 和 ntrip caster server之间相互绑定
this.ntripServerCaster.setNtripClientCaster(this.ntripClientCaster);
// 设置ntrip caster server数据接收回调
this.ntripServerCaster.setIDataCallback(this.fileService::writeHourRtcmFile);
ntrip相关的调用方法
// 创建ntrip对象
NtripBean ntripBean = NtripBean.builder().ip(deviceRtcm.getIp()).port(deviceRtcm.getPort()).stationName(deviceRtcm.getSncode().trim()).mountPoint(deviceRtcm.getMountPoint()).username(deviceRtcm.getUsername()).password(deviceRtcm.getPassword()).altitude(deviceRtcm.getAltitude()).longitude(deviceRtcm.getLongitude()).latitude(deviceRtcm.getLatitude()).gga(null != deviceRtcm.getLatitude() && null != deviceRtcm.getLongitude()).build();
// 停止ntrip协议
this.ntripClient.stop(ntripBean.getStationName());
// 启动ntrip协议
this.ntripClient.addNtripClient(ntripBean);
// 设置ntrip数据回调
this.ntripClient.setDataCallback((sncode, bytes) -> {
String data = new String(bytes);
if (StringUtils.contains(data, "result")) {
log.error("指令回复:{}", data);
this.cmdCallback(data);
return;
}
this.fileService.writeHourRtcmFile(sncode, bytes);
});
// 创建ntrip对象
NtripBean ntripBean = NtripBean.builder().ip(deviceRtcm.getIp()).port(deviceRtcm.getPort()).stationName(deviceRtcm.getSncode().trim()).mountPoint(deviceRtcm.getMountPoint()).username(deviceRtcm.getUsername()).password(deviceRtcm.getPassword()).altitude(deviceRtcm.getAltitude()).longitude(deviceRtcm.getLongitude()).latitude(deviceRtcm.getLatitude()).gga(null != deviceRtcm.getLatitude() && null != deviceRtcm.getLongitude()).build();
// 停止ntrip协议
this.ntripClient.stop(ntripBean.getStationName());
// 启动ntrip协议
this.ntripClient.addNtripClient(ntripBean);
// 设置ntrip数据回调
this.ntripClient.setDataCallback((sncode, bytes) -> {
String data = new String(bytes);
if (StringUtils.contains(data, "result")) {
log.error("指令回复:{}", data);
this.cmdCallback(data);
return;
}
this.fileService.writeHourRtcmFile(sncode, bytes);
});
TCP Server相关的调用方法
// 创建tcp server对象
TcpBean tcpBean = TcpBean.builder().port(deviceRtcm.getPort()).stationName(deviceRtcm.getSncode().trim()).build();
// 停止tcp server协议
this.tcpServer.stop(tcpBean.getStationName());
// 启动tcp server协议
this.tcpServer.addTcpServer(tcpBean);
// 设置tcp server数据回调
this.tcpServer.setDataCallback((sncode, bytes) -> {
String data = new String(bytes);
if (StringUtils.contains(data, "result")) {
log.error("指令回复:{}", data);
this.cmdCallback(data);
return;
}
this.fileService.writeHourRtcmFile(sncode, bytes);
});
// 创建tcp server对象
TcpBean tcpBean = TcpBean.builder().port(deviceRtcm.getPort()).stationName(deviceRtcm.getSncode().trim()).build();
// 停止tcp server协议
this.tcpServer.stop(tcpBean.getStationName());
// 启动tcp server协议
this.tcpServer.addTcpServer(tcpBean);
// 设置tcp server数据回调
this.tcpServer.setDataCallback((sncode, bytes) -> {
String data = new String(bytes);
if (StringUtils.contains(data, "result")) {
log.error("指令回复:{}", data);
this.cmdCallback(data);
return;
}
this.fileService.writeHourRtcmFile(sncode, bytes);
});
TCP Client相关的调用方法
// 创建tcp client对象
TcpBean tcpBean = TcpBean.builder().ip(deviceRtcm.getIp()).port(deviceRtcm.getPort()).stationName(deviceRtcm.getSncode().trim()).build();
// 停止tcp client协议
this.tcpClient.stop(tcpBean.getStationName());
// 启动tcp client协议
this.tcpClient.addTcpClient(tcpBean);
// 设置tcp client数据回调
this.tcpClient.setDataCallback((sncode, bytes) -> {
String data = new String(bytes);
if (StringUtils.contains(data, "result")) {
log.error("指令回复:{}", data);
this.cmdCallback(data);
return;
}
this.fileService.writeHourRtcmFile(sncode, bytes);
});
// 创建tcp client对象
TcpBean tcpBean = TcpBean.builder().ip(deviceRtcm.getIp()).port(deviceRtcm.getPort()).stationName(deviceRtcm.getSncode().trim()).build();
// 停止tcp client协议
this.tcpClient.stop(tcpBean.getStationName());
// 启动tcp client协议
this.tcpClient.addTcpClient(tcpBean);
// 设置tcp client数据回调
this.tcpClient.setDataCallback((sncode, bytes) -> {
String data = new String(bytes);
if (StringUtils.contains(data, "result")) {
log.error("指令回复:{}", data);
this.cmdCallback(data);
return;
}
this.fileService.writeHourRtcmFile(sncode, bytes);
});