-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
380 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
# JT905�� | ||
|
||
[![MIT Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/SmallChi/JT905/blob/main/LICENSE)![.NET Core](https://github.com/SmallChi/JT905/workflows/.NET%20Core/badge.svg?branch=main) | ||
|
||
## ǰ������ | ||
|
||
1. ���ս���ת����������תʮ�����ƣ� | ||
2. ����BCD���롢Hex���룻 | ||
3. ���ո���λ�ơ���� | ||
4. ���ճ��÷��䣻 | ||
5. ����JObject���÷��� | ||
6. ���տ���ctrl+c��ctrl+v�� | ||
7. ����Span\<T\>�Ļ����÷� | ||
8. ��������װ�Ƽ��ܣ��Ϳ��Կ�ʼ��ש�ˡ� | ||
|
||
## JT905���ݽṹ���� | ||
|
||
### ���ݰ�[JT905Package] | ||
|
||
| ͷ��ʶ | ����ͷ | ������ | У���� | β��ʶ | | ||
| :----: | :---------: | :---------: | :----------: | :----: | | ||
| Begin | JT905Header | JT905Bodies |CheckCode | End | | ||
| 7E | - | - | - | 7E | | ||
|
||
### ����ͷ[JT905Header] | ||
|
||
| ��ϢID | ��Ϣ�峤�� | ISU��ʶ | ��Ϣ��ˮ�� | | ||
| :---: | :---: | :---: |:---: | | ||
| MsgId | DataLength | ISU | MsgNum | | ||
|
||
#### ��Ϣ������[JT905Bodies] | ||
|
||
> ���ݶ�Ӧ��ϢID��MsgId | ||
|
||
***ע�⣺��������(��ȥͷ��β��ʶ)����ת���ж�*** | ||
|
||
ת���������: | ||
|
||
1. �������������г����ַ� 0x7e �ģ����滻Ϊ�ַ� 0x7d �����ַ� 0x02; | ||
2. �������������г����ַ� 0x7d �ģ����滻Ϊ�ַ� 0x7d �����ַ� 0x01; | ||
|
||
��ת���ԭ��ȷ��JT905Э���TCP��Ϣ�߽硣 | ||
|
||
### �ٸ�����1 | ||
|
||
#### 1.����� | ||
|
||
> MsgId 0x0200:λ����Ϣ�㱨 | ||
|
||
``` csharp | ||
|
||
JT905Package JT905Package = new JT905Package(); | ||
|
||
JT905Package.Header = new JT905Header | ||
{ | ||
MsgId = Enums.JT905MsgId.λ����Ϣ�㱨.ToUInt16Value(), | ||
ManualMsgNum = 126, | ||
ISU = "103456789012" | ||
}; | ||
|
||
JT905_0x0200 JT905_0x0200 = new JT905_0x0200 | ||
{ | ||
AlarmFlag = 1, | ||
GPSTime = DateTime.Parse("2021-10-15 21:10:10"), | ||
Lat = 12222222, | ||
Lng = 132444444, | ||
Speed = 60, | ||
Direction = 0, | ||
StatusFlag = 2, | ||
BasicLocationAttachData = new Dictionary<byte, JT905_0x0200_BodyBase>() | ||
}; | ||
|
||
JT905_0x0200.BasicLocationAttachData.Add(JT905Constants.JT905_0x0200_0x01, new JT905_0x0200_0x01 | ||
{ | ||
Mileage = 100 | ||
}); | ||
|
||
JT905_0x0200.BasicLocationAttachData.Add(JT905Constants.JT905_0x0200_0x02, new JT905_0x0200_0x02 | ||
{ | ||
Oil = 125 | ||
}); | ||
|
||
JT905Package.Bodies = JT905_0x0200; | ||
|
||
byte[] data = JT905Serializer.Serialize(JT905Package); | ||
|
||
var hex = data.ToHexString(); | ||
|
||
// ������Hex�� | ||
// 7E02000023103456789012007D02000000010000000200BA7F0E07E4F11C003C002110152110100104000000640202007D01347E | ||
``` | ||
|
||
#### 2.�ֶ������ | ||
|
||
``` csharp | ||
1.ԭ���� | ||
7E 02 00 00 23 10 34 56 78 90 12 00 (7D 02) 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 3C 00 21 10 15 21 10 10 01 04 00 00 00 64 02 02 00 (7D 01) 34 7E | ||
|
||
2.���з�ת�� | ||
7D 02 ->7E | ||
7D 01 ->7D | ||
��ת��� | ||
7E 02 00 00 23 10 34 56 78 90 12 00 7E 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 3C 00 21 10 15 21 10 10 01 04 00 00 00 64 02 02 00 7D 34 7E | ||
|
||
3.��� | ||
7E --ͷ��ʶ | ||
02 00 --����ͷ->��ϢID | ||
00 23 --����ͷ->��Ϣ������ | ||
10 34 56 78 90 12 --����ͷ->�ն��ֻ��� | ||
00 7E --����ͷ->��Ϣ��ˮ�� | ||
00 00 00 01 --��Ϣ��->������־ | ||
00 00 00 02 --��Ϣ��->״̬λ��־ | ||
00 BA 7F 0E --��Ϣ��->γ�� | ||
07 E4 F1 1C --��Ϣ��->���� | ||
00 3C --��Ϣ��->�ٶ� | ||
00 --��Ϣ��->���� | ||
21 10 15 21 10 10 --��Ϣ��->GPSʱ�� | ||
01 --��Ϣ��->������Ϣ->��� | ||
04 --��Ϣ��->������Ϣ->���� | ||
00 00 00 64 --��Ϣ��->������Ϣ->���� | ||
02 --��Ϣ��->������Ϣ->���� | ||
02 --��Ϣ��->������Ϣ->���� | ||
00 7D --��Ϣ��->������Ϣ->���� | ||
34 --������ | ||
7E --β��ʶ | ||
``` | ||
|
||
#### 3.�������� | ||
|
||
``` csharp | ||
//1.ת��byte���� | ||
byte[] bytes = "7E02000023103456789012007D02000000010000000200BA7F0E07E4F11C003C002110152110100104000000640202007D01347E".ToHexBytes(); | ||
|
||
//2.�����鷴���л� | ||
var jT905Package = JT905Serializer.Deserialize<JT905Package>(bytes); | ||
|
||
//3.���ݰ�ͷ | ||
Assert.Equal(Enums.JT905MsgId.λ����Ϣ�㱨.ToValue(), jT905Package.Header.MsgId); | ||
Assert.Equal(0x23, jT905Package.Header.DataLength); | ||
Assert.Equal(126, jT905Package.Header.MsgNum); | ||
Assert.Equal("103456789012", jT905Package.Header.ISU); | ||
|
||
//4.���ݰ��� | ||
JT905_0x0200 jT905_0x0200 = (JT905_0x0200)jT905Package.Bodies; | ||
Assert.Equal((uint)1, jT905_0x0200.AlarmFlag); | ||
Assert.Equal(DateTime.Parse("2021-10-15 21:10:10"), jT905_0x0200.GPSTime); | ||
Assert.Equal(12222222, jT905_0x0200.Lat); | ||
Assert.Equal(132444444, jT905_0x0200.Lng); | ||
Assert.Equal(60, jT905_0x0200.Speed); | ||
Assert.Equal(0, jT905_0x0200.Direction); | ||
Assert.Equal((uint)2, jT905_0x0200.StatusFlag); | ||
//4.1.������Ϣ1 | ||
Assert.Equal(100, ((JT905_0x0200_0x01)jT905_0x0200.BasicLocationAttachData[JT905Constants.JT905_0x0200_0x01]).Mileage); | ||
//4.2.������Ϣ2 | ||
Assert.Equal(125, ((JT905_0x0200_0x02)jT905_0x0200.BasicLocationAttachData[JT905Constants.JT905_0x0200_0x02]).Oil); | ||
``` | ||
|
||
## NuGet��װ | ||
|
||
| Package Name| Version| Preview Version |Downloads|Remark| | ||
| --- | --- | --- | ---| --- | | ||
| Install-Package JT905 | ![JT905](https://img.shields.io/nuget/v/JT905.svg) | ![JT905](https://img.shields.io/nuget/vpre/JT905.svg)|![JT905](https://img.shields.io/nuget/dt/JT905.svg) |JT905| | ||
|
||
## ʹ��BenchmarkDotNet���ܲ��Ա��棨ֻ�����棬���ܵ��棩 | ||
|
||
> todo: | ||
|
||
|
||
## JT905�ն�ͨѶЭ����Ϣ���ձ� | ||
|
||
| ��� | ��ϢID | ������ | ������� | ��Ϣ������ | | ||
| :---: | :---: | :---: | :---: | :--- | | ||
| 1 | 0x0200 | �� | X | λ����Ϣ�㱨 | | ||
|
||
> todo: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using JT905.Protocol.Extensions; | ||
using JT905.Protocol.Internal; | ||
using JT905.Protocol.MessageBody; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace JT905.Protocol.Test.MessageBody | ||
{ | ||
public class JT905_0x0001_Test | ||
{ | ||
public JT905Serializer JT905Serializer; | ||
public JT905_0x0001_Test() | ||
{ | ||
IJT905Config JT905Config = new DefaultGlobalConfig(); | ||
JT905Config.SkipCRCCode = true; | ||
JT905Serializer = new JT905Serializer(JT905Config); | ||
} | ||
|
||
[Fact] | ||
public void Test1() | ||
{ | ||
JT905.Protocol.JT905Package package = new JT905Package { | ||
Header = new JT905Header | ||
{ | ||
MsgId = Enums.JT905MsgId.ISU通用应答.ToUInt16Value(), | ||
ManualMsgNum = 1203, | ||
ISU = "012345678900", | ||
}, | ||
Bodies = new JT905_0x0001 | ||
{ | ||
ReplyMsgId = Enums.JT905MsgId.ISU心跳.ToUInt16Value(), | ||
ReplyMsgNum = 1000, | ||
ISUResult = Enums.JT905ISUResult.Success | ||
} | ||
}; | ||
byte[] vs = JT905Serializer.Serialize(package); | ||
string v = JT905Serializer.Analyze(vs,options:JTJsonWriterOptions.Instance); | ||
|
||
} | ||
|
||
[Fact] | ||
public void Test2() { | ||
JT905Package package = new JT905Package { | ||
Header = new JT905Header | ||
{ | ||
MsgId = Enums.JT905MsgId.ISU心跳.ToUInt16Value(), | ||
ManualMsgNum = 1203, | ||
ISU = "012345678900", | ||
}, | ||
}; | ||
|
||
byte[] vs = JT905Serializer.Serialize(package); | ||
string v = JT905Serializer.Analyze(vs, options: JTJsonWriterOptions.Instance); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using JT905.Protocol.Extensions; | ||
using JT905.Protocol.Internal; | ||
using JT905.Protocol.MessageBody; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace JT905.Protocol.Test.MessageBody | ||
{ | ||
public class JT905_0x0002_Test | ||
{ | ||
public JT905Serializer JT905Serializer; | ||
public JT905_0x0002_Test() | ||
{ | ||
IJT905Config JT905Config = new DefaultGlobalConfig(); | ||
JT905Config.SkipCRCCode = true; | ||
JT905Serializer = new JT905Serializer(JT905Config); | ||
} | ||
|
||
[Fact] | ||
public void Test1() | ||
{ | ||
JT905.Protocol.JT905Package package = new JT905Package { | ||
Header = new JT905Header | ||
{ | ||
MsgId = Enums.JT905MsgId.ISU心跳.ToUInt16Value(), | ||
ManualMsgNum = 1203, | ||
ISU = "012345678900", | ||
}, | ||
Bodies = new JT905_0x0002() | ||
}; | ||
var vs = JT905Serializer.Serialize(package).ToHexString(); | ||
Assert.Equal("7E0002000001234567890004B33C7E",vs); | ||
//string v = JT905Serializer.Analyze(vs,options:JTJsonWriterOptions.Instance); | ||
|
||
} | ||
|
||
[Fact] | ||
public void Test2() { | ||
var hex = "7E0002000001234567890004B33C7E".ToHexBytes(); | ||
|
||
string v = JT905Serializer.Analyze(hex, options: JTJsonWriterOptions.Instance); | ||
} | ||
|
||
[Fact] | ||
public void Test3() | ||
{ | ||
var hex = "7E0002000001234567890004B33C7E".ToHexBytes(); | ||
JT905Package jT905Package = JT905Serializer.Deserialize(hex); | ||
Assert.Equal(Enums.JT905MsgId.ISU心跳.ToUInt16Value(), jT905Package.Header.MsgId); | ||
Assert.Equal(1203, jT905Package.Header.MsgNum); | ||
Assert.Equal("12345678900", jT905Package.Header.ISU); | ||
Assert.Null(jT905Package.Bodies); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using JT905.Protocol.Extensions; | ||
using JT905.Protocol.MessageBody; | ||
using Xunit; | ||
|
||
namespace JT905.Protocol.Test.MessageBody | ||
{ | ||
public class JT905_0x8001_Test | ||
{ | ||
JT905Serializer JT905Serializer = new JT905Serializer(); | ||
[Fact] | ||
public void Test1() | ||
{ | ||
JT905Package JT905Package = new JT905Package | ||
{ | ||
Header = new JT905Header | ||
{ | ||
MsgId = Enums.JT905MsgId.中心通用应答.ToUInt16Value(), | ||
ManualMsgNum = 10, | ||
ISU = "12345678900", | ||
}, | ||
Bodies = new JT905_0x8001 | ||
{ | ||
ReplyMsgId = Enums.JT905MsgId.位置信息汇报.ToUInt16Value(), | ||
ISUResult = Enums.JT905ISUResult.Success, | ||
ReplyMsgNum = 100 | ||
} | ||
}; | ||
//"7E | ||
//80 01 | ||
//00 05 | ||
//01 23 45 67 89 00 | ||
//00 0A | ||
//00 64 | ||
//02 00 | ||
//00 | ||
//61 | ||
//7E" | ||
var hex = JT905Serializer.Serialize(JT905Package).ToHexString(); | ||
Assert.Equal("7E80010005012345678900000A0064020000617E", hex); | ||
} | ||
|
||
[Fact] | ||
public void Test2() | ||
{ | ||
var bytes = "7E 80 01 00 05 01 23 45 67 89 00 00 0A 00 64 02 00 00 61 7E".ToHexBytes(); | ||
JT905Package JT905Package = JT905Serializer.Deserialize<JT905Package>(bytes); | ||
Assert.Equal(Enums.JT905MsgId.中心通用应答.ToUInt16Value(), JT905Package.Header.MsgId); | ||
Assert.Equal(10, JT905Package.Header.MsgNum); | ||
Assert.Equal("12345678900", JT905Package.Header.ISU); | ||
|
||
JT905_0x8001 JT905Bodies = (JT905_0x8001)JT905Package.Bodies; | ||
Assert.Equal(Enums.JT905MsgId.位置信息汇报.ToUInt16Value(), JT905Bodies.ReplyMsgId); | ||
Assert.Equal(100, JT905Bodies.ReplyMsgNum); | ||
Assert.Equal(Enums.JT905ISUResult.Success, JT905Bodies.ISUResult); | ||
} | ||
|
||
[Fact] | ||
public void Test3() | ||
{ | ||
var bytes = "7E 80 01 00 05 01 23 45 67 89 00 00 0A 00 64 02 00 00 61 7E".ToHexBytes(); | ||
string json = JT905Serializer.Analyze<JT905Package>(bytes); | ||
} | ||
} | ||
} |
Oops, something went wrong.