From 48a82f264a598ded2145b26ed1c9c05d6baf7389 Mon Sep 17 00:00:00 2001 From: "SmallChi(Koike)" <564952747@qq.com> Date: Thu, 20 Jan 2022 21:11:48 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E5=B9=B3=E5=8F=B0=E4=B8=8B?= =?UTF-8?q?=E5=8F=91=E5=88=86=E5=8C=85=E6=95=B0=E6=8D=AE=E5=88=B0=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=EF=BC=88demo16=EF=BC=89=202.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 23 +++-- src/JT808.Protocol.Test/Simples/Demo16.cs | 101 ++++++++++++++++++++++ src/JT808.Protocol/JT808.Protocol.csproj | 4 +- 3 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 src/JT808.Protocol.Test/Simples/Demo16.cs diff --git a/README.md b/README.md index 49cea9b..3d942fa 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ > MsgId 0x0200:位置信息汇报 -``` package +``` csharp JT808Package jT808Package = new JT808Package(); @@ -98,7 +98,7 @@ var hex = data.ToHexString(); #### 2.手动解包: -``` unpackage +``` text 1.原包: 7E 02 00 00 26 12 34 56 78 90 12 00 (7D 02) 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 (7D 01) 13 7E @@ -134,7 +134,7 @@ var hex = data.ToHexString(); #### 3.程序解包: -``` unpackage2 +``` csharp //1.转成byte数组 byte[] bytes = "7E 02 00 00 26 12 34 56 78 90 12 00 7D 02 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E".ToHexBytes(); @@ -169,7 +169,7 @@ Assert.Equal(125, ((JT808_0x0200_0x02)jT808_0x0200.BasicLocationAttachData[JT808 ### 举个栗子2 -``` create package +``` csharp // 使用消息Id的扩展方法创建JT808Package包 JT808Package jT808Package = Enums.JT808MsgId.位置信息汇报.Create("123456789012", new JT808_0x0200 { @@ -197,7 +197,7 @@ var hex = data.ToHexString(); ### 举个栗子3 -``` config +``` csharp // 初始化配置 IJT808Config DT1JT808Config = new DT1Config(); IJT808Config DT2JT808Config = new DT2Config(); @@ -348,6 +348,15 @@ JT808Serializer DT2JT808Serializer = new JT808Serializer(DT2JT808Config); [可以参考Simples的Demo15](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo15.cs) +### 举个栗子16 + +场景: +平台下发分包数据到设备 + +可以参考【栗子5】中,设备上来的分包数据结构,然后举一反三的去实现。 + +[可以参考Simples的Demo16](https://github.com/SmallChi/JT808/blob/master/src/JT808.Protocol.Test/Simples/Demo16.cs) + ## NuGet安装 | Package Name| Version| Preview Version |Downloads|Remark| @@ -536,7 +545,7 @@ serviceDescriptors1.AddJT808Configure() ## 使用方法 -```dotnet +```csharp IServiceCollection serviceDescriptors1 = new ServiceCollection(); serviceDescriptors1.AddJT808Configure() .AddSuBiaoConfigure(); @@ -572,7 +581,7 @@ serviceDescriptors1.AddJT808Configure() ## 使用方法 -```dotnet +```csharp IServiceCollection serviceDescriptors1 = new ServiceCollection(); serviceDescriptors1.AddJT808Configure() .AddYueBiaoConfigure(); diff --git a/src/JT808.Protocol.Test/Simples/Demo16.cs b/src/JT808.Protocol.Test/Simples/Demo16.cs new file mode 100644 index 0000000..9c3883a --- /dev/null +++ b/src/JT808.Protocol.Test/Simples/Demo16.cs @@ -0,0 +1,101 @@ +using JT808.Protocol.Enums; +using JT808.Protocol.Interfaces; +using JT808.Protocol.Internal; +using JT808.Protocol.Extensions; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; +using JT808.Protocol.MessageBody; +using JT808.Protocol.Formatters; +using JT808.Protocol.MessagePack; +using System.Text.Json; +using JT808.Protocol.MessageBody.CarDVR; +using System.Linq; +using JT808.Protocol.Test.JT808LocationAttach; +using static JT808.Protocol.MessageBody.JT808_0x8105; +using System.Buffers.Binary; +using Newtonsoft.Json; + +namespace JT808.Protocol.Test.Simples +{ + public class Demo16 + { + JT808Serializer JT808Serializer; + + IJT808Config JT808Config; + + public Demo16() + { + IServiceCollection serviceDescriptors = new ServiceCollection(); + serviceDescriptors.AddJT808Configure(); + //通常在startup中使用app的Use进行扩展 + IServiceProvider serviceProvider = serviceDescriptors.BuildServiceProvider(); + JT808Config = serviceProvider.GetRequiredService(); + JT808Serializer = JT808Config.GetSerializer(); + } + + [Fact] + public void Test1() + { + var upgradePackage = new byte[1024 * 10]; + var splitPackage = JT808Config.SplitPackageStrategy.Processor(upgradePackage).ToList(); + ushort packgeCount = (ushort)splitPackage.Count(); + List hexs = new List(); + for (ushort i = 1; i <= packgeCount; i++) + { + if (i == 1) + { + var bodies = new JT808_0x8108 + { + UpgradeType = JT808UpgradeType.终端, + VersionNum = "v1.2.1", + MakerId = "1234", + UpgradePackage = splitPackage[i - 1].Data + }; + var firstBodies = JT808Serializer.Serialize(bodies); + JT808Package package = new JT808Package + { + Header = new JT808Header + { + MsgId = Enums.JT808MsgId.下发终端升级包.ToUInt16Value(), + ManualMsgNum = 10, + TerminalPhoneNo = "123456789", + MessageBodyProperty = new JT808HeaderMessageBodyProperty() + { + IsPackage = true, + }, + PackgeCount = packgeCount, + PackageIndex = i + }, + SubDataBodies = firstBodies + }; + var hex = JT808Serializer.Serialize(package).ToHexString(); + hexs.Add(hex); + } + else + { + JT808Package package = new JT808Package + { + Header = new JT808Header + { + MsgId = Enums.JT808MsgId.下发终端升级包.ToUInt16Value(), + ManualMsgNum = 10, + TerminalPhoneNo = "123456789", + MessageBodyProperty = new JT808HeaderMessageBodyProperty() + { + IsPackage = true, + }, + PackgeCount = packgeCount, + PackageIndex = i + }, + SubDataBodies = splitPackage[i - 1].Data + }; + var hex = JT808Serializer.Serialize(package).ToHexString(); + hexs.Add(hex); + } + } + } + } +} diff --git a/src/JT808.Protocol/JT808.Protocol.csproj b/src/JT808.Protocol/JT808.Protocol.csproj index 75d0747..685cb02 100644 --- a/src/JT808.Protocol/JT808.Protocol.csproj +++ b/src/JT808.Protocol/JT808.Protocol.csproj @@ -56,14 +56,14 @@ - + - +