From 13017d9d8b8448c48e168b6553f485f7ec021aef Mon Sep 17 00:00:00 2001 From: "SmallChi(Koike)" <564952747@qq.com> Date: Fri, 28 May 2021 18:36:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A02019=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=96=B0=E5=A2=9E0x0200=5F0x07=E9=99=84=E5=8A=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E8=A7=A3=E6=9E=90=E5=8F=8A=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=202.=E5=A2=9E=E5=8A=A02019=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=96=B0=E5=A2=9E0x0702=E5=AF=B9=E5=BA=94=E7=9A=84=E4=BA=BA?= =?UTF-8?q?=E8=84=B8=E5=8C=B9=E9=85=8D=E5=BA=A6=E3=80=81UID=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=85=BC=E5=AE=B9=E5=8F=8A=E5=AF=B9=E5=BA=94=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=203.=E4=BF=AE=E5=A4=8D=E4=BD=8D=E7=BD=AE=E9=99=84?= =?UTF-8?q?=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=B7=A5=E5=8E=82=E5=AF=B92019?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=9A=84=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JT808LocationAttachImpl0x06.cs | 22 +- .../MessageBody/JT808_0x0200Test.cs | 122 +++++++- .../MessageBody/JT808_0x0702Test.cs | 49 ++- .../Internal/JT808_0x0200_Factory.cs | 3 + src/JT808.Protocol/JT808.Protocol.xml | 117 +++++++ src/JT808.Protocol/JT808Constants.cs | 4 + .../MessageBody/JT808_0x0200_0x07.cs | 296 ++++++++++++++++++ .../MessageBody/JT808_0x0702.cs | 40 ++- 8 files changed, 629 insertions(+), 24 deletions(-) create mode 100644 src/JT808.Protocol/MessageBody/JT808_0x0200_0x07.cs diff --git a/src/JT808.Protocol.Test/MessageBody/JT808LocationAttachExtensions/JT808LocationAttachImpl0x06.cs b/src/JT808.Protocol.Test/MessageBody/JT808LocationAttachExtensions/JT808LocationAttachImpl0x06.cs index 35698bd..a12ea91 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808LocationAttachExtensions/JT808LocationAttachImpl0x06.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808LocationAttachExtensions/JT808LocationAttachImpl0x06.cs @@ -10,25 +10,25 @@ namespace JT808.Protocol.Test.JT808LocationAttach /// UserName-BCD(10) /// Gerder-byte-1 /// - public class JT808LocationAttachImpl0x06: JT808_0x0200_CustomBodyBase, IJT808MessagePackFormatter + public class JT808LocationAttachImpl0x61: JT808_0x0200_CustomBodyBase, IJT808MessagePackFormatter { - public override byte AttachInfoId { get; set; } = 0x06; + public override byte AttachInfoId { get; set; } = 0x61; public override byte AttachInfoLength { get; set; } = 13; public int Age { get; set; } public byte Gender { get; set; } public string UserName { get; set; } - public JT808LocationAttachImpl0x06 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + public JT808LocationAttachImpl0x61 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808LocationAttachImpl0x06 jT808LocationAttachImpl0x06 = new JT808LocationAttachImpl0x06(); - jT808LocationAttachImpl0x06.AttachInfoId = reader.ReadByte(); - jT808LocationAttachImpl0x06.AttachInfoLength = reader.ReadByte(); - jT808LocationAttachImpl0x06.Age = reader.ReadInt32(); - jT808LocationAttachImpl0x06.Gender = reader.ReadByte(); - jT808LocationAttachImpl0x06.UserName = reader.ReadRemainStringContent(); - return jT808LocationAttachImpl0x06; + JT808LocationAttachImpl0x61 jT808LocationAttachImpl0x61 = new JT808LocationAttachImpl0x61(); + jT808LocationAttachImpl0x61.AttachInfoId = reader.ReadByte(); + jT808LocationAttachImpl0x61.AttachInfoLength = reader.ReadByte(); + jT808LocationAttachImpl0x61.Age = reader.ReadInt32(); + jT808LocationAttachImpl0x61.Gender = reader.ReadByte(); + jT808LocationAttachImpl0x61.UserName = reader.ReadRemainStringContent(); + return jT808LocationAttachImpl0x61; } - public void Serialize(ref JT808MessagePackWriter writer, JT808LocationAttachImpl0x06 value, IJT808Config config) + public void Serialize(ref JT808MessagePackWriter writer, JT808LocationAttachImpl0x61 value, IJT808Config config) { writer.WriteByte(value.AttachInfoId); writer.WriteByte(value.AttachInfoLength); diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs index 3e2f102..101867a 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0200Test.cs @@ -25,7 +25,7 @@ namespace JT808.Protocol.Test.MessageBody IJT808Config jT808Config = new DefaultGlobalConfig(); IJT808Config jT808Config1 = new DefaultGlobalConfig(); jT808Config1.SkipCRCCode = true; - jT808Config.JT808_0X0200_Custom_Factory.SetMap(); + jT808Config.JT808_0X0200_Custom_Factory.SetMap(); JT808Serializer = new JT808Serializer(jT808Config); JT808Serializer1 = new JT808Serializer(jT808Config1); } @@ -192,21 +192,21 @@ namespace JT808.Protocol.Test.MessageBody { Oil = 55 }); - jT808UploadLocationRequest.JT808CustomLocationAttachData.Add(0x06, new JT808LocationAttachImpl0x06 + jT808UploadLocationRequest.JT808CustomLocationAttachData.Add(0x61, new JT808LocationAttachImpl0x61 { Age = 18, Gender = 1, UserName = "smallchi" }); var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString(); - Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037060D0000001201736D616C6C636869", hex); + Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037610D0000001201736D616C6C636869", hex); } [Fact] public void Test4() { // 1.添加自定义附加信息扩展 AddJT808LocationAttachMethod - byte[] bodys = "00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 07 15 10 10 10 01 04 00 00 00 64 02 02 00 37 06 0D 00 00 00 12 01 73 6D 61 6C 6C 63 68 69".ToHexBytes(); + byte[] bodys = "000000010000000200BA7F0E07E4F11C0028003C000018071510101001040000006402020037610D0000001201736D616C6C636869".ToHexBytes(); JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize(bodys); Assert.Equal((uint)1, jT808UploadLocationRequest.AlarmFlag); Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime); @@ -216,10 +216,10 @@ namespace JT808.Protocol.Test.MessageBody Assert.Equal((uint)2, jT808UploadLocationRequest.StatusFlag); Assert.Equal(100, ((JT808_0x0200_0x01)jT808UploadLocationRequest.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x01]).Mileage); Assert.Equal(55, ((JT808_0x0200_0x02)jT808UploadLocationRequest.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x02]).Oil); - var jT808LocationAttachImpl0x06 = (JT808LocationAttachImpl0x06)jT808UploadLocationRequest.JT808CustomLocationAttachData[0x06]; - Assert.Equal(18, jT808LocationAttachImpl0x06.Age); - Assert.Equal(1, jT808LocationAttachImpl0x06.Gender); - Assert.Equal("smallchi", jT808LocationAttachImpl0x06.UserName); + var jT808LocationAttachImpl0x61 = (JT808LocationAttachImpl0x61)jT808UploadLocationRequest.JT808CustomLocationAttachData[0x61]; + Assert.Equal(18, jT808LocationAttachImpl0x61.Age); + Assert.Equal(1, jT808LocationAttachImpl0x61.Gender); + Assert.Equal("smallchi", jT808LocationAttachImpl0x61.UserName); } [Fact] @@ -518,6 +518,112 @@ namespace JT808.Protocol.Test.MessageBody //16 //7E } + + [Fact] + public void Test_JT808_0x0200_0x07_1() + { + JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200(); + jT808UploadLocationRequest.AlarmFlag = 1; + jT808UploadLocationRequest.Altitude = 40; + jT808UploadLocationRequest.GPSTime = DateTime.Parse("2021-05-28 18:10:10"); + jT808UploadLocationRequest.Lat = 12222222; + jT808UploadLocationRequest.Lng = 132444444; + jT808UploadLocationRequest.Speed = 60; + jT808UploadLocationRequest.Direction = 0; + jT808UploadLocationRequest.StatusFlag = 2; + jT808UploadLocationRequest.JT808LocationAttachData = new Dictionary(); + jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808Constants.JT808_0x0200_0x07, new JT808_0x0200_0x07 + { + BeiDou=new List() + { + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=1, + Elevation=3, + AzimuthAngle=2 + }, + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=2, + Elevation=4, + AzimuthAngle=5 + }, + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=3, + Elevation=5, + AzimuthAngle=6 + }, + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=4, + Elevation=5, + AzimuthAngle=6 + } + }, + GPS=new List() + { + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=2, + Elevation=4, + AzimuthAngle=5 + }, + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=3, + Elevation=5, + AzimuthAngle=6 + }, + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=4, + Elevation=5, + AzimuthAngle=6 + } + }, + GLONASS = new List + { + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=3, + Elevation=5, + AzimuthAngle=6 + }, + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=4, + Elevation=5, + AzimuthAngle=6 + } + }, + Galileo =new List + { + new JT808_0x0200_0x07.SatelliteStatusInformation() + { + No=4, + Elevation=5, + AzimuthAngle=6 + } + } + }); + var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString(); + Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C0000210528181010072C0401030002020400050305000604050006030204000503050006040500060203050006040500060104050006", hex); + } + + [Fact] + public void Test_JT808_0x0200_0x07_2() + { + byte[] bytes = "000000010000000200BA7F0E07E4F11C0028003C0000210528181010072C0401030002020400050305000604050006030204000503050006040500060203050006040500060104050006".ToHexBytes(); + var jT808_0X0200 = JT808Serializer.Deserialize(bytes); + var jT808_0x0200_0x07=(JT808_0x0200_0x07)jT808_0X0200.JT808LocationAttachData[JT808Constants.JT808_0x0200_0x07]; + Assert.Equal((byte)(4 + (4 * 4 + 4 * 3 + 4 * 2 + 4)), jT808_0x0200_0x07.AttachInfoLength); + Assert.Equal(4, jT808_0x0200_0x07.BeiDou.Count); + Assert.Equal(3, jT808_0x0200_0x07.GPS.Count); + Assert.Equal(2, jT808_0x0200_0x07.GLONASS.Count); + Assert.Single(jT808_0x0200_0x07.Galileo); + } + [Fact] public void LatLngTest1_1() { diff --git a/src/JT808.Protocol.Test/MessageBody/JT808_0x0702Test.cs b/src/JT808.Protocol.Test/MessageBody/JT808_0x0702Test.cs index 0f12221..b90b14d 100644 --- a/src/JT808.Protocol.Test/MessageBody/JT808_0x0702Test.cs +++ b/src/JT808.Protocol.Test/MessageBody/JT808_0x0702Test.cs @@ -66,9 +66,8 @@ namespace JT808.Protocol.Test.MessageBody LicenseIssuing = "qwertx", CertificateExpiresDate = DateTime.Parse("2018-08-16") }; - var hex = JT808Serializer.Serialize(jT808_0X0702).ToHexString(); - Assert.Equal("0118081609161600056B6F696B6571776531323334353661616100000000000000000671776572747820180816".Replace(" ", ""), hex); + Assert.Equal("0118081609161600056B6F696B6500000000000000007177653132333435366161610671776572747820180816".Replace(" ", ""), hex); } [Fact] @@ -100,7 +99,7 @@ namespace JT808.Protocol.Test.MessageBody DriverIdentityCard="12345678901234567" }; var hex = JT808Serializer.Serialize(jT808_0X0702, JT808Version.JTT2019).ToHexString(); - Assert.Equal("0119120111111100056B6F696B65717765313233343536616161000000000000000006717765727478201912013132333435363738393031323334353637000000", hex); + Assert.Equal("0119120111111100056B6F696B65000000000000000071776531323334353661616106717765727478201912010000003132333435363738393031323334353637", hex); } @@ -125,5 +124,49 @@ namespace JT808.Protocol.Test.MessageBody byte[] bytes = "0119120111111100056B6F696B65717765313233343536616161303030303030303006717765727478201912013132333435363738393031323334353637303030".ToHexBytes(); string json = JT808Serializer.Analyze(bytes, JT808Version.JTT2019); } + + [Fact] + public void Test_2019_4() + { + JT808_0x0702 jT808_0X0702 = new JT808_0x0702 + { + IC_Card_Status = JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班, + IC_Card_PlugDateTime = DateTime.Parse("2021-05-28 18:11:11"), + IC_Card_ReadResult = JT808ICCardReadResult.IC卡读卡成功, + DriverUserName = "koike", + QualificationCode = "qwe123456aaa", + LicenseIssuing = "qwertx", + CertificateExpiresDate = DateTime.Parse("2021-05-28"), + DriverIdentityCard = "12345678901234567", + FaceMatchValue=99, + UID= "12345678901234567" + }; + var hex = JT808Serializer.Serialize(jT808_0X0702, JT808Version.JTT2019).ToHexString(); + Assert.Equal("0121052818111100056B6F696B65000000000000000071776531323334353661616106717765727478202105280000003132333435363738393031323334353637630000003132333435363738393031323334353637", hex); + } + + [Fact] + public void Test_2019_5() + { + byte[] bytes = "0121052818111100056B6F696B65000000000000000071776531323334353661616106717765727478202105280000003132333435363738393031323334353637630000003132333435363738393031323334353637".ToHexBytes(); + JT808_0x0702 jT808_0X0702 = JT808Serializer.Deserialize(bytes, JT808Version.JTT2019); + Assert.Equal(JT808ICCardStatus.从业资格证IC卡插入_驾驶员上班, jT808_0X0702.IC_Card_Status); + Assert.Equal(DateTime.Parse("2021-05-28 18:11:11"), jT808_0X0702.IC_Card_PlugDateTime); + Assert.Equal(JT808ICCardReadResult.IC卡读卡成功, jT808_0X0702.IC_Card_ReadResult); + Assert.Equal("koike", jT808_0X0702.DriverUserName); + Assert.Equal("qwe123456aaa", jT808_0X0702.QualificationCode); + Assert.Equal("qwertx", jT808_0X0702.LicenseIssuing); + Assert.Equal(DateTime.Parse("2021-05-28"), jT808_0X0702.CertificateExpiresDate); + Assert.Equal("12345678901234567", jT808_0X0702.DriverIdentityCard); + Assert.Equal(99, jT808_0X0702.FaceMatchValue.Value); + Assert.Equal("12345678901234567", jT808_0X0702.UID); + } + + [Fact] + public void Test_2019_6() + { + byte[] bytes = "0121052818111100056B6F696B65000000000000000071776531323334353661616106717765727478202105280000003132333435363738393031323334353637630000003132333435363738393031323334353637".ToHexBytes(); + string json = JT808Serializer.Analyze(bytes, JT808Version.JTT2019); + } } } diff --git a/src/JT808.Protocol/Internal/JT808_0x0200_Factory.cs b/src/JT808.Protocol/Internal/JT808_0x0200_Factory.cs index f60d230..e15ae62 100644 --- a/src/JT808.Protocol/Internal/JT808_0x0200_Factory.cs +++ b/src/JT808.Protocol/Internal/JT808_0x0200_Factory.cs @@ -20,6 +20,9 @@ namespace JT808.Protocol.Internal Map.Add(JT808Constants.JT808_0x0200_0x02, new JT808_0x0200_0x02()); Map.Add(JT808Constants.JT808_0x0200_0x03, new JT808_0x0200_0x03()); Map.Add(JT808Constants.JT808_0x0200_0x04, new JT808_0x0200_0x04()); + Map.Add(JT808Constants.JT808_0x0200_0x05, new JT808_0x0200_0x05()); + Map.Add(JT808Constants.JT808_0x0200_0x06, new JT808_0x0200_0x06()); + Map.Add(JT808Constants.JT808_0x0200_0x07, new JT808_0x0200_0x07()); Map.Add(JT808Constants.JT808_0x0200_0x11, new JT808_0x0200_0x11()); Map.Add(JT808Constants.JT808_0x0200_0x12, new JT808_0x0200_0x12()); Map.Add(JT808Constants.JT808_0x0200_0x13, new JT808_0x0200_0x13()); diff --git a/src/JT808.Protocol/JT808.Protocol.xml b/src/JT808.Protocol/JT808.Protocol.xml index 0a398ef..9d70f32 100644 --- a/src/JT808.Protocol/JT808.Protocol.xml +++ b/src/JT808.Protocol/JT808.Protocol.xml @@ -4891,6 +4891,11 @@ JT808_0x0200_0x06 + + + JT808_0x0200_0x07 + + JT808_0x0200_0x11 @@ -9218,6 +9223,104 @@ + + + 卫星状态数据 + 2019版本 + + + + + + + + + + JT808_0x0200_0x07 + + + + + 4 的倍数 + + + + + BeiDou + 最小值是 0,最大值 12,CN 值大于等于 20 的卫星数量 + + + + + GPS + 最小值是 0,最大值 12,CN 值大于等于 20 的卫星数量 + + + + + GLONASS + 最小值是 0,最大值 12,CN 值大于等于 20 的卫星数量 + + + + + Galileo + 最小值是 0,最大值 12,CN 值大于等于 20 的卫星数量 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 卫星状态信息 + + + + + 卫星编号 + 1-200 + + + + + 仰角 + 0-90 + + + + + 方位角 + + + + + + + + + 超速报警附加信息 @@ -10160,6 +10263,20 @@ 2019版本 + + + 人脸匹配度 + 身份证或从业资格证照片与人脸匹配度比例:0~100 + 2019版本 + + + + + 身份证 UID + 长度 20 位,不足补0x00 + 2019版本 + + diff --git a/src/JT808.Protocol/JT808Constants.cs b/src/JT808.Protocol/JT808Constants.cs index 411b782..e41e2cb 100644 --- a/src/JT808.Protocol/JT808Constants.cs +++ b/src/JT808.Protocol/JT808Constants.cs @@ -52,6 +52,10 @@ namespace JT808.Protocol /// public const byte JT808_0x0200_0x06 = 0x06; /// + /// JT808_0x0200_0x07 + /// + public const byte JT808_0x0200_0x07 = 0x07; + /// /// JT808_0x0200_0x11 /// public const byte JT808_0x0200_0x11 = 0x11; diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0200_0x07.cs b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x07.cs new file mode 100644 index 0000000..1446811 --- /dev/null +++ b/src/JT808.Protocol/MessageBody/JT808_0x0200_0x07.cs @@ -0,0 +1,296 @@ + +using JT808.Protocol.Extensions; +using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; +using JT808.Protocol.MessagePack; +using System.Collections.Generic; +using System.Text.Json; + +namespace JT808.Protocol.MessageBody +{ + /// + /// 卫星状态数据 + /// 2019版本 + /// + public class JT808_0x0200_0x07 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze, IJT808_2019_Version + { + /// + /// + /// + public JT808_0x0200_0x07() + { + BeiDou = new List(); + GPS = new List(); + GLONASS = new List(); + Galileo = new List(); + } + /// + /// JT808_0x0200_0x07 + /// + public override byte AttachInfoId { get; set; } = JT808Constants.JT808_0x0200_0x07; + /// + /// 4 的倍数 + /// + public override byte AttachInfoLength { get; set; } + /// + /// BeiDou + /// 最小值是 0,最大值 12,CN 值大于等于 20 的卫星数量 + /// + public List BeiDou { get; set; } + /// + /// GPS + /// 最小值是 0,最大值 12,CN 值大于等于 20 的卫星数量 + /// + public List GPS { get; set; } + /// + /// GLONASS + /// 最小值是 0,最大值 12,CN 值大于等于 20 的卫星数量 + /// + public List GLONASS { get; set; } + /// + /// Galileo + /// 最小值是 0,最大值 12,CN 值大于等于 20 的卫星数量 + /// + public List Galileo { get; set; } + /// + /// + /// + /// + /// + /// + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x07 value = new JT808_0x0200_0x07(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + //BeiDou + byte beidouCount = reader.ReadByte(); + writer.WriteNumber($"[{beidouCount.ReadNumber()}]北斗卫星数量", beidouCount); + writer.WriteStartArray(); + for (int i = 0; i < beidouCount; i++) + { + SatelliteStatusInformation ssi = new SatelliteStatusInformation(); + ssi.No = reader.ReadByte(); + ssi.Elevation = reader.ReadByte(); + ssi.AzimuthAngle = reader.ReadUInt16(); + ssi.Analyze("BeiDou", writer); + } + writer.WriteEndArray(); + //GPS + byte gpsCount = reader.ReadByte(); + writer.WriteNumber($"[{gpsCount.ReadNumber()}]GPS卫星数量", gpsCount); + writer.WriteStartArray(); + for (int i = 0; i < gpsCount; i++) + { + SatelliteStatusInformation ssi = new SatelliteStatusInformation(); + ssi.No = reader.ReadByte(); + ssi.Elevation = reader.ReadByte(); + ssi.AzimuthAngle = reader.ReadUInt16(); + ssi.Analyze("GPS", writer); + } + writer.WriteEndArray(); + //GLONASS + byte glonassCount = reader.ReadByte(); + writer.WriteNumber($"[{glonassCount.ReadNumber()}]GLONASS卫星数量", glonassCount); + writer.WriteStartArray(); + for (int i = 0; i < glonassCount; i++) + { + SatelliteStatusInformation ssi = new SatelliteStatusInformation(); + ssi.No = reader.ReadByte(); + ssi.Elevation = reader.ReadByte(); + ssi.AzimuthAngle = reader.ReadUInt16(); + ssi.Analyze("GLONASS", writer); + } + writer.WriteEndArray(); + //Galileo + byte galileoCount = reader.ReadByte(); + writer.WriteNumber($"[{galileoCount.ReadNumber()}]Galileo卫星数量", galileoCount); + writer.WriteStartArray(); + for (int i = 0; i < galileoCount; i++) + { + SatelliteStatusInformation ssi = new SatelliteStatusInformation(); + ssi.No = reader.ReadByte(); + ssi.Elevation = reader.ReadByte(); + ssi.AzimuthAngle = reader.ReadUInt16(); + ssi.Analyze("Galileo", writer); + } + writer.WriteEndArray(); + } + + /// + /// + /// + /// + /// + /// + public JT808_0x0200_0x07 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) + { + JT808_0x0200_0x07 value = new JT808_0x0200_0x07(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + //BeiDou + byte beidouCount = reader.ReadByte(); + for(int i = 0; i < beidouCount; i++) + { + SatelliteStatusInformation ssi = new SatelliteStatusInformation(); + ssi.No = reader.ReadByte(); + ssi.Elevation = reader.ReadByte(); + ssi.AzimuthAngle = reader.ReadUInt16(); + value.BeiDou.Add(ssi); + } + //GPS + byte gpsCount = reader.ReadByte(); + for (int i = 0; i < gpsCount; i++) + { + SatelliteStatusInformation ssi = new SatelliteStatusInformation(); + ssi.No = reader.ReadByte(); + ssi.Elevation = reader.ReadByte(); + ssi.AzimuthAngle = reader.ReadUInt16(); + value.GPS.Add(ssi); + } + //GLONASS + byte glonassCount = reader.ReadByte(); + for (int i = 0; i < glonassCount; i++) + { + SatelliteStatusInformation ssi = new SatelliteStatusInformation(); + ssi.No = reader.ReadByte(); + ssi.Elevation = reader.ReadByte(); + ssi.AzimuthAngle = reader.ReadUInt16(); + value.GLONASS.Add(ssi); + } + //Galileo + byte galileoCount = reader.ReadByte(); + for (int i = 0; i < galileoCount; i++) + { + SatelliteStatusInformation ssi = new SatelliteStatusInformation(); + ssi.No = reader.ReadByte(); + ssi.Elevation = reader.ReadByte(); + ssi.AzimuthAngle = reader.ReadUInt16(); + value.Galileo.Add(ssi); + } + return value; + } + /// + /// + /// + /// + /// + /// + public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x07 value, IJT808Config config) + { + writer.WriteByte(value.AttachInfoId); + //各个类型的卫星数量为1个字节 + int attachInfoLength = 4; + if (value.BeiDou != null) + { + attachInfoLength +=value.BeiDou.Count * 4; + } + if (value.GPS != null) + { + attachInfoLength += value.GPS.Count * 4; + } + if (value.GLONASS != null) + { + attachInfoLength += value.GLONASS.Count * 4; + } + if (value.Galileo != null) + { + attachInfoLength += value.Galileo.Count * 4; + } + writer.WriteByte((byte)attachInfoLength); + if (value.BeiDou != null) + { + writer.WriteByte((byte)value.BeiDou.Count); + foreach (var item in value.BeiDou) + { + writer.WriteByte(item.No); + writer.WriteByte(item.Elevation); + writer.WriteUInt16(item.AzimuthAngle); + } + } + else + { + writer.WriteByte(0); + } + if (value.GPS != null) + { + writer.WriteByte((byte)value.GPS.Count); + foreach (var item in value.GPS) + { + writer.WriteByte(item.No); + writer.WriteByte(item.Elevation); + writer.WriteUInt16(item.AzimuthAngle); + } + } + else + { + writer.WriteByte(0); + } + if (value.GLONASS != null) + { + writer.WriteByte((byte)value.GLONASS.Count); + foreach (var item in value.GLONASS) + { + writer.WriteByte(item.No); + writer.WriteByte(item.Elevation); + writer.WriteUInt16(item.AzimuthAngle); + } + } + else + { + writer.WriteByte(0); + } + if (value.Galileo != null) + { + writer.WriteByte((byte)value.Galileo.Count); + foreach (var item in value.Galileo) + { + writer.WriteByte(item.No); + writer.WriteByte(item.Elevation); + writer.WriteUInt16(item.AzimuthAngle); + } + } + else + { + writer.WriteByte(0); + } + } + + /// + /// 卫星状态信息 + /// + public class SatelliteStatusInformation + { + /// + /// 卫星编号 + /// 1-200 + /// + public byte No { get; set; } + /// + /// 仰角 + /// 0-90 + /// + public byte Elevation { get; set; } + /// + /// 方位角 + /// + public ushort AzimuthAngle { get; set; } + + /// + /// + /// + /// + /// + public void Analyze(string type,Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WriteNumber($"[{type}-{No}]卫星编号", No); + writer.WriteNumber($"[{type}-{Elevation}]仰角", Elevation); + writer.WriteNumber($"[{type}-{AzimuthAngle}]方位角", AzimuthAngle); + writer.WriteEndObject(); + } + } + } +} diff --git a/src/JT808.Protocol/MessageBody/JT808_0x0702.cs b/src/JT808.Protocol/MessageBody/JT808_0x0702.cs index 1dbec23..a610bc0 100644 --- a/src/JT808.Protocol/MessageBody/JT808_0x0702.cs +++ b/src/JT808.Protocol/MessageBody/JT808_0x0702.cs @@ -74,6 +74,18 @@ namespace JT808.Protocol.MessageBody /// public string DriverIdentityCard { get; set; } /// + /// 人脸匹配度 + /// 身份证或从业资格证照片与人脸匹配度比例:0~100 + /// 2019版本 + /// + public byte? FaceMatchValue { get; set; } + /// + /// 身份证 UID + /// 长度 20 位,不足补0x00 + /// 2019版本 + /// + public string UID { get; set; } + /// /// /// /// @@ -112,6 +124,15 @@ namespace JT808.Protocol.MessageBody var driverIdentityCardBuffer = reader.ReadVirtualArray(20); value.DriverIdentityCard = reader.ReadString(20); writer.WriteString($"[{driverIdentityCardBuffer.ToArray().ToHexString()}]驾驶员身份证号", value.DriverIdentityCard); + //兼容808-2019 补充 + if (reader.ReadCurrentRemainContentLength() > 0) + { + value.FaceMatchValue = reader.ReadByte(); + writer.WriteNumber($"[{value.FaceMatchValue.Value.ReadNumber()}]人脸匹配度", value.FaceMatchValue.Value); + var uidBuffer = reader.ReadVirtualArray(20); + value.UID = reader.ReadString(20); + writer.WriteString($"[{uidBuffer.ToArray().ToHexString()}]身份证UID", value.UID); + } } } } @@ -141,6 +162,12 @@ namespace JT808.Protocol.MessageBody if(reader.Version== JT808Version.JTT2019) { value.DriverIdentityCard = reader.ReadString(20); + //兼容808-2019 补充 + if (reader.ReadCurrentRemainContentLength() > 0) + { + value.FaceMatchValue = reader.ReadByte(); + value.UID = reader.ReadString(20); + } } } } @@ -163,13 +190,22 @@ namespace JT808.Protocol.MessageBody { writer.WriteByte((byte)value.DriverUserName.Length); writer.WriteString(value.DriverUserName); - writer.WriteString(value.QualificationCode.PadRight(20, '\0').ValiString(nameof(value.QualificationCode),20)); + writer.WriteString(value.QualificationCode.PadLeft(20, '\0').ValiString(nameof(value.QualificationCode),20)); writer.WriteByte((byte)value.LicenseIssuing.Length); writer.WriteString(value.LicenseIssuing); writer.WriteDateTime4(value.CertificateExpiresDate); if (writer.Version == JT808Version.JTT2019) { - writer.WriteString(value.DriverIdentityCard.PadRight(20,'\0').ValiString(nameof(value.DriverIdentityCard), 20)); + writer.WriteString(value.DriverIdentityCard.PadLeft(20,'\0').ValiString(nameof(value.DriverIdentityCard), 20)); + //兼容808-2019 补充 + if (value.FaceMatchValue.HasValue) + { + writer.WriteByte(value.FaceMatchValue.Value); + } + if (!string.IsNullOrEmpty(value.UID)) + { + writer.WriteString(value.UID.PadLeft(20, '\0').ValiString(nameof(value.UID), 20)); + } } } }