diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs index 7b6f039..05bb460 100644 --- a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs @@ -17,7 +17,7 @@ namespace JT809.Protocol.Test.JT809MessageBody public void Test1() { JT809_0x9007 jT809_0X9007 = new JT809_0x9007(); - jT809_0X9007.ReasonCode = JT809_0x9007_ReasonCode.无法连接下级平台指定的服务IP与端口; + jT809_0X9007.ErrorCode = JT809_0x1007_ErrorCode.主链路断开; var hex = JT809Serializer.Serialize(jT809_0X9007).ToHexString(); Assert.Equal("00", hex); } @@ -27,7 +27,7 @@ namespace JT809.Protocol.Test.JT809MessageBody { var bytes = "00".ToHexBytes(); JT809_0x9007 jT809_0X9007 = JT809Serializer.Deserialize<JT809_0x9007>(bytes); - Assert.Equal(JT809_0x9007_ReasonCode.无法连接下级平台指定的服务IP与端口, jT809_0X9007.ReasonCode); + Assert.Equal(JT809_0x1007_ErrorCode.主链路断开, jT809_0X9007.ErrorCode); } } } diff --git a/src/JT809.Protocol/Extensions/JT809AnalyzeExtensions.cs b/src/JT809.Protocol/Extensions/JT809AnalyzeExtensions.cs new file mode 100644 index 0000000..f6b6e1a --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809AnalyzeExtensions.cs @@ -0,0 +1,25 @@ +using JT809.Protocol; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; + +namespace JT809.Protocol.Extensions +{ + public static class JT809AnalyzeExtensions + { + public static void Analyze(this object instance, ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + if(instance is IJT809Analyze analyze) + { + analyze.Analyze(ref reader, writer, config); + } + else + { + throw new NotImplementedException($"Not Implemented {instance.GetType().FullName} {nameof(IJT809Analyze)}"); + } + } + } +} diff --git a/src/JT809.Protocol/Extensions/JT809HexExtensions.cs b/src/JT809.Protocol/Extensions/JT809HexExtensions.cs index 0bfb6e9..45b1639 100644 --- a/src/JT809.Protocol/Extensions/JT809HexExtensions.cs +++ b/src/JT809.Protocol/Extensions/JT809HexExtensions.cs @@ -133,6 +133,54 @@ namespace JT809.Protocol.Extensions return buf; } + public static string ReadNumber(this byte value, string format = "X2") + { + return value.ToString(format); + } + public static string ReadNumber(this int value, string format = "X8") + { + return value.ToString(format); + } + public static string ReadNumber(this uint value, string format = "X8") + { + return value.ToString(format); + } + public static string ReadNumber(this long value, string format = "X16") + { + return value.ToString(format); + } + public static string ReadNumber(this ulong value, string format = "X16") + { + return value.ToString(format); + } + public static string ReadNumber(this short value, string format = "X4") + { + return value.ToString(format); + } + public static string ReadNumber(this ushort value, string format = "X4") + { + return value.ToString(format); + } + public static ReadOnlySpan<char> ReadBinary(this ushort value) + { + return System.Convert.ToString(value, 2).PadLeft(16, '0').AsSpan(); + } + public static ReadOnlySpan<char> ReadBinary(this short value) + { + return System.Convert.ToString(value, 2).PadLeft(16, '0').AsSpan(); + } + public static ReadOnlySpan<char> ReadBinary(this uint value) + { + return System.Convert.ToString(value, 2).PadLeft(32, '0').AsSpan(); + } + public static ReadOnlySpan<char> ReadBinary(this int value) + { + return System.Convert.ToString(value, 2).PadLeft(32, '0').AsSpan(); + } + public static ReadOnlySpan<char> ReadBinary(this byte value) + { + return System.Convert.ToString(value, 2).PadLeft(8, '0').AsSpan(); + } public unsafe static string ReadHexStringLittle(ReadOnlySpan<byte> read, ref int offset, int len) { ReadOnlySpan<byte> source = read.Slice(offset, len); diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1001.cs b/src/JT809.Protocol/MessageBody/JT809_0x1001.cs index 32f8c3a..08a6485 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1001.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1001.cs @@ -3,7 +3,7 @@ using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; - +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -14,7 +14,7 @@ namespace JT809.Protocol.MessageBody /// <para>业务数据类型标识: UP-CONNECT-REQ</para> /// <para>描述:下级平台向上级平台发送用户名和密码等登录信息</para> /// </summary> - public class JT809_0x1001: JT809Bodies,IJT809MessagePackFormatter<JT809_0x1001>, IJT809_2019_Version + public class JT809_0x1001: JT809Bodies,IJT809MessagePackFormatter<JT809_0x1001>, IJT809Analyze, IJT809_2019_Version { /// <summary> /// 用户名 @@ -45,18 +45,38 @@ namespace JT809.Protocol.MessageBody public override JT809_LinkType LinkType => JT809_LinkType.main; + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1001 value = new JT809_0x1001(); + value.UserId = reader.ReadUInt32(); + writer.WriteNumber($"[{value.UserId.ReadNumber()}]用户名", value.UserId); + var virtualHex = reader.ReadVirtualArray(8); + value.Password = reader.ReadString(8); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]密码", value.Password); + if (config.Version == JT809Version.JTT2019) + { + value.MsgGNSSCENTERID = reader.ReadUInt32(); + writer.WriteNumber($"[{value.MsgGNSSCENTERID.ReadNumber()}]下级平台接入码", value.MsgGNSSCENTERID); + } + virtualHex = reader.ReadVirtualArray(32); + value.DownLinkIP = reader.ReadString(32); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]下级平台提供对应的从链路服务端IP地址", value.DownLinkIP); + value.DownLinkPort = reader.ReadUInt16(); + writer.WriteNumber($"[{value.DownLinkPort.ReadNumber()}]下级平台提供对应的从链路服务器端口号", value.DownLinkPort); + } + public JT809_0x1001 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x1001 jT809_0X1001 = new JT809_0x1001(); - jT809_0X1001.UserId = reader.ReadUInt32(); - jT809_0X1001.Password = reader.ReadString(8); + JT809_0x1001 value = new JT809_0x1001(); + value.UserId = reader.ReadUInt32(); + value.Password = reader.ReadString(8); if(config.Version== JT809Version.JTT2019) { - jT809_0X1001.MsgGNSSCENTERID = reader.ReadUInt32(); + value.MsgGNSSCENTERID = reader.ReadUInt32(); } - jT809_0X1001.DownLinkIP = reader.ReadString(32); - jT809_0X1001.DownLinkPort = reader.ReadUInt16(); - return jT809_0X1001; + value.DownLinkIP = reader.ReadString(32); + value.DownLinkPort = reader.ReadUInt16(); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1001 value, IJT809Config config) diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1002.cs b/src/JT809.Protocol/MessageBody/JT809_0x1002.cs index 1944eb9..8abd8cb 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1002.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1002.cs @@ -6,6 +6,7 @@ using JT809.Protocol.MessagePack; using System; using System.Collections.Generic; using System.Text; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -16,7 +17,7 @@ namespace JT809.Protocol.MessageBody /// <para>业务数据类型标识:UP_CONNCCT_RSP</para> /// <para>描述:上级平台对下级平台登录请求信息、进行安全验证后,返回相应的验证结果。</para> /// </summary> - public class JT809_0x1002 : JT809Bodies, IJT809MessagePackFormatter<JT809_0x1002>, IJT809_2019_Version + public class JT809_0x1002 : JT809Bodies, IJT809MessagePackFormatter<JT809_0x1002>, IJT809Analyze, IJT809_2019_Version { public override ushort MsgId => JT809BusinessType.主链路登录应答消息.ToUInt16Value(); @@ -38,12 +39,22 @@ namespace JT809.Protocol.MessageBody /// 校验码 /// </summary> public uint VerifyCode { get; set; } + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1002 value = new JT809_0x1002(); + value.Result = (JT809_0x1002_Result)reader.ReadByte(); + writer.WriteString($"[{value.Result.ToByteValue()}]验证结果", value.Result.ToString()); + value.VerifyCode = reader.ReadUInt32(); + writer.WriteNumber($"[{value.VerifyCode.ReadNumber()}]校验码",value.VerifyCode); + } + public JT809_0x1002 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x1002 jT809_0X1002 = new JT809_0x1002(); - jT809_0X1002.Result = (JT809_0x1002_Result)reader.ReadByte(); - jT809_0X1002.VerifyCode = reader.ReadUInt32(); - return jT809_0X1002; + JT809_0x1002 value = new JT809_0x1002(); + value.Result = (JT809_0x1002_Result)reader.ReadByte(); + value.VerifyCode = reader.ReadUInt32(); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1002 value, IJT809Config config) { diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1003.cs b/src/JT809.Protocol/MessageBody/JT809_0x1003.cs index 0161528..17efd25 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1003.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1003.cs @@ -1,10 +1,12 @@ using JT809.Protocol.Enums; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; using System; using System.Collections.Generic; using System.Text; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -15,7 +17,7 @@ namespace JT809.Protocol.MessageBody /// <para>业务数据类型标识:UP-DISCONNECT-REQ</para> /// <para>描述:下级平台在中断与上级平台的主链路连接时,应向上级平台发送主链路注销请求消息。</para> /// </summary> - public class JT809_0x1003 : JT809Bodies, IJT809MessagePackFormatter<JT809_0x1003> + public class JT809_0x1003 : JT809Bodies, IJT809MessagePackFormatter<JT809_0x1003>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.主链路注销请求消息.ToUInt16Value(); @@ -30,12 +32,23 @@ namespace JT809.Protocol.MessageBody /// 密码 /// </summary> public string Password { get; set; } + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1003 value = new JT809_0x1003(); + value.UserId = reader.ReadUInt32(); + writer.WriteNumber($"[{value.UserId.ReadNumber()}]用户名", value.UserId); + var virtualHex = reader.ReadVirtualArray(8); + value.Password = reader.ReadString(8); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]密码", value.Password); + } + public JT809_0x1003 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x1003 jT809_0X1003 = new JT809_0x1003(); - jT809_0X1003.UserId = reader.ReadUInt32(); - jT809_0X1003.Password = reader.ReadString(8); - return jT809_0X1003; + JT809_0x1003 value = new JT809_0x1003(); + value.UserId = reader.ReadUInt32(); + value.Password = reader.ReadString(8); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1003 value, IJT809Config config) { diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1007.cs b/src/JT809.Protocol/MessageBody/JT809_0x1007.cs index c266e2f..c0ca022 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1007.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1007.cs @@ -1,7 +1,9 @@ using JT809.Protocol.Enums; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -14,7 +16,7 @@ namespace JT809.Protocol.MessageBody /// <para>主链路连接保持应答消息,数据体为空</para> /// <para>本条消息无需被通知方应答</para> /// </summary> - public class JT809_0x1007:JT809Bodies, IJT809MessagePackFormatter<JT809_0x1007> + public class JT809_0x1007:JT809Bodies, IJT809MessagePackFormatter<JT809_0x1007>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.主链路断开通知消息.ToUInt16Value(); public override string Description => "主链路断开通知消息"; @@ -23,11 +25,19 @@ namespace JT809.Protocol.MessageBody /// 错误代码 /// </summary> public JT809_0x1007_ErrorCode ErrorCode { get; set; } + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1007 value = new JT809_0x1007(); + value.ErrorCode = (JT809_0x1007_ErrorCode)reader.ReadByte(); + writer.WriteString($"[{value.ErrorCode.ToByteValue()}]错误代码", value.ErrorCode.ToString()); + } + public JT809_0x1007 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x1007 jT809_0X1007 = new JT809_0x1007(); - jT809_0X1007.ErrorCode = (JT809_0x1007_ErrorCode)reader.ReadByte(); - return jT809_0X1007; + JT809_0x1007 value = new JT809_0x1007(); + value.ErrorCode = (JT809_0x1007_ErrorCode)reader.ReadByte(); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1007 value, IJT809Config config) diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1008.cs b/src/JT809.Protocol/MessageBody/JT809_0x1008.cs index d5e0681..0d4ddae 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1008.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1008.cs @@ -1,7 +1,9 @@ using JT809.Protocol.Enums; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -12,20 +14,28 @@ namespace JT809.Protocol.MessageBody /// <para>业务数据类型标识:UP_CLOSELINIC INFORM</para> /// <para>描述:下级平台作为服务端,发现从链路出现异常时,下级平台通过从链路向上级平台发送本消息,通知上级平台下级平台即将关闭主从链路</para> /// </summary> - public class JT809_0x1008:JT809Bodies, IJT809MessagePackFormatter<JT809_0x1008> + public class JT809_0x1008:JT809Bodies, IJT809MessagePackFormatter<JT809_0x1008>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.下级平台主动关闭主从链路通知消息.ToUInt16Value(); public override string Description => "下级平台主动关闭主从链路通知消息"; public override JT809_LinkType LinkType => JT809_LinkType.subordinate; /// <summary> - /// 错误代码 + /// 链路关闭原因 /// </summary> public JT809_0x1008_ReasonCode ReasonCode { get; set; } + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1008 value = new JT809_0x1008(); + value.ReasonCode = (JT809_0x1008_ReasonCode)reader.ReadByte(); + writer.WriteString($"[{value.ReasonCode.ToByteValue()}]链路关闭原因", value.ReasonCode.ToString()); + } + public JT809_0x1008 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x1008 jT809_0X1008 = new JT809_0x1008(); - jT809_0X1008.ReasonCode = (JT809_0x1008_ReasonCode)reader.ReadByte(); - return jT809_0X1008; + JT809_0x1008 value = new JT809_0x1008(); + value.ReasonCode = (JT809_0x1008_ReasonCode)reader.ReadByte(); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1008 value, IJT809Config config) diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1102.cs b/src/JT809.Protocol/MessageBody/JT809_0x1102.cs index 75bde4e..75e60de 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1102.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1102.cs @@ -6,6 +6,7 @@ using JT809.Protocol.Interfaces; using System; using System.Collections.Generic; using System.Text; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -16,7 +17,7 @@ namespace JT809.Protocol.MessageBody /// <para>业务类型标识:UP_MANAGE_MSG_RSP</para> /// <para>下级平台收到上级平台下发的“平台链路连接情况与车辆定位消息传输情况上报请求消息”后,上报指定平台,指定时间段内的平台链路连接情况与车辆定位消息传输情况</para> /// </summary> - public class JT809_0x1102 : JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1102>,IJT809_2019_Version + public class JT809_0x1102 : JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1102>, IJT809Analyze, IJT809_2019_Version { public override ushort MsgId => JT809BusinessType.平台链路连接情况与车辆定位消息传输情况上报应答消息_2019.ToUInt16Value(); public override string Description => "平台链路连接情况与车辆定位消息传输情况上报应答消息"; @@ -50,6 +51,28 @@ namespace JT809.Protocol.MessageBody /// START_TIME~END_TIME期间下级监控平台链路断开总时长,用秒表示 /// </summary> public uint DisconnectTime { get; set; } + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1102 value = new JT809_0x1102(); + var virtualHex = reader.ReadVirtualArray(11); + value.PlateformId = reader.ReadBigNumber(11); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]平台唯一编码", value.PlateformId); + virtualHex = reader.ReadVirtualArray(8); + value.StartTime = reader.ReadUTCDateTime(); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]开始时间", value.StartTime); + virtualHex = reader.ReadVirtualArray(8); + value.EndTime = reader.ReadUTCDateTime(); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]结束时间", value.EndTime); + value.LoseDymamicSum = reader.ReadUInt32(); + writer.WriteNumber($"[{value.LoseDymamicSum.ReadNumber()}]START_TIME~END_TIME期间下级平台丢失得车辆定位消息总数", value.LoseDymamicSum); + value.DisconnectNum = reader.ReadByte(); + writer.WriteNumber($"[{value.DisconnectNum.ReadNumber()}]START_TIME~END_TIME期间下级监控平台链路断开次数", value.DisconnectNum); + value.DisconnectTime = reader.ReadUInt32(); + writer.WriteNumber($"[{value.DisconnectTime.ReadNumber()}]START_TIME~END_TIME期间下级监控平台链路断开总时长,用秒表示", value.DisconnectTime); + + } + public JT809_0x1102 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1102 value = new JT809_0x1102(); diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1103.cs b/src/JT809.Protocol/MessageBody/JT809_0x1103.cs index 73ecf50..2d69e15 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1103.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1103.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Text; using JT809.Protocol.Metadata; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -17,7 +18,7 @@ namespace JT809.Protocol.MessageBody /// <para>业务类型标识:UP_MANAGE_MSG_SN_INFORM</para> /// <para>描述:链路登录成功后,平台须发送链路断开之前所有子业务数据类型对应的消息序列号,发送方根据收到的消息序列号,在发送消息时,续编链路中断之前的消息序列号</para> /// </summary> - public class JT809_0x1103 : JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1103>,IJT809_2019_Version + public class JT809_0x1103 : JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1103>, IJT809Analyze, IJT809_2019_Version { public override ushort MsgId => JT809BusinessType.上传平台间消息序列号通知消息_2019.ToUInt16Value(); public override string Description => "上传平台间消息序列号通知消息"; @@ -27,6 +28,32 @@ namespace JT809.Protocol.MessageBody public List<JT809ManageMsgSNInform> ManageMsgSNInform { get; set; } = new List<JT809ManageMsgSNInform>(); public byte Count { get; set; } + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1103 value = new JT809_0x1103(); + value.SubBusinessType = reader.ReadUInt16(); + writer.WriteString($"[{value.SubBusinessType.ReadNumber()}]子业务类型标识", ((JT809SubBusinessType)value.SubBusinessType).ToString()); + value.DataLength = reader.ReadUInt32(); + writer.WriteNumber($"[{value.DataLength.ReadNumber()}]后续数据长度", value.DataLength); + value.Count = reader.ReadByte(); + writer.WriteNumber($"[{value.Count.ReadNumber()}]个数", value.Count); + writer.WriteStartArray("上传平台间消息序列号通知消息"); + for (int i = 0; i < value.Count; i++) + { + writer.WriteStartObject(); + JT809ManageMsgSNInform item = new JT809ManageMsgSNInform(); + item.SubBusinessType = reader.ReadUInt16(); + writer.WriteString($"[{item.SubBusinessType.ReadNumber()}]子业务类型标识", ((JT809SubBusinessType)item.SubBusinessType).ToString()); + item.MsgSN = reader.ReadUInt32(); + writer.WriteNumber($"[{item.MsgSN.ReadNumber()}]对应得子夜吴数据类型报文序列号", item.MsgSN); + var virtualHex = reader.ReadVirtualArray(8); + item.Time = reader.ReadUTCDateTime(); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]系统UTC时间", item.Time); + writer.WriteEndObject(); + } + writer.WriteEndArray(); + } + public JT809_0x1103 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1103 value = new JT809_0x1103(); diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1200.cs b/src/JT809.Protocol/MessageBody/JT809_0x1200.cs index d0e7315..16a4904 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1200.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1200.cs @@ -1,10 +1,11 @@ - -using JT809.Protocol.Enums; +using JT809.Protocol.Enums; using JT809.Protocol.Exceptions; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; using System; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -15,12 +16,43 @@ namespace JT809.Protocol.MessageBody /// <para>业务数据类型标识:UP_EXG_MSG</para> /// <para>描述:下级平台向上级平台发送车辆动态信息交换业务数据包</para> /// </summary> - public class JT809_0x1200: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1200> + public class JT809_0x1200: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1200>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.主链路车辆动态信息交换业务.ToUInt16Value(); public override string Description => "主链路车辆动态信息交换业务"; public override JT809_LinkType LinkType => JT809_LinkType.main; + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1200 value = new JT809_0x1200(); + var virtualHex = reader.ReadVirtualArray(21); + value.VehicleNo = reader.ReadString(21); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]车牌号", value.VehicleNo); + value.VehicleColor = (JT809VehicleColorType)reader.ReadByte(); + writer.WriteString($"[{value.VehicleColor.ToByteValue()}]车牌颜色", value.VehicleColor.ToString()); + value.SubBusinessType = reader.ReadUInt16(); + writer.WriteString($"[{value.SubBusinessType.ReadNumber()}]子业务类型标识", ((JT809SubBusinessType)value.SubBusinessType).ToString()); + value.DataLength = reader.ReadUInt32(); + writer.WriteNumber($"[{value.DataLength.ReadNumber()}]后续数据长度", value.DataLength); + try + { + if (config.SubBusinessTypeFactory.TryGetValue(value.SubBusinessType, out object instance)) + { + if (instance is JT809SubBodies subBodies) + { + if (!subBodies.SkipSerialization) + { + instance.Analyze(ref reader, writer, config); + } + } + } + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); + } + } + public JT809_0x1200 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1200 value = new JT809_0x1200(); diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1300.cs b/src/JT809.Protocol/MessageBody/JT809_0x1300.cs index b7ab1cc..e82185e 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1300.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1300.cs @@ -2,8 +2,10 @@ using JT809.Protocol.Exceptions; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; using System; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -14,11 +16,38 @@ namespace JT809.Protocol.MessageBody /// <para>业务数据类型标识:UP_PLATFORM_MSG</para> /// <para>描述:下级平台向上级平台发送平台间交互信息</para> /// </summary> - public class JT809_0x1300: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1300> + public class JT809_0x1300: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1300>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.主链路平台间信息交互消息.ToUInt16Value(); public override string Description => "主链路平台间信息交互消息"; public override JT809_LinkType LinkType => JT809_LinkType.main; + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1300 value = new JT809_0x1300(); + value.SubBusinessType = reader.ReadUInt16(); + writer.WriteString($"[{value.SubBusinessType.ReadNumber()}]子业务类型标识", ((JT809SubBusinessType)value.SubBusinessType).ToString()); + value.DataLength = reader.ReadUInt32(); + writer.WriteNumber($"[{value.DataLength.ReadNumber()}]后续数据长度", value.DataLength); + try + { + if (config.SubBusinessTypeFactory.TryGetValue(value.SubBusinessType, out object instance)) + { + if (instance is JT809SubBodies subBodies) + { + if (!subBodies.SkipSerialization) + { + instance.Analyze(ref reader, writer, config); + } + } + } + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); + } + } + public JT809_0x1300 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1300 value = new JT809_0x1300(); diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1400.cs b/src/JT809.Protocol/MessageBody/JT809_0x1400.cs index 167db18..db66255 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1400.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1400.cs @@ -4,6 +4,7 @@ using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -15,12 +16,46 @@ namespace JT809.Protocol.MessageBody /// <para>业务数据类型标识:UP_WARN_MSG</para> /// <para>描述:下级平台向上级平台发送车辆报警信息业务</para> /// </summary> - public class JT809_0x1400: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1400>, IJT809_2019_Version + public class JT809_0x1400: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1400>, IJT809Analyze, IJT809_2019_Version { public override ushort MsgId => JT809BusinessType.主链路报警信息交互消息.ToUInt16Value(); public override string Description => "主链路报警信息交互消息"; public override JT809_LinkType LinkType => JT809_LinkType.main; + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1400 value = new JT809_0x1400(); + if (config.Version == JT809Version.JTT2011) + { + var virtualHex = reader.ReadVirtualArray(21); + value.VehicleNo = reader.ReadString(21); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]车牌号", value.VehicleNo); + value.VehicleColor = (JT809VehicleColorType)reader.ReadByte(); + writer.WriteString($"[{value.VehicleColor.ToByteValue()}]车牌颜色", value.VehicleColor.ToString()); + } + value.SubBusinessType = reader.ReadUInt16(); + writer.WriteString($"[{value.SubBusinessType.ReadNumber()}]子业务类型标识", ((JT809SubBusinessType)value.SubBusinessType).ToString()); + value.DataLength = reader.ReadUInt32(); + writer.WriteNumber($"[{value.DataLength.ReadNumber()}]后续数据长度", value.DataLength); + try + { + if (config.SubBusinessTypeFactory.TryGetValue(value.SubBusinessType, out object instance)) + { + if (instance is JT809SubBodies subBodies) + { + if (!subBodies.SkipSerialization) + { + instance.Analyze(ref reader, writer, config); + } + } + } + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); + } + } + public JT809_0x1400 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1400 value = new JT809_0x1400(); diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1500.cs b/src/JT809.Protocol/MessageBody/JT809_0x1500.cs index 8b69d91..5a5ddb1 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1500.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1500.cs @@ -2,7 +2,9 @@ using JT809.Protocol.Exceptions; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -13,11 +15,43 @@ namespace JT809.Protocol.MessageBody /// <para>业务数据类型标识:UP_CTRL_MSG</para> /// <para>描述:下级平台向上级平台发送车辆监管业务</para> /// </summary> - public class JT809_0x1500: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1500> + public class JT809_0x1500: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1500>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.主链路车辆监管消息.ToUInt16Value(); public override string Description => "主链路车辆监管消息"; public override JT809_LinkType LinkType => JT809_LinkType.main; + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1500 value = new JT809_0x1500(); + var virtualHex = reader.ReadVirtualArray(21); + value.VehicleNo = reader.ReadString(21); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]车牌号", value.VehicleNo); + value.VehicleColor = (JT809VehicleColorType)reader.ReadByte(); + writer.WriteString($"[{value.VehicleColor.ToByteValue()}]车牌颜色", value.VehicleColor.ToString()); + value.SubBusinessType = reader.ReadUInt16(); + writer.WriteString($"[{value.SubBusinessType.ReadNumber()}]子业务类型标识", ((JT809SubBusinessType)value.SubBusinessType).ToString()); + value.DataLength = reader.ReadUInt32(); + writer.WriteNumber($"[{value.DataLength.ReadNumber()}]后续数据长度", value.DataLength); + try + { + if (config.SubBusinessTypeFactory.TryGetValue(value.SubBusinessType, out object instance)) + { + if (instance is JT809SubBodies subBodies) + { + if (!subBodies.SkipSerialization) + { + instance.Analyze(ref reader, writer, config); + } + } + } + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); + } + } + public JT809_0x1500 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1500 value = new JT809_0x1500(); diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1600.cs b/src/JT809.Protocol/MessageBody/JT809_0x1600.cs index 51d5bae..8429500 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x1600.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x1600.cs @@ -2,7 +2,9 @@ using JT809.Protocol.Exceptions; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -13,12 +15,43 @@ namespace JT809.Protocol.MessageBody /// <para>消息方向:下级平台往上级平台</para> /// <para>描述:下级平台向上级平台发送车辆睁态信息交换业务</para> /// </summary> - public class JT809_0x1600: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1600> + public class JT809_0x1600: JT809ExchangeMessageBodies, IJT809MessagePackFormatter<JT809_0x1600>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.主链路静态信息交换消息.ToUInt16Value(); public override string Description => "主链路静态信息交换消息"; public override JT809_LinkType LinkType => JT809_LinkType.main; + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x1600 value = new JT809_0x1600(); + var virtualHex = reader.ReadVirtualArray(21); + value.VehicleNo = reader.ReadString(21); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}]车牌号", value.VehicleNo); + value.VehicleColor = (JT809VehicleColorType)reader.ReadByte(); + writer.WriteString($"[{value.VehicleColor.ToByteValue()}]车牌颜色", value.VehicleColor.ToString()); + value.SubBusinessType = reader.ReadUInt16(); + writer.WriteString($"[{value.SubBusinessType.ReadNumber()}]子业务类型标识", ((JT809SubBusinessType)value.SubBusinessType).ToString()); + value.DataLength = reader.ReadUInt32(); + writer.WriteNumber($"[{value.DataLength.ReadNumber()}]后续数据长度", value.DataLength); + try + { + if (config.SubBusinessTypeFactory.TryGetValue(value.SubBusinessType, out object instance)) + { + if (instance is JT809SubBodies subBodies) + { + if (!subBodies.SkipSerialization) + { + instance.Analyze(ref reader, writer, config); + } + } + } + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); + } + } + public JT809_0x1600 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x1600 value = new JT809_0x1600(); diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9001.cs b/src/JT809.Protocol/MessageBody/JT809_0x9001.cs index 35ce346..c3775c9 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x9001.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x9001.cs @@ -1,7 +1,9 @@ using JT809.Protocol.Enums; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -13,7 +15,7 @@ namespace JT809.Protocol.MessageBody /// <para>描述:主链路建立连接后,上级平台向下级平台发送从链路连接清求消息,以建立从链路连接</para> /// <para>下级平台在收到本息后,根据本校验码 VERIFY CODE 来实现数据的校验,校验后,则返回DOWN CONNECT RSP 消息</para> /// </summary> - public class JT809_0x9001 : JT809Bodies, IJT809MessagePackFormatter<JT809_0x9001> + public class JT809_0x9001 : JT809Bodies, IJT809MessagePackFormatter<JT809_0x9001>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.从链路连接请求消息.ToUInt16Value(); public override string Description => "从链路连接请求消息"; @@ -23,11 +25,18 @@ namespace JT809.Protocol.MessageBody /// </summary> public uint VerifyCode { get; set; } + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x9001 value = new JT809_0x9001(); + value.VerifyCode = reader.ReadUInt32(); + writer.WriteNumber($"[{value.VerifyCode.ReadNumber()}校验码]", value.VerifyCode); + } + public JT809_0x9001 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x9001 jT809_0X9001 = new JT809_0x9001(); - jT809_0X9001.VerifyCode = reader.ReadUInt32(); - return jT809_0X9001; + JT809_0x9001 value = new JT809_0x9001(); + value.VerifyCode = reader.ReadUInt32(); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9001 value, IJT809Config config) diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9002.cs b/src/JT809.Protocol/MessageBody/JT809_0x9002.cs index e1860a4..d6345c9 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x9002.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x9002.cs @@ -1,7 +1,9 @@ using JT809.Protocol.Enums; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -12,7 +14,7 @@ namespace JT809.Protocol.MessageBody /// <para>业务数据类型标识:DOWN_CONNNECT_RSP</para> /// <para>描述:下级平台作为服务器端向上级平台客户端返回从链路连接应答消息,上级平台在接收到该应答消息结果后</para> /// </summary> - public class JT809_0x9002:JT809Bodies, IJT809MessagePackFormatter<JT809_0x9002> + public class JT809_0x9002:JT809Bodies, IJT809MessagePackFormatter<JT809_0x9002>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.从链路连接应答信息.ToUInt16Value(); public override string Description => "从链路连接应答信息"; @@ -21,11 +23,19 @@ namespace JT809.Protocol.MessageBody /// 验证结果 /// </summary> public JT809_0x9002_Result Result { get; set; } + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x9002 value = new JT809_0x9002(); + value.Result = (JT809_0x9002_Result)reader.ReadByte(); + writer.WriteString($"[{value.Result.ToByteValue()}验证结果]", value.Result.ToString()); + } + public JT809_0x9002 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x9002 jT809_0X9002 = new JT809_0x9002(); - jT809_0X9002.Result = (JT809_0x9002_Result)reader.ReadByte(); - return jT809_0X9002; + JT809_0x9002 value = new JT809_0x9002(); + value.Result = (JT809_0x9002_Result)reader.ReadByte(); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9002 value, IJT809Config config) diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9003.cs b/src/JT809.Protocol/MessageBody/JT809_0x9003.cs index f070f1b..ba03cf6 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x9003.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x9003.cs @@ -1,7 +1,9 @@ using JT809.Protocol.Enums; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -12,7 +14,7 @@ namespace JT809.Protocol.MessageBody ///<para>业务数据类型标识:DOWN_DISCONNIrCT_REQ</para> ///<para>描述:从链路建立后,上级平台在取消该链路时,应向下级平台发送从链路注销请求消息</para> /// </summary> - public class JT809_0x9003: JT809Bodies, IJT809MessagePackFormatter<JT809_0x9003> + public class JT809_0x9003: JT809Bodies, IJT809MessagePackFormatter<JT809_0x9003>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.从链路注销请求消息.ToUInt16Value(); public override string Description => "从链路注销请求消息"; @@ -22,11 +24,18 @@ namespace JT809.Protocol.MessageBody /// </summary> public uint VerifyCode { get; set; } + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x9003 value = new JT809_0x9003(); + value.VerifyCode = reader.ReadUInt32(); + writer.WriteNumber($"[{value.VerifyCode.ReadNumber()}校验码]", value.VerifyCode); + } + public JT809_0x9003 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x9003 jT809_0X9003 = new JT809_0x9003(); - jT809_0X9003.VerifyCode = reader.ReadUInt32(); - return jT809_0X9003; + JT809_0x9003 value = new JT809_0x9003(); + value.VerifyCode = reader.ReadUInt32(); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9003 value, IJT809Config config) diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9007.cs b/src/JT809.Protocol/MessageBody/JT809_0x9007.cs index 9f3a0d8..695bfb9 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x9007.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x9007.cs @@ -1,7 +1,9 @@ using JT809.Protocol.Enums; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -16,7 +18,7 @@ namespace JT809.Protocol.MessageBody /// </para> /// <para>本条消息无需被通知方应答</para> /// </summary> - public class JT809_0x9007:JT809Bodies, IJT809MessagePackFormatter<JT809_0x9007> + public class JT809_0x9007:JT809Bodies, IJT809MessagePackFormatter<JT809_0x9007>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.从链路断开通知消息.ToUInt16Value(); public override string Description => "从链路断开通知消息"; @@ -24,16 +26,24 @@ namespace JT809.Protocol.MessageBody /// <summary> /// 错误代码 /// </summary> - public JT809_0x9007_ReasonCode ReasonCode { get; set; } + public JT809_0x1007_ErrorCode ErrorCode { get; set; } + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x9007 value = new JT809_0x9007(); + value.ErrorCode = (JT809_0x1007_ErrorCode)reader.ReadByte(); + writer.WriteString($"[{value.ErrorCode.ToByteValue()}错误代码]", value.ErrorCode.ToString()); + } + public JT809_0x9007 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x9007 jT809_0X9007 = new JT809_0x9007(); - jT809_0X9007.ReasonCode = (JT809_0x9007_ReasonCode)reader.ReadByte(); - return jT809_0X9007; + JT809_0x9007 value = new JT809_0x9007(); + value.ErrorCode = (JT809_0x1007_ErrorCode)reader.ReadByte(); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9007 value, IJT809Config config) { - writer.WriteByte((byte)value.ReasonCode); + writer.WriteByte((byte)value.ErrorCode); } } } diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9008.cs b/src/JT809.Protocol/MessageBody/JT809_0x9008.cs index 515f3b0..9cb3deb 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x9008.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x9008.cs @@ -1,7 +1,9 @@ using JT809.Protocol.Enums; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -9,21 +11,29 @@ namespace JT809.Protocol.MessageBody /// 上级平台主动关闭链路通知消息 /// <para>业务数据类型标识:DOWN_CLOSELINK_INFORM</para> /// </summary> - public class JT809_0x9008:JT809Bodies, IJT809MessagePackFormatter<JT809_0x9008> + public class JT809_0x9008:JT809Bodies, IJT809MessagePackFormatter<JT809_0x9008>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.上级平台主动关闭链路通知消息.ToUInt16Value(); public override string Description => "上级平台主动关闭链路通知消息"; #warning 待验证主从链路 public override JT809_LinkType LinkType => JT809_LinkType.subordinate; /// <summary> - /// 错误代码 + /// 链路关闭原因 /// </summary> public JT809_0x9008_ReasonCode ReasonCode { get; set; } + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x9008 value = new JT809_0x9008(); + value.ReasonCode = (JT809_0x9008_ReasonCode)reader.ReadByte(); + writer.WriteString($"[{value.ReasonCode.ToByteValue()}链路关闭原因]", value.ReasonCode.ToString()); + } + public JT809_0x9008 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { - JT809_0x9008 jT809_0X9008 = new JT809_0x9008(); - jT809_0X9008.ReasonCode = (JT809_0x9008_ReasonCode)reader.ReadByte(); - return jT809_0X9008; + JT809_0x9008 value = new JT809_0x9008(); + value.ReasonCode = (JT809_0x9008_ReasonCode)reader.ReadByte(); + return value; } public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9008 value, IJT809Config config) diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9101.cs b/src/JT809.Protocol/MessageBody/JT809_0x9101.cs index 16e3e58..0f5ac9d 100644 --- a/src/JT809.Protocol/MessageBody/JT809_0x9101.cs +++ b/src/JT809.Protocol/MessageBody/JT809_0x9101.cs @@ -1,10 +1,12 @@ using JT809.Protocol.Enums; using JT809.Protocol.Extensions; using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; using JT809.Protocol.MessagePack; using System; using System.Collections.Generic; using System.Text; +using System.Text.Json; namespace JT809.Protocol.MessageBody { @@ -16,7 +18,7 @@ namespace JT809.Protocol.MessageBody /// <para>描述:上级平台向下级平台定星通知已经收到下级平台上传的车辆定位信息数量(如:每收到10,000 条车辆定位信息通知一次)</para> /// <para>本条消息不需下级平台应答。</para> /// </summary> - public class JT809_0x9101:JT809Bodies, IJT809MessagePackFormatter<JT809_0x9101> + public class JT809_0x9101:JT809Bodies, IJT809MessagePackFormatter<JT809_0x9101>, IJT809Analyze { public override ushort MsgId => JT809BusinessType.接收车辆定位信息数量通知消息.ToUInt16Value(); public override string Description => "接收车辆定位信息数量通知消息"; @@ -35,6 +37,20 @@ namespace JT809.Protocol.MessageBody /// 注:采用 UTC 时间表示,如 2010-1-10 9:7:54 的 UTC 值为 1263085674,其在协议中表示为0x000000004B49286A. /// </summary> public DateTime EndTime { get; set; } + + public void Analyze(ref JT809MessagePackReader reader, Utf8JsonWriter writer, IJT809Config config) + { + JT809_0x9101 value = new JT809_0x9101(); + value.DynamicInfoTotal = reader.ReadUInt32(); + writer.WriteNumber($"[{value.DynamicInfoTotal.ReadNumber()}START_TIME_END_TIME共收到的车辆定位信息数量]", value.DynamicInfoTotal); + var virtualHex = reader.ReadVirtualArray(8); + value.StartTime = reader.ReadUTCDateTime(); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}开始时间]", value.StartTime); + virtualHex = reader.ReadVirtualArray(8); + value.EndTime = reader.ReadUTCDateTime(); + writer.WriteString($"[{virtualHex.ToArray().ToHexString()}结束时间]", value.EndTime); + } + public JT809_0x9101 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) { JT809_0x9101 value = new JT809_0x9101(); diff --git a/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs b/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs index 4163888..3c28c81 100644 --- a/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs +++ b/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs @@ -237,6 +237,10 @@ namespace JT809.Protocol.MessagePack { return BinaryPrimitives.ReadInt64BigEndian(GetReadOnlySpan(8)); } + public ReadOnlySpan<byte> ReadVirtualArray(int count) + { + return GetVirtualReadOnlySpan(count); + } public byte ReadByte() { return GetReadOnlySpan(1)[0];