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.

92 lines
3.5 KiB

  1. using JT808.Protocol.Enums;
  2. using JT808.Protocol.Extensions;
  3. using JT808.Protocol.Formatters;
  4. using JT808.Protocol.Interfaces;
  5. using JT808.Protocol.MessagePack;
  6. using System.Text.Json;
  7. namespace JT808.Protocol.MessageBody
  8. {
  9. /// <summary>
  10. /// 路段行驶时间不足/过长报警附加信息
  11. /// </summary>
  12. public class JT808_0x0200_0x13 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter<JT808_0x0200_0x13>, IJT808Analyze
  13. {
  14. /// <summary>
  15. /// JT808_0x0200_0x13
  16. /// </summary>
  17. public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x13;
  18. /// <summary>
  19. /// 7 byte
  20. /// </summary>
  21. public override byte AttachInfoLength { get; set; } = 7;
  22. /// <summary>
  23. /// 路段 ID
  24. /// </summary>
  25. public int DrivenRouteId { get; set; }
  26. /// <summary>
  27. /// 路段行驶时间
  28. /// 单位为秒(s)
  29. /// </summary>
  30. public ushort Time { get; set; }
  31. /// <summary>
  32. /// 结果 0:不足;1:过长
  33. /// </summary>
  34. public JT808DrivenRouteType DrivenRoute { get; set; }
  35. /// <summary>
  36. ///
  37. /// </summary>
  38. /// <param name="reader"></param>
  39. /// <param name="writer"></param>
  40. /// <param name="config"></param>
  41. public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config)
  42. {
  43. JT808_0x0200_0x13 value = new JT808_0x0200_0x13();
  44. value.AttachInfoId = reader.ReadByte();
  45. writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId);
  46. value.AttachInfoLength = reader.ReadByte();
  47. writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength);
  48. value.DrivenRouteId = reader.ReadInt32();
  49. writer.WriteNumber($"[{((byte)value.DrivenRouteId).ReadNumber()}]路段ID", value.DrivenRouteId);
  50. value.Time = reader.ReadUInt16();
  51. writer.WriteNumber($"[{value.Time.ReadNumber()}]路段行驶时间", value.Time);
  52. value.DrivenRoute = (JT808DrivenRouteType)reader.ReadByte();
  53. writer.WriteNumber($"[{((byte)value.DrivenRoute).ReadNumber()}]结果-{value.DrivenRoute.ToString()}", (byte)value.DrivenRoute);
  54. }
  55. /// <summary>
  56. ///
  57. /// </summary>
  58. /// <param name="reader"></param>
  59. /// <param name="config"></param>
  60. /// <returns></returns>
  61. public JT808_0x0200_0x13 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
  62. {
  63. JT808_0x0200_0x13 value = new JT808_0x0200_0x13();
  64. value.AttachInfoId = reader.ReadByte();
  65. value.AttachInfoLength = reader.ReadByte();
  66. value.DrivenRouteId = reader.ReadInt32();
  67. value.Time = reader.ReadUInt16();
  68. value.DrivenRoute = (JT808DrivenRouteType)reader.ReadByte();
  69. return value;
  70. }
  71. /// <summary>
  72. ///
  73. /// </summary>
  74. /// <param name="writer"></param>
  75. /// <param name="value"></param>
  76. /// <param name="config"></param>
  77. public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x13 value, IJT808Config config)
  78. {
  79. writer.WriteByte(value.AttachInfoId);
  80. writer.WriteByte(value.AttachInfoLength);
  81. writer.WriteInt32(value.DrivenRouteId);
  82. writer.WriteUInt16(value.Time);
  83. writer.WriteByte((byte)value.DrivenRoute);
  84. }
  85. }
  86. }