|
|
|
@ -12,6 +12,7 @@ import io.netty.handler.timeout.ReadTimeoutException;
|
|
|
|
|
import io.netty.util.AttributeKey;
|
|
|
|
|
import io.netty.util.CharsetUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
|
import java.net.SocketAddress;
|
|
|
|
@ -20,6 +21,7 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
|
|
|
|
|
import static com.hive.communication.util.CheckCode.*;
|
|
|
|
|
import static com.hive.util.DateConvetUtil.getCurrentSeconds;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@ -46,21 +48,43 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
public static void sendActive(ChannelHandlerContext ctx, boolean flag, BeeHive beeHive, boolean notice) {
|
|
|
|
|
if (flag) {
|
|
|
|
|
try {
|
|
|
|
|
String start="99";
|
|
|
|
|
String end ="AA";
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
stringBuilder.append(start);
|
|
|
|
|
stringBuilder.append("8561");
|
|
|
|
|
stringBuilder.append(beeHive.getDateUploadTimeHex());
|
|
|
|
|
stringBuilder.append("0b01");
|
|
|
|
|
// String paddedString = String.format("%4s", code).replace(' ', '0');
|
|
|
|
|
String codes = "注册完回复";
|
|
|
|
|
//获取十分钟后的时间秒数,需要转换为16进制
|
|
|
|
|
getCurrentSeconds();
|
|
|
|
|
log.info("当前时间: {}, 消息: {}", LocalDateTime.now(), codes);
|
|
|
|
|
//获取十分钟后的时间秒数,
|
|
|
|
|
// 转换为16进制
|
|
|
|
|
String hexSeconds = Long.toHexString(getCurrentSeconds()).toUpperCase();
|
|
|
|
|
stringBuilder.append(hexSeconds);
|
|
|
|
|
stringBuilder.append("0000ff000000");
|
|
|
|
|
|
|
|
|
|
byte[] dataSum = hexStringToByteArray(stringBuilder.toString());
|
|
|
|
|
// 计算校验码1
|
|
|
|
|
byte checksum1 = calculateChecksum1(dataSum);
|
|
|
|
|
// 计算校验码2
|
|
|
|
|
byte checksum2 = calculateChecksum2(dataSum);
|
|
|
|
|
String checksum1Hex = String.format("%02X", checksum1);
|
|
|
|
|
String checksum2Hex = String.format("%02X", checksum2);
|
|
|
|
|
stringBuilder.append(checksum1Hex);
|
|
|
|
|
stringBuilder.append(checksum2Hex);
|
|
|
|
|
stringBuilder.append(end);
|
|
|
|
|
|
|
|
|
|
log.info("当前时间: {}, 消息: {}", LocalDateTime.now(), stringBuilder);
|
|
|
|
|
// 先将十六进制字符串转换为字节数组
|
|
|
|
|
byte[] messageBytes = HexConversion.hexStringToByteArray(codes);
|
|
|
|
|
byte[] messageBytes = HexConversion.hexStringToByteArray(stringBuilder.toString());
|
|
|
|
|
// 将字节数组封装到ByteBuf中
|
|
|
|
|
ByteBuf messageBuffer = Unpooled.wrappedBuffer(messageBytes);
|
|
|
|
|
|
|
|
|
|
// 通过ChannelHandlerContext发送ByteBuf
|
|
|
|
|
// 关联设备编号与Channel
|
|
|
|
|
// sendRequest(ctx.channel(),messageBuffer,devicePointsSensor.getId());
|
|
|
|
|
retrySend(ctx, messageBuffer)
|
|
|
|
|
.whenComplete((result, error) -> {
|
|
|
|
|
log.info("发送状态: {},当前时间: {}, 消息: {},名称:{},蜂箱id:{}", result,LocalDateTime.now(), codes,beeHive.getBeeHiveName(),beeHive.getId());
|
|
|
|
|
log.info("发送状态: {},当前时间: {}, 消息: {},名称:{},蜂箱id:{}", result, LocalDateTime.now(), stringBuilder, beeHive.getBeeHiveName(), beeHive.getId());
|
|
|
|
|
/* if (result) {
|
|
|
|
|
// 发送成功
|
|
|
|
|
} else {
|
|
|
|
@ -92,6 +116,7 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
}
|
|
|
|
|
return future;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:发送消息并监听成功与失败进行重试
|
|
|
|
|
*/
|
|
|
|
@ -124,6 +149,7 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:或缺设备编号等存入pendingRequests等读取是进行匹配
|
|
|
|
|
*/
|
|
|
|
@ -142,6 +168,7 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:连接成功调用
|
|
|
|
|
*/
|
|
|
|
|