diff --git a/doc/JTT.808-2019.PDF b/doc/JTT.808-2019.PDF
new file mode 100644
index 0000000..dd195e2
Binary files /dev/null and b/doc/JTT.808-2019.PDF differ
diff --git a/src/JT808.Protocol/JT808.Protocol.csproj b/src/JT808.Protocol/JT808.Protocol.csproj
index f241eb5..74efb5e 100644
--- a/src/JT808.Protocol/JT808.Protocol.csproj
+++ b/src/JT808.Protocol/JT808.Protocol.csproj
@@ -14,7 +14,7 @@
https://github.com/SmallChi/JT808/blob/master/LICENSE
https://github.com/SmallChi/JT808/blob/master/LICENSE
false
- 2.1.8
+ 2.2.0
LICENSE
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0001.cs b/src/JT808.Protocol/MessageBody/JT808_0x0001.cs
index 66c79e2..0b51fdf 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0001.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0001.cs
@@ -1,6 +1,8 @@
using JT808.Protocol.Enums;
using JT808.Protocol.Formatters.MessageBodyFormatters;
using JT808.Protocol.Attributes;
+using JT808.Protocol.MessagePack;
+using JT808.Protocol.Formatters;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 终端通用应答
///
[JT808Formatter(typeof(JT808_0x0001_Formatter))]
- public class JT808_0x0001 : JT808Bodies
+ public class JT808_0x0001 : JT808Bodies,IJT808MessagePackFormatter
{
///
/// 应答流水号
@@ -26,5 +28,21 @@ namespace JT808.Protocol.MessageBody
/// 0:成功/确认;1:失败;2:消息有误;3:不支持
///
public JT808TerminalResult JT808TerminalResult { get; set; }
+
+ public JT808_0x0001 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0001 jT808_0X0001 = new JT808_0x0001();
+ jT808_0X0001.MsgNum = reader.ReadUInt16();
+ jT808_0X0001.MsgId = reader.ReadUInt16();
+ jT808_0X0001.JT808TerminalResult = (JT808TerminalResult)reader.ReadByte();
+ return jT808_0X0001;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0001 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.MsgNum);
+ writer.WriteUInt16(value.MsgId);
+ writer.WriteByte((byte)value.JT808TerminalResult);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0100.cs b/src/JT808.Protocol/MessageBody/JT808_0x0100.cs
index 0d727d3..240876e 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0100.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0100.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +9,7 @@ namespace JT808.Protocol.MessageBody
/// 终端注册
///
[JT808Formatter(typeof(JT808_0x0100_Formatter))]
- public class JT808_0x0100 : JT808Bodies
+ public class JT808_0x0100 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 省域 ID
@@ -58,5 +60,29 @@ namespace JT808.Protocol.MessageBody
/// 否则,表示公安交通管理部门颁发的机动车号牌。
///
public string PlateNo { get; set; }
+
+ public JT808_0x0100 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0100 jT808_0X0100 = new JT808_0x0100();
+ jT808_0X0100.AreaID = reader.ReadUInt16();
+ jT808_0X0100.CityOrCountyId = reader.ReadUInt16();
+ jT808_0X0100.MakerId = reader.ReadString(5);
+ jT808_0X0100.TerminalModel = reader.ReadString(20);
+ jT808_0X0100.TerminalId = reader.ReadString(7);
+ jT808_0X0100.PlateColor = reader.ReadByte();
+ jT808_0X0100.PlateNo = reader.ReadRemainStringContent();
+ return jT808_0X0100;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0100 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.AreaID);
+ writer.WriteUInt16(value.CityOrCountyId);
+ writer.WriteString(value.MakerId.PadRight(5, '0'));
+ writer.WriteString(value.TerminalModel.PadRight(20, '0'));
+ writer.WriteString(value.TerminalId.PadRight(7, '0'));
+ writer.WriteByte(value.PlateColor);
+ writer.WriteString(value.PlateNo);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0102.cs b/src/JT808.Protocol/MessageBody/JT808_0x0102.cs
index 31f7138..634f4b1 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0102.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0102.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Formatters.MessageBodyFormatters;
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,11 +9,23 @@ namespace JT808.Protocol.MessageBody
/// 终端鉴权
///
[JT808Formatter(typeof(JT808_0x0102_Formatter))]
- public class JT808_0x0102 : JT808Bodies
+ public class JT808_0x0102 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 鉴权码
///
public string Code { get; set; }
+
+ public JT808_0x0102 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0102 jT808_0X0102 = new JT808_0x0102();
+ jT808_0X0102.Code = reader.ReadRemainStringContent();
+ return jT808_0X0102;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0102 value, IJT808Config config)
+ {
+ writer.WriteString(value.Code);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0104.cs b/src/JT808.Protocol/MessageBody/JT808_0x0104.cs
index 59ac6b3..144e896 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0104.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0104.cs
@@ -1,5 +1,9 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Extensions;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
+using System;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -8,7 +12,7 @@ namespace JT808.Protocol.MessageBody
/// 查询终端参数应答
///
[JT808Formatter(typeof(JT808_0x0104_Formatter))]
- public class JT808_0x0104 : JT808Bodies
+ public class JT808_0x0104 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 应答流水号
@@ -23,5 +27,41 @@ namespace JT808.Protocol.MessageBody
/// 参数列表
///
public IList ParamList { get; set; }
+
+ public JT808_0x0104 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0104 jT808_0x0104 = new JT808_0x0104();
+ jT808_0x0104.MsgNum = reader.ReadUInt16();
+ jT808_0x0104.AnswerParamsCount = reader.ReadByte();
+ for (int i = 0; i < jT808_0x0104.AnswerParamsCount; i++)
+ {
+ var paramId = reader.ReadVirtualUInt32();//参数ID
+ if (config.JT808_0X8103_Factory.ParamMethods.TryGetValue(paramId, out Type type))
+ {
+ if (jT808_0x0104.ParamList != null)
+ {
+ jT808_0x0104.ParamList.Add(JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(
+ config.GetMessagePackFormatterByType(type), ref reader, config));
+ }
+ else
+ {
+ jT808_0x0104.ParamList = new List { JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(
+ config.GetMessagePackFormatterByType(type), ref reader, config) };
+ }
+ }
+ }
+ return jT808_0x0104;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0104 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.MsgNum);
+ writer.WriteByte(value.AnswerParamsCount);
+ foreach (var item in value.ParamList)
+ {
+ object obj = config.GetMessagePackFormatterByType(item.GetType());
+ JT808MessagePackFormatterResolverExtensions.JT808DynamicSerialize(obj, ref writer, item, config);
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0107.cs b/src/JT808.Protocol/MessageBody/JT808_0x0107.cs
index 4930fac..af0a841 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0107.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0107.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +9,7 @@ namespace JT808.Protocol.MessageBody
/// 查询终端属性应答
///
[JT808Formatter(typeof(JT808_0x0107_Formatter))]
- public class JT808_0x0107 : JT808Bodies
+ public class JT808_0x0107 : JT808Bodies,IJT808MessagePackFormatter
{
///
/// 终端类型
@@ -76,5 +78,37 @@ namespace JT808.Protocol.MessageBody
/// bit7,0:不支持其他通信方式, 1:支持其他通信方式
///
public byte CommunicationModule { get; set; }
+
+ public JT808_0x0107 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0107 jT808_0X0107 = new JT808_0x0107();
+ jT808_0X0107.TerminalType = reader.ReadUInt16();
+ jT808_0X0107.MakerId = reader.ReadString(5);
+ jT808_0X0107.TerminalModel = reader.ReadString(20);
+ jT808_0X0107.TerminalId = reader.ReadString(7);
+ jT808_0X0107.Terminal_SIM_ICCID = reader.ReadBCD(10, config.Trim);
+ jT808_0X0107.Terminal_Hardware_Version_Length = reader.ReadByte();
+ jT808_0X0107.Terminal_Hardware_Version_Num = reader.ReadString(jT808_0X0107.Terminal_Hardware_Version_Length);
+ jT808_0X0107.Terminal_Firmware_Version_Length = reader.ReadByte();
+ jT808_0X0107.Terminal_Firmware_Version_Num = reader.ReadString(jT808_0X0107.Terminal_Firmware_Version_Length);
+ jT808_0X0107.GNSSModule = reader.ReadByte();
+ jT808_0X0107.CommunicationModule = reader.ReadByte();
+ return jT808_0X0107;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0107 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.TerminalType);
+ writer.WriteString(value.MakerId.PadRight(5, '0'));
+ writer.WriteString(value.TerminalModel.PadRight(20, '0'));
+ writer.WriteString(value.TerminalId.PadRight(7, '0'));
+ writer.WriteBCD(value.Terminal_SIM_ICCID, 10);
+ writer.WriteByte((byte)value.Terminal_Hardware_Version_Num.Length);
+ writer.WriteString(value.Terminal_Hardware_Version_Num);
+ writer.WriteByte((byte)value.Terminal_Firmware_Version_Num.Length);
+ writer.WriteString(value.Terminal_Firmware_Version_Num);
+ writer.WriteByte(value.GNSSModule);
+ writer.WriteByte(value.CommunicationModule);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0108.cs b/src/JT808.Protocol/MessageBody/JT808_0x0108.cs
index 8c522b6..ab65f18 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0108.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0108.cs
@@ -1,6 +1,8 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 终端升级结果通知
///
[JT808Formatter(typeof(JT808_0x0108_Formatter))]
- public class JT808_0x0108 : JT808Bodies
+ public class JT808_0x0108 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 升级类型
@@ -21,5 +23,18 @@ namespace JT808.Protocol.MessageBody
/// 0:成功,1:失败,2:取消
///
public JT808UpgradeResult UpgradeResult { get; set; }
+ public JT808_0x0108 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0108 jT808_0X0108 = new JT808_0x0108();
+ jT808_0X0108.UpgradeType = (JT808UpgradeType)reader.ReadByte();
+ jT808_0X0108.UpgradeResult = (JT808UpgradeResult)reader.ReadByte();
+ return jT808_0X0108;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0108 value, IJT808Config config)
+ {
+ writer.WriteByte((byte)value.UpgradeType);
+ writer.WriteByte((byte)value.UpgradeResult);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200.cs
index d7a4886..d2f6bee 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200.cs
@@ -1,5 +1,10 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Enums;
+using JT808.Protocol.Exceptions;
+using JT808.Protocol.Extensions;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System;
using System.Collections.Generic;
@@ -9,7 +14,7 @@ namespace JT808.Protocol.MessageBody
/// 位置信息汇报
///
[JT808Formatter(typeof(JT808_0x0200_Formatter))]
- public class JT808_0x0200 : JT808Bodies
+ public class JT808_0x0200 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 报警标志
@@ -69,5 +74,140 @@ namespace JT808.Protocol.MessageBody
/// 依赖平台录入的设备类型
///
public Dictionary JT808CustomLocationAttachData { get; set; }
+
+ public JT808_0x0200 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200 jT808_0X0200 = new JT808_0x0200();
+ jT808_0X0200.AlarmFlag = reader.ReadUInt32();
+ jT808_0X0200.StatusFlag = reader.ReadUInt32();
+ if (((jT808_0X0200.StatusFlag >> 28) & 1) == 1)
+ { //南纬 268435456 0x10000000
+ jT808_0X0200.Lat = (int)reader.ReadUInt32();
+ }
+ else
+ {
+ jT808_0X0200.Lat = reader.ReadInt32();
+ }
+ if (((jT808_0X0200.StatusFlag >> 27) & 1) == 1)
+ { //西经 134217728 0x8000000
+ jT808_0X0200.Lng = (int)reader.ReadUInt32();
+ }
+ else
+ {
+ jT808_0X0200.Lng = reader.ReadInt32();
+ }
+ jT808_0X0200.Altitude = reader.ReadUInt16();
+ jT808_0X0200.Speed = reader.ReadUInt16();
+ jT808_0X0200.Direction = reader.ReadUInt16();
+ jT808_0X0200.GPSTime = reader.ReadDateTime6();
+ // 位置附加信息
+ jT808_0X0200.JT808LocationAttachData = new Dictionary();
+ jT808_0X0200.JT808CustomLocationAttachOriginalData = new Dictionary();
+ jT808_0X0200.JT808UnknownLocationAttachOriginalData = new Dictionary();
+ while (reader.ReadCurrentRemainContentLength() > 0)
+ {
+ try
+ {
+ ReadOnlySpan attachSpan = reader.GetVirtualReadOnlySpan(2);
+ byte attachId = attachSpan[0];
+ byte attachLen = attachSpan[1];
+ if (config.JT808_0X0200_Factory.JT808LocationAttachMethod.TryGetValue(attachId, out Type jT808LocationAttachType))
+ {
+ object attachImplObj = config.GetMessagePackFormatterByType(jT808LocationAttachType);
+ dynamic attachImpl = JT808MessagePackFormatterResolverExtensions.JT808DynamicDeserialize(attachImplObj, ref reader, config);
+ jT808_0X0200.JT808LocationAttachData.Add(attachImpl.AttachInfoId, attachImpl);
+ }
+ else if (config.JT808_0X0200_Custom_Factory.AttachIds.Contains(attachId))
+ {
+ reader.Skip(2);
+ jT808_0X0200.JT808CustomLocationAttachOriginalData.Add(attachId, reader.ReadArray(reader.ReaderCount - 2, attachLen + 2).ToArray());
+ reader.Skip(attachLen);
+ }
+ else
+ {
+ reader.Skip(2);
+ jT808_0X0200.JT808UnknownLocationAttachOriginalData.Add(attachId, reader.ReadArray(reader.ReaderCount - 2, attachLen + 2).ToArray());
+ reader.Skip(attachLen);
+ }
+ }
+ catch
+ {
+ try
+ {
+ byte attachId = reader.ReadByte();
+ byte attachLen = reader.ReadByte();
+ jT808_0X0200.JT808UnknownLocationAttachOriginalData.Add(attachId, reader.ReadArray(reader.ReaderCount - 2, attachLen + 2).ToArray());
+ reader.Skip(attachLen);
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+ }
+ }
+ return jT808_0X0200;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.AlarmFlag);
+ writer.WriteUInt32(value.StatusFlag);
+ //0x10000000 南纬 134217728
+ //0x8000000 西经 268435456
+ //0x18000000 南纬-西经 134217728+268435456
+ if (((value.StatusFlag >> 28) & 1) == 1)
+ {
+ uint lat = (uint)value.Lat;
+ writer.WriteUInt32(lat);
+ }
+ else
+ {
+ if (value.Lat < 0)
+ {
+ throw new JT808Exception(JT808ErrorCode.LatOrLngError, $"Lat {nameof(JT808_0x0200.StatusFlag)} ({value.StatusFlag}>>28) !=1");
+ }
+ writer.WriteInt32(value.Lat);
+ }
+ if (((value.StatusFlag >> 27) & 1) == 1)
+ {
+ uint lng = (uint)value.Lng;
+ writer.WriteUInt32(lng);
+ }
+ else
+ {
+ if (value.Lng < 0)
+ {
+ throw new JT808Exception(JT808ErrorCode.LatOrLngError, $"Lng {nameof(JT808_0x0200.StatusFlag)} ({value.StatusFlag}>>29) !=1");
+ }
+ writer.WriteInt32(value.Lng);
+ }
+ writer.WriteUInt16(value.Altitude);
+ writer.WriteUInt16(value.Speed);
+ writer.WriteUInt16(value.Direction);
+ writer.WriteDateTime6(value.GPSTime);
+ if (value.JT808LocationAttachData != null && value.JT808LocationAttachData.Count > 0)
+ {
+ foreach (var item in value.JT808LocationAttachData)
+ {
+ try
+ {
+ object attachImplObj = config.GetMessagePackFormatterByType(item.Value.GetType());
+ JT808MessagePackFormatterResolverExtensions.JT808DynamicSerialize(attachImplObj, ref writer, item.Value, config);
+ }
+ catch
+ {
+
+ }
+ }
+ }
+ if (value.JT808CustomLocationAttachData != null && value.JT808CustomLocationAttachData.Count > 0)
+ {
+ foreach (var item in value.JT808CustomLocationAttachData)
+ {
+ object attachImplObj = config.GetMessagePackFormatterByType(item.Value.GetType());
+ JT808MessagePackFormatterResolverExtensions.JT808DynamicSerialize(attachImplObj, ref writer, item.Value, config);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs
index 9472e6e..54520a7 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs
@@ -1,12 +1,14 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System.Runtime.Serialization;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x01_Formatter))]
- public class JT808_0x0200_0x01 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x01 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
public override byte AttachInfoId { get; set; } = 0x01;
public override byte AttachInfoLength { get; set; } = 4;
@@ -19,5 +21,20 @@ namespace JT808.Protocol.MessageBody
///
[IgnoreDataMember]
public double ConvertMileage => Mileage / 10.0;
+ public JT808_0x0200_0x01 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x01 jT808LocationAttachImpl0X01 = new JT808_0x0200_0x01();
+ jT808LocationAttachImpl0X01.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0X01.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0X01.Mileage = reader.ReadInt32();
+ return jT808LocationAttachImpl0X01;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x01 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteInt32(value.Mileage);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs
index 029e101..2459264 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs
@@ -1,11 +1,13 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System.Runtime.Serialization;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x02_Formatter))]
- public class JT808_0x0200_0x02 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x02 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// 油量
@@ -18,5 +20,21 @@ namespace JT808.Protocol.MessageBody
public double ConvertOil => Oil / 10.0;
public override byte AttachInfoId { get; set; } = 0x02;
public override byte AttachInfoLength { get; set; } = 2;
+
+ public JT808_0x0200_0x02 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x02 jT808LocationAttachImpl0X02 = new JT808_0x0200_0x02();
+ jT808LocationAttachImpl0X02.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0X02.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0X02.Oil = reader.ReadUInt16();
+ return jT808LocationAttachImpl0X02;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x02 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteUInt16(value.Oil);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs
index 6728959..44bcffc 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs
@@ -1,12 +1,14 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System.Runtime.Serialization;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x03_Formatter))]
- public class JT808_0x0200_0x03 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x03 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// 行驶记录功能获取的速度
@@ -19,5 +21,20 @@ namespace JT808.Protocol.MessageBody
public double ConvertSpeed => Speed / 10.0;
public override byte AttachInfoId { get; set; } = 0x03;
public override byte AttachInfoLength { get; set; } = 2;
+ public JT808_0x0200_0x03 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x03 jT808LocationAttachImpl0x03 = new JT808_0x0200_0x03();
+ jT808LocationAttachImpl0x03.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0x03.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0x03.Speed = reader.ReadUInt16();
+ return jT808LocationAttachImpl0x03;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x03 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteUInt16(value.Speed);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs
index fd1a908..03f5257 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs
@@ -1,10 +1,12 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x04_Formatter))]
- public class JT808_0x0200_0x04 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x04 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// 需要人工确认报警事件的 ID,从 1 开始计数
@@ -12,5 +14,21 @@ namespace JT808.Protocol.MessageBody
public ushort EventId { get; set; }
public override byte AttachInfoId { get; set; } = 0x04;
public override byte AttachInfoLength { get; set; } = 2;
+
+ public JT808_0x0200_0x04 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x04 jT808LocationAttachImpl0x04 = new JT808_0x0200_0x04();
+ jT808LocationAttachImpl0x04.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0x04.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0x04.EventId = reader.ReadUInt16();
+ return jT808LocationAttachImpl0x04;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x04 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteUInt16(value.EventId);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs
index 09a47c1..06a027d 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs
@@ -1,11 +1,13 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x11_Formatter))]
- public class JT808_0x0200_0x11 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x11 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// 超速报警附加信息
@@ -38,5 +40,29 @@ namespace JT808.Protocol.MessageBody
}
set { }
}
+
+ public JT808_0x0200_0x11 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x11 jT808LocationAttachImpl0x11 = new JT808_0x0200_0x11();
+ jT808LocationAttachImpl0x11.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0x11.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0x11.JT808PositionType = (JT808PositionType)reader.ReadByte();
+ if (jT808LocationAttachImpl0x11.JT808PositionType != JT808PositionType.无特定位置)
+ {
+ jT808LocationAttachImpl0x11.AreaId = reader.ReadInt32();
+ }
+ return jT808LocationAttachImpl0x11;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x11 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteByte((byte)value.JT808PositionType);
+ if (value.JT808PositionType != JT808PositionType.无特定位置)
+ {
+ writer.WriteInt32(value.AreaId);
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x12.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x12.cs
index 1112948..5bec96b 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x12.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x12.cs
@@ -1,11 +1,13 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x12_Formatter))]
- public class JT808_0x0200_0x12 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x12 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// 位置类型
@@ -29,5 +31,25 @@ namespace JT808.Protocol.MessageBody
public JT808DirectionType Direction { get; set; }
public override byte AttachInfoId { get; set; } = 0x12;
public override byte AttachInfoLength { get; set; } = 6;
+
+ public JT808_0x0200_0x12 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x12 jT808LocationAttachImpl0x12 = new JT808_0x0200_0x12();
+ jT808LocationAttachImpl0x12.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0x12.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0x12.JT808PositionType = (JT808PositionType)reader.ReadByte();
+ jT808LocationAttachImpl0x12.AreaId = reader.ReadInt32();
+ jT808LocationAttachImpl0x12.Direction = (JT808DirectionType)reader.ReadByte();
+ return jT808LocationAttachImpl0x12;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x12 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteByte((byte)value.JT808PositionType);
+ writer.WriteInt32(value.AreaId);
+ writer.WriteByte((byte)value.Direction);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x13.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x13.cs
index c05cff6..1eb95a7 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x13.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x13.cs
@@ -1,13 +1,14 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
-
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x13_Formatter))]
- public class JT808_0x0200_0x13 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x13 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
public override byte AttachInfoId { get; set; } = 0x13;
public override byte AttachInfoLength { get; set; } = 7;
@@ -27,5 +28,25 @@ namespace JT808.Protocol.MessageBody
/// 结果 0:不足;1:过长
///
public JT808DrivenRouteType DrivenRoute { get; set; }
+
+ public JT808_0x0200_0x13 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x13 jT808LocationAttachImpl0x13 = new JT808_0x0200_0x13();
+ jT808LocationAttachImpl0x13.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0x13.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0x13.DrivenRouteId = reader.ReadInt32();
+ jT808LocationAttachImpl0x13.Time = reader.ReadUInt16();
+ jT808LocationAttachImpl0x13.DrivenRoute = (JT808DrivenRouteType)reader.ReadByte();
+ return jT808LocationAttachImpl0x13;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x13 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteInt32(value.DrivenRouteId);
+ writer.WriteUInt16(value.Time);
+ writer.WriteByte((byte)value.DrivenRoute);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x25.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x25.cs
index a311942..3ad4fa4 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x25.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x25.cs
@@ -1,11 +1,12 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
-
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x25_Formatter))]
- public class JT808_0x0200_0x25 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x25 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// 扩展车辆信号状态位
@@ -13,5 +14,20 @@ namespace JT808.Protocol.MessageBody
public int CarSignalStatus { get; set; }
public override byte AttachInfoId { get; set; } = 0x25;
public override byte AttachInfoLength { get; set; } = 4;
+ public JT808_0x0200_0x25 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x25 jT808LocationAttachImpl0x13 = new JT808_0x0200_0x25();
+ jT808LocationAttachImpl0x13.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0x13.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0x13.CarSignalStatus = reader.ReadInt32();
+ return jT808LocationAttachImpl0x13;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x25 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteInt32(value.CarSignalStatus);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2A.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2A.cs
index 1928517..d49847f 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2A.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2A.cs
@@ -1,11 +1,12 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
-
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x2A_Formatter))]
- public class JT808_0x0200_0x2A : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x2A : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// IO状态位
@@ -13,5 +14,21 @@ namespace JT808.Protocol.MessageBody
public ushort IOStatus { get; set; }
public override byte AttachInfoId { get; set; } = 0x2A;
public override byte AttachInfoLength { get; set; } = 2;
+
+ public JT808_0x0200_0x2A Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x2A jT808LocationAttachImpl0X2A = new JT808_0x0200_0x2A();
+ jT808LocationAttachImpl0X2A.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0X2A.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0X2A.IOStatus = reader.ReadUInt16();
+ return jT808LocationAttachImpl0X2A;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x2A value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteUInt16(value.IOStatus);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2B.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2B.cs
index 67d70be..1ad662c 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2B.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x2B.cs
@@ -1,11 +1,12 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
-
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x2B_Formatter))]
- public class JT808_0x0200_0x2B : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x2B : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// 模拟量 bit0-15,AD0;bit16-31,AD1
@@ -13,5 +14,20 @@ namespace JT808.Protocol.MessageBody
public int Analog { get; set; }
public override byte AttachInfoId { get; set; } = 0x2B;
public override byte AttachInfoLength { get; set; } = 4;
+ public JT808_0x0200_0x2B Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x2B jT808LocationAttachImpl0x2B = new JT808_0x0200_0x2B();
+ jT808LocationAttachImpl0x2B.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0x2B.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0x2B.Analog = reader.ReadInt32();
+ return jT808LocationAttachImpl0x2B;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x2B value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteInt32(value.Analog);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x30.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x30.cs
index efb7b05..b3c14cf 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x30.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x30.cs
@@ -1,11 +1,12 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
-
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x30_Formatter))]
- public class JT808_0x0200_0x30 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x30 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// 无线通信网络信号强度
@@ -13,5 +14,20 @@ namespace JT808.Protocol.MessageBody
public byte WiFiSignalStrength { get; set; }
public override byte AttachInfoId { get; set; } = 0x30;
public override byte AttachInfoLength { get; set; } = 1;
+ public JT808_0x0200_0x30 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x30 jT808LocationAttachImpl0x30 = new JT808_0x0200_0x30();
+ jT808LocationAttachImpl0x30.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0x30.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0x30.WiFiSignalStrength = reader.ReadByte();
+ return jT808LocationAttachImpl0x30;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x30 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteByte(value.WiFiSignalStrength);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x31.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x31.cs
index 83cd000..740ebc0 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x31.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x31.cs
@@ -1,10 +1,12 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
[JT808Formatter(typeof(JT808_0x0200_0x31_Formatter))]
- public class JT808_0x0200_0x31 : JT808_0x0200_BodyBase
+ public class JT808_0x0200_0x31 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter
{
///
/// GNSS 定位卫星数
@@ -12,5 +14,19 @@ namespace JT808.Protocol.MessageBody
public byte GNSSCount { get; set; }
public override byte AttachInfoId { get; set; } = 0x31;
public override byte AttachInfoLength { get; set; } = 1;
+ public JT808_0x0200_0x31 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0200_0x31 jT808LocationAttachImpl0x31 = new JT808_0x0200_0x31();
+ jT808LocationAttachImpl0x31.AttachInfoId = reader.ReadByte();
+ jT808LocationAttachImpl0x31.AttachInfoLength = reader.ReadByte();
+ jT808LocationAttachImpl0x31.GNSSCount = reader.ReadByte();
+ return jT808LocationAttachImpl0x31;
+ }
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x31 value, IJT808Config config)
+ {
+ writer.WriteByte(value.AttachInfoId);
+ writer.WriteByte(value.AttachInfoLength);
+ writer.WriteByte(value.GNSSCount);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0201.cs b/src/JT808.Protocol/MessageBody/JT808_0x0201.cs
index b0645b1..2d219a7 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0201.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0201.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +9,7 @@ namespace JT808.Protocol.MessageBody
/// 位置信息查询应答
///
[JT808Formatter(typeof(JT808_0x0201_Formatter))]
- public class JT808_0x0201 : JT808Bodies
+ public class JT808_0x0201 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 应答流水号
@@ -19,5 +21,18 @@ namespace JT808.Protocol.MessageBody
/// 位置信息汇报见 8.12
///
public JT808_0x0200 Position { get; set; }
+ public JT808_0x0201 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0201 jT808_0X0201 = new JT808_0x0201();
+ jT808_0X0201.MsgNum = reader.ReadUInt16();
+ jT808_0X0201.Position = config.GetMessagePackFormatter().Deserialize(ref reader, config);
+ return jT808_0X0201;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0201 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.MsgNum);
+ config.GetMessagePackFormatter().Serialize(ref writer, value.Position, config);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0301.cs b/src/JT808.Protocol/MessageBody/JT808_0x0301.cs
index ac52cea..d573d02 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0301.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0301.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,11 +10,21 @@ namespace JT808.Protocol.MessageBody
/// 0x0301
///
[JT808Formatter(typeof(JT808_0x0301_Formatter))]
- public class JT808_0x0301 : JT808Bodies
+ public class JT808_0x0301 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 事件 ID
///
public byte EventId { get; set; }
+ public JT808_0x0301 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0301 jT808_0X0301 = new JT808_0x0301();
+ jT808_0X0301.EventId = reader.ReadByte();
+ return jT808_0X0301;
+ }
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0301 value, IJT808Config config)
+ {
+ writer.WriteByte(value.EventId);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0302.cs b/src/JT808.Protocol/MessageBody/JT808_0x0302.cs
index bc2ce56..4042c8e 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0302.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0302.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0302
///
[JT808Formatter(typeof(JT808_0x0302_Formatter))]
- public class JT808_0x0302 : JT808Bodies
+ public class JT808_0x0302 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 应答流水号
@@ -20,5 +22,17 @@ namespace JT808.Protocol.MessageBody
/// 提问下发中附带的答案 ID
///
public byte AnswerId { get; set; }
+ public JT808_0x0302 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0302 jT808_0X0302 = new JT808_0x0302();
+ jT808_0X0302.ReplySNo = reader.ReadUInt16();
+ jT808_0X0302.AnswerId = reader.ReadByte();
+ return jT808_0X0302;
+ }
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0302 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.ReplySNo);
+ writer.WriteByte(value.AnswerId);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0303.cs b/src/JT808.Protocol/MessageBody/JT808_0x0303.cs
index f098c59..3d577fc 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0303.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0303.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0303
///
[JT808Formatter(typeof(JT808_0x0303_Formatter))]
- public class JT808_0x0303 : JT808Bodies
+ public class JT808_0x0303 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 信息类型
@@ -18,5 +20,18 @@ namespace JT808.Protocol.MessageBody
/// 点播/取消标志
///
public byte Flag { get; set; }
+ public JT808_0x0303 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0303 jT808_0X0303 = new JT808_0x0303();
+ jT808_0X0303.InformationType = reader.ReadByte();
+ jT808_0X0303.Flag = reader.ReadByte();
+ return jT808_0X0303;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0303 value, IJT808Config config)
+ {
+ writer.WriteByte(value.InformationType);
+ writer.WriteByte(value.Flag);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0500.cs b/src/JT808.Protocol/MessageBody/JT808_0x0500.cs
index 270320e..214a026 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0500.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0500.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +9,7 @@ namespace JT808.Protocol.MessageBody
/// 车辆控制应答
///
[JT808Formatter(typeof(JT808_0x0500_Formatter))]
- public class JT808_0x0500 : JT808Bodies
+ public class JT808_0x0500 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 应答流水号
@@ -18,5 +20,18 @@ namespace JT808.Protocol.MessageBody
/// 位置信息汇报消息体
///
public JT808_0x0200 JT808_0x0200 { get; set; }
+ public JT808_0x0500 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0500 jT808_0X0500 = new JT808_0x0500();
+ jT808_0X0500.MsgNum = reader.ReadUInt16();
+ jT808_0X0500.JT808_0x0200 = config.GetMessagePackFormatter().Deserialize(ref reader, config);
+ return jT808_0X0500;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0500 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.MsgNum);
+ config.GetMessagePackFormatter().Serialize(ref writer, value.JT808_0x0200, config);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0701.cs b/src/JT808.Protocol/MessageBody/JT808_0x0701.cs
index 73284ee..f8f2cd6 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0701.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0701.cs
@@ -1,5 +1,8 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Extensions;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System;
namespace JT808.Protocol.MessageBody
@@ -9,7 +12,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0701
///
[JT808Formatter(typeof(JT808_0x0701_Formatter))]
- public class JT808_0x0701 : JT808Bodies
+ public class JT808_0x0701 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 电子运单长度
@@ -23,5 +26,21 @@ namespace JT808.Protocol.MessageBody
/// 注意:需要具体的实现
///
public JT808_0x0701_CustomBodyBase ElectronicContentObj { get; set; }
+ public JT808_0x0701 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0701 jT808_0X0701 = new JT808_0x0701();
+ jT808_0X0701.ElectronicWaybillLength = reader.ReadUInt32();
+ jT808_0X0701.ElectronicContent = reader.ReadArray((int)jT808_0X0701.ElectronicWaybillLength).ToArray();
+ return jT808_0X0701;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0701 value, IJT808Config config)
+ {
+ writer.Skip(4, out int skipPosition);
+ object obj = config.GetMessagePackFormatterByType(value.ElectronicContentObj.GetType());
+ JT808MessagePackFormatterResolverExtensions.JT808DynamicSerialize(obj, ref writer, value.ElectronicContentObj, config);
+ int contentLength = writer.GetCurrentPosition() - skipPosition - 4;
+ writer.WriteInt32Return(contentLength, skipPosition);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0702.cs b/src/JT808.Protocol/MessageBody/JT808_0x0702.cs
index fc8ca2c..7bbc36f 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0702.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0702.cs
@@ -1,6 +1,8 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System;
namespace JT808.Protocol.MessageBody
@@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 驾驶员身份信息采集上报
///
[JT808Formatter(typeof(JT808_0x0702_Formatter))]
- public class JT808_0x0702 : JT808Bodies
+ public class JT808_0x0702 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 状态
@@ -58,5 +60,44 @@ namespace JT808.Protocol.MessageBody
/// 证件有效期 BCD[4]
///
public DateTime CertificateExpiresDate { get; set; }
+ public JT808_0x0702 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0702 jT808_0X0702 = new JT808_0x0702();
+ jT808_0X0702.IC_Card_Status = (JT808ICCardStatus)reader.ReadByte();
+ jT808_0X0702.IC_Card_PlugDateTime = reader.ReadDateTime6();
+ if (jT808_0X0702.IC_Card_Status == JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班)
+ {
+ jT808_0X0702.IC_Card_ReadResult = (JT808ICCardReadResult)reader.ReadByte();
+ if (jT808_0X0702.IC_Card_ReadResult == JT808ICCardReadResult.IC卡读卡成功)
+ {
+ jT808_0X0702.DriverUserNameLength = reader.ReadByte();
+ jT808_0X0702.DriverUserName = reader.ReadString(jT808_0X0702.DriverUserNameLength);
+ jT808_0X0702.QualificationCode = reader.ReadString(20);
+ jT808_0X0702.LicenseIssuingLength = reader.ReadByte();
+ jT808_0X0702.LicenseIssuing = reader.ReadString(jT808_0X0702.LicenseIssuingLength);
+ jT808_0X0702.CertificateExpiresDate = reader.ReadDateTime4();
+ }
+ }
+ return jT808_0X0702;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0702 value, IJT808Config config)
+ {
+ writer.WriteByte((byte)value.IC_Card_Status);
+ writer.WriteDateTime6(value.IC_Card_PlugDateTime);
+ if (value.IC_Card_Status == JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班)
+ {
+ writer.WriteByte((byte)value.IC_Card_ReadResult);
+ if (value.IC_Card_ReadResult == JT808ICCardReadResult.IC卡读卡成功)
+ {
+ writer.WriteByte((byte)value.DriverUserName.Length);
+ writer.WriteString(value.DriverUserName);
+ writer.WriteString(value.QualificationCode.PadRight(20, '0'));
+ writer.WriteByte((byte)value.LicenseIssuing.Length);
+ writer.WriteString(value.LicenseIssuing);
+ writer.WriteDateTime4(value.CertificateExpiresDate);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0704.cs b/src/JT808.Protocol/MessageBody/JT808_0x0704.cs
index 389b3d8..dc01679 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0704.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0704.cs
@@ -1,5 +1,8 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
+using System;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 定位数据批量上传
///
[JT808Formatter(typeof(JT808_0x0704_Formatter))]
- public class JT808_0x0704 : JT808Bodies
+ public class JT808_0x0704 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 数据项个数
@@ -33,5 +36,49 @@ namespace JT808.Protocol.MessageBody
正常位置批量汇报 = 0x00,
盲区补报 = 0x01
}
+
+ public JT808_0x0704 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0704 jT808_0X0704 = new JT808_0x0704();
+ jT808_0X0704.Count = reader.ReadUInt16();
+ jT808_0X0704.LocationType = (JT808_0x0704.BatchLocationType)reader.ReadByte();
+ List jT808_0X0200s = new List();
+ for (int i = 0; i < jT808_0X0704.Count; i++)
+ {
+ int buflen = reader.ReadUInt16();
+ try
+ {
+ JT808MessagePackReader tmpReader = new JT808MessagePackReader(reader.ReadArray(buflen));
+ JT808_0x0200 jT808_0X0200 = config.GetMessagePackFormatter().Deserialize(ref tmpReader, config);
+ jT808_0X0200s.Add(jT808_0X0200);
+ }
+ catch (Exception)
+ {
+
+ }
+ }
+ jT808_0X0704.Positions = jT808_0X0200s;
+ return jT808_0X0704;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0704 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.Count);
+ writer.WriteByte((byte)value.LocationType);
+ foreach (var item in value?.Positions)
+ {
+ try
+ {
+ writer.Skip(2, out int position);
+ config.GetMessagePackFormatter().Serialize(ref writer, item, config);
+ ushort length = (ushort)(writer.GetCurrentPosition() - position - 2);
+ writer.WriteUInt16Return(length, position);
+ }
+ catch (Exception)
+ {
+
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0705.cs b/src/JT808.Protocol/MessageBody/JT808_0x0705.cs
index 2deed02..03009c4 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0705.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0705.cs
@@ -1,5 +1,8 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Exceptions;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using JT808.Protocol.Metadata;
using System;
using System.Collections.Generic;
@@ -11,7 +14,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0705
///
[JT808Formatter(typeof(JT808_0x0705_Formatter))]
- public class JT808_0x0705 : JT808Bodies
+ public class JT808_0x0705 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 数据项个数
@@ -27,5 +30,51 @@ namespace JT808.Protocol.MessageBody
/// CAN 总线数据项
///
public List CanItems { get; set; }
+
+ public JT808_0x0705 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0705 jT808_0X0705 = new JT808_0x0705();
+ jT808_0X0705.CanItemCount = reader.ReadUInt16();
+ jT808_0X0705.FirstCanReceiveTime = reader.ReadDateTime5();
+ jT808_0X0705.CanItems = new List();
+ for (var i = 0; i < jT808_0X0705.CanItemCount; i++)
+ {
+ JT808CanProperty jT808CanProperty = new JT808CanProperty();
+ jT808CanProperty.CanId = reader.ReadArray(4).ToArray();
+ if (jT808CanProperty.CanId.Length != 4)
+ {
+ throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808CanProperty.CanId)}->4");
+ }
+ jT808CanProperty.CanData = reader.ReadArray(8).ToArray();
+ if (jT808CanProperty.CanData.Length != 8)
+ {
+ throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808CanProperty.CanData)}->8");
+ }
+ jT808_0X0705.CanItems.Add(jT808CanProperty);
+ }
+ return jT808_0X0705;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0705 value, IJT808Config config)
+ {
+ if (value.CanItems != null && value.CanItems.Count > 0)
+ {
+ writer.WriteUInt16((ushort)value.CanItems.Count);
+ writer.WriteDateTime5(value.FirstCanReceiveTime);
+ foreach (var item in value.CanItems)
+ {
+ if (item.CanId.Length != 4)
+ {
+ throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(item.CanId)}->4");
+ }
+ writer.WriteArray(item.CanId);
+ if (item.CanData.Length != 8)
+ {
+ throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(item.CanData)}->8");
+ }
+ writer.WriteArray(item.CanData);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0800.cs b/src/JT808.Protocol/MessageBody/JT808_0x0800.cs
index 4473784..3b9b62b 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0800.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0800.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0800
///
[JT808Formatter(typeof(JT808_0x0800_Formatter))]
- public class JT808_0x0800 : JT808Bodies
+ public class JT808_0x0800 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 多媒体数据 ID
@@ -43,5 +45,24 @@ namespace JT808.Protocol.MessageBody
/// 通道 ID
///
public byte ChannelId { get; set; }
+ public JT808_0x0800 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0800 jT808_0X0800 = new JT808_0x0800();
+ jT808_0X0800.MultimediaId = reader.ReadUInt32();
+ jT808_0X0800.MultimediaType = reader.ReadByte();
+ jT808_0X0800.MultimediaCodingFormat = reader.ReadByte();
+ jT808_0X0800.EventItemCoding = reader.ReadByte();
+ jT808_0X0800.ChannelId = reader.ReadByte();
+ return jT808_0X0800;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0800 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.MultimediaId);
+ writer.WriteByte(value.MultimediaType);
+ writer.WriteByte(value.MultimediaCodingFormat);
+ writer.WriteByte(value.EventItemCoding);
+ writer.WriteByte(value.ChannelId);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0801.cs b/src/JT808.Protocol/MessageBody/JT808_0x0801.cs
index a27b30c..6263c08 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0801.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0801.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0801
///
[JT808Formatter(typeof(JT808_0x0801_Formatter))]
- public class JT808_0x0801 : JT808Bodies
+ public class JT808_0x0801 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 多媒体 ID
@@ -43,5 +45,30 @@ namespace JT808.Protocol.MessageBody
/// 多媒体数据包
///
public byte[] MultimediaDataPackage { get; set; }
+
+ public JT808_0x0801 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0801 jT808_0X0801 = new JT808_0x0801();
+ jT808_0X0801.MultimediaId = reader.ReadUInt32();
+ jT808_0X0801.MultimediaType = reader.ReadByte();
+ jT808_0X0801.MultimediaCodingFormat = reader.ReadByte();
+ jT808_0X0801.EventItemCoding = reader.ReadByte();
+ jT808_0X0801.ChannelId = reader.ReadByte();
+ JT808MessagePackReader positionReader = new JT808MessagePackReader(reader.ReadArray(28));
+ jT808_0X0801.Position = config.GetMessagePackFormatter().Deserialize(ref positionReader, config);
+ jT808_0X0801.MultimediaDataPackage = reader.ReadContent().ToArray();
+ return jT808_0X0801;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0801 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.MultimediaId);
+ writer.WriteByte(value.MultimediaType);
+ writer.WriteByte(value.MultimediaCodingFormat);
+ writer.WriteByte(value.EventItemCoding);
+ writer.WriteByte(value.ChannelId);
+ config.GetMessagePackFormatter().Serialize(ref writer, value.Position, config);
+ writer.WriteArray(value.MultimediaDataPackage);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0802.cs b/src/JT808.Protocol/MessageBody/JT808_0x0802.cs
index acd4491..be2d3b3 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0802.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0802.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using JT808.Protocol.Metadata;
using System.Collections.Generic;
@@ -10,7 +12,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0802
///
[JT808Formatter(typeof(JT808_0x0802_Formatter))]
- public class JT808_0x0802 : JT808Bodies
+ public class JT808_0x0802 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 应答流水号
@@ -26,5 +28,39 @@ namespace JT808.Protocol.MessageBody
/// 检索项集合
///
public List MultimediaSearchItems { get; set; }
+
+ public JT808_0x0802 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0802 JT808_0x0802 = new JT808_0x0802();
+ JT808_0x0802.MsgNum = reader.ReadUInt16();
+ JT808_0x0802.MultimediaItemCount = reader.ReadUInt16();
+ JT808_0x0802.MultimediaSearchItems = new List();
+ for (var i = 0; i < JT808_0x0802.MultimediaItemCount; i++)
+ {
+ JT808MultimediaSearchProperty jT808MultimediaSearchProperty = new JT808MultimediaSearchProperty();
+ jT808MultimediaSearchProperty.MultimediaId = reader.ReadUInt32();
+ jT808MultimediaSearchProperty.MultimediaType = reader.ReadByte();
+ jT808MultimediaSearchProperty.ChannelId = reader.ReadByte();
+ jT808MultimediaSearchProperty.EventItemCoding = reader.ReadByte();
+ JT808MessagePackReader positionReader = new JT808MessagePackReader(reader.ReadArray(28));
+ jT808MultimediaSearchProperty.Position = config.GetMessagePackFormatter().Deserialize(ref positionReader, config);
+ JT808_0x0802.MultimediaSearchItems.Add(jT808MultimediaSearchProperty);
+ }
+ return JT808_0x0802;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0802 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.MsgNum);
+ writer.WriteUInt16((ushort)value.MultimediaSearchItems.Count);
+ foreach (var item in value.MultimediaSearchItems)
+ {
+ writer.WriteUInt32(item.MultimediaId);
+ writer.WriteByte(item.MultimediaType);
+ writer.WriteByte(item.ChannelId);
+ writer.WriteByte(item.EventItemCoding);
+ config.GetMessagePackFormatter().Serialize(ref writer, item.Position, config);
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0805.cs b/src/JT808.Protocol/MessageBody/JT808_0x0805.cs
index afb60a8..b69f25f 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0805.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0805.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0805
///
[JT808Formatter(typeof(JT808_0x0805_Formatter))]
- public class JT808_0x0805 : JT808Bodies
+ public class JT808_0x0805 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 应答流水号
@@ -30,5 +32,31 @@ namespace JT808.Protocol.MessageBody
/// 多媒体ID列表
///
public List MultimediaIds { get; set; }
+
+ public JT808_0x0805 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0805 jT808_0X0805 = new JT808_0x0805();
+ jT808_0X0805.MsgNum = reader.ReadUInt16();
+ jT808_0X0805.Result = reader.ReadByte();
+ jT808_0X0805.MultimediaIdCount = reader.ReadUInt16();
+ jT808_0X0805.MultimediaIds = new List();
+ for (var i = 0; i < jT808_0X0805.MultimediaIdCount; i++)
+ {
+ uint id = reader.ReadUInt32();
+ jT808_0X0805.MultimediaIds.Add(id);
+ }
+ return jT808_0X0805;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0805 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.MsgNum);
+ writer.WriteByte(value.Result);
+ writer.WriteUInt16((ushort)value.MultimediaIds.Count);
+ foreach (var item in value.MultimediaIds)
+ {
+ writer.WriteUInt32(item);
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0900.cs b/src/JT808.Protocol/MessageBody/JT808_0x0900.cs
index 27c3042..409bdb7 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0900.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0900.cs
@@ -1,5 +1,8 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Extensions;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 数据上行透传
///
[JT808Formatter(typeof(JT808_0x0900_Formatter))]
- public class JT808_0x0900 : JT808Bodies
+ public class JT808_0x0900 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 透传消息类型
@@ -23,5 +26,20 @@ namespace JT808.Protocol.MessageBody
/// 透传消息内容
///
public JT808_0x0900_BodyBase JT808_0x0900_BodyBase { get; set; }
+
+ public JT808_0x0900 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0900 jT808_0X0900 = new JT808_0x0900();
+ jT808_0X0900.PassthroughType = reader.ReadByte();
+ jT808_0X0900.PassthroughData = reader.ReadContent().ToArray(); ;
+ return jT808_0X0900;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0900 value, IJT808Config config)
+ {
+ writer.WriteByte(value.PassthroughType);
+ object obj = config.GetMessagePackFormatterByType(value.JT808_0x0900_BodyBase.GetType());
+ JT808MessagePackFormatterResolverExtensions.JT808DynamicSerialize(obj, ref writer, value.JT808_0x0900_BodyBase, config);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0901.cs b/src/JT808.Protocol/MessageBody/JT808_0x0901.cs
index 26c2e16..f8a0717 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0901.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0901.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0901
///
[JT808Formatter(typeof(JT808_0x0901_Formatter))]
- public class JT808_0x0901 : JT808Bodies
+ public class JT808_0x0901 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 未压缩消息长度
@@ -20,5 +22,21 @@ namespace JT808.Protocol.MessageBody
/// 可实现 自定义压缩算法
///
public byte[] UnCompressMessage { get; set; }
+ public JT808_0x0901 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0901 jT808_0X0901 = new JT808_0x0901();
+ var compressMessageLength = reader.ReadUInt32();
+ var data = reader.ReadArray((int)compressMessageLength);
+ jT808_0X0901.UnCompressMessage = config.Compress.Decompress(data.ToArray());
+ jT808_0X0901.UnCompressMessageLength = (uint)jT808_0X0901.UnCompressMessage.Length;
+ return jT808_0X0901;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0901 value, IJT808Config config)
+ {
+ var data = config.Compress.Compress(value.UnCompressMessage);
+ writer.WriteUInt32((uint)data.Length);
+ writer.WriteArray(data);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0A00.cs b/src/JT808.Protocol/MessageBody/JT808_0x0A00.cs
index eb3c985..8d6aead 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x0A00.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x0A00.cs
@@ -1,5 +1,8 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Exceptions;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x0A00
///
[JT808Formatter(typeof(JT808_0x0A00_Formatter))]
- public class JT808_0x0A00 : JT808Bodies
+ public class JT808_0x0A00 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// e
@@ -20,5 +23,28 @@ namespace JT808.Protocol.MessageBody
/// RSA 公钥{e,n}中的 n
///
public byte[] N { get; set; }
+ public JT808_0x0A00 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x0A00 jT808_0X0A00 = new JT808_0x0A00
+ {
+ E = reader.ReadUInt32(),
+ N = reader.ReadArray(128).ToArray()
+ };
+ if (jT808_0X0A00.N.Length != 128)
+ {
+ throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(jT808_0X0A00.N)}->128");
+ }
+ return jT808_0X0A00;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0A00 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.E);
+ if (value.N.Length != 128)
+ {
+ throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(value.N)}->128");
+ }
+ writer.WriteArray(value.N);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8001.cs b/src/JT808.Protocol/MessageBody/JT808_0x8001.cs
index f295779..a397ec5 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8001.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8001.cs
@@ -1,6 +1,8 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 平台通用应答
///
[JT808Formatter(typeof(JT808_0x8001_Formatter))]
- public class JT808_0x8001 : JT808Bodies
+ public class JT808_0x8001 : JT808Bodies, IJT808MessagePackFormatter
{
public ushort MsgNum { get; set; }
///
@@ -16,5 +18,20 @@ namespace JT808.Protocol.MessageBody
///
public ushort MsgId { get; set; }
public JT808PlatformResult JT808PlatformResult { get; set; }
+ public JT808_0x8001 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8001 jT808_0X8001 = new JT808_0x8001();
+ jT808_0X8001.MsgNum = reader.ReadUInt16();
+ jT808_0X8001.MsgId = reader.ReadUInt16();
+ jT808_0X8001.JT808PlatformResult = (JT808PlatformResult)reader.ReadByte();
+ return jT808_0X8001;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8001 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.MsgNum);
+ writer.WriteUInt16(value.MsgId);
+ writer.WriteByte((byte)value.JT808PlatformResult);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8003.cs b/src/JT808.Protocol/MessageBody/JT808_0x8003.cs
index 2ff7b65..9c10d82 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8003.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8003.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8003
///
[JT808Formatter(typeof(JT808_0x8003_Formatter))]
- public class JT808_0x8003 : JT808Bodies
+ public class JT808_0x8003 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 原始消息流水号
@@ -26,5 +28,20 @@ namespace JT808.Protocol.MessageBody
/// 重传包序号顺序排列,如“包 ID1 包 ID2......包 IDn”。
///
public byte[] AgainPackageData { get; set; }
+ public JT808_0x8003 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8003 jT808_0X8003 = new JT808_0x8003();
+ jT808_0X8003.OriginalMsgNum = reader.ReadUInt16();
+ jT808_0X8003.AgainPackageCount = reader.ReadByte();
+ jT808_0X8003.AgainPackageData = reader.ReadArray(jT808_0X8003.AgainPackageCount * 2).ToArray();
+ return jT808_0X8003;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8003 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.OriginalMsgNum);
+ writer.WriteByte((byte)(value.AgainPackageData.Length / 2));
+ writer.WriteArray(value.AgainPackageData);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8100.cs b/src/JT808.Protocol/MessageBody/JT808_0x8100.cs
index bd5191a..6a8b90f 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8100.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8100.cs
@@ -1,6 +1,8 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 终端注册应答
///
[JT808Formatter(typeof(JT808_0x8100_Formatter))]
- public class JT808_0x8100 : JT808Bodies
+ public class JT808_0x8100 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 应答流水号
@@ -26,5 +28,29 @@ namespace JT808.Protocol.MessageBody
/// 只有在成功后才有该字段
///
public string Code { get; set; }
+
+ public JT808_0x8100 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8100 jT808_0X8100 = new JT808_0x8100();
+ jT808_0X8100.MsgNum = reader.ReadUInt16();
+ jT808_0X8100.JT808TerminalRegisterResult = (JT808TerminalRegisterResult)reader.ReadByte();
+ // 只有在成功后才有该字段
+ if (jT808_0X8100.JT808TerminalRegisterResult == JT808TerminalRegisterResult.成功)
+ {
+ jT808_0X8100.Code = reader.ReadRemainStringContent();
+ }
+ return jT808_0X8100;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8100 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.MsgNum);
+ writer.WriteByte((byte)value.JT808TerminalRegisterResult);
+ // 只有在成功后才有该字段
+ if (value.JT808TerminalRegisterResult == JT808TerminalRegisterResult.成功)
+ {
+ writer.WriteString(value.Code);
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8105.cs b/src/JT808.Protocol/MessageBody/JT808_0x8105.cs
index 669e2ef..d9ad8a6 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8105.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8105.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System;
namespace JT808.Protocol.MessageBody
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 终端控制
///
[JT808Formatter(typeof(JT808_0x8105_Formatter))]
- public class JT808_0x8105 : JT808Bodies
+ public class JT808_0x8105 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 命令字
@@ -18,6 +20,29 @@ namespace JT808.Protocol.MessageBody
/// 命令参数
///
public CommandParams CommandValue { get; set; }
+
+ public JT808_0x8105 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8105 jT808_0x8105 = new JT808_0x8105
+ {
+ CommandWord = reader.ReadByte()
+ };
+ if (jT808_0x8105.CommandWord == 1 || jT808_0x8105.CommandWord == 2)
+ {
+ jT808_0x8105.CommandValue = new CommandParams();
+ jT808_0x8105.CommandValue.SetCommandParams(reader.ReadRemainStringContent());
+ }
+ return jT808_0x8105;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8105 value, IJT808Config config)
+ {
+ writer.WriteByte(value.CommandWord);
+ if (value.CommandWord == 1 || value.CommandWord == 2)
+ {
+ writer.WriteString(value.CommandValue.ToString());
+ }
+ }
}
///
/// 命令参数
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8106.cs b/src/JT808.Protocol/MessageBody/JT808_0x8106.cs
index 960ab48..649aabd 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8106.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8106.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System;
namespace JT808.Protocol.MessageBody
@@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8106
///
[JT808Formatter(typeof(JT808_0x8106_Formatter))]
- public class JT808_0x8106 : JT808Bodies
+ public class JT808_0x8106 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 参数总数
@@ -20,6 +22,28 @@ namespace JT808.Protocol.MessageBody
/// 参数 ID 列表
/// 参数顺序排列,如“参数 ID1 参数 ID2......参数IDn”。
///
- public UInt32[] Parameters { get; set; }
+ public uint[] Parameters { get; set; }
+
+ public JT808_0x8106 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8106 jT808_0X8106 = new JT808_0x8106();
+ jT808_0X8106.ParameterCount = reader.ReadByte();
+ jT808_0X8106.Parameters = new uint[jT808_0X8106.ParameterCount];
+ for (int i = 0; i < jT808_0X8106.ParameterCount; i++)
+ {
+ jT808_0X8106.Parameters.SetValue(reader.ReadUInt32(), i);
+ }
+ return jT808_0X8106;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8106 value, IJT808Config config)
+ {
+ writer.WriteByte(value.ParameterCount);
+ for (int i = 0; i < value.ParameterCount; i++)
+ {
+ writer.WriteUInt32(value.Parameters[i]);
+ }
+ }
+
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8108.cs b/src/JT808.Protocol/MessageBody/JT808_0x8108.cs
index 350cdfc..69b3925 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8108.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8108.cs
@@ -1,6 +1,8 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 下发终端升级包
///
[JT808Formatter(typeof(JT808_0x8108_Formatter))]
- public class JT808_0x8108 : JT808Bodies
+ public class JT808_0x8108 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 升级类型
@@ -35,5 +37,27 @@ namespace JT808.Protocol.MessageBody
/// 升级数据包
///
public byte[] UpgradePackage { get; set; }
+
+ public JT808_0x8108 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8108 jT808_0X8108 = new JT808_0x8108();
+ jT808_0X8108.UpgradeType = (JT808UpgradeType)reader.ReadByte();
+ jT808_0X8108.MakerId = reader.ReadString(5);
+ jT808_0X8108.VersionNumLength = reader.ReadByte();
+ jT808_0X8108.VersionNum = reader.ReadString(jT808_0X8108.VersionNumLength);
+ jT808_0X8108.UpgradePackageLength = reader.ReadInt32();
+ jT808_0X8108.UpgradePackage = reader.ReadArray(jT808_0X8108.UpgradePackageLength).ToArray();
+ return jT808_0X8108;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8108 value, IJT808Config config)
+ {
+ writer.WriteByte((byte)value.UpgradeType);
+ writer.WriteString(value.MakerId.PadRight(5, '0'));
+ writer.WriteByte((byte)value.VersionNum.Length);
+ writer.WriteString(value.VersionNum);
+ writer.WriteInt32(value.UpgradePackage.Length);
+ writer.WriteArray(value.UpgradePackage);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8202.cs b/src/JT808.Protocol/MessageBody/JT808_0x8202.cs
index f78630b..9d1b49a 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8202.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8202.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +9,7 @@ namespace JT808.Protocol.MessageBody
/// 临时位置跟踪控制
///
[JT808Formatter(typeof(JT808_0x8202_Formatter))]
- public class JT808_0x8202 : JT808Bodies
+ public class JT808_0x8202 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 时间间隔
@@ -20,5 +22,18 @@ namespace JT808.Protocol.MessageBody
/// 单位为秒(s),终端在接收到位置跟踪控制消息后,在有效期截止时间之前,依据消息中的时间间隔发送位置汇报
///
public int LocationTrackingValidity { get; set; }
+ public JT808_0x8202 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8202 jT808_0X8202 = new JT808_0x8202();
+ jT808_0X8202.Interval = reader.ReadUInt16();
+ jT808_0X8202.LocationTrackingValidity = reader.ReadInt32();
+ return jT808_0X8202;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8202 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.Interval);
+ writer.WriteInt32(value.LocationTrackingValidity);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8203.cs b/src/JT808.Protocol/MessageBody/JT808_0x8203.cs
index 7392ee8..684ac00 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8203.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8203.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8203
///
[JT808Formatter(typeof(JT808_0x8203_Formatter))]
- public class JT808_0x8203 : JT808Bodies
+ public class JT808_0x8203 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 报警消息流水号
@@ -19,5 +21,19 @@ namespace JT808.Protocol.MessageBody
/// 人工确认报警类型
///
public uint ManualConfirmAlarmType { get; set; }
+
+ public JT808_0x8203 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8203 jT808_0X8203 = new JT808_0x8203();
+ jT808_0X8203.AlarmMsgNum = reader.ReadUInt16();
+ jT808_0X8203.ManualConfirmAlarmType = reader.ReadUInt32();
+ return jT808_0X8203;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8203 value, IJT808Config config)
+ {
+ writer.WriteUInt16(value.AlarmMsgNum);
+ writer.WriteUInt32(value.ManualConfirmAlarmType);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8300.cs b/src/JT808.Protocol/MessageBody/JT808_0x8300.cs
index 338553b..7dcbf8a 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8300.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8300.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +9,7 @@ namespace JT808.Protocol.MessageBody
/// 文本信息下发
///
[JT808Formatter(typeof(JT808_0x8300_Formatter))]
- public class JT808_0x8300 : JT808Bodies
+ public class JT808_0x8300 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 文本信息标志位含义见 表 38
@@ -19,5 +21,19 @@ namespace JT808.Protocol.MessageBody
/// 最长为 1024 字节,经GBK编码
///
public string TextInfo { get; set; }
+
+ public JT808_0x8300 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8300 jT808_0X8300 = new JT808_0x8300();
+ jT808_0X8300.TextFlag = reader.ReadByte();
+ jT808_0X8300.TextInfo = reader.ReadRemainStringContent();
+ return jT808_0X8300;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8300 value, IJT808Config config)
+ {
+ writer.WriteByte(value.TextFlag);
+ writer.WriteString(value.TextInfo);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8301.cs b/src/JT808.Protocol/MessageBody/JT808_0x8301.cs
index bdf8e82..28737ea 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8301.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8301.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using JT808.Protocol.Metadata;
using System.Collections.Generic;
@@ -10,7 +12,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8301
///
[JT808Formatter(typeof(JT808_0x8301_Formatter))]
- public class JT808_0x8301 : JT808Bodies
+ public class JT808_0x8301 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 设置类型
@@ -25,5 +27,40 @@ namespace JT808.Protocol.MessageBody
/// 事件项
///
public List EventItems { get; set; }
+
+ public JT808_0x8301 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8301 jT808_0X8301 = new JT808_0x8301();
+ jT808_0X8301.SettingType = reader.ReadByte();
+ jT808_0X8301.SettingCount = reader.ReadByte();
+ jT808_0X8301.EventItems = new List();
+ for (var i = 0; i < jT808_0X8301.SettingCount; i++)
+ {
+ JT808EventProperty jT808EventProperty = new JT808EventProperty();
+ jT808EventProperty.EventId = reader.ReadByte();
+ jT808EventProperty.EventContentLength = reader.ReadByte();
+ jT808EventProperty.EventContent = reader.ReadString(jT808EventProperty.EventContentLength);
+ jT808_0X8301.EventItems.Add(jT808EventProperty);
+ }
+ return jT808_0X8301;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8301 value, IJT808Config config)
+ {
+ writer.WriteByte(value.SettingType);
+ if (value.EventItems != null && value.EventItems.Count > 0)
+ {
+ writer.WriteByte((byte)value.EventItems.Count);
+ foreach (var item in value.EventItems)
+ {
+ writer.WriteByte(item.EventId);
+ // 先计算内容长度(汉字为两个字节)
+ writer.Skip(1, out int eventPosition);
+ writer.WriteString(item.EventContent);
+ byte eventLength = (byte)(writer.GetCurrentPosition() - eventPosition - 1);
+ writer.WriteByteReturn(eventLength, eventPosition);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8302.cs b/src/JT808.Protocol/MessageBody/JT808_0x8302.cs
index acad82b..0ce1755 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8302.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8302.cs
@@ -1,5 +1,8 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
+using System;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -9,7 +12,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8302
///
[JT808Formatter(typeof(JT808_0x8302_Formatter))]
- public class JT808_0x8302 : JT808Bodies
+ public class JT808_0x8302 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 标志
@@ -47,5 +50,51 @@ namespace JT808.Protocol.MessageBody
///
public string Content { get; set; }
}
+
+ public JT808_0x8302 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8302 jT808_0X8302 = new JT808_0x8302();
+ jT808_0X8302.Flag = reader.ReadByte();
+ jT808_0X8302.IssueContentLength = reader.ReadByte();
+ jT808_0X8302.Issue = reader.ReadString(jT808_0X8302.IssueContentLength);
+ jT808_0X8302.Answers = new List();
+ while (reader.ReadCurrentRemainContentLength() > 0)
+ {
+ try
+ {
+ JT808_0x8302.Answer answer = new JT808_0x8302.Answer();
+ answer.Id = reader.ReadByte();
+ answer.ContentLength = reader.ReadUInt16();
+ answer.Content = reader.ReadString(answer.ContentLength);
+ jT808_0X8302.Answers.Add(answer);
+ }
+ catch (Exception ex)
+ {
+ break;
+ }
+ }
+ return jT808_0X8302;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8302 value, IJT808Config config)
+ {
+ writer.WriteByte(value.Flag);
+ // 先计算内容长度(汉字为两个字节)
+ writer.Skip(1, out int issuePosition);
+ writer.WriteString(value.Issue);
+ ushort issueLength = (ushort)(writer.GetCurrentPosition() - issuePosition - 1);
+ writer.WriteByteReturn((byte)issueLength, issuePosition);
+ if (value.Answers != null && value.Answers.Count > 0)
+ {
+ foreach (var item in value.Answers)
+ {
+ writer.WriteByte(item.Id);
+ writer.Skip(2, out int answerPosition);
+ writer.WriteString(item.Content);
+ ushort answerLength = (ushort)(writer.GetCurrentPosition() - answerPosition - 2);
+ writer.WriteUInt16Return(answerLength, answerPosition);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8303.cs b/src/JT808.Protocol/MessageBody/JT808_0x8303.cs
index 02601a9..2638c4e 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8303.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8303.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using JT808.Protocol.Metadata;
using System.Collections.Generic;
@@ -10,7 +12,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8303
///
[JT808Formatter(typeof(JT808_0x8303_Formatter))]
- public class JT808_0x8303 : JT808Bodies
+ public class JT808_0x8303 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 设置类型
@@ -26,5 +28,36 @@ namespace JT808.Protocol.MessageBody
/// 信息项列表
///
public List InformationItems { get; set; }
+ public JT808_0x8303 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8303 jT808_0X8303 = new JT808_0x8303();
+ jT808_0X8303.SettingType = reader.ReadByte();
+ jT808_0X8303.InformationItemCount = reader.ReadByte();
+ jT808_0X8303.InformationItems = new List();
+ for (var i = 0; i < jT808_0X8303.InformationItemCount; i++)
+ {
+ JT808InformationItemProperty jT808InformationItemProperty = new JT808InformationItemProperty();
+ jT808InformationItemProperty.InformationType = reader.ReadByte();
+ jT808InformationItemProperty.InformationLength = reader.ReadUInt16();
+ jT808InformationItemProperty.InformationName = reader.ReadString(jT808InformationItemProperty.InformationLength);
+ jT808_0X8303.InformationItems.Add(jT808InformationItemProperty);
+ }
+ return jT808_0X8303;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8303 value, IJT808Config config)
+ {
+ writer.WriteByte(value.SettingType);
+ writer.WriteByte((byte)value.InformationItems.Count);
+ foreach (var item in value.InformationItems)
+ {
+ writer.WriteByte(item.InformationType);
+ // 先计算内容长度(汉字为两个字节)
+ writer.Skip(2, out int position);
+ writer.WriteString(item.InformationName);
+ ushort length = (ushort)(writer.GetCurrentPosition() - position - 2);
+ writer.WriteUInt16Return(length, position);
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8304.cs b/src/JT808.Protocol/MessageBody/JT808_0x8304.cs
index 56bfde9..8d22391 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8304.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8304.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8304
///
[JT808Formatter(typeof(JT808_0x8304_Formatter))]
- public class JT808_0x8304 : JT808Bodies
+ public class JT808_0x8304 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 信息类型
@@ -23,6 +25,24 @@ namespace JT808.Protocol.MessageBody
/// 经 GBK 编码
///
public string InformationContent { get; set; }
+ public JT808_0x8304 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8304 jT808_0X8304 = new JT808_0x8304();
+ jT808_0X8304.InformationType = reader.ReadByte();
+ jT808_0X8304.InformationLength = reader.ReadUInt16();
+ jT808_0X8304.InformationContent = reader.ReadString(jT808_0X8304.InformationLength);
+ return jT808_0X8304;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8304 value, IJT808Config config)
+ {
+ writer.WriteByte(value.InformationType);
+ // 先计算内容长度(汉字为两个字节)
+ writer.Skip(2, out int position);
+ writer.WriteString(value.InformationContent);
+ ushort length = (ushort)(writer.GetCurrentPosition() - position - 2);
+ writer.WriteUInt16Return(length, position);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8400.cs b/src/JT808.Protocol/MessageBody/JT808_0x8400.cs
index 40dc535..f84a2a0 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8400.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8400.cs
@@ -1,6 +1,8 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 电话回拨
///
[JT808Formatter(typeof(JT808_0x8400_Formatter))]
- public class JT808_0x8400 : JT808Bodies
+ public class JT808_0x8400 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 0:普通通话;1:监听
@@ -19,5 +21,20 @@ namespace JT808.Protocol.MessageBody
/// 最长为 20 字节
///
public string PhoneNumber { get; set; }
+
+ public JT808_0x8400 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8400 jT808_0X8400 = new JT808_0x8400();
+ jT808_0X8400.CallBack = (JT808CallBackType)reader.ReadByte();
+ // 最长为 20 字节
+ jT808_0X8400.PhoneNumber = reader.ReadRemainStringContent();
+ return jT808_0X8400;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8400 value, IJT808Config config)
+ {
+ writer.WriteByte((byte)value.CallBack);
+ writer.WriteString(value.PhoneNumber);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8401.cs b/src/JT808.Protocol/MessageBody/JT808_0x8401.cs
index 6c5790e..ccc69ac 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8401.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8401.cs
@@ -1,6 +1,8 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using JT808.Protocol.Metadata;
using System.Collections.Generic;
@@ -10,7 +12,7 @@ namespace JT808.Protocol.MessageBody
/// 设置电话本
///
[JT808Formatter(typeof(JT808_0x8401_Formatter))]
- public class JT808_0x8401 : JT808Bodies
+ public class JT808_0x8401 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 设置类型
@@ -24,5 +26,38 @@ namespace JT808.Protocol.MessageBody
/// 联系人项
///
public IList JT808ContactProperties { get; set; }
+ public JT808_0x8401 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8401 jT808_0X8401 = new JT808_0x8401();
+ jT808_0X8401.SettingTelephoneBook = (JT808SettingTelephoneBook)reader.ReadByte();
+ jT808_0X8401.ContactCount = reader.ReadByte();
+ List jT808_0X8401s = new List();
+ for (var i = 0; i < jT808_0X8401.ContactCount; i++)
+ {
+ JT808ContactProperty jT808ContactProperty = new JT808ContactProperty();
+ jT808ContactProperty.TelephoneBookContactType = (JT808TelephoneBookContactType)reader.ReadByte();
+ jT808ContactProperty.PhoneNumberLength = reader.ReadByte();
+ jT808ContactProperty.PhoneNumber = reader.ReadString(jT808ContactProperty.PhoneNumberLength);
+ jT808ContactProperty.ContactLength = reader.ReadByte();
+ jT808ContactProperty.Contact = reader.ReadString(jT808ContactProperty.ContactLength);
+ jT808_0X8401s.Add(jT808ContactProperty);
+ }
+ jT808_0X8401.JT808ContactProperties = jT808_0X8401s;
+ return jT808_0X8401;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8401 value, IJT808Config config)
+ {
+ writer.WriteByte((byte)value.SettingTelephoneBook);
+ writer.WriteByte((byte)value.JT808ContactProperties.Count);
+ foreach (var item in value.JT808ContactProperties)
+ {
+ writer.WriteByte((byte)item.TelephoneBookContactType);
+ writer.WriteByte((byte)item.PhoneNumber.Length);
+ writer.WriteString(item.PhoneNumber);
+ writer.WriteByte((byte)item.Contact.Length);
+ writer.WriteString(item.Contact);
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8500.cs b/src/JT808.Protocol/MessageBody/JT808_0x8500.cs
index bc70231..0efc718 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8500.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8500.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +9,7 @@ namespace JT808.Protocol.MessageBody
/// 车辆控制
///
[JT808Formatter(typeof(JT808_0x8500_Formatter))]
- public class JT808_0x8500 : JT808Bodies
+ public class JT808_0x8500 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 控制标志
@@ -16,5 +18,16 @@ namespace JT808.Protocol.MessageBody
/// 1-7 保留
///
public byte ControlFlag { get; set; }
+
+ public JT808_0x8500 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8500 jT808_0X8500 = new JT808_0x8500();
+ jT808_0X8500.ControlFlag = reader.ReadByte();
+ return jT808_0X8500;
+ }
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8500 value, IJT808Config config)
+ {
+ writer.WriteByte(value.ControlFlag);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8600.cs b/src/JT808.Protocol/MessageBody/JT808_0x8600.cs
index 4ca1a6b..5c5c138 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8600.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8600.cs
@@ -1,6 +1,9 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using JT808.Protocol.Metadata;
+using System;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -11,7 +14,7 @@ namespace JT808.Protocol.MessageBody
/// 注:本条消息协议支持周期时间范围,如要限制每天的8:30-18:00,起始/结束时间设为:00-00-00-08-30-00/00-00-00-18-00-00,其他以此类推
///
[JT808Formatter(typeof(JT808_0x8600_Formatter))]
- public class JT808_0x8600 : JT808Bodies
+ public class JT808_0x8600 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 设置属性
@@ -26,5 +29,79 @@ namespace JT808.Protocol.MessageBody
/// 区域项
///
public List AreaItems { get; set; }
+
+ public JT808_0x8600 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8600 jT808_0X8600 = new JT808_0x8600();
+ jT808_0X8600.SettingAreaProperty = reader.ReadByte();
+ jT808_0X8600.AreaCount = reader.ReadByte();
+ jT808_0X8600.AreaItems = new List();
+ for (var i = 0; i < jT808_0X8600.AreaCount; i++)
+ {
+ JT808CircleAreaProperty jT808CircleAreaProperty = new JT808CircleAreaProperty();
+ jT808CircleAreaProperty.AreaId = reader.ReadUInt32();
+ jT808CircleAreaProperty.AreaProperty = reader.ReadUInt16();
+ jT808CircleAreaProperty.CenterPointLat = reader.ReadUInt32();
+ jT808CircleAreaProperty.CenterPointLng = reader.ReadUInt32();
+ jT808CircleAreaProperty.Radius = reader.ReadUInt32();
+ ReadOnlySpan areaProperty16Bit = Convert.ToString(jT808CircleAreaProperty.AreaProperty, 2).PadLeft(16, '0').AsSpan();
+ bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!bit0Flag)
+ {
+ jT808CircleAreaProperty.StartTime = reader.ReadDateTime6();
+ jT808CircleAreaProperty.EndTime = reader.ReadDateTime6();
+ }
+ bool bit1Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 2, 1).ToString().Equals("0");
+ if (!bit1Flag)
+ {
+ jT808CircleAreaProperty.HighestSpeed = reader.ReadUInt16();
+ jT808CircleAreaProperty.OverspeedDuration = reader.ReadByte();
+ }
+ jT808_0X8600.AreaItems.Add(jT808CircleAreaProperty);
+ }
+ return jT808_0X8600;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8600 value, IJT808Config config)
+ {
+ writer.WriteByte(value.SettingAreaProperty);
+ if (value.AreaItems != null)
+ {
+ writer.WriteByte((byte)value.AreaItems.Count);
+ foreach (var item in value.AreaItems)
+ {
+ writer.WriteUInt32(item.AreaId);
+ writer.WriteUInt16(item.AreaProperty);
+ writer.WriteUInt32(item.CenterPointLat);
+ writer.WriteUInt32(item.CenterPointLng);
+ writer.WriteUInt32(item.Radius);
+ ReadOnlySpan areaProperty16Bit = Convert.ToString(item.AreaProperty, 2).PadLeft(16, '0').AsSpan();
+ bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!bit0Flag)
+ {
+ if (item.StartTime.HasValue)
+ {
+ writer.WriteDateTime6(item.StartTime.Value);
+ }
+ if (item.EndTime.HasValue)
+ {
+ writer.WriteDateTime6(item.EndTime.Value);
+ }
+ }
+ bool bit1Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 2, 1).ToString().Equals("0");
+ if (!bit1Flag)
+ {
+ if (item.HighestSpeed.HasValue)
+ {
+ writer.WriteUInt16(item.HighestSpeed.Value);
+ }
+ if (item.OverspeedDuration.HasValue)
+ {
+ writer.WriteByte(item.OverspeedDuration.Value);
+ }
+ }
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8601.cs b/src/JT808.Protocol/MessageBody/JT808_0x8601.cs
index 260d07f..9c2fc46 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8601.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8601.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8601
///
[JT808Formatter(typeof(JT808_0x8601_Formatter))]
- public class JT808_0x8601 : JT808Bodies
+ public class JT808_0x8601 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 区域数
@@ -20,5 +22,29 @@ namespace JT808.Protocol.MessageBody
/// 区域ID集合
///
public List AreaIds { get; set; }
+
+ public JT808_0x8601 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8601 jT808_0X8601 = new JT808_0x8601();
+ jT808_0X8601.AreaCount = reader.ReadByte();
+ jT808_0X8601.AreaIds = new List();
+ for (var i = 0; i < jT808_0X8601.AreaCount; i++)
+ {
+ jT808_0X8601.AreaIds.Add(reader.ReadUInt32());
+ }
+ return jT808_0X8601;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8601 value, IJT808Config config)
+ {
+ if (value.AreaIds != null)
+ {
+ writer.WriteByte((byte)value.AreaIds.Count);
+ foreach (var item in value.AreaIds)
+ {
+ writer.WriteUInt32(item);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8602.cs b/src/JT808.Protocol/MessageBody/JT808_0x8602.cs
index c5d9626..043f752 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8602.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8602.cs
@@ -1,6 +1,9 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using JT808.Protocol.Metadata;
+using System;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -10,7 +13,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8602
///
[JT808Formatter(typeof(JT808_0x8602_Formatter))]
- public class JT808_0x8602 : JT808Bodies
+ public class JT808_0x8602 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 设置属性
@@ -26,5 +29,80 @@ namespace JT808.Protocol.MessageBody
///
public List AreaItems { get; set; }
+ public JT808_0x8602 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8602 jT808_0X8602 = new JT808_0x8602();
+ jT808_0X8602.SettingAreaProperty = reader.ReadByte();
+ jT808_0X8602.AreaCount = reader.ReadByte();
+ jT808_0X8602.AreaItems = new List();
+ for (var i = 0; i < jT808_0X8602.AreaCount; i++)
+ {
+ JT808RectangleAreaProperty jT808CircleAreaProperty = new JT808RectangleAreaProperty();
+ jT808CircleAreaProperty.AreaId = reader.ReadUInt32();
+ jT808CircleAreaProperty.AreaProperty = reader.ReadUInt16();
+ jT808CircleAreaProperty.UpLeftPointLat = reader.ReadUInt32();
+ jT808CircleAreaProperty.UpLeftPointLng = reader.ReadUInt32();
+ jT808CircleAreaProperty.LowRightPointLat = reader.ReadUInt32();
+ jT808CircleAreaProperty.LowRightPointLng = reader.ReadUInt32();
+ ReadOnlySpan areaProperty16Bit = Convert.ToString(jT808CircleAreaProperty.AreaProperty, 2).PadLeft(16, '0').AsSpan();
+ bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!bit0Flag)
+ {
+ jT808CircleAreaProperty.StartTime = reader.ReadDateTime6();
+ jT808CircleAreaProperty.EndTime = reader.ReadDateTime6();
+ }
+ bool bit1Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 2, 1).ToString().Equals("0");
+ if (!bit1Flag)
+ {
+ jT808CircleAreaProperty.HighestSpeed = reader.ReadUInt16();
+ jT808CircleAreaProperty.OverspeedDuration = reader.ReadByte();
+ }
+ jT808_0X8602.AreaItems.Add(jT808CircleAreaProperty);
+ }
+ return jT808_0X8602;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8602 value, IJT808Config config)
+ {
+ writer.WriteByte(value.SettingAreaProperty);
+ if (value.AreaItems != null)
+ {
+ writer.WriteByte((byte)value.AreaItems.Count);
+ foreach (var item in value.AreaItems)
+ {
+ writer.WriteUInt32(item.AreaId);
+ writer.WriteUInt16(item.AreaProperty);
+ writer.WriteUInt32(item.UpLeftPointLat);
+ writer.WriteUInt32(item.UpLeftPointLng);
+ writer.WriteUInt32(item.LowRightPointLat);
+ writer.WriteUInt32(item.LowRightPointLng);
+ ReadOnlySpan areaProperty16Bit = Convert.ToString(item.AreaProperty, 2).PadLeft(16, '0').AsSpan();
+ bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!bit0Flag)
+ {
+ if (item.StartTime.HasValue)
+ {
+ writer.WriteDateTime6(item.StartTime.Value);
+ }
+ if (item.EndTime.HasValue)
+ {
+ writer.WriteDateTime6(item.EndTime.Value);
+ }
+ }
+ bool bit1Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 2, 1).ToString().Equals("0");
+ if (!bit1Flag)
+ {
+ if (item.HighestSpeed.HasValue)
+ {
+ writer.WriteUInt16(item.HighestSpeed.Value);
+ }
+ if (item.OverspeedDuration.HasValue)
+ {
+ writer.WriteByte(item.OverspeedDuration.Value);
+ }
+ }
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8603.cs b/src/JT808.Protocol/MessageBody/JT808_0x8603.cs
index f1041a2..0ae4cd8 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8603.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8603.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8603
///
[JT808Formatter(typeof(JT808_0x8603_Formatter))]
- public class JT808_0x8603 : JT808Bodies
+ public class JT808_0x8603 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 区域数
@@ -20,5 +22,29 @@ namespace JT808.Protocol.MessageBody
/// 区域ID集合
///
public List AreaIds { get; set; }
+
+ public JT808_0x8603 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8603 jT808_0X8603 = new JT808_0x8603();
+ jT808_0X8603.AreaCount = reader.ReadByte();
+ jT808_0X8603.AreaIds = new List();
+ for (var i = 0; i < jT808_0X8603.AreaCount; i++)
+ {
+ jT808_0X8603.AreaIds.Add(reader.ReadUInt32());
+ }
+ return jT808_0X8603;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8603 value, IJT808Config config)
+ {
+ if (value.AreaIds != null)
+ {
+ writer.WriteByte((byte)value.AreaIds.Count);
+ foreach (var item in value.AreaIds)
+ {
+ writer.WriteUInt32(item);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8604.cs b/src/JT808.Protocol/MessageBody/JT808_0x8604.cs
index 217f1f8..918ad12 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8604.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8604.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using JT808.Protocol.Metadata;
using System;
using System.Collections.Generic;
@@ -11,7 +13,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8604
///
[JT808Formatter(typeof(JT808_0x8604_Formatter))]
- public class JT808_0x8604 : JT808Bodies
+ public class JT808_0x8604 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 区域 ID
@@ -50,5 +52,75 @@ namespace JT808.Protocol.MessageBody
/// 顶点项
///
public List PeakItems { get; set; }
+
+ public JT808_0x8604 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8604 jT808_0X8604 = new JT808_0x8604();
+ jT808_0X8604.AreaId = reader.ReadUInt32();
+ jT808_0X8604.AreaProperty = reader.ReadUInt16();
+ ReadOnlySpan areaProperty16Bit = Convert.ToString(jT808_0X8604.AreaProperty, 2).PadLeft(16, '0').AsSpan();
+ bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!bit0Flag)
+ {
+ jT808_0X8604.StartTime = reader.ReadDateTime6();
+ jT808_0X8604.EndTime = reader.ReadDateTime6();
+ }
+ bool bit1Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 2, 1).ToString().Equals("0");
+ if (!bit1Flag)
+ {
+ jT808_0X8604.HighestSpeed = reader.ReadUInt16();
+ jT808_0X8604.OverspeedDuration = reader.ReadByte();
+ }
+ jT808_0X8604.PeakCount = reader.ReadUInt16();
+ jT808_0X8604.PeakItems = new List();
+ for (var i = 0; i < jT808_0X8604.PeakCount; i++)
+ {
+ var item = new JT808PeakProperty();
+ item.Lat = reader.ReadUInt32();
+ item.Lng = reader.ReadUInt32();
+ jT808_0X8604.PeakItems.Add(item);
+ }
+ return jT808_0X8604;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8604 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.AreaId);
+ writer.WriteUInt16(value.AreaProperty);
+ ReadOnlySpan areaProperty16Bit = Convert.ToString(value.AreaProperty, 2).PadLeft(16, '0').AsSpan();
+ bool bit0Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!bit0Flag)
+ {
+ if (value.StartTime.HasValue)
+ {
+ writer.WriteDateTime6(value.StartTime.Value);
+ }
+ if (value.EndTime.HasValue)
+ {
+ writer.WriteDateTime6(value.EndTime.Value);
+ }
+ }
+ bool bit1Flag = areaProperty16Bit.Slice(areaProperty16Bit.Length - 2, 1).ToString().Equals("0");
+ if (!bit1Flag)
+ {
+ if (value.HighestSpeed.HasValue)
+ {
+ writer.WriteUInt16(value.HighestSpeed.Value);
+ }
+ if (value.OverspeedDuration.HasValue)
+ {
+ writer.WriteByte(value.OverspeedDuration.Value);
+ }
+ }
+ if (value.PeakItems != null && value.PeakItems.Count > 0)
+ {
+ writer.WriteUInt16((ushort)value.PeakItems.Count);
+ foreach (var item in value.PeakItems)
+ {
+ writer.WriteUInt32(item.Lat);
+ writer.WriteUInt32(item.Lng);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8605.cs b/src/JT808.Protocol/MessageBody/JT808_0x8605.cs
index 6b98c1b..4cf6f0f 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8605.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8605.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8605
///
[JT808Formatter(typeof(JT808_0x8605_Formatter))]
- public class JT808_0x8605 : JT808Bodies
+ public class JT808_0x8605 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 区域数
@@ -20,5 +22,28 @@ namespace JT808.Protocol.MessageBody
/// 区域ID集合
///
public List AreaIds { get; set; }
+ public JT808_0x8605 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8605 jT808_0X8605 = new JT808_0x8605();
+ jT808_0X8605.AreaCount = reader.ReadByte();
+ jT808_0X8605.AreaIds = new List();
+ for (var i = 0; i < jT808_0X8605.AreaCount; i++)
+ {
+ jT808_0X8605.AreaIds.Add(reader.ReadUInt32());
+ }
+ return jT808_0X8605;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8605 value, IJT808Config config)
+ {
+ if (value.AreaIds != null)
+ {
+ writer.WriteByte((byte)value.AreaIds.Count);
+ foreach (var item in value.AreaIds)
+ {
+ writer.WriteUInt32(item);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8606.cs b/src/JT808.Protocol/MessageBody/JT808_0x8606.cs
index 976c61d..fd9975f 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8606.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8606.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using JT808.Protocol.Metadata;
using System;
using System.Collections.Generic;
@@ -11,7 +13,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8606
///
[JT808Formatter(typeof(JT808_0x8606_Formatter))]
- public class JT808_0x8606 : JT808Bodies
+ public class JT808_0x8606 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 路线 ID
@@ -40,5 +42,94 @@ namespace JT808.Protocol.MessageBody
/// 拐点项
///
public List InflectionPointItems { get; set; }
+
+ public JT808_0x8606 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8606 jT808_0X8606 = new JT808_0x8606();
+ jT808_0X8606.RouteId = reader.ReadUInt32();
+ jT808_0X8606.RouteProperty = reader.ReadUInt16();
+ ReadOnlySpan routeProperty16Bit = Convert.ToString(jT808_0X8606.RouteProperty, 2).PadLeft(16, '0').AsSpan();
+ bool bit0Flag = routeProperty16Bit.Slice(routeProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!bit0Flag)
+ {
+ jT808_0X8606.StartTime = reader.ReadDateTime6();
+ jT808_0X8606.EndTime = reader.ReadDateTime6();
+ }
+ jT808_0X8606.InflectionPointCount = reader.ReadUInt16();
+ jT808_0X8606.InflectionPointItems = new List();
+ for (var i = 0; i < jT808_0X8606.InflectionPointCount; i++)
+ {
+ JT808InflectionPointProperty jT808InflectionPointProperty = new JT808InflectionPointProperty();
+ jT808InflectionPointProperty.InflectionPointId = reader.ReadUInt32();
+ jT808InflectionPointProperty.SectionId = reader.ReadUInt32();
+ jT808InflectionPointProperty.InflectionPointLat = reader.ReadUInt32();
+ jT808InflectionPointProperty.InflectionPointLng = reader.ReadUInt32();
+ jT808InflectionPointProperty.SectionWidth = reader.ReadByte();
+ jT808InflectionPointProperty.SectionProperty = reader.ReadByte();
+ ReadOnlySpan sectionProperty16Bit = Convert.ToString(jT808InflectionPointProperty.SectionProperty, 2).PadLeft(16, '0').AsSpan();
+ bool sectionBit0Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!sectionBit0Flag)
+ {
+ jT808InflectionPointProperty.SectionLongDrivingThreshold = reader.ReadUInt16();
+ jT808InflectionPointProperty.SectionDrivingUnderThreshold = reader.ReadUInt16();
+ }
+ bool sectionBit1Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 2, 1).ToString().Equals("0");
+ if (!sectionBit1Flag)
+ {
+ jT808InflectionPointProperty.SectionHighestSpeed = reader.ReadUInt16();
+ jT808InflectionPointProperty.SectionOverspeedDuration = reader.ReadByte();
+ }
+ jT808_0X8606.InflectionPointItems.Add(jT808InflectionPointProperty);
+ }
+ return jT808_0X8606;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8606 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.RouteId);
+ writer.WriteUInt16(value.RouteProperty);
+ ReadOnlySpan routeProperty16Bit = Convert.ToString(value.RouteProperty, 2).PadLeft(16, '0').AsSpan();
+ bool bit0Flag = routeProperty16Bit.Slice(routeProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!bit0Flag)
+ {
+ if (value.StartTime.HasValue)
+ writer.WriteDateTime6(value.StartTime.Value);
+
+ if (value.EndTime.HasValue)
+ writer.WriteDateTime6(value.EndTime.Value);
+ }
+ //bool bit1Flag = routeProperty16Bit.Slice(routeProperty16Bit.Length - 2, 1).ToString().Equals("0");
+ if (value.InflectionPointItems != null && value.InflectionPointItems.Count > 0)
+ {
+ writer.WriteUInt16((ushort)value.InflectionPointItems.Count);
+ foreach (var item in value.InflectionPointItems)
+ {
+ writer.WriteUInt32(item.InflectionPointId);
+ writer.WriteUInt32(item.SectionId);
+ writer.WriteUInt32(item.InflectionPointLat);
+ writer.WriteUInt32(item.InflectionPointLng);
+ writer.WriteByte(item.SectionWidth);
+ writer.WriteByte(item.SectionProperty);
+
+ ReadOnlySpan sectionProperty16Bit = Convert.ToString(item.SectionProperty, 2).PadLeft(16, '0').AsSpan();
+ bool sectionBit0Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 1).ToString().Equals("0");
+ if (!sectionBit0Flag)
+ {
+ if (item.SectionLongDrivingThreshold.HasValue)
+ writer.WriteUInt16(item.SectionLongDrivingThreshold.Value);
+ if (item.SectionDrivingUnderThreshold.HasValue)
+ writer.WriteUInt16(item.SectionDrivingUnderThreshold.Value);
+ }
+ bool sectionBit1Flag = sectionProperty16Bit.Slice(sectionProperty16Bit.Length - 2, 1).ToString().Equals("0");
+ if (!sectionBit1Flag)
+ {
+ if (item.SectionHighestSpeed.HasValue)
+ writer.WriteUInt16(item.SectionHighestSpeed.Value);
+ if (item.SectionOverspeedDuration.HasValue)
+ writer.WriteByte(item.SectionOverspeedDuration.Value);
+ }
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8607.cs b/src/JT808.Protocol/MessageBody/JT808_0x8607.cs
index d6f506f..5aa2ead 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8607.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8607.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System.Collections.Generic;
namespace JT808.Protocol.MessageBody
@@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8607
///
[JT808Formatter(typeof(JT808_0x8607_Formatter))]
- public class JT808_0x8607 : JT808Bodies
+ public class JT808_0x8607 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 区域数
@@ -20,5 +22,29 @@ namespace JT808.Protocol.MessageBody
/// 区域ID集合
///
public List AreaIds { get; set; }
+
+ public JT808_0x8607 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8607 jT808_0X8607 = new JT808_0x8607();
+ jT808_0X8607.AreaCount = reader.ReadByte();
+ jT808_0X8607.AreaIds = new List();
+ for (var i = 0; i < jT808_0X8607.AreaCount; i++)
+ {
+ jT808_0X8607.AreaIds.Add(reader.ReadUInt32());
+ }
+ return jT808_0X8607;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8607 value, IJT808Config config)
+ {
+ if (value.AreaIds != null)
+ {
+ writer.WriteByte((byte)value.AreaIds.Count);
+ foreach (var item in value.AreaIds)
+ {
+ writer.WriteUInt32(item);
+ }
+ }
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8800.cs b/src/JT808.Protocol/MessageBody/JT808_0x8800.cs
index 6f3d3e0..3b9ed3a 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8800.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8800.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8800
///
[JT808Formatter(typeof(JT808_0x8800_Formatter))]
- public class JT808_0x8800 : JT808Bodies
+ public class JT808_0x8800 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 多媒体ID
@@ -23,5 +25,20 @@ namespace JT808.Protocol.MessageBody
/// 重传包序号顺序排列,如“包 ID1 包 ID2......包 IDn”。
///
public byte[] RetransmitPackageIds { get; set; }
+ public JT808_0x8800 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8800 jT808_0X8800 = new JT808_0x8800();
+ jT808_0X8800.MultimediaId = reader.ReadUInt32();
+ jT808_0X8800.RetransmitPackageCount = reader.ReadByte();
+ jT808_0X8800.RetransmitPackageIds = reader.ReadArray(jT808_0X8800.RetransmitPackageCount * 2).ToArray();
+ return jT808_0X8800;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8800 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.MultimediaId);
+ writer.WriteByte((byte)(value.RetransmitPackageIds.Length / 2));
+ writer.WriteArray(value.RetransmitPackageIds);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8801.cs b/src/JT808.Protocol/MessageBody/JT808_0x8801.cs
index f061c89..4ee6c7f 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8801.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8801.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8801
///
[JT808Formatter(typeof(JT808_0x8801_Formatter))]
- public class JT808_0x8801 : JT808Bodies
+ public class JT808_0x8801 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 通道 ID
@@ -66,5 +68,34 @@ namespace JT808.Protocol.MessageBody
/// 0-255
///
public byte Chroma { get; set; }
+ public JT808_0x8801 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8801 jT808_0X8801 = new JT808_0x8801();
+ jT808_0X8801.ChannelId = reader.ReadByte();
+ jT808_0X8801.ShootingCommand = reader.ReadUInt16();
+ jT808_0X8801.VideoTime = reader.ReadUInt16();
+ jT808_0X8801.SaveFlag = reader.ReadByte();
+ jT808_0X8801.Resolution = reader.ReadByte();
+ jT808_0X8801.VideoQuality = reader.ReadByte();
+ jT808_0X8801.Lighting = reader.ReadByte();
+ jT808_0X8801.Contrast = reader.ReadByte();
+ jT808_0X8801.Saturability = reader.ReadByte();
+ jT808_0X8801.Chroma = reader.ReadByte();
+ return jT808_0X8801;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8801 value, IJT808Config config)
+ {
+ writer.WriteByte(value.ChannelId);
+ writer.WriteUInt16(value.ShootingCommand);
+ writer.WriteUInt16(value.VideoTime);
+ writer.WriteByte(value.SaveFlag);
+ writer.WriteByte(value.Resolution);
+ writer.WriteByte(value.VideoQuality);
+ writer.WriteByte(value.Lighting);
+ writer.WriteByte(value.Contrast);
+ writer.WriteByte(value.Saturability);
+ writer.WriteByte(value.Chroma);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8802.cs b/src/JT808.Protocol/MessageBody/JT808_0x8802.cs
index 27b5231..87bada8 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8802.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8802.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System;
namespace JT808.Protocol.MessageBody
@@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8802
///
[JT808Formatter(typeof(JT808_0x8802_Formatter))]
- public class JT808_0x8802 : JT808Bodies
+ public class JT808_0x8802 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 多媒体类型
@@ -36,5 +38,24 @@ namespace JT808.Protocol.MessageBody
/// YY-MM-DD-hh-mm-ss
///
public DateTime EndTime { get; set; }
+ public JT808_0x8802 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8802 jT808_0X8802 = new JT808_0x8802();
+ jT808_0X8802.MultimediaType = reader.ReadByte();
+ jT808_0X8802.ChannelId = reader.ReadByte();
+ jT808_0X8802.EventItemCoding = reader.ReadByte();
+ jT808_0X8802.StartTime = reader.ReadDateTime6();
+ jT808_0X8802.EndTime = reader.ReadDateTime6();
+ return jT808_0X8802;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8802 value, IJT808Config config)
+ {
+ writer.WriteByte(value.MultimediaType);
+ writer.WriteByte(value.ChannelId);
+ writer.WriteByte(value.EventItemCoding);
+ writer.WriteDateTime6(value.StartTime);
+ writer.WriteDateTime6(value.EndTime);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8803.cs b/src/JT808.Protocol/MessageBody/JT808_0x8803.cs
index 2fe7a1e..cb82629 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8803.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8803.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
using System;
namespace JT808.Protocol.MessageBody
@@ -9,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8803
///
[JT808Formatter(typeof(JT808_0x8803_Formatter))]
- public class JT808_0x8803 : JT808Bodies
+ public class JT808_0x8803 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 多媒体类型
@@ -42,5 +44,26 @@ namespace JT808.Protocol.MessageBody
///
///
public byte MultimediaDeleted { get; set; }
+ public JT808_0x8803 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8803 jT808_0X8803 = new JT808_0x8803();
+ jT808_0X8803.MultimediaType = reader.ReadByte();
+ jT808_0X8803.ChannelId = reader.ReadByte();
+ jT808_0X8803.EventItemCoding = reader.ReadByte();
+ jT808_0X8803.StartTime = reader.ReadDateTime6();
+ jT808_0X8803.EndTime = reader.ReadDateTime6();
+ jT808_0X8803.MultimediaDeleted = reader.ReadByte();
+ return jT808_0X8803;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8803 value, IJT808Config config)
+ {
+ writer.WriteByte(value.MultimediaType);
+ writer.WriteByte(value.ChannelId);
+ writer.WriteByte(value.EventItemCoding);
+ writer.WriteDateTime6(value.StartTime);
+ writer.WriteDateTime6(value.EndTime);
+ writer.WriteByte(value.MultimediaDeleted);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8804.cs b/src/JT808.Protocol/MessageBody/JT808_0x8804.cs
index e1c9be0..5e312e4 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8804.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8804.cs
@@ -1,6 +1,8 @@
using JT808.Protocol.Attributes;
using JT808.Protocol.Enums;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 录音开始命令
///
[JT808Formatter(typeof(JT808_0x8804_Formatter))]
- public class JT808_0x8804 : JT808Bodies
+ public class JT808_0x8804 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 录音命令
@@ -29,5 +31,22 @@ namespace JT808.Protocol.MessageBody
/// 0:8K;1:11K;2:23K;3:32K;其他保留
///
public byte AudioSampleRate { get; set; }
+
+ public JT808_0x8804 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8804 jT808_0X8804 = new JT808_0x8804();
+ jT808_0X8804.RecordCmd = (JT808RecordCmd)reader.ReadByte();
+ jT808_0X8804.RecordTime = reader.ReadUInt16();
+ jT808_0X8804.RecordSave = (JT808RecordSave)reader.ReadByte();
+ jT808_0X8804.AudioSampleRate = reader.ReadByte();
+ return jT808_0X8804;
+ }
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8804 value, IJT808Config config)
+ {
+ writer.WriteByte((byte)value.RecordCmd);
+ writer.WriteUInt16(value.RecordTime);
+ writer.WriteByte((byte)value.RecordSave);
+ writer.WriteByte(value.AudioSampleRate);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8805.cs b/src/JT808.Protocol/MessageBody/JT808_0x8805.cs
index 46cd5c9..cf91e48 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8805.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8805.cs
@@ -1,5 +1,7 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +9,7 @@ namespace JT808.Protocol.MessageBody
/// 单条存储多媒体数据检索上传命令
///
[JT808Formatter(typeof(JT808_0x8805_Formatter))]
- public class JT808_0x8805 : JT808Bodies
+ public class JT808_0x8805 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 多媒体ID
@@ -18,5 +20,18 @@ namespace JT808.Protocol.MessageBody
///
///
public byte MultimediaDeleted { get; set; }
+ public JT808_0x8805 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8805 jT808_0X8805 = new JT808_0x8805();
+ jT808_0X8805.MultimediaId = reader.ReadUInt32();
+ jT808_0X8805.MultimediaDeleted = reader.ReadByte();
+ return jT808_0X8805;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8805 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.MultimediaId);
+ writer.WriteByte(value.MultimediaDeleted);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8900.cs b/src/JT808.Protocol/MessageBody/JT808_0x8900.cs
index baa03d6..58c8315 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8900.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8900.cs
@@ -1,5 +1,8 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Extensions;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -7,7 +10,7 @@ namespace JT808.Protocol.MessageBody
/// 数据下行透传
///
[JT808Formatter(typeof(JT808_0x8900_Formatter))]
- public class JT808_0x8900 : JT808Bodies
+ public class JT808_0x8900 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// 透传消息类型
@@ -24,5 +27,20 @@ namespace JT808.Protocol.MessageBody
/// 透传消息内容
///
public JT808_0x8900_BodyBase JT808_0X8900_BodyBase { get; set; }
+
+ public JT808_0x8900 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8900 jT808_0X8900 = new JT808_0x8900();
+ jT808_0X8900.PassthroughType = reader.ReadByte();
+ jT808_0X8900.PassthroughData = reader.ReadContent().ToArray();
+ return jT808_0X8900;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8900 value, IJT808Config config)
+ {
+ writer.WriteByte(value.PassthroughType);
+ object obj = config.GetMessagePackFormatterByType(value.JT808_0X8900_BodyBase.GetType());
+ JT808MessagePackFormatterResolverExtensions.JT808DynamicSerialize(obj, ref writer, value.JT808_0X8900_BodyBase, config);
+ }
}
}
diff --git a/src/JT808.Protocol/MessageBody/JT808_0x8A00.cs b/src/JT808.Protocol/MessageBody/JT808_0x8A00.cs
index 2cc7739..36110ef 100644
--- a/src/JT808.Protocol/MessageBody/JT808_0x8A00.cs
+++ b/src/JT808.Protocol/MessageBody/JT808_0x8A00.cs
@@ -1,5 +1,8 @@
using JT808.Protocol.Attributes;
+using JT808.Protocol.Exceptions;
+using JT808.Protocol.Formatters;
using JT808.Protocol.Formatters.MessageBodyFormatters;
+using JT808.Protocol.MessagePack;
namespace JT808.Protocol.MessageBody
{
@@ -8,7 +11,7 @@ namespace JT808.Protocol.MessageBody
/// 0x8A00
///
[JT808Formatter(typeof(JT808_0x8A00_Formatter))]
- public class JT808_0x8A00 : JT808Bodies
+ public class JT808_0x8A00 : JT808Bodies, IJT808MessagePackFormatter
{
///
/// e
@@ -20,5 +23,23 @@ namespace JT808.Protocol.MessageBody
/// RSA 公钥{e,n}中的 n
///
public byte[] N { get; set; }
+
+ public JT808_0x8A00 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
+ {
+ JT808_0x8A00 jT808_0X8A00 = new JT808_0x8A00();
+ jT808_0X8A00.E = reader.ReadUInt32();
+ jT808_0X8A00.N = reader.ReadArray(128).ToArray();
+ return jT808_0X8A00;
+ }
+
+ public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8A00 value, IJT808Config config)
+ {
+ writer.WriteUInt32(value.E);
+ if (value.N.Length != 128)
+ {
+ throw new JT808Exception(Enums.JT808ErrorCode.NotEnoughLength, $"{nameof(value.N)}->128");
+ }
+ writer.WriteArray(value.N);
+ }
}
}