From 2e916692c4eb2e11e6906af801e6a4f5f526cbc8 Mon Sep 17 00:00:00 2001 From: waterliu99 Date: Tue, 5 May 2020 21:21:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84readme=20=E5=92=8C=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 41 +++- .../JT809_0x1600_0x1602Test.cs | 2 +- src/JT809.Protocol.Test/Simples/Demo5.cs | 228 ++++++++++++++++++ 3 files changed, 265 insertions(+), 6 deletions(-) create mode 100644 src/JT809.Protocol.Test/Simples/Demo5.cs diff --git a/README.md b/README.md index 29c0cbb..ab77205 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,34 @@ public class JT809_2019_Config : JT809GlobalConfigBase } ``` +### 举个栗子5 + +如何在项目中同时使用808的2019版本和809的2019版本 + +``` data4 +IServiceCollection serviceDescriptors = new ServiceCollection(); +serviceDescriptors.AddJT808Configure(new JT808_2019_Config()); +serviceDescriptors.AddJT809Configure(new JT809_2019_Config()); +JT808Serializer JT808_2019_Serializer = ServiceProvider.GetRequiredService().GetSerializer(); +JT809Serializer JT809_2019_Serializer = ServiceProvider.GetRequiredService().GetSerializer(); +public class JT808_2019_Config : GlobalConfigBase +{ + public override string ConfigId { get; protected set; } + public JT808_2019_Config(string configId = "jt808_2019") + { + ConfigId = configId; + } +} +public class JT809_2019_Config : JT809GlobalConfigBase +{ + public override string ConfigId => "JT809_2019"; + public JT809_2019_Config() + { + Version = JT809Version.JTT2019; + } +} +``` + ## NuGet安装 | Package Name | Version | Downloads @@ -325,6 +353,8 @@ Platform=AnyCpu Server=False Toolchain=.NET Core 3.1 |序号|消息ID|完成情况|测试情况|消息体名称| |:------:|:------:|:------:|:------:|:------:| | 1 | 0x9101 | √ | √ |接收定位信息数量通知消息 | +| 1 | 0x9102 | √ | √ |平台链路连接情况与车辆定位消息传输情况上报请求消息 | +| 1 | 0x9103 | √ | √ |下发平台间消息序列号通知消息 | ### 车辆动态信息交换 @@ -343,8 +373,8 @@ Platform=AnyCpu Server=False Toolchain=.NET Core 3.1 | 9 | 0x1209 | √ | √ | 补发车辆定位信息请求 | | 10 | 0x120A | √ | √ | 上报车辆驾驶员身份识别信息应答 | | 11 | 0x120B | √ | √ | 上报车辆电子运单应答 | -| 12 | 0x120C | √ | √ | 主动上报驾驶员身份信息(809补充协议文档) | -| 13 | 0x120D | √ | √ | 主动上报车辆电子运单信息(809补充协议文档) | +| 12 | 0x120C | √ | √ | 主动上报驾驶员身份信息 | +| 13 | 0x120D | √ | √ | 主动上报车辆电子运单信息 | | 14 | 0x120E | √ | √ | 主动上报车辆行驶路线信息(809-2019) | #### 从链路动态信息交换消息 @@ -352,6 +382,7 @@ Platform=AnyCpu Server=False Toolchain=.NET Core 3.1 |序号|消息ID|完成情况|测试情况|消息体名称| |:------:|:------:|:------:|:------:|:------:| | 1 | 0x9200 | √ | √ | 从链路动态信息交换消息 | +| 1 | 0x9201 | √ | √(0x1201) | 车辆注册信息应答消息 | | 2 | 0x9202 | √ | √(0x1202) | 交换车辆定位信息消息(809补充协议文档) | | 3 | 0x9203 | √ | √(0x1203) | 车辆定位信息交换补发消息 | | 4 | 0x9204 | √ | √ | 交换车辆静态信息消息 | @@ -383,7 +414,7 @@ Platform=AnyCpu Server=False Toolchain=.NET Core 3.1 | 1 | 0x9300 | √ | √ | 从链路平台间信息交互消息 | | 2 | 0x9301 | √ | √ | 平台查岗请求(809补充协议文档) | | 3 | 0x9302 | √ | √ | 下发平台间报文请求(809补充协议文档) | -| 4 | 0x9304 | √ | √ | 下发平台间消息补传请求消息(809-2019) | +| 4 | 0x9303 | √ | √ | 下发平台间消息补传请求消息(809-2019) | ### 车辆报警信息交互类 @@ -426,8 +457,8 @@ Platform=AnyCpu Server=False Toolchain=.NET Core 3.1 | 2 | 0x9501 | √ | √ | 车辆单向监听请求 | | 3 | 0x9502 | √ | √ | 车辆拍照请求 | | 4 | 0x9503 | √ | √ | 下发车辆报文请求 | -| 5 | 0x9504 | √ | √ | 上报车辆行驶记录请求(809补充协议文档) | -| 6 | 0x9505 | √ | √ | 车辆应急接入监管平台请求消息(809补充协议文档) | +| 5 | 0x9504 | √ | √ | 上报车辆行驶记录请求 | +| 6 | 0x9505 | √ | √ | 车辆应急接入监管平台请求消息 | ### 车辆静态信息交换类 diff --git a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1602Test.cs b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1602Test.cs index cd8d28a..85dbac4 100644 --- a/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1602Test.cs +++ b/src/JT809.Protocol.Test/JT809SubMessageBody/JT809_0x1600_0x1602Test.cs @@ -21,7 +21,7 @@ namespace JT809.Protocol.Test.JT809SubMessageBody private JT809Serializer JT809Serializer = new JT809Serializer(); private JT809Serializer JT809_2019_Serializer = new JT809Serializer(new DefaultGlobalConfig() { Version = JT809Version.JTT2019 }); private JT808Serializer JT808Serializer_2019; -#warning 结合808协议包,解析808中的路线信息 + public JT809_0x1600_0x1602Test() { IJT808Config jT808Config = new DefaultGlobal808_2019Config(); diff --git a/src/JT809.Protocol.Test/Simples/Demo5.cs b/src/JT809.Protocol.Test/Simples/Demo5.cs new file mode 100644 index 0000000..a9ea6d4 --- /dev/null +++ b/src/JT809.Protocol.Test/Simples/Demo5.cs @@ -0,0 +1,228 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using JT809.Protocol.Test.JT1078; +using JT809.Protocol.Extensions; +using Xunit; +using JT809.Protocol.Enums; +using JT809.Protocol.Interfaces; +using JT808.Protocol.Interfaces; +using JT808.Protocol; +using JT808.Protocol.MessageBody; +using System.Collections.Generic; +using JT809.Protocol.SubMessageBody; +using JT808.Protocol.Metadata; + +namespace JT809.Protocol.Test.Simples +{ + /// + /// 1.此处结合808协议包解析 808中的定位信息 + /// 2.此处结合808协议包解析 808中的路线信息 + /// + public class Demo5 + { + IServiceProvider ServiceProvider; + JT809Serializer JT809_2019_Serializer; + JT809Serializer JT809_Serializer; + JT808Serializer JT808_2019_Serializer; + + public Demo5() + { + IServiceCollection serviceDescriptors = new ServiceCollection(); + serviceDescriptors.AddJT808Configure(new JT808_2019_Config()); + serviceDescriptors.AddJT809Configure(new JT809_2011_Config()) + .AddJT1078Configure(); + serviceDescriptors.AddJT809Configure(new JT809_2019_Config()) + .AddJT1078Configure(); + ServiceProvider = serviceDescriptors.BuildServiceProvider(); + var jT809_2011_Config = ServiceProvider.GetRequiredService(); + var jT809_2019_Config = ServiceProvider.GetRequiredService(); + var jT808_Config = ServiceProvider.GetRequiredService(); + + JT809_2019_Serializer = jT809_2019_Config.GetSerializer(); + JT809_Serializer = jT809_2011_Config.GetSerializer(); + JT808_2019_Serializer = jT808_Config.GetSerializer(); + } + [Fact] + public void Test_2019_1() + { + JT808_0x8606 jT808_0X8606 = new JT808_0x8606 + { + RouteId = 9999, + RouteProperty = 1268, + StartTime = DateTime.Parse("2018-11-20 00:00:12"), + EndTime = DateTime.Parse("2018-11-21 00:00:12"), + InflectionPointItems = new List() + }; + jT808_0X8606.InflectionPointItems.Add(new JT808InflectionPointProperty() + { + InflectionPointId = 1000, + InflectionPointLat = 123456789, + InflectionPointLng = 123456788, + SectionDrivingUnderThreshold = 123, + SectionHighestSpeed = 69, + SectionId = 1287, + SectionLongDrivingThreshold = 50, + SectionOverspeedDuration = 23, + SectionProperty = 89, + SectionWidth = 56 + }); + jT808_0X8606.InflectionPointItems.Add(new JT808InflectionPointProperty() + { + InflectionPointId = 1001, + InflectionPointLat = 123456780, + InflectionPointLng = 123456781, + SectionDrivingUnderThreshold = 124, + SectionHighestSpeed = 42, + SectionId = 12007, + SectionLongDrivingThreshold = 58, + SectionOverspeedDuration = 26, + SectionProperty = 50, + SectionWidth = 75 + }); + var jt808_hex = JT808_2019_Serializer.Serialize(jT808_0X8606); + + JT809_0x1600_0x1602 jT809_0x1600_0x1602 = new JT809_0x1600_0x1602 + { + DRVLine = jt808_hex + }; + var hex = JT809_2019_Serializer.Serialize(jT809_0x1600_0x1602).ToHexString(); + Assert.Equal("0000270F04F40002000003E800000507075BCD15075BCD1438590032007B000003E900002EE7075BCD0C075BCD0D4B32002A1A", hex); + } + + [Fact] + public void Test_2019_2() + { + var bytes = "0000270F04F40002000003E800000507075BCD15075BCD1438590032007B000003E900002EE7075BCD0C075BCD0D4B32002A1A".ToHexBytes(); + JT809_0x1600_0x1602 jT809_0x1600_0x1602 = JT809_2019_Serializer.Deserialize(bytes); + + JT808_0x8606 jT808_0X8606 = JT808_2019_Serializer.Deserialize(bytes); + + Assert.Equal((uint)9999, jT808_0X8606.RouteId); + Assert.Equal((uint)1268, jT808_0X8606.RouteProperty); + //Assert.Equal(DateTime.Parse("2018-11-20 00:00:12"), jT808_0X8606.StartTime); + //Assert.Equal(DateTime.Parse("2018-11-21 00:00:12"), jT808_0X8606.EndTime); + Assert.Null(jT808_0X8606.StartTime); + Assert.Null(jT808_0X8606.EndTime); + + Assert.Equal(2, jT808_0X8606.InflectionPointItems.Count); + + Assert.Equal((uint)1000, jT808_0X8606.InflectionPointItems[0].InflectionPointId); + Assert.Equal((uint)123456789, jT808_0X8606.InflectionPointItems[0].InflectionPointLat); + Assert.Equal((uint)123456788, jT808_0X8606.InflectionPointItems[0].InflectionPointLng); + + Assert.Equal((ushort)123, jT808_0X8606.InflectionPointItems[0].SectionDrivingUnderThreshold); + //Assert.Equal((ushort)69, jT808_0X8606.InflectionPointItems[0].SectionHighestSpeed); + Assert.Null(jT808_0X8606.InflectionPointItems[0].SectionHighestSpeed); + Assert.Equal((uint)1287, jT808_0X8606.InflectionPointItems[0].SectionId); + Assert.Equal((ushort)50, jT808_0X8606.InflectionPointItems[0].SectionLongDrivingThreshold); + //Assert.Equal((byte)23, jT808_0X8606.InflectionPointItems[0].SectionOverspeedDuration); + Assert.Equal(89, jT808_0X8606.InflectionPointItems[0].SectionProperty); + Assert.Equal(56, jT808_0X8606.InflectionPointItems[0].SectionWidth); + + Assert.Equal((uint)1001, jT808_0X8606.InflectionPointItems[1].InflectionPointId); + Assert.Equal((uint)123456780, jT808_0X8606.InflectionPointItems[1].InflectionPointLat); + Assert.Equal((uint)123456781, jT808_0X8606.InflectionPointItems[1].InflectionPointLng); + //Assert.Equal((ushort)124, jT808_0X8606.InflectionPointItems[1].SectionDrivingUnderThreshold); + Assert.Null(jT808_0X8606.InflectionPointItems[1].SectionDrivingUnderThreshold); + Assert.Equal((ushort)42, jT808_0X8606.InflectionPointItems[1].SectionHighestSpeed); + Assert.Equal((uint)12007, jT808_0X8606.InflectionPointItems[1].SectionId); + //Assert.Equal((ushort)58, jT808_0X8606.InflectionPointItems[1].SectionLongDrivingThreshold); + Assert.Null(jT808_0X8606.InflectionPointItems[1].SectionLongDrivingThreshold); + + Assert.Equal((byte)26, jT808_0X8606.InflectionPointItems[1].SectionOverspeedDuration); + Assert.Equal(50, jT808_0X8606.InflectionPointItems[1].SectionProperty); + Assert.Equal(75, jT808_0X8606.InflectionPointItems[1].SectionWidth); + } + + + [Fact] + public void Test_2019_3() + { + JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200 + { + AlarmFlag = 1, + Altitude = 40, + GPSTime = DateTime.Parse("2018-07-15 10:10:10"), + Lat = 12222222, + Lng = 132444444, + Speed = 60, + Direction = 0, + StatusFlag = 2, + JT808LocationAttachData = new Dictionary() + }; + jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x01, new JT808_0x0200_0x01 + { + Mileage = 100 + }); + jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x02, new JT808_0x0200_0x02 + { + Oil = 55 + }); + var jt808_0x0200Hex = JT808_2019_Serializer.Serialize(jT808UploadLocationRequest, JT808.Protocol.Enums.JT808Version.JTT2019); + + JT809_0x1200_0x1202 jT809_0X1200_0X1202 = new JT809_0x1200_0x1202(); + jT809_0X1200_0X1202.GNSSData = new Metadata.JT809VehiclePositionProperties_2019(); + jT809_0X1200_0X1202.GNSSData.Encrypt = JT809_VehiclePositionEncrypt.已加密; + jT809_0X1200_0X1202.GNSSData.GnssData = jt808_0x0200Hex; + jT809_0X1200_0X1202.GNSSData.PlatformId1 = "11111111111"; + jT809_0X1200_0X1202.GNSSData.Alarm1 = 1; + jT809_0X1200_0X1202.GNSSData.PlatformId2 = "22222222222"; + jT809_0X1200_0X1202.GNSSData.Alarm2 = 2; + jT809_0X1200_0X1202.GNSSData.PlatformId3 = "33333333333"; + jT809_0X1200_0X1202.GNSSData.Alarm3 = 3; + var hex = JT809_2019_Serializer.Serialize(jT809_0X1200_0X1202).ToHexString(); + Assert.Equal("0100000026000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037313131313131313131313100000001323232323232323232323200000002333333333333333333333300000003", hex); + + } + + [Fact] + public void Test_2019_4() + { + var bytes = "0100000026000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037313131313131313131313100000001323232323232323232323200000002333333333333333333333300000003".ToHexBytes(); + JT809_0x1200_0x1202 jT809_0X1200_0X1202 = JT809_2019_Serializer.Deserialize(bytes); + Assert.Equal(JT809_VehiclePositionEncrypt.已加密, jT809_0X1200_0X1202.GNSSData.Encrypt); + Assert.Equal("11111111111", jT809_0X1200_0X1202.GNSSData.PlatformId1); + Assert.Equal(1u, jT809_0X1200_0X1202.GNSSData.Alarm1); + Assert.Equal("22222222222", jT809_0X1200_0X1202.GNSSData.PlatformId2); + Assert.Equal(2u, jT809_0X1200_0X1202.GNSSData.Alarm2); + Assert.Equal("33333333333", jT809_0X1200_0X1202.GNSSData.PlatformId3); + Assert.Equal(3u, jT809_0X1200_0X1202.GNSSData.Alarm3); + + var jt808_0x0200Hex = jT809_0X1200_0X1202.GNSSData.GnssData; + var jt808_0x0200 = JT808_2019_Serializer.Deserialize(jt808_0x0200Hex, JT808.Protocol.Enums.JT808Version.JTT2019); + Assert.Equal((uint)1, jt808_0x0200.AlarmFlag); + Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jt808_0x0200.GPSTime); + Assert.Equal(12222222, jt808_0x0200.Lat); + Assert.Equal(132444444, jt808_0x0200.Lng); + Assert.Equal(60, jt808_0x0200.Speed); + Assert.Equal((uint)2, jt808_0x0200.StatusFlag); + Assert.Equal(100, ((JT808_0x0200_0x01)jt808_0x0200.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x01]).Mileage); + Assert.Equal(55, ((JT808_0x0200_0x02)jt808_0x0200.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x02]).Oil); + + } + + public class JT809_2011_Config : JT809GlobalConfigBase + { + public override string ConfigId => "JT809_2011"; + } + + public class JT809_2019_Config : JT809GlobalConfigBase + { + public override string ConfigId => "JT809_2019"; + + public JT809_2019_Config() + { + Version = JT809Version.JTT2019; + } + } + + public class JT808_2019_Config : GlobalConfigBase + { + public override string ConfigId { get; protected set; } + public JT808_2019_Config(string configId = "jt808_2019") + { + ConfigId = configId; + } + } + } +}