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.

133 line
6.5 KiB

  1. using JT808.Protocol.Formatters;
  2. using JT808.Protocol.MessagePack;
  3. using JT808.Protocol.Metadata;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace JT808.Protocol.MessageBody
  7. {
  8. /// <summary>
  9. /// 设置路线
  10. /// 0x8606
  11. /// </summary>
  12. public class JT808_0x8606 : JT808Bodies, IJT808MessagePackFormatter<JT808_0x8606>
  13. {
  14. /// <summary>
  15. /// 路线 ID
  16. /// </summary>
  17. public uint RouteId { get; set; }
  18. /// <summary>
  19. /// 路线属性
  20. /// 路线属性数据格式见 表 67
  21. /// </summary>
  22. public ushort RouteProperty { get; set; }
  23. /// <summary>
  24. /// 起始时间
  25. /// YY-MM-DD-hh-mm-ss,若区域属性 0 位为 0 则没有该字段
  26. /// </summary>
  27. public DateTime? StartTime { get; set; }
  28. /// <summary>
  29. /// 结束时间
  30. /// YY-MM-DD-hh-mm-ss,若区域属性 0 位为 0 则没有该字段
  31. /// </summary>
  32. public DateTime? EndTime { get; set; }
  33. /// <summary>
  34. /// 路线总拐点数
  35. /// </summary>
  36. public ushort InflectionPointCount { get; set; }
  37. /// <summary>
  38. /// 拐点项
  39. /// </summary>
  40. public List<JT808InflectionPointProperty> InflectionPointItems { get; set; }
  41. public JT808_0x8606 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
  42. {
  43. JT808_0x8606 jT808_0X8606 = new JT808_0x8606();
  44. jT808_0X8606.RouteId = reader.ReadUInt32();
  45. jT808_0X8606.RouteProperty = reader.ReadUInt16();
  46. ReadOnlySpan<char> routeProperty16Bit = Convert.ToString(jT808_0X8606.RouteProperty, 2).PadLeft(16, '0').AsSpan();
  47. bool bit0Flag = routeProperty16Bit.Slice(routeProperty16Bit.Length - 1).ToString().Equals("0");
  48. if (!bit0Flag)
  49. {
  50. jT808_0X8606.StartTime = reader.ReadDateTime6();
  51. jT808_0X8606.EndTime = reader.ReadDateTime6();
  52. }
  53. jT808_0X8606.InflectionPointCount = reader.ReadUInt16();
  54. jT808_0X8606.InflectionPointItems = new List<JT808InflectionPointProperty>();
  55. for (var i = 0; i < jT808_0X8606.InflectionPointCount; i++)
  56. {
  57. JT808InflectionPointProperty jT808InflectionPointProperty = new JT808InflectionPointProperty();
  58. jT808InflectionPointProperty.InflectionPointId = reader.ReadUInt32();
  59. jT808InflectionPointProperty.SectionId = reader.ReadUInt32();
  60. jT808InflectionPointProperty.InflectionPointLat = reader.ReadUInt32();
  61. jT808InflectionPointProperty.InflectionPointLng = reader.ReadUInt32();
  62. jT808InflectionPointProperty.SectionWidth = reader.ReadByte();
  63. jT808InflectionPointProperty.SectionProperty = reader.ReadByte();
  64. ReadOnlySpan<char> sectionProperty16Bit = Convert.ToString(jT808InflectionPointProperty.SectionProperty, 2).PadLeft(16, '0').AsSpan();
  65. bool sectionBit0Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 1).ToString().Equals("0");
  66. if (!sectionBit0Flag)
  67. {
  68. jT808InflectionPointProperty.SectionLongDrivingThreshold = reader.ReadUInt16();
  69. jT808InflectionPointProperty.SectionDrivingUnderThreshold = reader.ReadUInt16();
  70. }
  71. bool sectionBit1Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 2, 1).ToString().Equals("0");
  72. if (!sectionBit1Flag)
  73. {
  74. jT808InflectionPointProperty.SectionHighestSpeed = reader.ReadUInt16();
  75. jT808InflectionPointProperty.SectionOverspeedDuration = reader.ReadByte();
  76. }
  77. jT808_0X8606.InflectionPointItems.Add(jT808InflectionPointProperty);
  78. }
  79. return jT808_0X8606;
  80. }
  81. public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8606 value, IJT808Config config)
  82. {
  83. writer.WriteUInt32(value.RouteId);
  84. writer.WriteUInt16(value.RouteProperty);
  85. ReadOnlySpan<char> routeProperty16Bit = Convert.ToString(value.RouteProperty, 2).PadLeft(16, '0').AsSpan();
  86. bool bit0Flag = routeProperty16Bit.Slice(routeProperty16Bit.Length - 1).ToString().Equals("0");
  87. if (!bit0Flag)
  88. {
  89. if (value.StartTime.HasValue)
  90. writer.WriteDateTime6(value.StartTime.Value);
  91. if (value.EndTime.HasValue)
  92. writer.WriteDateTime6(value.EndTime.Value);
  93. }
  94. //bool bit1Flag = routeProperty16Bit.Slice(routeProperty16Bit.Length - 2, 1).ToString().Equals("0");
  95. if (value.InflectionPointItems != null && value.InflectionPointItems.Count > 0)
  96. {
  97. writer.WriteUInt16((ushort)value.InflectionPointItems.Count);
  98. foreach (var item in value.InflectionPointItems)
  99. {
  100. writer.WriteUInt32(item.InflectionPointId);
  101. writer.WriteUInt32(item.SectionId);
  102. writer.WriteUInt32(item.InflectionPointLat);
  103. writer.WriteUInt32(item.InflectionPointLng);
  104. writer.WriteByte(item.SectionWidth);
  105. writer.WriteByte(item.SectionProperty);
  106. ReadOnlySpan<char> sectionProperty16Bit = Convert.ToString(item.SectionProperty, 2).PadLeft(16, '0').AsSpan();
  107. bool sectionBit0Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 1).ToString().Equals("0");
  108. if (!sectionBit0Flag)
  109. {
  110. if (item.SectionLongDrivingThreshold.HasValue)
  111. writer.WriteUInt16(item.SectionLongDrivingThreshold.Value);
  112. if (item.SectionDrivingUnderThreshold.HasValue)
  113. writer.WriteUInt16(item.SectionDrivingUnderThreshold.Value);
  114. }
  115. bool sectionBit1Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 2, 1).ToString().Equals("0");
  116. if (!sectionBit1Flag)
  117. {
  118. if (item.SectionHighestSpeed.HasValue)
  119. writer.WriteUInt16(item.SectionHighestSpeed.Value);
  120. if (item.SectionOverspeedDuration.HasValue)
  121. writer.WriteByte(item.SectionOverspeedDuration.Value);
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }