Commit 2dceba5488603727744dc702e207cb713500b3a2

Authored by xp.Huang
2 parents 6c83c001 8e806d29

Merge remote-tracking branch 'origin/master_dev'

# Conflicts:
#	common/transport/tcp/src/main/java/org/thingsboard/server/transport/tcp/util/ByteUtils.java
... ... @@ -278,8 +278,8 @@ public class ByteUtils {
278 278 return result;
279 279 }
280 280
281   - public static byte[] strToBytes(String str) {
282   - if (Pattern.compile(messageRegular).matcher(str).matches()) {
  281 + public static byte[] strToBytes(String str){
  282 + if(Pattern.compile("^[A-Fa-f0-9]+$").matcher(str).matches()){
283 283 return hexStr2Bytes(str);
284 284 }
285 285 return getBytes(str, ByteUtils.UTF_8);
... ...
... ... @@ -40,10 +40,9 @@ import org.thingsboard.server.common.data.DeviceProfile;
40 40 import org.thingsboard.server.common.data.DeviceTransportType;
41 41 import org.thingsboard.server.common.data.device.profile.TkTcpDeviceProfileTransportConfiguration;
42 42 import org.thingsboard.server.common.data.id.DeviceId;
43   -import org.thingsboard.server.common.data.id.OtaPackageId;
44   -import org.thingsboard.server.common.data.ota.OtaPackageType;
45 43 import org.thingsboard.server.common.data.rpc.RpcStatus;
46 44 import org.thingsboard.server.common.data.yunteng.enums.TkScriptFunctionType;
  45 +import org.thingsboard.server.common.data.yunteng.utils.ByteUtils;
47 46 import org.thingsboard.server.common.msg.tools.TbRateLimitsException;
48 47 import org.thingsboard.server.common.transport.SessionMsgListener;
49 48 import org.thingsboard.server.common.transport.TransportService;
... ... @@ -62,7 +61,7 @@ import org.thingsboard.server.transport.tcp.adaptors.TcpUpEntry;
62 61 import org.thingsboard.server.transport.tcp.script.TkScriptFactory;
63 62 import org.thingsboard.server.transport.tcp.session.TcpDeviceSessionCtx;
64 63 import org.thingsboard.server.transport.tcp.session.TcpGatewaySessionHandler;
65   -import org.thingsboard.server.transport.tcp.util.ByteUtils;
  64 +import org.thingsboard.server.transport.tcp.util.ByteBufUtils;
66 65
67 66 import java.io.IOException;
68 67 import java.net.InetSocketAddress;
... ... @@ -156,9 +155,9 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements
156 155 try {
157 156 if (msg instanceof ByteBuf) {
158 157 ByteBuf message = (ByteBuf) msg;
159   - byte[] byteMsg = ByteUtils.buf2Bytes(message);
  158 + byte[] byteMsg = ByteBufUtils.buf2Bytes(message);
160 159 String msgStr = ByteUtils.bytesToStr(byteMsg);
161   - log.error("会话【{}】收到设备【{}】来自【{}】数据【{}】", sessionId, deviceSessionCtx.getDeviceId(), address, msgStr);
  160 + log.debug("会话【{}】收到设备【{}】来自【{}】数据【{}】", sessionId, deviceSessionCtx.getDeviceId(), address, msgStr);
162 161 deviceSessionCtx.setChannel(ctx);
163 162 if (deviceSessionCtx.getDeviceInfo() == null || deviceSessionCtx.getDeviceProfile() == null) {
164 163 processConnect(ctx, msgStr);
... ... @@ -535,7 +534,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements
535 534
536 535 @Override
537 536 public void onToDeviceRpcRequest(UUID sessionId, TransportProtos.ToDeviceRpcRequestMsg rpcRequest) {
538   - log.error("【{}】下发RPC命令【{}】给设备【{}】", sessionId, rpcRequest.getParams(), deviceSessionCtx.getDeviceInfo().getDeviceName());
  537 + log.debug("【{}】下发RPC命令【{}】给设备【{}】", sessionId, rpcRequest.getParams(), deviceSessionCtx.getDeviceInfo().getDeviceName());
539 538 TcpTransportAdaptor adaptor = deviceSessionCtx.getPayloadAdaptor();
540 539 try {
541 540 adaptor.convertToPublish(deviceSessionCtx, rpcRequest).ifPresent(payload -> {
... ... @@ -573,7 +572,7 @@ public class TcpTransportHandler extends ChannelInboundHandlerAdapter implements
573 572
574 573 @Override
575 574 public void onToServerRpcResponse(TransportProtos.ToServerRpcResponseMsg rpcResponse) {
576   - log.error("[{}] 服务端响应设备的RPC请求", sessionId);
  575 + log.debug("[{}] 服务端响应设备的RPC请求", sessionId);
577 576 // String baseTopic = toServerRpcSubTopicType.getRpcResponseTopicBase();
578 577 // TcpTransportAdaptor adaptor = deviceSessionCtx.getAdaptor(toServerRpcSubTopicType);
579 578 // try {
... ...
... ... @@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j;
32 32 import org.springframework.util.ConcurrentReferenceHashMap;
33 33 import org.springframework.util.StringUtils;
34 34 import org.thingsboard.common.util.JacksonUtil;
  35 +import org.thingsboard.server.common.data.yunteng.utils.ByteUtils;
35 36 import org.thingsboard.server.common.transport.TransportService;
36 37 import org.thingsboard.server.common.transport.TransportServiceCallback;
37 38 import org.thingsboard.server.common.transport.adaptor.AdaptorException;
... ... @@ -42,7 +43,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFro
42 43 import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
43 44 import org.thingsboard.server.transport.tcp.TcpTransportContext;
44 45 import org.thingsboard.server.transport.tcp.adaptors.TcpTransportAdaptor;
45   -import org.thingsboard.server.transport.tcp.util.ByteUtils;
  46 +import org.thingsboard.server.transport.tcp.util.ByteBufUtils;
46 47
47 48 import javax.annotation.Nullable;
48 49 import java.io.UnsupportedEncodingException;
... ...
  1 +package org.thingsboard.server.transport.tcp.util;
  2 +
  3 +import io.netty.buffer.ByteBuf;
  4 +
  5 +/**
  6 + *
  7 + */
  8 +public class ByteBufUtils {
  9 + public static byte[] buf2Bytes(ByteBuf in) {
  10 + return buf2Bytes(in, in.readableBytes());
  11 + }
  12 +
  13 + public static byte[] buf2Bytes(ByteBuf in, int readable) {
  14 + byte[] dst = new byte[readable];
  15 + in.getBytes(0, dst);
  16 + return dst;
  17 + }
  18 +
  19 +}
... ...
... ... @@ -282,7 +282,7 @@ public class ByteUtils {
282 282 }
283 283
284 284 public static byte[] strToBytes(String str){
285   - if(Pattern.compile("^[A-Fa-f0-9]+$").matcher(str).matches()){
  285 + if(Pattern.compile(messageRegular).matcher(str).matches()){
286 286 return hexStr2Bytes(str);
287 287 }
288 288 return getBytes(str,ByteUtils.UTF_8);
... ...