From 66fa51d6483c8cbab5bd87e613c1fb51a8df5174 Mon Sep 17 00:00:00 2001 From: "smallchi(Koike)" <564952747@qq.com> Date: Sat, 1 Feb 2020 13:29:43 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=8D=87=E7=BA=A7808=E5=BA=93=202.=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0Actions=E9=85=8D=E7=BD=AE=E5=8E=BB=E6=8E=89travis=203.?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=9A=E4=BD=8D=E9=99=84=E5=8A=A0=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=88=86=E6=9E=90=E5=99=A8=204.=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 --- .github/workflows/dotnetcore.yml | 31 +++++ .travis.yml | 19 --- README.md | 2 +- src/JT1078.sln | 1 - .../JT808LocationAttach.cs | 25 ++-- .../JT808_0x0200Test.cs | 114 ++++++++++++++++++ .../Enums/VideoRelateAlarmType.cs | 18 +++ .../JT808.Protocol.Extensions.JT1078.csproj | 4 +- .../JT808.Protocol.Extensions.JT1078.xml | 10 +- .../MessageBody/JT808_0x0200_0x14.cs | 38 +++++- .../MessageBody/JT808_0x0200_0x15.cs | 42 ++++++- .../MessageBody/JT808_0x0200_0x16.cs | 42 ++++++- .../MessageBody/JT808_0x0200_0x17.cs | 56 ++++++++- .../MessageBody/JT808_0x0200_0x18.cs | 72 +++++++++-- 14 files changed, 407 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/dotnetcore.yml delete mode 100644 .travis.yml create mode 100644 src/JT808.Protocol.Extensions.JT1078.Test/JT808_0x0200Test.cs create mode 100644 src/JT808.Protocol.Extensions.JT1078/Enums/VideoRelateAlarmType.cs diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml new file mode 100644 index 0000000..f6b5759 --- /dev/null +++ b/.github/workflows/dotnetcore.yml @@ -0,0 +1,31 @@ +name: .NET Core + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@master + - name: Setup .NET Core + uses: actions/setup-dotnet@master + with: + dotnet-version: 3.1.101 + - name: dotnet info + run: dotnet --info + - name: dotnet restore + run: dotnet restore ./src/JT1078.sln + - name: dotnet JT1078.Protocol.Test build + run: dotnet build ./src/JT1078.Protocol.Test/JT1078.Protocol.Test.csproj + - name: dotnet JT1078.Protocol.Test test + run: dotnet test ./src/JT1078.Protocol.Test/JT1078.Protocol.Test.csproj + - name: dotnet JT808.Protocol.Extensions.JT1078.Test build + run: dotnet build ./src/JT808.Protocol.Extensions.JT1078.Test/JT808.Protocol.Extensions.JT1078.Test.csproj + - name: dotnet JT808.Protocol.Extensions.JT1078.Test test + run: dotnet test ./src/JT808.Protocol.Extensions.JT1078.Test/JT808.Protocol.Extensions.JT1078.Test.csproj + - name: dotnet JT809.Protocol.Extensions.JT1078.Test build + run: dotnet build ./src/JT809.Protocol.Extensions.JT1078.Test/JT809.Protocol.Extensions.JT1078.Test.csproj + - name: dotnet JT809.Protocol.Extensions.JT1078.Test test + run: dotnet test ./src/JT809.Protocol.Extensions.JT1078.Test/JT809.Protocol.Extensions.JT1078.Test.csproj diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3ab9d34..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: csharp -solution: JT1078.sln -dotnet: 3.1.100 -os: linux -mono: none -dist: trusty2 -script: - - dotnet restore src/JT1078.sln - - dotnet build src/JT1078.Protocol.Test/JT1078.Protocol.Test.csproj - - dotnet test src/JT1078.Protocol.Test/JT1078.Protocol.Test.csproj - - dotnet build src/JT808.Protocol.Extensions.JT1078.Test/JT808.Protocol.Extensions.JT1078.Test.csproj - - dotnet test src/JT808.Protocol.Extensions.JT1078.Test/JT808.Protocol.Extensions.JT1078.Test.csproj - - dotnet build src/JT809.Protocol.Extensions.JT1078.Test/JT809.Protocol.Extensions.JT1078.Test.csproj - - dotnet test src/JT809.Protocol.Extensions.JT1078.Test/JT809.Protocol.Extensions.JT1078.Test.csproj -after_success: - - echo successful build! -branches: - only: - - master diff --git a/README.md b/README.md index 211a0de..5406365 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 3.1 [将1078的数据(h264)编码成FLV](#1078flv) 3.2 [将1078的数据(h264)编码成HLS(尚未实现)](#1078HLS) -[![MIT Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/SmallChi/JT1078/blob/master/LICENSE)[![Build Status](https://travis-ci.org/SmallChi/JT1078.svg?branch=master)](https://travis-ci.org/SmallChi/JT1078) +[![MIT Licence](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/SmallChi/JT1078/blob/master/LICENSE)[![Github Build status](https://github.com/SmallChi/JT1078/workflows/.NET%20Core/badge.svg)]() ## NuGet安装 diff --git a/src/JT1078.sln b/src/JT1078.sln index b49264d..620b8c8 100644 --- a/src/JT1078.sln +++ b/src/JT1078.sln @@ -21,7 +21,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT1078.Protocol.Benchmark", EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E378A80C-5708-4D0C-BA1A-73EEF08957F6}" ProjectSection(SolutionItems) = preProject - ..\.travis.yml = ..\.travis.yml ..\README.md = ..\README.md EndProjectSection EndProject diff --git a/src/JT808.Protocol.Extensions.JT1078.Test/JT808LocationAttach.cs b/src/JT808.Protocol.Extensions.JT1078.Test/JT808LocationAttach.cs index 6be3cbb..9f94c3b 100644 --- a/src/JT808.Protocol.Extensions.JT1078.Test/JT808LocationAttach.cs +++ b/src/JT808.Protocol.Extensions.JT1078.Test/JT808LocationAttach.cs @@ -39,32 +39,33 @@ namespace JT808.Protocol.Extensions.JT1078.Test }; jT808UploadLocationRequest.JT808LocationAttachData.Add(0x14, new JT808_0x0200_0x14 { - VideoRelateAlarm = 100 + VideoRelateAlarm = 100 }); jT808UploadLocationRequest.JT808LocationAttachData.Add(0x15, new JT808_0x0200_0x15 { - VideoSignalLoseAlarmStatus = 100 + VideoSignalLoseAlarmStatus = 100 }); jT808UploadLocationRequest.JT808LocationAttachData.Add(0x16, new JT808_0x0200_0x16 { - VideoSignalOcclusionAlarmStatus = 100 + VideoSignalOcclusionAlarmStatus = 100 }); jT808UploadLocationRequest.JT808LocationAttachData.Add(0x17, new JT808_0x0200_0x17 { - StorageFaultAlarmStatus = 100 + StorageFaultAlarmStatus = 100 }); jT808UploadLocationRequest.JT808LocationAttachData.Add(0x18, new JT808_0x0200_0x18 { - AbnormalDrivingBehaviorAlarmInfo = 100 + AbnormalDrivingBehaviorAlarmType = 100, + FatigueLevel = 88 }); var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString(); - Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C00001807151010101404000000641504000000641604000000641702006418020064", hex); + Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C0000180715101010140400000064150400000064160400000064170200641803006458", hex); } [Fact] public void Test2() { - byte[] bodys = "000000010000000200BA7F0E07E4F11C0028003C00001807151010101404000000641504000000641604000000641702006418020064".ToHexBytes(); + byte[] bodys = "000000010000000200BA7F0E07E4F11C0028003C0000180715101010140400000064150400000064160400000064170200641803006458".ToHexBytes(); JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize(bodys); Assert.Equal(1u, jT808UploadLocationRequest.AlarmFlag); Assert.Equal(DateTime.Parse("2018-07-15 10:10:10"), jT808UploadLocationRequest.GPSTime); @@ -76,7 +77,15 @@ namespace JT808.Protocol.Extensions.JT1078.Test Assert.Equal(100u, ((JT808_0x0200_0x15)jT808UploadLocationRequest.JT808LocationAttachData[0x15]).VideoSignalLoseAlarmStatus); Assert.Equal(100u, ((JT808_0x0200_0x16)jT808UploadLocationRequest.JT808LocationAttachData[0x16]).VideoSignalOcclusionAlarmStatus); Assert.Equal(100u, ((JT808_0x0200_0x17)jT808UploadLocationRequest.JT808LocationAttachData[0x17]).StorageFaultAlarmStatus); - Assert.Equal(100u, ((JT808_0x0200_0x18)jT808UploadLocationRequest.JT808LocationAttachData[0x18]).AbnormalDrivingBehaviorAlarmInfo); + Assert.Equal(100u, ((JT808_0x0200_0x18)jT808UploadLocationRequest.JT808LocationAttachData[0x18]).AbnormalDrivingBehaviorAlarmType); + Assert.Equal(88, ((JT808_0x0200_0x18)jT808UploadLocationRequest.JT808LocationAttachData[0x18]).FatigueLevel); + } + + [Fact] + public void Test3() + { + byte[] bodys = "000000010000000200BA7F0E07E4F11C0028003C0000180715101010140400000064150400000064160400000064170200641803006458".ToHexBytes(); + string json = JT808Serializer.Analyze(bodys); } } } diff --git a/src/JT808.Protocol.Extensions.JT1078.Test/JT808_0x0200Test.cs b/src/JT808.Protocol.Extensions.JT1078.Test/JT808_0x0200Test.cs new file mode 100644 index 0000000..0158215 --- /dev/null +++ b/src/JT808.Protocol.Extensions.JT1078.Test/JT808_0x0200Test.cs @@ -0,0 +1,114 @@ +using JT808.Protocol.Extensions.JT1078.MessageBody; +using JT808.Protocol.Extensions.JT1078.Enums; +using JT808.Protocol.MessageBody; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace JT808.Protocol.Extensions.JT1078.Test +{ + public class JT808_0x0200Test + { + JT808Serializer JT808Serializer; + public JT808_0x0200Test() + { + IServiceCollection serviceDescriptors1 = new ServiceCollection(); + serviceDescriptors1 + .AddJT808Configure() + .AddJT1078Configure(); + var ServiceProvider1 = serviceDescriptors1.BuildServiceProvider(); + var defaultConfig = ServiceProvider1.GetRequiredService(); + JT808Serializer = defaultConfig.GetSerializer(); + } + + [Fact] + public void Test_0x14_1() + { + JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200 + { + AlarmFlag = 1, + Altitude = 40, + GPSTime = DateTime.Parse("2020-01-31 20:20:20"), + Lat = 12222222, + Lng = 132444444, + Speed = 60, + Direction = 0, + StatusFlag = 2, + JT808LocationAttachData = new Dictionary() + }; + jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_JT1078_Constants.JT808_0X0200_0x14, new JT808_0x0200_0x14 + { + VideoRelateAlarm = (uint)(VideoRelateAlarmType.视频信号遮挡报警 | VideoRelateAlarmType.其他视频设备故障报警) + }); + var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString(); + Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C000020013120202014040000000A", hex); + } + + [Fact] + public void Test_0x14_2() + { + byte[] bodys = "000000010000000200BA7F0E07E4F11C0028003C000020013120202014040000000A".ToHexBytes(); + JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize(bodys); + Assert.Equal((uint)1, jT808UploadLocationRequest.AlarmFlag); + Assert.Equal(DateTime.Parse("2020-01-31 20:20:20"), jT808UploadLocationRequest.GPSTime); + Assert.Equal(12222222, jT808UploadLocationRequest.Lat); + Assert.Equal(132444444, jT808UploadLocationRequest.Lng); + Assert.Equal(60, jT808UploadLocationRequest.Speed); + Assert.Equal((uint)2, jT808UploadLocationRequest.StatusFlag); + Assert.Equal((uint)(VideoRelateAlarmType.视频信号遮挡报警 | VideoRelateAlarmType.其他视频设备故障报警), ((JT808_0x0200_0x14)jT808UploadLocationRequest.JT808LocationAttachData[JT808_JT1078_Constants.JT808_0X0200_0x14]).VideoRelateAlarm); + } + + [Fact] + public void Test_0x14_3() + { + byte[] bodys = "000000010000000200BA7F0E07E4F11C0028003C000020013120202014040000000A".ToHexBytes(); + string json = JT808Serializer.Analyze(bodys); + } + + [Fact] + public void Test_0x15_1() + { + JT808_0x0200 jT808UploadLocationRequest = new JT808_0x0200 + { + AlarmFlag = 1, + Altitude = 40, + GPSTime = DateTime.Parse("2020-01-31 20:20:20"), + Lat = 12222222, + Lng = 132444444, + Speed = 60, + Direction = 0, + StatusFlag = 2, + JT808LocationAttachData = new Dictionary() + }; + jT808UploadLocationRequest.JT808LocationAttachData.Add(JT808_JT1078_Constants.JT808_0X0200_0x15, new JT808_0x0200_0x15 + { + VideoSignalLoseAlarmStatus=3 + }); + var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString(); + Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C0000200131202020150400000003", hex); + } + + [Fact] + public void Test_0x15_2() + { + byte[] bodys = "000000010000000200BA7F0E07E4F11C0028003C0000200131202020150400000003".ToHexBytes(); + JT808_0x0200 jT808UploadLocationRequest = JT808Serializer.Deserialize(bodys); + Assert.Equal((uint)1, jT808UploadLocationRequest.AlarmFlag); + Assert.Equal(DateTime.Parse("2020-01-31 20:20:20"), jT808UploadLocationRequest.GPSTime); + Assert.Equal(12222222, jT808UploadLocationRequest.Lat); + Assert.Equal(132444444, jT808UploadLocationRequest.Lng); + Assert.Equal(60, jT808UploadLocationRequest.Speed); + Assert.Equal((uint)2, jT808UploadLocationRequest.StatusFlag); + Assert.Equal(3u, ((JT808_0x0200_0x15)jT808UploadLocationRequest.JT808LocationAttachData[JT808_JT1078_Constants.JT808_0X0200_0x15]).VideoSignalLoseAlarmStatus); + } + + [Fact] + public void Test_0x15_3() + { + byte[] bodys = "000000010000000200BA7F0E07E4F11C0028003C0000200131202020150400000003".ToHexBytes(); + string json = JT808Serializer.Analyze(bodys); + } + } +} diff --git a/src/JT808.Protocol.Extensions.JT1078/Enums/VideoRelateAlarmType.cs b/src/JT808.Protocol.Extensions.JT1078/Enums/VideoRelateAlarmType.cs new file mode 100644 index 0000000..95527e3 --- /dev/null +++ b/src/JT808.Protocol.Extensions.JT1078/Enums/VideoRelateAlarmType.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.Protocol.Extensions.JT1078.Enums +{ + [Flags] + public enum VideoRelateAlarmType:uint + { + 视频信号丢失报警=0, + 视频信号遮挡报警=2, + 存储单元故障报警=4, + 其他视频设备故障报警=8, + 客车超员报警=16, + 异常驾驶行为报警=32, + 特殊报警录像达到存储阈值报警=64, + } +} diff --git a/src/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.csproj b/src/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.csproj index 96a1e37..09f4afb 100644 --- a/src/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.csproj +++ b/src/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.csproj @@ -15,7 +15,7 @@ https://github.com/SmallChi/JT1078/blob/master/LICENSE https://github.com/SmallChi/JT1078/blob/master/LICENSE false - 2.2.5 + 2.2.6 LICENSE @@ -28,7 +28,7 @@ - + diff --git a/src/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.xml b/src/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.xml index 918c483..59e98ba 100644 --- a/src/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.xml +++ b/src/JT808.Protocol.Extensions.JT1078/JT808.Protocol.Extensions.JT1078.xml @@ -78,6 +78,7 @@ 视频相关报警 + @@ -139,9 +140,14 @@ 数据 长度 - + - 异常驾驶行为报警详细描述 + 异常驾驶行为报警类型 + + + + + 疲劳程度 diff --git a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x14.cs b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x14.cs index 53e7179..c0e7289 100644 --- a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x14.cs +++ b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x14.cs @@ -1,6 +1,10 @@ using JT808.Protocol.Formatters; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; +using JT808.Protocol.Interfaces; +using System.Text.Json; +using JT808.Protocol.Extensions.JT1078.Enums; +using System.Linq; namespace JT808.Protocol.Extensions.JT1078.MessageBody { @@ -8,7 +12,7 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody /// 视频相关报警 /// 0x0200_0x14 /// - public class JT808_0x0200_0x14 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x14 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter,IJT808Analyze { public override byte AttachInfoId { get; set; } = 0x14; /// @@ -17,16 +21,38 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody public override byte AttachInfoLength { get; set; } = 4; /// /// 视频相关报警 + /// /// public uint VideoRelateAlarm { get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x14 value = new JT808_0x0200_0x14(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.VideoRelateAlarm = reader.ReadUInt32(); + writer.WriteNumber($"[{value.VideoRelateAlarm.ReadNumber()}]视频相关报警", value.VideoRelateAlarm); + var videoRelateAlarmFlags = JT808EnumExtensions.GetEnumTypes((int)value.VideoRelateAlarm, 32); + if (videoRelateAlarmFlags.Any()) + { + writer.WriteStartArray("视频报警集合"); + foreach (var item in videoRelateAlarmFlags) + { + writer.WriteStringValue(item.ToString()); + } + writer.WriteEndArray(); + } + } + public JT808_0x0200_0x14 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x14 jT808_0x0200_0x14 = new JT808_0x0200_0x14(); - jT808_0x0200_0x14.AttachInfoId = reader.ReadByte(); - jT808_0x0200_0x14.AttachInfoLength = reader.ReadByte(); - jT808_0x0200_0x14.VideoRelateAlarm = reader.ReadUInt32(); - return jT808_0x0200_0x14; + JT808_0x0200_0x14 value = new JT808_0x0200_0x14(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.VideoRelateAlarm = reader.ReadUInt32(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x14 value, IJT808Config config) diff --git a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x15.cs b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x15.cs index 8283e3d..db886b9 100644 --- a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x15.cs +++ b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x15.cs @@ -1,6 +1,9 @@ using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; +using System; +using System.Text.Json; namespace JT808.Protocol.Extensions.JT1078.MessageBody { @@ -8,7 +11,7 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody /// 视频信号丢失报警状态 /// 0x0200_0x15 /// - public class JT808_0x0200_0x15 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x15 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { public override byte AttachInfoId { get; set; } = 0x15; /// @@ -20,13 +23,40 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody /// public uint VideoSignalLoseAlarmStatus { get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x15 value = new JT808_0x0200_0x15(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.VideoSignalLoseAlarmStatus = reader.ReadUInt32(); + writer.WriteNumber($"[{value.VideoSignalLoseAlarmStatus.ReadNumber()}]视频信号丢失报警状态", value.VideoSignalLoseAlarmStatus); + var videoSignalLoseAlarmStatusSpan = Convert.ToString(value.VideoSignalLoseAlarmStatus, 2).PadLeft(32, '0').AsSpan(); + writer.WriteStartArray("视频信号丢失报警状态集合"); + int index = 0; + foreach (var item in videoSignalLoseAlarmStatusSpan) + { + if (item == '1') + { + writer.WriteStringValue($"{index}通道视频信号丢失"); + } + else + { + writer.WriteStringValue($"{index}通道视频正常"); + } + index++; + } + writer.WriteEndArray(); + } + public JT808_0x0200_0x15 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x15 jT808_0x0200_0x15 = new JT808_0x0200_0x15(); - jT808_0x0200_0x15.AttachInfoId = reader.ReadByte(); - jT808_0x0200_0x15.AttachInfoLength = reader.ReadByte(); - jT808_0x0200_0x15.VideoSignalLoseAlarmStatus = reader.ReadUInt32(); - return jT808_0x0200_0x15; + JT808_0x0200_0x15 value = new JT808_0x0200_0x15(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.VideoSignalLoseAlarmStatus = reader.ReadUInt32(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x15 value, IJT808Config config) diff --git a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x16.cs b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x16.cs index 036d968..5602d06 100644 --- a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x16.cs +++ b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x16.cs @@ -1,6 +1,9 @@ using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; +using System; +using System.Text.Json; namespace JT808.Protocol.Extensions.JT1078.MessageBody { @@ -8,7 +11,7 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody /// 视频信号遮挡报警状态 /// 0x0200_0x16 /// - public class JT808_0x0200_0x16 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x16 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { public override byte AttachInfoId { get; set; } = 0x16; /// @@ -20,13 +23,40 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody /// public uint VideoSignalOcclusionAlarmStatus { get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x16 value = new JT808_0x0200_0x16(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.VideoSignalOcclusionAlarmStatus = reader.ReadUInt32(); + writer.WriteNumber($"[{value.VideoSignalOcclusionAlarmStatus.ReadNumber()}]视频信号遮挡报警状态", value.VideoSignalOcclusionAlarmStatus); + var videoSignalOcclusionAlarmStatusSpan = Convert.ToString(value.VideoSignalOcclusionAlarmStatus, 2).PadLeft(32, '0').AsSpan(); + writer.WriteStartArray("视频信号遮挡报警状态集合"); + int index = 0; + foreach (var item in videoSignalOcclusionAlarmStatusSpan) + { + if (item == '1') + { + writer.WriteStringValue($"{index}通道视频信号遮挡"); + } + else + { + writer.WriteStringValue($"{index}通道视频正常"); + } + index++; + } + writer.WriteEndArray(); + } + public JT808_0x0200_0x16 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x16 jT808_0x0200_0x16 = new JT808_0x0200_0x16(); - jT808_0x0200_0x16.AttachInfoId = reader.ReadByte(); - jT808_0x0200_0x16.AttachInfoLength = reader.ReadByte(); - jT808_0x0200_0x16.VideoSignalOcclusionAlarmStatus = reader.ReadUInt32(); - return jT808_0x0200_0x16; + JT808_0x0200_0x16 value = new JT808_0x0200_0x16(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.VideoSignalOcclusionAlarmStatus = reader.ReadUInt32(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x16 value, IJT808Config config) diff --git a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x17.cs b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x17.cs index 0890082..373b8b9 100644 --- a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x17.cs +++ b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x17.cs @@ -1,6 +1,9 @@ using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; +using System; +using System.Text.Json; namespace JT808.Protocol.Extensions.JT1078.MessageBody { @@ -8,7 +11,7 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody /// 存储器故障报警状态 /// 0x0200_0x17 /// - public class JT808_0x0200_0x17 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x17 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { public override byte AttachInfoId { get; set; } = 0x17; /// @@ -20,13 +23,54 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody /// public ushort StorageFaultAlarmStatus{ get; set; } + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x17 value = new JT808_0x0200_0x17(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.StorageFaultAlarmStatus = reader.ReadUInt16(); + writer.WriteNumber($"[{value.StorageFaultAlarmStatus.ReadNumber()}]存储器故障报警状态", value.StorageFaultAlarmStatus); + var storageFaultAlarmStatusSpan = Convert.ToString(value.StorageFaultAlarmStatus, 2).PadLeft(16, '0').AsSpan(); + writer.WriteStartArray("存储器故障报警状态集合"); + int index = 0; + foreach (var item in storageFaultAlarmStatusSpan) + { + if (index < 4) + { + if (item == '1') + { + writer.WriteStringValue($"{index}灾备存储装置故障"); + } + else + { + writer.WriteStringValue($"{index}灾备存储装置正常"); + } + } + else + { + if (item == '1') + { + writer.WriteStringValue($"{index}主存储器故障"); + } + else + { + writer.WriteStringValue($"{index}主存储器正常"); + } + } + index++; + } + writer.WriteEndArray(); + } + public JT808_0x0200_0x17 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x17 jT808_0x0200_0x17 = new JT808_0x0200_0x17(); - jT808_0x0200_0x17.AttachInfoId = reader.ReadByte(); - jT808_0x0200_0x17.AttachInfoLength = reader.ReadByte(); - jT808_0x0200_0x17.StorageFaultAlarmStatus = reader.ReadUInt16(); - return jT808_0x0200_0x17; + JT808_0x0200_0x17 value = new JT808_0x0200_0x17(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.StorageFaultAlarmStatus = reader.ReadUInt16(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x17 value, IJT808Config config) diff --git a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x18.cs b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x18.cs index 80bc2f6..a71c553 100644 --- a/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x18.cs +++ b/src/JT808.Protocol.Extensions.JT1078/MessageBody/JT808_0x0200_0x18.cs @@ -1,6 +1,9 @@ using JT808.Protocol.Formatters; +using JT808.Protocol.Interfaces; using JT808.Protocol.MessageBody; using JT808.Protocol.MessagePack; +using System; +using System.Text.Json; namespace JT808.Protocol.Extensions.JT1078.MessageBody { @@ -8,31 +11,80 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody /// 异常驾驶行为报警详细描述 /// 0x0200_0x18 /// - public class JT808_0x0200_0x18 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter + public class JT808_0x0200_0x18 : JT808_0x0200_BodyBase, IJT808MessagePackFormatter, IJT808Analyze { public override byte AttachInfoId { get; set; } = 0x18; /// /// 数据 长度 /// - public override byte AttachInfoLength { get; set; } = 2; + public override byte AttachInfoLength { get; set; } = 3; /// - /// 异常驾驶行为报警详细描述 + /// 异常驾驶行为报警类型 /// - public ushort AbnormalDrivingBehaviorAlarmInfo { get; set; } + public ushort AbnormalDrivingBehaviorAlarmType{ get; set; } + /// + /// 疲劳程度 + /// + public byte FatigueLevel { get; set; } + + public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJT808Config config) + { + JT808_0x0200_0x18 value = new JT808_0x0200_0x18(); + value.AttachInfoId = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoId.ReadNumber()}]附加信息Id", value.AttachInfoId); + value.AttachInfoLength = reader.ReadByte(); + writer.WriteNumber($"[{value.AttachInfoLength.ReadNumber()}]附加信息长度", value.AttachInfoLength); + value.AbnormalDrivingBehaviorAlarmType = reader.ReadUInt16(); + writer.WriteNumber($"[{value.AbnormalDrivingBehaviorAlarmType.ReadNumber()}]异常驾驶行为报警类型", value.AbnormalDrivingBehaviorAlarmType); + writer.WriteStartArray("视频信号遮挡报警状态集合"); + var abnormalDrivingBehaviorAlarmTypeSpan = Convert.ToString(value.AbnormalDrivingBehaviorAlarmType, 2).PadLeft(16, '0').AsSpan(); + int index = 0; + foreach (var item in abnormalDrivingBehaviorAlarmTypeSpan) + { + string tmpResult = item == '1' ? "有" : "无"; + if (index == 0) + { + writer.WriteStringValue($"[bit{index}疲劳]_{tmpResult}"); + } + else if (index == 1) + { + writer.WriteStringValue($"[bit{index}打电话]_{tmpResult}"); + } + else if (index == 2) + { + writer.WriteStringValue($"[bit{index}抽烟]_{tmpResult}"); + } + else if (index>=3 && index<=10) + { + writer.WriteStringValue($"[bit{index}保留]_{tmpResult}"); + } + else + { + writer.WriteStringValue($"[bit{index}自定义]_{tmpResult}"); + } + index++; + } + writer.WriteEndArray(); + value.FatigueLevel = reader.ReadByte(); + writer.WriteNumber($"[{value.FatigueLevel.ReadNumber()}]疲劳程度", value.FatigueLevel); + } + public JT808_0x0200_0x18 Deserialize(ref JT808MessagePackReader reader, IJT808Config config) { - JT808_0x0200_0x18 jT808_0x0200_0x18 = new JT808_0x0200_0x18(); - jT808_0x0200_0x18.AttachInfoId = reader.ReadByte(); - jT808_0x0200_0x18.AttachInfoLength = reader.ReadByte(); - jT808_0x0200_0x18.AbnormalDrivingBehaviorAlarmInfo = reader.ReadUInt16(); - return jT808_0x0200_0x18; + JT808_0x0200_0x18 value = new JT808_0x0200_0x18(); + value.AttachInfoId = reader.ReadByte(); + value.AttachInfoLength = reader.ReadByte(); + value.AbnormalDrivingBehaviorAlarmType = reader.ReadUInt16(); + value.FatigueLevel = reader.ReadByte(); + return value; } public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0x18 value, IJT808Config config) { writer.WriteByte(value.AttachInfoId); writer.WriteByte(value.AttachInfoLength); - writer.WriteUInt16(value.AbnormalDrivingBehaviorAlarmInfo); + writer.WriteUInt16(value.AbnormalDrivingBehaviorAlarmType); + writer.WriteByte(value.FatigueLevel); } } }