Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

81 linhas
3.2 KiB

  1. using JT808.Protocol.Attributes;
  2. using JT808.Protocol.Exceptions;
  3. using JT808.Protocol.Formatters;
  4. using JT808.Protocol.Formatters.MessageBodyFormatters;
  5. using JT808.Protocol.MessagePack;
  6. using JT808.Protocol.Metadata;
  7. using System;
  8. using System.Collections.Generic;
  9. namespace JT808.Protocol.MessageBody
  10. {
  11. /// <summary>
  12. /// CAN 总线数据上传
  13. /// 0x0705
  14. /// </summary>
  15. [JT808Formatter(typeof(JT808_0x0705_Formatter))]
  16. public class JT808_0x0705 : JT808Bodies, IJT808MessagePackFormatter<JT808_0x0705>
  17. {
  18. /// <summary>
  19. /// 数据项个数
  20. /// 包含的 CAN 总线数据项个数,>0
  21. /// </summary>
  22. public ushort CanItemCount { get; set; }
  23. /// <summary>
  24. /// CAN 总线数据接收时间
  25. /// 第 1 条 CAN 总线数据的接收时间,hh-mm-ss-msms
  26. /// </summary>
  27. public DateTime FirstCanReceiveTime { get; set; }
  28. /// <summary>
  29. /// CAN 总线数据项
  30. /// </summary>
  31. public List<JT808CanProperty> CanItems { get; set; }
  32. public JT808_0x0705 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
  33. {
  34. JT808_0x0705 jT808_0X0705 = new JT808_0x0705();
  35. jT808_0X0705.CanItemCount = reader.ReadUInt16();
  36. jT808_0X0705.FirstCanReceiveTime = reader.ReadDateTime5();
  37. jT808_0X0705.CanItems = new List<JT808CanProperty>();
  38. for (var i = 0; i < jT808_0X0705.CanItemCount; i++)
  39. {
  40. JT808CanProperty jT808CanProperty = new JT808CanProperty();
  41. jT808CanProperty.CanId = reader.ReadArray(4).ToArray();
  42. if (jT808CanProperty.CanId.Length != 4)
  43. {
  44. throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808CanProperty.CanId)}->4");
  45. }
  46. jT808CanProperty.CanData = reader.ReadArray(8).ToArray();
  47. if (jT808CanProperty.CanData.Length != 8)
  48. {
  49. throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808CanProperty.CanData)}->8");
  50. }
  51. jT808_0X0705.CanItems.Add(jT808CanProperty);
  52. }
  53. return jT808_0X0705;
  54. }
  55. public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0705 value, IJT808Config config)
  56. {
  57. if (value.CanItems != null && value.CanItems.Count > 0)
  58. {
  59. writer.WriteUInt16((ushort)value.CanItems.Count);
  60. writer.WriteDateTime5(value.FirstCanReceiveTime);
  61. foreach (var item in value.CanItems)
  62. {
  63. if (item.CanId.Length != 4)
  64. {
  65. throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(item.CanId)}->4");
  66. }
  67. writer.WriteArray(item.CanId);
  68. if (item.CanData.Length != 8)
  69. {
  70. throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(item.CanData)}->8");
  71. }
  72. writer.WriteArray(item.CanData);
  73. }
  74. }
  75. }
  76. }
  77. }