commit 3ecbef0a274e1ebe8ce06829f7a4c2f36f8aa5e3 Author: SmallChi <564952747@qq.com> Date: Sat Jun 29 23:00:52 2019 +0800 重新出发 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..940794e --- /dev/null +++ b/.gitignore @@ -0,0 +1,288 @@ +## 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 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# 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 + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.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 + +# 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 + +# 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 +# TODO: 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 +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/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 + +# 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 + +# 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 + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Typescript v1 declaration files +typings/ + +# 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 + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a48f30b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: csharp +solution: JT809.Protocol.sln +dotnet: 2.2.101 +os: linux +mono: none +dist: trusty2 +script: + - dotnet restore src/JT809.Protocol.sln + - dotnet build src/JT809.Protocol.Test/JT809.Protocol.Test.csproj + - dotnet test src/JT809.Protocol.Test/JT809.Protocol.Test.csproj +after_success: + - echo successful build! +branches: + only: + - master diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c0783ad --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 SmallChi + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e78219b --- /dev/null +++ b/README.md @@ -0,0 +1,431 @@ +# JT809协议 + +[![MIT Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/SmallChi/JT809/blob/master/LICENSE)[![Build Status](https://travis-ci.org/SmallChi/JT809.svg?branch=master)](https://travis-ci.org/SmallChi/JT809) + +## 前提条件 + +1. 掌握进制转换:二进制转十六进制; +2. 掌握BCD编码、Hex编码; +3. 掌握各种位移、异或; +4. 掌握常用反射; +5. 掌握快速ctrl+c、ctrl+v; +6. 掌握Span\的基本用法 +7. 掌握以上装逼技能,就可以开始搬砖了。 + +## JT809数据结构解析 + +### 数据包[JT809Package] + +|头标识|数据头|数据体|CRC校验码|尾标识 +|:------:|:------:|:------:|:------:|:------:| +| BeginFlag | JT809Header | JT809Bodies | CRCCode | EndFlag | +| 5B | - | - | - | 5D | + +### 数据头[JT809Header] + +|数据长度|报文序列号|业务数据类型|下级平台接入码|协议版本号标识|报文加密标识位|数据加密的密匙| +|:------:|:------:|:------:|:------:|:------:|:------:|:------:| +| MsgLength | MsgSN | BusinessType | MsgGNSSCENTERID | Version |EncryptFlag | EncryptKey | + +### 数据体[JT809Bodies] + +> 根据对应业务数据类型:BusinessType + +|车牌号|车辆颜色|子业务类型标识|后续数据长度|子业务数据体 +|:------:|:------:|:------:|:------:|:------:| +| VehicleNo | VehicleColor | SubBusinessType | DataLength | JT809SubBodies | + +### 子数据体[JT809SubBodies] + +> 根据对应子业务数据类型 SubBusinessType 处理子业务数据体(JT809SubBodies)。 + +***注意:数据内容(除去头和尾标识)进行转义判断*** + +转义规则如下: + +1. 若数据内容中有出现字符 0x5b 的,需替换为字符 0x5a 紧跟字符 0x01; +2. 若数据内容中有出现字符 0x5a 的,需替换为字符 0x5a 紧跟字符 0x02; +3. 若数据内容中有出现字符 0x5d 的,需替换为字符 0x5e 紧跟字符 0x01; +4. 若数据内容中有出现字符 0x5e 的,需替换为字符 0x5e 紧跟字符 0x02. + +反转义的原因:确认JT809协议的TCP消息边界。 + +### 举个栗子1 + +#### 1.组包: + +> 业务数据类型 BusinessType:从链路报警信息交互消息 +> +> 子业务类型标识 SubBusinessType:报警督办请求消息 + +``` code +JT809Package jT809Package = new JT809Package(); + +jT809Package.Header = new JT809Header +{ + MsgSN = 1666, + EncryptKey = 9999, + EncryptFlag= JT809Header_Encrypt.None, + Version = new JT809Header_Version(1, 0, 0), + BusinessType = JT809BusinessType.从链路报警信息交互消息, + MsgGNSSCENTERID = 20180920, +}; + +JT809_0x9400 bodies = new JT809_0x9400 +{ + VehicleNo="粤A12345", + VehicleColor= JT809VehicleColorType.黄色, + SubBusinessType= JT809SubBusinessType.报警督办请求消息, +}; + +JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401 +{ + WarnSrc = JT809WarnSrc.车载终端, + WarnType = JT809WarnType.疲劳驾驶报警, + WarnTime = DateTime.Parse("2018-09-27 10:24:00"), + SupervisionID = "123FFAA1", + SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), + SupervisionLevel = 3, + Supervisor = "smallchi", + SupervisorTel = "12345678901", + SupervisorEmail = "123456@qq.com" +}; + +bodies.SubBodies = jT809_0x9400_0x9401; + +jT809Package.Bodies = bodies; + +byte[] data = JT809Serializer.Serialize(jT809Package); + +string hex = data.ToHexString(); + +// 输出结果Hex: +// 5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D +``` + +#### 2.手动解包: + +``` data +1.原包: +5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 (5A 01) AC 3F 40 12 3F FA A1 00 00 00 00 (5A 01) AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D + +2.进行反转义 +5A 01 ->5B +5A 02 ->5A +5E 01 ->5D +5E 02 ->5E +反转义后 +5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5B AC 3F 40 12 3F FA A1 00 00 00 00 5B AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D + +3.拆解 +5B --头标识 +00 00 00 92 --数据头->数据长度 +00 00 06 82 --数据头->报文序列号 +94 00 --数据头->业务数据类型 +01 33 EF B8 --数据头->下级平台接入码,上级平台给下级平台分配唯一标识码 +01 00 00 --数据头->协议版本号标识 +00 --数据头->报文加密标识位 +00 00 27 0F --数据头->数据加密的密匙 +D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 --数据体->车牌号 +02 --数据体->车辆颜色 +94 01 --数据体->子业务类型标识 +00 00 00 5C --数据体->后续数据长度 +01 --子数据体->报警信息来源 +00 02 --子数据体->报警类型 +00 00 00 00 5B AC 3F 40 --子数据体->报警时间UTCDateTime +12 3F FA A1 --子数据体->报警督办ID +00 00 00 00 5B AC 4D 50 --子数据体->督办截止时间 +03 --子数据体->督办级别 +73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 --子数据体->督办人 +31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 --子数据体->督办联系电话 +31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --子数据体->督办联系电子邮件 +BA D8 --CRC校验码 +5D --尾标识 +``` + +#### 3.程序解包: + +``` data +//1.转成byte数组 +var bytes = "5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D".ToHexBytes(); + +//2.将数组反序列化 +JT809Package jT809Package = JT809Serializer.Deserialize(bytes); + +//3.数据包头 +Assert.Equal((uint)146, jT809Package.Header.MsgLength); +Assert.Equal((uint)1666, jT809Package.Header.MsgSN); +Assert.Equal((uint)9999, jT809Package.Header.EncryptKey); +Assert.Equal(JT809Header_Encrypt.None, jT809Package.Header.EncryptFlag); +Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); +Assert.Equal(JT809BusinessType.从链路报警信息交互消息, jT809Package.Header.BusinessType); +Assert.Equal(new JT809Header_Version(1, 0, 0).ToString(), jT809Package.Header.Version.ToString()); + +//4.数据包体 +JT809_0x9400 jT809_0X400 = (JT809_0x9400)jT809Package.Bodies; +Assert.Equal("粤A12345", jT809_0X400.VehicleNo); +Assert.Equal(JT809VehicleColorType.黄色, jT809_0X400.VehicleColor); +Assert.Equal(JT809SubBusinessType.报警督办请求消息, jT809_0X400.SubBusinessType); +Assert.Equal((uint)92, jT809_0X400.DataLength); + +//5.子数据包体 +JT809_0x9400_0x9401 jT809_0x9400_0x9401 = (JT809_0x9400_0x9401)jT809_0X400.JT809SubBodies; +Assert.Equal(JT809WarnSrc.车载终端, jT809_0x9400_0x9401.WarnSrc); +Assert.Equal(JT809WarnType.疲劳驾驶报警, jT809_0x9400_0x9401.WarnType); +Assert.Equal(DateTime.Parse("2018-09-27 10:24:00"), jT809_0x9400_0x9401.WarnTime); +Assert.Equal("123FFAA1", jT809_0x9400_0x9401.SupervisionID); +Assert.Equal(DateTime.Parse("2018-09-27 11:24:00"), jT809_0x9400_0x9401.SupervisionEndTime); +Assert.Equal(3, jT809_0x9400_0x9401.SupervisionLevel); +Assert.Equal("smallchi", jT809_0x9400_0x9401.Supervisor); +Assert.Equal("12345678901", jT809_0x9400_0x9401.SupervisorTel); +Assert.Equal("123456@qq.com", jT809_0x9400_0x9401.SupervisorEmail); + +``` + +### 举个栗子2 + +``` data2 +// 根据业务类型创建对应包 +JT809Package jT809Package = JT809BusinessType.从链路报警信息交互消息.Create_从链路报警信息交互消息( + new JT809Header + { + MsgSN = 1666, + EncryptKey = 9999, + EncryptFlag = JT809Header_Encrypt.None, + Version = new JT809Header_Version(1, 0, 0), + MsgGNSSCENTERID = 20180920, + }, new JT809_0x9400 + { + VehicleNo = "粤A12345", + VehicleColor = JT809VehicleColorType.黄色, + SubBusinessType = JT809SubBusinessType.报警督办请求, + SubBodies = JT809SubBusinessType.报警督办请求.Create_报警督办请求( + new JT809_0x9400_0x9401 + { + WarnSrc = JT809WarnSrc.车载终端, + WarnType = JT809WarnType.疲劳驾驶报警, + WarnTime = DateTime.Parse("2018-09-27 10:24:00"), + SupervisionID = "123FFAA1", + SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), + SupervisionLevel = 3, + Supervisor = "smallchi", + SupervisorTel = "12345678901", + SupervisorEmail = "123456@qq.com" + }) + } +); +var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); +``` + +### 举个栗子3 + +``` data3 +static void Main(string[] args) +{ + class JT809GlobalConfig: GlobalConfigBase + { + public override JT809EncryptOptions EncryptOptions { get; set; }= new JT809EncryptOptions() + { + IA1 = 20000000, + IC1 = 20000000, + M1 = 30000000 + }; + public override string ConfigId => "JT809GlobalConfig"; + } + JT809Serializer JT809Serializer = new JT809Serializer(new JT809GlobalConfig()); + // todo: +} +``` + +### 举个栗子4 + +使用依赖注入的方式实现配置 + +Install-Package JT809.Extensions.DependencyInjection + +[参考例子](https://github.com/SmallChi/JT809/blob/master/src/JT809.Protocol.Extensions.DependencyInjection.Test/Program.cs) + +## NuGet安装 + +| Package Name | Version | Downloads +|--------------| ------- | ---- +| Install-Package JT809 | ![JT809](https://img.shields.io/nuget/v/JT809.svg) | ![JT809](https://img.shields.io/nuget/dt/JT809.svg) +| Install-Package JT809.Extensions.DependencyInjection | ![JT809.Ext](https://img.shields.io/nuget/v/JT809.Extensions.DependencyInjection.svg) | ![JT809.Ext](https://img.shields.io/nuget/dt/JT809.Extensions.DependencyInjection.svg) + +## 使用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.3416.0 + Job-FVMQGI : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.3416.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 | N | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated | +|---------------------------------------- |-------------- |------- |-------------:|-------------:|-------------:|-----------:|------:|------:|-------------:| +| **JT809_0x9400_0x9401_Package_Deserialize** | **Default** | **100** | **690.1 us** | **13.596 us** | **21.565 us** | **18.5547** | **-** | **-** | **118.75 KB** | +| JT809_0x9400_0x9401_Package_Serialize | Default | 100 | 332.8 us | 6.863 us | 7.047 us | 11.7188 | - | - | 74.22 KB | +| JT809_0x9400_0x9401_Package_Deserialize | .NET Core 2.2 | 100 | 385.4 us | 5.410 us | 5.061 us | 19.0430 | - | - | 118.75 KB | +| JT809_0x9400_0x9401_Package_Serialize | .NET Core 2.2 | 100 | 201.0 us | 2.146 us | 1.903 us | 11.9629 | - | - | 74.22 KB | +| **JT809_0x9400_0x9401_Package_Deserialize** | **Default** | **10000** | **68,568.1 us** | **1,263.632 us** | **1,182.002 us** | **1857.1429** | **-** | **-** | **11875.59 KB** | +| JT809_0x9400_0x9401_Package_Serialize | Default | 10000 | 32,706.0 us | 440.949 us | 412.464 us | 1187.5000 | - | - | 7422.12 KB | +| JT809_0x9400_0x9401_Package_Deserialize | .NET Core 2.2 | 10000 | 38,843.3 us | 968.815 us | 858.829 us | 1928.5714 | - | - | 11875 KB | +| JT809_0x9400_0x9401_Package_Serialize | .NET Core 2.2 | 10000 | 19,914.1 us | 383.802 us | 394.136 us | 1187.5000 | - | - | 7421.88 KB | +| **JT809_0x9400_0x9401_Package_Deserialize** | **Default** | **100000** | **678,892.7 us** | **9,244.595 us** | **8,647.400 us** | **19000.0000** | **-** | **-** | **118753.65 KB** | +| JT809_0x9400_0x9401_Package_Serialize | Default | 100000 | 336,631.2 us | 2,672.170 us | 2,499.550 us | 12000.0000 | - | - | 74225.1 KB | +| JT809_0x9400_0x9401_Package_Deserialize | .NET Core 2.2 | 100000 | 387,380.1 us | 6,355.761 us | 5,945.183 us | 19000.0000 | - | - | 118750 KB | +| JT809_0x9400_0x9401_Package_Serialize | .NET Core 2.2 | 100000 | 198,709.1 us | 3,502.843 us | 3,276.562 us | 12000.0000 | - | - | 74218.75 KB | + +## JT809协议消息对照表 + +### 链路管理类 + +#### 主链路 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x1001 | √ | √ | 主链路登录请求消息 | +| 2 | 0x1002 | √ | √ | 主链路登录应答消息 | +| 3 | 0x1003 | √ | √ | 主链路注销请求消息 | +| 4 | 0x1004 | √ | √ | 主链路注销应答消息 | +| 5 | 0x1005 | √ | √ | 主链路连接保持请求消息 | +| 6 | 0x1006 | √ | √ | 主链路连接保持应答消息 | +| 7 | 0x1007 | √ | √ | 主链路断开通知消息 | +| 8 | 0x1008 | √ | √ |下级平台主动关闭链路通知消息 | + +#### 从链路 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x9001 | √ | √ | 从链路连接请求消息 | +| 2 | 0x9002 | √ | √ | 从链路连接应答消息 | +| 3 | 0x9003 | √ | √ | 从链路注销请求消息 | +| 4 | 0x9004 | √ | √ | 从链路注销应答消息 | +| 5 | 0x9005 | √ | √ | 从链路连接保持请求消息 | +| 6 | 0x9006 | √ | √ | 从链路连接保持应答消息 | +| 7 | 0x9007 | √ | √ | 从链路断开通知消息 | +| 8 | 0x9008 | √ | √ | 上级平台主动关闭链路通知消息 | + +### 信息统计类 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x9101 | √ | √ |接收定位信息数量通知消息 | + +### 车辆动态信息交换 + +#### 主链路动态信息交换消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x1200 | √ | √ | 主链路动态信息交换消息 | +| 2 | 0x1201 | √ | √ | 上传车辆注册信息(809补充协议文档) | +| 3 | 0x1202 | √ | √ | 实时上传车辆定位信息 | +| 4 | 0x1203 | √ | √ | 车辆定位信息自动补报 | +| 5 | 0x1205 | √ | √ | 启动车辆定位信息交换应答消息 | +| 6 | 0x1206 | √ | √ | 结束车辆定位信息交换应答消息 | +| 7 | 0x1207 | √ | √ | 申请交换指定车辆定位信息请求消息 | +| 8 | 0x1208 | √ | √ | 取消交换指定车辆定位信息请求 | +| 9 | 0x1209 | √ | √ | 补发车辆定位信息请求 | +| 10 | 0x120A | √ | √ | 上报车辆驾驶员身份识别信息应答 | +| 11 | 0x120B | √ | √ | 上报车辆电子运单应答 | +| 12 | 0x120C | √ | √ | 主动上报驾驶员身份信息(809补充协议文档) | +| 13 | 0x120D | √ | √ | 主动上报车辆电子运单信息(809补充协议文档) | + +#### 从链路动态信息交换消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x9200 | √ | √ | 从链路动态信息交换消息 | +| 2 | 0x9202 | √ | √(0x1202) | 交换车辆定位信息消息(809补充协议文档) | +| 3 | 0x9203 | √ | √(0x1203) | 车辆定位信息交换补发消息 | +| 4 | 0x9204 | √ | √ | 交换车辆静态信息消息 | +| 5 | 0x9205 | √ | √ | 启动车辆定位信息交换请求消息 | +| 6 | 0x9206 | √ | √ | 结束车辆定位信息交换请求消息 | +| 7 | 0x9207 | √ | √ | 申请交换指定车辆定位信息应答消息 | +| 8 | 0x9208 | √ | √ | 取消申请交换指定车辆定位信息应答消息 | +| 9 | 0x9209 | √ | √ | 补发车辆定位信息应答消息 | +| 10 | 0x920A | √ | √ | 上报驾驶员身份识别信息请求消息 | +| 11 | 0x920B | √ | √ | 上报车辆电子运单请求消息 | + +### 平台间信息交互类 + +#### 主链路平台间信息交互消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x1300 | √ | √ | 主链路平台间信息交互消息 | +| 2 | 0x1301 | √ | √ | 平台查岗应答消息(809补充协议文档) | +| 3 | 0x1302 | √ | √ | 下发平台间报文应答消息(809补充协议文档) | + +#### 从链路平台间信息交互消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x9300 | √ | √ | 从链路平台间信息交互消息 | +| 2 | 0x9301 | √ | √ | 平台查岗请求(809补充协议文档) | +| 3 | 0x9302 | √ | √ | 下发平台间报文请求(809补充协议文档) | + +### 车辆报警信息交互类 + +#### 主链路报警信息交互消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x1400 | √ | √ | 主链路平台间信息交互消息 | +| 2 | 0x1401 | √ | √ | 报警督办应答消息 | +| 3 | 0x1402 | √ | √ | 上报报警信息消息 | +| 4 | 0x1403 | √ | √ | 主动上报报警处理结果信息(809补充协议文档) | + +#### 从链路报警信息交互消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x9400 | √ | √ | 主链路平台间信息交互消息 | +| 2 | 0x9401 | √ | √ | 报警督办请求 | +| 3 | 0x9402 | √ | √ | 报警预警 | +| 4 | 0x9403 | √ | √ | 实时交换报警信息 | + +### 车辆监管类 + +#### 主链路车辆监管消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x1500 | √ | √ | 主链路车辆监管消息 | +| 2 | 0x1501 | √ | √ | 车辆单向监听应答 | +| 3 | 0x1502 | √ | √ | 车辆拍照应答 | +| 4 | 0x1503 | √ | √ | 下发车辆报文应答 | +| 5 | 0x1504 | √ | √ | 上报车辆行驶记录应答(809补充协议文档) | +| 6 | 0x1505 | √ | √ | 车辆应急接入监管平台应答消息 | + +#### 从链路车辆监管消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x9500 | √ | √ | 从链路车辆监管消息 | +| 2 | 0x9501 | √ | √ | 车辆单向监听请求 | +| 3 | 0x9502 | √ | √ | 车辆拍照请求 | +| 4 | 0x9503 | √ | √ | 下发车辆报文请求 | +| 5 | 0x9504 | √ | √ | 上报车辆行驶记录请求(809补充协议文档) | +| 6 | 0x9505 | √ | √ | 车辆应急接入监管平台请求消息(809补充协议文档) | + +### 车辆静态信息交换类 + +#### 主链路静态信息交换消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x1600 | √ | √ | 主链路静态信息交换消息 | +| 2 | 0x1601 | √ | √ | 补报车辆静态信息应答 | + +#### 从链路静态信息交换消息 + +|序号|消息ID|完成情况|测试情况|消息体名称| +|:------:|:------:|:------:|:------:|:------:| +| 1 | 0x9600 | √ | √ | 从链路静态信息交换消息 | +| 2 | 0x9601 | √ | √ | 补报车辆静态信息应答 | diff --git a/doc/808809补充协议.pdf b/doc/808809补充协议.pdf new file mode 100644 index 0000000..0e7ccc5 Binary files /dev/null and b/doc/808809补充协议.pdf differ diff --git a/doc/GBT-19056.pdf b/doc/GBT-19056.pdf new file mode 100644 index 0000000..12d9b38 Binary files /dev/null and b/doc/GBT-19056.pdf differ diff --git a/doc/JT-T809.pdf b/doc/JT-T809.pdf new file mode 100644 index 0000000..5b37a4b Binary files /dev/null and b/doc/JT-T809.pdf differ diff --git a/doc/JTT415-2006.pdf b/doc/JTT415-2006.pdf new file mode 100644 index 0000000..21f49e6 Binary files /dev/null and b/doc/JTT415-2006.pdf differ diff --git a/doc/jt809协议解析.txt b/doc/jt809协议解析.txt new file mode 100644 index 0000000..7983b5e --- /dev/null +++ b/doc/jt809协议解析.txt @@ -0,0 +1,32 @@ +5B +00 00 +00 5A 02 00 00 00 85 12 00 01 33 53 D5 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 12 02 00 00 00 24 00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 32 00 34 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 00 00 43 BF +5D + +5B -- ʶͷ +00 00 00 5A -- Unit32_t ݳ +00 00 00 85 -- Unit32_t к a +12 00 -- Unit16_t ҵ +01 33 53 D5 -- Unit32_t ¼ƽ̨룬ϼƽ̨¼ƽ̨Ψһʶ +01 00 00 -- BYTES Э汾ñʶ +00 -- BYTE ļܱʶλ b: 0 ʾIJܣ1 ʾļ +00 00 27 0F -- Unit32_t ݼܵܳףΪ 4 ֽ +D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 -- 21 Octet String ƺ +01 -- 1 BYTE ɫ JT/T415-2006 5.4.12 Ĺ涨 +12 02 --2 Uint16_t ҵͱʶ +00 00 00 24 -- 4 Uint32_t ݳ +-----********************************************** ݲ********************************************----- +00 -- BYTE ֶαʶĶλϢǷʹùҲ׼ĵͼܲмܡܱʶ1-Ѽܣ0-δܡ +13 07 07 DC -- 4 BYTES ꣨dmyy) +0F 0F 0F -- 3 BYTES ʱ루hms +07 EF 4D 80 --4 Uint32_t ȣλΪ 1*10^-6 +01 70 18 40 -- 4 Uint32_t γȣλΪ 1*10^-6 +00 32 -- 2 Uint16_t ٶȣ +00 34 -- 2 Uint16_t ʻ¼ٶ +00 00 00 96 -- 4 Uint32_t ǰ +00 2D --2 Uint16_t 0-359λΪȣ +00 2D --2 Uint16_t θ߶ȣλΪףm +00 00 00 03 -- 4 Uint32_t ״̬ƱʾB31B30B29B2B1B0.嶨尴 JT/T808-2011 б 17 Ĺ涨 +00 00 00 00 --4 Uint32_t ״̬Ʊʾ0 ʶ1 ʾB31B30B29 B2B1B0. JT/T808-2011 б 18 Ĺ涨 +43 BF -- 2 Unint16_t CRC У +5D -- ʶβ \ No newline at end of file diff --git a/src/JT809.Protocol.Benchmark/JT809.Protocol.Benchmark.csproj b/src/JT809.Protocol.Benchmark/JT809.Protocol.Benchmark.csproj new file mode 100644 index 0000000..417a34d --- /dev/null +++ b/src/JT809.Protocol.Benchmark/JT809.Protocol.Benchmark.csproj @@ -0,0 +1,18 @@ + + + + Exe + netcoreapp2.2;net472; + + + + + + + + + + + + + diff --git a/src/JT809.Protocol.Benchmark/JT809SerializerContext.cs b/src/JT809.Protocol.Benchmark/JT809SerializerContext.cs new file mode 100644 index 0000000..221af1b --- /dev/null +++ b/src/JT809.Protocol.Benchmark/JT809SerializerContext.cs @@ -0,0 +1,95 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Toolchains.CsProj; +using JT809.Protocol.Enums; +using JT809.Protocol.MessageBody; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Benchmark +{ + [Config(typeof(JT809SerializerContextConfig))] + [MarkdownExporter] + [MemoryDiagnoser] + public class JT809SerializerContext + { + private byte[] bytes; + private JT809Serializer JT809Serializer; + [Params(100, 10000,100000)] + public int N; + + [GlobalSetup] + public void Setup() + { + JT809Serializer = new JT809Serializer(); + bytes = "5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D".ToHexBytes(); + } + + [Benchmark(Description = "JT809_0x9400_0x9401_Package_Deserialize")] + public void JT809_0x9400_0x9401_Package_Deserialize_Test() + { + for (int i = 0; i < N; i++) + { + var result = JT809Serializer.Deserialize(bytes); + } + } + + [Benchmark(Description = "JT809_0x9400_0x9401_Package_Serialize")] + public void JT809_0x9400_0x9401_Package_Serialize_Test() + { + for (int i = 0; i < N; i++) + { + JT809Package jT809Package = new JT809Package(); + + jT809Package.Header = new JT809Header + { + MsgSN = 1666, + EncryptKey = 9999, + EncryptFlag = JT809Header_Encrypt.None, + Version = new JT809Header_Version(1, 0, 0), + BusinessType = JT809BusinessType.从链路报警信息交互消息, + MsgGNSSCENTERID = 20180920, + }; + + JT809_0x9400 bodies = new JT809_0x9400 + { + VehicleNo = "粤A12345", + VehicleColor = JT809VehicleColorType.黄色, + SubBusinessType = JT809SubBusinessType.报警督办请求, + }; + + JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401 + { + WarnSrc = JT809WarnSrc.车载终端, + WarnType = JT809WarnType.疲劳驾驶报警, + WarnTime = DateTime.Parse("2018-09-27 10:24:00"), + SupervisionID = "123FFAA1", + SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), + SupervisionLevel = 3, + Supervisor = "smallchi", + SupervisorTel = "12345678901", + SupervisorEmail = "123456@qq.com" + }; + bodies.SubBodies = jT809_0x9400_0x9401; + jT809Package.Bodies = bodies; + var hex = JT809Serializer.Serialize(jT809Package); + } + } + + } + + public class JT809SerializerContextConfig : ManualConfig + { + public JT809SerializerContextConfig() + { + Add(Job.Default.WithGcServer(false).With(Runtime.Clr).With(Platform.AnyCpu)); + + Add(Job.Default.WithGcServer(false).With(CsProjCoreToolchain.NetCoreApp22).With(Platform.AnyCpu)); + } + } +} diff --git a/src/JT809.Protocol.Benchmark/Program.cs b/src/JT809.Protocol.Benchmark/Program.cs new file mode 100644 index 0000000..0dcb34b --- /dev/null +++ b/src/JT809.Protocol.Benchmark/Program.cs @@ -0,0 +1,20 @@ +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; + +namespace JT809.Protocol.Benchmark +{ + class Program + { + static void Main(string[] args) + { + Summary summary = BenchmarkRunner.Run(); + } + } +} diff --git a/src/JT809.Protocol.Extensions.DependencyInjection.Test/JT809.Protocol.Extensions.DependencyInjection.Test.csproj b/src/JT809.Protocol.Extensions.DependencyInjection.Test/JT809.Protocol.Extensions.DependencyInjection.Test.csproj new file mode 100644 index 0000000..fa0c50b --- /dev/null +++ b/src/JT809.Protocol.Extensions.DependencyInjection.Test/JT809.Protocol.Extensions.DependencyInjection.Test.csproj @@ -0,0 +1,27 @@ + + + + Exe + netcoreapp2.2 + 7.3 + + + + + + + + + + + + + + + + + Always + + + + diff --git a/src/JT809.Protocol.Extensions.DependencyInjection.Test/Program.cs b/src/JT809.Protocol.Extensions.DependencyInjection.Test/Program.cs new file mode 100644 index 0000000..bad2280 --- /dev/null +++ b/src/JT809.Protocol.Extensions.DependencyInjection.Test/Program.cs @@ -0,0 +1,68 @@ +using JT809.Protocol.Interfaces; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using System; +using System.Threading.Tasks; + +namespace JT809.Protocol.Extensions.DependencyInjection.Test +{ + class Program + { + static void Main(string[] args) + { + //单个 + IServiceCollection serviceDescriptors1 = new ServiceCollection(); + serviceDescriptors1.AddJT809Configure(new DefaultConfig()); + var ServiceProvider1 = serviceDescriptors1.BuildServiceProvider(); + var defaultConfig = ServiceProvider1.GetRequiredService(); + + //多个 + IServiceCollection serviceDescriptors2 = new ServiceCollection(); + serviceDescriptors2.AddJT809Configure(new Config1()); + serviceDescriptors2.AddJT809Configure(new Config2()); + serviceDescriptors2.AddSingleton(factory => + { + Func accesor = key => + { + if (key.Equals("Config1")) + { + return factory.GetService(); + } + else if (key.Equals("Config2")) + { + return factory.GetService(); + } + else + { + throw new ArgumentException($"Not Support key : {key}"); + } + }; + return accesor; + }); + + var ServiceProvider2 = serviceDescriptors2.BuildServiceProvider(); + + var config1 = ServiceProvider2.GetRequiredService>()("Config1"); + var flag21 = config1.GetSerializer().SerializerId == "Config1"; + + var config2 = ServiceProvider2.GetRequiredService>()("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"; + } +} diff --git a/src/JT809.Protocol.Extensions.DependencyInjection.Test/appsettings.json b/src/JT809.Protocol.Extensions.DependencyInjection.Test/appsettings.json new file mode 100644 index 0000000..34c6936 --- /dev/null +++ b/src/JT809.Protocol.Extensions.DependencyInjection.Test/appsettings.json @@ -0,0 +1,19 @@ +{ + "JT809Options": { + "HeaderOptions": { + "MsgGNSSCENTERID": 20181012, + "EncryptFlag": "Common", + "EncryptKey": 9999, + "Version": { + "Major": 2, + "Minor": 1, + "Build": 2 + } + }, + "EncryptOptions": { + "M1": 10000000, + "IA1": 20000000, + "IC1": 30000000 + } + } +} diff --git a/src/JT809.Protocol.Extensions.DependencyInjection/DependencyInjectionExtensions.cs b/src/JT809.Protocol.Extensions.DependencyInjection/DependencyInjectionExtensions.cs new file mode 100644 index 0000000..407f5ac --- /dev/null +++ b/src/JT809.Protocol.Extensions.DependencyInjection/DependencyInjectionExtensions.cs @@ -0,0 +1,26 @@ +using Microsoft.Extensions.DependencyInjection; +using JT809.Protocol.Interfaces; + +namespace JT809.Protocol.Extensions.DependencyInjection +{ + public static class DependencyInjectionExtensions + { + public static IServiceCollection AddJT809Configure(this IServiceCollection services, IJT809Config jT809Config) + { + services.AddSingleton(jT809Config.GetType(), jT809Config); + services.AddSingleton(jT809Config); + return services; + } + + public static IServiceCollection AddJT809Configure(this IServiceCollection services) + { + services.AddSingleton(new DefaultGlobalConfig()); + return services; + } + + class DefaultGlobalConfig : GlobalConfigBase + { + public override string ConfigId => "default"; + } + } +} diff --git a/src/JT809.Protocol.Extensions.DependencyInjection/JT809.Protocol.Extensions.DependencyInjection.csproj b/src/JT809.Protocol.Extensions.DependencyInjection/JT809.Protocol.Extensions.DependencyInjection.csproj new file mode 100644 index 0000000..1a70564 --- /dev/null +++ b/src/JT809.Protocol.Extensions.DependencyInjection/JT809.Protocol.Extensions.DependencyInjection.csproj @@ -0,0 +1,32 @@ + + + + netstandard2.0 + latest + Copyright 2018. + SmallChi + JT809.Extensions.DependencyInjection + JT809.Extensions.DependencyInjection + JT809协议依赖注入扩展包 + JT809协议依赖注入扩展包 + false + https://github.com/SmallChi/JT809 + https://github.com/SmallChi/JT809 + https://github.com/SmallChi/JT809/blob/master/LICENSE + true + 2.0.0 + + + + + + + + + + + + + + + diff --git a/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj b/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj new file mode 100644 index 0000000..ca7d236 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809.Protocol.Test.csproj @@ -0,0 +1,27 @@ + + + + netcoreapp2.2 + + false + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + diff --git a/src/JT809.Protocol.Test/JT809Encrypt/JT809EncryptTest.cs b/src/JT809.Protocol.Test/JT809Encrypt/JT809EncryptTest.cs new file mode 100644 index 0000000..8c1b87c --- /dev/null +++ b/src/JT809.Protocol.Test/JT809Encrypt/JT809EncryptTest.cs @@ -0,0 +1,45 @@ +using JT809.Protocol.Configs; +using JT809.Protocol.Encrypt; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; + +namespace JT809.Protocol.Test.JT809Encrypt +{ + public class JT809EncryptTest + { + private JT809EncryptOptions options = new JT809EncryptOptions + { + IA1 = 20000000, + IC1 = 20000000, + M1 = 30000000 + }; + + [Fact] + public void Test1() + { + byte[] bytes = new byte[] + { + 01,02,03,04,05,06,07 + }; + IJT809Encrypt jT809Encrypt = new JT809EncryptImpl(); + var data = jT809Encrypt.Encrypt(bytes, options, 256178).ToHexString(); + //"D3 4C 70 78 A7 3A 41" + } + + [Fact] + public void Test2() + { + byte[] bytes = "D3 4C 70 78 A7 3A 41".ToHexBytes(); + IJT809Encrypt jT809Encrypt = new JT809EncryptImpl(); + var data = jT809Encrypt.Decrypt(bytes, options, 256178); + Assert.Equal(new byte[] + { + 01,02,03,04,05,06,07 + }, data); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809Extensions/JT809BinaryExtensionsTest.cs b/src/JT809.Protocol.Test/JT809Extensions/JT809BinaryExtensionsTest.cs new file mode 100644 index 0000000..67efbb4 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809Extensions/JT809BinaryExtensionsTest.cs @@ -0,0 +1,47 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.JT809Extensions +{ + public class JT809BinaryExtensionsTest + { + [Fact] + public void Test2() + { + var jT808_Alarms = JT809EnumExtensions.GetEnumTypes(24, 32); + var jT808_Alarms1 = JT809EnumExtensions.GetEnumTypes(5, 32); + var jT808_Alarms2 = JT809EnumExtensions.GetEnumTypes(16, 32); + var jT808_Alarms3 = JT809EnumExtensions.GetEnumTypes(18, 32); + var jT808_Alarms4 = JT809EnumExtensions.GetEnumTypes(31, 32); + var jT808_Alarms5= JT809EnumExtensions.GetEnumTypes(8388609, 32); + } + + + [Fact] + public void Test3() + { + var jT808_Status = JT809EnumExtensions.GetEnumTypes(24, 32); + var jT808_Status1 = JT809EnumExtensions.GetEnumTypes(5, 32); + var jT808_Status2 = JT809EnumExtensions.GetEnumTypes(16, 32); + var jT808_Status3 = JT809EnumExtensions.GetEnumTypes(18, 32); + var jT808_Status4 = JT809EnumExtensions.GetEnumTypes(31, 32); + var jT808_Status5 = JT809EnumExtensions.GetEnumTypes(8388609, 32); + } + + [Fact] + public void Test4() + { + var jT808_Status5 = JT809EnumExtensions.GetEnumTypes(8388609, 32); + } + + [Fact] + public void Test5() + { + var jT808_Status5 = JT809EnumExtensions.GetEnumTypes(8388609, 32,false); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809Extensions/JT809SubPackageExtensionsTest.cs b/src/JT809.Protocol.Test/JT809Extensions/JT809SubPackageExtensionsTest.cs new file mode 100644 index 0000000..7362153 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809Extensions/JT809SubPackageExtensionsTest.cs @@ -0,0 +1,91 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.SubMessageBody; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.JT809Extensions +{ + public class JT809SubPackageExtensionsTest + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + var types = Enum.GetNames(typeof(JT809SubBusinessType)); + foreach (var item in types) + { + JT809SubBusinessType jT809SubBusinessType = item.ToEnum(); + JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809SubBusinessType.GetAttribute(); + JT809SubBusinessTypeDescriptionAttribute jT809SubBusinessTypeDescriptionAttribute = jT809SubBusinessType.GetAttribute(); + if (jT809SubBusinessType == JT809SubBusinessType.None) + { + Assert.Null(jT809SubBodiesTypeAttribute); + Assert.Null(jT809SubBusinessTypeDescriptionAttribute); + continue; + } + Assert.NotNull(jT809SubBusinessTypeDescriptionAttribute.Code); + Assert.NotNull(jT809SubBusinessTypeDescriptionAttribute.Name); + } + } + + [Fact] + public void Create_0x1001_Test() + { + JT809Package jT809Package= JT809BusinessType.主链路登录请求消息.Create_主链路登录请求消息(new JT809Header + { + MsgSN = 133, + EncryptKey = 9999, + MsgGNSSCENTERID = 20180920, + }, new MessageBody.JT809_0x1001 + { + UserId = 20180920, + Password = "20180920", + DownLinkIP = "127.0.0.1", + DownLinkPort = 809 + }); + var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); + Assert.Equal("5B000000480000008510010133EFB8010000000000270F0133EFB832303138303932303132372E302E302E31000000000000000000000000000000000000000000000003296A915D", hex); + } + + [Fact] + public void Create_JT809_0x9400_0x9401_Test() + { + JT809Package jT809Package = JT809BusinessType.从链路报警信息交互消息.Create_从链路报警信息交互消息( + new JT809Header + { + MsgSN = 1666, + EncryptKey = 9999, + EncryptFlag = JT809Header_Encrypt.None, + Version = new JT809Header_Version(1, 0, 0), + MsgGNSSCENTERID = 20180920, + }, new JT809_0x9400 + { + VehicleNo = "粤A12345", + VehicleColor = JT809VehicleColorType.黄色, + SubBusinessType = JT809SubBusinessType.报警督办请求, + SubBodies = JT809SubBusinessType.报警督办请求.Create_报警督办请求( + new JT809_0x9400_0x9401 + { + WarnSrc = JT809WarnSrc.车载终端, + WarnType = JT809WarnType.疲劳驾驶报警, + WarnTime = DateTime.Parse("2018-09-27 10:24:00"), + SupervisionID = "123FFAA1", + SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), + SupervisionLevel = 3, + Supervisor = "smallchi", + SupervisorTel = "12345678901", + SupervisorEmail = "123456@qq.com" + }) + } + ); + var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); + Assert.Equal("5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D", hex); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809HeaderTest.cs b/src/JT809.Protocol.Test/JT809HeaderTest.cs new file mode 100644 index 0000000..fb9aef1 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809HeaderTest.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using System.Threading.Tasks; +using System.Diagnostics; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test +{ + public class JT809HeaderTest + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809Header jT809Header = new JT809Header(); + jT809Header.MsgLength = 24; + jT809Header.MsgSN = 1024; + jT809Header.BusinessType = JT809BusinessType.从链路静态信息交换消息; + jT809Header.MsgGNSSCENTERID = 1200; + jT809Header.Version = new JT809Header_Version(); + jT809Header.EncryptFlag = JT809Header_Encrypt.None; + jT809Header.EncryptKey = 0; + var hex = JT809Serializer.Serialize(jT809Header).ToHexString(); + Assert.Equal("00000018000004009600000004B00100000000000000", hex); + //"00 00 00 18 00 00 04 00 96 00 00 00 04 B0 01 00 00 00 00 00 00 00" + } + + [Fact] + public void Test2() + { + var bytes = "00 00 00 18 00 00 04 00 96 00 00 00 04 B0 01 00 00 00 00 00 00 00".ToHexBytes(); + JT809Header jT809Header= JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)24, jT809Header.MsgLength); + Assert.Equal((uint)1024, jT809Header.MsgSN); + Assert.Equal(JT809BusinessType.从链路静态信息交换消息, jT809Header.BusinessType); + Assert.Equal((uint)1200, jT809Header.MsgGNSSCENTERID); + Assert.Equal(new JT809Header_Version().ToString(), jT809Header.Version.ToString()); + Assert.Equal(JT809Header_Encrypt.None, jT809Header.EncryptFlag); + Assert.Equal((uint)0, jT809Header.EncryptKey); + } + + [Fact] + public void Test4() + { + JT809Header jT809Header = new JT809Header(); + jT809Header.MsgLength = 24; + jT809Header.MsgSN = 1024; + jT809Header.BusinessType = JT809BusinessType.从链路静态信息交换消息; + jT809Header.MsgGNSSCENTERID = 1200; + jT809Header.Version = new JT809Header_Version (0xFF,0xAA,0xBB); + jT809Header.EncryptFlag = JT809Header_Encrypt.None; + jT809Header.EncryptKey = 0; + var hex = JT809Serializer.Serialize(jT809Header).ToHexString(); + Assert.Equal("00000018000004009600000004B0FFAABB0000000000", hex); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs new file mode 100644 index 0000000..6b2f499 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1001Test.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1001Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1001 jT809_0X1001 = new JT809_0x1001(); + jT809_0X1001.UserId = 20180920; + jT809_0X1001.Password = "20180920"; + jT809_0X1001.DownLinkIP = "127.0.0.1"; + jT809_0X1001.DownLinkPort = 809; + var hex = JT809Serializer.Serialize(jT809_0X1001).ToHexString(); + Assert.Equal("0133EFB832303138303932303132372E302E302E3100000000000000000000000000000000000000000000000329", hex); + //5B + //00 00 00 48 + //00 00 00 85 + //10 01 + //01 33 53 D5 + //01 00 00 + //00 + //00 00 27 0F + + //01 33 EF B8 + //32 30 31 38 30 39 32 30 + //31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + //03 29 + //C3 0D + //5D + + //"01 33 EF B8 + //32 30 31 38 30 39 32 30 + //31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + //03 29" + } + + [Fact] + public void Test2() + { + var bytes = "01 33 EF B8 32 30 31 38 30 39 32 30 31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 29".ToHexBytes(); + JT809_0x1001 jT809_0X1001 = JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)20180920, jT809_0X1001.UserId); + Assert.Equal("20180920", jT809_0X1001.Password); + Assert.Equal("127.0.0.1", jT809_0X1001.DownLinkIP); + Assert.Equal((ushort)809,jT809_0X1001.DownLinkPort); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs new file mode 100644 index 0000000..989bc5c --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1002Test.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1002Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1002 jT809_0X1002 = new JT809_0x1002(); + jT809_0X1002.Result = JT809_0x1002_Result.成功; + jT809_0X1002.VerifyCode = 54456; + var hex = JT809Serializer.Serialize(jT809_0X1002).ToHexString(); + //"00 00 00 D4 B8" + Assert.Equal("000000D4B8", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 00 D4 B8".ToHexBytes(); + JT809_0x1002 jT809_0X1002 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1002_Result.成功, jT809_0X1002.Result); + Assert.Equal((uint)54456, jT809_0X1002.VerifyCode); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1003Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1003Test.cs new file mode 100644 index 0000000..1c371c5 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1003Test.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1003Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1003 jT809_0X1003 = new JT809_0x1003(); + jT809_0X1003.UserId = 20180920; + jT809_0X1003.Password = "20180920"; + var hex = JT809Serializer.Serialize(jT809_0X1003).ToHexString(); + //"01 33 EF B8 32 30 31 38 30 39 32 30" + Assert.Equal("0133EFB83230313830393230", hex); + } + + [Fact] + public void Test2() + { + var bytes = "01 33 EF B8 32 30 31 38 30 39 32 30".ToHexBytes(); + JT809_0x1003 jT809_0X1003 = JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)20180920, jT809_0X1003.UserId); + Assert.Equal("20180920", jT809_0X1003.Password); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1005Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1005Test.cs new file mode 100644 index 0000000..8e6e587 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1005Test.cs @@ -0,0 +1,20 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1005Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809Package heartbeatPackage = JT809BusinessType.主链路连接保持请求消息.Create(); + byte[] sendHeartbeatData = JT809Serializer.Serialize(heartbeatPackage, 100); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1006Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1006Test.cs new file mode 100644 index 0000000..52a6511 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1006Test.cs @@ -0,0 +1,26 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1006Test + { + [Fact] + public void Test1() + { + + } + + [Fact] + public void Test2() + { + + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1007Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1007Test.cs new file mode 100644 index 0000000..af71860 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1007Test.cs @@ -0,0 +1,33 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1007Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1007 jT809_0X1007 = new JT809_0x1007(); + jT809_0X1007.ErrorCode = JT809_0x1007_ErrorCode.主链路断开; + var hex = JT809Serializer.Serialize(jT809_0X1007).ToHexString(); + Assert.Equal("00", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00".ToHexBytes(); + JT809_0x1007 jT809_0X1007 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1007_ErrorCode.主链路断开, jT809_0X1007.ErrorCode); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1008Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1008Test.cs new file mode 100644 index 0000000..8a769a5 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1008Test.cs @@ -0,0 +1,33 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1008Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1008 jT809_0X1008 = new JT809_0x1008(); + jT809_0X1008.ReasonCode = JT809_0x1008_ReasonCode.网关重启; + var hex = JT809Serializer.Serialize(jT809_0X1008).ToHexString(); + Assert.Equal("00", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00".ToHexBytes(); + JT809_0x1008 jT809_0X1008 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1008_ReasonCode.网关重启, jT809_0X1008.ReasonCode); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs new file mode 100644 index 0000000..3a47bea --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1200Test.cs @@ -0,0 +1,66 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1200Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200 jT809_0X1200 = new JT809_0x1200(); + jT809_0X1200.VehicleNo= "粤A12345"; + jT809_0X1200.VehicleColor = JT809VehicleColorType.蓝色; + jT809_0X1200.SubBusinessType = JT809SubBusinessType.上传车辆注册信息; + jT809_0X1200.DataLength = 61; + JT809_0x1200_0x1201 jT809_0X1200_0X1201 = new JT809_0x1200_0x1201 + { + PlateformId = "1111111111", + ProducerId = "1111111111", + TerminalId = "11111AA", + TerminalModelType = "11111111", + TerminalSimCode = "222222222222" + }; + jT809_0X1200.SubBodies = jT809_0X1200_0X1201; + var hex = JT809Serializer.Serialize(jT809_0X1200).ToHexString(); + //D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 + //00 + //01 + //12 01 + //00 00 00 3D + //00 00 00 00 00 00 00 42 3A 35 C7 + //00 00 00 00 00 00 00 42 3A 35 C7 31 31 31 31 31 31 31 31 + //00 00 00 00 00 00 00 00 00 00 00 00 31 31 31 31 31 41 41 32 32 32 32 32 32 32 32 32 32 32 32 + //D4C1413132333435000000000000000000000000000112010000003D00000000000000423A35C700000000000000423A35C7313131313131313100000000000000000000000031313131314141323232323232323232323232 + Assert.Equal("D4C1413132333435000000000000000000000000000112010000003D00000000000000423A35C700000000000000423A35C7313131313131313100000000000000000000000031313131314141323232323232323232323232", hex); + //"D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 12 01 00 00 00 3D 00 00 00 00 00 00 00 42 3A 35 C7 00 00 00 00 00 00 00 42 3A 35 C7 31 31 31 31 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 31 31 31 31 31 41 41 32 32 32 32 32 32 32 32 32 32 32 32" + //"D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 12 01 00 00 00 3D 00 00 00 00 00 00 00 42 3A 35 C7 00 00 00 00 00 00 00 42 3A 35 C7 31 31 31 31 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 31 31 31 31 31 61 61 32 32 32 32 32 32 32 32 32 32 32 32" + } + + [Fact] + public void Test2() + { + var bytes = "D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 12 01 00 00 00 3D 00 00 00 00 00 00 00 42 3A 35 C7 00 00 00 00 00 00 00 42 3A 35 C7 31 31 31 31 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 31 31 31 31 31 41 41 32 32 32 32 32 32 32 32 32 32 32 32".ToHexBytes(); + JT809_0x1200 jT809_0X9001 = JT809Serializer.Deserialize(bytes); + Assert.Equal("粤A12345", jT809_0X9001.VehicleNo); + Assert.Equal(JT809VehicleColorType.蓝色, jT809_0X9001.VehicleColor); + Assert.Equal(JT809SubBusinessType.上传车辆注册信息, jT809_0X9001.SubBusinessType); + Assert.Equal((ushort)61, jT809_0X9001.DataLength); + JT809_0x1200_0x1201 jT809_0X1200_0X1201 = jT809_0X9001.SubBodies as JT809_0x1200_0x1201; + Assert.Equal("1111111111", jT809_0X1200_0X1201.PlateformId); + Assert.Equal("1111111111", jT809_0X1200_0X1201.ProducerId); + Assert.Equal("11111AA", jT809_0X1200_0X1201.TerminalId); + Assert.Equal("11111111", jT809_0X1200_0X1201.TerminalModelType); + Assert.Equal("222222222222", jT809_0X1200_0X1201.TerminalSimCode); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs new file mode 100644 index 0000000..4af98eb --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1300Test.cs @@ -0,0 +1,47 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1300Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1300 jT809Bodies = new JT809_0x1300(); + jT809Bodies.SubBusinessType = JT809SubBusinessType.平台查岗应答; + jT809Bodies.SubBodies = new JT809_0x1300_0x1301 + { + ObjectID="111", + InfoContent= "22ha22", + InfoID= 1234, + ObjectType= JT809_0x1301_ObjectType.当前连接的下级平台 + }; + var hex = JT809Serializer.Serialize(jT809Bodies).ToHexString(); + //"13 01 00 00 00 1B 01 31 31 31 00 00 00 00 00 00 00 00 00 00 00 04 D2 00 00 00 06 32 32 68 61 32 32" + Assert.Equal("13010000001B01313131000000000000000000000004D200000006323268613232", hex); + } + + [Fact] + public void Test2() + { + var bytes = "13 01 00 00 00 1B 01 31 31 31 00 00 00 00 00 00 00 00 00 00 00 04 D2 00 00 00 06 32 32 68 61 32 32".ToHexBytes(); + JT809_0x1300 jT809Bodies = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809SubBusinessType.平台查岗应答, jT809Bodies.SubBusinessType); + JT809_0x1300_0x1301 jT809SubBodies = (JT809_0x1300_0x1301)jT809Bodies.SubBodies; + Assert.Equal("111", jT809SubBodies.ObjectID); + Assert.Equal("22ha22", jT809SubBodies.InfoContent); + Assert.Equal((uint)1234, jT809SubBodies.InfoID); + Assert.Equal(JT809_0x1301_ObjectType.当前连接的下级平台, jT809SubBodies.ObjectType); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs new file mode 100644 index 0000000..589fb41 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x1600Test.cs @@ -0,0 +1,44 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x1600Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1600 jT809Bodies = new JT809_0x1600(); + jT809Bodies.VehicleNo = "粤A12345"; + jT809Bodies.VehicleColor = JT809VehicleColorType.蓝色; + jT809Bodies.SubBusinessType = JT809SubBusinessType.补报车辆静态信息应答; + jT809Bodies.SubBodies = new JT809_0x1600_0x1601 + { + CarInfo = "什么鬼" + }; + var hex = JT809Serializer.Serialize(jT809Bodies).ToHexString(); + //"D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 16 01 00 00 00 06 CA B2 C3 B4 B9 ED" + Assert.Equal("D4C14131323334350000000000000000000000000001160100000006CAB2C3B4B9ED",hex); + } + + [Fact] + public void Test2() + { + var bytes = "D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 01 16 01 00 00 00 06 CA B2 C3 B4 B9 ED".ToHexBytes(); + JT809_0x1600 jT809Bodies = JT809Serializer.Deserialize(bytes); + Assert.Equal("粤A12345", jT809Bodies.VehicleNo); + Assert.Equal(JT809VehicleColorType.蓝色, jT809Bodies.VehicleColor); + Assert.Equal(JT809SubBusinessType.补报车辆静态信息应答, jT809Bodies.SubBusinessType); + Assert.Equal("什么鬼", ((JT809_0x1600_0x1601)jT809Bodies.SubBodies).CarInfo); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs new file mode 100644 index 0000000..ba5d819 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9001Test.cs @@ -0,0 +1,32 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x9001Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9001 jT809_0X9001 = new JT809_0x9001(); + jT809_0X9001.VerifyCode = 45454; + var hex = JT809Serializer.Serialize(jT809_0X9001).ToHexString(); + Assert.Equal("0000B18E", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 B1 8E".ToHexBytes(); + JT809_0x9001 jT809_0X9001 = JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)45454, jT809_0X9001.VerifyCode); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9002Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9002Test.cs new file mode 100644 index 0000000..4868a61 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9002Test.cs @@ -0,0 +1,33 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x9002Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9002 jT809_0X9002 = new JT809_0x9002(); + jT809_0X9002.Result = JT809_0x9002_Result.成功; + var hex = JT809Serializer.Serialize(jT809_0X9002).ToHexString(); + Assert.Equal("00", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00".ToHexBytes(); + JT809_0x9002 jT809_0X9002 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9002_Result.成功, jT809_0X9002.Result); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9003Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9003Test.cs new file mode 100644 index 0000000..ef3f476 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9003Test.cs @@ -0,0 +1,32 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x9003Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9003 jT809_0X9003 = new JT809_0x9003(); + jT809_0X9003.VerifyCode = 45454; + var hex = JT809Serializer.Serialize(jT809_0X9003).ToHexString(); + Assert.Equal("0000B18E",hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 B1 8E".ToHexBytes(); + JT809_0x9003 jT809_0X9003 = JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)45454, jT809_0X9003.VerifyCode); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs new file mode 100644 index 0000000..7b6f039 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9007Test.cs @@ -0,0 +1,33 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x9007Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9007 jT809_0X9007 = new JT809_0x9007(); + jT809_0X9007.ReasonCode = JT809_0x9007_ReasonCode.无法连接下级平台指定的服务IP与端口; + var hex = JT809Serializer.Serialize(jT809_0X9007).ToHexString(); + Assert.Equal("00", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00".ToHexBytes(); + JT809_0x9007 jT809_0X9007 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9007_ReasonCode.无法连接下级平台指定的服务IP与端口, jT809_0X9007.ReasonCode); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9008Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9008Test.cs new file mode 100644 index 0000000..32ac3f2 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9008Test.cs @@ -0,0 +1,33 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x9008Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9008 jT809_0X9008 = new JT809_0x9008(); + jT809_0X9008.ReasonCode = JT809_0x9008_ReasonCode.其它原因; + var hex = JT809Serializer.Serialize(jT809_0X9008).ToHexString(); + Assert.Equal("01", hex); + } + + [Fact] + public void Test2() + { + var bytes = "01".ToHexBytes(); + JT809_0x9008 jT809_0X9008 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9008_ReasonCode.其它原因, jT809_0X9008.ReasonCode); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9101Test.cs b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9101Test.cs new file mode 100644 index 0000000..4ce9dde --- /dev/null +++ b/src/JT809.Protocol.Test/JT809MessageBody/JT809_0x9101Test.cs @@ -0,0 +1,36 @@ +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.JT809MessageBody +{ + public class JT809_0x9101Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9101 jT809_0X9101 = new JT809_0x9101(); + jT809_0X9101.DynamicInfoTotal = 10000; + jT809_0X9101.StartTime = 1537513862; + jT809_0X9101.EndTime = 1537531862; + var hex = JT809Serializer.Serialize(jT809_0X9101).ToHexString(); + Assert.Equal("00002710000000005BA49986000000005BA4DFD6",hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 27 10 00 00 00 00 5B A4 99 86 00 00 00 00 5B A4 DF D6".ToHexBytes(); + JT809_0x9101 jT809_0X9101 = JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)10000, jT809_0X9101.DynamicInfoTotal); + Assert.Equal((ulong)1537513862, jT809_0X9101.StartTime); + Assert.Equal((ulong)1537531862, jT809_0X9101.EndTime); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809Packages/JT809HeaderPackageTest.cs b/src/JT809.Protocol.Test/JT809Packages/JT809HeaderPackageTest.cs new file mode 100644 index 0000000..cf4012e --- /dev/null +++ b/src/JT809.Protocol.Test/JT809Packages/JT809HeaderPackageTest.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809Packages +{ + public class JT809HeaderPackageTest + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + var bytes = "5B 00 00 00 48 00 00 00 85 10 01 01 33 EF B8 01 00 00 00 00 00 27 0F 01 33 EF B8 32 30 31 38 30 39 32 30 31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 29 6A 91 5D".ToHexBytes(); + JT809HeaderPackage jT809HeaderPackage = JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)72, jT809HeaderPackage.Header.MsgLength); + Assert.Equal((uint)133, jT809HeaderPackage.Header.MsgSN); + Assert.Equal((uint)9999, jT809HeaderPackage.Header.EncryptKey); + Assert.Equal((uint)20180920, jT809HeaderPackage.Header.MsgGNSSCENTERID); + Assert.Equal(JT809BusinessType.主链路登录请求消息, jT809HeaderPackage.Header.BusinessType); + Assert.Equal(new JT809Header_Version().ToString(), jT809HeaderPackage.Header.Version.ToString()); + JT809_0x1001 jT809_0X1001 = JT809Serializer.Deserialize(jT809HeaderPackage.Bodies); + Assert.Equal((uint)20180920, jT809_0X1001.UserId); + Assert.Equal("20180920", jT809_0X1001.Password); + Assert.Equal("127.0.0.1", jT809_0X1001.DownLinkIP); + Assert.Equal((ushort)809, jT809_0X1001.DownLinkPort); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs new file mode 100644 index 0000000..a85e233 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001EncryptPackageTest.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Encrypt; +using JT809.Protocol.Enums; +using JT809.Protocol.Configs; +using JT809.Protocol.Internal; +using JT809.Protocol.Interfaces; + +namespace JT809.Protocol.Test.JT809Packages +{ + public class JT809_0x1001EncryptPackageTest + { + class JT809GlobalConfig: GlobalConfigBase + { + public override JT809EncryptOptions EncryptOptions { get; set; }= new JT809EncryptOptions() + { + IA1 = 20000000, + IC1 = 20000000, + M1 = 30000000 + }; + public override string ConfigId => "JT809GlobalConfig"; + } + private JT809Serializer JT809Serializer; + public JT809_0x1001EncryptPackageTest() + { + JT809Serializer = new JT809Serializer(new JT809GlobalConfig()); + } + + [Fact] + public void Test1() + { + JT809Package jT809Package = new JT809Package(); + jT809Package.Header = new JT809Header + { + EncryptFlag = JT809Header_Encrypt.Common, + MsgSN = 133, + EncryptKey = 256178, + BusinessType = JT809BusinessType.主链路登录请求消息, + MsgGNSSCENTERID = 20180920, + }; + JT809_0x1001 jT809_0X1001 = new JT809_0x1001(); + jT809_0X1001.UserId = 20180920; + jT809_0X1001.Password = "20180920"; + jT809_0X1001.DownLinkIP = "127.0.0.1"; + jT809_0X1001.DownLinkPort = 809; + jT809Package.Bodies = jT809_0X1001; + var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); + //"5B 00 00 00 48 00 00 00 85 10 01 01 33 EF B8 01 00 00 01 00 00 16 BB D3 7D 9C C4 90 0C 77 DC 78 F8 67 65 27 D8 AE 12 24 3C FB 64 CC 2F BA 61 9A EF AD 33 AC CB 32 56 F6 7B FF 19 DF 33 09 78 41 09 86 65 70 3F 2E B5 5D" + //5B000000480000008510010133EFB8010000010003E8B2 0133EFB832303138303932303132372E302E302E3100000000000000000000000000000000000000000000000329 03C5 5D + //5B000000480000008510010133EFB8010000010003E8B2 D37D9CC4900C77DC78F8676527D8AE12243CFB64CC2FBA619AEFAD33ACCB3256F67BFF19DF33097841098665703F E36E 5D + Assert.Equal("5B000000480000008510010133EFB8010000010003E8B2D37D9CC4900C77DC78F8676527D8AE12243CFB64CC2FBA619AEFAD33ACCB3256F67BFF19DF33097841098665703FE36E5D", hex); + } + + [Fact] + public void Test2() + { + var bytes = "5B000000480000008510010133EFB8010000010003E8B2D37D9CC4900C77DC78F8676527D8AE12243CFB64CC2FBA619AEFAD33ACCB3256F67BFF19DF33097841098665703FE36E5D".ToHexBytes(); + JT809Package jT809Package = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809Header_Encrypt.Common, jT809Package.Header.EncryptFlag); + Assert.Equal((uint)256178, jT809Package.Header.EncryptKey); + Assert.Equal((uint)72, jT809Package.Header.MsgLength); + Assert.Equal((uint)133, jT809Package.Header.MsgSN); + Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); + Assert.Equal(JT809BusinessType.主链路登录请求消息, jT809Package.Header.BusinessType); + Assert.Equal("1.0.0", jT809Package.Header.Version.ToString()); + JT809_0x1001 jT809_0X1001 = (JT809_0x1001)jT809Package.Bodies; + Assert.Equal((uint)20180920, jT809_0X1001.UserId); + Assert.Equal("20180920", jT809_0X1001.Password); + Assert.Equal("127.0.0.1", jT809_0X1001.DownLinkIP); + Assert.Equal((ushort)809, jT809_0X1001.DownLinkPort); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001PackageTest.cs b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001PackageTest.cs new file mode 100644 index 0000000..cbf9e7f --- /dev/null +++ b/src/JT809.Protocol.Test/JT809Packages/JT809_0x1001PackageTest.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809Packages +{ + public class JT809_0x1001PackageTest + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809Package jT809Package = new JT809Package(); + jT809Package.Header = new JT809Header + { + MsgSN= 133, + EncryptKey=9999, + BusinessType= JT809BusinessType.主链路登录请求消息, + MsgGNSSCENTERID= 20180920, + }; + JT809_0x1001 jT809_0X1001 = new JT809_0x1001(); + jT809_0X1001.UserId = 20180920; + jT809_0X1001.Password = "20180920"; + jT809_0X1001.DownLinkIP = "127.0.0.1"; + jT809_0X1001.DownLinkPort = 809; + jT809Package.Bodies = jT809_0X1001; + var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); + //5B000000 4800000085 10010133EFB801 000000000027 0F0133EFB8 323031383 039323031 32372 E302E302E31 00000000000000000000000000000000000000000000000329 4055 5D + //5B000000 4800000085 10010133EFB801 000000000027 0F0133EFB8 323031383 039323031 32372 E302E302E31 00000000000000000000000000000000000000000000000329 6A91 5D + Assert.Equal("5B000000480000008510010133EFB8010000000000270F0133EFB832303138303932303132372E302E302E31000000000000000000000000000000000000000000000003296A915D", hex); + //"5B + //00 00 00 48 + //00 00 00 85 + //10 01 + //01 33 EF B8 + //01 00 00 + //00 + //00 00 27 0F + //01 33 EF B8 + //32 30 31 38 30 39 32 30 + //31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + //03 29 + //6A 91 + //5D" + } + + [Fact] + public void Test2() + { + var bytes = "5B 00 00 00 48 00 00 00 85 10 01 01 33 EF B8 01 00 00 00 00 00 27 0F 01 33 EF B8 32 30 31 38 30 39 32 30 31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 29 6A 91 5D".ToHexBytes(); + JT809Package jT809Package = JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)72, jT809Package.Header.MsgLength); + Assert.Equal((uint)133, jT809Package.Header.MsgSN); + Assert.Equal((uint)9999, jT809Package.Header.EncryptKey); + Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); + Assert.Equal(JT809BusinessType.主链路登录请求消息, jT809Package.Header.BusinessType); + Assert.Equal(new JT809Header_Version().ToString(), jT809Package.Header.Version.ToString()); + JT809_0x1001 jT809_0X1001 = (JT809_0x1001)jT809Package.Bodies; + Assert.Equal((uint)20180920, jT809_0X1001.UserId); + Assert.Equal("20180920", jT809_0X1001.Password); + Assert.Equal("127.0.0.1", jT809_0X1001.DownLinkIP); + Assert.Equal((ushort)809, jT809_0X1001.DownLinkPort); + } + + [Fact] + public void Test3() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + //字符'0':char c = '0'; 它的ASCII码实际上是48。 + //字符'\0' : ASCII码为0,表示一个字符串结束的标志。 + //"5B 00 00 00 48 00 00 00 85 10 01 01 33 EF B8 01 00 00 00 00 00 27 0F 30 01 33 EF B8 32 30 31 38 30 39 32 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 31 32 37 2E 30 2E 30 2E 31 03 29 7D 38 5D" + var data="32 30 31 38 30 39 32 30".ToHexBytes(); + var str = Encoding.GetEncoding("GBK").GetString(data); + var data1 = "31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00".ToHexBytes(); + var str1 = Encoding.GetEncoding("GBK").GetString(data1); + var test1 = Encoding.GetEncoding("GBK").GetBytes("\0\0\0\0\0\0127.0.0.1"); + var test2 = Encoding.GetEncoding("GBK").GetBytes("127.0.0.1\0\0\0\0\0\0"); + var test3 = Encoding.GetEncoding("GBK").GetBytes("000000127.0.0.1"); + var test4 = Encoding.GetEncoding("GBK").GetBytes("127.0.0.1000000"); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809Packages/JT809_0x9400_0x9401PackageTest.cs b/src/JT809.Protocol.Test/JT809Packages/JT809_0x9400_0x9401PackageTest.cs new file mode 100644 index 0000000..d1dbc62 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809Packages/JT809_0x9400_0x9401PackageTest.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; +using JT809.Protocol.Configs; + +namespace JT809.Protocol.Test.JT809Packages +{ + public class JT809_0x9400_0x9401PackageTest + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + + [Fact] + public void Test1() + { + JT809Package jT809Package = new JT809Package(); + + jT809Package.Header = new JT809Header + { + MsgSN = 1666, + EncryptKey = 9999, + EncryptFlag= JT809Header_Encrypt.None, + Version = new JT809Header_Version(1, 0, 0), + BusinessType = JT809BusinessType.从链路报警信息交互消息, + MsgGNSSCENTERID = 20180920, + }; + + JT809_0x9400 bodies = new JT809_0x9400 + { + VehicleNo="粤A12345", + VehicleColor= JT809VehicleColorType.黄色, + SubBusinessType= JT809SubBusinessType.报警督办请求, + }; + + JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401 + { + WarnSrc = JT809WarnSrc.车载终端, + WarnType = JT809WarnType.疲劳驾驶报警, + WarnTime = DateTime.Parse("2018-09-27 10:24:00"), + SupervisionID = "123FFAA1", + SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), + SupervisionLevel = 3, + Supervisor = "smallchi", + SupervisorTel = "12345678901", + SupervisorEmail = "123456@qq.com" + }; + bodies.SubBodies = jT809_0x9400_0x9401; + jT809Package.Bodies = bodies; + var hex = JT809Serializer.Serialize(jT809Package).ToHexString(); + //"5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D" + //5B000000900000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000C69C5D + //5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D + Assert.Equal("5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D", hex); + } + + [Fact] + public void Test2() + { + var bytes = "5B 00 00 00 92 00 00 06 82 94 00 01 33 EF B8 01 00 00 00 00 00 27 0F D4 C1 41 31 32 33 34 35 00 00 00 00 00 00 00 00 00 00 00 00 00 02 94 01 00 00 00 5C 01 00 02 00 00 00 00 5A 01 AC 3F 40 12 3F FA A1 00 00 00 00 5A 01 AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BA D8 5D".ToHexBytes(); + JT809Package jT809Package = JT809Serializer.Deserialize(bytes); + + Assert.Equal((uint)146, jT809Package.Header.MsgLength); + Assert.Equal((uint)1666, jT809Package.Header.MsgSN); + Assert.Equal((uint)9999, jT809Package.Header.EncryptKey); + Assert.Equal(JT809Header_Encrypt.None, jT809Package.Header.EncryptFlag); + Assert.Equal((uint)20180920, jT809Package.Header.MsgGNSSCENTERID); + Assert.Equal(JT809BusinessType.从链路报警信息交互消息, jT809Package.Header.BusinessType); + Assert.Equal(new JT809Header_Version().ToString(), jT809Package.Header.Version.ToString()); + + JT809_0x9400 jT809_0X400 = (JT809_0x9400)jT809Package.Bodies; + Assert.Equal("粤A12345", jT809_0X400.VehicleNo); + Assert.Equal(JT809VehicleColorType.黄色, jT809_0X400.VehicleColor); + Assert.Equal(JT809SubBusinessType.报警督办请求, jT809_0X400.SubBusinessType); + Assert.Equal((uint)92, jT809_0X400.DataLength); + + JT809_0x9400_0x9401 jT809_0x9400_0x9401 = (JT809_0x9400_0x9401)jT809_0X400.SubBodies; + Assert.Equal(JT809WarnSrc.车载终端, jT809_0x9400_0x9401.WarnSrc); + Assert.Equal(JT809WarnType.疲劳驾驶报警, jT809_0x9400_0x9401.WarnType); + Assert.Equal(DateTime.Parse("2018-09-27 10:24:00"), jT809_0x9400_0x9401.WarnTime); + Assert.Equal("123FFAA1", jT809_0x9400_0x9401.SupervisionID); + Assert.Equal(DateTime.Parse("2018-09-27 11:24:00"), jT809_0x9400_0x9401.SupervisionEndTime); + Assert.Equal(3, jT809_0x9400_0x9401.SupervisionLevel); + Assert.Equal("smallchi", jT809_0x9400_0x9401.Supervisor); + Assert.Equal("12345678901", jT809_0x9400_0x9401.SupervisorTel); + Assert.Equal("123456@qq.com", jT809_0x9400_0x9401.SupervisorEmail); + } + + [Fact] + public void Test3() + { + JT809Serializer JT809SerializerTest3 = new JT809Serializer(); + JT809Package jT809Package = JT809BusinessType.从链路报警信息交互消息.Create(new JT809_0x9400 + { + VehicleNo = "粤A12345", + VehicleColor = JT809VehicleColorType.黄色, + SubBusinessType = JT809SubBusinessType.报警督办请求, + SubBodies = new JT809_0x9400_0x9401 + { + WarnSrc = JT809WarnSrc.车载终端, + WarnType = JT809WarnType.疲劳驾驶报警, + WarnTime = DateTime.Parse("2018-09-27 10:24:00"), + SupervisionID = "123FFAA1", + SupervisionEndTime = DateTime.Parse("2018-09-27 11:24:00"), + SupervisionLevel = 3, + Supervisor = "smallchi", + SupervisorTel = "12345678901", + SupervisorEmail = "123456@qq.com" + } + }); + jT809Package.Header.MsgSN = 1666; + jT809Package.Header.EncryptKey = 9999; + jT809Package.Header.MsgGNSSCENTERID = 20180920; + var hex = JT809SerializerTest3.Serialize(jT809Package).ToHexString(); + //"5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D" + Assert.Equal("5B000000920000068294000133EFB8010000000000270FD4C1413132333435000000000000000000000000000294010000005C010002000000005A01AC3F40123FFAA1000000005A01AC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000BAD85D", hex); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs new file mode 100644 index 0000000..2d51c4c --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1201Test.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1200_0x1201Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200_0x1201 jT809_0X1200_0X1201 = new JT809_0x1200_0x1201 + { + PlateformId= "1111111111", + ProducerId= "1111111111", + TerminalId= "11111AA", + TerminalModelType= "11111111", + TerminalSimCode= "222222222222" + }; + var hex = JT809Serializer.Serialize(jT809_0X1200_0X1201).ToHexString(); + //"00 00 00 00 00 00 00 42 3A 35 C7 00 00 00 00 00 00 00 42 3A 35 C7 31 31 31 31 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 31 31 31 31 31 41 41 32 32 32 32 32 32 32 32 32 32 32 32" + Assert.Equal("00000000000000423A35C700000000000000423A35C7313131313131313100000000000000000000000031313131314141323232323232323232323232",hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 00 00 00 00 00 42 3A 35 C7 00 00 00 00 00 00 00 42 3A 35 C7 31 31 31 31 31 31 31 31 00 00 00 00 00 00 00 00 00 00 00 00 31 31 31 31 31 41 41 32 32 32 32 32 32 32 32 32 32 32 32".ToHexBytes(); + JT809_0x1200_0x1201 jT809_0X1200_0X1201 = JT809Serializer.Deserialize(bytes); + Assert.Equal("1111111111", jT809_0X1200_0X1201.PlateformId); + Assert.Equal("1111111111", jT809_0X1200_0X1201.ProducerId); + Assert.Equal("11111AA", jT809_0X1200_0X1201.TerminalId); + Assert.Equal("11111111", jT809_0X1200_0X1201.TerminalModelType); + Assert.Equal("222222222222", jT809_0X1200_0X1201.TerminalSimCode); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1202Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1202Test.cs new file mode 100644 index 0000000..4e68615 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1202Test.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1200_0x1202Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200_0x1202 jT809_0X1200_0X1202 = new JT809_0x1200_0x1202(); + jT809_0X1200_0X1202.VehiclePosition.Day = 19; + jT809_0X1200_0X1202.VehiclePosition.Month = 7; + jT809_0X1200_0X1202.VehiclePosition.Year = 2012; + jT809_0X1200_0X1202.VehiclePosition.Hour = 15; + jT809_0X1200_0X1202.VehiclePosition.Minute = 15; + jT809_0X1200_0X1202.VehiclePosition.Second = 15; + jT809_0X1200_0X1202.VehiclePosition.Lon = 133123456; + jT809_0X1200_0X1202.VehiclePosition.Lat = 24123456; + jT809_0X1200_0X1202.VehiclePosition.Vec1 = 50; + jT809_0X1200_0X1202.VehiclePosition.Vec2 = 51; + jT809_0X1200_0X1202.VehiclePosition.Vec3 = 150; + jT809_0X1200_0X1202.VehiclePosition.Direction = 45; + jT809_0X1200_0X1202.VehiclePosition.Altitude = 45; + jT809_0X1200_0X1202.VehiclePosition.State = 3; + jT809_0X1200_0X1202.VehiclePosition.Alarm = 257; + var hex = JT809Serializer.Serialize(jT809_0X1200_0X1202).ToHexString(); + //"00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01" + Assert.Equal("00130707DC0F0F0F07EF4D80017018400032003300000096002D002D0000000300000101", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01".ToHexBytes(); + JT809_0x1200_0x1202 jT809_0X1200_0X1202 = JT809Serializer.Deserialize(bytes); + Assert.Equal(19, jT809_0X1200_0X1202.VehiclePosition.Day); + Assert.Equal(7, jT809_0X1200_0X1202.VehiclePosition.Month); + Assert.Equal(2012, jT809_0X1200_0X1202.VehiclePosition.Year); + Assert.Equal(15, jT809_0X1200_0X1202.VehiclePosition.Hour); + Assert.Equal(15, jT809_0X1200_0X1202.VehiclePosition.Minute); + Assert.Equal(15, jT809_0X1200_0X1202.VehiclePosition.Second); + Assert.Equal((uint)133123456, jT809_0X1200_0X1202.VehiclePosition.Lon); + Assert.Equal((uint)24123456, jT809_0X1200_0X1202.VehiclePosition.Lat); + Assert.Equal(50, jT809_0X1200_0X1202.VehiclePosition.Vec1); + Assert.Equal(51, jT809_0X1200_0X1202.VehiclePosition.Vec2); + Assert.Equal((ushort)45, jT809_0X1200_0X1202.VehiclePosition.Direction); + Assert.Equal((ushort)45, jT809_0X1200_0X1202.VehiclePosition.Altitude); + Assert.Equal((uint)3, jT809_0X1200_0X1202.VehiclePosition.State); + Assert.Equal((uint)257, jT809_0X1200_0X1202.VehiclePosition.Alarm); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1203Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1203Test.cs new file mode 100644 index 0000000..263b10c --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1203Test.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1200_0x1203Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200_0x1203 jT809_0X1200_0X1203 = new JT809_0x1200_0x1203(); + jT809_0X1200_0X1203.GNSS = new List(); + + JT809_0x1200_0x1202 jT809_0X1200_0X1202_1 = new JT809_0x1200_0x1202(); + jT809_0X1200_0X1202_1.VehiclePosition.Day = 19; + jT809_0X1200_0X1202_1.VehiclePosition.Month = 7; + jT809_0X1200_0X1202_1.VehiclePosition.Year = 2012; + jT809_0X1200_0X1202_1.VehiclePosition.Hour = 15; + jT809_0X1200_0X1202_1.VehiclePosition.Minute = 15; + jT809_0X1200_0X1202_1.VehiclePosition.Second = 15; + jT809_0X1200_0X1202_1.VehiclePosition.Lon = 133123456; + jT809_0X1200_0X1202_1.VehiclePosition.Lat = 24123456; + jT809_0X1200_0X1202_1.VehiclePosition.Vec1 = 50; + jT809_0X1200_0X1202_1.VehiclePosition.Vec2 = 51; + jT809_0X1200_0X1202_1.VehiclePosition.Vec3 = 150; + jT809_0X1200_0X1202_1.VehiclePosition.Direction = 45; + jT809_0X1200_0X1202_1.VehiclePosition.Altitude = 45; + jT809_0X1200_0X1202_1.VehiclePosition.State = 3; + jT809_0X1200_0X1202_1.VehiclePosition.Alarm = 257; + + JT809_0x1200_0x1202 jT809_0X1200_0X1202_2 = new JT809_0x1200_0x1202(); + jT809_0X1200_0X1202_2.VehiclePosition.Day = 19; + jT809_0X1200_0X1202_2.VehiclePosition.Month = 7; + jT809_0X1200_0X1202_2.VehiclePosition.Year = 2012; + jT809_0X1200_0X1202_2.VehiclePosition.Hour = 16; + jT809_0X1200_0X1202_2.VehiclePosition.Minute = 16; + jT809_0X1200_0X1202_2.VehiclePosition.Second = 16; + jT809_0X1200_0X1202_2.VehiclePosition.Lon = 133123456; + jT809_0X1200_0X1202_2.VehiclePosition.Lat = 24123456; + jT809_0X1200_0X1202_2.VehiclePosition.Vec1 = 50; + jT809_0X1200_0X1202_2.VehiclePosition.Vec2 = 51; + jT809_0X1200_0X1202_2.VehiclePosition.Vec3 = 150; + jT809_0X1200_0X1202_2.VehiclePosition.Direction = 45; + jT809_0X1200_0X1202_2.VehiclePosition.Altitude = 45; + jT809_0X1200_0X1202_2.VehiclePosition.State = 3; + jT809_0X1200_0X1202_2.VehiclePosition.Alarm = 257; + + JT809_0x1200_0x1202 jT809_0X1200_0X1202_3 = new JT809_0x1200_0x1202(); + jT809_0X1200_0X1202_3.VehiclePosition.Day = 19; + jT809_0X1200_0X1202_3.VehiclePosition.Month = 7; + jT809_0X1200_0X1202_3.VehiclePosition.Year = 2012; + jT809_0X1200_0X1202_3.VehiclePosition.Hour = 17; + jT809_0X1200_0X1202_3.VehiclePosition.Minute = 17; + jT809_0X1200_0X1202_3.VehiclePosition.Second = 17; + jT809_0X1200_0X1202_3.VehiclePosition.Lon = 133123456; + jT809_0X1200_0X1202_3.VehiclePosition.Lat = 24123456; + jT809_0X1200_0X1202_3.VehiclePosition.Vec1 = 50; + jT809_0X1200_0X1202_3.VehiclePosition.Vec2 = 51; + jT809_0X1200_0X1202_3.VehiclePosition.Vec3 = 150; + jT809_0X1200_0X1202_3.VehiclePosition.Direction = 45; + jT809_0X1200_0X1202_3.VehiclePosition.Altitude = 45; + jT809_0X1200_0X1202_3.VehiclePosition.State = 3; + jT809_0X1200_0X1202_3.VehiclePosition.Alarm = 257; + + + jT809_0X1200_0X1203.GNSS.Add(jT809_0X1200_0X1202_1); + jT809_0X1200_0X1203.GNSS.Add(jT809_0X1200_0X1202_2); + jT809_0X1200_0X1203.GNSS.Add(jT809_0X1200_0X1202_3); + + var hex = JT809Serializer.Serialize(jT809_0X1200_0X1203).ToHexString(); + //"03 00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01 00 13 07 07 DC 10 10 10 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01 00 13 07 07 DC 11 11 11 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01" + Assert.Equal("0300130707DC0F0F0F07EF4D80017018400032003300000096002D002D000000030000010100130707DC10101007EF4D80017018400032003300000096002D002D000000030000010100130707DC11111107EF4D80017018400032003300000096002D002D0000000300000101", hex); + } + + [Fact] + public void Test2() + { + var bytes = "03 00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01 00 13 07 07 DC 10 10 10 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01 00 13 07 07 DC 11 11 11 07 EF 4D 80 01 70 18 40 00 32 00 33 00 00 00 96 00 2D 00 2D 00 00 00 03 00 00 01 01".ToHexBytes(); + JT809_0x1200_0x1203 jT809_0X1200_0X1203 = JT809Serializer.Deserialize(bytes); + + Assert.Equal(3, jT809_0X1200_0X1203.GNSSCount); + + + Assert.Equal(19, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Day); + Assert.Equal(7, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Month); + Assert.Equal(2012, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Year); + Assert.Equal(15, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Hour); + Assert.Equal(15, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Minute); + Assert.Equal(15, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Second); + Assert.Equal((uint)133123456, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Lon); + Assert.Equal((uint)24123456, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Lat); + Assert.Equal(50, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Vec1); + Assert.Equal(51, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Vec2); + Assert.Equal((ushort)45, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Direction); + Assert.Equal((ushort)45, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Altitude); + Assert.Equal((uint)3, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.State); + Assert.Equal((uint)257, jT809_0X1200_0X1203.GNSS[0].VehiclePosition.Alarm); + + Assert.Equal(19, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Day); + Assert.Equal(7, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Month); + Assert.Equal(2012, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Year); + Assert.Equal(16, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Hour); + Assert.Equal(16, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Minute); + Assert.Equal(16, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Second); + Assert.Equal((uint)133123456, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Lon); + Assert.Equal((uint)24123456, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Lat); + Assert.Equal(50, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Vec1); + Assert.Equal(51, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Vec2); + Assert.Equal((ushort)45, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Direction); + Assert.Equal((ushort)45, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Altitude); + Assert.Equal((uint)3, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.State); + Assert.Equal((uint)257, jT809_0X1200_0X1203.GNSS[1].VehiclePosition.Alarm); + + Assert.Equal(19, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Day); + Assert.Equal(7, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Month); + Assert.Equal(2012, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Year); + Assert.Equal(17, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Hour); + Assert.Equal(17, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Minute); + Assert.Equal(17, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Second); + Assert.Equal((uint)133123456, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Lon); + Assert.Equal((uint)24123456, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Lat); + Assert.Equal(50, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Vec1); + Assert.Equal(51, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Vec2); + Assert.Equal((ushort)45, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Direction); + Assert.Equal((ushort)45, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Altitude); + Assert.Equal((uint)3, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.State); + Assert.Equal((uint)257, jT809_0X1200_0X1203.GNSS[2].VehiclePosition.Alarm); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1207Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1207Test.cs new file mode 100644 index 0000000..ef4a8d8 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1207Test.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1200_0x1207Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200_0x1207 jT809_0X1200_0X1201 = new JT809_0x1200_0x1207 + { + StartTime = DateTime.Parse("2018-09-24 14:14:14"), + EndTime = DateTime.Parse("2018-09-24 23:23:23") + }; + var hex = JT809Serializer.Serialize(jT809_0X1200_0X1201).ToHexString(); + //"00 00 00 00 5B A8 80 B6 00 00 00 00 5B A9 01 6B" + Assert.Equal("000000005BA880B6000000005BA9016B",hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 00 00 5B A8 80 B6 00 00 00 00 5B A9 01 6B".ToHexBytes(); + JT809_0x1200_0x1207 jT809_0X1200_0X1201 = JT809Serializer.Deserialize(bytes); + Assert.Equal(DateTime.Parse("2018-09-24 14:14:14"), jT809_0X1200_0X1201.StartTime); + Assert.Equal(DateTime.Parse("2018-09-24 23:23:23"), jT809_0X1200_0X1201.EndTime); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1209Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1209Test.cs new file mode 100644 index 0000000..097b8d0 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x1209Test.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1200_0x1209Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200_0x1209 jT809_0X1200_0X1209 = new JT809_0x1200_0x1209 + { + StartTime = DateTime.Parse("2018-09-24 14:14:14"), + EndTime = DateTime.Parse("2018-09-24 23:23:23") + }; + var hex = JT809Serializer.Serialize(jT809_0X1200_0X1209).ToHexString(); + //"00 00 00 00 5B A8 80 B6 00 00 00 00 5B A9 01 6B" + Assert.Equal("000000005BA880B6000000005BA9016B",hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 00 00 5B A8 80 B6 00 00 00 00 5B A9 01 6B".ToHexBytes(); + JT809_0x1200_0x1209 jT809_0X1200_0X1209 = JT809Serializer.Deserialize(bytes); + Assert.Equal(DateTime.Parse("2018-09-24 14:14:14"), jT809_0X1200_0X1209.StartTime); + Assert.Equal(DateTime.Parse("2018-09-24 23:23:23"), jT809_0X1200_0X1209.EndTime); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120ATest.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120ATest.cs new file mode 100644 index 0000000..f83de94 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120ATest.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1200_0x120ATest + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200_0x120A jT809_0X1200_0X120A = new JT809_0x1200_0x120A + { + DriverID = "123456789123456789", + DriverName = "smallchi", + Licence= "abcdef123456789", + OrgName= "www123456789" + }; + var hex = JT809Serializer.Serialize(jT809_0X1200_0X120A).ToHexString(); + //"73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 31 32 33 34 35 36 37 38 39 00 00 61 62 63 64 65 66 31 32 33 34 35 36 37 38 39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 77 77 77 31 32 33 34 35 36 37 38 39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" + Assert.Equal("736D616C6C63686900000000000000003132333435363738393132333435363738390000616263646566313233343536373839000000000000000000000000000000000000000000000000007777773132333435363738390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", hex);Assert.Equal("736D616C6C63686900000000000000003132333435363738393132333435363738390000616263646566313233343536373839000000000000000000000000000000000000000000000000007777773132333435363738390000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", hex); + } + + [Fact] + public void Test2() + { + var bytes = "73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 31 32 33 34 35 36 37 38 39 00 00 61 62 63 64 65 66 31 32 33 34 35 36 37 38 39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 77 77 77 31 32 33 34 35 36 37 38 39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00".ToHexBytes(); + JT809_0x1200_0x120A jT809_0X1200_0X120A = JT809Serializer.Deserialize(bytes); + Assert.Equal("123456789123456789", jT809_0X1200_0X120A.DriverID); + Assert.Equal("smallchi", jT809_0X1200_0X120A.DriverName); + Assert.Equal("abcdef123456789", jT809_0X1200_0X120A.Licence); + Assert.Equal("www123456789", jT809_0X1200_0X120A.OrgName); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120BTest.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120BTest.cs new file mode 100644 index 0000000..bd2f59e --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120BTest.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1200_0x120BTest + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200_0x120B jT809_0X1200_0X120B = new JT809_0x1200_0x120B + { + EwaybillInfo="asd123456asd" + }; + var hex = JT809Serializer.Serialize(jT809_0X1200_0X120B).ToHexString(); + //"00 00 00 0C 61 73 64 31 32 33 34 35 36 61 73 64" + Assert.Equal("0000000C617364313233343536617364", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 00 0C 61 73 64 31 32 33 34 35 36 61 73 64".ToHexBytes(); + JT809_0x1200_0x120B jT809_0X1200_0X120B = JT809Serializer.Deserialize(bytes); + Assert.Equal("asd123456asd", jT809_0X1200_0X120B.EwaybillInfo); + Assert.Equal((uint)12, jT809_0X1200_0X120B.EwaybillLength); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120CTest.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120CTest.cs new file mode 100644 index 0000000..ea95d5f --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120CTest.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1200_0x120CTest + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200_0x120C jT809_0X1200_0X120C = new JT809_0x1200_0x120C + { + DriverID="1234567890123", + DriverName="smallchi", + Licence="3210987654321", + OrgName = "gov" + }; + var hex = JT809Serializer.Serialize(jT809_0X1200_0X120C).ToHexString(); + Assert.Equal("736D616C6C6368690000000000000000313233343536373839303132330000000000000033323130393837363534333231000000000000000000000000000000000000000000000000000000676F760000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", hex); + } + + [Fact] + public void Test2() + { + var bytes = "736D616C6C6368690000000000000000313233343536373839303132330000000000000033323130393837363534333231000000000000000000000000000000000000000000000000000000676F760000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".ToHexBytes(); + JT809_0x1200_0x120C jT809_0X1200_0X120C = JT809Serializer.Deserialize(bytes); + Assert.Equal("1234567890123", jT809_0X1200_0X120C.DriverID); + Assert.Equal("smallchi", jT809_0X1200_0X120C.DriverName); + Assert.Equal("3210987654321", jT809_0X1200_0X120C.Licence); + Assert.Equal("gov", jT809_0X1200_0X120C.OrgName); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120DTest.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120DTest.cs new file mode 100644 index 0000000..d287e0c --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1200_0x120DTest.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1200_0x120DTest + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1200_0x120D jT809_0X1200_0X120D = new JT809_0x1200_0x120D + { + EwaybillInfo="asd123456asd" + }; + var hex = JT809Serializer.Serialize(jT809_0X1200_0X120D).ToHexString(); + Assert.Equal("0000000C617364313233343536617364", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 00 0C 61 73 64 31 32 33 34 35 36 61 73 64".ToHexBytes(); + JT809_0x1200_0x120D jT809_0X1200_0X120D = JT809Serializer.Deserialize(bytes); + Assert.Equal("asd123456asd", jT809_0X1200_0X120D.EwaybillInfo); + Assert.Equal((uint)12, jT809_0X1200_0X120D.EwaybillLength); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1301Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1301Test.cs new file mode 100644 index 0000000..ca8da94 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1301Test.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1300_0x1301Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1300_0x1301 jT809_0x1300_0x1301 = new JT809_0x1300_0x1301 + { + ObjectID = "111", + InfoContent = "22ha22", + InfoID = 1234, + ObjectType = JT809_0x1301_ObjectType.当前连接的下级平台 + }; + var hex = JT809Serializer.Serialize(jT809_0x1300_0x1301).ToHexString(); + //"01 31 31 31 00 00 00 00 00 00 00 00 00 00 00 04 D2 00 00 00 06 32 32 68 61 32 32" + Assert.Equal("01313131000000000000000000000004D200000006323268613232", hex); + } + + [Fact] + public void Test2() + { + var bytes = "01 31 31 31 00 00 00 00 00 00 00 00 00 00 00 04 D2 00 00 00 06 32 32 68 61 32 32".ToHexBytes(); + JT809_0x1300_0x1301 jT809_0x1300_0x1301 = JT809Serializer.Deserialize(bytes); + Assert.Equal("111", jT809_0x1300_0x1301.ObjectID); + Assert.Equal("22ha22", jT809_0x1300_0x1301.InfoContent); + Assert.Equal((uint)1234, jT809_0x1300_0x1301.InfoID); + Assert.Equal(JT809_0x1301_ObjectType.当前连接的下级平台, jT809_0x1300_0x1301.ObjectType); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1302Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1302Test.cs new file mode 100644 index 0000000..e1ecf5a --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1300_0x1302Test.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1300_0x1302Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1300_0x1302 jT809_0x1300_0x1302 = new JT809_0x1300_0x1302 + { + InfoID = 1234 + }; + var hex = JT809Serializer.Serialize(jT809_0x1300_0x1302).ToHexString(); + Assert.Equal("000004D2", hex); + } + + [Fact] + public void Test2() + { + var bytes = "000004D2".ToHexBytes(); + JT809_0x1300_0x1302 jT809_0x1300_0x1302 = JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)1234, jT809_0x1300_0x1302.InfoID); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1401Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1401Test.cs new file mode 100644 index 0000000..def9cd7 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1401Test.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1400_0x1401Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1400_0x1401 jT809_0x1400_0x1401 = new JT809_0x1400_0x1401 + { + SupervisionID=9898, + Result= JT809_0x1401_Result.处理中 + }; + var hex = JT809Serializer.Serialize(jT809_0x1400_0x1401).ToHexString(); + Assert.Equal("000026AA00", hex); + } + + [Fact] + public void Test2() + { + var bytes = "000026AA00".ToHexBytes(); + JT809_0x1400_0x1401 jT809_0x1400_0x1401 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1401_Result.处理中, jT809_0x1400_0x1401.Result); + Assert.Equal((uint)9898, jT809_0x1400_0x1401.SupervisionID); + + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs new file mode 100644 index 0000000..9f79a75 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1402Test.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1400_0x1402Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1400_0x1402 jT809_0x1400_0x1402 = new JT809_0x1400_0x1402 + { + WarnSrc= JT809WarnSrc.车载终端, + WarnType = JT809WarnType.偏离路线报警, + WarnTime=DateTime.Parse("2018-09-26"), + InfoContent = "gfdf454553", + InfoID = 3344, + }; + var hex = JT809Serializer.Serialize(jT809_0x1400_0x1402).ToHexString(); + // "01 00 0B 00 00 00 00 5B AA 5B 80 00 00 0D 10 00 00 00 0A 67 66 64 66 34 35 34 35 35 33" + Assert.Equal("01000B000000005BAA5B8000000D100000000A67666466343534353533", hex); + } + + [Fact] + public void Test2() + { + var bytes = "01 00 0B 00 00 00 00 5B AA 5B 80 00 00 0D 10 00 00 00 0A 67 66 64 66 34 35 34 35 35 33".ToHexBytes(); + JT809_0x1400_0x1402 jT809_0x1400_0x1402 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809WarnSrc.车载终端, jT809_0x1400_0x1402.WarnSrc); + Assert.Equal("gfdf454553", jT809_0x1400_0x1402.InfoContent); + Assert.Equal(JT809WarnType.偏离路线报警, jT809_0x1400_0x1402.WarnType); + Assert.Equal((uint)3344, jT809_0x1400_0x1402.InfoID); + Assert.Equal((uint)10, jT809_0x1400_0x1402.InfoLength); + Assert.Equal(DateTime.Parse("2018-09-26"), jT809_0x1400_0x1402.WarnTime); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs new file mode 100644 index 0000000..c9a65ca --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1400_0x1403Test.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1400_0x1403Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1400_0x1403 jT809_0x1400_0x1403 = new JT809_0x1400_0x1403 + { + Result= JT809_0x1403_Result.将来处理, + InfoID = 3344, + }; + var hex = JT809Serializer.Serialize(jT809_0x1400_0x1403).ToHexString(); + // "00 00 0D 10 03" + Assert.Equal("00000D1003", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 0D 10 03".ToHexBytes(); + JT809_0x1400_0x1403 jT809_0x1400_0x1403 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1403_Result.将来处理, jT809_0x1400_0x1403.Result); + Assert.Equal((uint)3344, jT809_0x1400_0x1403.InfoID); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1501Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1501Test.cs new file mode 100644 index 0000000..48b9947 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1501Test.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1500_0x1501Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1500_0x1501 jT809_0X1500_0X1501 = new JT809_0x1500_0x1501 + { + Result= JT809_0x1501_Result.监听成功 + }; + var hex = JT809Serializer.Serialize(jT809_0X1500_0X1501).ToHexString(); + Assert.Equal("00",hex); + } + + [Fact] + public void Test2() + { + var bytes = "00".ToHexBytes(); + JT809_0x1500_0x1501 jT809_0X1500_0X1501 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1501_Result.监听成功, jT809_0X1500_0X1501.Result); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs new file mode 100644 index 0000000..5803067 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1502Test.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; +using JT809.Protocol.Metadata; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1500_0x1502Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1500_0x1502 jT809_0x1500_0x1502 = new JT809_0x1500_0x1502 + { + PhotoRspFlag= JT809_0x1502_PhotoRspFlag.完成拍照, + VehiclePosition=new JT809VehiclePositionProperties + { + Encrypt= JT809_VehiclePositionEncrypt.未加密, + Day=19, + Month=7, + Year=2012, + Hour=15, + Minute=15, + Second=15, + Lon= 133123456, + Lat= 24123456, + Vec1=53, + Vec2=45, + Vec3=1234, + Direction=45, + Altitude=45, + State=1, + Alarm=1 + }, + LensID=123, + SizeType=1, + Type=1, + }; + var hex = JT809Serializer.Serialize(jT809_0x1500_0x1502).ToHexString(); + //"01 00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 35 00 2D 00 00 04 D2 00 2D 00 2D 00 00 00 01 00 00 00 01 7B 00 00 00 00 01 01" + Assert.Equal("0100130707DC0F0F0F07EF4D80017018400035002D000004D2002D002D00000001000000017B000000000101", hex); + } + + [Fact] + public void Test2() + { + var bytes = "01 00 13 07 07 DC 0F 0F 0F 07 EF 4D 80 01 70 18 40 00 35 00 2D 00 00 04 D2 00 2D 00 2D 00 00 00 01 00 00 00 01 7B 00 00 00 00 01 01".ToHexBytes(); + JT809_0x1500_0x1502 jT809_0x1500_0x1502 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1502_PhotoRspFlag.完成拍照, jT809_0x1500_0x1502.PhotoRspFlag); + Assert.Equal(JT809_VehiclePositionEncrypt.未加密, jT809_0x1500_0x1502.VehiclePosition.Encrypt); + Assert.Equal(19, jT809_0x1500_0x1502.VehiclePosition.Day); + Assert.Equal(7, jT809_0x1500_0x1502.VehiclePosition.Month); + Assert.Equal(2012, jT809_0x1500_0x1502.VehiclePosition.Year); + Assert.Equal(15, jT809_0x1500_0x1502.VehiclePosition.Hour); + Assert.Equal(15, jT809_0x1500_0x1502.VehiclePosition.Minute); + Assert.Equal(15, jT809_0x1500_0x1502.VehiclePosition.Second); + Assert.Equal((uint)133123456, jT809_0x1500_0x1502.VehiclePosition.Lon); + Assert.Equal((uint)24123456, jT809_0x1500_0x1502.VehiclePosition.Lat); + Assert.Equal((ushort)53, jT809_0x1500_0x1502.VehiclePosition.Vec1); + Assert.Equal((ushort)45, jT809_0x1500_0x1502.VehiclePosition.Vec2); + Assert.Equal((uint)1234, jT809_0x1500_0x1502.VehiclePosition.Vec3); + Assert.Equal((ushort)45, jT809_0x1500_0x1502.VehiclePosition.Direction); + Assert.Equal((ushort)45, jT809_0x1500_0x1502.VehiclePosition.Altitude); + Assert.Equal((uint)1, jT809_0x1500_0x1502.VehiclePosition.State); + Assert.Equal((uint)1, jT809_0x1500_0x1502.VehiclePosition.Alarm); + Assert.Equal(123, jT809_0x1500_0x1502.LensID); + Assert.Equal(1, jT809_0x1500_0x1502.SizeType); + Assert.Equal(1, jT809_0x1500_0x1502.Type); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1503Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1503Test.cs new file mode 100644 index 0000000..f4aa123 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1503Test.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1500_0x1503Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1500_0x1503 jT809_0X1500_0X1503 = new JT809_0x1500_0x1503 + { + MsgID=9999, + Result= JT809_0x1503_Result.下发成功 + }; + var hex = JT809Serializer.Serialize(jT809_0X1500_0X1503).ToHexString(); + Assert.Equal("0000270F00", hex); + } + + [Fact] + public void Test2() + { + var bytes = "0000270F00".ToHexBytes(); + JT809_0x1500_0x1503 jT809_0X1500_0X1503 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1503_Result.下发成功, jT809_0X1500_0X1503.Result); + Assert.Equal((uint)9999, jT809_0X1500_0X1503.MsgID); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs new file mode 100644 index 0000000..c8e178d --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1504Test.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1500_0x1504Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1400_0x1403 jT809_0x1400_0x1403 = new JT809_0x1400_0x1403 + { + Result = JT809_0x1403_Result.将来处理, + InfoID = 3344, + }; + var hex = JT809Serializer.Serialize(jT809_0x1400_0x1403).ToHexString(); + // "00 00 0D 10 03" + Assert.Equal("00000D1003",hex); + } + + [Fact] + public void Test2() + { + var bytes = "00 00 0D 10 03".ToHexBytes(); + JT809_0x1400_0x1403 jT809_0x1400_0x1403 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1403_Result.将来处理, jT809_0x1400_0x1403.Result); + Assert.Equal((uint)3344, jT809_0x1400_0x1403.InfoID); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1505Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1505Test.cs new file mode 100644 index 0000000..574f626 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1500_0x1505Test.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1500_0x1505Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1500_0x1505 jT809_0X1500_0X1505 = new JT809_0x1500_0x1505 + { + Result= JT809_0x1505_Result.无该车辆 + }; + var hex = JT809Serializer.Serialize(jT809_0X1500_0X1505).ToHexString(); + Assert.Equal("01",hex); + } + + [Fact] + public void Test2() + { + var bytes = "01".ToHexBytes(); + JT809_0x1500_0x1505 jT809_0X1500_0X1505 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x1505_Result.无该车辆, jT809_0X1500_0X1505.Result); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1601Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1601Test.cs new file mode 100644 index 0000000..70470c8 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1601Test.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x1600_0x1601Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x1600_0x1601 jT809_0x1600_0x1601 = new JT809_0x1600_0x1601 + { + CarInfo = "smallchi", + }; + var hex = JT809Serializer.Serialize(jT809_0x1600_0x1601).ToHexString(); + Assert.Equal("736D616C6C636869", hex); + } + + [Fact] + public void Test2() + { + var bytes = "736D616C6C636869".ToHexBytes(); + JT809_0x1600_0x1601 jT809_0x1600_0x1601 = JT809Serializer.Deserialize(bytes); + Assert.Equal("smallchi", jT809_0x1600_0x1601.CarInfo); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9204Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9204Test.cs new file mode 100644 index 0000000..421be3a --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9204Test.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9200_0x9204Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9200_0x9204 jT809_0X9200_0X9204 = new JT809_0x9200_0x9204 + { + CarInfo= "车辆信息" + }; + var hex = JT809Serializer.Serialize(jT809_0X9200_0X9204).ToHexString(); + Assert.Equal("B3B5C1BED0C5CFA2", hex); + } + + [Fact] + public void Test2() + { + var bytes = "B3B5C1BED0C5CFA2".ToHexBytes(); + JT809_0x9200_0x9204 jT809_0X9200_0X9204 = JT809Serializer.Deserialize(bytes); + Assert.Equal("车辆信息", jT809_0X9200_0X9204.CarInfo); + } + + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9205Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9205Test.cs new file mode 100644 index 0000000..8f36e06 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9205Test.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9200_0x9205Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9200_0x9205 jT809_0X9200_0X9205 = new JT809_0x9200_0x9205 + { + ReasonCode= JT809_0x9205_ReasonCode.应急状态下车辆定位信息回传 + }; + var hex = JT809Serializer.Serialize(jT809_0X9200_0X9205).ToHexString(); + Assert.Equal("02", hex); + } + + [Fact] + public void Test2() + { + var bytes = "02".ToHexBytes(); + JT809_0x9200_0x9205 jT809_0X9200_0X9205 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9205_ReasonCode.应急状态下车辆定位信息回传, jT809_0X9200_0X9205.ReasonCode); + } + + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9206Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9206Test.cs new file mode 100644 index 0000000..b007841 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9206Test.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9200_0x9206Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9200_0x9206 jT809_0X9200_0X9206 = new JT809_0x9200_0x9206 + { + ReasonCode= JT809_0x9206_ReasonCode.紧急监控完成 + }; + var hex = JT809Serializer.Serialize(jT809_0X9200_0X9206).ToHexString(); + Assert.Equal("02", hex); + } + + [Fact] + public void Test2() + { + var bytes = "02".ToHexBytes(); + JT809_0x9200_0x9206 jT809_0X9200_0X9206 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9206_ReasonCode.紧急监控完成, jT809_0X9200_0X9206.ReasonCode); + } + + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9207Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9207Test.cs new file mode 100644 index 0000000..ddf4de4 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9207Test.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9200_0x9207Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9200_0x9207 jT809_0X9200_0X9207 = new JT809_0x9200_0x9207 + { + Result= JT809_0x9207_Result.申请成功 + }; + var hex = JT809Serializer.Serialize(jT809_0X9200_0X9207).ToHexString(); + Assert.Equal("00", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00".ToHexBytes(); + JT809_0x9200_0x9207 jT809_0X9200_0X9207 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9207_Result.申请成功, jT809_0X9200_0X9207.Result); + } + + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9208Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9208Test.cs new file mode 100644 index 0000000..275ef76 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9208Test.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9200_0x9208Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9200_0x9208 jT809_0X9200_0X9208 = new JT809_0x9200_0x9208 + { + Result= JT809_0x9208_Result.其它 + }; + var hex = JT809Serializer.Serialize(jT809_0X9200_0X9208).ToHexString(); + Assert.Equal("02", hex); + } + + [Fact] + public void Test2() + { + var bytes = "02".ToHexBytes(); + JT809_0x9200_0x9208 jT809_0X9200_0X9208 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9208_Result.其它, jT809_0X9200_0X9208.Result); + } + + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9209Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9209Test.cs new file mode 100644 index 0000000..2b80a2d --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9200_0x9209Test.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9200_0x9209Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9200_0x9209 jT809_0X9200_0X9209 = new JT809_0x9200_0x9209 + { + Result= JT809_0x9209_Result.成功_上级平台即刻补发 + }; + var hex = JT809Serializer.Serialize(jT809_0X9200_0X9209).ToHexString(); + Assert.Equal("00", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00".ToHexBytes(); + JT809_0x9200_0x9209 jT809_0X9200_0X9209 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9209_Result.成功_上级平台即刻补发, jT809_0X9200_0X9209.Result); + } + + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs new file mode 100644 index 0000000..1410a8e --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9301Test.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9300_0x9301Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9300_0x9301 jT809_0x9300_0x9301 = new JT809_0x9300_0x9301 + { + ObjectID="smallchi", + ObjectType= JT809_0x9301_ObjectType.下级平台所属单一业户, + InfoContent="reply", + InfoID = 3344, + }; + var hex = JT809Serializer.Serialize(jT809_0x9300_0x9301).ToHexString(); + // "02 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 0D 10 00 00 00 05 72 65 70 6C 79" + Assert.Equal("02736D616C6C6368690000000000000D10000000057265706C79", hex); + } + + [Fact] + public void Test2() + { + var bytes = "02 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 0D 10 00 00 00 05 72 65 70 6C 79".ToHexBytes(); + JT809_0x9300_0x9301 jT809_0x9300_0x9301 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9301_ObjectType.下级平台所属单一业户, jT809_0x9300_0x9301.ObjectType); + Assert.Equal((uint)3344, jT809_0x9300_0x9301.InfoID); + Assert.Equal("reply", jT809_0x9300_0x9301.InfoContent); + Assert.Equal("smallchi", jT809_0x9300_0x9301.ObjectID); + } + + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9302Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9302Test.cs new file mode 100644 index 0000000..265318c --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9300_0x9302Test.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9300_0x9302Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9300_0x9302 jT809_0X9300_0X9302 = new JT809_0x9300_0x9302 + { + ObjectType= JT809_0x9302_ObjectType.下级平台所属单一平台, + ObjectID="afdasf3", + InfoID=1234, + InfoContent= "下级平台所属单一平台" + }; + var hex = JT809Serializer.Serialize(jT809_0X9300_0X9302).ToHexString(); + Assert.Equal("00616664617366330000000000000004D200000014CFC2BCB6C6BDCCA8CBF9CAF4B5A5D2BBC6BDCCA8", hex); + } + + [Fact] + public void Test2() + { + var bytes = "00616664617366330000000000000004D200000014CFC2BCB6C6BDCCA8CBF9CAF4B5A5D2BBC6BDCCA8".ToHexBytes(); + JT809_0x9300_0x9302 jT809_0X9300_0X9302 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809_0x9302_ObjectType.下级平台所属单一平台, jT809_0X9300_0X9302.ObjectType); + Assert.Equal("afdasf3", jT809_0X9300_0X9302.ObjectID); + Assert.Equal((uint)1234, jT809_0X9300_0X9302.InfoID); + Assert.Equal("下级平台所属单一平台", jT809_0X9300_0X9302.InfoContent); + Assert.Equal((uint)20, jT809_0X9300_0X9302.InfoLength); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs new file mode 100644 index 0000000..91e3e54 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9401Test.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9400_0x9401Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9400_0x9401 jT809_0x9400_0x9401 = new JT809_0x9400_0x9401 + { + WarnSrc= JT809WarnSrc.车载终端, + WarnType= JT809WarnType.疲劳驾驶报警, + WarnTime=DateTime.Parse("2018-09-27 10:24:00"), + SupervisionID="123FFAA1", + SupervisionEndTime= DateTime.Parse("2018-09-27 11:24:00"), + SupervisionLevel=3, + Supervisor="smallchi", + SupervisorTel= "12345678901", + SupervisorEmail= "123456@qq.com" + }; + var hex = JT809Serializer.Serialize(jT809_0x9400_0x9401).ToHexString(); + //010002000000005BAC3F40123FFAA1000000005BAC4D5003736D616C6C63686931323334353637383930313132333435364071712E636F6D + //010002000000005BAC3F40123FFAA1000000005BAC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000 + //"01 00 02 00 00 00 00 5B AC 3F 40 12 3F FA A1 00 00 00 00 5B AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" + Assert.Equal("010002000000005BAC3F40123FFAA1000000005BAC4D5003736D616C6C636869000000000000000031323334353637383930310000000000000000003132333435364071712E636F6D00000000000000000000000000000000000000", hex); + } + + [Fact] + public void Test2() + { + var bytes = "01 00 02 00 00 00 00 5B AC 3F 40 12 3F FA A1 00 00 00 00 5B AC 4D 50 03 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 31 32 33 34 35 36 37 38 39 30 31 00 00 00 00 00 00 00 00 00 31 32 33 34 35 36 40 71 71 2E 63 6F 6D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00".ToHexBytes(); + JT809_0x9400_0x9401 jT809_0x9400_0x9401 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809WarnSrc.车载终端, jT809_0x9400_0x9401.WarnSrc); + Assert.Equal(JT809WarnType.疲劳驾驶报警, jT809_0x9400_0x9401.WarnType); + Assert.Equal(DateTime.Parse("2018-09-27 10:24:00"), jT809_0x9400_0x9401.WarnTime); + Assert.Equal("123FFAA1", jT809_0x9400_0x9401.SupervisionID); + Assert.Equal(DateTime.Parse("2018-09-27 11:24:00"), jT809_0x9400_0x9401.SupervisionEndTime); + Assert.Equal(3, jT809_0x9400_0x9401.SupervisionLevel); + Assert.Equal("smallchi", jT809_0x9400_0x9401.Supervisor); + Assert.Equal("12345678901", jT809_0x9400_0x9401.SupervisorTel); + Assert.Equal("123456@qq.com", jT809_0x9400_0x9401.SupervisorEmail); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9402Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9402Test.cs new file mode 100644 index 0000000..33b0144 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9402Test.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9400_0x9402Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9400_0x9402 jT809_0x9400_0x9402 = new JT809_0x9400_0x9402 + { + WarnSrc= JT809WarnSrc.车载终端, + WarnType= JT809WarnType.劫警, + WarnTime=DateTime.Parse("2018-11-11 10:24:00"), + WarnContent= "劫警", + }; + var hex = JT809Serializer.Serialize(jT809_0x9400_0x9402).ToHexString(); + Assert.Equal("01000A000000005BE792C000000004BDD9BEAF", hex); + } + + [Fact] + public void Test2() + { + var bytes = "01000A000000005BE792C000000004BDD9BEAF".ToHexBytes(); + JT809_0x9400_0x9402 jT809_0x9400_0x9402 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809WarnSrc.车载终端, jT809_0x9400_0x9402.WarnSrc); + Assert.Equal(JT809WarnType.劫警, jT809_0x9400_0x9402.WarnType); + Assert.Equal(DateTime.Parse("2018-11-11 10:24:00"), jT809_0x9400_0x9402.WarnTime); + Assert.Equal("劫警", jT809_0x9400_0x9402.WarnContent); + Assert.Equal((uint)4, jT809_0x9400_0x9402.WarnLength); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9403Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9403Test.cs new file mode 100644 index 0000000..3ac0179 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9400_0x9403Test.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9400_0x9403Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9400_0x9403 jT809_0x9400_0x9403 = new JT809_0x9400_0x9403 + { + WarnSrc= JT809WarnSrc.车载终端, + WarnType= JT809WarnType.疲劳驾驶报警, + WarnTime=DateTime.Parse("2018-11-11 10:24:00"), + WarnContent= "疲劳驾驶报警", + }; + var hex = JT809Serializer.Serialize(jT809_0x9400_0x9403).ToHexString(); + Assert.Equal("010002000000005BE792C00000000CC6A3C0CDBCDDCABBB1A8BEAF", hex); + } + + [Fact] + public void Test2() + { + var bytes = "010002000000005BE792C00000000CC6A3C0CDBCDDCABBB1A8BEAF".ToHexBytes(); + JT809_0x9400_0x9403 jT809_0x9400_0x9403 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809WarnSrc.车载终端, jT809_0x9400_0x9403.WarnSrc); + Assert.Equal(JT809WarnType.疲劳驾驶报警, jT809_0x9400_0x9403.WarnType); + Assert.Equal(DateTime.Parse("2018-11-11 10:24:00"), jT809_0x9400_0x9403.WarnTime); + Assert.Equal("疲劳驾驶报警", jT809_0x9400_0x9403.WarnContent); + Assert.Equal((uint)12, jT809_0x9400_0x9403.WarnLength); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9501Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9501Test.cs new file mode 100644 index 0000000..f1a7eb1 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9501Test.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9500_0x9501Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9500_0x9501 jT809_0X9500_0X9501 = new JT809_0x9500_0x9501 + { + MonitorTel="123456789" + }; + var hex = JT809Serializer.Serialize(jT809_0X9500_0X9501).ToHexString(); + Assert.Equal("3132333435363738390000000000000000000000", hex); + } + + [Fact] + public void Test2() + { + var bytes = "3132333435363738390000000000000000000000".ToHexBytes(); + JT809_0x9500_0x9501 jT809_0X9500_0X9501 = JT809Serializer.Deserialize(bytes); + Assert.Equal("123456789", jT809_0X9500_0X9501.MonitorTel); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9502Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9502Test.cs new file mode 100644 index 0000000..7488c24 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9502Test.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9500_0x9502Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9500_0x9502 jT809_0X9500_0X9502 = new JT809_0x9500_0x9502 + { + LensID=0x09, + SizeType=0x01 + }; + var hex = JT809Serializer.Serialize(jT809_0X9500_0X9502).ToHexString(); + Assert.Equal("0901", hex); + } + + [Fact] + public void Test2() + { + var bytes = "0901".ToHexBytes(); + JT809_0x9500_0x9502 jT809_0X9500_0X9502 = JT809Serializer.Deserialize(bytes); + Assert.Equal(0x09, jT809_0X9500_0X9502.LensID); + Assert.Equal(0x01, jT809_0X9500_0X9502.SizeType); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9503Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9503Test.cs new file mode 100644 index 0000000..ef39fa5 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9503Test.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9500_0x9503Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9500_0x9503 jT809_0X9500_0X9503 = new JT809_0x9500_0x9503 + { + MsgSequence=333, + MsgPriority=2, + MsgContent="汉_sfdf3dfs" + }; + var hex = JT809Serializer.Serialize(jT809_0X9500_0X9503).ToHexString(); + Assert.Equal("0000014D020000000BBABA5F7366646633646673", hex); + } + + [Fact] + public void Test2() + { + var bytes = "0000014D020000000BBABA5F7366646633646673".ToHexBytes(); + JT809_0x9500_0x9503 jT809_0X9500_0X9503 = JT809Serializer.Deserialize(bytes); + Assert.Equal((uint)333, jT809_0X9500_0X9503.MsgSequence); + Assert.Equal(2, jT809_0X9500_0X9503.MsgPriority); + Assert.Equal((uint)11, jT809_0X9500_0X9503.MsgLength); + Assert.Equal("汉_sfdf3dfs", jT809_0X9500_0X9503.MsgContent); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs new file mode 100644 index 0000000..4d99a5d --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9504Test.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9500_0x9504Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9500_0x9504 jT809_0X9500_0X9504 = new JT809_0x9500_0x9504 + { + Command= JT809CommandType.采集记录仪事故疑点记录, + StartTime=DateTime.Parse("2018-09-27 20:00:20"), + EndTime=DateTime.Parse("2018-09-27 23:00:20"), + Max=5556 + }; + var hex = JT809Serializer.Serialize(jT809_0X9500_0X9504).ToHexString(); + //"10 18 09 27 20 00 20 18 09 27 23 00 20 15 B4" + //"10 18 09 27 20 00 20 18 09 27 23 00 20 15 B4" + Assert.Equal("1018092720002018092723002015B4",hex); + //5B 00 00 00 45 00 00 00 85 95 00 01 33 53 D5 01 00 00 00 00 00 27 0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 95 04 00 00 00 0F 10 18 09 27 20 00 20 18 09 27 23 00 20 15 B4 3C D8 5D + } + + [Fact] + public void Test2() + { + var bytes = "10 18 09 27 20 00 20 18 09 27 23 00 20 15 B4".ToHexBytes(); + JT809_0x9500_0x9504 jT809_0X9500_0X9504 = JT809Serializer.Deserialize(bytes); + Assert.Equal(JT809CommandType.采集记录仪事故疑点记录, jT809_0X9500_0X9504.Command); + Assert.Equal(DateTime.Parse("2018-09-27 20:00:20"), jT809_0X9500_0X9504.StartTime); + Assert.Equal(DateTime.Parse("2018-09-27 23:00:20"), jT809_0X9500_0X9504.EndTime); + Assert.Equal(5556, jT809_0X9500_0X9504.Max); + } + } +} diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs new file mode 100644 index 0000000..e3b8b96 --- /dev/null +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x9500_0x9505Test.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT809.Protocol; +using JT809.Protocol.Extensions; +using JT809.Protocol.MessageBody; +using JT809.Protocol.Exceptions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Test.JT809SubMessageBody +{ + public class JT809_0x9500_0x9505Test + { + private JT809Serializer JT809Serializer = new JT809Serializer(); + [Fact] + public void Test1() + { + JT809_0x9500_0x9505 jT809_0X9500_0X9505 = new JT809_0x9500_0x9505 + { + AuthenticationCode= "808", + AccessPointName= "jt808", + UserName = "adslsmallchi", + Password= "adsl123", + ServerIP= "127.0.0.1", + TcpPort=808, + UdpPort=809, + EndTime=DateTime.Parse("2018-09-27 20:00:00") + }; + var hex = JT809Serializer.Serialize(jT809_0X9500_0X9505).ToHexString(); + Assert.Equal("000000000000000008086A743830380000000000000000000000000000006164736C736D616C6C636869000000000000000000000000000000000000000000000000000000000000000000000000006164736C3132330000000000000000000000000000003132372E302E302E31000000000000000000000000000000000000000000000003280329000000005BACC640", hex); + //"00 00 00 00 00 00 00 00 08 08 6A 74 38 30 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 31 32 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 28 03 29 00 00 00 00 5B AC C6 40" + //"00 00 00 00 00 00 00 00 08 08 6A 74 38 30 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 31 32 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 28 03 29 00 00 00 00 5A 01 AC C6 40" + } + + [Fact] + public void Test2() + { + var bytes = "00 00 00 00 00 00 00 00 08 08 6A 74 38 30 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 73 6D 61 6C 6C 63 68 69 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 61 64 73 6C 31 32 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 32 37 2E 30 2E 30 2E 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 28 03 29 00 00 00 00 5B AC C6 40".ToHexBytes(); + JT809_0x9500_0x9505 jT809_0X9500_0X9505 = JT809Serializer.Deserialize(bytes); + Assert.Equal("808", jT809_0X9500_0X9505.AuthenticationCode); + Assert.Equal("jt808", jT809_0X9500_0X9505.AccessPointName); + Assert.Equal("adslsmallchi", jT809_0X9500_0X9505.UserName); + Assert.Equal("adsl123", jT809_0X9500_0X9505.Password); + Assert.Equal("127.0.0.1", jT809_0X9500_0X9505.ServerIP); + Assert.Equal(808, jT809_0X9500_0X9505.TcpPort); + Assert.Equal(809, jT809_0X9500_0X9505.UdpPort); + Assert.Equal(DateTime.Parse("2018-09-27 20:00:00"), jT809_0X9500_0X9505.EndTime); + } + } +} diff --git a/src/JT809.Protocol.Test/MessagePack/JT809MessagePackReaderTest.cs b/src/JT809.Protocol.Test/MessagePack/JT809MessagePackReaderTest.cs new file mode 100644 index 0000000..990f56b --- /dev/null +++ b/src/JT809.Protocol.Test/MessagePack/JT809MessagePackReaderTest.cs @@ -0,0 +1,30 @@ +using JT809.Protocol.MessagePack; +using JT809.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.MessagePack +{ + public class JT808MessagePackReaderTest + { + [Fact] + public void WriteCRC16Test() + { + var data = "5B000000480000008510010133EFB8010000000000270F0133EFB832303138303932303132372E302E302E31000000000000000000000000000000000000000000000003296A915D".ToHexBytes(); + JT809MessagePackReader jT809MessagePackReader = new JT809MessagePackReader(data); + jT809MessagePackReader.Decode(); + Assert.True(jT809MessagePackReader.CheckXorCodeVali); + } + + [Fact] + public void WriteCRC16Test1() + { + var data = "5A 01 00 5A 02 48 5E 02 5E 00 5E 01".ToHexBytes(); + JT809MessagePackReader jT809MessagePackReader = new JT809MessagePackReader(data); + jT809MessagePackReader.FullDecode(); + Assert.Equal("5B 00 5A 48 5E 5E 00 5D".ToHexBytes(), jT809MessagePackReader.Reader.ToArray()); + } + } +} diff --git a/src/JT809.Protocol.Test/MessagePack/JT809MessagePackWriterTest.cs b/src/JT809.Protocol.Test/MessagePack/JT809MessagePackWriterTest.cs new file mode 100644 index 0000000..edfbb5a --- /dev/null +++ b/src/JT809.Protocol.Test/MessagePack/JT809MessagePackWriterTest.cs @@ -0,0 +1,24 @@ +using JT809.Protocol.MessagePack; +using JT809.Protocol.Extensions; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT809.Protocol.Test.MessagePack +{ + public class JT809MessagePackWriterTest + { + [Fact] + public void WriteCRC16Test() + { + var bytes = new byte[4096]; + var data = "5B000000480000008510010133EFB8010000000000270F0133EFB832303138303932303132372E302E302E31000000000000000000000000000000000000000000000003296A915D".ToHexBytes(); + JT809MessagePackWriter jT809MessagePackWriter = new JT809MessagePackWriter(bytes); + jT809MessagePackWriter.WriteArray(data); + jT809MessagePackWriter.WriteEncode(); + var result=jT809MessagePackWriter.FlushAndGetEncodingArray(); + Assert.Equal(data, result); + } + } +} diff --git a/src/JT809.Protocol.sln b/src/JT809.Protocol.sln new file mode 100644 index 0000000..702c9bb --- /dev/null +++ b/src/JT809.Protocol.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28407.52 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol", "JT809.Protocol\JT809.Protocol.csproj", "{4D33A5C9-F583-4230-9791-AB0394EFAD57}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Test", "JT809.Protocol.Test\JT809.Protocol.Test.csproj", "{59D2D876-8D81-4CCE-839A-B153912C0C27}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Benchmark", "JT809.Protocol.Benchmark\JT809.Protocol.Benchmark.csproj", "{47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Extensions.DependencyInjection", "JT809.Protocol.Extensions.DependencyInjection\JT809.Protocol.Extensions.DependencyInjection.csproj", "{9C6AD175-2B56-46F6-8817-FA920720BEB2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Extensions.DependencyInjection.Test", "JT809.Protocol.Extensions.DependencyInjection.Test\JT809.Protocol.Extensions.DependencyInjection.Test.csproj", "{3A5D2CC3-4658-4C73-8C73-6E3B97740A66}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4D33A5C9-F583-4230-9791-AB0394EFAD57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D33A5C9-F583-4230-9791-AB0394EFAD57}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D33A5C9-F583-4230-9791-AB0394EFAD57}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D33A5C9-F583-4230-9791-AB0394EFAD57}.Release|Any CPU.Build.0 = Release|Any CPU + {59D2D876-8D81-4CCE-839A-B153912C0C27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {59D2D876-8D81-4CCE-839A-B153912C0C27}.Debug|Any CPU.Build.0 = Debug|Any CPU + {59D2D876-8D81-4CCE-839A-B153912C0C27}.Release|Any CPU.ActiveCfg = Release|Any CPU + {59D2D876-8D81-4CCE-839A-B153912C0C27}.Release|Any CPU.Build.0 = Release|Any CPU + {47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {47CE50B3-A0D6-4F5F-907B-01BD7B8AB87F}.Release|Any CPU.Build.0 = Release|Any CPU + {9C6AD175-2B56-46F6-8817-FA920720BEB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C6AD175-2B56-46F6-8817-FA920720BEB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C6AD175-2B56-46F6-8817-FA920720BEB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C6AD175-2B56-46F6-8817-FA920720BEB2}.Release|Any CPU.Build.0 = Release|Any CPU + {3A5D2CC3-4658-4C73-8C73-6E3B97740A66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A5D2CC3-4658-4C73-8C73-6E3B97740A66}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A5D2CC3-4658-4C73-8C73-6E3B97740A66}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A5D2CC3-4658-4C73-8C73-6E3B97740A66}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6159526D-F9A2-4984-A941-B65CA7B0E2EE} + EndGlobalSection +EndGlobal diff --git a/src/JT809.Protocol/Attributes/JT809BodiesTypeAttribute.cs b/src/JT809.Protocol/Attributes/JT809BodiesTypeAttribute.cs new file mode 100644 index 0000000..b7726fd --- /dev/null +++ b/src/JT809.Protocol/Attributes/JT809BodiesTypeAttribute.cs @@ -0,0 +1,14 @@ +using System; + +namespace JT809.Protocol.Attributes +{ + [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] + public sealed class JT809BodiesTypeAttribute : Attribute + { + public JT809BodiesTypeAttribute(Type jT809BodiesType) + { + JT809BodiesType = jT809BodiesType; + } + public Type JT809BodiesType { get;} + } +} diff --git a/src/JT809.Protocol/Attributes/JT809BusinessTypeDescriptionAttribute.cs b/src/JT809.Protocol/Attributes/JT809BusinessTypeDescriptionAttribute.cs new file mode 100644 index 0000000..0a0deae --- /dev/null +++ b/src/JT809.Protocol/Attributes/JT809BusinessTypeDescriptionAttribute.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Attributes +{ + [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] + public sealed class JT809BusinessTypeDescriptionAttribute : Attribute + { + public string Code { get; set; } + + public string Name { get; set; } + + public JT809BusinessTypeDescriptionAttribute(string code,string name) + { + Code = code; + Name = name; + } + } +} diff --git a/src/JT809.Protocol/Attributes/JT809FormatterAttribute.cs b/src/JT809.Protocol/Attributes/JT809FormatterAttribute.cs new file mode 100644 index 0000000..4b33038 --- /dev/null +++ b/src/JT809.Protocol/Attributes/JT809FormatterAttribute.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Attributes +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, AllowMultiple = false, Inherited = true)] + public sealed class JT809FormatterAttribute:Attribute + { + public Type FormatterType { get; private set; } + + public object[] Arguments { get; private set; } + + public JT809FormatterAttribute(Type formatterType) + { + this.FormatterType = formatterType; + } + + public JT809FormatterAttribute(Type formatterType, params object[] arguments) + { + this.FormatterType = formatterType; + this.Arguments = arguments; + } + } +} diff --git a/src/JT809.Protocol/Attributes/JT809SubBusinessTypeDescriptionAttribute.cs b/src/JT809.Protocol/Attributes/JT809SubBusinessTypeDescriptionAttribute.cs new file mode 100644 index 0000000..ed89e15 --- /dev/null +++ b/src/JT809.Protocol/Attributes/JT809SubBusinessTypeDescriptionAttribute.cs @@ -0,0 +1,24 @@ +using JT809.Protocol.Enums; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Attributes +{ + [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)] + public sealed class JT809SubBusinessTypeDescriptionAttribute : Attribute + { + public JT809BusinessType BusinessType { get; set; } + + public string Code { get; set; } + + public string Name { get; set; } + + public JT809SubBusinessTypeDescriptionAttribute(string code,string name, JT809BusinessType businessType) + { + Code = code; + Name = name; + BusinessType = businessType; + } + } +} diff --git a/src/JT809.Protocol/Buffers/JT809BufferWriter.cs b/src/JT809.Protocol/Buffers/JT809BufferWriter.cs new file mode 100644 index 0000000..76f422f --- /dev/null +++ b/src/JT809.Protocol/Buffers/JT809BufferWriter.cs @@ -0,0 +1,35 @@ +using System; + +namespace JT809.Protocol.Buffers +{ + /// + /// + /// + ref partial struct JT809BufferWriter + { + private Span _buffer; + public JT809BufferWriter(Span buffer) + { + _buffer = buffer; + WrittenCount = 0; + BeforeCodingWrittenPosition = 0; + } + public Span Free => _buffer.Slice(WrittenCount); + public Span Written => _buffer.Slice(0, WrittenCount); + /// + /// 编码之前的写入位置 + /// + public int BeforeCodingWrittenPosition { get;internal set; } + public int WrittenCount { get; private set; } + + public void Shrink(int count) + { + WrittenCount -= count; + } + + public void Advance(int count) + { + WrittenCount += count; + } + } +} diff --git a/src/JT809.Protocol/Configs/JT809EncryptOptions.cs b/src/JT809.Protocol/Configs/JT809EncryptOptions.cs new file mode 100644 index 0000000..c8c51b9 --- /dev/null +++ b/src/JT809.Protocol/Configs/JT809EncryptOptions.cs @@ -0,0 +1,9 @@ +namespace JT809.Protocol.Configs +{ + public class JT809EncryptOptions + { + public uint M1 { get; set; } + public uint IA1 { get; set; } + public uint IC1 { get; set; } + } +} diff --git a/src/JT809.Protocol/Configs/JT809HeaderOptions.cs b/src/JT809.Protocol/Configs/JT809HeaderOptions.cs new file mode 100644 index 0000000..2617e82 --- /dev/null +++ b/src/JT809.Protocol/Configs/JT809HeaderOptions.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Configs +{ + public class JT809HeaderOptions + { + /// + /// 下级平台接入码,上级平台给下级平台分配唯一标识码。 + /// + public uint MsgGNSSCENTERID { get; set; } + /// + /// 协议版本号标识,上下级平台之间采用的标准协议版 + /// 编号;长度为 3 个字节来表示,0x01 0x02 0x0F 标识 + /// 的版本号是 v1.2.15,以此类推。 + /// + public JT809Header_Version Version { get; set; } = new JT809Header_Version(); + /// + /// 报文加密标识位 b: 0 表示报文不加密,1 表示报文加密。 + /// + public JT809Header_Encrypt EncryptFlag { get; set; } = JT809Header_Encrypt.None; + /// + /// 数据加密的密匙,长度为 4 个字节 + /// + public uint EncryptKey { get; set; } + } +} diff --git a/src/JT809.Protocol/Encrypt/JT809EncryptImpl.cs b/src/JT809.Protocol/Encrypt/JT809EncryptImpl.cs new file mode 100644 index 0000000..ebedc75 --- /dev/null +++ b/src/JT809.Protocol/Encrypt/JT809EncryptImpl.cs @@ -0,0 +1,39 @@ +using JT809.Protocol.Configs; +using JT809.Protocol.Interfaces; +using System; + +namespace JT809.Protocol.Encrypt +{ + /// + /// JT809 异或加密解密为同一算法 + /// + public class JT809EncryptImpl : IJT809Encrypt + { + public byte[] Decrypt(ReadOnlySpan buffer, JT809EncryptOptions encryptOptions, uint privateKey) + { + return Encrypt(buffer, encryptOptions,privateKey); + } + + public byte[] Encrypt(ReadOnlySpan buffer, JT809EncryptOptions encryptOptions, uint privateKey) + { + byte[] data = new byte[buffer.Length]; + if (0 == privateKey) + { + privateKey = 1; + } + uint mkey = encryptOptions.M1; + if (0 == mkey) + { + mkey = 1; + } + for (int idx = 0; idx < buffer.Length; idx++) + { + privateKey = encryptOptions.IA1 * (privateKey % mkey) + encryptOptions.IC1; + byte tmp = buffer[idx]; + tmp ^= (byte)((privateKey >> 20) & 0xFF); + data[idx] = tmp; + } + return data; + } + } +} diff --git a/src/JT809.Protocol/Enums/JT808_Alarm.cs b/src/JT809.Protocol/Enums/JT808_Alarm.cs new file mode 100644 index 0000000..baefbd9 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT808_Alarm.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 报警标志 + /// + [Flags] + public enum JT808_Alarm : uint + { + /// + /// 紧急报警_触动报警开关后触发 + /// 收到应答后清零 + /// + 紧急报警_触动报警开关后触发 = 1, + /// + /// 超速报警 + /// 标志维持至报警条件解除 + /// + 超速报警 = 2, + /// + /// 标志维持至报警条件解除 + /// 疲劳驾驶 + /// + 疲劳驾驶 = 4, + /// + /// 危险预警 + /// 收到应答后清零 + /// + 危险预警 = 8, + /// + /// GNSS模块发生故障 + /// 标志维持至报警条件解除 + /// + GNSS模块发生故障=16, + /// + /// GNSS天线未接或被剪断 + /// 标志维持至报警条件解除 + /// + GNSS天线未接或被剪断 = 32, + /// + /// GNSS天线短路 + /// 标志维持至报警条件解除 + /// + GNSS天线短路 = 64, + /// + /// 终端主电源欠压 + /// 标志维持至报警条件解除 + /// + 终端主电源欠压 = 128, + /// + /// 终端主电源掉电 + /// 标志维持至报警条件解除 + /// + 终端主电源掉电 = 256, + /// + /// 终端LCD或显示器故障 + /// 标志维持至报警条件解除 + /// + 终端LCD或显示器故障 = 512, + /// + /// TTS模块故障 + /// 标志维持至报警条件解除 + /// + TTS模块故障 = 1024, + /// + /// 摄像头故障 + /// 标志维持至报警条件解除 + /// + 摄像头故障 = 2048, + /// + /// 道路运输证IC卡模块故障 + /// 标志维持至报警条件解除 + /// + 道路运输证IC卡模块故障 = 4096, + /// + /// 超速预警 + /// 标志维持至报警条件解除 + /// + 超速预警 = 8192, + /// + /// 疲劳驾驶预警 + /// 标志维持至报警条件解除 + /// + 疲劳驾驶预警 = 16384, + 保留1=32768, + 保留2=65536, + 保留3=131072, + /// + /// 当天累计驾驶超时 + /// 标志维持至报警条件解除 + /// + 当天累计驾驶超时 = 262144, + /// + /// 超时停车 + /// 标志维持至报警条件解除 + /// + 超时停车 = 524288, + /// + /// 进出区域 + /// 收到应答后清零 + /// + 进出区域 = 1048576, + /// + /// 进出路线 + /// 收到应答后清零 + /// + 进出路线 = 2097152, + /// + /// 路段行驶时间不足或过长 + /// 收到应答后清零 + /// + 路段行驶时间不足或过长= 4194304, + /// + /// 路线偏离报警 + /// 标志维持至报警条件解除 + /// + 路线偏离报警 = 8388608, + /// + /// 车辆VSS故障 + /// 标志维持至报警条件解除 + /// + 车辆VSS故障= 16777216, + /// + /// 车辆油量异常 + /// 标志维持至报警条件解除 + /// + 车辆油量异常 = 33554432, + /// + /// 车辆被盗通过车辆防盗器 + /// 标志维持至报警条件解除 + /// + 车辆被盗 = 67108864, + /// + /// 车辆非法点火 + /// + 车辆非法点火 = 134217728, + /// + /// 车辆非法位移 + /// 收到应答后清零 + /// + 车辆非法位移 = 268435456, + /// + /// 碰撞预警 + /// 标志维持至报警条件解除 + /// + 碰撞预警 = 536870912, + /// + /// 侧翻预警 + /// 标志维持至报警条件解除 + /// + 侧翻预警 = 1073741824, + /// + /// 非法开门报警 + /// (终端未设置区域时,不判断非法开门) + /// 收到应答后清零 + /// + 非法开门报警 = 2147483648 + } +} diff --git a/src/JT809.Protocol/Enums/JT808_Status.cs b/src/JT809.Protocol/Enums/JT808_Status.cs new file mode 100644 index 0000000..a8beb2d --- /dev/null +++ b/src/JT809.Protocol/Enums/JT808_Status.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + [Flags] + public enum JT808_Status : uint + { + ACC开 = 1, + 定位 = 2, + 南纬 = 4, + 西经 = 8, + 停运状态 = 16, + 经纬度已经保密插件加密 = 32, + //保留 = 64, + //保留 = 128, + 半载 = 256, + //保留 = 512, + 满载 = 768, + 车辆油路断开 = 1024, + 车辆电路断开 = 2048, + 车门加锁 = 4096, + 前门开 = 8192, + 中门开 = 16384, + 后门开 = 32768, + 驾驶席门开 = 65536, + 自定义 = 131072, + 使用GPS卫星进行定位 = 262144, + 使用北斗卫星进行定位 = 524288, + 使用GLONASS卫星进行定位 = 1048576, + 使用Galileo卫星进行定位 = 2097152 + } +} diff --git a/src/JT809.Protocol/Enums/JT809BusinessType.cs b/src/JT809.Protocol/Enums/JT809BusinessType.cs new file mode 100644 index 0000000..b747987 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809BusinessType.cs @@ -0,0 +1,246 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.MessageBody; +using System.ComponentModel; + +namespace JT809.Protocol.Enums +{ + /// + /// 业务数据类型标识 + /// 数据交换一协议规定的业务数据类型名称和标识常量定义见表 73。业务数据类型标识的命名规则如下: + /// a) 上级平台向下级平台发送的请求消息,一般以“DOWN_”开头,以后缀_REQ 结尾;而下级平台向上级平台发送的请求消息一般以“UP_”开头,以后缀_REQ 结尾; + /// b) 当上下级平台之间有应答消息情况下,应答消息可继续沿用对应的请求消息开头标识符,而通过后缀 RSP 来标识结尾。 + /// + public enum JT809BusinessType : ushort + { + #region 链路管理类 + /// + ///主链路登录请求消息 + ///UP_CONNECT_REQ + /// + [Description("主链路登录请求消息")] + [JT809BodiesType(typeof(JT809_0x1001))] + [JT809BusinessTypeDescription("UP_CONNECT_REQ", "主链路登录请求消息")] + 主链路登录请求消息 = 0x1001, + /// + ///主链路登录应答消息 + ///UP_CONNECT_RSP + /// + [Description("主链路登录应答消息")] + [JT809BusinessTypeDescription("UP_CONNECT_RSP", "主链路登录应答消息")] + [JT809BodiesType(typeof(JT809_0x1002))] + 主链路登录应答消息 = 0x1002, + /// + ///主链路注销请求消息 + ///UP_DISCONNECT_REQ + /// + [Description("主链路注销请求消息")] + [JT809BusinessTypeDescription("UP_DISCONNECT_REQ", "主链路注销请求消息")] + [JT809BodiesType(typeof(JT809_0x1003))] + 主链路注销请求消息 = 0x1003, + /// + ///主链路注销应答消息 + ///UP_DISCONNECT_RSP + /// + [Description("主链路注销应答消息")] + [JT809BodiesType(typeof(JT809_0x1004))] + [JT809BusinessTypeDescription("UP_DISCONNECT_RSP", "主链路注销应答消息")] + 主链路注销应答消息 = 0x1004, + /// + ///主链路连接保持请求消息 + ///UP_LINKTEST_REQ + /// + [Description("主链路连接保持请求消息")] + [JT809BodiesType(typeof(JT809_0x1005))] + [JT809BusinessTypeDescription("UP_LINKTEST_REQ", "主链路连接保持请求消息")] + 主链路连接保持请求消息 = 0x1005, + /// + ///主链路连接保持应答消息 + ///UP_LINKTEST_RSP + /// + [Description("主链路连接保持应答消息")] + [JT809BodiesType(typeof(JT809_0x1006))] + [JT809BusinessTypeDescription("UP_LINKTEST_RSP", "主链路连接保持应答消息")] + 主链路连接保持应答消息 = 0x1006, + /// + ///主链路断开通知消息 + ///UP_DISCONNECT_INFORM + /// + [Description("主链路断开通知消息")] + [JT809BodiesType(typeof(JT809_0x1007))] + [JT809BusinessTypeDescription("UP_DISCONNECT_INFORM", "主链路断开通知消息")] + 主链路断开通知消息 = 0x1007, + /// + ///下级平台主动关闭链路通知消息 + ///UP_CLOSELINK_INFORM + /// + [Description("下级平台主动关闭链路通知消息")] + [JT809BodiesType(typeof(JT809_0x1008))] + [JT809BusinessTypeDescription("UP_CLOSELINK_INFORM", "下级平台主动关闭链路通知消息")] + 下级平台主动关闭链路通知消息 = 0x1008, + /// + ///从链路连接请求消息 + ///DOWN_CONNECT_REQ + /// + [Description("从链路连接请求消息")] + [JT809BodiesType(typeof(JT809_0x9001))] + [JT809BusinessTypeDescription("DOWN_CONNECT_REQ", "从链路连接请求消息")] + 从链路连接请求消息 = 0x9001, + /// + ///从链路连接应答消息 + ///DOWN_CONNECT_RSP + /// + [Description("从链路连接应答消息")] + [JT809BodiesType(typeof(JT809_0x9002))] + [JT809BusinessTypeDescription("DOWN_CONNECT_RSP", "从链路连接应答消息")] + 从链路连接应答消息 = 0x9002, + /// + ///从链路注销请求消息 + ///DOWN_DISCONNECT_REQ + /// + [Description("从链路注销请求消息")] + [JT809BodiesType(typeof(JT809_0x9003))] + [JT809BusinessTypeDescription("DOWN_DISCONNECT_REQ", "从链路注销请求消息")] + 从链路注销请求消息 = 0x9003, + /// + ///从链路注销应答消息 + ///DOWN_DISCONNECT_RSP + /// + [Description("从链路注销应答消息")] + [JT809BodiesType(typeof(JT809_0x9004))] + [JT809BusinessTypeDescription("DOWN_DISCONNECT_RSP", "从链路注销应答消息")] + 从链路注销应答消息 = 0x9004, + /// + ///从链路连接保持请求消息 + ///DOWN_LINKTEST_REQ + /// + [Description("从链路连接保持请求消息")] + [JT809BodiesType(typeof(JT809_0x9005))] + [JT809BusinessTypeDescription("DOWN_LINKTEST_REQ", "从链路连接保持请求消息")] + 从链路连接保持请求消息 = 0x9005, + /// + ///从链路连接保持应答消息 + ///DOWN_LINKTEST_RSP + /// + [Description("从链路连接保持应答消息")] + [JT809BodiesType(typeof(JT809_0x9006))] + [JT809BusinessTypeDescription("DOWN_LINKTEST_RSP", "从链路连接保持应答消息")] + 从链路连接保持应答消息 = 0x9006, + /// + ///从链路断开通知消息 + ///DOWN_DISCONNECT_INFORM + /// + [Description("从链路断开通知消息")] + [JT809BodiesType(typeof(JT809_0x9007))] + [JT809BusinessTypeDescription("DOWN_DISCONNECT_INFORM", "从链路断开通知消息")] + 从链路断开通知消息 = 0x9007, + /// + ///上级平台主动关闭链路通知消息 + ///DOWN_CLOSELINK_INFORM + /// + [Description("上级平台主动关闭链路通知消息")] + [JT809BodiesType(typeof(JT809_0x9008))] + [JT809BusinessTypeDescription("DOWN_CLOSELINK_INFORM", "上级平台主动关闭链路通知消息")] + 上级平台主动关闭链路通知消息 = 0x9008, + #endregion + #region 信息统计类 + /// + ///接收定位信息数量通知消息 + ///DOWN_TOTAL_RECV_BACK_MSG + /// + [Description("接收定位信息数量通知消息")] + [JT809BodiesType(typeof(JT809_0x9101))] + [JT809BusinessTypeDescription("DOWN_TOTAL_RECV_BACK_MSG", "接收定位信息数量通知消息")] + 接收定位信息数量通知消息 = 0x9101, + #endregion + #region 车辆动态信息交换 + /// + ///主链路动态信息交换消息 + ///UP_EXG_MSG + /// + [Description("主链路动态信息交换消息")] + [JT809BodiesType(typeof(JT809_0x1200))] + [JT809BusinessTypeDescription("UP_EXG_MSG", "主链路动态信息交换消息")] + 主链路动态信息交换消息 = 0x1200, + /// + ///从链路动态信息交换消息 + ///DOWN_EXG_MSG + /// + [Description("从链路动态信息交换消息")] + [JT809BodiesType(typeof(JT809_0x9200))] + [JT809BusinessTypeDescription("DOWN_EXG_MSG", "从链路动态信息交换消息")] + 从链路动态信息交换消息 = 0x9200, + #endregion + #region 平台间信息交互类 + /// + ///主链路平台间信息交互消息 + ///UP_PLATFORM_MSG + /// + [Description("主链路平台间信息交互消息")] + [JT809BodiesType(typeof(JT809_0x1300))] + [JT809BusinessTypeDescription("UP_PLATFORM_MSG", "主链路平台间信息交互消息")] + 主链路平台间信息交互消息 = 0x1300, + /// + ///从链路平台间信息交互消息 + ///DOWN_PLATFORM_MSG + /// + [Description("从链路平台间信息交互消息")] + [JT809BodiesType(typeof(JT809_0x9300))] + [JT809BusinessTypeDescription("DOWN_PLATFORM_MSG", "从链路平台间信息交互消息")] + 从链路平台间信息交互消息 = 0x9300, + #endregion + #region 车辆报警信息交互类 + /// + ///主链路报警信息交互消息 + ///UP_WARN_MSG + /// + [Description("主链路报警信息交互消息")] + [JT809BodiesType(typeof(JT809_0x1400))] + [JT809BusinessTypeDescription("UP_WARN_MSG", "主链路报警信息交互消息")] + 主链路报警信息交互消息 = 0x1400, + /// + ///从链路报警信息交互消息 + ///DOWN_WARN_MSG + /// + [Description("从链路报警信息交互消息")] + [JT809BodiesType(typeof(JT809_0x9400))] + [JT809BusinessTypeDescription("DOWN_WARN_MSG", "从链路报警信息交互消息")] + 从链路报警信息交互消息 = 0x9400, + #endregion + #region 车辆监管类 + /// + ///主链路车辆监管消息 + ///UP_CTRL_MSG + /// + [Description("主链路车辆监管消息")] + [JT809BodiesType(typeof(JT809_0x1500))] + [JT809BusinessTypeDescription("UP_CTRL_MSG", "主链路车辆监管消息")] + 主链路车辆监管消息 = 0x1500, + /// + ///从链路车辆监管消息 + ///DOWN_CTRL_MSG + /// + [Description("从链路车辆监管消息")] + [JT809BodiesType(typeof(JT809_0x9500))] + [JT809BusinessTypeDescription("DOWN_CTRL_MSG", "从链路车辆监管消息")] + 从链路车辆监管消息 = 0x9500, + #endregion + #region 车辆静态信息交换类 + /// + ///主链路静态信息交换消息 + ///UP_BASE_MSG + /// + [Description("主链路静态信息交换消息")] + [JT809BodiesType(typeof(JT809_0x1600))] + [JT809BusinessTypeDescription("UP_BASE_MSG", "主链路静态信息交换消息")] + 主链路静态信息交换消息 = 0x1600, + /// + ///从链路静态信息交换消息 + ///DOWN_BASE_MSG + /// + [Description("从链路静态信息交换消息")] + [JT809BodiesType(typeof(JT809_0x9600))] + [JT809BusinessTypeDescription("DOWN_BASE_MSG", "从链路静态信息交换消息")] + 从链路静态信息交换消息 = 0x9600, + #endregion + } +} diff --git a/src/JT809.Protocol/Enums/JT809CommandType.cs b/src/JT809.Protocol/Enums/JT809CommandType.cs new file mode 100644 index 0000000..ce56196 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809CommandType.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 命令字ID + /// + public enum JT809CommandType:byte + { + 记录仪标准版本=0x00, + 当前驾驶人信息=0x01, + 记录仪时间=0x02, + 记录仪累计行驶里程=0x03, + 记录仪脉冲系数=0x04, + 车辆信息 = 0x05, + 记录仪状态信号配置信息 = 0x06, + 记录仪唯一性编号 = 0x07, + 采集记录仪行驶记录 = 0x08, + 采集记录仪位置信息记录 = 0x09, + 采集记录仪事故疑点记录 = 0x10, + 采集记录仪超时驾驶记录 = 0x11, + 采集记录仪驾驶人身份记录=0x12, + 采集记录仪外部供电记录=0x13, + 采集记录仪参数修改记录 = 0x14, + 采集记录仪速度状态日志 = 0x15, + } +} diff --git a/src/JT809.Protocol/Enums/JT809ErrorCode.cs b/src/JT809.Protocol/Enums/JT809ErrorCode.cs new file mode 100644 index 0000000..a369807 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809ErrorCode.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + public enum JT809ErrorCode + { + CRC16CheckInvalid = 1001, + HeaderLengthNotEqualBodyLength=1002, + GetFormatterError=1003, + SerializeError=1004, + DeserializeError=1005, + HeaderParseError=1006, + BodiesParseError=1007, + SubBodiesParseError = 1008, + GetAttributeError=1009 + } +} diff --git a/src/JT809.Protocol/Enums/JT809SubBusinessType.cs b/src/JT809.Protocol/Enums/JT809SubBusinessType.cs new file mode 100644 index 0000000..7fbc926 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809SubBusinessType.cs @@ -0,0 +1,394 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.SubMessageBody; +using System.ComponentModel; + +namespace JT809.Protocol.Enums +{ + /// + ///子业务类型标识 + /// + public enum JT809SubBusinessType : ushort + { + None=0x0000, + #region 主链路动态信息交换消息 UP_EXG_MSG + /// + /// 上传车辆注册信息 + /// UP_EXG_MSG_REGISTER + /// + [Description("上传车辆注册信息")] + [JT809BodiesType(typeof(JT809_0x1200_0x1201))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_REGISTER", "上传车辆注册信息", JT809BusinessType.主链路动态信息交换消息)] + 上传车辆注册信息 = 0x1201, + /// + ///实时上传车辆定位信息 + ///UP_EXG_MSG_REAL_LOCATION + /// + [Description("实时上传车辆定位信息")] + [JT809BodiesType(typeof(JT809_0x1200_0x1202))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_REAL_LOCATION", "实时上传车辆定位信息", JT809BusinessType.主链路动态信息交换消息)] + 实时上传车辆定位信息 = 0x1202, + /// + ///车辆定位信息自动补报 + ///UP_EXG_MSG_HISTORY_LOCATION + /// + [Description("车辆定位信息自动补报")] + [JT809BodiesType(typeof(JT809_0x1200_0x1203))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_HISTORY_LOCATION", "车辆定位信息自动补报", JT809BusinessType.主链路动态信息交换消息)] + 车辆定位信息自动补报 = 0x1203, + /// + ///启动车辆定位信息交换应答 + ///UP_EXG_MSG_RETURN_STARTUP_ACK + /// + [Description("启动车辆定位信息交换应答")] + [JT809BodiesType(typeof(JT809_0x1200_0x1205))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_RETURN_STARTUP_ACK", "启动车辆定位信息交换应答", JT809BusinessType.主链路动态信息交换消息)] + 启动车辆定位信息交换应答 = 0x1205, + /// + ///结束车辆定位信息交换应答 + ///UP_EXG_MSG_RETURN_END_ACK + /// + [Description("结束车辆定位信息交换应答")] + [JT809BodiesType(typeof(JT809_0x1200_0x1206))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_RETURN_END_ACK", "结束车辆定位信息交换应答", JT809BusinessType.主链路动态信息交换消息)] + 结束车辆定位信息交换应答 = 0x1206, + /// + ///申请交换指定车辆定位信息请求 + ///UP_EXG_MSG_APPLY_FOR_MONITOR_STARTUP + /// + [Description("申请交换指定车辆定位信息请求")] + [JT809BodiesType(typeof(JT809_0x1200_0x1207))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_APPLY_FOR_MONITOR_STARTUP", "申请交换指定车辆定位信息请求", JT809BusinessType.主链路动态信息交换消息)] + 申请交换指定车辆定位信息请求 = 0x1207, + /// + ///取消交换指定车辆定位信息请求 + ///UP_EXG_MSG_APPLY_FOR_MONITOR_END + /// + [Description("取消交换指定车辆定位信息请求")] + [JT809BodiesType(typeof(JT809_0x1200_0x1208))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_APPLY_FOR_MONITOR_END", "取消交换指定车辆定位信息请求", JT809BusinessType.主链路动态信息交换消息)] + 取消交换指定车辆定位信息请求 = 0x1208, + /// + ///补发车辆定位信息请求 + ///UP_EXG_MSG_APPLY_HISGNSSDATA_REQ + /// + [Description("补发车辆定位信息请求")] + [JT809BodiesType(typeof(JT809_0x1200_0x1209))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_APPLY_HISGNSSDATA_REQ", "补发车辆定位信息请求", JT809BusinessType.主链路动态信息交换消息)] + 补发车辆定位信息请求 = 0x1209, + /// + ///上报车辆驾驶员身份识别信息应答 + ///UP_EXG_MSG_REPORT_DRIVER_INFO_ACK + /// + [Description("上报车辆驾驶员身份识别信息应答")] + [JT809BodiesType(typeof(JT809_0x1200_0x120A))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_REPORT_DRIVER_INFO_ACK", "上报车辆驾驶员身份识别信息应答", JT809BusinessType.主链路动态信息交换消息)] + 上报车辆驾驶员身份识别信息应答 = 0x120A, + /// + ///上报车辆电子运单应答 + ///UP_EXG_MSG_TAKE_EWAYBILL_ACK + /// + [Description("上报车辆电子运单应答")] + [JT809BodiesType(typeof(JT809_0x1200_0x120B))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_TAKE_EWAYBILL_ACK", "上报车辆电子运单应答", JT809BusinessType.主链路动态信息交换消息)] + 上报车辆电子运单应答 = 0x120B, + /// + ///主动上报驾驶员身份信息 + ///UP_EXG_MSG_REPORT_DRIVER_INFO + /// + [Description("主动上报驾驶员身份信息")] + [JT809BodiesType(typeof(JT809_0x1200_0x120C))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_REPORT_DRIVER_INFO", "主动上报驾驶员身份信息", JT809BusinessType.主链路动态信息交换消息)] + 主动上报驾驶员身份信息 = 0x120C, + /// + ///主动上报车辆电子运单信息 + ///UP_EXG_MSG_REPORT_EWAYBILL_INFO + /// + [Description("主动上报车辆电子运单信息")] + [JT809BodiesType(typeof(JT809_0x1200_0x120D))] + [JT809SubBusinessTypeDescription("UP_EXG_MSG_REPORT_EWAYBILL_INFO", "主动上报车辆电子运单信息", JT809BusinessType.主链路动态信息交换消息)] + 主动上报车辆电子运单信息 = 0x120D, + #endregion + + #region 从链路动态信息交换消息 DOWN_EXG_MSG + /// + ///交换车辆定位信息 + ///DOWN_EXG_MSG_CAR_LOCATION + /// + [Description("交换车辆定位信息")] + [JT809BodiesType(typeof(JT809_0x9200_0x9202))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_CAR_LOCATION", "交换车辆定位信息", JT809BusinessType.从链路动态信息交换消息)] + 交换车辆定位信息 = 0x9202, + /// + ///车辆定位信息交换补发 + ///DOWN_EXG_MSG_HISTORY_ARCOSSAREA + /// + [Description("车辆定位信息交换补发")] + [JT809BodiesType(typeof(JT809_0x9200_0x9203))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_HISTORY_ARCOSSAREA", "车辆定位信息交换补发", JT809BusinessType.从链路动态信息交换消息)] + 车辆定位信息交换补发 = 0x9203, + /// + ///交换车辆静态信息 + ///DOWN_EXG_MSG_CAR_INFO + /// + [Description("交换车辆静态信息")] + [JT809BodiesType(typeof(JT809_0x9200_0x9204))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_CAR_INFO", "交换车辆静态信息", JT809BusinessType.从链路动态信息交换消息)] + 交换车辆静态信息 = 0x9204, + /// + ///启动车辆定位信息交换请求 + ///DOWN_EXG_MSG_RETURN_STARTUP + /// + [Description("启动车辆定位信息交换请求")] + [JT809BodiesType(typeof(JT809_0x9200_0x9205))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_RETURN_STARTUP", "启动车辆定位信息交换请求", JT809BusinessType.从链路动态信息交换消息)] + 启动车辆定位信息交换请求 = 0x9205, + /// + ///结束车辆定位信息交换请求 + /// + [Description("结束车辆定位信息交换请求")] + [JT809BodiesType(typeof(JT809_0x9200_0x9206))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_RETURN_END", "结束车辆定位信息交换请求", JT809BusinessType.从链路动态信息交换消息)] + 结束车辆定位信息交换请求 = 0x9206, + /// + ///申请交换指定车辆定位信息应答 + ///DOWN_EXG_MSG_APPLY_FOR_MONITOR_STARTUP_ACK + /// + [Description("申请交换指定车辆定位信息应答")] + [JT809BodiesType(typeof(JT809_0x9200_0x9207))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_APPLY_FOR_MONITOR_STARTUP_ACK", "申请交换指定车辆定位信息应答", JT809BusinessType.从链路动态信息交换消息)] + 申请交换指定车辆定位信息应答 = 0x9207, + /// + ///取消交换指定车辆定位信息应答 + ///DOWN_EXG_MSG_APPLY_FOR_MONITOR_END_ACK + /// + [Description("取消交换指定车辆定位信息应答")] + [JT809BodiesType(typeof(JT809_0x9200_0x9208))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_APPLY_FOR_MONITOR_END_ACK", "取消交换指定车辆定位信息应答", JT809BusinessType.从链路动态信息交换消息)] + 取消交换指定车辆定位信息应答 = 0x9208, + /// + ///补发车辆定位信息应答 + ///DOWN_EXG_MSG_APPLY_HISGNSSDATA_ACK + /// + [Description("补发车辆定位信息应答")] + [JT809BodiesType(typeof(JT809_0x9200_0x9209))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_APPLY_HISGNSSDATA_ACK", "补发车辆定位信息应答", JT809BusinessType.从链路动态信息交换消息)] + 补发车辆定位信息应答 = 0x9209, + /// + ///上报车辆驾驶员身份识别信息请求 + ///DOWN_EXG_MSG_REPORT_DRIVER_INFO + /// + [Description("上报车辆驾驶员身份识别信息请求")] + [JT809BodiesType(typeof(JT809_0x9200_0x920A))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_REPORT_DRIVER_INFO", "上报车辆驾驶员身份识别信息请求", JT809BusinessType.从链路动态信息交换消息)] + 上报车辆驾驶员身份识别信息请求 = 0x920A, + /// + ///上报车辆电子运单请求 + ///DOWN_EXG_MSG_TAKE_EWAYBILL_REQ + /// + [Description("上报车辆电子运单请求")] + [JT809BodiesType(typeof(JT809_0x9200_0x920B))] + [JT809SubBusinessTypeDescription("DOWN_EXG_MSG_TAKE_EWAYBILL_REQ", "上报车辆电子运单请求", JT809BusinessType.从链路动态信息交换消息)] + 上报车辆电子运单请求 = 0x920B, + #endregion + + #region 主链路平台信息交互消息 UP_PLATFORM_MSG + /// + ///平台查岗应答 + ///UP_PLATFORM_MSG_POST_QUERY_ACK + /// + [Description("平台查岗应答")] + [JT809BodiesType(typeof(JT809_0x1300_0x1301))] + [JT809SubBusinessTypeDescription("UP_PLATFORM_MSG_POST_QUERY_ACK", "平台查岗应答", JT809BusinessType.主链路平台间信息交互消息)] + 平台查岗应答 = 0x1301, + /// + ///下发平台间报文应答 + ///UP_PLATFORM_MSG_INFO_ACK + /// + [Description("下发平台间报文应答")] + [JT809BodiesType(typeof(JT809_0x1300_0x1302))] + [JT809SubBusinessTypeDescription("UP_PLATFORM_MSG_INFO_ACK", "下发平台间报文应答", JT809BusinessType.主链路平台间信息交互消息)] + 下发平台间报文应答 = 0x1302, + #endregion + + #region 从链路平台信息交互消息 DOWN_PLATFORM_MSG + /// + ///平台查岗请求 + ///DOWN_PLATFORM_MSG_POST_QUERY_REQ + /// + [Description("平台查岗请求")] + [JT809BodiesType(typeof(JT809_0x9300_0x9301))] + [JT809SubBusinessTypeDescription("DOWN_PLATFORM_MSG_POST_QUERY_REQ", "平台查岗请求", JT809BusinessType.从链路平台间信息交互消息)] + 平台查岗请求 = 0x9301, + /// + ///下发平台间报文请求 + ///DOWN_PLATFORM_MSG_INFO_REQ + /// + [Description("下发平台间报文请求")] + [JT809BodiesType(typeof(JT809_0x9300_0x9302))] + [JT809SubBusinessTypeDescription("DOWN_PLATFORM_MSG_INFO_REQ", "下发平台间报文请求", JT809BusinessType.从链路平台间信息交互消息)] + 下发平台间报文请求 = 0x9302, + #endregion + + #region 主链路报警信息交互消息 UP_WARN_MSG + /// + ///报警督办应答 + ///UP_WARN_MSG_URGE_TODO_ACK + /// + [Description("报警督办应答")] + [JT809BodiesType(typeof(JT809_0x1400_0x1401))] + [JT809SubBusinessTypeDescription("UP_WARN_MSG_URGE_TODO_ACK", "报警督办应答", JT809BusinessType.主链路报警信息交互消息)] + 报警督办应答 = 0x1401, + /// + ///上报报警信息 + ///UP_WARN_MSG_ADPT_INFO + /// + [Description("上报报警信息")] + [JT809BodiesType(typeof(JT809_0x1400_0x1402))] + [JT809SubBusinessTypeDescription("UP_WARN_MSG_ADPT_INFO", "上报报警信息", JT809BusinessType.主链路报警信息交互消息)] + 上报报警信息 = 0x1402, + /// + ///主动上报报警处理结果信息 + ///UP_WARN_MSG_ADPT_TODO_INFO + /// + [Description("主动上报报警处理结果信息")] + [JT809BodiesType(typeof(JT809_0x1400_0x1403))] + [JT809SubBusinessTypeDescription("UP_WARN_MSG_ADPT_TODO_INFO", "主动上报报警处理结果信息", JT809BusinessType.主链路报警信息交互消息)] + 主动上报报警处理结果信息 = 0x1403, + #endregion + + #region 从链路报警信息交互消息 DOWN_WARN_MSG + /// + ///报警督办请求 + ///DOWN_WARN_MSG_URGE_TODO_REQ + /// + [Description("报警督办请求")] + [JT809BodiesType(typeof(JT809_0x9400_0x9401))] + [JT809SubBusinessTypeDescription("DOWN_WARN_MSG_URGE_TODO_REQ", "报警督办请求", JT809BusinessType.从链路报警信息交互消息)] + 报警督办请求 = 0x9401, + /// + ///报警预警 + ///DOWN_WARN_MSG_INFORM_TIPS + /// + [Description("报警预警")] + [JT809BodiesType(typeof(JT809_0x9400_0x9402))] + [JT809SubBusinessTypeDescription("DOWN_WARN_MSG_INFORM_TIPS", "报警预警", JT809BusinessType.从链路报警信息交互消息)] + 报警预警 = 0x9402, + /// + ///实时交换报警信息 + ///DOWN_WARN_MSG_EXG_INFORM + /// + [Description("实时交换报警信息")] + [JT809BodiesType(typeof(JT809_0x9400_0x9403))] + [JT809SubBusinessTypeDescription("DOWN_WARN_MSG_EXG_INFORM", "实时交换报警信息", JT809BusinessType.从链路报警信息交互消息)] + 实时交换报警信息 = 0x9403, + #endregion + + #region 主链路车辆监管消息 UP_CTRL_MSG + /// + ///车辆单向监听应答 + ///UP_CTRL_MSG_MONITOR_VEHICLE_ACK + /// + [Description("车辆单向监听应答")] + [JT809BodiesType(typeof(JT809_0x1500_0x1501))] + [JT809SubBusinessTypeDescription("UP_CTRL_MSG_MONITOR_VEHICLE_ACK", "车辆单向监听应答", JT809BusinessType.主链路车辆监管消息)] + 车辆单向监听应答 = 0x1501, + /// + ///车辆拍照应答 + ///UP_CTRL_MSG_TAKE_PHOTO_ACK + /// + [Description("车辆拍照应答")] + [JT809BodiesType(typeof(JT809_0x1500_0x1502))] + [JT809SubBusinessTypeDescription("UP_CTRL_MSG_TAKE_PHOTO_ACK", "车辆拍照应答", JT809BusinessType.主链路车辆监管消息)] + 车辆拍照应答 = 0x1502, + /// + ///下发车辆报文应答 + ///UP_CTRL_MSG_TEXT_INFO_ACK + /// + [Description("下发车辆报文应答")] + [JT809BodiesType(typeof(JT809_0x1500_0x1503))] + [JT809SubBusinessTypeDescription("UP_CTRL_MSG_TEXT_INFO_ACK", "下发车辆报文应答", JT809BusinessType.主链路车辆监管消息)] + 下发车辆报文应答 = 0x1503, + /// + ///上报车辆行驶记录应答 + ///UP_CTRL_MSG_TAKE_TRAVEL_ACK + /// + [Description("上报车辆行驶记录应答")] + [JT809BodiesType(typeof(JT809_0x1500_0x1504))] + [JT809SubBusinessTypeDescription("UP_CTRL_MSG_TAKE_TRAVEL_ACK", "上报车辆行驶记录应答", JT809BusinessType.主链路车辆监管消息)] + 上报车辆行驶记录应答 = 0x1504, + /// + ///车辆应急接入监管平台应答消息 + ///UP_CTRL_MSG_EMERGENCY_MONITORING_ACK + /// + [Description("车辆应急接入监管平台应答消息")] + [JT809BodiesType(typeof(JT809_0x1500_0x1505))] + [JT809SubBusinessTypeDescription("UP_CTRL_MSG_EMERGENCY_MONITORING_ACK", "车辆应急接入监管平台应答消息", JT809BusinessType.主链路车辆监管消息)] + 车辆应急接入监管平台应答消息 = 0x1505, + #endregion + + #region 从链路车辆监管消息 DOWN_CTRL_MSG + /// + ///车辆单向监听请求 + ///DOWN_CTRL_MSG_MONITOR_VEHICLE_REQ + /// + [Description("车辆单向监听请求")] + [JT809BodiesType(typeof(JT809_0x9500_0x9501))] + [JT809SubBusinessTypeDescription("DOWN_CTRL_MSG_MONITOR_VEHICLE_REQ", "车辆单向监听请求", JT809BusinessType.从链路车辆监管消息)] + 车辆单向监听请求 = 0x9501, + /// + ///车辆拍照请求 + ///DOWN_CTRL_MSG_TAKE_PHOTO_REQ + /// + [Description("车辆拍照请求")] + [JT809BodiesType(typeof(JT809_0x9500_0x9502))] + [JT809SubBusinessTypeDescription("DOWN_CTRL_MSG_TAKE_PHOTO_REQ", "车辆拍照请求", JT809BusinessType.从链路车辆监管消息)] + 车辆拍照请求 = 0x9502, + /// + ///下发车辆报文请求 + ///DOWN_CTRL_MSG_TEXT_INFO + /// + [Description("下发车辆报文请求")] + [JT809BodiesType(typeof(JT809_0x9500_0x9503))] + [JT809SubBusinessTypeDescription("DOWN_CTRL_MSG_TEXT_INFO", "下发车辆报文请求", JT809BusinessType.从链路车辆监管消息)] + 下发车辆报文请求 = 0x9503, + /// + ///上报车辆行驶记录请求 + ///DOWN_CTRL_MSG_TAKE_TRAVEL_REQ + /// + [Description("上报车辆行驶记录请求")] + [JT809BodiesType(typeof(JT809_0x9500_0x9504))] + [JT809SubBusinessTypeDescription("DOWN_CTRL_MSG_TAKE_TRAVEL_REQ", "上报车辆行驶记录请求", JT809BusinessType.从链路车辆监管消息)] + 上报车辆行驶记录请求 = 0x9504, + /// + ///车辆应急接入监管平台请求消息 + ///DOWN_CTRL_MSG_EMERGENCY_MONITORING_REQ + /// + [Description("车辆应急接入监管平台请求消息")] + [JT809BodiesType(typeof(JT809_0x9500_0x9505))] + [JT809SubBusinessTypeDescription("DOWN_CTRL_MSG_EMERGENCY_MONITORING_REQ", "车辆应急接入监管平台请求消息", JT809BusinessType.从链路车辆监管消息)] + 车辆应急接入监管平台请求消息 = 0x9505, + #endregion + + #region 主链路静态信息交换消息 UP_BASE_MSG + /// + ///补报车辆静态信息应答 + ///UP_BASE_MSG_VEHICLE_ADDED_ACK + /// + [Description("补报车辆静态信息应答")] + [JT809BodiesType(typeof(JT809_0x1600_0x1601))] + [JT809SubBusinessTypeDescription("UP_BASE_MSG_VEHICLE_ADDED_ACK", "补报车辆静态信息应答", JT809BusinessType.主链路静态信息交换消息)] + 补报车辆静态信息应答 = 0x1601, + #endregion + + #region 从链路静态信息交换消息 DOWN_BASE_MSG + /// + ///补报车辆静态信息请求 + ///DOWN_BASE_MSG_VEHICLE_ADDED + /// + [Description("补报车辆静态信息请求")] + [JT809BodiesType(typeof(JT809_0x9600_0x9601))] + [JT809SubBusinessTypeDescription("DOWN_BASE_MSG_VEHICLE_ADDED", "补报车辆静态信息请求", JT809BusinessType.从链路静态信息交换消息)] + 补报车辆静态信息请求 = 0x9601, + #endregion + } +} diff --git a/src/JT809.Protocol/Enums/JT809VehicleColorType.cs b/src/JT809.Protocol/Enums/JT809VehicleColorType.cs new file mode 100644 index 0000000..0e9af58 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809VehicleColorType.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 车辆颜色,按照 JT/T415-2006 中5.4.12 的规定 + /// + public enum JT809VehicleColorType:byte + { + 蓝色=0x01, + 黄色=0x02, + 黑色 = 0x03, + 白色 = 0x04, + 其他 =0x09, + } +} diff --git a/src/JT809.Protocol/Enums/JT809WarnSrc.cs b/src/JT809.Protocol/Enums/JT809WarnSrc.cs new file mode 100644 index 0000000..f798118 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809WarnSrc.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 报警信息来源 + /// + public enum JT809WarnSrc : byte + { + 车载终端 = 0x01, + 企业监控平台 = 0x02, + 政府监管平台 = 0x03, + 其他 =0x09 + } +} diff --git a/src/JT809.Protocol/Enums/JT809WarnType.cs b/src/JT809.Protocol/Enums/JT809WarnType.cs new file mode 100644 index 0000000..7316532 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809WarnType.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 报警类型 + /// + public enum JT809WarnType:ushort + { + 超速报警=0x0001, + 疲劳驾驶报警=0x0002, + 紧急报警= 0x0003, + 进入指定区域报警= 0x0004, + 离开指定区域报警= 0x0005, + 路段赌赛报警= 0x0006, + 危险路段报警= 0x0007, + 越界报警= 0x0008, + 盗警= 0x0009, + 劫警= 0x000A, + 偏离路线报警= 0x000B, + 车辆移动报警= 0x000C, + 超时驾驶报警= 0x000D, + 其他报警= 0x000E + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1002_Result.cs b/src/JT809.Protocol/Enums/JT809_0x1002_Result.cs new file mode 100644 index 0000000..13f42a2 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1002_Result.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 验证结果 + /// + public enum JT809_0x1002_Result:byte + { + 成功=0x00, + IP地址不正确=0x01, + 接入码不正确=0x02, + 用户没用注册=0x03, + 密码错误=0x04, + 资源紧张_稍后再连接_已经占用= 0x05, + 其他 =0x06 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1007_ErrorCode.cs b/src/JT809.Protocol/Enums/JT809_0x1007_ErrorCode.cs new file mode 100644 index 0000000..336f7e1 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1007_ErrorCode.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 错误代码 + /// + public enum JT809_0x1007_ErrorCode:byte + { + 主链路断开=0x00, + 其他原因=0x01 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1008_ReasonCode.cs b/src/JT809.Protocol/Enums/JT809_0x1008_ReasonCode.cs new file mode 100644 index 0000000..9d5c924 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1008_ReasonCode.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 错误代码 + /// + public enum JT809_0x1008_ReasonCode:byte + { + 网关重启=0x00, + 其他原因=0x01 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1301_ObjectType.cs b/src/JT809.Protocol/Enums/JT809_0x1301_ObjectType.cs new file mode 100644 index 0000000..fb4e568 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1301_ObjectType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 查岗对象的类型 + /// + public enum JT809_0x1301_ObjectType:byte + { + 当前连接的下级平台=0x01, + 下级平台所属单一业户=0x02, + 下级平台所属所有业户=0x03 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1401_Result.cs b/src/JT809.Protocol/Enums/JT809_0x1401_Result.cs new file mode 100644 index 0000000..fd2b19c --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1401_Result.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 报警处理结果 + /// + public enum JT809_0x1401_Result : byte + { + 处理中 = 0x00, + 已处理完毕 = 0x01, + 不做处理 = 0x02, + 将来处理 = 0x03 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1403_Result.cs b/src/JT809.Protocol/Enums/JT809_0x1403_Result.cs new file mode 100644 index 0000000..e7eaef4 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1403_Result.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 报警处理结果 + /// + public enum JT809_0x1403_Result : byte + { + 处理中 = 0x00, + 已处理完毕 = 0x01, + 不做处理 = 0x02, + 将来处理 = 0x03 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1501_Result.cs b/src/JT809.Protocol/Enums/JT809_0x1501_Result.cs new file mode 100644 index 0000000..5774691 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1501_Result.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 应答结果 + /// + public enum JT809_0x1501_Result : byte + { + 监听成功 = 0x00, + 监听失败 = 0x01 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1502_PhotoRspFlag.cs b/src/JT809.Protocol/Enums/JT809_0x1502_PhotoRspFlag.cs new file mode 100644 index 0000000..691f349 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1502_PhotoRspFlag.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 拍照应答标识 + /// + public enum JT809_0x1502_PhotoRspFlag : byte + { + 不支持拍照 = 0x00, + 完成拍照 = 0x01, + 完成拍照_照片数据稍后传送 = 0x02, + 未拍照_不在线 = 0x03, + 未拍照_无法使用指定镜头 = 0x04, + 未拍照_其他原因 = 0x05, + 车牌号码错误 = 0x09, + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1503_Result.cs b/src/JT809.Protocol/Enums/JT809_0x1503_Result.cs new file mode 100644 index 0000000..40fcb62 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1503_Result.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 应答结果 + /// + public enum JT809_0x1503_Result : byte + { + 下发成功 = 0x00, + 下发失败 = 0x01, + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x1505_Result.cs b/src/JT809.Protocol/Enums/JT809_0x1505_Result.cs new file mode 100644 index 0000000..6ebf41d --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x1505_Result.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 应答结果 + /// + public enum JT809_0x1505_Result : byte + { + 车载终端成功收到该命令 = 0x00, + 无该车辆 = 0x01, + 其它原因失败=0x02 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9002_Result.cs b/src/JT809.Protocol/Enums/JT809_0x9002_Result.cs new file mode 100644 index 0000000..4dfc1ae --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9002_Result.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 验证结果 + /// + public enum JT809_0x9002_Result:byte + { + 成功=0x00, + VERIFY_CODE错误= 0x01, + 资源紧张_稍后再连接_已经占用= 0x02, + 其他= 0x03 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9007_ReasonCode.cs b/src/JT809.Protocol/Enums/JT809_0x9007_ReasonCode.cs new file mode 100644 index 0000000..1547bb2 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9007_ReasonCode.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 错误代码 + /// + public enum JT809_0x9007_ReasonCode : byte + { + 无法连接下级平台指定的服务IP与端口 = 0x00, + 上级平台客户端与下级平台服务端断开 = 0x01, + 其他原因=0x02 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9008_ReasonCode.cs b/src/JT809.Protocol/Enums/JT809_0x9008_ReasonCode.cs new file mode 100644 index 0000000..b7bbdf1 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9008_ReasonCode.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 错误代码 + /// + public enum JT809_0x9008_ReasonCode:byte + { + 网关重启=0x00, + 其它原因=0x01 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9205_ReasonCode.cs b/src/JT809.Protocol/Enums/JT809_0x9205_ReasonCode.cs new file mode 100644 index 0000000..e8428ea --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9205_ReasonCode.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 错误代码 + /// + public enum JT809_0x9205_ReasonCode : byte + { + 车辆进入指定区域 = 0x00, + 人工指定交换 = 0x01, + 应急状态下车辆定位信息回传 = 0x02, + 其它原因 = 0x03 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9206_ReasonCode.cs b/src/JT809.Protocol/Enums/JT809_0x9206_ReasonCode.cs new file mode 100644 index 0000000..e428c0b --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9206_ReasonCode.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 错误代码 + /// + public enum JT809_0x9206_ReasonCode : byte + { + 车辆离开指定区域 = 0x00, + 人工停止交换 = 0x01, + 紧急监控完成 = 0x02, + 车辆离线 = 0x03, + 其它原因 = 0x04 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9207_Result.cs b/src/JT809.Protocol/Enums/JT809_0x9207_Result.cs new file mode 100644 index 0000000..6b5147b --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9207_Result.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 验证结果 + /// + public enum JT809_0x9207_Result : byte + { + 申请成功 = 0x00, + 上级平台没有该车数据 = 0x01, + 申请时间段错误 = 0x02, + 其它 = 0x03 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9208_Result.cs b/src/JT809.Protocol/Enums/JT809_0x9208_Result.cs new file mode 100644 index 0000000..647e824 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9208_Result.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 验证结果 + /// + public enum JT809_0x9208_Result : byte + { + 取消申请成功 = 0x00, + 之前没有对应申请信息 = 0x01, + 其它 = 0x02 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9209_Result.cs b/src/JT809.Protocol/Enums/JT809_0x9209_Result.cs new file mode 100644 index 0000000..b549bdb --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9209_Result.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 验证结果 + /// + public enum JT809_0x9209_Result : byte + { + 成功_上级平台即刻补发 = 0x00, + 成功_上级平台择机补发 = 0x01, + 失败_上级平台无对应申请的定位数据 = 0x02, + 失败_申请内容不正确 = 0x03, + 其它原因 = 0x04, + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9301_ObjectType.cs b/src/JT809.Protocol/Enums/JT809_0x9301_ObjectType.cs new file mode 100644 index 0000000..021ab20 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9301_ObjectType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 查岗对象的类型 + /// + public enum JT809_0x9301_ObjectType : byte + { + 当前连接的下级平台=0x01, + 下级平台所属单一业户=0x02, + 下级平台所属所有业户=0x03 + } +} diff --git a/src/JT809.Protocol/Enums/JT809_0x9302_ObjectType.cs b/src/JT809.Protocol/Enums/JT809_0x9302_ObjectType.cs new file mode 100644 index 0000000..b3ab510 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_0x9302_ObjectType.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 查岗对象的类型 + /// + public enum JT809_0x9302_ObjectType : byte + { + 下级平台所属单一平台 = 0x00, + 当前连接的下级平台 = 0x01, + 下级平台所属单一业户 = 0x02, + 下级平台所属所有业户 = 0x03, + 下级平台所属所有平台 = 0x04, + 下级平台所属所有平台和业户 = 0x05, + 下级平台所属所有政府监管平台_含监控端 = 0x06, + 下级平台所属所有企业监控平台 = 0x07, + 下级平台所属所有经营性企业监控平台 = 0x08, + 下级平台所属所有非经营性企业监控平台 = 0x09, + } +} diff --git a/src/JT809.Protocol/Enums/JT809_VehiclePositionEncrypt.cs b/src/JT809.Protocol/Enums/JT809_VehiclePositionEncrypt.cs new file mode 100644 index 0000000..cf9ef14 --- /dev/null +++ b/src/JT809.Protocol/Enums/JT809_VehiclePositionEncrypt.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Enums +{ + /// + /// 定位信息是否使用国家测绘局批准的地图保密插件进行加密。 + /// + public enum JT809_VehiclePositionEncrypt:byte + { + 未加密 = 0x00, + 已加密 = 0x01 + } +} diff --git a/src/JT809.Protocol/Exceptions/JT809Exception.cs b/src/JT809.Protocol/Exceptions/JT809Exception.cs new file mode 100644 index 0000000..18575c1 --- /dev/null +++ b/src/JT809.Protocol/Exceptions/JT809Exception.cs @@ -0,0 +1,32 @@ +using JT809.Protocol.Enums; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Exceptions +{ + public class JT809Exception:Exception + { + public JT809Exception(JT809ErrorCode errorCode) : base(errorCode.ToString()) + { + ErrorCode = errorCode; + } + + public JT809Exception(JT809ErrorCode errorCode, string message) : base(message) + { + ErrorCode = errorCode; + } + + public JT809Exception(JT809ErrorCode errorCode, Exception ex) : base(ex.Message, ex) + { + ErrorCode = errorCode; + } + + public JT809Exception(JT809ErrorCode errorCode, string message, Exception ex) : base(ex.Message, ex) + { + ErrorCode = errorCode; + } + + public JT809ErrorCode ErrorCode { get;} + } +} diff --git a/src/JT809.Protocol/Extensions/JT809ConfigExtensions.cs b/src/JT809.Protocol/Extensions/JT809ConfigExtensions.cs new file mode 100644 index 0000000..c97b02b --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809ConfigExtensions.cs @@ -0,0 +1,22 @@ +using JT809.Protocol.Interfaces; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Extensions +{ + public static class JT809ConfigExtensions + { + private readonly static ConcurrentDictionary jT809SerializerDict = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + public static JT809Serializer GetSerializer(this IJT809Config jT808Config) + { + if(!jT809SerializerDict.TryGetValue(jT808Config.ConfigId,out var serializer)) + { + serializer = new JT809Serializer(jT808Config); + jT809SerializerDict.TryAdd(jT808Config.ConfigId, serializer); + } + return serializer; + } + } +} diff --git a/src/JT809.Protocol/Extensions/JT809EnumExtensions.cs b/src/JT809.Protocol/Extensions/JT809EnumExtensions.cs new file mode 100644 index 0000000..e774843 --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809EnumExtensions.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; + +namespace JT809.Protocol.Extensions +{ + /// + /// 枚举扩展 + /// + public static class JT809EnumExtensions + { + /// + /// 转为整型 + /// + /// + /// + /// + public static int ToValue(this T t) where T : struct + { + return Convert.ToInt32(t); + } + + /// + /// 转为 u16 整型 + /// + /// + /// + /// + public static ushort ToUInt16Value(this T t) where T : struct + { + return Convert.ToUInt16(t); + } + + /// + /// 转为Byte + /// + /// + /// + /// + public static byte ToByteValue(this T t) where T : struct + { + return Convert.ToByte(t); + } + + /// + /// 转为整型 + /// + /// + /// + /// + public static string ToValueString(this T t) where T : struct + { + return Convert.ToInt32(t).ToString(); + } + + /// + /// 字符转枚举 + /// + /// + /// + /// + public static T ToEnum(this string value) where T : struct + { + return (T)Enum.Parse(typeof(T), value); + } + + /// + /// 获取枚举字符串 + /// + /// + public static string GetName(this Enum valueEnum) + { + return valueEnum.ToString(); + } + + /// + /// 获取DescriptionAttribute特性枚举值的描述 + /// + /// + /// + public static string GetDescription(this Enum value) + { + var attribute = value.GetAttribute(); + return attribute == null ? value.ToString() : attribute.Description; + } + + /// + /// 验证是否是枚举类型 + /// + /// + /// + /// + public static bool IsEnumValid(this int enumValue) + { + return Enum.IsDefined(typeof(TEnum), enumValue); + } + + /// + /// 获取DescriptionAttribute特性枚举及描述 + /// + /// + /// + public static Dictionary GetDescriptionAttributeDictionary(this Enum value) + { + Dictionary dictionary = new Dictionary(); + var fields = value.GetType().GetFields(BindingFlags.Static | BindingFlags.Public); + foreach (var fi in fields) + { + DescriptionAttribute attr = Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute), false) as DescriptionAttribute; + dictionary.Add(fi.Name, attr != null ? attr.Description : ""); + } + return dictionary; + } + + /// + /// 获取DisplayNameAttribute特性枚举值的描述 + /// + /// 枚举值 + /// + public static string GetDisplayName(this Enum value) + { + var attribute = value.GetAttribute(); + return attribute == null ? value.ToString() : attribute.DisplayName; + } + + /// + /// 获取DisplayNameAttribute特性枚举及描述 + /// + /// + /// + public static Dictionary GetDisplayNameAttributeDictionary(this Enum value) + { + Dictionary dictionary = new Dictionary(); + var fields = value.GetType().GetFields(BindingFlags.Static | BindingFlags.Public); + foreach (var fi in fields) + { + DisplayNameAttribute attr = Attribute.GetCustomAttribute(fi, typeof(DisplayNameAttribute), false) as DisplayNameAttribute; + dictionary.Add(fi.Name, attr != null ? attr.DisplayName : ""); + } + return dictionary; + } + + /// + /// 获取枚举对应特性 + /// + /// + /// + /// + public static T GetAttribute(this Enum value) where T : Attribute + { + try + { + var type = value.GetType(); + var memberInfo = type.GetMember(value.ToString()); + var attributes = memberInfo[0].GetCustomAttributes(typeof(T), false); + return (T)attributes[0]; + } + catch + { + return default; + } + } + + /// + /// 根据值获取对应枚举类型集合 + /// + /// 具体枚举类型 + /// 枚举值 + /// 位数(8,16,32) + /// 是否忽略未知数据 + /// + public static IEnumerable GetEnumTypes(this int value, int digit, bool ignoreUnknown = false) where T : Enum + { + List values = new List(); + for (int i = 0; i < digit; i++) + { + if (Math.Pow(2, i) <= value) continue; + values.Add((T)Enum.ToObject(typeof(T), (int)Math.Pow(2, i - 1))); + value = value - (int)Math.Pow(2, i - 1); + i = 0; + if (value <= 0) break; + } + if (ignoreUnknown) + { + List results = new List(); + foreach (var item in values) + { + foreach (string itemChild in Enum.GetNames(typeof(T))) + { + if (item.ToString() == itemChild) + { + results.Add(item); + break; + } + } + } + return results; + } + else + { + return values; + } + } + } +} diff --git a/src/JT809.Protocol/Extensions/JT809HexExtensions.cs b/src/JT809.Protocol/Extensions/JT809HexExtensions.cs new file mode 100644 index 0000000..0bfb6e9 --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809HexExtensions.cs @@ -0,0 +1,267 @@ +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace JT809.Protocol.Extensions +{ + /// + /// + /// ref:"www.codeproject.com/tips/447938/high-performance-csharp-byte-array-to-hex-string-t" + /// + public static partial class JT809BinaryExtensions + { + static readonly int[] toHexTable = new int[] { + 3145776, 3211312, 3276848, 3342384, 3407920, 3473456, 3538992, 3604528, 3670064, 3735600, + 4259888, 4325424, 4390960, 4456496, 4522032, 4587568, 3145777, 3211313, 3276849, 3342385, + 3407921, 3473457, 3538993, 3604529, 3670065, 3735601, 4259889, 4325425, 4390961, 4456497, + 4522033, 4587569, 3145778, 3211314, 3276850, 3342386, 3407922, 3473458, 3538994, 3604530, + 3670066, 3735602, 4259890, 4325426, 4390962, 4456498, 4522034, 4587570, 3145779, 3211315, + 3276851, 3342387, 3407923, 3473459, 3538995, 3604531, 3670067, 3735603, 4259891, 4325427, + 4390963, 4456499, 4522035, 4587571, 3145780, 3211316, 3276852, 3342388, 3407924, 3473460, + 3538996, 3604532, 3670068, 3735604, 4259892, 4325428, 4390964, 4456500, 4522036, 4587572, + 3145781, 3211317, 3276853, 3342389, 3407925, 3473461, 3538997, 3604533, 3670069, 3735605, + 4259893, 4325429, 4390965, 4456501, 4522037, 4587573, 3145782, 3211318, 3276854, 3342390, + 3407926, 3473462, 3538998, 3604534, 3670070, 3735606, 4259894, 4325430, 4390966, 4456502, + 4522038, 4587574, 3145783, 3211319, 3276855, 3342391, 3407927, 3473463, 3538999, 3604535, + 3670071, 3735607, 4259895, 4325431, 4390967, 4456503, 4522039, 4587575, 3145784, 3211320, + 3276856, 3342392, 3407928, 3473464, 3539000, 3604536, 3670072, 3735608, 4259896, 4325432, + 4390968, 4456504, 4522040, 4587576, 3145785, 3211321, 3276857, 3342393, 3407929, 3473465, + 3539001, 3604537, 3670073, 3735609, 4259897, 4325433, 4390969, 4456505, 4522041, 4587577, + 3145793, 3211329, 3276865, 3342401, 3407937, 3473473, 3539009, 3604545, 3670081, 3735617, + 4259905, 4325441, 4390977, 4456513, 4522049, 4587585, 3145794, 3211330, 3276866, 3342402, + 3407938, 3473474, 3539010, 3604546, 3670082, 3735618, 4259906, 4325442, 4390978, 4456514, + 4522050, 4587586, 3145795, 3211331, 3276867, 3342403, 3407939, 3473475, 3539011, 3604547, + 3670083, 3735619, 4259907, 4325443, 4390979, 4456515, 4522051, 4587587, 3145796, 3211332, + 3276868, 3342404, 3407940, 3473476, 3539012, 3604548, 3670084, 3735620, 4259908, 4325444, + 4390980, 4456516, 4522052, 4587588, 3145797, 3211333, 3276869, 3342405, 3407941, 3473477, + 3539013, 3604549, 3670085, 3735621, 4259909, 4325445, 4390981, 4456517, 4522053, 4587589, + 3145798, 3211334, 3276870, 3342406, 3407942, 3473478, 3539014, 3604550, 3670086, 3735622, + 4259910, 4325446, 4390982, 4456518, 4522054, 4587590 + }; + + /// + /// values for '\0' to 'f' where 255 indicates invalid input character + /// starting from '\0' and not from '0' costs 48 bytes + /// but results 0 subtructions and less if conditions + /// + static readonly byte[] fromHexTable = new byte[] { + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 0, 1, + 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, + 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, + 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 10, 11, 12, + 13, 14, 15 + }; + + /// + /// same as above but valid values are multiplied by 16 + /// + static readonly byte[] fromHexTable16 = new byte[] { + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 0, 16, + 32, 48, 64, 80, 96, 112, 128, 144, 255, 255, + 255, 255, 255, 255, 255, 160, 176, 192, 208, 224, + 240, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 160, 176, 192, + 208, 224, 240 + }; + + public static string ToHexString(this byte[] source) + { + //return string.Join(separator, source.Select(s => s.ToString("X2"))); + return ToHexString(source, false); + } + + public static int WriteHexStringLittle(byte[] bytes, int offset, string data, int len) + { + if (data == null) data = ""; + data = data.Replace(" ", ""); + int startIndex = 0; + if (data.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) + { + startIndex = 2; + } + int length = len; + if (length == -1) + { + length = (data.Length - startIndex) / 2; + } + int noOfZero = length * 2 + startIndex - data.Length; + if (noOfZero > 0) + { + data = data.Insert(startIndex, new string('0', noOfZero)); + } + int byteIndex = 0; + while (startIndex < data.Length && byteIndex < length) + { + bytes[offset+byteIndex] = Convert.ToByte(data.Substring(startIndex, 2), 16); + startIndex += 2; + byteIndex++; + } + return length; + } + + /// + /// 16进制字符串转16进制数组 + /// + /// + /// + /// + public static byte[] ToHexBytes(this string hexString) + { + hexString = hexString.Replace(" ", ""); + byte[] buf = new byte[hexString.Length / 2]; + ReadOnlySpan readOnlySpan = hexString.AsSpan(); + for (int i = 0; i < hexString.Length; i++) + { + if (i % 2 == 0) + { + buf[i / 2] = Convert.ToByte(readOnlySpan.Slice(i, 2).ToString(), 16); + } + } + return buf; + } + + public unsafe static string ReadHexStringLittle(ReadOnlySpan read, ref int offset, int len) + { + ReadOnlySpan source = read.Slice(offset, len); + offset += len; + // freeze toHexTable position in memory + fixed (int* hexRef = toHexTable) + // freeze source position in memory + fixed (byte* sourceRef = source) + { + // take first parsing position of source - allow inline pointer positioning + byte* s = sourceRef; + // calculate result length + int resultLen = (source.Length << 1); + // initialize result string with any character expect '\0' + string result = new string(' ', resultLen); + // take the first character address of result + fixed (char* resultRef = result) + { + // pairs of characters explain the endianess of toHexTable + // move on by pairs of characters (2 x 2 bytes) - allow inline pointer positioning + int* pair = (int*)resultRef; + // more to go + while (*pair != 0) + // set the value of the current pair and move to next pair and source byte + *pair++ = hexRef[*s++]; + return result; + } + } + } + + /// + /// hexIndicator: use prefix ("0x") or not + /// + /// + /// + /// + public unsafe static string ToHexString(byte[] source, bool hexIndicator) + { + // freeze toHexTable position in memory + fixed (int* hexRef = toHexTable) + // freeze source position in memory + fixed (byte* sourceRef = source) + { + // take first parsing position of source - allow inline pointer positioning + byte* s = sourceRef; + // calculate result length + int resultLen = (source.Length << 1); + // use prefix ("Ox") + if (hexIndicator) + // adapt result length + resultLen += 2; + // initialize result string with any character expect '\0' + string result = new string(' ', resultLen); + // take the first character address of result + fixed (char* resultRef = result) + { + // pairs of characters explain the endianess of toHexTable + // move on by pairs of characters (2 x 2 bytes) - allow inline pointer positioning + int* pair = (int*)resultRef; + // use prefix ("Ox") ? + if (hexIndicator) + // set first pair value + *pair++ = 7864368; + // more to go + while (*pair != 0) + // set the value of the current pair and move to next pair and source byte + *pair++ = hexRef[*s++]; + return result; + } + } + } + + public unsafe static byte[] FromHexString(this string source) + { + // return an empty array in case of null or empty source + if (string.IsNullOrEmpty(source)) + return new byte[0]; // you may change it to return null + if (source.Length % 2 == 1) // source length must be even + throw new ArgumentException(); + int + index = 0, // start position for parsing source + len = source.Length >> 1; // initial length of result + // take the first character address of source + fixed (char* sourceRef = source) + { + if (*(int*)sourceRef == 7864368) // source starts with "0x" + { + if (source.Length == 2) // source must not be just a "0x") + throw new ArgumentException(); + index += 2; // start position (bypass "0x") + len -= 1; // result length (exclude "0x") + } + byte add = 0; // keeps a fromHexTable value + byte[] result = new byte[len]; // initialization of result for known length + // freeze fromHexTable16 position in memory + fixed (byte* hiRef = fromHexTable16) + // freeze fromHexTable position in memory + fixed (byte* lowRef = fromHexTable) + // take the first byte address of result + fixed (byte* resultRef = result) + { + // take first parsing position of source - allow inremental memory position + char* s = (char*)&sourceRef[index]; + // take first byte position of result - allow incremental memory position + byte* r = resultRef; + // source has more characters to parse + while (*s != 0) + { + // check for non valid characters in pairs + // you may split it if you don't like its readbility + if ( + // check for character > 'f' + *s > 102 || + // assign source value to current result position and increment source position + // and check if is a valid character + (*r = hiRef[*s++]) == 255 || + // check for character > 'f' + *s > 102 || + // assign source value to "add" parameter and increment source position + // and check if is a valid character + (add = lowRef[*s++]) == 255 + ) + throw new ArgumentException(); + // set final value of current result byte and move pointer to next byte + *r++ += add; + } + return result; + } + } + } + } +} diff --git a/src/JT809.Protocol/Extensions/JT809MessagePackFormatterExtensions.cs b/src/JT809.Protocol/Extensions/JT809MessagePackFormatterExtensions.cs new file mode 100644 index 0000000..df4a281 --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809MessagePackFormatterExtensions.cs @@ -0,0 +1,42 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Exceptions; +using JT809.Protocol.Formatters; +using System; +using System.Collections.Concurrent; +using System.Reflection; + +namespace JT809.Protocol.Extensions +{ + public static class JT809MessagePackFormatterExtensions + { + private readonly static ConcurrentDictionary cache = new ConcurrentDictionary(); + + public static IJT809MessagePackFormatter GetFormatter() + { + return (IJT809MessagePackFormatter) GetFormatter(typeof(T)); + } + + public static object GetFormatter(Type type) + { + if(!cache.TryGetValue(type.GUID,out object formatter)) + { + var attr = type.GetTypeInfo().GetCustomAttribute(); + if (attr == null) + { + throw new JT809Exception(JT809ErrorCode.GetFormatterError, $"该类{type.FullName}没有标记JT809FormatterAttribute"); + } + if (attr.Arguments == null) + { + formatter = Activator.CreateInstance(attr.FormatterType); + } + else + { + formatter = Activator.CreateInstance(attr.FormatterType, attr.Arguments); + } + cache.TryAdd(type.GUID, formatter); + } + return formatter; + } + } +} diff --git a/src/JT809.Protocol/Extensions/JT809MessagePackFormatterResolverExtensions.cs b/src/JT809.Protocol/Extensions/JT809MessagePackFormatterResolverExtensions.cs new file mode 100644 index 0000000..b6465c1 --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809MessagePackFormatterResolverExtensions.cs @@ -0,0 +1,85 @@ +using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; +using System.Text; + +namespace JT809.Protocol.Extensions +{ + /// + /// + /// ref http://adamsitnik.com/Span/#span-must-not-be-a-generic-type-argument + /// ref http://adamsitnik.com/Span/ + /// ref MessagePack.Formatters.DynamicObjectTypeFallbackFormatter + /// + public static class JT809MessagePackFormatterResolverExtensions + { + delegate int JT809SerializeMethod(object dynamicFormatter, ref JT809MessagePackWriter writer,object value, IJT809Config config); + + delegate dynamic JT809DeserializeMethod(object dynamicFormatter, ref JT809MessagePackReader reader, IJT809Config config); + + static readonly ConcurrentDictionary jT809Serializers = new ConcurrentDictionary(); + + static readonly ConcurrentDictionary jT809Deserializes = new ConcurrentDictionary(); + + public static int JT809DynamicSerialize(object objFormatter, ref JT809MessagePackWriter writer, object value, IJT809Config config) + { + Type type = value.GetType(); + var ti = type.GetTypeInfo(); + (object Value, JT809SerializeMethod SerializeMethod) formatterAndDelegate; + if (!jT809Serializers.TryGetValue(type, out formatterAndDelegate)) + { + var t = type; + { + var formatterType = typeof(IJT809MessagePackFormatter<>).MakeGenericType(t); + var param0 = Expression.Parameter(typeof(object), "formatter"); + var param1 = Expression.Parameter(typeof(JT809MessagePackWriter).MakeByRefType(), "writer"); + var param2 = Expression.Parameter(typeof(object), "value"); + var param3 = Expression.Parameter(typeof(IJT809Config), "config"); + var serializeMethodInfo = formatterType.GetRuntimeMethod("Serialize", new[] { typeof(JT809MessagePackWriter).MakeByRefType(),t, typeof(IJT809Config)}); + var body = Expression.Call( + Expression.Convert(param0, formatterType), + serializeMethodInfo, + param1, + ti.IsValueType ? Expression.Unbox(param2, t) : Expression.Convert(param2, t), + param3); + var lambda = Expression.Lambda(body, param0, param1, param2, param3).Compile(); + formatterAndDelegate = (objFormatter, lambda); + } + jT809Serializers.TryAdd(t, formatterAndDelegate); + } + return formatterAndDelegate.SerializeMethod(formatterAndDelegate.Value, ref writer, value, config); + } + + public static dynamic JT809DynamicDeserialize(object objFormatter, ref JT809MessagePackReader reader, IJT809Config config) + { + var type = objFormatter.GetType(); + (object Value, JT809DeserializeMethod DeserializeMethod) formatterAndDelegate; + if (!jT809Deserializes.TryGetValue(type, out formatterAndDelegate)) + { + var t = type; + { + var formatterType = typeof(IJT809MessagePackFormatter<>).MakeGenericType(t); + ParameterExpression param0 = Expression.Parameter(typeof(object), "formatter"); + ParameterExpression param1 = Expression.Parameter(typeof(JT809MessagePackReader).MakeByRefType(), "reader"); + ParameterExpression param2 = Expression.Parameter(typeof(IJT809Config), "config"); + var deserializeMethodInfo = type.GetRuntimeMethod("Deserialize", new[] { typeof(JT809MessagePackReader).MakeByRefType(), typeof(IJT809Config) }); + var body = Expression.Call( + Expression.Convert(param0, type), + deserializeMethodInfo, + param1, + param2 + ); + var lambda = Expression.Lambda(body, param0, param1, param2).Compile(); + formatterAndDelegate = (objFormatter, lambda); + } + jT809Deserializes.TryAdd(t, formatterAndDelegate); + } + return formatterAndDelegate.DeserializeMethod(formatterAndDelegate.Value,ref reader, config); + } + } +} diff --git a/src/JT809.Protocol/Extensions/JT809PackageExtensions.cs b/src/JT809.Protocol/Extensions/JT809PackageExtensions.cs new file mode 100644 index 0000000..09e11ef --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809PackageExtensions.cs @@ -0,0 +1,64 @@ +using JT809.Protocol.Enums; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Extensions +{ + public static partial class JT809PackageExtensions + { + public static JT809Package Create(this JT809BusinessType jT809BusinessType, TJT809Bodies jT809Bodies) + where TJT809Bodies: JT809Bodies + { + JT809Package jT809Package = new JT809Package(); + jT809Package.Bodies = jT809Bodies; + jT809Package.Header = new JT809Header() + { + BusinessType = jT809BusinessType + }; + return jT809Package; + } + + public static JT809Package Create(this JT809BusinessType jT809BusinessType) + { + JT809Package jT809Package = new JT809Package(); + jT809Package.Header = new JT809Header() + { + BusinessType = jT809BusinessType, + }; + return jT809Package; + } + + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809Header jT809Header, TJT809Bodies jT809Bodies) + where TJT809Bodies : JT809Bodies + { + JT809Package jT809Package = new JT809Package(); + jT809Package.Bodies = jT809Bodies; + jT809Package.Header = new JT809Header() + { + BusinessType = jT809BusinessType, + MsgSN = jT809Header.MsgSN, + EncryptFlag = jT809Header.EncryptFlag, + EncryptKey = jT809Header.EncryptKey, + MsgGNSSCENTERID = jT809Header.MsgGNSSCENTERID, + Version = jT809Header.Version + }; + return jT809Package; + } + + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809Header jT809Header) + { + JT809Package jT809Package = new JT809Package(); + jT809Package.Header = new JT809Header() + { + BusinessType = jT809BusinessType, + MsgSN = jT809Header.MsgSN, + EncryptFlag = jT809Header.EncryptFlag, + EncryptKey = jT809Header.EncryptKey, + MsgGNSSCENTERID = jT809Header.MsgGNSSCENTERID, + Version = jT809Header.Version + }; + return jT809Package; + } + } +} diff --git a/src/JT809.Protocol/Extensions/JT809PackageExtensionsTemplate.cs b/src/JT809.Protocol/Extensions/JT809PackageExtensionsTemplate.cs new file mode 100644 index 0000000..3a37f1c --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809PackageExtensionsTemplate.cs @@ -0,0 +1,711 @@ + +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Extensions +{ + public static partial class JT809PackageExtensions + { + /// + /// UP_CONNECT_REQ - 主链路登录请求消息 + /// auto-generated + /// + public static JT809Package Create_主链路登录请求消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1001 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_CONNECT_REQ - 主链路登录请求消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1001 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_CONNECT_REQ - 主链路登录请求消息 + /// auto-generated + /// + public static JT809Package Create_主链路登录请求消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1001 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_CONNECT_RSP - 主链路登录应答消息 + /// auto-generated + /// + public static JT809Package Create_主链路登录应答消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1002 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_CONNECT_RSP - 主链路登录应答消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1002 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_CONNECT_RSP - 主链路登录应答消息 + /// auto-generated + /// + public static JT809Package Create_主链路登录应答消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1002 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_DISCONNECT_REQ - 主链路注销请求消息 + /// auto-generated + /// + public static JT809Package Create_主链路注销请求消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1003 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_DISCONNECT_REQ - 主链路注销请求消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1003 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_DISCONNECT_REQ - 主链路注销请求消息 + /// auto-generated + /// + public static JT809Package Create_主链路注销请求消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1003 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_DISCONNECT_RSP - 主链路注销应答消息 + /// auto-generated + /// + public static JT809Package Create_主链路注销应答消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1004 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_DISCONNECT_RSP - 主链路注销应答消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1004 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_DISCONNECT_RSP - 主链路注销应答消息 + /// auto-generated + /// + public static JT809Package Create_主链路注销应答消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1004 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_LINKTEST_REQ - 主链路连接保持请求消息 + /// auto-generated + /// + public static JT809Package Create_主链路连接保持请求消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1005 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_LINKTEST_REQ - 主链路连接保持请求消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1005 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_LINKTEST_REQ - 主链路连接保持请求消息 + /// auto-generated + /// + public static JT809Package Create_主链路连接保持请求消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1005 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_LINKTEST_RSP - 主链路连接保持应答消息 + /// auto-generated + /// + public static JT809Package Create_主链路连接保持应答消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1006 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_LINKTEST_RSP - 主链路连接保持应答消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1006 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_LINKTEST_RSP - 主链路连接保持应答消息 + /// auto-generated + /// + public static JT809Package Create_主链路连接保持应答消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1006 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_DISCONNECT_INFORM - 主链路断开通知消息 + /// auto-generated + /// + public static JT809Package Create_主链路断开通知消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1007 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_DISCONNECT_INFORM - 主链路断开通知消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1007 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_DISCONNECT_INFORM - 主链路断开通知消息 + /// auto-generated + /// + public static JT809Package Create_主链路断开通知消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1007 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_CLOSELINK_INFORM - 下级平台主动关闭链路通知消息 + /// auto-generated + /// + public static JT809Package Create_下级平台主动关闭链路通知消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1008 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_CLOSELINK_INFORM - 下级平台主动关闭链路通知消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1008 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_CLOSELINK_INFORM - 下级平台主动关闭链路通知消息 + /// auto-generated + /// + public static JT809Package Create_下级平台主动关闭链路通知消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1008 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_EXG_MSG - 主链路动态信息交换消息 + /// auto-generated + /// + public static JT809Package Create_主链路动态信息交换消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1200 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_EXG_MSG - 主链路动态信息交换消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1200 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_EXG_MSG - 主链路动态信息交换消息 + /// auto-generated + /// + public static JT809Package Create_主链路动态信息交换消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1200 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_PLATFORM_MSG - 主链路平台间信息交互消息 + /// auto-generated + /// + public static JT809Package Create_主链路平台间信息交互消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1300 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_PLATFORM_MSG - 主链路平台间信息交互消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1300 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_PLATFORM_MSG - 主链路平台间信息交互消息 + /// auto-generated + /// + public static JT809Package Create_主链路平台间信息交互消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1300 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_WARN_MSG - 主链路报警信息交互消息 + /// auto-generated + /// + public static JT809Package Create_主链路报警信息交互消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1400 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_WARN_MSG - 主链路报警信息交互消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1400 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_WARN_MSG - 主链路报警信息交互消息 + /// auto-generated + /// + public static JT809Package Create_主链路报警信息交互消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1400 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_CTRL_MSG - 主链路车辆监管消息 + /// auto-generated + /// + public static JT809Package Create_主链路车辆监管消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1500 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_CTRL_MSG - 主链路车辆监管消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1500 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_CTRL_MSG - 主链路车辆监管消息 + /// auto-generated + /// + public static JT809Package Create_主链路车辆监管消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1500 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// UP_BASE_MSG - 主链路静态信息交换消息 + /// auto-generated + /// + public static JT809Package Create_主链路静态信息交换消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x1600 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_BASE_MSG - 主链路静态信息交换消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x1600 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// UP_BASE_MSG - 主链路静态信息交换消息 + /// auto-generated + /// + public static JT809Package Create_主链路静态信息交换消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x1600 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_CONNECT_REQ - 从链路连接请求消息 + /// auto-generated + /// + public static JT809Package Create_从链路连接请求消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9001 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_CONNECT_REQ - 从链路连接请求消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9001 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_CONNECT_REQ - 从链路连接请求消息 + /// auto-generated + /// + public static JT809Package Create_从链路连接请求消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9001 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_CONNECT_RSP - 从链路连接应答消息 + /// auto-generated + /// + public static JT809Package Create_从链路连接应答消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9002 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_CONNECT_RSP - 从链路连接应答消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9002 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_CONNECT_RSP - 从链路连接应答消息 + /// auto-generated + /// + public static JT809Package Create_从链路连接应答消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9002 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_DISCONNECT_REQ - 从链路注销请求消息 + /// auto-generated + /// + public static JT809Package Create_从链路注销请求消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9003 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_DISCONNECT_REQ - 从链路注销请求消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9003 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_DISCONNECT_REQ - 从链路注销请求消息 + /// auto-generated + /// + public static JT809Package Create_从链路注销请求消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9003 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_DISCONNECT_RSP - 从链路注销应答消息 + /// auto-generated + /// + public static JT809Package Create_从链路注销应答消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9004 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_DISCONNECT_RSP - 从链路注销应答消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9004 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_DISCONNECT_RSP - 从链路注销应答消息 + /// auto-generated + /// + public static JT809Package Create_从链路注销应答消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9004 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_LINKTEST_REQ - 从链路连接保持请求消息 + /// auto-generated + /// + public static JT809Package Create_从链路连接保持请求消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9005 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_LINKTEST_REQ - 从链路连接保持请求消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9005 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_LINKTEST_REQ - 从链路连接保持请求消息 + /// auto-generated + /// + public static JT809Package Create_从链路连接保持请求消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9005 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_LINKTEST_RSP - 从链路连接保持应答消息 + /// auto-generated + /// + public static JT809Package Create_从链路连接保持应答消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9006 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_LINKTEST_RSP - 从链路连接保持应答消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9006 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_LINKTEST_RSP - 从链路连接保持应答消息 + /// auto-generated + /// + public static JT809Package Create_从链路连接保持应答消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9006 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_DISCONNECT_INFORM - 从链路断开通知消息 + /// auto-generated + /// + public static JT809Package Create_从链路断开通知消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9007 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_DISCONNECT_INFORM - 从链路断开通知消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9007 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_DISCONNECT_INFORM - 从链路断开通知消息 + /// auto-generated + /// + public static JT809Package Create_从链路断开通知消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9007 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_CLOSELINK_INFORM - 上级平台主动关闭链路通知消息 + /// auto-generated + /// + public static JT809Package Create_上级平台主动关闭链路通知消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9008 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_CLOSELINK_INFORM - 上级平台主动关闭链路通知消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9008 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_CLOSELINK_INFORM - 上级平台主动关闭链路通知消息 + /// auto-generated + /// + public static JT809Package Create_上级平台主动关闭链路通知消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9008 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_TOTAL_RECV_BACK_MSG - 接收定位信息数量通知消息 + /// auto-generated + /// + public static JT809Package Create_接收定位信息数量通知消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9101 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_TOTAL_RECV_BACK_MSG - 接收定位信息数量通知消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9101 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_TOTAL_RECV_BACK_MSG - 接收定位信息数量通知消息 + /// auto-generated + /// + public static JT809Package Create_接收定位信息数量通知消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9101 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_EXG_MSG - 从链路动态信息交换消息 + /// auto-generated + /// + public static JT809Package Create_从链路动态信息交换消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9200 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_EXG_MSG - 从链路动态信息交换消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9200 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_EXG_MSG - 从链路动态信息交换消息 + /// auto-generated + /// + public static JT809Package Create_从链路动态信息交换消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9200 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_PLATFORM_MSG - 从链路平台间信息交互消息 + /// auto-generated + /// + public static JT809Package Create_从链路平台间信息交互消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9300 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_PLATFORM_MSG - 从链路平台间信息交互消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9300 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_PLATFORM_MSG - 从链路平台间信息交互消息 + /// auto-generated + /// + public static JT809Package Create_从链路平台间信息交互消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9300 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_WARN_MSG - 从链路报警信息交互消息 + /// auto-generated + /// + public static JT809Package Create_从链路报警信息交互消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9400 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_WARN_MSG - 从链路报警信息交互消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9400 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_WARN_MSG - 从链路报警信息交互消息 + /// auto-generated + /// + public static JT809Package Create_从链路报警信息交互消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9400 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_CTRL_MSG - 从链路车辆监管消息 + /// auto-generated + /// + public static JT809Package Create_从链路车辆监管消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9500 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_CTRL_MSG - 从链路车辆监管消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9500 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_CTRL_MSG - 从链路车辆监管消息 + /// auto-generated + /// + public static JT809Package Create_从链路车辆监管消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9500 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + /// + /// DOWN_BASE_MSG - 从链路静态信息交换消息 + /// auto-generated + /// + public static JT809Package Create_从链路静态信息交换消息(this JT809BusinessType jT809BusinessType,JT809.Protocol.MessageBody.JT809_0x9600 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_BASE_MSG - 从链路静态信息交换消息 + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, JT809.Protocol.MessageBody.JT809_0x9600 bodies) + { + return Create(jT809BusinessType,bodies); + } + + /// + /// DOWN_BASE_MSG - 从链路静态信息交换消息 + /// auto-generated + /// + public static JT809Package Create_从链路静态信息交换消息(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, JT809.Protocol.MessageBody.JT809_0x9600 bodies) + { + return Create(jT809BusinessType,jT809Header,bodies); + } + } +} \ No newline at end of file diff --git a/src/JT809.Protocol/Extensions/JT809PackageExtensionsTemplate.tt b/src/JT809.Protocol/Extensions/JT809PackageExtensionsTemplate.tt new file mode 100644 index 0000000..87db0b3 --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809PackageExtensionsTemplate.tt @@ -0,0 +1,63 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="netstandard" #> +<#@ assembly name="System.Core" #> +<#@ assembly name="System" #> +<#@ assembly name="$(TargetPath)" #> +<#@ import namespace="JT809.Protocol" #> +<#@ import namespace="JT809.Protocol.Enums" #> +<#@ import namespace="JT809.Protocol.Extensions" #> +<#@ import namespace="JT809.Protocol.Attributes" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="System.Reflection" #> +<#@ output extension=".cs" #> + +<# + var types=Enum.GetNames(typeof(JT809BusinessType)); +#> +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Extensions +{ + public static partial class JT809PackageExtensions + { + <# + foreach (var item in types) + { + JT809BusinessType jT809BusinessType = item.ToEnum(); + JT809BodiesTypeAttribute jT809BodiesTypeAttribute = jT809BusinessType.GetAttribute(); + JT809BusinessTypeDescriptionAttribute jT809MsgIdDescriptionAttribute = jT809BusinessType.GetAttribute(); + +#> + /// + /// <#= jT809MsgIdDescriptionAttribute.Code #> - <#= jT809MsgIdDescriptionAttribute.Name #> + /// auto-generated + /// + public static JT809Package Create_<#= jT809MsgIdDescriptionAttribute.Name #>(this JT809BusinessType jT809BusinessType,<#= jT809BodiesTypeAttribute.JT809BodiesType.FullName #> bodies) + { + return Create<<#= jT809BodiesTypeAttribute.JT809BodiesType.FullName#>>(jT809BusinessType,bodies); + } + + /// + /// <#= jT809MsgIdDescriptionAttribute.Code #> - <#= jT809MsgIdDescriptionAttribute.Name #> + /// auto-generated + /// + public static JT809Package Create(this JT809BusinessType jT809BusinessType, <#= jT809BodiesTypeAttribute.JT809BodiesType.FullName #> bodies) + { + return Create<<#= jT809BodiesTypeAttribute.JT809BodiesType.FullName#>>(jT809BusinessType,bodies); + } + + /// + /// <#= jT809MsgIdDescriptionAttribute.Code #> - <#= jT809MsgIdDescriptionAttribute.Name #> + /// auto-generated + /// + public static JT809Package Create_<#= jT809MsgIdDescriptionAttribute.Name #>(this JT809BusinessType jT809BusinessType,JT809Header jT809Header, <#= jT809BodiesTypeAttribute.JT809BodiesType.FullName #> bodies) + { + return Create<<#= jT809BodiesTypeAttribute.JT809BodiesType.FullName#>>(jT809BusinessType,jT809Header,bodies); + } +<# + } +#> + } +} \ No newline at end of file diff --git a/src/JT809.Protocol/Extensions/JT809SubPackageExtensions.cs b/src/JT809.Protocol/Extensions/JT809SubPackageExtensions.cs new file mode 100644 index 0000000..17dc8e6 --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809SubPackageExtensions.cs @@ -0,0 +1,16 @@ +using JT809.Protocol.Enums; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Extensions +{ + public static partial class JT809SubPackageExtensions + { + public static TJT809SubBodies Create(this JT809SubBusinessType jT809SubBusinessType, TJT809SubBodies jT809SubBodies) + where TJT809SubBodies : JT809SubBodies + { + return jT809SubBodies; + } + } +} diff --git a/src/JT809.Protocol/Extensions/JT809SubPackageExtensionsTemplate.cs b/src/JT809.Protocol/Extensions/JT809SubPackageExtensionsTemplate.cs new file mode 100644 index 0000000..67c9184 --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809SubPackageExtensionsTemplate.cs @@ -0,0 +1,410 @@ + +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Extensions +{ + /// + /// 子命令包 + /// auto-generated + /// + public static partial class JT809SubPackageExtensions + { + + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_REGISTER - 上传车辆注册信息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x1201 Create_上传车辆注册信息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x1201 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_REAL_LOCATION - 实时上传车辆定位信息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x1202 Create_实时上传车辆定位信息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x1202 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_HISTORY_LOCATION - 车辆定位信息自动补报 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x1203 Create_车辆定位信息自动补报(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x1203 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_RETURN_STARTUP_ACK - 启动车辆定位信息交换应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x1205 Create_启动车辆定位信息交换应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x1205 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_RETURN_END_ACK - 结束车辆定位信息交换应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x1206 Create_结束车辆定位信息交换应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x1206 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_APPLY_FOR_MONITOR_STARTUP - 申请交换指定车辆定位信息请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x1207 Create_申请交换指定车辆定位信息请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x1207 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_APPLY_FOR_MONITOR_END - 取消交换指定车辆定位信息请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x1208 Create_取消交换指定车辆定位信息请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x1208 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_APPLY_HISGNSSDATA_REQ - 补发车辆定位信息请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x1209 Create_补发车辆定位信息请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x1209 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_REPORT_DRIVER_INFO_ACK - 上报车辆驾驶员身份识别信息应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x120A Create_上报车辆驾驶员身份识别信息应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x120A subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_TAKE_EWAYBILL_ACK - 上报车辆电子运单应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x120B Create_上报车辆电子运单应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x120B subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_REPORT_DRIVER_INFO - 主动上报驾驶员身份信息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x120C Create_主动上报驾驶员身份信息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x120C subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路动态信息交换消息 + /// UP_EXG_MSG_REPORT_EWAYBILL_INFO - 主动上报车辆电子运单信息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1200_0x120D Create_主动上报车辆电子运单信息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1200_0x120D subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路平台间信息交互消息 + /// UP_PLATFORM_MSG_POST_QUERY_ACK - 平台查岗应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1300_0x1301 Create_平台查岗应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1300_0x1301 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路平台间信息交互消息 + /// UP_PLATFORM_MSG_INFO_ACK - 下发平台间报文应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1300_0x1302 Create_下发平台间报文应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1300_0x1302 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路报警信息交互消息 + /// UP_WARN_MSG_URGE_TODO_ACK - 报警督办应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1400_0x1401 Create_报警督办应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1400_0x1401 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路报警信息交互消息 + /// UP_WARN_MSG_ADPT_INFO - 上报报警信息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1400_0x1402 Create_上报报警信息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1400_0x1402 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路报警信息交互消息 + /// UP_WARN_MSG_ADPT_TODO_INFO - 主动上报报警处理结果信息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1400_0x1403 Create_主动上报报警处理结果信息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1400_0x1403 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路车辆监管消息 + /// UP_CTRL_MSG_MONITOR_VEHICLE_ACK - 车辆单向监听应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1500_0x1501 Create_车辆单向监听应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1500_0x1501 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路车辆监管消息 + /// UP_CTRL_MSG_TAKE_PHOTO_ACK - 车辆拍照应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1500_0x1502 Create_车辆拍照应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1500_0x1502 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路车辆监管消息 + /// UP_CTRL_MSG_TEXT_INFO_ACK - 下发车辆报文应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1500_0x1503 Create_下发车辆报文应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1500_0x1503 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路车辆监管消息 + /// UP_CTRL_MSG_TAKE_TRAVEL_ACK - 上报车辆行驶记录应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1500_0x1504 Create_上报车辆行驶记录应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1500_0x1504 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路车辆监管消息 + /// UP_CTRL_MSG_EMERGENCY_MONITORING_ACK - 车辆应急接入监管平台应答消息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1500_0x1505 Create_车辆应急接入监管平台应答消息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1500_0x1505 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 主链路静态信息交换消息 + /// UP_BASE_MSG_VEHICLE_ADDED_ACK - 补报车辆静态信息应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x1600_0x1601 Create_补报车辆静态信息应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x1600_0x1601 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_CAR_LOCATION - 交换车辆定位信息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x9202 Create_交换车辆定位信息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x9202 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_HISTORY_ARCOSSAREA - 车辆定位信息交换补发 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x9203 Create_车辆定位信息交换补发(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x9203 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_CAR_INFO - 交换车辆静态信息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x9204 Create_交换车辆静态信息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x9204 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_RETURN_STARTUP - 启动车辆定位信息交换请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x9205 Create_启动车辆定位信息交换请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x9205 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_RETURN_END - 结束车辆定位信息交换请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x9206 Create_结束车辆定位信息交换请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x9206 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_APPLY_FOR_MONITOR_STARTUP_ACK - 申请交换指定车辆定位信息应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x9207 Create_申请交换指定车辆定位信息应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x9207 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_APPLY_FOR_MONITOR_END_ACK - 取消交换指定车辆定位信息应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x9208 Create_取消交换指定车辆定位信息应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x9208 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_APPLY_HISGNSSDATA_ACK - 补发车辆定位信息应答 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x9209 Create_补发车辆定位信息应答(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x9209 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_REPORT_DRIVER_INFO - 上报车辆驾驶员身份识别信息请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x920A Create_上报车辆驾驶员身份识别信息请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x920A subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路动态信息交换消息 + /// DOWN_EXG_MSG_TAKE_EWAYBILL_REQ - 上报车辆电子运单请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9200_0x920B Create_上报车辆电子运单请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9200_0x920B subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路平台间信息交互消息 + /// DOWN_PLATFORM_MSG_POST_QUERY_REQ - 平台查岗请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9300_0x9301 Create_平台查岗请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9300_0x9301 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路平台间信息交互消息 + /// DOWN_PLATFORM_MSG_INFO_REQ - 下发平台间报文请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9300_0x9302 Create_下发平台间报文请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9300_0x9302 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路报警信息交互消息 + /// DOWN_WARN_MSG_URGE_TODO_REQ - 报警督办请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9400_0x9401 Create_报警督办请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9400_0x9401 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路报警信息交互消息 + /// DOWN_WARN_MSG_INFORM_TIPS - 报警预警 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9400_0x9402 Create_报警预警(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9400_0x9402 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路报警信息交互消息 + /// DOWN_WARN_MSG_EXG_INFORM - 实时交换报警信息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9400_0x9403 Create_实时交换报警信息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9400_0x9403 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路车辆监管消息 + /// DOWN_CTRL_MSG_MONITOR_VEHICLE_REQ - 车辆单向监听请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9500_0x9501 Create_车辆单向监听请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9500_0x9501 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路车辆监管消息 + /// DOWN_CTRL_MSG_TAKE_PHOTO_REQ - 车辆拍照请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9500_0x9502 Create_车辆拍照请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9500_0x9502 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路车辆监管消息 + /// DOWN_CTRL_MSG_TEXT_INFO - 下发车辆报文请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9500_0x9503 Create_下发车辆报文请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9500_0x9503 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路车辆监管消息 + /// DOWN_CTRL_MSG_TAKE_TRAVEL_REQ - 上报车辆行驶记录请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9500_0x9504 Create_上报车辆行驶记录请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9500_0x9504 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路车辆监管消息 + /// DOWN_CTRL_MSG_EMERGENCY_MONITORING_REQ - 车辆应急接入监管平台请求消息 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9500_0x9505 Create_车辆应急接入监管平台请求消息(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9500_0x9505 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + /// + /// 从链路静态信息交换消息 + /// DOWN_BASE_MSG_VEHICLE_ADDED - 补报车辆静态信息请求 + /// auto-generated + /// + public static JT809.Protocol.SubMessageBody.JT809_0x9600_0x9601 Create_补报车辆静态信息请求(this JT809SubBusinessType jT809SubBusinessType,JT809.Protocol.SubMessageBody.JT809_0x9600_0x9601 subBodies) + { + return Create(jT809SubBusinessType,subBodies); + } + } +} \ No newline at end of file diff --git a/src/JT809.Protocol/Extensions/JT809SubPackageExtensionsTemplate.tt b/src/JT809.Protocol/Extensions/JT809SubPackageExtensionsTemplate.tt new file mode 100644 index 0000000..a623d92 --- /dev/null +++ b/src/JT809.Protocol/Extensions/JT809SubPackageExtensionsTemplate.tt @@ -0,0 +1,51 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="netstandard" #> +<#@ assembly name="System.Core" #> +<#@ assembly name="System" #> +<#@ assembly name="$(TargetPath)" #> +<#@ import namespace="JT809.Protocol" #> +<#@ import namespace="JT809.Protocol.Enums" #> +<#@ import namespace="JT809.Protocol.Extensions" #> +<#@ import namespace="JT809.Protocol.Attributes" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="System.Reflection" #> +<#@ output extension=".cs" #> + +<# + var types=Enum.GetNames(typeof(JT809SubBusinessType)); +#> +using JT809.Protocol.Enums; + +namespace JT809.Protocol.Extensions +{ + /// + /// 子命令包 + /// auto-generated + /// + public static partial class JT809SubPackageExtensions + { + +<# + foreach (var item in types) + { + JT809SubBusinessType jT809SubBusinessType = item.ToEnum(); + if (jT809SubBusinessType == JT809SubBusinessType.None) continue; + JT809BodiesTypeAttribute jT809SubBodiesTypeAttribute = jT809SubBusinessType.GetAttribute(); + JT809SubBusinessTypeDescriptionAttribute jT809SubBusinessTypeDescriptionAttribute = jT809SubBusinessType.GetAttribute(); +#> + /// + /// <#= jT809SubBusinessTypeDescriptionAttribute.BusinessType.ToString() #> + /// <#= jT809SubBusinessTypeDescriptionAttribute.Code #> - <#= jT809SubBusinessTypeDescriptionAttribute.Name #> + /// auto-generated + /// + public static <#= jT809SubBodiesTypeAttribute.JT809BodiesType.FullName #> Create_<#= jT809SubBusinessTypeDescriptionAttribute.Name #>(this JT809SubBusinessType jT809SubBusinessType,<#= jT809SubBodiesTypeAttribute.JT809BodiesType.FullName #> subBodies) + { + return Create<<#= jT809SubBodiesTypeAttribute.JT809BodiesType.FullName#>>(jT809SubBusinessType,subBodies); + } +<# + } +#> + } +} \ No newline at end of file diff --git a/src/JT809.Protocol/Formatters/IJT809FormatterOfT.cs b/src/JT809.Protocol/Formatters/IJT809FormatterOfT.cs new file mode 100644 index 0000000..5407d31 --- /dev/null +++ b/src/JT809.Protocol/Formatters/IJT809FormatterOfT.cs @@ -0,0 +1,15 @@ +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; + +namespace JT809.Protocol.Formatters +{ + [Obsolete("请使用 IJT809MessagePackFormatter")] + public interface IJT809Formatter: IJT809Formatter + { + T Deserialize(ReadOnlySpan bytes, out int readSize); + + int Serialize(ref byte[] bytes, int offset, T value); + } +} diff --git a/src/JT809.Protocol/Formatters/IJT809MessagePackFormatterOfT.cs b/src/JT809.Protocol/Formatters/IJT809MessagePackFormatterOfT.cs new file mode 100644 index 0000000..ab85be6 --- /dev/null +++ b/src/JT809.Protocol/Formatters/IJT809MessagePackFormatterOfT.cs @@ -0,0 +1,19 @@ +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters +{ + public interface IJT809MessagePackFormatter : IJT809Formatter + { + void Serialize(ref JT809MessagePackWriter writer, T value, IJT809Config config); + T Deserialize(ref JT809MessagePackReader reader, IJT809Config config); + } + + public interface IJT809Formatter + { + + } +} diff --git a/src/JT809.Protocol/Formatters/JT809BodiesFormatter.cs b/src/JT809.Protocol/Formatters/JT809BodiesFormatter.cs new file mode 100644 index 0000000..1286118 --- /dev/null +++ b/src/JT809.Protocol/Formatters/JT809BodiesFormatter.cs @@ -0,0 +1,64 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Exceptions; +using JT809.Protocol.Extensions; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Internal; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.MessageBody; + +namespace JT809.Protocol.Formatters +{ + public class JT809BodiesFormatter : IJT809MessagePackFormatter + where TJT809Bodies: JT809ExchangeMessageBodies, new () + { + public readonly static JT809BodiesFormatter Instance_0x1200 = new JT809BodiesFormatter(); + public readonly static JT809BodiesFormatter Instance_0x1400 = new JT809BodiesFormatter(); + public readonly static JT809BodiesFormatter Instance_0x1500 = new JT809BodiesFormatter(); + public readonly static JT809BodiesFormatter Instance_0x1600 = new JT809BodiesFormatter(); + public readonly static JT809BodiesFormatter Instance_0x9200 = new JT809BodiesFormatter(); + public readonly static JT809BodiesFormatter Instance_0x9400 = new JT809BodiesFormatter(); + public readonly static JT809BodiesFormatter Instance_0x9500 = new JT809BodiesFormatter(); + public readonly static JT809BodiesFormatter Instance_0x9600 = new JT809BodiesFormatter(); + + public TJT809Bodies Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + TJT809Bodies jT809Bodies = new TJT809Bodies(); + jT809Bodies.VehicleNo = reader.ReadString(21); + jT809Bodies.VehicleColor = (JT809VehicleColorType)reader.ReadByte(); + jT809Bodies.SubBusinessType = (JT809SubBusinessType)reader.ReadUInt16(); + jT809Bodies.DataLength = reader.ReadUInt32(); + try + { + jT809Bodies.SubBodies = jT809Bodies.SubBusinessType.Deserialize(ref reader, config); + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809Bodies.SubBusinessType.ToString()}"); + } + return jT809Bodies; + } + + public void Serialize(ref JT809MessagePackWriter writer, TJT809Bodies value, IJT809Config config) + { + writer.WriteStringPadRight(value.VehicleNo, 21); + writer.WriteByte((byte)value.VehicleColor); + writer.WriteUInt16((ushort)value.SubBusinessType); + try + { + // 先写入内容,然后在根据内容反写内容长度 + writer.Skip(4, out int subContentLengthPosition); + value.SubBusinessType.Serialize(ref writer,value.SubBodies, config); + writer.WriteInt32Return(writer.GetCurrentPosition()- subContentLengthPosition - 4, subContentLengthPosition); + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); + } + } + } +} diff --git a/src/JT809.Protocol/Formatters/JT809HeaderFormatter.cs b/src/JT809.Protocol/Formatters/JT809HeaderFormatter.cs new file mode 100644 index 0000000..d0c90e8 --- /dev/null +++ b/src/JT809.Protocol/Formatters/JT809HeaderFormatter.cs @@ -0,0 +1,40 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters +{ + public class JT809HeaderFormatter : IJT809MessagePackFormatter + { + public readonly static JT809HeaderFormatter Instance = new JT809HeaderFormatter(); + + public JT809Header Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809Header jT809Header = new JT809Header(); + jT809Header.MsgLength = reader.ReadUInt32(); + jT809Header.MsgSN = reader.ReadUInt32(); + jT809Header.BusinessType = (JT809BusinessType)reader.ReadUInt16(); + jT809Header.MsgGNSSCENTERID = reader.ReadUInt32(); + jT809Header.Version = new JT809Header_Version(reader.ReadArray(JT809Header_Version.FixedByteLength)); + jT809Header.EncryptFlag = (JT809Header_Encrypt)reader.ReadByte(); + jT809Header.EncryptKey = reader.ReadUInt32(); + return jT809Header; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809Header value, IJT809Config config) + { + writer.WriteUInt32(value.MsgLength); + writer.WriteUInt32( value.MsgSN); + writer.WriteUInt16((ushort)value.BusinessType); + writer.WriteUInt32(value.MsgGNSSCENTERID); + writer.WriteArray(value.Version.Buffer); + writer.WriteByte((byte)value.EncryptFlag); + writer.WriteUInt32(value.EncryptKey); + } + } +} diff --git a/src/JT809.Protocol/Formatters/JT809HeaderPackageFormatter.cs b/src/JT809.Protocol/Formatters/JT809HeaderPackageFormatter.cs new file mode 100644 index 0000000..3004c92 --- /dev/null +++ b/src/JT809.Protocol/Formatters/JT809HeaderPackageFormatter.cs @@ -0,0 +1,72 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Exceptions; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using System; + +namespace JT809.Protocol.Formatters +{ + public class JT809HeaderPackageFormatter : IJT809MessagePackFormatter + { + public readonly static JT809HeaderPackageFormatter Instance = new JT809HeaderPackageFormatter(); + public JT809HeaderPackage Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + // 1. 验证校验码 + if (!config.SkipCRCCode) + { + // 1.2. 验证校验码 + if (!reader.CheckXorCodeVali) + { + throw new JT809Exception(JT809ErrorCode.CRC16CheckInvalid, $"{reader.CalculateCheckXorCode.ToString()}!={reader.RealCheckXorCode.ToString()}"); + } + } + JT809HeaderPackage jT809Package = new JT809HeaderPackage(); + // 2.读取起始头 + jT809Package.BeginFlag = reader.ReadStart(); + // 3.初始化消息头 + try + { + jT809Package.Header = JT809HeaderFormatter.Instance.Deserialize(ref reader, config); + } + catch (Exception ex) + { + throw new JT809Exception(JT809ErrorCode.HeaderParseError, $"offset>{reader.ReadCurrentRemainContentLength().ToString()}", ex); + } + // 5.数据体处理 + // 5.1 判断是否有数据体(总长度-固定长度)> 0 + if ((jT809Package.Header.MsgLength - JT809Package.FixedByteLength) > 0) + { + try + { + // 5.2 是否加密 + switch (jT809Package.Header.EncryptFlag) + { + case JT809Header_Encrypt.None: + // 5.3 处理消息体 + jT809Package.Bodies = reader.ReadContent().ToArray(); + break; + case JT809Header_Encrypt.Common: + // 5.4. 处理加密消息体 + byte[] bodiesData = config.Encrypt.Decrypt(reader.ReadContent(), config.EncryptOptions, jT809Package.Header.EncryptKey); + jT809Package.Bodies = bodiesData; + break; + } + } + catch (Exception ex) + { + throw new JT809Exception(JT809ErrorCode.BodiesParseError, $"offset>{reader.ReadCurrentRemainContentLength().ToString()}", ex); + } + } + jT809Package.CRCCode = reader.CalculateCheckXorCode; + jT809Package.EndFlag = reader.ReadEnd(); + return jT809Package; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809HeaderPackage value, IJT809Config config) + { + throw new NotImplementedException("只适用反序列化"); + } + } +} diff --git a/src/JT809.Protocol/Formatters/JT809PackageFormatter.cs b/src/JT809.Protocol/Formatters/JT809PackageFormatter.cs new file mode 100644 index 0000000..7dbbe2f --- /dev/null +++ b/src/JT809.Protocol/Formatters/JT809PackageFormatter.cs @@ -0,0 +1,143 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Exceptions; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.Internal; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters +{ + public class JT809PackageFormatter : IJT809MessagePackFormatter + { + public readonly static JT809PackageFormatter Instance = new JT809PackageFormatter(); + public JT809Package Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + // 1. 验证校验码 + if (!config.SkipCRCCode) + { + // 1.2. 验证校验码 + if (!reader.CheckXorCodeVali) + { + throw new JT809Exception(JT809ErrorCode.CRC16CheckInvalid, $"{reader.CalculateCheckXorCode.ToString()}!={reader.RealCheckXorCode.ToString()}"); + } + } + JT809Package jT809Package = new JT809Package(); + // 2.读取起始头 + jT809Package.BeginFlag = reader.ReadStart(); + // 3.初始化消息头 + try + { + jT809Package.Header = JT809HeaderFormatter.Instance.Deserialize(ref reader, config); + } + catch (Exception ex) + { + throw new JT809Exception(JT809ErrorCode.HeaderParseError, $"offset>{reader.ReadCurrentRemainContentLength().ToString()}", ex); + } + // 5.数据体处理 + // 5.1 判断是否有数据体(总长度-固定长度)> 0 + if ((jT809Package.Header.MsgLength - JT809Package.FixedByteLength) > 0) + { + try + { + // 5.2 是否加密 + switch (jT809Package.Header.EncryptFlag) + { + case JT809Header_Encrypt.None: + // 5.3 处理消息体 + jT809Package.Bodies = jT809Package.Header.BusinessType.Deserialize(ref reader, config); + break; + case JT809Header_Encrypt.Common: + // 5.4. 处理加密消息体 + byte[] bodiesData = config.Encrypt.Decrypt(reader.ReadContent(), config.EncryptOptions, jT809Package.Header.EncryptKey); + JT809MessagePackReader bodiesReader = new JT809MessagePackReader(bodiesData); + jT809Package.Bodies = jT809Package.Header.BusinessType.Deserialize(ref bodiesReader, config); + break; + } + } + catch (Exception ex) + { + throw new JT809Exception(JT809ErrorCode.BodiesParseError, $"offset>{reader.ReadCurrentRemainContentLength().ToString()}", ex); + } + } + jT809Package.CRCCode = reader.CalculateCheckXorCode; + jT809Package.EndFlag = reader.ReadEnd(); + return jT809Package; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809Package value, IJT809Config config) + { + // -----------开始组包---------- + // 1.起始符 + writer.WriteByte(value.BeginFlag); + // 2.写入头部数据 + // 2.1.跳过数据长度的写入 + writer.Skip(4, out int lengthPosition); + // 2.2.报文序列号 + value.Header.MsgSN = value.Header.MsgSN > 0 ? value.Header.MsgSN : config.MsgSNDistributed.Increment(); + writer.WriteUInt32(value.Header.MsgSN); + // 2.3.业务数据类型 + writer.WriteUInt16((ushort)value.Header.BusinessType); + // 2.4.下级平台接入码 + writer.WriteUInt32(value.Header.MsgGNSSCENTERID); + // 2.5.版本号 + writer.WriteArray(value.Header.Version.Buffer); + // 2.6.报文加密 + writer.WriteByte((byte)value.Header.EncryptFlag); + // 2.7.数据加密密钥 + writer.WriteUInt32(value.Header.EncryptKey); + // 3.写入数据体 + // 3.1.记录当前开始位置 + int startIndex = writer.GetCurrentPosition(); + // 3.2.写入数据对应数据体 + value.Header.BusinessType.Serialize(ref writer, value.Bodies, config); + // 3.3.记录当前结束位置 + int endIndex = writer.GetCurrentPosition(); + int contentLength = endIndex - startIndex; + if (contentLength > 0) + { + // 3.4. 数据加密 + switch (value.Header.EncryptFlag) + { + case JT809Header_Encrypt.None: + break; + case JT809Header_Encrypt.Common: + // 3.5. 提取数据体并进行加密处理 + byte[] messageBodyDatEncrypted = config.Encrypt.Encrypt(writer.Extract(startIndex), config.EncryptOptions, value.Header.EncryptKey); + int flagLength = messageBodyDatEncrypted.Length - contentLength; + if (flagLength == 0) + { + // 相等复制 + writer.CopyTo(messageBodyDatEncrypted, startIndex); + } + else if (flagLength > 0) + { + // 扩容 + writer.Skip(flagLength, out _); + writer.CopyTo(messageBodyDatEncrypted, startIndex); + } + else + { + // 缩减 + writer.CopyTo(messageBodyDatEncrypted, startIndex); + writer.Shrink(-flagLength); + } + break; + } + } + // 4.计算内容的总长度(校验码2+终止符1=3) + writer.WriteInt32Return(writer.GetCurrentPosition() + 3, lengthPosition); + // 5.校验码 + writer.WriteCRC16(); + // 6.终止符 + writer.WriteByte(value.EndFlag); + // 7.转义 + writer.WriteEncode(); + // -----------组包完成---------- + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1001_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1001_Formatter.cs new file mode 100644 index 0000000..50eaf6c --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1001_Formatter.cs @@ -0,0 +1,34 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x1001_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1001_Formatter Instance = new JT809_0x1001_Formatter(); + + public JT809_0x1001 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1001 jT809_0X1001 = new JT809_0x1001(); + jT809_0X1001.UserId = reader.ReadUInt32(); + jT809_0X1001.Password = reader.ReadString(8); + jT809_0X1001.DownLinkIP = reader.ReadString(32); + jT809_0X1001.DownLinkPort = reader.ReadUInt16(); + return jT809_0X1001; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1001 value, IJT809Config config) + { + writer.WriteUInt32(value.UserId); + writer.WriteStringPadRight(value.Password, 8); + writer.WriteStringPadRight(value.DownLinkIP, 32); + writer.WriteUInt16(value.DownLinkPort); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1002_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1002_Formatter.cs new file mode 100644 index 0000000..47e8d35 --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1002_Formatter.cs @@ -0,0 +1,31 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x1002_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1002_Formatter Instance = new JT809_0x1002_Formatter(); + + public JT809_0x1002 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1002 jT809_0X1002 = new JT809_0x1002(); + jT809_0X1002.Result = (JT809_0x1002_Result)reader.ReadByte(); + jT809_0X1002.VerifyCode = reader.ReadUInt32(); + return jT809_0X1002; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1002 value, IJT809Config config) + { + writer.WriteByte((byte)value.Result); + writer.WriteUInt32(value.VerifyCode); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1003_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1003_Formatter.cs new file mode 100644 index 0000000..4477136 --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1003_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x1003_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1003_Formatter Instance = new JT809_0x1003_Formatter(); + public JT809_0x1003 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1003 jT809_0X1003 = new JT809_0x1003(); + jT809_0X1003.UserId = reader.ReadUInt32(); + jT809_0X1003.Password = reader.ReadString(8); + return jT809_0X1003; + } + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1003 value, IJT809Config config) + { + writer.WriteUInt32(value.UserId); + writer.WriteStringPadLeft(value.Password, 8); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1007_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1007_Formatter.cs new file mode 100644 index 0000000..30f8b96 --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1007_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x1007_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1007_Formatter Instance = new JT809_0x1007_Formatter(); + + public JT809_0x1007 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1007 jT809_0X1007 = new JT809_0x1007(); + jT809_0X1007.ErrorCode = (JT809_0x1007_ErrorCode)reader.ReadByte(); + return jT809_0X1007; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1007 value, IJT809Config config) + { + writer.WriteByte((byte)value.ErrorCode); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1008_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1008_Formatter.cs new file mode 100644 index 0000000..a15227b --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1008_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x1008_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1008_Formatter Instance = new JT809_0x1008_Formatter(); + + public JT809_0x1008 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1008 jT809_0X1008 = new JT809_0x1008(); + jT809_0X1008.ReasonCode = (JT809_0x1008_ReasonCode)reader.ReadByte(); + return jT809_0X1008; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1008 value, IJT809Config config) + { + writer.WriteByte((byte)value.ReasonCode); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1300_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1300_Formatter.cs new file mode 100644 index 0000000..bde1b04 --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x1300_Formatter.cs @@ -0,0 +1,54 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Exceptions; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using JT809.Protocol.Internal; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x1300_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1300_Formatter Instance = new JT809_0x1300_Formatter(); + + public JT809_0x1300 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1300 jT809_0X1300 = new JT809_0x1300(); + jT809_0X1300.SubBusinessType = (JT809SubBusinessType)reader.ReadUInt16(); + jT809_0X1300.DataLength = reader.ReadUInt32(); + try + { + //JT809.Protocol.Enums.JT809BusinessType 映射对应消息特性 + jT809_0X1300.SubBodies = jT809_0X1300.SubBusinessType.Deserialize(ref reader, config); + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X1300.SubBusinessType.ToString()}"); + } + return jT809_0X1300; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1300 value, IJT809Config config) + { + writer.WriteUInt16((ushort)value.SubBusinessType); + //JT809.Protocol.Enums.JT809BusinessType 映射对应消息特性 + try + { + // 先写入内容,然后在根据内容反写内容长度 + writer.Skip(4, out int subContentLengthPosition); + value.SubBusinessType.Serialize(ref writer, value.SubBodies, config); + writer.WriteInt32Return(writer.GetCurrentPosition() - subContentLengthPosition - 4, subContentLengthPosition); + } + catch(Exception ex) + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}",ex); + } + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9001_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9001_Formatter.cs new file mode 100644 index 0000000..5b7feaf --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9001_Formatter.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x9001_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9001_Formatter Instance = new JT809_0x9001_Formatter(); + + public JT809_0x9001 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9001 jT809_0X9001 = new JT809_0x9001(); + jT809_0X9001.VerifyCode = reader.ReadUInt32(); + return jT809_0X9001; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9001 value, IJT809Config config) + { + writer.WriteUInt32(value.VerifyCode); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9002_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9002_Formatter.cs new file mode 100644 index 0000000..62aebc4 --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9002_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x9002_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9002_Formatter Instance = new JT809_0x9002_Formatter(); + + public JT809_0x9002 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9002 jT809_0X9002 = new JT809_0x9002(); + jT809_0X9002.Result = (JT809_0x9002_Result)reader.ReadByte(); + return jT809_0X9002; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9002 value, IJT809Config config) + { + writer.WriteByte((byte)value.Result); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9003_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9003_Formatter.cs new file mode 100644 index 0000000..551f30b --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9003_Formatter.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x9003_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9003_Formatter Instance = new JT809_0x9003_Formatter(); + + public JT809_0x9003 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9003 jT809_0X9003 = new JT809_0x9003(); + jT809_0X9003.VerifyCode = reader.ReadUInt32(); + return jT809_0X9003; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9003 value, IJT809Config config) + { + writer.WriteUInt32(value.VerifyCode); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9007_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9007_Formatter.cs new file mode 100644 index 0000000..ccd49fa --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9007_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.MessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x9007_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9007_Formatter Instance = new JT809_0x9007_Formatter(); + + public JT809_0x9007 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9007 jT809_0X9007 = new JT809_0x9007(); + jT809_0X9007.ReasonCode = (JT809_0x9007_ReasonCode)reader.ReadByte(); + return jT809_0X9007; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9007 value, IJT809Config config) + { + writer.WriteByte((byte)value.ReasonCode); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9008_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9008_Formatter.cs new file mode 100644 index 0000000..30062ea --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9008_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.MessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x9008_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9008_Formatter Instance = new JT809_0x9008_Formatter(); + + public JT809_0x9008 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9008 jT809_0X9008 = new JT809_0x9008(); + jT809_0X9008.ReasonCode = (JT809_0x9008_ReasonCode)reader.ReadByte(); + return jT809_0X9008; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9008 value, IJT809Config config) + { + writer.WriteByte((byte)value.ReasonCode); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9101_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9101_Formatter.cs new file mode 100644 index 0000000..bb01f20 --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9101_Formatter.cs @@ -0,0 +1,32 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x9101_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9101_Formatter Instance = new JT809_0x9101_Formatter(); + + public JT809_0x9101 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9101 jT809_0X9101 = new JT809_0x9101(); + jT809_0X9101.DynamicInfoTotal = reader.ReadUInt32(); + jT809_0X9101.StartTime = reader.ReadUInt64(); + jT809_0X9101.EndTime = reader.ReadUInt64(); + return jT809_0X9101; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9101 value, IJT809Config config) + { + writer.WriteUInt32(value.DynamicInfoTotal); + writer.WriteUInt64(value.StartTime); + writer.WriteUInt64(value.EndTime); + } + } +} diff --git a/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9300_Formatter.cs b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9300_Formatter.cs new file mode 100644 index 0000000..9c5bf1f --- /dev/null +++ b/src/JT809.Protocol/Formatters/MessageBodyFormatters/JT809_0x9300_Formatter.cs @@ -0,0 +1,54 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Exceptions; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.Internal; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.MessageBodyFormatters +{ + public class JT809_0x9300_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9300_Formatter Instance = new JT809_0x9300_Formatter(); + + public JT809_0x9300 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9300 jT809_0X9300 = new JT809_0x9300(); + jT809_0X9300.SubBusinessType = (JT809SubBusinessType)reader.ReadUInt16(); + jT809_0X9300.DataLength = reader.ReadUInt32(); + //JT809.Protocol.Enums.JT809BusinessType 映射对应消息特性 + try + { + jT809_0X9300.SubBodies = jT809_0X9300.SubBusinessType.Deserialize(ref reader, config); + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{jT809_0X9300.SubBusinessType.ToString()}"); + } + return jT809_0X9300; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9300 value, IJT809Config config) + { + writer.WriteUInt16((ushort)value.SubBusinessType); + //JT809.Protocol.Enums.JT809BusinessType 映射对应消息特性 + try + { + // 先写入内容,然后在根据内容反写内容长度 + writer.Skip(4, out int subContentLengthPosition); + value.SubBusinessType.Serialize(ref writer, value.SubBodies, config); + writer.WriteInt32Return(writer.GetCurrentPosition() - subContentLengthPosition - 4, subContentLengthPosition); + } + catch + { + throw new JT809Exception(JT809ErrorCode.SubBodiesParseError, $"SubBusinessType>{value.SubBusinessType.ToString()}"); + } + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1201_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1201_Formatter.cs new file mode 100644 index 0000000..275016a --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1201_Formatter.cs @@ -0,0 +1,38 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1200_0x1201_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1200_0x1201_Formatter Instance = new JT809_0x1200_0x1201_Formatter(); + + public JT809_0x1200_0x1201 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1200_0x1201 jT809_0X1200_0X1201 = new JT809_0x1200_0x1201(); + jT809_0X1200_0X1201.PlateformId = reader.ReadBigNumber(11); + jT809_0X1200_0X1201.ProducerId = reader.ReadBigNumber(11); + jT809_0X1200_0X1201.TerminalModelType = reader.ReadString(20); + jT809_0X1200_0X1201.TerminalId = reader.ReadString(7); + jT809_0X1200_0X1201.TerminalId = jT809_0X1200_0X1201.TerminalId.ToUpper(); + jT809_0X1200_0X1201.TerminalSimCode = reader.ReadString(12); + return jT809_0X1200_0X1201; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x1201 value, IJT809Config config) + { + writer.WriteBigNumber(value.PlateformId, 11); + writer.WriteBigNumber(value.ProducerId, 11); + writer.WriteStringPadRight(value.TerminalModelType, 20); + writer.WriteStringPadRight(value.TerminalId.ToUpper(), 7); + writer.WriteStringPadRight(value.TerminalSimCode, 12); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1202_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1202_Formatter.cs new file mode 100644 index 0000000..46c0cd1 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1202_Formatter.cs @@ -0,0 +1,59 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1200_0x1202_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1200_0x1202_Formatter Instance = new JT809_0x1200_0x1202_Formatter(); + + public JT809_0x1200_0x1202 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1200_0x1202 jT809_0X1200_0X1202 = new JT809_0x1200_0x1202(); + jT809_0X1200_0X1202.VehiclePosition.Encrypt = (JT809_VehiclePositionEncrypt)reader.ReadByte(); + jT809_0X1200_0X1202.VehiclePosition.Day = reader.ReadByte(); + jT809_0X1200_0X1202.VehiclePosition.Month = reader.ReadByte(); + jT809_0X1200_0X1202.VehiclePosition.Year = reader.ReadUInt16(); + jT809_0X1200_0X1202.VehiclePosition.Hour = reader.ReadByte(); + jT809_0X1200_0X1202.VehiclePosition.Minute = reader.ReadByte(); + jT809_0X1200_0X1202.VehiclePosition.Second = reader.ReadByte(); + jT809_0X1200_0X1202.VehiclePosition.Lon = reader.ReadUInt32(); + jT809_0X1200_0X1202.VehiclePosition.Lat = reader.ReadUInt32(); + jT809_0X1200_0X1202.VehiclePosition.Vec1 = reader.ReadUInt16(); + jT809_0X1200_0X1202.VehiclePosition.Vec2 = reader.ReadUInt16(); + jT809_0X1200_0X1202.VehiclePosition.Vec3 = reader.ReadUInt32(); + jT809_0X1200_0X1202.VehiclePosition.Direction = reader.ReadUInt16(); + jT809_0X1200_0X1202.VehiclePosition.Altitude = reader.ReadUInt16(); + jT809_0X1200_0X1202.VehiclePosition.State = reader.ReadUInt32(); + jT809_0X1200_0X1202.VehiclePosition.Alarm = reader.ReadUInt32(); + return jT809_0X1200_0X1202; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x1202 value, IJT809Config config) + { + writer.WriteByte((byte)value.VehiclePosition.Encrypt); + writer.WriteByte(value.VehiclePosition.Day); + writer.WriteByte(value.VehiclePosition.Month); + writer.WriteUInt16(value.VehiclePosition.Year); + writer.WriteByte(value.VehiclePosition.Hour); + writer.WriteByte(value.VehiclePosition.Minute); + writer.WriteByte(value.VehiclePosition.Second); + writer.WriteUInt32(value.VehiclePosition.Lon); + writer.WriteUInt32(value.VehiclePosition.Lat); + writer.WriteUInt16(value.VehiclePosition.Vec1); + writer.WriteUInt16(value.VehiclePosition.Vec2); + writer.WriteUInt32(value.VehiclePosition.Vec3); + writer.WriteUInt16(value.VehiclePosition.Direction); + writer.WriteUInt16(value.VehiclePosition.Altitude); + writer.WriteUInt32(value.VehiclePosition.State); + writer.WriteUInt32(value.VehiclePosition.Alarm); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1203_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1203_Formatter.cs new file mode 100644 index 0000000..b2da99c --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1203_Formatter.cs @@ -0,0 +1,58 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.Metadata; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1200_0x1203_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1200_0x1203_Formatter Instance = new JT809_0x1200_0x1203_Formatter(); + + public JT809_0x1200_0x1203 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1200_0x1203 jT809_0X1200_0X1203 = new JT809_0x1200_0x1203(); + jT809_0X1200_0X1203.GNSSCount = reader.ReadByte(); + jT809_0X1200_0X1203.GNSS = new List(); + if (jT809_0X1200_0X1203.GNSSCount > 0) + { + for (int i = 0; i < jT809_0X1200_0X1203.GNSSCount; i++) + { + try + { + JT809MessagePackReader jT809_0x1200_0x1202Reader = new JT809MessagePackReader(reader.ReadArray(36)); + var jT809_0x1200_0x1202= JT809_0x1200_0x1202_Formatter.Instance.Deserialize(ref jT809_0x1200_0x1202Reader, config); + jT809_0X1200_0X1203.GNSS.Add(jT809_0x1200_0x1202); + } + catch (Exception) + { + + } + } + } + return jT809_0X1200_0X1203; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x1203 value, IJT809Config config) + { + writer.WriteByte((byte)value.GNSS.Count); + foreach (var item in value.GNSS) + { + try + { + JT809_0x1200_0x1202_Formatter.Instance.Serialize(ref writer, item, config); + } + catch (Exception ex) + { + + } + } + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1207_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1207_Formatter.cs new file mode 100644 index 0000000..211b245 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1207_Formatter.cs @@ -0,0 +1,30 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1200_0x1207_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1200_0x1207_Formatter Instance = new JT809_0x1200_0x1207_Formatter(); + + public JT809_0x1200_0x1207 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1200_0x1207 jT809_0X1200_0X1207 = new JT809_0x1200_0x1207(); + jT809_0X1200_0X1207.StartTime = reader.ReadUTCDateTime(); + jT809_0X1200_0X1207.EndTime = reader.ReadUTCDateTime(); + return jT809_0X1200_0X1207; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x1207 value, IJT809Config config) + { + writer.WriteUTCDateTime(value.StartTime); + writer.WriteUTCDateTime(value.EndTime); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1209_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1209_Formatter.cs new file mode 100644 index 0000000..6fbbd11 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x1209_Formatter.cs @@ -0,0 +1,30 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1200_0x1209_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1200_0x1209_Formatter Instance = new JT809_0x1200_0x1209_Formatter(); + + public JT809_0x1200_0x1209 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1200_0x1209 jT809_0X1200_0X1207 = new JT809_0x1200_0x1209(); + jT809_0X1200_0X1207.StartTime = reader.ReadUTCDateTime(); + jT809_0X1200_0X1207.EndTime = reader.ReadUTCDateTime(); + return jT809_0X1200_0X1207; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x1209 value, IJT809Config config) + { + writer.WriteUTCDateTime(value.StartTime); + writer.WriteUTCDateTime(value.EndTime); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120A_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120A_Formatter.cs new file mode 100644 index 0000000..a596065 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120A_Formatter.cs @@ -0,0 +1,34 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1200_0x120A_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1200_0x120A_Formatter Instance = new JT809_0x1200_0x120A_Formatter(); + + public JT809_0x1200_0x120A Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1200_0x120A jT809_0X1200_0X120A = new JT809_0x1200_0x120A(); + jT809_0X1200_0X120A.DriverName = reader.ReadString(16); + jT809_0X1200_0X120A.DriverID = reader.ReadString(20); + jT809_0X1200_0X120A.Licence = reader.ReadString(40); + jT809_0X1200_0X120A.OrgName = reader.ReadString(200); + return jT809_0X1200_0X120A; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x120A value, IJT809Config config) + { + writer.WriteStringPadRight(value.DriverName, 16); + writer.WriteStringPadRight(value.DriverID, 20); + writer.WriteStringPadRight(value.Licence, 40); + writer.WriteStringPadRight(value.OrgName, 200); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120B_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120B_Formatter.cs new file mode 100644 index 0000000..99c181f --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120B_Formatter.cs @@ -0,0 +1,30 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1200_0x120B_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1200_0x120B_Formatter Instance = new JT809_0x1200_0x120B_Formatter(); + + public JT809_0x1200_0x120B Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1200_0x120B jT809_0X1200_0X120B = new JT809_0x1200_0x120B(); + jT809_0X1200_0X120B.EwaybillLength = reader.ReadUInt32(); + jT809_0X1200_0X120B.EwaybillInfo = reader.ReadString((int)jT809_0X1200_0X120B.EwaybillLength); + return jT809_0X1200_0X120B; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x120B value, IJT809Config config) + { + writer.WriteUInt32((uint)value.EwaybillInfo.Length); + writer.WriteString(value.EwaybillInfo); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120C_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120C_Formatter.cs new file mode 100644 index 0000000..4b3f70e --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120C_Formatter.cs @@ -0,0 +1,34 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1200_0x120C_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1200_0x120C_Formatter Instance = new JT809_0x1200_0x120C_Formatter(); + + public JT809_0x1200_0x120C Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1200_0x120C jT809_0X1200_0X120C = new JT809_0x1200_0x120C(); + jT809_0X1200_0X120C.DriverName = reader.ReadString(16); + jT809_0X1200_0X120C.DriverID = reader.ReadString(20); + jT809_0X1200_0X120C.Licence = reader.ReadString(40); + jT809_0X1200_0X120C.OrgName = reader.ReadString(200); + return jT809_0X1200_0X120C; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x120C value, IJT809Config config) + { + writer.WriteStringPadRight(value.DriverName, 16); + writer.WriteStringPadRight(value.DriverID, 20); + writer.WriteStringPadRight(value.Licence, 40); + writer.WriteStringPadRight(value.OrgName, 200); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120D_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120D_Formatter.cs new file mode 100644 index 0000000..b767fe9 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1200_0x120D_Formatter.cs @@ -0,0 +1,30 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1200_0x120D_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1200_0x120D_Formatter Instance = new JT809_0x1200_0x120D_Formatter(); + + public JT809_0x1200_0x120D Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1200_0x120D jT809_0X1200_0X120D = new JT809_0x1200_0x120D(); + jT809_0X1200_0X120D.EwaybillLength = reader.ReadUInt32(); + jT809_0X1200_0X120D.EwaybillInfo = reader.ReadString((int)jT809_0X1200_0X120D.EwaybillLength); + return jT809_0X1200_0X120D; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1200_0x120D value, IJT809Config config) + { + writer.WriteUInt32((uint)value.EwaybillInfo.Length); + writer.WriteString(value.EwaybillInfo); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1300_0x1301_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1300_0x1301_Formatter.cs new file mode 100644 index 0000000..d3dbc48 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1300_0x1301_Formatter.cs @@ -0,0 +1,39 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1300_0x1301_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1300_0x1301_Formatter Instance = new JT809_0x1300_0x1301_Formatter(); + + public JT809_0x1300_0x1301 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1300_0x1301 jT809_0X1200_0X1301 = new JT809_0x1300_0x1301(); + jT809_0X1200_0X1301.ObjectType = (JT809_0x1301_ObjectType)reader.ReadByte(); + jT809_0X1200_0X1301.ObjectID = reader.ReadString(12); + jT809_0X1200_0X1301.InfoID = reader.ReadUInt32(); + jT809_0X1200_0X1301.InfoLength = reader.ReadUInt32(); + jT809_0X1200_0X1301.InfoContent = reader.ReadString((int)jT809_0X1200_0X1301.InfoLength); + return jT809_0X1200_0X1301; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1300_0x1301 value, IJT809Config config) + { + writer.WriteByte((byte)value.ObjectType); + writer.WriteStringPadRight(value.ObjectID, 12); + writer.WriteUInt32(value.InfoID); + // 先计算内容长度(汉字为两个字节) + writer.Skip(4, out int lengthPosition); + writer.WriteString(value.InfoContent); + writer.WriteInt32Return(writer.GetCurrentPosition() - lengthPosition - 4, lengthPosition); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1300_0x1302_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1300_0x1302_Formatter.cs new file mode 100644 index 0000000..572d420 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1300_0x1302_Formatter.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1300_0x1302_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1300_0x1302_Formatter Instance = new JT809_0x1300_0x1302_Formatter(); + + public JT809_0x1300_0x1302 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1300_0x1302 jT809_0X1200_0X1302 = new JT809_0x1300_0x1302(); + jT809_0X1200_0X1302.InfoID = reader.ReadUInt32(); + return jT809_0X1200_0X1302; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1300_0x1302 value, IJT809Config config) + { + writer.WriteUInt32(value.InfoID); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1400_0x1401_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1400_0x1401_Formatter.cs new file mode 100644 index 0000000..5c30359 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1400_0x1401_Formatter.cs @@ -0,0 +1,31 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1400_0x1401_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1400_0x1401_Formatter Instance = new JT809_0x1400_0x1401_Formatter(); + + public JT809_0x1400_0x1401 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1400_0x1401 jT809_0X1400_0X1401 = new JT809_0x1400_0x1401(); + jT809_0X1400_0X1401.SupervisionID = reader.ReadUInt32(); + jT809_0X1400_0X1401.Result = (JT809_0x1401_Result)reader.ReadByte(); + return jT809_0X1400_0X1401; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1400_0x1401 value, IJT809Config config) + { + writer.WriteUInt32(value.SupervisionID); + writer.WriteByte((byte)value.Result); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1400_0x1402_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1400_0x1402_Formatter.cs new file mode 100644 index 0000000..87e8c83 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1400_0x1402_Formatter.cs @@ -0,0 +1,41 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1400_0x1402_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1400_0x1402_Formatter Instance = new JT809_0x1400_0x1402_Formatter(); + + public JT809_0x1400_0x1402 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1400_0x1402 jT809_0X1400_0X1402 = new JT809_0x1400_0x1402(); + jT809_0X1400_0X1402.WarnSrc = (JT809WarnSrc)reader.ReadByte(); + jT809_0X1400_0X1402.WarnType = (JT809WarnType)reader.ReadUInt16(); + jT809_0X1400_0X1402.WarnTime = reader.ReadUTCDateTime(); + jT809_0X1400_0X1402.InfoID = reader.ReadUInt32(); + jT809_0X1400_0X1402.InfoLength = reader.ReadUInt32(); + jT809_0X1400_0X1402.InfoContent = reader.ReadString((int)jT809_0X1400_0X1402.InfoLength); + return jT809_0X1400_0X1402; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1400_0x1402 value, IJT809Config config) + { + writer.WriteByte((byte)value.WarnSrc); + writer.WriteUInt16((ushort)value.WarnType); + writer.WriteUTCDateTime(value.WarnTime); + writer.WriteUInt32(value.InfoID); + // 先计算内容长度(汉字为两个字节) + writer.Skip(4, out int lengthPosition); + writer.WriteString(value.InfoContent); + writer.WriteInt32Return(writer.GetCurrentPosition() - lengthPosition - 4, lengthPosition); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1400_0x1403_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1400_0x1403_Formatter.cs new file mode 100644 index 0000000..ec5ed21 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1400_0x1403_Formatter.cs @@ -0,0 +1,31 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1400_0x1403_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1400_0x1403_Formatter Instance = new JT809_0x1400_0x1403_Formatter(); + + public JT809_0x1400_0x1403 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1400_0x1403 jT809_0X1400_0X1403 = new JT809_0x1400_0x1403(); + jT809_0X1400_0X1403.InfoID = reader.ReadUInt32(); + jT809_0X1400_0X1403.Result = (JT809_0x1403_Result)reader.ReadByte(); + return jT809_0X1400_0X1403; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1400_0x1403 value, IJT809Config config) + { + writer.WriteUInt32(value.InfoID); + writer.WriteByte((byte)value.Result); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1501_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1501_Formatter.cs new file mode 100644 index 0000000..5a4103b --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1501_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1500_0x1501_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1500_0x1501_Formatter Instance = new JT809_0x1500_0x1501_Formatter(); + + public JT809_0x1500_0x1501 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1500_0x1501 jT809_0X1500_0X1501 = new JT809_0x1500_0x1501(); + jT809_0X1500_0X1501.Result = (JT809_0x1501_Result)reader.ReadByte(); + return jT809_0X1500_0X1501; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1500_0x1501 value, IJT809Config config) + { + writer.WriteByte((byte)value.Result); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1502_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1502_Formatter.cs new file mode 100644 index 0000000..38a9de4 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1502_Formatter.cs @@ -0,0 +1,78 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1500_0x1502_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1500_0x1502_Formatter Instance = new JT809_0x1500_0x1502_Formatter(); + + public JT809_0x1500_0x1502 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1500_0x1502 jT809_0X1500_0X1502 = new JT809_0x1500_0x1502(); + jT809_0X1500_0X1502.PhotoRspFlag = (JT809_0x1502_PhotoRspFlag)reader.ReadByte(); + jT809_0X1500_0X1502.VehiclePosition.Encrypt = (JT809_VehiclePositionEncrypt)reader.ReadByte(); + jT809_0X1500_0X1502.VehiclePosition.Day = reader.ReadByte(); + jT809_0X1500_0X1502.VehiclePosition.Month = reader.ReadByte(); + jT809_0X1500_0X1502.VehiclePosition.Year = reader.ReadUInt16(); + jT809_0X1500_0X1502.VehiclePosition.Hour = reader.ReadByte(); + jT809_0X1500_0X1502.VehiclePosition.Minute = reader.ReadByte(); + jT809_0X1500_0X1502.VehiclePosition.Second = reader.ReadByte(); + jT809_0X1500_0X1502.VehiclePosition.Lon = reader.ReadUInt32(); + jT809_0X1500_0X1502.VehiclePosition.Lat = reader.ReadUInt32(); + jT809_0X1500_0X1502.VehiclePosition.Vec1 = reader.ReadUInt16(); + jT809_0X1500_0X1502.VehiclePosition.Vec2 = reader.ReadUInt16(); + jT809_0X1500_0X1502.VehiclePosition.Vec3 = reader.ReadUInt32(); + jT809_0X1500_0X1502.VehiclePosition.Direction = reader.ReadUInt16(); + jT809_0X1500_0X1502.VehiclePosition.Altitude = reader.ReadUInt16(); + jT809_0X1500_0X1502.VehiclePosition.State = reader.ReadUInt32(); + jT809_0X1500_0X1502.VehiclePosition.Alarm = reader.ReadUInt32(); + jT809_0X1500_0X1502.LensID = reader.ReadByte(); + jT809_0X1500_0X1502.PhotoLen = reader.ReadUInt32(); + jT809_0X1500_0X1502.SizeType = reader.ReadByte(); + jT809_0X1500_0X1502.Type = reader.ReadByte(); + if (jT809_0X1500_0X1502.PhotoLen > 0) + { + jT809_0X1500_0X1502.Photo = reader.ReadArray((int)jT809_0X1500_0X1502.PhotoLen).ToArray(); + } + return jT809_0X1500_0X1502; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1500_0x1502 value, IJT809Config config) + { + writer.WriteByte((byte)value.PhotoRspFlag); + writer.WriteByte((byte)value.VehiclePosition.Encrypt); + writer.WriteByte(value.VehiclePosition.Day); + writer.WriteByte(value.VehiclePosition.Month); + writer.WriteUInt16(value.VehiclePosition.Year); + writer.WriteByte(value.VehiclePosition.Hour); + writer.WriteByte(value.VehiclePosition.Minute); + writer.WriteByte(value.VehiclePosition.Second); + writer.WriteUInt32(value.VehiclePosition.Lon); + writer.WriteUInt32(value.VehiclePosition.Lat); + writer.WriteUInt16(value.VehiclePosition.Vec1); + writer.WriteUInt16(value.VehiclePosition.Vec2); + writer.WriteUInt32(value.VehiclePosition.Vec3); + writer.WriteUInt16(value.VehiclePosition.Direction); + writer.WriteUInt16(value.VehiclePosition.Altitude); + writer.WriteUInt32(value.VehiclePosition.State); + writer.WriteUInt32(value.VehiclePosition.Alarm); + writer.WriteByte(value.LensID); + bool isPhoto = (value.Photo != null && value.Photo.Length > 0); + writer.WriteUInt32(isPhoto ? (uint)value.Photo.Length : 0); + writer.WriteByte(value.SizeType); + writer.WriteByte(value.Type); + if (isPhoto) + { + writer.WriteArray(value.Photo); + } + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1503_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1503_Formatter.cs new file mode 100644 index 0000000..b58c7fc --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1503_Formatter.cs @@ -0,0 +1,31 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1500_0x1503_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1500_0x1503_Formatter Instance = new JT809_0x1500_0x1503_Formatter(); + + public JT809_0x1500_0x1503 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1500_0x1503 jT809_0X1500_0X1503 = new JT809_0x1500_0x1503(); + jT809_0X1500_0X1503.MsgID = reader.ReadUInt32(); + jT809_0X1500_0X1503.Result = (JT809_0x1503_Result)reader.ReadByte(); + return jT809_0X1500_0X1503; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1500_0x1503 value, IJT809Config config) + { + writer.WriteUInt32(value.MsgID); + writer.WriteByte((byte)value.Result); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1504_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1504_Formatter.cs new file mode 100644 index 0000000..d8d1d5c --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1504_Formatter.cs @@ -0,0 +1,35 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1500_0x1504_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1500_0x1504_Formatter Instance = new JT809_0x1500_0x1504_Formatter(); + + public JT809_0x1500_0x1504 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1500_0x1504 jT809_0X1500_0X1504 = new JT809_0x1500_0x1504(); + jT809_0X1500_0X1504.CommandType = (JT809CommandType)reader.ReadByte(); + jT809_0X1500_0X1504.TraveldataLength = reader.ReadUInt32(); + jT809_0X1500_0X1504.TraveldataInfo = reader.ReadString((int)jT809_0X1500_0X1504.TraveldataLength); + return jT809_0X1500_0X1504; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1500_0x1504 value, IJT809Config config) + { + writer.WriteByte((byte)value.CommandType); + // 先计算内容长度(汉字为两个字节) + writer.Skip(4, out int lengthPosition); + writer.WriteString(value.TraveldataInfo); + writer.WriteInt32Return(writer.GetCurrentPosition() - lengthPosition - 4, lengthPosition); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1505_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1505_Formatter.cs new file mode 100644 index 0000000..346ef5b --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1500_0x1505_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1500_0x1505_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1500_0x1505_Formatter Instance = new JT809_0x1500_0x1505_Formatter(); + + public JT809_0x1500_0x1505 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1500_0x1505 jT809_0X1500_0X1505 = new JT809_0x1500_0x1505(); + jT809_0X1500_0X1505.Result = (JT809_0x1505_Result)reader.ReadByte(); + return jT809_0X1500_0X1505; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1500_0x1505 value, IJT809Config config) + { + writer.WriteByte((byte)value.Result); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1600_0x1601_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1600_0x1601_Formatter.cs new file mode 100644 index 0000000..83a3015 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x1600_0x1601_Formatter.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x1600_0x1601_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x1600_0x1601_Formatter Instance = new JT809_0x1600_0x1601_Formatter(); + + public JT809_0x1600_0x1601 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x1600_0x1601 jT809_0X9600_0X1601 = new JT809_0x1600_0x1601(); + jT809_0X9600_0X1601.CarInfo = reader.ReadRemainStringContent(); + return jT809_0X9600_0X1601; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x1600_0x1601 value, IJT809Config config) + { + writer.WriteString(value.CarInfo); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9202_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9202_Formatter.cs new file mode 100644 index 0000000..5356b83 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9202_Formatter.cs @@ -0,0 +1,59 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.SubMessageBody; +using JT809.Protocol.Enums; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9200_0x9202_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9200_0x9202_Formatter Instance = new JT809_0x9200_0x9202_Formatter(); + + public JT809_0x9200_0x9202 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9200_0x9202 jT809_0X1200_0x9202 = new JT809_0x9200_0x9202(); + jT809_0X1200_0x9202.VehiclePosition.Encrypt = (JT809_VehiclePositionEncrypt)reader.ReadByte(); + jT809_0X1200_0x9202.VehiclePosition.Day = reader.ReadByte(); + jT809_0X1200_0x9202.VehiclePosition.Month = reader.ReadByte(); + jT809_0X1200_0x9202.VehiclePosition.Year = reader.ReadUInt16(); + jT809_0X1200_0x9202.VehiclePosition.Hour = reader.ReadByte(); + jT809_0X1200_0x9202.VehiclePosition.Minute = reader.ReadByte(); + jT809_0X1200_0x9202.VehiclePosition.Second = reader.ReadByte(); + jT809_0X1200_0x9202.VehiclePosition.Lon = reader.ReadUInt32(); + jT809_0X1200_0x9202.VehiclePosition.Lat = reader.ReadUInt32(); + jT809_0X1200_0x9202.VehiclePosition.Vec1 = reader.ReadUInt16(); + jT809_0X1200_0x9202.VehiclePosition.Vec2 = reader.ReadUInt16(); + jT809_0X1200_0x9202.VehiclePosition.Vec3 = reader.ReadUInt32(); + jT809_0X1200_0x9202.VehiclePosition.Direction = reader.ReadUInt16(); + jT809_0X1200_0x9202.VehiclePosition.Altitude = reader.ReadUInt16(); + jT809_0X1200_0x9202.VehiclePosition.State = reader.ReadUInt32(); + jT809_0X1200_0x9202.VehiclePosition.Alarm = reader.ReadUInt32(); + return jT809_0X1200_0x9202; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9200_0x9202 value, IJT809Config config) + { + writer.WriteByte((byte)value.VehiclePosition.Encrypt); + writer.WriteByte(value.VehiclePosition.Day); + writer.WriteByte(value.VehiclePosition.Month); + writer.WriteUInt16(value.VehiclePosition.Year); + writer.WriteByte(value.VehiclePosition.Hour); + writer.WriteByte(value.VehiclePosition.Minute); + writer.WriteByte(value.VehiclePosition.Second); + writer.WriteUInt32(value.VehiclePosition.Lon); + writer.WriteUInt32(value.VehiclePosition.Lat); + writer.WriteUInt16(value.VehiclePosition.Vec1); + writer.WriteUInt16(value.VehiclePosition.Vec2); + writer.WriteUInt32(value.VehiclePosition.Vec3); + writer.WriteUInt16(value.VehiclePosition.Direction); + writer.WriteUInt16(value.VehiclePosition.Altitude); + writer.WriteUInt32(value.VehiclePosition.State); + writer.WriteUInt32(value.VehiclePosition.Alarm); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9203_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9203_Formatter.cs new file mode 100644 index 0000000..e11f6ab --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9203_Formatter.cs @@ -0,0 +1,57 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.Metadata; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9200_0x9203_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9200_0x9203_Formatter Instance = new JT809_0x9200_0x9203_Formatter(); + + public JT809_0x9200_0x9203 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9200_0x9203 jT809_0X1200_0x9203 = new JT809_0x9200_0x9203(); + jT809_0X1200_0x9203.GNSSCount = reader.ReadByte(); + jT809_0X1200_0x9203.GNSS = new List(); + if (jT809_0X1200_0x9203.GNSSCount > 0) + { + for (int i = 0; i < jT809_0X1200_0x9203.GNSSCount; i++) + { + try + { + JT809MessagePackReader jT809_0x9200_0x9202Reader = new JT809MessagePackReader(reader.ReadArray(36)); + JT809_0x9200_0x9202 jT809_0x1200_0x1202 = JT809_0x9200_0x9202_Formatter.Instance.Deserialize(ref jT809_0x9200_0x9202Reader, config); + jT809_0X1200_0x9203.GNSS.Add(jT809_0x1200_0x1202); + } + catch (Exception) + { + } + } + } + return jT809_0X1200_0x9203; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9200_0x9203 value, IJT809Config config) + { + writer.WriteByte((byte)value.GNSS.Count); + foreach (var item in value.GNSS) + { + try + { + JT809_0x9200_0x9202_Formatter.Instance.Serialize(ref writer, item, config); + } + catch (Exception ex) + { + + } + } + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9204_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9204_Formatter.cs new file mode 100644 index 0000000..5143974 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9204_Formatter.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9200_0x9204_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9200_0x9204_Formatter Instance = new JT809_0x9200_0x9204_Formatter(); + + public JT809_0x9200_0x9204 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9200_0x9204 jT809_0X1200_0x9204 = new JT809_0x9200_0x9204(); + jT809_0X1200_0x9204.CarInfo = reader.ReadRemainStringContent(); + return jT809_0X1200_0x9204; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9200_0x9204 value, IJT809Config config) + { + writer.WriteString(value.CarInfo); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9205_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9205_Formatter.cs new file mode 100644 index 0000000..214b291 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9205_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9200_0x9205_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9200_0x9205_Formatter Instance = new JT809_0x9200_0x9205_Formatter(); + + public JT809_0x9200_0x9205 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9200_0x9205 jT809_0X1200_0x9205 = new JT809_0x9200_0x9205(); + jT809_0X1200_0x9205.ReasonCode = (JT809_0x9205_ReasonCode)reader.ReadByte(); + return jT809_0X1200_0x9205; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9200_0x9205 value, IJT809Config config) + { + writer.WriteByte((byte)value.ReasonCode); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9206_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9206_Formatter.cs new file mode 100644 index 0000000..d0a62d8 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9206_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9200_0x9206_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9200_0x9206_Formatter Instance = new JT809_0x9200_0x9206_Formatter(); + + public JT809_0x9200_0x9206 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9200_0x9206 jT809_0X1200_0x9206 = new JT809_0x9200_0x9206(); + jT809_0X1200_0x9206.ReasonCode = (JT809_0x9206_ReasonCode)reader.ReadByte(); + return jT809_0X1200_0x9206; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9200_0x9206 value, IJT809Config config) + { + writer.WriteByte((byte)value.ReasonCode); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9207_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9207_Formatter.cs new file mode 100644 index 0000000..54c2271 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9207_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9200_0x9207_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9200_0x9207_Formatter Instance = new JT809_0x9200_0x9207_Formatter(); + + public JT809_0x9200_0x9207 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9200_0x9207 jT809_0X1200_0x9207 = new JT809_0x9200_0x9207(); + jT809_0X1200_0x9207.Result = (JT809_0x9207_Result)reader.ReadByte(); + return jT809_0X1200_0x9207; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9200_0x9207 value, IJT809Config config) + { + writer.WriteByte((byte)value.Result); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9208_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9208_Formatter.cs new file mode 100644 index 0000000..2e7c51f --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9208_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9200_0x9208_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9200_0x9208_Formatter Instance = new JT809_0x9200_0x9208_Formatter(); + + public JT809_0x9200_0x9208 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9200_0x9208 jT809_0X1200_0x9208 = new JT809_0x9200_0x9208(); + jT809_0X1200_0x9208.Result = (JT809_0x9208_Result)reader.ReadByte(); + return jT809_0X1200_0x9208; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9200_0x9208 value, IJT809Config config) + { + writer.WriteByte((byte)value.Result); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9209_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9209_Formatter.cs new file mode 100644 index 0000000..0289f6d --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9200_0x9209_Formatter.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9200_0x9209_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9200_0x9209_Formatter Instance = new JT809_0x9200_0x9209_Formatter(); + + public JT809_0x9200_0x9209 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9200_0x9209 jT809_0X1200_0x9209 = new JT809_0x9200_0x9209(); + jT809_0X1200_0x9209.Result = (JT809_0x9209_Result)reader.ReadByte(); + return jT809_0X1200_0x9209; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9200_0x9209 value, IJT809Config config) + { + writer.WriteByte((byte)value.Result); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9300_0x9301_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9300_0x9301_Formatter.cs new file mode 100644 index 0000000..2d41b28 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9300_0x9301_Formatter.cs @@ -0,0 +1,40 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9300_0x9301_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9300_0x9301_Formatter Instance = new JT809_0x9300_0x9301_Formatter(); + + public JT809_0x9300_0x9301 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9300_0x9301 jT809_0X9300_0X9301 = new JT809_0x9300_0x9301(); + jT809_0X9300_0X9301.ObjectType = (JT809_0x9301_ObjectType)reader.ReadByte(); + jT809_0X9300_0X9301.ObjectID = reader.ReadString(12); + jT809_0X9300_0X9301.InfoID = reader.ReadUInt32(); + jT809_0X9300_0X9301.InfoLength = reader.ReadUInt32(); + jT809_0X9300_0X9301.InfoContent = reader.ReadString((int)jT809_0X9300_0X9301.InfoLength); + return jT809_0X9300_0X9301; + } + + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9300_0x9301 value, IJT809Config config) + { + writer.WriteByte((byte)value.ObjectType); + writer.WriteStringPadRight(value.ObjectID, 12); + writer.WriteUInt32(value.InfoID); + // 先计算内容长度(汉字为两个字节) + writer.Skip(4, out int lengthPosition); + writer.WriteString(value.InfoContent); + writer.WriteInt32Return(writer.GetCurrentPosition() - lengthPosition - 4, lengthPosition); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9300_0x9302_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9300_0x9302_Formatter.cs new file mode 100644 index 0000000..6f1ebef --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9300_0x9302_Formatter.cs @@ -0,0 +1,39 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9300_0x9302_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9300_0x9302_Formatter Instance = new JT809_0x9300_0x9302_Formatter(); + + public JT809_0x9300_0x9302 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9300_0x9302 jT809_0X9300_0X9302 = new JT809_0x9300_0x9302(); + jT809_0X9300_0X9302.ObjectType = (JT809_0x9302_ObjectType)reader.ReadByte(); + jT809_0X9300_0X9302.ObjectID = reader.ReadString(12); + jT809_0X9300_0X9302.InfoID = reader.ReadUInt32(); + jT809_0X9300_0X9302.InfoLength = reader.ReadUInt32(); + jT809_0X9300_0X9302.InfoContent = reader.ReadString((int)jT809_0X9300_0X9302.InfoLength); + return jT809_0X9300_0X9302; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9300_0x9302 value, IJT809Config config) + { + writer.WriteByte((byte)value.ObjectType); + writer.WriteStringPadRight(value.ObjectID, 12); + writer.WriteUInt32( value.InfoID); + // 先计算内容长度(汉字为两个字节) + writer.Skip(4, out int lengthPosition); + writer.WriteString(value.InfoContent); + writer.WriteInt32Return(writer.GetCurrentPosition() - lengthPosition - 4, lengthPosition); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9400_0x9401_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9400_0x9401_Formatter.cs new file mode 100644 index 0000000..3022792 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9400_0x9401_Formatter.cs @@ -0,0 +1,45 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9400_0x9401_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9400_0x9401_Formatter Instance = new JT809_0x9400_0x9401_Formatter(); + + public JT809_0x9400_0x9401 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9400_0x9401 jT809_0X9400_0X9401 = new JT809_0x9400_0x9401(); + jT809_0X9400_0X9401.WarnSrc = (JT809WarnSrc)reader.ReadByte(); + jT809_0X9400_0X9401.WarnType = (JT809WarnType)reader.ReadUInt16(); + jT809_0X9400_0X9401.WarnTime = reader.ReadUTCDateTime(); + jT809_0X9400_0X9401.SupervisionID = reader.ReadHex(4); + jT809_0X9400_0X9401.SupervisionEndTime = reader.ReadUTCDateTime(); + jT809_0X9400_0X9401.SupervisionLevel = reader.ReadByte(); + jT809_0X9400_0X9401.Supervisor = reader.ReadString(16); + jT809_0X9400_0X9401.SupervisorTel = reader.ReadString(20); + jT809_0X9400_0X9401.SupervisorEmail = reader.ReadString(32); + return jT809_0X9400_0X9401; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9400_0x9401 value, IJT809Config config) + { + writer.WriteByte((byte)value.WarnSrc); + writer.WriteUInt16((ushort)value.WarnType); + writer.WriteUTCDateTime(value.WarnTime); + writer.WriteHex(value.SupervisionID, 4); + writer.WriteUTCDateTime(value.SupervisionEndTime); + writer.WriteByte(value.SupervisionLevel); + writer.WriteStringPadRight(value.Supervisor, 16); + writer.WriteStringPadRight(value.SupervisorTel, 20); + writer.WriteStringPadRight(value.SupervisorEmail, 32); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9400_0x9402_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9400_0x9402_Formatter.cs new file mode 100644 index 0000000..25ce0e2 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9400_0x9402_Formatter.cs @@ -0,0 +1,39 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9400_0x9402_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9400_0x9402_Formatter Instance = new JT809_0x9400_0x9402_Formatter(); + + public JT809_0x9400_0x9402 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9400_0x9402 jT809_0X9400_0X9402 = new JT809_0x9400_0x9402(); + jT809_0X9400_0X9402.WarnSrc = (JT809WarnSrc)reader.ReadByte(); + jT809_0X9400_0X9402.WarnType = (JT809WarnType)reader.ReadUInt16(); + jT809_0X9400_0X9402.WarnTime = reader.ReadUTCDateTime(); + jT809_0X9400_0X9402.WarnLength = reader.ReadUInt32(); + jT809_0X9400_0X9402.WarnContent = reader.ReadString( (int)jT809_0X9400_0X9402.WarnLength); + return jT809_0X9400_0X9402; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9400_0x9402 value, IJT809Config config) + { + writer.WriteByte((byte)value.WarnSrc); + writer.WriteUInt16((ushort)value.WarnType); + writer.WriteUTCDateTime(value.WarnTime); + // 先计算内容长度(汉字为两个字节) + writer.Skip(4, out int lengthPosition); + writer.WriteString(value.WarnContent); + writer.WriteInt32Return(writer.GetCurrentPosition() - lengthPosition - 4, lengthPosition); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9400_0x9403_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9400_0x9403_Formatter.cs new file mode 100644 index 0000000..0838674 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9400_0x9403_Formatter.cs @@ -0,0 +1,39 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9400_0x9403_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9400_0x9403_Formatter Instance = new JT809_0x9400_0x9403_Formatter(); + + public JT809_0x9400_0x9403 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9400_0x9403 jT809_0X9400_0X9403 = new JT809_0x9400_0x9403(); + jT809_0X9400_0X9403.WarnSrc = (JT809WarnSrc)reader.ReadByte(); + jT809_0X9400_0X9403.WarnType = (JT809WarnType)reader.ReadUInt16(); + jT809_0X9400_0X9403.WarnTime = reader.ReadUTCDateTime(); + jT809_0X9400_0X9403.WarnLength = reader.ReadUInt32(); + jT809_0X9400_0X9403.WarnContent = reader.ReadString((int)jT809_0X9400_0X9403.WarnLength); + return jT809_0X9400_0X9403; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9400_0x9403 value, IJT809Config config) + { + writer.WriteByte( (byte)value.WarnSrc); + writer.WriteUInt16((ushort)value.WarnType); + writer.WriteUTCDateTime(value.WarnTime); + // 先计算内容长度(汉字为两个字节) + writer.Skip(4, out int lengthPosition); + writer.WriteString(value.WarnContent); + writer.WriteInt32Return(writer.GetCurrentPosition() - lengthPosition - 4, lengthPosition); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9501_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9501_Formatter.cs new file mode 100644 index 0000000..c01dc83 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9501_Formatter.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9501_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9500_0x9501_Formatter Instance = new JT809_0x9500_0x9501_Formatter(); + + public JT809_0x9500_0x9501 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9500_0x9501 jT809_0X9500_0X9501 = new JT809_0x9500_0x9501(); + jT809_0X9500_0X9501.MonitorTel = reader.ReadString(20); + return jT809_0X9500_0X9501; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9500_0x9501 value, IJT809Config config) + { + writer.WriteStringPadRight(value.MonitorTel, 20); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9502_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9502_Formatter.cs new file mode 100644 index 0000000..47ba036 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9502_Formatter.cs @@ -0,0 +1,30 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9502_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9500_0x9502_Formatter Instance = new JT809_0x9500_0x9502_Formatter(); + + public JT809_0x9500_0x9502 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9500_0x9502 jT809_0X9500_0X9502 = new JT809_0x9500_0x9502(); + jT809_0X9500_0X9502.LensID = reader.ReadByte(); + jT809_0X9500_0X9502.SizeType = reader.ReadByte(); + return jT809_0X9500_0X9502; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9500_0x9502 value, IJT809Config config) + { + writer.WriteByte(value.LensID); + writer.WriteByte(value.SizeType); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9503_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9503_Formatter.cs new file mode 100644 index 0000000..8ddcd62 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9503_Formatter.cs @@ -0,0 +1,36 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9503_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9500_0x9503_Formatter Instance = new JT809_0x9500_0x9503_Formatter(); + + public JT809_0x9500_0x9503 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9500_0x9503 jT809_0X9500_0X9503 = new JT809_0x9500_0x9503(); + jT809_0X9500_0X9503.MsgSequence = reader.ReadUInt32(); + jT809_0X9500_0X9503.MsgPriority = reader.ReadByte(); + jT809_0X9500_0X9503.MsgLength = reader.ReadUInt32(); + jT809_0X9500_0X9503.MsgContent = reader.ReadString((int)jT809_0X9500_0X9503.MsgLength); + return jT809_0X9500_0X9503; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9500_0x9503 value, IJT809Config config) + { + writer.WriteUInt32(value.MsgSequence); + writer.WriteByte(value.MsgPriority); + // 先计算内容长度(汉字为两个字节) + writer.Skip(4, out int lengthPosition); + writer.WriteString(value.MsgContent); + writer.WriteInt32Return(writer.GetCurrentPosition() - lengthPosition - 4, lengthPosition); + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9504_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9504_Formatter.cs new file mode 100644 index 0000000..da5979d --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9504_Formatter.cs @@ -0,0 +1,77 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Enums; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9504_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9500_0x9504_Formatter Instance = new JT809_0x9500_0x9504_Formatter(); + + public JT809_0x9500_0x9504 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9500_0x9504 jT809_0X9500_0X9504 = new JT809_0x9500_0x9504(); + jT809_0X9500_0X9504.Command = (JT809CommandType)reader.ReadByte(); + switch (jT809_0X9500_0X9504.Command) + { + case JT809CommandType.记录仪标准版本: + case JT809CommandType.当前驾驶人信息: + case JT809CommandType.记录仪时间: + case JT809CommandType.记录仪累计行驶里程: + case JT809CommandType.记录仪脉冲系数: + case JT809CommandType.车辆信息: + case JT809CommandType.记录仪状态信号配置信息: + case JT809CommandType.记录仪唯一性编号: + break; + case JT809CommandType.采集记录仪行驶记录: + case JT809CommandType.采集记录仪位置信息记录: + case JT809CommandType.采集记录仪事故疑点记录: + case JT809CommandType.采集记录仪超时驾驶记录: + case JT809CommandType.采集记录仪驾驶人身份记录: + case JT809CommandType.采集记录仪外部供电记录: + case JT809CommandType.采集记录仪参数修改记录: + case JT809CommandType.采集记录仪速度状态日志: + jT809_0X9500_0X9504.StartTime = reader.ReadDateTime6(); + jT809_0X9500_0X9504.EndTime = reader.ReadDateTime6(); + jT809_0X9500_0X9504.Max = reader.ReadUInt16(); + break; + } + return jT809_0X9500_0X9504; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9500_0x9504 value, IJT809Config config) + { + writer.WriteByte((byte)value.Command); + switch (value.Command) + { + case JT809CommandType.记录仪标准版本: + case JT809CommandType.当前驾驶人信息: + case JT809CommandType.记录仪时间: + case JT809CommandType.记录仪累计行驶里程: + case JT809CommandType.记录仪脉冲系数: + case JT809CommandType.车辆信息: + case JT809CommandType.记录仪状态信号配置信息: + case JT809CommandType.记录仪唯一性编号: + break; + case JT809CommandType.采集记录仪行驶记录: + case JT809CommandType.采集记录仪位置信息记录: + case JT809CommandType.采集记录仪事故疑点记录: + case JT809CommandType.采集记录仪超时驾驶记录: + case JT809CommandType.采集记录仪驾驶人身份记录: + case JT809CommandType.采集记录仪外部供电记录: + case JT809CommandType.采集记录仪参数修改记录: + case JT809CommandType.采集记录仪速度状态日志: + writer.WriteDateTime6(value.StartTime); + writer.WriteDateTime6(value.EndTime); + writer.WriteUInt16(value.Max); + break; + } + } + } +} diff --git a/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9505_Formatter.cs b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9505_Formatter.cs new file mode 100644 index 0000000..0213025 --- /dev/null +++ b/src/JT809.Protocol/Formatters/SubMessageBodyFormatters/JT809_0x9500_0x9505_Formatter.cs @@ -0,0 +1,42 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Formatters.SubMessageBodyFormatters +{ + public class JT809_0x9500_0x9505_Formatter : IJT809MessagePackFormatter + { + public readonly static JT809_0x9500_0x9505_Formatter Instance = new JT809_0x9500_0x9505_Formatter(); + + public JT809_0x9500_0x9505 Deserialize(ref JT809MessagePackReader reader, IJT809Config config) + { + JT809_0x9500_0x9505 jT809_0X9500_0X9505 = new JT809_0x9500_0x9505(); + jT809_0X9500_0X9505.AuthenticationCode = reader.ReadBCD(20); + jT809_0X9500_0X9505.AccessPointName = reader.ReadString(20); + jT809_0X9500_0X9505.UserName = reader.ReadString(49); + jT809_0X9500_0X9505.Password = reader.ReadString(22); + jT809_0X9500_0X9505.ServerIP = reader.ReadString(32); + jT809_0X9500_0X9505.TcpPort = reader.ReadUInt16(); + jT809_0X9500_0X9505.UdpPort = reader.ReadUInt16(); + jT809_0X9500_0X9505.EndTime = reader.ReadUTCDateTime(); + return jT809_0X9500_0X9505; + } + + public void Serialize(ref JT809MessagePackWriter writer, JT809_0x9500_0x9505 value, IJT809Config config) + { + writer.WriteBCD(value.AuthenticationCode, 20); + writer.WriteStringPadRight(value.AccessPointName, 20); + writer.WriteStringPadRight(value.UserName, 49); + writer.WriteStringPadRight(value.Password, 22); + writer.WriteStringPadRight(value.ServerIP, 32); + writer.WriteUInt16(value.TcpPort); + writer.WriteUInt16(value.UdpPort); + writer.WriteUTCDateTime(value.EndTime); + } + } +} diff --git a/src/JT809.Protocol/Interfaces/IJT809Config.cs b/src/JT809.Protocol/Interfaces/IJT809Config.cs new file mode 100644 index 0000000..6443754 --- /dev/null +++ b/src/JT809.Protocol/Interfaces/IJT809Config.cs @@ -0,0 +1,45 @@ +using JT809.Protocol.Configs; +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + +namespace JT809.Protocol.Interfaces +{ + public interface IJT809Config + { + string ConfigId { get; } + /// + /// 消息流水号 + /// + IJT809MsgSNDistributed MsgSNDistributed { get; set; } + /// + /// 头部选项 + /// + JT809HeaderOptions HeaderOptions { get; set; } + /// + /// 统一编码 + /// + Encoding Encoding { get; set; } + /// + /// 跳过校验码 + /// 测试的时候需要手动修改值,避免验证 + /// 默认:false + /// + bool SkipCRCCode { get; set; } + /// + /// 加密接口 + /// + IJT809Encrypt Encrypt { get; set; } + /// + /// 加密选项 + /// + JT809EncryptOptions EncryptOptions { get; set; } + /// + /// 全局注册外部程序集 + /// + /// + /// + IJT809Config Register(params Assembly[] externalAssemblies); + } +} diff --git a/src/JT809.Protocol/Interfaces/IJT809Encrypt.cs b/src/JT809.Protocol/Interfaces/IJT809Encrypt.cs new file mode 100644 index 0000000..ba43f14 --- /dev/null +++ b/src/JT809.Protocol/Interfaces/IJT809Encrypt.cs @@ -0,0 +1,11 @@ +using JT809.Protocol.Configs; +using System; + +namespace JT809.Protocol.Interfaces +{ + public interface IJT809Encrypt + { + byte[] Encrypt(ReadOnlySpan buffer, JT809EncryptOptions encryptOptions, uint privateKey); + byte[] Decrypt(ReadOnlySpan buffer, JT809EncryptOptions encryptOptions, uint privateKey); + } +} diff --git a/src/JT809.Protocol/Interfaces/IJT809MsgSNDistributed.cs b/src/JT809.Protocol/Interfaces/IJT809MsgSNDistributed.cs new file mode 100644 index 0000000..84ca7d6 --- /dev/null +++ b/src/JT809.Protocol/Interfaces/IJT809MsgSNDistributed.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Interfaces +{ + public interface IJT809MsgSNDistributed + { + uint Increment(); + } +} diff --git a/src/JT809.Protocol/Interfaces/JT809GlobalConfigBase.cs b/src/JT809.Protocol/Interfaces/JT809GlobalConfigBase.cs new file mode 100644 index 0000000..e21c404 --- /dev/null +++ b/src/JT809.Protocol/Interfaces/JT809GlobalConfigBase.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Configs; +using JT809.Protocol.Encrypt; +using JT809.Protocol.Internal; +using System; +using System.Reflection; +using System.Text; + +namespace JT809.Protocol.Interfaces +{ + public abstract class GlobalConfigBase : IJT809Config + { + protected GlobalConfigBase() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + Encoding = Encoding.GetEncoding("GBK"); + } + public abstract string ConfigId { get; } + public virtual IJT809MsgSNDistributed MsgSNDistributed { get; set; }= new DefaultMsgSNDistributedImpl(); + public virtual Encoding Encoding { get; set; } + public virtual bool SkipCRCCode { get; set; } = false; + public virtual IJT809Encrypt Encrypt { get; set; } = new JT809EncryptImpl(); + public virtual JT809EncryptOptions EncryptOptions { get; set; } + public virtual JT809HeaderOptions HeaderOptions { get; set; } + public virtual IJT809Config Register(params Assembly[] externalAssemblies) + { + return this; + } + } +} diff --git a/src/JT809.Protocol/Internal/BusinessTypeSerializerFactory.cs b/src/JT809.Protocol/Internal/BusinessTypeSerializerFactory.cs new file mode 100644 index 0000000..e4833dd --- /dev/null +++ b/src/JT809.Protocol/Internal/BusinessTypeSerializerFactory.cs @@ -0,0 +1,136 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessageBody; +using JT809.Protocol.MessagePack; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Internal +{ + static class BusinessTypeSerializerFactory + { + public static JT809Bodies Deserialize(this JT809BusinessType jT809BusinessType, ref JT809MessagePackReader reader,IJT809Config config) + { + switch (jT809BusinessType) + { + case JT809BusinessType.主链路登录请求消息: + return JT809_0x1001_Formatter.Instance.Deserialize(ref reader, config); + case JT809BusinessType.主链路登录应答消息: + return JT809_0x1002_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.主链路注销请求消息: + return JT809_0x1003_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.主链路断开通知消息: + return JT809_0x1007_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.下级平台主动关闭链路通知消息: + return JT809_0x1008_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.主链路动态信息交换消息: + return JT809BodiesFormatter.Instance_0x1200.Deserialize(ref reader,config); + case JT809BusinessType.主链路平台间信息交互消息: + return JT809_0x1300_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.主链路报警信息交互消息: + return JT809BodiesFormatter.Instance_0x1400.Deserialize(ref reader,config); + case JT809BusinessType.主链路车辆监管消息: + return JT809BodiesFormatter.Instance_0x1500.Deserialize(ref reader,config); + case JT809BusinessType.主链路静态信息交换消息: + return JT809BodiesFormatter.Instance_0x1600.Deserialize(ref reader,config); + case JT809BusinessType.从链路连接请求消息: + return JT809_0x9001_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.从链路连接应答消息: + return JT809_0x9002_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.从链路注销请求消息: + return JT809_0x9003_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.从链路断开通知消息: + return JT809_0x9007_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.上级平台主动关闭链路通知消息: + return JT809_0x9008_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.接收定位信息数量通知消息: + return JT809_0x9101_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.从链路动态信息交换消息: + return JT809BodiesFormatter.Instance_0x9200.Deserialize(ref reader,config); + case JT809BusinessType.从链路平台间信息交互消息: + return JT809_0x9300_Formatter.Instance.Deserialize(ref reader,config); + case JT809BusinessType.从链路报警信息交互消息: + return JT809BodiesFormatter.Instance_0x9400.Deserialize(ref reader,config); + case JT809BusinessType.从链路车辆监管消息: + return JT809BodiesFormatter.Instance_0x9500.Deserialize(ref reader,config); + case JT809BusinessType.从链路静态信息交换消息: + return JT809BodiesFormatter.Instance_0x9600.Deserialize(ref reader,config); + default: + return default; + } + } + + public static void Serialize(this JT809BusinessType jT809BusinessType, ref JT809MessagePackWriter writer, object value,IJT809Config config) + { + switch (jT809BusinessType) + { + case JT809BusinessType.主链路登录请求消息: + JT809_0x1001_Formatter.Instance.Serialize(ref writer, (JT809_0x1001)value, config); + break; + case JT809BusinessType.主链路登录应答消息: + JT809_0x1002_Formatter.Instance.Serialize(ref writer, (JT809_0x1002)value, config); + break; + case JT809BusinessType.主链路注销请求消息: + JT809_0x1003_Formatter.Instance.Serialize(ref writer, (JT809_0x1003)value, config); + break; + case JT809BusinessType.主链路断开通知消息: + JT809_0x1007_Formatter.Instance.Serialize(ref writer, (JT809_0x1007)value, config); + break; + case JT809BusinessType.下级平台主动关闭链路通知消息: + JT809_0x1008_Formatter.Instance.Serialize(ref writer, (JT809_0x1008)value, config); + break; + case JT809BusinessType.主链路动态信息交换消息: + JT809BodiesFormatter.Instance_0x1200.Serialize(ref writer, (JT809_0x1200)value, config); + break; + case JT809BusinessType.主链路平台间信息交互消息: + JT809_0x1300_Formatter.Instance.Serialize(ref writer, (JT809_0x1300)value, config); + break; + case JT809BusinessType.主链路报警信息交互消息: + JT809BodiesFormatter.Instance_0x1400.Serialize(ref writer, (JT809_0x1400)value, config); + break; + case JT809BusinessType.主链路车辆监管消息: + JT809BodiesFormatter.Instance_0x1500.Serialize(ref writer,(JT809_0x1500) value, config); + break; + case JT809BusinessType.主链路静态信息交换消息: + JT809BodiesFormatter.Instance_0x1600.Serialize(ref writer,(JT809_0x1600) value, config); + break; + case JT809BusinessType.从链路连接请求消息: + JT809_0x9001_Formatter.Instance.Serialize(ref writer, (JT809_0x9001)value, config); + break; + case JT809BusinessType.从链路连接应答消息: + JT809_0x9002_Formatter.Instance.Serialize(ref writer, (JT809_0x9002)value, config); + break; + case JT809BusinessType.从链路注销请求消息: + JT809_0x9003_Formatter.Instance.Serialize(ref writer, (JT809_0x9003)value, config); + break; + case JT809BusinessType.从链路断开通知消息: + JT809_0x9007_Formatter.Instance.Serialize(ref writer, (JT809_0x9007)value, config); + break; + case JT809BusinessType.上级平台主动关闭链路通知消息: + JT809_0x9008_Formatter.Instance.Serialize(ref writer, (JT809_0x9008)value, config); + break; + case JT809BusinessType.接收定位信息数量通知消息: + JT809_0x9101_Formatter.Instance.Serialize(ref writer, (JT809_0x9101)value, config); + break; + case JT809BusinessType.从链路动态信息交换消息: + JT809BodiesFormatter.Instance_0x9200.Serialize(ref writer, (JT809_0x9200)value, config); + break; + case JT809BusinessType.从链路平台间信息交互消息: + JT809_0x9300_Formatter.Instance.Serialize(ref writer, (JT809_0x9300)value, config); + break; + case JT809BusinessType.从链路报警信息交互消息: + JT809BodiesFormatter.Instance_0x9400.Serialize(ref writer, (JT809_0x9400)value, config); + break; + case JT809BusinessType.从链路车辆监管消息: + JT809BodiesFormatter.Instance_0x9500.Serialize(ref writer, (JT809_0x9500)value, config); + break; + case JT809BusinessType.从链路静态信息交换消息: + JT809BodiesFormatter.Instance_0x9600.Serialize(ref writer, (JT809_0x9600)value, config); + break; + } + } + } +} diff --git a/src/JT809.Protocol/Internal/DefaultGlobalConfig.cs b/src/JT809.Protocol/Internal/DefaultGlobalConfig.cs new file mode 100644 index 0000000..5102587 --- /dev/null +++ b/src/JT809.Protocol/Internal/DefaultGlobalConfig.cs @@ -0,0 +1,9 @@ +using JT809.Protocol.Interfaces; + +namespace JT809.Protocol.Internal +{ + class DefaultGlobalConfig : GlobalConfigBase + { + public override string ConfigId => "Default"; + } +} diff --git a/src/JT809.Protocol/Internal/DefaultMsgSNDistributedImpl.cs b/src/JT809.Protocol/Internal/DefaultMsgSNDistributedImpl.cs new file mode 100644 index 0000000..e9baf42 --- /dev/null +++ b/src/JT809.Protocol/Internal/DefaultMsgSNDistributedImpl.cs @@ -0,0 +1,18 @@ +using JT809.Protocol.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +namespace JT809.Protocol.Internal +{ + internal class DefaultMsgSNDistributedImpl : IJT809MsgSNDistributed + { + int _counter = 0; + + public uint Increment() + { + return (uint)Interlocked.Increment(ref _counter); + } + } +} diff --git a/src/JT809.Protocol/Internal/SubBodiesTypeSerializerFactory.cs b/src/JT809.Protocol/Internal/SubBodiesTypeSerializerFactory.cs new file mode 100644 index 0000000..58374da --- /dev/null +++ b/src/JT809.Protocol/Internal/SubBodiesTypeSerializerFactory.cs @@ -0,0 +1,218 @@ +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using JT809.Protocol.Interfaces; +using JT809.Protocol.MessagePack; +using JT809.Protocol.SubMessageBody; +using System; + +namespace JT809.Protocol.Internal +{ + static class SubBodiesTypeSerializerFactory + { + public static JT809SubBodies Deserialize(this JT809SubBusinessType jT809SubBusinessType, ref JT809MessagePackReader reader, IJT809Config config) + { + switch (jT809SubBusinessType) + { + case JT809SubBusinessType.上传车辆注册信息: + return JT809_0x1200_0x1201_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.实时上传车辆定位信息: + return JT809_0x1200_0x1202_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.车辆定位信息自动补报: + return JT809_0x1200_0x1203_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.申请交换指定车辆定位信息请求: + return JT809_0x1200_0x1207_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.补发车辆定位信息请求: + return JT809_0x1200_0x1209_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.上报车辆驾驶员身份识别信息应答: + return JT809_0x1200_0x120A_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.上报车辆电子运单应答: + return JT809_0x1200_0x120B_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.主动上报驾驶员身份信息: + return JT809_0x1200_0x120C_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.主动上报车辆电子运单信息: + return JT809_0x1200_0x120D_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.平台查岗应答: + return JT809_0x1300_0x1301_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.下发平台间报文应答: + return JT809_0x1300_0x1302_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.报警督办应答: + return JT809_0x1400_0x1401_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.上报报警信息: + return JT809_0x1400_0x1402_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.主动上报报警处理结果信息: + return JT809_0x1400_0x1403_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.车辆单向监听应答: + return JT809_0x1500_0x1501_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.车辆拍照应答: + return JT809_0x1500_0x1502_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.下发车辆报文应答: + return JT809_0x1500_0x1503_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.上报车辆行驶记录应答: + return JT809_0x1500_0x1504_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.车辆应急接入监管平台应答消息: + return JT809_0x1500_0x1505_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.补报车辆静态信息应答: + return JT809_0x1600_0x1601_Formatter.Instance.Deserialize(ref reader,config); + case JT809SubBusinessType.交换车辆定位信息: + return JT809_0x9200_0x9202_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.车辆定位信息交换补发: + return JT809_0x9200_0x9203_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.交换车辆静态信息: + return JT809_0x9200_0x9204_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.启动车辆定位信息交换请求: + return JT809_0x9200_0x9205_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.结束车辆定位信息交换请求: + return JT809_0x9200_0x9206_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.申请交换指定车辆定位信息应答: + return JT809_0x9200_0x9207_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.取消交换指定车辆定位信息应答: + return JT809_0x9200_0x9208_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.补发车辆定位信息应答: + return JT809_0x9200_0x9209_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.平台查岗请求: + return JT809_0x9300_0x9301_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.下发平台间报文请求: + return JT809_0x9300_0x9302_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.报警督办请求: + return JT809_0x9400_0x9401_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.报警预警: + return JT809_0x9400_0x9402_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.实时交换报警信息: + return JT809_0x9400_0x9403_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.车辆单向监听请求: + return JT809_0x9500_0x9501_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.车辆拍照请求: + return JT809_0x9500_0x9502_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.下发车辆报文请求: + return JT809_0x9500_0x9503_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.上报车辆行驶记录请求: + return JT809_0x9500_0x9504_Formatter.Instance.Deserialize(ref reader, config); + case JT809SubBusinessType.车辆应急接入监管平台请求消息: + return JT809_0x9500_0x9505_Formatter.Instance.Deserialize(ref reader, config); + default: + return default; + } + } + + public static void Serialize(this JT809SubBusinessType jT809SubBusinessType, ref JT809MessagePackWriter writer, object value, IJT809Config config) + { + switch (jT809SubBusinessType) + { + case JT809SubBusinessType.上传车辆注册信息: + JT809_0x1200_0x1201_Formatter.Instance.Serialize(ref writer, (JT809_0x1200_0x1201)value, config); + break; + case JT809SubBusinessType.实时上传车辆定位信息: + JT809_0x1200_0x1202_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x1202)value, config); + break; + case JT809SubBusinessType.车辆定位信息自动补报: + JT809_0x1200_0x1203_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x1203)value, config); + break; + case JT809SubBusinessType.申请交换指定车辆定位信息请求: + JT809_0x1200_0x1207_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x1207)value, config); + break; + case JT809SubBusinessType.补发车辆定位信息请求: + JT809_0x1200_0x1209_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x1209)value, config); + break; + case JT809SubBusinessType.上报车辆驾驶员身份识别信息应答: + JT809_0x1200_0x120A_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x120A)value, config); + break; + case JT809SubBusinessType.上报车辆电子运单应答: + JT809_0x1200_0x120B_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x120B)value, config); + break; + case JT809SubBusinessType.主动上报驾驶员身份信息: + JT809_0x1200_0x120C_Formatter.Instance.Serialize(ref writer, (JT809_0x1200_0x120C)value, config); + break; + case JT809SubBusinessType.主动上报车辆电子运单信息: + JT809_0x1200_0x120D_Formatter.Instance.Serialize(ref writer,(JT809_0x1200_0x120D)value, config); + break; + case JT809SubBusinessType.平台查岗应答: + JT809_0x1300_0x1301_Formatter.Instance.Serialize(ref writer, (JT809_0x1300_0x1301)value, config); + break; + case JT809SubBusinessType.下发平台间报文应答: + JT809_0x1300_0x1302_Formatter.Instance.Serialize(ref writer, (JT809_0x1300_0x1302)value, config); + break; + case JT809SubBusinessType.报警督办应答: + JT809_0x1400_0x1401_Formatter.Instance.Serialize(ref writer, (JT809_0x1400_0x1401)value, config); + break; + case JT809SubBusinessType.上报报警信息: + JT809_0x1400_0x1402_Formatter.Instance.Serialize(ref writer, (JT809_0x1400_0x1402)value, config); + break; + case JT809SubBusinessType.主动上报报警处理结果信息: + JT809_0x1400_0x1403_Formatter.Instance.Serialize(ref writer, (JT809_0x1400_0x1403)value, config); + break; + case JT809SubBusinessType.车辆单向监听应答: + JT809_0x1500_0x1501_Formatter.Instance.Serialize(ref writer, (JT809_0x1500_0x1501)value, config); + break; + case JT809SubBusinessType.车辆拍照应答: + JT809_0x1500_0x1502_Formatter.Instance.Serialize(ref writer, (JT809_0x1500_0x1502)value, config); + break; + case JT809SubBusinessType.下发车辆报文应答: + JT809_0x1500_0x1503_Formatter.Instance.Serialize(ref writer, (JT809_0x1500_0x1503)value, config); + break; + case JT809SubBusinessType.上报车辆行驶记录应答: + JT809_0x1500_0x1504_Formatter.Instance.Serialize(ref writer,(JT809_0x1500_0x1504) value, config); + break; + case JT809SubBusinessType.车辆应急接入监管平台应答消息: + JT809_0x1500_0x1505_Formatter.Instance.Serialize(ref writer, (JT809_0x1500_0x1505)value, config); + break; + case JT809SubBusinessType.补报车辆静态信息应答: + JT809_0x1600_0x1601_Formatter.Instance.Serialize(ref writer, (JT809_0x1600_0x1601)value, config); + break; + case JT809SubBusinessType.交换车辆定位信息: + JT809_0x9200_0x9202_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9202)value, config); + break; + case JT809SubBusinessType.车辆定位信息交换补发: + JT809_0x9200_0x9203_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9203)value, config); + break; + case JT809SubBusinessType.交换车辆静态信息: + JT809_0x9200_0x9204_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9204)value, config); + break; + case JT809SubBusinessType.启动车辆定位信息交换请求: + JT809_0x9200_0x9205_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9205)value, config); + break; + case JT809SubBusinessType.结束车辆定位信息交换请求: + JT809_0x9200_0x9206_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9206)value, config); + break; + case JT809SubBusinessType.申请交换指定车辆定位信息应答: + JT809_0x9200_0x9207_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9207)value, config); + break; + case JT809SubBusinessType.取消交换指定车辆定位信息应答: + JT809_0x9200_0x9208_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9208)value, config); + break; + case JT809SubBusinessType.补发车辆定位信息应答: + JT809_0x9200_0x9209_Formatter.Instance.Serialize(ref writer, (JT809_0x9200_0x9209)value, config); + break; + case JT809SubBusinessType.平台查岗请求: + JT809_0x9300_0x9301_Formatter.Instance.Serialize(ref writer, (JT809_0x9300_0x9301)value, config); + break; + case JT809SubBusinessType.下发平台间报文请求: + JT809_0x9300_0x9302_Formatter.Instance.Serialize(ref writer, (JT809_0x9300_0x9302)value, config); + break; + case JT809SubBusinessType.报警督办请求: + JT809_0x9400_0x9401_Formatter.Instance.Serialize(ref writer, (JT809_0x9400_0x9401)value, config); + break; + case JT809SubBusinessType.报警预警: + JT809_0x9400_0x9402_Formatter.Instance.Serialize(ref writer, (JT809_0x9400_0x9402)value, config); + break; + case JT809SubBusinessType.实时交换报警信息: + JT809_0x9400_0x9403_Formatter.Instance.Serialize(ref writer, (JT809_0x9400_0x9403)value, config); + break; + case JT809SubBusinessType.车辆单向监听请求: + JT809_0x9500_0x9501_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9501)value, config); + break; + case JT809SubBusinessType.车辆拍照请求: + JT809_0x9500_0x9502_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9502)value, config); + break; + case JT809SubBusinessType.下发车辆报文请求: + JT809_0x9500_0x9503_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9503)value, config); + break; + case JT809SubBusinessType.上报车辆行驶记录请求: + JT809_0x9500_0x9504_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9504)value, config); + break; + case JT809SubBusinessType.车辆应急接入监管平台请求消息: + JT809_0x9500_0x9505_Formatter.Instance.Serialize(ref writer, (JT809_0x9500_0x9505)value, config); + break; + } + } + } +} diff --git a/src/JT809.Protocol/JT809.Protocol.csproj b/src/JT809.Protocol/JT809.Protocol.csproj new file mode 100644 index 0000000..e367c9d --- /dev/null +++ b/src/JT809.Protocol/JT809.Protocol.csproj @@ -0,0 +1,136 @@ + + + + netstandard2.0 + latest + Copyright 2018. + SmallChi + JT809 + JT809 + JT809协议、GB809协议、道路运输车辆卫星定位系统平台数据交换协议 + JT809协议、GB809协议、道路运输车辆卫星定位系统平台数据交换协议 + false + https://github.com/SmallChi/JT809 + https://github.com/SmallChi/JT809 + https://github.com/SmallChi/JT809/blob/master/LICENSE + true + 2.0.0 + + + + bin\Release\netstandard2.0\JT809.Protocol.xml + true + 1701;1702;1591 + + + + true + + 1701;1702;1591 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + True + JT809PackageExtensionsTemplate.tt + + + True + True + JT809SubPackageExtensionsTemplate.tt + + + + + + + + + + + + + + TextTemplatingFileGenerator + JT809PackageExtensionsTemplate.cs + + + TextTemplatingFileGenerator + JT809SubPackageExtensionsTemplate.cs + + + + + + + + + + True + True + JT809PackageExtensionsTemplate.tt + + + True + True + JT809SubPackageExtensionsTemplate.tt + + + + diff --git a/src/JT809.Protocol/JT809ArrayPool.cs b/src/JT809.Protocol/JT809ArrayPool.cs new file mode 100644 index 0000000..424ddcf --- /dev/null +++ b/src/JT809.Protocol/JT809ArrayPool.cs @@ -0,0 +1,27 @@ +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + internal static class JT809ArrayPool + { + private readonly static ArrayPool ArrayPool; + + static JT809ArrayPool() + { + ArrayPool = ArrayPool.Create(); + } + + public static byte[] Rent(int minimumLength) + { + return ArrayPool.Rent(minimumLength); + } + + public static void Return(byte[] array, bool clearArray = false) + { + ArrayPool.Return(array, clearArray); + } + } +} diff --git a/src/JT809.Protocol/JT809Bodies.cs b/src/JT809.Protocol/JT809Bodies.cs new file mode 100644 index 0000000..25a4c09 --- /dev/null +++ b/src/JT809.Protocol/JT809Bodies.cs @@ -0,0 +1,14 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + public abstract class JT809Bodies + { + + } +} diff --git a/src/JT809.Protocol/JT809Constants.cs b/src/JT809.Protocol/JT809Constants.cs new file mode 100644 index 0000000..7b8dfb7 --- /dev/null +++ b/src/JT809.Protocol/JT809Constants.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + public static class JT809Constants + { + static JT809Constants() + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + Encoding = Encoding.GetEncoding("GBK"); + } + /// + /// 日期限制于2000年 + /// + public const int DateLimitYear = 2000; + public static readonly DateTime UTCBaseTime = new DateTime(1970, 1, 1); + public static Encoding Encoding { get;} + } +} diff --git a/src/JT809.Protocol/JT809ExchangeMessageBodies.cs b/src/JT809.Protocol/JT809ExchangeMessageBodies.cs new file mode 100644 index 0000000..eb34c79 --- /dev/null +++ b/src/JT809.Protocol/JT809ExchangeMessageBodies.cs @@ -0,0 +1,36 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + /// + /// 交换信息体 + /// + public abstract class JT809ExchangeMessageBodies: JT809Bodies + { + /// + /// 车牌号 + /// + public string VehicleNo { get; set; } + /// + /// 车辆颜色 + /// + public JT809VehicleColorType VehicleColor { get; set; } = JT809VehicleColorType.其他; + /// + /// 子业务类型标识 + /// + public JT809SubBusinessType SubBusinessType { get; set; } = JT809SubBusinessType.None; + /// + /// 后续数据长度 + /// + public uint DataLength { get; set; } + /// + /// 子业务数据体 + /// + public JT809SubBodies SubBodies { get; set; } + } +} diff --git a/src/JT809.Protocol/JT809Header.cs b/src/JT809.Protocol/JT809Header.cs new file mode 100644 index 0000000..fd94c7b --- /dev/null +++ b/src/JT809.Protocol/JT809Header.cs @@ -0,0 +1,53 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + [JT809Formatter(typeof(JT809HeaderFormatter))] + public class JT809Header + { + /// + /// 固定为22个字节长度 + /// MSG LENGTH + MSG_SN + MSG_ID + MSG_GNSSCENTERID + VERSION_FLAG + ENCRYPT_FLAG + ENCRYPT_KEY + /// 4 + 4 + 2 + 4 + 3 + 1 + 4 = 22 + /// + public const int FixedByteLength = 22; + /// + /// 数据长度(包括头标识、数据头、数据体和尾标识) + /// 头标识 + 数据头 + 数据体 + 尾标识 + /// 1 + 22 + n + 1 + /// + public uint MsgLength { get; set; } + /// + /// 报文序列号 a + /// + public uint MsgSN { get; set; } + /// + /// 业务数据类型 + /// + public JT809BusinessType BusinessType { get; set; } + /// + /// 下级平台接入码,上级平台给下级平台分配唯一标识码。 + /// + public uint MsgGNSSCENTERID { get; set; } + /// + /// 协议版本号标识,上下级平台之间采用的标准协议版 + /// 编号;长度为 3 个字节来表示,0x01 0x02 0x0F 标识 + /// 的版本号是 v1.2.15,以此类推。 + /// Hex编码 + /// + public JT809Header_Version Version { get; set; } = new JT809Header_Version(); + /// + /// 报文加密标识位 b: 0 表示报文不加密,1 表示报文加密。 + /// + public JT809Header_Encrypt EncryptFlag { get; set; } = JT809Header_Encrypt.None; + /// + /// 数据加密的密匙,长度为 4 个字节 + /// + public uint EncryptKey { get; set; } + } +} diff --git a/src/JT809.Protocol/JT809HeaderPackage.cs b/src/JT809.Protocol/JT809HeaderPackage.cs new file mode 100644 index 0000000..4f46968 --- /dev/null +++ b/src/JT809.Protocol/JT809HeaderPackage.cs @@ -0,0 +1,25 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + /// + /// JT809头部数据包 + /// + [JT809Formatter(typeof(JT809HeaderPackageFormatter))] + public class JT809HeaderPackage + { + public byte BeginFlag { get; set; } = JT809Package.BEGINFLAG; + + public JT809Header Header { get; set; } + + public byte[] Bodies { get; set; } + + public ushort CRCCode { get; set; } + + public byte EndFlag { get; set; } = JT809Package.ENDFLAG; + } +} diff --git a/src/JT809.Protocol/JT809Header_Encrypt.cs b/src/JT809.Protocol/JT809Header_Encrypt.cs new file mode 100644 index 0000000..49ae3d1 --- /dev/null +++ b/src/JT809.Protocol/JT809Header_Encrypt.cs @@ -0,0 +1,11 @@ +namespace JT809.Protocol +{ + /// + /// 报文加密标识位 b: 0 表示报文不加密,1 表示报文加密。 + /// + public enum JT809Header_Encrypt:byte + { + None = 0X00, + Common = 0X01, + } +} diff --git a/src/JT809.Protocol/JT809Header_Version.cs b/src/JT809.Protocol/JT809Header_Version.cs new file mode 100644 index 0000000..d0f99f9 --- /dev/null +++ b/src/JT809.Protocol/JT809Header_Version.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + /// + /// 协议版本号标识 + /// Hex编码 + /// + public class JT809Header_Version + { + public byte[] Buffer { get; } = new byte[3]; + private const int MajorIndex = 0; + private const int MinorIndex = 1; + private const int BuildIndex = 2; + public const int FixedByteLength = 3; + + public byte Major + { + get { return Buffer[MajorIndex]; } + set { Buffer[MajorIndex] = value; } + } + + public byte Minor + { + get { return Buffer[MinorIndex]; } + set { Buffer[MinorIndex] = value; } + } + + public byte Build + { + get { return Buffer[BuildIndex]; } + set { Buffer[BuildIndex] = value; } + } + + /// + /// 默认1.0.0版本 + /// Hex编码 + /// + public JT809Header_Version() + { + Major = 1; + Minor = 0; + Build = 0; + } + /// + /// + /// + /// 0x00~0xFF + /// 0x00~0xFF + /// 0x00~0xFF + public JT809Header_Version(byte major, byte minor, byte buid) + { + Major = major; + Minor = minor; + Build = buid; + } + /// + /// + /// + /// [0x00~0xFF,0x00~0xFF,0x00~0xFF] + public JT809Header_Version(byte[] bytes) + { + Major = bytes[0]; + Minor = bytes[1]; + Build = bytes[2]; + } + /// + /// + /// + /// [0x00~0xFF,0x00~0xFF,0x00~0xFF] + public JT809Header_Version(ReadOnlySpan bytes) + { + Major = bytes[0]; + Minor = bytes[1]; + Build = bytes[2]; + } + + public override string ToString() + { + return $"{Major}.{Minor}.{Build}"; + } + } +} diff --git a/src/JT809.Protocol/JT809Package.cs b/src/JT809.Protocol/JT809Package.cs new file mode 100644 index 0000000..ed6e05b --- /dev/null +++ b/src/JT809.Protocol/JT809Package.cs @@ -0,0 +1,33 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + [JT809Formatter(typeof(JT809PackageFormatter))] + public class JT809Package + { + public const byte BEGINFLAG = 0X5B; + + public const byte ENDFLAG = 0X5D; + + /// + /// 固定为26个字节长度 + /// Head flag + Message Header + CRC Code + End Flag + /// 1 + 22 + 2 + 1 = 26 + /// + public const int FixedByteLength = 26; + + public byte BeginFlag { get; set; } = BEGINFLAG; + + public JT809Header Header { get; set; } + + public JT809Bodies Bodies { get; set; } + + public ushort CRCCode { get; set; } + + public byte EndFlag { get; set; } = ENDFLAG; + } +} diff --git a/src/JT809.Protocol/JT809Serializer.cs b/src/JT809.Protocol/JT809Serializer.cs new file mode 100644 index 0000000..324b713 --- /dev/null +++ b/src/JT809.Protocol/JT809Serializer.cs @@ -0,0 +1,113 @@ +using JT809.Protocol.Extensions; +using JT809.Protocol.Formatters; +using JT809.Protocol.Interfaces; +using JT809.Protocol.Internal; +using JT809.Protocol.MessagePack; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + /// + /// + /// ref:https://adamsitnik.com/Array-Pool/ + /// + public class JT809Serializer + { + private readonly IJT809Config jT809Config; + + public JT809Serializer(IJT809Config jT809Config) + { + this.jT809Config = jT809Config; + } + + public JT809Serializer():this(new DefaultGlobalConfig()) + { + + } + + public string SerializerId => jT809Config.ConfigId; + public byte[] Serialize(JT809Package jT809Package, int minBufferSize = 4096) + { + byte[] buffer = JT809ArrayPool.Rent(minBufferSize); + try + { + JT809MessagePackWriter jT809MessagePackWriter = new JT809MessagePackWriter(buffer); + JT809PackageFormatter.Instance.Serialize(ref jT809MessagePackWriter,jT809Package, jT809Config); + return jT809MessagePackWriter.FlushAndGetEncodingArray(); + } + finally + { + JT809ArrayPool.Return(buffer); + } + } + + public JT809Package Deserialize(ReadOnlySpan bytes, int minBufferSize = 4096) + { + byte[] buffer = JT809ArrayPool.Rent(minBufferSize); + try + { + JT809MessagePackReader jT809MessagePackReader = new JT809MessagePackReader(bytes); + jT809MessagePackReader.Decode(buffer); + return JT809PackageFormatter.Instance.Deserialize(ref jT809MessagePackReader, jT809Config); + } + finally + { + JT809ArrayPool.Return(buffer); + } + } + + private static bool CheckPackageType(Type type) + { + return type == typeof(JT809Package) || type == typeof(JT809HeaderPackage); + } + + public byte[] Serialize(T obj,int minBufferSize = 4096) + { + byte[] buffer = JT809ArrayPool.Rent(minBufferSize); + try + { + JT809MessagePackWriter jT809MessagePackWriter = new JT809MessagePackWriter(buffer); + JT809MessagePackFormatterExtensions.GetFormatter().Serialize(ref jT809MessagePackWriter, obj,jT809Config); + return jT809MessagePackWriter.FlushAndGetEncodingArray(); + } + finally + { + JT809ArrayPool.Return(buffer); + } + } + + public T Deserialize(ReadOnlySpan bytes, int minBufferSize = 4096) + { + byte[] buffer = JT809ArrayPool.Rent(minBufferSize); + try + { + JT809MessagePackReader jT809MessagePackReader = new JT809MessagePackReader(bytes); + if (CheckPackageType(typeof(T))) + jT809MessagePackReader.Decode(buffer); + return JT809MessagePackFormatterExtensions.GetFormatter().Deserialize(ref jT809MessagePackReader, jT809Config); + } + finally + { + JT809ArrayPool.Return(buffer); + } + } + + public JT809HeaderPackage HeaderDeserialize(ReadOnlySpan bytes, int minBufferSize = 4096) + { + byte[] buffer = JT809ArrayPool.Rent(minBufferSize); + try + { + JT809MessagePackReader jT808MessagePackReader = new JT809MessagePackReader(bytes); + jT808MessagePackReader.Decode(buffer); + return JT809HeaderPackageFormatter.Instance.Deserialize(ref jT808MessagePackReader, jT809Config); + } + finally + { + JT809ArrayPool.Return(buffer); + } + } + } +} diff --git a/src/JT809.Protocol/JT809SubBodies.cs b/src/JT809.Protocol/JT809SubBodies.cs new file mode 100644 index 0000000..dac3ce8 --- /dev/null +++ b/src/JT809.Protocol/JT809SubBodies.cs @@ -0,0 +1,15 @@ +using JT809.Protocol.Enums; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + /// + /// 子业务数据体 + /// + public abstract class JT809SubBodies + { + + } +} diff --git a/src/JT809.Protocol/JT809Util.cs b/src/JT809.Protocol/JT809Util.cs new file mode 100644 index 0000000..ddaf8ad --- /dev/null +++ b/src/JT809.Protocol/JT809Util.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol +{ + public static class HexUtil + { + static readonly char[] HexdumpTable = new char[256 * 4]; + static HexUtil() + { + char[] digits = "0123456789ABCDEF".ToCharArray(); + for (int i = 0; i < 256; i++) + { + HexdumpTable[i << 1] = digits[(int)((uint)i >> 4 & 0x0F)]; + HexdumpTable[(i << 1) + 1] = digits[i & 0x0F]; + } + } + + public static string DoHexDump(ReadOnlySpan buffer, int fromIndex, int length) + { + if (length == 0) + { + return ""; + } + int endIndex = fromIndex + length; + var buf = new char[length << 1]; + int srcIdx = fromIndex; + int dstIdx = 0; + for (; srcIdx < endIndex; srcIdx++, dstIdx += 2) + { + Array.Copy(HexdumpTable, buffer[srcIdx] << 1, buf, dstIdx, 2); + } + return new string(buf); + } + + public static string DoHexDump(byte[] array, int fromIndex, int length) + { + if (length == 0) + { + return ""; + } + int endIndex = fromIndex + length; + var buf = new char[length << 1]; + int srcIdx = fromIndex; + int dstIdx = 0; + for (; srcIdx < endIndex; srcIdx++, dstIdx += 2) + { + Array.Copy(HexdumpTable, (array[srcIdx] & 0xFF) << 1, buf, dstIdx, 2); + } + return new string(buf); + } + } + + public static class CRCUtil + { + public static ulong[] CRC; //建立CRC16表 + private const ushort cnCRC_CCITT = 0x1021; //CRC校验多项式 + static CRCUtil() + { + InitCrcTable(); + } + private static void InitCrcTable() + { + CRC = new ulong[256]; + ushort i, j; + ushort nData; + ushort nAccum; + for (i = 0; i < 256; i++) + { + nData = (ushort)(i << 8); + nAccum = 0; + for (j = 0; j < 8; j++) + { + if (((nData ^ nAccum) & 0x8000) > 0) + nAccum = (ushort)((nAccum << 1) ^ cnCRC_CCITT); + else + nAccum <<= 1; + nData <<= 1; + } + CRC[i] = (ulong)nAccum; + } + } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1001.cs b/src/JT809.Protocol/MessageBody/JT809_0x1001.cs new file mode 100644 index 0000000..326d863 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1001.cs @@ -0,0 +1,38 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路登录请求消息 + /// 链路类型:主链路 + /// 消息方向:下级平台往上级平台 + /// 业务数据类型标识: UP-CONNECT-REQ + /// 描述:下级平台向上级平台发送用户名和密码等登录信息 + /// + [JT809Formatter(typeof(JT809_0x1001_Formatter))] + public class JT809_0x1001: JT809Bodies + { + /// + /// 用户名 + /// + public uint UserId { get; set; } + /// + /// 密码 + /// 8位 + /// + public string Password { get; set; } + /// + /// 下级平台提供对应的从链路服务端 IP 地址 + /// 32位 + /// + public string DownLinkIP { get; set; } + /// + /// 下级平台提供对应的从链路服务器端口号 + /// + public ushort DownLinkPort { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1002.cs b/src/JT809.Protocol/MessageBody/JT809_0x1002.cs new file mode 100644 index 0000000..130e599 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1002.cs @@ -0,0 +1,36 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路登录应答消息 + /// 链路类型:主链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:UP_CONNCCT_RSP + /// 描述:上级平台对下级平台登录请求信息、进行安全验证后,返回相应的验证结果。 + /// + [JT809Formatter(typeof(JT809_0x1002_Formatter))] + public class JT809_0x1002 : JT809Bodies + { + /// + /// 验证结果,定义如下: + /// 0x00:成功; + /// 0x01:IP 地址不正确; + /// 0x02:接入码不正确; + /// 0x03:用户没用注册; + /// 0x04:密码错误; + /// 0x05:资源紧张,稍后再连接(已经占用; + /// 0x06:其他。 + /// + public JT809_0x1002_Result Result { get; set; } + /// + /// 校验码 + /// + public uint VerifyCode { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1003.cs b/src/JT809.Protocol/MessageBody/JT809_0x1003.cs new file mode 100644 index 0000000..919f270 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1003.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路注销请求消息 + /// 链路类型:主链路 + /// 消息方向:下级平台往上级平台 + /// 业务数据类型标识:UP-DISCONNECT-REQ + /// 描述:下级平台在中断与上级平台的主链路连接时,应向上级平台发送主链路注销请求消息。 + /// + [JT809Formatter(typeof(JT809_0x1003_Formatter))] + public class JT809_0x1003 : JT809Bodies + { + /// + /// 用户名 + /// + public uint UserId { get; set; } + /// + /// 密码 + /// + public string Password { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1004.cs b/src/JT809.Protocol/MessageBody/JT809_0x1004.cs new file mode 100644 index 0000000..93b475e --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1004.cs @@ -0,0 +1,20 @@ +using JT809.Protocol.Attributes; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路注销应答消息 + /// 链路类型:主链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:UP_DISCONNECT_RSP + /// 描述:上级平台收到下级平台发送的主链路注销请求消息后,向下级平台返回主链路注销应答消息,并记录链路注销日志,下级平台接收到应答消息后,可中断主从链路联接。 + /// 主链路注销应答消息,数据体为空。 + /// + public class JT809_0x1004 : JT809Bodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1005.cs b/src/JT809.Protocol/MessageBody/JT809_0x1005.cs new file mode 100644 index 0000000..9bd11f0 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1005.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路连接保持请求消息 + /// 链路类型:主链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:UP_LINKTEST_RSP + /// 描述:上级平台收到下级平台的主链路连接保持请求消息后,向下级平台返回.主链路连接保持应答消息,保持主链路的连接状态 + /// 主链路连接保持应答消息,数据体为空 + /// + public class JT809_0x1005:JT809Bodies + { + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1006.cs b/src/JT809.Protocol/MessageBody/JT809_0x1006.cs new file mode 100644 index 0000000..0f154d6 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1006.cs @@ -0,0 +1,18 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路连接保持应答消息 + /// 链路类型:主链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:UP_LINKTEST_RSP。 + /// 描述:上级平台收到下级平台的主链路连接保持请求消息后,向下级平台返回.主链路连接保持应答消息,保持主链路的连接状态。 + /// 主链路连接保持应答消息,数据体为空。 + /// + public class JT809_0x1006:JT809Bodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1007.cs b/src/JT809.Protocol/MessageBody/JT809_0x1007.cs new file mode 100644 index 0000000..58f28f8 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1007.cs @@ -0,0 +1,27 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路断开通知消息 + /// 链路类型:从链路 + /// 消息方向:下级平台往上级平台 + /// 业务数据类型标识:UP_DISCONNECT_INFORM + /// 描述:'当主链路中断后,下级平台可通过从链路向上级平台发送本消息通知上级平台主链路中断 + /// 主链路连接保持应答消息,数据体为空 + /// 本条消息无需被通知方应答 + /// + [JT809Formatter(typeof(JT809_0x1007_Formatter))] + public class JT809_0x1007:JT809Bodies + { + /// + /// 错误代码 + /// + public JT809_0x1007_ErrorCode ErrorCode { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1008.cs b/src/JT809.Protocol/MessageBody/JT809_0x1008.cs new file mode 100644 index 0000000..3da5305 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1008.cs @@ -0,0 +1,25 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 下级平台主动关闭主从链路通知消息 + /// 链路类型:从链路 + /// 消息方向:下级平台往上级平台 + /// 业务数据类型标识:UP_CLOSELINIC INFORM + /// 描述:下级平台作为服务端,发现从链路出现异常时,下级平台通过从链路向上级平台发送本消息,通知上级平台下级平台即将关闭主从链路 + /// + [JT809Formatter(typeof(JT809_0x1008_Formatter))] + public class JT809_0x1008:JT809Bodies + { + /// + /// 错误代码 + /// + public JT809_0x1008_ReasonCode ReasonCode { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1200.cs b/src/JT809.Protocol/MessageBody/JT809_0x1200.cs new file mode 100644 index 0000000..dea4c1f --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1200.cs @@ -0,0 +1,19 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; + + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路车辆动态信息交换业务 + /// 链路类型:主链路 + /// 消息方向:下级平台往上级平台 + /// 业务数据类型标识:UP_EXG_MSG + /// 描述:下级平台向上级平台发送车辆动态信息交换业务数据包 + /// + [JT809Formatter(typeof(JT809BodiesFormatter))] + public class JT809_0x1200: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1300.cs b/src/JT809.Protocol/MessageBody/JT809_0x1300.cs new file mode 100644 index 0000000..0bf854c --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1300.cs @@ -0,0 +1,19 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; +using JT809.Protocol.Formatters.MessageBodyFormatters; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路平台间信息交互消息 + /// 链路类型:主链路 + /// 消息方向:下级平台往上级平台 + /// 业务数据类型标识:UP_PLATFORM_MSG + /// 描述:下级平台向上级平台发送平台间交互信息 + /// + [JT809Formatter(typeof(JT809_0x1300_Formatter))] + public class JT809_0x1300: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1400.cs b/src/JT809.Protocol/MessageBody/JT809_0x1400.cs new file mode 100644 index 0000000..e285608 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1400.cs @@ -0,0 +1,20 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; + + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路报警信息交互消息 + /// 主链路车辆报警信息业务 + /// 链路类型:主链路 + /// 消息方向:下级平台往上级平台 + /// 业务数据类型标识:UP_WARN_MSG + /// 描述:下级平台向上级平台发送车辆报警信息业务 + /// + [JT809Formatter(typeof(JT809BodiesFormatter))] + public class JT809_0x1400: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1500.cs b/src/JT809.Protocol/MessageBody/JT809_0x1500.cs new file mode 100644 index 0000000..6d9850a --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1500.cs @@ -0,0 +1,19 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; + + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路车辆监管消息 + /// 链路类型:主链路 + /// 消息方向:下级平台往上级平台 + /// 业务数据类型标识:UP_CTRL_MSG + /// 描述:下级平台向上级平台发送车辆监管业务 + /// + [JT809Formatter(typeof(JT809BodiesFormatter))] + public class JT809_0x1500: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x1600.cs b/src/JT809.Protocol/MessageBody/JT809_0x1600.cs new file mode 100644 index 0000000..0cbe802 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x1600.cs @@ -0,0 +1,19 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; + + +namespace JT809.Protocol.MessageBody +{ + /// + /// 主链路静态信息交换消息 + /// 链路类型:主链路 + /// 业务数据类型标识:UP_ BASE_ MSG + /// 消息方向:下级平台往上级平台 + /// 描述:下级平台向上级平台发送车辆睁态信息交换业务 + /// + [JT809Formatter(typeof(JT809BodiesFormatter))] + public class JT809_0x1600: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9001.cs b/src/JT809.Protocol/MessageBody/JT809_0x9001.cs new file mode 100644 index 0000000..9239dd0 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9001.cs @@ -0,0 +1,25 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路连接请求消息 + /// 链路类型:从链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:DOWN_CONNECT_REQ + /// 描述:主链路建立连接后,上级平台向下级平台发送从链路连接清求消息,以建立从链路连接 + /// 下级平台在收到本息后,根据本校验码 VERIFY CODE 来实现数据的校验,校验后,则返回DOWN CONNECT RSP 消息 + /// + [JT809Formatter(typeof(JT809_0x9001_Formatter))] + public class JT809_0x9001 : JT809Bodies + { + /// + /// 4.5.1.2 对应的校验码 + /// + public uint VerifyCode { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9002.cs b/src/JT809.Protocol/MessageBody/JT809_0x9002.cs new file mode 100644 index 0000000..13751cf --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9002.cs @@ -0,0 +1,25 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路连接应答信息 + /// 链路类型:从链路 + /// 消息方问:下级平台往上级平台 + /// 业务数据类型标识:DOWN_CONNNECT_RSP + /// 描述:下级平台作为服务器端向上级平台客户端返回从链路连接应答消息,上级平台在接收到该应答消息结果后 + /// + [JT809Formatter(typeof(JT809_0x9002_Formatter))] + public class JT809_0x9002:JT809Bodies + { + /// + /// 验证结果 + /// + public JT809_0x9002_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9003.cs b/src/JT809.Protocol/MessageBody/JT809_0x9003.cs new file mode 100644 index 0000000..fe5f55a --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9003.cs @@ -0,0 +1,24 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + ///从链路注销请求消息 + ///链路类型:从链路 + ///消息方向:上级平台往下级平台 + ///业务数据类型标识:DOWN_DISCONNIrCT_REQ + ///描述:从链路建立后,上级平台在取消该链路时,应向下级平台发送从链路注销请求消息 + /// + [JT809Formatter(typeof(JT809_0x9003_Formatter))] + public class JT809_0x9003: JT809Bodies + { + /// + /// 校验码 + /// + public uint VerifyCode { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9004.cs b/src/JT809.Protocol/MessageBody/JT809_0x9004.cs new file mode 100644 index 0000000..3a30aa3 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9004.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路注销应答消息 + /// 链路类型:从链路 + /// 消息方向:下级平台往上级平台 + /// 业务数据类型构之识:DOWN_DISCONNECT_RSP + /// 描述:下级平台在收到上级平台发送的从链路注销请求消息后,返回从链路注销应答消息,记录相关日志,中断该从链路 + /// 从链路注销应答消息,数据体为空 + /// + public class JT809_0x9004:JT809Bodies + { + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9005.cs b/src/JT809.Protocol/MessageBody/JT809_0x9005.cs new file mode 100644 index 0000000..2812e02 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9005.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路连接保持请求消息 + /// 链路类型:从链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:DOWN_LINKTEST_REQ + /// 描述:从链路建立成功后,上级平台向下级平台发送从链路连接保持请求消息,以保持从链路的连接状态 + /// 从链路连接保持请求消息,数据体为空 + /// + public class JT809_0x9005:JT809Bodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9006.cs b/src/JT809.Protocol/MessageBody/JT809_0x9006.cs new file mode 100644 index 0000000..33d5c20 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9006.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路连接保持应答消息 + /// 链路类型:从链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:DOWN_LINKTEST_REP + /// 描述:下级平台收到上级平台链路连接保持请求消息后,向上级平台返回从链路连接保持应答消息,保持从链路连接状态 + /// 从链路连接保持应答消息,数据体为空 + /// + public class JT809_0x9006:JT809Bodies + { + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9007.cs b/src/JT809.Protocol/MessageBody/JT809_0x9007.cs new file mode 100644 index 0000000..62145cd --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9007.cs @@ -0,0 +1,29 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路断开通知消息 + /// 链路类型:主链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:DOWN_DISCONNECT_INFORM + /// 描述: + /// 情景 1:上级平台与下级平台的从链路中断后,重连二次仍未成功时,上级平台通过主链路发送本消息给下级平台。 + /// 情景 2:上级平台作为客户端向下级平台登录时,根据之前收到的 IP 地址及端口无法连接到下级平台服务端时发送本消息通知下级平台。 + /// + /// 本条消息无需被通知方应答 + /// + [JT809Formatter(typeof(JT809_0x9007_Formatter))] + public class JT809_0x9007:JT809Bodies + { + /// + /// 错误代码 + /// + public JT809_0x9007_ReasonCode ReasonCode { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9008.cs b/src/JT809.Protocol/MessageBody/JT809_0x9008.cs new file mode 100644 index 0000000..3f480c8 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9008.cs @@ -0,0 +1,22 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 上级平台主动关闭链路通知消息 + /// 业务数据类型标识:DOWN_CLOSELINK_INFORM + /// + [JT809Formatter(typeof(JT809_0x9008_Formatter))] + public class JT809_0x9008:JT809Bodies + { + /// + /// 错误代码 + /// + public JT809_0x9008_ReasonCode ReasonCode { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9101.cs b/src/JT809.Protocol/MessageBody/JT809_0x9101.cs new file mode 100644 index 0000000..7f1b243 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9101.cs @@ -0,0 +1,35 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 接收车辆定位信息数量通知消息 + /// 链路类型:从链路 + /// 消息方向:上级平台往下级平台 + /// 业务类型标识: DOWN_TOTAL_RECV_BACK_MSG + /// 描述:上级平台向下级平台定星通知已经收到下级平台上传的车辆定位信息数量(如:每收到10,000 条车辆定位信息通知一次) + /// 本条消息不需下级平台应答。 + /// + [JT809Formatter(typeof(JT809_0x9101_Formatter))] + public class JT809_0x9101:JT809Bodies + { + /// + /// START_TIME_END_TIME共收到的车辆定位信息数量 + /// + public uint DynamicInfoTotal { get; set; } + /// + /// 开始时间,用 UTC 时间表示 + /// 注:采用 UTC 时间表示,如 2010-1-10 9:7:54 的 UTC 值为 1263085674,其在协议中表示为0x000000004B49286A. + /// + public ulong StartTime { get; set; } + /// + /// 结束时间,用 UTC 时间表示 + /// 注:采用 UTC 时间表示,如 2010-1-10 9:7:54 的 UTC 值为 1263085674,其在协议中表示为0x000000004B49286A. + /// + public ulong EndTime { get; set; } + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9200.cs b/src/JT809.Protocol/MessageBody/JT809_0x9200.cs new file mode 100644 index 0000000..bdc4f7c --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9200.cs @@ -0,0 +1,19 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; + + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路车辆动态信息交换业务 + /// 链路类型:从链路 + /// 消息方向:上级平台台往下级平台 + /// 业务数据类型标识:DOWN_EXG_MSG + /// 描述:上级平台作为客户端向下级平台服务端发送车辆动态信息交换业务 + /// + [JT809Formatter(typeof(JT809BodiesFormatter))] + public class JT809_0x9200: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9300.cs b/src/JT809.Protocol/MessageBody/JT809_0x9300.cs new file mode 100644 index 0000000..af799c0 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9300.cs @@ -0,0 +1,19 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; +using JT809.Protocol.Formatters.MessageBodyFormatters; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路平台间信息交互业务 + /// 链路类型:从链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:DOWN_PLATFORM_MSG + /// 描述:上级平台向下级平台发送平台问交互信息 + /// + [JT809Formatter(typeof(JT809_0x9300_Formatter))] + public class JT809_0x9300: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9400.cs b/src/JT809.Protocol/MessageBody/JT809_0x9400.cs new file mode 100644 index 0000000..8f20136 --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9400.cs @@ -0,0 +1,23 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路报警信息交互消息 + /// 链路类型:从链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:DOWN_WARN_MSG + /// 描述:上级平台向下级平台发送报瞥信息业务 + /// + [JT809Formatter(typeof(JT809BodiesFormatter))] + public class JT809_0x9400: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9500.cs b/src/JT809.Protocol/MessageBody/JT809_0x9500.cs new file mode 100644 index 0000000..b5d279e --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9500.cs @@ -0,0 +1,19 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters; + + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路车辆监管消息 + /// 链路类型:从链路 + /// 消息方向:上级平台往下级平台 + /// 业务数据类型标识:DOWN_CTRL_MSG + /// 描述:上级平台向下级平台发送车辆监监管业务 + /// + [JT809Formatter(typeof(JT809BodiesFormatter))] + public class JT809_0x9500: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessageBody/JT809_0x9600.cs b/src/JT809.Protocol/MessageBody/JT809_0x9600.cs new file mode 100644 index 0000000..44c717e --- /dev/null +++ b/src/JT809.Protocol/MessageBody/JT809_0x9600.cs @@ -0,0 +1,23 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters; +using JT809.Protocol.Formatters.MessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.MessageBody +{ + /// + /// 从链路静态信息交换消息 + /// 链路类型:从链路 + /// 消息方向:上级平台往下级台 + /// 业务数据类型标识:DOWN_BASE_MSG + /// 描述:上级平台向下级平台发送车辆静态信息交换业务 + /// + [JT809Formatter(typeof(JT809BodiesFormatter))] + public class JT809_0x9600: JT809ExchangeMessageBodies + { + + } +} diff --git a/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs b/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs new file mode 100644 index 0000000..c39531d --- /dev/null +++ b/src/JT809.Protocol/MessagePack/JT809MessagePackReader.cs @@ -0,0 +1,438 @@ +using JT809.Protocol.Buffers; +using JT809.Protocol.Extensions; +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Text; + + +namespace JT809.Protocol.MessagePack +{ + public ref struct JT809MessagePackReader + { + public ReadOnlySpan Reader { get; private set; } + public ReadOnlySpan SrcBuffer { get; } + public int ReaderCount { get; private set; } + private ushort _calculateCheckCRCCode; + private ushort _realCheckCRCCode; + private bool _checkCRCCodeVali; + /// + /// 是否进行解码操作 + /// 若进行解码操作,则对应的是一个正常的包 + /// 若不进行解码操作,则对应的是一个非正常的包(头部包,数据体包等等) + /// 主要用来一次性读取所有数据体内容操作 + /// + private bool _decoded; + private static byte[] decode5a01 = new byte[] { 0x5a, 0x01 }; + private static byte[] decode5a02 = new byte[] { 0x5a, 0x02 }; + private static byte[] decode5e01 = new byte[] { 0x5e, 0x01 }; + private static byte[] decode5e02 = new byte[] { 0x5e, 0x02 }; + /// + /// 解码(转义还原),计算校验和 + /// + /// + public JT809MessagePackReader(ReadOnlySpan srcBuffer) + { + SrcBuffer = srcBuffer; + ReaderCount = 0; + _realCheckCRCCode = 0x00; + _calculateCheckCRCCode = 0xFFFF; + _checkCRCCodeVali = false; + _decoded = false; + Reader = srcBuffer; + } + /// + /// 在解码的时候把校验和也计算出来,避免在循环一次进行校验 + /// + /// + public void Decode() + { + Span span = new byte[SrcBuffer.Length]; + Decode(span); + _decoded = true; + } + /// + /// 在解码的时候把校验和也计算出来,避免在循环一次进行校验 + /// + /// + public void Decode(Span allocateBuffer) + { + int offset = 0; + int len = SrcBuffer.Length; + allocateBuffer[offset++] = SrcBuffer[0]; + // 取出校验码看是否需要转义 + ReadOnlySpan checkCodeBufferSpan1 = SrcBuffer.Slice(len - 3, 2); + int checkCodeLen = 0; + if (TryDecode(checkCodeBufferSpan1, out byte value1)) + { + //最后两位是转义的 + byte[] tmpCrc2 = new byte[2]; + checkCodeLen += 2; + tmpCrc2[1] = value1; + //从最后往前在取两位进行转义 + ReadOnlySpan checkCodeBufferSpan2 = SrcBuffer.Slice(len - 5, 2); + if (TryDecode(checkCodeBufferSpan2, out byte value2)) + { + //转义成功 + tmpCrc2[0] = value2; + checkCodeLen += 2; + } + else + { + //转义不成功取当前最后一位 + tmpCrc2[0] = checkCodeBufferSpan2[1]; + checkCodeLen += 1; + } + _realCheckCRCCode = ReadUInt16(tmpCrc2); + } + else + { + //最后两位不是转义的 + _realCheckCRCCode=ReadUInt16(checkCodeBufferSpan1); + checkCodeLen += 2; + } + //转义数据长度 + len = len - checkCodeLen - 1 - 1; + ReadOnlySpan tmpBufferSpan = SrcBuffer.Slice(1, len); + for (int i = 0; i < tmpBufferSpan.Length; i++) + { + byte tmp = 0; + if ((tmpBufferSpan.Length - i) >= 2) + { + if (TryDecode(tmpBufferSpan.Slice(i, 2), out tmp)) + { + i++; + } + } + else + { + tmp = tmpBufferSpan[i]; + } + allocateBuffer[offset++] = tmp; + _calculateCheckCRCCode = (ushort)((_calculateCheckCRCCode << 8) ^ (ushort)CRCUtil.CRC[(_calculateCheckCRCCode >> 8) ^ tmp]); + } + allocateBuffer[offset++] = (byte)(_calculateCheckCRCCode >> 8); + allocateBuffer[offset++] = (byte)_calculateCheckCRCCode; + allocateBuffer[offset++] = SrcBuffer[SrcBuffer.Length- 1]; + _checkCRCCodeVali = (_calculateCheckCRCCode == _realCheckCRCCode); + Reader = allocateBuffer.Slice(0, offset); + _decoded = true; + } + + public void FullDecode() + { + int offset = 0; + Span span = new byte[SrcBuffer.Length]; + int len = SrcBuffer.Length; + for (int i = 0; i < len; i++) + { + byte tmp = 0; + if ((SrcBuffer.Length - i) >= 2) + { + if (TryDecode(SrcBuffer.Slice(i, 2), out tmp)) + { + i++; + } + } + else + { + tmp = SrcBuffer[i]; + } + span[offset++] = tmp; + } + Reader = span.Slice(0, offset); + } + + private bool TryDecode(ReadOnlySpan buffer,out byte value) + { + if (buffer.SequenceEqual(decode5a01)) + { + value = 0x5b; + return true; + } + else if (buffer.SequenceEqual(decode5a02)) + { + value = 0x5a; + return true; + } + else if (buffer.SequenceEqual(decode5e01)) + { + value = 0x5d; + return true; + } + else if (buffer.SequenceEqual(decode5e02)) + { + value = 0x5e; + return true; + } + else + { + value = buffer[0]; + return false; + } + } + public ushort CalculateCheckXorCode => _calculateCheckCRCCode; + public ushort RealCheckXorCode => _realCheckCRCCode; + public bool CheckXorCodeVali => _checkCRCCodeVali; + public byte ReadStart()=> ReadByte(); + public byte ReadEnd()=> ReadByte(); + public ushort ReadUInt16() + { + var readOnlySpan = GetReadOnlySpan(2); + ushort value = (ushort)((readOnlySpan[0] << 8) | (readOnlySpan[1])); + return value; + } + public ushort ReadUInt16(ReadOnlySpan buffer) + { + return (ushort)((buffer[0] << 8) | (buffer[1])); + } + public uint ReadUInt32() + { + var readOnlySpan = GetReadOnlySpan(4); + uint value = (uint)((readOnlySpan[0] << 24) | (readOnlySpan[1] << 16) | (readOnlySpan[2] << 8) | readOnlySpan[3]); + return value; + } + public int ReadInt32() + { + var readOnlySpan = GetReadOnlySpan(4); + int value = (int)((readOnlySpan[0] << 24) | (readOnlySpan[1] << 16) | (readOnlySpan[2] << 8) | readOnlySpan[3]); + return value; + } + public ulong ReadUInt64() + { + var readOnlySpan = GetReadOnlySpan(8); + ulong value = (ulong)( + (readOnlySpan[0] << 56) | + (readOnlySpan[1] << 48) | + (readOnlySpan[2] << 40) | + (readOnlySpan[3] << 32) | + (readOnlySpan[4] << 24) | + (readOnlySpan[5] << 16) | + (readOnlySpan[6] << 8) | + readOnlySpan[7]); + return value; + } + public byte ReadByte() + { + var readOnlySpan = GetReadOnlySpan(1); + return readOnlySpan[0]; + } + public byte ReadVirtualByte() + { + var readOnlySpan = GetVirtualReadOnlySpan(1); + return readOnlySpan[0]; + } + public ushort ReadVirtualUInt16() + { + var readOnlySpan = GetVirtualReadOnlySpan(2); + return (ushort)((readOnlySpan[0] << 8) | (readOnlySpan[1])); + } + public uint ReadVirtualUInt32() + { + var readOnlySpan = GetVirtualReadOnlySpan(4); + return (uint)((readOnlySpan[0] << 24) | (readOnlySpan[1] << 16) | (readOnlySpan[2] << 8) | readOnlySpan[3]); + } + public ulong ReadVirtualUInt64() + { + var readOnlySpan = GetVirtualReadOnlySpan(8); + return (ulong)( + (readOnlySpan[0] << 56) | + (readOnlySpan[1] << 48) | + (readOnlySpan[2] << 40) | + (readOnlySpan[3] << 32) | + (readOnlySpan[4] << 24) | + (readOnlySpan[5] << 16) | + (readOnlySpan[6] << 8) | + readOnlySpan[7]); + } + /// + /// 数字编码 大端模式、高位在前 + /// + /// + public string ReadBigNumber(int len) + { + ulong result = 0; + var readOnlySpan = GetReadOnlySpan(len); + for (int i = 0; i < len; i++) + { + ulong currentData = (ulong)readOnlySpan[i] << (8 * (len - i - 1)); + result += currentData; + } + return result.ToString(); + } + public ReadOnlySpan ReadArray(int len) + { + var readOnlySpan = GetReadOnlySpan(len); + return readOnlySpan.Slice(0, len); + } + public ReadOnlySpan ReadArray(int start,int end) + { + return Reader.Slice(start,end); + } + public string ReadString(int len) + { + var readOnlySpan = GetReadOnlySpan(len); + string value = JT809Constants.Encoding.GetString(readOnlySpan.Slice(0, len).ToArray()); + return value.Trim('\0'); + } + public string ReadRemainStringContent() + { + var readOnlySpan = ReadContent(0); + string value = JT809Constants.Encoding.GetString(readOnlySpan.ToArray()); + return value.Trim('\0'); + } + public string ReadHex(int len) + { + var readOnlySpan = GetReadOnlySpan(len); + string hex = HexUtil.DoHexDump(readOnlySpan, 0, len); + return hex; + } + /// + /// yyMMddHHmmss + /// + /// >D2: 10 X2:16 + public DateTime ReadDateTime6(string format = "X2") + { + DateTime d; + try + { + var readOnlySpan = GetReadOnlySpan(6); + int year = Convert.ToInt32(readOnlySpan[0].ToString(format)) + JT809Constants.DateLimitYear; + int month = Convert.ToInt32(readOnlySpan[1].ToString(format)); + int day = Convert.ToInt32(readOnlySpan[2].ToString(format)); + int hour = Convert.ToInt32(readOnlySpan[3].ToString(format)); + int minute = Convert.ToInt32(readOnlySpan[4].ToString(format)); + int second = Convert.ToInt32(readOnlySpan[5].ToString(format)); + d = new DateTime(year, month, day, hour, minute, second); + } + catch (Exception) + { + d = JT809Constants.UTCBaseTime; + } + return d; + } + /// + /// HH-mm-ss-msms + /// HH-mm-ss-fff + /// + /// D2: 10 X2:16 + public DateTime ReadDateTime5(string format = "X2") + { + DateTime d; + try + { + var readOnlySpan = GetReadOnlySpan(5); + d = new DateTime( + DateTime.Now.Year, + DateTime.Now.Month, + DateTime.Now.Day, + Convert.ToInt32(readOnlySpan[0].ToString(format)), + Convert.ToInt32(readOnlySpan[1].ToString(format)), + Convert.ToInt32(readOnlySpan[2].ToString(format)), + Convert.ToInt32(((readOnlySpan[3] << 8) + readOnlySpan[4]))); + } + catch + { + d = JT809Constants.UTCBaseTime; + } + return d; + } + /// + /// YYYYMMDD + /// + /// D2: 10 X2:16 + public DateTime ReadDateTime4(string format = "X2") + { + DateTime d; + try + { + var readOnlySpan = GetReadOnlySpan(4); + d = new DateTime( + (Convert.ToInt32(readOnlySpan[0].ToString(format)) << 8) + Convert.ToByte(readOnlySpan[1]), + Convert.ToInt32(readOnlySpan[2].ToString(format)), + Convert.ToInt32(readOnlySpan[3].ToString(format))); + } + catch (Exception) + { + d = JT809Constants.UTCBaseTime; + } + return d; + } + public DateTime ReadUTCDateTime() + { + DateTime d; + try + { + ulong result = 0; + var readOnlySpan = GetReadOnlySpan(8); + for (int i = 0; i < 8; i++) + { + ulong currentData = (ulong)readOnlySpan[i] << (8 * (8 - i - 1)); + result += currentData; + } + d = JT809Constants.UTCBaseTime.AddSeconds(result).AddHours(8); + } + catch (Exception) + { + d = JT809Constants.UTCBaseTime; + } + return d; + } + public string ReadBCD(int len) + { + int count = len / 2; + var readOnlySpan = GetReadOnlySpan(count); + StringBuilder bcdSb = new StringBuilder(count); + for (int i = 0; i < count; i++) + { + bcdSb.Append(readOnlySpan[i].ToString("X2")); + } + // todo:对于协议来说这个0是有意义的,下个版本在去掉 + return bcdSb.ToString().TrimStart('0'); + } + private ReadOnlySpan GetReadOnlySpan(int count) + { + ReaderCount += count; + return Reader.Slice(ReaderCount - count); + } + public ReadOnlySpan GetVirtualReadOnlySpan(int count) + { + return Reader.Slice(ReaderCount, count); + } + public ReadOnlySpan ReadContent(int count=0) + { + if (_decoded) + { + //内容长度=总长度-读取的长度-3(校验码1位+终止符1位) + int totalContent = Reader.Length - ReaderCount - 3; + //实际读取内容长度 + int realContent = totalContent - count; + int tempReaderCount = ReaderCount; + ReaderCount += realContent; + return Reader.Slice(tempReaderCount, realContent); + } + else + { + return Reader.Slice(ReaderCount); + } + } + public int ReadCurrentRemainContentLength() + { + if (_decoded) + { + //内容长度=总长度-读取的长度-3(校验码2位+终止符1位) + return Reader.Length - ReaderCount - 3; + } + else + { + return Reader.Length - ReaderCount; + } + } + public void Skip(int count=1) + { + ReaderCount += count; + } + } +} diff --git a/src/JT809.Protocol/MessagePack/JT809MessagePackWriter.cs b/src/JT809.Protocol/MessagePack/JT809MessagePackWriter.cs new file mode 100644 index 0000000..4d1be07 --- /dev/null +++ b/src/JT809.Protocol/MessagePack/JT809MessagePackWriter.cs @@ -0,0 +1,463 @@ +using JT809.Protocol.Buffers; +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Linq; +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("JT809.Protocol.Test")] + +namespace JT809.Protocol.MessagePack +{ + public ref struct JT809MessagePackWriter + { + private JT809BufferWriter writer; + public JT809MessagePackWriter(Span buffer) + { + this.writer = new JT809BufferWriter(buffer); + } + public byte[] FlushAndGetEncodingArray() + { + return writer.Written.Slice(writer.BeforeCodingWrittenPosition).ToArray(); + } + public byte[] FlushAndGetRealArray() + { + return writer.Written.ToArray(); + } + public void WriteStart()=> WriteByte(JT809Package.BEGINFLAG); + public void WriteEnd() => WriteByte(JT809Package.ENDFLAG); + public void Nil(out int position) + { + position = writer.WrittenCount; + var span = writer.Free; + span[0] = 0x00; + writer.Advance(1); + } + public void Skip(int count, out int position) + { + position = writer.WrittenCount; + var span = writer.Free; + for (var i = 0; i < count; i++) + { + span[i] = 0x00; + } + writer.Advance(count); + } + public void Skip(int count,out int position, byte fullValue = 0x00) + { + position = writer.WrittenCount; + var span = writer.Free; + for (var i = 0; i < count; i++) + { + span[i] = fullValue; + } + writer.Advance(count); + } + public void WriteByte(byte value) + { + var span = writer.Free; + span[0] = value; + writer.Advance(1); + } + public void WriteUInt16(ushort value) + { + var span = writer.Free; + span[0] = (byte)(value >> 8); + span[1] = (byte)value; + writer.Advance(2); + } + public void WriteInt32(int value) + { + var span = writer.Free; + span[0] = (byte)(value >> 24); + span[1] = (byte)(value >> 16); + span[2] = (byte)(value >> 8); + span[3] = (byte)value; + writer.Advance(4); + } + public void WriteUInt64(ulong value) + { + var span = writer.Free; + span[0] = (byte)(value >> 56); + span[1] = (byte)(value >> 48); + span[2] = (byte)(value >> 40); + span[3] = (byte)(value >> 32); + span[4] = (byte)(value >> 24); + span[5] = (byte)(value >> 16); + span[6] = (byte)(value >> 8); + span[7] = (byte)value; + writer.Advance(8); + } + public void WriteUInt32(uint value) + { + var span = writer.Free; + span[0] = (byte)(value >> 24); + span[1] = (byte)(value >> 16); + span[2] = (byte)(value >> 8); + span[3] = (byte)value; + writer.Advance(4); + } + public void WriteStringPadLeft(string value, int len) + { + Span codeBytes = JT809Constants.Encoding.GetBytes(value).AsSpan(); + var fillLength = codeBytes.Length - len; + if (fillLength > 0) + { + codeBytes.Slice(0, len).CopyTo(writer.Free); + writer.Advance(codeBytes.Length); + } + else if (fillLength < 0) + { + Skip(-fillLength, out _); + codeBytes.CopyTo(writer.Free); + writer.Advance(codeBytes.Length); + } + else + { + codeBytes.CopyTo(writer.Free); + writer.Advance(codeBytes.Length); + } + } + public void WriteStringPadRight(string value,int len) + { + Span codeBytes = JT809Constants.Encoding.GetBytes(value).AsSpan(); + var fillLength = codeBytes.Length - len; + if (fillLength > 0) + { + codeBytes.Slice(0, len).CopyTo(writer.Free); + writer.Advance(codeBytes.Length); + } + else if(fillLength < 0) + { + codeBytes.CopyTo(writer.Free); + writer.Advance(codeBytes.Length); + Skip(-fillLength, out _); + } + else + { + codeBytes.CopyTo(writer.Free); + writer.Advance(codeBytes.Length); + } + } + public void WriteString(string value) + { + byte[] codeBytes = JT809Constants.Encoding.GetBytes(value); + codeBytes.CopyTo(writer.Free); + writer.Advance(codeBytes.Length); + } + public void WriteArray(ReadOnlySpan src) + { + src.CopyTo(writer.Free); + writer.Advance(src.Length); + } + public void WriteUInt16Return(ushort value, int position) + { + writer.Written[position] = (byte)(value >> 8); + writer.Written[position + 1] = (byte)value; + } + public void WriteInt32Return(int value, int position) + { + writer.Written[position] = (byte)(value >> 24); + writer.Written[position + 1] = (byte)(value >> 16); + writer.Written[position + 2] = (byte)(value >> 8); + writer.Written[position + 3] = (byte)value; + } + public void WriteUInt32Return(uint value, int position) + { + writer.Written[position] = (byte)(value >> 24); + writer.Written[position + 1] = (byte)(value >> 16); + writer.Written[position + 2] = (byte)(value >> 8); + writer.Written[position + 3] = (byte)value; + } + public void WriteByteReturn(byte value, int position) + { + writer.Written[position] = value; + } + public void WriteBCDReturn(string value,int len, int position) + { + string bcdText = value ?? ""; + int startIndex = 0; + int noOfZero = len - bcdText.Length; + if (noOfZero > 0) + { + bcdText = bcdText.Insert(startIndex, new string('0', noOfZero)); + } + int byteIndex = 0; + int count = len / 2; + var bcdSpan = bcdText.AsSpan(); + while (startIndex < bcdText.Length && byteIndex < count) + { + writer.Written[position+(byteIndex++)] = Convert.ToByte(bcdSpan.Slice(startIndex, 2).ToString(), 16); + startIndex += 2; + } + } + public void WriteStringReturn(string value, int position) + { + byte[] codeBytes = JT809Constants.Encoding.GetBytes(value); + for (var i = 0; i < codeBytes.Length; i++) + { + writer.Written[position + i] = codeBytes[i]; + } + } + public void WriteArrayReturn(ReadOnlySpan src, int position) + { + foreach (var item in src) + { + writer.Written[position] = item; + position++; + } + } + /// + /// yyMMddHHmmss + /// + /// + /// + public void WriteDateTime6(DateTime value, int fromBase = 16) + { + var span = writer.Free; + span[0] = Convert.ToByte(value.ToString("yy"), fromBase); + span[1] = Convert.ToByte(value.ToString("MM"), fromBase); + span[2] = Convert.ToByte(value.ToString("dd"), fromBase); + span[3] = Convert.ToByte(value.ToString("HH"), fromBase); + span[4] = Convert.ToByte(value.ToString("mm"), fromBase); + span[5] = Convert.ToByte(value.ToString("ss"), fromBase); + writer.Advance(6); + } + /// + /// HH-mm-ss-msms + /// HH-mm-ss-fff + /// + /// + /// + public void WriteDateTime5(DateTime value, int fromBase = 16) + { + var span = writer.Free; + span[0] = Convert.ToByte(value.ToString("HH"), fromBase); + span[1] = Convert.ToByte(value.ToString("mm"), fromBase); + span[2] = Convert.ToByte(value.ToString("ss"), fromBase); + span[3] = (byte)(value.Millisecond >> 8); + span[4] = (byte)(value.Millisecond); + writer.Advance(5); + } + public void WriteUTCDateTime(DateTime value) + { + ulong totalSecends = (ulong)(value.AddHours(-8) - JT809Constants.UTCBaseTime).TotalSeconds; + var span = writer.Free; + //高位在前 + for (int i = 7; i >= 0; i--) + { + span[i] = (byte)(totalSecends & 0xFF); //取低8位 + totalSecends >>= 8; + } + writer.Advance(8); + } + /// + /// YYYYMMDD + /// + /// + /// + public void WriteDateTime4(DateTime value, int fromBase = 16) + { + var span = writer.Free; + span[0] = (byte)(value.Year >> 8); + span[1] = (byte)(value.Year); + span[2] = Convert.ToByte(value.ToString("MM"), fromBase); + span[3] = Convert.ToByte(value.ToString("dd"), fromBase); + writer.Advance(4); + } + public void WriteCRC16(int start, int end) + { + if (start > end) + { + throw new ArgumentOutOfRangeException($"start>end:{start}>{end}"); + } + var crcSpan = writer.Written.Slice(start, end); + ushort crcCode = 0xFFFF; + for (int i = 0; i < crcSpan.Length; i++) + { + crcCode = (ushort)((crcCode << 8) ^ (ushort)CRCUtil.CRC[(crcCode >> 8) ^ crcSpan[i]]); + } + WriteUInt16(crcCode); + } + public void WriteCRC16(int start) + { + if (writer.WrittenCount < start) + { + throw new ArgumentOutOfRangeException($"Written{1}"); + } + var crcSpan = writer.Written.Slice(start); + ushort crcCode = 0xFFFF; + for (int i = 0; i < crcSpan.Length; i++) + { + crcCode = (ushort)((crcCode << 8) ^ (ushort)CRCUtil.CRC[(crcCode >> 8) ^ crcSpan[i]]); + } + WriteUInt16(crcCode); + } + public void WriteCRC16() + { + if (writer.WrittenCount < 1) + { + throw new ArgumentOutOfRangeException($"Written{1}"); + } + //从第1位开始 + var crcSpan = writer.Written.Slice(1); + ushort crcCode = 0xFFFF; + for (int i = 0; i < crcSpan.Length; i++) + { + crcCode = (ushort)((crcCode << 8) ^ (ushort)CRCUtil.CRC[(crcCode >> 8) ^ crcSpan[i]]); + } + WriteUInt16(crcCode); + } + public void WriteBCD(string value, int len) + { + string bcdText = value ?? ""; + int startIndex = 0; + int noOfZero = len - bcdText.Length; + if (noOfZero > 0) + { + bcdText = bcdText.Insert(startIndex, new string('0', noOfZero)); + } + int byteIndex = 0; + int count = len / 2; + var bcdSpan = bcdText.AsSpan(); + var spanFree = writer.Free; + while (startIndex < bcdText.Length && byteIndex < count) + { + spanFree[byteIndex++] = Convert.ToByte(bcdSpan.Slice(startIndex, 2).ToString(), 16); + startIndex += 2; + } + writer.Advance(byteIndex); + } + public void WriteHex(string value, int len) + { + value = value ?? ""; + value = value.Replace(" ", ""); + int startIndex = 0; + if (value.StartsWith("0x", StringComparison.OrdinalIgnoreCase)) + { + startIndex = 2; + } + int length = len; + if (length == -1) + { + length = (value.Length - startIndex) / 2; + } + int noOfZero = length * 2 + startIndex - value.Length; + if (noOfZero > 0) + { + value = value.Insert(startIndex, new string('0', noOfZero)); + } + int byteIndex = 0; + var hexSpan = value.AsSpan(); + var spanFree = writer.Free; + while (startIndex < value.Length && byteIndex < length) + { + spanFree[byteIndex++] = Convert.ToByte(hexSpan.Slice(startIndex, 2).ToString(), 16); + startIndex += 2; + } + writer.Advance(byteIndex); + } + public void WriteFullEncode() + { + var tmpSpan = writer.Written; + writer.BeforeCodingWrittenPosition = writer.WrittenCount; + var spanFree = writer.Free; + int tmpOffset = 0; + for (int i = 0; i < tmpSpan.Length; i++) + { + var item = tmpSpan[i]; + switch (item) + { + case 0x5b: + spanFree[tmpOffset++] = 0x5a; + spanFree[tmpOffset++] = 0x01; + break; + case 0x5a: + spanFree[tmpOffset++] = 0x5a; + spanFree[tmpOffset++] = 0x02; + break; + case 0x5d: + spanFree[tmpOffset++] = 0x5e; + spanFree[tmpOffset++] = 0x01; + break; + case 0x5e: + spanFree[tmpOffset++] = 0x5e; + spanFree[tmpOffset++] = 0x02; + break; + default: + spanFree[tmpOffset++] = item; + break; + } + } + writer.Advance(tmpOffset); + } + internal void WriteEncode() + { + var tmpSpan = writer.Written; + writer.BeforeCodingWrittenPosition = writer.WrittenCount; + var spanFree = writer.Free; + int tmpOffset = 0; + spanFree[tmpOffset++] = tmpSpan[0]; + for (int i = 1; i < tmpSpan.Length - 1; i++) + { + var item = tmpSpan[i]; + switch (item) + { + case 0x5b: + spanFree[tmpOffset++] = 0x5a; + spanFree[tmpOffset++] = 0x01; + break; + case 0x5a: + spanFree[tmpOffset++] = 0x5a; + spanFree[tmpOffset++] = 0x02; + break; + case 0x5d: + spanFree[tmpOffset++] = 0x5e; + spanFree[tmpOffset++] = 0x01; + break; + case 0x5e: + spanFree[tmpOffset++] = 0x5e; + spanFree[tmpOffset++] = 0x02; + break; + default: + spanFree[tmpOffset++] = item; + break; + } + } + spanFree[tmpOffset++] = tmpSpan[tmpSpan.Length - 1]; + writer.Advance(tmpOffset); + } + /// + /// 数字编码 大端模式、高位在前 + /// + /// + /// + public void WriteBigNumber(string value, int len) + { + var spanFree = writer.Free; + ulong number = string.IsNullOrEmpty(value) ? 0 : (ulong)double.Parse(value); + for (int i = len - 1; i >= 0; i--) + { + spanFree[i] = (byte)(number & 0xFF); //取低8位 + number = number >> 8; + } + writer.Advance(len); + } + public ReadOnlySpan Extract(int start) + { + return writer.Written.Slice(start); + } + public void CopyTo(ReadOnlySpan buffer, int from) + { + buffer.CopyTo(writer.Written.Slice(from, buffer.Length)); + } + public void Shrink(int length) + { + writer.Shrink(length); + } + public int GetCurrentPosition() + { + return writer.WrittenCount; + } + } +} diff --git a/src/JT809.Protocol/Metadata/JT809VehiclePositionProperties.cs b/src/JT809.Protocol/Metadata/JT809VehiclePositionProperties.cs new file mode 100644 index 0000000..9962ed6 --- /dev/null +++ b/src/JT809.Protocol/Metadata/JT809VehiclePositionProperties.cs @@ -0,0 +1,78 @@ +using JT809.Protocol.Enums; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.Metadata +{ + /// + /// 车辆定位 + /// + public class JT809VehiclePositionProperties + { + /// + /// 该字段标识传输的定位信息是否使用国家测绘局批准的地图保密插件进行加密。 + /// + public JT809_VehiclePositionEncrypt Encrypt { get; set; } + /// + /// 日 + /// + public byte Day { get; set; } + /// + /// 月 + /// + public byte Month { get; set; } + /// + /// 年 + /// + public ushort Year { get; set; } + /// + /// 时 + /// + public byte Hour { get; set; } + /// + /// 分 + /// + public byte Minute { get; set; } + /// + /// 秒 + /// + public byte Second { get; set; } + /// + /// 经度,单位为 1*10^-6 度。 + /// + public uint Lon { get; set; } + /// + /// 纬度,单位为 1*10^-6 度。 + /// + public uint Lat { get; set; } + /// + /// 速度,指卫星定位车载终端设备上传的行车速度信息,为必填项。单位为千米每小时(km/h)。 + /// + public ushort Vec1 { get; set; } + /// + /// 行驶记录速度,指车辆行驶记录设备上传的行车速度 信息,为必填项。单位为千米每小时(km/h)。 + /// + public ushort Vec2 { get; set; } + /// + /// 车辆当前总里程数,值车辆上传的行车里程数。单位单位为千米(km) + /// + public uint Vec3 { get; set; } + /// + /// 方向,0-359,单位为度(。),正北为 0,顺时针。 + /// + public ushort Direction { get; set; } + /// + /// 海拔高度,单位为米(m)。 + /// + public ushort Altitude { get; set; } + /// + /// 车辆状态,二进制表示,B31B30B29。。。。。。B2B1B0.具体定义按照 JT/T808-2011 中表 17 的规定 + /// + public uint State { get; set; } + /// + /// 报警状态,二进制表示,0 标识正常,1 表示报警: B31B30B29 。。。。。。 B2B1B0.具 体 定 义 按 照JT/T808-2011 中表 18 的规定 + /// + public uint Alarm { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs new file mode 100644 index 0000000..e6de76b --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1201.cs @@ -0,0 +1,40 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 上传车辆注册信息消息 + /// 子业务类型标识:UP_ EXG_ MSG_ REGISTER + /// 描述:监控平台收到车载终端鉴权信息后,启动本命令向上级监管平台上传该车辆注册信息.各级监管平台再逐级向上级平台上传该信息 + /// 本条消息服务端无需应答 + /// + [JT809Formatter(typeof(JT809_0x1200_0x1201_Formatter))] + public class JT809_0x1200_0x1201:JT809SubBodies + { + /// + /// 平台唯一编码 + /// + public string PlateformId { get; set; } + /// + /// 车载终端厂商唯一编码 + /// + public string ProducerId { get; set; } + /// + /// 车载终端型号,不是 8 位时以“\0”终结 + /// + public string TerminalModelType { get; set; } + /// + /// 车载终端编号,大写字母和数字组成 + /// + public string TerminalId { get; set; } + /// + /// 车载终端 SIM 卡电话号码。号码不是12 位,则在前补充数字 0. + /// + public string TerminalSimCode { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1202.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1202.cs new file mode 100644 index 0000000..2ab9938 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1202.cs @@ -0,0 +1,26 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using JT809.Protocol.Metadata; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 实时上传车辆定位信息 + /// 子业务类型标识:UP_EXG_MSG_REAL_LOCATION + /// + [JT809Formatter(typeof(JT809_0x1200_0x1202_Formatter))] + public class JT809_0x1200_0x1202:JT809SubBodies + { + public JT809_0x1200_0x1202() + { + VehiclePosition = new JT809VehiclePositionProperties(); + } + /// + /// 车辆定位信息 + /// + public JT809VehiclePositionProperties VehiclePosition { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1203.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1203.cs new file mode 100644 index 0000000..b5264c8 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1203.cs @@ -0,0 +1,31 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using JT809.Protocol.Metadata; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 车辆定位信息自动补报请求消息 + /// 子业务类型标识:UP_EXG_MSG_HISTORY_LOCATION + /// 描述:如果平台间传输链路中断,下级平台重新登录并与上级平台建立通信链路后,下级平台应将中断期间内车载终端上传的车辆定位信息自动补报到上级平台。 + /// 如果系统断线期间,该车需发送的数据包条数大于 5,则以每包五条进行补发,直到补发完毕。 + /// 多条数据以卫星定位时间先后顺序排列。 + /// 本条消息上级平台采用定量回复,即收到一定数量的数据后,即通过从链路应答数据量。 + /// + /// + [JT809Formatter(typeof(JT809_0x1200_0x1203_Formatter))] + public class JT809_0x1200_0x1203 : JT809SubBodies + { + /// + /// 卫星定位数据个数 1大于GNSS_CNT小于5 + /// + public byte GNSSCount { get; set; } + /// + /// 卫星定位数据集合 + /// + public List GNSS { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1205.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1205.cs new file mode 100644 index 0000000..ebe505c --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1205.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 启动车辆定位信息交换应答消息 + /// 子业务类型标识:UP_EXG_ MSG_ RETURN_ STARTUP ACK + /// 描述:本条消息是下级平台对上级平台下发的 DOWN_EXG_ MSG_ RETURN_STARTUP 消息的应答消息 + /// + public class JT809_0x1200_0x1205:JT809SubBodies + { + + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1206.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1206.cs new file mode 100644 index 0000000..df238ec --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1206.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 结束车辆定位信息交换应答消息 + /// 子业务类型标识:UP_EXG_MSG_RETURN_END_ACK + /// + public class JT809_0x1200_0x1206:JT809SubBodies + { + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1207.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1207.cs new file mode 100644 index 0000000..07cc8f5 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1207.cs @@ -0,0 +1,26 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 申请交换指定车辆定位信息请求消息 + /// 子业务类型标识:UP_EXG_MSG_APPLY-FOR_MONITOR_STARTUP + /// 描述:当下级平台需要在特定时问段内监控特殊车辆时,可上传此命令到上级平台申请对该车辆定位数据交换到下级平台,申请成功后,此车辆定位数据将在指定时间内交换到该平台(即使该车没有进入该平台所属区域也会交换) + /// + [JT809Formatter(typeof(JT809_0x1200_0x1207_Formatter))] + public class JT809_0x1200_0x1207:JT809SubBodies + { + /// + /// 开始时间,用 UTC 时间表示 + /// + public DateTime StartTime { get; set; } + /// + /// 结束时间,用 UTC 时间表示 + /// + public DateTime EndTime { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1208.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1208.cs new file mode 100644 index 0000000..2be53f0 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1208.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 取消交换指定车辆定位信息请 + /// 子业务类型标识:UP_EXG_MSG_APPLY_F0R_MONIOR_END + /// 描述:下级平台上传该命令给上级平台,取消之前申请监控的特殊车辆 + /// + public class JT809_0x1200_0x1208:JT809SubBodies + { + + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1209.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1209.cs new file mode 100644 index 0000000..9f0ed55 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x1209.cs @@ -0,0 +1,26 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 补发车辆定位信息请求 + /// 子业务类型标识:UP_EXG_MSG_APPLY_HISGNSSDATA_REQ + /// 描述:在平台间传输链路中断并重新建立连接后,下级平台向上级平台请求中断期间内上级平台需交换至下级平台的车辆定位信息时,向上级平台发出补发车辆定位信息请求,上级平台对请求应答后进行“补发车辆定位信息” + /// + [JT809Formatter(typeof(JT809_0x1200_0x1209_Formatter))] + public class JT809_0x1200_0x1209:JT809SubBodies + { + /// + /// 开始时间,用 UTC 时间表示 + /// + public DateTime StartTime { get; set; } + /// + /// 结束时间,用 UTC 时间表示 + /// + public DateTime EndTime { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120A.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120A.cs new file mode 100644 index 0000000..beb57aa --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120A.cs @@ -0,0 +1,34 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 上报驾驶员身份识别信息应答消息 + /// 子业务类型标识:UP_EXG_MSG_REPORT_DRIVER_INFO_ACK + /// 描述:下级平台应答上级平台发送的上报驾驶员身份识别信息请求消息,上传指定车辆的驾驶员身份识别信息数据 + /// + [JT809Formatter(typeof(JT809_0x1200_0x120A_Formatter))] + public class JT809_0x1200_0x120A:JT809SubBodies + { + /// + /// 驾驶员姓名 + /// + public string DriverName { get; set; } + /// + /// 身份证编号 + /// + public string DriverID { get; set; } + /// + /// 从业资格证(备用) + /// + public string Licence { get; set; } + /// + /// 发证机构名称(备用) + /// + public string OrgName { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120B.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120B.cs new file mode 100644 index 0000000..d45236c --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120B.cs @@ -0,0 +1,26 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 上报车辆电子运单应答消息 + /// 子业务类型标识:UP_CXG_MSG_TAKE_EWAYBILL_ACK + /// 描述:下级平台应答上级平台发送的上报车辆电子运单请求消息,向上级平台上传车辆当前电子运单 + /// + [JT809Formatter(typeof(JT809_0x1200_0x120B_Formatter))] + public class JT809_0x1200_0x120B:JT809SubBodies + { + /// + /// 电子运单数据体长度 + /// + public uint EwaybillLength { get; set; } + /// + /// 电子运单数据内容 + /// + public string EwaybillInfo { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120C.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120C.cs new file mode 100644 index 0000000..292623e --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120C.cs @@ -0,0 +1,33 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 主动上报驾驶员身份信息消息 + /// 子业务类型标识:UP_EXG_MSG_REPORT_DRIVER_INFO + /// + [JT809Formatter(typeof(JT809_0x1200_0x120C_Formatter))] + public class JT809_0x1200_0x120C:JT809SubBodies + { + /// + /// 驾驶员姓名 + /// + public string DriverName { get; set; } + /// + /// 身份证编号 + /// + public string DriverID { get; set; } + /// + /// 从业资格证(备用) + /// + public string Licence { get; set; } + /// + /// 发证机构名称(备用) + /// + public string OrgName { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120D.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120D.cs new file mode 100644 index 0000000..794f013 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1200_0x120D.cs @@ -0,0 +1,25 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 主动上报车辆电子运单信息 + /// 子业务类型标识:UP_EXG_MSG_REPORT_EWAYBILL_INFO + /// + [JT809Formatter(typeof(JT809_0x1200_0x120D_Formatter))] + public class JT809_0x1200_0x120D:JT809SubBodies + { + /// + /// 电子运单数据体长度 + /// + public uint EwaybillLength { get; set; } + /// + /// 电子运单数据内容 + /// + public string EwaybillInfo { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1301.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1301.cs new file mode 100644 index 0000000..e4e03ac --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1301.cs @@ -0,0 +1,39 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 平台查岗应答消息 + /// 子业务类型标识:UP_PLATFORM_MSG_POST_QUERY_ACK + /// 描述:下级平台应答上级平台发送的不定期平台查岗消息 + /// + [JT809Formatter(typeof(JT809_0x1300_0x1301_Formatter))] + public class JT809_0x1300_0x1301:JT809SubBodies + { + /// + /// 查岗对象的类型 + /// + public JT809_0x1301_ObjectType ObjectType { get; set; } + /// + /// 查岗对象的ID + /// + public string ObjectID { get; set; } + /// + /// 信息ID + /// + public uint InfoID { get; set; } + /// + /// 数据长度 + /// + public uint InfoLength { get; set; } + /// + /// 应答内容 + /// + public string InfoContent { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1302.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1302.cs new file mode 100644 index 0000000..c095478 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1300_0x1302.cs @@ -0,0 +1,22 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 下发平台间报文应答消息 + /// 子业务类型标识:UP_PLATFORM_MSG_INFO_ACK + /// 描述:下级平台收到上级平台发送的下发平台间报文请求消息后,发送应答消息 + /// + [JT809Formatter(typeof(JT809_0x1300_0x1302_Formatter))] + public class JT809_0x1300_0x1302:JT809SubBodies + { + /// + /// 信息ID + /// + public uint InfoID { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1401.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1401.cs new file mode 100644 index 0000000..2601730 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1401.cs @@ -0,0 +1,27 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 报警督办应答消息 + /// 子业务类型标识:UP_WARN_MSG_URGE_TODO_ACK + /// 描述:下级平台应答上级平台下发的报警督办请求消息,向上.级平台上报车辆的报瞥处理结果 + /// + [JT809Formatter(typeof(JT809_0x1400_0x1401_Formatter))] + public class JT809_0x1400_0x1401:JT809SubBodies + { + /// + /// 报警督办 ID + /// + public uint SupervisionID { get; set; } + /// + /// 报警处理结果 + /// + public JT809_0x1401_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1402.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1402.cs new file mode 100644 index 0000000..4d2734a --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1402.cs @@ -0,0 +1,44 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 上报报警信息消息 + /// 子业务类型标识:UP_WARN_MSG_ADPT_INFO + /// 描述:下级平台向上级平台上报某车辆的报警信息 + /// 本条消息上级平台无需应答 + /// + [JT809Formatter(typeof(JT809_0x1400_0x1402_Formatter))] + public class JT809_0x1400_0x1402:JT809SubBodies + { + /// + /// 报警信息来源 + /// + public JT809WarnSrc WarnSrc { get; set; } + /// + /// 报警类型 + /// + public JT809WarnType WarnType { get; set; } + /// + /// 报警时间 + /// + public DateTime WarnTime { get; set; } + /// + /// 信息ID + /// + public uint InfoID { get; set; } + /// + /// 数据长度 + /// + public uint InfoLength { get; set; } + /// + /// 数据长度 + /// + public string InfoContent { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1403.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1403.cs new file mode 100644 index 0000000..a78f2dd --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1400_0x1403.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 主动上报报警处理结果信息 + /// 子业务类型标识:UP_WARN_MSG_ADPT_TODO_INFO + /// 描述:下级平台向上级平台上报报警处理结果 + /// 本条消息上级平台无需应答 + /// + [JT809Formatter(typeof(JT809_0x1400_0x1403_Formatter))] + public class JT809_0x1400_0x1403:JT809SubBodies + { + /// + /// 报警信息ID + /// + public uint InfoID { get; set; } + /// + /// 处理结果 + /// + public JT809_0x1403_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1501.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1501.cs new file mode 100644 index 0000000..9920553 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1501.cs @@ -0,0 +1,23 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 车辆单向监听应答 + /// 子业务类型标识:UP_CTRL_MSG_MONITOR_VEHTCLE_ACK + /// 描述:下级平台向上级平台上传车辆单向监听请求消息的应答 + /// + [JT809Formatter(typeof(JT809_0x1500_0x1501_Formatter))] + public class JT809_0x1500_0x1501:JT809SubBodies + { + /// + /// 应答结果 + /// + public JT809_0x1501_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1502.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1502.cs new file mode 100644 index 0000000..98d87c9 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1502.cs @@ -0,0 +1,53 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using JT809.Protocol.Metadata; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 车辆拍照应答 + /// 子业务类型标识:UP_ CTRL_ MSG _TAKE_ PHOTO_ ACK + /// 描述:下级平台应答上级平台发送的车辆拍照请求消息,上传图片信息到上级平台 + /// + [JT809Formatter(typeof(JT809_0x1500_0x1502_Formatter))] + public class JT809_0x1500_0x1502:JT809SubBodies + { + public JT809_0x1500_0x1502() + { + VehiclePosition = new JT809VehiclePositionProperties(); + } + /// + /// 拍照应答标识 + /// + public JT809_0x1502_PhotoRspFlag PhotoRspFlag { get; set; } + + /// + /// 车辆定位信息 + /// + public JT809VehiclePositionProperties VehiclePosition { get; set; } + /// + /// 镜头ID + /// + public byte LensID { get; set; } + /// + /// 图片长度 + /// + public uint PhotoLen { get; set; } + /// + /// 图片大小 + /// + public byte SizeType { get; set; } + /// + /// 图像格式 + /// + public byte Type { get; set; } + /// + /// 图片内容 + /// + public byte[] Photo { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1503.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1503.cs new file mode 100644 index 0000000..0ea98ad --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1503.cs @@ -0,0 +1,28 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 下发车辆报文应答消息 + /// 子业务类型标识:UP_CTRL_MSG_TEXT_INFO_ACK + /// 描述:下级平台应答上级平台下发的报文是否成功到达指定车辆 + /// + [JT809Formatter(typeof(JT809_0x1500_0x1503_Formatter))] + public class JT809_0x1500_0x1503:JT809SubBodies + { + /// + /// 消息ID + /// 对应“下发车辆报文请求消息”中的MSG_ID + /// + public uint MsgID { get; set; } + /// + /// 应答结果 + /// + public JT809_0x1503_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1504.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1504.cs new file mode 100644 index 0000000..393297a --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1504.cs @@ -0,0 +1,31 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 上报车辆行驶记录应答消息 + /// 子业务类型标识:UP_CTRL_MSG_TAKE_T'RAVEL_ACK + /// 描述:下级平台应答上级平台下发的上报车辆行驶记录请求消息,将车辆行驶记录数据上传至上级平台 + /// + [JT809Formatter(typeof(JT809_0x1500_0x1504_Formatter))] + public class JT809_0x1500_0x1504:JT809SubBodies + { + /// + /// 命令字 + /// + public JT809CommandType CommandType { get; set; } + /// + /// 车辆行驶记录数据体长度 + /// + public uint TraveldataLength { get; set; } + /// + /// 车辆行驶记录信息 + /// + public string TraveldataInfo { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1505.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1505.cs new file mode 100644 index 0000000..b327eb2 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1500_0x1505.cs @@ -0,0 +1,23 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 车辆应急接入监管平台应答消息 + /// 子业务类型标识: UP_CTRL_MSG_EMERGENCY_MONITORING_ACK + /// 描述:下级平台应答上级平台下发的车辆应急接入监管平台请求消息应答 + /// + [JT809Formatter(typeof(JT809_0x1500_0x1505_Formatter))] + public class JT809_0x1500_0x1505:JT809SubBodies + { + /// + /// 应答结果 + /// + public JT809_0x1505_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x1600_0x1601.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x1600_0x1601.cs new file mode 100644 index 0000000..0d201d5 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x1600_0x1601.cs @@ -0,0 +1,22 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 补报车辆静态信息应答 + /// 子业务类型标识:UP_BASE_MSG_VEHICLE_ADDED_ACK + /// 描述:上级平台应答下级平台发送的补报车辆静态信息清求消息 + /// + [JT809Formatter(typeof(JT809_0x1600_0x1601_Formatter))] + public class JT809_0x1600_0x1601:JT809SubBodies + { + /// + /// 车辆信息 + /// + public string CarInfo { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9202.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9202.cs new file mode 100644 index 0000000..13e4709 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9202.cs @@ -0,0 +1,27 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using JT809.Protocol.Metadata; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 交换车辆定位信息消息 + /// 子业务类型标识:DOWN_EXG_MSG_CAR_LOCATION + /// 描述:上级平台通过该消息不间断地向车辆驶入区域所属的下级平台发送车辆定位信息,直到该车驶离该区域 + /// + [JT809Formatter(typeof(JT809_0x9200_0x9202_Formatter))] + public class JT809_0x9200_0x9202:JT809SubBodies + { + public JT809_0x9200_0x9202() + { + VehiclePosition = new JT809VehiclePositionProperties(); + } + /// + /// 车辆定位信息 + /// + public JT809VehiclePositionProperties VehiclePosition { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9203.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9203.cs new file mode 100644 index 0000000..1c6b775 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9203.cs @@ -0,0 +1,26 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 车辆定位信息交换补发消息 + /// 子业务类型标识:DOWN_EXG_MSG_HISTORY_ARCOSSAREA + /// 描述:本业务在 DOWN_EXG_MSG_APPLY_HISGNSSDATA_ACK 应答成功后,立即开始交换。如果申请失败,则不进行数据转发 + /// + [JT809Formatter(typeof(JT809_0x9200_0x9203_Formatter))] + public class JT809_0x9200_0x9203:JT809SubBodies + { + /// + /// 卫星定位数据个数 1大于GNSS_CNT小于5 + /// + public byte GNSSCount { get; set; } + /// + /// 卫星定位数据集合 + /// + public List GNSS { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9204.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9204.cs new file mode 100644 index 0000000..704d7e1 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9204.cs @@ -0,0 +1,22 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 交换车辆静态信息消息 + /// 子业务类型标识:DOWN_EXG_MSG_CAR_INFO + /// 描述:在首次启动跨域车辆定位信息交换,或者以后交换过程中车辆静态信息有更新时,由上级平台向下级平台下发一次车辆静态信息。下.级平台接收后自行更新该车辆静态信息 + /// + [JT809Formatter(typeof(JT809_0x9200_0x9204_Formatter))] + public class JT809_0x9200_0x9204:JT809SubBodies + { + /// + /// 车辆信息 + /// + public string CarInfo { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9205.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9205.cs new file mode 100644 index 0000000..df704ae --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9205.cs @@ -0,0 +1,23 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 启动车辆定位信息交换请求消息 + /// 子业务类型标识:DOWN_EXG_MSG_RETURN_STARTUP + /// 描述:在有车辆进入非归属地区地理区域、人工指定车辆定位信息交换和应急状态监控车辆时,上级平台向下级平台发出启动车辆定位信息交换清求消息。下级平台收到此命令后需要回复启动车辆定位信息交换应答消息给上级平台,即UP_EXG_MSG-RETURN-STARTUP_ ACK + /// + [JT809Formatter(typeof(JT809_0x9200_0x9205_Formatter))] + public class JT809_0x9200_0x9205:JT809SubBodies + { + /// + /// 错误代码 + /// + public JT809_0x9205_ReasonCode ReasonCode { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9206.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9206.cs new file mode 100644 index 0000000..3332b55 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9206.cs @@ -0,0 +1,23 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 结束车辆定位信息交换请求 + /// 子业务类型标识:DOWN_EXG_MSG_RETURN_END + /// 描述:在进入非归属地区地理区域的车辆离开该地理区域、人上取消指定车辆定位信息交换和应急状态结束时,上级平台向下级平台发出结束车辆定位信息交换请求消息。下级平台收到该命令后应回复结束车辆定位信息交换应答消息,即 UP_EXG_MSG_RE_TURN_END_ACK + /// + [JT809Formatter(typeof(JT809_0x9200_0x9206_Formatter))] + public class JT809_0x9200_0x9206:JT809SubBodies + { + /// + /// 错误代码 + /// + public JT809_0x9206_ReasonCode ReasonCode { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9207.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9207.cs new file mode 100644 index 0000000..352b79f --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9207.cs @@ -0,0 +1,23 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 申请交换指定车辆定位信息应答 + /// 子业务类型标识:DOWN_EXG_MSG_APPLY_FOR_MONITOR_STARTUP_ACK + /// 描述:应答下级平台申请交换指定车辆定位信息,请求消息."即 UP_EXG_MSG_APPLY_FOR_MONITOR_STARTUP + /// + [JT809Formatter(typeof(JT809_0x9200_0x9207_Formatter))] + public class JT809_0x9200_0x9207:JT809SubBodies + { + /// + /// 返回结果 + /// + public JT809_0x9207_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9208.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9208.cs new file mode 100644 index 0000000..33b5e29 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9208.cs @@ -0,0 +1,22 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 取消交换指定车辆定位信息应答 + /// 子业务类型标识:DOWN_EXG_MSG_APPLY_FOR_MONITOR_END_ACK + /// + [JT809Formatter(typeof(JT809_0x9200_0x9208_Formatter))] + public class JT809_0x9200_0x9208:JT809SubBodies + { + /// + /// 返回结果 + /// + public JT809_0x9208_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9209.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9209.cs new file mode 100644 index 0000000..0ad6dbe --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x9209.cs @@ -0,0 +1,22 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 取消交换指定车辆定位信息应答 + /// 子业务类型标识:DOWN_EXG_MSG_APPLY_FOR_MONITOR_END_ACK + /// + [JT809Formatter(typeof(JT809_0x9200_0x9209_Formatter))] + public class JT809_0x9200_0x9209: JT809SubBodies + { + /// + /// 返回结果 + /// + public JT809_0x9209_Result Result { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x920A.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x920A.cs new file mode 100644 index 0000000..669b9f4 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x920A.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 上报车辆驾驶员身份识别信息请求 + /// 子业务类型标识:DOWN_EXG_MSG_REPORT_DRIVER_INFO + /// + public class JT809_0x9200_0x920A:JT809SubBodies + { + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x920B.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x920B.cs new file mode 100644 index 0000000..fe0695b --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9200_0x920B.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 上报车辆电子运单请求消息 + /// 子业务类型标识:DOWN_EXG_MSG_TAKE_EWAYBILL_REQ + /// + public class JT809_0x9200_0x920B:JT809SubBodies + { + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9300_0x9301.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9300_0x9301.cs new file mode 100644 index 0000000..79e3ea8 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9300_0x9301.cs @@ -0,0 +1,39 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 平台查岗请求 + /// 子业务类型标识:DOWN_PLATFORM-MSG_POST_QUERY_REQ + /// 描述:上级平台不定期向下级平台发送平台查岗信息 + /// + [JT809Formatter(typeof(JT809_0x9300_0x9301_Formatter))] + public class JT809_0x9300_0x9301:JT809SubBodies + { + /// + /// 查岗对象的类型 + /// + public JT809_0x9301_ObjectType ObjectType { get; set; } + /// + /// 查岗对象的ID + /// + public string ObjectID { get; set; } + /// + /// 信息ID + /// + public uint InfoID { get; set; } + /// + /// 数据长度 + /// + public uint InfoLength { get; set; } + /// + /// 应答内容 + /// + public string InfoContent { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9300_0x9302.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9300_0x9302.cs new file mode 100644 index 0000000..f32bb37 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9300_0x9302.cs @@ -0,0 +1,39 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 下发平台间报文请求 + /// 子业务类型标识:DOWN_PLATFORM_MSG_INFO_REQ + /// 描述:上级平台不定期向下级平台下发平台间报文 + /// + [JT809Formatter(typeof(JT809_0x9300_0x9302_Formatter))] + public class JT809_0x9300_0x9302:JT809SubBodies + { + /// + /// 查岗对象的类型 + /// + public JT809_0x9302_ObjectType ObjectType { get; set; } + /// + /// 查岗对象的ID + /// + public string ObjectID { get; set; } + /// + /// 信息ID + /// + public uint InfoID { get; set; } + /// + /// 数据长度 + /// + public uint InfoLength { get; set; } + /// + /// 应答内容 + /// + public string InfoContent { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9401.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9401.cs new file mode 100644 index 0000000..2772ae7 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9401.cs @@ -0,0 +1,55 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 报警督办请求消息 + /// 子业务类型标识:DOWN_WARN_MSG_URGE_TODO_REQ + /// 描述:上级平台向车辆归属下级平台下发本消息,催促其及时处理相关车辆的报警信息 + /// + [JT809Formatter(typeof(JT809_0x9400_0x9401_Formatter))] + public class JT809_0x9400_0x9401:JT809SubBodies + { + /// + /// 报警信息来源 + /// + public JT809WarnSrc WarnSrc { get; set; } + /// + /// 报警类型 + /// + public JT809WarnType WarnType { get; set; } + /// + /// 报警时间UTCDateTime + /// + public DateTime WarnTime { get; set; } + /// + /// 报警督办ID HexString + /// + public string SupervisionID { get; set; } + /// + /// 督办截止时间 + /// + public DateTime SupervisionEndTime { get; set; } + /// + /// 督办级别 + /// + public byte SupervisionLevel { get; set; } + /// + /// 督办人 + /// + public string Supervisor { get; set; } + /// + /// 督办联系电话 + /// + public string SupervisorTel { get; set; } + /// + /// 督办联系电子邮件 + /// + public string SupervisorEmail { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9402.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9402.cs new file mode 100644 index 0000000..91cf26c --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9402.cs @@ -0,0 +1,40 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 报警预警 + /// 子业务类型标识:DOWN_WARN_MSG_INFORM_TIPS + /// 描述:用于上级平台向车辆归属或车辆跨域下级平台下发相关车辆的报警顶警或运行提示信息 + /// 本条消息下级平台无需应答 + /// + [JT809Formatter(typeof(JT809_0x9400_0x9402_Formatter))] + public class JT809_0x9400_0x9402:JT809SubBodies + { + /// + /// 报警信息来源 + /// + public JT809WarnSrc WarnSrc { get; set; } + /// + /// 报警类型 + /// + public JT809WarnType WarnType { get; set; } + /// + /// 报警时间 UTCDateTime + /// + public DateTime WarnTime { get; set; } + /// + /// 数据长度 + /// + public uint WarnLength { get; set; } + /// + /// 报警描述 + /// + public string WarnContent { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9403.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9403.cs new file mode 100644 index 0000000..7cb0a1d --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9400_0x9403.cs @@ -0,0 +1,40 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 实时交换报警信息 + /// 子业务类型标识:DOWN_WARN_MSG_EXG_INFORM + /// 描述:用于上级平台向车辆跨域目的地下级平台下发相关车辆的当前报警情况 + /// 本条消息下级平台无需应答 + /// + [JT809Formatter(typeof(JT809_0x9400_0x9403_Formatter))] + public class JT809_0x9400_0x9403:JT809SubBodies + { + /// + /// 报警信息来源 + /// + public JT809WarnSrc WarnSrc { get; set; } + /// + /// 报警类型 + /// + public JT809WarnType WarnType { get; set; } + /// + /// 报警时间 + /// + public DateTime WarnTime { get; set; } + /// + /// 数据长度 + /// + public uint WarnLength { get; set; } + /// + /// 报警描述 + /// + public string WarnContent { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9501.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9501.cs new file mode 100644 index 0000000..bc67cf3 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9501.cs @@ -0,0 +1,22 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 车辆单向监听请求消息 + /// 子业务类型标识:DOWN_CTRL_MSG_MONITOR_VEHICLE_REQ + /// 描述:上级平台向下级平台下发车辆单向监听清求消息 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9501_Formatter))] + public class JT809_0x9500_0x9501:JT809SubBodies + { + /// + /// 回拨电话号码 + /// + public string MonitorTel { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9502.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9502.cs new file mode 100644 index 0000000..0088b5e --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9502.cs @@ -0,0 +1,34 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 车辆拍照请求消息 + /// 子业务类型标识:DOWN_CTRL_MSG_TAKE_PHOTO_REQ + /// 描述:上级平台向下级平台下发对某指定车辆的拍照请求消息 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9502_Formatter))] + public class JT809_0x9500_0x9502:JT809SubBodies + { + /// + /// 镜头ID + /// + public byte LensID { get; set; } + /// + /// 图片大小 + /// Ox01:320x240: + /// Ox02:640x480: + /// Ox03;:800x600: + /// Ox04:1024x768: + /// Ox05:176x 144[QCIF]; + /// 0x06:704x288[CIF]; + /// 0x07:704x288[HALF D]; + /// Ox08:704576[DI] + /// + public byte SizeType { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9503.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9503.cs new file mode 100644 index 0000000..097bb6d --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9503.cs @@ -0,0 +1,34 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 下发车辆报文请求 + /// 子业务类型标识:DOWN_CTRL_MSG_TEXT_INFO + /// 描述:用于上级平台向下级平台下发报文到某指定车辆 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9503_Formatter))] + public class JT809_0x9500_0x9503:JT809SubBodies + { + /// + /// 消息ID序号 + /// + public uint MsgSequence { get; set; } + /// + /// 报文优先级 + /// + public byte MsgPriority { get; set; } + /// + /// 报文信息长度 + /// + public uint MsgLength { get; set; } + /// + /// 报文信息内容 + /// + public string MsgContent { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9504.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9504.cs new file mode 100644 index 0000000..d497a6a --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9504.cs @@ -0,0 +1,35 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Enums; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 上报车辆行驶记录请求消息 + /// 子业务类型标识:DOVJN_CTRL_MSG_TAKE_TRAVEL_REQ + /// 描述:上级平台向下级平台下发上报车辆行驶记录请求消息 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9504_Formatter))] + public class JT809_0x9500_0x9504:JT809SubBodies + { + /// + /// 命令字ID + /// + public JT809CommandType Command { get; set; } + /// + /// 开始时间 + /// + public DateTime StartTime { get; set; } + /// + /// 开始时间 + /// + public DateTime EndTime { get; set; } + /// + /// 最大数据数 + /// + public ushort Max { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9505.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9505.cs new file mode 100644 index 0000000..972e799 --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9500_0x9505.cs @@ -0,0 +1,50 @@ +using JT809.Protocol.Attributes; +using JT809.Protocol.Formatters.SubMessageBodyFormatters; +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 车辆应急接入监管平台请求消息 + /// 子业务类型标识:UP_CTRL_MSG_EMERGENCY_MONITORING_REQ + /// 描述:发生应急情况时,政府监管平台需要及时监控该车辆时,就向该车辆归属的下级平台发送该命令 + /// + [JT809Formatter(typeof(JT809_0x9500_0x9505_Formatter))] + public class JT809_0x9500_0x9505:JT809SubBodies + { + /// + /// 监管平台下发的鉴权码 + /// + public string AuthenticationCode { get; set; } + /// + /// 拨号点名称 + /// + public string AccessPointName { get; set; } + /// + /// 拨号用户名 + /// + public string UserName { get; set; } + /// + /// 拨号密码 + /// + public string Password { get; set; } + /// + /// 地址 + /// + public string ServerIP { get; set; } + /// + /// 服务器TCP端口 + /// + public ushort TcpPort { get; set; } + /// + /// 服务器UDP端口 + /// + public ushort UdpPort { get; set; } + /// + /// 结束时间 + /// + public DateTime EndTime { get; set; } + } +} diff --git a/src/JT809.Protocol/SubMessageBody/JT809_0x9600_0x9601.cs b/src/JT809.Protocol/SubMessageBody/JT809_0x9600_0x9601.cs new file mode 100644 index 0000000..cee119d --- /dev/null +++ b/src/JT809.Protocol/SubMessageBody/JT809_0x9600_0x9601.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT809.Protocol.SubMessageBody +{ + /// + /// 补报车辆静态信息请求消息 + /// 子业务类型标识:DOWN_BASE_MSG_VEHICLE_ADDED + /// 描述:上级平台在接收到车辆定位信息后,发现该车辆静态信息在上级平台不存在,上级平台向下级平台下发补报该车辆静态信息的请求消息 + /// + public class JT809_0x9600_0x9601:JT809SubBodies + { + } +}