@@ -33,10 +33,12 @@ namespace JT808.Protocol.Internal | |||||
var instance = Activator.CreateInstance(type); | var instance = Activator.CreateInstance(type); | ||||
ushort msgId = 0; | ushort msgId = 0; | ||||
JT809Version version; | JT809Version version; | ||||
bool replaceInternalMsgId; | |||||
try | try | ||||
{ | { | ||||
msgId = (ushort)type.GetProperty(nameof(JT809Bodies.MsgId)).GetValue(instance); | msgId = (ushort)type.GetProperty(nameof(JT809Bodies.MsgId)).GetValue(instance); | ||||
version = (JT809Version)type.GetProperty(nameof(JT809Bodies.Version)).GetValue(instance); | version = (JT809Version)type.GetProperty(nameof(JT809Bodies.Version)).GetValue(instance); | ||||
replaceInternalMsgId = (bool)type.GetProperty(nameof(JT809Bodies.ReplaceInternalMsgId)).GetValue(instance); | |||||
} | } | ||||
catch (Exception ex) | catch (Exception ex) | ||||
{ | { | ||||
@@ -44,13 +46,20 @@ namespace JT808.Protocol.Internal | |||||
} | } | ||||
if (Map_2019.ContainsKey(msgId)) | if (Map_2019.ContainsKey(msgId)) | ||||
{ | { | ||||
if (version == JT809Version.JTT2019) | if (replaceInternalMsgId) | ||||
{ | { | ||||
Map_2019[msgId] = instance; | Map_2019[msgId] = instance; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | if (version == JT809Version.JTT2019) | ||||
{ | |||||
Map_2019[msgId] = instance; | |||||
} | |||||
else | |||||
{ | |||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | |||||
} | |||||
} | } | ||||
} | } | ||||
else | else | ||||
@@ -61,7 +70,14 @@ namespace JT808.Protocol.Internal | |||||
{ | { | ||||
if (version != JT809Version.JTT2019) | if (version != JT809Version.JTT2019) | ||||
{ | { | ||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | if (replaceInternalMsgId) | ||||
{ | |||||
Map[msgId] = instance; | |||||
} | |||||
else | |||||
{ | |||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | |||||
} | |||||
} | } | ||||
} | } | ||||
else | else | ||||
@@ -77,11 +93,19 @@ namespace JT808.Protocol.Internal | |||||
var instance = Activator.CreateInstance(type); | var instance = Activator.CreateInstance(type); | ||||
var msgId = (ushort)type.GetProperty(nameof(JT809Bodies.MsgId)).GetValue(instance); | var msgId = (ushort)type.GetProperty(nameof(JT809Bodies.MsgId)).GetValue(instance); | ||||
JT809Version version = (JT809Version)type.GetProperty(nameof(JT809Bodies.Version)).GetValue(instance); | JT809Version version = (JT809Version)type.GetProperty(nameof(JT809Bodies.Version)).GetValue(instance); | ||||
bool replaceInternalMsgId = (bool)type.GetProperty(nameof(JT809Bodies.ReplaceInternalMsgId)).GetValue(instance); | |||||
if (Map.ContainsKey(msgId)) | if (Map.ContainsKey(msgId)) | ||||
{ | { | ||||
if (version != JT809Version.JTT2019) | if (replaceInternalMsgId) | ||||
{ | { | ||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | Map[msgId] = instance; | ||||
} | |||||
else | |||||
{ | |||||
if (version != JT809Version.JTT2019) | |||||
{ | |||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | |||||
} | |||||
} | } | ||||
} | } | ||||
else | else | ||||
@@ -90,13 +114,20 @@ namespace JT808.Protocol.Internal | |||||
} | } | ||||
if (Map_2019.ContainsKey(msgId)) | if (Map_2019.ContainsKey(msgId)) | ||||
{ | { | ||||
if (version == JT809Version.JTT2019) | if (replaceInternalMsgId) | ||||
{ | { | ||||
Map_2019[msgId] = instance; | Map_2019[msgId] = instance; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | if (version == JT809Version.JTT2019) | ||||
{ | |||||
Map_2019[msgId] = instance; | |||||
} | |||||
else | |||||
{ | |||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | |||||
} | |||||
} | } | ||||
} | } | ||||
else | else | ||||
@@ -27,9 +27,11 @@ namespace JT808.Protocol.Internal | |||||
{ | { | ||||
var instance = Activator.CreateInstance(type); | var instance = Activator.CreateInstance(type); | ||||
ushort msgId = 0; | ushort msgId = 0; | ||||
bool replaceInternalSubMsgId; | |||||
try | try | ||||
{ | { | ||||
msgId = (ushort)type.GetProperty(nameof(JT809SubBodies.SubMsgId)).GetValue(instance); | msgId = (ushort)type.GetProperty(nameof(JT809SubBodies.SubMsgId)).GetValue(instance); | ||||
replaceInternalSubMsgId = (bool)type.GetProperty(nameof(JT809SubBodies.ReplaceInternalSubMsgId)).GetValue(instance); | |||||
} | } | ||||
catch (Exception ex) | catch (Exception ex) | ||||
{ | { | ||||
@@ -37,7 +39,14 @@ namespace JT808.Protocol.Internal | |||||
} | } | ||||
if (Map.ContainsKey(msgId)) | if (Map.ContainsKey(msgId)) | ||||
{ | { | ||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | if (replaceInternalSubMsgId) | ||||
{ | |||||
Map[msgId] = instance; | |||||
} | |||||
else | |||||
{ | |||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -56,9 +65,17 @@ namespace JT808.Protocol.Internal | |||||
Type type = typeof(TJT809SubBodies); | Type type = typeof(TJT809SubBodies); | ||||
var instance = Activator.CreateInstance(type); | var instance = Activator.CreateInstance(type); | ||||
var msgId = (ushort)type.GetProperty(nameof(JT809SubBodies.SubMsgId)).GetValue(instance); | var msgId = (ushort)type.GetProperty(nameof(JT809SubBodies.SubMsgId)).GetValue(instance); | ||||
bool replaceInternalSubMsgId = (bool)type.GetProperty(nameof(JT809SubBodies.ReplaceInternalSubMsgId)).GetValue(instance); | |||||
if (Map.ContainsKey(msgId)) | if (Map.ContainsKey(msgId)) | ||||
{ | { | ||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | if (replaceInternalSubMsgId) | ||||
{ | |||||
Map[msgId] = instance; | |||||
} | |||||
else | |||||
{ | |||||
throw new ArgumentException($"{type.FullName} {msgId} An element with the same key already exists."); | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -14,7 +14,7 @@ | |||||
<PackageProjectUrl>https://github.com/SmallChi/JT809</PackageProjectUrl> | <PackageProjectUrl>https://github.com/SmallChi/JT809</PackageProjectUrl> | ||||
<license>https://github.com/SmallChi/JT809/blob/master/LICENSE</license> | <license>https://github.com/SmallChi/JT809/blob/master/LICENSE</license> | ||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | <GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||||
<Version>2.1.4-preview2</Version> | <Version>2.1.4-preview3</Version> | ||||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | <PackageLicenseFile>LICENSE</PackageLicenseFile> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
@@ -15,5 +15,10 @@ namespace JT809.Protocol | |||||
public abstract ushort MsgId { get; } | public abstract ushort MsgId { get; } | ||||
public abstract JT809_LinkType LinkType { get; } | public abstract JT809_LinkType LinkType { get; } | ||||
public abstract string Description { get; } | public abstract string Description { get; } | ||||
/// <summary> | |||||
/// 当外部注册的扩展809的消息Id跟国标的消息Id冲突时可以使用该字段替换国标的消息Id | |||||
/// 默认是false,不替换 | |||||
/// </summary> | |||||
public virtual bool ReplaceInternalMsgId { get; } = false; | |||||
} | } | ||||
} | } |
@@ -17,5 +17,10 @@ namespace JT809.Protocol | |||||
public abstract ushort SubMsgId { get; } | public abstract ushort SubMsgId { get; } | ||||
public abstract string Description { get; } | public abstract string Description { get; } | ||||
/// <summary> | |||||
/// 当外部注册的扩展809的消息Id跟国标的消息Id冲突时可以使用该字段替换国标的消息Id | |||||
/// 默认是false,不替换 | |||||
/// </summary> | |||||
public virtual bool ReplaceInternalSubMsgId { get; } = false; | |||||
} | } | ||||
} | } |