From 5321f098d0a6abbdce7a9f358b41c934a674c743 Mon Sep 17 00:00:00 2001 From: "SmallChi(Koike)" <564952747@qq.com> Date: Sat, 6 Feb 2021 22:52:30 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=AE=8C=E5=96=84=E7=BB=84=E5=8C=85=E7=9A=84?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E6=A0=A1=E9=AA=8C=202.=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E6=B6=88=E6=81=AF=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/JT808ValidationExtensions.cs | 9 +- src/JT808.Protocol/JT808.Protocol.csproj | 4 - src/JT808.Protocol/JT808.Protocol.xml | 646 ++++++++++++++++-- .../MessageBody/JT808_0x0001.cs | 27 +- .../MessageBody/JT808_0x0002.cs | 10 +- .../MessageBody/JT808_0x0003.cs | 8 +- .../MessageBody/JT808_0x0004.cs | 8 +- .../MessageBody/JT808_0x0005.cs | 26 +- .../MessageBody/JT808_0x0100.cs | 38 +- .../MessageBody/JT808_0x0102.cs | 29 +- .../MessageBody/JT808_0x0104.cs | 27 +- .../MessageBody/JT808_0x0107.cs | 42 +- .../MessageBody/JT808_0x0108.cs | 27 +- .../MessageBody/JT808_0x0200.cs | 27 +- .../MessageBody/JT808_0x0200_0x01.cs | 30 +- .../MessageBody/JT808_0x0200_0x02.cs | 30 +- .../MessageBody/JT808_0x0200_0x03.cs | 31 +- .../MessageBody/JT808_0x0200_0x04.cs | 30 +- .../MessageBody/JT808_0x0200_0x05.cs | 27 +- .../MessageBody/JT808_0x0200_0x06.cs | 27 +- .../MessageBody/JT808_0x0200_0x11.cs | 30 +- .../MessagePack/JT808MessagePackWriter.cs | 76 +-- 22 files changed, 1062 insertions(+), 147 deletions(-) diff --git a/src/JT808.Protocol/Extensions/JT808ValidationExtensions.cs b/src/JT808.Protocol/Extensions/JT808ValidationExtensions.cs index 21a1f3a..0cabe2c 100644 --- a/src/JT808.Protocol/Extensions/JT808ValidationExtensions.cs +++ b/src/JT808.Protocol/Extensions/JT808ValidationExtensions.cs @@ -18,9 +18,10 @@ namespace JT808.Protocol.Extensions /// /// /// - public static void ValiString(this string value,in string fieldName, in int fixedLength) + public static string ValiString(this string value,in string fieldName, in int fixedLength) { vali(value.Length, fieldName, fixedLength); + return value; } /// @@ -29,9 +30,10 @@ namespace JT808.Protocol.Extensions /// /// /// - public static void ValiBytes(this byte[] value,in string fieldName, in int fixedLength) + public static byte[] ValiBytes(this byte[] value,in string fieldName, in int fixedLength) { vali(value.Length, fieldName, fixedLength); + return value; } @@ -41,9 +43,10 @@ namespace JT808.Protocol.Extensions /// /// /// - public static void ValiList(this IEnumerable value, in string fieldName, in int fixedLength) + public static IEnumerable ValiList(this IEnumerable value, in string fieldName, in int fixedLength) { vali(value.Count(), fieldName, fixedLength); + return value; } /// diff --git a/src/JT808.Protocol/JT808.Protocol.csproj b/src/JT808.Protocol/JT808.Protocol.csproj index 510c3f8..7f4c55c 100644 --- a/src/JT808.Protocol/JT808.Protocol.csproj +++ b/src/JT808.Protocol/JT808.Protocol.csproj @@ -90,8 +90,4 @@ JT808PackageExtensionsTemplate.tt - - - - diff --git a/src/JT808.Protocol/JT808.Protocol.xml b/src/JT808.Protocol/JT808.Protocol.xml index e090168..e92ee6a 100644 --- a/src/JT808.Protocol/JT808.Protocol.xml +++ b/src/JT808.Protocol/JT808.Protocol.xml @@ -5077,6 +5077,16 @@ 终端通用应答 + + + 0x0001 + + + + + 终端通用应答 + + 应答流水号 @@ -5096,11 +5106,50 @@ 0:成功/确认;1:失败;2:消息有误;3:不支持 + + + + + + + + + + + + + + + + + + + + + + + + 终端心跳 + + + 跳过数据体序列化 + + + + + 0x0002 + + + + + 终端心跳 + + 终端注销请求 @@ -5111,6 +5160,16 @@ 跳过数据体序列化 + + + 0x0003 + + + + + 终端注销 + + 查询服务器时间请求 @@ -5122,12 +5181,32 @@ 跳过数据体序列化 + + + 0x0004 + + + + + 查询服务器时间请求 + + 终端补传分包请求 2019版本 + + + 0x0005 + + + + + 终端补传分包请求 + + 原始消息流水号 @@ -5147,11 +5226,45 @@ 重传包序号顺序排列,如“包 ID1 包 ID2......包 IDn”。 + + + + + + + + + + + + + + + + + + + + + + + + 终端注册 + + + 0x0100 + + + + + 终端注册 + + 省域 ID @@ -5203,11 +5316,45 @@ 否则,表示公安交通管理部门颁发的机动车号牌。 + + + + + + + + + + + + + + + + + + + + + + + + 终端鉴权 + + + 0x0102 + + + + + 终端鉴权 + + 鉴权码 @@ -5229,11 +5376,45 @@ 软件版本号 长度20 后补 "0x00" 2019版本 + + + + + + + + + + + + + + + + + + + + + + + + 查询终端参数应答 + + + 0x0104 + + + + + 查询终端参数应答 + + 应答流水号 @@ -5250,11 +5431,45 @@ 参数列表 + + + + + + + + + + + + + + + + + + + + + + + + 查询终端属性应答 + + + 0x0107 + + + + + 查询终端属性应答 + + 终端类型 @@ -5336,11 +5551,45 @@ bit7,0:不支持其他通信方式, 1:支持其他通信方式 + + + + + + + + + + + + + + + + + + + + + + + + 终端升级结果通知 + + + 0x0108 + + + + + 终端升级结果通知 + + 升级类型 @@ -5353,11 +5602,45 @@ 0:成功,1:失败,2:取消 + + + + + + + + + + + + + + + + + + + + + + + + 位置信息汇报 + + + 0x0200 + + + + + 位置信息汇报 + + 报警标志 @@ -5425,6 +5708,45 @@ 依赖平台录入的设备类型 + + + + + + + + + + + + + + + + + + + + + + + + + + + 里程 + + + + + JT808_0x0200_0x01 + + + + + 4 byte + + 里程 @@ -5435,6 +5757,35 @@ 里程 1/10km,对应车上里程表读数 + + + + + + + + + + + + + + + + + + + + + + + + + + + 油量 + + 油量 @@ -5445,6 +5796,45 @@ 油量 1/10L,对应车上油量表读数 + + + JT808_0x0200_0x02 + + + + + 2 byte + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 行驶记录功能获取的速度 + + 行驶记录功能获取的速度 @@ -5455,11 +5845,84 @@ 行驶记录功能获取的速度 1/10km/h + + + JT808_0x0200_0x03 + + + + + 2 byte + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 人工确认报警事件 + + 需要人工确认报警事件的 ID,从 1 开始计数 + + + JT808_0x0200_0x04 + + + + + 2 byte + + + + + + + + + + + + + + + + + + + + + + + + + + 胎压 @@ -5471,6 +5934,40 @@ 胎压 + + + JT808_0x0200_0x05 + + + + + 30 byte + + + + + + + + + + + + + + + + + + + + + + + + + + 胎压 @@ -5482,6 +5979,45 @@ 车厢温度 + + + JT808_0x0200_0x06 + + + + + 2 byte + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 超速报警附加信息 + + 超速报警附加信息 @@ -5498,6 +6034,40 @@ 若位置类型为 0,无该字段 + + + JT808_0x0200_0x11 + + + + + 1或5 byte + + + + + + + + + + + + + + + + + + + + + + + + + + 位置类型 @@ -8924,14 +9494,14 @@ - + 跳过多少字节数 跳过前的内存位置 - + 跳过多少字节数 @@ -8939,116 +9509,116 @@ 跳过前的内存位置 用什么数值填充跳过的内存块 - + 写入一个字符 - + 写入一个字节 - + 写入两个字节的有符号数值类型 - + 写入两个字节的无符号数值类型 - + 写入四个字节的有符号数值类型 - + 写入四个字节的无符号数值类型 - + 写入八个字节的无符号数值类型 - + 写入八个字节的有符号数值类型 - + 写入字符串 - + 写入数组 - + 根据内存定位,反写两个字节的无符号数值类型 - + 根据内存定位,反写两个字节的有符号数值类型 - + 根据内存定位,反写四个字节的有符号数值类型 - + 根据内存定位,反写四个字节的无符号数值类型 - + 根据内存定位,反写八个字节的有符号数值类型 - + 根据内存定位,反写八个字节的无符号数值类型 - + 根据内存定位,反写1个字节的数值类型 - + 根据内存定位,反写BCD编码数据 @@ -9056,90 +9626,90 @@ - + 根据内存定位,反写一串字符串数据 - + 根据内存定位,反写一组数组数据 - + 写入六个字节的日期类型,yyMMddHHmmss - + 写入六个字节的可空日期类型,yyMMddHHmmss - + 写入五个字节的日期类型,HH-mm-ss-msms或HH-mm-ss-fff - + 写入五个字节的可空日期类型,HH-mm-ss-msms或HH-mm-ss-fff - + 写入UTC日期类型 - + 写入四个字节的日期类型,YYYYMMDD BCD[4] 数据形如:20200101 - + 写入四个字节的可空日期类型,YYYYMMDD BCD[4]数据形如:20200101 - + 写入三个字节的日期类型,YYMMDD 数据形如:20200101 - + 写入三个字节的可空日期类型,YYMMDD 数据形如:20200101 - + 将指定内存块进行或运算并写入一个字节 - + 将指定内存块进行或运算并写入一个字节 @@ -9150,21 +9720,21 @@ 将内存块进行或运算并写入一个字节 - + 写入BCD编码数据 - + 写入Hex编码数据 - + 写入ASCII编码数据 @@ -9180,7 +9750,7 @@ 将内存块进行808转义处理 - + 写入数值类型,数字编码 大端模式、高位在前 @@ -9199,7 +9769,7 @@ - + 写入JT19056校验码 diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0001.cs b/src/JT808.Protocol/MessageBody/JT808_0x0001.cs index a6741b6..6f9ca7a 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0001.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0001.cs @@ -12,7 +12,13 @@ namespace JT808.Protocol.MessageBody /// public class JT808_0x0001 : JT808Bodies,IJT808MessagePackFormatter, IJT808Analyze { + /// + /// 0x0001 + /// public override ushort MsgId => 0x0001; + /// + /// 终端通用应答 + /// public override string Description => "终端通用应答"; /// /// 应答流水号 @@ -31,7 +37,12 @@ namespace JT808.Protocol.MessageBody /// 0:成功/确认;1:失败;2:消息有误;3:不支持 /// public JT808TerminalResult TerminalResult { get; set; } - + /// + /// + /// + /// + /// + /// public JT808_0x0001 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0001 jT808_0X0001 = new JT808_0x0001(); @@ -40,14 +51,24 @@ namespace JT808.Protocol.MessageBody jT808_0X0001.TerminalResult = (JT808TerminalResult)reader.ReadByte(); return jT808_0X0001; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0001 value, IJT808Config config) { writer.WriteUInt16(value.ReplyMsgNum); writer.WriteUInt16(value.ReplyMsgId); writer.WriteByte((byte)value.TerminalResult); } - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { var replyMsgNum = reader.ReadUInt16(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0002.cs b/src/JT808.Protocol/MessageBody/JT808_0x0002.cs index 1460fb4..dbfaac3 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0002.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0002.cs @@ -5,9 +5,17 @@ /// public class JT808_0x0002 : JT808Bodies { + /// + /// 跳过数据体序列化 + /// public override bool SkipSerialization { get; set; } = true; + /// + /// 0x0002 + /// public override ushort MsgId { get; } = 0x0002; - + /// + /// 终端心跳 + /// public override string Description => "终端心跳"; } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0003.cs b/src/JT808.Protocol/MessageBody/JT808_0x0003.cs index 79f0419..09bde20 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0003.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0003.cs @@ -9,9 +9,13 @@ /// 跳过数据体序列化 /// public override bool SkipSerialization { get; set; } = true; - + /// + /// 0x0003 + /// public override ushort MsgId { get; } = 0x0003; - + /// + /// 终端注销 + /// public override string Description => "终端注销"; } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0004.cs b/src/JT808.Protocol/MessageBody/JT808_0x0004.cs index 444947a..d86fd98 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0004.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0004.cs @@ -12,9 +12,13 @@ namespace JT808.Protocol.MessageBody /// 跳过数据体序列化 /// public override bool SkipSerialization { get; set; } = true; - + /// + /// 0x0004 + /// public override ushort MsgId { get; } = 0x0004; - + /// + /// 查询服务器时间请求 + /// public override string Description => "查询服务器时间请求"; } } diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0005.cs b/src/JT808.Protocol/MessageBody/JT808_0x0005.cs index 4e3653f..e8519db 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0005.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0005.cs @@ -13,7 +13,13 @@ namespace JT808.Protocol.MessageBody /// public class JT808_0x0005 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version, IJT808Analyze { + /// + /// 0x0005 + /// public override ushort MsgId { get; } = 0x0005; + /// + /// 终端补传分包请求 + /// public override string Description => "终端补传分包请求"; /// /// 原始消息流水号 @@ -31,7 +37,12 @@ namespace JT808.Protocol.MessageBody /// 重传包序号顺序排列,如“包 ID1 包 ID2......包 IDn”。 /// public byte[] AgainPackageData { get; set; } - + /// + /// + /// + /// + /// + /// public JT808_0x0005 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0005 value = new JT808_0x0005(); @@ -47,6 +58,12 @@ namespace JT808.Protocol.MessageBody value.AgainPackageData = reader.ReadArray(value.AgainPackageCount * 2).ToArray(); return value; } + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0005 value, IJT808Config config) { writer.WriteUInt16(value.OriginalMsgNum); @@ -60,7 +77,12 @@ namespace JT808.Protocol.MessageBody } writer.WriteArray(value.AgainPackageData); } - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { var originalMsgNum = reader.ReadUInt16(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0100.cs b/src/JT808.Protocol/MessageBody/JT808_0x0100.cs index 6a69c26..e408814 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0100.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0100.cs @@ -14,7 +14,13 @@ namespace JT808.Protocol.MessageBody /// public class JT808_0x0100 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version,IJT808Analyze { + /// + /// 0x0100 + /// public override ushort MsgId { get; } = 0x0100; + /// + /// 终端注册 + /// public override string Description => "终端注册"; /// /// 省域 ID @@ -66,7 +72,12 @@ 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(); @@ -88,26 +99,37 @@ namespace JT808.Protocol.MessageBody 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); if (writer.Version == JT808Version.JTT2019) { - writer.WriteString(value.MakerId.PadLeft(11, '0')); - writer.WriteString(value.TerminalModel.PadLeft(30, '0')); - writer.WriteString(value.TerminalId.PadLeft(30, '0')); + writer.WriteString(value.MakerId.PadLeft(11, '0').ValiString(nameof(value.MakerId),11)); + writer.WriteString(value.TerminalModel.PadLeft(30, '0').ValiString(nameof(value.TerminalModel), 30)); + writer.WriteString(value.TerminalId.PadLeft(30, '0').ValiString(nameof(value.TerminalId), 30)); } else { - writer.WriteString(value.MakerId.PadRight(5, '0')); - writer.WriteString(value.TerminalModel.PadRight(20, '0')); - writer.WriteString(value.TerminalId.PadRight(7, '0')); + writer.WriteString(value.MakerId.PadRight(5, '0').ValiString(nameof(value.MakerId), 5)); + writer.WriteString(value.TerminalModel.PadRight(20, '0').ValiString(nameof(value.TerminalModel), 20)); + writer.WriteString(value.TerminalId.PadRight(7, '0').ValiString(nameof(value.TerminalId), 7)); } writer.WriteByte(value.PlateColor); writer.WriteString(value.PlateNo); } + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0100 jT808_0X0100 = new JT808_0x0100(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0102.cs b/src/JT808.Protocol/MessageBody/JT808_0x0102.cs index 15bf90e..081de45 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0102.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0102.cs @@ -13,7 +13,13 @@ namespace JT808.Protocol.MessageBody /// public class JT808_0x0102 : JT808Bodies, IJT808MessagePackFormatter, IJT808_2019_Version, IJT808Analyze { + /// + /// 0x0102 + /// public override ushort MsgId { get; } = 0x0102; + /// + /// 终端鉴权 + /// public override string Description => "终端鉴权"; /// /// 鉴权码 @@ -32,7 +38,12 @@ namespace JT808.Protocol.MessageBody /// 软件版本号 长度20 后补 "0x00" 2019版本 /// public string SoftwareVersion { get; set; } - + /// + /// + /// + /// + /// + /// public JT808_0x0102 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0102 jT808_0X0102 = new JT808_0x0102(); @@ -50,7 +61,12 @@ namespace JT808.Protocol.MessageBody return jT808_0X0102; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0102 value, IJT808Config config) { if (writer.Version == JT808Version.JTT2019) @@ -59,14 +75,19 @@ namespace JT808.Protocol.MessageBody writer.WriteString(value.Code); writer.WriteByteReturn((byte)(writer.GetCurrentPosition() - CodeLengthPosition - 1), CodeLengthPosition); writer.WriteString(value.IMEI); - writer.WriteString(value.SoftwareVersion.PadRight(20,'0')); + writer.WriteString(value.SoftwareVersion.PadRight(20,'0').ValiString(nameof(value.SoftwareVersion),20)); } else { writer.WriteString(value.Code); } } - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0102 jT808_0X0102 = new JT808_0x0102(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0104.cs b/src/JT808.Protocol/MessageBody/JT808_0x0104.cs index 10bbcd2..e44803c 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0104.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0104.cs @@ -14,7 +14,13 @@ namespace JT808.Protocol.MessageBody /// public class JT808_0x0104 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { + /// + /// 0x0104 + /// public override ushort MsgId { get; } = 0x0104; + /// + /// 查询终端参数应答 + /// public override string Description => "查询终端参数应答"; /// /// 应答流水号 @@ -29,7 +35,12 @@ 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(); @@ -52,7 +63,12 @@ namespace JT808.Protocol.MessageBody } return jT808_0x0104; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0104 value, IJT808Config config) { writer.WriteUInt16(value.MsgNum); @@ -63,7 +79,12 @@ namespace JT808.Protocol.MessageBody JT808MessagePackFormatterResolverExtensions.JT808DynamicSerialize(obj, ref writer, item, config); } } - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0104 jT808_0x0104 = new JT808_0x0104(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0107.cs b/src/JT808.Protocol/MessageBody/JT808_0x0107.cs index 66ed640..a45a05a 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0107.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0107.cs @@ -15,8 +15,13 @@ namespace JT808.Protocol.MessageBody /// public class JT808_0x0107 : JT808Bodies,IJT808MessagePackFormatter, IJT808_2019_Version,IJT808Analyze { + /// + /// 0x0107 + /// public override ushort MsgId { get; } = 0x0107; - + /// + /// 查询终端属性应答 + /// public override string Description => "查询终端属性应答"; /// /// 终端类型 @@ -88,7 +93,12 @@ 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(); @@ -114,23 +124,28 @@ namespace JT808.Protocol.MessageBody jT808_0X0107.CommunicationModule = reader.ReadByte(); return jT808_0X0107; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0107 value, IJT808Config config) { writer.WriteUInt16(value.TerminalType); if (writer.Version == JT808Version.JTT2019) { - writer.WriteString(value.MakerId.PadLeft(11, '0')); - writer.WriteString(value.TerminalModel.PadLeft(30, '0')); - writer.WriteString(value.TerminalId.PadLeft(30, '0')); + writer.WriteString(value.MakerId.PadLeft(11, '0').ValiString(nameof(value.MakerId),11)); + writer.WriteString(value.TerminalModel.PadLeft(30, '0').ValiString(nameof(value.TerminalModel), 30)); + writer.WriteString(value.TerminalId.PadLeft(30, '0').ValiString(nameof(value.TerminalId), 30)); } else { - writer.WriteString(value.MakerId.PadRight(5, '0')); - writer.WriteString(value.TerminalModel.PadRight(20, '0')); - writer.WriteString(value.TerminalId.PadRight(7, '0')); + writer.WriteString(value.MakerId.PadRight(5, '0').ValiString(nameof(value.MakerId), 5)); + writer.WriteString(value.TerminalModel.PadRight(20, '0').ValiString(nameof(value.TerminalModel), 20)); + writer.WriteString(value.TerminalId.PadRight(7, '0').ValiString(nameof(value.TerminalId), 7)); } - writer.WriteBCD(value.Terminal_SIM_ICCID, 20); + writer.WriteBCD(value.Terminal_SIM_ICCID.ValiString(nameof(value.Terminal_SIM_ICCID), 20), 20); 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); @@ -138,7 +153,12 @@ namespace JT808.Protocol.MessageBody writer.WriteByte(value.GNSSModule); writer.WriteByte(value.CommunicationModule); } - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0107 jT808_0X0107 = new JT808_0x0107(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0108.cs b/src/JT808.Protocol/MessageBody/JT808_0x0108.cs index 49ea819..9cb94a1 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0108.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0108.cs @@ -12,7 +12,13 @@ namespace JT808.Protocol.MessageBody /// public class JT808_0x0108 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { + /// + /// 0x0108 + /// public override ushort MsgId { get; } = 0x0108; + /// + /// 终端升级结果通知 + /// public override string Description => "终端升级结果通知"; /// /// 升级类型 @@ -25,7 +31,12 @@ 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(); @@ -33,13 +44,23 @@ namespace JT808.Protocol.MessageBody 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); } - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0108 jT808_0X0108 = new JT808_0x0108(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200.cs index 5d69a1a..cac7adb 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200.cs @@ -16,7 +16,13 @@ namespace JT808.Protocol.MessageBody /// public class JT808_0x0200 : JT808Bodies, IJT808MessagePackFormatter, IJT808Analyze { + /// + /// 0x0200 + /// public override ushort MsgId { get; } = 0x0200; + /// + /// 位置信息汇报 + /// public override string Description => "位置信息汇报"; /// /// 报警标志 @@ -74,7 +80,12 @@ 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(); @@ -145,7 +156,12 @@ namespace JT808.Protocol.MessageBody } return jT808_0X0200; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200 value, IJT808Config config) { writer.WriteUInt32(value.AlarmFlag); @@ -205,7 +221,12 @@ namespace JT808.Protocol.MessageBody } } } - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0200 value = new JT808_0x0200(); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs index 8f8543e..eee4c3c 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x01.cs @@ -7,9 +7,18 @@ using System.Text.Json; namespace JT808.Protocol.MessageBody { + /// + /// 里程 + /// public class JT808_0x0200_0x01 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { + /// + /// JT808_0x0200_0x01 + /// public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x01; + /// + /// 4 byte + /// public override byte AttachInfoLength { get; set; } = 4; /// /// 里程 @@ -20,7 +29,12 @@ namespace JT808.Protocol.MessageBody /// [IgnoreDataMember] public double ConvertMileage => Mileage / 10.0; - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0200_0x01 value = new JT808_0x0200_0x01(); @@ -31,7 +45,12 @@ namespace JT808.Protocol.MessageBody value.Mileage = reader.ReadInt32(); writer.WriteNumber($"[{value.Mileage.ReadNumber()}]里程", value.Mileage); } - + /// + /// + /// + /// + /// + /// public JT808_0x0200_0x01 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0200_0x01 value = new JT808_0x0200_0x01(); @@ -40,7 +59,12 @@ namespace JT808.Protocol.MessageBody value.Mileage = reader.ReadInt32(); return value; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x01 value, IJT808Config config) { writer.WriteByte(value.AttachInfoId); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs index c65ac20..9ab21bf 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x02.cs @@ -7,6 +7,9 @@ using System.Text.Json; namespace JT808.Protocol.MessageBody { + /// + /// 油量 + /// public class JT808_0x0200_0x02 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// @@ -18,9 +21,20 @@ namespace JT808.Protocol.MessageBody /// [IgnoreDataMember] public double ConvertOil => Oil / 10.0; + /// + /// JT808_0x0200_0x02 + /// public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x02; + /// + /// 2 byte + /// public override byte AttachInfoLength { get; set; } = 2; - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0200_0x02 value = new JT808_0x0200_0x02(); @@ -31,7 +45,12 @@ namespace JT808.Protocol.MessageBody value.Oil = reader.ReadUInt16(); writer.WriteNumber($"[{value.Oil.ReadNumber()}]油量", value.Oil); } - + /// + /// + /// + /// + /// + /// public JT808_0x0200_0x02 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0200_0x02 value = new JT808_0x0200_0x02(); @@ -40,7 +59,12 @@ namespace JT808.Protocol.MessageBody value.Oil = reader.ReadUInt16(); return value; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x02 value, IJT808Config config) { writer.WriteByte(value.AttachInfoId); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs index b4bc4ef..9b2e6aa 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x03.cs @@ -7,7 +7,9 @@ using System.Text.Json; namespace JT808.Protocol.MessageBody { - + /// + /// 行驶记录功能获取的速度 + /// public class JT808_0x0200_0x03 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// @@ -19,9 +21,20 @@ namespace JT808.Protocol.MessageBody /// [IgnoreDataMember] public double ConvertSpeed => Speed / 10.0; + /// + /// JT808_0x0200_0x03 + /// public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x03; + /// + /// 2 byte + /// public override byte AttachInfoLength { get; set; } = 2; - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0200_0x03 value = new JT808_0x0200_0x03(); @@ -32,7 +45,12 @@ namespace JT808.Protocol.MessageBody value.Speed = reader.ReadUInt16(); writer.WriteNumber($"[{value.Speed.ReadNumber()}]速度", value.Speed); } - + /// + /// + /// + /// + /// + /// public JT808_0x0200_0x03 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0200_0x03 value = new JT808_0x0200_0x03(); @@ -41,7 +59,12 @@ namespace JT808.Protocol.MessageBody value.Speed = reader.ReadUInt16(); return value; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x03 value, IJT808Config config) { writer.WriteByte(value.AttachInfoId); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs index c5575bd..d251131 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x04.cs @@ -7,15 +7,29 @@ using System.Text.Json; namespace JT808.Protocol.MessageBody { + /// + /// 人工确认报警事件 + /// public class JT808_0x0200_0x04 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// /// 需要人工确认报警事件的 ID,从 1 开始计数 /// public ushort EventId { get; set; } + /// + /// JT808_0x0200_0x04 + /// public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x04; + /// + /// 2 byte + /// public override byte AttachInfoLength { get; set; } = 2; - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0200_0x04 value = new JT808_0x0200_0x04(); @@ -26,7 +40,12 @@ namespace JT808.Protocol.MessageBody value.EventId = reader.ReadUInt16(); writer.WriteNumber($"[{value.EventId.ReadNumber()}]报警事件ID", value.EventId); } - + /// + /// + /// + /// + /// + /// public JT808_0x0200_0x04 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0200_0x04 value = new JT808_0x0200_0x04(); @@ -35,7 +54,12 @@ namespace JT808.Protocol.MessageBody value.EventId = reader.ReadUInt16(); return value; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x04 value, IJT808Config config) { writer.WriteByte(value.AttachInfoId); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x05.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x05.cs index a06e8dc..ccd07b5 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x05.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x05.cs @@ -17,9 +17,20 @@ namespace JT808.Protocol.MessageBody /// 胎压 /// public byte[] TirePressure { get; set; } + /// + /// JT808_0x0200_0x05 + /// public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x05; + /// + /// 30 byte + /// public override byte AttachInfoLength { get; set; } = 30; - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0200_0x05 value = new JT808_0x0200_0x05(); @@ -30,7 +41,12 @@ namespace JT808.Protocol.MessageBody value.TirePressure = reader.ReadArray(value.AttachInfoLength).ToArray(); writer.WriteString($"胎压", value.TirePressure.ToHexString()); } - + /// + /// + /// + /// + /// + /// public JT808_0x0200_0x05 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0200_0x05 value = new JT808_0x0200_0x05(); @@ -39,7 +55,12 @@ namespace JT808.Protocol.MessageBody value.TirePressure = reader.ReadArray(value.AttachInfoLength).ToArray(); return value; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x05 value, IJT808Config config) { writer.WriteByte(value.AttachInfoId); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x06.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x06.cs index 789d3a4..4bc7905 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x06.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x06.cs @@ -17,9 +17,20 @@ namespace JT808.Protocol.MessageBody /// 车厢温度 /// public short CarTemperature { get; set; } + /// + /// JT808_0x0200_0x06 + /// public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x06; + /// + /// 2 byte + /// public override byte AttachInfoLength { get; set; } = 2; - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0200_0x06 value = new JT808_0x0200_0x06(); @@ -30,7 +41,12 @@ namespace JT808.Protocol.MessageBody value.CarTemperature = reader.ReadInt16(); writer.WriteNumber($"[{value.CarTemperature.ReadNumber()}]车厢温度", value.CarTemperature); } - + /// + /// + /// + /// + /// + /// public JT808_0x0200_0x06 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0200_0x06 value = new JT808_0x0200_0x06(); @@ -39,7 +55,12 @@ namespace JT808.Protocol.MessageBody value.CarTemperature =reader.ReadInt16(); return value; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x06 value, IJT808Config config) { writer.WriteByte(value.AttachInfoId); diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs index a043b85..829f552 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x11.cs @@ -7,6 +7,9 @@ using System.Text.Json; namespace JT808.Protocol.MessageBody { + /// + /// 超速报警附加信息 + /// public class JT808_0x0200_0x11 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { /// @@ -24,7 +27,13 @@ namespace JT808.Protocol.MessageBody /// 若位置类型为 0,无该字段 /// public uint AreaId { get; set; } + /// + /// JT808_0x0200_0x11 + /// public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x11; + /// + /// 1或5 byte + /// public override byte AttachInfoLength { get @@ -40,7 +49,12 @@ namespace JT808.Protocol.MessageBody } set { } } - + /// + /// + /// + /// + /// + /// public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0200_0x11 value = new JT808_0x0200_0x11(); @@ -56,7 +70,12 @@ namespace JT808.Protocol.MessageBody writer.WriteNumber($"[{value.AreaId.ReadNumber()}]区域或路段ID", value.AreaId); } } - + /// + /// + /// + /// + /// + /// public JT808_0x0200_0x11 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { JT808_0x0200_0x11 value = new JT808_0x0200_0x11(); @@ -69,7 +88,12 @@ namespace JT808.Protocol.MessageBody } return value; } - + /// + /// + /// + /// + /// + /// public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x11 value, IJT808Config config) { writer.WriteByte(value.AttachInfoId); diff --git a/src/JT808.Protocol/MessagePack/JT808MessagePackWriter.cs b/src/JT808.Protocol/MessagePack/JT808MessagePackWriter.cs index dfb7d81..c66eef8 100644 --- a/src/JT808.Protocol/MessagePack/JT808MessagePackWriter.cs +++ b/src/JT808.Protocol/MessagePack/JT808MessagePackWriter.cs @@ -83,7 +83,7 @@ namespace JT808.Protocol.MessagePack /// /// /// 跳过前的内存位置 - public void Skip(int count, out int position) + public void Skip(in int count, out int position) { position = writer.WrittenCount; var span = writer.Free; @@ -99,7 +99,7 @@ namespace JT808.Protocol.MessagePack /// /// 跳过前的内存位置 /// 用什么数值填充跳过的内存块 - public void Skip(int count,out int position, byte fullValue = 0x00) + public void Skip(in int count,out int position, in byte fullValue = 0x00) { position = writer.WrittenCount; var span = writer.Free; @@ -113,7 +113,7 @@ namespace JT808.Protocol.MessagePack /// 写入一个字符 /// /// - public void WriteChar(char value) + public void WriteChar(in char value) { var span = writer.Free; span[0] = (byte)value; @@ -123,7 +123,7 @@ namespace JT808.Protocol.MessagePack /// 写入一个字节 /// /// - public void WriteByte(byte value) + public void WriteByte(in byte value) { var span = writer.Free; span[0] = value; @@ -133,7 +133,7 @@ namespace JT808.Protocol.MessagePack /// 写入两个字节的有符号数值类型 /// /// - public void WriteInt16(short value) + public void WriteInt16(in short value) { BinaryPrimitives.WriteInt16BigEndian(writer.Free, value); writer.Advance(2); @@ -142,7 +142,7 @@ namespace JT808.Protocol.MessagePack /// 写入两个字节的无符号数值类型 /// /// - public void WriteUInt16(ushort value) + public void WriteUInt16(in ushort value) { BinaryPrimitives.WriteUInt16BigEndian(writer.Free, value); writer.Advance(2); @@ -151,7 +151,7 @@ namespace JT808.Protocol.MessagePack /// 写入四个字节的有符号数值类型 /// /// - public void WriteInt32(int value) + public void WriteInt32(in int value) { BinaryPrimitives.WriteInt32BigEndian(writer.Free, value); writer.Advance(4); @@ -160,7 +160,7 @@ namespace JT808.Protocol.MessagePack /// 写入四个字节的无符号数值类型 /// /// - public void WriteUInt32(uint value) + public void WriteUInt32(in uint value) { BinaryPrimitives.WriteUInt32BigEndian(writer.Free, value); writer.Advance(4); @@ -169,7 +169,7 @@ namespace JT808.Protocol.MessagePack /// 写入八个字节的无符号数值类型 /// /// - public void WriteUInt64(ulong value) + public void WriteUInt64(in ulong value) { BinaryPrimitives.WriteUInt64BigEndian(writer.Free, value); writer.Advance(8); @@ -178,7 +178,7 @@ namespace JT808.Protocol.MessagePack /// 写入八个字节的有符号数值类型 /// /// - public void WriteInt64(long value) + public void WriteInt64(in long value) { BinaryPrimitives.WriteInt64BigEndian(writer.Free, value); writer.Advance(8); @@ -187,7 +187,7 @@ namespace JT808.Protocol.MessagePack /// 写入字符串 /// /// - public void WriteString(string value) + public void WriteString(in string value) { byte[] codeBytes = JT808Constants.Encoding.GetBytes(value); codeBytes.CopyTo(writer.Free); @@ -197,7 +197,7 @@ namespace JT808.Protocol.MessagePack /// 写入数组 /// /// - public void WriteArray(ReadOnlySpan src) + public void WriteArray(in ReadOnlySpan src) { src.CopyTo(writer.Free); writer.Advance(src.Length); @@ -207,7 +207,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteUInt16Return(ushort value, int position) + public void WriteUInt16Return(in ushort value, in int position) { BinaryPrimitives.WriteUInt16BigEndian(writer.Written.Slice(position, 2), value); } @@ -216,7 +216,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteInt16Return(short value, int position) + public void WriteInt16Return(in short value, in int position) { BinaryPrimitives.WriteInt16BigEndian(writer.Written.Slice(position, 2), value); } @@ -225,7 +225,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteInt32Return(int value, int position) + public void WriteInt32Return(in int value, in int position) { BinaryPrimitives.WriteInt32BigEndian(writer.Written.Slice(position, 4), value); } @@ -234,7 +234,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteUInt32Return(uint value, int position) + public void WriteUInt32Return(in uint value, in int position) { BinaryPrimitives.WriteUInt32BigEndian(writer.Written.Slice(position, 4), value); } @@ -244,7 +244,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteInt64Return(long value, int position) + public void WriteInt64Return(in long value, in int position) { BinaryPrimitives.WriteInt64BigEndian(writer.Written.Slice(position, 8), value); } @@ -253,7 +253,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteUInt64Return(ulong value, int position) + public void WriteUInt64Return(in ulong value, in int position) { BinaryPrimitives.WriteUInt64BigEndian(writer.Written.Slice(position, 8), value); } @@ -262,7 +262,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteByteReturn(byte value, int position) + public void WriteByteReturn(in byte value, in int position) { writer.Written[position] = value; } @@ -272,7 +272,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteBCDReturn(string value,int len, int position) + public void WriteBCDReturn(in string value, in int len, in int position) { string bcdText = value ?? ""; int startIndex = 0; @@ -295,7 +295,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteStringReturn(string value, int position) + public void WriteStringReturn(in string value, in int position) { Span codeBytes = JT808Constants.Encoding.GetBytes(value); codeBytes.CopyTo(writer.Written.Slice(position)); @@ -305,7 +305,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteArrayReturn(ReadOnlySpan src, int position) + public void WriteArrayReturn(in ReadOnlySpan src, in int position) { src.CopyTo(writer.Written.Slice(position)); } @@ -314,7 +314,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteDateTime6(DateTime value, int fromBase = 16) + public void WriteDateTime6(in DateTime value, in int fromBase = 16) { var span = writer.Free; span[0] = Convert.ToByte(value.ToString("yy"), fromBase); @@ -330,7 +330,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteDateTime6(DateTime? value, int fromBase = 16) + public void WriteDateTime6(in DateTime? value, in int fromBase = 16) { var span = writer.Free; if (value == null || value.HasValue) @@ -358,7 +358,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteDateTime5(DateTime value, int fromBase = 16) + public void WriteDateTime5(in DateTime value, in int fromBase = 16) { var span = writer.Free; span[0] = Convert.ToByte(value.ToString("HH"), fromBase); @@ -374,7 +374,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteDateTime5(DateTime? value, int fromBase = 16) + public void WriteDateTime5(in DateTime? value, in int fromBase = 16) { var span = writer.Free; if (value == null || value.HasValue) @@ -400,7 +400,7 @@ namespace JT808.Protocol.MessagePack /// 写入UTC日期类型 /// /// - public void WriteUTCDateTime(DateTime value) + public void WriteUTCDateTime(in DateTime value) { ulong totalSecends = (ulong)(value.AddHours(-8) - JT808Constants.UTCBaseTime).TotalSeconds; var span = writer.Free; @@ -417,7 +417,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteDateTime4(DateTime value, int fromBase = 16) + public void WriteDateTime4(in DateTime value, in int fromBase = 16) { var span = writer.Free; var yearSpan=value.ToString("yyyy").AsSpan(); @@ -433,7 +433,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteDateTime4(DateTime? value, int fromBase = 16) + public void WriteDateTime4(in DateTime? value, in int fromBase = 16) { var span = writer.Free; if (value==null || value.HasValue) @@ -459,7 +459,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteDateTime3(DateTime value, int fromBase = 16) + public void WriteDateTime3(in DateTime value, in int fromBase = 16) { var span = writer.Free; span[0] = Convert.ToByte(value.ToString("yy"), fromBase); @@ -473,7 +473,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteDateTime3(DateTime? value, int fromBase = 16) + public void WriteDateTime3(in DateTime? value, in int fromBase = 16) { var span = writer.Free; if (value == null || value.HasValue) @@ -495,7 +495,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteXor(int start, int end) + public void WriteXor(in int start, in int end) { if (start > end) { @@ -515,7 +515,7 @@ namespace JT808.Protocol.MessagePack /// 将指定内存块进行或运算并写入一个字节 /// /// - public void WriteXor(int start) + public void WriteXor(in int start) { if(writer.WrittenCount< start) { @@ -556,7 +556,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteBCD(string value, int len) + public void WriteBCD(in string value, in int len) { string bcdText = value ?? ""; int startIndex = 0; @@ -581,7 +581,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteHex(string value, int len) + public void WriteHex(string value, in int len) { value = value ?? ""; value = value.Replace(" ", ""); @@ -614,7 +614,7 @@ namespace JT808.Protocol.MessagePack /// 写入ASCII编码数据 /// /// - public void WriteASCII(string value) + public void WriteASCII(in string value) { var spanFree = writer.Free; var bytes = Encoding.ASCII.GetBytes(value).AsSpan(); @@ -684,7 +684,7 @@ namespace JT808.Protocol.MessagePack /// /// /// - public void WriteBigNumber(string value, int len) + public void WriteBigNumber(in string value, int len) { var spanFree = writer.Free; ulong number = string.IsNullOrEmpty(value) ? 0 : (ulong)double.Parse(value); @@ -716,7 +716,7 @@ namespace JT808.Protocol.MessagePack /// 写入JT19056校验码 /// /// - public void WriteCarDVRCheckCode(int currentPosition) + public void WriteCarDVRCheckCode(in int currentPosition) { var carDVRPackage = writer.Written.Slice(currentPosition, writer.WrittenCount- currentPosition); byte calculateXorCheckCode = 0;