2.增加0x1008|0x9001|0x9002|0x9003测试tags/v1.3.0
@@ -6,7 +6,7 @@ | |||||
> 该JT809协议是参考[MessagePack-CSharp](https://github.com/neuecc/MessagePack-CSharp)一款二进制序列化器,站在巨人的肩膀上搬砖就是爽歪歪。 | > 该JT809协议是参考[MessagePack-CSharp](https://github.com/neuecc/MessagePack-CSharp)一款二进制序列化器,站在巨人的肩膀上搬砖就是爽歪歪。 | ||||
## JT809终端通讯协议消息对照表 | |||||
## JT809协议消息对照表 | |||||
|序号|消息ID|完成情况|消息体名称| | |序号|消息ID|完成情况|消息体名称| | ||||
|:------:|:------:|:------:|:------:| | |:------:|:------:|:------:|:------:| | ||||
@@ -17,5 +17,14 @@ | |||||
| 5 | 0x1005 | √ | 主链路连接保持请求消息 | | | 5 | 0x1005 | √ | 主链路连接保持请求消息 | | ||||
| 6 | 0x1006 | √ | 主链路连接保持应答消息 | | | 6 | 0x1006 | √ | 主链路连接保持应答消息 | | ||||
| 7 | 0x1007 | √ | 主链路断开通知消息 | | | 7 | 0x1007 | √ | 主链路断开通知消息 | | ||||
| 8 | 0x1008 | √ | 下级平台主动关闭链路通知消息 | | |||||
| 9 | 0x9001 | √ | 从链路连接请求消息 | | |||||
| 10 | 0x9002 | √ | 从链路连接应答消息 | | |||||
| 11 | 0x9003 | √ | 从链路注销请求消息 | | |||||
| 12 | 0x9004 | √ | 从链路注销应答消息 | | |||||
@@ -0,0 +1,30 @@ | |||||
using JT809.Protocol; | |||||
using JT809.Protocol.JT809Extensions; | |||||
using JT809.Protocol.JT809MessageBody; | |||||
using JT809.Protocol.JT809Exceptions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
namespace JT809.Protocol.Test.JT809MessageBody | |||||
{ | |||||
public class JT809_0x1008Test | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT809_0x1008 jT809_0X1008 = new JT809_0x1008(); | |||||
jT809_0X1008.ReasonCode = JT809Enums.JT809_0x1008_ReasonCode.网关重启; | |||||
var hex = JT809Serializer.Serialize(jT809_0X1008).ToHexString(); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "00".ToHexBytes(); | |||||
JT809_0x1008 jT809_0X1008 = JT809Serializer.Deserialize<JT809_0x1008>(bytes); | |||||
Assert.Equal(JT809Enums.JT809_0x1008_ReasonCode.网关重启, jT809_0X1008.ReasonCode); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,30 @@ | |||||
using JT809.Protocol; | |||||
using JT809.Protocol.JT809Extensions; | |||||
using JT809.Protocol.JT809MessageBody; | |||||
using JT809.Protocol.JT809Exceptions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
namespace JT809.Protocol.Test.JT809MessageBody | |||||
{ | |||||
public class JT809_0x9001Test | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT809_0x9001 jT809_0X9001 = new JT809_0x9001(); | |||||
jT809_0X9001.VerifyCode = 45454; | |||||
var hex = JT809Serializer.Serialize(jT809_0X9001).ToHexString(); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "00 00 B1 8E".ToHexBytes(); | |||||
JT809_0x9001 jT809_0X9001 = JT809Serializer.Deserialize<JT809_0x9001>(bytes); | |||||
Assert.Equal((uint)45454, jT809_0X9001.VerifyCode); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,30 @@ | |||||
using JT809.Protocol; | |||||
using JT809.Protocol.JT809Extensions; | |||||
using JT809.Protocol.JT809MessageBody; | |||||
using JT809.Protocol.JT809Exceptions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
namespace JT809.Protocol.Test.JT809MessageBody | |||||
{ | |||||
public class JT809_0x9002Test | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT809_0x9002 jT809_0X9002 = new JT809_0x9002(); | |||||
jT809_0X9002.Result = JT809Enums.JT809_0x9002_Result.成功; | |||||
var hex = JT809Serializer.Serialize(jT809_0X9002).ToHexString(); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "00".ToHexBytes(); | |||||
JT809_0x9002 jT809_0X9002 = JT809Serializer.Deserialize<JT809_0x9002>(bytes); | |||||
Assert.Equal(JT809Enums.JT809_0x9002_Result.成功, jT809_0X9002.Result); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,30 @@ | |||||
using JT809.Protocol; | |||||
using JT809.Protocol.JT809Extensions; | |||||
using JT809.Protocol.JT809MessageBody; | |||||
using JT809.Protocol.JT809Exceptions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
namespace JT809.Protocol.Test.JT809MessageBody | |||||
{ | |||||
public class JT809_0x9003Test | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT809_0x9003 jT809_0X9003 = new JT809_0x9003(); | |||||
jT809_0X9003.VerifyCode = 45454; | |||||
var hex = JT809Serializer.Serialize(jT809_0X9003).ToHexString(); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "00 00 B1 8E".ToHexBytes(); | |||||
JT809_0x9003 jT809_0X9003 = JT809Serializer.Deserialize<JT809_0x9003>(bytes); | |||||
Assert.Equal((uint)45454, jT809_0X9003.VerifyCode); | |||||
} | |||||
} | |||||
} |
@@ -39,6 +39,8 @@ | |||||
<Compile Include="JT809Enums\JT809SubBusinessType.cs" /> | <Compile Include="JT809Enums\JT809SubBusinessType.cs" /> | ||||
<Compile Include="JT809Enums\JT809_0x1002_Result.cs" /> | <Compile Include="JT809Enums\JT809_0x1002_Result.cs" /> | ||||
<Compile Include="JT809Enums\JT809_0x1007_ErrorCode.cs" /> | <Compile Include="JT809Enums\JT809_0x1007_ErrorCode.cs" /> | ||||
<Compile Include="JT809Enums\JT809_0x1008_ReasonCode.cs" /> | |||||
<Compile Include="JT809Enums\JT809_0x9002_Result.cs" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -59,26 +59,31 @@ namespace JT809.Protocol.JT809Enums | |||||
///下级平台主动关闭链路通知消息 | ///下级平台主动关闭链路通知消息 | ||||
///</summary> | ///</summary> | ||||
[Description("下级平台主动关闭链路通知消息")] | [Description("下级平台主动关闭链路通知消息")] | ||||
[JT809BodiesType(typeof(JT809_0x1008))] | |||||
UP_CLOSELINK_INFORM = 0x1008, | UP_CLOSELINK_INFORM = 0x1008, | ||||
///<summary> | ///<summary> | ||||
///从链路连接请求消息 | ///从链路连接请求消息 | ||||
///</summary> | ///</summary> | ||||
[Description("从链路连接请求消息")] | [Description("从链路连接请求消息")] | ||||
[JT809BodiesType(typeof(JT809_0x9001))] | |||||
DOWN_CONNECT_REQ = 0x9001, | DOWN_CONNECT_REQ = 0x9001, | ||||
///<summary> | ///<summary> | ||||
///从链路连接应答消息 | ///从链路连接应答消息 | ||||
///</summary> | ///</summary> | ||||
[Description("从链路连接应答消息")] | [Description("从链路连接应答消息")] | ||||
[JT809BodiesType(typeof(JT809_0x9002))] | |||||
DOWN_CONNECT_RSP = 0x9002, | DOWN_CONNECT_RSP = 0x9002, | ||||
///<summary> | ///<summary> | ||||
///从链路注销请求消息 | ///从链路注销请求消息 | ||||
///</summary> | ///</summary> | ||||
[Description("从链路注销请求消息")] | [Description("从链路注销请求消息")] | ||||
[JT809BodiesType(typeof(JT809_0x9003))] | |||||
DOWN_DISCONNECT_REQ = 0x9003, | DOWN_DISCONNECT_REQ = 0x9003, | ||||
///<summary> | ///<summary> | ||||
///从链路注销应答消息 | ///从链路注销应答消息 | ||||
///</summary> | ///</summary> | ||||
[Description("从链路注销应答消息")] | [Description("从链路注销应答消息")] | ||||
[JT809BodiesType(typeof(JT809_0x9004))] | |||||
DOWN_DISCONNECT_RSP = 0x9004, | DOWN_DISCONNECT_RSP = 0x9004, | ||||
///<summary> | ///<summary> | ||||
///从链路连接保持请求消息 | ///从链路连接保持请求消息 | ||||
@@ -0,0 +1,15 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace JT809.Protocol.JT809Enums | |||||
{ | |||||
/// <summary> | |||||
/// 错误代码 | |||||
/// </summary> | |||||
public enum JT809_0x1008_ReasonCode:byte | |||||
{ | |||||
网关重启=0x00, | |||||
其他原因=0x01 | |||||
} | |||||
} |
@@ -0,0 +1,17 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace JT809.Protocol.JT809Enums | |||||
{ | |||||
/// <summary> | |||||
/// 验证结果 | |||||
/// </summary> | |||||
public enum JT809_0x9002_Result:byte | |||||
{ | |||||
成功=0x00, | |||||
VERIFY_CODE错误= 0x01, | |||||
资源紧张_稍后再连接_已经占用= 0x02, | |||||
其他= 0x03 | |||||
} | |||||
} |
@@ -0,0 +1,27 @@ | |||||
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_0x1008Formatter : IJT809Formatter<JT809_0x1008> | |||||
{ | |||||
public JT809_0x1008 Deserialize(ReadOnlySpan<byte> bytes, out int readSize) | |||||
{ | |||||
int offset = 0; | |||||
JT809_0x1008 jT809_0X1008 = new JT809_0x1008(); | |||||
jT809_0X1008.ReasonCode = (JT809Enums.JT809_0x1008_ReasonCode)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); | |||||
readSize = offset; | |||||
return jT809_0X1008; | |||||
} | |||||
public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x1008 value) | |||||
{ | |||||
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.ReasonCode); | |||||
return offset; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,27 @@ | |||||
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_0x9001Formatter : IJT809Formatter<JT809_0x9001> | |||||
{ | |||||
public JT809_0x9001 Deserialize(ReadOnlySpan<byte> bytes, out int readSize) | |||||
{ | |||||
int offset = 0; | |||||
JT809_0x9001 jT809_0X9001 = new JT809_0x9001(); | |||||
jT809_0X9001.VerifyCode = JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset); | |||||
readSize = offset; | |||||
return jT809_0X9001; | |||||
} | |||||
public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9001 value) | |||||
{ | |||||
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VerifyCode); | |||||
return offset; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,28 @@ | |||||
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_0x9002Formatter : IJT809Formatter<JT809_0x9002> | |||||
{ | |||||
public JT809_0x9002 Deserialize(ReadOnlySpan<byte> bytes, out int readSize) | |||||
{ | |||||
int offset = 0; | |||||
JT809_0x9002 jT809_0X9002 = new JT809_0x9002(); | |||||
jT809_0X9002.Result = (JT809_0x9002_Result)JT809BinaryExtensions.ReadByteLittle(bytes, ref offset); | |||||
readSize = offset; | |||||
return jT809_0X9002; | |||||
} | |||||
public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9002 value) | |||||
{ | |||||
offset += JT809BinaryExtensions.WriteByteLittle(memoryOwner, offset, (byte)value.Result); | |||||
return offset; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,27 @@ | |||||
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_0x9003Formatter : IJT809Formatter<JT809_0x9003> | |||||
{ | |||||
public JT809_0x9003 Deserialize(ReadOnlySpan<byte> bytes, out int readSize) | |||||
{ | |||||
int offset = 0; | |||||
JT809_0x9003 jT809_0X9003 = new JT809_0x9003(); | |||||
jT809_0X9003.VerifyCode = (JT809BinaryExtensions.ReadUInt32Little(bytes, ref offset)); | |||||
readSize = offset; | |||||
return jT809_0X9003; | |||||
} | |||||
public int Serialize(IMemoryOwner<byte> memoryOwner, int offset, JT809_0x9003 value) | |||||
{ | |||||
offset += JT809BinaryExtensions.WriteUInt32Little(memoryOwner, offset, value.VerifyCode); | |||||
return offset; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,25 @@ | |||||
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_CLOSELINIC INFORM</para> | |||||
/// <para>描述:下级平台作为服务端,发现从链路出现异常时,下级平台通过从链路向上级平台发送本消息,通知上级平台下级平台即将关闭主从链路</para> | |||||
/// </summary> | |||||
[JT809Formatter(typeof(JT809_0x1008Formatter))] | |||||
public class JT809_0x1008:JT809Bodies | |||||
{ | |||||
/// <summary> | |||||
/// 错误代码 | |||||
/// </summary> | |||||
public JT809_0x1008_ReasonCode ReasonCode { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,25 @@ | |||||
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>业务数据类型标识:DOWN_CONNECT_REQ</para> | |||||
/// <para>描述:主链路建立连接后,上级平台向下级平台发送从链路连接清求消息,以建立从链路连接</para> | |||||
/// <para>下级平台在收到本息后,根据本校验码 VERIFY CODE 来实现数据的校验,校验后,则返回DOWN CONNECT RSP 消息</para> | |||||
/// </summary> | |||||
[JT809Formatter(typeof(JT809_0x9001Formatter))] | |||||
public class JT809_0x9001 : JT809Bodies | |||||
{ | |||||
/// <summary> | |||||
/// 4.5.1.2 对应的校验码 | |||||
/// </summary> | |||||
public uint VerifyCode { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,25 @@ | |||||
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>业务数据类型标识:DOWN_CONNNECT_RSP</para> | |||||
/// <para>描述:下级平台作为服务器端向上级平台客户端返回从链路连接应答消息,上级平台在接收到该应答消息结果后</para> | |||||
/// </summary> | |||||
[JT809Formatter(typeof(JT809_0x9002Formatter))] | |||||
public class JT809_0x9002:JT809Bodies | |||||
{ | |||||
/// <summary> | |||||
/// 验证结果 | |||||
/// </summary> | |||||
public JT809_0x9002_Result Result { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,24 @@ | |||||
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>业务数据类型标识:DOWN_DISCONNIrCT_REQ</para> | |||||
///<para>描述:从链路建立后,上级平台在取消该链路时,应向下级平台发送从链路注销请求消息</para> | |||||
/// </summary> | |||||
[JT809Formatter(typeof(JT809_0x9003Formatter))] | |||||
public class JT809_0x9003: JT809Bodies | |||||
{ | |||||
/// <summary> | |||||
/// 校验码 | |||||
/// </summary> | |||||
public uint VerifyCode { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,18 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
namespace JT809.Protocol.JT809MessageBody | |||||
{ | |||||
/// <summary> | |||||
/// 从链路注销应答消息 | |||||
/// <para>链路类型:从链路</para> | |||||
/// <para>消息方向:下级平台往上级平台</para> | |||||
/// <para>业务数据类型构之识:DOWN_DISCONNECT_RSP</para> | |||||
/// <para>描述:下级平台在收到上级平台发送的从链路注销请求消息后,返回从链路注销应答消息,记录相关日志,中断该从链路</para> | |||||
/// <para>从链路注销应答消息,数据体为空</para> | |||||
/// </summary> | |||||
public class JT809_0x9004:JT809Bodies | |||||
{ | |||||
} | |||||
} |