Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

报文解析错误 #71

Closed
pruidong opened this issue Sep 6, 2022 · 2 comments
Closed

报文解析错误 #71

pruidong opened this issue Sep 6, 2022 · 2 comments

Comments

@pruidong
Copy link
Contributor

pruidong commented Sep 6, 2022

如下报文解析错误:

7E0200005B01234567891000110000000000000000020A3AAC067EAA2400000000000022083117155601040000014A30011D310100EB31000C00B28986049401208044782200060089FFFFFFFE000600C5FFFFFFE7000B00D801CC0090050FEC20C7000400B71D00947E

异常信息:

2022-09-06 11:31:29.978 [nioEventLoopGroup-5-1] ERROR jt-808.channel.dispatcher - 
java.lang.IndexOutOfBoundsException: index: 12, length: 91 (expected: range(0, 25))
	at io.netty.buffer.AbstractByteBuf.checkRangeBounds(AbstractByteBuf.java:1390)
	at io.netty.buffer.AbstractByteBuf.checkIndex0(AbstractByteBuf.java:1397)
	at io.netty.buffer.PooledSlicedByteBuf.slice(PooledSlicedByteBuf.java:106)
	at io.github.hylexus.jt.jt808.support.codec.impl.DefaultJt808MsgDecoder.decode(DefaultJt808MsgDecoder.java:57)
	at io.github.hylexus.jt.jt808.support.netty.Jt808DispatchChannelHandlerAdapter.channelRead(Jt808DispatchChannelHandlerAdapter.java:53)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:314)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:435)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:279)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:995)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)
2022-09-06 11:31:29.980 [nioEventLoopGroup-5-1] ERROR jt-808.request.decoder - Received unknown msg, msgId = 43556(0xaa24). ignore.
2022-09-06 11:31:29.980 [nioEventLoopGroup-5-1] ERROR jt-808.channel.dispatcher - 
io.github.hylexus.jt.exception.JtIllegalStateException: Received unknown msg, msgId=43556
	at io.github.hylexus.jt.jt808.support.codec.impl.DefaultJt808MsgDecoder.lambda$parseMsgType$0(DefaultJt808MsgDecoder.java:91)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
	at io.github.hylexus.jt.jt808.support.codec.impl.DefaultJt808MsgDecoder.parseMsgType(DefaultJt808MsgDecoder.java:89)
	at io.github.hylexus.jt.jt808.support.codec.impl.DefaultJt808MsgDecoder.decode(DefaultJt808MsgDecoder.java:52)
	at io.github.hylexus.jt.jt808.support.netty.Jt808DispatchChannelHandlerAdapter.channelRead(Jt808DispatchChannelHandlerAdapter.java:53)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:299)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:995)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)


厂商解释:

"中间出现7E的情况这个是属于正常情况,而且设备上传的时候都是将中间出现的7E转义成7D02上传的,只是说你解析的时候需要转义回7E进行解析"

"数据都是实时发送,刚好数据发到有7E的字节那设备就会去进行转义,本来这个7E就算一个字节的,又不是一个没有的字节"

请问这种怎么处理?谢谢.

@pruidong
Copy link
Contributor Author

pruidong commented Sep 6, 2022

原因为: 在报文中间出现了7E,但框架截取了前面半部分,漏掉了后面半部分.导致异常发生.

@pruidong
Copy link
Contributor Author

检查后,发现我在0200位置上报处理方法内获取到的报文是被框架处理过的.

如果需要原始报文,则需要自定义解码器来实现.

感谢 @hylexus 提供实现代码.

实现代码如下:

/**
 * 自定义解码器
 *
 * <p>备注: (主要用于将原始报文,传递至后续流程[官方原有流程为: 将修改后的报文传递至后续流程])
 *
 * @author 
 * @version 2022/9/10
 */
@Component
public class CustomJt808MsgDecoder extends DefaultJt808MsgDecoder {

  public CustomJt808MsgDecoder(
      Jt808MsgTypeParser msgTypeParser,
      Jt808MsgBytesProcessor msgBytesProcessor,
      Jt808ProtocolVersionDetectorRegistry versionDetectorRegistry) {
    super(msgTypeParser, msgBytesProcessor, versionDetectorRegistry);
  }

  @Override
  public Jt808Request decode(ByteBuf byteBuf) {
    final ByteBuf copy = byteBuf.copy();
    final Jt808Request request = super.decode(byteBuf);
    return request.mutate().rawByteBuf(copy).build();
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant