@@ -16,6 +16,7 @@ namespace GBNewEnergy.Protocol.Test | |||||
{ | { | ||||
}; | }; | ||||
#region 车辆登入 | #region 车辆登入 | ||||
[Fact] | [Fact] | ||||
public void NELoginUpStreamConstructor4_1() | public void NELoginUpStreamConstructor4_1() | ||||
@@ -70,7 +71,7 @@ namespace GBNewEnergy.Protocol.Test | |||||
} | } | ||||
#endregion | #endregion | ||||
#region 车辆登出(依赖车辆登录的流水号所有必须先进行登录产生流水号) | |||||
#region 车辆登出(依赖车辆登入的流水号所有必须先进行登入产生流水号) | |||||
[Fact] | [Fact] | ||||
public void NELogoutUpStream1_1() | public void NELogoutUpStream1_1() | ||||
@@ -155,5 +156,74 @@ namespace GBNewEnergy.Protocol.Test | |||||
#endregion | #endregion | ||||
#region 平台登入 | |||||
[Fact] | |||||
public void NEPlatformLogin1_1() | |||||
{ | |||||
NEPlatformLoginProperty nEPlatformLoginProperty = new NEPlatformLoginProperty | |||||
{ | |||||
EncryptMethod = NEEncryptMethod.None, | |||||
Password = "123456", | |||||
UserName = "smallchi", | |||||
}; | |||||
NEPlatformLoginUpStream nEPlatformLoginUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); | |||||
INEProperties nEPackageProperty = new NEPackageProperty | |||||
{ | |||||
Bodies = nEPlatformLoginUpStream, | |||||
MsgId = Enums.NEMsgId.platformlogin, | |||||
AskId = Enums.NEAskId.cmd, | |||||
VIN = "LGHC4V1D3HE202652" | |||||
}; | |||||
NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); | |||||
string headerHex = nEPackage.Header.ToHexString(); | |||||
string bodiesHex = nEPackage.Bodies.Buffer.ToHexString(); | |||||
string packageHex = nEPackage.Buffer.ToHexString(); | |||||
} | |||||
#endregion | |||||
#region 平台登出(依赖平台登出的流水号所有必须先进行登入产生流水号) | |||||
[Fact] | |||||
public void NEPlatformLogin2_1() | |||||
{ | |||||
NEPlatformLoginProperty nEPlatformLoginProperty = new NEPlatformLoginProperty | |||||
{ | |||||
EncryptMethod = NEEncryptMethod.None, | |||||
Password = "123456", | |||||
UserName = "smallchi", | |||||
}; | |||||
NEPlatformLoginUpStream nEPlatformLoginUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); | |||||
INEProperties nEPackageProperty = new NEPackageProperty | |||||
{ | |||||
Bodies = nEPlatformLoginUpStream, | |||||
MsgId = Enums.NEMsgId.platformlogin, | |||||
AskId = Enums.NEAskId.cmd, | |||||
VIN = "LGHC4V1D3HE202652" | |||||
}; | |||||
NEPackage nEPackage = new NEPackage(nEPackageProperty, NEGlobalConfigs); | |||||
NEPlatformLogoutProperty nEPlatformLogoutProperty = new NEPlatformLogoutProperty | |||||
{ | |||||
UserName = "smallchi", | |||||
}; | |||||
NEPlatformLoginUpStream nEPlatformLogoutUpStream = new NEPlatformLoginUpStream(nEPlatformLoginProperty, NEGlobalConfigs); | |||||
INEProperties logoutNEPackageProperty = new NEPackageProperty | |||||
{ | |||||
Bodies = nEPlatformLogoutUpStream, | |||||
MsgId = Enums.NEMsgId.platformlogout, | |||||
AskId = Enums.NEAskId.cmd, | |||||
VIN = "LGHC4V1D3HE202652" | |||||
}; | |||||
NEPackage loginNEPackage = new NEPackage(logoutNEPackageProperty, NEGlobalConfigs); | |||||
string headerHex = loginNEPackage.Header.ToHexString(); | |||||
string bodiesHex = loginNEPackage.Bodies.Buffer.ToHexString(); | |||||
string packageHex = loginNEPackage.Buffer.ToHexString(); | |||||
} | |||||
#endregion | |||||
} | } | ||||
} | } |
@@ -18,17 +18,25 @@ namespace GBNewEnergy.Protocol.Enums | |||||
/// </summary> | /// </summary> | ||||
uploadim = 0x02, | uploadim = 0x02, | ||||
/// <summary> | /// <summary> | ||||
/// 心跳 | |||||
/// </summary> | |||||
heartbeat = 0x03, | |||||
/// <summary> | |||||
/// 补传信息上传 | /// 补传信息上传 | ||||
/// </summary> | /// </summary> | ||||
uploadsup = 0x04, | |||||
uploadsup = 0x03, | |||||
/// <summary> | /// <summary> | ||||
/// 车辆登出 | /// 车辆登出 | ||||
/// </summary> | /// </summary> | ||||
loginout = 0x05, | |||||
loginout = 0x04, | |||||
/// <summary> | |||||
/// 平台登入 | |||||
/// </summary> | |||||
platformlogin = 0x05, | |||||
/// <summary> | |||||
/// 平台登出 | |||||
/// </summary> | |||||
platformlogout = 0x06, | |||||
/// <summary> | |||||
/// 心跳 | |||||
/// </summary> | |||||
heartbeat = 0x07, | |||||
/// <summary> | /// <summary> | ||||
/// 终端校时 | /// 终端校时 | ||||
/// </summary> | /// </summary> | ||||
@@ -82,6 +82,11 @@ namespace GBNewEnergy.Protocol.Extensions | |||||
Array.Copy(bytes, 0, write, offset, len); | Array.Copy(bytes, 0, write, offset, len); | ||||
} | } | ||||
public static void WriteLittle(this byte[] write, byte bit, int offset) | |||||
{ | |||||
write[offset] = bit; | |||||
} | |||||
public static void WriteLittle(this byte[] write, DateTime date, int offset,int len) | public static void WriteLittle(this byte[] write, DateTime date, int offset,int len) | ||||
{ | { | ||||
write[offset++] = (byte)(date.Year - DateLimitYear); | write[offset++] = (byte)(date.Year - DateLimitYear); | ||||
@@ -8,14 +8,21 @@ namespace GBNewEnergy.Protocol | |||||
public abstract class NEBodies : NEBufferedEntityBase | public abstract class NEBodies : NEBufferedEntityBase | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// VIN - 登录流水号,过期时间(每天置1) | |||||
/// VIN - 登入流水号,过期时间(每天置1) | |||||
/// 车载终端登入一次,登入流水号自动加1,从1开始循环累加,最大值为65531,循环周期为天 | /// 车载终端登入一次,登入流水号自动加1,从1开始循环累加,最大值为65531,循环周期为天 | ||||
/// </summary> | /// </summary> | ||||
protected static readonly ConcurrentDictionary<string, LoginInfo> LoginNumDict; | protected static readonly ConcurrentDictionary<string, LoginInfo> LoginNumDict; | ||||
/// <summary> | |||||
/// 平台登入 登录流水号,过期时间(每天置1) | |||||
/// 下级平台登入一次,登入流水号自动加1,从1开始循环累加,最大值为65531,循环周期为天 | |||||
/// </summary> | |||||
protected static readonly ConcurrentDictionary<string, PlatformLoginInfo> PlatformLoginNumDict; | |||||
static NEBodies() | static NEBodies() | ||||
{ | { | ||||
LoginNumDict = new ConcurrentDictionary<string, LoginInfo>(); | LoginNumDict = new ConcurrentDictionary<string, LoginInfo>(); | ||||
PlatformLoginNumDict = new ConcurrentDictionary<string, PlatformLoginInfo>(); | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -39,5 +46,11 @@ namespace GBNewEnergy.Protocol | |||||
public ushort LoginNum { get; set; } | public ushort LoginNum { get; set; } | ||||
public DateTime ExpirationTime { get; set; } | public DateTime ExpirationTime { get; set; } | ||||
} | } | ||||
protected class PlatformLoginInfo | |||||
{ | |||||
public ushort LoginNum { get; set; } | |||||
public DateTime ExpirationTime { get; set; } | |||||
} | |||||
} | } | ||||
} | } |
@@ -0,0 +1,27 @@ | |||||
using GBNewEnergy.Protocol.Enums; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace GBNewEnergy.Protocol.NEProperties | |||||
{ | |||||
public class NEPlatformLoginProperty : INEProperties | |||||
{ | |||||
[Obsolete("平台登入无用字段")] | |||||
public string VIN { get ; set; } | |||||
/// <summary> | |||||
/// 平台用户名 | |||||
/// </summary> | |||||
public string UserName { get; set; } | |||||
/// <summary> | |||||
/// 加密规则 | |||||
/// </summary> | |||||
public NEEncryptMethod EncryptMethod { get; set; } | |||||
/// <summary> | |||||
/// 平台密码 | |||||
/// </summary> | |||||
public string Password { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,16 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace GBNewEnergy.Protocol.NEProperties | |||||
{ | |||||
public class NEPlatformLogoutProperty : INEProperties | |||||
{ | |||||
[Obsolete("平台登入无用字段")] | |||||
public string VIN { get; set; } | |||||
/// <summary> | |||||
/// 平台用户名 | |||||
/// </summary> | |||||
public string UserName { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,88 @@ | |||||
using GBNewEnergy.Protocol.Enums; | |||||
using GBNewEnergy.Protocol.Extensions; | |||||
using GBNewEnergy.Protocol.NEProperties; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace GBNewEnergy.Protocol.UpStream | |||||
{ | |||||
/// <summary> | |||||
/// 平台登入 | |||||
/// </summary> | |||||
public class NEPlatformLoginUpStream : NEBodies | |||||
{ | |||||
public NEPlatformLoginUpStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs) | |||||
{ | |||||
} | |||||
public NEPlatformLoginUpStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs) | |||||
{ | |||||
} | |||||
/// <summary> | |||||
/// 平台用户名 | |||||
/// </summary> | |||||
public string UserName { get; set; } | |||||
/// <summary> | |||||
/// 加密规则 | |||||
/// </summary> | |||||
public NEEncryptMethod EncryptMethod { get; set; } | |||||
/// <summary> | |||||
/// 平台密码 | |||||
/// </summary> | |||||
public string Password { get; set; } | |||||
protected override void InitializeProperties(INEProperties nEProperties) | |||||
{ | |||||
NEPlatformLoginProperty nEPlatformLoginProperty = (NEPlatformLoginProperty)nEProperties; | |||||
if (PlatformLoginNumDict.ContainsKey(nEPlatformLoginProperty.UserName)) | |||||
{ | |||||
PlatformLoginInfo temp; | |||||
if (PlatformLoginNumDict.TryGetValue(nEPlatformLoginProperty.UserName, out temp)) | |||||
{ | |||||
// 不等于当天 | |||||
if (temp.ExpirationTime != DateTime.Now.Date) | |||||
{ | |||||
LoginNum = 1; | |||||
PlatformLoginNumDict.TryUpdate(nEPlatformLoginProperty.UserName, new PlatformLoginInfo { LoginNum = LoginNum, ExpirationTime = DateTime.Now.Date }, temp); | |||||
} | |||||
else | |||||
{// 自增1 更新字典 | |||||
LoginNum = temp.LoginNum++; | |||||
PlatformLoginNumDict.TryUpdate(nEPlatformLoginProperty.UserName, new PlatformLoginInfo { LoginNum = LoginNum, ExpirationTime = DateTime.Now.Date }, temp); | |||||
} | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
LoginNum = 1; | |||||
PlatformLoginNumDict.TryAdd(nEPlatformLoginProperty.UserName, new PlatformLoginInfo { LoginNum = LoginNum, ExpirationTime = DateTime.Now.Date }); | |||||
} | |||||
UserName = nEPlatformLoginProperty.UserName; | |||||
EncryptMethod = nEPlatformLoginProperty.EncryptMethod; | |||||
Password = nEPlatformLoginProperty.Password; | |||||
} | |||||
protected override void InitializePropertiesFromBuffer() | |||||
{ | |||||
CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6); | |||||
LoginNum = Buffer.ReadUShortH2LLittle(6, 2); | |||||
UserName = Buffer.ReadStringLittle(6, 12); | |||||
Password = Buffer.ReadStringLittle(12, 20); | |||||
EncryptMethod= (NEEncryptMethod)Buffer[21]; | |||||
} | |||||
protected override void ToBuffer() | |||||
{ | |||||
Buffer = new byte[6+2+12+20+1]; | |||||
Buffer.WriteLittle(CurrentDateTime, 0, 6); | |||||
Buffer.WriteLittle(LoginNum, 6, 2); | |||||
Buffer.WriteLittle(UserName, 12); | |||||
Buffer.WriteLittle(Password, 20); | |||||
Buffer.WriteLittle((byte)EncryptMethod, 21); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,47 @@ | |||||
using GBNewEnergy.Protocol.Exceptions; | |||||
using GBNewEnergy.Protocol.Extensions; | |||||
using GBNewEnergy.Protocol.NEProperties; | |||||
namespace GBNewEnergy.Protocol.UpStream | |||||
{ | |||||
/// <summary> | |||||
/// 平台登出 | |||||
/// </summary> | |||||
public class NEPlatformLogoutUpStream : NEBodies | |||||
{ | |||||
public NEPlatformLogoutUpStream(INEProperties nEProperties, NEGlobalConfigs nEConfigs) : base(nEProperties, nEConfigs) | |||||
{ | |||||
} | |||||
public NEPlatformLogoutUpStream(byte[] buffer, NEGlobalConfigs nEConfigs) : base(buffer, nEConfigs) | |||||
{ | |||||
} | |||||
protected override void InitializeProperties(INEProperties nEProperties) | |||||
{ | |||||
NEPlatformLogoutProperty nEPlatformLogoutProperty = (NEPlatformLogoutProperty)nEProperties; | |||||
PlatformLoginInfo temp; | |||||
if (PlatformLoginNumDict.TryGetValue(nEPlatformLogoutProperty.UserName, out temp)) | |||||
{ | |||||
LoginNum = temp.LoginNum; | |||||
} | |||||
else | |||||
{ | |||||
throw new NEException(Enums.NEErrorCode.LoginSerialNoError, "Must Dependency NEPlatformLoginUpStream Class."); | |||||
} | |||||
} | |||||
protected override void InitializePropertiesFromBuffer() | |||||
{ | |||||
CurrentDateTime = Buffer.ReadDateTimeLittle(0, 6); | |||||
LoginNum = Buffer.ReadUShortH2LLittle(6, 2); | |||||
} | |||||
protected override void ToBuffer() | |||||
{ | |||||
Buffer = new byte[8]; | |||||
Buffer.WriteLittle(CurrentDateTime, 0, 6); | |||||
Buffer.WriteLittle(LoginNum, 6, 2); | |||||
} | |||||
} | |||||
} |