@@ -11,3 +11,6 @@ | |||||
|序号|消息体名称|消息ID|完成情况| | |序号|消息体名称|消息ID|完成情况| | ||||
|:------:|:------:|:------:|:------:| | |:------:|:------:|:------:|:------:| | ||||
| 1 | 主链路登录请求消息 | 0x1001 | √ | | | 1 | 主链路登录请求消息 | 0x1001 | √ | | ||||
| 2 | 主链路登录应答消息 | 0x1002 | √ | | |||||
| 3 | 主链路注销请求消息 | 0x1003 | √ | | |||||
| 4 | 主链路注销应答消息 | 0x1004 | √ | |
@@ -0,0 +1,33 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
using JT809.Protocol; | |||||
using JT809.Protocol.JT809Extensions; | |||||
using JT809.Protocol.JT809MessageBody; | |||||
using JT809.Protocol.JT809Exceptions; | |||||
namespace JT809.Protocol.Test.JT809MessageBody | |||||
{ | |||||
public class JT809_0x1002Test | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT809_0x1002 jT809_0X1002 = new JT809_0x1002(); | |||||
jT809_0X1002.Result = JT809Enums.JT809_0x1002_Result.成功; | |||||
jT809_0X1002.VerifyCode = 54456; | |||||
var hex = JT809Serializer.Serialize(jT809_0X1002).ToHexString(); | |||||
//"00 00 00 D4 B8" | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "00 00 00 D4 B8".ToHexBytes(); | |||||
JT809_0x1002 jT809_0X1002 = JT809Serializer.Deserialize<JT809_0x1002>(bytes); | |||||
Assert.Equal(JT809Enums.JT809_0x1002_Result.成功, jT809_0X1002.Result); | |||||
Assert.Equal((uint)54456, jT809_0X1002.VerifyCode); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,33 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
using JT809.Protocol; | |||||
using JT809.Protocol.JT809Extensions; | |||||
using JT809.Protocol.JT809MessageBody; | |||||
using JT809.Protocol.JT809Exceptions; | |||||
namespace JT809.Protocol.Test.JT809MessageBody | |||||
{ | |||||
public class JT809_0x1003Test | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT809_0x1003 jT809_0X1003 = new JT809_0x1003(); | |||||
jT809_0X1003.UserId = 20180920; | |||||
jT809_0X1003.Password = "20180920"; | |||||
var hex = JT809Serializer.Serialize(jT809_0X1003).ToHexString(); | |||||
//"01 33 EF B8 32 30 31 38 30 39 32 30" | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "01 33 EF B8 32 30 31 38 30 39 32 30".ToHexBytes(); | |||||
JT809_0x1003 jT809_0X1003 = JT809Serializer.Deserialize<JT809_0x1003>(bytes); | |||||
Assert.Equal((uint)20180920, jT809_0X1003.UserId); | |||||
Assert.Equal("20180920", jT809_0X1003.Password); | |||||
} | |||||
} | |||||
} |
@@ -37,6 +37,7 @@ | |||||
<Compile Include="JT809Enums\JT809ErrorCode.cs" /> | <Compile Include="JT809Enums\JT809ErrorCode.cs" /> | ||||
<Compile Include="JT809Enums\JT809BusinessType.cs" /> | <Compile Include="JT809Enums\JT809BusinessType.cs" /> | ||||
<Compile Include="JT809Enums\JT809SubBusinessType.cs" /> | <Compile Include="JT809Enums\JT809SubBusinessType.cs" /> | ||||
<Compile Include="JT809Enums\JT809_0x1002_Result.cs" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -23,16 +23,19 @@ namespace JT809.Protocol.JT809Enums | |||||
///主链路登录应答消息 | ///主链路登录应答消息 | ||||
///</summary> | ///</summary> | ||||
[Description("主链路登录应答消息")] | [Description("主链路登录应答消息")] | ||||
[JT809BodiesType(typeof(JT809_0x1002))] | |||||
UP_CONNECT_RSP = 0x1002, | UP_CONNECT_RSP = 0x1002, | ||||
///<summary> | ///<summary> | ||||
///主链路注销请求消息 | ///主链路注销请求消息 | ||||
///</summary> | ///</summary> | ||||
[Description("主链路注销请求消息")] | [Description("主链路注销请求消息")] | ||||
[JT809BodiesType(typeof(JT809_0x1003))] | |||||
UP_DISCONNECT_REQ = 0x1003, | UP_DISCONNECT_REQ = 0x1003, | ||||
///<summary> | ///<summary> | ||||
///主链路注销应答消息 | ///主链路注销应答消息 | ||||
///</summary> | ///</summary> | ||||
[Description("主链路注销应答消息")] | [Description("主链路注销应答消息")] | ||||
[JT809BodiesType(typeof(JT809_0x1004))] | |||||
UP_DISCONNECT_RSP = 0x1004, | UP_DISCONNECT_RSP = 0x1004, | ||||
///<summary> | ///<summary> | ||||
///主链路连接保持请求消息 | ///主链路连接保持请求消息 | ||||
@@ -0,0 +1,20 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace JT809.Protocol.JT809Enums | |||||
{ | |||||
/// <summary> | |||||
/// 验证结果 | |||||
/// </summary> | |||||
public enum JT809_0x1002_Result:byte | |||||
{ | |||||
成功=0x00, | |||||
IP地址不正确=0x01, | |||||
接入码不正确=0x02, | |||||
用户没用注册=0x03, | |||||
密码错误=0x04, | |||||
资源紧张_稍后再连接_已经占用= 0x05, | |||||
其他 =0x06 | |||||
} | |||||
} |
@@ -268,6 +268,22 @@ namespace JT809.Protocol.JT809Extensions | |||||
return codeBytes.Length; | return codeBytes.Length; | ||||
} | } | ||||
public static int WriteStringPadLeftLittle(IMemoryOwner<byte> memoryOwner, int offset, string data,int len) | |||||
{ | |||||
data = data.PadLeft(len, '\0'); | |||||
byte[] codeBytes = encoding.GetBytes(data); | |||||
CopyTo(codeBytes, memoryOwner.Memory.Span, offset); | |||||
return codeBytes.Length; | |||||
} | |||||
public static int WriteStringPadRightLittle(IMemoryOwner<byte> memoryOwner, int offset, string data, int len) | |||||
{ | |||||
data = data.PadRight(len, '\0'); | |||||
byte[] codeBytes = encoding.GetBytes(data); | |||||
CopyTo(codeBytes, memoryOwner.Memory.Span, offset); | |||||
return codeBytes.Length; | |||||
} | |||||
public static int WriteBCDLittle(ref byte[] write, int offset, string data, int digit, int len) | public static int WriteBCDLittle(ref byte[] write, int offset, string data, int digit, int len) | ||||
{ | { | ||||
ReadOnlySpan<char> bcd = data.PadLeft(len, '0').AsSpan(); | ReadOnlySpan<char> bcd = data.PadLeft(len, '0').AsSpan(); | ||||
@@ -24,8 +24,8 @@ namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters | |||||
public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1001 value) | public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1001 value) | ||||
{ | { | ||||
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.UserId); | offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.UserId); | ||||
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.Password.PadRight(8,'\0')); | |||||
offset += JT809BinaryExtensions.WriteStringLittle(memoryOwner, offset, value.DownLinkIP.PadRight(32, '\0')); | |||||
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.Password,8); | |||||
offset += JT809BinaryExtensions.WriteStringPadRightLittle(memoryOwner, offset, value.DownLinkIP,32); | |||||
offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.DownLinkPort); | offset += JT809BinaryExtensions.WriteUInt16Little(memoryOwner, offset, value.DownLinkPort); | ||||
return offset; | return offset; | ||||
} | } | ||||
@@ -0,0 +1,30 @@ | |||||
using JT809.Protocol.JT809Enums; | |||||
using JT809.Protocol.JT809Extensions; | |||||
using JT809.Protocol.JT809MessageBody; | |||||
using System; | |||||
using System.Buffers; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters | |||||
{ | |||||
public class JT809_0x1002Formatter : IJT809Formatter<JT809_0x1002> | |||||
{ | |||||
public JT809_0x1002 Deserialize(ReadOnlySpan<byte> bytes, out int readSize) | |||||
{ | |||||
int offset = 0; | |||||
JT809_0x1002 jT809_0X1002 = new JT809_0x1002 (); | |||||
jT809_0X1002.Result=(JT809_0x1002_Result)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); | |||||
jT809_0X1002.VerifyCode= JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); | |||||
readSize =offset; | |||||
return jT809_0X1002; | |||||
} | |||||
public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1002 value) | |||||
{ | |||||
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result); | |||||
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VerifyCode); | |||||
return offset; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,30 @@ | |||||
using JT809.Protocol.JT809Enums; | |||||
using JT809.Protocol.JT809Extensions; | |||||
using JT809.Protocol.JT809MessageBody; | |||||
using System; | |||||
using System.Buffers; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters | |||||
{ | |||||
public class JT809_0x1003Formatter : IJT809Formatter<JT809_0x1003> | |||||
{ | |||||
public JT809_0x1003 Deserialize(ReadOnlySpan<byte> bytes, out int readSize) | |||||
{ | |||||
int offset = 0; | |||||
JT809_0x1003 jT809_0X1003 = new JT809_0x1003(); | |||||
jT809_0X1003.UserId = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); | |||||
jT809_0X1003.Password = JT809BinaryExtensions.ReadStringLittle(bytes, ref offset, 8); | |||||
readSize = offset; | |||||
return jT809_0X1003; | |||||
} | |||||
public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1003 value) | |||||
{ | |||||
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.UserId); | |||||
offset += JT809BinaryExtensions.WriteStringPadLeftLittle(memoryOwner, offset, value.Password,8); | |||||
return offset; | |||||
} | |||||
} | |||||
} |
@@ -8,6 +8,10 @@ namespace JT809.Protocol.JT809MessageBody | |||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// 主链路登录请求消息 | /// 主链路登录请求消息 | ||||
/// <para>链路类型:主链路</para> | |||||
/// <para>消息方向:下级平台往上级平台</para> | |||||
/// <para>业务数据类型标识: UP-CONNECT-REQ</para> | |||||
/// <para>描述:下级平台向上级平台发送用户名和密码等登录信息</para> | |||||
/// </summary> | /// </summary> | ||||
[JT809Formatter(typeof(JT809_0x1001Formatter))] | [JT809Formatter(typeof(JT809_0x1001Formatter))] | ||||
public class JT809_0x1001: JT809Bodies | public class JT809_0x1001: JT809Bodies | ||||
@@ -0,0 +1,36 @@ | |||||
using JT809.Protocol.JT809Attributes; | |||||
using JT809.Protocol.JT809Enums; | |||||
using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace JT809.Protocol.JT809MessageBody | |||||
{ | |||||
/// <summary> | |||||
/// 主链路登录应答消息 | |||||
/// <para>链路类型:主链路</para> | |||||
/// <para>消息方向:上级平台往下级平台</para> | |||||
/// <para>业务数据类型标识:UP_CONNCCT_RSP</para> | |||||
/// <para>上级平台对下级平台登录请求信息、进行安全验证后,返回相应的验证结果。</para> | |||||
/// </summary> | |||||
[JT809Formatter(typeof(JT809_0x1002Formatter))] | |||||
public class JT809_0x1002 : JT809Bodies | |||||
{ | |||||
/// <summary> | |||||
/// 验证结果,定义如下: | |||||
/// 0x00:成功; | |||||
/// 0x01:IP 地址不正确; | |||||
/// 0x02:接入码不正确; | |||||
/// 0x03:用户没用注册; | |||||
/// 0x04:密码错误; | |||||
/// 0x05:资源紧张,稍后再连接(已经占用; | |||||
/// 0x06:其他。 | |||||
/// </summary> | |||||
public JT809_0x1002_Result Result { get; set; } | |||||
/// <summary> | |||||
/// 校验码 | |||||
/// </summary> | |||||
public uint VerifyCode { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,28 @@ | |||||
using JT809.Protocol.JT809Attributes; | |||||
using JT809.Protocol.JT809Formatters.JT809MessageBodyFormatters; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace JT809.Protocol.JT809MessageBody | |||||
{ | |||||
/// <summary> | |||||
/// 主链路注销请求消息 | |||||
/// <para>链路类型:主链路</para> | |||||
/// <para>消息方向:下级平台往上级平台</para> | |||||
/// <para>业务数据类型标识:UP-DISCONNECT-REQ</para> | |||||
/// <para>描述:下级平台在中断与上级平台的主链路连接时,应向上级平台发送主链路注销请求消息。</para> | |||||
/// </summary> | |||||
[JT809Formatter(typeof(JT809_0x1003Formatter))] | |||||
public class JT809_0x1003 : JT809Bodies | |||||
{ | |||||
/// <summary> | |||||
/// 用户名 | |||||
/// </summary> | |||||
public uint UserId { get; set; } | |||||
/// <summary> | |||||
/// 密码 | |||||
/// </summary> | |||||
public string Password { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,20 @@ | |||||
using JT809.Protocol.JT809Attributes; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace JT809.Protocol.JT809MessageBody | |||||
{ | |||||
/// <summary> | |||||
/// 主链路注销应答消息 | |||||
/// <para>链路类型:主链路</para> | |||||
/// <para>消息方向:上级平台往下级平台</para> | |||||
/// <para>业务数据类型标识:UP_DISCONNECT_RSP</para> | |||||
/// <para>描述:上级平台收到下级平台发送的主链路注销请求消息后,向下级平台返回主链路注销应答消息,并记录链路注销日志,下级平台接收到应答消息后,可中断主从链路联接。</para> | |||||
/// <para>主链路注销应答消息,数据体为空。</para> | |||||
/// </summary> | |||||
public class JT809_0x1004 : JT809Bodies | |||||
{ | |||||
} | |||||
} |