diff --git a/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj b/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj index 0553d6f..a34e159 100644 --- a/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj +++ b/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.1 diff --git a/src/JT809.Protocol.Test/JT809Extensions/JT809BinaryExtensionsTest.cs b/src/JT809.Protocol.Test/JT809Extensions/JT809BinaryExtensionsTest.cs new file mode 100644 index 0000000..40ca6a8 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809Extensions/JT809BinaryExtensionsTest.cs @@ -0,0 +1,20 @@ +using JT809.Protocol.JT809Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.JT809Extensions +{ + public class JT809BinaryExtensionsTest + { + [Fact] + public void Test1() + { + string vno = "粤A12345"; + byte[] bytes = JT809BinaryExtensions.encoding.GetBytes(vno); + Assert.Equal(7,vno.Length); + Assert.Equal(8, bytes.Length); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1006Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1006Test.cs new file mode 100644 index 0000000..67f6aa0 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1006Test.cs @@ -0,0 +1,26 @@ +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1006Test + { + [Fact] + public void Test1() + { + + } + + [Fact] + public void Test2() + { + + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs new file mode 100644 index 0000000..cafe73a --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs @@ -0,0 +1,44 @@ +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.JT809SubMessageBody; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1300Test + { + [Fact] + public void Test1() + { + JT809_0x1300 jT809Bodies = new JT809_0x1300(); + jT809Bodies.SubBusinessType = JT809Enums.JT809SubBusinessType.UP_PLATFORM_MSG_POST_QUERY_ACK; + jT809Bodies.JT809SubBodies = new JT809_0x1300_0x1301 + { + ObjectID="111", + InfoContent= "22ha22", + InfoID= 1234, + ObjectType= JT809Enums.JT809_0x1301_ObjectType.当前连接的下级平台 + }; + var hex = JT809Serializer.Serialize(jT809Bodies).ToHexString(); + //"13 01 00 00 00 1B 01 31 31 31 00 00 00 00 00 00 00 00 00 00 00 04 D2 00 00 00 06 32 32 68 61 32 32" + } + + [Fact] + public void Test2() + { + var bytes = "13 01 00 00 00 1B 01 31 31 31 00 00 00 00 00 00 00 00 00 00 00 04 D2 00 00 00 06 32 32 68 61 32 32".ToHexBytes(); + JT809_0x1300 jT809Bodies = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809Enums.JT809SubBusinessType.UP_PLATFORM_MSG_POST_QUERY_ACK, jT809Bodies.SubBusinessType); + JT809_0x1300_0x1301 jT809SubBodies = (JT809_0x1300_0x1301)jT809Bodies.JT809SubBodies; + Assert.Equal("111", jT809SubBodies.ObjectID); + Assert.Equal("22ha22", jT809SubBodies.InfoContent); + Assert.Equal((uint)1234, jT809SubBodies.InfoID); + Assert.Equal(JT809Enums.JT809_0x1301_ObjectType.当前连接的下级平台, jT809SubBodies.ObjectType); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs new file mode 100644 index 0000000..6e70e51 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs @@ -0,0 +1,41 @@ +using JT809.Protocol; +using JT809.Protocol.JT809Extensions; +using JT809.Protocol.JT809MessageBody; +using JT809.Protocol.JT809Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.JT809SubMessageBody; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1600Test + { + [Fact] + public void Test1() + { + JT809_0x1600 jT809Bodies = new JT809_0x1600(); + jT809Bodies.VehicleNo = "粤A12345"; + jT809Bodies.VehicleColor = JT809Enums.JT809VehicleColorType.蓝色; + jT809Bodies.SubBusinessType = JT809Enums.JT809SubBusinessType.UP_BASE_MSG_VEHICLE_ADDED_ACK; + jT809Bodies.JT809SubBodies = new JT809_0x1600_0x1601 + { + CarInfo = "什么鬼" + }; + var hex = JT809Serializer.Serialize(jT809Bodies).ToHexString(); + //"D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 16 01 00 00 00 06 CA B2 C3 B4 B9 ED" + } + + [Fact] + public void Test2() + { + var bytes = "D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 16 01 00 00 00 06 CA B2 C3 B4 B9 ED".ToHexBytes(); + JT809_0x1600 jT809Bodies = JT809Serializer.Deserialize(bytes); + Assert.Equal("粤A12345", jT809Bodies.VehicleNo); + Assert.Equal(JT809Enums.JT809VehicleColorType.蓝色, jT809Bodies.VehicleColor); + Assert.Equal(JT809Enums.JT809SubBusinessType.UP_BASE_MSG_VEHICLE_ADDED_ACK, jT809Bodies.SubBusinessType); + Assert.Equal("什么鬼", ((JT809_0x1600_0x1601)jT809Bodies.JT809SubBodies).CarInfo); + } + } +} diff --git a/src/JT809.Protocol/JT809.Protocol.csproj b/src/JT809.Protocol/JT809.Protocol.csproj index bc1209b..f5acd13 100644 --- a/src/JT809.Protocol/JT809.Protocol.csproj +++ b/src/JT809.Protocol/JT809.Protocol.csproj @@ -3,6 +3,13 @@ netstandard2.0 latest + Copyright 2016-2018. + SmallChi + JT809 + JT809 + JT809 + JT809 + true diff --git a/src/JT809.Protocol/JT809Bodies.cs b/src/JT809.Protocol/JT809Bodies.cs index 69d1d77..3baba1c 100644 --- a/src/JT809.Protocol/JT809Bodies.cs +++ b/src/JT809.Protocol/JT809Bodies.cs @@ -1,10 +1,33 @@ -using System; +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Enums; +using JT809.Protocol.JT809Formatters; +using System; using System.Collections.Generic; using System.Text; namespace JT809.Protocol { - public abstract class JT809Bodies + public abstract class JT809Bodies { + /// + /// 车牌号 + /// + public string VehicleNo { get; set; } + /// + /// 车辆颜色 + /// + public JT809VehicleColorType VehicleColor { get; set; } = JT809VehicleColorType.其他; + /// + /// 子业务类型标识 + /// + public JT809SubBusinessType SubBusinessType { get; set; } = JT809SubBusinessType.None; + /// + /// 后续数据长度 + /// + public uint DataLength { get; set; } + /// + /// 子业务数据体 + /// + public JT809SubBodies JT809SubBodies { get; set; } } } diff --git a/src/JT809.Protocol/JT809Enums/JT809SubBusinessType.cs b/src/JT809.Protocol/JT809Enums/JT809SubBusinessType.cs index 5f703e1..6648373 100644 --- a/src/JT809.Protocol/JT809Enums/JT809SubBusinessType.cs +++ b/src/JT809.Protocol/JT809Enums/JT809SubBusinessType.cs @@ -9,6 +9,7 @@ namespace JT809.Protocol.JT809Enums /// public enum JT809SubBusinessType : ushort { + None=0x0000, #region 主链路动态信息交换消息 UP_EXG_MSG /// /// 上传车辆注册信息 diff --git a/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs b/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs index 9f7c4fd..0ba8294 100644 --- a/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs +++ b/src/JT809.Protocol/JT809Extensions/JT809BinaryExtensions.cs @@ -43,7 +43,7 @@ namespace JT809.Protocol.JT809Extensions } } - private static Encoding encoding; + public static Encoding encoding; public static int ReadBCD32(this byte data, byte dig) { diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1006Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809BodiesFormatter.cs similarity index 51% rename from src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1006Formatter.cs rename to src/JT809.Protocol/JT809Formatters/JT809BodiesFormatter.cs index 5308752..b90849c 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1006Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809BodiesFormatter.cs @@ -2,48 +2,47 @@ using JT809.Protocol.JT809Enums; using JT809.Protocol.JT809Exceptions; using JT809.Protocol.JT809Extensions; -using JT809.Protocol.JT809MessageBody; using System; using System.Buffers; using System.Collections.Generic; using System.Text; -namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters +namespace JT809.Protocol.JT809Formatters { - public class JT809_0x1006Formatter : IJT809Formatter + public class JT809BodiesFormatter : IJT809Formatter + where TJT809Bodies: JT809Bodies,new () { - public JT809_0x1006 Deserialize(ReadOnlySpan bytes, out int readSize) + public TJT809Bodies Deserialize(ReadOnlySpan bytes, out int readSize) { int offset = 0; - JT809_0x1006 jT809_0X1006 = new JT809_0x1006(); - jT809_0X1006.VehicleNo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21); - jT809_0X1006.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X1006.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X1006.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); + TJT809Bodies jT809Bodies = new TJT809Bodies(); + jT809Bodies.VehicleNo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21); + jT809Bodies.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); + jT809Bodies.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); + jT809Bodies.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809_0X1006.SubBusinessType.GetAttribute(); + JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809Bodies.SubBusinessType.GetAttribute(); if (jT809SubBodiesTypeAttribute == null) { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809_0X1006.SubBusinessType.ToString()}"); + throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809Bodies.SubBusinessType.ToString()}"); } try { - jT809_0X1006.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809_0X1006.DataLength), out readSize); + jT809Bodies.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809Bodies.DataLength), out readSize); } catch { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X1006.SubBusinessType.ToString()}"); + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809Bodies.SubBusinessType.ToString()}"); } readSize = offset; - return jT809_0X1006; + return jT809Bodies; } - public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1006 value) + public int Serialize(IMemoryOwner memoryOwner, int offset, TJT809Bodies value) { offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21); offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor); offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); if (jT809SubBodiesTypeAttribute == null) @@ -52,7 +51,11 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters } try { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); + // 先写入内容,然后在根据内容反写内容长度 + offset = offset + 4; + int contentOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); + JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset - 4, (uint)(contentOffset- offset)); + offset = contentOffset; } catch { diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1200Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1200Formatter.cs deleted file mode 100644 index 33be53b..0000000 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1200Formatter.cs +++ /dev/null @@ -1,64 +0,0 @@ -using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Exceptions; -using JT809.Protocol.JT809Extensions; -using JT809.Protocol.JT809MessageBody; -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Text; - -namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters -{ - public class JT809_0x1200Formatter : IJT809Formatter - { - public JT809_0x1200 Deserialize(ReadOnlySpan bytes, out int readSize) - { - int offset = 0; - JT809_0x1200 jT809_0X1200 = new JT809_0x1200(); - jT809_0X1200.VehicleNo =JT809BinaryExtensions.ReadStringLittle(bytes, ref offset,21); - jT809_0X1200.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X1200.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X1200.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809_0X1200.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809_0X1200.SubBusinessType.ToString()}"); - } - try - { - jT809_0X1200.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809_0X1200.DataLength), out readSize); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X1200.SubBusinessType.ToString()}"); - } - readSize = offset; - return jT809_0X1200; - } - - public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1200 value) - { - offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21); - offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{value.SubBusinessType.ToString()}"); - } - try - { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); - } - return offset; - } - } -} diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs index fb4ea0d..43c62c9 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1300Formatter.cs @@ -39,7 +39,7 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1300 value) { offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); + //offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); if (jT809SubBodiesTypeAttribute == null) @@ -48,7 +48,11 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters } try { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); + // 先写入内容,然后在根据内容反写内容长度 + offset = offset + 4; + int contentOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); + JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset - 4, (uint)(contentOffset - offset)); + offset = contentOffset; } catch { diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1400Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1400Formatter.cs deleted file mode 100644 index 8333a8f..0000000 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1400Formatter.cs +++ /dev/null @@ -1,64 +0,0 @@ -using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Exceptions; -using JT809.Protocol.JT809Extensions; -using JT809.Protocol.JT809MessageBody; -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Text; - -namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters -{ - public class JT809_0x1400Formatter : IJT809Formatter - { - public JT809_0x1400 Deserialize(ReadOnlySpan bytes, out int readSize) - { - int offset = 0; - JT809_0x1400 jT809_0X1400 = new JT809_0x1400(); - jT809_0X1400.VehicleNo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21); - jT809_0X1400.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X1400.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X1400.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809_0X1400.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809_0X1400.SubBusinessType.ToString()}"); - } - try - { - jT809_0X1400.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809_0X1400.DataLength), out readSize); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X1400.SubBusinessType.ToString()}"); - } - readSize = offset; - return jT809_0X1400; - } - - public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1400 value) - { - offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21); - offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{value.SubBusinessType.ToString()}"); - } - try - { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); - } - return offset; - } - } -} diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1500Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1500Formatter.cs deleted file mode 100644 index fc84cb3..0000000 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1500Formatter.cs +++ /dev/null @@ -1,64 +0,0 @@ -using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Exceptions; -using JT809.Protocol.JT809Extensions; -using JT809.Protocol.JT809MessageBody; -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Text; - -namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters -{ - public class JT809_0x1500Formatter : IJT809Formatter - { - public JT809_0x1500 Deserialize(ReadOnlySpan bytes, out int readSize) - { - int offset = 0; - JT809_0x1500 jT809_0X1500 = new JT809_0x1500(); - jT809_0X1500.VehicleNo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21); - jT809_0X1500.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X1500.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X1500.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809_0X1500.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809_0X1500.SubBusinessType.ToString()}"); - } - try - { - jT809_0X1500.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809_0X1500.DataLength), out readSize); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X1500.SubBusinessType.ToString()}"); - } - readSize = offset; - return jT809_0X1500; - } - - public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1500 value) - { - offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21); - offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{value.SubBusinessType.ToString()}"); - } - try - { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); - } - return offset; - } - } -} diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1600Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1600Formatter.cs deleted file mode 100644 index 678e4b1..0000000 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x1600Formatter.cs +++ /dev/null @@ -1,64 +0,0 @@ -using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Exceptions; -using JT809.Protocol.JT809Extensions; -using JT809.Protocol.JT809MessageBody; -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Text; - -namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters -{ - public class JT809_0x1600Formatter : IJT809Formatter - { - public JT809_0x1600 Deserialize(ReadOnlySpan bytes, out int readSize) - { - int offset = 0; - JT809_0x1600 jT809_0X1600 = new JT809_0x1600(); - jT809_0X1600.VehicleNo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21); - jT809_0X1600.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X1600.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X1600.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809_0X1600.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809_0X1600.SubBusinessType.ToString()}"); - } - try - { - jT809_0X1600.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809_0X1600.DataLength), out readSize); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X1600.SubBusinessType.ToString()}"); - } - readSize = offset; - return jT809_0X1600; - } - - public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x1600 value) - { - offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21); - offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{value.SubBusinessType.ToString()}"); - } - try - { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); - } - return offset; - } - } -} diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9200Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9200Formatter.cs deleted file mode 100644 index dbe687c..0000000 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9200Formatter.cs +++ /dev/null @@ -1,64 +0,0 @@ -using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Exceptions; -using JT809.Protocol.JT809Extensions; -using JT809.Protocol.JT809MessageBody; -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Text; - -namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters -{ - public class JT809_0x9200Formatter : IJT809Formatter - { - public JT809_0x9200 Deserialize(ReadOnlySpan bytes, out int readSize) - { - int offset = 0; - JT809_0x9200 jT809_0X9200 = new JT809_0x9200(); - jT809_0X9200.VehicleNo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21); - jT809_0X9200.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X9200.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X9200.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809_0X9200.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809_0X9200.SubBusinessType.ToString()}"); - } - try - { - jT809_0X9200.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809_0X9200.DataLength), out readSize); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X9200.SubBusinessType.ToString()}"); - } - readSize = offset; - return jT809_0X9200; - } - - public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9200 value) - { - offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21); - offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{value.SubBusinessType.ToString()}"); - } - try - { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); - } - return offset; - } - } -} diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs index 32d786d..7d32c1e 100644 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs +++ b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9300Formatter.cs @@ -39,7 +39,7 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9300 value) { offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); + //offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); if (jT809SubBodiesTypeAttribute == null) @@ -48,7 +48,11 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters } try { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); + // 先写入内容,然后在根据内容反写内容长度 + offset = offset + 4; + int contentOffset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); + JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset - 4, (uint)(contentOffset - offset)); + offset = contentOffset; } catch { diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9400Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9400Formatter.cs deleted file mode 100644 index 081fab2..0000000 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9400Formatter.cs +++ /dev/null @@ -1,64 +0,0 @@ -using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Exceptions; -using JT809.Protocol.JT809Extensions; -using JT809.Protocol.JT809MessageBody; -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Text; - -namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters -{ - public class JT809_0x9400Formatter : IJT809Formatter - { - public JT809_0x9400 Deserialize(ReadOnlySpan bytes, out int readSize) - { - int offset = 0; - JT809_0x9400 jT809_0X9400 = new JT809_0x9400(); - jT809_0X9400.VehicleNo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21); - jT809_0X9400.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X9400.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X9400.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809_0X9400.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809_0X9400.SubBusinessType.ToString()}"); - } - try - { - jT809_0X9400.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809_0X9400.DataLength), out readSize); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X9400.SubBusinessType.ToString()}"); - } - readSize = offset; - return jT809_0X9400; - } - - public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9400 value) - { - offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21); - offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{value.SubBusinessType.ToString()}"); - } - try - { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); - } - return offset; - } - } -} diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9500Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9500Formatter.cs deleted file mode 100644 index 9303a30..0000000 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9500Formatter.cs +++ /dev/null @@ -1,64 +0,0 @@ -using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Exceptions; -using JT809.Protocol.JT809Extensions; -using JT809.Protocol.JT809MessageBody; -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Text; - -namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters -{ - public class JT809_0x9500Formatter : IJT809Formatter - { - public JT809_0x9500 Deserialize(ReadOnlySpan bytes, out int readSize) - { - int offset = 0; - JT809_0x9500 jT809_0X9500 = new JT809_0x9500(); - jT809_0X9500.VehicleNo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21); - jT809_0X9500.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X9500.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X9500.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809_0X9500.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809_0X9500.SubBusinessType.ToString()}"); - } - try - { - jT809_0X9500.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809_0X9500.DataLength), out readSize); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X9500.SubBusinessType.ToString()}"); - } - readSize = offset; - return jT809_0X9500; - } - - public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9500 value) - { - offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21); - offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{value.SubBusinessType.ToString()}"); - } - try - { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); - } - return offset; - } - } -} diff --git a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9600Formatter.cs b/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9600Formatter.cs deleted file mode 100644 index 0010368..0000000 --- a/src/JT809.Protocol/JT809Formatters/JT809MessageBodyFormatters/JT809_0x9600Formatter.cs +++ /dev/null @@ -1,64 +0,0 @@ -using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Exceptions; -using JT809.Protocol.JT809Extensions; -using JT809.Protocol.JT809MessageBody; -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Text; - -namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters -{ - public class JT809_0x9600Formatter : IJT809Formatter - { - public JT809_0x9600 Deserialize(ReadOnlySpan bytes, out int readSize) - { - int offset = 0; - JT809_0x9600 jT809_0X9600 = new JT809_0x9600(); - jT809_0X9600.VehicleNo = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 21); - jT809_0X9600.VehicleColor = (JT809VehicleColorType)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); - jT809_0X9600.SubBusinessType = (JT809SubBusinessType)JT809BinaryExtensions.ReadUInt16Little(bytes, ref offset); - jT809_0X9600.DataLength = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809_0X9600.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{jT809_0X9600.SubBusinessType.ToString()}"); - } - try - { - jT809_0X9600.JT809SubBodies = JT809FormatterResolverExtensions.JT809DynamicDeserialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), bytes.Slice(offset, (int)jT809_0X9600.DataLength), out readSize); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X9600.SubBusinessType.ToString()}"); - } - readSize = offset; - return jT809_0X9600; - } - - public int Serialize(IMemoryOwner memoryOwner, int offset, JT809_0x9600 value) - { - offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.VehicleNo, 21); - offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.VehicleColor); - offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, (ushort)value.SubBusinessType); - offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.DataLength); - //JT809.Protocol.JT809Enums.JT809BusinessType 映射对应消息特性 - JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = value.SubBusinessType.GetAttribute(); - if (jT809SubBodiesTypeAttribute == null) - { - throw new JT809Exception(JT809ErrorCode.GetAttributeError, $"JT809BodiesTypeAttribute Not Found>{value.SubBusinessType.ToString()}"); - } - try - { - offset = JT809FormatterResolverExtensions.JT809DynamicSerialize(JT809FormatterExtensions.GetFormatter(jT809SubBodiesTypeAttribute.JT809BodiesType), memoryOwner, offset, value.JT809SubBodies); - } - catch - { - throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); - } - return offset; - } - } -} diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x1006.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x1006.cs index 0fab2b9..dbd8386 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x1006.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x1006.cs @@ -1,7 +1,5 @@ -using JT809.Protocol.JT809Enums; -using System; -using System.Collections.Generic; -using System.Text; +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Formatters; namespace JT809.Protocol.JT809MessageBody { @@ -13,27 +11,9 @@ namespace JT809.Protocol.JT809MessageBody /// 描述:上级平台收到下级平台的主链路连接保持请求消息后,向下级平台返回.主链路连接保持应答消息,保持主链路的连接状态。 /// 主链路连接保持应答消息,数据体为空。 /// + [JT809Formatter(typeof(JT809BodiesFormatter))] public class JT809_0x1006:JT809Bodies { - /// - /// 车牌号 - /// - public string VehicleNo { get; set; } - /// - /// 车辆颜色 - /// - public JT809VehicleColorType VehicleColor { get; set; } - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x1200.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x1200.cs index 92cf7bc..2ae9a7b 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x1200.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x1200.cs @@ -1,9 +1,6 @@ using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; -using System; -using System.Collections.Generic; -using System.Text; +using JT809.Protocol.JT809Formatters; + namespace JT809.Protocol.JT809MessageBody { @@ -14,28 +11,9 @@ namespace JT809.Protocol.JT809MessageBody /// 业务数据类型标识:UP_EXG_MSG /// 描述:下级平台向上级平台发送车辆动态信息交换业务数据包 /// - [JT809Formatter(typeof(JT809_0x1200Formatter))] + [JT809Formatter(typeof(JT809BodiesFormatter))] public class JT809_0x1200:JT809Bodies { - /// - /// 车牌号 - /// - public string VehicleNo { get; set; } - /// - /// 车辆颜色 - /// - public JT809VehicleColorType VehicleColor { get; set; } - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x1300.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x1300.cs index 3136f9c..85650a7 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x1300.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x1300.cs @@ -1,7 +1,6 @@ -using JT809.Protocol.JT809Enums; -using System; -using System.Collections.Generic; -using System.Text; +using JT809.Protocol.JT809Attributes; +using JT809.Protocol.JT809Formatters; +using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; namespace JT809.Protocol.JT809MessageBody { @@ -12,19 +11,9 @@ namespace JT809.Protocol.JT809MessageBody /// 业务数据类型标识:UP_PLATFORM_MSG /// 描述:下级平台向上级平台发送平台间交互信息 /// + [JT809Formatter(typeof(JT809_0x1300Formatter))] public class JT809_0x1300:JT809Bodies { - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x1400.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x1400.cs index 8979616..bce5a89 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x1400.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x1400.cs @@ -1,9 +1,6 @@ using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; -using System; -using System.Collections.Generic; -using System.Text; +using JT809.Protocol.JT809Formatters; + namespace JT809.Protocol.JT809MessageBody { @@ -15,28 +12,9 @@ namespace JT809.Protocol.JT809MessageBody /// 业务数据类型标识:UP_WARN_MSG /// 描述:下级平台向上级平台发送车辆报警信息业务 /// - [JT809Formatter(typeof(JT809_0x1400Formatter))] + [JT809Formatter(typeof(JT809BodiesFormatter))] public class JT809_0x1400:JT809Bodies { - /// - /// 车牌号 - /// - public string VehicleNo { get; set; } - /// - /// 车辆颜色 - /// - public JT809VehicleColorType VehicleColor { get; set; } - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x1500.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x1500.cs index 863e5d7..a7fa1b0 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x1500.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x1500.cs @@ -1,9 +1,6 @@ using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; -using System; -using System.Collections.Generic; -using System.Text; +using JT809.Protocol.JT809Formatters; + namespace JT809.Protocol.JT809MessageBody { @@ -14,28 +11,9 @@ namespace JT809.Protocol.JT809MessageBody /// 业务数据类型标识:UP_CTRL_MSG /// 描述:下级平台向上级平台发送车辆监管业务 /// - [JT809Formatter(typeof(JT809_0x1500Formatter))] + [JT809Formatter(typeof(JT809BodiesFormatter))] public class JT809_0x1500:JT809Bodies { - /// - /// 车牌号 - /// - public string VehicleNo { get; set; } - /// - /// 车辆颜色 - /// - public JT809VehicleColorType VehicleColor { get; set; } - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x1600.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x1600.cs index 0f92142..6ff3410 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x1600.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x1600.cs @@ -1,9 +1,6 @@ using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; -using System; -using System.Collections.Generic; -using System.Text; +using JT809.Protocol.JT809Formatters; + namespace JT809.Protocol.JT809MessageBody { @@ -14,28 +11,9 @@ namespace JT809.Protocol.JT809MessageBody /// 消息方向:下级平台往上级平台 /// 描述:下级平台向上级平台发送车辆睁态信息交换业务 /// - [JT809Formatter(typeof(JT809_0x1600Formatter))] + [JT809Formatter(typeof(JT809BodiesFormatter))] public class JT809_0x1600:JT809Bodies { - /// - /// 车牌号 - /// - public string VehicleNo { get; set; } - /// - /// 车辆颜色 - /// - public JT809VehicleColorType VehicleColor { get; set; } - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x9200.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x9200.cs index 57562b0..55f397d 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x9200.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x9200.cs @@ -1,9 +1,6 @@ using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; -using System; -using System.Collections.Generic; -using System.Text; +using JT809.Protocol.JT809Formatters; + namespace JT809.Protocol.JT809MessageBody { @@ -14,28 +11,9 @@ namespace JT809.Protocol.JT809MessageBody /// 业务数据类型标识:DOWN_EXG_MSG /// 描述:上级平台作为客户端向下级平台服务端发送车辆动态信息交换业务 /// - [JT809Formatter(typeof(JT809_0x9200Formatter))] + [JT809Formatter(typeof(JT809BodiesFormatter))] public class JT809_0x9200:JT809Bodies { - /// - /// 车牌号 - /// - public string VehicleNo { get; set; } - /// - /// 车辆颜色 - /// - public JT809VehicleColorType VehicleColor { get; set; } - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x9300.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x9300.cs index e1642be..8182731 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x9300.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x9300.cs @@ -1,9 +1,6 @@ using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; +using JT809.Protocol.JT809Formatters; using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; -using System; -using System.Collections.Generic; -using System.Text; namespace JT809.Protocol.JT809MessageBody { @@ -17,17 +14,6 @@ namespace JT809.Protocol.JT809MessageBody [JT809Formatter(typeof(JT809_0x9300Formatter))] public class JT809_0x9300:JT809Bodies { - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x9400.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x9400.cs index bb4944c..022e305 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x9400.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x9400.cs @@ -1,5 +1,6 @@ using JT809.Protocol.JT809Attributes; using JT809.Protocol.JT809Enums; +using JT809.Protocol.JT809Formatters; using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; using System; using System.Collections.Generic; @@ -14,28 +15,9 @@ namespace JT809.Protocol.JT809MessageBody /// 业务数据类型标识:DOWN_WARN_MSG /// 描述:上级平台向下级平台发送报瞥信息业务 /// - [JT809Formatter(typeof(JT809_0x9400Formatter))] + [JT809Formatter(typeof(JT809BodiesFormatter))] public class JT809_0x9400:JT809Bodies { - /// - /// 车牌号 - /// - public string VehicleNo { get; set; } - /// - /// 车辆颜色 - /// - public JT809VehicleColorType VehicleColor { get; set; } - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x9500.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x9500.cs index fd20f19..b640b54 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x9500.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x9500.cs @@ -1,9 +1,6 @@ using JT809.Protocol.JT809Attributes; -using JT809.Protocol.JT809Enums; -using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; -using System; -using System.Collections.Generic; -using System.Text; +using JT809.Protocol.JT809Formatters; + namespace JT809.Protocol.JT809MessageBody { @@ -14,28 +11,9 @@ namespace JT809.Protocol.JT809MessageBody /// 业务数据类型标识:DOWN_CTRL_MSG /// 描述:上级平台向下级平台发送车辆监监管业务 /// - [JT809Formatter(typeof(JT809_0x9500Formatter))] + [JT809Formatter(typeof(JT809BodiesFormatter))] public class JT809_0x9500:JT809Bodies { - /// - /// 车牌号 - /// - public string VehicleNo { get; set; } - /// - /// 车辆颜色 - /// - public JT809VehicleColorType VehicleColor { get; set; } - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } } diff --git a/src/JT809.Protocol/JT809MessageBody/JT809_0x9600.cs b/src/JT809.Protocol/JT809MessageBody/JT809_0x9600.cs index 72aff60..6f96fb0 100644 --- a/src/JT809.Protocol/JT809MessageBody/JT809_0x9600.cs +++ b/src/JT809.Protocol/JT809MessageBody/JT809_0x9600.cs @@ -1,5 +1,6 @@ using JT809.Protocol.JT809Attributes; using JT809.Protocol.JT809Enums; +using JT809.Protocol.JT809Formatters; using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; using System; using System.Collections.Generic; @@ -14,28 +15,9 @@ namespace JT809.Protocol.JT809MessageBody /// 业务数据类型标识:DOWN_BASE_MSG /// 描述:上级平台向下级平台发送车辆静态信息交换业务 /// - [JT809Formatter(typeof(JT809_0x9600Formatter))] + [JT809Formatter(typeof(JT809BodiesFormatter))] public class JT809_0x9600:JT809Bodies { - /// - /// 车牌号 - /// - public string VehicleNo { get; set; } - /// - /// 车辆颜色 - /// - public JT809VehicleColorType VehicleColor { get; set; } - /// - /// 子业务类型标识 - /// - public JT809SubBusinessType SubBusinessType { get; set; } - /// - /// 后续数据长度 - /// - public uint DataLength { get; set; } - /// - /// 子业务数据体 - /// - public JT809SubBodies JT809SubBodies { get; set; } + } }