diff --git a/src/main/java/com/telpo/dipperposition/common/SocketClient.java b/src/main/java/com/telpo/dipperposition/common/SocketClient.java index ebc3e5e..3dc7473 100644 --- a/src/main/java/com/telpo/dipperposition/common/SocketClient.java +++ b/src/main/java/com/telpo/dipperposition/common/SocketClient.java @@ -38,7 +38,7 @@ public class SocketClient { } - public String sendCmd(String astCmd, String ackAckCheckRef) { + public byte[] sendCmd(String astCmd, String ackAckCheckRef) { try { OutputStream os=socket.getOutputStream(); PrintWriter pw=new PrintWriter(os); @@ -80,7 +80,7 @@ public class SocketClient { os.close(); //log.debug(ackResult); log.debug("接收服务器的信息:"+in2b.toString()); - return in2b.toString(); + return in2b; } catch (IOException e) { log.error("Socket sendCmd Error:" + e.getMessage()); return null; diff --git a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java index 8c38627..193a9ca 100644 --- a/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java +++ b/src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java @@ -116,10 +116,12 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 返回时间指令 //if (Integer.parseInt(timeAsycServerPort) == channel.localAddress().getPort()) { ByteBuf recvmg = (ByteBuf) msg; + ByteBuf buf = null; String recvmgStr = recvmg.toString(); if (AST_TIME_CMD.equals(recvmg)) { // 初始时间辅助输入; channelAns = dipperTimeAsyncTaskService.pushAstTime(); + buf = Unpooled.buffer(channelAns.getBytes().length); } // 发送SDBP-AST-POS获取辅助位置信息 @@ -131,12 +133,14 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { centerProvince, ipPositionRequestPath, ipPositionRequestKey); + buf = Unpooled.buffer(channelAns.getBytes().length); } // 从缓存获取SDBP-AST-EPH星历数 //if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) { if (AST_POS_CMD.equals(recvmg)) { - channelAns = dipperDataAsyncTaskService.getAstEPH(); + byte[] astEPHBytes = dipperDataAsyncTaskService.getAstEPH(); + buf = Unpooled.buffer(astEPHBytes.length); } @@ -144,7 +148,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 设备采用16进制获取数据,则代理服务器也是采用16进制返回数据。 // 通知客户端链消息发送成功 // String str = "服务端收到:" + LocalDateTime.now() + " " + msg + "\r\n"; - ByteBuf buf = Unpooled.buffer(channelAns.getBytes().length); buf.writeBytes(channelAns.getBytes("GBK")); ctx.writeAndFlush(buf); //ctx.write("你也好哦"); diff --git a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java index 708e6df..ec70f9e 100644 --- a/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java +++ b/src/main/java/com/telpo/dipperposition/service/IDipperDataAsyncTaskService.java @@ -23,6 +23,6 @@ public interface IDipperDataAsyncTaskService { * 根据IP获取EPH * */ - String getAstEPH(); + byte[] getAstEPH(); } diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index aec944e..72b3a0a 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -32,7 +32,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override public void pullAstEPH() { // (1) 发送bds获取星历数据 - String dipperData = pullEPHFromDipper(); + byte[] dipperData = pullEPHFromDipper(); // (2) 获取星历数据 if (dipperData == null) { @@ -44,7 +44,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi } - private String pullEPHFromDipper() { + private byte[] pullEPHFromDipper() { // 创建Socket客户端实例; SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), schedulingExecutorConfig.getEphAstHexPort(),schedulingExecutorConfig.getAstTimeout()); @@ -54,7 +54,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd); String ackAckCheckRef = "233E010102000421293C"; - String sendResult = client.sendCmd(hexIn, ackAckCheckRef); + byte[] sendResult = client.sendCmd(hexIn, ackAckCheckRef); client.closeConnection(); return sendResult; @@ -62,7 +62,7 @@ public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskServi @Override @Async("asyncServiceExecutor") - public String getAstEPH(){ - return (String)redisUtil.get(DIPPER_DATA_KEY); + public byte[] getAstEPH(){ + return (byte[])redisUtil.get(DIPPER_DATA_KEY); } }