@@ -1,4 +1,4 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<PropertyGroup> | |||
<TargetFramework>netcoreapp2.1</TargetFramework> | |||
@@ -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); | |||
} | |||
} | |||
} |
@@ -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() | |||
{ | |||
} | |||
} | |||
} |
@@ -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<JT809_0x1300>(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); | |||
} | |||
} | |||
} |
@@ -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<JT809_0x1600>(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); | |||
} | |||
} | |||
} |
@@ -3,6 +3,13 @@ | |||
<PropertyGroup> | |||
<TargetFramework>netstandard2.0</TargetFramework> | |||
<LangVersion>latest</LangVersion> | |||
<Copyright>Copyright 2016-2018.</Copyright> | |||
<Authors>SmallChi</Authors> | |||
<PackageId>JT809</PackageId> | |||
<Product>JT809</Product> | |||
<Description>JT809</Description> | |||
<PackageReleaseNotes>JT809</PackageReleaseNotes> | |||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | |||
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } = JT809VehicleColorType.其他; | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } = JT809SubBusinessType.None; | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -9,6 +9,7 @@ namespace JT809.Protocol.JT809Enums | |||
///</summary> | |||
public enum JT809SubBusinessType : ushort | |||
{ | |||
None=0x0000, | |||
#region 主链路动态信息交换消息 UP_EXG_MSG | |||
/// <summary> | |||
/// 上传车辆注册信息 | |||
@@ -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) | |||
{ | |||
@@ -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<JT809_0x1006> | |||
public class JT809BodiesFormatter<TJT809Bodies> : IJT809Formatter<TJT809Bodies> | |||
where TJT809Bodies: JT809Bodies,new () | |||
{ | |||
public JT809_0x1006 Deserialize(ReadOnlySpan<byte> bytes, out int readSize) | |||
public TJT809Bodies Deserialize(ReadOnlySpan<byte> 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>(); | |||
JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809Bodies.SubBusinessType.GetAttribute<JT809BodiesTypeAttribute>(); | |||
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<byte> memoryOwner, int offset, JT809_0x1006 value) | |||
public int Serialize(IMemoryOwner<byte> 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<JT809BodiesTypeAttribute>(); | |||
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 | |||
{ |
@@ -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<JT809_0x1200> | |||
{ | |||
public JT809_0x1200 Deserialize(ReadOnlySpan<byte> 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<JT809BodiesTypeAttribute>(); | |||
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<byte> 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<JT809BodiesTypeAttribute>(); | |||
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; | |||
} | |||
} | |||
} |
@@ -39,7 +39,7 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters | |||
public int Serialize(IMemoryOwner<byte> 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<JT809BodiesTypeAttribute>(); | |||
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 | |||
{ | |||
@@ -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<JT809_0x1400> | |||
{ | |||
public JT809_0x1400 Deserialize(ReadOnlySpan<byte> 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<JT809BodiesTypeAttribute>(); | |||
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<byte> 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<JT809BodiesTypeAttribute>(); | |||
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; | |||
} | |||
} | |||
} |
@@ -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<JT809_0x1500> | |||
{ | |||
public JT809_0x1500 Deserialize(ReadOnlySpan<byte> 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<JT809BodiesTypeAttribute>(); | |||
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<byte> 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<JT809BodiesTypeAttribute>(); | |||
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; | |||
} | |||
} | |||
} |
@@ -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<JT809_0x1600> | |||
{ | |||
public JT809_0x1600 Deserialize(ReadOnlySpan<byte> 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<JT809BodiesTypeAttribute>(); | |||
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<byte> 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<JT809BodiesTypeAttribute>(); | |||
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; | |||
} | |||
} | |||
} |
@@ -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<JT809_0x9200> | |||
{ | |||
public JT809_0x9200 Deserialize(ReadOnlySpan<byte> 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<JT809BodiesTypeAttribute>(); | |||
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<byte> 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<JT809BodiesTypeAttribute>(); | |||
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; | |||
} | |||
} | |||
} |
@@ -39,7 +39,7 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters | |||
public int Serialize(IMemoryOwner<byte> 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<JT809BodiesTypeAttribute>(); | |||
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 | |||
{ | |||
@@ -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<JT809_0x9400> | |||
{ | |||
public JT809_0x9400 Deserialize(ReadOnlySpan<byte> 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<JT809BodiesTypeAttribute>(); | |||
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<byte> 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<JT809BodiesTypeAttribute>(); | |||
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; | |||
} | |||
} | |||
} |
@@ -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<JT809_0x9500> | |||
{ | |||
public JT809_0x9500 Deserialize(ReadOnlySpan<byte> 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<JT809BodiesTypeAttribute>(); | |||
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<byte> 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<JT809BodiesTypeAttribute>(); | |||
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; | |||
} | |||
} | |||
} |
@@ -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<JT809_0x9600> | |||
{ | |||
public JT809_0x9600 Deserialize(ReadOnlySpan<byte> 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<JT809BodiesTypeAttribute>(); | |||
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<byte> 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<JT809BodiesTypeAttribute>(); | |||
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; | |||
} | |||
} | |||
} |
@@ -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 | |||
/// <para>描述:上级平台收到下级平台的主链路连接保持请求消息后,向下级平台返回.主链路连接保持应答消息,保持主链路的连接状态。</para> | |||
/// <para>主链路连接保持应答消息,数据体为空。</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT809_0x1006>))] | |||
public class JT809_0x1006:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
/// <para>业务数据类型标识:UP_EXG_MSG</para> | |||
/// <para>描述:下级平台向上级平台发送车辆动态信息交换业务数据包</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809_0x1200Formatter))] | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT809_0x1200>))] | |||
public class JT809_0x1200:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
/// <para>业务数据类型标识:UP_PLATFORM_MSG</para> | |||
/// <para>描述:下级平台向上级平台发送平台间交互信息</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809_0x1300Formatter))] | |||
public class JT809_0x1300:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
/// <para>业务数据类型标识:UP_WARN_MSG</para> | |||
/// <para>描述:下级平台向上级平台发送车辆报警信息业务</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809_0x1400Formatter))] | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT809_0x1400>))] | |||
public class JT809_0x1400:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
/// <para>业务数据类型标识:UP_CTRL_MSG</para> | |||
/// <para>描述:下级平台向上级平台发送车辆监管业务</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809_0x1500Formatter))] | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT809_0x1500>))] | |||
public class JT809_0x1500:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
/// <para>消息方向:下级平台往上级平台</para> | |||
/// <para>描述:下级平台向上级平台发送车辆睁态信息交换业务</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809_0x1600Formatter))] | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT809_0x1600>))] | |||
public class JT809_0x1600:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
/// <para>业务数据类型标识:DOWN_EXG_MSG</para> | |||
/// <para>描述:上级平台作为客户端向下级平台服务端发送车辆动态信息交换业务</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809_0x9200Formatter))] | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT809_0x9200>))] | |||
public class JT809_0x9200:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
/// <para>业务数据类型标识:DOWN_WARN_MSG</para> | |||
/// <para>描述:上级平台向下级平台发送报瞥信息业务</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809_0x9400Formatter))] | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT809_0x9400>))] | |||
public class JT809_0x9400:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
/// <para>业务数据类型标识:DOWN_CTRL_MSG</para> | |||
/// <para>描述:上级平台向下级平台发送车辆监监管业务</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809_0x9500Formatter))] | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT809_0x9500>))] | |||
public class JT809_0x9500:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |
@@ -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 | |||
/// <para>业务数据类型标识:DOWN_BASE_MSG</para> | |||
/// <para>描述:上级平台向下级平台发送车辆静态信息交换业务</para> | |||
/// </summary> | |||
[JT809Formatter(typeof(JT809_0x9600Formatter))] | |||
[JT809Formatter(typeof(JT809BodiesFormatter<JT809_0x9600>))] | |||
public class JT809_0x9600:JT809Bodies | |||
{ | |||
/// <summary> | |||
/// 车牌号 | |||
/// </summary> | |||
public string VehicleNo { get; set; } | |||
/// <summary> | |||
/// 车辆颜色 | |||
/// </summary> | |||
public JT809VehicleColorType VehicleColor { get; set; } | |||
/// <summary> | |||
/// 子业务类型标识 | |||
/// </summary> | |||
public JT809SubBusinessType SubBusinessType { get; set; } | |||
/// <summary> | |||
/// 后续数据长度 | |||
/// </summary> | |||
public uint DataLength { get; set; } | |||
/// <summary> | |||
/// 子业务数据体 | |||
/// </summary> | |||
public JT809SubBodies JT809SubBodies { get; set; } | |||
} | |||
} |