diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/JT808.Protocol.Extensions.SuBiao.xml b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/JT808.Protocol.Extensions.SuBiao.xml index 0cc9ee1..34e794a 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/JT808.Protocol.Extensions.SuBiao.xml +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/JT808.Protocol.Extensions.SuBiao.xml @@ -314,6 +314,9 @@ 高级驾驶辅助系统报警信息Id + + + 高级驾驶辅助系统报警信息附加长度 @@ -435,6 +438,9 @@ 驾驶员状态监测系统报警信息Id + + + 驾驶员状态监测系统报警信息长度 @@ -541,6 +547,9 @@ 胎压监测系统报警信息Id + + + 胎压监测系统报警信息长度 @@ -637,6 +646,9 @@ 盲区监测系统报警信息Id + + + 盲区监测系统报警信息长度 diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x64.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x64.cs index 15902e0..bdfef06 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x64.cs +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x64.cs @@ -1,24 +1,26 @@ -using JT808.Protocol.Extensions.SuBiao.Metadata; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.SuBiao.Metadata; using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; -using System; -using System.Collections.Generic; -using System.Text; -using System.Text.Json; namespace JT808.Protocol.Extensions.SuBiao.MessageBody { /// /// 高级驾驶辅助系统报警信息 /// - public class JT808_0x0200_0x64 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + public class JT808_0x0200_0x64 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, JT808_0x8900_BodyBase, IJT808Analyze { /// /// 高级驾驶辅助系统报警信息Id /// public byte AttachInfoId { get; set; } = JT808_SuBiao_Constants.JT808_0X0200_0x64; + /// + public byte PassthroughType { get; set; } = JT808_SuBiao_Constants.JT808_0X0200_0x64; /// /// 高级驾驶辅助系统报警信息附加长度 /// @@ -34,7 +36,7 @@ namespace JT808.Protocol.Extensions.SuBiao.MessageBody /// /// 报警/事件类型 /// - public byte AlarmOrEventType{ get; set; } + public byte AlarmOrEventType { get; set; } /// /// 报警/事件类型 /// @@ -89,6 +91,7 @@ namespace JT808.Protocol.Extensions.SuBiao.MessageBody /// 报警标识号 /// public AlarmIdentificationProperty AlarmIdentification { get; set; } + /// /// /// @@ -277,7 +280,7 @@ namespace JT808.Protocol.Extensions.SuBiao.MessageBody /// /// public override JT808_0x0200_0x64 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) - { + { JT808_0x0200_0x64 value = new JT808_0x0200_0x64(); value.AttachInfoId = reader.ReadByte(); value.AttachInfoLength = reader.ReadByte(); @@ -331,7 +334,8 @@ namespace JT808.Protocol.Extensions.SuBiao.MessageBody writer.WriteUInt32((uint)value.Longitude); writer.WriteDateTime_yyMMddHHmmss(value.AlarmTime); writer.WriteUInt16(value.VehicleState); - if (value.AlarmIdentification == null) { + if (value.AlarmIdentification == null) + { throw new NullReferenceException($"{nameof(AlarmIdentificationProperty)}不为空"); } writer.WriteString(value.AlarmIdentification.TerminalID); diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x65.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x65.cs index dc7c51f..39af6cc 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x65.cs +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x65.cs @@ -1,24 +1,26 @@ -using JT808.Protocol.Extensions.SuBiao.Metadata; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.SuBiao.Metadata; using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; -using System; -using System.Collections.Generic; -using System.Text; -using System.Text.Json; namespace JT808.Protocol.Extensions.SuBiao.MessageBody { /// /// 驾驶员状态监测系统报警信息 /// - public class JT808_0x0200_0x65 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + public class JT808_0x0200_0x65 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, JT808_0x8900_BodyBase, IJT808Analyze { /// /// 驾驶员状态监测系统报警信息Id /// public byte AttachInfoId { get; set; } = JT808_SuBiao_Constants.JT808_0X0200_0x65; + /// + public byte PassthroughType { get; set; } = JT808_SuBiao_Constants.JT808_0X0200_0x65; /// /// 驾驶员状态监测系统报警信息长度 /// @@ -34,7 +36,7 @@ namespace JT808.Protocol.Extensions.SuBiao.MessageBody /// /// 报警/事件类型 /// - public byte AlarmOrEventType{ get; set; } + public byte AlarmOrEventType { get; set; } /// /// 报警级别 /// @@ -86,7 +88,7 @@ namespace JT808.Protocol.Extensions.SuBiao.MessageBody public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) { JT808_0x0200_0x65 value = new JT808_0x0200_0x65(); - value.AttachInfoId = reader.ReadByte(); + value.AttachInfoId = reader.ReadByte(); writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); value.AttachInfoLength = reader.ReadByte(); writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x66.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x66.cs index c617ea0..a48c875 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x66.cs +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x66.cs @@ -1,24 +1,26 @@ -using JT808.Protocol.Extensions.SuBiao.Metadata; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.SuBiao.Metadata; using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; -using System; -using System.Collections.Generic; -using System.Text; -using System.Text.Json; namespace JT808.Protocol.Extensions.SuBiao.MessageBody { /// /// 胎压监测系统报警信息 /// - public class JT808_0x0200_0x66 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + public class JT808_0x0200_0x66 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, JT808_0x8900_BodyBase, IJT808Analyze { /// /// 胎压监测系统报警信息Id /// public byte AttachInfoId { get; set; } = JT808_SuBiao_Constants.JT808_0X0200_0x66; + /// + public byte PassthroughType { get; set; } = JT808_SuBiao_Constants.JT808_0X0200_0x66; /// /// 胎压监测系统报警信息长度 /// diff --git a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x67.cs b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x67.cs index 8065881..6cdeb71 100644 --- a/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x67.cs +++ b/src/JT808.Protocol.Extensions/JT808.Protocol.Extensions.SuBiao/MessageBody/JT808_0x0200_0x67.cs @@ -1,24 +1,26 @@ -using JT808.Protocol.Extensions.SuBiao.Metadata; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json; +using JT808.Protocol.Extensions.SuBiao.Metadata; using JT808.Protocol.Formatters; using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; -using System; -using System.Collections.Generic; -using System.Text; -using System.Text.Json; namespace JT808.Protocol.Extensions.SuBiao.MessageBody { /// /// 盲区监测系统报警信息 /// - public class JT808_0x0200_0x67 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, IJT808Analyze + public class JT808_0x0200_0x67 : JT808MessagePackFormatter, JT808_0x0200_CustomBodyBase, JT808_0x8900_BodyBase, IJT808Analyze { /// /// 盲区监测系统报警信息Id /// public byte AttachInfoId { get; set; } = JT808_SuBiao_Constants.JT808_0X0200_0x67; + /// + public byte PassthroughType { get; set; } = JT808_SuBiao_Constants.JT808_0X0200_0x67; /// /// 盲区监测系统报警信息长度 /// @@ -34,7 +36,7 @@ namespace JT808.Protocol.Extensions.SuBiao.MessageBody /// /// 报警/事件类型 /// - public byte AlarmOrEventType{ get; set; } + public byte AlarmOrEventType { get; set; } /// /// 报警/事件类型 /// @@ -182,12 +184,12 @@ namespace JT808.Protocol.Extensions.SuBiao.MessageBody writer.WriteString($"[{value.AlarmTime.ToString("yyMMddHHmmss")}]日期时间", value.AlarmTime.ToString("yyyy-MM-dd HH:mm:ss")); value.VehicleState = reader.ReadUInt16(); writer.WriteNumber($"[{value.VehicleState.ReadNumber()}]车辆状态", value.VehicleState); - var vehicleStateBits=Convert.ToString(value.VehicleState, 2).PadLeft(16, '0'); + var vehicleStateBits = Convert.ToString(value.VehicleState, 2).PadLeft(16, '0'); writer.WriteStartObject($"车辆状态对象[{vehicleStateBits}]"); - writer.WriteString($"[{vehicleStateBits[15]}]Bit0ACC状态", vehicleStateBits[15]=='0'?"关闭":"打开"); - writer.WriteString($"[{vehicleStateBits[14]}]Bit1左转向状态", vehicleStateBits[14]=='0'?"关闭":"打开"); - writer.WriteString($"[{vehicleStateBits[13]}]Bit2右转向状态", vehicleStateBits[13]=='0'?"关闭":"打开"); - writer.WriteString($"[{vehicleStateBits[12]}]Bit3雨刮器状态", vehicleStateBits[12]=='0'?"关闭":"打开"); + writer.WriteString($"[{vehicleStateBits[15]}]Bit0ACC状态", vehicleStateBits[15] == '0' ? "关闭" : "打开"); + writer.WriteString($"[{vehicleStateBits[14]}]Bit1左转向状态", vehicleStateBits[14] == '0' ? "关闭" : "打开"); + writer.WriteString($"[{vehicleStateBits[13]}]Bit2右转向状态", vehicleStateBits[13] == '0' ? "关闭" : "打开"); + writer.WriteString($"[{vehicleStateBits[12]}]Bit3雨刮器状态", vehicleStateBits[12] == '0' ? "关闭" : "打开"); writer.WriteString($"[{vehicleStateBits[11]}]Bit4制动状态", vehicleStateBits[11] == '0' ? "未制动" : "制动"); writer.WriteString($"[{vehicleStateBits[10]}]Bit5插卡状态", vehicleStateBits[10] == '0' ? "未插卡" : "已插卡"); writer.WriteString($"[{vehicleStateBits[9]}]Bit6自定义", vehicleStateBits[9].ToString()); diff --git a/src/JT808.Protocol/Interfaces/IJT808_0x8900_Custom_Factory.cs b/src/JT808.Protocol/Interfaces/IJT808_0x8900_Custom_Factory.cs index 620e69e..970efcf 100644 --- a/src/JT808.Protocol/Interfaces/IJT808_0x8900_Custom_Factory.cs +++ b/src/JT808.Protocol/Interfaces/IJT808_0x8900_Custom_Factory.cs @@ -1,7 +1,7 @@ -using System; +using JT808.Protocol.MessageBody; +using System; using System.Collections.Generic; using System.Text; -using JT808.Protocol.MessageBody; namespace JT808.Protocol.Interfaces { @@ -19,6 +19,6 @@ namespace JT808.Protocol.Interfaces /// /// /// - IJT808_0x8900_Custom_Factory SetMap(); + IJT808_0x8900_Custom_Factory SetMap() where TJT808_0x8900_BodyBase : JT808_0x8900_BodyBase; } } diff --git a/src/JT808.Protocol/Internal/JT808_0x8900_Custom_Factory.cs b/src/JT808.Protocol/Internal/JT808_0x8900_Custom_Factory.cs index a2a9a2c..5ac0429 100644 --- a/src/JT808.Protocol/Internal/JT808_0x8900_Custom_Factory.cs +++ b/src/JT808.Protocol/Internal/JT808_0x8900_Custom_Factory.cs @@ -15,15 +15,15 @@ namespace JT808.Protocol.Internal public void Register(Assembly externalAssembly) { - foreach (var item in externalAssembly.GetTypes().Where(x => x.GetConstructor(Type.EmptyTypes) != default)) + foreach (var item in externalAssembly.GetTypes().Where(x => x is JT808_0x8900_BodyBase && x.GetConstructor(Type.EmptyTypes) != default)) { Register(item); } } - public IJT808_0x8900_Custom_Factory SetMap() + public IJT808_0x8900_Custom_Factory SetMap() where TJT808_0x8900_BodyBase : JT808_0x8900_BodyBase { - var type = typeof(T); + var type = typeof(TJT808_0x8900_BodyBase); if (type.GetConstructor(Type.EmptyTypes) != default) { Register(type); @@ -38,9 +38,9 @@ namespace JT808.Protocol.Internal void Register(Type type) { var instance = Activator.CreateInstance(type); - if (instance is JT808_0x0200_CustomBodyBase jT808_0X0200_Custom) + if (instance is JT808_0x8900_BodyBase jT808_0X8900_Custom) { - var key = jT808_0X0200_Custom.AttachInfoId; + var key = jT808_0X8900_Custom.PassthroughType; if (Map.ContainsKey(key)) { throw new ArgumentException($"{type.FullName} {key} An element with the same key already exists."); @@ -50,17 +50,9 @@ namespace JT808.Protocol.Internal Map.Add(key, instance); } } - else if (instance is JT808_0x8900_BodyBase jT808_0X8900_Custom) + else { - var key = jT808_0X8900_Custom.PassthroughType; - if (Map.ContainsKey(key)) - { - throw new ArgumentException($"{type.FullName} {key} An element with the same key already exists."); - } - else - { - Map.Add(key, instance); - } + throw new ArgumentException($"{type.FullName} must be implement of {typeof(JT808_0x8900_BodyBase).FullName}."); } } }