Bladeren bron

星历数据简化为byte[]数组

tags/v1.0.0^2
林万龙 3 jaren geleden
bovenliggende
commit
4fb557eaf6
6 gewijzigde bestanden met toevoegingen van 131 en 71 verwijderingen
  1. +56
    -20
      src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java
  2. +41
    -25
      src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java
  3. +23
    -21
      src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java
  4. +8
    -2
      src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java
  5. +1
    -1
      src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java
  6. +2
    -2
      src/main/resources/application.properties

+ 56
- 20
src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java Bestand weergeven

@@ -1,5 +1,6 @@
package com.telpo.dipperposition.handler;

import com.telpo.dipperposition.common.HexConvert;
import com.telpo.dipperposition.config.PositionConfig;
import com.telpo.dipperposition.service.IDipperAstPosAsyncTaskService;
import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService;
@@ -73,10 +74,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
//通知客户端链接建立成功
// 默认返回取得时间成功
// String ackAckCheckRef = "233E0101020004020A1D";
String ackAckCheckRef = "23 3E 01 01 02 00 04 21 29 3C";
ByteBuf buf = Unpooled.buffer(ackAckCheckRef.getBytes().length);
buf.writeBytes(ackAckCheckRef.getBytes(CharsetUtil.UTF_8));
ctx.writeAndFlush(buf);
//String ackAckCheckRef = "23 3E 01 01 02 00 04 21 29 3C";
//ByteBuf buf = Unpooled.buffer(ackAckCheckRef.getBytes().length);
//buf.writeBytes(ackAckCheckRef.getBytes(CharsetUtil.UTF_8));
//ctx.writeAndFlush(buf);
}


@@ -112,9 +113,14 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime();
//log.debug(channelAns);
if (channelAns != null) {
buf = bba.buffer(channelAns.getBytes().length);
// buf = bba.buffer(channelAns.getBytes().length);
byte[] returnBytes = getReturnBytes(channelAns);
buf = bba.buffer(returnBytes.length + 4);
//Unpooled.buffer(channelAns.getBytes().length);
buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8));
// buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8));
buf.writeBytes(returnBytes);
buf.writeBytes(getCheckSumBytes(channelAns));
buf.writeBytes(getReturnBytes());
ctx.write(buf);
ctx.flush();
}
@@ -124,9 +130,15 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress);
//log.debug(channelAns);
if (channelAns != null) {
buf = bba.buffer(channelAns.getBytes().length);
// buf = bba.buffer(channelAns.getBytes().length);
byte[] returnBytes = getReturnBytes(channelAns);
buf = bba.buffer(returnBytes.length + 4);
//Unpooled.buffer(channelAns.getBytes().length);
buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8));
// buf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8));
buf.writeBytes(returnBytes);
buf.writeBytes(getCheckSumBytes(channelAns));
buf.writeBytes(getReturnBytes());

ctx.write(buf);
ctx.flush();
}
@@ -154,23 +166,23 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
channelAns = nettyServerHandler.dipperTimeAsyncTaskService.pushAstTime();

if (channelAns != null) {
log.debug("Time Buffer Length is:" + channelAns.getBytes().length);
ByteBuf channelTimeAnsBuf = bba.buffer(channelAns.getBytes().length);
//Unpooled.buffer(channelAns.getBytes().length);
channelTimeAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8));
// compositeByteBuf.addComponent(channelTimeAnsBuf);
ctx.write(channelTimeAnsBuf);
byte[] returnBytes = getReturnBytes(channelAns);
buf = bba.buffer(returnBytes.length + 4);
buf.writeBytes(returnBytes);
buf.writeBytes(getCheckSumBytes(channelAns));
buf.writeBytes(getReturnBytes());
ctx.write(buf);
ctx.flush();
}
channelAns = nettyServerHandler.dipperAstPosAsyncTaskService.pushAstPos(ipAddress);

if (channelAns != null) {
log.debug("Pos Buffer Length is:" + channelAns.getBytes().length);
ByteBuf channelPosAnsBuf = bba.buffer(channelAns.getBytes().length);
//Unpooled.buffer(channelAns.getBytes().length);
channelPosAnsBuf.writeBytes(channelAns.getBytes(CharsetUtil.UTF_8));
//compositeByteBuf.addComponent(channelPosAnsBuf);
ctx.write(channelPosAnsBuf);
byte[] returnBytes = getReturnBytes(channelAns);
buf = bba.buffer(returnBytes.length + 4);
buf.writeBytes(returnBytes);
buf.writeBytes(getCheckSumBytes(channelAns));
buf.writeBytes(getReturnBytes());
ctx.write(buf);
ctx.flush();
}
byte[] returnBytes = nettyServerHandler.dipperDataAsyncTaskService.getAstEPH();
@@ -203,5 +215,29 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
ctx.close();
}

