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.

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