25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
5.3 KiB

  1. using JT808.Protocol.Extensions;
  2. using JT808.Protocol.Formatters;
  3. using JT808.Protocol.Interfaces;
  4. using JT808.Protocol.MessagePack;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text.Json;
  8. namespace JT808.Protocol.MessageBody
  9. {
  10. /// <summary>
  11. /// 定位数据批量上传
  12. /// </summary>
  13. public class JT808_0x0704 : JT808Bodies, IJT808MessagePackFormatter<JT808_0x0704>, IJT808Analyze
  14. {
  15. /// <summary>
  16. /// 0x0704
  17. /// </summary>
  18. public override ushort MsgId { get; } = 0x0704;
  19. /// <summary>
  20. /// 定位数据批量上传
  21. /// </summary>
  22. public override string Description => "定位数据批量上传";
  23. /// <summary>
  24. /// 数据项个数
  25. /// </summary>
  26. public ushort Count { get; set; }
  27. /// <summary>
  28. /// 位置数据类型
  29. /// </summary>
  30. public BatchLocationType LocationType { get; set; }
  31. /// <summary>
  32. /// 位置汇报数据集合
  33. /// </summary>
  34. public IList<JT808_0x0200> Positions { get; set; }
  35. /// <summary>
  36. /// 位置数据类型
  37. /// </summary>
  38. public enum BatchLocationType : byte
  39. {
  40. /// <summary>
  41. /// 正常位置批量汇报
  42. /// </summary>
  43. 正常位置批量汇报 = 0x00,
  44. /// <summary>
  45. /// 盲区补报
  46. /// </summary>
  47. 盲区补报 = 0x01
  48. }
  49. /// <summary>
  50. ///
  51. /// </summary>
  52. /// <param name="reader"></param>
  53. /// <param name="config"></param>
  54. /// <returns></returns>
  55. public JT808_0x0704 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
  56. {
  57. JT808_0x0704 jT808_0X0704 = new JT808_0x0704();
  58. jT808_0X0704.Count = reader.ReadUInt16();
  59. jT808_0X0704.LocationType = (JT808_0x0704.BatchLocationType)reader.ReadByte();
  60. List<JT808_0x0200> jT808_0X0200s = new List<JT808_0x0200>();
  61. for (int i = 0; i < jT808_0X0704.Count; i++)
  62. {
  63. int buflen = reader.ReadUInt16();
  64. try
  65. {
  66. JT808MessagePackReader tmpReader = new JT808MessagePackReader(reader.ReadArray(buflen));
  67. JT808_0x0200 jT808_0X0200 = config.GetMessagePackFormatter<JT808_0x0200>().Deserialize(ref tmpReader, config);
  68. jT808_0X0200s.Add(jT808_0X0200);
  69. }
  70. catch (Exception)
  71. {
  72. }
  73. }
  74. jT808_0X0704.Positions = jT808_0X0200s;
  75. return jT808_0X0704;
  76. }
  77. /// <summary>
  78. ///
  79. /// </summary>
  80. /// <param name="writer"></param>
  81. /// <param name="value"></param>
  82. /// <param name="config"></param>
  83. public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0704 value, IJT808Config config)
  84. {
  85. writer.WriteUInt16(value.Count);
  86. writer.WriteByte((byte)value.LocationType);
  87. foreach (var item in value?.Positions)
  88. {
  89. try
  90. {
  91. writer.Skip(2, out int position);
  92. config.GetMessagePackFormatter<JT808_0x0200>().Serialize(ref writer, item, config);
  93. ushort length = (ushort)(writer.GetCurrentPosition() - position - 2);
  94. writer.WriteUInt16Return(length, position);
  95. }
  96. catch (Exception)
  97. {
  98. }
  99. }
  100. }
  101. /// <summary>
  102. ///
  103. /// </summary>
  104. /// <param name="reader"></param>
  105. /// <param name="writer"></param>
  106. /// <param name="config"></param>
  107. public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config)
  108. {
  109. JT808_0x0704 jT808_0X0704 = new JT808_0x0704();
  110. jT808_0X0704.Count = reader.ReadUInt16();
  111. writer.WriteNumber($"[{jT808_0X0704.Count.ReadNumber()}]数据项个数", jT808_0X0704.Count);
  112. jT808_0X0704.LocationType = (JT808_0x0704.BatchLocationType)reader.ReadByte();
  113. writer.WriteNumber($"[{((byte)jT808_0X0704.LocationType).ReadNumber()}]位置数据类型-{jT808_0X0704.LocationType}", (byte)jT808_0X0704.LocationType);
  114. writer.WriteStartArray("位置汇报数据集合");
  115. for (int i = 0; i < jT808_0X0704.Count; i++)
  116. {
  117. writer.WriteStartObject();
  118. int buflen = reader.ReadUInt16();
  119. writer.WriteNumber($"[{buflen.ReadNumber()}]位置汇报数据长度", buflen);
  120. try
  121. {
  122. writer.WriteString($"位置汇报数据", reader.ReadVirtualArray(buflen).ToArray().ToHexString());
  123. JT808MessagePackReader tmpReader = new JT808MessagePackReader(reader.ReadArray(buflen));
  124. writer.WriteStartObject("位置信息汇报");
  125. config.GetAnalyze<JT808_0x0200>().Analyze(ref tmpReader, writer, config);
  126. writer.WriteEndObject();
  127. }
  128. catch (Exception)
  129. {
  130. }
  131. writer.WriteEndObject();
  132. }
  133. writer.WriteEndArray();
  134. }
  135. }
  136. }