/*
* 取得byte数组
*/
private byte[] getReturnBytes(String astCmdBuf) {
return HexConvert.hexStringToBytes(astCmdBuf);
}

private byte[] getCheckSumBytes(String astCmdBuf) {
String checkSum = HexConvert.makeChecksum(astCmdBuf).toUpperCase();
StringBuffer astCheckSumBuf = new StringBuffer();
astCheckSumBuf.append(checkSum);
while (astCheckSumBuf.length()<4) {
astCheckSumBuf.insert(0,"0");
}
return getReturnBytes(astCheckSumBuf.toString());
//log.info(checkSum);
}


private byte[] getReturnBytes() {
String returnStr = "0D0A";
return getReturnBytes(returnStr);
}


}

+ 41
- 25
src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java Bestand weergeven

@@ -163,17 +163,15 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS
double lanValue = Double.parseDouble(lonStr) * 10000000;
long lanLongValue = Double.doubleToLongBits(lanValue);
if (lanLongValue < 0) {
// FFFFFFFF - 439C3270 + 1= BC63CD90(补码)
lanLongValue = lanLongValue + 4294967295L + 1;
}
double altValue = Double.parseDouble(altStr) * 10000000;
long altLongValue = Double.doubleToLongBits(altValue);
if (altLongValue < 0) {
// FFFFFFFF - 439C3270 + 1= BC63CD90(补码)
altLongValue = altLongValue + 4294967295L + 1;
}
// 小端模式补码
// FFFFFFFF - 439C3270 + 1= BC63CD90(补码)
lanLongValue = 4294967295L - lanLongValue + 1;
altLongValue = 4294967295L - altLongValue + 1;

// 数值换算举例(以经度举例。纬度、高度、位置精度换算方法一致):
// (1)经度数值为 113.431,则换算方法如下:
@@ -202,32 +200,50 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS
StringBuilder astPosCmdBuf = new StringBuilder();
astPosCmdBuf.append("233E0401");
astPosCmdBuf.append("1000");
astPosCmdBuf.append(HexConvert.encodeHEX(lanLongValue).toUpperCase());
astPosCmdBuf.append(HexConvert.encodeHEX(altLongValue).toUpperCase());


// 小端模式
String lanString = HexConvert.encodeHEX(lanLongValue).toUpperCase();
String altSting = HexConvert.encodeHEX(altLongValue).toUpperCase();
//astPosCmdBuf.append(HexConvert.encodeHEX(lanLongValue).toUpperCase());
astPosCmdBuf.append(lanString.substring(6,8));
astPosCmdBuf.append(lanString.substring(4,6));
astPosCmdBuf.append(lanString.substring(2,4));
astPosCmdBuf.append(lanString.substring(0,2));

//astPosCmdBuf.append(HexConvert.encodeHEX(altLongValue).toUpperCase());

astPosCmdBuf.append(altSting.substring(6,8));
astPosCmdBuf.append(altSting.substring(4,6));
astPosCmdBuf.append(altSting.substring(2,4));
astPosCmdBuf.append(altSting.substring(0,2));
astPosCmdBuf.append("70170000");
astPosCmdBuf.append("A0860100");

//log.info(astPosCmd);
String checkSum = HexConvert.makeChecksum(astPosCmdBuf.toString()).toUpperCase();
StringBuffer astCheckSumBuf = new StringBuffer();
astCheckSumBuf.append(checkSum);
while (astCheckSumBuf.length()<4) {
astCheckSumBuf.insert(0,"0");
}
checkSum = astCheckSumBuf.toString();
//log.info(checkSum);

byte[] astPosCmdBytes = HexConvert.hexStringToBytes(astPosCmdBuf.toString());
StringBuilder astPosCmdNewBuf = new StringBuilder();
for (byte astPosCmdByte : astPosCmdBytes) {
String s = Integer.toHexString(astPosCmdByte & 0xff);
if (s.length() < 2) {
astPosCmdNewBuf.append('0');
}
astPosCmdNewBuf.append(s + " ");
}
// String checkSum = HexConvert.makeChecksum(astPosCmdBuf.toString()).toUpperCase();
// StringBuffer astCheckSumBuf = new StringBuffer();
// astCheckSumBuf.append(checkSum);
// while (astCheckSumBuf.length()<4) {
// astCheckSumBuf.insert(0,"0");
// }
// checkSum = astCheckSumBuf.toString();
// //log.info(checkSum);
//
// byte[] astPosCmdBytes = HexConvert.hexStringToBytes(astPosCmdBuf.toString());
// StringBuilder astPosCmdNewBuf = new StringBuilder();
// for (byte astPosCmdByte : astPosCmdBytes) {
// String s = Integer.toHexString(astPosCmdByte & 0xff);
// if (s.length() < 2) {
// astPosCmdNewBuf.append('0');
// }
// astPosCmdNewBuf.append(s + " ");
// }
//
return astPosCmdBuf.toString();
//+ checkSum.substring(0,2) + " " + checkSum.substring(2,4);


