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.

84 rivejä
3.7 KiB

  1. using JT808.Protocol.Formatters;
  2. using JT808.Protocol.Interfaces;
  3. using JT808.Protocol.MessageBody;
  4. using JT808.Protocol.MessagePack;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.Json;
  8. namespace JT808.Protocol.Extensions.JT1078.MessageBody
  9. {
  10. /// <summary>
  11. ///单独视频通道参数设置
  12. /// 0x8103_0x0077
  13. /// </summary>
  14. public class JT808_0x8103_0x0077 : JT808_0x8103_BodyBase, IJT808MessagePackFormatter<JT808_0x8103_0x0077>, IJT808Analyze
  15. {
  16. public override uint ParamId { get; set; } = 0x0077;
  17. /// <summary>
  18. /// 数据 长度
  19. /// </summary>
  20. public override byte ParamLength { get; set; }
  21. /// <summary>
  22. /// 需单独设置视频参数的通道数量 用n表示
  23. /// </summary>
  24. public byte NeedSetChannelTotal { get; set; }
  25. public List<JT808_0x8103_0x0077_SignalChannel> SignalChannels { get; set; }
  26. public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config)
  27. {
  28. JT808_0x8103_0x0077 value = new JT808_0x8103_0x0077();
  29. value.ParamId = reader.ReadUInt32();
  30. writer.WriteNumber($"[{value.ParamId.ReadNumber()}]参数 ID", value.ParamId);
  31. value.ParamLength = reader.ReadByte();
  32. writer.WriteNumber($"[{value.ParamLength.ReadNumber()}]数据长度", value.ParamLength);
  33. value.NeedSetChannelTotal = reader.ReadByte();
  34. writer.WriteNumber($"[{value.NeedSetChannelTotal.ReadNumber()}]需单独设置视频参数的通道数量", value.NeedSetChannelTotal);
  35. writer.WriteStartArray("音视频通道对照表");
  36. for (int i = 0; i < value.NeedSetChannelTotal; i++)
  37. {
  38. writer.WriteStartObject();
  39. var formatter = config.GetMessagePackFormatter<JT808_0x8103_0x0077_SignalChannel>();
  40. formatter.Analyze(ref reader, writer, config);
  41. writer.WriteEndObject();
  42. }
  43. writer.WriteEndArray();
  44. }
  45. public JT808_0x8103_0x0077 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
  46. {
  47. JT808_0x8103_0x0077 jT808_0X8103_0X0077 = new JT808_0x8103_0x0077();
  48. jT808_0X8103_0X0077.ParamId = reader.ReadUInt32();
  49. jT808_0X8103_0X0077.ParamLength = reader.ReadByte();
  50. jT808_0X8103_0X0077.NeedSetChannelTotal = reader.ReadByte();
  51. if (jT808_0X8103_0X0077.NeedSetChannelTotal > 0)
  52. {
  53. jT808_0X8103_0X0077.SignalChannels = new List<JT808_0x8103_0x0077_SignalChannel>();
  54. var formatter = config.GetMessagePackFormatter<JT808_0x8103_0x0077_SignalChannel>();
  55. for (int i = 0; i < jT808_0X8103_0X0077.NeedSetChannelTotal; i++)
  56. {
  57. jT808_0X8103_0X0077.SignalChannels.Add(formatter.Deserialize(ref reader, config));
  58. }
  59. }
  60. return jT808_0X8103_0X0077;
  61. }
  62. public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8103_0x0077 value, IJT808Config config)
  63. {
  64. writer.WriteUInt32(value.ParamId);
  65. writer.Skip(1, out var position);
  66. writer.WriteByte(value.NeedSetChannelTotal);
  67. if (value.SignalChannels.Any())
  68. {
  69. var formatter = config.GetMessagePackFormatter<JT808_0x8103_0x0077_SignalChannel>();
  70. foreach (var signalChannel in value.SignalChannels)
  71. {
  72. formatter.Serialize(ref writer, signalChannel, config);
  73. }
  74. }
  75. writer.WriteByteReturn((byte)(writer.GetCurrentPosition() - position - 1), position);
  76. }
  77. }
  78. }