@@ -0,0 +1,330 @@ | |||||
## Ignore Visual Studio temporary files, build results, and | |||||
## files generated by popular Visual Studio add-ons. | |||||
## | |||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore | |||||
# User-specific files | |||||
*.suo | |||||
*.user | |||||
*.userosscache | |||||
*.sln.docstates | |||||
# User-specific files (MonoDevelop/Xamarin Studio) | |||||
*.userprefs | |||||
# Build results | |||||
[Dd]ebug/ | |||||
[Dd]ebugPublic/ | |||||
[Rr]elease/ | |||||
[Rr]eleases/ | |||||
x64/ | |||||
x86/ | |||||
bld/ | |||||
[Bb]in/ | |||||
[Oo]bj/ | |||||
[Ll]og/ | |||||
# Visual Studio 2015/2017 cache/options directory | |||||
.vs/ | |||||
# Uncomment if you have tasks that create the project's static files in wwwroot | |||||
#wwwroot/ | |||||
# Visual Studio 2017 auto generated files | |||||
Generated\ Files/ | |||||
# MSTest test Results | |||||
[Tt]est[Rr]esult*/ | |||||
[Bb]uild[Ll]og.* | |||||
# NUNIT | |||||
*.VisualState.xml | |||||
TestResult.xml | |||||
# Build Results of an ATL Project | |||||
[Dd]ebugPS/ | |||||
[Rr]eleasePS/ | |||||
dlldata.c | |||||
# Benchmark Results | |||||
BenchmarkDotNet.Artifacts/ | |||||
# .NET Core | |||||
project.lock.json | |||||
project.fragment.lock.json | |||||
artifacts/ | |||||
**/Properties/launchSettings.json | |||||
# StyleCop | |||||
StyleCopReport.xml | |||||
# Files built by Visual Studio | |||||
*_i.c | |||||
*_p.c | |||||
*_i.h | |||||
*.ilk | |||||
*.meta | |||||
*.obj | |||||
*.iobj | |||||
*.pch | |||||
*.pdb | |||||
*.ipdb | |||||
*.pgc | |||||
*.pgd | |||||
*.rsp | |||||
*.sbr | |||||
*.tlb | |||||
*.tli | |||||
*.tlh | |||||
*.tmp | |||||
*.tmp_proj | |||||
*.log | |||||
*.vspscc | |||||
*.vssscc | |||||
.builds | |||||
*.pidb | |||||
*.svclog | |||||
*.scc | |||||
# Chutzpah Test files | |||||
_Chutzpah* | |||||
# Visual C++ cache files | |||||
ipch/ | |||||
*.aps | |||||
*.ncb | |||||
*.opendb | |||||
*.opensdf | |||||
*.sdf | |||||
*.cachefile | |||||
*.VC.db | |||||
*.VC.VC.opendb | |||||
# Visual Studio profiler | |||||
*.psess | |||||
*.vsp | |||||
*.vspx | |||||
*.sap | |||||
# Visual Studio Trace Files | |||||
*.e2e | |||||
# TFS 2012 Local Workspace | |||||
$tf/ | |||||
# Guidance Automation Toolkit | |||||
*.gpState | |||||
# ReSharper is a .NET coding add-in | |||||
_ReSharper*/ | |||||
*.[Rr]e[Ss]harper | |||||
*.DotSettings.user | |||||
# JustCode is a .NET coding add-in | |||||
.JustCode | |||||
# TeamCity is a build add-in | |||||
_TeamCity* | |||||
# DotCover is a Code Coverage Tool | |||||
*.dotCover | |||||
# AxoCover is a Code Coverage Tool | |||||
.axoCover/* | |||||
!.axoCover/settings.json | |||||
# Visual Studio code coverage results | |||||
*.coverage | |||||
*.coveragexml | |||||
# NCrunch | |||||
_NCrunch_* | |||||
.*crunch*.local.xml | |||||
nCrunchTemp_* | |||||
# MightyMoose | |||||
*.mm.* | |||||
AutoTest.Net/ | |||||
# Web workbench (sass) | |||||
.sass-cache/ | |||||
# Installshield output folder | |||||
[Ee]xpress/ | |||||
# DocProject is a documentation generator add-in | |||||
DocProject/buildhelp/ | |||||
DocProject/Help/*.HxT | |||||
DocProject/Help/*.HxC | |||||
DocProject/Help/*.hhc | |||||
DocProject/Help/*.hhk | |||||
DocProject/Help/*.hhp | |||||
DocProject/Help/Html2 | |||||
DocProject/Help/html | |||||
# Click-Once directory | |||||
publish/ | |||||
# Publish Web Output | |||||
*.[Pp]ublish.xml | |||||
*.azurePubxml | |||||
# Note: Comment the next line if you want to checkin your web deploy settings, | |||||
# but database connection strings (with potential passwords) will be unencrypted | |||||
*.pubxml | |||||
*.publishproj | |||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to | |||||
# checkin your Azure Web App publish settings, but sensitive information contained | |||||
# in these scripts will be unencrypted | |||||
PublishScripts/ | |||||
# NuGet Packages | |||||
*.nupkg | |||||
# The packages folder can be ignored because of Package Restore | |||||
**/[Pp]ackages/* | |||||
# except build/, which is used as an MSBuild target. | |||||
!**/[Pp]ackages/build/ | |||||
# Uncomment if necessary however generally it will be regenerated when needed | |||||
#!**/[Pp]ackages/repositories.config | |||||
# NuGet v3's project.json files produces more ignorable files | |||||
*.nuget.props | |||||
*.nuget.targets | |||||
# Microsoft Azure Build Output | |||||
csx/ | |||||
*.build.csdef | |||||
# Microsoft Azure Emulator | |||||
ecf/ | |||||
rcf/ | |||||
# Windows Store app package directories and files | |||||
AppPackages/ | |||||
BundleArtifacts/ | |||||
Package.StoreAssociation.xml | |||||
_pkginfo.txt | |||||
*.appx | |||||
# Visual Studio cache files | |||||
# files ending in .cache can be ignored | |||||
*.[Cc]ache | |||||
# but keep track of directories ending in .cache | |||||
!*.[Cc]ache/ | |||||
# Others | |||||
ClientBin/ | |||||
~$* | |||||
*~ | |||||
*.dbmdl | |||||
*.dbproj.schemaview | |||||
*.jfm | |||||
*.pfx | |||||
*.publishsettings | |||||
orleans.codegen.cs | |||||
# Including strong name files can present a security risk | |||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424) | |||||
#*.snk | |||||
# Since there are multiple workflows, uncomment next line to ignore bower_components | |||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) | |||||
#bower_components/ | |||||
# RIA/Silverlight projects | |||||
Generated_Code/ | |||||
# Backup & report files from converting an old project file | |||||
# to a newer Visual Studio version. Backup files are not needed, | |||||
# because we have git ;-) | |||||
_UpgradeReport_Files/ | |||||
Backup*/ | |||||
UpgradeLog*.XML | |||||
UpgradeLog*.htm | |||||
ServiceFabricBackup/ | |||||
*.rptproj.bak | |||||
# SQL Server files | |||||
*.mdf | |||||
*.ldf | |||||
*.ndf | |||||
# Business Intelligence projects | |||||
*.rdl.data | |||||
*.bim.layout | |||||
*.bim_*.settings | |||||
*.rptproj.rsuser | |||||
# Microsoft Fakes | |||||
FakesAssemblies/ | |||||
# GhostDoc plugin setting file | |||||
*.GhostDoc.xml | |||||
# Node.js Tools for Visual Studio | |||||
.ntvs_analysis.dat | |||||
node_modules/ | |||||
# Visual Studio 6 build log | |||||
*.plg | |||||
# Visual Studio 6 workspace options file | |||||
*.opt | |||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) | |||||
*.vbw | |||||
# Visual Studio LightSwitch build output | |||||
**/*.HTMLClient/GeneratedArtifacts | |||||
**/*.DesktopClient/GeneratedArtifacts | |||||
**/*.DesktopClient/ModelManifest.xml | |||||
**/*.Server/GeneratedArtifacts | |||||
**/*.Server/ModelManifest.xml | |||||
_Pvt_Extensions | |||||
# Paket dependency manager | |||||
.paket/paket.exe | |||||
paket-files/ | |||||
# FAKE - F# Make | |||||
.fake/ | |||||
# JetBrains Rider | |||||
.idea/ | |||||
*.sln.iml | |||||
# CodeRush | |||||
.cr/ | |||||
# Python Tools for Visual Studio (PTVS) | |||||
__pycache__/ | |||||
*.pyc | |||||
# Cake - Uncomment if you are using it | |||||
# tools/** | |||||
# !tools/packages.config | |||||
# Tabs Studio | |||||
*.tss | |||||
# Telerik's JustMock configuration file | |||||
*.jmconfig | |||||
# BizTalk build output | |||||
*.btp.cs | |||||
*.btm.cs | |||||
*.odx.cs | |||||
*.xsd.cs | |||||
# OpenCover UI analysis results | |||||
OpenCover/ | |||||
# Azure Stream Analytics local run output | |||||
ASALocalRun/ | |||||
# MSBuild Binary and Structured Log | |||||
*.binlog | |||||
# NVidia Nsight GPU debugger configuration file | |||||
*.nvuser | |||||
# MFractors (Xamarin productivity tool) working folder | |||||
.mfractor/ |
@@ -0,0 +1,15 @@ | |||||
language: csharp | |||||
solution: JT808.Protocol.sln | |||||
dotnet: 2.2.101 | |||||
os: linux | |||||
mono: none | |||||
dist: trusty2 | |||||
script: | |||||
- dotnet restore src/JT808.Protocol.sln | |||||
- dotnet build src/JT808.Protocol.Test/JT808.Protocol.Test.csproj | |||||
- dotnet test src/JT808.Protocol.Test/JT808.Protocol.Test.csproj | |||||
after_success: | |||||
- echo successful build! | |||||
branches: | |||||
only: | |||||
- master |
@@ -0,0 +1,21 @@ | |||||
MIT License | |||||
Copyright (c) 2018 SmallChi(Koike) | |||||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||||
of this software and associated documentation files (the "Software"), to deal | |||||
in the Software without restriction, including without limitation the rights | |||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||||
copies of the Software, and to permit persons to whom the Software is | |||||
furnished to do so, subject to the following conditions: | |||||
The above copyright notice and this permission notice shall be included in all | |||||
copies or substantial portions of the Software. | |||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||||
SOFTWARE. |
@@ -0,0 +1,377 @@ | |||||
# JT808协议 | |||||
[](https://github.com/SmallChi/JT808/blob/master/LICENSE)[](https://app.fossa.io/projects/git%2Bgithub.com%2FSmallChi%2FJT808?ref=badge_shield)[](https://travis-ci.org/SmallChi/JT808) | |||||
## 前提条件 | |||||
1. 掌握进制转换:二进制转十六进制; | |||||
2. 掌握BCD编码、Hex编码; | |||||
3. 掌握各种位移、异或; | |||||
4. 掌握常用反射; | |||||
5. 掌握快速ctrl+c、ctrl+v; | |||||
6. 掌握Span\<T\>的基本用法 | |||||
7. 掌握以上装逼技能,就可以开始搬砖了。 | |||||
## JT808数据结构解析 | |||||
### 数据包[JT808Package] | |||||
| 头标识 | 数据头 | 数据体 | 校验码 | 尾标识 | | |||||
| :----: | :---------: | :---------: | :-------: | :----: | | |||||
| Begin | JT808Header | JT808Bodies | CheckCode | End | | |||||
| 7E | - | - | - | 7E | | |||||
### 数据头[JT808Header] | |||||
| 消息ID | 消息体属性 | 终端手机号 | 消息流水号 | | |||||
| :----: | :----------------------------: | :-------------: | :--------: | | |||||
| MsgId | JT808HeaderMessageBodyProperty | TerminalPhoneNo | MsgNum | | |||||
#### 数据头-消息体属性[JT808HeaderMessageBodyProperty] | |||||
| 是否分包 | 加密标识 | 消息体长度 | 消息总包数 | 包序号 | | |||||
| :------: | :------: | :--------: | :---------: | :----------: | | |||||
| IsPackge | Encrypt | DataLength | PackgeCount | PackageIndex | | |||||
#### 消息体属性[JT808Bodies] | |||||
> 根据对应消息ID:MsgId | |||||
***注意:数据内容(除去头和尾标识)进行转义判断*** | |||||
转义规则如下: | |||||
1. 若数据内容中有出现字符 0x7e 的,需替换为字符 0x7d 紧跟字符 0x02; | |||||
2. 若数据内容中有出现字符 0x7d 的,需替换为字符 0x7d 紧跟字符 0x01; | |||||
反转义的原因:确认JT808协议的TCP消息边界。 | |||||
### 举个栗子1 | |||||
#### 1.组包: | |||||
> MsgId 0x0200:位置信息汇报 | |||||
``` package | |||||
JT808Package jT808Package = new JT808Package(); | |||||
jT808Package.Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.位置信息汇报, | |||||
MsgNum = 126, | |||||
TerminalPhoneNo = "123456789012" | |||||
}; | |||||
JT808_0x0200 jT808_0x0200 = new JT808_0x0200(); | |||||
jT808_0x0200.AlarmFlag = 1; | |||||
jT808_0x0200.Altitude = 40; | |||||
jT808_0x0200.GPSTime = DateTime.Parse("2018-10-15 10:10:10"); | |||||
jT808_0x0200.Lat = 12222222; | |||||
jT808_0x0200.Lng = 132444444; | |||||
jT808_0x0200.Speed = 60; | |||||
jT808_0x0200.Direction = 0; | |||||
jT808_0x0200.StatusFlag = 2; | |||||
jT808_0x0200.JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>(); | |||||
jT808_0x0200.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
jT808_0x0200.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 125 | |||||
}); | |||||
jT808Package.Bodies = jT808_0x0200; | |||||
byte[] data = JT808Serializer.Serialize(jT808Package); | |||||
var hex = data.ToHexString(); | |||||
// 输出结果Hex: | |||||
// 7E 02 00 00 26 12 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 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E | |||||
``` | |||||
#### 2.手动解包: | |||||
``` unpackage | |||||
1.原包: | |||||
7E 02 00 00 26 12 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 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 (7D 01) 13 7E | |||||
2.进行反转义 | |||||
7D 02 ->7E | |||||
7D 01 ->7D | |||||
反转义后 | |||||
7E 02 00 00 26 12 34 56 78 90 12 00 7E 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 13 7E | |||||
3.拆解 | |||||
7E --头标识 | |||||
02 00 --数据头->消息ID | |||||
00 26 --数据头->消息体属性 | |||||
12 34 56 78 90 12 --数据头->终端手机号 | |||||
00 7E --数据头->消息流水号 | |||||
00 00 00 01 --消息体->报警标志 | |||||
00 00 00 02 --消息体->状态位标志 | |||||
00 BA 7F 0E --消息体->纬度 | |||||
07 E4 F1 1C --消息体->经度 | |||||
00 28 --消息体->海拔高度 | |||||
00 3C --消息体->速度 | |||||
00 00 --消息体->方向 | |||||
18 10 15 10 10 10 --消息体->GPS时间 | |||||
01 --消息体->附加信息->里程 | |||||
04 --消息体->附加信息->长度 | |||||
00 00 00 64 --消息体->附加信息->数据 | |||||
02 --消息体->附加信息->油量 | |||||
02 --消息体->附加信息->长度 | |||||
00 7D --消息体->附加信息->数据 | |||||
13 --检验码 | |||||
7E --尾标识 | |||||
``` | |||||
#### 3.程序解包: | |||||
``` unpackage2 | |||||
//1.转成byte数组 | |||||
byte[] bytes = "7E 02 00 00 26 12 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 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E".ToHexBytes(); | |||||
//2.将数组反序列化 | |||||
var jT808Package = JT808Serializer.Deserialize(bytes); | |||||
//3.数据包头 | |||||
Assert.Equal(Enums.JT808MsgId.位置信息汇报, jT808Package.Header.MsgId); | |||||
Assert.Equal(38, jT808Package.Header.MessageBodyProperty.DataLength); | |||||
Assert.Equal(126, jT808Package.Header.MsgNum); | |||||
Assert.Equal("123456789012", jT808Package.Header.TerminalPhoneNo); | |||||
Assert.False(jT808Package.Header.MessageBodyProperty.IsPackge); | |||||
Assert.Equal(0, jT808Package.Header.MessageBodyProperty.PackageIndex); | |||||
Assert.Equal(0, jT808Package.Header.MessageBodyProperty.PackgeCount); | |||||
Assert.Equal(JT808EncryptMethod.None, jT808Package.Header.MessageBodyProperty.Encrypt); | |||||
//4.数据包体 | |||||
JT808_0x0200 jT808_0x0200 = (JT808_0x0200)jT808Package.Bodies; | |||||
Assert.Equal((uint)1, jT808_0x0200.AlarmFlag); | |||||
Assert.Equal((uint)40, jT808_0x0200.Altitude); | |||||
Assert.Equal(DateTime.Parse("2018-10-15 10:10:10"), jT808_0x0200.GPSTime); | |||||
Assert.Equal(12222222, jT808_0x0200.Lat); | |||||
Assert.Equal(132444444, jT808_0x0200.Lng); | |||||
Assert.Equal(60, jT808_0x0200.Speed); | |||||
Assert.Equal(0, jT808_0x0200.Direction); | |||||
Assert.Equal((uint)2, jT808_0x0200.StatusFlag); | |||||
//4.1.附加信息1 | |||||
Assert.Equal(100, ((JT808_0x0200_0x01)jT808_0x0200.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x01]).Mileage); | |||||
//4.2.附加信息2 | |||||
Assert.Equal(125, ((JT808_0x0200_0x02)jT808_0x0200.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x02]).Oil); | |||||
``` | |||||
### 举个栗子2 | |||||
``` create package | |||||
// 使用消息Id的扩展方法创建JT808Package包 | |||||
JT808Package jT808Package = Enums.JT808MsgId.位置信息汇报.Create("123456789012", | |||||
new JT808_0x0200 { | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-10-15 10:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808LocationAttachBase> | |||||
{ | |||||
{ JT808_0x0200_BodyBase.AttachId0x01,new JT808_0x0200_0x01{Mileage = 100}}, | |||||
{ JT808_0x0200_BodyBase.AttachId0x02,new JT808_0x0200_0x02{Oil = 125}} | |||||
} | |||||
}); | |||||
byte[] data = JT808Serializer.Serialize(jT808Package); | |||||
var hex = data.ToHexString(); | |||||
//输出结果Hex: | |||||
//7E 02 00 00 26 12 34 56 78 90 12 00 01 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 6C 7E | |||||
``` | |||||
### 举个栗子3 | |||||
``` config | |||||
// 初始化配置 | |||||
IJT808Config jT808Config = DefaultGlobalConfig.Create(); | |||||
// 注册自定义消息外部程序集 | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
// 跳过校验和验证 | |||||
jT808Config.SkipCRCCode = true; | |||||
// 根据不同的设备终端号,添加自定义消息Id | |||||
jT808Config.MsgIdFactory.CustomSetMap<DT1Demo6>(0x91, "1234567891"); | |||||
jT808Config.MsgIdFactory.CustomSetMap<DT2Demo6>(0x91, "1234567892"); | |||||
// 初始化序列化实例 | |||||
JT808Serializer JT808Serializer = new JT808Serializer(jT808Coonfig); | |||||
``` | |||||
### 举个栗子4 | |||||
#### 遇到的问题-多设备多协议的自定义位置附加信息 | |||||
场景: | |||||
一个设备厂商对应多个设备类型,不同设备类型可能存在相同的自定义位置附加信息Id,导致自定义附加信息Id冲突,无法解析。 | |||||
***解决方式:*** | |||||
1.凡是解析自定义附加信息Id协议的,先进行分割存储,然后在根据外部的设备类型进行统一处理; | |||||
2.可以根据设备类型做个工厂,解耦对公共序列化器的依赖。 | |||||
[可以参考Simples的Demo4](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo4.cs) | |||||
> 要是哪位大佬还有其他的解决方式,请您告知我下,谢谢您了。 | |||||
### 举个栗子5 | |||||
#### 遇到的问题-多媒体数据上传进行分包处理 | |||||
场景: | |||||
设备在上传多媒体数据的时候,由于数据比较多,一次上传不了,所以采用分包方式处理。 | |||||
***解决方式:*** | |||||
1. 第一包数据上来采用平常的方式去解析数据; | |||||
2. 当N包数据上来,采用统一分包消息体去接收数据,最后在合并成一条。 | |||||
> 普及知识点:一般行业分包是按256的整数倍,太多不行,太少也不行,必须刚刚好。 | |||||
[可以参考Simples的Demo5](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo5.cs) | |||||
### 举个栗子6 | |||||
#### 遇到的问题-多设备多协议的消息ID冲突 | |||||
场景: | |||||
由于每个设备厂商不同,导致设备的私有协议可能使用相同的消息ID作为指令,导致平台解析不了。 | |||||
***解决方式:*** | |||||
对于设备来说,设备终端号是唯一标识,可以通过使用设备终端号和消息ID去查询对应的序列化器。 | |||||
[可以参考Simples的Demo6](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo6.cs) | |||||
## NuGet安装 | |||||
| Package Name | Version | Downloads | | |||||
| --------------------- | -------------------------------------------------- | --------------------------------------------------- | | |||||
| Install-Package JT808 |  |  | | |||||
| Install-Package JT808.Extensions.DependencyInjection |  |  | | |||||
## 使用BenchmarkDotNet性能测试报告(只是玩玩,不能当真) | |||||
``` ini | |||||
BenchmarkDotNet=v0.11.5, OS=Windows 10.0.17763.557 (1809/October2018Update/Redstone5) | |||||
Intel Core i7-8700K CPU 3.70GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores | |||||
[Host] : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3362.0 | |||||
Job-FVMQGI : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3362.0 | |||||
Job-LGLQDK : .NET Core 2.2.5 (CoreCLR 4.6.27617.05, CoreFX 4.6.27618.01), 64bit RyuJIT | |||||
Platform=AnyCpu Runtime=Clr Server=False | |||||
``` | |||||
| Method | Toolchain | Categories | N | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | | |||||
|-------------------------------- |-------------- |----------------- |------- |---------------:|---------------:|---------------:|------------:|------:|------:|-------------:| | |||||
| **0x0200_All_AttachId_Serialize** | **Default** | **0x0200Serializer** | **100** | **2,738.7 us** | **35.0088 us** | **32.7472 us** | **35.1563** | **-** | **-** | **216.41 KB** | | |||||
| 0x0200_All_AttachId_Deserialize | Default | 0x0200Serializer | 100 | 3,538.1 us | 11.0285 us | 10.3161 us | 101.5625 | - | - | 642.21 KB | | |||||
| 0x0200_All_AttachId_Serialize | .NET Core 2.2 | 0x0200Serializer | 100 | 2,363.2 us | 20.2865 us | 18.9760 us | 35.1563 | - | - | 216.41 KB | | |||||
| 0x0200_All_AttachId_Deserialize | .NET Core 2.2 | 0x0200Serializer | 100 | 3,164.9 us | 6.5366 us | 6.1143 us | 85.9375 | - | - | 529.69 KB | | |||||
| **0x0200_All_AttachId_Serialize** | **Default** | **0x0200Serializer** | **10000** | **274,593.1 us** | **1,039.6220 us** | **921.5978 us** | **3500.0000** | **-** | **-** | **21644.48 KB** | | |||||
| 0x0200_All_AttachId_Deserialize | Default | 0x0200Serializer | 10000 | 350,085.6 us | 970.7176 us | 908.0098 us | 10000.0000 | - | - | 64225.99 KB | | |||||
| 0x0200_All_AttachId_Serialize | .NET Core 2.2 | 0x0200Serializer | 10000 | 234,316.8 us | 465.8545 us | 412.9679 us | 3333.3333 | - | - | 21640.63 KB | | |||||
| 0x0200_All_AttachId_Deserialize | .NET Core 2.2 | 0x0200Serializer | 10000 | 320,220.8 us | 1,991.8278 us | 1,863.1570 us | 8000.0000 | - | - | 52968.75 KB | | |||||
| **0x0200_All_AttachId_Serialize** | **Default** | **0x0200Serializer** | **100000** | **2,712,565.1 us** | **18,460.3868 us** | **17,267.8572 us** | **35000.0000** | **-** | **-** | **216412.65 KB** | | |||||
| 0x0200_All_AttachId_Deserialize | Default | 0x0200Serializer | 100000 | 3,592,549.6 us | 38,841.1809 us | 36,332.0647 us | 104000.0000 | - | - | 642194.54 KB | | |||||
| 0x0200_All_AttachId_Serialize | .NET Core 2.2 | 0x0200Serializer | 100000 | 2,464,747.5 us | 10,310.9610 us | 9,140.3984 us | 35000.0000 | - | - | 216406.25 KB | | |||||
| 0x0200_All_AttachId_Deserialize | .NET Core 2.2 | 0x0200Serializer | 100000 | 3,258,521.7 us | 19,946.9515 us | 17,682.4529 us | 86000.0000 | - | - | 529687.5 KB | | |||||
| | | | | | | | | | | | | |||||
| **0x0100Serialize** | **Default** | **0x0100Serializer** | **100** | **327.8 us** | **4.3377 us** | **4.0575 us** | **15.1367** | **-** | **-** | **93.75 KB** | | |||||
| 0x0100Deserialize | Default | 0x0100Serializer | 100 | 334.6 us | 1.9826 us | 1.6556 us | 21.4844 | - | - | 132.03 KB | | |||||
| 0x0100Serialize | .NET Core 2.2 | 0x0100Serializer | 100 | 249.6 us | 1.6019 us | 1.4985 us | 13.6719 | - | - | 85.94 KB | | |||||
| 0x0100Deserialize | .NET Core 2.2 | 0x0100Serializer | 100 | 270.0 us | 0.9267 us | 0.7235 us | 21.4844 | - | - | 132.03 KB | | |||||
| **0x0100Serialize** | **Default** | **0x0100Serializer** | **10000** | **32,514.3 us** | **244.6675 us** | **228.8622 us** | **1500.0000** | **-** | **-** | **9375.11 KB** | | |||||
| 0x0100Deserialize | Default | 0x0100Serializer | 10000 | 34,035.9 us | 194.8483 us | 182.2612 us | 2133.3333 | - | - | 13203.35 KB | | |||||
| 0x0100Serialize | .NET Core 2.2 | 0x0100Serializer | 10000 | 24,874.6 us | 35.8662 us | 33.5493 us | 1375.0000 | - | - | 8593.75 KB | | |||||
| 0x0100Deserialize | .NET Core 2.2 | 0x0100Serializer | 10000 | 28,835.0 us | 286.1119 us | 253.6307 us | 2125.0000 | - | - | 13203.13 KB | | |||||
| **0x0100Serialize** | **Default** | **0x0100Serializer** | **100000** | **341,547.6 us** | **4,437.9179 us** | **3,934.0986 us** | **15000.0000** | **-** | **-** | **93753.05 KB** | | |||||
| 0x0100Deserialize | Default | 0x0100Serializer | 100000 | 348,338.5 us | 3,373.6509 us | 3,155.7151 us | 21000.0000 | - | - | 132033.48 KB | | |||||
| 0x0100Serialize | .NET Core 2.2 | 0x0100Serializer | 100000 | 255,128.1 us | 2,711.3270 us | 2,536.1770 us | 13500.0000 | - | - | 85937.5 KB | | |||||
| 0x0100Deserialize | .NET Core 2.2 | 0x0100Serializer | 100000 | 284,679.7 us | 3,831.0625 us | 3,396.1371 us | 21000.0000 | - | - | 132031.25 KB | | |||||
## JT808终端通讯协议消息对照表 | |||||
| 序号 | 消息ID | 完成情况 | 测试情况 | 消息体名称 | | |||||
| :---: | :-----------: | :------: | :------: | :----------------------------: | | |||||
| 1 | 0x0001 | √ | √ | 终端通用应答 | | |||||
| 2 | 0x8001 | √ | √ | 平台通用应答 | | |||||
| 3 | 0x0002 | √ | √ | 终端心跳 | | |||||
| 4 | 0x8003 | √ | √ | 补传分包请求 | | |||||
| 5 | 0x0100 | √ | √ | 终端注册 | | |||||
| 6 | 0x8100 | √ | √ | 终端注册应答 | | |||||
| 7 | 0x0003 | √ | √ | 终端注销 | | |||||
| 8 | 0x0102 | √ | √ | 终端鉴权 | | |||||
| 9 | 0x8103 | √ | √ | 设置终端参数 | | |||||
| 10 | 0x8104 | √ | √ | 查询终端参数 | | |||||
| 11 | 0x0104 | √ | √ | 查询终端参数应答 | | |||||
| 12 | 0x8105 | √ | √ | 终端控制 | | |||||
| 13 | 0x8106 | √ | √ | 查询指定终端参数 | | |||||
| 14 | 0x8107 | √ | 消息体为空| 查询终端属性 | | |||||
| 15 | 0x0107 | √ | √ | 查询终端属性应答 | | |||||
| 16 | 0x8108 | √ | √ | 下发终端升级包 | | |||||
| 17 | 0x0108 | √ | √ | 终端升级结果通知 | | |||||
| 18 | 0x0200 | √ | √ | 位置信息汇报 | | |||||
| 19 | 0x8201 | √ | √ | 位置信息查询 | | |||||
| 20 | 0x0201 | √ | √ | 位置信息查询应答 | | |||||
| 21 | 0x8202 | √ | √ | 临时位置跟踪控制 | | |||||
| 22 | 0x8203 | √ | √ | 人工确认报警消息 | | |||||
| 23 | 0x8300 | √ | √ | 文本信息下发 | | |||||
| 24 | 0x8301 | √ | √ | 事件设置 | | |||||
| 25 | 0x0301 | √ | √ | 事件报告 | | |||||
| 26 | 0x8302 | √ | √ | 提问下发 | | |||||
| 27 | 0x0302 | √ | √ | 提问应答 | | |||||
| 28 | 0x8303 | √ | √ | 信息点播菜单设置 | | |||||
| 29 | 0x0303 | √ | √ | 信息点播/取消 | | |||||
| 30 | 0x8304 | √ | √ | 信息服务 | | |||||
| 31 | 0x8400 | √ | √ | 电话回拨 | | |||||
| 32 | 0x8401 | √ | √ | 设置电话本 | | |||||
| 33 | 0x8500 | √ | √ | 车辆控制 | | |||||
| 34 | 0x0500 | √ | √ | 车辆控制应答 | | |||||
| 35 | 0x8600 | √ | √ | 设置圆形区域 | | |||||
| 36 | 0x8601 | √ | √ | 删除圆形区域 | | |||||
| 37 | 0x8602 | √ | √ | 设置矩形区域 | | |||||
| 38 | 0x8603 | √ | √ | 删除矩形区域 | | |||||
| 39 | 0x8604 | √ | √ | 设置多边形区域 | | |||||
| 40 | 0x8605 | √ | √ | 删除多边形区域 | | |||||
| 41 | 0x8606 | √ | √ | 设置路线 | | |||||
| 42 | 0x8607 | √ | √ | 删除路线 | | |||||
| 43 | 0x8700 | x | 下个版本 | 行驶记录仪数据采集命令 | | |||||
| 44 | 0x0700 | x | 下个版本 | 行驶记录仪数据上传 | | |||||
| 45 | 0x8701 | x | 下个版本 | 行驶记录仪参数下传命令 | | |||||
| 46 | 0x0701 | √ | √ | 电子运单上报 | | |||||
| 47 | 0x0702 | √ | √ | 驾驶员身份信息采集上报 | | |||||
| 48 | 0x8702 | √ | 消息体为空| 上报驾驶员身份信息请求 | | |||||
| 49 | 0x0704 | √ | √ | 定位数据批量上传 | | |||||
| 50 | 0x0705 | √ | √ | CAN 总线数据上传 | | |||||
| 51 | 0x0800 | √ | √ | 多媒体事件信息上传 | | |||||
| 52 | 0x0801 | √ | √ | 多媒体数据上传 | | |||||
| 53 | 0x8800 | √ | √ | 多媒体数据上传应答 | | |||||
| 54 | 0x8801 | √ | √ | 摄像头立即拍摄命令 | | |||||
| 55 | 0x0805 | √ | √ | 摄像头立即拍摄命令应答 | | |||||
| 56 | 0x8802 | √ | √ | 存储多媒体数据检索 | | |||||
| 57 | 0x0802 | √ | √ | 存储多媒体数据检索应答 | | |||||
| 58 | 0x8803 | √ | √ | 存储多媒体数据上传 | | |||||
| 59 | 0x8804 | √ | √ | 录音开始命令 | | |||||
| 60 | 0x8805 | √ | √ | 单条存储多媒体数据检索上传命令 | | |||||
| 61 | 0x8900 | √ | √ | 数据下行透传 | | |||||
| 62 | 0x0900 | √ | √ | 数据上行透传 | | |||||
| 63 | 0x0901 | √ | √ | 数据压缩上报 | | |||||
| 64 | 0x8A00 | √ | √ | 平台 RSA 公钥 | | |||||
| 65 | 0x0A00 | √ | √ | 终端 RSA 公钥 | | |||||
| 66 | 0x8F00~0x8FFF | 保留 | 保留 | 平台下行消息保留 | | |||||
| 67 | 0x0F00~0x0FFF | 保留 | 保留 | 终端上行消息保留 | |
@@ -0,0 +1,26 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<PropertyGroup> | |||||
<TargetFrameworks>netcoreapp2.2;net472</TargetFrameworks> | |||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||||
<PlatformTarget>AnyCPU</PlatformTarget> | |||||
<OutputType>Exe</OutputType> | |||||
<StartupObject /> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<Compile Remove="ReportTest\**" /> | |||||
<EmbeddedResource Remove="ReportTest\**" /> | |||||
<None Remove="ReportTest\**" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" /> | |||||
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.11.5" /> | |||||
<PackageReference Include="NETStandard.Library" Version="2.0.3" /> | |||||
<PackageReference Include="System.Buffers" Version="4.5.0" /> | |||||
<PackageReference Include="System.Memory" Version="4.5.3" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\JT808.Protocol\JT808.Protocol.csproj" /> | |||||
</ItemGroup> | |||||
</Project> |
@@ -0,0 +1,171 @@ | |||||
using BenchmarkDotNet.Attributes; | |||||
using BenchmarkDotNet.Configs; | |||||
using BenchmarkDotNet.Environments; | |||||
using BenchmarkDotNet.Jobs; | |||||
using BenchmarkDotNet.Toolchains.CsProj; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
namespace JT808.Protocol.Benchmark | |||||
{ | |||||
[Config(typeof(JT808SerializerConfig))] | |||||
[MarkdownExporterAttribute.GitHub] | |||||
[MemoryDiagnoser] | |||||
[CategoriesColumn] | |||||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] | |||||
public class JT808SerializerContext | |||||
{ | |||||
private byte[] bytes0x0200; | |||||
private byte[] bytes0x0100; | |||||
[Params(100, 10000, 100000)] | |||||
public int N; | |||||
private ushort MsgId0x0200; | |||||
private ushort MsgId0x0100; | |||||
JT808Serializer JT808Serializer; | |||||
[GlobalSetup] | |||||
public void Setup() | |||||
{ | |||||
JT808Serializer = new JT808Serializer(); | |||||
bytes0x0200 = "7E0200005C11223344556622B8000000010000000200BA7F0E07E4F11C0028003C00001807151010100104000000640202003703020038040200011105010000000112060100000001011307000000020022012504000000172A0200F42B04000000F2300102310105167E".ToHexBytes(); | |||||
MsgId0x0200 = Enums.JT808MsgId.位置信息汇报.ToUInt16Value(); | |||||
MsgId0x0100 = Enums.JT808MsgId.终端注册.ToUInt16Value(); | |||||
bytes0x0100 = "7E 01 00 00 2D 00 01 23 45 67 89 00 0A 00 28 00 32 31 32 33 34 30 73 6D 61 6C 6C 63 68 69 31 32 33 30 30 30 30 30 30 30 30 30 43 48 49 31 32 33 30 01 D4 C1 41 31 32 33 34 35 BA 7E".ToHexBytes(); | |||||
} | |||||
[Benchmark(Description = "0x0200_All_AttachId_Serialize"), BenchmarkCategory("0x0200Serializer")] | |||||
public void TestJT808_0x0200_All_AttachId_Serialize() | |||||
{ | |||||
for (int i = 0; i < N; i++) | |||||
{ | |||||
JT808Package jT808Package = new JT808Package(); | |||||
jT808Package.Header = new JT808Header | |||||
{ | |||||
MsgId = MsgId0x0200, | |||||
MsgNum = 8888, | |||||
TerminalPhoneNo = "112233445566", | |||||
}; | |||||
JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200(); | |||||
jT808UploadLocationRequest.AlarmFlag = 1; | |||||
jT808UploadLocationRequest.Altitude = 40; | |||||
jT808UploadLocationRequest.GPSTime = DateTime.Parse("2018-07-15 10:10:10"); | |||||
jT808UploadLocationRequest.Lat = 12222222; | |||||
jT808UploadLocationRequest.Lng = 132444444; | |||||
jT808UploadLocationRequest.Speed = 60; | |||||
jT808UploadLocationRequest.Direction = 0; | |||||
jT808UploadLocationRequest.StatusFlag = 2; | |||||
jT808UploadLocationRequest.JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>(); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 55 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x03, new JT808_0x0200_0x03 | |||||
{ | |||||
Speed=56 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x04, new JT808_0x0200_0x04 | |||||
{ | |||||
EventId=1 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x11, new JT808_0x0200_0x11 | |||||
{ | |||||
AreaId=1, | |||||
JT808PositionType= Enums.JT808PositionType.圆形区域 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x12, new JT808_0x0200_0x12 | |||||
{ | |||||
AreaId = 1, | |||||
JT808PositionType = Enums.JT808PositionType.圆形区域, | |||||
Direction= Enums.JT808DirectionType.出 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x13, new JT808_0x0200_0x13 | |||||
{ | |||||
DrivenRoute= Enums.JT808DrivenRouteType.过长, | |||||
DrivenRouteId=2, | |||||
Time=34 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x25, new JT808_0x0200_0x25 | |||||
{ | |||||
CarSignalStatus=23 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x2A, new JT808_0x0200_0x2A | |||||
{ | |||||
IOStatus=244 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x2B, new JT808_0x0200_0x2B | |||||
{ | |||||
Analog = 242 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x30, new JT808_0x0200_0x30 | |||||
{ | |||||
WiFiSignalStrength=0x02 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x31, new JT808_0x0200_0x31 | |||||
{ | |||||
GNSSCount=0x05 | |||||
}); | |||||
jT808Package.Bodies = jT808UploadLocationRequest; | |||||
var result = JT808Serializer.Serialize(jT808Package); | |||||
} | |||||
} | |||||
[Benchmark(Description = "0x0200_All_AttachId_Deserialize"), BenchmarkCategory("0x0200Serializer")] | |||||
public void TestJT808_0x0200_Deserialize() | |||||
{ | |||||
for (int i = 0; i < N; i++) | |||||
{ | |||||
var result = JT808Serializer.Deserialize(bytes0x0200); | |||||
} | |||||
} | |||||
[Benchmark(Description = "0x0100Serialize"), BenchmarkCategory("0x0100Serializer")] | |||||
public void TestJT808_0x0100_Serialize() | |||||
{ | |||||
for (int i = 0; i < N; i++) | |||||
{ | |||||
JT808Package jT808Package = new JT808Package(); | |||||
jT808Package.Header = new JT808Header | |||||
{ | |||||
MsgId = MsgId0x0100, | |||||
MsgNum = (ushort)(i + 1), | |||||
TerminalPhoneNo = "112233445566", | |||||
}; | |||||
JT808_0x0100 jT808_0X0100 = new JT808_0x0100(); | |||||
jT808_0X0100.AreaID = 12345; | |||||
jT808_0X0100.CityOrCountyId = 23454; | |||||
jT808_0X0100.PlateColor = 0x02; | |||||
jT808_0X0100.PlateNo = "测A123456"; | |||||
jT808_0X0100.TerminalId = "1234567"; | |||||
jT808_0X0100.TerminalModel = "1234567890000"; | |||||
jT808_0X0100.MakerId = "12345"; | |||||
jT808Package.Bodies = jT808_0X0100; | |||||
var result = JT808Serializer.Serialize(jT808Package); | |||||
} | |||||
} | |||||
[Benchmark(Description = "0x0100Deserialize"), BenchmarkCategory("0x0100Serializer")] | |||||
public void TestJT808_0x0100_Deserialize() | |||||
{ | |||||
for (int i = 0; i < N; i++) | |||||
{ | |||||
var result = JT808Serializer.Deserialize(bytes0x0100); | |||||
} | |||||
} | |||||
} | |||||
public class JT808SerializerConfig : ManualConfig | |||||
{ | |||||
public JT808SerializerConfig() | |||||
{ | |||||
Add(Job.Default.WithGcServer(false).With(Runtime.Clr).With(Platform.AnyCpu)); | |||||
Add(Job.Default.WithGcServer(false).With(CsProjCoreToolchain.NetCoreApp22).With(Platform.AnyCpu)); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,26 @@ | |||||
using BenchmarkDotNet.Attributes; | |||||
using BenchmarkDotNet.Configs; | |||||
using BenchmarkDotNet.Environments; | |||||
using BenchmarkDotNet.Exporters; | |||||
using BenchmarkDotNet.Jobs; | |||||
using BenchmarkDotNet.Reports; | |||||
using BenchmarkDotNet.Running; | |||||
using BenchmarkDotNet.Toolchains.CsProj; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Threading.Tasks; | |||||
namespace JT808.Protocol.Benchmark | |||||
{ | |||||
class Program | |||||
{ | |||||
static void Main(string[] args) | |||||
{ | |||||
//安装NuGet包,BenchmarkDotNet | |||||
//在需要做性能测试的方法前加上属性[Benchmark]。 | |||||
Summary summary = BenchmarkRunner.Run<JT808SerializerContext>(); | |||||
//Summary summary1 = BenchmarkRunner.Run<JT808DeEscapeContext>(); | |||||
//Summary summary2 = BenchmarkRunner.Run<JT808EscapeContext>(); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,27 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<PropertyGroup> | |||||
<OutputType>Exe</OutputType> | |||||
<TargetFramework>netcoreapp2.2</TargetFramework> | |||||
<LangVersion>latest</LangVersion> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" /> | |||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> | |||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" /> | |||||
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" /> | |||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\JT808.Protocol.Extensions.DependencyInjection\JT808.Protocol.Extensions.DependencyInjection.csproj" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<None Update="appsettings.json"> | |||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||||
</None> | |||||
</ItemGroup> | |||||
</Project> |
@@ -0,0 +1,30 @@ | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.MessagePack; | |||||
using System; | |||||
namespace JT808.Protocol.Extensions.DependencyInjection.Test.JT808LocationAttach | |||||
{ | |||||
public class JT808_0x0200_0x06Formatter : IJT808MessagePackFormatter<JT808LocationAttachImpl0x06> | |||||
{ | |||||
public JT808LocationAttachImpl0x06 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||||
{ | |||||
JT808LocationAttachImpl0x06 jT808LocationAttachImpl0x06 = new JT808LocationAttachImpl0x06() { }; | |||||
jT808LocationAttachImpl0x06.AttachInfoId = reader.ReadByte(); | |||||
jT808LocationAttachImpl0x06.AttachInfoLength = reader.ReadByte(); | |||||
jT808LocationAttachImpl0x06.Age = reader.ReadInt32(); | |||||
jT808LocationAttachImpl0x06.Gender = reader.ReadByte(); | |||||
jT808LocationAttachImpl0x06.UserName = reader.ReadRemainStringContent(); | |||||
return jT808LocationAttachImpl0x06; | |||||
} | |||||
public void Serialize(ref JT808MessagePackWriter writer, JT808LocationAttachImpl0x06 value, IJT808Config config) | |||||
{ | |||||
writer.WriteByte(value.AttachInfoId); | |||||
writer.WriteByte( value.AttachInfoLength); | |||||
writer.WriteInt32(value.Age); | |||||
writer.WriteByte(value.Gender); | |||||
writer.WriteString(value.UserName); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,28 @@ | |||||
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808_0x0701BodiesImpl; | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.MessagePack; | |||||
using System; | |||||
namespace JT808.Protocol.Extensions.DependencyInjection.Test.JT808Formatters | |||||
{ | |||||
public class JT808_0x0701TestBodiesImplFormatter : IJT808MessagePackFormatter<JT808_0x0701TestBodiesImpl> | |||||
{ | |||||
public JT808_0x0701TestBodiesImpl Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||||
{ | |||||
JT808_0x0701TestBodiesImpl jT808_0X0701TestBodiesImpl = new JT808_0x0701TestBodiesImpl(); | |||||
jT808_0X0701TestBodiesImpl.Id = reader.ReadUInt32(); | |||||
jT808_0X0701TestBodiesImpl.UserNameLength = reader.ReadUInt16(); | |||||
return jT808_0X0701TestBodiesImpl; | |||||
} | |||||
public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0701TestBodiesImpl value, IJT808Config config) | |||||
{ | |||||
writer.WriteUInt32(value.Id); | |||||
// 先计算内容长度(汉字为两个字节) | |||||
writer.Skip(2, out int position); | |||||
writer.WriteString(value.UserName); | |||||
writer.WriteUInt16Return((ushort)(writer.GetCurrentPosition()- position-2), position); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,21 @@ | |||||
using JT808.Protocol.Attributes; | |||||
using JT808.Protocol.MessageBody; | |||||
namespace JT808.Protocol.Extensions.DependencyInjection.Test.JT808LocationAttach | |||||
{ | |||||
/// <summary> | |||||
/// 自定义附加信息 | |||||
/// Age-word-2 | |||||
/// UserName-BCD(10) | |||||
/// Gerder-byte-1 | |||||
/// </summary> | |||||
[JT808Formatter(typeof(JT808_0x0200_0x06Formatter))] | |||||
public class JT808LocationAttachImpl0x06 : JT808_0x0200_BodyBase | |||||
{ | |||||
public override byte AttachInfoId { get; set; } = 0x06; | |||||
public override byte AttachInfoLength { get; set; } = 13; | |||||
public int Age { get; set; } | |||||
public byte Gender { get; set; } | |||||
public string UserName { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,16 @@ | |||||
using JT808.Protocol.Attributes; | |||||
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808Formatters; | |||||
using JT808.Protocol.MessageBody; | |||||
namespace JT808.Protocol.Extensions.DependencyInjection.Test.JT808_0x0701BodiesImpl | |||||
{ | |||||
[JT808Formatter(typeof(JT808_0x0701TestBodiesImplFormatter))] | |||||
public class JT808_0x0701TestBodiesImpl : JT808_0x0701_CustomBodyBase | |||||
{ | |||||
public uint Id { get; set; } | |||||
public ushort UserNameLength { get; set; } | |||||
public string UserName { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,74 @@ | |||||
using Microsoft.Extensions.Configuration; | |||||
using Microsoft.Extensions.Hosting; | |||||
using Microsoft.Extensions.DependencyInjection; | |||||
using System; | |||||
using System.Threading.Tasks; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Linq; | |||||
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808LocationAttach; | |||||
using JT808.Protocol.Extensions.DependencyInjection.Test.JT808_0x0701BodiesImpl; | |||||
using System.Reflection; | |||||
using JT808.Protocol.Interfaces; | |||||
namespace JT808.Protocol.Extensions.DependencyInjection.Test | |||||
{ | |||||
class Program | |||||
{ | |||||
static void Main(string[] args) | |||||
{ | |||||
//单个 | |||||
IServiceCollection serviceDescriptors1 = new ServiceCollection(); | |||||
serviceDescriptors1.AddJT808Configure(new DefaultConfig()); | |||||
var ServiceProvider1 = serviceDescriptors1.BuildServiceProvider(); | |||||
var defaultConfig = ServiceProvider1.GetRequiredService<IJT808Config>(); | |||||
//多个 | |||||
IServiceCollection serviceDescriptors2 = new ServiceCollection(); | |||||
serviceDescriptors2.AddJT808Configure(new Config1()); | |||||
serviceDescriptors2.AddJT808Configure(new Config2()); | |||||
serviceDescriptors2.AddSingleton(factory => | |||||
{ | |||||
Func<string, IJT808Config> accesor = key => | |||||
{ | |||||
if (key.Equals("Config1")) | |||||
{ | |||||
return factory.GetService<Config1>(); | |||||
} | |||||
else if (key.Equals("Config2")) | |||||
{ | |||||
return factory.GetService<Config2>(); | |||||
} | |||||
else | |||||
{ | |||||
throw new ArgumentException($"Not Support key : {key}"); | |||||
} | |||||
}; | |||||
return accesor; | |||||
}); | |||||
var ServiceProvider2 = serviceDescriptors2.BuildServiceProvider(); | |||||
var config1 = ServiceProvider2.GetRequiredService<Func<string, IJT808Config>>()("Config1"); | |||||
var flag21 = config1.GetSerializer().SerializerId == "Config1"; | |||||
var config2 = ServiceProvider2.GetRequiredService<Func<string, IJT808Config>>()("Config2"); | |||||
var flag22 = config2.GetSerializer().SerializerId == "Config2"; | |||||
} | |||||
} | |||||
public class DefaultConfig : GlobalConfigBase | |||||
{ | |||||
public override string ConfigId => "test"; | |||||
} | |||||
public class Config1 : GlobalConfigBase | |||||
{ | |||||
public override string ConfigId => "Config1"; | |||||
} | |||||
public class Config2 : GlobalConfigBase | |||||
{ | |||||
public override string ConfigId => "Config2"; | |||||
} | |||||
} | |||||
@@ -0,0 +1,5 @@ | |||||
{ | |||||
"JT809Options": { | |||||
"SkipCRCCode": false | |||||
} | |||||
} |
@@ -0,0 +1,26 @@ | |||||
using JT808.Protocol.Interfaces; | |||||
using Microsoft.Extensions.DependencyInjection; | |||||
namespace JT808.Protocol.Extensions.DependencyInjection | |||||
{ | |||||
public static class DependencyInjectionExtensions | |||||
{ | |||||
public static IServiceCollection AddJT808Configure(this IServiceCollection services, IJT808Config jT808Config) | |||||
{ | |||||
services.AddSingleton(jT808Config.GetType(), jT808Config); | |||||
services.AddSingleton(jT808Config); | |||||
return services; | |||||
} | |||||
public static IServiceCollection AddJT808Configure(this IServiceCollection services) | |||||
{ | |||||
services.AddSingleton<IJT808Config>(new DefaultGlobalConfig()); | |||||
return services; | |||||
} | |||||
class DefaultGlobalConfig : GlobalConfigBase | |||||
{ | |||||
public override string ConfigId => "default"; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<PropertyGroup> | |||||
<TargetFramework>netcoreapp2.2</TargetFramework> | |||||
<LangVersion>latest</LangVersion> | |||||
<Copyright>Copyright 2018.</Copyright> | |||||
<Authors>SmallChi</Authors> | |||||
<PackageId>JT808.Extensions.DependencyInjection</PackageId> | |||||
<Product>JT808.Extensions.DependencyInjection</Product> | |||||
<Description>JT808协议依赖注入扩展包</Description> | |||||
<PackageReleaseNotes>JT808协议依赖注入扩展包</PackageReleaseNotes> | |||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | |||||
<RepositoryUrl>https://github.com/SmallChi/JT808</RepositoryUrl> | |||||
<PackageProjectUrl>https://github.com/SmallChi/JT808</PackageProjectUrl> | |||||
<license>https://github.com/SmallChi/JT808/blob/master/LICENSE</license> | |||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | |||||
<Version>2.0.0</Version> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" /> | |||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> | |||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" /> | |||||
<PackageReference Include="NETStandard.Library" Version="2.0.3" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\JT808.Protocol\JT808.Protocol.csproj" /> | |||||
</ItemGroup> | |||||
</Project> |
@@ -0,0 +1,18 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.Extensions | |||||
{ | |||||
public class JT808EnumExtensionsTest | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
var list0 = JT808EnumExtensions.GetEnumTypes<JT808.Protocol.Enums.JT808Alarm>(5, 32); | |||||
var list1 = JT808EnumExtensions.GetEnumTypes<JT808.Protocol.Enums.JT808Alarm>(16, 32); | |||||
var list2 = JT808EnumExtensions.GetEnumTypes<JT808.Protocol.Enums.JT808Alarm>(18, 32); | |||||
var list3 = JT808EnumExtensions.GetEnumTypes<JT808.Protocol.Enums.JT808Alarm>(24, 32); | |||||
var list4 = JT808EnumExtensions.GetEnumTypes<JT808.Protocol.Enums.JT808Alarm>(31, 32); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
using JT808.Protocol.Enums; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
using JT808.Protocol.Extensions; | |||||
using System.Reflection; | |||||
using System.Linq; | |||||
using JT808.Protocol.Formatters; | |||||
namespace JT808.Protocol.Test.Extensions | |||||
{ | |||||
public class JT808PackageExtensionsTest | |||||
{ | |||||
[Fact] | |||||
public void CreatePackage() | |||||
{ | |||||
var package= JT808MsgId.终端心跳.Create_终端心跳("123456789", new Protocol.MessageBody.JT808_0x0002 { | |||||
}); | |||||
} | |||||
//[Fact] | |||||
//public void Get() | |||||
//{ | |||||
// string type = "222".Replace("",""); | |||||
// var a = Assembly.GetAssembly(typeof(JT808Package)).GetTypes().Where(w=>w.FullName.EndsWith("Formatter")).ToList(); | |||||
//} | |||||
} | |||||
} |
@@ -0,0 +1,23 @@ | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.Formatters.MessageBodyFormatters; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.MessagePack; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.Internal | |||||
{ | |||||
public class JT808MsgIdFactoryTest | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
IJT808MsgIdFactory jT808MsgIdFactory = new JT808MsgIdFactory(); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,18 @@ | |||||
using JT808.Protocol.Internal; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Reflection; | |||||
using System.Text; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.Internal | |||||
{ | |||||
public class JT808_0x0200_Custom_FactoryTest | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
new JT808_0x0200_Custom_Factory().Register(Assembly.GetExecutingAssembly()); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,126 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | |||||
<PropertyGroup> | |||||
<TargetFramework>netcoreapp2.2</TargetFramework> | |||||
<IsPackable>false</IsPackable> | |||||
<LangVersion>7.1</LangVersion> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | |||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<Compile Remove="Extensions\**" /> | |||||
<Compile Remove="MessageBody\**" /> | |||||
<EmbeddedResource Remove="Extensions\**" /> | |||||
<EmbeddedResource Remove="MessageBody\**" /> | |||||
<None Remove="Extensions\**" /> | |||||
<None Remove="MessageBody\**" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<Compile Remove="JT808GlobalConfigTest.cs" /> | |||||
<Compile Remove="JT808UtilsTest.cs" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<Compile Include="Extensions\JT808EnumExtensionsTest.cs" /> | |||||
<Compile Include="Extensions\JT808PackageExtensionsTest.cs" /> | |||||
<Compile Include="MessageBody\JT808Formatters\JT808_0x0200_0x06Formatter.cs" /> | |||||
<Compile Include="MessageBody\JT808Formatters\JT808_0x0701TestBodiesImplFormatter.cs" /> | |||||
<Compile Include="MessageBody\JT808Formatters\JT808_0x0900_0x83Formatter.cs" /> | |||||
<Compile Include="MessageBody\JT808Formatters\JT808_0X8900_Test_BodiesImplFormatter.cs" /> | |||||
<Compile Include="MessageBody\JT808LocationAttachExtensions\JT808LocationAttachImpl0x06.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0001Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0002Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0003Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0100Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0102Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0104Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0107Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0108Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0200Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0201Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0301Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0302Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0303Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0500Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0701BodiesImpl\JT808_0x0701TestBodiesImpl.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0701Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0702Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0704Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0705Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0800Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0801Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0802Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0805Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0900Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0900_BodiesImpl\JT808_0x0900_0x83.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0901Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x0A00Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8001Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8003Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8100Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8103Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8104Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8105Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8106Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8108Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8202Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8203Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8300Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8301Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8302Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8303Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8304Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8400Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8401Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8500Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8600Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8601Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8602Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8603Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8604Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8605Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8606Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8800Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8801Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8802Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8803Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8804Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8805Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8900Test.cs" /> | |||||
<Compile Include="MessageBody\JT808_0X8900_BodiesImpl\JT808_0X8900_Test_BodiesImpl.cs" /> | |||||
<Compile Include="MessageBody\JT808_0x8A00Test.cs" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | |||||
<PackageReference Include="NETStandard.Library" Version="2.0.3" /> | |||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> | |||||
<PackageReference Include="System.Drawing.Common" Version="4.5.1" /> | |||||
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" /> | |||||
<PackageReference Include="xunit" Version="2.4.1" /> | |||||
<PackageReference Include="xunit.runner.console" Version="2.4.1"> | |||||
<PrivateAssets>all</PrivateAssets> | |||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | |||||
</PackageReference> | |||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"> | |||||
<PrivateAssets>all</PrivateAssets> | |||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | |||||
</PackageReference> | |||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\JT808.Protocol\JT808.Protocol.csproj" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<None Update="Files\test.txt"> | |||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||||
</None> | |||||
</ItemGroup> | |||||
</Project> |
@@ -0,0 +1,79 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using System; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test | |||||
{ | |||||
public class JT808HeaderTest | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test3() | |||||
{ | |||||
ReadOnlySpan<char> dataLen = Convert.ToString(5, 2).PadLeft(10, '0').AsSpan(); | |||||
} | |||||
[Fact] | |||||
public void Test4() | |||||
{ | |||||
// "0000000000000101" | |||||
short a = Convert.ToInt16("0000000000000101",2); | |||||
var msgMethodBytes = BitConverter.GetBytes(a); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Header jT808HeaderProperty = new JT808Header | |||||
{ | |||||
TerminalPhoneNo = "13812345678" | |||||
}; | |||||
jT808HeaderProperty.MessageBodyProperty.DataLength = 5; | |||||
jT808HeaderProperty.MsgNum = 135; | |||||
jT808HeaderProperty.MsgId = JT808MsgId.终端鉴权.ToUInt16Value(); | |||||
var hex = JT808Serializer.Serialize(jT808HeaderProperty).ToHexString(); | |||||
Assert.Equal("01 02 00 05 01 38 12 34 56 78 00 87".Replace(" ",""), hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_2() | |||||
{ | |||||
//01 02 00 05 01 38 12 34 56 78 00 87 | |||||
byte[] headerBytes = "01 02 00 05 01 38 12 34 56 78 00 87".ToHexBytes(); | |||||
JT808Header jT808Header = JT808Serializer.Deserialize<JT808Header>(headerBytes); | |||||
Assert.Equal(135, jT808Header.MsgNum); | |||||
Assert.Equal("13812345678", jT808Header.TerminalPhoneNo); | |||||
Assert.False(jT808Header.MessageBodyProperty.IsPackge); | |||||
Assert.Equal(JT808MsgId.终端鉴权.ToValue(), jT808Header.MsgId); | |||||
Assert.Equal(5, jT808Header.MessageBodyProperty.DataLength); | |||||
} | |||||
[Fact] | |||||
public void Test5() | |||||
{ | |||||
JT808Header jT808HeaderProperty = new JT808Header(); | |||||
jT808HeaderProperty.TerminalPhoneNo = "13812345678"; | |||||
jT808HeaderProperty.MessageBodyProperty.DataLength = 5; | |||||
jT808HeaderProperty.MsgNum = 135; | |||||
jT808HeaderProperty.MsgId = JT808MsgId.终端鉴权.ToUInt16Value(); | |||||
//"01 02 00 05 01 38 12 34 56 78 00 87" | |||||
var hex = JT808Serializer.Serialize(jT808HeaderProperty).ToHexString(); | |||||
Assert.Equal("010200050138123456780087", hex); | |||||
} | |||||
[Fact] | |||||
public void Test5_2() | |||||
{ | |||||
//01 02 00 05 01 38 12 34 56 78 00 87 | |||||
byte[] headerBytes = "01 02 00 05 01 38 12 34 56 78 00 87".ToHexBytes(); | |||||
JT808Header jT808Header = JT808Serializer.Deserialize<JT808Header>(headerBytes); | |||||
Assert.Equal(135, jT808Header.MsgNum); | |||||
Assert.Equal("13812345678", jT808Header.TerminalPhoneNo); | |||||
Assert.False(jT808Header.MessageBodyProperty.IsPackge); | |||||
Assert.Equal(JT808MsgId.终端鉴权.ToValue(), jT808Header.MsgId); | |||||
Assert.Equal(5, jT808Header.MessageBodyProperty.DataLength); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,29 @@ | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Reflection; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test | |||||
{ | |||||
public class JT808SerializerTest | |||||
{ | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
var result = Parallel.For(0, 100, new ParallelOptions { MaxDegreeOfParallelism = 2 }, (i) => | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer jT808Serializer = new JT808Serializer(jT808Config); | |||||
}); | |||||
if (result.IsCompleted) | |||||
{ | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,26 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.MessagePack; | |||||
using JT808.Protocol.Test.MessageBody.JT808_0X8900_BodiesImpl; | |||||
using System; | |||||
namespace JT808.Protocol.Test.MessageBody.JT808Formatters | |||||
{ | |||||
public class JT808_0X8900_Test_BodiesImplFormatter : IJT808MessagePackFormatter<JT808_0X8900_Test_BodiesImpl> | |||||
{ | |||||
public JT808_0X8900_Test_BodiesImpl Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||||
{ | |||||
JT808_0X8900_Test_BodiesImpl jT808_0X8900_Test_BodiesImpl = new JT808_0X8900_Test_BodiesImpl(); | |||||
jT808_0X8900_Test_BodiesImpl.Id = reader.ReadUInt32(); | |||||
jT808_0X8900_Test_BodiesImpl.Sex = reader.ReadByte(); | |||||
return jT808_0X8900_Test_BodiesImpl; | |||||
} | |||||
public void Serialize(ref JT808MessagePackWriter writer, JT808_0X8900_Test_BodiesImpl value, IJT808Config config) | |||||
{ | |||||
writer.WriteUInt32(value.Id); | |||||
writer.WriteByte(value.Sex); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.MessagePack; | |||||
using JT808.Protocol.Test.JT808LocationAttach; | |||||
using System; | |||||
namespace JT808.Protocol.Test.JT808Formatters.MessageBodyFormatters.JT808LocationAttach | |||||
{ | |||||
public class JT808_0x0200_0x06Formatter : IJT808MessagePackFormatter<JT808LocationAttachImpl0x06> | |||||
{ | |||||
public JT808LocationAttachImpl0x06 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||||
{ | |||||
JT808LocationAttachImpl0x06 jT808LocationAttachImpl0x06 = new JT808LocationAttachImpl0x06(); | |||||
jT808LocationAttachImpl0x06.AttachInfoId = reader.ReadByte(); | |||||
jT808LocationAttachImpl0x06.AttachInfoLength = reader.ReadByte(); | |||||
jT808LocationAttachImpl0x06.Age = reader.ReadInt32(); | |||||
jT808LocationAttachImpl0x06.Gender = reader.ReadByte(); | |||||
jT808LocationAttachImpl0x06.UserName = reader.ReadRemainStringContent(); | |||||
return jT808LocationAttachImpl0x06; | |||||
} | |||||
public void Serialize(ref JT808MessagePackWriter writer, JT808LocationAttachImpl0x06 value, IJT808Config config) | |||||
{ | |||||
writer.WriteByte(value.AttachInfoId); | |||||
writer.WriteByte(value.AttachInfoLength); | |||||
writer.WriteInt32(value.Age); | |||||
writer.WriteByte(value.Gender); | |||||
writer.WriteString(value.UserName); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,30 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.MessagePack; | |||||
using JT808.Protocol.Test.MessageBody.JT808_0x0701BodiesImpl; | |||||
using System; | |||||
namespace JT808.Protocol.Test.MessageBody.JT808Formatters | |||||
{ | |||||
public class JT808_0x0701TestBodiesImplFormatter : IJT808MessagePackFormatter<JT808_0x0701TestBodiesImpl> | |||||
{ | |||||
public JT808_0x0701TestBodiesImpl Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||||
{ | |||||
JT808_0x0701TestBodiesImpl jT808_0X0701TestBodiesImpl = new JT808_0x0701TestBodiesImpl(); | |||||
jT808_0X0701TestBodiesImpl.Id = reader.ReadUInt32(); | |||||
jT808_0X0701TestBodiesImpl.UserNameLength = reader.ReadUInt16(); | |||||
jT808_0X0701TestBodiesImpl.UserName = reader.ReadString(jT808_0X0701TestBodiesImpl.UserNameLength); | |||||
return jT808_0X0701TestBodiesImpl; | |||||
} | |||||
public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0701TestBodiesImpl value, IJT808Config config) | |||||
{ | |||||
writer.WriteUInt32(value.Id); | |||||
writer.Skip(2,out int position); | |||||
writer.WriteString(value.UserName); | |||||
int strLength = writer.GetCurrentPosition() - position - 2; | |||||
writer.WriteUInt16Return((ushort)strLength, position); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,24 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.MessagePack; | |||||
using JT808.Protocol.Test.JT808_0x0900_BodiesImpl; | |||||
using System; | |||||
namespace JT808.Protocol.Test.MessageBody.JT808Formatters | |||||
{ | |||||
public class JT808_0x0900_0x83Formatter : IJT808MessagePackFormatter<JT808_0x0900_0x83> | |||||
{ | |||||
public JT808_0x0900_0x83 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||||
{ | |||||
JT808_0x0900_0x83 jT808PassthroughType0x83 = new JT808_0x0900_0x83(); | |||||
jT808PassthroughType0x83.PassthroughContent = reader.ReadRemainStringContent(); | |||||
return jT808PassthroughType0x83; | |||||
} | |||||
public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0900_0x83 value, IJT808Config config) | |||||
{ | |||||
writer.WriteString(value.PassthroughContent); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,22 @@ | |||||
using JT808.Protocol.Attributes; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Test.JT808Formatters.MessageBodyFormatters.JT808LocationAttach; | |||||
namespace JT808.Protocol.Test.JT808LocationAttach | |||||
{ | |||||
/// <summary> | |||||
/// 自定义附加信息 | |||||
/// Age-word-2 | |||||
/// UserName-BCD(10) | |||||
/// Gerder-byte-1 | |||||
/// </summary> | |||||
[JT808Formatter(typeof(JT808_0x0200_0x06Formatter))] | |||||
public class JT808LocationAttachImpl0x06: JT808_0x0200_CustomBodyBase | |||||
{ | |||||
public override byte AttachInfoId { get; set; } = 0x06; | |||||
public override byte AttachInfoLength { get; set; } = 13; | |||||
public int Age { get; set; } | |||||
public byte Gender { get; set; } | |||||
public string UserName { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,14 @@ | |||||
using JT808.Protocol.Attributes; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Test.MessageBody.JT808Formatters; | |||||
namespace JT808.Protocol.Test.MessageBody.JT808_0X8900_BodiesImpl | |||||
{ | |||||
[JT808Formatter(typeof(JT808_0X8900_Test_BodiesImplFormatter))] | |||||
public class JT808_0X8900_Test_BodiesImpl: JT808_0x8900_BodyBase | |||||
{ | |||||
public uint Id { get; set; } | |||||
public byte Sex { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,48 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0001Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端通用应答.ToUInt16Value(), | |||||
MsgNum = 1203, | |||||
TerminalPhoneNo = "012345678900" | |||||
}, | |||||
Bodies = new JT808_0x0001 | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端心跳.ToUInt16Value(), | |||||
MsgNum = 1000, | |||||
JT808TerminalResult = Enums.JT808TerminalResult.Success | |||||
} | |||||
}; | |||||
//"7E 00 01 00 05 01 23 45 67 89 00 04 B3 03 E8 00 02 00 D3 7E" | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E0001000501234567890004B303E8000200D37E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "7E 00 01 00 05 01 23 45 67 89 00 04 B3 03 E8 00 02 00 D3 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端通用应答.ToValue(), jT808Package.Header.MsgId); | |||||
Assert.Equal(1203, jT808Package.Header.MsgNum); | |||||
JT808_0x0001 JT808Bodies = (JT808_0x0001)jT808Package.Bodies; | |||||
Assert.Equal(Enums.JT808MsgId.终端心跳.ToUInt16Value(), JT808Bodies.MsgId); | |||||
Assert.Equal(1000, JT808Bodies.MsgNum); | |||||
Assert.Equal(Enums.JT808TerminalResult.Success, JT808Bodies.JT808TerminalResult); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,70 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0002Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端心跳.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "12345678900", | |||||
} | |||||
}; | |||||
//"7E 00 02 00 00 01 23 45 67 89 00 00 0A 81 7E" | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E00020000012345678900000A817E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "7E 00 02 00 00 01 23 45 67 89 00 00 0A 81 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端心跳.ToValue(), jT808Package.Header.MsgId); | |||||
Assert.Equal(10, jT808Package.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808Package.Header.TerminalPhoneNo); | |||||
Assert.Null(jT808Package.Bodies); | |||||
} | |||||
[Fact] | |||||
public void Test3() | |||||
{ | |||||
var bytes = "7E 00 02 00 00 04 00 21 67 92 87 00 2B 7D 02 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端心跳.ToValue(), jT808Package.Header.MsgId); | |||||
Assert.Equal(43, jT808Package.Header.MsgNum); | |||||
Assert.Equal("40021679287", jT808Package.Header.TerminalPhoneNo); | |||||
Assert.Null(jT808Package.Bodies); | |||||
} | |||||
[Fact] | |||||
public void Test4() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端心跳.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "12345678900", | |||||
}, | |||||
Bodies= new JT808_0x0002() | |||||
}; | |||||
//"7E 00 02 00 00 01 23 45 67 89 00 00 0A 81 7E" | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E00020000012345678900000A817E", hex); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,37 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0003Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端注销.ToUInt16Value(), | |||||
MsgNum = 1, | |||||
TerminalPhoneNo = "12345678900", | |||||
} | |||||
}; | |||||
//"7E 00 03 00 00 01 23 45 67 89 00 00 01 8B 7E" | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E0003000001234567890000018B7E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "7E 00 03 00 00 01 23 45 67 89 00 00 01 8B 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端注销.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(1, jT808Package.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808Package.Header.TerminalPhoneNo); | |||||
Assert.Null(jT808Package.Bodies); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,56 @@ | |||||
using Xunit; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Extensions; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0100Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808_0X0100 = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端注册.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "123456789", | |||||
}, | |||||
Bodies = new JT808_0x0100 | |||||
{ | |||||
AreaID = 40, | |||||
CityOrCountyId = 50, | |||||
MakerId = "1234", | |||||
PlateColor = 1, | |||||
PlateNo = "粤A12345", | |||||
TerminalId = "CHI123", | |||||
TerminalModel = "smallchi123" | |||||
} | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0100).ToHexString(); | |||||
Assert.Equal("7E0100002D000123456789000A002800323132333430736D616C6C6368693132333030303030303030304348493132333001D4C1413132333435BA7E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
byte[] bytes = "7E 01 00 00 2D 00 01 23 45 67 89 00 0A 00 28 00 32 31 32 33 34 30 73 6D 61 6C 6C 63 68 69 31 32 33 30 30 30 30 30 30 30 30 30 43 48 49 31 32 33 30 01 D4 C1 41 31 32 33 34 35 BA 7E".ToHexBytes(); | |||||
JT808Package jT808_0X0100 = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端注册.ToUInt16Value(), jT808_0X0100.Header.MsgId); | |||||
Assert.Equal(10, jT808_0X0100.Header.MsgNum); | |||||
Assert.Equal("123456789", jT808_0X0100.Header.TerminalPhoneNo); | |||||
JT808_0x0100 JT808Bodies = (JT808_0x0100)jT808_0X0100.Bodies; | |||||
Assert.Equal(40, JT808Bodies.AreaID); | |||||
Assert.Equal(50, JT808Bodies.CityOrCountyId); | |||||
Assert.Equal("12340", JT808Bodies.MakerId); | |||||
Assert.Equal(1, JT808Bodies.PlateColor); | |||||
Assert.Equal("粤A12345", JT808Bodies.PlateNo); | |||||
Assert.Equal("CHI1230", JT808Bodies.TerminalId); | |||||
Assert.Equal("smallchi123000000000", JT808Bodies.TerminalModel); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,62 @@ | |||||
using Xunit; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Extensions; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0102Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0102 jT808LoginRequestProperty = new JT808_0x0102 | |||||
{ | |||||
Code = "45612" | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808LoginRequestProperty).ToHexString(); | |||||
Assert.Equal("3435363132", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bodys = "34 35 36 31 32".ToHexBytes(); | |||||
JT808_0x0102 jT808LoginRequest = JT808Serializer.Deserialize<JT808_0x0102>(bodys); | |||||
Assert.Equal("45612", jT808LoginRequest.Code); | |||||
} | |||||
[Fact] | |||||
public void Test3() | |||||
{ | |||||
JT808Package jT808LoginRequest = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端鉴权.ToUInt16Value(), | |||||
MsgNum = 12345, | |||||
TerminalPhoneNo = "12345678900", | |||||
}, | |||||
Bodies = new JT808_0x0102 | |||||
{ | |||||
Code = "456121111" | |||||
} | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808LoginRequest).ToHexString(); | |||||
Assert.Equal("7E010200090123456789003039343536313231313131BE7E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test4() | |||||
{ | |||||
byte[] bodys = "7E 01 02 00 09 01 23 45 67 89 00 30 39 34 35 36 31 32 31 31 31 31 BE 7E".ToHexBytes(); | |||||
JT808Package jT808LoginRequest = JT808Serializer.Deserialize<JT808Package>(bodys); | |||||
Assert.Equal(Enums.JT808MsgId.终端鉴权.ToUInt16Value(), jT808LoginRequest.Header.MsgId); | |||||
Assert.Equal(12345, jT808LoginRequest.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808LoginRequest.Header.TerminalPhoneNo); | |||||
JT808_0x0102 JT808Bodies = (JT808_0x0102)jT808LoginRequest.Bodies; | |||||
Assert.Equal("456121111", JT808Bodies.Code); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,125 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0104Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.查询终端参数应答.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "123456789", | |||||
}, | |||||
Bodies = new JT808_0x0104 | |||||
{ | |||||
MsgNum = 20, | |||||
AnswerParamsCount = 1, | |||||
ParamList = new List<JT808_0x8103_BodyBase> { | |||||
new JT808_0x8103_0x0001() { | |||||
ParamId=0x0001, | |||||
ParamLength=4, | |||||
ParamValue=10 | |||||
} | |||||
} | |||||
} | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E0104000C000123456789000A00140100000001040000000A907E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
byte[] bytes = "7E0104000C000123456789000A00140100000001040000000A907E".ToHexBytes(); | |||||
JT808Package jT808_0X8104 = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.查询终端参数应答.ToUInt16Value(), jT808_0X8104.Header.MsgId); | |||||
Assert.Equal(10, jT808_0X8104.Header.MsgNum); | |||||
Assert.Equal("123456789", jT808_0X8104.Header.TerminalPhoneNo); | |||||
JT808_0x0104 JT808Bodies = (JT808_0x0104)jT808_0X8104.Bodies; | |||||
Assert.Equal(20, JT808Bodies.MsgNum); | |||||
Assert.Equal(1, JT808Bodies.AnswerParamsCount); | |||||
foreach (var item in JT808Bodies.ParamList) | |||||
{ | |||||
Assert.Equal(0x0001u, ((JT808_0x8103_0x0001)item).ParamId); | |||||
Assert.Equal(4, ((JT808_0x8103_0x0001)item).ParamLength); | |||||
Assert.Equal(10u, ((JT808_0x8103_0x0001)item).ParamValue); | |||||
} | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.查询终端参数应答.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "123456789", | |||||
}, | |||||
Bodies = new JT808_0x0104 | |||||
{ | |||||
MsgNum = 20, | |||||
AnswerParamsCount = 2, | |||||
ParamList = new List<JT808_0x8103_BodyBase> { | |||||
new JT808_0x8103_0x0001() { | |||||
ParamId=0x0001, | |||||
ParamLength=4, | |||||
ParamValue=10 | |||||
}, | |||||
new JT808_0x8103_0x0013(){ | |||||
ParamId=0x0013, | |||||
ParamValue="www.baidu.com" | |||||
} | |||||
} | |||||
} | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
//7E0104001E000123456789000A00140200000001040000000A000000130F7777772E62616964752E636F6DF07E | |||||
//7E0104001E000123456789000A00140200000001040000000A000000130D7777772E62616964752E636F6DF27E | |||||
Assert.Equal("7E0104001E000123456789000A00140200000001040000000A000000130D7777772E62616964752E636F6DF27E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2_1() | |||||
{ | |||||
byte[] bytes = "7E0104001E000123456789000A00140200000001040000000A000000130D7777772E62616964752E636F6DF27E".ToHexBytes(); | |||||
JT808Package jT808_0X8104 = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.查询终端参数应答.ToUInt16Value(), jT808_0X8104.Header.MsgId); | |||||
Assert.Equal(10, jT808_0X8104.Header.MsgNum); | |||||
Assert.Equal("123456789", jT808_0X8104.Header.TerminalPhoneNo); | |||||
JT808_0x0104 JT808Bodies = (JT808_0x0104)jT808_0X8104.Bodies; | |||||
Assert.Equal(20, JT808Bodies.MsgNum); | |||||
Assert.Equal(2, JT808Bodies.AnswerParamsCount); | |||||
foreach (var item in JT808Bodies.ParamList) | |||||
{ | |||||
switch (item.ParamId) | |||||
{ | |||||
case 0x0001: | |||||
Assert.Equal(0x0001u, ((JT808_0x8103_0x0001)item).ParamId); | |||||
Assert.Equal(4, ((JT808_0x8103_0x0001)item).ParamLength); | |||||
Assert.Equal(10u, ((JT808_0x8103_0x0001)item).ParamValue); | |||||
break; | |||||
case 0x0013: | |||||
Assert.Equal(0x0013u, ((JT808_0x8103_0x0013)item).ParamId); | |||||
Assert.Equal("www.baidu.com", ((JT808_0x8103_0x0013)item).ParamValue); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,63 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0107Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.查询终端属性应答.ToUInt16Value(), | |||||
MsgNum = 8888, | |||||
TerminalPhoneNo = "112233445566", | |||||
} | |||||
}; | |||||
JT808_0x0107 jT808_0X0107 = new JT808_0x0107 | |||||
{ | |||||
// 00000000 00000101 | |||||
TerminalType = 5, | |||||
MakerId = "10601", | |||||
TerminalModel = "10455545955103", | |||||
TerminalId = "4d6a13", | |||||
Terminal_SIM_ICCID = "1232355987", | |||||
Terminal_Hardware_Version_Num = "abcdefg", | |||||
Terminal_Firmware_Version_Num = "poiuytrewq", | |||||
// 00000111 | |||||
GNSSModule = 7, | |||||
// 00001001 | |||||
CommunicationModule = 9 | |||||
}; | |||||
jT808Package.Bodies = jT808_0X0107; | |||||
string hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
//"7E 01 07 00 3C 11 22 33 44 55 66 22 B8 00 05 31 30 36 30 31 31 30 34 35 35 35 34 35 39 35 35 31 30 33 30 30 30 30 30 30 34 64 36 61 31 33 30 12 32 35 59 87 07 61 62 63 64 65 66 67 0A 70 6F 69 75 79 74 72 65 77 71 07 09 6C 7E" | |||||
Assert.Equal("7E 01 07 00 3C 11 22 33 44 55 66 22 B8 00 05 31 30 36 30 31 31 30 34 35 35 35 34 35 39 35 35 31 30 33 30 30 30 30 30 30 34 64 36 61 31 33 30 12 32 35 59 87 07 61 62 63 64 65 66 67 0A 70 6F 69 75 79 74 72 65 77 71 07 09 6C 7E".Replace(" ", ""), hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "7E 01 07 00 3C 11 22 33 44 55 66 22 B8 00 05 31 30 36 30 31 31 30 34 35 35 35 34 35 39 35 35 31 30 33 30 30 30 30 30 30 34 64 36 61 31 33 30 12 32 35 59 87 07 61 62 63 64 65 66 67 0A 70 6F 69 75 79 74 72 65 77 71 07 09 6C 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize(bytes); | |||||
JT808_0x0107 jT808_0X0107 = (JT808_0x0107)jT808Package.Bodies; | |||||
Assert.Equal(8888, jT808Package.Header.MsgNum); | |||||
Assert.Equal("112233445566", jT808Package.Header.TerminalPhoneNo); | |||||
Assert.Equal(Enums.JT808MsgId.查询终端属性应答.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(5, jT808_0X0107.TerminalType); | |||||
Assert.Equal("10601", jT808_0X0107.MakerId); | |||||
Assert.Equal("10455545955103000000", jT808_0X0107.TerminalModel); | |||||
Assert.Equal("4d6a130", jT808_0X0107.TerminalId); | |||||
Assert.Equal("1232355987", jT808_0X0107.Terminal_SIM_ICCID); | |||||
Assert.Equal("abcdefg", jT808_0X0107.Terminal_Hardware_Version_Num); | |||||
Assert.Equal("poiuytrewq", jT808_0X0107.Terminal_Firmware_Version_Num); | |||||
Assert.Equal(7, jT808_0X0107.GNSSModule); | |||||
Assert.Equal(9, jT808_0X0107.CommunicationModule); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0108Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0108 jT808_0X0108 = new JT808_0x0108 | |||||
{ | |||||
UpgradeType = JT808UpgradeType.北斗卫星定位模块, | |||||
UpgradeResult = JT808UpgradeResult.成功 | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X0108).ToHexString(); | |||||
Assert.Equal("3400", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "34 00".ToHexBytes(); | |||||
JT808_0x0108 jT808_0X0108 = JT808Serializer.Deserialize<JT808_0x0108>(bytes); | |||||
Assert.Equal(JT808UpgradeResult.成功, jT808_0X0108.UpgradeResult); | |||||
Assert.Equal(JT808UpgradeType.北斗卫星定位模块, jT808_0X0108.UpgradeType); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,375 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Test.JT808LocationAttach; | |||||
using System; | |||||
using System.Collections.Concurrent; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Reflection; | |||||
using System.Threading.Tasks; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0200Test | |||||
{ | |||||
JT808Serializer JT808Serializer; | |||||
public JT808_0x0200Test() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-07-15 10:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>() | |||||
}; | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 55 | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString(); | |||||
Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037", hex); | |||||
} | |||||
[Fact] | |||||
public void Parallel_Test1_1() | |||||
{ | |||||
ConcurrentBag<string> hexs = new ConcurrentBag<string>(); | |||||
Parallel.For(1, 20, new ParallelOptions | |||||
{ | |||||
MaxDegreeOfParallelism=5 | |||||
}, (i) => | |||||
{ | |||||
JT808Package jT808Package = new JT808Package(); | |||||
jT808Package.Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.位置信息汇报.ToUInt16Value(), | |||||
MsgNum = (ushort)i, | |||||
TerminalPhoneNo = "1122334455"+i.ToString(), | |||||
}; | |||||
JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-07-15 10:10:10").AddSeconds(i), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>() | |||||
}; | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 55 | |||||
}); | |||||
jT808Package.Bodies = jT808UploadLocationRequest; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
hexs.Add(hex); | |||||
}); | |||||
//7E02000026 112233445519 0013 000000010000000200BA7F0E07E4F11C0028003C0000 180715101029 01040000006402020037987E, | |||||
//7E02000026 112233445518 0012 000000010000000200BA7F0E07E4F11C0028003C0000 180715101028 01040000006402020037997E, | |||||
//7E02000026 112233445517 0011 000000010000000200BA7F0E07E4F11C0028003C0000 180715101027 010400000064020200379A7E, | |||||
//7E02000026 112233445516 0010 000000010000000200BA7F0E07E4F11C0028003C0000 180715101026 010400000064020200379B7E, | |||||
//7E02000026 112233445515 000F 000000010000000200BA7F0E07E4F11C0028003C0000 180715101025 01040000006402020037847E, | |||||
//7E02000026 112233445514 000E 000000010000000200BA7F0E07E4F11C0028003C0000 180715101024 01040000006402020037857E, | |||||
//7E02000026 112233445513 000D 000000010000000200BA7F0E07E4F11C0028003C0000 180715101023 01040000006402020037867E, | |||||
//7E02000026 112233445512 000C 000000010000000200BA7F0E07E4F11C0028003C0000 180715101022 01040000006402020037877E, | |||||
//7E02000026 112233445511 000B 000000010000000200BA7F0E07E4F11C0028003C0000 180715101021 01040000006402020037807E, | |||||
//7E02000026 112233445510 000A 000000010000000200BA7F0E07E4F11C0028003C0000 180715101020 01040000006402020037817E, | |||||
//7E02000026 011223344559 0009 000000010000000200BA7F0E07E4F11C0028003C0000 180715101019 01040000006402020037A27E, | |||||
//7E02000026 011223344558 0008 000000010000000200BA7F0E07E4F11C0028003C0000 180715101018 01040000006402020037A37E, | |||||
//7E02000026 011223344557 0007 000000010000000200BA7F0E07E4F11C0028003C0000 180715101017 01040000006402020037AC7E, | |||||
//7E02000026 011223344556 0006 000000010000000200BA7F0E07E4F11C0028003C0000 180715101016 01040000006402020037AD7E, | |||||
//7E02000026 011223344555 0005 000000010000000200BA7F0E07E4F11C0028003C0000 180715101015 01040000006402020037AE7E, | |||||
//7E02000026 011223344554 0004 000000010000000200BA7F0E07E4F11C0028003C0000 180715101014 01040000006402020037AF7E, | |||||
//7E02000026 011223344553 0003 000000010000000200BA7F0E07E4F11C0028003C0000 180715101013 01040000006402020037A87E, | |||||
//7E02000026 011223344552 0002 000000010000000200BA7F0E07E4F11C0028003C0000 180715101012 01040000006402020037A97E, | |||||
//7E02000026 011223344551 0001 000000010000000200BA7F0E07E4F11C0028003C0000 180715101011 01040000006402020037AA7E, | |||||
//7E02000026 011223344550 0001 000000010000000200BA7F0E07E4F11C0028003C0000 180715101010 01040000006402020037AA7E | |||||
//7E02000026 011223344550 0000 000000010000000200BA7F0E07E4F11C0028003C0000 180715101010 01040000006402020037AB7E, | |||||
string result = "7E020000260112233445500000000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037AB7E,7E020000260112233445570007000000010000000200BA7F0E07E4F11C0028003C000018071510101701040000006402020037AC7E,7E020000260112233445560006000000010000000200BA7F0E07E4F11C0028003C000018071510101601040000006402020037AD7E,7E020000260112233445550005000000010000000200BA7F0E07E4F11C0028003C000018071510101501040000006402020037AE7E,7E020000260112233445540004000000010000000200BA7F0E07E4F11C0028003C000018071510101401040000006402020037AF7E,7E020000261122334455190013000000010000000200BA7F0E07E4F11C0028003C000018071510102901040000006402020037987E,7E020000261122334455180012000000010000000200BA7F0E07E4F11C0028003C000018071510102801040000006402020037997E,7E020000261122334455170011000000010000000200BA7F0E07E4F11C0028003C0000180715101027010400000064020200379A7E,7E020000261122334455160010000000010000000200BA7F0E07E4F11C0028003C0000180715101026010400000064020200379B7E,7E02000026112233445515000F000000010000000200BA7F0E07E4F11C0028003C000018071510102501040000006402020037847E,7E02000026112233445514000E000000010000000200BA7F0E07E4F11C0028003C000018071510102401040000006402020037857E,7E02000026112233445513000D000000010000000200BA7F0E07E4F11C0028003C000018071510102301040000006402020037867E,7E02000026112233445512000C000000010000000200BA7F0E07E4F11C0028003C000018071510102201040000006402020037877E,7E020000260112233445530003000000010000000200BA7F0E07E4F11C0028003C000018071510101301040000006402020037A87E,7E020000260112233445520002000000010000000200BA7F0E07E4F11C0028003C000018071510101201040000006402020037A97E,7E020000260112233445510001000000010000000200BA7F0E07E4F11C0028003C000018071510101101040000006402020037AA7E,7E02000026112233445511000B000000010000000200BA7F0E07E4F11C0028003C000018071510102101040000006402020037807E,7E02000026112233445510000A000000010000000200BA7F0E07E4F11C0028003C000018071510102001040000006402020037817E,7E020000260112233445590009000000010000000200BA7F0E07E4F11C0028003C000018071510101901040000006402020037A27E,7E020000260112233445580008000000010000000200BA7F0E07E4F11C0028003C000018071510101801040000006402020037A37E"; | |||||
//7E020000260112233445500001000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037AA7E | |||||
List<string> resultHexs = result.Split(',').ToList(); | |||||
string hexStr = string.Join(',', hexs); | |||||
foreach (var item in hexs) | |||||
{ | |||||
Assert.Contains(item, resultHexs); | |||||
} | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bodys = "00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37".ToHexBytes(); | |||||
JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys); | |||||
Assert.Equal((uint)1, jT808UploadLocationRequest.AlarmFlag); | |||||
Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime); | |||||
Assert.Equal(12222222, jT808UploadLocationRequest.Lat); | |||||
Assert.Equal(132444444, jT808UploadLocationRequest.Lng); | |||||
Assert.Equal(60, jT808UploadLocationRequest.Speed); | |||||
Assert.Equal((uint)2, jT808UploadLocationRequest.StatusFlag); | |||||
Assert.Equal(100, ((JT808_0x0200_0x01)jT808UploadLocationRequest.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x01]).Mileage); | |||||
Assert.Equal(55, ((JT808_0x0200_0x02)jT808UploadLocationRequest.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x02]).Oil); | |||||
} | |||||
[Fact] | |||||
public void Test3() | |||||
{ | |||||
//00 00 00 01 | |||||
//00 00 00 02 | |||||
//00 BA 7F 0E | |||||
//07 E4 F1 1C | |||||
//00 28 | |||||
//00 3C | |||||
//00 00 | |||||
//18 07 15 10 10 10 | |||||
//01 | |||||
// 04 | |||||
// 00 00 00 64 | |||||
//02 | |||||
// 02 | |||||
// 00 37 | |||||
//06 | |||||
// 0D | |||||
// 00 00 00 12 01 73 6D 61 6C 6C 63 68 69" | |||||
JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-07-15 10:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>(), | |||||
JT808CustomLocationAttachData = new Dictionary<byte, JT808_0x0200_CustomBodyBase>() | |||||
}; | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 55 | |||||
}); | |||||
jT808UploadLocationRequest.JT808CustomLocationAttachData.Add(0x06, new JT808LocationAttachImpl0x06 | |||||
{ | |||||
Age = 18, | |||||
Gender = 1, | |||||
UserName = "smallchi" | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString(); | |||||
Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037060D0000001201736D616C6C636869", hex); | |||||
} | |||||
[Fact] | |||||
public void Test4() | |||||
{ | |||||
// 1.添加自定义附加信息扩展 AddJT808LocationAttachMethod | |||||
byte[] bodys = "00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37 06 0D 00 00 00 12 01 73 6D 61 6C 6C 63 68 69".ToHexBytes(); | |||||
JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize<JT808_0x0200>(bodys); | |||||
Assert.Equal((uint)1, jT808UploadLocationRequest.AlarmFlag); | |||||
Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime); | |||||
Assert.Equal(12222222, jT808UploadLocationRequest.Lat); | |||||
Assert.Equal(132444444, jT808UploadLocationRequest.Lng); | |||||
Assert.Equal(60, jT808UploadLocationRequest.Speed); | |||||
Assert.Equal((uint)2, jT808UploadLocationRequest.StatusFlag); | |||||
Assert.Equal(100, ((JT808_0x0200_0x01)jT808UploadLocationRequest.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x01]).Mileage); | |||||
Assert.Equal(55, ((JT808_0x0200_0x02)jT808UploadLocationRequest.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x02]).Oil); | |||||
var jT808LocationAttachImpl0x06 = JT808Serializer.Deserialize<JT808LocationAttachImpl0x06>(jT808UploadLocationRequest.JT808CustomLocationAttachOriginalData[0x06]); | |||||
Assert.Equal(18, jT808LocationAttachImpl0x06.Age); | |||||
Assert.Equal(1, jT808LocationAttachImpl0x06.Gender); | |||||
Assert.Equal("smallchi", jT808LocationAttachImpl0x06.UserName); | |||||
} | |||||
[Fact] | |||||
public void Test5_1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package(); | |||||
jT808Package.Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.位置信息汇报.ToUInt16Value(), | |||||
MsgNum = 8888, | |||||
TerminalPhoneNo = "112233445566", | |||||
//MessageBodyProperty=new JT808MessageBodyProperty(38), | |||||
}; | |||||
JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-07-15 10:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>() | |||||
}; | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 55 | |||||
}); | |||||
jT808Package.Bodies = jT808UploadLocationRequest; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
} | |||||
[Fact] | |||||
public void Test5() | |||||
{ | |||||
//7E | |||||
//02 00 | |||||
//00 33 | |||||
//11 22 33 44 55 66 | |||||
//22 B8 | |||||
//00 00 00 01 | |||||
//00 00 00 02 | |||||
//00 BA 7F 0E | |||||
//07 E4 F1 1C | |||||
//00 28 | |||||
//00 3C | |||||
//00 00 | |||||
//18 07 15 10 10 10 | |||||
//01 | |||||
// 04 | |||||
// 00 00 00 64 | |||||
//02 | |||||
// 02 | |||||
// 00 37 | |||||
//42 7E | |||||
byte[] bytes = "7E 02 00 00 26 11 22 33 44 55 66 22 B8 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37 57 7E".ToHexBytes(); | |||||
var jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.位置信息汇报.ToValue(), jT808Package.Header.MsgId); | |||||
Assert.Equal(38, jT808Package.Header.MessageBodyProperty.DataLength); | |||||
Assert.Equal(8888, jT808Package.Header.MsgNum); | |||||
Assert.Equal("112233445566", jT808Package.Header.TerminalPhoneNo); | |||||
//Assert.Equal(1, jT808Package.Header.MessageBodyProperty.DataLength); | |||||
Assert.False(jT808Package.Header.MessageBodyProperty.IsPackge); | |||||
Assert.Equal(0, jT808Package.Header.MessageBodyProperty.PackageIndex); | |||||
Assert.Equal(0, jT808Package.Header.MessageBodyProperty.PackgeCount); | |||||
Assert.Equal(JT808EncryptMethod.None, jT808Package.Header.MessageBodyProperty.Encrypt); | |||||
JT808_0x0200 jT808UploadLocationRequest = (JT808_0x0200)jT808Package.Bodies; | |||||
Assert.Equal((uint)1, jT808UploadLocationRequest.AlarmFlag); | |||||
Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime); | |||||
Assert.Equal(12222222, jT808UploadLocationRequest.Lat); | |||||
Assert.Equal(132444444, jT808UploadLocationRequest.Lng); | |||||
Assert.Equal(60, jT808UploadLocationRequest.Speed); | |||||
Assert.Equal((uint)2, jT808UploadLocationRequest.StatusFlag); | |||||
Assert.Equal(100, ((JT808_0x0200_0x01)jT808UploadLocationRequest.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x01]).Mileage); | |||||
Assert.Equal(55, ((JT808_0x0200_0x02)jT808UploadLocationRequest.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x02]).Oil); | |||||
} | |||||
[Fact] | |||||
public void Test_all_attcahids() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package(); | |||||
jT808Package.Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.位置信息汇报.ToUInt16Value(), | |||||
MsgNum = 8888, | |||||
TerminalPhoneNo = "112233445566", | |||||
}; | |||||
JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200(); | |||||
jT808UploadLocationRequest.AlarmFlag = 1; | |||||
jT808UploadLocationRequest.Altitude = 40; | |||||
jT808UploadLocationRequest.GPSTime = DateTime.Parse("2018-07-15 10:10:10"); | |||||
jT808UploadLocationRequest.Lat = 12222222; | |||||
jT808UploadLocationRequest.Lng = 132444444; | |||||
jT808UploadLocationRequest.Speed = 60; | |||||
jT808UploadLocationRequest.Direction = 0; | |||||
jT808UploadLocationRequest.StatusFlag = 2; | |||||
jT808UploadLocationRequest.JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>(); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 55 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x03, new JT808_0x0200_0x03 | |||||
{ | |||||
Speed = 56 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x04, new JT808_0x0200_0x04 | |||||
{ | |||||
EventId = 1 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x11, new JT808_0x0200_0x11 | |||||
{ | |||||
AreaId = 1, | |||||
JT808PositionType = Enums.JT808PositionType.圆形区域 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x12, new JT808_0x0200_0x12 | |||||
{ | |||||
AreaId = 1, | |||||
JT808PositionType = Enums.JT808PositionType.圆形区域, | |||||
Direction = Enums.JT808DirectionType.出 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x13, new JT808_0x0200_0x13 | |||||
{ | |||||
DrivenRoute = Enums.JT808DrivenRouteType.过长, | |||||
DrivenRouteId = 2, | |||||
Time = 34 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x25, new JT808_0x0200_0x25 | |||||
{ | |||||
CarSignalStatus = 23 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x2A, new JT808_0x0200_0x2A | |||||
{ | |||||
IOStatus = 244 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x2B, new JT808_0x0200_0x2B | |||||
{ | |||||
Analog = 242 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x30, new JT808_0x0200_0x30 | |||||
{ | |||||
WiFiSignalStrength = 0x02 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x31, new JT808_0x0200_0x31 | |||||
{ | |||||
GNSSCount = 0x05 | |||||
}); | |||||
jT808Package.Bodies = jT808UploadLocationRequest; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E0200005C11223344556622B8000000010000000200BA7F0E07E4F11C0028003C00001807151010100104000000640202003703020038040200011105010000000112060100000001011307000000020022012504000000172A0200F42B04000000F2300102310105167E", hex); | |||||
//7E0200005C11223344556622B8000000010000000200BA7F0E07E4F11C0028003C00001807151010100104000000640202003703020038040200011105010000000112060100000001011307000000020022012504000000172A0200F42B04000000F2300102310105167E | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,72 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0201Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.位置信息查询应答.ToUInt16Value(), | |||||
MsgNum = 8888, | |||||
TerminalPhoneNo = "112233445566", | |||||
} | |||||
}; | |||||
JT808_0x0201 jT808_0X0201 = new JT808_0x0201 | |||||
{ | |||||
MsgNum = 12345 | |||||
}; | |||||
JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-07-15 10:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>() | |||||
}; | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 55 | |||||
}); | |||||
jT808_0X0201.Position = jT808UploadLocationRequest; | |||||
jT808Package.Bodies = jT808_0X0201; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E0201002811223344556622B83039000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037517E".Length, hex.Length); | |||||
Assert.Equal("7E0201002811223344556622B83039000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037517E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "7E0201002811223344556622B83039000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037517E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize(bytes); | |||||
JT808_0x0201 jT808_0X0201 = (JT808_0x0201) jT808Package.Bodies; | |||||
Assert.Equal(12345, jT808_0X0201.MsgNum); | |||||
Assert.Equal((uint)1, jT808_0X0201.Position.AlarmFlag); | |||||
Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808_0X0201.Position.GPSTime); | |||||
Assert.Equal(12222222, jT808_0X0201.Position.Lat); | |||||
Assert.Equal(132444444, jT808_0X0201.Position.Lng); | |||||
Assert.Equal(60, jT808_0X0201.Position.Speed); | |||||
Assert.Equal((uint)2, jT808_0X0201.Position.StatusFlag); | |||||
Assert.Equal(100, ((JT808_0x0200_0x01)jT808_0X0201.Position.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x01]).Mileage); | |||||
Assert.Equal(55, ((JT808_0x0200_0x02)jT808_0X0201.Position.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x02]).Oil); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,29 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0301Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0301 jT808_0X0301 = new JT808_0x0301 | |||||
{ | |||||
EventId = 123 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0301).ToHexString(); | |||||
Assert.Equal("7B", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
byte[] bytes = "7B".ToHexBytes(); | |||||
JT808_0x0301 jT808_0X8104 = JT808Serializer.Deserialize<JT808_0x0301>(bytes); | |||||
Assert.Equal(123, jT808_0X8104.EventId); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0302Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0302 jT808_0X0302 = new JT808_0x0302 | |||||
{ | |||||
AnswerId = 123, | |||||
ReplySNo = 4521 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0302).ToHexString(); | |||||
Assert.Equal("11A97B", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
byte[] bytes = "11A97B".ToHexBytes(); | |||||
JT808_0x0302 jT808_0X0302 = JT808Serializer.Deserialize<JT808_0x0302>(bytes); | |||||
Assert.Equal(123, jT808_0X0302.AnswerId); | |||||
Assert.Equal(4521, jT808_0X0302.ReplySNo); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0303Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0303 jT808_0X0303 = new JT808_0x0303 | |||||
{ | |||||
Flag = 123, | |||||
InformationType = 12 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0303).ToHexString(); | |||||
Assert.Equal("0C7B", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
byte[] bytes = "0C7B".ToHexBytes(); | |||||
JT808_0x0303 jT808_0X0303 = JT808Serializer.Deserialize<JT808_0x0303>(bytes); | |||||
Assert.Equal(123, jT808_0X0303.Flag); | |||||
Assert.Equal(12, jT808_0X0303.InformationType); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,74 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0500Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.车辆控制应答.ToUInt16Value(), | |||||
MsgNum = 8888, | |||||
TerminalPhoneNo = "112233445566", | |||||
} | |||||
}; | |||||
JT808_0x0500 jT808_0X0500 = new JT808_0x0500(); | |||||
JT808_0x0200 JT808_0x0200_1 = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-07-15 10:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>() | |||||
}; | |||||
JT808_0x0200_1.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
JT808_0x0200_1.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 55 | |||||
}); | |||||
jT808_0X0500.JT808_0x0200 = JT808_0x0200_1; | |||||
jT808_0X0500.MsgNum = 1000; | |||||
jT808Package.Bodies = jT808_0X0500; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E0500002811223344556622B803E8000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037B57E".Length, hex.Length); | |||||
Assert.Equal("7E0500002811223344556622B803E8000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037B57E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "7E0500002811223344556622B803E8000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037B57E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.车辆控制应答.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(8888, jT808Package.Header.MsgNum); | |||||
Assert.Equal("112233445566", jT808Package.Header.TerminalPhoneNo); | |||||
JT808_0x0500 JT808Bodies = (JT808_0x0500)jT808Package.Bodies; | |||||
Assert.Equal(1000, JT808Bodies.MsgNum); | |||||
Assert.Equal((uint)1, JT808Bodies.JT808_0x0200.AlarmFlag); | |||||
Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), JT808Bodies.JT808_0x0200.GPSTime); | |||||
Assert.Equal(12222222, JT808Bodies.JT808_0x0200.Lat); | |||||
Assert.Equal(132444444, JT808Bodies.JT808_0x0200.Lng); | |||||
Assert.Equal(0, JT808Bodies.JT808_0x0200.Direction); | |||||
Assert.Equal(60, JT808Bodies.JT808_0x0200.Speed); | |||||
Assert.Equal((uint)2, JT808Bodies.JT808_0x0200.StatusFlag); | |||||
Assert.Equal(100, ((JT808_0x0200_0x01)JT808Bodies.JT808_0x0200.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x01]).Mileage); | |||||
Assert.Equal(55, ((JT808_0x0200_0x02)JT808Bodies.JT808_0x0200.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x02]).Oil); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,16 @@ | |||||
using JT808.Protocol.Attributes; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Test.MessageBody.JT808Formatters; | |||||
namespace JT808.Protocol.Test.MessageBody.JT808_0x0701BodiesImpl | |||||
{ | |||||
[JT808Formatter(typeof(JT808_0x0701TestBodiesImplFormatter))] | |||||
public class JT808_0x0701TestBodiesImpl: JT808_0x0701_CustomBodyBase | |||||
{ | |||||
public uint Id { get; set; } | |||||
public ushort UserNameLength { get; set; } | |||||
public string UserName { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,47 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Test.MessageBody.JT808_0x0701BodiesImpl; | |||||
using System.Reflection; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0701Test | |||||
{ | |||||
JT808Serializer JT808Serializer; | |||||
public JT808_0x0701Test() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0701 jT808_0X0701 = new JT808_0x0701(); | |||||
var body = new JT808_0x0701TestBodiesImpl | |||||
{ | |||||
Id = 333, | |||||
UserName = "汉smallchi" | |||||
}; | |||||
jT808_0X0701.ElectronicContentObj = body; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0701).ToHexString(); | |||||
Assert.Equal("000000100000014D000ABABA736D616C6C636869", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "000000100000014D000ABABA736D616C6C636869".ToHexBytes(); | |||||
JT808_0x0701 jT808_0X0701 = JT808Serializer.Deserialize<JT808_0x0701>(bytes); | |||||
Assert.Equal((uint)16, jT808_0X0701.ElectronicWaybillLength); | |||||
JT808_0x0701TestBodiesImpl jT808_0X0701_content = JT808Serializer.Deserialize<JT808_0x0701TestBodiesImpl>(jT808_0X0701.ElectronicContent); | |||||
Assert.Equal((uint)333, jT808_0X0701_content.Id); | |||||
Assert.Equal("汉smallchi", jT808_0X0701_content.UserName); | |||||
Assert.Equal(10, jT808_0X0701_content.UserNameLength); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,88 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0702Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0702 jT808_0X0702 = new JT808_0x0702 | |||||
{ | |||||
IC_Card_Status = JT808ICCardStatus.从业资格证IC卡拔出_驾驶员下班, | |||||
IC_Card_PlugDateTime = DateTime.Parse("2018-08-16 09:16:16") | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0702).ToHexString(); | |||||
Assert.Equal("02 18 08 16 09 16 16".Replace(" ", ""), hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_2() | |||||
{ | |||||
byte[] bytes = "02 18 08 16 09 16 16".ToHexBytes(); | |||||
JT808_0x0702 jT808_0X0702 = JT808Serializer.Deserialize<JT808_0x0702>(bytes); | |||||
Assert.Equal(JT808ICCardStatus.从业资格证IC卡拔出_驾驶员下班, jT808_0X0702.IC_Card_Status); | |||||
Assert.Equal(DateTime.Parse("2018-08-16 09:16:16"), jT808_0X0702.IC_Card_PlugDateTime); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
JT808_0x0702 jT808_0X0702 = new JT808_0x0702 | |||||
{ | |||||
IC_Card_Status = JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班, | |||||
IC_Card_PlugDateTime = DateTime.Parse("2018-08-16 09:16:16"), | |||||
IC_Card_ReadResult = JT808ICCardReadResult.读卡失败_原因为卡片密钥认证未通过 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0702).ToHexString(); | |||||
Assert.Equal("01 18 08 16 09 16 16 01".Replace(" ", ""), hex); | |||||
} | |||||
[Fact] | |||||
public void Test2_2() | |||||
{ | |||||
byte[] bytes = "01 18 08 16 09 16 16 01".ToHexBytes(); | |||||
JT808_0x0702 jT808_0X0702 = JT808Serializer.Deserialize<JT808_0x0702>(bytes); | |||||
Assert.Equal(JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班, jT808_0X0702.IC_Card_Status); | |||||
Assert.Equal(DateTime.Parse("2018-08-16 09:16:16"), jT808_0X0702.IC_Card_PlugDateTime); | |||||
Assert.Equal(JT808ICCardReadResult.读卡失败_原因为卡片密钥认证未通过, jT808_0X0702.IC_Card_ReadResult); | |||||
} | |||||
[Fact] | |||||
public void Test3() | |||||
{ | |||||
JT808_0x0702 jT808_0X0702 = new JT808_0x0702 | |||||
{ | |||||
IC_Card_Status = JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班, | |||||
IC_Card_PlugDateTime = DateTime.Parse("2018-08-16 09:16:16"), | |||||
IC_Card_ReadResult = JT808ICCardReadResult.IC卡读卡成功, | |||||
DriverUserName = "koike", | |||||
QualificationCode = "qwe123456aaa", | |||||
LicenseIssuing = "qwertx", | |||||
CertificateExpiresDate = DateTime.Parse("2018-08-16") | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0702).ToHexString(); | |||||
Assert.Equal("01 18 08 16 09 16 16 00 05 6B 6F 69 6B 65 71 77 65 31 32 33 34 35 36 61 61 61 30 30 30 30 30 30 30 30 06 71 77 65 72 74 78 07 E2 08 16".Replace(" ", ""), hex); | |||||
//"01 18 08 16 09 16 16 00 05 6B 6F 69 6B 65 71 77 65 31 32 33 34 35 36 61 61 61 30 30 30 30 30 30 30 30 06 71 77 65 72 74 78 07 E2 08 16" | |||||
} | |||||
[Fact] | |||||
public void Test3_1() | |||||
{ | |||||
byte[] bytes = "01 18 08 16 09 16 16 00 05 6B 6F 69 6B 65 71 77 65 31 32 33 34 35 36 61 61 61 30 30 30 30 30 30 30 30 06 71 77 65 72 74 78 07 E2 08 16".ToHexBytes(); | |||||
JT808_0x0702 jT808_0X0702 = JT808Serializer.Deserialize<JT808_0x0702>(bytes); | |||||
Assert.Equal(JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班, jT808_0X0702.IC_Card_Status); | |||||
Assert.Equal(DateTime.Parse("2018-08-16 09:16:16"), jT808_0X0702.IC_Card_PlugDateTime); | |||||
Assert.Equal(JT808ICCardReadResult.IC卡读卡成功, jT808_0X0702.IC_Card_ReadResult); | |||||
Assert.Equal("koike", jT808_0X0702.DriverUserName); | |||||
Assert.Equal("qwe123456aaa00000000", jT808_0X0702.QualificationCode); | |||||
Assert.Equal("qwertx", jT808_0X0702.LicenseIssuing); | |||||
Assert.Equal(DateTime.Parse("2018-08-16"), jT808_0X0702.CertificateExpiresDate); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,155 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0704Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.定位数据批量上传.ToUInt16Value(), | |||||
MsgNum = 8888, | |||||
TerminalPhoneNo = "112233445566", | |||||
} | |||||
}; | |||||
JT808_0x0704 jT808_0X0704 = new JT808_0x0704 | |||||
{ | |||||
Count = 2, | |||||
LocationType = JT808_0x0704.BatchLocationType.正常位置批量汇报 | |||||
}; | |||||
JT808_0x0200 JT808_0x0200_1 = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-07-15 10:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>() | |||||
}; | |||||
JT808_0x0200_1.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
JT808_0x0200_1.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 55 | |||||
}); | |||||
List<JT808_0x0200> jT808_0X0200s = new List<JT808_0x0200>(); | |||||
jT808_0X0200s.Add(JT808_0x0200_1); | |||||
JT808_0x0200 JT808_0x0200_2 = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 2, | |||||
Altitude = 41, | |||||
GPSTime = DateTime.Parse("2018-07-15 10:10:30"), | |||||
Lat = 13333333, | |||||
Lng = 132555555, | |||||
Speed = 54, | |||||
Direction = 120, | |||||
StatusFlag = 1, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>() | |||||
}; | |||||
JT808_0x0200_2.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 96 | |||||
}); | |||||
JT808_0x0200_2.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 66 | |||||
}); | |||||
jT808_0X0200s.Add(JT808_0x0200_2); | |||||
jT808_0X0704.Positions = jT808_0X0200s; | |||||
jT808Package.Bodies = jT808_0X0704; | |||||
//7E | |||||
//07 04 | |||||
//00 53 | |||||
//11 22 33 44 55 66 | |||||
//22 B8 | |||||
//00 02 | |||||
//00 | |||||
//00 26 | |||||
//00 00 00 01 | |||||
//00 00 00 02 | |||||
//00 BA 7F 0E | |||||
//07 E4 F1 1C | |||||
//00 28 | |||||
//00 3C | |||||
//00 00 | |||||
//18 07 15 10 10 10 | |||||
//01 | |||||
// 04 | |||||
// 00 00 00 64 | |||||
//02 | |||||
// 02 | |||||
// 00 37 | |||||
//00 26 | |||||
//00 00 00 02 | |||||
//00 00 00 01 | |||||
//00 CB 73 55 | |||||
//07 E6 A3 23 | |||||
//00 29 | |||||
//00 36 | |||||
//00 78 | |||||
//18 07 15 10 10 30 | |||||
//01 | |||||
// 04 | |||||
// 00 00 00 60 | |||||
//02 | |||||
// 02 | |||||
// 00 42 | |||||
//D4 | |||||
//7E | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E0704005311223344556622B80002000026000000010000000200BA7F0E07E4F11C0028003C0000180715101010010400000064020200370026000000020000000100CB735507E6A32300290036007818071510103001040000006002020042D47E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "7E 07 04 00 53 11 22 33 44 55 66 22 B8 00 02 00 00 26 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37 00 26 00 00 00 02 00 00 00 01 00 CB 73 55 07 E6 A3 23 00 29 00 36 00 78 18 07 15 10 10 30 01 04 00 00 00 60 02 02 00 42 D4 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.定位数据批量上传.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(8888, jT808Package.Header.MsgNum); | |||||
Assert.Equal("112233445566", jT808Package.Header.TerminalPhoneNo); | |||||
JT808_0x0704 JT808Bodies = (JT808_0x0704)jT808Package.Bodies; | |||||
Assert.Equal(2, JT808Bodies.Count); | |||||
Assert.Equal(JT808_0x0704.BatchLocationType.正常位置批量汇报, JT808Bodies.LocationType); | |||||
Assert.Equal((uint)1, JT808Bodies.Positions[0].AlarmFlag); | |||||
Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), JT808Bodies.Positions[0].GPSTime); | |||||
Assert.Equal(12222222, JT808Bodies.Positions[0].Lat); | |||||
Assert.Equal(132444444, JT808Bodies.Positions[0].Lng); | |||||
Assert.Equal(0, JT808Bodies.Positions[0].Direction); | |||||
Assert.Equal(60, JT808Bodies.Positions[0].Speed); | |||||
Assert.Equal((uint)2, JT808Bodies.Positions[0].StatusFlag); | |||||
Assert.Equal(100, ((JT808_0x0200_0x01)JT808Bodies.Positions[0].JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x01]).Mileage); | |||||
Assert.Equal(55, ((JT808_0x0200_0x02)JT808Bodies.Positions[0].JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x02]).Oil); | |||||
Assert.Equal((uint)2, JT808Bodies.Positions[1].AlarmFlag); | |||||
Assert.Equal(DateTime.Parse("2018-07-15 10:10:30"), JT808Bodies.Positions[1].GPSTime); | |||||
Assert.Equal(13333333, JT808Bodies.Positions[1].Lat); | |||||
Assert.Equal(132555555, JT808Bodies.Positions[1].Lng); | |||||
Assert.Equal(54, JT808Bodies.Positions[1].Speed); | |||||
Assert.Equal(120, JT808Bodies.Positions[1].Direction); | |||||
Assert.Equal((uint)1, JT808Bodies.Positions[1].StatusFlag); | |||||
Assert.Equal(96, ((JT808_0x0200_0x01)JT808Bodies.Positions[1].JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x01]).Mileage); | |||||
Assert.Equal(66, ((JT808_0x0200_0x02)JT808Bodies.Positions[1].JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x02]).Oil); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,52 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
using JT808.Protocol.Metadata; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0705Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0705 jT808_0X0705 = new JT808_0x0705 | |||||
{ | |||||
FirstCanReceiveTime = DateTime.Parse("2018-11-15 20:00:05.350"), | |||||
CanItems = new List<JT808CanProperty>() | |||||
}; | |||||
jT808_0X0705.CanItems.Add(new JT808CanProperty() | |||||
{ | |||||
CanId = new byte[] { 0x01, 0x02, 0x03, 0x04 }, | |||||
CanData = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }, | |||||
}); | |||||
jT808_0X0705.CanItems.Add(new JT808CanProperty() | |||||
{ | |||||
CanId = new byte[] { 0x05, 0x06, 0x07, 0x08 }, | |||||
CanData = new byte[] { 0x01, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01 }, | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808_0X0705).ToHexString(); | |||||
Assert.Equal("0002200005015E010203040102030401020304050607080103040506070801", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "0002200005015E010203040102030401020304050607080103040506070801".ToHexBytes(); | |||||
JT808_0x0705 jT808_0X0705 = JT808Serializer.Deserialize<JT808_0x0705>(bytes); | |||||
Assert.Equal(2, jT808_0X0705.CanItemCount); | |||||
Assert.Equal(DateTime.Parse("20:00:05.350"), jT808_0X0705.FirstCanReceiveTime); | |||||
Assert.Equal(new byte[] { 0x01, 0x02, 0x03, 0x04 }, jT808_0X0705.CanItems[0].CanId); | |||||
Assert.Equal(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }, jT808_0X0705.CanItems[0].CanData); | |||||
Assert.Equal(new byte[] { 0x05, 0x06, 0x07, 0x08 }, jT808_0X0705.CanItems[1].CanId); | |||||
Assert.Equal(new byte[] { 0x01, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01 }, jT808_0X0705.CanItems[1].CanData); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,37 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0800Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0800 jT808_0X0800 = new JT808_0x0800 | |||||
{ | |||||
MultimediaId = 5569, | |||||
MultimediaType = 0x01, | |||||
MultimediaCodingFormat = 0x02, | |||||
ChannelId = 0x06, | |||||
EventItemCoding = 0x01 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0800).ToHexString(); | |||||
Assert.Equal("000015C101020106", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "000015C101020106".ToHexBytes(); | |||||
JT808_0x0800 jT808_0X0800 = JT808Serializer.Deserialize<JT808_0x0800>(bytes); | |||||
Assert.Equal((uint)5569, jT808_0X0800.MultimediaId); | |||||
Assert.Equal(0x01, jT808_0X0800.MultimediaType); | |||||
Assert.Equal(0x02, jT808_0X0800.MultimediaCodingFormat); | |||||
Assert.Equal(0x06, jT808_0X0800.ChannelId); | |||||
Assert.Equal(0x01, jT808_0X0800.EventItemCoding); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,95 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Reflection; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0801Test | |||||
{ | |||||
JT808Serializer JT808Serializer; | |||||
public JT808_0x0801Test() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
jT808Config.SkipCRCCode = true; | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0801 jT808_0X0801 = new JT808_0x0801 | |||||
{ | |||||
ChannelId = 123, | |||||
EventItemCoding = JT808EventItemCoding.定时动作.ToByteValue(), | |||||
MultimediaCodingFormat = JT808MultimediaCodingFormat.JPEG.ToByteValue(), | |||||
MultimediaId = 2567, | |||||
MultimediaType = JT808MultimediaType.图像.ToByteValue(), | |||||
MultimediaDataPackage = new byte[] { 0x01, 0x02, 0x03, 0x04 }, | |||||
Position = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-11-15 23:26:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2 | |||||
} | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X0801).ToHexString(); | |||||
Assert.Equal("00000A070000017B000000010000000200BA7F0E07E4F11C0028003C000018111523261001020304", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "00000A070000017B000000010000000200BA7F0E07E4F11C0028003C000018111523261001020304".ToHexBytes(); | |||||
JT808_0x0801 jT808_0X0801 = JT808Serializer.Deserialize<JT808_0x0801>(bytes); | |||||
Assert.Equal(123, jT808_0X0801.ChannelId); | |||||
Assert.Equal(JT808EventItemCoding.定时动作.ToByteValue(), jT808_0X0801.EventItemCoding); | |||||
Assert.Equal(JT808MultimediaCodingFormat.JPEG.ToByteValue(), jT808_0X0801.MultimediaCodingFormat); | |||||
Assert.Equal((uint)2567, jT808_0X0801.MultimediaId); | |||||
Assert.Equal(JT808MultimediaType.图像.ToByteValue(), jT808_0X0801.MultimediaType); | |||||
Assert.Equal(new byte[] { 0x01, 0x02, 0x03, 0x04 }, jT808_0X0801.MultimediaDataPackage); | |||||
Assert.Equal((uint)1, jT808_0X0801.Position.AlarmFlag); | |||||
Assert.Equal(40, jT808_0X0801.Position.Altitude); | |||||
Assert.Equal(DateTime.Parse("2018-11-15 23:26:10"), jT808_0X0801.Position.GPSTime); | |||||
Assert.Equal(40, jT808_0X0801.Position.Altitude); | |||||
Assert.Equal(12222222, jT808_0X0801.Position.Lat); | |||||
Assert.Equal(132444444, jT808_0X0801.Position.Lng); | |||||
Assert.Equal(60, jT808_0X0801.Position.Speed); | |||||
Assert.Equal(0, jT808_0X0801.Position.Direction); | |||||
Assert.Equal((uint)2, jT808_0X0801.Position.StatusFlag); | |||||
} | |||||
[Fact] | |||||
public void Package1() | |||||
{ | |||||
byte[] bytes = "7e080123240138123456782031000a00010000271d0000010100000000000c200301d2400a063296a501e100000000190104092952ffd8ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d0101020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffdb004300080606070605080707070909080a0c140d0c0b0b0c1912130f141d1a1f1e1d1a1c1c20242e2720222c231c1c2837292c30313434341f27393d38323c2e333432ffdb0043010909090c0b0c180d0d1832211c213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232fffe000b4750456e636f646572ffdb0043000d090a0b0a080d0b0a0b0e0e0d0f13201513121213271c1e17202e2931302e292d2c333a4a3e333646372c2d405741464c4e525352323e5a615a50604a51524fffdb0043010e0e0e131113261515264f352d354f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4fffc000110800f0014003012100021101031101ffc4001f000001050101010101010000000000000000010203041c7e".ToHexBytes(); | |||||
JT808Package jT808_0X0801 = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
} | |||||
[Fact] | |||||
public void Package2() | |||||
{ | |||||
byte[] bytes = "7e080123000138123456782032000a000205060708090a0bffc400b5100002010303020403050504040000017d0101020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffdd00040000ffda000c03010002110311003f006c6a2a755ce299a5c942e0f35281c5004aa72314a54e38a07b8841ef4840a0673de21b4ff498ee402038dade991fe7f4acc110f4a0cd8ef2f1405cd01d45f2e9360a062edc5745616a6dad511861cfccff0053499512e056cf1460e3348a0ed4b8e338fc2819cb5edbfd9ee648b18556f97fdd3d3f4aafb4d332ea433a6573e9550d3131d18c9c558031c0a4083a503039a60c42c2984e4f4a06260d370690098ef4751400c615132d021868a621431a33480ef235e05595403eb54cbb0b8e7069dc0e3a9a41b12a024f4a9d40f4a18c5651e951c88179268194ee614b989a2719461ffea35cfdcda4b6b2ed71c1e55874345c96ba91819a704c50217613db349b39031c9e945c66a69ba794713cebf30fb8be9ee6b540c1e948a48760e3a526d2dc77a0a144471d297cb623a71484646bb685234b81d01d8e7d018f43f9ff003ac16386c552225b8300c2a84c8c8c4ed247b502616cc0517e".ToHexBytes(); | |||||
JT808Package jT808_0X0801 = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
} | |||||
[Fact] | |||||
public void Package3() | |||||
{ | |||||
byte[] bytes = "7e080123000138123456782032000a000205060708090a0bffc400b5100002010303020403050504040000017d0101020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffdd00040000ffda000c03010002110311003f006c6a2a755ce299a5c942e0f35281c5004aa72314a54e38a07b8841ef4840a0673de21b4ff498ee402038dade991fe7f4acc110f4a0cd8ef2f1405cd01d45f2e9360a062edc5745616a6dad511861cfccff0053499512e056cf1460e3348a0ed4b8e338fc2819cb5edbfd9ee648b18556f97fdd3d3f4aafb4d332ea433a6573e9550d3131d18c9c558031c0a4083a503039a60c42c2984e4f4a06260d370690098ef4751400c615132d021868a621431a33480ef235e05595403eb54cbb0b8e7069dc0e3a9a41b12a024f4a9d40f4a18c5651e951c88179268194ee614b989a2719461ffea35cfdcda4b6b2ed71c1e55874345c96ba91819a704c50217613db349b39031c9e945c66a69ba794713cebf30fb8be9ee6b540c1e948a48760e3a526d2dc77a0a144471d297cb623a71484646bb685234b81d01d8e7d018f43f9ff003ac16386c552225b8300c2a84c8c8c4ed247b502616cc0517e".ToHexBytes(); | |||||
JT808HeaderPackage jT808_0X0801 = JT808Serializer.Deserialize<JT808HeaderPackage>(bytes); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,103 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
using JT808.Protocol.Metadata; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0802Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0802 jT808_0X0802 = new JT808_0x0802 | |||||
{ | |||||
MsgNum = 12369, | |||||
MultimediaSearchItems = new List<JT808MultimediaSearchProperty>() | |||||
}; | |||||
jT808_0X0802.MultimediaSearchItems.Add(new JT808MultimediaSearchProperty() | |||||
{ | |||||
ChannelId = 123, | |||||
EventItemCoding = JT808EventItemCoding.定时动作.ToByteValue(), | |||||
MultimediaId = 258, | |||||
MultimediaType = JT808MultimediaType.图像.ToByteValue(), | |||||
Position = new JT808_0x0200() | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-11-16 20:20:20"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
} | |||||
}); | |||||
jT808_0X0802.MultimediaSearchItems.Add(new JT808MultimediaSearchProperty() | |||||
{ | |||||
ChannelId = 124, | |||||
EventItemCoding = JT808EventItemCoding.平台下发指令.ToByteValue(), | |||||
MultimediaId = 259, | |||||
MultimediaType = JT808MultimediaType.视频.ToByteValue(), | |||||
Position = new JT808_0x0200() | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-11-16 22:22:22"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
} | |||||
}); | |||||
string hex = JT808Serializer.Serialize(jT808_0X0802).ToHexString(); | |||||
Assert.Equal("3051000200000102007B01000000010000000200BA7F0E07E4F11C0028003C000018111620202000000103027C00000000010000000200BA7F0E07E4F11C0028003C0000181116222222", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "3051000200000102007B01000000010000000200BA7F0E07E4F11C0028003C000018111620202000000103027C00000000010000000200BA7F0E07E4F11C0028003C0000181116222222".ToHexBytes(); | |||||
JT808_0x0802 jT808_0X0802 = JT808Serializer.Deserialize<JT808_0x0802>(bytes); | |||||
Assert.Equal(12369, jT808_0X0802.MsgNum); | |||||
Assert.Equal(2, jT808_0X0802.MultimediaItemCount); | |||||
Assert.Equal(123, jT808_0X0802.MultimediaSearchItems[0].ChannelId); | |||||
Assert.Equal(JT808EventItemCoding.定时动作.ToByteValue(), jT808_0X0802.MultimediaSearchItems[0].EventItemCoding); | |||||
Assert.Equal(JT808MultimediaType.图像.ToByteValue(), jT808_0X0802.MultimediaSearchItems[0].MultimediaType); | |||||
Assert.Equal((uint)258, jT808_0X0802.MultimediaSearchItems[0].MultimediaId); | |||||
Assert.Equal((uint)1, jT808_0X0802.MultimediaSearchItems[0].Position.AlarmFlag); | |||||
Assert.Equal((ushort)40, jT808_0X0802.MultimediaSearchItems[0].Position.Altitude); | |||||
Assert.Equal(DateTime.Parse("2018-11-16 20:20:20"), jT808_0X0802.MultimediaSearchItems[0].Position.GPSTime); | |||||
Assert.Equal(12222222, jT808_0X0802.MultimediaSearchItems[0].Position.Lat); | |||||
Assert.Equal(132444444, jT808_0X0802.MultimediaSearchItems[0].Position.Lng); | |||||
Assert.Equal((ushort)60, jT808_0X0802.MultimediaSearchItems[0].Position.Speed); | |||||
Assert.Equal((ushort)0, jT808_0X0802.MultimediaSearchItems[0].Position.Direction); | |||||
Assert.Equal((uint)2, jT808_0X0802.MultimediaSearchItems[0].Position.StatusFlag); | |||||
Assert.Equal(124, jT808_0X0802.MultimediaSearchItems[1].ChannelId); | |||||
Assert.Equal(JT808EventItemCoding.平台下发指令.ToByteValue(), jT808_0X0802.MultimediaSearchItems[1].EventItemCoding); | |||||
Assert.Equal(JT808MultimediaType.视频.ToByteValue(), jT808_0X0802.MultimediaSearchItems[1].MultimediaType); | |||||
Assert.Equal((uint)259, jT808_0X0802.MultimediaSearchItems[1].MultimediaId); | |||||
Assert.Equal((uint)1, jT808_0X0802.MultimediaSearchItems[1].Position.AlarmFlag); | |||||
Assert.Equal((ushort)40, jT808_0X0802.MultimediaSearchItems[1].Position.Altitude); | |||||
Assert.Equal(DateTime.Parse("2018-11-16 22:22:22"), jT808_0X0802.MultimediaSearchItems[1].Position.GPSTime); | |||||
Assert.Equal(12222222, jT808_0X0802.MultimediaSearchItems[1].Position.Lat); | |||||
Assert.Equal(132444444, jT808_0X0802.MultimediaSearchItems[1].Position.Lng); | |||||
Assert.Equal((ushort)60, jT808_0X0802.MultimediaSearchItems[1].Position.Speed); | |||||
Assert.Equal((ushort)0, jT808_0X0802.MultimediaSearchItems[1].Position.Direction); | |||||
Assert.Equal((uint)2, jT808_0X0802.MultimediaSearchItems[1].Position.StatusFlag); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,41 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0805Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0805 jT808_0X0805 = new JT808_0x0805(); | |||||
jT808_0X0805.MsgNum = 12456; | |||||
jT808_0X0805.Result = 1; | |||||
jT808_0X0805.MultimediaIds = new List<uint>() | |||||
{ | |||||
12306, | |||||
12580 | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X0805).ToHexString(); | |||||
Assert.Equal("30A80100020000301200003124", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "30A80100020000301200003124".ToHexBytes(); | |||||
JT808_0x0805 jT808_0X0805 = JT808Serializer.Deserialize<JT808_0x0805>(bytes); | |||||
Assert.Equal(12456, jT808_0X0805.MsgNum); | |||||
Assert.Equal(1, jT808_0X0805.Result); | |||||
Assert.Equal(2, jT808_0X0805.MultimediaIdCount); | |||||
Assert.Equal(new List<uint>() | |||||
{ | |||||
12306, | |||||
12580 | |||||
}, jT808_0X0805.MultimediaIds); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,57 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Test.JT808_0x0900_BodiesImpl; | |||||
using System.Reflection; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0900Test | |||||
{ | |||||
JT808Serializer JT808Serializer; | |||||
public JT808_0x0900Test() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808_0X0900 = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.数据上行透传.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "123456789", | |||||
}, | |||||
Bodies = new JT808_0x0900 | |||||
{ | |||||
JT808_0x0900_BodyBase = new JT808_0x0900_0x83() { PassthroughContent = "smallchi" }, | |||||
PassthroughType = 0x83 | |||||
} | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0900).ToHexString(); | |||||
Assert.Equal("7E09000009000123456789000A83736D616C6C6368691D7E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
byte[] bytes = "7E 09 00 00 09 00 01 23 45 67 89 00 0A 83 73 6D 61 6C 6C 63 68 69 1D 7E".ToHexBytes(); | |||||
JT808Package jT808_0X0900 = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.数据上行透传.ToUInt16Value(), jT808_0X0900.Header.MsgId); | |||||
Assert.Equal(10, jT808_0X0900.Header.MsgNum); | |||||
Assert.Equal("123456789", jT808_0X0900.Header.TerminalPhoneNo); | |||||
JT808_0x0900 JT808Bodies = (JT808_0x0900)jT808_0X0900.Bodies; | |||||
JT808_0x0900_0x83 jT808_0x0900_0x83 = JT808Serializer.Deserialize<JT808_0x0900_0x83>(JT808Bodies.PassthroughData); | |||||
Assert.Equal("smallchi", jT808_0x0900_0x83.PassthroughContent); | |||||
Assert.Equal(0x83, JT808Bodies.PassthroughType); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,15 @@ | |||||
using JT808.Protocol.Attributes; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Test.MessageBody.JT808Formatters; | |||||
namespace JT808.Protocol.Test.JT808_0x0900_BodiesImpl | |||||
{ | |||||
[JT808Formatter(typeof(JT808_0x0900_0x83Formatter))] | |||||
public class JT808_0x0900_0x83 : JT808_0x0900_BodyBase | |||||
{ | |||||
/// <summary> | |||||
/// 透传内容 | |||||
/// </summary> | |||||
public string PassthroughContent { get; set; } | |||||
} | |||||
} |
@@ -0,0 +1,41 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Runtime.InteropServices; | |||||
using System.Text; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0901Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
const string UserName = "smallchismallchismallchismallchismallchismallchismallchismallchismallchismallchismallchi"; | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0901 jT808_0X0901 = new JT808_0x0901(); | |||||
var data = Encoding.UTF8.GetBytes(UserName); | |||||
jT808_0X0901.UnCompressMessage = data; | |||||
var hex = JT808Serializer.Serialize(jT808_0X0901).ToHexString(); | |||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | |||||
{ | |||||
Assert.Equal("0000001F1F8B08000000000000032BCE4DCCC949CEC82CA6320D0027F897E258000000", hex); | |||||
} | |||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | |||||
{ | |||||
Assert.Equal("0000001F1F8B080000000000000B2BCE4DCCC949CEC82CA6320D0027F897E258000000", hex); | |||||
} | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "0000001F1F8B080000000000000B2BCE4DCCC949CEC82CA6320D0027F897E258000000".ToHexBytes(); | |||||
JT808_0x0901 jT808_0X8600 = JT808Serializer.Deserialize<JT808_0x0901>(bytes); | |||||
Assert.Equal((uint)88, jT808_0X8600.UnCompressMessageLength); | |||||
Assert.Equal(Encoding.UTF8.GetBytes(UserName), jT808_0X8600.UnCompressMessage); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,40 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Linq; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x0A00Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
byte[] N; | |||||
public JT808_0x0A00Test() | |||||
{ | |||||
N = Enumerable.Range(0, 128).Select(s => Convert.ToByte(s)).ToArray(); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x0A00 jT808_0X0A00 = new JT808_0x0A00 | |||||
{ | |||||
E = 128, | |||||
N = N | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X0A00).ToHexString(); | |||||
Assert.Equal("00000080000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "00000080000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F".ToHexBytes(); | |||||
JT808_0x0A00 jT808_0X0A00 = JT808Serializer.Deserialize<JT808_0x0A00>(bytes); | |||||
Assert.Equal((uint)128, jT808_0X0A00.E); | |||||
Assert.Equal(N, jT808_0X0A00.N); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,57 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8001Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.平台通用应答.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "12345678900", | |||||
}, | |||||
Bodies = new JT808_0x8001 | |||||
{ | |||||
MsgId = Enums.JT808MsgId.位置信息汇报.ToUInt16Value(), | |||||
JT808PlatformResult = Enums.JT808PlatformResult.成功, | |||||
MsgNum = 100 | |||||
} | |||||
}; | |||||
//"7E | |||||
//80 01 | |||||
//00 05 | |||||
//01 23 45 67 89 00 | |||||
//00 0A | |||||
//00 64 | |||||
//02 00 | |||||
//00 | |||||
//61 | |||||
//7E" | |||||
var hex = JT808Serializer.Serialize(jT808Package).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(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.平台通用应答.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(10, jT808Package.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808Package.Header.TerminalPhoneNo); | |||||
JT808_0x8001 JT808Bodies = (JT808_0x8001)jT808Package.Bodies; | |||||
Assert.Equal(Enums.JT808MsgId.位置信息汇报.ToUInt16Value(), JT808Bodies.MsgId); | |||||
Assert.Equal(100, JT808Bodies.MsgNum); | |||||
Assert.Equal(Enums.JT808PlatformResult.成功, JT808Bodies.JT808PlatformResult); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,33 @@ | |||||
using System.Text; | |||||
using Xunit; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8003Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8003 jT808_0X8003 = new JT808_0x8003 | |||||
{ | |||||
OriginalMsgNum = 1234, | |||||
AgainPackageData = new byte[] { 0x01, 0x02, 0x02, 0x03 } | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X8003).ToHexString(); | |||||
Assert.Equal("04D20201020203", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "04D20201020203".ToHexBytes(); | |||||
JT808_0x8003 jT808_0X8003 = JT808Serializer.Deserialize<JT808_0x8003>(bytes); | |||||
Assert.Equal(1234, jT808_0X8003.OriginalMsgNum); | |||||
Assert.Equal(new byte[] { 0x01, 0x02, 0x02, 0x03 }, jT808_0X8003.AgainPackageData); | |||||
Assert.Equal(2, jT808_0X8003.AgainPackageCount); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,142 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8100Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端注册应答.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "012345678900", | |||||
}, | |||||
Bodies = new JT808_0x8100 | |||||
{ | |||||
Code = "123456", | |||||
JT808TerminalRegisterResult = Enums.JT808TerminalRegisterResult.成功, | |||||
MsgNum = 100 | |||||
} | |||||
}; | |||||
//"7E | |||||
//81 00 | |||||
//00 09 | |||||
//01 23 45 67 89 00 | |||||
//00 0A | |||||
//00 64 | |||||
//00 | |||||
//31 32 33 34 35 36 | |||||
//68 | |||||
//7E" | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E81000009012345678900000A006400313233343536687E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "7E 81 00 00 09 01 23 45 67 89 00 00 0A 00 64 00 31 32 33 34 35 36 68 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端注册应答.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(10, jT808Package.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808Package.Header.TerminalPhoneNo); | |||||
JT808_0x8100 JT808Bodies = (JT808_0x8100)jT808Package.Bodies; | |||||
Assert.Equal("123456", JT808Bodies.Code); | |||||
Assert.Equal(100, JT808Bodies.MsgNum); | |||||
Assert.Equal(Enums.JT808TerminalRegisterResult.成功, JT808Bodies.JT808TerminalRegisterResult); | |||||
} | |||||
[Fact] | |||||
public void Test3() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端注册应答.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "12345678900", | |||||
}, | |||||
Bodies = new JT808_0x8100 | |||||
{ | |||||
Code = "123456", | |||||
JT808TerminalRegisterResult = Enums.JT808TerminalRegisterResult.数据库中无该终端, | |||||
MsgNum = 100 | |||||
} | |||||
}; | |||||
//"7E | |||||
//81 00 | |||||
//00 03 | |||||
//01 23 45 67 89 00 | |||||
//00 0A | |||||
//00 64 | |||||
//04 | |||||
//61 | |||||
//7E" | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E81000003012345678900000A006404617E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test4() | |||||
{ | |||||
var bytes = "7E 81 00 00 03 01 23 45 67 89 00 00 0A 00 64 04 61 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端注册应答.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(10, jT808Package.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808Package.Header.TerminalPhoneNo); | |||||
JT808_0x8100 JT808Bodies = (JT808_0x8100)jT808Package.Bodies; | |||||
Assert.Null(JT808Bodies.Code); | |||||
Assert.Equal(100, JT808Bodies.MsgNum); | |||||
Assert.Equal(Enums.JT808TerminalRegisterResult.数据库中无该终端, JT808Bodies.JT808TerminalRegisterResult); | |||||
} | |||||
[Fact] | |||||
public void Test5() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端注册应答.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "12345678900", | |||||
}, | |||||
Bodies = new JT808_0x8100 | |||||
{ | |||||
Code = "zssdaf23124sfdsc", | |||||
JT808TerminalRegisterResult = Enums.JT808TerminalRegisterResult.成功, | |||||
MsgNum = 100 | |||||
} | |||||
}; | |||||
//"7E 81 00 00 13 01 23 45 67 89 00 00 0A 00 64 00 7A 73 73 64 61 66 32 33 31 32 34 73 66 64 73 63 3B 7E" | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E81000013012345678900000A0064007A7373646166323331323473666473633B7E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test6() | |||||
{ | |||||
var bytes = "7E 81 00 00 13 01 23 45 67 89 00 00 0A 00 64 00 7A 73 73 64 61 66 32 33 31 32 34 73 66 64 73 63 3B 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端注册应答.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(10, jT808Package.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808Package.Header.TerminalPhoneNo); | |||||
JT808_0x8100 JT808Bodies = (JT808_0x8100)jT808Package.Bodies; | |||||
Assert.Equal("zssdaf23124sfdsc", JT808Bodies.Code); | |||||
Assert.Equal(100, JT808Bodies.MsgNum); | |||||
Assert.Equal(Enums.JT808TerminalRegisterResult.成功, JT808Bodies.JT808TerminalRegisterResult); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,126 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Collections.Generic; | |||||
using System.Reflection; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8103Test | |||||
{ | |||||
JT808Serializer JT808Serializer; | |||||
public JT808_0x8103Test() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.设置终端参数.ToUInt16Value(), | |||||
MsgNum = 10, | |||||
TerminalPhoneNo = "123456789", | |||||
}, | |||||
Bodies = new JT808_0x8103 | |||||
{ | |||||
ParamList = new List<JT808_0x8103_BodyBase> { | |||||
new JT808_0x8103_0x0001() { | |||||
ParamId=0x0001, | |||||
ParamLength=4, | |||||
ParamValue=10 | |||||
} | |||||
} | |||||
} | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E8103000A000123456789000A0100000001040000000A057E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
//7E | |||||
//81 03 | |||||
//00 0A | |||||
//00 | |||||
//01 23 45 67 89 00 | |||||
//0A 01 | |||||
//00 00 00 01 | |||||
//04 | |||||
// 00 00 00 0A | |||||
//05 | |||||
//7E | |||||
byte[] bytes = "7E8103000A000123456789000A0100000001040000000A057E".ToHexBytes(); | |||||
JT808Package jT808_0X8103 = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.设置终端参数.ToUInt16Value(), jT808_0X8103.Header.MsgId); | |||||
Assert.Equal(10, jT808_0X8103.Header.MsgNum); | |||||
Assert.Equal("123456789", jT808_0X8103.Header.TerminalPhoneNo); | |||||
JT808_0x8103 JT808Bodies = (JT808_0x8103)jT808_0X8103.Bodies; | |||||
foreach (var item in JT808Bodies.ParamList) | |||||
{ | |||||
Assert.Equal(0x0001u, ((JT808_0x8103_0x0001)item).ParamId); | |||||
Assert.Equal(4, ((JT808_0x8103_0x0001)item).ParamLength); | |||||
Assert.Equal(10u, ((JT808_0x8103_0x0001)item).ParamValue); | |||||
} | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var JT808_0x8103 = new JT808_0x8103 | |||||
{ | |||||
ParamList = new List<JT808_0x8103_BodyBase> { | |||||
new JT808_0x8103_0x0001() { | |||||
ParamId=0x0001, | |||||
ParamLength=4, | |||||
ParamValue=10 | |||||
}, | |||||
new JT808_0x8103_0x0013(){ | |||||
ParamId=0x0013, | |||||
ParamValue="www.baidu.com" | |||||
} | |||||
} | |||||
}; | |||||
var hex = JT808Serializer.Serialize(JT808_0x8103).ToHexString(); | |||||
//"0200000001040000000A000000130D7777772E62616964752E636F6D" | |||||
Assert.Equal("0200000001040000000A000000130D7777772E62616964752E636F6D", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2_1() | |||||
{ | |||||
byte[] bytes = "0200000001040000000A000000130D7777772E62616964752E636F6D".ToHexBytes(); | |||||
JT808_0x8103 jT808_0X8103 = JT808Serializer.Deserialize<JT808_0x8103>(bytes); | |||||
foreach (var item in jT808_0X8103.ParamList) | |||||
{ | |||||
switch (item.ParamId) | |||||
{ | |||||
case 0x0001: | |||||
Assert.Equal(0x0001u, ((JT808_0x8103_0x0001)item).ParamId); | |||||
Assert.Equal(4, ((JT808_0x8103_0x0001)item).ParamLength); | |||||
Assert.Equal(10u, ((JT808_0x8103_0x0001)item).ParamValue); | |||||
break; | |||||
case 0x0013: | |||||
Assert.Equal(0x0013u, ((JT808_0x8103_0x0013)item).ParamId); | |||||
Assert.Equal("www.baidu.com", ((JT808_0x8103_0x0013)item).ParamValue); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,36 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8104Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.查询终端参数.ToUInt16Value(), | |||||
MsgNum = 1, | |||||
TerminalPhoneNo = "12345678900", | |||||
} | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E8104000001234567890000010D7E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "7E8104000001234567890000010D7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.查询终端参数.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(1, jT808Package.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808Package.Header.TerminalPhoneNo); | |||||
Assert.Null(jT808Package.Bodies); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,105 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8105Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端控制.ToUInt16Value(), | |||||
MsgNum = 1, | |||||
TerminalPhoneNo = "12345678900", | |||||
}, | |||||
Bodies = new JT808_0x8105 | |||||
{ | |||||
CommandWord = 1, | |||||
CommandValue = new CommandParams | |||||
{ | |||||
ConnectionControl = 1, | |||||
DialPointName = "TKName", | |||||
DialUserName = "TK", | |||||
DialPwd = "TK123", | |||||
FirmwareVersion = "1.0", | |||||
HardwareVersion = "2.0", | |||||
ConnectTimeLimit = 60, | |||||
ManufacturerCode = 12345, | |||||
MonitoringPlatformAuthenticationCode = "code", | |||||
ServerUrl = "www.baidu.com", | |||||
TCPPort = 8806, | |||||
UDPPort = 3306, | |||||
URL = "www.TK.com" | |||||
} | |||||
} | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E8105004B012345678900000101313B544B4E616D653B544B3B544B3132333B7777772E62616964752E636F6D3B383830363B333330363B31323334353B636F64653B322E303B312E303B7777772E544B2E636F6D3B3630227E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
var bytes = "7E8105004B012345678900000101313B544B4E616D653B544B3B544B3132333B7777772E62616964752E636F6D3B383830363B333330363B31323334353B636F64653B322E303B312E303B7777772E544B2E636F6D3B3630227E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端控制.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(1, jT808Package.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808Package.Header.TerminalPhoneNo); | |||||
var JT808_0x8105 = (JT808_0x8105)jT808Package.Bodies; | |||||
Assert.Equal(1, JT808_0x8105.CommandWord); | |||||
Assert.Equal("www.TK.com", JT808_0x8105.CommandValue.URL); | |||||
Assert.Equal(3306, (int)JT808_0x8105.CommandValue.UDPPort); | |||||
Assert.Equal(8806, (int)JT808_0x8105.CommandValue.TCPPort); | |||||
Assert.Equal("www.baidu.com", JT808_0x8105.CommandValue.ServerUrl); | |||||
Assert.Equal("code", JT808_0x8105.CommandValue.MonitoringPlatformAuthenticationCode); | |||||
Assert.Equal(12345, JT808_0x8105.CommandValue.ManufacturerCode); | |||||
Assert.Equal("2.0", JT808_0x8105.CommandValue.HardwareVersion); | |||||
Assert.Equal("1.0", JT808_0x8105.CommandValue.FirmwareVersion); | |||||
Assert.Equal("TK", JT808_0x8105.CommandValue.DialUserName); | |||||
Assert.Equal("TK123", JT808_0x8105.CommandValue.DialPwd); | |||||
Assert.Equal("TKName", JT808_0x8105.CommandValue.DialPointName); | |||||
Assert.Equal(1, (byte)JT808_0x8105.CommandValue.ConnectionControl); | |||||
Assert.Equal(60, (UInt16)JT808_0x8105.CommandValue.ConnectTimeLimit); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package(); | |||||
jT808Package.Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.终端控制.ToUInt16Value(), | |||||
MsgNum = 1, | |||||
TerminalPhoneNo = "12345678900", | |||||
}; | |||||
jT808Package.Bodies = new JT808_0x8105 | |||||
{ | |||||
CommandWord = 5 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E81050001012345678900000105087E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2_1() | |||||
{ | |||||
var bytes = "7E81050001012345678900000105087E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
Assert.Equal(Enums.JT808MsgId.终端控制.ToUInt16Value(), jT808Package.Header.MsgId); | |||||
Assert.Equal(1, jT808Package.Header.MsgNum); | |||||
Assert.Equal("12345678900", jT808Package.Header.TerminalPhoneNo); | |||||
var JT808_0x8105 = (JT808_0x8105)jT808Package.Bodies; | |||||
Assert.Equal(5, JT808_0x8105.CommandWord); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8106Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8106 jT808_0X8106 = new JT808_0x8106 | |||||
{ | |||||
ParameterCount = 2, | |||||
Parameters = new uint[] { 0x0001, 0x0002 } | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8106).ToHexString(); | |||||
Assert.Equal("020000000100000002", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "020000000100000002".ToHexBytes(); | |||||
JT808_0x8106 jT808_0X8106 = JT808Serializer.Deserialize<JT808_0x8106>(bytes); | |||||
Assert.Equal(2, jT808_0X8106.ParameterCount); | |||||
Assert.Equal(new uint[] { 0x0001, 0x0002 }, jT808_0X8106.Parameters); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,37 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8108Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8108 jT808_0X8108 = new JT808_0x8108 | |||||
{ | |||||
UpgradeType = JT808UpgradeType.北斗卫星定位模块, | |||||
MakerId = "asdfg", | |||||
VersionNum = "qscvhiuytrew", | |||||
UpgradePackage = new byte[] { 1, 2, 3, 4, 5 } | |||||
}; | |||||
//"34 61 73 64 66 67 0C 71 73 63 76 68 69 75 79 74 72 65 77 00 00 00 05 01 02 03 04 05" | |||||
string hex = JT808Serializer.Serialize(jT808_0X8108).ToHexString(); | |||||
Assert.Equal("3461736466670C717363766869757974726577000000050102030405", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "34 61 73 64 66 67 0C 71 73 63 76 68 69 75 79 74 72 65 77 00 00 00 05 01 02 03 04 05".ToHexBytes(); | |||||
JT808_0x8108 jT808_0X8108 = JT808Serializer.Deserialize<JT808_0x8108>(bytes); | |||||
Assert.Equal(JT808UpgradeType.北斗卫星定位模块, jT808_0X8108.UpgradeType); | |||||
Assert.Equal("asdfg", jT808_0X8108.MakerId); | |||||
Assert.Equal("qscvhiuytrew", jT808_0X8108.VersionNum); | |||||
Assert.Equal(new byte[] { 1, 2, 3, 4, 5 }, jT808_0X8108.UpgradePackage); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8202Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8202 jT808_0X8202 = new JT808_0x8202 | |||||
{ | |||||
Interval = 69, | |||||
LocationTrackingValidity = 123 | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8202).ToHexString(); | |||||
Assert.Equal("00450000007B", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "00 45 00 00 00 7B".ToHexBytes(); | |||||
JT808_0x8202 jT808_0X8108 = JT808Serializer.Deserialize<JT808_0x8202>(bytes); | |||||
Assert.Equal(69, jT808_0X8108.Interval); | |||||
Assert.Equal(123, jT808_0X8108.LocationTrackingValidity); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8203Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8203 jT808_0X8203 = new JT808_0x8203 | |||||
{ | |||||
AlarmMsgNum = 5554, | |||||
ManualConfirmAlarmType = 123 | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8203).ToHexString(); | |||||
Assert.Equal("15B20000007B", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "15B20000007B".ToHexBytes(); | |||||
JT808_0x8203 jT808_0X8203 = JT808Serializer.Deserialize<JT808_0x8203>(bytes); | |||||
Assert.Equal(5554, jT808_0X8203.AlarmMsgNum); | |||||
Assert.Equal((uint)123, jT808_0X8203.ManualConfirmAlarmType); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,43 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8300Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
//"7E 83 00 00 0D 01 23 45 67 89 00 00 01 05 73 6D 61 6C 6C 63 68 69 20 35 31 38 02 7E" | |||||
JT808Package jT808Package = new JT808Package | |||||
{ | |||||
Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.文本信息下发.ToUInt16Value(), | |||||
MsgNum = 1, | |||||
TerminalPhoneNo = "012345678900", | |||||
} | |||||
}; | |||||
JT808_0x8300 jT808TextSend = new JT808_0x8300 | |||||
{ | |||||
TextInfo = "smallchi 518", | |||||
TextFlag = 5 | |||||
}; | |||||
jT808Package.Bodies = jT808TextSend; | |||||
string hex = JT808Serializer.Serialize(jT808Package).ToHexString(); | |||||
Assert.Equal("7E8300000D012345678900000105736D616C6C63686920353138027E", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_2() | |||||
{ | |||||
byte[] bytes = "7E 83 00 00 0D 01 23 45 67 89 00 00 01 05 73 6D 61 6C 6C 63 68 69 20 35 31 38 02 7E".ToHexBytes(); | |||||
JT808Package jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
JT808_0x8300 jT808TextSend = (JT808_0x8300)jT808Package.Bodies; | |||||
Assert.Equal("smallchi 518", jT808TextSend.TextInfo); | |||||
Assert.Equal(5, jT808TextSend.TextFlag); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,52 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
using JT808.Protocol.Metadata; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8301Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8301 jT808_0X8301 = new JT808_0x8301 | |||||
{ | |||||
SettingType = JT808EventSettingType.删除终端现有所有事件_该命令后不带后继字节.ToByteValue(), | |||||
EventItems = new List<JT808EventProperty>() | |||||
}; | |||||
jT808_0X8301.EventItems.Add(new JT808EventProperty | |||||
{ | |||||
EventId=1, | |||||
EventContent="123456" | |||||
}); | |||||
jT808_0X8301.EventItems.Add(new JT808EventProperty | |||||
{ | |||||
EventId = 2, | |||||
EventContent = "789456" | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808_0X8301).ToHexString(); | |||||
Assert.Equal("000201063132333435360206373839343536", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
byte[] bytes = "000201063132333435360206373839343536".ToHexBytes(); | |||||
JT808_0x8301 jT808_0X8301 = JT808Serializer.Deserialize<JT808_0x8301>(bytes); | |||||
Assert.Equal(JT808EventSettingType.删除终端现有所有事件_该命令后不带后继字节.ToByteValue(), jT808_0X8301.SettingType); | |||||
Assert.Equal(2, jT808_0X8301.SettingCount); | |||||
Assert.Equal(1, jT808_0X8301.EventItems[0].EventId); | |||||
Assert.Equal(6, jT808_0X8301.EventItems[0].EventContentLength); | |||||
Assert.Equal("123456", jT808_0X8301.EventItems[0].EventContent); | |||||
Assert.Equal(2, jT808_0X8301.EventItems[1].EventId); | |||||
Assert.Equal(6, jT808_0X8301.EventItems[1].EventContentLength); | |||||
Assert.Equal("789456", jT808_0X8301.EventItems[1].EventContent); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,45 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8302Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8302 jT808_0X8302 = new JT808_0x8302 | |||||
{ | |||||
AnswerId = 128, | |||||
AnswerContent = "123456", | |||||
Flag = 1, | |||||
Issue = "sdddaff" | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X8302).ToHexString(); | |||||
//01 | |||||
//07 | |||||
//73 64 64 64 61 66 66 | |||||
//80 | |||||
//06 00 | |||||
//31 32 33 34 35 36 | |||||
//010006646464616666800000313233343536 | |||||
//010773646464616666800006313233343536 | |||||
Assert.Equal("010773646464616666800006313233343536", hex); | |||||
} | |||||
[Fact] | |||||
public void Test1_1() | |||||
{ | |||||
byte[] bytes = "010773646464616666800006313233343536".ToHexBytes(); | |||||
JT808_0x8302 jT808_0X8302 = JT808Serializer.Deserialize<JT808_0x8302>(bytes); | |||||
Assert.Equal(128, jT808_0X8302.AnswerId); | |||||
Assert.Equal("123456", jT808_0X8302.AnswerContent); | |||||
Assert.Equal(1, jT808_0X8302.Flag); | |||||
Assert.Equal("sdddaff", jT808_0X8302.Issue); | |||||
Assert.Equal(6, jT808_0X8302.AnswerContentLength); | |||||
Assert.Equal(7, jT808_0X8302.IssueContentLength); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,51 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
using JT808.Protocol.Metadata; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8303Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8303 jT808_0X8303 = new JT808_0x8303 | |||||
{ | |||||
SettingType = JT808InformationSettingType.删除终端全部信息项.ToByteValue(), | |||||
InformationItems = new List<JT808InformationItemProperty>() | |||||
}; | |||||
jT808_0X8303.InformationItems.Add(new JT808InformationItemProperty | |||||
{ | |||||
InformationType=11, | |||||
InformationName="smallchi1" | |||||
}); | |||||
jT808_0X8303.InformationItems.Add(new JT808InformationItemProperty | |||||
{ | |||||
InformationType = 22, | |||||
InformationName = "smallchi2" | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808_0X8303).ToHexString(); | |||||
Assert.Equal("00020B0009736D616C6C63686931160009736D616C6C63686932", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "00020B0009736D616C6C63686931160009736D616C6C63686932".ToHexBytes(); | |||||
JT808_0x8303 jT808_0X8303 = JT808Serializer.Deserialize<JT808_0x8303>(bytes); | |||||
Assert.Equal(JT808InformationSettingType.删除终端全部信息项.ToByteValue(), jT808_0X8303.SettingType); | |||||
Assert.Equal(11, jT808_0X8303.InformationItems[0].InformationType); | |||||
Assert.Equal("smallchi1", jT808_0X8303.InformationItems[0].InformationName); | |||||
Assert.Equal(9, jT808_0X8303.InformationItems[0].InformationLength); | |||||
Assert.Equal(22, jT808_0X8303.InformationItems[1].InformationType); | |||||
Assert.Equal("smallchi2", jT808_0X8303.InformationItems[1].InformationName); | |||||
Assert.Equal(9, jT808_0X8303.InformationItems[1].InformationLength); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8304Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8304 jT808_0X8304 = new JT808_0x8304 | |||||
{ | |||||
InformationType = 123, | |||||
InformationContent = "信息内容" | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X8304).ToHexString(); | |||||
Assert.Equal("7B0008D0C5CFA2C4DAC8DD", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "7B0008D0C5CFA2C4DAC8DD".ToHexBytes(); | |||||
JT808_0x8304 jT808_0X8304 = JT808Serializer.Deserialize<JT808_0x8304>(bytes); | |||||
Assert.Equal(123, jT808_0X8304.InformationType); | |||||
Assert.Equal("信息内容", jT808_0X8304.InformationContent); | |||||
Assert.Equal(8, jT808_0X8304.InformationLength); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8400Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8400 jT808_0X8400 = new JT808_0x8400 | |||||
{ | |||||
CallBack = Enums.JT808CallBackType.普通通话, | |||||
PhoneNumber = "12345679810" | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X8400).ToHexString(); | |||||
Assert.Equal("003132333435363739383130", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "00 31 32 33 34 35 36 37 39 38 31 30".ToHexBytes(); | |||||
JT808_0x8400 jT808_0X8400 = JT808Serializer.Deserialize<JT808_0x8400>(bytes); | |||||
Assert.Equal(Enums.JT808CallBackType.普通通话, jT808_0X8400.CallBack); | |||||
Assert.Equal("12345679810", jT808_0X8400.PhoneNumber); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,56 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Metadata; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8401Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8401 jT808_0X8401 = new JT808_0x8401 | |||||
{ | |||||
SettingTelephoneBook = Enums.JT808SettingTelephoneBook.追加电话本 | |||||
}; | |||||
List<JT808ContactProperty> jT808ContactProperties = new List<JT808ContactProperty>(); | |||||
jT808ContactProperties.Add(new JT808ContactProperty | |||||
{ | |||||
TelephoneBookContactType= Enums.JT808TelephoneBookContactType.呼入, | |||||
Contact="smallchi", | |||||
PhoneNumber="13456smallch" | |||||
}); | |||||
jT808ContactProperties.Add(new JT808ContactProperty | |||||
{ | |||||
TelephoneBookContactType = Enums.JT808TelephoneBookContactType.呼入_呼出, | |||||
Contact = "koike", | |||||
PhoneNumber = "koike123456" | |||||
}); | |||||
jT808_0X8401.JT808ContactProperties = jT808ContactProperties; | |||||
var hex = JT808Serializer.Serialize(jT808_0X8401).ToHexString(); | |||||
Assert.Equal("0202010C3133343536736D616C6C636808736D616C6C636869030B6B6F696B65313233343536056B6F696B65", hex); | |||||
//"02 02 01 0C 31 33 34 35 36 73 6D 61 6C 6C 63 68 08 73 6D 61 6C 6C 63 68 69 03 0B 6B 6F 69 6B 65 31 32 33 34 35 36 05 6B 6F 69 6B 65" | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "02 02 01 0C 31 33 34 35 36 73 6D 61 6C 6C 63 68 08 73 6D 61 6C 6C 63 68 69 03 0B 6B 6F 69 6B 65 31 32 33 34 35 36 05 6B 6F 69 6B 65".ToHexBytes(); | |||||
JT808_0x8401 jT808_0X8401 = JT808Serializer.Deserialize<JT808_0x8401>(bytes); | |||||
Assert.Equal(Enums.JT808SettingTelephoneBook.追加电话本, jT808_0X8401.SettingTelephoneBook); | |||||
Assert.Equal(2, jT808_0X8401.ContactCount); | |||||
Assert.Equal("13456smallch", jT808_0X8401.JT808ContactProperties[0].PhoneNumber); | |||||
Assert.Equal(Enums.JT808TelephoneBookContactType.呼入, jT808_0X8401.JT808ContactProperties[0].TelephoneBookContactType); | |||||
Assert.Equal("smallchi", jT808_0X8401.JT808ContactProperties[0].Contact); | |||||
Assert.Equal("koike123456", jT808_0X8401.JT808ContactProperties[1].PhoneNumber); | |||||
Assert.Equal(Enums.JT808TelephoneBookContactType.呼入_呼出, jT808_0X8401.JT808ContactProperties[1].TelephoneBookContactType); | |||||
Assert.Equal("koike", jT808_0X8401.JT808ContactProperties[1].Contact); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,29 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8500Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8500 jT808_0X8500 = new JT808_0x8500 | |||||
{ | |||||
ControlFlag = 12 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X8500).ToHexString(); | |||||
Assert.Equal("0C", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "0C".ToHexBytes(); | |||||
JT808_0x8500 jT808_0X8500 = JT808Serializer.Deserialize<JT808_0x8500>(bytes); | |||||
Assert.Equal(12, jT808_0X8500.ControlFlag); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,108 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
using JT808.Protocol.Metadata; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8600Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8600 jT808_0X8600 = new JT808_0x8600 | |||||
{ | |||||
SettingAreaProperty = JT808SettingProperty.追加区域.ToByteValue(), | |||||
AreaItems = new List<JT808CircleAreaProperty>() | |||||
}; | |||||
jT808_0X8600.AreaItems.Add(new JT808CircleAreaProperty | |||||
{ | |||||
AreaId = 1522, | |||||
AreaProperty = 222, | |||||
CenterPointLat = 123456789, | |||||
CenterPointLng = 123456789, | |||||
Radius = 200, | |||||
StartTime = DateTime.Parse("2018-10-18 00:00:12"), | |||||
EndTime = DateTime.Parse("2018-10-19 00:00:12"), | |||||
HighestSpeed = 60, | |||||
OverspeedDuration = 200 | |||||
}); | |||||
jT808_0X8600.AreaItems.Add(new JT808CircleAreaProperty | |||||
{ | |||||
AreaId = 1523, | |||||
AreaProperty = 0, | |||||
CenterPointLat = 123456789, | |||||
CenterPointLng = 123456789, | |||||
Radius = 200, | |||||
StartTime = DateTime.Parse("2018-10-18 00:00:12"), | |||||
EndTime = DateTime.Parse("2018-10-19 00:00:12"), | |||||
HighestSpeed = 60, | |||||
OverspeedDuration = 200 | |||||
}); | |||||
jT808_0X8600.AreaItems.Add(new JT808CircleAreaProperty | |||||
{ | |||||
AreaId = 1524, | |||||
AreaProperty = 2211, | |||||
CenterPointLat = 123456789, | |||||
CenterPointLng = 123456789, | |||||
Radius = 200, | |||||
StartTime = DateTime.Parse("2018-10-18 00:00:12"), | |||||
EndTime = DateTime.Parse("2018-10-19 00:00:12"), | |||||
HighestSpeed = 60, | |||||
OverspeedDuration = 200 | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808_0X8600).ToHexString(); | |||||
//"01 03 00 00 05 F2 00 DE 07 5B CD 15 07 5B CD 15 00 00 00 C8 00 3C C8 00 00 05 F3 00 00 07 5B CD 15 07 5B CD 15 00 00 00 C8 00 00 05 F4 08 A3 07 5B CD 15 07 5B CD 15 00 00 00 C8 18 10 18 00 00 12 18 10 19 00 00 12 00 3C C8" | |||||
Assert.Equal("0103000005F200DE075BCD15075BCD15000000C8003CC8000005F30000075BCD15075BCD15000000C8000005F408A3075BCD15075BCD15000000C8181018000012181019000012003CC8", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "01 03 00 00 05 F2 00 DE 07 5B CD 15 07 5B CD 15 00 00 00 C8 00 3C C8 00 00 05 F3 00 00 07 5B CD 15 07 5B CD 15 00 00 00 C8 00 00 05 F4 08 A3 07 5B CD 15 07 5B CD 15 00 00 00 C8 18 10 18 00 00 12 18 10 19 00 00 12 00 3C C8".ToHexBytes(); | |||||
JT808_0x8600 jT808_0X8600 = JT808Serializer.Deserialize<JT808_0x8600>(bytes); | |||||
Assert.Equal(JT808SettingProperty.追加区域.ToByteValue(), jT808_0X8600.SettingAreaProperty); | |||||
Assert.Equal(3, jT808_0X8600.AreaCount); | |||||
var item0 = jT808_0X8600.AreaItems[0]; | |||||
Assert.Equal((uint)1522, item0.AreaId); | |||||
Assert.Equal((ushort)222, item0.AreaProperty); | |||||
Assert.Equal((uint)123456789, item0.CenterPointLat); | |||||
Assert.Equal((uint)123456789, item0.CenterPointLng); | |||||
Assert.Equal((uint)200, item0.Radius); | |||||
Assert.Null(item0.StartTime); | |||||
Assert.Null(item0.EndTime); | |||||
Assert.Equal((ushort)60, item0.HighestSpeed); | |||||
Assert.Equal((byte)200, item0.OverspeedDuration); | |||||
var item1 = jT808_0X8600.AreaItems[1]; | |||||
Assert.Equal((uint)1523, item1.AreaId); | |||||
Assert.Equal(0, item1.AreaProperty); | |||||
Assert.Equal((uint)123456789, item1.CenterPointLat); | |||||
Assert.Equal((uint)123456789, item1.CenterPointLng); | |||||
Assert.Equal((uint)200, item1.Radius); | |||||
Assert.Null(item1.StartTime); | |||||
Assert.Null(item1.EndTime); | |||||
Assert.Null(item1.HighestSpeed); | |||||
Assert.Null(item1.OverspeedDuration); | |||||
var item2 = jT808_0X8600.AreaItems[2]; | |||||
Assert.Equal((uint)1524, item2.AreaId); | |||||
Assert.Equal((ushort)2211, item2.AreaProperty); | |||||
Assert.Equal((uint)123456789, item2.CenterPointLat); | |||||
Assert.Equal((uint)123456789, item2.CenterPointLng); | |||||
Assert.Equal((uint)200, item2.Radius); | |||||
Assert.Equal(DateTime.Parse("2018-10-18 00:00:12"), item2.StartTime); | |||||
Assert.Equal(DateTime.Parse("2018-10-19 00:00:12"), item2.EndTime); | |||||
Assert.Equal((ushort)60, item2.HighestSpeed); | |||||
Assert.Equal((byte)200, item2.OverspeedDuration); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,33 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8601Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8601 jT808_0X8601 = new JT808_0x8601(); | |||||
jT808_0X8601.AreaIds = new List<uint>() | |||||
{ | |||||
1,2 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X8601).ToHexString(); | |||||
Assert.Equal("020000000100000002", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
var bytes = "020000000100000002".ToHexBytes(); | |||||
JT808_0x8601 jT808_0X8601 = JT808Serializer.Deserialize<JT808_0x8601>(bytes); | |||||
Assert.Equal(2, jT808_0X8601.AreaCount); | |||||
Assert.Equal((uint)1, jT808_0X8601.AreaIds[0]); | |||||
Assert.Equal((uint)2, jT808_0X8601.AreaIds[1]); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,90 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
using JT808.Protocol.Metadata; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8602Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8602 jT808_0X8602 = new JT808_0x8602 | |||||
{ | |||||
SettingAreaProperty = JT808SettingProperty.追加区域.ToByteValue(), | |||||
AreaItems = new List<JT808RectangleAreaProperty>() | |||||
}; | |||||
jT808_0X8602.AreaItems.Add(new JT808RectangleAreaProperty | |||||
{ | |||||
AreaId = 1522, | |||||
AreaProperty = 222, | |||||
LowRightPointLat= 123456789, | |||||
LowRightPointLng= 123456788, | |||||
UpLeftPointLat= 123456787, | |||||
UpLeftPointLng= 123456786, | |||||
StartTime = DateTime.Parse("2018-11-20 00:00:12"), | |||||
EndTime = DateTime.Parse("2018-11-21 00:00:12"), | |||||
HighestSpeed = 60, | |||||
OverspeedDuration = 200 | |||||
}); | |||||
jT808_0X8602.AreaItems.Add(new JT808RectangleAreaProperty | |||||
{ | |||||
AreaId = 1523, | |||||
AreaProperty = 10, | |||||
LowRightPointLat = 123456700, | |||||
LowRightPointLng = 123456701, | |||||
UpLeftPointLat = 123456702, | |||||
UpLeftPointLng = 123456703, | |||||
StartTime = DateTime.Parse("2018-11-20 12:12:12"), | |||||
EndTime = DateTime.Parse("2018-11-21 11:11:11"), | |||||
HighestSpeed = 60, | |||||
OverspeedDuration = 200 | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808_0X8602).ToHexString(); | |||||
Assert.Equal("0102000005F200DE075BCD13075BCD12075BCD15075BCD14003CC8000005F3000A075BCCBE075BCCBF075BCCBC075BCCBD003CC8", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "0102000005F200DE075BCD13075BCD12075BCD15075BCD14003CC8000005F3000A075BCCBE075BCCBF075BCCBC075BCCBD003CC8".ToHexBytes(); | |||||
JT808_0x8602 jT808_0X8602 = JT808Serializer.Deserialize<JT808_0x8602>(bytes); | |||||
Assert.Equal(JT808SettingProperty.追加区域.ToByteValue(), jT808_0X8602.SettingAreaProperty); | |||||
Assert.Equal(2, jT808_0X8602.AreaCount); | |||||
var item0 = jT808_0X8602.AreaItems[0]; | |||||
Assert.Equal((uint)1522, item0.AreaId); | |||||
Assert.Equal((ushort)222, item0.AreaProperty); | |||||
Assert.Equal((uint)123456789, item0.LowRightPointLat); | |||||
Assert.Equal((uint)123456788, item0.LowRightPointLng); | |||||
Assert.Equal((uint)123456787, item0.UpLeftPointLat); | |||||
Assert.Equal((uint)123456786, item0.UpLeftPointLng); | |||||
Assert.Null(item0.StartTime); | |||||
Assert.Null(item0.EndTime); | |||||
Assert.Equal((ushort)60, item0.HighestSpeed); | |||||
Assert.Equal((byte)200, item0.OverspeedDuration); | |||||
var item1 = jT808_0X8602.AreaItems[1]; | |||||
Assert.Equal((uint)1523, item1.AreaId); | |||||
Assert.Equal(10, item1.AreaProperty); | |||||
Assert.Equal((uint)123456700, item1.LowRightPointLat); | |||||
Assert.Equal((uint)123456701, item1.LowRightPointLng); | |||||
Assert.Equal((uint)123456702, item1.UpLeftPointLat); | |||||
Assert.Equal((uint)123456703, item1.UpLeftPointLng); | |||||
Assert.Null(item1.StartTime); | |||||
Assert.Null(item1.EndTime); | |||||
Assert.Equal((ushort)60, item1.HighestSpeed); | |||||
Assert.Equal((byte)200, item1.OverspeedDuration); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,35 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8603Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8603 jT808_0X8603 = new JT808_0x8603(); | |||||
jT808_0X8603.AreaIds = new List<uint>() | |||||
{ | |||||
2838,1717,772 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X8603).ToHexString(); | |||||
Assert.Equal("0300000B16000006B500000304", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "0300000B16000006B500000304".ToHexBytes(); | |||||
JT808_0x8603 jT808_0X8603 = JT808Serializer.Deserialize<JT808_0x8603>(bytes); | |||||
Assert.Equal((uint)2838, jT808_0X8603.AreaIds[0]); | |||||
Assert.Equal((uint)1717, jT808_0X8603.AreaIds[1]); | |||||
Assert.Equal((uint)772, jT808_0X8603.AreaIds[2]); | |||||
Assert.Equal(3, jT808_0X8603.AreaCount); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,60 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
using JT808.Protocol.Metadata; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8604Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8604 jT808_0X8604 = new JT808_0x8604 | |||||
{ | |||||
AreaId = 1234, | |||||
AreaProperty = JT808SettingProperty.追加区域.ToByteValue(), | |||||
StartTime = DateTime.Parse("2018-11-20 00:00:12"), | |||||
EndTime = DateTime.Parse("2018-11-21 00:00:12"), | |||||
HighestSpeed = 62, | |||||
OverspeedDuration = 218, | |||||
PeakItems = new List<JT808PeakProperty>() | |||||
}; | |||||
jT808_0X8604.PeakItems.Add(new JT808PeakProperty | |||||
{ | |||||
Lat= 123456789, | |||||
Lng= 123456788 | |||||
}); | |||||
jT808_0X8604.PeakItems.Add(new JT808PeakProperty | |||||
{ | |||||
Lat = 123456700, | |||||
Lng = 123456701 | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808_0X8604).ToHexString(); | |||||
Assert.Equal("000004D200011811200000121811210000120002075BCD15075BCD14075BCCBC075BCCBD", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "000004D200011811200000121811210000120002075BCD15075BCD14075BCCBC075BCCBD".ToHexBytes(); | |||||
JT808_0x8604 jT808_0X8604 = JT808Serializer.Deserialize<JT808_0x8604>(bytes); | |||||
Assert.Equal((uint)1234, jT808_0X8604.AreaId); | |||||
Assert.Equal(JT808SettingProperty.追加区域.ToByteValue(), jT808_0X8604.AreaProperty); | |||||
Assert.Null(jT808_0X8604.HighestSpeed); | |||||
Assert.Null(jT808_0X8604.OverspeedDuration); | |||||
Assert.Equal(DateTime.Parse("2018-11-20 00:00:12"),jT808_0X8604.StartTime); | |||||
Assert.Equal(DateTime.Parse("2018-11-21 00:00:12"),jT808_0X8604.EndTime); | |||||
Assert.Equal(2, jT808_0X8604.PeakItems.Count); | |||||
Assert.Equal((uint)123456789, jT808_0X8604.PeakItems[0].Lat); | |||||
Assert.Equal((uint)123456788, jT808_0X8604.PeakItems[0].Lng); | |||||
Assert.Equal((uint)123456700, jT808_0X8604.PeakItems[1].Lat); | |||||
Assert.Equal((uint)123456701, jT808_0X8604.PeakItems[1].Lng); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,35 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8605Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8605 jT808_0X8605 = new JT808_0x8605(); | |||||
jT808_0X8605.AreaIds = new List<uint>() | |||||
{ | |||||
2838,1717,772 | |||||
}; | |||||
var hex = JT808Serializer.Serialize(jT808_0X8605).ToHexString(); | |||||
Assert.Equal("0300000B16000006B500000304", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "0300000B16000006B500000304".ToHexBytes(); | |||||
JT808_0x8605 jT808_0X8605 = JT808Serializer.Deserialize<JT808_0x8605>(bytes); | |||||
Assert.Equal((uint)2838, jT808_0X8605.AreaIds[0]); | |||||
Assert.Equal((uint)1717, jT808_0X8605.AreaIds[1]); | |||||
Assert.Equal((uint)772, jT808_0X8605.AreaIds[2]); | |||||
Assert.Equal(3, jT808_0X8605.AreaCount); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,213 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using Xunit; | |||||
using JT808.Protocol.Metadata; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8606Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8606 jT808_0X8606 = new JT808_0x8606 | |||||
{ | |||||
RouteId = 9999, | |||||
RouteProperty = 1268, | |||||
StartTime = DateTime.Parse("2018-11-20 00:00:12"), | |||||
EndTime = DateTime.Parse("2018-11-21 00:00:12"), | |||||
InflectionPointItems = new List<JT808InflectionPointProperty>() | |||||
}; | |||||
jT808_0X8606.InflectionPointItems.Add(new JT808InflectionPointProperty() | |||||
{ | |||||
InflectionPointId = 1000, | |||||
InflectionPointLat = 123456789, | |||||
InflectionPointLng = 123456788, | |||||
SectionDrivingUnderThreshold = 123, | |||||
SectionHighestSpeed = 69, | |||||
SectionId = 1287, | |||||
SectionLongDrivingThreshold = 50, | |||||
SectionOverspeedDuration = 23, | |||||
SectionProperty = 89, | |||||
SectionWidth = 56 | |||||
}); | |||||
jT808_0X8606.InflectionPointItems.Add(new JT808InflectionPointProperty() | |||||
{ | |||||
InflectionPointId = 1001, | |||||
InflectionPointLat = 123456780, | |||||
InflectionPointLng = 123456781, | |||||
SectionDrivingUnderThreshold = 124, | |||||
SectionHighestSpeed = 42, | |||||
SectionId = 12007, | |||||
SectionLongDrivingThreshold = 58, | |||||
SectionOverspeedDuration = 26, | |||||
SectionProperty = 50, | |||||
SectionWidth = 75 | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808_0X8606).ToHexString(); | |||||
//00 00 27 0F | |||||
//04 F4 | |||||
//00 02 | |||||
//00 00 03 E8 | |||||
//00 00 05 07 | |||||
//07 5B CD 15 | |||||
//07 5B CD 14 | |||||
//38 | |||||
//59 //0101 1001 | |||||
//00 32 | |||||
//00 7B | |||||
//00 00 03 E9 | |||||
//00 00 2E E7 | |||||
//07 5B CD 0C | |||||
//07 5B CD 0D | |||||
//4B | |||||
//32 //0011 0010 | |||||
//00 2A | |||||
//1A | |||||
Assert.Equal("0000270F04F40002000003E800000507075BCD15075BCD1438590032007B000003E900002EE7075BCD0C075BCD0D4B32002A1A", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "0000270F04F40002000003E800000507075BCD15075BCD1438590032007B000003E900002EE7075BCD0C075BCD0D4B32002A1A".ToHexBytes(); | |||||
JT808_0x8606 jT808_0X8606 = JT808Serializer.Deserialize<JT808_0x8606>(bytes); | |||||
Assert.Equal((uint)9999, jT808_0X8606.RouteId); | |||||
Assert.Equal((uint)1268, jT808_0X8606.RouteProperty); | |||||
//Assert.Equal(DateTime.Parse("2018-11-20 00:00:12"), jT808_0X8606.StartTime); | |||||
//Assert.Equal(DateTime.Parse("2018-11-21 00:00:12"), jT808_0X8606.EndTime); | |||||
Assert.Null(jT808_0X8606.StartTime); | |||||
Assert.Null(jT808_0X8606.EndTime); | |||||
Assert.Equal(2, jT808_0X8606.InflectionPointItems.Count); | |||||
Assert.Equal((uint)1000, jT808_0X8606.InflectionPointItems[0].InflectionPointId); | |||||
Assert.Equal((uint)123456789, jT808_0X8606.InflectionPointItems[0].InflectionPointLat); | |||||
Assert.Equal((uint)123456788, jT808_0X8606.InflectionPointItems[0].InflectionPointLng); | |||||
Assert.Equal((ushort)123, jT808_0X8606.InflectionPointItems[0].SectionDrivingUnderThreshold); | |||||
//Assert.Equal((ushort)69, jT808_0X8606.InflectionPointItems[0].SectionHighestSpeed); | |||||
Assert.Null(jT808_0X8606.InflectionPointItems[0].SectionHighestSpeed); | |||||
Assert.Equal((uint)1287, jT808_0X8606.InflectionPointItems[0].SectionId); | |||||
Assert.Equal((ushort)50, jT808_0X8606.InflectionPointItems[0].SectionLongDrivingThreshold); | |||||
//Assert.Equal((byte)23, jT808_0X8606.InflectionPointItems[0].SectionOverspeedDuration); | |||||
Assert.Equal(89, jT808_0X8606.InflectionPointItems[0].SectionProperty); | |||||
Assert.Equal(56, jT808_0X8606.InflectionPointItems[0].SectionWidth); | |||||
Assert.Equal((uint)1001, jT808_0X8606.InflectionPointItems[1].InflectionPointId); | |||||
Assert.Equal((uint)123456780, jT808_0X8606.InflectionPointItems[1].InflectionPointLat); | |||||
Assert.Equal((uint)123456781, jT808_0X8606.InflectionPointItems[1].InflectionPointLng); | |||||
//Assert.Equal((ushort)124, jT808_0X8606.InflectionPointItems[1].SectionDrivingUnderThreshold); | |||||
Assert.Null(jT808_0X8606.InflectionPointItems[1].SectionDrivingUnderThreshold); | |||||
Assert.Equal((ushort)42, jT808_0X8606.InflectionPointItems[1].SectionHighestSpeed); | |||||
Assert.Equal((uint)12007, jT808_0X8606.InflectionPointItems[1].SectionId); | |||||
//Assert.Equal((ushort)58, jT808_0X8606.InflectionPointItems[1].SectionLongDrivingThreshold); | |||||
Assert.Null(jT808_0X8606.InflectionPointItems[1].SectionLongDrivingThreshold); | |||||
Assert.Equal((byte)26, jT808_0X8606.InflectionPointItems[1].SectionOverspeedDuration); | |||||
Assert.Equal(50, jT808_0X8606.InflectionPointItems[1].SectionProperty); | |||||
Assert.Equal(75, jT808_0X8606.InflectionPointItems[1].SectionWidth); | |||||
} | |||||
[Fact] | |||||
public void Test3() | |||||
{ | |||||
JT808_0x8606 jT808_0X8606 = new JT808_0x8606 | |||||
{ | |||||
RouteId = 9999, | |||||
RouteProperty = 51, | |||||
StartTime = DateTime.Parse("2018-11-20 00:00:12"), | |||||
EndTime = DateTime.Parse("2018-11-21 00:00:12"), | |||||
InflectionPointItems = new List<JT808InflectionPointProperty>() | |||||
}; | |||||
jT808_0X8606.InflectionPointItems.Add(new JT808InflectionPointProperty() | |||||
{ | |||||
InflectionPointId = 1000, | |||||
InflectionPointLat = 123456789, | |||||
InflectionPointLng = 123456788, | |||||
SectionDrivingUnderThreshold = 123, | |||||
SectionHighestSpeed = 69, | |||||
SectionId = 1287, | |||||
SectionLongDrivingThreshold = 50, | |||||
SectionOverspeedDuration = 23, | |||||
SectionProperty = 3, | |||||
SectionWidth = 56 | |||||
}); | |||||
jT808_0X8606.InflectionPointItems.Add(new JT808InflectionPointProperty() | |||||
{ | |||||
InflectionPointId = 1001, | |||||
InflectionPointLat = 123456780, | |||||
InflectionPointLng = 123456781, | |||||
SectionDrivingUnderThreshold = 124, | |||||
SectionHighestSpeed = 42, | |||||
SectionId = 12007, | |||||
SectionLongDrivingThreshold = 58, | |||||
SectionOverspeedDuration = 26, | |||||
SectionProperty = 3, | |||||
SectionWidth = 75 | |||||
}); | |||||
var hex = JT808Serializer.Serialize(jT808_0X8606).ToHexString(); | |||||
//00 00 27 0F | |||||
//04 F4 | |||||
//00 02 | |||||
//00 00 03 E8 | |||||
//00 00 05 07 | |||||
//07 5B CD 15 | |||||
//07 5B CD 14 | |||||
//38 | |||||
//59 //0000000000110011 | |||||
//00 32 | |||||
//00 7B | |||||
//00 00 03 E9 | |||||
//00 00 2E E7 | |||||
//07 5B CD 0C | |||||
//07 5B CD 0D | |||||
//4B | |||||
//32 //0000000000000011 | |||||
//00 2A | |||||
//1A | |||||
Assert.Equal("0000270F00331811200000121811210000120002000003E800000507075BCD15075BCD1438030032007B004517000003E900002EE7075BCD0C075BCD0D4B03003A007C002A1A", hex); | |||||
} | |||||
[Fact] | |||||
public void Test4() | |||||
{ | |||||
byte[] bytes = "0000270F00331811200000121811210000120002000003E800000507075BCD15075BCD1438030032007B004517000003E900002EE7075BCD0C075BCD0D4B03003A007C002A1A".ToHexBytes(); | |||||
JT808_0x8606 jT808_0X8606 = JT808Serializer.Deserialize<JT808_0x8606>(bytes); | |||||
Assert.Equal((uint)9999, jT808_0X8606.RouteId); | |||||
Assert.Equal((uint)51, jT808_0X8606.RouteProperty); | |||||
Assert.Equal(DateTime.Parse("2018-11-20 00:00:12"), jT808_0X8606.StartTime); | |||||
Assert.Equal(DateTime.Parse("2018-11-21 00:00:12"), jT808_0X8606.EndTime); | |||||
Assert.Equal(2, jT808_0X8606.InflectionPointItems.Count); | |||||
Assert.Equal((uint)1000, jT808_0X8606.InflectionPointItems[0].InflectionPointId); | |||||
Assert.Equal((uint)123456789, jT808_0X8606.InflectionPointItems[0].InflectionPointLat); | |||||
Assert.Equal((uint)123456788, jT808_0X8606.InflectionPointItems[0].InflectionPointLng); | |||||
Assert.Equal((ushort)123, jT808_0X8606.InflectionPointItems[0].SectionDrivingUnderThreshold); | |||||
Assert.Equal((ushort)69, jT808_0X8606.InflectionPointItems[0].SectionHighestSpeed); | |||||
Assert.Equal((uint)1287, jT808_0X8606.InflectionPointItems[0].SectionId); | |||||
Assert.Equal((ushort)50, jT808_0X8606.InflectionPointItems[0].SectionLongDrivingThreshold); | |||||
Assert.Equal((byte)23, jT808_0X8606.InflectionPointItems[0].SectionOverspeedDuration); | |||||
Assert.Equal(3, jT808_0X8606.InflectionPointItems[0].SectionProperty); | |||||
Assert.Equal(56, jT808_0X8606.InflectionPointItems[0].SectionWidth); | |||||
Assert.Equal((uint)1001, jT808_0X8606.InflectionPointItems[1].InflectionPointId); | |||||
Assert.Equal((uint)123456780, jT808_0X8606.InflectionPointItems[1].InflectionPointLat); | |||||
Assert.Equal((uint)123456781, jT808_0X8606.InflectionPointItems[1].InflectionPointLng); | |||||
Assert.Equal((ushort)124, jT808_0X8606.InflectionPointItems[1].SectionDrivingUnderThreshold); | |||||
Assert.Equal((ushort)42, jT808_0X8606.InflectionPointItems[1].SectionHighestSpeed); | |||||
Assert.Equal((uint)12007, jT808_0X8606.InflectionPointItems[1].SectionId); | |||||
Assert.Equal((ushort)58, jT808_0X8606.InflectionPointItems[1].SectionLongDrivingThreshold); | |||||
Assert.Equal((byte)26, jT808_0X8606.InflectionPointItems[1].SectionOverspeedDuration); | |||||
Assert.Equal(3, jT808_0X8606.InflectionPointItems[1].SectionProperty); | |||||
Assert.Equal(75, jT808_0X8606.InflectionPointItems[1].SectionWidth); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,32 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8800Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8800 jT808_0X8800 = new JT808_0x8800 | |||||
{ | |||||
MultimediaId = 129, | |||||
RetransmitPackageIds = new byte[] { 0x01, 0x02, 0x03, 0x04 } | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8800).ToHexString(); | |||||
Assert.Equal("000000810201020304", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "000000810201020304".ToHexBytes(); | |||||
JT808_0x8800 jT808_0X8800 = JT808Serializer.Deserialize<JT808_0x8800>(bytes); | |||||
Assert.Equal((uint)129, jT808_0X8800.MultimediaId); | |||||
Assert.Equal(2, jT808_0X8800.RetransmitPackageCount); | |||||
Assert.Equal(new byte[] { 0x01, 0x02, 0x03, 0x04 }, jT808_0X8800.RetransmitPackageIds); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,47 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8801Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8801 jT808_0X8801 = new JT808_0x8801 | |||||
{ | |||||
ChannelId = 128, | |||||
Chroma = 245, | |||||
Contrast = 126, | |||||
Lighting = 235, | |||||
Resolution = 0x08, | |||||
Saturability = 120, | |||||
SaveFlag = 1, | |||||
ShootingCommand = 0, | |||||
VideoQuality = 9, | |||||
VideoTime = 2686 | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8801).ToHexString(); | |||||
Assert.Equal("8000000A7E010809EB7E78F5", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "8000000A7E010809EB7E78F5".ToHexBytes(); | |||||
JT808_0x8801 jT808_0X8801 = JT808Serializer.Deserialize<JT808_0x8801>(bytes); | |||||
Assert.Equal(128, jT808_0X8801.ChannelId); | |||||
Assert.Equal(245, jT808_0X8801.Chroma); | |||||
Assert.Equal(126, jT808_0X8801.Contrast); | |||||
Assert.Equal(235, jT808_0X8801.Lighting); | |||||
Assert.Equal(0x08, jT808_0X8801.Resolution); | |||||
Assert.Equal(120, jT808_0X8801.Saturability); | |||||
Assert.Equal(1, jT808_0X8801.SaveFlag); | |||||
Assert.Equal(0, jT808_0X8801.ShootingCommand); | |||||
Assert.Equal(9, jT808_0X8801.VideoQuality); | |||||
Assert.Equal(2686, jT808_0X8801.VideoTime); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,39 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8802Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8802 jT808_0X8802 = new JT808_0x8802 | |||||
{ | |||||
ChannelId = 123, | |||||
EventItemCoding = JT808EventItemCoding.碰撞侧翻报警触发.ToByteValue(), | |||||
MultimediaType = JT808MultimediaType.视频.ToByteValue(), | |||||
StartTime = DateTime.Parse("2018-11-16 21:00:08"), | |||||
EndTime = DateTime.Parse("2018-11-16 22:00:08") | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8802).ToHexString(); | |||||
Assert.Equal("027B03181116210008181116220008", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "027B03181116210008181116220008".ToHexBytes(); | |||||
JT808_0x8802 jT808_0X8802 = JT808Serializer.Deserialize<JT808_0x8802>(bytes); | |||||
Assert.Equal(123, jT808_0X8802.ChannelId); | |||||
Assert.Equal(JT808EventItemCoding.碰撞侧翻报警触发.ToByteValue(), jT808_0X8802.EventItemCoding); | |||||
Assert.Equal(JT808MultimediaType.视频.ToByteValue(), jT808_0X8802.MultimediaType); | |||||
Assert.Equal(DateTime.Parse("2018-11-16 21:00:08"), jT808_0X8802.StartTime); | |||||
Assert.Equal(DateTime.Parse("2018-11-16 22:00:08"), jT808_0X8802.EndTime); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,41 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8803Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8803 jT808_0X8803 = new JT808_0x8803 | |||||
{ | |||||
ChannelId = 128, | |||||
EventItemCoding = JT808EventItemCoding.平台下发指令.ToByteValue(), | |||||
MultimediaDeleted = JT808MultimediaDeleted.删除.ToByteValue(), | |||||
MultimediaType = JT808MultimediaType.图像.ToByteValue(), | |||||
StartTime = DateTime.Parse("2018-11-16 22:00:21"), | |||||
EndTime = DateTime.Parse("2018-11-16 23:00:21") | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8803).ToHexString(); | |||||
Assert.Equal("00800018111622002118111623002101", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "00800018111622002118111623002101".ToHexBytes(); | |||||
JT808_0x8803 jT808_0X8803 = JT808Serializer.Deserialize<JT808_0x8803>(bytes); | |||||
Assert.Equal(128, jT808_0X8803.ChannelId); | |||||
Assert.Equal(JT808EventItemCoding.平台下发指令.ToByteValue(), jT808_0X8803.EventItemCoding); | |||||
Assert.Equal(JT808MultimediaDeleted.删除.ToByteValue(), jT808_0X8803.MultimediaDeleted); | |||||
Assert.Equal(JT808MultimediaType.图像.ToByteValue(), jT808_0X8803.MultimediaType); | |||||
Assert.Equal(DateTime.Parse("2018-11-16 22:00:21"), jT808_0X8803.StartTime); | |||||
Assert.Equal(DateTime.Parse("2018-11-16 23:00:21"), jT808_0X8803.EndTime); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,37 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8804Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8804 jT808_0X8804 = new JT808_0x8804 | |||||
{ | |||||
RecordCmd = JT808RecordCmd.停止录音, | |||||
RecordTime = 30, | |||||
RecordSave = JT808RecordSave.实时上传, | |||||
AudioSampleRate = 1 | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8804).ToHexString(); | |||||
//"00 00 1E 00 01" | |||||
Assert.Equal("00001E0001", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "00 00 1E 00 01".ToHexBytes(); | |||||
JT808_0x8804 jT808_0X8804 = JT808Serializer.Deserialize<JT808_0x8804>(bytes); | |||||
Assert.Equal(JT808RecordCmd.停止录音, jT808_0X8804.RecordCmd); | |||||
Assert.Equal(30, jT808_0X8804.RecordTime); | |||||
Assert.Equal(JT808RecordSave.实时上传, jT808_0X8804.RecordSave); | |||||
Assert.Equal(1, jT808_0X8804.AudioSampleRate); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8805Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8805 jT808_0X8805 = new JT808_0x8805 | |||||
{ | |||||
MultimediaId = 10000, | |||||
MultimediaDeleted = Enums.JT808MultimediaDeleted.保留.ToByteValue() | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8805).ToHexString(); | |||||
Assert.Equal("0000271000", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "00 00 27 10 00".ToHexBytes(); | |||||
JT808_0x8805 jT808_0X8805 = JT808Serializer.Deserialize<JT808_0x8805>(bytes); | |||||
Assert.Equal(Enums.JT808MultimediaDeleted.保留.ToByteValue(), jT808_0X8805.MultimediaDeleted); | |||||
Assert.Equal((uint)10000, jT808_0X8805.MultimediaId); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,48 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Test.MessageBody.JT808_0X8900_BodiesImpl; | |||||
using System.Reflection; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8900Test | |||||
{ | |||||
JT808Serializer JT808Serializer; | |||||
public JT808_0x8900Test() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8900 jT808_0X8900 = new JT808_0x8900 | |||||
{ | |||||
PassthroughType = 0x0B, | |||||
JT808_0X8900_BodyBase = new JT808_0X8900_Test_BodiesImpl | |||||
{ | |||||
Id = 12345, | |||||
Sex = 0x01 | |||||
} | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8900).ToHexString(); | |||||
Assert.Equal("0B0000303901", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "0B0000303901".ToHexBytes(); | |||||
JT808_0x8900 jT808_0X8900 = JT808Serializer.Deserialize<JT808_0x8900>(bytes); | |||||
JT808_0X8900_Test_BodiesImpl jT808_0X8900_Test_BodiesImpl = JT808Serializer.Deserialize<JT808_0X8900_Test_BodiesImpl>(jT808_0X8900.PassthroughData); | |||||
Assert.Equal(0x0B, jT808_0X8900.PassthroughType); | |||||
Assert.Equal((uint)12345, jT808_0X8900_Test_BodiesImpl.Id); | |||||
Assert.Equal(0x01, jT808_0X8900_Test_BodiesImpl.Sex); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,40 @@ | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Linq; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.MessageBody | |||||
{ | |||||
public class JT808_0x8A00Test | |||||
{ | |||||
JT808Serializer JT808Serializer = new JT808Serializer(); | |||||
byte[] N; | |||||
public JT808_0x8A00Test() | |||||
{ | |||||
N = Enumerable.Range(0, 128).Select(s => Convert.ToByte(s)).ToArray(); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808_0x8A00 jT808_0X8A00 = new JT808_0x8A00 | |||||
{ | |||||
E = 128, | |||||
N = N | |||||
}; | |||||
string hex = JT808Serializer.Serialize(jT808_0X8A00).ToHexString(); | |||||
Assert.Equal("00000080000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F", hex); | |||||
} | |||||
[Fact] | |||||
public void Test2() | |||||
{ | |||||
byte[] bytes = "00000080000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F".ToHexBytes(); | |||||
JT808_0x8A00 jT808_0X8A00 = JT808Serializer.Deserialize<JT808_0x8A00>(bytes); | |||||
Assert.Equal((uint)128, jT808_0X8A00.E); | |||||
Assert.Equal(N, jT808_0X8A00.N); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,224 @@ | |||||
using JT808.Protocol.MessagePack; | |||||
using JT808.Protocol.Extensions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
using System.Buffers; | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
namespace JT808.Protocol.Test.MessagePack | |||||
{ | |||||
public class JT808MessagePackReaderTest | |||||
{ | |||||
[Fact] | |||||
public void JT808MessagePackReaderConstructorTest() | |||||
{ | |||||
byte[] bytes = "7E 02 00 00 26 12 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 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
jT808MessagePackReader.Decode(new byte[4096]); | |||||
Assert.Equal(0x13, jT808MessagePackReader.CalculateCheckXorCode); | |||||
Assert.Equal(jT808MessagePackReader.SrcBuffer.Length, bytes.Length); | |||||
byte[] bytes1 = "7E 02 00 00 26 12 34 56 78 90 12 00 7E 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 13 7E".ToHexBytes(); | |||||
//7E02000026123456789012007E000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D137D | |||||
//7E02000026123456789012007E000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D137E | |||||
var a = jT808MessagePackReader.Reader.ToArray().ToHexString(); | |||||
Assert.Equal(jT808MessagePackReader.Reader.ToArray(), bytes1); | |||||
} | |||||
[Fact] | |||||
public void ReadEncodeTest() | |||||
{ | |||||
byte[] bytes = "7E 7D 02 7D 01 7D 02 7D 01 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
jT808MessagePackReader.Decode(new byte[4096]); | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
Assert.Equal(0x7E, jT808MessagePackReader.ReadByte()); | |||||
Assert.Equal(0x7D, jT808MessagePackReader.ReadByte()); | |||||
Assert.Equal(0x7E, jT808MessagePackReader.ReadByte()); | |||||
Assert.Equal(0x7D, jT808MessagePackReader.ReadByte()); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
Assert.Equal(6, jT808MessagePackReader.ReaderCount); | |||||
} | |||||
[Fact] | |||||
public void ReadEncodeTest1() | |||||
{ | |||||
byte[] bytes = "7E 00 02 00 00 04 00 21 67 92 87 00 2B 7D 02 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
} | |||||
[Fact] | |||||
public void ReadEncodeTest2() | |||||
{ | |||||
byte[] bytes = "7E 00 02 00 00 04 00 21 67 92 87 00 2B 7D 02 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
jT808MessagePackReader.Decode(); | |||||
Assert.Equal(0x7E, jT808MessagePackReader.CalculateCheckXorCode); | |||||
} | |||||
[Fact] | |||||
public void ReadDateTimeTest() | |||||
{ | |||||
byte[] bytes = "7E 07 E3 06 19 23 23 23 00 7B 19 06 19 23 23 23 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
Assert.Equal(DateTime.Parse("2019-06-19"), jT808MessagePackReader.ReadDateTime4()); | |||||
Assert.Equal(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,23,23,23,123), jT808MessagePackReader.ReadDateTime5()); | |||||
Assert.Equal(DateTime.Parse("2019-06-19 23:23:23"), jT808MessagePackReader.ReadDateTime6()); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
} | |||||
[Theory] | |||||
[InlineData("smallchi(Koike)")] | |||||
public void ReadStringTest(string str) | |||||
{ | |||||
byte[] bytes = "7E736D616C6C636869284B6F696B65297E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
Assert.Equal(str, jT808MessagePackReader.ReadString(str.Length)); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
} | |||||
[Theory] | |||||
[InlineData("0000000000000000000000ABCDEF1234")] | |||||
public void ReadHexTest(string hexStr) | |||||
{ | |||||
byte[] bytes = "7E0000000000000000000000ABCDEF12347E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
//0000000000000000000000ABCDEF1234 | |||||
Assert.Equal(hexStr, jT808MessagePackReader.ReadHex(16)); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
} | |||||
[Fact] | |||||
public void ReadUTCDateTimeTest() | |||||
{ | |||||
byte[] bytes = "000000005D0CF66B".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(DateTime.Parse("2019-06-21 23:23:23"), jT808MessagePackReader.ReadUTCDateTime()); | |||||
} | |||||
[Fact] | |||||
public void ReadBCDTest1() | |||||
{ | |||||
byte[] bytes = "7E 12 34 56 78 90 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
Assert.Equal("1234567890", jT808MessagePackReader.ReadBCD(10)); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
} | |||||
[Fact] | |||||
public void ReadBCDTest2() | |||||
{ | |||||
byte[] bytes = "7E 12 34 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
Assert.Equal("1234", jT808MessagePackReader.ReadBCD(5)); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
} | |||||
[Fact] | |||||
public void ReadBCDTest3() | |||||
{ | |||||
byte[] bytes = "7E 00 12 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
Assert.Equal("12", jT808MessagePackReader.ReadBCD(5)); | |||||
//Assert.Equal("0012", jT808MessagePackReader.ReadBCD(5)); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
} | |||||
[Fact] | |||||
public void ReadArrayTest() | |||||
{ | |||||
byte[] bytes = "7E 01 02 03 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
Assert.Equal(new byte[] { 0x01, 0x02, 0x03 }, jT808MessagePackReader.ReadArray(3).ToArray()); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
} | |||||
[Fact] | |||||
public void ReadNumericalTest() | |||||
{ | |||||
byte[] bytes = "7E 01 00 10 00 00 00 20 00 00 00 40 7E".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
Assert.Equal(0x01, jT808MessagePackReader.ReadByte()); | |||||
Assert.Equal(16, jT808MessagePackReader.ReadUInt16()); | |||||
Assert.Equal(32, jT808MessagePackReader.ReadInt32()); | |||||
Assert.Equal((uint)64, jT808MessagePackReader.ReadUInt32()); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
} | |||||
[Fact] | |||||
public void ReadUInt64Test() | |||||
{ | |||||
byte[] bytes = "00 00 00 00 00 0F 63 E3".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal((ulong)1008611, jT808MessagePackReader.ReadUInt64()); | |||||
} | |||||
[Theory] | |||||
[InlineData("123456789")] | |||||
public void ReadBigNumberTest(string numStr) | |||||
{ | |||||
byte[] bytes = "0000000000075BCD15".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
Assert.Equal(numStr, jT808MessagePackReader.ReadBigNumber(numStr.Length)); | |||||
} | |||||
[Fact] | |||||
public void ReadContentTest() | |||||
{ | |||||
var bytes = "7e080123000138123456782032000a000205060708090a0bffc400b5100002010303020403050504040000017d0101020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffdd00040000ffda000c03010002110311003f006c6a2a755ce299a5c942e0f35281c5004aa72314a54e38a07b8841ef4840a0673de21b4ff498ee402038dade991fe7f4acc110f4a0cd8ef2f1405cd01d45f2e9360a062edc5745616a6dad511861cfccff0053499512e056cf1460e3348a0ed4b8e338fc2819cb5edbfd9ee648b18556f97fdd3d3f4aafb4d332ea433a6573e9550d3131d18c9c558031c0a4083a503039a60c42c2984e4f4a06260d370690098ef4751400c615132d021868a621431a33480ef235e05595403eb54cbb0b8e7069dc0e3a9a41b12a024f4a9d40f4a18c5651e951c88179268194ee614b989a2719461ffea35cfdcda4b6b2ed71c1e55874345c96ba91819a704c50217613db349b39031c9e945c66a69ba794713cebf30fb8be9ee6b540c1e948a48760e3a526d2dc77a0a144471d297cb623a71484646bb685234b81d01d8e7d018f43f9ff003ac16386c552225b8300c2a84c8c8c4ed247b502616cc0517e".ToHexBytes(); | |||||
JT808MessagePackReader jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
JT808PackageFormatter jT808PackageFormatter = new JT808PackageFormatter(); | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.SkipCRCCode = true; | |||||
var package=jT808PackageFormatter.Deserialize(ref jT808MessagePackReader, jT808Config); | |||||
} | |||||
[Theory] | |||||
[InlineData(100000)] | |||||
//[InlineData(1000000)] | |||||
//[InlineData(10000000)] | |||||
//[InlineData(100000000)] | |||||
public void ArrayPoolTest1(int count) | |||||
{ | |||||
var arrayPool = ArrayPool<byte>.Create(); | |||||
while (count >= 0) | |||||
{ | |||||
var buffer = arrayPool.Rent(4096); | |||||
byte[] bytes = "7E 7D 02 7D 01 7D 02 7D 01 7E".ToHexBytes(); | |||||
var jT808MessagePackReader = new JT808MessagePackReader(bytes); | |||||
jT808MessagePackReader.Decode(buffer); | |||||
try | |||||
{ | |||||
Assert.Equal(JT808Package.BeginFlag, jT808MessagePackReader.ReadStart()); | |||||
Assert.Equal(0x7E, jT808MessagePackReader.ReadByte()); | |||||
Assert.Equal(0x7D, jT808MessagePackReader.ReadByte()); | |||||
Assert.Equal(0x7E, jT808MessagePackReader.ReadByte()); | |||||
Assert.Equal(0x7D, jT808MessagePackReader.ReadByte()); | |||||
Assert.Equal(JT808Package.EndFlag, jT808MessagePackReader.ReadEnd()); | |||||
Assert.Equal(6, jT808MessagePackReader.ReaderCount); | |||||
} | |||||
catch (Exception) | |||||
{ | |||||
} | |||||
finally | |||||
{ | |||||
arrayPool.Return(buffer); | |||||
count--; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,450 @@ | |||||
using JT808.Protocol.MessagePack; | |||||
using JT808.Protocol.Extensions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Text; | |||||
using Xunit; | |||||
using System.Buffers; | |||||
namespace JT808.Protocol.Test.MessagePack | |||||
{ | |||||
public class JT808MessagePackWriterTest | |||||
{ | |||||
[Fact] | |||||
public void WriteEncodeTest() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteByte(0x7E); | |||||
msgpackWriter.WriteByte(0x7D); | |||||
msgpackWriter.WriteByte(0x7E); | |||||
msgpackWriter.WriteByte(0x7D); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//===========output========= | |||||
//Unencode: | |||||
//7E 7E 7D 7E 7D 7E | |||||
//Encode | |||||
//7E 7D 02 7D 01 7D 02 7D 01 7E | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 7E 7D 7E 7D 7E 7E 7D 02 7D 01 7D 02 7D 01 7E".Replace(" ", ""), realBytes); | |||||
} | |||||
[Fact] | |||||
public void WriteEncodeTest1() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteByte(0x7E); | |||||
msgpackWriter.WriteByte(0x7D); | |||||
msgpackWriter.WriteByte(0x7E); | |||||
msgpackWriter.WriteByte(0x7D); | |||||
msgpackWriter.WriteFullEncode(); | |||||
//===========output========= | |||||
//Unencode: | |||||
//7E 7D 7E 7D | |||||
//Encode | |||||
//7D 02 7D 01 7D 02 7D 01 | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 7D 7E 7D 7D 02 7D 01 7D 02 7D 01".Replace(" ", ""), realBytes); | |||||
} | |||||
[Fact] | |||||
public void WriteDateTimeTest() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteDateTime4(DateTime.Parse("2019-06-19 23:23:23")); | |||||
msgpackWriter.WriteDateTime5(DateTime.Parse("2019-06-19 23:23:23.123")); | |||||
msgpackWriter.WriteDateTime6(DateTime.Parse("2019-06-19 23:23:23")); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//===========output========= | |||||
//WriteDateTime4=>YYYYMMDD=>07 E3 06 19 | |||||
//WriteDateTime5=>HH-mm-ss-fff|HH-mm-ss-msms=>23 23 23 00 7B | |||||
//WriteDateTime6=>yyMMddHHmmss=>19 23 23 23 | |||||
//Unencode: | |||||
//7E 07 E3 06 19 23 23 23 00 7B 19 06 19 23 23 23 7E | |||||
//Encode | |||||
//7E 07 E3 06 19 23 23 23 00 7B 19 06 19 23 23 23 7E | |||||
var encodeBytes = msgpackWriter.FlushAndGetEncodingArray().ToHexString(); | |||||
Assert.Equal("7E07E30619232323007B1906192323237E".Replace(" ", ""), encodeBytes); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E07E30619232323007B1906192323237E7E07E30619232323007B1906192323237E", realBytes); | |||||
} | |||||
[Fact] | |||||
public void WriteUTCDateTimeTest() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteUTCDateTime(DateTime.Parse("2019-06-21 23:23:23")); | |||||
var encodeBytes = msgpackWriter.FlushAndGetEncodingArray().ToHexString(); | |||||
Assert.Equal("000000005D0CF66B", encodeBytes); | |||||
} | |||||
[Fact] | |||||
public void WriteBCDTest1() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteBCD("1234567890", 10); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//7E 12 34 56 78 90 7E 7E 12 34 56 78 90 7E | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 12 34 56 78 90 7E 7E 12 34 56 78 90 7E".Replace(" ", ""), realBytes); | |||||
} | |||||
[Fact] | |||||
public void WriteBCDTest2() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteBCD("1234567890", 5); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//7E 12 34 7E 7E 12 34 7E | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 12 34 7E 7E 12 34 7E".Replace(" ", ""), realBytes); | |||||
} | |||||
[Fact] | |||||
public void WriteBCDTest3() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteBCD("123", 5); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//7E 00 12 7E 7E 00 12 7E | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 00 12 7E 7E 00 12 7E".Replace(" ", ""), realBytes); | |||||
} | |||||
[Theory] | |||||
[InlineData("smallchi(Koike)")] | |||||
public void WriteStringTest(string str) | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteString(str); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
byte[] strBytes = JT808Constants.Encoding.GetBytes(str); | |||||
var strHex = strBytes.ToHexString(); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
//7E736D616C6C636869284B6F696B65297E7E736D616C6C636869284B6F696B65297E | |||||
Assert.StartsWith(strHex, realBytes.Substring(2)); | |||||
Assert.Equal("7E736D616C6C636869284B6F696B65297E7E736D616C6C636869284B6F696B65297E", realBytes); | |||||
} | |||||
[Theory] | |||||
[InlineData("ABCDEF1234")] | |||||
public void WriteHexTest(string hexStr) | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteHex(hexStr, 16); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
//7E0000000000000000000000ABCDEF12347E7E0000000000000000000000ABCDEF12347E | |||||
Assert.StartsWith("0000000000000000000000ABCDEF1234", realBytes.Substring(2)); | |||||
Assert.Equal("7E0000000000000000000000ABCDEF12347E7E0000000000000000000000ABCDEF12347E", realBytes); | |||||
} | |||||
[Theory] | |||||
[InlineData(new byte[] { 0x01, 0x02, 0x03 })] | |||||
public void WriteArrayTest(byte[] dara) | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteArray(dara); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//===========output========= | |||||
//Unencode: | |||||
//7E 01 02 03 7E | |||||
//Encode | |||||
//7E 01 02 03 7E | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 01 02 03 7E 7E 01 02 03 7E".Replace(" ",""), realBytes); | |||||
} | |||||
[Fact] | |||||
public void WriteNumericalTest() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteByte(0x01); | |||||
msgpackWriter.WriteUInt16(16); | |||||
msgpackWriter.WriteInt32(32); | |||||
msgpackWriter.WriteUInt32(64); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//===========output========= | |||||
//Unencode: | |||||
//7E 01 00 10 00 00 00 20 00 00 00 40 7E | |||||
//Encode | |||||
//7E 01 00 10 00 00 00 20 00 00 00 40 7E | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 01 00 10 00 00 00 20 00 00 00 40 7E 7E 01 00 10 00 00 00 20 00 00 00 40 7E".Replace(" ", ""), realBytes); | |||||
} | |||||
[Theory] | |||||
[InlineData(5)] | |||||
public void SkipTest(int count) | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.Skip(count, out int position); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//===========output========= | |||||
//Unencode: | |||||
//7E 00 00 00 00 00 7E | |||||
//Encode | |||||
//7E 00 00 00 00 00 7E | |||||
Assert.Equal(1, position); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 00 00 00 00 00 7E 7E 00 00 00 00 00 7E".Replace(" ",""), realBytes); | |||||
} | |||||
[Theory] | |||||
[InlineData(5,0xFF)] | |||||
public void CustomSkipTest(int count,byte fullValue) | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.Skip(count, out int position, fullValue); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//===========output========= | |||||
//Unencode: | |||||
//7E FF FF FF FF FF 7E | |||||
//Encode | |||||
//7E FF FF FF FF FF 7E | |||||
Assert.Equal(1, position); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E FF FF FF FF FF 7E 7E FF FF FF FF FF 7E".Replace(" ", ""), realBytes); | |||||
} | |||||
[Fact] | |||||
public void NilTest() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.Nil(out int position); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
Assert.Equal(1, position); | |||||
//===========output========= | |||||
//Unencode: | |||||
//7E 00 7E | |||||
//Encode | |||||
//7E 00 7E | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 00 7E 7E 00 7E".Replace(" ", ""), realBytes); | |||||
} | |||||
[Theory] | |||||
[InlineData(1, 12)] | |||||
public void WriteXorTest1(int start,int end) | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteArray("02 00 00 26 12 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 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01".ToHexBytes()); | |||||
msgpackWriter.WriteXor(start, end); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.NotEqual("13", realBytes.Substring(realBytes.Length-4, 2)); | |||||
} | |||||
[Theory] | |||||
[InlineData(12, 1)] | |||||
public void WriteXorTest2(int start, int end) | |||||
{ | |||||
Assert.Throws<ArgumentOutOfRangeException>(() => | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteXor(start, end); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
}); | |||||
} | |||||
[Fact] | |||||
public void WriteXorTest3() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteArray("02 00 00 26 12 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 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01".ToHexBytes()); | |||||
msgpackWriter.WriteXor(); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("13", realBytes.Substring(realBytes.Length - 4, 2)); | |||||
} | |||||
[Theory] | |||||
[InlineData(1,0x02, | |||||
2,8, | |||||
4,9, | |||||
6,"654321", | |||||
3,new byte[] { 0x01,0x02,0x03})] | |||||
public void WriteReturnTest( | |||||
int skipbyte, byte writeNewByte, | |||||
int skipInt16, ushort writeNewInt16, | |||||
int skipInt32, int writeNewInt32, | |||||
int skipString, string writeNewString, | |||||
int skipArray3, byte[] writeNewArray) | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.Skip(skipbyte, out var position1); | |||||
msgpackWriter.Skip(skipInt16, out var position2); | |||||
msgpackWriter.Skip(skipInt32, out var position3); | |||||
msgpackWriter.Skip(skipString, out var position4); | |||||
msgpackWriter.Skip(skipArray3, out var position5); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//===========skip output========= | |||||
//Unencode: | |||||
//7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7E | |||||
//Encode | |||||
//7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7E | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7E 7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7E".Replace(" ", ""), realBytes); | |||||
msgpackWriter.WriteByteReturn(writeNewByte, position1); | |||||
msgpackWriter.WriteUInt16Return(writeNewInt16, position2); | |||||
msgpackWriter.WriteInt32Return(writeNewInt32, position3); | |||||
msgpackWriter.WriteBCDReturn(writeNewString, skipString, position4); | |||||
msgpackWriter.WriteArrayReturn(writeNewArray, position5); | |||||
//===========write return output========= | |||||
//7E 02 00 08 00 00 00 09 65 43 21 00 00 00 01 02 03 7E | |||||
var writeRealBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 02 00 08 00 00 00 09 65 43 21 00 00 00 01 02 03 7E 7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7E".Replace(" ", ""), writeRealBytes); | |||||
} | |||||
[Fact] | |||||
public void WriteUInt64Test() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteUInt64(1008611); | |||||
var hex = msgpackWriter.FlushAndGetEncodingArray().ToHexString(); | |||||
//00 00 00 00 00 0F 63 E3 | |||||
Assert.Equal("00 00 00 00 00 0F 63 E3".Replace(" ", ""), hex); | |||||
} | |||||
[Theory] | |||||
[InlineData("123456789")] | |||||
public void WriteBigNumberTest(string numStr) | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteBigNumber(numStr, numStr.Length); | |||||
var hex = msgpackWriter.FlushAndGetEncodingArray().ToHexString(); | |||||
Assert.Equal("0000000000075BCD15", hex); | |||||
} | |||||
[Theory] | |||||
[InlineData(100000)] | |||||
//[InlineData(1000000)] | |||||
//[InlineData(10000000)] | |||||
//[InlineData(100000000)] | |||||
public void ArrayPoolTest1(int count) | |||||
{ | |||||
var arrayPool = ArrayPool<byte>.Create(); | |||||
while (count>=0) | |||||
{ | |||||
var buffer = arrayPool.Rent(65535); | |||||
var msgpackWriter = new JT808MessagePackWriter(buffer); | |||||
try | |||||
{ | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteInt32(16); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 00 00 00 10 7E 7E 00 00 00 10 7E".Replace(" ", ""), realBytes); | |||||
} | |||||
catch (Exception) | |||||
{ | |||||
} | |||||
finally | |||||
{ | |||||
arrayPool.Return(buffer); | |||||
count--; | |||||
} | |||||
} | |||||
} | |||||
[Fact] | |||||
public void CompositeTest1() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteByte(0x01); | |||||
msgpackWriter.WriteByte(0x7E); | |||||
msgpackWriter.WriteByte(0x7d); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
var encodeBytes = msgpackWriter.FlushAndGetEncodingArray().ToHexString(); | |||||
Assert.Equal("7E017D027D017E", encodeBytes); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E017E7D7E7E017D027D017E", realBytes); | |||||
} | |||||
[Fact] | |||||
public void CompositeTest2() | |||||
{ | |||||
byte[] array = new byte[4096]; | |||||
var msgpackWriter = new JT808MessagePackWriter(array); | |||||
msgpackWriter.WriteStart(); | |||||
msgpackWriter.WriteByte(0x01); | |||||
msgpackWriter.WriteByte(0x7E); | |||||
msgpackWriter.Nil(out int nilPosition); | |||||
Assert.Equal(3, nilPosition); | |||||
msgpackWriter.WriteByte(0x7d); | |||||
msgpackWriter.WriteBCD("123456789", 10); | |||||
msgpackWriter.Skip(5, out int skipPostion); | |||||
Assert.Equal(10, skipPostion); | |||||
msgpackWriter.WriteEnd(); | |||||
msgpackWriter.WriteEncode(); | |||||
//===========output========= | |||||
//Unencode: | |||||
//7E 01 7E 00 7D 01 23 45 67 89 00 00 00 00 00 7E | |||||
//Encode | |||||
//7E 01 7D 02 00 7D 01 01 23 45 67 89 00 00 00 00 00 7E | |||||
//7E 01 7D 02 00 7D 01 01 00 23 00 45 00 00 00 00 00 7E | |||||
var encodeBytes = msgpackWriter.FlushAndGetEncodingArray().ToHexString(); | |||||
Assert.Equal("7E 01 7D 02 00 7D 01 01 23 45 67 89 00 00 00 00 00 7E".Replace(" ", ""), encodeBytes); | |||||
var realBytes = msgpackWriter.FlushAndGetRealArray().ToHexString(); | |||||
Assert.Equal("7E 01 7E 00 7D 01 23 45 67 89 00 00 00 00 00 7E 7E 01 7D 02 00 7D 01 01 23 45 67 89 00 00 00 00 00 7E".Replace(" ", ""), realBytes); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,69 @@ | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Extensions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Reflection; | |||||
using System.Text; | |||||
using Xunit; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Internal; | |||||
namespace JT808.Protocol.Test.Simples | |||||
{ | |||||
public class Demo1 | |||||
{ | |||||
public JT808Serializer JT808Serializer; | |||||
public Demo1() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = new JT808Package(); | |||||
jT808Package.Header = new JT808Header | |||||
{ | |||||
MsgId = Enums.JT808MsgId.位置信息汇报.ToUInt16Value(), | |||||
MsgNum = 126, | |||||
TerminalPhoneNo = "123456789012" | |||||
}; | |||||
JT808_0x0200 jT808_0x0200 = new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-10-15 10:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase>() | |||||
}; | |||||
jT808_0x0200.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x01, new JT808_0x0200_0x01 | |||||
{ | |||||
Mileage = 100 | |||||
}); | |||||
jT808_0x0200.JT808LocationAttachData.Add(JT808_0x0200_BodyBase.AttachId0x02, new JT808_0x0200_0x02 | |||||
{ | |||||
Oil = 125 | |||||
}); | |||||
jT808Package.Bodies = jT808_0x0200; | |||||
byte[] data = JT808Serializer.Serialize(jT808Package); | |||||
var hex = data.ToHexString(); | |||||
//"7E020000261234567890120001000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D016C7E" | |||||
Assert.Equal("7E02000026123456789012007D02000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D01137E", hex); | |||||
// 输出结果Hex: | |||||
// 7E 02 00 00 26 12 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 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,59 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Extensions; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.Internal; | |||||
using JT808.Protocol.MessageBody; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Reflection; | |||||
using System.Text; | |||||
using Xunit; | |||||
namespace JT808.Protocol.Test.Simples | |||||
{ | |||||
public class Demo2 | |||||
{ | |||||
public JT808Serializer JT808Serializer; | |||||
public Demo2() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
//1.转成byte数组 | |||||
byte[] bytes = "7E 02 00 00 26 12 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 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E".ToHexBytes(); | |||||
//2.将数组反序列化 | |||||
var jT808Package = JT808Serializer.Deserialize<JT808Package>(bytes); | |||||
//3.数据包头 | |||||
Assert.Equal(Enums.JT808MsgId.位置信息汇报.ToValue(), jT808Package.Header.MsgId); | |||||
Assert.Equal(38, jT808Package.Header.MessageBodyProperty.DataLength); | |||||
Assert.Equal(126, jT808Package.Header.MsgNum); | |||||
Assert.Equal("123456789012", jT808Package.Header.TerminalPhoneNo); | |||||
Assert.False(jT808Package.Header.MessageBodyProperty.IsPackge); | |||||
Assert.Equal(0, jT808Package.Header.MessageBodyProperty.PackageIndex); | |||||
Assert.Equal(0, jT808Package.Header.MessageBodyProperty.PackgeCount); | |||||
Assert.Equal(JT808EncryptMethod.None, jT808Package.Header.MessageBodyProperty.Encrypt); | |||||
//4.数据包体 | |||||
JT808_0x0200 jT808_0x0200 = (JT808_0x0200)jT808Package.Bodies; | |||||
Assert.Equal((uint)1, jT808_0x0200.AlarmFlag); | |||||
Assert.Equal((uint)40, jT808_0x0200.Altitude); | |||||
Assert.Equal(DateTime.Parse("2018-10-15 10:10:10"), jT808_0x0200.GPSTime); | |||||
Assert.Equal(12222222, jT808_0x0200.Lat); | |||||
Assert.Equal(132444444, jT808_0x0200.Lng); | |||||
Assert.Equal(60, jT808_0x0200.Speed); | |||||
Assert.Equal(0, jT808_0x0200.Direction); | |||||
Assert.Equal((uint)2, jT808_0x0200.StatusFlag); | |||||
//4.1.附加信息1 | |||||
Assert.Equal(100, ((JT808_0x0200_0x01)jT808_0x0200.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x01]).Mileage); | |||||
//4.2.附加信息2 | |||||
Assert.Equal(125, ((JT808_0x0200_0x02)jT808_0x0200.JT808LocationAttachData[JT808_0x0200_BodyBase.AttachId0x02]).Oil); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,53 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Extensions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Reflection; | |||||
using System.Text; | |||||
using Xunit; | |||||
using JT808.Protocol.Internal; | |||||
namespace JT808.Protocol.Test.Simples | |||||
{ | |||||
public class Demo3 | |||||
{ | |||||
public JT808Serializer JT808Serializer; | |||||
public Demo3() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
JT808Package jT808Package = JT808MsgId.位置信息汇报.Create("123456789012", | |||||
new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-10-15 10:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808LocationAttachData = new Dictionary<byte, JT808_0x0200_BodyBase> | |||||
{ | |||||
{ JT808_0x0200_BodyBase.AttachId0x01,new JT808_0x0200_0x01{Mileage = 100}}, | |||||
{ JT808_0x0200_BodyBase.AttachId0x02,new JT808_0x0200_0x02{Oil = 125}} | |||||
} | |||||
}); | |||||
jT808Package.Header.MsgNum = 1; | |||||
byte[] data = JT808Serializer.Serialize(jT808Package); | |||||
var hex = data.ToHexString(); | |||||
//输出结果Hex: | |||||
//7E 02 00 00 26 12 34 56 78 90 12 00 01 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 6C 7E | |||||
//"7E020000261234567890120001000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D016C7E" | |||||
Assert.Equal("7E020000261234567890120001000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D016C7E", hex); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,355 @@ | |||||
using JT808.Protocol.Enums; | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Extensions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Reflection; | |||||
using System.Text; | |||||
using Xunit; | |||||
using JT808.Protocol.Formatters; | |||||
using JT808.Protocol.MessagePack; | |||||
using JT808.Protocol.Attributes; | |||||
using Newtonsoft.Json.Linq; | |||||
using Newtonsoft.Json; | |||||
using JT808.Protocol.Internal; | |||||
namespace JT808.Protocol.Test.Simples | |||||
{ | |||||
public class Demo4 | |||||
{ | |||||
public JT808Serializer JT808Serializer; | |||||
public Demo4() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
private Dictionary<string, DeviceType> cache = new Dictionary<string, DeviceType> | |||||
{ | |||||
{ "123456789012",DeviceType.DT1 }, | |||||
{ "123456789013",DeviceType.DT2 } | |||||
}; | |||||
/// <summary> | |||||
/// 处理多设备多协议附加信息Id冲突 | |||||
/// </summary> | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer demo5JT808Serializer = new JT808Serializer(jT808Config); | |||||
JT808Package jT808Package = JT808MsgId.位置信息汇报.Create("123456789012", | |||||
new JT808_0x0200 | |||||
{ | |||||
AlarmFlag = 1, | |||||
Altitude = 40, | |||||
GPSTime = DateTime.Parse("2018-12-20 20:10:10"), | |||||
Lat = 12222222, | |||||
Lng = 132444444, | |||||
Speed = 60, | |||||
Direction = 0, | |||||
StatusFlag = 2, | |||||
JT808CustomLocationAttachData = new Dictionary<byte, JT808_0x0200_CustomBodyBase> | |||||
{ | |||||
{0x81,new JT808_0x0200_DT1_0x81 { | |||||
Age=15, | |||||
Gender=1, | |||||
UserName="smallchi" | |||||
} } | |||||
} | |||||
}); | |||||
byte[] data = demo5JT808Serializer.Serialize(jT808Package); | |||||
var jT808PackageResult = demo5JT808Serializer.Deserialize<JT808Package>(data); | |||||
JT808_0x0200 jT808_0X0200 = jT808PackageResult.Bodies as JT808_0x0200; | |||||
var attach = DeviceTypeFactory.Create(cache[jT808PackageResult.Header.TerminalPhoneNo], jT808_0X0200.JT808CustomLocationAttachOriginalData); | |||||
var extJson = attach.ExtData.Data.ToString(Formatting.None); | |||||
var attachinfo81 = (JT808_0x0200_DT1_0x81)attach.JT808CustomLocationAttachData[0x81]; | |||||
Assert.Equal((uint)15, attachinfo81.Age); | |||||
Assert.Equal(1, attachinfo81.Gender); | |||||
Assert.Equal("smallchi", attachinfo81.UserName); | |||||
} | |||||
} | |||||
public interface IExtData | |||||
{ | |||||
JObject Data { get; set; } | |||||
} | |||||
public interface IExtDataProcessor | |||||
{ | |||||
void Processor(IExtData extData); | |||||
} | |||||
public class JT808_0x0200_DT1_0x81_ExtDataProcessor : IExtDataProcessor | |||||
{ | |||||
private JT808_0x0200_DT1_0x81 jT808_0X0200_DT1_0X81; | |||||
public JT808_0x0200_DT1_0x81_ExtDataProcessor(JT808_0x0200_DT1_0x81 jT808_0X0200_DT1_0X81) | |||||
{ | |||||
this.jT808_0X0200_DT1_0X81 = jT808_0X0200_DT1_0X81; | |||||
} | |||||
public void Processor(IExtData extData) | |||||
{ | |||||
extData.Data.Add(nameof(JT808_0x0200_DT1_0x81.Age), jT808_0X0200_DT1_0X81.Age); | |||||
extData.Data.Add(nameof(JT808_0x0200_DT1_0x81.UserName), jT808_0X0200_DT1_0X81.UserName); | |||||
extData.Data.Add(nameof(JT808_0x0200_DT1_0x81.Gender), jT808_0X0200_DT1_0X81.Gender); | |||||
} | |||||
} | |||||
public class JT808_0x0200_DT1_0x82_ExtDataProcessor : IExtDataProcessor | |||||
{ | |||||
private JT808_0x0200_DT1_0x82 jT808_0X0200_DT1_0X82; | |||||
public JT808_0x0200_DT1_0x82_ExtDataProcessor(JT808_0x0200_DT1_0x82 jT808_0X0200_DT1_0X82) | |||||
{ | |||||
this.jT808_0X0200_DT1_0X82 = jT808_0X0200_DT1_0X82; | |||||
} | |||||
public void Processor(IExtData extData) | |||||
{ | |||||
extData.Data.Add(nameof(JT808_0x0200_DT1_0x82.Gender1), jT808_0X0200_DT1_0X82.Gender1); | |||||
} | |||||
} | |||||
public class JT808_0x0200_DT2_0x81_ExtDataProcessor : IExtDataProcessor | |||||
{ | |||||
private JT808_0x0200_DT2_0x81 jT808_0X0200_DT2_0X81; | |||||
public JT808_0x0200_DT2_0x81_ExtDataProcessor(JT808_0x0200_DT2_0x81 jT808_0X0200_DT2_0X81) | |||||
{ | |||||
this.jT808_0X0200_DT2_0X81 = jT808_0X0200_DT2_0X81; | |||||
} | |||||
public void Processor(IExtData extData) | |||||
{ | |||||
extData.Data.Add(nameof(JT808_0x0200_DT2_0x81.Age), jT808_0X0200_DT2_0X81.Age); | |||||
extData.Data.Add(nameof(JT808_0x0200_DT2_0x81.Gender), jT808_0X0200_DT2_0X81.Gender); | |||||
} | |||||
} | |||||
public class DeviceTypeFactory | |||||
{ | |||||
public static DeviceTypeBase Create(DeviceType deviceType, Dictionary<byte, byte[]> jT808CustomLocationAttachOriginalData) | |||||
{ | |||||
switch (deviceType) | |||||
{ | |||||
case DeviceType.DT1: | |||||
return new DeviceType1(jT808CustomLocationAttachOriginalData); | |||||
case DeviceType.DT2: | |||||
return new DeviceType2(jT808CustomLocationAttachOriginalData); | |||||
default: | |||||
return default; | |||||
} | |||||
} | |||||
} | |||||
public enum DeviceType | |||||
{ | |||||
DT1 = 1, | |||||
DT2 = 2 | |||||
} | |||||
public abstract class DeviceTypeBase | |||||
{ | |||||
protected JT808Serializer JT808Serializer; | |||||
protected class DefaultExtDataImpl : IExtData | |||||
{ | |||||
public JObject Data { get; set; } = new JObject(); | |||||
} | |||||
public virtual IExtData ExtData { get; protected set; } = new DefaultExtDataImpl(); | |||||
public abstract Dictionary<byte, JT808_0x0200_CustomBodyBase> JT808CustomLocationAttachData { get; protected set; } | |||||
protected DeviceTypeBase(Dictionary<byte, byte[]> jT808CustomLocationAttachOriginalData) | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
Execute(jT808CustomLocationAttachOriginalData); | |||||
} | |||||
protected abstract void Execute(Dictionary<byte, byte[]> jT808CustomLocationAttachOriginalData); | |||||
} | |||||
public class DeviceType1 : DeviceTypeBase | |||||
{ | |||||
private const byte dt1_0x81 = 0x81; | |||||
private const byte dt1_0x82 = 0x82; | |||||
public DeviceType1(Dictionary<byte, byte[]> jT808CustomLocationAttachOriginalData) : base(jT808CustomLocationAttachOriginalData) | |||||
{ | |||||
} | |||||
public override Dictionary<byte, JT808_0x0200_CustomBodyBase> JT808CustomLocationAttachData { get; protected set; } | |||||
protected override void Execute(Dictionary<byte, byte[]> jT808CustomLocationAttachOriginalData) | |||||
{ | |||||
JT808CustomLocationAttachData = new Dictionary<byte, JT808_0x0200_CustomBodyBase>(); | |||||
foreach (var item in jT808CustomLocationAttachOriginalData) | |||||
{ | |||||
try | |||||
{ | |||||
switch (item.Key) | |||||
{ | |||||
case dt1_0x81: | |||||
var info81 = JT808Serializer.Deserialize<JT808_0x0200_DT1_0x81>(item.Value); | |||||
if (info81 != null) | |||||
{ | |||||
IExtDataProcessor extDataProcessor = new JT808_0x0200_DT1_0x81_ExtDataProcessor(info81); | |||||
extDataProcessor.Processor(ExtData); | |||||
JT808CustomLocationAttachData.Add(dt1_0x81, info81); | |||||
} | |||||
break; | |||||
case dt1_0x82: | |||||
var info82 = JT808Serializer.Deserialize<JT808_0x0200_DT1_0x82>(item.Value); | |||||
if (info82 != null) | |||||
{ | |||||
IExtDataProcessor extDataProcessor = new JT808_0x0200_DT1_0x82_ExtDataProcessor(info82); | |||||
extDataProcessor.Processor(ExtData); | |||||
JT808CustomLocationAttachData.Add(dt1_0x82, info82); | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
} | |||||
} | |||||
} | |||||
} | |||||
public class DeviceType2 : DeviceTypeBase | |||||
{ | |||||
public DeviceType2(Dictionary<byte, byte[]> jT808CustomLocationAttachOriginalData) : base(jT808CustomLocationAttachOriginalData) | |||||
{ | |||||
} | |||||
public override Dictionary<byte, JT808_0x0200_CustomBodyBase> JT808CustomLocationAttachData { get; protected set; } | |||||
private const byte dt2_0x81 = 0x81; | |||||
protected override void Execute(Dictionary<byte, byte[]> jT808CustomLocationAttachOriginalData) | |||||
{ | |||||
JT808CustomLocationAttachData = new Dictionary<byte, JT808_0x0200_CustomBodyBase>(); | |||||
foreach (var item in jT808CustomLocationAttachOriginalData) | |||||
{ | |||||
try | |||||
{ | |||||
switch (item.Key) | |||||
{ | |||||
case dt2_0x81: | |||||
var info81 = JT808Serializer.Deserialize<JT808_0x0200_DT2_0x81>(item.Value); | |||||
if (info81 != null) | |||||
{ | |||||
IExtDataProcessor extDataProcessor = new JT808_0x0200_DT2_0x81_ExtDataProcessor(info81); | |||||
extDataProcessor.Processor(ExtData); | |||||
JT808CustomLocationAttachData.Add(dt2_0x81, info81); | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
catch (Exception) | |||||
{ | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// 设备类型1-对应消息协议0x81 | |||||
/// </summary> | |||||
[JT808Formatter(typeof(JT808_0x0200_DT1_0x81Formatter))] | |||||
public class JT808_0x0200_DT1_0x81 : JT808_0x0200_CustomBodyBase | |||||
{ | |||||
public override byte AttachInfoId { get; set; } = 0x81; | |||||
public override byte AttachInfoLength { get; set; } = 13; | |||||
public uint Age { get; set; } | |||||
public byte Gender { get; set; } | |||||
public string UserName { get; set; } | |||||
} | |||||
/// <summary> | |||||
/// 设备类型1-对应消息协议0x82 | |||||
/// </summary> | |||||
[JT808Formatter(typeof(JT808_0x0200_DT1_0x82Formatter))] | |||||
public class JT808_0x0200_DT1_0x82 : JT808_0x0200_CustomBodyBase | |||||
{ | |||||
public override byte AttachInfoId { get; set; } = 0x82; | |||||
public override byte AttachInfoLength { get; set; } = 1; | |||||
public byte Gender1 { get; set; } | |||||
} | |||||
/// <summary> | |||||
/// 设备类型2-对应消息协议0x81 | |||||
/// </summary> | |||||
[JT808Formatter(typeof(JT808_0x0200_DT2_0x81Formatter))] | |||||
public class JT808_0x0200_DT2_0x81 : JT808_0x0200_CustomBodyBase | |||||
{ | |||||
public override byte AttachInfoId { get; set; } = 0x81; | |||||
public override byte AttachInfoLength { get; set; } = 7; | |||||
public uint Age { get; set; } | |||||
public byte Gender { get; set; } | |||||
public ushort MsgNum { get; set; } | |||||
} | |||||
/// <summary> | |||||
/// 设备类型1-对应消息协议序列化器 0x81 | |||||
/// </summary> | |||||
public class JT808_0x0200_DT1_0x81Formatter : IJT808MessagePackFormatter<JT808_0x0200_DT1_0x81> | |||||
{ | |||||
public JT808_0x0200_DT1_0x81 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||||
{ | |||||
JT808_0x0200_DT1_0x81 jT808_0X0200_DT1_0X81 = new JT808_0x0200_DT1_0x81(); | |||||
jT808_0X0200_DT1_0X81.AttachInfoId = reader.ReadByte(); | |||||
jT808_0X0200_DT1_0X81.AttachInfoLength = reader.ReadByte(); | |||||
jT808_0X0200_DT1_0X81.Age = reader.ReadUInt32(); | |||||
jT808_0X0200_DT1_0X81.Gender = reader.ReadByte(); | |||||
jT808_0X0200_DT1_0X81.UserName = reader.ReadRemainStringContent(); | |||||
return jT808_0X0200_DT1_0X81; | |||||
} | |||||
public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_DT1_0x81 value, IJT808Config config) | |||||
{ | |||||
writer.WriteByte(value.AttachInfoId); | |||||
writer.WriteByte(value.AttachInfoLength); | |||||
writer.WriteUInt32(value.Age); | |||||
writer.WriteByte(value.Gender); | |||||
writer.WriteString(value.UserName); | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// 设备类型1-对应消息协议序列化器 0x82 | |||||
/// </summary> | |||||
public class JT808_0x0200_DT1_0x82Formatter : IJT808MessagePackFormatter<JT808_0x0200_DT1_0x82> | |||||
{ | |||||
public JT808_0x0200_DT1_0x82 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||||
{ | |||||
JT808_0x0200_DT1_0x82 jT808_0X0200_DT1_0X82 = new JT808_0x0200_DT1_0x82(); | |||||
jT808_0X0200_DT1_0X82.AttachInfoId = reader.ReadByte(); | |||||
jT808_0X0200_DT1_0X82.AttachInfoLength = reader.ReadByte(); | |||||
jT808_0X0200_DT1_0X82.Gender1 = reader.ReadByte(); | |||||
return jT808_0X0200_DT1_0X82; | |||||
} | |||||
public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_DT1_0x82 value, IJT808Config config) | |||||
{ | |||||
writer.WriteByte(value.AttachInfoId); | |||||
writer.WriteByte(value.AttachInfoLength); | |||||
writer.WriteByte(value.Gender1); | |||||
} | |||||
} | |||||
/// <summary> | |||||
/// 设备类型2-对应消息协议序列化器 0x81 | |||||
/// </summary> | |||||
public class JT808_0x0200_DT2_0x81Formatter : IJT808MessagePackFormatter<JT808_0x0200_DT2_0x81> | |||||
{ | |||||
public JT808_0x0200_DT2_0x81 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) | |||||
{ | |||||
JT808_0x0200_DT2_0x81 jT808_0X0200_DT2_0X81 = new JT808_0x0200_DT2_0x81(); | |||||
jT808_0X0200_DT2_0X81.AttachInfoId = reader.ReadByte(); | |||||
jT808_0X0200_DT2_0X81.AttachInfoLength = reader.ReadByte(); | |||||
jT808_0X0200_DT2_0X81.Age = reader.ReadUInt32(); | |||||
jT808_0X0200_DT2_0X81.Gender = reader.ReadByte(); | |||||
jT808_0X0200_DT2_0X81.MsgNum = reader.ReadUInt16(); | |||||
return jT808_0X0200_DT2_0X81; | |||||
} | |||||
public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_DT2_0x81 value, IJT808Config config) | |||||
{ | |||||
writer.WriteByte(value.AttachInfoId); | |||||
writer.WriteByte(value.AttachInfoLength); | |||||
writer.WriteUInt32(value.Age); | |||||
writer.WriteByte(value.Gender); | |||||
writer.WriteUInt16(value.MsgNum); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,96 @@ | |||||
using JT808.Protocol.Interfaces; | |||||
using JT808.Protocol.MessageBody; | |||||
using JT808.Protocol.Extensions; | |||||
using System.Reflection; | |||||
using Xunit; | |||||
using System.Linq; | |||||
using JT808.Protocol.Internal; | |||||
namespace JT808.Protocol.Test.Simples | |||||
{ | |||||
public class Demo5 | |||||
{ | |||||
public JT808Serializer JT808Serializer; | |||||
public Demo5() | |||||
{ | |||||
IJT808Config jT808Config = new DefaultGlobalConfig(); | |||||
jT808Config.Register(Assembly.GetExecutingAssembly()); | |||||
jT808Config.SkipCRCCode = true; | |||||
JT808Serializer = new JT808Serializer(jT808Config); | |||||
} | |||||
/// <summary> | |||||
/// 处理多媒体数据上传分包处理方式 | |||||
/// </summary> | |||||
[Fact] | |||||
public void Test1() | |||||
{ | |||||
//1.首先了解行业的分包策略 | |||||
//一般行业分包是按256的整数倍,太多不行,太少也不行,必须刚刚好 | |||||
//例:这边以256的3倍进行处理 | |||||
var quotient = 6935 / (256 * 3); | |||||
var remainder = 6935 % (256 * 3); | |||||
if (remainder != 0) | |||||
{ | |||||
quotient = quotient + 1; | |||||
} | |||||
Assert.Equal(23, remainder); | |||||
Assert.Equal(10, quotient); | |||||
//得到有10包的数据 | |||||
//2.根据以上信息,来解分包数据 | |||||
//第一包 有具体信息+多媒体 | |||||
//第二包 多媒体数据 | |||||
//... | |||||
//最N包 多媒体数据 | |||||
byte[] bytes1 = "7e080123240138123456782031000a00010000271d0000010100000000000c200301d2400a063296a501e100000000190104092952ffd8ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d0101020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffdb004300080606070605080707070909080a0c140d0c0b0b0c1912130f141d1a1f1e1d1a1c1c20242e2720222c231c1c2837292c30313434341f27393d38323c2e333432ffdb0043010909090c0b0c180d0d1832211c213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232fffe000b4750456e636f646572ffdb0043000d090a0b0a080d0b0a0b0e0e0d0f13201513121213271c1e17202e2931302e292d2c333a4a3e333646372c2d405741464c4e525352323e5a615a50604a51524fffdb0043010e0e0e131113261515264f352d354f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4f4fffc000110800f0014003012100021101031101ffc4001f000001050101010101010000000000000000010203041c7e".ToHexBytes(); | |||||
byte[] bytes2 = "7e080123000138123456782032000a000205060708090a0bffc400b5100002010303020403050504040000017d0101020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffdd00040000ffda000c03010002110311003f006c6a2a755ce299a5c942e0f35281c5004aa72314a54e38a07b8841ef4840a0673de21b4ff498ee402038dade991fe7f4acc110f4a0cd8ef2f1405cd01d45f2e9360a062edc5745616a6dad511861cfccff0053499512e056cf1460e3348a0ed4b8e338fc2819cb5edbfd9ee648b18556f97fdd3d3f4aafb4d332ea433a6573e9550d3131d18c9c558031c0a4083a503039a60c42c2984e4f4a06260d370690098ef4751400c615132d021868a621431a33480ef235e05595403eb54cbb0b8e7069dc0e3a9a41b12a024f4a9d40f4a18c5651e951c88179268194ee614b989a2719461ffea35cfdcda4b6b2ed71c1e55874345c96ba91819a704c50217613db349b39031c9e945c66a69ba794713cebf30fb8be9ee6b540c1e948a48760e3a526d2dc77a0a144471d297cb623a71484646bb685234b81d01d8e7d018f43f9ff003ac16386c552225b8300c2a84c8c8c4ed247b502616cc0517e".ToHexBytes(); | |||||
byte[] bytes3 = "7e080123000138123456782033000a0003b104558fe2c0a0561a4a2fde603ea69a67887f10fca80b8c33a960aa0b13d001d6a4f2e73d2d2e3f189a906e42653fdd23eb40dec3229dc7b91bc855b19e69c8dbc7d29081bad308a2e0308a6e281094b4c0efd41152a83815459623518c9a4000391f852192ad4c89923340131031c5579327822a4645e5f534bf6649c794f109037f0e33f8fb530226f0a1621a39bca1dc30dd4f8fc2d1a91be791cfb1007f2a9bb15916a3f0f59a0cb4793ebb98ff005a6369f6d6f70c6285548c60e327a5090f4e82f94b8e050235eb8cd3192000f6a76063a0a62b8840e83ad3447d02f487723b8b549edde09092b229527fad70d3c4e8ed1b7d01e462a7ea0e0d344b05538a8a7520676d0495611fbd1907a54ea3e623de80335d8b4849eb46334124d6937d019aee19b3808e0b7d013a1fd09aebc001871d0e2933481c83fdf6efc9fe75620c6de693d89452bb189734d82508ff0037434c4f72c821864546d4c08c9a4ed4084cd25203d284240e68db8e2acb628cf4a72825b9a2c05855e47bd4c1690c5ee39fca8f2c1393d2900151c8c0ad2b1882401f1f31efed43d81ec583498f6a424348acd9c66773ef8a10c6600c534af3c530142f7c52ede2818a073cd21a4034d739e21b411dca5c8185986d6f671fe23f9500f63194e1b069d20057a5324a9b3f7a1881c53e4555607d0168119772bb6e5fd09c8fc69b412275eb5d468f78b736b1c6cdfbd880571dc81d1bfcf7a4ca8bb330580dc40f53fcea488606293d86ad733e6ddb8ef3920d474c82cdbb020a9fc2a465c8a0688186293b5021292803d594074e7f0a89a160724552346089baa558c861c67f0a6c0777e94aa0e79a901ebef4fe31400a3a678ad4b7188231fecd0c4c7d01252101acc941f31ffde3fce84086e3bd2ed0062994252f14009c629b814804e38f5aaf7d016ab79672db9382c32a4f661d0d0338a91086391b4824303d88ea29c872281113a60f34c7e573e94c452d413947f6c5550322826c1814a32ac1d58ab0e841c11f8d0200cc3bd289a453f2b63f006931a644e4b1249e6a3a043a27dae0d5cc823340d0d2aa7ad3590638a632e77e".ToHexBytes(); | |||||
byte[] bytes4 = "7e080123000138123456782035000a00041208ed499f6a449ead03f1524846474abb1a0232820e29dc1e7ad20184e7a52a939a180f3c1a073dc502141c02066b5e2ff5298fee8a4c18b4b484277acb392324fbd34026de393d280a31c0a0a178f4a3ad001f8521a402714868039bf1159ecb85b940764dc37b3fff005c7f235891b6d6c1a043a5191915120c8c1a68457ba42d6ad9c165e7fc6b3874a04c3bd5ab3837923ece66661951e66deffafe74304421148ce08cfbd396dc367d026c52b82d4ad2aec62b9ce38a84d0480abb6bf347f8d0344a5451b01a650d31835198850267a4c6c78c54c32464d51403f3a777ce39fa5001c8e9d68f28c992cdc7a6290c9428005017b81400e00107e95ad19fdd27fba293131b24b1c632ed8cfe755daf3fb8871eadfe148446d7331fe20bf4150e6a876179c507ebcd2013bd2f7d02b40c303bd2607ad201300f4a69c77a01115ddba5d5bbc127dd71d7fba7b1fceb89ba824b79de39542ba1c30f5f71ed4d0d8d07726291461a8246b2fcecad92a47d029d0d63152ae55ba8e0d02618abb6ccb04f6f234ea132a5846fc8ee411498968439c28fa5393279ed40d22adcae253ef55cd0896255bb161b8a9eb8c8a016e5a75a68e0505aee148453623d063391565785e6ada180fa714ea401d3a5381cf7a00909e3af3429f97d01a900efa035a687f769fee8fe552c199ef966663f7893d699c81540213f4a33400bc91ed41ebd28181e7bd02900beb49c039a004e868c7ad218d3d39ac9d774ff00b4422e625ccb18c3003efaff0088ff001f6a019cc018e54e41a53c72699224bfc2c2b2af976cf9ecdcd026419ab576e860b4db22bb2c655b6f6e8403ef834988801cf34fdc7a0a0115e62c4fcc7245407ad026253a362ac18751c8a048d546124418742298460f34cd3a077a4228b08f404ed8a9d73deb41920507a52e30290213b50bd793480939a7a807f1a403fa0eb5a31f31a7a6d1fca930651907ccdfef1fe74dc647340119ebc11477a602f34bc628003d29052016909a0043cfad21e281a003e5e691b83c1a451ce6b3a68819aea15fdcb1f9947f013dfe9fcab16746d9f2119a09636305f17e".ToHexBytes(); | |||||
byte[] bytes5 = "7e080123000138123456782036000a0005e0d87395e39aa77d02bbe049076feb4c9281276123ae2b5756b69223120c1853708f1db2727f1e83f0a4dd848cec1cfd29caac4f14011dcc4ea4b31041f4aaadd681356128140917ac64f98c4ddf95feb53bafcd4ee5a0e945219e8082a55ad009948c0a0f5e690098e694601e68043875229c0f6348078208c55813b9558e24e40029010bee048239cf34c24fe1400879e86933c530173c71450028e68e7b5200cf1cd1d28189cf7a6f7a0033e941a431ac0104100823041ef5ce6a7a5b5bee96005adfa95ef1ff0088a00c644f2dfe5fba6a3963dc92463b8247f9fad3259931a6f9163e9bc85fcf8aeb6f915ecae5994102372323b80706a5847a9cb370dc5390f4e69b12dc5bbe62ace6a5109ee349a01a64122b302194e083915a88e254571d08fca8452131cd25319e82bd29ea735a0c91781c714b4807720d1d4d20141ff38a7fe14980e19c702b4605558548ee326a58156e062673ea47f21509071c53431a69b4c42f238a5140071d28a402fd68ebcd0310b718a414001e3ad44cf8e00cd21d803315191cd009c66819caf8996dec6680c3195926dc59411b703b8f7c9e9d2b145d6eb80a5782700e7f2a086ecc86e54db5d4770abb9438703d483922b7deee0bad3259607d01ca40057bae481823f1a182dce6dc0dec3d09a68386cd0224b878cc240910923b106b3de9209319494c81c2ae58cbb4b467a1e47d017bd0868b8453282cf425c60669c0815a88703e94e1f5a4317a914b9a005079a729f7a404d1f4e6b42123c95e73c5430655bac79bf85454c6842335191838a10064668ce7b531052e6818123346714804c8cf14848cd16018fcf5a3e5ce33cd2283349cd202b5e5a5ade2aa5ddba4a14e5438e95c8788eca1b3d563682210c32c61f0a30b9048381db803f3a052d88595590c728f620f5154e4b22afba07cfe383f9d321a20659d3ef231f7c66a32f92322810e7784a711b06c7d021fceaab74a1098ca4a04396a48d5f70d80ee078a011aad8e7151e683447a103c5387bd6a214714e07b5218eed49cd210b5228cd0c68915702afdb7302fe3fcea58d8c9e2df8651cd46b17e".ToHexBytes(); | |||||
byte[] bytes6 = "7e080123000138123456782037000a00062d98fde200fce95c02689121cae4b64724d553d734d0098a2988075e29739a061c75a43d6900a00f7cd21a010d23351f92a4e49a4324031c0a42300fafa503216697236c6847bb91fd2b03c636cd2e9b0cdb483149b49073856183fa85a2e26b42e2edbdd3ade5b8b433bcb023332ed0725413825811595aa69d0c16ed730a5cc2c1954233232f240f527f5a416b984d75872acac307069a6ef9fbb914c812496129cc0c0b742c8067f1aa0d4098ca4a091d19c383ef5a8846060505445249ed4d39c5051e8601ed4a2b5174179a72d201e791d680290583daa44f7340d130e956ed8feeb1e86a18c968a40417471171d73548903ad5201327a51d45301474a43d78a041d283f5a062134bee6800ed4dcd21a133c51d4521dc43ef54758b6375a45dc001666889503a961cafea0520650f0ccab2e816e158b142e873dbe6240fc88a678924f2ec2200f0f3a839f4dac7f9814093d0e36521a6761ce5891f9d307d01ea642dcd28119e103cc700f1818ac871c9a888e6b44454559980abf6d306f948e719a0a44ae48a8c927bd0ca3d21474a76dad405ed4a05210a4d00fbd0028fcaa44cd26324c9c60d5ab5276107d6a58c9ba5213807daa40a72c85db3dbb66a02393d7156803b51da80141a0d00379cd19e6980734a6a404cfe2293ad030cf3d69290087ad267041f439a0673de1b516a752d3c2b0fb3dc92a4f752303f44cfe351f8ad87d8201d499f3f9237f88a5d457f74e489e4d20eb4cccd4b63fba0738ac89861d87bd4c772e7b101a43546402acdb1fde7e140e25966cd309a451e96b8c53b391c56cc032334b9ed4ba007229473400e5f5ef5203498c783ed566d8f2c3f1a96327c8f4aad7126ef917a0eb490105348f6a60373da81f4aa00e334669083a77d02b49939a00075a318340c3f4a0e290c4ef487af1486235337608c73cd0c673da0e9c63b896f9aefce626481814e490e0649cfa2838c77aafe2e3f2d90c9c7ef4ffe81fe34913f64e58f5a55049e29999ab021f2c2e39ac8b9c79cf8e066a22f52e7b15cd2559900a9adff00d60a06b72e374a61a459e97818a33c735b517e".ToHexBytes(); | |||||
byte[] bytes7 = "7e080123000138123456782039000a0007083753860d0201eb474249a431c0e3be69e0feb40c78e9cd4f6ee164e4f0c3152c09e57f2d38fbc7a553e49e7a9a48628cd205c0ed400df6a4ebc835420a3a74a0043463b5201067d453bad0310d2521852646290c6139a6e307e94018fa080a9a8afa6a330ffd06b27c5b213776f1e785889c7d015bff00b1fd2844bd8e74d2ae148dd43211785f4318eacc7fd95ff1ace9dc492b3818c92706a522e72bab101a61aa320152c270e28045eea29bde91a1e900e40ce29df4ad84181fe34bdb148017a7ad29191c1e28004523bfeb52af4a0687678a5cf03fc6900fdc4f2c72693d719a40814f34ee3191487718c78f534cfa55210527d2900528a6301d68ed4803eb49f5a43427e34879a430f6a6b71de90185a54d1c17fa9d9cce893bde3cc8acc01757c118f5e954f58b34bef10c56f2dca5b462d4349230e803bf41dc9240fc68b93ba33aef4db479c47a79b928bd65b8651bbaf450338fa9cfb53e3b3d3e1426e2de795c63ef30c1fa053fce84db1596e4332d938262b344278c3123f406b1e7016420631ed4214add080d34d32029e870c0d008be0fca28a469d0f46538a767dab6b08307ae452e79a02c3c0f6a5e280157834ef6a43428a5079e2900e5a53de90c4ce0d283400d61f5a667d29a00e293340833cd3a90013471c7340c4a3ad218d079a53eff00a5201a698719e681952fac6d2f902dd4092606031e187d0108e4571da9eed3b549618a5790441510ca7710a541c7b637629589969b14cea175962b22ae7fba8bf9722a169e763969a4fc188a6436205790e0b649fef1a8e58cc6d8241fa52b85b42134ca64853875a00bf09cc629c691a743d1507a53803bab7247f51487afad20147b529a060bc53b3f4a40283c734e1dbd6818e1c1a71a402639a00f5a0071195a85bae69218ccf3d697b5310718a39ec2801d9a09e290c4cf3d68ef498c4cf3f4a42690210f4a6e05031ae462b83f104825d5ee88c7126dff00be542ffecb40a5b1979a51419a244201a8e76dcf483a15cf5a6d3244a506802edb1fddd48c78a562d6c7a42e78152003ad6c21718a61ebc503140e79a0f5c57e".ToHexBytes(); | |||||
byte[] bytes8 = "7e08012300013812345678203a000a0008e050003d69c39148078a75030073cd2e49a402819a4ce38a100ecf1cd31c11490c8f1ef4d2714c419e697340200d9e28c8cd0302e0537713d2900b839a711523108f6a61e940d0c6e481d2bcef527126a172ebd1a7908ffbecd3265b1529b9a4412c43229938c3500f62b93494122502802dda9e08a9cfa522d6c7a4af4a7027b56cc07751cd37239a003349df02801ca29e01cd201e07ad35b9c8eded4863870296800fc6900e7d01e818ece3a8e29924c8382d4ac0425d4f3918fcf346e07bfe54c41de940e280414c7ce06290d0880f7a9028a40380e48a5268631b8ebe9519e3a5201bbb69dc7a0e4d798e7f7683fd914132129941058807cb51dce7752ea37b158d253244a050059b53f362ad1eb525ad8f4843c52b673c56e02eee314dcf6a40380cf6a728e78a02c380a7724d0324c7151b019ef48031c7b8a51db8c9a00701bbd2823029019f7b3b2f0a08acc6f3a46ea49f6a4d945eb585f6fef2ae2a63914d09ee3b1487a5315c074a303bd200e94a39a063b9141e9d290d0c272714d3d7a74a4329ea6e63d32f1c1c15b79083efb4e2bcea4c6ec0e8381411313b532820b76e3e5a86ec7cf496e53d8aa69299025140135b9c3d5c26917167a5a8c2d2119e6b604369ebc9a043a9573e940c701eb4ec60648a43149fca8efcd201a41fafd2973d38a00907e82931da9011490abff0d462dd57955c51618e031d051f8d3105250c04c668c7a50160fc29d8e3b5218a38a3ad218d34da00cbf11b32e857454e090a99f666507f426b8173f3923d6826436900e69106a4501f211d57aa838aa179feb2a22f53492b22a9eb4dab3210d1401243f7c55ea0a47a59e94bdb9ad46263238a700062801ddf9a075a063874e3a0a5038a4027d290668121738a51d7148a2651c507bfa5480da461ef4c061fc2986a84250460520003bf5cfa526da005007526979a06264fad2e38a4034e477a692690cc3f16c853485453feb27453f400b7f3515c4b0e68225b801c53e38c33804f7a4248d9b71b620a3a0e0565ea8a05c123bd4477349af74cf34dab310c5262801f1fdf15a1fc2291713d29e17e".ToHexBytes(); | |||||
byte[] bytes9 = "7e08012300013812345678203b000a000979e3a53f19c56e00571401c83e94807751477a062f7a334806939a51400ee714e51ce6900fcf6a5c8c62a4634900e05464f38a6806f4149926a8570fc281f4a00300f5147514804cf38ef4a46690d09c62973e94980c6e05373c734586735e309084b3887d01d66773f50001ff00a11ae5475a4449ea3a917a8a03a9b96e331afd05656abff1f1f854477349fc2671a6d5988525021cbf785690c14071499713d1d6a5e715b80b8a41c5031e3d7a51838a9005ce6822801b8c7ffaa9caa3a8a00514f0063ae6a406938e9c500d3189c93d29ac0d0210d3698801e334eea3fa50301411405841cd21a430f6a09348686923bd37a0c0a40723e2d918ea11467d02ea4008fab31cff00e822b0145043dc5229557914811b36ff00eac7d2b2b533998d4477349ec67914d356602514000eb5a28dfbb1499513d2e300549c56c317391d29b8a009171dea4c6471c5263136e39a69eb4806d2e71da980139e3934a091ee29580060d03b71de900a00fad35a980d6a691d85001e94a05300ed49ef4009c75c51d690c404678a2a410c6a6ee3eb40d1c4788df76b574339d9b147e083fa9359a9410c76053d00dc2902352318502b2750e6723d2a62692d8a2d4d35460211498a003bd5f888f2c50ca47a62364022a4072335b0c55c9a5c67b5218a3838e69eadf4a403b3c534f348031c51b7d2800dbcf4a52bdfad201b4ee9cd00216fad464f3c9cfd280140e39cd3714c050b498e7ad0027b671450c2e21e4534d0019f6a439a43434f4e69a4f6148a380d4dfccd46e9f76eccefce7a80c40fd00aacb4198a4e29eae030c52046ba8205635f9ff486a989a4f6291eb486a8c46d250201d6ae43f7052291e8f6d28c0c9e2ae2e36e715b8c701de9c0fd6a405e0f14a3e940c3bd2e38a4029e3147005200f4a427b50027f5a4ddda9821a7149804d031c41e9498f4033ed400e031d69ac31d29086f5a4fd6a806fe94948000a53d3148a18c31e86a3670877b7217938f41480f36e91203fdd1403c506605b1525b61a6553d09a4f61adcdf8903b2a138cfa75c77ac1d54a7db64f2d76a6e3b46738fc6b38b6b7e".ToHexBytes(); | |||||
byte[] bytes10 = "7e08012017013812345678203c000a000ad4dea2f72e50269b5a1ca251400a2ad427e5a4ca47ffd9d17e".ToHexBytes(); | |||||
JT808Package jT808_0X0801_1 = JT808Serializer.Deserialize<JT808Package>(bytes1); | |||||
JT808Package jT808_0X0801_2 = JT808Serializer.Deserialize<JT808Package>(bytes2); | |||||
JT808Package jT808_0X0801_3 = JT808Serializer.Deserialize<JT808Package>(bytes3); | |||||
JT808Package jT808_0X0801_4 = JT808Serializer.Deserialize<JT808Package>(bytes4); | |||||
JT808Package jT808_0X0801_5 = JT808Serializer.Deserialize<JT808Package>(bytes5); | |||||
JT808Package jT808_0X0801_6 = JT808Serializer.Deserialize<JT808Package>(bytes6); | |||||
JT808Package jT808_0X0801_7 = JT808Serializer.Deserialize<JT808Package>(bytes7); | |||||
JT808Package jT808_0X0801_8 = JT808Serializer.Deserialize<JT808Package>(bytes8); | |||||
JT808Package jT808_0X0801_9 = JT808Serializer.Deserialize<JT808Package>(bytes9); | |||||
JT808Package jT808_0X0801_10 = JT808Serializer.Deserialize<JT808Package>(bytes10); | |||||
var jT808_0X0801_body_1 = jT808_0X0801_1.Bodies as JT808_0x0801; | |||||
var jT808_0X0801_body_2 = jT808_0X0801_2.Bodies as JT808SplitPackageBodies; | |||||
var jT808_0X0801_body_3 = jT808_0X0801_3.Bodies as JT808SplitPackageBodies; | |||||
var jT808_0X0801_body_4 = jT808_0X0801_4.Bodies as JT808SplitPackageBodies; | |||||
var jT808_0X0801_body_5 = jT808_0X0801_5.Bodies as JT808SplitPackageBodies; | |||||
var jT808_0X0801_body_6 = jT808_0X0801_6.Bodies as JT808SplitPackageBodies; | |||||
var jT808_0X0801_body_7 = jT808_0X0801_7.Bodies as JT808SplitPackageBodies; | |||||
var jT808_0X0801_body_8 = jT808_0X0801_8.Bodies as JT808SplitPackageBodies; | |||||
var jT808_0X0801_body_9 = jT808_0X0801_9.Bodies as JT808SplitPackageBodies; | |||||
var jT808_0X0801_body_10 = jT808_0X0801_10.Bodies as JT808SplitPackageBodies; | |||||
var imageBytes = jT808_0X0801_body_1.MultimediaDataPackage | |||||
.Concat(jT808_0X0801_body_2.Data) | |||||
.Concat(jT808_0X0801_body_3.Data) | |||||
.Concat(jT808_0X0801_body_4.Data) | |||||
.Concat(jT808_0X0801_body_5.Data) | |||||
.Concat(jT808_0X0801_body_6.Data) | |||||
.Concat(jT808_0X0801_body_7.Data) | |||||
.Concat(jT808_0X0801_body_8.Data) | |||||
.Concat(jT808_0X0801_body_9.Data) | |||||
.Concat(jT808_0X0801_body_10.Data).ToArray(); | |||||
//using (MemoryStream ms = new MemoryStream(imageBytes)) | |||||
//{ | |||||
// Image image = Image.FromStream(ms); | |||||
// image.Save("test.jpeg"); | |||||
//} | |||||
} | |||||
} | |||||
} |