return astPosCmdNewBuf.toString() + checkSum.substring(0,2) + " " + checkSum.substring(2,4);

}
}

+ 23
- 21
src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java Bestand weergeven

@@ -77,30 +77,32 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas
hexSecondString = "0" + hexSecondString;
}
astTimeCmdBuf.append(hexSecondString.toUpperCase());
astTimeCmdBuf.append("0000000000");
astTimeCmdBuf.append("00000000");
astTimeCmdBuf.append("005ED0B2");

byte[] astTimeCmdBytes = HexConvert.hexStringToBytes(astTimeCmdBuf.toString());
StringBuilder astTimeCmdNewBuf = new StringBuilder();
for(int i=0; i<astTimeCmdBytes.length; i++) {
String s = Integer.toHexString(astTimeCmdBytes[i] & 0xff);
if (s.length() < 2) {
astTimeCmdNewBuf.append('0');
}
astTimeCmdNewBuf.append(s + " ");
}

//log.info(astTimeCmd);
String checkSum = HexConvert.makeChecksum(astTimeCmdBuf.toString()).toUpperCase();
StringBuilder astCheckSumBuf = new StringBuilder();
astCheckSumBuf.append(checkSum);
while (astCheckSumBuf.length()<4) {
astCheckSumBuf.insert(0,"0");
}
checkSum = astCheckSumBuf.toString();
//log.info(checkSum);
return astTimeCmdBuf.toString();

return astTimeCmdNewBuf.toString() + checkSum.substring(0,2) + " " + checkSum.substring(2,4);
// byte[] astTimeCmdBytes = HexConvert.hexStringToBytes(astTimeCmdBuf.toString());
// StringBuilder astTimeCmdNewBuf = new StringBuilder();
// for(int i=0; i<astTimeCmdBytes.length; i++) {
// String s = Integer.toHexString(astTimeCmdBytes[i] & 0xff);
// if (s.length() < 2) {
// astTimeCmdNewBuf.append('0');
// }
// astTimeCmdNewBuf.append(s + " ");
// }
//
// //log.info(astTimeCmd);
// String checkSum = HexConvert.makeChecksum(astTimeCmdBuf.toString()).toUpperCase();
// StringBuilder astCheckSumBuf = new StringBuilder();
// astCheckSumBuf.append(checkSum);
// while (astCheckSumBuf.length()<4) {
// astCheckSumBuf.insert(0,"0");
// }
// checkSum = astCheckSumBuf.toString();
// //log.info(checkSum);
//
// return astTimeCmdNewBuf.toString() + checkSum.substring(0,2) + " " + checkSum.substring(2,4);
//String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd);
//log.info("DipperAstTimeAsyncTaskServiceImpl 返回时间:" + hexIn);



+ 8
- 2
src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java Bestand weergeven

@@ -30,7 +30,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi
private SchedulingExecutorConfig schedulingExecutorConfig;

@Override
//@Async("asyncServiceExecutor")
@Async("asyncServiceExecutor")
public void pullAstEPH() {
// (1) 发送bds获取星历数据
byte[] dipperData = pullEPHFromDipper();
@@ -73,6 +73,12 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi
@Override
public byte[] getAstEPH(){
// String dipperData = pullEPHFromDipper();
return (byte[])redisUtil.get(DIPPER_DATA_KEY);
byte[] dipperData;
if (!redisUtil.hasKey(DIPPER_DATA_KEY)) {
this.pullAstEPH();
}

dipperData = (byte[])redisUtil.get(DIPPER_DATA_KEY);
return dipperData;
}
}

+ 1
- 1
src/main/java/com/telpo/dipperposition/service/impl/IpProvinceServiceImpl.java Bestand weergeven

@@ -55,7 +55,7 @@ public class IpProvinceServiceImpl implements IpProvinceService {
ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("_class");
Example<IpProvinceEntity> example = Example.of(query, matcher);
Optional<IpProvinceEntity> data = ipProvinceMapper.findOne(example);
return data.get();
return data.orElse(null);
} catch (Exception e) {
log.error("获取IP省份异常:", e);
return null;


+ 2
- 2
src/main/resources/application.properties Bestand weergeven

@@ -5,9 +5,9 @@ logging.level.com.telpo.dipperposition.service.mapper=DEBUG
spring.application.name=dipperposition-service

spring.redis.database=1
spring.redis.host=172.19.42.45
spring.redis.host=127.0.0.1
#8090
spring.redis.port=6389
spring.redis.port=6379
spring.redis.password=telpo#1234
spring.redis.timeout=3000
spring.redis.lettuce.pool.max-active=100


Laden…
Annuleren
Opslaan