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.

95 lines
4.4 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;
  7. using System.Buffers.Binary;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using System.Text.Json;
  11. namespace JT808.Protocol.MessageBody.CarDVR
  12. {
  13. /// <summary>
  14. /// 采集指定的外部供电记录
  15. /// 返回:符合条件的供电记录
  16. /// </summary>
  17. public class JT808_CarDVR_Up_0x13 : JT808CarDVRUpBodies, IJT808MessagePackFormatter<JT808_CarDVR_Up_0x13>, IJT808Analyze
  18. {
  19. public override byte CommandId => JT808CarDVRCommandID.采集指定的外部供电记录.ToByteValue();
  20. /// <summary>
  21. /// 请求发送指定的时间范围内 N 个单位数据块的数据(N≥1)
  22. /// </summary>
  23. public List<JT808_CarDVR_Up_0x13_ExternalPowerSupply> JT808_CarDVR_Up_0x13_ExternalPowerSupplys { get; set; }
  24. public override string Description => "符合条件的供电记录";
  25. public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config)
  26. {
  27. JT808_CarDVR_Up_0x13 value = new JT808_CarDVR_Up_0x13();
  28. writer.WriteStartArray("请求发送指定的时间范围内 N 个单位数据块的数据");
  29. var count = (reader.ReadCurrentRemainContentLength() - 1) / 7;//记录块个数, -1 去掉校验位
  30. for (int i = 0; i < count; i++)
  31. {
  32. JT808_CarDVR_Up_0x13_ExternalPowerSupply jT808_CarDVR_Up_0x13_ExternalPowerSupply = new JT808_CarDVR_Up_0x13_ExternalPowerSupply();
  33. writer.WriteStartObject();
  34. writer.WriteStartObject($"从指定的结束时间之前最近的第{i+1}条外部电源记录");
  35. var hex = reader.ReadVirtualArray(6);
  36. jT808_CarDVR_Up_0x13_ExternalPowerSupply.EventTime = reader.ReadDateTime6();
  37. writer.WriteString($"[{hex.ToArray().ToHexString()}]事件发生时间", jT808_CarDVR_Up_0x13_ExternalPowerSupply.EventTime);
  38. jT808_CarDVR_Up_0x13_ExternalPowerSupply.EventType = reader.ReadByte();
  39. writer.WriteString($"[{ jT808_CarDVR_Up_0x13_ExternalPowerSupply.EventType.ReadNumber()}]事件类型", EventTypeDisplay(jT808_CarDVR_Up_0x13_ExternalPowerSupply.EventType));
  40. writer.WriteEndObject();
  41. writer.WriteEndObject();
  42. }
  43. writer.WriteEndArray();
  44. string EventTypeDisplay(byte eventType) {
  45. if (eventType == 1)
  46. {
  47. return "供电";
  48. }
  49. else {
  50. return "断电";
  51. }
  52. }
  53. }
  54. public void Serialize(ref JT808MessagePackWriter writer, JT808_CarDVR_Up_0x13 value, IJT808Config config)
  55. {
  56. foreach (var externalPowerSupply in value.JT808_CarDVR_Up_0x13_ExternalPowerSupplys)
  57. {
  58. writer.WriteDateTime6(externalPowerSupply.EventTime);
  59. writer.WriteByte(externalPowerSupply.EventType);
  60. }
  61. }
  62. public JT808_CarDVR_Up_0x13 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
  63. {
  64. JT808_CarDVR_Up_0x13 value = new JT808_CarDVR_Up_0x13();
  65. value.JT808_CarDVR_Up_0x13_ExternalPowerSupplys = new List<JT808_CarDVR_Up_0x13_ExternalPowerSupply>();
  66. var count = (reader.ReadCurrentRemainContentLength() - 1) / 7;//记录块个数, -1 去掉校验位
  67. for (int i = 0; i < count; i++)
  68. {
  69. JT808_CarDVR_Up_0x13_ExternalPowerSupply jT808_CarDVR_Up_0x13_ExternalPowerSupply = new JT808_CarDVR_Up_0x13_ExternalPowerSupply();
  70. jT808_CarDVR_Up_0x13_ExternalPowerSupply.EventTime = reader.ReadDateTime6();
  71. jT808_CarDVR_Up_0x13_ExternalPowerSupply.EventType = reader.ReadByte();
  72. value.JT808_CarDVR_Up_0x13_ExternalPowerSupplys.Add(jT808_CarDVR_Up_0x13_ExternalPowerSupply);
  73. }
  74. return value;
  75. }
  76. }
  77. /// <summary>
  78. /// 单位记录仪外部供电记录数据块格式
  79. /// </summary>
  80. public class JT808_CarDVR_Up_0x13_ExternalPowerSupply
  81. {
  82. /// <summary>
  83. /// 事件发生时间
  84. /// </summary>
  85. public DateTime EventTime { get; set; }
  86. /// <summary>
  87. /// 事件类型
  88. /// </summary>
  89. public byte EventType { get; set; }
  90. }
  91. }