Преглед изворни кода

ALL改为all

tags/v1.0.0^2
林万龙 пре 3 година
родитељ
комит
ced270333d
3 измењених фајлова са 48 додато и 23 уклоњено
  1. +1
    -1
      src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java
  2. +31
    -8
      src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java
  3. +16
    -14
      src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java

+ 1
- 1
src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java Прегледај датотеку

@@ -154,7 +154,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
log.info(channelAns);
if (channelAns != null) {
buf = Unpooled.buffer(channelAns.getBytes().length);
buf.writeBytes(channelAns.getBytes("GBK"));
buf.writeBytes(channelAns.getBytes("UTF-8"));
ctx.writeAndFlush(buf);
}
}


+ 31
- 8
src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java Прегледај датотеку

@@ -210,14 +210,37 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS
// 00 2F 为校验和

// astTimeCmd 组装
String astTimeCmd = "233E0401";
astTimeCmd += "1000";
astTimeCmd += HexConvert.encodeHEX(lanLongValue);
astTimeCmd += HexConvert.encodeHEX(altLongValue);
astTimeCmd += "70170000";
astTimeCmd += "A0860100";

return astTimeCmd + HexConvert.makeChecksum(astTimeCmd);
String astTimeCmd = "23 3E 04 01 ";
astTimeCmd += "10 00 ";
byte[] lanBytes = HexConvert.hexStringToBytes(HexConvert.encodeHEX(lanLongValue).toUpperCase());

byte[] altBytes = HexConvert.hexStringToBytes(HexConvert.encodeHEX(altLongValue).toUpperCase());

StringBuffer lanBuf = new StringBuffer();
for(int i=0; i<lanBytes.length; i++) {
String s = Integer.toHexString(lanBytes[i] & 0xff);
if (s.length() < 2) {
lanBuf.append('0');
}
lanBuf.append(s + " ");
}

StringBuffer altBuf = new StringBuffer();
for(int i=0; i<altBytes.length; i++) {
String s = Integer.toHexString(altBytes[i] & 0xff);
if (s.length() < 2) {
altBuf.append('0');
}
altBuf.append(s + " ");
}

astTimeCmd += lanBuf;
astTimeCmd += altBuf;
astTimeCmd += "70 17 00 00 ";
astTimeCmd += "A0 86 01 00 ";

String checkSum = HexConvert.makeChecksum(astTimeCmd).toUpperCase();
return astTimeCmd + checkSum.substring(0,1) + " " + checkSum.substring(2,3);

}
}

+ 16
- 14
src/main/java/com/telpo/dipperposition/service/impl/DipperAstTimeAsyncTaskServiceImpl.java Прегледај датотеку

@@ -43,24 +43,25 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas
// 00 5E D0 B2 表示 3 秒的时间精度(十六进制 B2 D0 5E 00 转为十进制为3000000000,乘以比 例因子 10-9就是 3 秒 小端模式00 5E D0 B2)
// 00 2F 为校验和
// TODO astTimeCmd 组装
String astTimeCmd = "233E0402";
astTimeCmd += "1000";
astTimeCmd += "20E1";
String astTimeCmd = "23 3E 04 02 ";
astTimeCmd += "10 00 ";
astTimeCmd += "20 E1 ";
LocalDateTime now = LocalDateTime.now();
int year = now.getYear();
int month = now.getMonthValue();
int day = now.getDayOfMonth();
String hexYearString = Integer.toHexString(year);
hexYearString = "0" + hexYearString;
astTimeCmd += hexYearString.substring(2,2) + hexYearString.substring(0,2);
astTimeCmd += hexYearString.substring(2,3).toUpperCase() + " " + hexYearString.substring(0,1).toUpperCase() + " ";
String hexMonthString = Integer.toHexString(month);
hexMonthString = "0" + hexMonthString;
astTimeCmd += hexMonthString;
astTimeCmd += hexMonthString.toUpperCase() + " ";

String hexDayString = Integer.toHexString(day);
if (day < 16) {
hexDayString = "0" + hexDayString;
}
astTimeCmd += hexDayString;
astTimeCmd += hexDayString.toUpperCase() + " ";

int hour = now.getHour();
int minitor = now.getMinute();
@@ -69,23 +70,24 @@ public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTas
if (hour < 16) {
hexHourString = "0" + hexHourString;
}
astTimeCmd += hexHourString;
astTimeCmd += hexHourString.toUpperCase() + " ";
String hexMinitorString = Integer.toHexString(minitor);
if (minitor < 16) {
hexMinitorString = "0" + hexMinitorString;
}
astTimeCmd += hexMinitorString;
astTimeCmd += hexMinitorString.toUpperCase() + " ";
String hexSecondString = Integer.toHexString(second);
if (second < 16) {
hexSecondString = "0" + hexSecondString;
}
astTimeCmd += hexSecondString;
astTimeCmd += "0000000000";
astTimeCmd += "005ED0B2";
astTimeCmd += hexSecondString.toUpperCase() + " ";
astTimeCmd += "00 00 00 00 00 ";
astTimeCmd += "00 5E D0 B2 ";

String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd);
log.info("DipperAstTimeAsyncTaskServiceImpl 返回时间:" + hexIn);
String checkSum = HexConvert.makeChecksum(astTimeCmd).toUpperCase();
return astTimeCmd + checkSum.substring(0,1) + " " + checkSum.substring(2,3);
//String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd);
//log.info("DipperAstTimeAsyncTaskServiceImpl 返回时间:" + hexIn);

return hexIn;
}
}

Loading…
Откажи
Сачувај