You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
1.1 KiB

  1. using DotNetty.Buffers;
  2. using DotNetty.Codecs;
  3. using System.Collections.Generic;
  4. using JT808.Protocol;
  5. using DotNetty.Transport.Channels;
  6. namespace JT808.DotNetty.Core.Codecs
  7. {
  8. public class JT808TcpDecoder : ByteToMessageDecoder
  9. {
  10. protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
  11. {
  12. //过滤掉不是808标准包
  13. //不包括头尾标识
  14. //(消息 ID )2+(消息体属性)2+(终端手机号)6+(消息流水号)2+(检验码 )1
  15. if (input.Capacity < 12)
  16. {
  17. byte[] buffer = new byte[input.Capacity];
  18. input.ReadBytes(buffer, 0, input.Capacity);
  19. return;
  20. }
  21. else
  22. {
  23. byte[] buffer = new byte[input.Capacity + 2];
  24. input.ReadBytes(buffer, 1, input.Capacity);
  25. buffer[0] = JT808Package.BeginFlag;
  26. buffer[input.Capacity + 1] = JT808Package.EndFlag;
  27. output.Add(buffer);
  28. }
  29. }
  30. }
  31. }