Skip to content

Commit

Permalink
完善1078存储器信息
Browse files Browse the repository at this point in the history
  • Loading branch information
yedajiang44 committed Jul 24, 2024
1 parent cfa2cf2 commit ac47289
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
using System.Reflection;
using System.Linq;

namespace JT808.Protocol.Extensions.JT1078.Test
{
Expand Down Expand Up @@ -41,7 +40,7 @@ public void Test_0x14_1()
};
jT808UploadLocationRequest.CustomLocationAttachData.Add(JT808_JT1078_Constants.JT808_0X0200_0x14, new JT808_0x0200_0x14
{
VideoRelateAlarm = (uint)(VideoRelateAlarmType.video_signal_occlusion_alarm | VideoRelateAlarmType.other_video_equipment_fault_alarm)
VideoRelateAlarm = (uint)(VideoRelateAlarmType.video_signal_occlusion_alarm | VideoRelateAlarmType.other_video_equipment_fault_alarm)
});
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C000020013120202014040000000A", hex);
Expand Down Expand Up @@ -85,7 +84,7 @@ public void Test_0x15_1()
};
jT808UploadLocationRequest.CustomLocationAttachData.Add(JT808_JT1078_Constants.JT808_0X0200_0x15, new JT808_0x0200_0x15
{
VideoSignalLoseAlarmStatus=3
VideoSignalLoseAlarmStatus = 3
});
var hex = JT808Serializer.Serialize(jT808UploadLocationRequest).ToHexString();
Assert.Equal("000000010000000200BA7F0E07E4F11C0028003C0000200131202020150400000003", hex);
Expand Down Expand Up @@ -133,5 +132,19 @@ public void Test_0x15_5()
byte[] bodys = "7e020040420100000000013419905507021200040000001410010213679206c4a97d01001300000002220720103957010400000e3e020200000302025825040000001030014531010814040000000115040000000c797e".ToHexBytes();
string json = JT808Serializer.Instance.Analyze<JT808Package>(bodys);
}

[Theory]
[InlineData("7e020040600100000000653695850003022a00000000000c000300145b2206312b7a002e000000002407021142520104000001c404020000030200001404000000041504000000001604000000001702000218030000001904000000002504000000002b0400000000300100310119520100c57e")]
public void Test_0x17(string hex)
{
var package = JT808Serializer.Deserialize(hex.ToHexBytes());
Assert.IsType<JT808_0x0200>(package.Bodies);

var _0x0200 = (JT808_0x0200)package.Bodies;
var _0x17 = _0x0200.CustomLocationAttachData.FirstOrDefault(x => x.Key == 0x017).Value;
Assert.IsType<JT808_0x0200_0x17>(_0x17);
var _0x0200_0x17 = (JT808_0x0200_0x17)_0x17;
Assert.True(_0x0200_0x17.StorageFault.FirstOrDefault(x => x.Index == 2).Fault);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace JT808.Protocol.Extensions.JT1078.MessageBody
/// 存储器故障报警状态
/// 0x0200_0x17
/// </summary>
public class JT808_0x0200_0x17 : JT808MessagePackFormatter<JT808_0x0200_0x17>, JT808_0x0200_CustomBodyBase, IJT808Analyze
public class JT808_0x0200_0x17 : JT808MessagePackFormatter<JT808_0x0200_0x17>, JT808_0x0200_CustomBodyBase, IJT808Analyze
{
/// <summary>
///
Expand All @@ -24,7 +24,20 @@ public class JT808_0x0200_0x17 : JT808MessagePackFormatter<JT808_0x0200_0x17>, J
/// <summary>
/// 存储器故障报警状态
/// </summary>
public ushort StorageFaultAlarmStatus{ get; set; }
public ushort StorageFaultAlarmStatus { get; set; }

/// <summary>
/// 存储器故障集合
/// <para>表示第 1 ~ 12 个主存储器</para>
/// </summary>
public List<FaultItem> StorageFault { get; set; } = new();

/// <summary>
/// 灾备存储故障集合
/// <para>表示第 1 ~ 4 个灾备存储装置</para>
/// </summary>
public List<FaultItem> DisasterFault { get; set; } = new();

/// <summary>
///
/// </summary>
Expand All @@ -40,35 +53,13 @@ public void Analyze(ref JT808MessagePackReader reader, Utf8JsonWriter writer, IJ
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++;
}
FaultItem.Parse(value.StorageFaultAlarmStatus, out var storageFault, out var disasterFault);
storageFault.ForEach(x => writer.WriteStringValue($"{x.Index}主存储器{(x.Fault ? "故障" : "正常")}"));
disasterFault.ForEach(x => writer.WriteStringValue($"{x.Index}灾备存储装置{(x.Fault ? "故障" : "正常")}"));
writer.WriteEndArray();
}
/// <summary>
Expand All @@ -83,6 +74,9 @@ public override JT808_0x0200_0x17 Deserialize(ref JT808MessagePackReader reader,
value.AttachInfoId = reader.ReadByte();
value.AttachInfoLength = reader.ReadByte();
value.StorageFaultAlarmStatus = reader.ReadUInt16();
FaultItem.Parse(value.StorageFaultAlarmStatus, out var storageFault, out var disasterFault);
value.StorageFault = storageFault;
value.DisasterFault = disasterFault;
return value;
}
/// <summary>
Expand All @@ -97,5 +91,32 @@ public override void Serialize(ref JT808MessagePackWriter writer, JT808_0x0200_0
writer.WriteByte(value.AttachInfoLength);
writer.WriteUInt16(value.StorageFaultAlarmStatus);
}

/// <summary>
/// 故障信息
/// </summary>
/// <param name="Index">存储器索引,表示第几个存储器,从1开始</param>
/// <param name="Fault">是否存在故障</param>
public record FaultItem(int Index, bool Fault)
{
/// <summary>
/// 解析故障信息
/// </summary>
/// <param name="value"></param>
/// <param name="storageFault"></param>
/// <param name="disasterFault"></param>
public static void Parse(ushort value, out List<FaultItem> storageFault, out List<FaultItem> disasterFault)
{
disasterFault = storageFault = [];
for (int i = 0; i < 12; i++)
{
storageFault.Add(new(i + 1, ((value >> i) & 1) > 0));
}
for (int i = 12; i < 16; i++)
{
disasterFault.Add(new(i + 1, ((value >> i) & 1) > 0));
}
}
}
}
}

0 comments on commit ac47289

Please sign in to comment.