@@ -1,21 +1,18 @@ | |||||
using System; | |||||
using System.Collections.Concurrent; | |||||
using System.Collections.Generic; | |||||
using System.Threading; | |||||
using System.Collections.Concurrent; | |||||
using JT808.Protocol.Interfaces; | using JT808.Protocol.Interfaces; | ||||
namespace JT808.Protocol.Internal | namespace JT808.Protocol.Internal | ||||
{ | { | ||||
internal class DefaultMsgSNDistributedImpl : IJT808MsgSNDistributed | internal class DefaultMsgSNDistributedImpl : IJT808MsgSNDistributed | ||||
{ | { | ||||
ConcurrentDictionary<string, ushort> counterDict; | |||||
readonly ConcurrentDictionary<string, ushort> counterDict; | |||||
public DefaultMsgSNDistributedImpl() | public DefaultMsgSNDistributedImpl() | ||||
{ | { | ||||
counterDict = new ConcurrentDictionary<string, ushort>(StringComparer.OrdinalIgnoreCase); | counterDict = new ConcurrentDictionary<string, ushort>(StringComparer.OrdinalIgnoreCase); | ||||
} | } | ||||
public ushort Increment(string terminalPhoneNo) | public ushort Increment(string terminalPhoneNo) | ||||
{ | { | ||||
if (counterDict.TryGetValue(terminalPhoneNo, out ushort value)) | |||||
if (counterDict.TryGetValue(terminalPhoneNo, out ushort value)) | |||||
{ | { | ||||
ushort newValue = ++value; | ushort newValue = ++value; | ||||
counterDict.TryUpdate(terminalPhoneNo, newValue, value); | counterDict.TryUpdate(terminalPhoneNo, newValue, value); | ||||
@@ -23,8 +20,8 @@ namespace JT808.Protocol.Internal | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
counterDict.TryAdd(terminalPhoneNo, 1); | |||||
return 1; | |||||
counterDict.TryAdd(terminalPhoneNo, 0); | |||||
return 0; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -26,14 +26,14 @@ namespace JT808.Protocol | |||||
/// 根据安装后终端自身的手机号转换。手机号不足 12 位,则在前补充数字,大陆手机号补充数字 0,港澳台则根据其区号进行位数补充 | /// 根据安装后终端自身的手机号转换。手机号不足 12 位,则在前补充数字,大陆手机号补充数字 0,港澳台则根据其区号进行位数补充 | ||||
/// (2019版本)手机号不足 20 位,则在前补充数字 0 | /// (2019版本)手机号不足 20 位,则在前补充数字 0 | ||||
/// </summary> | /// </summary> | ||||
public string TerminalPhoneNo { get; set; } | |||||
public string TerminalPhoneNo { get; set; } | |||||
/// <summary> | /// <summary> | ||||
/// 消息流水号 | /// 消息流水号 | ||||
/// 发送计数器 | /// 发送计数器 | ||||
/// 占用两个字节,为发送信息的序列号,用于接收方检测是否有信息的丢失,上级平台和下级平台接自己发送数据包的个数计数,互不影响。 | /// 占用两个字节,为发送信息的序列号,用于接收方检测是否有信息的丢失,上级平台和下级平台接自己发送数据包的个数计数,互不影响。 | ||||
/// 程序开始运行时等于零,发送第一帧数据时开始计数,到最大数后自动归零 | /// 程序开始运行时等于零,发送第一帧数据时开始计数,到最大数后自动归零 | ||||
/// </summary> | /// </summary> | ||||
public ushort MsgNum { get; set; } | |||||
public ushort MsgNum { get { return ManualMsgNum ?? 0; } set { ManualMsgNum = value; } } | |||||
/// <summary> | /// <summary> | ||||
/// 手动消息流水号(only test) | /// 手动消息流水号(only test) | ||||
/// 发送计数器 | /// 发送计数器 | ||||
@@ -63,7 +63,7 @@ namespace JT808.Protocol | |||||
// 2.消息体属性 | // 2.消息体属性 | ||||
jT808Header.MessageBodyProperty = new JT808HeaderMessageBodyProperty(reader.ReadUInt16()); | jT808Header.MessageBodyProperty = new JT808HeaderMessageBodyProperty(reader.ReadUInt16()); | ||||
if (jT808Header.MessageBodyProperty.VersionFlag) | if (jT808Header.MessageBodyProperty.VersionFlag) | ||||
{ | |||||
{ | |||||
// 2019 版本 | // 2019 版本 | ||||
// 3.协议版本号 | // 3.协议版本号 | ||||
jT808Header.ProtocolVersion = reader.ReadByte(); | jT808Header.ProtocolVersion = reader.ReadByte(); | ||||
@@ -193,8 +193,7 @@ namespace JT808.Protocol | |||||
else | else | ||||
{ | { | ||||
// 2.4.消息流水号 | // 2.4.消息流水号 | ||||
if (value.Header.MsgNum <= 0) | |||||
value.Header.MsgNum = config.MsgSNDistributed.Increment(value.Header.TerminalPhoneNo); | |||||
value.Header.MsgNum = config.MsgSNDistributed.Increment(value.Header.TerminalPhoneNo); | |||||
writer.WriteUInt16(value.Header.MsgNum); | writer.WriteUInt16(value.Header.MsgNum); | ||||
} | } | ||||
// 2.5.判断是否分包 | // 2.5.判断是否分包 | ||||